Difference between revisions of "Check for good units to target (based on distance,status,coordinate)"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Updated Documentation)
Line 1: Line 1:
<font face='Courier New'>
+
'''BATTLE.BIN''' - Check for good units to target (based on distance,status,coordinate)
Check for good units to target (based on distance,status,coordinate) <font face='Courier New'>
+
Should probably be : Set Enemies proximity score
 
+
-------------------------------------------------------------------------------------------------------------------------------------
  0019971c: 27bdffc8 addiu r29,r29,0xffc8
+
Parameters : Nothing
  00199720: afb20028 sw r18,0x0028(r29)
+
  00199724: 3c12801a lui r18,0x801a
+
Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move
  00199728: 2652f3c4 addiu r18,r18,0xf3c4
+
          r2 = 0x00 if Unit Can move but has berserk or confuse
  0019972c: afb00020 sw r16,0x0020(r29)
+
          r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?)
  00199730: 00008021 addu r16,r0,r0
+
  00199734: afb3002c sw r19,0x002c(r29)
+
First fill targetable ennemies list ( 0x8019f3c4 + 0xc8d )
  00199738: 34130001 ori r19,r0,0x0001
+
Then fill Table 0x0174 with some proximity score for each Tile of the map. the higher the score, the more ennemies surround the tile.
  0019973c: afbf0030 sw r31,0x0030(r29)
+
-------------------------------------------------------------------------------------------------
  00199740: afb10024 sw r17,0x0024(r29)
+
0019971c: 27bdffc8 addiu r29,r29,-0x0038    |
  00199744: 02508821 addu r17,r18,r16
+
00199720: afb20028 sw r18,0x0028(r29)      |
  00199748: a2200c8d sb r0,0x0c8d(r17)
+
00199724: 3c12801a lui r18,0x801a          |
  0019974c: 0c065b23 jal 0x00196c8c [[Check target type]]
+
00199728: 2652f3c4 addiu r18,r18,-0x0c3c    |{{f/adr|AI data pointer ( 8019f3c4 )}}
  00199750: 02002021 addu r4,r16,r0
+
0019972c: afb00020 sw r16,0x0020(r29)      |
  00199754: 14400006 bne r2,r0,0x00199770 branch if not targetable
+
00199730: 00008021 addu r16,r0,r0           |{{f/std|Initialize loop counter}}
  00199758: 00000000 nop
+
00199734: afb3002c sw r19,0x002c(r29)      |
  0019975c: 0c066632 jal 0x001998c8 [[Check if Regen/Charm/DM/Reraise/DA Can be Inflicted]]
+
00199738: 34130001 ori r19,r0,0x0001        |{{f/std|Prepare flag value}}
  00199760: 02002021 addu r4,r16,r0
+
0019973c: afbf0030 sw r31,0x0030(r29)       |
  00199764: 14400002 bne r2,r0,0x00199770 Next Unit if Unit has Stop/Don't Act/Sleep/Chicken/Charm or spell can't go off in time
+
00199740: afb10024 sw r17,0x0024(r29)      |
  00199768: 00000000 nop
+
00199744: 02508821 addu r17,r18,r16        |{{f/adr|AI data pointer + Unit offset}}
  0019976c: a2330c8d sb r19,0x0c8d(r17) Unit Targetable = True
+
                                            {{f/bloop|LOOP - though all units}}
 
+
00199748: a2200c8d sb r0,0x0c8d(r17)            |{{f/store|Initialize Unit flag in targetable list}}
  00199770: 26100001 addiu r16,r16,0x0001
+
0019974c: 0c065b23 jal 0x00196c8c              |{{f/jal|Check target type|Check target type}} {{f/std|<nowiki>Returns r2 = 0x00 if This iteration unit is targetable</nowiki>}}
  00199774: 2a020015 slti r2,r16,0x0015
+
00199750: 02002021 addu r4,r16,r0              |{{f/std|This iteration Unit ID}}
  00199778: 1440fff3 bne r2,r0,0x00199748 do for all units
+
00199754: 14400006 bne r2,r0,0x00199770        {{f/Cond|If This unit is targetable / Else branch to }} {{f/loc|Next Unit}}
  0019977c: 02508821 addu r17,r18,r16
+
00199758: 00000000 nop                             |{{f/std|}}
 
