AI Target Unit for Direct vs Arc Attack (0019cd9c)

From Final Fantasy Hacktics Wiki
Revision as of 19:45, 8 June 2024 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
BATTLE.BIN :  - AI_Target_Unit_for_Direct_vs_Arc_Attack_(0019cd9c)
Ability simulation from a given position : handle Targeting and outcome. Test all targetable tiles, compare priority score, keep the best in AI 0x34 Table
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : r2 = 0x00 Default result / No tiles to Target ( Set_Target_Tiles ) / AI 0x19bc = 0x00 (after checking priority)
         r2 = -0x01 if VSync_call returns r2 > 0x1b8
         r2 = -0x01 if Check_Set_Highest_Unit_Priority_(0019d308) returns r2 -0x01
------------------------------------------------------------------------------------------
0019cd9c: 3c02801a lui r2,0x801a             |
0019cda0: 90420d7b lbu r2,0x0d7b(r2)         |AI 0x19b7
0019cda4: 27bdffb8 addiu r29,r29,-0x0048     |
0019cda8: afb10034 sw r17,0x0034(r29)        |
0019cdac: 3c11801a lui r17,0x801a            |
0019cdb0: 2631f3c4 addiu r17,r17,-0x0c3c     |0x8019f3c4
0019cdb4: afbf0044 sw r31,0x0044(r29)        |
0019cdb8: afb40040 sw r20,0x0040(r29)        |
0019cdbc: afb3003c sw r19,0x003c(r29)        |
0019cdc0: afb20038 sw r18,0x0038(r29)        |
0019cdc4: 10400015 beq r2,r0,0x0019ce1c      #If AI 0x19b7 <> 0x00
0019cdc8: afb00030 sw r16,0x0030(r29)            |
0019cdcc: 3c02801a lui r2,0x801a                 |
0019cdd0: 90420036 lbu r2,0x0036(r2)             |AI 0xc72
0019cdd4: 00000000 nop                           |
0019cdd8: 10400010 beq r2,r0,0x0019ce1c          #If AI 0xc72 = 0x00 branch to AI 0x19b7 = 0x00 Section
0019cddc: 00000000 nop                           |
0019cde0: 3c10801a lui r16,0x801a                |
0019cde4: 9610f3ec lhu r16,-0x0c14(r16)          |Considered Action X coordinates AI 0x1c + 0x0c
0019cde8: 3c13801a lui r19,0x801a                |
0019cdec: 9673f3ee lhu r19,-0x0c12(r19)          |Considered Action Elevation AI 0x1c + 0x0e
0019cdf0: 3c12801a lui r18,0x801a                |
0019cdf4: 9652f3f0 lhu r18,-0x0c10(r18)          |Considered Action Y coordinates AI 0x1c + 0x10
0019cdf8: 001310c0 sll r2,r19,0x03               |
0019cdfc: 00531021 addu r2,r2,r19                |
0019ce00: 00021080 sll r2,r2,0x02                |Elevation offset (0x24)
0019ce04: 00511021 addu r2,r2,r17                |
0019ce08: 00121840 sll r3,r18,0x01               |Y offset (halfword)
0019ce0c: 00431021 addu r2,r2,r3                 |
0019ce10: 94540b4c lhu r20,0x0b4c(r2)            |Considered Action Y row flags in AI 0xb4c Table AI 0xb4c + Elevation offset + Y row offset
0019ce14: 0806744f j 0x0019d13c                  >>Jump to  Check priority section Checking only one tile ?
0019ce18: 00000000 nop                           |

=== TARGETING SECTION ===
                                             Else : AI 0x19b7 = 0x00 or AI 0x0c72 = 0x00
0019ce1c: 0c0076ea jal 0x0001dba8                |-->VSync_call
0019ce20: 34040001 ori r4,r0,0x0001              |send 0x01
0019ce24: 284201b9 slti r2,r2,0x01b9             |
0019ce28: 14400003 bne r2,r0,0x0019ce38          #If Vsync call returns a value > 0x1b8
0019ce2c: 2402ffff addiu r2,r0,-0x0001               |
0019ce30: 0806747d j 0x0019d1f4                      |Exit  Return -0x01
0019ce34: a2200c72 sb r0,0x0c72(r17)                 |No units are in range
                                                 Else :  Vsync is Ok do not abort the routine
