Difference between revisions of "AI Target Priority Super Routine (001999c8)"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m (Dokurider moved page 001999c8 - 00199b94 to AI Target Priority Super Routine (001999c8): Renaming and adding new documentation)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<font face='Courier New'>
+
'''BATTLE.BIN : ''' :  - AI_Target_Priority_Super_Routine_(001999c8)
 +
Set Priority score for each reachable tiles and  store it at AI 0x5f4 as a negative value (0 - AI 0x32)
 +
------------------------------------------------------------------------------------------
 +
Parameter : Nothing
 +
Return : r2 = 0x00 Default value
 +
          r2 = -0x01 if routine Abort while looping (Seems to be tied to [[VSync_call]] - Update screen and com back ?)
 +
------------------------------------------------------------------------------------------
 +
001999c8: 3c02801a lui r2,0x801a            |
 +
001999cc: 90420d7b lbu r2,0x0d7b(r2)        |{{f/load|AI 0x19b7}}
 +
001999d0: 27bdffc8 addiu r29,r29,-0x0038    |
 +
001999d4: afb3002c sw r19,0x002c(r29)        |
 +
001999d8: 3c13801a lui r19,0x801a            |
 +
001999dc: 2673f3c4 addiu r19,r19,-0x0c3c    |{{f/adr|0x8019f3c4 }}
 +
001999e0: afbf0034 sw r31,0x0034(r29)        |
 +
001999e4: afb40030 sw r20,0x0030(r29)        |
 +
001999e8: afb20028 sw r18,0x0028(r29)        |
 +
001999ec: afb10024 sw r17,0x0024(r29)        |
 
   
 
   
  001999c8: 3c02801a lui r2,0x801a
+
  {{f/sec|<nowiki>=== AI 0x19b7 <> 0x00 (resume where code returns -0x01 ?) ===</nowiki>}}
001999cc: 90420d7b lbu r2,0x0d7b(r2)
+
  001999f0: 10400019 beq r2,r0,0x00199a58     {{f/Cond|If 0x19b7 <> 0x00 }}
001999d0: 27bdffc8 addiu r29,r29,0xffc8
+
  001999f4: afb00020 sw r16,0x0020(r29)           |
001999d4: afb3002c sw r19,0x002c(r29)
+
  001999f8: 3c10801a lui r16,0x801a               |
001999d8: 3c13801a lui r19,0x801a
+
  001999fc: 9210f3dc lbu r16,-0x0c24(r16)         |{{f/load|Caster/ Focused X coordonates}} {{f/std|Could be the last coord. That caused the routine to returns -0x01}}
001999dc: 2673f3c4 addiu r19,r19,0xf3c4
+
  00199a00: 3c11801a lui r17,0x801a               |
001999e0: afbf0034 sw r31,0x0034(r29)
+
  00199a04: 9231f3de lbu r17,-0x0c22(r17)         |{{f/load|Caster/ Focused Y coordonates}}
001999e4: afb40030 sw r20,0x0030(r29)
+
  00199a08: 3c02801a lui r2,0x801a                 |
001999e8: afb20028 sw r18,0x0028(r29)
+
  00199a0c: 904201f1 lbu r2,0x01f1(r2)             |{{f/load|AI 0xe2d}} {{f/std|Offset for reachable Tile Table (0x0 All tiles, 0x1 Closer to target, 0x2 Away from target)}}
001999ec: afb10024 sw r17,0x0024(r29)
+
  00199a10: 3c12801a lui r18,0x801a               |
  001999f0: 10400019 beq r2,r0,0x00199a58
+
  00199a14: 9252f3dd lbu r18,-0x0c23(r18)         |{{f/load|Elevation}}
  001999f4: afb00020 sw r16,0x0020(r29)
+
  00199a18: 000218c0 sll r3,r2,0x03               |{{f/std|ID*8}}
  001999f8: 3c10801a lui r16,0x801a
+
  00199a1c: 00621821 addu r3,r3,r2                 |{{f/std|ID*9}}
  001999fc: 9210f3dc lbu r16,-0x0c24(r16) load acting unit X
