Find Tiles for the AI to move to (00178ca4)

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
r4 = Acting Unit ID
r5 = Caster X
r6 = Caster Y
r7 = Map Level
00178ca4: 27bdfdc8 addiu r29,r29,0xfdc8
00178ca8: 8fa20248 lw r2,0x0248(r29)			Evaluate Action?
00178cac: afb10214 sw r17,0x0214(r29)
00178cb0: 3c118019 lui r17,0x8019
00178cb4: 8e31f4e0 lw r17,-0x0b20(r17)			r17 = Movement Related Data Pointer
00178cb8: afb00210 sw r16,0x0210(r29)
00178cbc: 3c108019 lui r16,0x8019
00178cc0: 8e10f4e4 lw r16,-0x0b1c(r16)			r16 = ?
00178cc4: afb3021c sw r19,0x021c(r29)
00178cc8: 3c138019 lui r19,0x8019
00178ccc: 8e73f4e8 lw r19,-0x0b18(r19)			r19 = ?
00178cd0: afb40220 sw r20,0x0220(r29)
00178cd4: 3c148019 lui r20,0x8019
00178cd8: 8e94f4f0 lw r20,-0x0b10(r20)			r20 = 18f4f0 ?
00178cdc: 8fa8024c lw r8,0x024c(r29)			r8 = Previous Routine's Pointer + 20
00178ce0: afbe0230 sw r30,0x0230(r29)
00178ce4: 00a0f021 addu r30,r5,r0				r30 = Acting Unit X
00178ce8: afb50224 sw r21,0x0224(r29)
00178cec: 00c0a821 addu r21,r6,r0				r21 = Acting Unit Y
00178cf0: afb60228 sw r22,0x0228(r29)
00178cf4: 00e0b021 addu r22,r7,r0				r22 = Acting Unit Map Level
00178cf8: afb7022c sw r23,0x022c(r29)
00178cfc: 0000b821 addu r23,r0,r0				r23 = 0
00178d00: afbf0234 sw r31,0x0234(r29)
00178d04: afb20218 sw r18,0x0218(r29)
00178d08: 1040004b beq r2,r0,0x00178e38			Branch if Evaluate Action? = False
00178d0c: ad000000 sw r0,0x0000(r8)				0x20 = False
<Evaluate Action>
00178d10: 000410c0 sll r2,r4,0x03				Unit ID * 8
00178d14: 00441023 subu r2,r2,r4				Unit ID * 7
00178d18: 00021180 sll r2,r2,0x06				Unit ID * 1c0
00178d1c: 3c018019 lui r1,0x8019
00178d20: 00220821 addu r1,r1,r2
00178d24: 902308cd lbu r3,0x08cd(r1)			Load Unit ID (from Unit Data)
00178d28: 340200ff ori r2,r0,0x00ff
00178d2c: 14620003 bne r3,r2,0x00178d3c			Branch if Unit Exists
00178d30: 00000000 nop
00178d34: 0805e474 j 0x001791d0					Exit and return -1
00178d38: 2402ffff addiu r2,r0,0xffff
00178d3c: 0c05d10c jal 0x00174430				Evaluate Walkabilty on Map (Where unit can move to)
00178d40: 3412000f ori r18,r0,0x000f			r18 = 0x0f
00178d44: 3402007c ori r2,r0,0x007c
00178d48: a2220006 sb r2,0x0006(r17)			Save Move = 4 to Movement Related Data ([0x80 - Move] is how Move is stored)
00178d4c: 340300ff ori r3,r0,0x00ff
00178d50: 26620069 addiu r2,r19,0x0069			r19 = ? + 69
00178d54: a0430003 sb r3,0x0003(r2)
00178d58: 2652ffff addiu r18,r18,0xffff
00178d5c: 0641fffd bgez r18,0x00178d54			Do 0x0f times	
00178d60: 2442fff9 addiu r2,r2,0xfff9
00178d64: 0c05d3a1 jal 0x00174e84				Evaluate Map Walkability (Water Depth, Move on Lava?, etc.)
00178d68: 34040001 ori r4,r0,0x0001
00178d6c: 92230008 lbu r3,0x0008(r17)			Load Y
00178d70: 92220018 lbu r2,0x0018(r17)			Load Max X
00178d74: 00000000 nop
00178d78: 00620018 mult r3,r2					Y * Max X
00178d7c: 92220009 lbu r2,0x0009(r17)			Load Map Level
00178d80: 92240007 lbu r4,0x0007(r17)			Load X
00178d84: 00021200 sll r2,r2,0x08
00178d88: 00001812 mflo r3						Y * Max X
00178d8c: 00431021 addu r2,r2,r3				
00178d90: 00441821 addu r3,r2,r4				Y * Max X + X + Map Level
00178d94: 00031080 sll r2,r3,0x02				"" * 4
00178d98: 00431021 addu r2,r2,r3				"" * 5 (Get Tile Pointer)
00178d9c: 3c048019 lui r4,0x8019
00178da0: 24842dd8 addiu r4,r4,0x2dd8			Moveable/Targetable Grid Panel
00178da4: 00442821 addu r5,r2,r4				Get Current Tile from Grid		
00178da8: 02831821 addu r3,r20,r3				Tile Pointer + 18f4f0
00178dac: a0a00003 sb r0,0x0003(r5)				Clear ?
00178db0: a0a00000 sb r0,0x0000(r5)				Clear AoE
00178db4: 90620000 lbu r2,0x0000(r3)			Load ?
00178db8: 00000000 nop
00178dbc: 304200fe andi r2,r2,0x00fe
00178dc0: a0620000 sb r2,0x0000(r3)				Remove 0x01 from ?
00178dc4: 34020004 ori r2,r0,0x0004
00178dc8: a2020054 sb r2,0x0054(r16)
00178dcc: a2020055 sb r2,0x0055(r16)
00178dd0: 340200ff ori r2,r0,0x00ff
00178dd4: a0a00000 sb r0,0x0000(r5)				Clear AoE
00178dd8: a0a20004 sb r2,0x0004(r5)				Default tile to Obstructed
00178ddc: 92220018 lbu r2,0x0018(r17)			Load Max X
00178de0: 00000000 nop
00178de4: 02a20018 mult r21,r2					Acting Unit's Y * Max X
00178de8: 00161200 sll r2,r22,0x08				Acting Unit Map Level * 100
00178dec: 00001812 mflo r3						Acting Unit's Y * Max X
00178df0: 00431021 addu r2,r2,r3				Acting Unit's Y * Max X + Map Level
00178df4: 005e1821 addu r3,r2,r30				"" + Acting Unit's X
00178df8: 00031080 sll r2,r3,0x02				Acting Unit Tile Pointer * 4
00178dfc: 00431021 addu r2,r2,r3				"" * 5
00178e00: 00442821 addu r5,r2,r4				"" + MoveTarget Grid Panel
00178e04: 3402007d ori r2,r0,0x007d				(Is this supposed to represent a 3 movement minimum?)
00178e08: 02831821 addu r3,r20,r3				? + Acting Tile Pointer
00178e0c: a0a20000 sb r2,0x0000(r5)				Save desired minimum movement?
00178e10: 90620000 lbu r2,0x0000(r3)			Load AoE?
00178e14: 00000000 nop
00178e18: 34420001 ori r2,r2,0x0001
00178e1c: a0620000 sb r2,0x0000(r3)				Mark AoE?
00178e20: 34020001 ori r2,r0,0x0001
00178e24: a0a00004 sb r0,0x0004(r5)				Tile is not obstructed
00178e28: 3c018019 lui r1,0x8019
00178e2c: ac20f7e8 sw r0,-0x0818(r1)			Clear word
00178e30: 0805e393 j 0x00178e4c
00178e34: a2220023 sb r2,0x0023(r17)			Save ? as true
<Haven't decided on an action yet>
00178e38: 3c048019 lui r4,0x8019
00178e3c: 24843924 addiu r4,r4,0x3924			r4 = Unit AI Extended Status Data
00178e40: 3c051f80 lui r5,0x1f80				r5 = 0x1f800000
00178e44: 0c017895 jal 0x0005e254				Save every unit's AI Extended Status data to 0x1f800000 (Store X Byte into Y)
00178e48: 34060400 ori r6,r0,0x0400				r6 = 0x0400
00178e4c: 9223000e lbu r3,0x000e(r17)			Load Bypass Obstacle?
00178e50: 34020001 ori r2,r0,0x0001
00178e54: 14620015 bne r3,r2,0x00178eac			Branch if Unit can Bypass Obstacle? (Set when Move Underwater/Teleport)
<Clear all AoE>
00178e58: 34030001 ori r3,r0,0x0001
00178e5c: 341201ff ori r18,r0,0x01ff
00178e60: 3c028019 lui r2,0x8019
00178e64: 244237d3 addiu r2,r2,0x37d3			Load MoveTarget Grid Panel (From last byte)
00178e68: a0430000 sb r3,0x0000(r2)				Clear all AoE
00178e6c: 2652ffff addiu r18,r18,0xffff
00178e70: 0641fffd bgez r18,0x00178e68			Loop and clear all tiles from AoE starting backwards
00178e74: 2442fffb addiu r2,r2,0xfffb
00178e78: 0805e46b j 0x001791ac
00178e7c: 00000000 nop
<r23 has been set>
00178e80: 3c058019 lui r5,0x8019
00178e84: 24a53924 addiu r5,r5,0x3924			r5 = Unit AI Extended Status Data
00178e88: 34060400 ori r6,r0,0x0400				r6 = 0x0400 (Unit AI Extended Status Data's size)
00178e8c: 8fa8024c lw r8,0x024c(r29)			r8 = Previous Routine's Pointer + 20
00178e90: 34020001 ori r2,r0,0x0001
00178e94: 3c018019 lui r1,0x8019
00178e98: ac32f7e8 sw r18,-0x0818(r1)			Save Move Counter
00178e9c: 0c017895 jal 0x0005e254				Save every unit's AI Extended Status data to 0x1f800000 (Store X Byte into Y)
00178ea0: ad020000 sw r2,0x0000(r8)				0x20 = Unit cannot Move?
00178ea4: 0805e474 j 0x001791d0					Exit and return 0
00178ea8: 00001021 addu r2,r0,r0
<Unit can bypass obstacles?>
00178eac: 3c128019 lui r18,0x8019
00178eb0: 8e52f7e8 lw r18,-0x0818(r18)			Load Desired? Move
00178eb4: 92220006 lbu r2,0x0006(r17)			Load Move (Defaults to 4 Move)
00178eb8: 00000000 nop
00178ebc: 0242102a slt r2,r18,r2
00178ec0: 104000ba beq r2,r0,0x001791ac			Branch to last routine and exit if desired move is out of reach?
00178ec4: 00000000 nop
<Initialize>
00178ec8: 0000f021 addu r30,r0,r0
00178ecc: 3c168019 lui r22,0x8019
00178ed0: 26d6f8cc addiu r22,r22,0xf8cc
00178ed4: 3c158019 lui r21,0x8019
00178ed8: 26b52dd8 addiu r21,r21,0x2dd8
00178edc: 27b30010 addiu r19,r29,0x0010
<Move Loop>
00178ee0: 8fa80250 lw r8,0x0250(r29)				Load isNormalMovement
00178ee4: 00000000 nop
00178ee8: 11000007 beq r8,r0,0x00178f08				Branch if not normal movement (Teleport, etc.)
00178eec: 00000000 nop
00178ef0: 0c066bbc jal 0x0019aef0					Frame Data RNG wrapper
00178ef4: 00000000 nop
00178ef8: 10400003 beq r2,r0,0x00178f08				Branch if the Frame RNG said false
00178efc: 00000000 nop
00178f00: 16e0ffdf bne r23,r0,0x00178e80			Branch back and exit if r23 has been set (only set at the very end)
00178f04: 3c041f80 lui r4,0x1f80					Load AI Extended Status
00178f08: 92020062 lbu r2,0x0062(r16)				Load ?
00178f0c: 00000000 nop
00178f10: 104000a6 beq r2,r0,0x001791ac				Last Routine and Exit if false
00178f14: 00000000 nop
00178f18: a600002a sh r0,0x002a(r16)				Clear Map Level
<Map Level Loop (Inner)>
00178f1c: 8602002a lh r2,0x002a(r16)				Get Map Level before it's overwritten
00178f20: a6000028 sh r0,0x0028(r16)				Clear Y
00178f24: 00021200 sll r2,r2,0x08
00178f28: a602002c sh r2,0x002c(r16)
00178f2c: 92220019 lbu r2,0x0019(r17)				Load Max Y
00178f30: 00000000 nop
00178f34: 03c2102a slt r2,r30,r2
00178f38: 1040003e beq r2,r0,0x00179034				Branch if Current X is out of bounds
00178f3c: 00000000 nop
<Inner Y Loop>
00178f40: 86030028 lh r3,0x0028(r16)				Y?			
00178f44: 92220018 lbu r2,0x0018(r17)				Load Max X
00178f48: 00000000 nop
00178f4c: 00620018 mult r3,r2						Max X * Y?
00178f50: a6000026 sh r0,0x0026(r16)				Clear ?
00178f54: 9603002c lhu r3,0x002c(r16)				X?
00178f58: 00001012 mflo r2
00178f5c: 00621821 addu r3,r3,r2					Max X * Y? + X?
00178f60: a603002e sh r3,0x002e(r16)				Save Tile Pointer
00178f64: 92220018 lbu r2,0x0018(r17)				Load Max X
00178f68: 00000000 nop
00178f6c: 03c2102a slt r2,r30,r2					
00178f70: 10400026 beq r2,r0,0x0017900c				<Inner Y++> if Current X is out of bounds (Why compare to both Max X and Y?)
00178f74: 00000000 nop
<Inner X Loop>
00178f78: 9602002e lhu r2,0x002e(r16)				Load Tile Pointer
00178f7c: 96030026 lhu r3,0x0026(r16)				Load Cleared ? (High Tile?)
00178f80: 00000000 nop
00178f84: 00431021 addu r2,r2,r3					Tile Pointer + ?
00178f88: a602001a sh r2,0x001a(r16)				Save Tile Pointer
00178f8c: 00021400 sll r2,r2,0x10					Tile Pointer * 10000
00178f90: 00021343 sra r2,r2,0x0d					Tile Pointer / 2000
00178f94: 8603001a lh r3,0x001a(r16)				Load Saved Tile Pointer
00178f98: 00561021 addu r2,r2,r22					Tile Pointer / 2000 + Map Level
00178f9c: ae020000 sw r2,0x0000(r16)				Save Tile Pointer * 8
00178fa0: 00031080 sll r2,r3,0x02					Saved Tile Pointer * 4
00178fa4: 00431021 addu r2,r2,r3					Saved Tile Pointer * 5
00178fa8: 8603001a lh r3,0x001a(r16)				Load Saved Tile Pointer
00178fac: 00551021 addu r2,r2,r21					Get Current Tile from MoveTarget Grid Panel
00178fb0: ae020008 sw r2,0x0008(r16)				Save Current Tile Pointer
00178fb4: 02831021 addu r2,r20,r3 					Save Tile POinter + 18f4f0
00178fb8: 90420000 lbu r2,0x0000(r2)				Load ?
00178fbc: 02631821 addu r3,r19,r3					r3 = 18f4e8 + Tile Pointer
00178fc0: 30420001 andi r2,r2,0x0001
00178fc4: a0620000 sb r2,0x0000(r3)					Save flag to 18f4e8 + Tile Pointer
00178fc8: 8603001a lh r3,0x001a(r16)
00178fcc: 00000000 nop
00178fd0: 02831821 addu r3,r20,r3
00178fd4: 90620000 lbu r2,0x0000(r3)
00178fd8: 00000000 nop
00178fdc: 304200fe andi r2,r2,0x00fe
00178fe0: a0620000 sb r2,0x0000(r3)
<Inner X++>
00178fe4: 96020026 lhu r2,0x0026(r16)
00178fe8: 00000000 nop
00178fec: 24420001 addiu r2,r2,0x0001
00178ff0: a6020026 sh r2,0x0026(r16)
00178ff4: 00021400 sll r2,r2,0x10
00178ff8: 92230018 lbu r3,0x0018(r17)				Load Max X
00178ffc: 00021403 sra r2,r2,0x10
00179000: 0043102a slt r2,r2,r3
00179004: 1440ffdc bne r2,r0,0x00178f78				Branch if X? is out of bounds
00179008: 00000000 nop
<Inner Y++>
0017900c: 96020028 lhu r2,0x0028(r16)
00179010: 00000000 nop
00179014: 24420001 addiu r2,r2,0x0001
00179018: a6020028 sh r2,0x0028(r16)
0017901c: 00021400 sll r2,r2,0x10
00179020: 92230019 lbu r3,0x0019(r17)				Load Max Y
00179024: 00021403 sra r2,r2,0x10
00179028: 0043102a slt r2,r2,r3
0017902c: 1440ffc4 bne r2,r0,0x00178f40				Branch if Y? is out of bounds
00179030: 00000000 nop
<Map Level++ (Inner)>
00179034: 9602002a lhu r2,0x002a(r16)
00179038: 00000000 nop
0017903c: 24420001 addiu r2,r2,0x0001
00179040: a602002a sh r2,0x002a(r16)
00179044: 00021400 sll r2,r2,0x10					Increase value by * 10000 just before it gets saved?
00179048: 00021403 sra r2,r2,0x10
0017904c: 28420002 slti r2,r2,0x0002
00179050: 1440ffb2 bne r2,r0,0x00178f1c				Branch for High Tile
00179054: 00000000 nop
00179058: a2000062 sb r0,0x0062(r16)
0017905c: a600002a sh r0,0x002a(r16)
<Map Level Loop (Main)>
00179060: 8602002a lh r2,0x002a(r16)
00179064: a6000028 sh r0,0x0028(r16)
00179068: 00021200 sll r2,r2,0x08
0017906c: a602002c sh r2,0x002c(r16)
00179070: 92220019 lbu r2,0x0019(r17)				Load Max Y
00179074: 00000000 nop
00179078: 1040003e beq r2,r0,0x00179174				<Map Level++> if Max Y is 0
0017907c: 00000000 nop
<Y Loop>
00179080: 86030028 lh r3,0x0028(r16)
00179084: 92220018 lbu r2,0x0018(r17)				Load Max X
00179088: 00000000 nop
0017908c: 00620018 mult r3,r2						Max X * ?
00179090: a6000026 sh r0,0x0026(r16)
00179094: 9603002c lhu r3,0x002c(r16)
00179098: 00001012 mflo r2
0017909c: 00621821 addu r3,r3,r2
001790a0: a603002e sh r3,0x002e(r16)
001790a4: 92220018 lbu r2,0x0018(r17)				Load Max X
001790a8: 00000000 nop
001790ac: 10400027 beq r2,r0,0x0017914c				<Y++> if Max X is 0
001790b0: 00000000 nop
<X Loop>
001790b4: 9602002e lhu r2,0x002e(r16)
001790b8: 96030026 lhu r3,0x0026(r16)
001790bc: 00000000 nop
001790c0: 00431021 addu r2,r2,r3
001790c4: a602001a sh r2,0x001a(r16)
001790c8: 00021400 sll r2,r2,0x10
001790cc: 00021343 sra r2,r2,0x0d
001790d0: 8603001a lh r3,0x001a(r16)
001790d4: 00561021 addu r2,r2,r22
001790d8: ae020000 sw r2,0x0000(r16)
001790dc: 00031080 sll r2,r3,0x02
001790e0: 00431021 addu r2,r2,r3
001790e4: 8603001a lh r3,0x001a(r16)
001790e8: 00551021 addu r2,r2,r21
001790ec: ae020008 sw r2,0x0008(r16)
001790f0: 02631821 addu r3,r19,r3
001790f4: 90620000 lbu r2,0x0000(r3)
001790f8: 00000000 nop
001790fc: 10400009 beq r2,r0,0x00179124				<X++ if false>
00179100: 00000000 nop
00179104: 0c05de77 jal 0x001779dc					Multi Functions for Movement Routine
00179108: a2000040 sb r0,0x0040(r16)
0017910c: 9222001d lbu r2,0x001d(r17)				Load Teleport Check?
00179110: 00000000 nop
00179114: 14400003 bne r2,r0,0x00179124				<X++> if Teleport (Checked off when Teleport in 174430)
00179118: 00000000 nop
0017911c: 0c05df02 jal 0x00177c08					Multi Functions for Movement Routine (Longer than the one above)
00179120: a2000040 sb r0,0x0040(r16)
<X++>
00179124: 96020026 lhu r2,0x0026(r16)
00179128: 00000000 nop
0017912c: 24420001 addiu r2,r2,0x0001
00179130: a6020026 sh r2,0x0026(r16)
00179134: 00021400 sll r2,r2,0x10
00179138: 92230018 lbu r3,0x0018(r17)				Load Max X
0017913c: 00021403 sra r2,r2,0x10
00179140: 0043102a slt r2,r2,r3
00179144: 1440ffdb bne r2,r0,0x001790b4				Loop until Max X	
00179148: 00000000 nop
<Y++>
0017914c: 96020028 lhu r2,0x0028(r16)
00179150: 00000000 nop
00179154: 24420001 addiu r2,r2,0x0001
00179158: a6020028 sh r2,0x0028(r16)
0017915c: 00021400 sll r2,r2,0x10
00179160: 92230019 lbu r3,0x0019(r17)
00179164: 00021403 sra r2,r2,0x10
00179168: 0043102a slt r2,r2,r3
0017916c: 1440ffc4 bne r2,r0,0x00179080				Loop until Max Y
00179170: 00000000 nop
<Map Level++>
00179174: 9602002a lhu r2,0x002a(r16)
00179178: 00000000 nop
0017917c: 24420001 addiu r2,r2,0x0001
00179180: a602002a sh r2,0x002a(r16)
00179184: 00021400 sll r2,r2,0x10
00179188: 00021403 sra r2,r2,0x10
0017918c: 28420002 slti r2,r2,0x0002
00179190: 1440ffb3 bne r2,r0,0x00179060				Loop again for high tiles		
00179194: 00000000 nop
<Move Counter++>
00179198: 92220006 lbu r2,0x0006(r17)				Load Move
0017919c: 26520001 addiu r18,r18,0x0001				Move Counter++
001791a0: 0242102a slt r2,r18,r2
001791a4: 1440ff4e bne r2,r0,0x00178ee0				Loop until Move (Move usually defaults to 7c, increment until 80)
001791a8: 34170001 ori r23,r0,0x0001
<Exit>
001791ac: 0c05d4a2 jal 0x00175288
001791b0: 00000000 nop
001791b4: 34030001 ori r3,r0,0x0001
001791b8: 3c018019 lui r1,0x8019
001791bc: ac23f510 sw r3,-0x0af0(r1)
001791c0: 9223000d lbu r3,0x000d(r17)
001791c4: 86020018 lh r2,0x0018(r16)
001791c8: 3c018019 lui r1,0x8019
001791cc: ac23f514 sw r3,-0x0aec(r1)
001791d0: 8fbf0234 lw r31,0x0234(r29)
001791d4: 8fbe0230 lw r30,0x0230(r29)
001791d8: 8fb7022c lw r23,0x022c(r29)
001791dc: 8fb60228 lw r22,0x0228(r29)
001791e0: 8fb50224 lw r21,0x0224(r29)
001791e4: 8fb40220 lw r20,0x0220(r29)
001791e8: 8fb3021c lw r19,0x021c(r29)
001791ec: 8fb20218 lw r18,0x0218(r29)
001791f0: 8fb10214 lw r17,0x0214(r29)
001791f4: 8fb00210 lw r16,0x0210(r29)
001791f8: 27bd0238 addiu r29,r29,0x0238
001791fc: 03e00008 jr r31
00179200: 00000000 nop