0019ce38: 92220014 lbu r2,0x0014(r17)                |AI 0x0014 Related to caster position ?
0019ce3c: 00000000 nop                               |
0019ce40: 10400003 beq r2,r0,0x0019ce50              #If AI 0x14 <> 0x00  Caster already is at action location ?
0019ce44: a22019b7 sb r0,0x19b7(r17)                 |Set AI 0x19b7 = 0x00
0019ce48: 08067395 j 0x0019ce54                          >>Avoid opposite section
0019ce4c: 26300e30 addiu r16,r17,0x0e30                  |r16 =  Acting Unit coordinates pointer
                                                     Else : AI 0x14 = 0x00
0019ce50: 26300018 addiu r16,r17,0x0018                  |r16 = AI 0x0018 Coordinates pointer Considered Tile (Destination - Best priority score)
0019ce54: 0c067c96 jal 0x0019f258                    |-->Store units coordinates Send considered coordinates in Acting Unit Battle data (Placement simulation ?)
0019ce58: 02002021 addu r4,r16,r0                    |Send pointer
0019ce5c: 92220004 lbu r2,0x0004(r17)                |Considered Ability Range
0019ce60: 00000000 nop                               |

                  --- Set Targetable Tiles (range > 0x00) ---
0019ce64: 1040000b beq r2,r0,0x0019ce94              #If Ability range <> 0x00
0019ce68: 00002021 addu r4,r0,r0                     |
0019ce6c: 0c05ea30 jal 0x0017a8c0                        |-->Set_Target_Tiles Returns 0x0 or 0x1 if There are tiles to target    -   Enable all targetable tiles around caster (Tile data byte 0x05 flag 0x40)
0019ce70: 2624001c addiu r4,r17,0x001c                   |Send  AI 0x001c
0019ce74: 34030003 ori r3,r0,0x0003                      |
0019ce78: 14430023 bne r2,r3,0x0019cf08                  #If Nb of Targeted Tiles > 0x00 : Branch to  Post-Range section
0019ce7c: 00009821 addu r19,r0,r0                        |
                                                         Else : No Tile to Target (r2 = 0x03)
0019ce80: 0806747d j 0x0019d1f4                              |Exit returns 0x00
0019ce84: 00001021 addu r2,r0,r0                             |

                                                    Weird BACK JUMP (fail section ? Update AI 0xc72 and exit)
0019ce88: a2220c72 sb r2,0x0c72(r17)                     |Update AI 0xc72  ? Control variable for this routine ? 
0019ce8c: 0806747d j 0x0019d1f4                          |Exit returns -0x01
0019ce90: 2402ffff addiu r2,r0,-0x0001                       |

                  --- Set Targetable Tiles (range = 0x00) ---
                                                     Else : Ability Range = 0x00
0019ce94: 3c038019 lui r3,0x8019                         |
0019ce98: 2463f8d1 addiu r3,r3,-0x072f                   |Dynamic pointer to Tile data 0x05 8018f8cc + 0x05
                                                        @LOOP - All tiles (remove targeting flag)