+
  00199a20: 000318c0 sll r3,r3,0x03               |{{f/std|0x2ed Offset (0x48)}}
  00199a00: 3c11801a lui r17,0x801a
+
  00199a24: 00731821 addu r3,r3,r19               |
  00199a04: 9231f3de lbu r17,-0x0c22(r17) load acting unit Y
+
  00199a28: 24630a74 addiu r3,r3,0x0a74           |{{f/std|Prepare pointer to reachable tiles}}
  00199a08: 3c02801a lui r2,0x801a
+
  00199a2c: 001210c0 sll r2,r18,0x03               |
  00199a0c: 904201f1 lbu r2,0x01f1(r2) ??
+
  00199a30: 00521021 addu r2,r2,r18               |
  00199a10: 3c12801a lui r18,0x801a
+
  00199a34: 00021080 sll r2,r2,0x02               |{{f/std|Elevation offset (0x24)}}
  00199a14: 9252f3dd lbu r18,-0x0c23(r18) load map level
+
  00199a38: 00431021 addu r2,r2,r3                 |
  00199a18: 000218c0 sll r3,r2,0x03 ??*8
+
  00199a3c: 00111840 sll r3,r17,0x01               |{{f/std|Y row offset (Halfword)}}
  00199a1c: 00621821 addu r3,r3,r2 ??*9
+
  00199a40: 00621821 addu r3,r3,r2                 |{{f/adr|Pointer to AI Reachable Tiles (+offset based on 0xe2d)}}
  00199a20: 000318c0 sll r3,r3,0x03 ??*72
+
  00199a44: 94740000 lhu r20,0x0000(r3)           |{{f/load|ConsideredY row tiles flags}}
  00199a24: 00731821 addu r3,r3,r19
+
  00199a48: 080666bc j 0x00199af0                 {{f/jump|Jump/Return where routines stops}} {{f/loc|*Set Priority via [[AI End of turn, in between turn, etc.]]}}
  00199a28: 24630a74 addiu r3,r3,0x0a74
+
  00199a4c: 00000000 nop                           |
  00199a2c: 001210c0 sll r2,r18,0x03 maplevel*8
+
  00199a30: 00521021 addu r2,r2,r18 maplevel*9
+
                  {{f/sec|---Exit Section (reached by backward Jump)---}}
  00199a34: 00021080 sll r2,r2,0x02 maplevel*36
+
  00199a50: 080666dd j 0x00199b74                 {{f/jump|Jump to }} {{f/loc|END}} {{f/Returns|Return -0x01}}
  00199a38: 00431021 addu r2,r2,r3 maplevel*36 + r3 address
+
  00199a54: 2402ffff addiu r2,r0,-0x0001          |
  00199a3c: 00111840 sll r3,r17,0x01 Y coordinate*2
+
  00199a40: 00621821 addu r3,r3,r2
+
{{f/sec|<nowiki>=== SET PRIORITY for ALL CONSIDERED TILES ===</nowiki>}}
  00199a44: 94740000 lhu r20,0x0000(r3)
+
                                              '''<nowiki>Else 19b7 = 0x00</nowiki>'''
  00199a48: 080666bc j 0x00199af0
+
  00199a58: 00009021 addu r18,r0,r0               |{{f/std|Elevation counter}}
  00199a4c: 00000000 nop
+
  00199a5c: 3c01801a lui r1,0x801a                 |
  00199a50: 080666dd j 0x00199b74
+
  00199a60: a020f3d8 sb r0,-0x0c28(r1)             |{{f/store|Reset AI 0x14}} {{f/std|?? Used  AI_End_of_turn,_in_between_turn,_etc. (seems to depend on whether the caster has to move or not)}}
  00199a54: 2402ffff addiu r2,r0,0xffff
+
  00199a64: 3c01801a lui r1,0x801a                 |
  00199a58: 00009021 addu r18,r0,r0
+
  00199a68: a020f3e1 sb r0,-0x0c1f(r1)             |{{f/store|<nowiki>Set considered Skillset = 0x00 </nowiki>}} {{f/std|Tell the code This is a movement simulation only ?}}
  00199a5c: 3c01801a lui r1,0x801a