+
0019975c: 0c066632 jal 0x001998c8                  |{{f/jal|AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm|AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm}} {{f/std|<nowiki> Returns 0x00 if enemy Unit could suffer any of these (= is worth to be considered)</nowiki>}}
  00199780: 00007021 addu r14,r0,r0
+
00199760: 02002021 addu r4,r16,r0                  |
  00199784: 3c118019 lui r17,0x8019
+
00199764: 14400002 bne r2,r0,0x00199770            {{f/Cond|If Unit is an ennemy worth to be considered / Else branch to }} {{f/loc|Next Unit}}
  00199788: 263108cc addiu r17,r17,0x08cc
+
00199768: 00000000 nop                                  |{{f/std|}}
  0019978c: 340f000a ori r15,r0,0x000a
+
0019976c: a2330c8d sb r19,0x0c8d(r17)                  |{{f/store|<nowiki>Unit Targetable = True</nowiki>}}
  00199790: 02406821 addu r13,r18,r0
+
00199770: 26100001 addiu r16,r16,0x0001         |{{f/std|Unit counter + 1}}
  00199794: 02406021 addu r12,r18,r0
+
00199774: 2a020015 slti r2,r16,0x0015          |{{f/std|Check limit}}
 
+
00199778: 1440fff3 bne r2,r0,0x00199748    {{f/eloop|Loop 0x15 Times}}
  00199798: 92420e3b lbu r2,0x0e3b(r18) load map max X?
+
0019977c: 02508821 addu r17,r18,r16            |{{f/std|Ai data offset (+1 each iteration)}}
  0019979c: 00000000 nop
+
00199780: 00007021 addu r14,r0,r0           |{{f/std|Initialize elevation loop counter}}
  001997a0: 1840003c blez r2,0x00199894
+
00199784: 3c118019 lui r17,0x8019          |
  001997a4: 00004021 addu r8,r0,r0
+
00199788: 263108cc addiu r17,r17,0x08cc    |{{f/adr|Start of Battle stats data pointer}}
  001997a8: 25ab0174 addiu r11,r13,0x0174
+
0019978c: 340f000a ori r15,r0,0x000a        |{{f/std|<nowiki>r15 = 10 (used to set the proximity score)</nowiki>}}
  001997ac: 258a0a74 addiu r10,r12,0x0a74 load ?? data
+
00199790: 02406821 addu r13,r18,r0          |{{f/adr|AI data pointer ( 8019f3c4 )}}
  001997b0: 95490000 lhu r9,0x0000(r10) Load Highest Target Priority
+
00199794: 02406021 addu r12,r18,r0          |{{f/adr|AI data pointer ( 8019f3c4 )}}
  001997b4: 00000000 nop
+
  001997b8: 11200030 beq r9,r0,0x0019987c              Branch if Highest Target Priority hasn't been set yet
+
00199798: 92420e3b lbu r2,0x0e3b(r18)          |{{f/load|Load map max Y}}
  001997bc: 00000000 nop
+
0019979c: 00000000 nop                         |
  001997c0: 92420e3a lbu r2,0x0e3a(r18) load map max y?
+
001997a0: 1840003c blez r2,0x00199894          {{f/Cond|If Map max Y is invalid : Branch to }} {{f/loc|next iteration}}
  001997c4: 00000000 nop
+
001997a4: 00004021 addu r8,r0,r0                |{{f/std|Initialize Y counter}}
  001997c8: 1840002c blez r2,0x0019987c
