Difference between revisions of "Map movement decision/data setting"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Updated Documentation)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<font face='Courier New'>
+
'''BATTLE.BIN''' :  - Map_movement_decision/data_setting
 +
Fill AI 0x3b4 Table - 1 Byte per Tile. If reachable (ON in AI 0xa74) Default data is distance to focused Target. Forced to 0x1 if there is a crystal (if needed)
 +
Set potential destination, store best destination tile coordonates in AI 0xcc4
 +
------------------------------------------------------------------------------------------
 +
Parameter : Nothing
 +
Return : r2 = 0x00 (Default)
 +
          r2 = -0x01 if routine Abort (Vsync call ?)
 +
------------------------------------------------------------------------------------------
 +
0019638c: 34020001 ori r2,r0,0x0001          |
 +
00196390: 3c01801a lui r1,0x801a            |
 +
00196394: a02201f1 sb r2,0x01f1(r1)          |{{f/store|<nowiki>Set AI 0xe2d = 0x01</nowiki>}} {{f/std|801a01f1 (aka 8019f3c4 + 0xe2d)}}
 +
00196398: 3c02801a lui r2,0x801a            |
 +
0019639c: 90420d7b lbu r2,0x0d7b(r2)        |{{f/load|AI 0x19b7}} {{f/std| 801a0d7b aka 8019f3c4 + 0x19b7}}
 +
001963a0: 27bdffe0 addiu r29,r29,-0x0020    |
 +
001963a4: afb10014 sw r17,0x0014(r29)        |
 +
001963a8: 3c11801a lui r17,0x801a            |
 +