+
                                                {{f/bloop|LOOP - both elevation}}
  00199a60: a020f3d8 sb r0,-0x0c28(r1)
+
  00199a6c: 92620e3b lbu r2,0x0e3b(r19)               |{{f/load|Load Map Max Y}}
  00199a64: 3c01801a lui r1,0x801a
+
  00199a70: 00000000 nop                               |
  00199a68: a020f3e1 sb r0,-0x0c1f(r1)
+
  00199a74: 18400038 blez r2,0x00199b58               {{f/Cond|If Max Y is invalid : branch to}} {{f/loc|next Elevation iteration}}
  00199a6c: 92620e3b lbu r2,0x0e3b(r19)
+
  00199a78: 00008821 addu r17,r0,r0                   |{{f/std|Y counter}}
  00199a70: 00000000 nop
+
                                                    {{f/bloop|LOOP - All Y rows}}
  00199a74: 18400038 blez r2,0x00199b58
+
  00199a7c: 92620e2d lbu r2,0x0e2d(r19)                   |{{f/load|AI 0xe2d}} {{f/std|Offset for reachable Tile Table (0x0 All tiles, 0x1 Closer to target, 0x2 Away from target)}}
  00199a78: 00008821 addu r17,r0,r0
+
  00199a80: 00000000 nop                                   |
  00199a7c: 92620e2d lbu r2,0x0e2d(r19)
+
  00199a84: 000218c0 sll r3,r2,0x03                       |
  00199a80: 00000000 nop
+
  00199a88: 00621821 addu r3,r3,r2                         |
  00199a84: 000218c0 sll r3,r2,0x03
+
  00199a8c: 000318c0 sll r3,r3,0x03                       |{{f/std|0xe2d Offset (0x48)}}
  00199a88: 00621821 addu r3,r3,r2
+
  00199a90: 00731821 addu r3,r3,r19                       |
  00199a8c: 000318c0 sll r3,r3,0x03
+
  00199a94: 24630a74 addiu r3,r3,0x0a74                   |{{f/adr|AI 0xa74 Pointer (reachable tiles) + 0xe2d (0x48)}}
  00199a90: 00731821 addu r3,r3,r19
+
  00199a98: 001210c0 sll r2,r18,0x03                       |
  00199a94: 24630a74 addiu r3,r3,0x0a74
+
  00199a9c: 00521021 addu r2,r2,r18                       |
  00199a98: 001210c0 sll r2,r18,0x03
+
  00199aa0: 00021080 sll r2,r2,0x02                       |{{f/std|Elevation offset (0x24)}}
  00199a9c: 00521021 addu r2,r2,r18
+
  00199aa4: 00431021 addu r2,r2,r3                         |
  00199aa0: 00021080 sll r2,r2,0x02
+
  00199aa8: 00111840 sll r3,r17,0x01                       |{{f/std|Y offset (halfword)}}
  00199aa4: 00431021 addu r2,r2,r3
+
  00199aac: 00621821 addu r3,r3,r2                         |{{f/adr|This  iteration 0xa74 Pointer (Elevation and Y row) + 0xe2d offset(0x48) }} {{f/std|Reachable +/- Get closer or further offset}}
  00199aa8: 00111840 sll r3,r17,0x01
+
  00199ab0: 94740000 lhu r20,0x0000(r3)                   |{{f/load|This Y row tiles flags}}
  00199aac: 00621821 addu r3,r3,r2
+
  00199ab4: 00000000 nop                                   |
  00199ab0: 94740000 lhu r20,0x0000(r3)
+
  00199ab8: 12800022 beq r20,r0,0x00199b44                 {{f/Cond|If no flags in this row : branch to }} {{f/loc|Next Y row}}
  00199ab4: 00000000 nop
+
  00199abc: 00000000 nop                                   |
  00199ab8: 12800022 beq r20,r0,0x00199b44
+
  00199ac0: 92620e3a lbu r2,0x0e3a(r19)                   |{{f/load|Load Map Max X}}
  00199abc: 00000000 nop
+
  00199ac4: 00000000 nop                                   |
  00199ac0: 92620e3a lbu r2,0x0e3a(r19)