+
001997a8: 25ab0174 addiu r11,r13,0x0174        |{{f/adr|This elevation iteration of Tile's target proximity data Table}} {{f/std| + 0x120 for high elevation}}
  001997cc: 00002821 addu r5,r0,r0
+
001997ac: 258a0a74 addiu r10,r12,0x0a74        |{{f/adr|This elevation iteration ?}} {{f/std| + 0x24 for high elevation}}
  001997d0: 01603021 addu r6,r11,r0
+
  001997d4: 00a91004 sllv r2,r9,r5
+
001997b0: 95490000 lhu r9,0x0000(r10)          |{{f/load|Load Y coordinates Halfword (0x10 reachable tiles flags)}}
  001997d8: 30428000 andi r2,r2,0x8000
+
001997b4: 00000000 nop                          |
  001997dc: 10400022 beq r2,r0,0x00199868         Next X if Targeted Unit is not in that Targeting Matrix Coordinate
+
001997b8: 11200030 beq r9,r0,0x0019987c        {{f/Cond|If there is somereachable tile in this row}}
  001997e0: 00000000 nop
+
001997bc: 00000000 nop                              |
  001997e4: a0c00000 sb r0,0x0000(r6)                  Empty part of Target Priority
+
001997c0: 92420e3a lbu r2,0x0e3a(r18)               |{{f/load|Load map max X}}
  001997e8: 00008021 addu r16,r0,r0
+
001997c4: 00000000 nop                              |
  001997ec: 00c03821 addu r7,r6,r0
+
001997c8: 1840002c blez r2,0x0019987c              {{f/Cond|If Map max Y is invalid : Branch to }} {{f/loc|next iteration}}
  001997f0: 02202021 addu r4,r17,r0
+
001997cc: 00002821 addu r5,r0,r0                    |{{f/std|Initialize X counter}}
  001997f4: 02501021 addu r2,r18,r16
+
001997d0: 01603021 addu r6,r11,r0                  |{{f/adr|Pointer to 8019f3c4 - 0x174 data}} {{f/std| +0x10 each Yrow iteration}}
  001997f8: 90420c8d lbu r2,0x0c8d(r2) Load Can Target List
+
                                                    {{f/bloop|LOOP - through all X tiles (in Y row)}}
  001997fc: 00000000 nop
+
001997d4: 00a91004 sllv r2,r9,r5                        |{{f/std|Shift Row flag (this iteration X tile flag will be the highest in the halfword)}}
  00199800: 10400015 beq r2,r0,0x00199858 Next Unit if unit cannot/should not be targeted
+
001997d8: 30428000 andi r2,r2,0x8000                    |{{f/std|Bitmask on this iteration Tile's flag (is reachable by AI  unit)}}
  00199804: 00000000 nop
+
001997dc: 10400022 beq r2,r0,0x00199868                {{f/Cond|If This Tile is reachable}}
  00199808: 90820047 lbu r2,0x0047(r4) load coordinate
+
001997e0: 00000000 nop                                      |{{f/std|}}
  0019980c: 00000000 nop
+
001997e4: a0c00000 sb r0,0x0000(r6)                         |{{f/store|Initialize this Tile byte in 0x174 data}}
  00199810: 00451823 subu r3,r2,r5 coordinate - ??
+
001997e8: 00008021 addu r16,r0,r0                          |{{f/std|Initialize Unit counter}}
  00199814: 04610002 bgez r3,0x00199820 branch if out in range?
+
001997ec: 00c03821 addu r7,r6,r0                            |{{f/adr|This tile 0x174 data pointer}}
  00199818: 00000000 nop
+
001997f0: 02202021 addu r4,r17,r0                           |{{f/adr|Start of Battle stats data pointer}}
  0019981c: 00031823 subu r3,r0,r3 make positive
+
                                                            {{f/bloop|LOOP - through all units}}
  00199820: 90820048 lbu r2,0x0048(r4) load coordinate
+
001997f4: 02501021 addu r2,r18,r16                              |{{f/adr|This iteration unit AI data pointer}}
  00199824: 00000000 nop
+
001997f8: 90420c8d lbu r2,0x0c8d(r2)                           |{{f/load|Load this unit targetable flag (in targetable list)}}
  00199828: 00481023 subu r2,r2,r8
+
001997fc: 00000000 nop                                          |
  0019982c: 04410002 bgez r2,0x00199838
+
00199800: 10400015 beq r2,r0,0x00199858                        {{f/Cond|If this unit is a Targetable foe / Worth to be considered}}
  00199830: 00000000 nop
+
00199804: 00000000 nop                                              |{{f/std|}}
  00199834: 00021023 subu r2,r0,r2 make positive
+
00199808: 90820047 lbu r2,0x0047(r4)                                |{{f/load|Load This unit X coordinate}}
  00199838: 00621821 addu r3,r3,r2 r3 = distance
+
0019980c: 00000000 nop                                              |
  0019983c: 2862000b slti r2,r3,0x000b Next Unit if distance < 11 (more than 5 Panels away)
+
00199810: 00451823 subu r3,r2,r5                                    |{{f/std|Delta X (This Unit - This Tile X)}}
  00199840: 10400005 beq r2,r0,0x00199858 branch if not
+
00199814: 04610002 bgez r3,0x00199820                              {{f/Cond|If Delta X < 0x00}}
  00199844: 01e31823 subu r3,r15,r3 10 - Distance (5 Panels away)
+
00199818: 00000000 nop                                                  |{{f/std|}}
  00199848: 90e20000 lbu r2,0x0000(r7) load ??
+
0019981c: 00031823 subu r3,r0,r3                                        |{{f/std|Make delta X positive}}
  0019984c: 00000000 nop
+
00199820: 90820048 lbu r2,0x0048(r4)                                |{{f/load|Load This unit Y coordinates}}
  00199850: 00431021 addu r2,r2,r3 add amounts
+
00199824: 00000000 nop                                              |
  00199854: a0e20000 sb r2,0x0000(r7) Save Distance
+
00199828: 00481023 subu r2,r2,r8                                    |{{f/std|Delta Y (This Unit - This Tile Y)}}
  00199858: 26100001 addiu r16,r16,0x0001
+
0019982c: 04410002 bgez r2,0x00199838                              {{f/Cond|If Delta Y < 0x00}}
  0019985c: 2a020015 slti r2,r16,0x0015
+
00199830: 00000000 nop                                                  |{{f/std|}}
  00199860: 1440ffe4 bne r2,r0,0x001997f4
+
00199834: 00021023 subu r2,r0,r2                                        |{{f/std|Make delta Y positive}}
  00199864: 248401c0 addiu r4,r4,0x01c0
+
00199838: 00621821 addu r3,r3,r2                                    |{{f/std|Distance Between This Unit and This Tile}}
 
+
0019983c: 2862000b slti r2,r3,0x000b                                |
  00199868: 92420e3a lbu r2,0x0e3a(r18) load map max x
+
00199840: 10400005 beq r2,r0,0x00199858                            {{f/Cond|If Unit Distance from Tile is less than 11}}
  0019986c: 24a50001 addiu r5,r5,0x0001 go to next coordinate
+
00199844: 01e31823 subu r3,r15,r3                                      |{{f/std|10 - Distance (5 Panels away)}}
  00199870: 00a2102a slt r2,r5,r2 set if < max coordinate
+
  00199848: 90e20000 lbu r2,0x0000(r7)                                    |{{f/load|Load this Tile Proximity data}}
  00199874: 1440ffd7 bne r2,r0,0x001997d4 do for each X coordinate
+
0019984c: 00000000 nop                                                  |
  00199878: 24c60001 addiu r6,r6,0x0001 increment coordinate array
+
00199850: 00431021 addu r2,r2,r3                                        |{{f/std|Add Amounts}}
  0019987c: 256b0010 addiu r11,r11,0x0010 increment unit coordinate array by row
+
00199854: a0e20000 sb r2,0x0000(r7)                                    |{{f/store|<nowiki>Update This tile data : Higher amount = Higher nb of target near the tile</nowiki>}}
 
+
00199858: 26100001 addiu r16,r16,0x0001                        |{{f/std|Unit counter + 1}}
  00199880: 92420e3b lbu r2,0x0e3b(r18)
+
0019985c: 2a020015 slti r2,r16,0x0015                          |{{f/std|Check Limit}}
  00199884: 25080001 addiu r8,r8,0x0001
+
00199860: 1440ffe4 bne r2,r0,0x001997f4                    {{f/eloop|Loop through all units}}
  00199888: 0102102a slt r2,r8,r2
+
00199864: 248401c0 addiu r4,r4,0x01c0                          |{{f/std|Unit Battle data offset }}
  0019988c: 1440ffc8 bne r2,r0,0x001997b0 do for each y coordinate
+
00199868: 92420e3a lbu r2,0x0e3a(r18)                  |{{f/load|Load map max X}}
  00199890: 254a0002 addiu r10,r10,0x0002
+
0019986c: 24a50001 addiu r5,r5,0x0001                  |{{f/std|X counter +1}}
 
+
00199870: 00a2102a slt r2,r5,r2                        |{{f/std|Check limit}}
  00199894: 25ad0120 addiu r13,r13,0x0120
+
00199874: 1440ffd7 bne r2,r0,0x001997d4            {{f/eloop|Loop while not at max X}}
  00199898: 25ce0001 addiu r14,r14,0x0001
+
00199878: 24c60001 addiu r6,r6,0x0001                  |{{f/std|X Offset in AI Tile's 0x174 Table (+1 each iteration)}}
  0019989c: 29c20002 slti r2,r14,0x0002
+
0019987c: 256b0010 addiu r11,r11,0x0010            |{{f/std|Row Offset in AI Tile's 0x174 Table (+0x10 each Y iteration)}}
  001998a0: 1440ffbd bne r2,r0,0x00199798 do for each map level
+
00199880: 92420e3b lbu r2,0x0e3b(r18)              |{{f/load|Load map max Y}}
  001998a4: 258c0024 addiu r12,r12,0x0024
+
00199884: 25080001 addiu r8,r8,0x0001              |{{f/std|Y counter + 1}}
 
+
00199888: 0102102a slt r2,r8,r2                    |{{f/std|Check Y Limit}}
  001998a8: 8fbf0030 lw r31,0x0030(r29)
+
0019988c: 1440ffc8 bne r2,r0,0x001997b0        {{f/eloop|Loop while not at max Y}}
  001998ac: 8fb3002c lw r19,0x002c(r29)
+
00199890: 254a0002 addiu r10,r10,0x0002            |{{f/std|Offset in AI Tile's 0xa74 Table + 0x02 each iteration (Half word)}}
  001998b0: 8fb20028 lw r18,0x0028(r29)
+
00199894: 25ad0120 addiu r13,r13,0x0120        |{{f/std|<nowiki>r13 = ? Offset + 0x120 Each iteration</nowiki>}}
  001998b4: 8fb10024 lw r17,0x0024(r29)
+
00199898: 25ce0001 addiu r14,r14,0x0001        |{{f/std|Elevation counter + 1}}
  001998b8: 8fb00020 lw r16,0x0020(r29)
+
0019989c: 29c20002 slti r2,r14,0x0002          |{{f/std|Check limit}}
  001998bc: 27bd0038 addiu r29,r29,0x0038
+
001998a0: 1440ffbd bne r2,r0,0x00199798    {{f/eloop|Loop 0x2 Times (Elevation 0 and 1)}}
  001998c0: 03e00008 jr r31
+
001998a4: 258c0024 addiu r12,r12,0x0024        |{{f/std|<nowiki>r12 = ? Offset + 0x24 each iteration</nowiki>}}
  001998c4: 00000000 nop
+
001998a8: 8fbf0030 lw r31,0x0030(r29)      END
  </font></font>
+
001998ac: 8fb3002c lw r19,0x002c(r29)
 +
001998b0: 8fb20028 lw r18,0x0028(r29)
 +
001998b4: 8fb10024 lw r17,0x0024(r29)
 +
001998b8: 8fb00020 lw r16,0x0020(r29)
 +
001998bc: 27bd0038 addiu r29,r29,0x0038
 +
001998c0: 03e00008 jr r31
 +
001998c4: 00000000 nop
 +
=== Return location ===
 +
'''BATTLE.BIN'''
 +
00195e44: [[00195d94_-_00195f68]]

Revision as of 13:50, 31 July 2023

BATTLE.BIN - Check for good units to target (based on distance,status,coordinate)
Should probably be : Set Enemies proximity score
-------------------------------------------------------------------------------------------------------------------------------------
Parameters : Nothing

Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move
          r2 = 0x00 if Unit Can move but has berserk or confuse
          r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?)

First fill targetable ennemies list ( 0x8019f3c4 + 0xc8d ) 
Then fill Table 0x0174 with some proximity score for each Tile of the map. the higher the score, the more ennemies surround the tile.
-------------------------------------------------------------------------------------------------
0019971c: 27bdffc8 addiu r29,r29,-0x0038    |
00199720: afb20028 sw r18,0x0028(r29)       |
00199724: 3c12801a lui r18,0x801a           |
00199728: 2652f3c4 addiu r18,r18,-0x0c3c    |AI data pointer ( 8019f3c4 )
0019972c: afb00020 sw r16,0x0020(r29)       |
00199730: 00008021 addu r16,r0,r0           |Initialize loop counter
00199734: afb3002c sw r19,0x002c(r29)       |
00199738: 34130001 ori r19,r0,0x0001        |Prepare flag value
0019973c: afbf0030 sw r31,0x0030(r29)       |
00199740: afb10024 sw r17,0x0024(r29)       |
00199744: 02508821 addu r17,r18,r16         |AI data pointer + Unit offset
                                            @LOOP - though all units
00199748: a2200c8d sb r0,0x0c8d(r17)            |Initialize Unit flag in targetable list
0019974c: 0c065b23 jal 0x00196c8c               |-->Check target type Returns r2 = 0x00 if This iteration unit is targetable
00199750: 02002021 addu r4,r16,r0               |This iteration Unit ID
00199754: 14400006 bne r2,r0,0x00199770         #If This unit is targetable / Else branch to  Next Unit
00199758: 00000000 nop                              |
0019975c: 0c066632 jal 0x001998c8                   |-->AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm  Returns 0x00 if enemy Unit could suffer any of these (= is worth to be considered)
00199760: 02002021 addu r4,r16,r0                   |
00199764: 14400002 bne r2,r0,0x00199770             #If Unit is an ennemy worth to be considered / Else branch to  Next Unit
00199768: 00000000 nop                                  |
0019976c: a2330c8d sb r19,0x0c8d(r17)                   |Unit Targetable = True
00199770: 26100001 addiu r16,r16,0x0001         |Unit counter + 1
00199774: 2a020015 slti r2,r16,0x0015           |Check limit
00199778: 1440fff3 bne r2,r0,0x00199748     Λ Loop 0x15 Times
0019977c: 02508821 addu r17,r18,r16             |Ai data offset (+1 each iteration)
00199780: 00007021 addu r14,r0,r0           |Initialize elevation loop counter
00199784: 3c118019 lui r17,0x8019           |
00199788: 263108cc addiu r17,r17,0x08cc     |Start of Battle stats data pointer
0019978c: 340f000a ori r15,r0,0x000a        |r15 = 10 (used to set the proximity score)
00199790: 02406821 addu r13,r18,r0          |AI data pointer ( 8019f3c4 )
00199794: 02406021 addu r12,r18,r0          |AI data pointer ( 8019f3c4 )

00199798: 92420e3b lbu r2,0x0e3b(r18)           |Load map max Y
0019979c: 00000000 nop                          |
001997a0: 1840003c blez r2,0x00199894           #If Map max Y is invalid : Branch to  next iteration
001997a4: 00004021 addu r8,r0,r0                |Initialize Y counter
001997a8: 25ab0174 addiu r11,r13,0x0174         |This elevation iteration of Tile's target proximity data Table  + 0x120 for high elevation
001997ac: 258a0a74 addiu r10,r12,0x0a74         |This elevation iteration ?  + 0x24 for high elevation

001997b0: 95490000 lhu r9,0x0000(r10)           |Load Y coordinates Halfword (0x10 reachable tiles flags)
001997b4: 00000000 nop                          |
001997b8: 11200030 beq r9,r0,0x0019987c         #If there is somereachable tile in this row
001997bc: 00000000 nop                              |
001997c0: 92420e3a lbu r2,0x0e3a(r18)               |Load map max X
001997c4: 00000000 nop                              |
001997c8: 1840002c blez r2,0x0019987c               #If Map max Y is invalid : Branch to  next iteration
001997cc: 00002821 addu r5,r0,r0                    |Initialize X counter
001997d0: 01603021 addu r6,r11,r0                   |Pointer to 8019f3c4 - 0x174 data  +0x10 each Yrow iteration
                                                    @LOOP - through all X tiles (in Y row)
001997d4: 00a91004 sllv r2,r9,r5                        |Shift Row flag (this iteration X tile flag will be the highest in the halfword)
001997d8: 30428000 andi r2,r2,0x8000                    |Bitmask on this iteration Tile's flag (is reachable by AI  unit)
001997dc: 10400022 beq r2,r0,0x00199868                 #If This Tile is reachable
001997e0: 00000000 nop                                      |
001997e4: a0c00000 sb r0,0x0000(r6)                         |Initialize this Tile byte in 0x174 data
001997e8: 00008021 addu r16,r0,r0                           |Initialize Unit counter
001997ec: 00c03821 addu r7,r6,r0                            |This tile 0x174 data pointer
001997f0: 02202021 addu r4,r17,r0                           |Start of Battle stats data pointer
                                                            @LOOP - through all units
001997f4: 02501021 addu r2,r18,r16                              |This iteration unit AI data pointer
001997f8: 90420c8d lbu r2,0x0c8d(r2)                            |Load this unit targetable flag (in targetable list)
001997fc: 00000000 nop                                          |
00199800: 10400015 beq r2,r0,0x00199858                         #If this unit is a Targetable foe / Worth to be considered
00199804: 00000000 nop                                              |
00199808: 90820047 lbu r2,0x0047(r4)                                |Load This unit X coordinate
0019980c: 00000000 nop                                              |
00199810: 00451823 subu r3,r2,r5                                    |Delta X (This Unit - This Tile X)
00199814: 04610002 bgez r3,0x00199820                               #If Delta X < 0x00
00199818: 00000000 nop                                                  |
0019981c: 00031823 subu r3,r0,r3                                        |Make delta X positive
00199820: 90820048 lbu r2,0x0048(r4)                                |Load This unit Y coordinates
00199824: 00000000 nop                                              |
00199828: 00481023 subu r2,r2,r8                                    |Delta Y (This Unit - This Tile Y)
0019982c: 04410002 bgez r2,0x00199838                               #If Delta Y < 0x00
00199830: 00000000 nop                                                  |
00199834: 00021023 subu r2,r0,r2                                        |Make delta Y positive
00199838: 00621821 addu r3,r3,r2                                    |Distance Between This Unit and This Tile
0019983c: 2862000b slti r2,r3,0x000b                                |
00199840: 10400005 beq r2,r0,0x00199858                             #If Unit Distance from Tile is less than 11
00199844: 01e31823 subu r3,r15,r3                                       |10 - Distance (5 Panels away)
00199848: 90e20000 lbu r2,0x0000(r7)                                    |Load this Tile Proximity data
0019984c: 00000000 nop                                                  |
00199850: 00431021 addu r2,r2,r3                                        |Add Amounts
00199854: a0e20000 sb r2,0x0000(r7)                                     |Update This tile data : Higher amount = Higher nb of target near the tile
00199858: 26100001 addiu r16,r16,0x0001                         |Unit counter + 1
0019985c: 2a020015 slti r2,r16,0x0015                           |Check Limit
00199860: 1440ffe4 bne r2,r0,0x001997f4                     Λ Loop through all units
00199864: 248401c0 addiu r4,r4,0x01c0                           |Unit Battle data offset 
00199868: 92420e3a lbu r2,0x0e3a(r18)                   |Load map max X
0019986c: 24a50001 addiu r5,r5,0x0001                   |X counter +1
00199870: 00a2102a slt r2,r5,r2                         |Check limit
00199874: 1440ffd7 bne r2,r0,0x001997d4             Λ Loop while not at max X
00199878: 24c60001 addiu r6,r6,0x0001                   |X Offset in AI Tile's 0x174 Table (+1 each iteration)
0019987c: 256b0010 addiu r11,r11,0x0010             |Row Offset in AI Tile's 0x174 Table (+0x10 each Y iteration)
00199880: 92420e3b lbu r2,0x0e3b(r18)               |Load map max Y
00199884: 25080001 addiu r8,r8,0x0001               |Y counter + 1
00199888: 0102102a slt r2,r8,r2                     |Check Y Limit
0019988c: 1440ffc8 bne r2,r0,0x001997b0         Λ Loop while not at max Y
00199890: 254a0002 addiu r10,r10,0x0002             |Offset in AI Tile's 0xa74 Table + 0x02 each iteration (Half word)
00199894: 25ad0120 addiu r13,r13,0x0120         |r13 = ? Offset + 0x120 Each iteration
00199898: 25ce0001 addiu r14,r14,0x0001         |Elevation counter + 1
0019989c: 29c20002 slti r2,r14,0x0002           |Check limit
001998a0: 1440ffbd bne r2,r0,0x00199798     Λ Loop 0x2 Times (Elevation 0 and 1)
001998a4: 258c0024 addiu r12,r12,0x0024         |r12 = ? Offset + 0x24 each iteration
001998a8: 8fbf0030 lw r31,0x0030(r29)       END
001998ac: 8fb3002c lw r19,0x002c(r29)
001998b0: 8fb20028 lw r18,0x0028(r29)
001998b4: 8fb10024 lw r17,0x0024(r29)
001998b8: 8fb00020 lw r16,0x0020(r29)
001998bc: 27bd0038 addiu r29,r29,0x0038
001998c0: 03e00008 jr r31
001998c4: 00000000 nop

Return location

BATTLE.BIN
00195e44: 00195d94_-_00195f68