0019ce9c: 90620000 lbu r2,0x0000(r3)                         |This iteration Tile 0x05
0019cea0: 24840001 addiu r4,r4,0x0001                        |Tile counter +1
0019cea4: 304200bf andi r2,r2,0x00bf                         |Remove flag 0x40 (targeted flag)
0019cea8: a0620000 sb r2,0x0000(r3)                          |Remove Targeting from Tile
0019ceac: 28820200 slti r2,r4,0x0200                         |
0019ceb0: 1440fffa bne r2,r0,0x0019ce9c                  Λ Loop 0x200 times
0019ceb4: 24630008 addiu r3,r3,0x0008                        |Tile data offset
0019ceb8: 92030002 lbu r3,0x0002(r16)                    |Caster Y coordinates
0019cebc: 92220e3a lbu r2,0x0e3a(r17)                    |Map max X
0019cec0: 00000000 nop                                   |
0019cec4: 00620018 mult r3,r2                            |
0019cec8: 92020001 lbu r2,0x0001(r16)                    |Caster elevation
0019cecc: 92040000 lbu r4,0x0000(r16)                    |Caster X coordinates
0019ced0: 00021200 sll r2,r2,0x08                        |Elevation offset
0019ced4: 00001812 mflo r3                               |
0019ced8: 00641821 addu r3,r3,r4                         |
0019cedc: 00621821 addu r3,r3,r2                         |Unit Tile ID  X + YMax X + Elvation offset
0019cee0: 000318c0 sll r3,r3,0x03                        |
0019cee4: 3c018019 lui r1,0x8019                         |
0019cee8: 00230821 addu r1,r1,r3                         |
0019ceec: 9022f8d1 lbu r2,-0x072f(r1)                    |Unit Tile data 0x05 0x8018f8cc + 0x05 + Tile offset
0019cef0: 00000000 nop                                   |
0019cef4: 34420040 ori r2,r2,0x0040                      |
0019cef8: 3c018019 lui r1,0x8019                         |
0019cefc: 00230821 addu r1,r1,r3                         |
0019cf00: a022f8d1 sb r2,-0x072f(r1)                     |Enable Targeted flag on Unit Tile 0x8018f8cc + 0x05 + Tile offset
0019cf04: 00009821 addu r19,r0,r0                        |Force r19 to 0x00

=== POST TARGETING SECTION - Enable Tile's flags in AI 0xb4c if Tile is ON in AI 0xbdc and Targetable (Tile 0x05 flag 0x40 is ON) ===
0019cf08: 02204021 addu r8,r17,r0                |Prepare Dynamic AI pointer (+0x24 for high elevation)
                                                @LOOP - Both elevation
0019cf0c: 92220e3b lbu r2,0x0e3b(r17)                |Map Max Y
0019cf10: 00000000 nop                               |
0019cf14: 1840002e blez r2,0x0019cfd0                #If max Y is invalid : branch to 
0019cf18: 00009021 addu r18,r0,r0                    |intialize Y counter
0019cf1c: 00134a00 sll r9,r19,0x08                   |Elevation offset for tile data
0019cf20: 25050b4c addiu r5,r8,0x0b4c                |Dynamic pointer to AI 0xb4c (+Elevation offset)
0019cf24: 25060bdc addiu r6,r8,0x0bdc                |Dynamic pointer to AI 0xbdc (+Elevation offset) Tiles you can target to hit a unit
                                                    @LOOP - All Y rows
0019cf28: 94d40000 lhu r20,0x0000(r6)                    |This Y row flags in AI 0xbdc Tiles from where you can hit a target
0019cf2c: 00000000 nop                                   |
0019cf30: 3282ffff andi r2,r20,0xffff                    |
0019cf34: 10400020 beq r2,r0,0x0019cfb8                  #If there is no flags in this row  (AI 0xbdc): branch to  Next Y row AI 0xbdc is Targetable tiles Table
0019cf38: a4a00000 sh r0,0x0000(r5)                      |Initialize this row flag in AI 0x0b4c
0019cf3c: 92230e3a lbu r3,0x0e3a(r17)                    |Max X
0019cf40: 00000000 nop                                   |
0019cf44: 1060001c beq r3,r0,0x0019cfb8                  #If Map max X is invalid : branch to  Next Y row
0019cf48: 00008021 addu r16,r0,r0                        |Initialize X counter
0019cf4c: 00403821 addu r7,r2,r0                         |Row of flag (AI 0xbdc)
0019cf50: 00a02021 addu r4,r5,r0                         |Dynamic pointer to AI 0xb4c (+Y row and Elevation offset)
0019cf54: 02071004 sllv r2,r7,r16                        |Shift by X counter (Tiles of interest flag is in 0x8000 position)
                                                        @LOOP All Tiles in Row