+
  00199ac8: 1840001e blez r2,0x00199b44                   {{f/Cond|If Max X is invalid : branch to }} {{f/loc|Next Y row}}
  00199ac4: 00000000 nop
+
  00199acc: 00008021 addu r16,r0,r0                       |{{f/std|Reset X counter}}
  00199ac8: 1840001e blez r2,0x00199b44
+
  00199ad0: 02141004 sllv r2,r20,r16                       |{{f/std|Shift Row flags : flag of interest is in 0x8000 position}}
  00199acc: 00008021 addu r16,r0,r0
+
                                                        {{f/bloop|LOOP - All X Tiles in row}}
  00199ad0: 02141004 sllv r2,r20,r16
+
  00199ad4: 30428000 andi r2,r2,0x8000                         |
  00199ad4: 30428000 andi r2,r2,0x8000
+
  00199ad8: 10400015 beq r2,r0,0x00199b30                     {{f/Cond|If This tile is OFF : branch to }} {{f/loc|Next Tile}}
  00199ad8: 10400015 beq r2,r0,0x00199b30
+
  00199adc: 00000000 nop                                       |
  00199adc: 00000000 nop
+
  00199ae0: a2700018 sb r16,0x0018(r19)                       |{{f/store|Save Current X}}
  00199ae0: a2700018 sb r16,0x0018(r19)
+
  00199ae4: a271001a sb r17,0x001a(r19)                       |{{f/store|Save Current Y}}
  00199ae4: a271001a sb r17,0x001a(r19)
+
  00199ae8: 0c066ec8 jal 0x0019bb20                           |{{f/jal|AI_Check_if_Unit_is_a_Crystal/Treasure_(0019bb20)|AI_Check_if_Unit_is_a_Crystal/Treasure_(0019bb20)}} {{f/std|Set Value of AI 0xcbf ( 801a0083 )}}
  00199ae8: 0c066ec8 jal 0x0019bb20                 [[0019bb20 - 0019bbb8]]
+
  00199aec: a2720019 sb r18,0x0019(r19)                       |{{f/store|Save Current Map Level}}
  00199aec: a2720019 sb r18,0x0019(r19)
+
                  {{f/sec|19b7 <> 0x00 jump here}}
  00199af0: 0c0674df jal 0x0019d37c                 [[AI End of turn, in between turn, etc.]]
+
  00199af0: 0c0674df jal 0x0019d37c                           |{{f/jal|AI End of turn, in between turn, etc.|AI End of turn, in between turn, etc.}} {{f/std| Set Priority score (AI 0x32) for each considered Tile}}
  00199af4: 00000000 nop
+
  00199af4: 00000000 nop                                       |
  00199af8: 2403ffff addiu r3,r0,0xffff
+
  00199af8: 2403ffff addiu r3,r0,-0x0001                      |
  00199afc: 1043ffd4 beq r2,r3,0x00199a50
+
  00199afc: 1043ffd4 beq r2,r3,0x00199a50                     {{f/Cond|If Routine above returns -0x01}} {{f/loc|Exit}} {{f/Returns|Return -0x01}}
  00199b00: 001210c0 sll r2,r18,0x03
+
  00199b00: 001210c0 sll r2,r18,0x03                           |
  00199b04: 00521021 addu r2,r2,r18
+
  00199b04: 00521021 addu r2,r2,r18                           |
  00199b08: 00021180 sll r2,r2,0x06
+
  00199b08: 00021180 sll r2,r2,0x06                           |{{f/std|Elevation offset (0x240)}}
  00199b0c: 00531021 addu r2,r2,r19
+
  00199b0c: 00531021 addu r2,r2,r19                           |{{f/std|AI Pointer + Map Level offset}}
  00199b10: 244205f4 addiu r2,r2,0x05f4
+
  00199b10: 244205f4 addiu r2,r2,0x05f4                       |{{f/adr|Prepare pointer to AI 0x5f4 Table (each tile priority score)}}
  00199b14: 00111940 sll r3,r17,0x05
+
  00199b14: 00111940 sll r3,r17,0x05                           |{{f/std|Y Row offset (0x20)}}
  00199b18: 00621821 addu r3,r3,r2