001963ac: 8e3101f8 lw r17,0x01f8(r17)        |{{f/adr|Pointer to Acting Unit's AI Decision Data  (Caster AI 0x182c)}} {{f/std| 801a01f8 aka 8019f3c4 + 0xe34}}
 +
001963b0: afb00010 sw r16,0x0010(r29)        |
 +
001963b4: 3c10801a lui r16,0x801a            |
 +
001963b8: 2610f3c4 addiu r16,r16,-0x0c3c    |{{f/adr|0x8019f3c4}}
 +
001963bc: afbf001c sw r31,0x001c(r29)        |
 +
001963c0: 10400008 beq r2,r0,0x001963e4      {{f/Cond|If AI 0x19b7 <> 0x00 }}
 +
001963c4: afb20018 sw r18,0x0018(r29)            |
 +
001963c8: 3c02801a lui r2,0x801a                |
 +
001963cc: 90420035 lbu r2,0x0035(r2)            |{{f/load|AI 0xc71 (This routine control variable)}}
 +
001963d0: 00000000 nop                          |
 +
001963d4: 1040001a beq r2,r0,0x00196440          {{f/Cond|<nowiki>If Ai 0xc71 = 0x01</nowiki>}} {{f/loc| jump/return to AI 0x3b4 filling section}}
 +
001963d8: 00000000 nop                          |
 +
001963dc: 080659a0 j 0x00196680                  {{f/jump|Else, branch to :}} {{f/loc|AI Target Priority Super Routine (evaluate best destination)}}
 +
001963e0: 00000000 nop                          |
 
   
 
   
Non-Specific/True Default AI Movement Routine
+
{{f/sec|<nowiki>=== Set potential destination ===</nowiki>}}
 +
                                              '''<nowiki>Else : AI 0x19b7 = 0x00</nowiki>'''
 +
001963e4: 92220004 lbu r2,0x0004(r17)            |{{f/load|Acting Unit decision data 0x04}} {{f/std|Ai 0x182c + 0x04}}
 +
001963e8: 00000000 nop                          |
 +
001963ec: 30420040 andi r2,r2,0x0040            |
 +
001963f0: 10400013 beq r2,r0,0x00196440          {{f/Cond|If Acting Unit has no Unit to Focus : branch to }} {{f/loc| AI 0x3b4 setting}}
 +
001963f4: 00000000 nop                          |
 +
001963f8: 92230005 lbu r3,0x0005(r17)            |{{f/load|Focused Unit ID}}
 +
001963fc: 3c02801a lui r2,0x801a                |
 +
00196400: 904201f2 lbu r2,0x01f2(r2)            |{{f/load|Acting units ID}} {{f/std|801a01f2 aka 8019f3c4 + e2e}}
 +
00196404: 00000000 nop                          |
 +
00196408: 10620009 beq r3,r2,0x00196430          {{f/Cond|If Acting Unit is NOT self focusing }}
 +
0019640c: 260403b4 addiu r4,r16,0x03b4          |{{f/adr|8019f3c4 + 0x3b4}}
 +
00196410: 00031100 sll r2,r3,0x04                    |{{f/std|Focused Unit  offset (0x10)}}
 +
00196414: 00501021 addu r2,r2,r16                    |{{f/std|Part of pointer}}
 +
00196418: 90421833 lbu r2,0x1833(r2)                |{{f/load|load target type (Decision byte 0x07)}} {{f/std| 8019f3c4 + 0x182c + 0x07 + Focused Unit offset}}
 +
0019641c: 00000000 nop                              |
 +
00196420: 00021102 srl r2,r2,0x04                    |{{f/std|0x10 becomes 0x01}}
 +
00196424: 30420001 andi r2,r2,0x0001                |
 +
00196428: 10400005 beq r2,r0,0x00196440              {{f/Cond|If Focused unit is not Targetable : branch to }} {{f/loc| AI 0x3b4 setting}}
 +
0019642c: 00000000 nop                              |
 
   
 
   
0019638c: 34020001 ori r2,r0,0x0001
+
                  {{f/sec|--- Clear AI 0x3b4 section (distance to target is not needed) ---}}
00196390: 3c01801a lui r1,0x801a
+
                                                  '''Else : self targeting or untargetable target - Clear AI 0x3b4'''
00196394: a02201f1 sb r2,0x01f1(r1)
+
  00196430: 0c066ade jal 0x0019ab78                    |{{f/jal|Word_Nulling|Word_Nulling}} {{f/std|Nullify data from AI 0x3b4 to 0x5f4 (Distance from caster Table)}}
00196398: 3c02801a lui r2,0x801a
+
  00196434: 34050240 ori r5,r0,0x0240                  |
  0019639c: 90420d7b lbu r2,0x0d7b(r2) Action = Decided byte
+
  00196438: 0806594e j 0x00196538                      |{{f/loc|Keep AI 0x3b4 Empty and Avoid Crystal loop}}
  001963a0: 27bdffe0 addiu r29,r29,0xffe0
+
  0019643c: 00000000 nop                              |
  001963a4: afb10014 sw r17,0x0014(r29)
 
001963a8: 3c11801a lui r17,0x801a
 
001963ac: 8e3101f8 lw r17,0x01f8(r17) Acting Unit's AI Decision Pointer
 
001963b0: afb00010 sw r16,0x0010(r29)
 
  001963b4: 3c10801a lui r16,0x801a
 
  001963b8: 2610f3c4 addiu r16,r16,0xf3c4
 
001963bc: afbf001c sw r31,0x001c(r29)
 
001963c0: 10400008 beq r2,r0,0x001963e4 Branch if an Action has been decided on
 
001963c4: afb20018 sw r18,0x0018(r29)
 
 
   
 
   
 +
                  {{f/sec|--- Fill AI 0x3b4 Section (distance to Target for each tile) ---}}
 +
00196440: 0c06653e jal 0x001994f8                |{{f/jal|See_if_able_to_move_to_target%3F|See_if_able_to_move_to_target%3F}} {{f/std|Fill Table at 8019f3c4 + 0x3b4 (Each tile Distance to Target)}}
 +
00196444: 02202021 addu r4,r17,r0                |{{f/std|Send Acting Unit AI decision data pointer}}
 +
00196448: 2403ffff addiu r3,r0,-0x0001          |
 +
0019644c: 14430003 bne r2,r3,0x0019645c          {{f/Cond|if returned value is -0x01 (Vsync call issue ?)}}
 +
00196450: 2402ffff addiu r2,r0,-0x0001              |
 +
00196454: 08065a20 j 0x00196880                      |{{f/loc|Exit routine}} {{f/Returns|Returns -0x01}}
 +
00196458: a2000c71 sb r0,0x0c71(r16)                |{{f/store|<nowiki>AI 0xc71 = 0x00</nowiki>}}
 +
                                                  '''Else : r2 <> -0x01'''
 +
0019645c: 92220007 lbu r2,0x0007(r17)                |{{f/load|Acting Unit AI decision byte 0x07}}
 +
00196460: 00000000 nop                              |
 +
00196464: 30420003 andi r2,r2,0x0003                |
 +
00196468: 10400033 beq r2,r0,0x00196538              {{f/Cond|If Acting unit is not lacking of HP nor MP : }} {{f/loc|Avoid Crystal loop}}
 +
0019646c: 00000000 nop                              |
 +
00196470: 8e0217f8 lw r2,0x17f8(r16)                |{{f/adr|Acting Unit battle data pointer}} {{f/std|0x801908cc}}
 +
00196474: 00000000 nop                              |
 +
00196478: 9042005c lbu r2,0x005c(r2)                |{{f/load|Acting Unit current status 5}}
 +
0019647c: 00000000 nop                              |
 +
00196480: 30420001 andi r2,r2,0x0001                |
 +
00196484: 1440002c bne r2,r0,0x00196538              {{f/Cond|If Acting Unit has [Death Sentence] branch to }} {{f/loc|Avoid Crystal loop}}
 +
00196488: 00000000 nop                              |
 +
0019648c: 3c01801a lui r1,0x801a                    |
 +
00196490: ac20f370 sw r0,-0x0c90(r1)                |{{f/store|Initialize Unit Counter}} {{f/std|Reset 8019f370}}
 +
                                                    {{f/bloop|LOOP - Search for Crystal }}
 +
00196494: 3c04801a lui r4,0x801a                        |
 +
00196498: 8c84f370 lw r4,-0x0c90(r4)                    |{{f/load|Load Dynamic Unit ID}}
 +
0019649c: 3c038019 lui r3,0x8019                        |
 +
001964a0: 246308cc addiu r3,r3,0x08cc                    |
 +
001964a4: 000410c0 sll r2,r4,0x03                        |
 +
001964a8: 00441023 subu r2,r2,r4                        |
 +
001964ac: 00021180 sll r2,r2,0x06                        |{{f/std|ID*0x1c0}}
 +
001964b0: 00432821 addu r5,r2,r3                        |{{f/adr|Dynamic Pointer to Unit battle data}}
 +
001964b4: 90a30001 lbu r3,0x0001(r5)                    |{{f/load|load unit ID}}
 +
001964b8: 340200ff ori r2,r0,0x00ff                      |
 +
001964bc: 10620015 beq r3,r2,0x00196514                  {{f/Cond|<nowiki>If This Unit ID = 0xff : branch to </nowiki>}} {{f/loc|Next unit}}
 +
001964c0: 00000000 nop                                  |
 +
001964c4: 90a20058 lbu r2,0x0058(r5)                    |{{f/load|This Unit Current Status 1}}
 +
001964c8: 00000000 nop                                  |
 +
001964cc: 30420040 andi r2,r2,0x0040                    |
 +
001964d0: 10400010 beq r2,r0,0x00196514                  {{f/Cond|If This Unit is a [Crystal] - Update AI 0x3b4}}
 +
001964d4: 00000000 nop                                      |
 +
001964d8: 0c067ca9 jal 0x0019f2a4                            |{{f/jal|Transfer_Unit_Coordinates_to_AI|Transfer_Unit_Coordinates_to_AI}} {{f/std|Transfer This Unit coordinate at 8019f3c4 + 0xc74}}
 +
001964dc: 26050c74 addiu r5,r16,0x0c74                      |{{f/std|Send Pointer to AI 0xc74}}
 +
001964e0: 92030c75 lbu r3,0x0c75(r16)                        |{{f/load|This Unit elevation}}
 +
001964e4: 92040c74 lbu r4,0x0c74(r16)                        |{{f/load|This Unit X coordinate}}
 +
001964e8: 000310c0 sll r2,r3,0x03                            |
 +
001964ec: 00431021 addu r2,r2,r3                            |
 +
001964f0: 00021140 sll r2,r2,0x05                            |{{f/std|Elevation offset (0x120)}}
 +
001964f4: 00501021 addu r2,r2,r16                            |{{f/std|AI pointer + elevation offset}}
 +
001964f8: 92030c76 lbu r3,0x0c76(r16)                        |{{f/load|Load Y coordinate}}
 +
001964fc: 244203b4 addiu r2,r2,0x03b4                        |{{f/std|Part of pointer to 8019f3c4 + 0x3b4}}
 +
00196500: 00031900 sll r3,r3,0x04                            |{{f/std|Y offset (0x10)}}
 +
00196504: 00621821 addu r3,r3,r2                            |{{f/std|Part of pointer to 8019f3c4 + 0x3b4}}
 +
00196508: 00641821 addu r3,r3,r4                            |{{f/adr|Pointer to this Unit 8019f3c4 + 0x3b4 Tile's data}}
 +
0019650c: 34020001 ori r2,r0,0x0001                          |
 +
00196510: a0620000 sb r2,0x0000(r3)                          |{{f/store|Store 0x01 in panel data (AI 0x3b4)}} {{f/std|instead of distance between unit ? Forces the crystal to feel closer ?}}
 +
00196514: 3c02801a lui r2,0x801a                        |
 +
00196518: 8c42f370 lw r2,-0x0c90(r2)                    |{{f/load|Load Unit Counter}}
 +
0019651c: 00000000 nop                                  |
 +
00196520: 24420001 addiu r2,r2,0x0001                    |
 +
00196524: 3c01801a lui r1,0x801a                        |
 +
00196528: ac22f370 sw r2,-0x0c90(r1)                    |{{f/store|Store increased Unit Counter}}
 +
0019652c: 28420015 slti r2,r2,0x0015                    |
 +
00196530: 1440ffd8 bne r2,r0,0x00196494              {{f/eloop|Do for each unit}}
 +
00196534: 00000000 nop                              |
 
   
 
   
  001963c8: 3c02801a lui r2,0x801a
+
                  {{f/sec|--- POST CRYSTAL ---}}
  001963cc: 90420035 lbu r2,0x0035(r2)
+
00196538: 92020e31 lbu r2,0x0e31(r16)        |{{f/load|Acting Unit elevation}}
  001963d0: 00000000 nop
+
0019653c: 92040e30 lbu r4,0x0e30(r16)        |{{f/load|Acting Unit X coordinates}}
  001963d4: 1040001a beq r2,r0,0x00196440 Skip targeting if False
+
00196540: 000218c0 sll r3,r2,0x03            |
  001963d8: 00000000 nop
+
00196544: 00621821 addu r3,r3,r2            |
  001963dc: 080659a0 j 0x00196680 Skip to Panel Priority
+
00196548: 00031940 sll r3,r3,0x05            |
  001963e0: 00000000 nop
+
  0019654c: 00701821 addu r3,r3,r16            |{{f/std|8019f3c4 + Elevation offset (+0x120 if high elevation)}}
 +
00196550: 92020e32 lbu r2,0x0e32(r16)        |{{f/load|Acting Unit Y coordinates}}
 +
00196554: 246303b4 addiu r3,r3,0x03b4        |{{f/std|Elevation offset + 0x3b4}}
 +
00196558: 00021100 sll r2,r2,0x04            |{{f/std|Y*16 (Y offset)}}
 +
0019655c: 00431021 addu r2,r2,r3            |{{f/std|0x3b4 + Y offset + Elevation offset}}
 +
00196560: 00441021 addu r2,r2,r4            |{{f/adr|8019f3c4 + 0x3b4 + Caster Tile offset}}
 +
  00196564: 90420000 lbu r2,0x0000(r2)         |{{f/load|Acting Unit Distance from Target}}
 +
00196568: 3c01801a lui r1,0x801a            |
 +
0019656c: ac22f374 sw r2,-0x0c8c(r1)        |{{f/store|Store distance from Target at 0x8019f374}}
 +
00196570: 0c0658a8 jal 0x001962a0            |{{f/jal|Get_Longest_Range_Ability_or_Move|Get_Longest_Range_Ability_or_Move}} {{f/std|Returns Closest Ability range if focusing, Acting unit move if not}}
 +
  00196574: 00000000 nop                       |
 +
00196578: 3c04801a lui r4,0x801a            |
 +
0019657c: 8c84f374 lw r4,-0x0c8c(r4)        |{{f/load|Caster Distance from Target}}
 +
00196580: 3c01801a lui r1,0x801a            |
 +
00196584: ac22f36c sw r2,-0x0c94(r1)        |{{f/store|Store Closest Ability Range (or Unit move) at 0x8019f36c}}
 +
00196588: 3c01801a lui r1,0x801a            |
 +
  0019658c: ac20f378 sw r0,-0x0c88(r1)        |{{f/store|Reset 0x8019f378}}
 +
00196590: 0044102a slt r2,r2,r4              |{{f/std|0x1 if  Closest range + Move < Distance From Target}}
 +
00196594: 10400006 beq r2,r0,0x001965b0      {{f/Cond|If Closest Ability > Distance From Target : branch to }} {{f/loc|Hit and run (?) section }}
 +
00196598: 34120001 ori r18,r0,0x0001        |
 +
0019659c: 92220006 lbu r2,0x0006(r17)        |{{f/load|Acting Unit decision Byte 0x06}}
 +
  001965a0: 00000000 nop                       |
 +
  001965a4: 30420008 andi r2,r2,0x0008        |{{f/std|Check Ability CT flag}}
 +
001965a8: 10400030 beq r2,r0,0x0019666c      {{f/Cond|If caster is not charging: branch to }} {{f/loc| Move then Hit section}}
 +
  001965ac: 00000000 nop                       |
 
   
 
   
001963e4: 92220004 lbu r2,0x0004(r17) Load Targeting Flag 1
+
                  {{f/sec|--- SECTION : TARGET is IN RANGE - Hit and run ? / Run while charging ---  }}
  001963e8: 00000000 nop
+
                                              '''Else : Target is in range / Or Unit is Charging (Target already acquired?)'''
001963ec: 30420040 andi r2,r2,0x0040
+
  001965b0: 3c01801a lui r1,0x801a                 |
001963f0: 10400013 beq r2,r0,0x00196440 branch if not focus on target
+
  001965b4: ac32f368 sw r18,-0x0c98(r1)           |{{f/store|<nowiki>Target is in range = True // Hit and Run flag ?</nowiki>}} {{f/std|Target could be a tile or a unit}}
001963f4: 00000000 nop
+
  001965b8: 92220004 lbu r2,0x0004(r17)           |{{f/load|Load Acting Unit AI 0x182c byte 0x04}}
001963f8: 92230005 lbu r3,0x0005(r17) load main target ID
+
  001965bc: 00000000 nop                           |
  001963fc: 3c02801a lui r2,0x801a
+
  001965c0: 30420020 andi r2,r2,0x0020            |
  00196400: 904201f2 lbu r2,0x01f2(r2) load acting units ID
+
  001965c4: 10400024 beq r2,r0,0x00196658          {{f/Cond|If Acting Unit do not have [Stay Near] flag :}} {{f/loc|Avoid Stay near section}}
  00196404: 00000000 nop
+
  001965c8: 00000000 nop                           |
00196408: 10620009 beq r3,r2,0x00196430 branch if self
 
0019640c: 260403b4 addiu r4,r16,0x03b4
 
00196410: 00031100 sll r2,r3,0x04
 
00196414: 00501021 addu r2,r2,r16
 
00196418: 90421833 lbu r2,0x1833(r2) load target type
 
  0019641c: 00000000 nop
 
  00196420: 00021102 srl r2,r2,0x04
 
00196424: 30420001 andi r2,r2,0x0001
 
  00196428: 10400005 beq r2,r0,0x00196440 branch if able to be targeted
 
0019642c: 00000000 nop
 
00196430: 0c066ade jal 0x0019ab78 word nulling
 
00196434: 34050240 ori r5,r0,0x0240
 
00196438: 0806594e j 0x00196538 Jump to Longest Ability/Move
 
  0019643c: 00000000 nop
 
 
   
 
   
  00196440: 0c06653e jal 0x001994f8 see if able to move to target
+
                                            {{f/sec|--- STAY NEAR - CAN REACH TILE of INTEREST ? ---}}
  00196444: 02202021 addu r4,r17,r0
+
  001965cc: 0c0674a5 jal 0x0019d294                    |{{f/jal|Get_unit_that_matches_coordinates|Get_unit_that_matches_coordinates}} {{f/std| returns ID of Unit of Tile to protect ? (0x15 if none)}}
  00196448: 2403ffff addiu r3,r0,0xffff
+
  001965d0: 02202021 addu r4,r17,r0                   |{{f/std|Send AI decision data pointer}}
  0019644c: 14430003 bne r2,r3,0x0019645c
+
  001965d4: 92030e2e lbu r3,0x0e2e(r16)                |{{f/load|Load acting unit ID}}
  00196450: 2402ffff addiu r2,r0,0xffff
+
001965d8: 00402021 addu r4,r2,r0                     |
  00196454: 08065a20 j 0x00196880 Frame Timer Exit
+
001965dc: 3c01801a lui r1,0x801a                    |
  00196458: a2000c71 sb r0,0x0c71(r16) 0x1a0035 = False
+
  001965e0: ac24f370 sw r4,-0x0c90(r1)                |{{f/store|Store unit ID }}
 +
001965e4: 10830003 beq r4,r3,0x001965f4              {{f/Cond|If Acting Unit is on [stay near]Coordinates}} {{f/loc|Focused Tile is reachable section}}
 +
  001965e8: 34020015 ori r2,r0,0x0015                  |
 +
  001965ec: 1482001a bne r4,r2,0x00196658              {{f/Cond|If There is a Unit on This Tile : branch to}} {{f/loc|Focused Tile is not reachable section}}
 +
  001965f0: 00000000 nop                              |
 
   
 
   
  0019645c: 92220007 lbu r2,0x0007(r17) load type of target flags
+
                                                {{f/sec|--- Focused Tile is reachable (already on tile /Tile in range and empty) ---}}
  00196460: 00000000 nop
+
001965f4: 92230001 lbu r3,0x0001(r17)                |{{f/load|Focused Tile Elevation}} {{f/std|8019f3c4 + 0x182c + 0x01}}
  00196464: 30420003 andi r2,r2,0x0003
+
  001965f8: 92240000 lbu r4,0x0000(r17)                |{{f/load|Focused Tile X coordinates}}
  00196468: 10400033 beq r2,r0,0x00196538 branch if not low hp/mp unit
+
001965fc: 000310c0 sll r2,r3,0x03                    |
  0019646c: 00000000 nop
+
00196600: 00431021 addu r2,r2,r3                    |
  00196470: 8e0217f8 lw r2,0x17f8(r16) load acting units data
+
00196604: 00021080 sll r2,r2,0x02                    |{{f/std|Elevation offset (0x24)}}
  00196474: 00000000 nop
+
00196608: 92230002 lbu r3,0x0002(r17)               |{{f/load|Focused Tile Y coordinates}}
  00196478: 9042005c lbu r2,0x005c(r2) load status
+
0019660c: 00501021 addu r2,r2,r16                    |
  0019647c: 00000000 nop
+
  00196610: 00031840 sll r3,r3,0x01                    |{{f/std|Y offset (Halfword)}}
  00196480: 30420001 andi r2,r2,0x0001
+
  00196614: 00431021 addu r2,r2,r3                    |{{f/std|Pointer to 0x8019f3c4 + 0xa74 + Acting Unit Y Row offset}}
  00196484: 1440002c bne r2,r0,0x00196538 branch if death sentence
+
00196618: 34038000 ori r3,r0,0x8000                  |{{f/std|Base bitmask}}
  00196488: 00000000 nop
+
  0019661c: 94420a74 lhu r2,0x0a74(r2)                |{{f/load|Load Acting Unit Row's flags}}
  0019648c: 3c01801a lui r1,0x801a
+
00196620: 00831807 srav r3,r3,r4                    |{{f/std|Acting Unit's Tile's bitmask}}
  00196490: ac20f370 sw r0,-0x0c90(r1) Initialize Unit Counter
+
  00196624: 00431024 and r2,r2,r3                      |{{f/std|Acting Unit's Tile's Flag in AI 0xa74 Table}}
 +
  00196628: 1040000b beq r2,r0,0x00196658              {{f/Cond|If Acting Unit Tile is Unreachable (Flag OFF)}} {{f/loc|Branch to get closer section}}
 +
  0019662c: 00000000 nop                               |
 +
  00196630: 92020e2d lbu r2,0x0e2d(r16)               |{{f/load|Load 0x8019f3c4 + 0xe2d}} {{f/std|This routine control variable ? }}
 +
  00196634: 8e230000 lw r3,0x0000(r17)                |{{f/load|Load  Focused Tile Full coordinates}}
 +
  00196638: 00021080 sll r2,r2,0x02                    |{{f/std|0x0e2d * 4}}
 +
  0019663c: 00501021 addu r2,r2,r16                    |{{f/std|0x8019f3c4 + Offset based on 0xe2d}}
 +
  00196640: 0c0664e8 jal 0x001993a0                    |{{f/jal|001993a0_-_00199494|Update Reachable Tile's Flags}} {{f/std|Turn off any reachable Tile but the acting unit ones and the focused Tile one}}
 +
00196644: ac430cc4 sw r3,0x0cc4(r2)                  |{{f/store|Store Full Coordinates at 0x8019f3c4 + 0xcc4 (based on 0xe2d)}} {{f/std|AI 0xcc8}}
 +
  00196648: 3c01801a lui r1,0x801a                     |
 +
  0019664c: ac32f378 sw r18,-0x0c88(r1)               |{{f/store|Set 0x8019f378 to 0x01}}
 +
00196650: 080659a0 j 0x00196680                      {{f/jump|Jump to Movement Priority Routine}}
 +
00196654: 00000000 nop                              |
 
   
 
   
Search for Crystals
+
                                                {{f/sec|--- Get closer of Target (Unit or occupied tile)}}
  00196494: 3c04801a lui r4,0x801a
+
  00196658: 92020e38 lbu r2,0x0e38(r16)               |{{f/load|Acting Unit's Move}}
00196498: 8c84f370 lw r4,-0x0c90(r4) Load Unit Counter
+
  0019665c: 3c04801a lui r4,0x801a                    |
  0019649c: 3c038019 lui r3,0x8019
+
  00196660: 8c84f374 lw r4,-0x0c8c(r4)                 |{{f/load|Acting Unit's distance from Target}}
001964a0: 246308cc addiu r3,r3,0x08cc
+
  00196664: 0806599e j 0x00196678                      {{f/jump|Jump directly to }} {{f/loc|Next routine (Fill AI 0xabc)}} {{f/std|Will Enable all tiles closest to Focused Tile in AI 0x74}}
001964a4: 000410c0 sll r2,r4,0x03
+
  00196668: 00442021 addu r4,r2,r4                    |{{f/std|Move + Distance}}
  001964a8: 00441023 subu r2,r2,r4
 
001964ac: 00021180 sll r2,r2,0x06
 
001964b0: 00432821 addu r5,r2,r3
 
001964b4: 90a30001 lbu r3,0x0001(r5) load unit ID
 
001964b8: 340200ff ori r2,r0,0x00ff
 
001964bc: 10620015 beq r3,r2,0x00196514 branch if Unit doesn't exist
 
  001964c0: 00000000 nop
 
001964c4: 90a20058 lbu r2,0x0058(r5)
 
001964c8: 00000000 nop
 
001964cc: 30420040 andi r2,r2,0x0040
 
001964d0: 10400010 beq r2,r0,0x00196514 branch if not crystal
 
001964d4: 00000000 nop
 
001964d8: 0c067ca9 jal 0x0019f2a4 transfer unit coordinates to AI
 
  001964dc: 26050c74 addiu r5,r16,0x0c74
 
001964e0: 92030c75 lbu r3,0x0c75(r16)                Load map level
 
001964e4: 92040c74 lbu r4,0x0c74(r16)                Load X coordinate
 
001964e8: 000310c0 sll r2,r3,0x03                    *8
 
001964ec: 00431021 addu r2,r2,r3                    *9
 
001964f0: 00021140 sll r2,r2,0x05                    *120
 
001964f4: 00501021 addu r2,r2,r16                   
 
001964f8: 92030c76 lbu r3,0x0c76(r16)                Load Y coordinate
 
001964fc: 244203b4 addiu r2,r2,0x03b4
 
00196500: 00031900 sll r3,r3,0x04                    Y coordinate*16
 
00196504: 00621821 addu r3,r3,r2                   
 
00196508: 00641821 addu r3,r3,r4                    +X coordinate
 
0019650c: 34020001 ori r2,r0,0x0001
 
00196510: a0620000 sb r2,0x0000(r3)                  Store 0x01 in panel data
 
00196514: 3c02801a lui r2,0x801a
 
00196518: 8c42f370 lw r2,-0x0c90(r2) Load Unit Counter
 
0019651c: 00000000 nop
 
00196520: 24420001 addiu r2,r2,0x0001
 
00196524: 3c01801a lui r1,0x801a
 
00196528: ac22f370 sw r2,-0x0c90(r1) Unit Counter++
 
0019652c: 28420015 slti r2,r2,0x0015
 
00196530: 1440ffd8 bne r2,r0,0x00196494        Do for each unit
 
00196534: 00000000 nop
 
 
   
 
   
  00196538: 92020e31 lbu r2,0x0e31(r16)           load map level
+
                  {{f/sec|--- GET CLOSER THEN HIT Section (Target is not reachable with all abilities)---}}
0019653c: 92040e30 lbu r4,0x0e30(r16)          load x coordinate
+
  0019666c: 3c01801a lui r1,0x801a             |
  00196540: 000218c0 sll r3,r2,0x03
+
  00196670: ac20f368 sw r0,-0x0c98(r1)         |{{f/store|Reset 0x8019f3c8}} {{f/std|Target in range flag ? }}
00196544: 00621821 addu r3,r3,r2
+
  00196674: 2484ffff addiu r4,r4,-0x0001      |{{f/std|Send  Distance from Target - 1 (From  001965a8)}}
00196548: 00031940 sll r3,r3,0x05
+
  00196678: 0c065ab7 jal 0x00196adc            |{{f/jal|Check_AI_Target_Type_(00196adc)|Check_AI_Target_Type_(00196adc)}} {{f/std|Set data to 0xabc Table (reachable and closer to Target)}}
0019654c: 00701821 addu r3,r3,r16
+
  0019667c: 00000000 nop                       |
00196550: 92020e32 lbu r2,0x0e32(r16)          load Y coordinate
 
00196554: 246303b4 addiu r3,r3,0x03b4
 
00196558: 00021100 sll r2,r2,0x04
 
0019655c: 00431021 addu r2,r2,r3
 
00196560: 00441021 addu r2,r2,r4
 
00196564: 90420000 lbu r2,0x0000(r2)            load panel value
 
00196568: 3c01801a lui r1,0x801a
 
  0019656c: ac22f374 sw r2,-0x0c8c(r1)           store panel value
 
  00196570: 0c0658a8 jal 0x001962a0 Get Longest Range Ability or Move
 
00196574: 00000000 nop
 
00196578: 3c04801a lui r4,0x801a
 
0019657c: 8c84f374 lw r4,-0x0c8c(r4)           load panel value
 
  00196580: 3c01801a lui r1,0x801a
 
00196584: ac22f36c sw r2,-0x0c94(r1)           19f36c
 
00196588: 3c01801a lui r1,0x801a
 
0019658c: ac20f378 sw r0,-0x0c88(r1)          
 
00196590: 0044102a slt r2,r2,r4
 
00196594: 10400006 beq r2,r0,0x001965b0        branch if New Panel Value > Old Value
 
00196598: 34120001 ori r18,r0,0x0001
 
0019659c: 92220006 lbu r2,0x0006(r17)
 
  001965a0: 00000000 nop
 
001965a4: 30420008 andi r2,r2,0x0008
 
001965a8: 10400030 beq r2,r0,0x0019666c        branch if not charging ability
 
001965ac: 00000000 nop
 
001965b0: 3c01801a lui r1,0x801a
 
001965b4: ac32f368 sw r18,-0x0c98(r1) Target is in range = True
 
 
   
 
   
  001965b8: 92220004 lbu r2,0x0004(r17)
+
  {{f/sec|<nowiki>=== CHOOSE THE BEST DESTINATION  CLOSER TO TARGET    store it in AI 0xcc8        (movement only without ability simulation) ===</nowiki>}}
  001965bc: 00000000 nop
+
00196680: 0c066672 jal 0x001999c8            |{{f/jal|AI_Target_Priority_Super_Routine_(001999c8)|AI_Target_Priority_Super_Routine_(001999c8)}} {{f/std|Set Priority Mod for each Tiles in Table at AI 0x5f4 }}
  001965c0: 30420020 andi r2,r2,0x0020
+
00196684: 00000000 nop                      |
  001965c4: 10400024 beq r2,r0,0x00196658        branch if stay near X/Y location AI
+
00196688: 2403ffff addiu r3,r0,-0x0001      |
  001965c8: 00000000 nop
+
0019668c: 14430004 bne r2,r3,0x001966a0      {{f/Cond|If Routine returns -0x0001 (Table 0x5f4 not Updated) }} {{f/std|- Vsync related}}
  001965cc: 0c0674a5 jal 0x0019d294 Get unit that matches coordinates
+
00196690: 34020001 ori r2,r0,0x0001              |
  001965d0: 02202021 addu r4,r17,r0
+
00196694: a2020c71 sb r2,0x0c71(r16)            |{{f/store|Set AI 0xc71 to 0x01}}
  001965d4: 92030e2e lbu r3,0x0e2e(r16)           load acting unit id
+
00196698: 08065a20 j 0x00196880                  |{{f/loc|Exit}} {{f/Returns|Returns -0x0001}}
  001965d8: 00402021 addu r4,r2,r0
+
0019669c: 2402ffff addiu r2,r0,-0x0001          |
  001965dc: 3c01801a lui r1,0x801a
+
                                              '''Else : Table AI 0x5f4 has been Updated'''
  001965e0: ac24f370 sw r4,-0x0c90(r1)           store unit ID
+
001966a0: 3c02801a lui r2,0x801a                |
  001965e4: 10830003 beq r4,r3,0x001965f4        branch if calculated ID is acting unit
+
001966a4: 8c42f378 lw r2,-0x0c88(r2)             |{{f/load|Load 0x8019f378}} {{f/std| 0x1 if Caster has [Stay Near] and Can move on This tile}}
  001965e8: 34020015 ori r2,r0,0x0015
+
001966a8: 00000000 nop                          |
  001965ec: 1482001a bne r4,r2,0x00196658        branch if not end of unit counter?
+
001966ac: 14400029 bne r2,r0,0x00196754          {{f/Cond|If Destination is already chosen }} {{f/loc|Avoid looking for best tile }}
  001965f0: 00000000 nop
+
  001966b0: 00000000 nop                           |
 +
  001966b4: 3c02801a lui r2,0x801a                |
 +
001966b8: 8c42f368 lw r2,-0x0c98(r2)            |{{f/load|Load 8019f368 - Target in Range Flag ? }} {{f/std|0x1 if Targeted Unit distance < Closest Ability (Hit and Run is an option ?)}}
 +
  001966bc: 00000000 nop                          |
 +
001966c0: 10400006 beq r2,r0,0x001966dc          {{f/Cond|If Target is Targetable without moving}}
 +
001966c4: 3c047fff lui r4,0x7fff                    |
 +
  001966c8: 3484ffff ori r4,r4,0xffff                  |{{f/std|Send Max possible distance}}
 +
  001966cc: 0c065a4f jal 0x0019693c                    |{{f/jal|AI_Post_Action_Movement_Decision_Routine_(0019693c)|AI_Post_Action_Movement_Decision_Routine_(0019693c)}} {{f/std|Find best Tile and store coordinates at AI 0xcc8}}
 +
  001966d0: 00002821 addu r5,r0,r0                     |{{f/std|Priority prevails mod}}
 +
  001966d4: 080659d5 j 0x00196754                      |{{f/loc|Keep result and Avoid opposite section}}
 +
001966d8: 00000000 nop                              |
 +
                                                  '''Else : Not Targetable with all abilities'''
 +
001966dc: 92020e39 lbu r2,0x0e39(r16)               |{{f/load|load acting units team}}
 +
001966e0: 00000000 nop                              |
 +
001966e4: 10400017 beq r2,r0,0x00196744              {{f/Cond|if Acting Unit is in Player Team :}} {{f/loc|Avoid random stuff  (!?)}}
 +
  001966e8: 00000000 nop                              |
 +
001966ec: 0c0088c3 jal 0x0002230c                    |{{f/jal|Random_Number_Generator|Random_Number_Generator}} {{f/std|returns 0 to 0x7fff}}
 +
001966f0: 00000000 nop                              |
 +
001966f4: 3c039249 lui r3,0x9249                    |
 +
001966f8: 34632493 ori r3,r3,0x2493                  |{{f/std|0x92492493}} {{f/std| 4/7  2^32}}
 +
001966fc: 00430018 mult r2,r3                        |
 +
00196700: 000227c3 sra r4,r2,0x1f                    |{{f/std|0}}
 +
00196704: 00001810 mfhi r3                          |{{f/std|<nowiki>r3 = Rdm *-3/7 * 2^32</nowiki>}}
 +
00196708: 00621821 addu r3,r3,r2                    |{{f/std|Rdm * 4/7}}
 +
0019670c: 00031883 sra r3,r3,0x02                    |{{f/std|Rdm / 7}}
 +
00196710: 00641823 subu r3,r3,r4                    |{{f/std|- 0x00}}
 +
00196714: 000320c0 sll r4,r3,0x03                    |{{f/std|Rdm * 8 / 7}}
 +
00196718: 00832023 subu r4,r4,r3                    |{{f/std|Rdm * 7 / 7 (but you lost the 1st byte during the right shift)}}
 +
0019671c: 14440009 bne r2,r4,0x00196744              {{f/Cond|If Random Number if a multiple of 7 and 16 (?)}}
 +
00196720: 00000000 nop                                  |
 +
  00196724: 3c02801a lui r2,0x801a                         |
 +
  00196728: 8c42f36c lw r2,-0x0c94(r2)                     |{{f/load|Shortest Range}}
 +
0019672c: 00000000 nop                                  |
 +
00196730: 00021fc2 srl r3,r2,0x1f                        |
 +
  00196734: 00431021 addu r2,r2,r3                         |{{f/std|Range}}
 +
  00196738: 00021043 sra r2,r2,0x01                        |{{f/std|Range / 2}}
 +
  0019673c: 3c01801a lui r1,0x801a                        |
 +
00196740: ac22f36c sw r2,-0x0c94(r1)                    |{{f/store|Randomly Halve Ability range ? }}
 +
00196744: 3c04801a lui r4,0x801a                    |
 +
00196748: 8c84f36c lw r4,-0x0c94(r4)                |{{f/load|Shortest Range}}
 +
0019674c: 0c065a42 jal 0x00196908                    |{{f/jal|Get_Positive_Priority_(00196908)|Get_Positive_Priority_(00196908)}} {{f/std|Find best Tile and store coordinates at AI 0xcc8}}
 +
  00196750: 00000000 nop                               |
 
   
 
   
  001965f4: 92230001 lbu r3,0x0001(r17)           load map level flag
+
  {{f/sec|<nowiki>=== Set potential destination away from target (all cases)===</nowiki>}}
  001965f8: 92240000 lbu r4,0x0000(r17)           load X coordinate
+
  00196754: 92030e3b lbu r3,0x0e3b(r16)           |{{f/load|Map Max Y}}
  001965fc: 000310c0 sll r2,r3,0x03
+
  00196758: 34020002 ori r2,r0,0x0002              |
  00196600: 00431021 addu r2,r2,r3
+
  0019675c: a2020e2d sb r2,0x0e2d(r16)            |{{f/store|Set 0xe2d to 0x02 (Away from Target offset)}}
  00196604: 00021080 sll r2,r2,0x02
+
00196760: 3c01801a lui r1,0x801a                |
  00196608: 92230002 lbu r3,0x0002(r17)           load Y coordinate
+
  00196764: ac20f370 sw r0,-0x0c90(r1)            |{{f/store|Reset 0x8019f370}}
  0019660c: 00501021 addu r2,r2,r16
+
  00196768: 10600015 beq r3,r0,0x001967c0          {{f/Cond|If Map max Y is invalid}} {{f/loc|Avoid loop}}
  00196610: 00031840 sll r3,r3,0x01
+
0019676c: 00000000 nop                          |
  00196614: 00431021 addu r2,r2,r3
+
                                                {{f/bloop|LOOP - Set Table of reachable tiles farther from Target (AI 0xb04)}}
  00196618: 34038000 ori r3,r0,0x8000
+
  00196770: 3c05801a lui r5,0x801a                    |
  0019661c: 94420a74 lhu r2,0x0a74(r2)
+
00196774: 8ca5f370 lw r5,-0x0c90(r5)                |{{f/load|This Loop counter}}
  00196620: 00831807 srav r3,r3,r4
+
00196778: 00000000 nop                              |
  00196624: 00431024 and r2,r2,r3
+
  0019677c: 00051040 sll r2,r5,0x01                   |{{f/std|Y counter * 2 (halford offset)}}
  00196628: 1040000b beq r2,r0,0x00196658 Branch if acting unit is not in range?
+
  00196780: 00501021 addu r2,r2,r16                    |{{f/adr|Dynamic pointer to AI data (halfword offset)}}
0019662c: 00000000 nop
+
  00196784: 94430a74 lhu r3,0x0a74(r2)                |{{f/load|This Y row Flags in Reachable Tiles Table}} {{f/std|8019f3c4 + 0xa74}}
  00196630: 92020e2d lbu r2,0x0e2d(r16)
+
  00196788: 94460abc lhu r6,0x0abc(r2)                 |{{f/load|This Y row Flags in Reachable and closer to Target Tiles Table}} {{f/std|8019f3c4 + 0xa74 + 0x48 }}
  00196634: 8e230000 lw r3,0x0000(r17)
+
  0019678c: 94440a98 lhu r4,0x0a98(r2)                |{{f/load|Same Y row but high elevation (AI 0xa74)}}
  00196638: 00021080 sll r2,r2,0x02
+
  00196790: 94470ae0 lhu r7,0x0ae0(r2)                |{{f/load|Same Y row but high elevation (AI 0xa74 + 0x48)}}
  0019663c: 00501021 addu r2,r2,r16
+
  00196794: 00661826 xor r3,r3,r6                      |{{f/std|Toggle Low elevation flags : reachable and farther from target}}
  00196640: 0c0664e8 jal 0x001993a0 Save new coordinates
+
  00196798: 00872026 xor r4,r4,r7                      |{{f/std|Toggle High elevation flags : reachable and farther from target}}
00196644: ac430cc4 sw r3,0x0cc4(r2)
+
  0019679c: a4430b04 sh r3,0x0b04(r2)                 |{{f/store|Store Reachable and Farther flags at 0x8019f3c4 + 0xa74 + 0x90}} {{f/std|<nowiki>2 times 0x48 offset (and 0xe2d is = 2)</nowiki>}}
  00196648: 3c01801a lui r1,0x801a
+
  001967a0: a4440b28 sh r4,0x0b28(r2)                  |{{f/store|Store High elevation Reachable and Farther flags }} {{f/std|<nowiki>2 times 0x48 offset (and 0xe2d is = 2)</nowiki>}}
  0019664c: ac32f378 sw r18,-0x0c88(r1)
+
  001967a4: 92020e3b lbu r2,0x0e3b(r16)                |{{f/load|Map Max Y}}
  00196650: 080659a0 j 0x00196680 Jump to Movement Priority Routine
+
  001967a8: 24a50001 addiu r5,r5,0x0001                |{{f/std|Y counter +1}}
  00196654: 00000000 nop
+
  001967ac: 3c01801a lui r1,0x801a                     |
 +
  001967b0: ac25f370 sw r5,-0x0c90(r1)                 |{{f/store|Store counter}}
 +
  001967b4: 00a2282a slt r5,r5,r2                      |{{f/std|Loop }}
 +
001967b8: 14a0ffed bne r5,r0,0x00196770          {{f/eloop|Loop while Y < Max Y}}
 +
  001967bc: 00000000 nop                           |
 
   
 
   
  00196658: 92020e38 lbu r2,0x0e38(r16)
+
  {{f/sec|<nowiki>=== CHOOSE THE BEST DESTINATION  and store it in AI 0xcc4  (movement only without ability simulation) ===</nowiki>}}
  0019665c: 3c04801a lui r4,0x801a
+
001967c0: 8e020cc8 lw r2,0x0cc8(r16)            |{{f/load|<nowiki>Load Coordinates of result 0xe2d = 0x1 </nowiki>}} {{f/std|Caster best destination closer to target}}
  00196660: 8c84f374 lw r4,-0x0c8c(r4)
+
001967c4: 8e0317f8 lw r3,0x17f8(r16)            |{{f/adr|Acting Unit battle data pointer}}
  00196664: 0806599e j 0x00196678
+
001967c8: a2000e2d sb r0,0x0e2d(r16)            |{{f/store|Reset 0x2ed}}
  00196668: 00442021 addu r4,r2,r4
+
001967cc: ae020ccc sw r2,0x0ccc(r16)            |{{f/store|<nowiki>Store coordinates in 0xAI 0xccc (coordinates for 0xe2d = 2)</nowiki>}}
 +
001967d0: 90620188 lbu r2,0x0188(r3)            |{{f/load|Acting Unit Action Taken flag}}
 +
001967d4: 00000000 nop                          |
 +
001967d8: 14400016 bne r2,r0,0x00196834          {{f/Cond|If Acting Unit has already Taken his Action branch to}} {{f/loc|Keep Tile from AI 0xcc8}}
 +
001967dc: 00000000 nop                          |
 +
001967e0: 92220004 lbu r2,0x0004(r17)           |{{f/load|Acting Unit Decision Byte 0x04}} {{f/std|8019f3c4 + 0x182c + 0x04}}
 +
001967e4: 00000000 nop                          |
 +
  001967e8: 30420040 andi r2,r2,0x0040            |
 +
001967ec: 10400011 beq r2,r0,0x00196834          {{f/Cond|If Acting Unit has no Targeted Unit}} {{f/loc|Keep Tile from AI 0xcc8}}
 +
001967f0: 00000000 nop                          |
 +
001967f4: 3c02801a lui r2,0x801a                 |
 +
  001967f8: 8c42f368 lw r2,-0x0c98(r2)             |{{f/load|0x8019f368}}
 +
  001967fc: 00000000 nop                          |
 +
  00196800: 1040000c beq r2,r0,0x00196834          {{f/Cond|<nowiki>If 8019f368 = 0x00 (Cannot hit without moving)</nowiki>}} {{f/loc|Keep Tile from AI 0xcc8}}
 +
00196804: 00000000 nop                          |
 +
00196808: 92220006 lbu r2,0x0006(r17)            |{{f/load|Acting Unit Decision 0x06}} {{f/std|8019f3c4 + 0x182c + 0x6}}
 +
0019680c: 00000000 nop                          |
 +
00196810: 30420008 andi r2,r2,0x0008            |
 +
00196814: 14400007 bne r2,r0,0x00196834          {{f/Cond|If Acting Unit is Charging}} {{f/loc|Keep Tile from AI 0xcc8}}
 +
00196818: 00000000 nop                          |
 
   
 
   
  0019666c: 3c01801a lui r1,0x801a
+
                  {{f/sec|--- Find the best Tile in all reachable tiles (Action not Taken / Not Charging / Can Attack without moving / is focusing a Unit) ---}}
  00196670: ac20f368 sw r0,-0x0c98(r1)
+
  0019681c: 3c04801a lui r4,0x801a                 |
  00196674: 2484ffff addiu r4,r4,0xffff
+
  00196820: 8c84f374 lw r4,-0x0c8c(r4)             |{{f/load|Distance from Target}}
00196678: 0c065ab7 jal 0x00196adc Find Panel in Range
+
  00196824: 0c065a27 jal 0x0019689c                |{{f/jal|Find_Positive_Priority_Target_within_3_Range_(0019689c)|Find_Positive_Priority_Target_within_3_Range_(0019689c)}} {{f/std|0xe2d set to 0x00 here (will consider all reachable tiles)}}
0019667c: 00000000 nop
+
  00196828: 2484ffff addiu r4,r4,-0x0001           |{{f/std|Distance from Target - 1 (melee range ?)}}
00196680: 0c066672 jal 0x001999c8 AI Target Priority Super Routine
+
  0019682c: 08065a11 j 0x00196844                  {{f/jump|Go to Last section}} {{f/Returns|Return 0x00}}
  00196684: 00000000 nop
+
  00196830: 00001021 addu r2,r0,r0                |
00196688: 2403ffff addiu r3,r0,0xffff
 
0019668c: 14430004 bne r2,r3,0x001966a0
 
00196690: 34020001 ori r2,r0,0x0001
 
00196694: a2020c71 sb r2,0x0c71(r16) Save to 0x1a0035
 
  00196698: 08065a20 j 0x00196880 Exit and return -1
 
  0019669c: 2402ffff addiu r2,r0,0xffff
 
 
   
 
   
001966a0: 3c02801a lui r2,0x801a
+
                  {{f/sec|--- Store Tile from AI 0xcc8 in AI 0xcc4 (Get closer of main target) ---}}
  001966a4: 8c42f378 lw r2,-0x0c88(r2)
+
  00196834: 8e020cc8 lw r2,0x0cc8(r16)             |{{f/load|Load Better coordinates so Far}}
  001966a8: 00000000 nop
+
  00196838: 00000000 nop                           |
001966ac: 14400029 bne r2,r0,0x00196754 Branch to Move Range stuff if Distance already Set?
+
  0019683c: ae020cc4 sw r2,0x0cc4(r16)             |{{f/store|Save as new coordinates of interest ?}}
001966b0: 00000000 nop
+
  00196840: 00001021 addu r2,r0,r0                 |{{f/Returns|Return 0x00}}
  001966b4: 3c02801a lui r2,0x801a
 
001966b8: 8c42f368 lw r2,-0x0c98(r2) Target is in range?
 
  001966bc: 00000000 nop
 
001966c0: 10400006 beq r2,r0,0x001966dc Randomize Target Distance if false
 
001966c4: 3c047fff lui r4,0x7fff
 
001966c8: 3484ffff ori r4,r4,0xffff
 
001966cc: 0c065a4f jal 0x0019693c AI Post Action Movement Decision Routine
 
001966d0: 00002821 addu r5,r0,r0 Move Away from Enemy
 
001966d4: 080659d5 j 0x00196754 Jump to Move Range stuff
 
001966d8: 00000000 nop
 
 
   
 
   
Randomize coordinate values
+
                  {{f/sec|--- Last section ---}}
001966dc: 92020e39 lbu r2,0x0e39(r16) load acting units team
+
  00196844: 92040e31 lbu r4,0x0e31(r16)           |{{f/load|Acting Unit elevation}}
001966e0: 00000000 nop
+
  00196848: 92050e32 lbu r5,0x0e32(r16)           |{{f/load|Acting Unit Y}}
001966e4: 10400017 beq r2,r0,0x00196744 branch if uncontrolled Blue player team
+
  0019684c: 92060e30 lbu r6,0x0e30(r16)           |{{f/load|Acting Unit X}}
001966e8: 00000000 nop
+
  00196850: 000418c0 sll r3,r4,0x03               |
001966ec: 0c0088c3 jal 0x0002230c Random
+
  00196854: 00641821 addu r3,r3,r4                 |
001966f0: 00000000 nop
+
  00196858: 00031880 sll r3,r3,0x02               |{{f/std|Elevation offset (+0x24)}}
001966f4: 3c039249 lui r3,0x9249
+
  0019685c: 00701821 addu r3,r3,r16               |
001966f8: 34632493 ori r3,r3,0x2493
+
  00196860: 24630abc addiu r3,r3,0x0abc           |{{f/adr|Pointer to 0x8019f3c4 + 0xabc + elevation offset}} {{f/std|<nowiki> AI 0xa74 + 0x48 = Reachable and closer to Target</nowiki>}}
001966fc: 00430018 mult r2,r3
+
  00196864: 00052840 sll r5,r5,0x01               |{{f/std|Y offset (Halfword)}}
00196700: 000227c3 sra r4,r2,0x1f
+
  00196868: 00a32821 addu r5,r5,r3                 |{{f/std|add to pointer}}
00196704: 00001810 mfhi r3
+
  0019686c: 34048000 ori r4,r0,0x8000             |{{f/std|prepare bitmask}}
00196708: 00621821 addu r3,r3,r2
+
  00196870: 94a30000 lhu r3,0x0000(r5)             |{{f/load|Acting Unit Y row flags }} {{f/std|<nowiki> AI 0xa74 + 0x48 = Reachable and closer to Target</nowiki>}}
0019670c: 00031883 sra r3,r3,0x02
+
  00196874: 00c42007 srav r4,r4,r6                 |{{f/std|Bitmask for acting unit Tile}}
00196710: 00641823 subu r3,r3,r4
+
  00196878: 00641825 or r3,r3,r4                   |
00196714: 000320c0 sll r4,r3,0x03
+
  0019687c: a4a30000 sh r3,0x0000(r5)             |{{f/store|Enable Acting Unit Tile in Table of reachable and closer Tiles}} {{f/std|<nowiki> AI 0xa74 + 0x48 = Reachable and closer to Target</nowiki>}}
00196718: 00832023 subu r4,r4,r3
 
0019671c: 14440009 bne r2,r4,0x00196744 Branch Randomly
 
00196720: 00000000 nop
 
00196724: 3c02801a lui r2,0x801a
 
00196728: 8c42f36c lw r2,-0x0c94(r2) Load Target Distance
 
0019672c: 00000000 nop
 
00196730: 00021fc2 srl r3,r2,0x1f
 
00196734: 00431021 addu r2,r2,r3
 
00196738: 00021043 sra r2,r2,0x01
 
0019673c: 3c01801a lui r1,0x801a
 
00196740: ac22f36c sw r2,-0x0c94(r1) Save new Target Distance
 
 
00196744: 3c04801a lui r4,0x801a
 
00196748: 8c84f36c lw r4,-0x0c94(r4) Load Target Distance
 
0019674c: 0c065a42 jal 0x00196908 Find Best Panel to move to
 
00196750: 00000000 nop
 
00196754: 92030e3b lbu r3,0x0e3b(r16) map max y
 
00196758: 34020002 ori r2,r0,0x0002
 
0019675c: a2020e2d sb r2,0x0e2d(r16) ??
 
00196760: 3c01801a lui r1,0x801a
 
00196764: ac20f370 sw r0,-0x0c90(r1)
 
00196768: 10600015 beq r3,r0,0x001967c0
 
0019676c: 00000000 nop
 
00196770: 3c05801a lui r5,0x801a
 
00196774: 8ca5f370 lw r5,-0x0c90(r5)
 
00196778: 00000000 nop
 
0019677c: 00051040 sll r2,r5,0x01
 
00196780: 00501021 addu r2,r2,r16
 
00196784: 94430a74 lhu r3,0x0a74(r2)
 
00196788: 94460abc lhu r6,0x0abc(r2)
 
0019678c: 94440a98 lhu r4,0x0a98(r2)
 
00196790: 94470ae0 lhu r7,0x0ae0(r2)
 
00196794: 00661826 xor r3,r3,r6
 
00196798: 00872026 xor r4,r4,r7
 
0019679c: a4430b04 sh r3,0x0b04(r2)
 
001967a0: a4440b28 sh r4,0x0b28(r2)
 
001967a4: 92020e3b lbu r2,0x0e3b(r16)
 
001967a8: 24a50001 addiu r5,r5,0x0001
 
001967ac: 3c01801a lui r1,0x801a
 
001967b0: ac25f370 sw r5,-0x0c90(r1)
 
001967b4: 00a2282a slt r5,r5,r2
 
001967b8: 14a0ffed bne r5,r0,0x00196770
 
001967bc: 00000000 nop
 
001967c0: 8e020cc8 lw r2,0x0cc8(r16)
 
001967c4: 8e0317f8 lw r3,0x17f8(r16)
 
001967c8: a2000e2d sb r0,0x0e2d(r16)
 
001967cc: ae020ccc sw r2,0x0ccc(r16)
 
001967d0: 90620188 lbu r2,0x0188(r3) act flag?
 
001967d4: 00000000 nop
 
001967d8: 14400016 bne r2,r0,0x00196834 branch if able to act
 
001967dc: 00000000 nop
 
001967e0: 92220004 lbu r2,0x0004(r17)
 
001967e4: 00000000 nop
 
001967e8: 30420040 andi r2,r2,0x0040
 
001967ec: 10400011 beq r2,r0,0x00196834                    branch if not focus on unit
 
001967f0: 00000000 nop
 
001967f4: 3c02801a lui r2,0x801a
 
001967f8: 8c42f368 lw r2,-0x0c98(r2)
 
001967fc: 00000000 nop
 
00196800: 1040000c beq r2,r0,0x00196834       
 
00196804: 00000000 nop
 
00196808: 92220006 lbu r2,0x0006(r17)
 
0019680c: 00000000 nop
 
00196810: 30420008 andi r2,r2,0x0008
 
00196814: 14400007 bne r2,r0,0x00196834                  branch if charging ability
 
00196818: 00000000 nop
 
0019681c: 3c04801a lui r4,0x801a
 
00196820: 8c84f374 lw r4,-0x0c8c(r4)
 
00196824: 0c065a27 jal 0x0019689c Arcing Weapon Pathfinding
 
00196828: 2484ffff addiu r4,r4,0xffff
 
0019682c: 08065a11 j 0x00196844
 
00196830: 00001021 addu r2,r0,r0
 
 
00196834: 8e020cc8 lw r2,0x0cc8(r16)
 
00196838: 00000000 nop
 
0019683c: ae020cc4 sw r2,0x0cc4(r16) Save as new coordinates
 
00196840: 00001021 addu r2,r0,r0
 
  00196844: 92040e31 lbu r4,0x0e31(r16)
 
  00196848: 92050e32 lbu r5,0x0e32(r16)
 
  0019684c: 92060e30 lbu r6,0x0e30(r16)
 
  00196850: 000418c0 sll r3,r4,0x03
 
  00196854: 00641821 addu r3,r3,r4
 
  00196858: 00031880 sll r3,r3,0x02
 
  0019685c: 00701821 addu r3,r3,r16
 
  00196860: 24630abc addiu r3,r3,0x0abc
 
  00196864: 00052840 sll r5,r5,0x01
 
  00196868: 00a32821 addu r5,r5,r3
 
  0019686c: 34048000 ori r4,r0,0x8000
 
  00196870: 94a30000 lhu r3,0x0000(r5)
 
  00196874: 00c42007 srav r4,r4,r6
 
  00196878: 00641825 or r3,r3,r4
 
  0019687c: a4a30000 sh r3,0x0000(r5)
 
 
  00196880: 8fbf001c lw r31,0x001c(r29)
 
  00196880: 8fbf001c lw r31,0x001c(r29)
 
  00196884: 8fb20018 lw r18,0x0018(r29)
 
  00196884: 8fb20018 lw r18,0x0018(r29)
Line 344: Line 369:
 
  00196894: 03e00008 jr r31
 
  00196894: 03e00008 jr r31
 
  00196898: 00000000 nop
 
  00196898: 00000000 nop
 
+
===Return locations===
</font>
+
'''BATTLE.BIN'''
 +
  001961f4: [[ Non-Specific AI AutoBattle (Enemies)]]

Latest revision as of 20:06, 20 June 2024

BATTLE.BIN :  - Map_movement_decision/data_setting
Fill AI 0x3b4 Table - 1 Byte per Tile. If reachable (ON in AI 0xa74) Default data is distance to focused Target. Forced to 0x1 if there is a crystal (if needed)
Set potential destination, store best destination tile coordonates in AI 0xcc4
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : r2 = 0x00 (Default)
         r2 = -0x01 if routine Abort (Vsync call ?)
------------------------------------------------------------------------------------------
0019638c: 34020001 ori r2,r0,0x0001          |
00196390: 3c01801a lui r1,0x801a             |
00196394: a02201f1 sb r2,0x01f1(r1)          |Set AI 0xe2d = 0x01 801a01f1 (aka 8019f3c4 + 0xe2d)
00196398: 3c02801a lui r2,0x801a             |
0019639c: 90420d7b lbu r2,0x0d7b(r2)         |AI 0x19b7  801a0d7b aka 8019f3c4 + 0x19b7
001963a0: 27bdffe0 addiu r29,r29,-0x0020     |
001963a4: afb10014 sw r17,0x0014(r29)        |
001963a8: 3c11801a lui r17,0x801a            |
001963ac: 8e3101f8 lw r17,0x01f8(r17)        |Pointer to Acting Unit's AI Decision Data  (Caster AI 0x182c)  801a01f8 aka 8019f3c4 + 0xe34
001963b0: afb00010 sw r16,0x0010(r29)        |
001963b4: 3c10801a lui r16,0x801a            |
001963b8: 2610f3c4 addiu r16,r16,-0x0c3c     |0x8019f3c4
001963bc: afbf001c sw r31,0x001c(r29)        |
001963c0: 10400008 beq r2,r0,0x001963e4      #If AI 0x19b7 <> 0x00 
001963c4: afb20018 sw r18,0x0018(r29)            |
001963c8: 3c02801a lui r2,0x801a                 |
001963cc: 90420035 lbu r2,0x0035(r2)             |AI 0xc71 (This routine control variable)
001963d0: 00000000 nop                           |
001963d4: 1040001a beq r2,r0,0x00196440          #If Ai 0xc71 = 0x01  jump/return to AI 0x3b4 filling section
001963d8: 00000000 nop                           |
001963dc: 080659a0 j 0x00196680                  >>Else, branch to : AI Target Priority Super Routine (evaluate best destination)
001963e0: 00000000 nop                           |

=== Set potential destination ===
                                             Else : AI 0x19b7 = 0x00
001963e4: 92220004 lbu r2,0x0004(r17)            |Acting Unit decision data 0x04 Ai 0x182c + 0x04
001963e8: 00000000 nop                           |
001963ec: 30420040 andi r2,r2,0x0040             |
001963f0: 10400013 beq r2,r0,0x00196440          #If Acting Unit has no Unit to Focus : branch to   AI 0x3b4 setting
001963f4: 00000000 nop                           |
001963f8: 92230005 lbu r3,0x0005(r17)            |Focused Unit ID
001963fc: 3c02801a lui r2,0x801a                 |
00196400: 904201f2 lbu r2,0x01f2(r2)             |Acting units ID 801a01f2 aka 8019f3c4 + e2e
00196404: 00000000 nop                           |
00196408: 10620009 beq r3,r2,0x00196430          #If Acting Unit is NOT self focusing 
0019640c: 260403b4 addiu r4,r16,0x03b4           |8019f3c4 + 0x3b4
00196410: 00031100 sll r2,r3,0x04                    |Focused Unit  offset (0x10)
00196414: 00501021 addu r2,r2,r16                    |Part of pointer
00196418: 90421833 lbu r2,0x1833(r2)                 |load target type (Decision byte 0x07)  8019f3c4 + 0x182c + 0x07 + Focused Unit offset
0019641c: 00000000 nop                               |
00196420: 00021102 srl r2,r2,0x04                    |0x10 becomes 0x01
00196424: 30420001 andi r2,r2,0x0001                 |
00196428: 10400005 beq r2,r0,0x00196440              #If Focused unit is not Targetable : branch to   AI 0x3b4 setting
0019642c: 00000000 nop                               |

                  --- Clear AI 0x3b4 section (distance to target is not needed) ---
                                                 Else : self targeting or untargetable target - Clear AI 0x3b4
00196430: 0c066ade jal 0x0019ab78                    |-->Word_Nulling Nullify data from AI 0x3b4 to 0x5f4 (Distance from caster Table)
00196434: 34050240 ori r5,r0,0x0240                  |
00196438: 0806594e j 0x00196538                      |Keep AI 0x3b4 Empty  and Avoid Crystal loop
0019643c: 00000000 nop                               |

                  --- Fill AI 0x3b4 Section (distance to Target for each tile) ---
00196440: 0c06653e jal 0x001994f8                |-->See_if_able_to_move_to_target%3F Fill Table at 8019f3c4 + 0x3b4 (Each tile Distance to Target)
00196444: 02202021 addu r4,r17,r0                |Send Acting Unit AI decision data pointer
00196448: 2403ffff addiu r3,r0,-0x0001           |
0019644c: 14430003 bne r2,r3,0x0019645c          #if returned value is -0x01 (Vsync call issue ?)
00196450: 2402ffff addiu r2,r0,-0x0001               |
00196454: 08065a20 j 0x00196880                      |Exit routine Returns -0x01
00196458: a2000c71 sb r0,0x0c71(r16)                 |AI 0xc71 = 0x00
                                                 Else : r2 <> -0x01
0019645c: 92220007 lbu r2,0x0007(r17)                |Acting Unit AI decision byte 0x07
00196460: 00000000 nop                               |
00196464: 30420003 andi r2,r2,0x0003                 |
00196468: 10400033 beq r2,r0,0x00196538              #If Acting unit is not lacking of HP nor MP :  Avoid Crystal loop
0019646c: 00000000 nop                               |
00196470: 8e0217f8 lw r2,0x17f8(r16)                 |Acting Unit battle data pointer 0x801908cc
00196474: 00000000 nop                               |
00196478: 9042005c lbu r2,0x005c(r2)                 |Acting Unit current status 5
0019647c: 00000000 nop                               |
00196480: 30420001 andi r2,r2,0x0001                 |
00196484: 1440002c bne r2,r0,0x00196538              #If Acting Unit has [Death Sentence] branch to  Avoid Crystal loop
00196488: 00000000 nop                               |
0019648c: 3c01801a lui r1,0x801a                     |
00196490: ac20f370 sw r0,-0x0c90(r1)                 |Initialize Unit Counter Reset 8019f370
                                                    @LOOP - Search for Crystal 
00196494: 3c04801a lui r4,0x801a                         |
00196498: 8c84f370 lw r4,-0x0c90(r4)                     |Load Dynamic Unit ID
0019649c: 3c038019 lui r3,0x8019                         |
001964a0: 246308cc addiu r3,r3,0x08cc                    |
001964a4: 000410c0 sll r2,r4,0x03                        |
001964a8: 00441023 subu r2,r2,r4                         |
001964ac: 00021180 sll r2,r2,0x06                        |ID*0x1c0
001964b0: 00432821 addu r5,r2,r3                         |Dynamic Pointer to Unit battle data
001964b4: 90a30001 lbu r3,0x0001(r5)                     |load unit ID
001964b8: 340200ff ori r2,r0,0x00ff                      |
001964bc: 10620015 beq r3,r2,0x00196514                  #If This Unit ID = 0xff : branch to  Next unit
001964c0: 00000000 nop                                   |
001964c4: 90a20058 lbu r2,0x0058(r5)                     |This Unit Current Status 1
001964c8: 00000000 nop                                   |
001964cc: 30420040 andi r2,r2,0x0040                     |
001964d0: 10400010 beq r2,r0,0x00196514                  #If This Unit is a [Crystal] - Update AI 0x3b4
001964d4: 00000000 nop                                       |
001964d8: 0c067ca9 jal 0x0019f2a4                            |-->Transfer_Unit_Coordinates_to_AI Transfer This Unit coordinate at 8019f3c4 + 0xc74
001964dc: 26050c74 addiu r5,r16,0x0c74                       |Send Pointer to AI 0xc74
001964e0: 92030c75 lbu r3,0x0c75(r16)                        |This Unit elevation
001964e4: 92040c74 lbu r4,0x0c74(r16)                        |This Unit X coordinate
001964e8: 000310c0 sll r2,r3,0x03                            |
001964ec: 00431021 addu r2,r2,r3                             |
001964f0: 00021140 sll r2,r2,0x05                            |Elevation offset (0x120)
001964f4: 00501021 addu r2,r2,r16                            |AI pointer + elevation offset
001964f8: 92030c76 lbu r3,0x0c76(r16)                        |Load Y coordinate
001964fc: 244203b4 addiu r2,r2,0x03b4                        |Part of pointer to 8019f3c4 + 0x3b4
00196500: 00031900 sll r3,r3,0x04                            |Y offset (0x10)
00196504: 00621821 addu r3,r3,r2                             |Part of pointer to 8019f3c4 + 0x3b4
00196508: 00641821 addu r3,r3,r4                             |Pointer to this Unit 8019f3c4 + 0x3b4 Tile's data
0019650c: 34020001 ori r2,r0,0x0001                          |
00196510: a0620000 sb r2,0x0000(r3)                          |Store 0x01 in panel data (AI 0x3b4) instead of distance between unit ? Forces the crystal to feel closer ?
00196514: 3c02801a lui r2,0x801a                         |
00196518: 8c42f370 lw r2,-0x0c90(r2)                     |Load Unit Counter
0019651c: 00000000 nop                                   |
00196520: 24420001 addiu r2,r2,0x0001                    |
00196524: 3c01801a lui r1,0x801a                         |
00196528: ac22f370 sw r2,-0x0c90(r1)                     |Store increased Unit Counter
0019652c: 28420015 slti r2,r2,0x0015                     |
00196530: 1440ffd8 bne r2,r0,0x00196494              Λ Do for each unit
00196534: 00000000 nop                               |

                  --- POST CRYSTAL ---
00196538: 92020e31 lbu r2,0x0e31(r16)        |Acting Unit elevation
0019653c: 92040e30 lbu r4,0x0e30(r16)        |Acting Unit X coordinates
00196540: 000218c0 sll r3,r2,0x03            |
00196544: 00621821 addu r3,r3,r2             |
00196548: 00031940 sll r3,r3,0x05            |
0019654c: 00701821 addu r3,r3,r16            |8019f3c4 + Elevation offset (+0x120 if high elevation)
00196550: 92020e32 lbu r2,0x0e32(r16)        |Acting Unit Y coordinates
00196554: 246303b4 addiu r3,r3,0x03b4        |Elevation offset + 0x3b4
00196558: 00021100 sll r2,r2,0x04            |Y*16 (Y offset)
0019655c: 00431021 addu r2,r2,r3             |0x3b4 + Y offset + Elevation offset
00196560: 00441021 addu r2,r2,r4             |8019f3c4 + 0x3b4 + Caster Tile offset
00196564: 90420000 lbu r2,0x0000(r2)         |Acting Unit Distance from Target
00196568: 3c01801a lui r1,0x801a             |
0019656c: ac22f374 sw r2,-0x0c8c(r1)         |Store distance from Target at 0x8019f374
00196570: 0c0658a8 jal 0x001962a0            |-->Get_Longest_Range_Ability_or_Move Returns Closest Ability range if focusing, Acting unit move if not
00196574: 00000000 nop                       |
00196578: 3c04801a lui r4,0x801a             |
0019657c: 8c84f374 lw r4,-0x0c8c(r4)         |Caster Distance from Target
00196580: 3c01801a lui r1,0x801a             |
00196584: ac22f36c sw r2,-0x0c94(r1)         |Store Closest Ability Range (or Unit move) at 0x8019f36c
00196588: 3c01801a lui r1,0x801a             |
0019658c: ac20f378 sw r0,-0x0c88(r1)         |Reset 0x8019f378
00196590: 0044102a slt r2,r2,r4              |0x1 if  Closest range + Move < Distance From Target
00196594: 10400006 beq r2,r0,0x001965b0      #If Closest Ability > Distance From Target : branch to  Hit and run (?) section 
00196598: 34120001 ori r18,r0,0x0001         |
0019659c: 92220006 lbu r2,0x0006(r17)        |Acting Unit decision Byte 0x06
001965a0: 00000000 nop                       |
001965a4: 30420008 andi r2,r2,0x0008         |Check Ability CT flag
001965a8: 10400030 beq r2,r0,0x0019666c      #If caster is not charging: branch to   Move then Hit section
001965ac: 00000000 nop                       |

                  --- SECTION : TARGET is IN RANGE - Hit and run ?  / Run while charging ---   
                                             Else : Target is in range / Or Unit is Charging (Target already acquired?)
001965b0: 3c01801a lui r1,0x801a                 |
001965b4: ac32f368 sw r18,-0x0c98(r1)            |Target is in range = True // Hit and Run flag ? Target could be a tile or a unit
001965b8: 92220004 lbu r2,0x0004(r17)            |Load Acting Unit AI 0x182c byte 0x04
001965bc: 00000000 nop                           |
001965c0: 30420020 andi r2,r2,0x0020             |
001965c4: 10400024 beq r2,r0,0x00196658          #If Acting Unit do not have [Stay Near] flag : Avoid Stay near section
001965c8: 00000000 nop                           |

                                            --- STAY NEAR - CAN REACH TILE of INTEREST ? ---
001965cc: 0c0674a5 jal 0x0019d294                    |-->Get_unit_that_matches_coordinates  returns ID of Unit of Tile to protect ? (0x15 if none)
001965d0: 02202021 addu r4,r17,r0                    |Send AI decision data pointer
001965d4: 92030e2e lbu r3,0x0e2e(r16)                |Load acting unit ID
001965d8: 00402021 addu r4,r2,r0                     |
001965dc: 3c01801a lui r1,0x801a                     |
001965e0: ac24f370 sw r4,-0x0c90(r1)                 |Store unit ID 
001965e4: 10830003 beq r4,r3,0x001965f4              #If Acting Unit is on [stay near]Coordinates Focused Tile is reachable section
001965e8: 34020015 ori r2,r0,0x0015                  |
001965ec: 1482001a bne r4,r2,0x00196658              #If There is a Unit on This Tile : branch to Focused Tile is not reachable section
001965f0: 00000000 nop                               |

                                                --- Focused Tile is reachable (already on tile /Tile in range and empty) ---
001965f4: 92230001 lbu r3,0x0001(r17)                |Focused Tile Elevation 8019f3c4 + 0x182c + 0x01
001965f8: 92240000 lbu r4,0x0000(r17)                |Focused Tile X coordinates
001965fc: 000310c0 sll r2,r3,0x03                    |
00196600: 00431021 addu r2,r2,r3                     |
00196604: 00021080 sll r2,r2,0x02                    |Elevation offset (0x24)
00196608: 92230002 lbu r3,0x0002(r17)                |Focused Tile Y coordinates
0019660c: 00501021 addu r2,r2,r16                    |
00196610: 00031840 sll r3,r3,0x01                    |Y offset (Halfword)
00196614: 00431021 addu r2,r2,r3                     |Pointer to 0x8019f3c4 + 0xa74 + Acting Unit Y Row offset
00196618: 34038000 ori r3,r0,0x8000                  |Base bitmask
0019661c: 94420a74 lhu r2,0x0a74(r2)                 |Load Acting Unit Row's flags
00196620: 00831807 srav r3,r3,r4                     |Acting Unit's Tile's bitmask
00196624: 00431024 and r2,r2,r3                      |Acting Unit's Tile's Flag in AI 0xa74 Table
00196628: 1040000b beq r2,r0,0x00196658              #If Acting Unit Tile is Unreachable (Flag OFF) Branch to get closer section
0019662c: 00000000 nop                               |
00196630: 92020e2d lbu r2,0x0e2d(r16)                |Load 0x8019f3c4 + 0xe2d This routine control variable ? 
00196634: 8e230000 lw r3,0x0000(r17)                 |Load  Focused Tile Full coordinates
00196638: 00021080 sll r2,r2,0x02                    |0x0e2d * 4
0019663c: 00501021 addu r2,r2,r16                    |0x8019f3c4 + Offset based on 0xe2d
00196640: 0c0664e8 jal 0x001993a0                    |-->Update Reachable Tile's Flags Turn off any reachable Tile but the acting unit ones and the focused Tile one
00196644: ac430cc4 sw r3,0x0cc4(r2)                  |Store Full Coordinates at 0x8019f3c4 + 0xcc4 (based on 0xe2d) AI 0xcc8
00196648: 3c01801a lui r1,0x801a                     |
0019664c: ac32f378 sw r18,-0x0c88(r1)                |Set 0x8019f378 to 0x01
00196650: 080659a0 j 0x00196680                      >>Jump to Movement Priority Routine
00196654: 00000000 nop                               |

                                                --- Get closer of Target (Unit or occupied tile)
00196658: 92020e38 lbu r2,0x0e38(r16)                |Acting Unit's Move
0019665c: 3c04801a lui r4,0x801a                     |
00196660: 8c84f374 lw r4,-0x0c8c(r4)                 |Acting Unit's distance from Target
00196664: 0806599e j 0x00196678                      >>Jump directly to  Next routine (Fill AI 0xabc) Will Enable all tiles closest to Focused Tile in AI 0x74
00196668: 00442021 addu r4,r2,r4                     |Move + Distance

                  --- GET CLOSER THEN HIT Section  (Target is not reachable with all abilities)---
0019666c: 3c01801a lui r1,0x801a             |
00196670: ac20f368 sw r0,-0x0c98(r1)         |Reset 0x8019f3c8 Target in range flag ? 
00196674: 2484ffff addiu r4,r4,-0x0001       |Send  Distance from Target - 1 (From  001965a8)
00196678: 0c065ab7 jal 0x00196adc            |-->Check_AI_Target_Type_(00196adc) Set data to 0xabc Table (reachable and closer to Target)
0019667c: 00000000 nop                       |

=== CHOOSE THE BEST DESTINATION   CLOSER TO TARGET     store it in AI 0xcc8         (movement only without ability simulation) ===
00196680: 0c066672 jal 0x001999c8            |-->AI_Target_Priority_Super_Routine_(001999c8) Set Priority Mod for each Tiles in Table at AI 0x5f4 
00196684: 00000000 nop                       |
00196688: 2403ffff addiu r3,r0,-0x0001       |
0019668c: 14430004 bne r2,r3,0x001966a0      #If Routine returns -0x0001 (Table 0x5f4 not Updated)  - Vsync related
00196690: 34020001 ori r2,r0,0x0001              |
00196694: a2020c71 sb r2,0x0c71(r16)             |Set AI 0xc71 to 0x01
00196698: 08065a20 j 0x00196880                  |Exit Returns -0x0001
0019669c: 2402ffff addiu r2,r0,-0x0001           |
                                             Else : Table AI 0x5f4 has been Updated
001966a0: 3c02801a lui r2,0x801a                 |
001966a4: 8c42f378 lw r2,-0x0c88(r2)             |Load 0x8019f378  0x1 if Caster has [Stay Near] and Can move on This tile
001966a8: 00000000 nop                           |
001966ac: 14400029 bne r2,r0,0x00196754          #If Destination is already chosen  Avoid looking for best tile 
001966b0: 00000000 nop                           |
001966b4: 3c02801a lui r2,0x801a                 |
001966b8: 8c42f368 lw r2,-0x0c98(r2)             |Load 8019f368 - Target in Range Flag ?  0x1 if Targeted Unit distance < Closest Ability (Hit and Run is an option ?)
001966bc: 00000000 nop                           |
001966c0: 10400006 beq r2,r0,0x001966dc          #If Target is Targetable without moving
001966c4: 3c047fff lui r4,0x7fff                     |
001966c8: 3484ffff ori r4,r4,0xffff                  |Send Max possible distance
001966cc: 0c065a4f jal 0x0019693c                    |-->AI_Post_Action_Movement_Decision_Routine_(0019693c) Find best Tile and store coordinates at AI 0xcc8
001966d0: 00002821 addu r5,r0,r0                     |Priority prevails mod
001966d4: 080659d5 j 0x00196754                      |Keep result and Avoid opposite section
001966d8: 00000000 nop                               |
                                                 Else : Not Targetable with all abilities
001966dc: 92020e39 lbu r2,0x0e39(r16)                |load acting units team
001966e0: 00000000 nop                               |
001966e4: 10400017 beq r2,r0,0x00196744              #if Acting Unit is in Player Team : Avoid random stuff  (!?)
001966e8: 00000000 nop                               |
001966ec: 0c0088c3 jal 0x0002230c                    |-->Random_Number_Generator returns 0 to 0x7fff
001966f0: 00000000 nop                               |
001966f4: 3c039249 lui r3,0x9249                     |
001966f8: 34632493 ori r3,r3,0x2493                  |0x92492493  4/7  2^32
001966fc: 00430018 mult r2,r3                        |
00196700: 000227c3 sra r4,r2,0x1f                    |0
00196704: 00001810 mfhi r3                           |r3 = Rdm *-3/7 * 2^32
00196708: 00621821 addu r3,r3,r2                     |Rdm * 4/7
0019670c: 00031883 sra r3,r3,0x02                    |Rdm / 7
00196710: 00641823 subu r3,r3,r4                     |- 0x00
00196714: 000320c0 sll r4,r3,0x03                    |Rdm * 8 / 7
00196718: 00832023 subu r4,r4,r3                     |Rdm * 7 / 7 (but you lost the 1st byte during the right shift)
0019671c: 14440009 bne r2,r4,0x00196744              #If Random Number if a multiple of 7 and 16 (?)
00196720: 00000000 nop                                   |
00196724: 3c02801a lui r2,0x801a                         |
00196728: 8c42f36c lw r2,-0x0c94(r2)                     |Shortest Range
0019672c: 00000000 nop                                   |
00196730: 00021fc2 srl r3,r2,0x1f                        |
00196734: 00431021 addu r2,r2,r3                         |Range
00196738: 00021043 sra r2,r2,0x01                        |Range / 2
0019673c: 3c01801a lui r1,0x801a                         |
00196740: ac22f36c sw r2,-0x0c94(r1)                     |Randomly Halve Ability range ? 
00196744: 3c04801a lui r4,0x801a                     |
00196748: 8c84f36c lw r4,-0x0c94(r4)                 |Shortest Range
0019674c: 0c065a42 jal 0x00196908                    |-->Get_Positive_Priority_(00196908) Find best Tile and store coordinates at AI 0xcc8
00196750: 00000000 nop                               |

=== Set potential destination away from target (all cases)===
00196754: 92030e3b lbu r3,0x0e3b(r16)            |Map Max Y
00196758: 34020002 ori r2,r0,0x0002              |
0019675c: a2020e2d sb r2,0x0e2d(r16)             |Set 0xe2d to 0x02 (Away from Target offset)
00196760: 3c01801a lui r1,0x801a                 |
00196764: ac20f370 sw r0,-0x0c90(r1)             |Reset 0x8019f370
00196768: 10600015 beq r3,r0,0x001967c0          #If Map max Y is invalid Avoid loop
0019676c: 00000000 nop                           |
                                                @LOOP - Set Table of reachable tiles farther from Target (AI 0xb04)
00196770: 3c05801a lui r5,0x801a                     |
00196774: 8ca5f370 lw r5,-0x0c90(r5)                 |This Loop counter
00196778: 00000000 nop                               |
0019677c: 00051040 sll r2,r5,0x01                    |Y counter * 2 (halford offset)
00196780: 00501021 addu r2,r2,r16                    |Dynamic pointer to AI data (halfword offset)
00196784: 94430a74 lhu r3,0x0a74(r2)                 |This Y row Flags in Reachable Tiles Table 8019f3c4 + 0xa74
00196788: 94460abc lhu r6,0x0abc(r2)                 |This Y row Flags in Reachable and closer to Target Tiles Table 8019f3c4 + 0xa74 + 0x48 
0019678c: 94440a98 lhu r4,0x0a98(r2)                 |Same Y row but high elevation (AI 0xa74)
00196790: 94470ae0 lhu r7,0x0ae0(r2)                 |Same Y row but high elevation (AI 0xa74 + 0x48)
00196794: 00661826 xor r3,r3,r6                      |Toggle Low elevation flags : reachable and farther from target
00196798: 00872026 xor r4,r4,r7                      |Toggle High elevation flags : reachable and farther from target
0019679c: a4430b04 sh r3,0x0b04(r2)                  |Store Reachable and Farther flags at 0x8019f3c4 + 0xa74 + 0x90 2 times 0x48 offset (and 0xe2d is = 2)
001967a0: a4440b28 sh r4,0x0b28(r2)                  |Store High elevation Reachable and Farther flags  2 times 0x48 offset (and 0xe2d is = 2)
001967a4: 92020e3b lbu r2,0x0e3b(r16)                |Map Max Y
001967a8: 24a50001 addiu r5,r5,0x0001                |Y counter +1
001967ac: 3c01801a lui r1,0x801a                     |
001967b0: ac25f370 sw r5,-0x0c90(r1)                 |Store counter
001967b4: 00a2282a slt r5,r5,r2                      |Loop 
001967b8: 14a0ffed bne r5,r0,0x00196770          Λ Loop while Y < Max Y
001967bc: 00000000 nop                           |

=== CHOOSE THE BEST DESTINATION   and store it in AI 0xcc4  (movement only without ability simulation) ===
001967c0: 8e020cc8 lw r2,0x0cc8(r16)             |Load Coordinates of result 0xe2d = 0x1  Caster best destination closer to target
001967c4: 8e0317f8 lw r3,0x17f8(r16)             |Acting Unit battle data pointer
001967c8: a2000e2d sb r0,0x0e2d(r16)             |Reset 0x2ed
001967cc: ae020ccc sw r2,0x0ccc(r16)             |Store coordinates in 0xAI 0xccc (coordinates for 0xe2d = 2)
001967d0: 90620188 lbu r2,0x0188(r3)             |Acting Unit Action Taken flag
001967d4: 00000000 nop                           |
001967d8: 14400016 bne r2,r0,0x00196834          #If Acting Unit has already Taken his Action branch to Keep Tile from AI 0xcc8
001967dc: 00000000 nop                           |
001967e0: 92220004 lbu r2,0x0004(r17)            |Acting Unit Decision Byte 0x04 8019f3c4 + 0x182c + 0x04
001967e4: 00000000 nop                           |
001967e8: 30420040 andi r2,r2,0x0040             |
001967ec: 10400011 beq r2,r0,0x00196834          #If Acting Unit has no Targeted Unit Keep Tile from AI 0xcc8
001967f0: 00000000 nop                           |
001967f4: 3c02801a lui r2,0x801a                 |
001967f8: 8c42f368 lw r2,-0x0c98(r2)             |0x8019f368
001967fc: 00000000 nop                           |
00196800: 1040000c beq r2,r0,0x00196834          #If 8019f368 = 0x00 (Cannot hit without moving) Keep Tile from AI 0xcc8
00196804: 00000000 nop                           |
00196808: 92220006 lbu r2,0x0006(r17)            |Acting Unit Decision 0x06 8019f3c4 + 0x182c + 0x6
0019680c: 00000000 nop                           |
00196810: 30420008 andi r2,r2,0x0008             |
00196814: 14400007 bne r2,r0,0x00196834          #If Acting Unit is Charging Keep Tile from AI 0xcc8
00196818: 00000000 nop                           |

                  --- Find the best Tile in all reachable tiles (Action not Taken / Not Charging / Can Attack without moving / is focusing a Unit) ---
0019681c: 3c04801a lui r4,0x801a                 |
00196820: 8c84f374 lw r4,-0x0c8c(r4)             |Distance from Target
00196824: 0c065a27 jal 0x0019689c                |-->Find_Positive_Priority_Target_within_3_Range_(0019689c) 0xe2d set to 0x00 here (will consider all reachable tiles)
00196828: 2484ffff addiu r4,r4,-0x0001           |Distance from Target - 1 (melee range ?)
0019682c: 08065a11 j 0x00196844                  >>Go to Last section Return 0x00
00196830: 00001021 addu r2,r0,r0                 |

                  --- Store Tile from AI 0xcc8 in AI 0xcc4 (Get closer of main target) ---
00196834: 8e020cc8 lw r2,0x0cc8(r16)             |Load Better coordinates so Far
00196838: 00000000 nop                           |
0019683c: ae020cc4 sw r2,0x0cc4(r16)             |Save as new coordinates of interest ?
00196840: 00001021 addu r2,r0,r0                 |Return 0x00

                  --- Last section ---
00196844: 92040e31 lbu r4,0x0e31(r16)            |Acting Unit elevation
00196848: 92050e32 lbu r5,0x0e32(r16)            |Acting Unit Y
0019684c: 92060e30 lbu r6,0x0e30(r16)            |Acting Unit X
00196850: 000418c0 sll r3,r4,0x03                |
00196854: 00641821 addu r3,r3,r4                 |
00196858: 00031880 sll r3,r3,0x02                |Elevation offset (+0x24)
0019685c: 00701821 addu r3,r3,r16                |
00196860: 24630abc addiu r3,r3,0x0abc            |Pointer to 0x8019f3c4 + 0xabc + elevation offset  AI 0xa74 + 0x48 = Reachable and closer to Target
00196864: 00052840 sll r5,r5,0x01                |Y offset (Halfword)
00196868: 00a32821 addu r5,r5,r3                 |add to pointer
0019686c: 34048000 ori r4,r0,0x8000              |prepare bitmask
00196870: 94a30000 lhu r3,0x0000(r5)             |Acting Unit Y row flags   AI 0xa74 + 0x48 = Reachable and closer to Target
00196874: 00c42007 srav r4,r4,r6                 |Bitmask for acting unit Tile
00196878: 00641825 or r3,r3,r4                   |
0019687c: a4a30000 sh r3,0x0000(r5)              |Enable Acting Unit Tile in Table of reachable and closer Tiles  AI 0xa74 + 0x48 = Reachable and closer to Target
00196880: 8fbf001c lw r31,0x001c(r29)
00196884: 8fb20018 lw r18,0x0018(r29)
00196888: 8fb10014 lw r17,0x0014(r29)
0019688c: 8fb00010 lw r16,0x0010(r29)
00196890: 27bd0020 addiu r29,r29,0x0020
00196894: 03e00008 jr r31
00196898: 00000000 nop

Return locations

BATTLE.BIN
 001961f4: Non-Specific AI AutoBattle (Enemies)