0019cf58: 30428000 andi r2,r2,0x8000                         |Bitmask
0019cf5c: 10400011 beq r2,r0,0x0019cfa4                      #If This tile flag is disabled (AI 0xbdc) : branch to  Next Tile
0019cf60: 02430018 mult r18,r3                               |
0019cf64: 00001012 mflo r2                                   |Y counter * Max X
0019cf68: 00501021 addu r2,r2,r16                            |+ X 
0019cf6c: 00491021 addu r2,r2,r9                             |+ Elevation offset
0019cf70: 000210c0 sll r2,r2,0x03                            |
0019cf74: 3c018019 lui r1,0x8019                             |
0019cf78: 00220821 addu r1,r1,r2                             |
0019cf7c: 9022f8d1 lbu r2,-0x072f(r1)                        |This Tile data 0x05 0x8018f8cc + 0x05 + Tile offset
0019cf80: 00000000 nop                                       |
0019cf84: 00021182 srl r2,r2,0x06                            |Shift Byte (0x40 becomes 0x1)
0019cf88: 30420001 andi r2,r2,0x0001                         |
0019cf8c: 10400005 beq r2,r0,0x0019cfa4                      #If This Tile is not in Targeted AoE : branch to  Next Tile

0019cf90: 34028000 ori r2,r0,0x8000                          |
0019cf94: 94830000 lhu r3,0x0000(r4)                         |This Y row flags in AI 0x0b4c
0019cf98: 02021007 srav r2,r2,r16                            |Bitmask for this iteration Tile
0019cf9c: 00621825 or r3,r3,r2                               |
0019cfa0: a4830000 sh r3,0x0000(r4)                          |Enable this Tile in AI 0x0b4c If this tile is in AI 0xbdc and is in Targeted AoE

0019cfa4: 92230e3a lbu r3,0x0e3a(r17)                        |Max X
0019cfa8: 26100001 addiu r16,r16,0x0001                      |X counter +1
0019cfac: 0203102a slt r2,r16,r3                             |
0019cfb0: 1440ffe9 bne r2,r0,0x0019cf58                  Λ Loop while X < Max X
0019cfb4: 02071004 sllv r2,r7,r16                            |Shift Row's Flag by X counter (bit of interest is 0x8000)
0019cfb8: 24a50002 addiu r5,r5,0x0002                    |Y offset (halfword) for AI 0xb4c
0019cfbc: 92220e3b lbu r2,0x0e3b(r17)                    |Max Y
0019cfc0: 26520001 addiu r18,r18,0x0001                  |Y counter +1
0019cfc4: 0242102a slt r2,r18,r2                         |
0019cfc8: 1440ffd7 bne r2,r0,0x0019cf28              Λ Loop while Y < Max Y
0019cfcc: 24c60002 addiu r6,r6,0x0002                    |Y offset (halfword) for AI 0xbdc
0019cfd0: 26730001 addiu r19,r19,0x0001              |Elevation counter + 1
0019cfd4: 2a620002 slti r2,r19,0x0002                |
0019cfd8: 1440ffcc bne r2,r0,0x0019cf0c          Λ Loop 2 times
0019cfdc: 25080024 addiu r8,r8,0x0024                |AI data elevation offset
0019cfe0: 00009821 addu r19,r0,r0                    |

=== TEST ALL TARGETABLE TILES (in AI 0xb4c) ===
                                                @LOOP - Both elevation
0019cfe4: 92220e3b lbu r2,0x0e3b(r17)                |Max Y
0019cfe8: 00000000 nop                               |
0019cfec: 1840007d blez r2,0x0019d1e4                #If Map Max Y is invalid : branch to  Next elevation
0019cff0: 00009021 addu r18,r0,r0                    |Initialize Y counter
0019cff4: 001310c0 sll r2,r19,0x03                   |
                                                    @LOOP - All Y rows