+
  00199b18: 00621821 addu r3,r3,r2                             |
  00199b1c: 00102040 sll r4,r16,0x01
+
  00199b1c: 00102040 sll r4,r16,0x01                           |{{f/std|X offset (1 halfword per tile)}}
  00199b20: 96620032 lhu r2,0x0032(r19)
+
  00199b20: 96620032 lhu r2,0x0032(r19)                       |{{f/load|This Tile Priority Score}} {{f/std|Tile Priority (could change because of crystal / Treasure/Poison Marsh etc...)}}
  00199b24: 00832021 addu r4,r4,r3
+
  00199b24: 00832021 addu r4,r4,r3                             |{{f/adr|Pointer to 0x8019f3c4 + 0x5f4 + Tile offset}}
  00199b28: 00021023 subu r2,r0,r2
+
  00199b28: 00021023 subu r2,r0,r2                             |{{f/std|-Priority}}
  00199b2c: a4820000 sh r2,0x0000(r4)
+
  00199b2c: a4820000 sh r2,0x0000(r4)                         |{{f/store|Save Tile Priority }}
  00199b30: 92620e3a lbu r2,0x0e3a(r19)
+
  00199b30: 92620e3a lbu r2,0x0e3a(r19)                       |{{f/load|Load Max X}}
  00199b34: 26100001 addiu r16,r16,0x0001
+
  00199b34: 26100001 addiu r16,r16,0x0001                     |{{f/std|Current X++}}
  00199b38: 0202102a slt r2,r16,r2
+
  00199b38: 0202102a slt r2,r16,r2                             |
  00199b3c: 1440ffe5 bne r2,r0,0x00199ad4
+
  00199b3c: 1440ffe5 bne r2,r0,0x00199ad4                 {{f/eloop|<nowiki>Loop until X = Max X</nowiki>}}
  00199b40: 02141004 sllv r2,r20,r16
+
  00199b40: 02141004 sllv r2,r20,r16                       |{{f/std|Row Coordinate * Current X}}
  00199b44: 92620e3b lbu r2,0x0e3b(r19)
+
  00199b44: 92620e3b lbu r2,0x0e3b(r19)                   |{{f/load|Load Max Y}}
  00199b48: 26310001 addiu r17,r17,0x0001
+
  00199b48: 26310001 addiu r17,r17,0x0001                 |{{f/std|Current Y++}}
  00199b4c: 0222102a slt r2,r17,r2
+
  00199b4c: 0222102a slt r2,r17,r2                         |{{f/std|Check if Y counter < max Y}}
  00199b50: 1440ffca bne r2,r0,0x00199a7c
+
  00199b50: 1440ffca bne r2,r0,0x00199a7c             {{f/eloop|<nowiki>Loop until Y = Max Y</nowiki>}}
  00199b54: 00000000 nop
+
  00199b54: 00000000 nop                                   |
  00199b58: 26520001 addiu r18,r18,0x0001
+
  00199b58: 26520001 addiu r18,r18,0x0001             |{{f/std|Map Level++}}
  00199b5c: 2a420002 slti r2,r18,0x0002
+
  00199b5c: 2a420002 slti r2,r18,0x0002               |
  00199b60: 1440ffc2 bne r2,r0,0x00199a6c
+
  00199b60: 1440ffc2 bne r2,r0,0x00199a6c         {{f/eloop|Loop for both low and high tiles}}
  00199b64: 00000000 nop
+
  00199b64: 00000000 nop                           |
  00199b68: 0c067c96 jal 0x0019f258                   [[Store units coordinates]]
+
  00199b68: 0c067c96 jal 0x0019f258           |{{f/jal|Store units coordinates|Store units coordinates}} {{f/std|Retore acting Units coordinates}}
  00199b6c: 26640e30 addiu r4,r19,0x0e30
+
  00199b6c: 26640e30 addiu r4,r19,0x0e30       |{{f/std|Pointer to 0x8019f3c4 + 0xe30}}
  00199b70: 00001021 addu r2,r0,r0
+
  00199b70: 00001021 addu r2,r0,r0             |{{f/Returns|Return 0x00}}
 
  00199b74: 8fbf0034 lw r31,0x0034(r29)
 
  00199b74: 8fbf0034 lw r31,0x0034(r29)
 
  00199b78: 8fb40030 lw r20,0x0030(r29)
 
  00199b78: 8fb40030 lw r20,0x0030(r29)
Line 117: Line 133:
 
  00199b90: 03e00008 jr r31
 
  00199b90: 03e00008 jr r31
 
  00199b94: 00000000 nop
 
  00199b94: 00000000 nop
</font>
+
===Return locations===
 +
'''BATTLE.BIN'''
 +
  00196688: [[Map_movement_decision/data_setting]]
 +
  0019722c: [[Set_chosen_ability/target_for_AI_status]]
 +
  001981cc: [[Fight_for_Life_-_Auto_Battle_(00197ff4)]]
 +
  00198580: [[Protect_Allies_-_Auto_Battle_(001984ec)]]
 +
  001990a8: [[0019905c_-_00199120]]

Latest revision as of 08:19, 20 June 2024

BATTLE.BIN :  :  - AI_Target_Priority_Super_Routine_(001999c8)
Set Priority score for each reachable tiles and  store it at AI 0x5f4 as a negative value (0 - AI 0x32)
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : r2 = 0x00 Default value
         r2 = -0x01 if routine Abort while looping (Seems to be tied to VSync_call - Update screen and com back ?)
------------------------------------------------------------------------------------------
001999c8: 3c02801a lui r2,0x801a             |
001999cc: 90420d7b lbu r2,0x0d7b(r2)         |AI 0x19b7
001999d0: 27bdffc8 addiu r29,r29,-0x0038     |
001999d4: afb3002c sw r19,0x002c(r29)        |
001999d8: 3c13801a lui r19,0x801a            |
001999dc: 2673f3c4 addiu r19,r19,-0x0c3c     |0x8019f3c4 
001999e0: afbf0034 sw r31,0x0034(r29)        |
001999e4: afb40030 sw r20,0x0030(r29)        |
001999e8: afb20028 sw r18,0x0028(r29)        |
001999ec: afb10024 sw r17,0x0024(r29)        |

=== AI 0x19b7 <> 0x00 (resume where code returns -0x01 ?) ===
001999f0: 10400019 beq r2,r0,0x00199a58      #If 0x19b7 <> 0x00 
001999f4: afb00020 sw r16,0x0020(r29)            |
001999f8: 3c10801a lui r16,0x801a                |
001999fc: 9210f3dc lbu r16,-0x0c24(r16)          |Caster/ Focused X coordonates Could be the last coord. That caused the routine to returns -0x01
00199a00: 3c11801a lui r17,0x801a                |
00199a04: 9231f3de lbu r17,-0x0c22(r17)          |Caster/ Focused Y coordonates
00199a08: 3c02801a lui r2,0x801a                 |
00199a0c: 904201f1 lbu r2,0x01f1(r2)             |AI 0xe2d Offset for reachable Tile Table (0x0 All tiles, 0x1 Closer to target, 0x2 Away from target)
00199a10: 3c12801a lui r18,0x801a                |
00199a14: 9252f3dd lbu r18,-0x0c23(r18)          |Elevation
00199a18: 000218c0 sll r3,r2,0x03                |ID*8
00199a1c: 00621821 addu r3,r3,r2                 |ID*9
00199a20: 000318c0 sll r3,r3,0x03                |0x2ed Offset (0x48)
00199a24: 00731821 addu r3,r3,r19                |
00199a28: 24630a74 addiu r3,r3,0x0a74            |Prepare pointer to reachable tiles
00199a2c: 001210c0 sll r2,r18,0x03               |
00199a30: 00521021 addu r2,r2,r18                |
00199a34: 00021080 sll r2,r2,0x02                |Elevation offset (0x24)
00199a38: 00431021 addu r2,r2,r3                 |
00199a3c: 00111840 sll r3,r17,0x01               |Y row offset (Halfword)
00199a40: 00621821 addu r3,r3,r2                 |Pointer to AI Reachable Tiles (+offset based on 0xe2d)
00199a44: 94740000 lhu r20,0x0000(r3)            |ConsideredY row tiles flags
00199a48: 080666bc j 0x00199af0                  >>Jump/Return where routines stops *Set Priority via AI End of turn, in between turn, etc.
00199a4c: 00000000 nop                           |

                  ---Exit Section (reached by backward Jump)---