0019cff8: 00531021 addu r2,r2,r19                        |
0019cffc: 00021080 sll r2,r2,0x02                        |
0019d000: 00511021 addu r2,r2,r17                        |
0019d004: 00121840 sll r3,r18,0x01                       |
0019d008: 00431021 addu r2,r2,r3                         |
0019d00c: 94540b4c lhu r20,0x0b4c(r2)                    |This Y row flags in AI 0x0b4c 0x8019f3c4 + 0xb4c + Elevation offset (0x24) + Y offset (halfword) Targetable and targeted
0019d010: 00000000 nop                                   |
0019d014: 1280006e beq r20,r0,0x0019d1d0                 #If There is no flags in this row : branch to  Next Y row  in AI 0xb4c
0019d018: 00000000 nop                                   |
0019d01c: 92220e3a lbu r2,0x0e3a(r17)                    |Max X
0019d020: 00000000 nop                                   |
0019d024: 1840006a blez r2,0x0019d1d0                    #If Map Max X is invalid : Branch to  Next Y row
0019d028: 00008021 addu r16,r0,r0                        |Initialize X counter
0019d02c: 02141004 sllv r2,r20,r16                       |Shift Y row of flags by X counter (Tile of interest flag is in 0x8000 position)
                                                        @LOOP - All tiles in Y row
0019d030: 30428000 andi r2,r2,0x8000                         |
0019d034: 10400061 beq r2,r0,0x0019d1bc                      #If This iteration Tile's flag is OFF : branch to  Next Tile  in AI 0xb4c
0019d038: 34020006 ori r2,r0,0x0006                          |
0019d03c: 92230026 lbu r3,0x0026(r17)                        |Load AI 0x0026 (Targeting type)
0019d040: a6300028 sh r16,0x0028(r17)                        |Store X counter at AI 0x0028
0019d044: a632002c sh r18,0x002c(r17)                        |Store Y counter at AI 0x002c

                  --- More Targeting checks (unit, obstacles) ---
0019d048: 10620006 beq r3,r2,0x0019d064                      #If Targeting is not Unit specific (<> 0x06)
0019d04c: a633002a sh r19,0x002a(r17)                        |Store Elevation counter at AI 0x002a
0019d050: 8e23000c lw r3,0x000c(r17)                             |Considered Ability AI Behavior 1 to 4
0019d054: 3c0200c0 lui r2,0x00c0                                 |
0019d058: 00621824 and r3,r3,r2                                  |
0019d05c: 10600008 beq r3,r0,0x0019d080                          #If Considered Ability do NOT have [Longbow Attack] or [Stop at obstacle] Avoid routine below Do not seek a Unit on considered panel
0019d060: 00000000 nop                                           |
                                                             Else : Targeting is Unit Specific or  [Longbow Attack] or [Stop at obstacle]
0019d064: 0c067486 jal 0x0019d218                                |-->See_if_any_units_are_on_target_panel returns Unit ID (or 0x15)
0019d068: 00000000 nop                                           |
0019d06c: a2220027 sb r2,0x0027(r17)                             |Store Unit ID at AI 0x27
0019d070: 304200ff andi r2,r2,0x00ff                             |
0019d074: 34030015 ori r3,r0,0x0015                              |
0019d078: 10430039 beq r2,r3,0x0019d160                          #If No Unit found on Considered Tile Post priority section
0019d07c: 00000000 nop                                           |
0019d080: 8e23000c lw r3,0x000c(r17)                         |Considered Ability AI Behavior 1 to 4
0019d084: 3c020080 lui r2,0x0080                             |
0019d088: 00621024 and r2,r3,r2                              |
0019d08c: 10400007 beq r2,r0,0x0019d0ac                      #If considered Ability has [Longbow attack]
0019d090: 3c020040 lui r2,0x0040                                 |
0019d094: 92240e2e lbu r4,0x0e2e(r17)                            |Acting Unit ID
0019d098: 92250027 lbu r5,0x0027(r17)                            |Target ID
0019d09c: 0c06bf64 jal 0x001afd90                                |-->001afd90_-_001aff14 Trajectory ? 
0019d0a0: 00000000 nop                                           |
0019d0a4: 08067445 j 0x0019d114                                  >>jump and  check result (obstacle ?)
0019d0a8: 00000000 nop                                           |
                                                             Else : not longbow attack