00199a50: 080666dd j 0x00199b74                  >>Jump to  END Return -0x01
00199a54: 2402ffff addiu r2,r0,-0x0001           |

=== SET PRIORITY for ALL CONSIDERED TILES ===
                                             Else 19b7 = 0x00
00199a58: 00009021 addu r18,r0,r0                |Elevation counter
00199a5c: 3c01801a lui r1,0x801a                 |
00199a60: a020f3d8 sb r0,-0x0c28(r1)             |Reset AI 0x14 ?? Used  AI_End_of_turn,_in_between_turn,_etc. (seems to depend on whether the caster has to move or not)
00199a64: 3c01801a lui r1,0x801a                 |
00199a68: a020f3e1 sb r0,-0x0c1f(r1)             |Set considered Skillset = 0x00  Tell the code This is a movement simulation only ?
                                                @LOOP - both elevation
00199a6c: 92620e3b lbu r2,0x0e3b(r19)                |Load Map Max Y
00199a70: 00000000 nop                               |
00199a74: 18400038 blez r2,0x00199b58                #If Max Y is invalid : branch to next Elevation iteration
00199a78: 00008821 addu r17,r0,r0                    |Y counter
                                                    @LOOP - All Y rows
00199a7c: 92620e2d lbu r2,0x0e2d(r19)                    |AI 0xe2d Offset for reachable Tile Table (0x0 All tiles, 0x1 Closer to target, 0x2 Away from target)
00199a80: 00000000 nop                                   |
00199a84: 000218c0 sll r3,r2,0x03                        |
00199a88: 00621821 addu r3,r3,r2                         |
00199a8c: 000318c0 sll r3,r3,0x03                        |0xe2d Offset (0x48)
00199a90: 00731821 addu r3,r3,r19                        |
00199a94: 24630a74 addiu r3,r3,0x0a74                    |AI 0xa74 Pointer (reachable tiles) + 0xe2d (0x48)
00199a98: 001210c0 sll r2,r18,0x03                       |
00199a9c: 00521021 addu r2,r2,r18                        |
00199aa0: 00021080 sll r2,r2,0x02                        |Elevation offset (0x24)
00199aa4: 00431021 addu r2,r2,r3                         |
00199aa8: 00111840 sll r3,r17,0x01                       |Y offset (halfword)
00199aac: 00621821 addu r3,r3,r2                         |This  iteration 0xa74 Pointer (Elevation and Y row) + 0xe2d offset(0x48)  Reachable +/- Get closer or further offset
00199ab0: 94740000 lhu r20,0x0000(r3)                    |This Y row tiles flags
00199ab4: 00000000 nop                                   |
00199ab8: 12800022 beq r20,r0,0x00199b44                 #If no flags in this row : branch to  Next Y row
00199abc: 00000000 nop                                   |
00199ac0: 92620e3a lbu r2,0x0e3a(r19)                    |Load Map Max X
00199ac4: 00000000 nop                                   |
00199ac8: 1840001e blez r2,0x00199b44                    #If Max X is invalid : branch to  Next Y row
00199acc: 00008021 addu r16,r0,r0                        |Reset X counter
00199ad0: 02141004 sllv r2,r20,r16                       |Shift Row flags : flag of interest is in 0x8000 position
                                                        @LOOP - All X Tiles in row
00199ad4: 30428000 andi r2,r2,0x8000                         |
00199ad8: 10400015 beq r2,r0,0x00199b30                      #If This tile is OFF : branch to  Next Tile
00199adc: 00000000 nop                                       |
00199ae0: a2700018 sb r16,0x0018(r19)                        |Save Current X
00199ae4: a271001a sb r17,0x001a(r19)                        |Save Current Y
00199ae8: 0c066ec8 jal 0x0019bb20                            |-->AI_Check_if_Unit_is_a_Crystal/Treasure_(0019bb20) Set Value of AI 0xcbf ( 801a0083 )
00199aec: a2720019 sb r18,0x0019(r19)                        |Save Current Map Level
                  19b7 <> 0x00 jump here