0019d0ac: 00621024 and r2,r3,r2                              |
0019d0b0: 1040001a beq r2,r0,0x0019d11c                      #If Considered Ability has [Stop at obstacle]
0019d0b4: 00000000 nop                                           |
0019d0b8: 92220000 lbu r2,0x0000(r17)                            |Considered Ability's skillset
0019d0bc: 3c018006 lui r1,0x8006                                 |
0019d0c0: 00220821 addu r1,r1,r2                                 |
0019d0c4: 90235cb4 lbu r3,0x5cb4(r1)                             |Considered skillset's action menu
0019d0c8: 34020001 ori r2,r0,0x0001                              |
0019d0cc: 1462000d bne r3,r2,0x0019d104                          #If Considered Action menu is [Item inventory]
0019d0d0: 00000000 nop                                               |
0019d0d4: 92220027 lbu r2,0x0027(r17)                                |Target ID
0019d0d8: 8e2417f8 lw r4,0x17f8(r17)                                 |Send
0019d0dc: 000228c0 sll r5,r2,0x03                                    |
0019d0e0: 00a22823 subu r5,r5,r2                                     |
0019d0e4: 00052980 sll r5,r5,0x06                                    |
0019d0e8: 3c028019 lui r2,0x8019                                     |
0019d0ec: 244208cc addiu r2,r2,0x08cc                                |
0019d0f0: 0c0664db jal 0x0019936c                                    |-->Calculate_Distance_Between_Units
0019d0f4: 00a22821 addu r5,r5,r2                                     |Send Targeted Unit data pointer
0019d0f8: 28420002 slti r2,r2,0x0002                                 |
0019d0fc: 14400007 bne r2,r0,0x0019d11c                              #If Item inventory with point blank target or self targeting Do not seek obstacles
0019d100: 00000000 nop                                               |
                                                                 Else : Ability has [Stop at Obstacle] or Item is throwed
0019d104: 92240e2e lbu r4,0x0e2e(r17)                                |Caster ID
0019d108: 92250027 lbu r5,0x0027(r17)                                |Target ID
0019d10c: 0c06c1b4 jal 0x001b06d0                                    |-->001b06d0_-_001b0814 Obstacle related
0019d110: 00000000 nop                                               |
                                                            Check if Obstacle (longbow or direct)
0019d114: 10400029 beq r2,r0,0x0019d1bc                      #If r2 = 0x00 (Obstacle ?) branch to  Next Tile
0019d118: 00000000 nop                                       |

                   --- (AI 0x0cb4) POST TARGETING / OBSTACLE ---
0019d11c: 8e230cb4 lw r3,0x0cb4(r17)                         |Load AI 0x0cb4 AI processing ?
0019d120: 3c020200 lui r2,0x0200                             |
0019d124: 00621824 and r3,r3,r2                              |
0019d128: 10600003 beq r3,r0,0x0019d138                      #If AI 0xcb4 flag 0x02000000 is ON
0019d12c: 34020001 ori r2,r0,0x0001                              |
0019d130: 0806744f j 0x0019d13c                                  >>Avoid opposite case
0019d134: a2220e4e sb r2,0x0e4e(r17)                             |Set AI 0xe4e to 0x01
                                                             Else : AI 0xcb4 flag 0x02000000 is OFF
0019d138: a2200e4e sb r0,0x0e4e(r17)                             |Set AI 0xe4e to 0x00

                   --- CHECK ABILITY RESULT (store best outcome in AI 0x34) ---
0019d13c: 0c0674c2 jal 0x0019d308                            |-->Check_Set_Highest_Unit_Priority_(0019d308)  Simulate Considered Ability from considered Position Targeting considered Tile and store it in AI 0x34 if better
0019d140: 00000000 nop                                       |
0019d144: 2403ffff addiu r3,r0,-0x0001                       |
0019d148: 1043ff4f beq r2,r3,0x0019ce88                      #If Returned value is -0x01 Store 0x01 in AI 0xc72 and exit  0x19d37c didn't update priority ?
0019d14c: 34020001 ori r2,r0,0x0001                          |
                                                             Else : returned value <> -0x01
0019d150: 922219bc lbu r2,0x19bc(r17)                            |AI 0x19bc
0019d154: 00000000 nop                                           |
0019d158: 10400026 beq r2,r0,0x0019d1f4                          #if AI 0x19bc = 0x00  Exit returns 0x00
0019d15c: 00001021 addu r2,r0,r0                                 |

                  --- (AI 0x0e4e) POST-PRIORITY Section
0019d160: 92220e4e lbu r2,0x0e4e(r17)                        |AI 0xe4e
0019d164: 00000000 nop                                       |
0019d168: 10400014 beq r2,r0,0x0019d1bc                      #If AI 0xe4e = 0x00 (not fine for caster ?) branch to  Next tile
0019d16c: 001310c0 sll r2,r19,0x03                           |
                                                             Else : Ok for caster ?
0019d170: 00531021 addu r2,r2,r19                                |
0019d174: 00021080 sll r2,r2,0x02                                |Elevation offset (0x24)
0019d178: 00511021 addu r2,r2,r17                                |
0019d17c: 24420bdc addiu r2,r2,0x0bdc                            |
0019d180: 00122040 sll r4,r18,0x01                               |Y row offset (halfword)
0019d184: 00822021 addu r4,r4,r2                                 |0x8019f3c4 + 0xbdc + this row offset
0019d188: 34028000 ori r2,r0,0x8000                              |
0019d18c: 94830000 lhu r3,0x0000(r4)                             |This Y row flags in AI 0xbdc
0019d190: 02021007 srav r2,r2,r16                                |Bitmask for this iteration Tile
0019d194: 00621826 xor r3,r3,r2                                  |
0019d198: a4830000 sh r3,0x0000(r4)                              |Delete this Tile flag in AI 0xbdc
0019d19c: 92220cbb lbu r2,0x0cbb(r17)                            |Nb of Tiles in AI 0xbdc
0019d1a0: 00000000 nop                                           |
0019d1a4: 2442ffff addiu r2,r2,-0x0001                           |
0019d1a8: a2220cbb sb r2,0x0cbb(r17)                             |Decrease Tile's counter in 0xbdc
0019d1ac: 92220cbb lbu r2,0x0cbb(r17)                            |Tile counter
0019d1b0: 00000000 nop                                           |
0019d1b4: 10400006 beq r2,r0,0x0019d1d0                          #If there is no tiles left in AI 0xbdc : branch to  Next Y row
0019d1b8: 00000000 nop                                           |
0019d1bc: 92220e3a lbu r2,0x0e3a(r17)                        |Map Max X
0019d1c0: 26100001 addiu r16,r16,0x0001                      |X counter + 1
0019d1c4: 0202102a slt r2,r16,r2                             |
0019d1c8: 1440ff99 bne r2,r0,0x0019d030                  Λ Loop while X < Max X
0019d1cc: 02141004 sllv r2,r20,r16                       |
0019d1d0: 92220e3b lbu r2,0x0e3b(r17)                    |Max Y
0019d1d4: 26520001 addiu r18,r18,0x0001                  |Y counter + 1
0019d1d8: 0242102a slt r2,r18,r2                         |
0019d1dc: 1440ff86 bne r2,r0,0x0019cff8              Λ Loop while Y < Max Y
0019d1e0: 001310c0 sll r2,r19,0x03                       |Prepare elevation offset
0019d1e4: 26730001 addiu r19,r19,0x0001              |Elevation + 1
0019d1e8: 2a620002 slti r2,r19,0x0002                |
0019d1ec: 1440ff7d bne r2,r0,0x0019cfe4          Λ Loop 2 times
0019d1f0: 00001021 addu r2,r0,r0                 |Return 0x00
0019d1f4: 8fbf0044 lw r31,0x0044(r29)
0019d1f8: 8fb40040 lw r20,0x0040(r29)
0019d1fc: 8fb3003c lw r19,0x003c(r29)
0019d200: 8fb20038 lw r18,0x0038(r29)
0019d204: 8fb10034 lw r17,0x0034(r29)
0019d208: 8fb00030 lw r16,0x0030(r29)
0019d20c: 27bd0048 addiu r29,r29,0x0048
0019d210: 03e00008 jr r31
0019d214: 00000000 nop

Return locations

BATTLE.BIN
 0019b480: Check_if_any_units_are_in_range_(0019b30c)
 0019ba5c: AI_Targeting_Matrix_Analysis_(0019b7b8)
 0019c0c4: Find_Highest_Target_Priority_in_Ability_Range_(0019bf2c)
 0019c16c: Find_Highest_Target_Priority_in_Ability_Range_(0019bf2c)