00199af0: 0c0674df jal 0x0019d37c                            |-->AI End of turn, in between turn, etc.  Set Priority score (AI 0x32) for each considered Tile
00199af4: 00000000 nop                                       |
00199af8: 2403ffff addiu r3,r0,-0x0001                       |
00199afc: 1043ffd4 beq r2,r3,0x00199a50                      #If Routine above returns -0x01 Exit Return -0x01
00199b00: 001210c0 sll r2,r18,0x03                           |
00199b04: 00521021 addu r2,r2,r18                            |
00199b08: 00021180 sll r2,r2,0x06                            |Elevation offset (0x240)
00199b0c: 00531021 addu r2,r2,r19                            |AI Pointer + Map Level offset
00199b10: 244205f4 addiu r2,r2,0x05f4                        |Prepare pointer to AI 0x5f4 Table (each tile priority score)
00199b14: 00111940 sll r3,r17,0x05                           |Y Row offset (0x20)
00199b18: 00621821 addu r3,r3,r2                             |
00199b1c: 00102040 sll r4,r16,0x01                           |X offset (1 halfword per tile)
00199b20: 96620032 lhu r2,0x0032(r19)                        |This Tile Priority Score Tile Priority (could change because of crystal / Treasure/Poison Marsh etc...)
00199b24: 00832021 addu r4,r4,r3                             |Pointer to 0x8019f3c4 + 0x5f4 + Tile offset
00199b28: 00021023 subu r2,r0,r2                             |-Priority
00199b2c: a4820000 sh r2,0x0000(r4)                          |Save Tile Priority 
00199b30: 92620e3a lbu r2,0x0e3a(r19)                        |Load Max X
00199b34: 26100001 addiu r16,r16,0x0001                      |Current X++
00199b38: 0202102a slt r2,r16,r2                             |
00199b3c: 1440ffe5 bne r2,r0,0x00199ad4                  Λ Loop until X = Max X
00199b40: 02141004 sllv r2,r20,r16                       |Row Coordinate * Current X
00199b44: 92620e3b lbu r2,0x0e3b(r19)                    |Load Max Y
00199b48: 26310001 addiu r17,r17,0x0001                  |Current Y++
00199b4c: 0222102a slt r2,r17,r2                         |Check if Y counter < max Y
00199b50: 1440ffca bne r2,r0,0x00199a7c              Λ Loop until Y = Max Y
00199b54: 00000000 nop                                   |
00199b58: 26520001 addiu r18,r18,0x0001              |Map Level++
00199b5c: 2a420002 slti r2,r18,0x0002                |
00199b60: 1440ffc2 bne r2,r0,0x00199a6c          Λ Loop for both low and high tiles
00199b64: 00000000 nop                           |
00199b68: 0c067c96 jal 0x0019f258            |-->Store units coordinates Retore acting Units coordinates
00199b6c: 26640e30 addiu r4,r19,0x0e30       |Pointer to 0x8019f3c4 + 0xe30
00199b70: 00001021 addu r2,r0,r0             |Return 0x00
00199b74: 8fbf0034 lw r31,0x0034(r29)
00199b78: 8fb40030 lw r20,0x0030(r29)
00199b7c: 8fb3002c lw r19,0x002c(r29)
00199b80: 8fb20028 lw r18,0x0028(r29)
00199b84: 8fb10024 lw r17,0x0024(r29)
00199b88: 8fb00020 lw r16,0x0020(r29)
00199b8c: 27bd0038 addiu r29,r29,0x0038
00199b90: 03e00008 jr r31
00199b94: 00000000 nop

Return locations

BATTLE.BIN
 00196688: Map_movement_decision/data_setting
 0019722c: Set_chosen_ability/target_for_AI_status
 001981cc: Fight_for_Life_-_Auto_Battle_(00197ff4)
 00198580: Protect_Allies_-_Auto_Battle_(001984ec)
 001990a8: 0019905c_-_00199120