Difference between revisions of "Targeting routine"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  Targeting routine:
+
  '''0017b874 - 0017bc74'''    [[#Notes|Notes]]
  0017b874: 27bdffb8 addiu r29,r29,0xffb8
+
  0017b878: 27a50010 addiu r5,r29,0x0010
+
  '''Parameters''' : r4 = Pointer to Attacker 0x16e to 0x181 data
  0017b87c: afbf0040 sw r31,0x0040(r29)
+
   
  0017b880: afb5003c sw r21,0x003c(r29)
+
  '''Returns''' : r2 = number of Tiles with "green panel" flag
  0017b884: afb40038 sw r20,0x0038(r29)
+
          r2 = -0x01 (invalid coordinates, unselectable tile)
  0017b888: afb30034 sw r19,0x0034(r29)
+
   
  0017b88c: afb20030 sw r18,0x0030(r29)
+
  This routine will set the "green panel" flag (Tile byte 0x05 - flag 0x80) on tile targeted by ability
  0017b890: afb1002c sw r17,0x002c(r29)
+
It will use the Targetable panel grid ( 0x80192dd8 ), using AoE (byte 0x00) and Targeted flag (byte 0x01) [[#Notes|See notes]]
  0017b894: 0c01788b jal 0x0005e22c
+
------------------------------------------------------------------------------------------------------
0017b898: afb00028 sw r16,0x0028(r29)
+
   
  0017b89c: 3c058019 lui r5,0x8019
+
0017b874: 27bdffb8 addiu r29,r29,-0x0048   
  0017b8a0: 24a508cc addiu r5,r5,0x08cc
+
  0017b878: 27a50010 addiu r5,r29,0x0010          |{{f/std|<nowiki>r5 = Stack 0x10</nowiki>}}
  0017b8a4: 87a20012 lh r2,0x0012(r29)
+
  0017b87c: afbf0040 sw r31,0x0040(r29)           |
  0017b8a8: 93b40010 lbu r20,0x0010(r29)
+
  0017b880: afb5003c sw r21,0x003c(r29)           |
  0017b8ac: 000218c0 sll r3,r2,0x03
+
  0017b884: afb40038 sw r20,0x0038(r29)            |
  0017b8b0: 00621823 subu r3,r3,r2
+
  0017b888: afb30034 sw r19,0x0034(r29)            |
  0017b8b4: 00031840 sll r3,r3,0x01
+
  0017b88c: afb20030 sw r18,0x0030(r29)           |
0017b8b8: 3c028006 lui r2,0x8006
+
  0017b890: afb1002c sw r17,0x002c(r29)           |
  0017b8bc: 2442fbf0 addiu r2,r2,0xfbf0
+
  0017b894: 0c01788b jal 0x0005e22c                |{{f/jal|Copy_Byte_Data_(20_Bytes)|<nowiki>Copy_Byte_Data_(20_Bytes)</nowiki>}} Copy Attacker 0x16e to 0x181 on Stack r29 0x10 to 0x23
  0017b8c0: 00621821 addu r3,r3,r2
+
  0017b898: afb00028 sw r16,0x0028(r29)            |
  0017b8c4: 001410c0 sll r2,r20,0x03
+
  0017b89c: 3c058019 lui r5,0x8019                |{{f/std|<nowiki>r5 = 0x80190000</nowiki>}}
  0017b8c8: 00541023 subu r2,r2,r20
+
  0017b8a0: 24a508cc addiu r5,r5,0x08cc            |{{f/std|<nowiki>r5 = Start of unit data</nowiki>}}
  0017b8cc: 00021180 sll r2,r2,0x06
+
  0017b8a4: 87a20012 lh r2,0x0012(r29)            |{{f/load|<nowiki>r2 = Attacker's used ability ID</nowiki>}}
  0017b8d0: 90690003 lbu r9,0x0003(r3) ability flags 1
+
  0017b8a8: 93b40010 lbu r20,0x0010(r29)          |{{f/load|<nowiki>r20 = Attacker ID</nowiki>}}
  0017b8d4: 90710004 lbu r17,0x0004(r3) ability flags 2
+
  0017b8ac: 000218c0 sll r3,r2,0x03                |{{f/std|<nowiki>r3 = Attacker's used ability ID * 8</nowiki>}}
  0017b8d8: 90640006 lbu r4,0x0006(r3) ability flags 4
+
  0017b8b0: 00621823 subu r3,r3,r2                |{{f/std|<nowiki>r3 = Attacker's used ability ID * 7</nowiki>}}
  0017b8dc: 90730001 lbu r19,0x0001(r3) load aoe
+
  0017b8b4: 00031840 sll r3,r3,0x01                |{{f/std|<nowiki>r3 = Attacker's used ability ID * 14</nowiki>}}
0017b8e0: 90750002 lbu r21,0x0002(r3) load verticle
+
  0017b8b8: 3c028006 lui r2,0x8006                |{{f/std|<nowiki>r2 = 0x80060000</nowiki>}}
  0017b8e4: 30840020 andi r4,r4,0x0020
+
  0017b8bc: 2442fbf0 addiu r2,r2,-0x0410          |{{f/std|<nowiki>r2 = 0x8005fbf0 (start of ability data 2)</nowiki>}}
  0017b8e8: 10800003 beq r4,r0,0x0017b8f8 branch  if not direct attack
+
  0017b8c0: 00621821 addu r3,r3,r2                |{{f/adr|<nowiki>r3 = Start of Attacker'd used ability data 2</nowiki>}}
  0017b8ec: 00458021 addu r16,r2,r5 r16 = unit data pointer
+
  0017b8c4: 001410c0 sll r2,r20,0x03              |{{f/std|<nowiki>r2 = Attacker's ID * 8</nowiki>}}
  0017b8f0: 35290020 ori r9,r9,0x0020 r9 = 2 0
+
  0017b8c8: 00541023 subu r2,r2,r20                |{{f/std|<nowiki>r2 = Attacker's ID * 7</nowiki>}}
  0017b8f4: 32310039 andi r17,r17,0x0039 set if all flags under cannot hit  allies=true
+
  0017b8cc: 00021180 sll r2,r2,0x06                |{{f/std|<nowiki>r2 = Attacker's ID * 448 (448 = unot data size)</nowiki>}}
  0017b8f8: 32220006 andi r2,r17,0x0006 set if linear 3 direction
+
  0017b8d0: 90690003 lbu r9,0x0003(r3)            |{{f/load|<nowiki>r9 = Attacker used Ability flag 1</nowiki>}}
  0017b8fc: 10400006 beq r2,r0,0x0017b918 else branch
+
  0017b8d4: 90710004 lbu r17,0x0004(r3)            |{{f/load|<nowiki>r17 = Attacker used Ability flags 2</nowiki>}}
  0017b900: 34020006 ori r2,r0,0x0006 r2= 06
+
  0017b8d8: 90640006 lbu r4,0x0006(r3)            |{{f/load|<nowiki>r4 = Attacker used Ability flags 4</nowiki>}}
  0017b904: 92050047 lbu r5,0x0047(r16) load x coordinate
+
  0017b8dc: 90730001 lbu r19,0x0001(r3)            |{{f/load|<nowiki>r19 = Attacker used Ability AoE (Effect area in patcher)</nowiki>}}
  0017b908: 96020048 lhu r2,0x0048(r16) load y coordinate
+
  0017b8e0: 90750002 lbu r21,0x0002(r3)           |{{f/load|<nowiki>r21 = Attacker used Ability vertical</nowiki>}}
  0017b90c: 92040048 lbu r4,0x0048(r16) load y coordinate
+
  0017b8e4: 30840020 andi r4,r4,0x0020            |{{f/std|<nowiki>r4 = 0x20 if Attacker used Ability stop at obstacle is checked</nowiki>}}
  0017b910: 0805ee59 j 0x0017b964 skip following routine
+
  0017b8e8: 10800003 beq r4,r0,0x0017b8f8          {{f/Cond|<nowiki>If Attacker used Ability stops at obstacle </nowiki>}} / Else avoid flags manipulation
0017b914: 00021bc2 srl r3,r2,0x0f r2= y coordinate/2^0f?
+
  0017b8ec: 00458021 addu r16,r2,r5                |{{f/adr|<nowiki>r16 = Attacker Unit Data Pointer</nowiki>}}
  0017b918: 93a3001a lbu r3,0x001a(r29) load target Y coordinate?
+
  0017b8f0: 35290020 ori r9,r9,0x0020                  |{{f/std|<nowiki>r9 = Attacker used Ability flag 1 with Weapon range forced ON</nowiki>}}
  0017b91c: 00000000 nop
+
  0017b8f4: 32310039 andi r17,r17,0x0039              |{{f/std|<nowiki>r17 = Attacker used Ability flags 2 with Hit caster, 3 direction, Linear AoE and follow target forced OFF</nowiki>}}
0017b920: 10620006 beq r3,r2,0x0017b93c branch if target y = caster y
+
  0017b8f8: 32220006 andi r2,r17,0x0006            |{{f/std|<nowiki>r2 <> 0x00 if Attacker used Ability Is a linear attack or 3 directions attack</nowiki>}}
  0017b924: 00000000 nop
+
  0017b8fc: 10400006 beq r2,r0,0x0017b918          {{f/Cond|<nowiki>If Attacker used Ability is linear and/or 3 directions</nowiki>}}
  0017b928: 93a5001c lbu r5,0x001c(r29) load target x
+
  0017b900: 34020006 ori r2,r0,0x0006              |{{f/std|<nowiki>r2 = 0x06</nowiki>}}
  0017b92c: 93a40020 lbu r4,0x0020(r29) load target y
+
  0017b904: 92050047 lbu r5,0x0047(r16)               |{{f/load|<nowiki>r5 = Attacker X coordinate</nowiki>}}
  0017b930: 93a3001e lbu r3,0x001e(r29) load ?
+
  0017b908: 96020048 lhu r2,0x0048(r16)               |{{f/load|<nowiki>r2 = Attacker Y & Elevation/facing</nowiki>}}
  0017b934: 0805ee59 j 0x0017b964
+
  0017b90c: 92040048 lbu r4,0x0048(r16)                |{{f/load|<nowiki>r4 = Attacker Y coordinate</nowiki>}}
0017b938: 00000000 nop
+
  0017b910: 0805ee59 j 0x0017b964                      {{f/jump|<nowiki>jump to Coordinates validation section</nowiki>}} {{f/std|<nowiki>keeping Attacker coordinate as Targeted coordinates</nowiki>}}
0017b93c: 93a2001b lbu r2,0x001b(r29) load ?
+
  0017b914: 00021bc2 srl r3,r2,0x0f                    |{{f/std|<nowiki>r3 = 0x01 if Higher elevation was checked (0x80) else 0x00</nowiki>}}
  0017b940: 00000000 nop
+
  0017b918: 93a3001a lbu r3,0x001a(r29)            {{f/Cond|<nowiki>Else (not linear/3Di)</nowiki>}} {{f/load|<nowiki>r3 = Attacker 0x178</nowiki>}}
0017b944: 000218c0 sll r3,r2,0x03
+
  0017b91c: 00000000 nop                              |{{f/std|<nowiki> </nowiki>}}
  0017b948: 00621823 subu r3,r3,r2
+
  0017b920: 10620006 beq r3,r2,0x0017b93c              {{f/Cond|<nowiki>If Attacker used Ability is not  a Target specific ability</nowiki>}} {{f/std|<nowiki>(player ?)</nowiki>}}
  0017b94c: 00031980 sll r3,r3,0x06
+
  0017b924: 00000000 nop                                  |{{f/std|<nowiki> </nowiki>}}
0017b950: 00651821 addu r3,r3,r5
+
  0017b928: 93a5001c lbu r5,0x001c(r29)                   |{{f/load|<nowiki>r5 = Targeted tile X coord</nowiki>}}
  0017b954: 90650047 lbu r5,0x0047(r3) load caster x
+
  0017b92c: 93a40020 lbu r4,0x0020(r29)                    |{{f/load|<nowiki>r4 = Targeted tile Y coord</nowiki>}}
  0017b958: 94620048 lhu r2,0x0048(r3) load caster y
+
  0017b930: 93a3001e lbu r3,0x001e(r29)                    |{{f/load|<nowiki>r3 = Targeted tile Elevation</nowiki>}}
  0017b95c: 90640048 lbu r4,0x0048(r3) load caster y
+
0017b934: 0805ee59 j 0x0017b964                          {{f/jump|<nowiki>jump to Coordinates control</nowiki>}}
0017b960: 00021bc2 srl r3,r2,0x0f caster y/2^0f?
+
  0017b938: 00000000 nop                                  |{{f/std|<nowiki> </nowiki>}}
  0017b964: 3c06800e lui r6,0x800e
+
  0017b93c: 93a2001b lbu r2,0x001b(r29)                {{f/Cond|<nowiki> Else (Attacker used Ability is Target specific)</nowiki>}} {{f/load|<nowiki>r2 = Target ID</nowiki>}} {{f/std|<nowiki>(AI ?)</nowiki>}}
  0017b968: 90c64e9c lbu r6,0x4e9c(r6) map max x
+
  0017b940: 00000000 nop                                   |{{f/std|<nowiki>    </nowiki>}} {{f/std|<nowiki> </nowiki>}}
0017b96c: 00000000 nop
+
  0017b944: 000218c0 sll r3,r2,0x03                        |{{f/std|<nowiki>r3 = Target ID * 8</nowiki>}}
  0017b970: 00a6102a slt r2,r5,r6 set if caster x < max x??
+
  0017b948: 00621823 subu r3,r3,r2                        |{{f/std|<nowiki>r3 = Target ID * 7</nowiki>}}
  0017b974: 104000b6 beq r2,r0,0x0017bc50 skip to end if not
+
  0017b94c: 00031980 sll r3,r3,0x06                        |{{f/std|<nowiki>r3 = Target ID * 448</nowiki>}}
  0017b978: 2402ffff addiu r2,r0,0xffff
+
  0017b950: 00651821 addu r3,r3,r5                        |{{f/adr|<nowiki>r5 = Target data pointer</nowiki>}}
  0017b97c: 3c02800e lui r2,0x800e
+
  0017b954: 90650047 lbu r5,0x0047(r3)                    |{{f/load|<nowiki>r5 = Target X</nowiki>}}
0017b980: 90424ea0 lbu r2,0x4ea0(r2) load max y?
+
  0017b958: 94620048 lhu r2,0x0048(r3)                    |{{f/load|<nowiki>r2 = TargetY & Elevation/facing</nowiki>}}
  0017b984: 00000000 nop
+
  0017b95c: 90640048 lbu r4,0x0048(r3)                    |{{f/load|<nowiki>r4 = Target Y</nowiki>}}
  0017b988: 0082102a slt r2,r4,r2 set if caster y < max y??
+
  0017b960: 00021bc2 srl r3,r2,0x0f                        |{{f/std|<nowiki>r3 = 0x01 if Higher elevation was checked (0x80) else 0x00</nowiki>}}
  0017b98c: 10400010 beq r2,r0,0x0017b9d0 skip to end if not
+
  0017b964: 3c06800e lui r6,0x800e                |{{f/std|<nowiki>r6 = 0x800e0000</nowiki>}}
  0017b990: 28620002 slti r2,r3,0x0002 set if caster y/2^0f < 02
+
  0017b968: 90c64e9c lbu r6,0x4e9c(r6)            |{{f/load|<nowiki>r6 = Map Max X</nowiki>}}
  0017b994: 1040000e beq r2,r0,0x0017b9d0 skip to end if not?
+
  0017b96c: 00000000 nop                          |
  0017b998: 00860018 mult r4,r6
+
  0017b970: 00a6102a slt r2,r5,r6                  |{{f/std|<nowiki>r2 = 0x01 if Target X < Max X</nowiki>}}
  0017b99c: 00031200 sll r2,r3,0x08
+
  0017b974: 104000b6 beq r2,r0,0x0017bc50          {{f/Cond|<nowiki>If Target X is valid</nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (r2 = -0x01)
  0017b9a0: 00001812 mflo r3
+
  0017b978: 2402ffff addiu r2,r0,-0x0001           |{{f/std|<nowiki>r2 = -0x01</nowiki>}}
  0017b9a4: 00431021 addu r2,r2,r3
+
  0017b97c: 3c02800e lui r2,0x800e                    |{{f/std|<nowiki>r2 = 0x800e</nowiki>}}
  0017b9a8: 00453021 addu r6,r2,r5
+
0017b980: 90424ea0 lbu r2,0x4ea0(r2)                |{{f/load|<nowiki>r2 = Map Max Y</nowiki>}}
  0017b9ac: 000618c0 sll r3,r6,0x03
+
  0017b984: 00000000 nop                               |
  0017b9b0: 3c028019 lui r2,0x8019
+
  0017b988: 0082102a slt r2,r4,r2                      |{{f/std|<nowiki>r2 = 0x01 if Target Y < Max Y</nowiki>}}
  0017b9b4: 2442f8cc addiu r2,r2,0xf8cc load tile data start
+
  0017b98c: 10400010 beq r2,r0,0x0017b9d0              {{f/Cond|<nowiki>If Target Y is valid </nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (via a jump setting r2 to -0x01)
0017b9b8: 00622821 addu r5,r3,r2
+
  0017b990: 28620002 slti r2,r3,0x0002                    |{{f/std|<nowiki>r2 = 0x01 if Elevation < 0x02</nowiki>}}
  0017b9bc: 90a20006 lbu r2,0x0006(r5) load byte at 8018f8cc + 2B8 (20)
+
  0017b994: 1040000e beq r2,r0,0x0017b9d0                  {{f/Cond|<nowiki>If Target elevation is valid</nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (via a jump setting r2 to -0x01)
  0017b9c0: 00000000 nop
+
  0017b998: 00860018 mult r4,r6                                |{{f/std|<nowiki>Target Y * Map Max X</nowiki>}}
0017b9c4: 30420001 andi r2,r2,0x0001
+
  0017b99c: 00031200 sll r2,r3,0x08                            |{{f/std|<nowiki>r2 = Elevation  * 256</nowiki>}}
  0017b9c8: 10400003 beq r2,r0,0x0017b9d8 jump if tile isn't unselectable via  cursor
+
  0017b9a0: 00001812 mflo r3                                  |{{f/std|<nowiki>r3 = Target Y * Map Max X</nowiki>}}
  0017b9cc: 00000000 nop
+
  0017b9a4: 00431021 addu r2,r2,r3                            |{{f/std|<nowiki>r3 = Target Y * Map Max X + Elevation*256</nowiki>}}
  0017b9d0: 0805ef14 j 0x0017bc50 else skip to end
+
  0017b9a8: 00453021 addu r6,r2,r5                            |{{f/std|<nowiki>r6 = Tile ID = Target X + Target Y * Map Max X + Elevation*256</nowiki>}}
  0017b9d4: 2402ffff addiu r2,r0,0xffff
+
  0017b9ac: 000618c0 sll r3,r6,0x03                            |{{f/std|<nowiki>r3 = Tile ID* 8 </nowiki>}} {{f/std|<nowiki>(8 = size of tile data)</nowiki>}}
0017b9d8: 90a40002 lbu r4,0x0002(r5) load tile height
+
  0017b9b0: 3c028019 lui r2,0x8019                            |{{f/std|<nowiki>r2 = 0x80190000</nowiki>}}
  0017b9dc: 90a30003 lbu r3,0x0003(r5) load depth
+
  0017b9b4: 2442f8cc addiu r2,r2,-0x0734                      |{{f/std|<nowiki>r2 = 0x8018f8cc (Start of Tiles data)</nowiki>}}
  0017b9e0: 90a20003 lbu r2,0x0003(r5) load depth
+
  0017b9b8: 00622821 addu r5,r3,r2                            |{{f/adr|<nowiki>r5 = Target's Tile data pointer</nowiki>}}
  0017b9e4: 00042040 sll r4,r4,0x01 height*2
+
  0017b9bc: 90a20006 lbu r2,0x0006(r5)                        |{{f/load|<nowiki>r2 = Target's Tile 0x06 byte</nowiki>}}
  0017b9e8: 3063001f andi r3,r3,0x001f set if depth flag = 1f? (never)
+
  0017b9c0: 00000000 nop                                      |
  0017b9ec: 00832021 addu r4,r4,r3 r4 = (height*2) + 0?
+
  0017b9c4: 30420001 andi r2,r2,0x0001                        |{{f/std|<nowiki>r2 = 0x01 if tile is unselectable</nowiki>}}
  0017b9f0: 00021142 srl r2,r2,0x05 depth/2^5
+
  0017b9c8: 10400003 beq r2,r0,0x0017b9d8                      {{f/Cond|<nowiki>If tile is unselectable</nowiki>}} /Else branch to avoid routine exit
  0017b9f4: 00021040 sll r2,r2,0x01 depth*2
+
  0017b9cc: 00000000 nop                                          |{{f/std|<nowiki> </nowiki>}}
  0017b9f8: 00829021 addu r18,r4,r2
+
  0017b9d0: 0805ef14 j 0x0017bc50                                  {{f/jump|<nowiki>jump to </nowiki>{{f/loc|<nowiki>END</nowiki>}}<nowiki>  (with r2 = -0x01)</nowiki>}}
0017b9fc: 326300ff andi r3,r19,0x00ff ?dunno what r19 is, 01 in this case
+
  0017b9d4: 2402ffff addiu r2,r0,-0x0001                          |{{f/std|<nowiki>r2 = -0x01</nowiki>}}
  0017ba00: 340200ff ori r2,r0,0x00ff
+
  0017b9d8: 90a40002 lbu r4,0x0002(r5)                        {{f/Cond|<nowiki>Else (Tile is valid)</nowiki>}} {{f/load|<nowiki>r4 = Target tile Height</nowiki>}}
  0017ba04: 1462000c bne r3,r2,0x0017ba38 ?
+
0017b9dc: 90a30003 lbu r3,0x0003(r5)                            |{{f/load|<nowiki>r3 = Target tile halves + depht</nowiki>}}
  0017ba08: 00002021 addu r4,r0,r0
+
  0017b9e0: 90a20003 lbu r2,0x0003(r5)                            |{{f/load|<nowiki>r2 = Target tile halves + depht</nowiki>}}
  0017ba0c: 34050001 ori r5,r0,0x0001
+
  0017b9e4: 00042040 sll r4,r4,0x01                                |{{f/std|<nowiki>r4 = Target tile Height * 2</nowiki>}}
  0017ba10: 3c038019 lui r3,0x8019
+
0017b9e8: 3063001f andi r3,r3,0x001f                            |{{f/std|<nowiki>r3 = Target tile halves</nowiki>}}
  0017ba14: 24632dd8 addiu r3,r3,0x2dd8
+
  0017b9ec: 00832021 addu r4,r4,r3                                 |{{f/std|<nowiki>r4 = Target Tile  (height*2) +  halves</nowiki>}}
  0017ba18: a0650000 sb r5,0x0000(r3)
+
  0017b9f0: 00021142 srl r2,r2,0x05                                |{{f/std|<nowiki>r2 = Target Tile effective depht (0x20 becomes 0x01 / 0x80 becomes 0x04)</nowiki>}}
0017ba1c: a0600001 sb r0,0x0001(r3)
+
  0017b9f4: 00021040 sll r2,r2,0x01                                |{{f/std|<nowiki>r2 = Target Tile depht * 2</nowiki>}}
  0017ba20: 24840001 addiu r4,r4,0x0001
+
  0017b9f8: 00829021 addu r18,r4,r2                                |{{f/std|<nowiki>r18 = Target Tile Total Height</nowiki>}}
  0017ba24: 28820200 slti r2,r4,0x0200 loop runs 200 times?
+
  0017b9fc: 326300ff andi r3,r19,0x00ff                            |{{f/std|<nowiki>r3 = Attacker used Ability AoE last byte (=AoE)</nowiki>}}
  0017ba28: 1440fffb bne r2,r0,0x0017ba18
+
  0017ba00: 340200ff ori r2,r0,0x00ff                              |{{f/std|<nowiki>r2 = 0xff</nowiki>}}
  0017ba2c: 24630005 addiu r3,r3,0x0005
+
  0017ba04: 1462000c bne r3,r2,0x0017ba38                          {{f/Cond|<nowiki>If AoE = 255</nowiki>}}
  0017ba30: 0805eebf j 0x0017bafc skip big following routine
+
  0017ba08: 00002021 addu r4,r0,r0                                    |{{f/std|<nowiki>r4 = 0x00 (loop counter)</nowiki>}}
  0017ba34: 00000000 nop
+
  0017ba0c: 34050001 ori r5,r0,0x0001                                  |{{f/std|<nowiki>r5 = 0x01</nowiki>}}
0017ba38: 3c038019 lui r3,0x8019
+
  0017ba10: 3c038019 lui r3,0x8019                                    |{{f/std|<nowiki>r3 = 0x80190000</nowiki>}}
0017ba3c: 24632dd8 addiu r3,r3,0x2dd8
+
  0017ba14: 24632dd8 addiu r3,r3,0x2dd8                                |{{f/adr|<nowiki>r3 = Targetable grid data pointer</nowiki>}} {{f/std|<nowiki> 0x80192dd8</nowiki>}}
  0017ba40: a0600000 sb r0,0x0000(r3)
+
  0017ba18: a0650000 sb r5,0x0000(r3)                                  {{f/bloop|<nowiki>Loop (all grid panels)</nowiki>}} {{f/store|<nowiki>Store AoE = 0x01</nowiki>}}
  0017ba44: a0600001 sb r0,0x0001(r3)
+
  0017ba1c: a0600001 sb r0,0x0001(r3)                                      |{{f/store|<nowiki>Nullify Targetable panel targeted flag (byte 0x01 = 0x00)</nowiki>}}
  0017ba48: 24840001 addiu r4,r4,0x0001
+
  0017ba20: 24840001 addiu r4,r4,0x0001                                    |{{f/std|<nowiki>r4 = Counter + 1</nowiki>}}
  0017ba4c: 28820200 slti r2,r4,0x0200
+
  0017ba24: 28820200 slti r2,r4,0x0200                                    |{{f/std|<nowiki>r2 = 0x01 while r4 <0x200</nowiki>}}
  0017ba50: 1440fffb bne r2,r0,0x0017ba40 loop runs 200 times, clearing every 5th byte starting at 80192dd8
+
  0017ba28: 1440fffb bne r2,r0,0x0017ba18                              {{f/eloop|<nowiki>Loop While Counter < 0x200</nowiki>}} {{f/Cond|<nowiki>(All tiles)</nowiki>}}
  0017ba54: 24630005 addiu r3,r3,0x0005
+
  0017ba2c: 24630005 addiu r3,r3,0x0005                                    |{{f/std|<nowiki>r3 = Targetable grid panel counter</nowiki>}}
  0017ba58: 00061080 sll r2,r6,0x02
+
  0017ba30: 0805eebf j 0x0017bafc                                      {{f/jump|<nowiki>jump after AoE < 255 section</nowiki>}}
  0017ba5c: 00461821 addu r3,r2,r6
+
  0017ba34: 00000000 nop                                              |
  0017ba60: 3c048019 lui r4,0x8019
+
  0017ba38: 3c038019 lui r3,0x8019                                {{f/Cond|<nowiki>Else (AoE < 255)</nowiki>}} {{f/std|<nowiki>r3 = 0x80190000</nowiki>}}
0017ba64: 24842dd8 addiu r4,r4,0x2dd8
+
  0017ba3c: 24632dd8 addiu r3,r3,0x2dd8                                |{{f/adr|<nowiki>r3 = Targetable grid data pointer</nowiki>}} {{f/std|<nowiki> 0x80192dd8</nowiki>}}
  0017ba68: 00644021 addu r8,r3,r4
+
  0017ba40: a0600000 sb r0,0x0000(r3)                                  {{f/bloop|<nowiki>LOOP (all grid panels)</nowiki>}} {{f/store|<nowiki>Store AoE = 0x00</nowiki>}}
  0017ba6c: 26620001 addiu r2,r19,0x0001
+
  0017ba44: a0600001 sb r0,0x0001(r3)                                      |{{f/store|<nowiki>Store panel targeted flag = 0x00</nowiki>}}
  0017ba70: a1020000 sb r2,0x0000(r8)
+
  0017ba48: 24840001 addiu r4,r4,0x0001                                   |{{f/std|<nowiki>r4 = counter + 1</nowiki>}}
  0017ba74: 28c20100 slti r2,r6,0x0100
+
  0017ba4c: 28820200 slti r2,r4,0x0200                                    |{{f/std|<nowiki>r2 = 0x01 while counter < 0x200</nowiki>}}
0017ba78: 10400005 beq r2,r0,0x0017ba90
+
  0017ba50: 1440fffb bne r2,r0,0x0017ba40                              {{f/eloop|<nowiki>Loop while counter < 0x200</nowiki>}}
  0017ba7c: 24820500 addiu r2,r4,0x0500
+
  0017ba54: 24630005 addiu r3,r3,0x0005                                    |{{f/std|<nowiki>r3 = Targetable grid tile counter</nowiki>}}
  0017ba80: 00623821 addu r7,r3,r2
+
  0017ba58: 00061080 sll r2,r6,0x02                                    |{{f/std|<nowiki>r2 = Targeted Tile ID *4</nowiki>}}
  0017ba84: 34020001 ori r2,r0,0x0001
+
  0017ba5c: 00461821 addu r3,r2,r6                                    |{{f/std|<nowiki>r2 = Targeted Tile ID *5</nowiki>}}
0017ba88: 0805eea8 j 0x0017baa0
+
  0017ba60: 3c048019 lui r4,0x8019                                    |{{f/std|<nowiki>r4 = 0x80190000</nowiki>}}
0017ba8c: a1020001 sb r2,0x0001(r8)
+
  0017ba64: 24842dd8 addiu r4,r4,0x2dd8                                |{{f/std|<nowiki>r4 = 0x80192dd8</nowiki>}} {{f/std|<nowiki>Moveable/Targetable Panel Grid</nowiki>}}
  0017ba90: 2482fb00 addiu r2,r4,0xfb00
+
  0017ba68: 00644021 addu r8,r3,r4                                    |{{f/adr|<nowiki>r8 = Targeted Panel grid data pointer</nowiki>}}
  0017ba94: 00623821 addu r7,r3,r2
+
  0017ba6c: 26620001 addiu r2,r19,0x0001                              |{{f/std|<nowiki>r2 =AoE + 1</nowiki>}}
  0017ba98: 34020001 ori r2,r0,0x0001
+
  0017ba70: a1020000 sb r2,0x0000(r8)                                 |{{f/store|<nowiki>Store AoE +1 in at Targeted Panel 0x00</nowiki>}}
  0017ba9c: a0e20001 sb r2,0x0001(r7)
+
  0017ba74: 28c20100 slti r2,r6,0x0100                                |{{f/std|<nowiki>r2 = 0x01 if Targeted panel is on lower elevation</nowiki>}}
  0017baa0: 30c300ff andi r3,r6,0x00ff
+
  0017ba78: 10400005 beq r2,r0,0x0017ba90                              {{f/Cond|<nowiki>If Target panel is on lower elevation</nowiki>}}
  0017baa4: 00031080 sll r2,r3,0x02
+
  0017ba7c: 24820500 addiu r2,r4,0x0500                                    |{{f/std|<nowiki>r2 = 0x801932d8</nowiki>}} {{f/std|<nowiki>Start of higher elevation grid on Targetable panel grid (0x100 * 5)</nowiki>}}
  0017baa8: 00431021 addu r2,r2,r3
+
  0017ba80: 00623821 addu r7,r3,r2                                        |{{f/adr|<nowiki>r7 = Above panel data pointer</nowiki>}}
  0017baac: 34030001 ori r3,r0,0x0001
+
  0017ba84: 34020001 ori r2,r0,0x0001                                     |{{f/std|<nowiki>r2 = 0x01 </nowiki>}}
  0017bab0: 3c018019 lui r1,0x8019
+
  0017ba88: 0805eea8 j 0x0017baa0                                          {{f/jump|<nowiki>jump just after Else section</nowiki>}}
0017bab4: 00220821 addu r1,r1,r2
+
  0017ba8c: a1020001 sb r2,0x0001(r8)                                      |{{f/store|<nowiki>Flag lower Targeted panel 0x0001 (= green flag)</nowiki>}}
  0017bab8: a0232dd9 sb r3,0x2dd9(r1)
+
  0017ba90: 2482fb00 addiu r2,r4,-0x0500                              {{f/Cond|<nowiki>Else (Targeted panel is on higher elevation)</nowiki>}} {{f/std|<nowiki>r2 = 0x801928d8  (0x500 byte before start of Targetable grid data)</nowiki>}}
  0017babc: 31220020 andi r2,r9,0x0020
+
  0017ba94: 00623821 addu r7,r3,r2                                        |{{f/adr|<nowiki>r7 = Below panel data pointer</nowiki>}}
  0017bac0: 1440000e bne r2,r0,0x0017bafc
+
  0017ba98: 34020001 ori r2,r0,0x0001                                      |{{f/std|<nowiki>r2 = 0x01</nowiki>}}
  0017bac4: 02602021 addu r4,r19,r0
+
  0017ba9c: a0e20001 sb r2,0x0001(r7)                                      |{{f/store|<nowiki>Flag lower Targeted panel 0x0001 (= green flag)</nowiki>}}
  0017bac8: 00002821 addu r5,r0,r0
+
  0017baa0: 30c300ff andi r3,r6,0x00ff                                |{{f/std|<nowiki>r3 = Tile coordinates without elevation (+ 0x100) = [Tile ground coordinate]</nowiki>}}
  0017bacc: 26620001 addiu r2,r19,0x0001
+
  0017baa4: 00031080 sll r2,r3,0x02                                    |{{f/std|<nowiki>r2 = [Tile ground coordinate] * 4</nowiki>}}
  0017bad0: a1020000 sb r2,0x0000(r8)
+
  0017baa8: 00431021 addu r2,r2,r3                                    |{{f/std|<nowiki>r2 = [Tile ground coordinate] * 5</nowiki>}}
  0017bad4: 0c05e546 jal 0x00179518
+
  0017baac: 34030001 ori r3,r0,0x0001                                  |{{f/std|<nowiki>r3 = 0x01</nowiki>}}
  0017bad8: a0e20000 sb r2,0x0000(r7)
+
  0017bab0: 3c018019 lui r1,0x8019                                    |{{f/std|<nowiki>r1 = 0x80190000</nowiki>}}
  0017badc: 324400ff andi r4,r18,0x00ff
+
  0017bab4: 00220821 addu r1,r1,r2                                    |{{f/std|<nowiki>r1 = 0x80190000 + Offset for targetable grid</nowiki>}}
  0017bae0: 02a02821 addu r5,r21,r0
+
  0017bab8: a0232dd9 sb r3,0x2dd9(r1)                                  |{{f/store|<nowiki>Store 0x01 at Lower high targeted panel 0x01 (redundant ?)</nowiki>}}
  0017bae4: 00113142 srl r6,r17,0x05
+
  0017babc: 31220020 andi r2,r9,0x0020                                |{{f/std|<nowiki>r2 = 0x20 if Attacker used Ability has flag weapon range</nowiki>}}
  0017bae8: 0c05e4a9 jal 0x001792a4
+
  0017bac0: 1440000e bne r2,r0,0x0017bafc                              {{f/Cond|<nowiki>If Attacker used ability is NOT weapon ranged</nowiki>}}
  0017baec: 30c60001 andi r6,r6,0x0001
+
  0017bac4: 02602021 addu r4,r19,r0                                       |{{f/std|<nowiki>r4 = AoE</nowiki>}}
  0017baf0: 87a40012 lh r4,0x0012(r29)
+
  0017bac8: 00002821 addu r5,r0,r0                                        |{{f/std|<nowiki>r5 = 0x00</nowiki>}}
  0017baf4: 0c05e481 jal 0x00179204
+
0017bacc: 26620001 addiu r2,r19,0x0001                                  |{{f/std|<nowiki>r2 = AoE + 1</nowiki>}}
  0017baf8: 00000000 nop
+
  0017bad0: a1020000 sb r2,0x0000(r8)                                      |{{f/store|<nowiki>Store AoE +1 At Targeted panel AoE (grid)</nowiki>}}
0017bafc: 0c060428 jal 0x001810a0
+
  0017bad4: 0c05e546 jal 0x00179518                                        |{{f/jal|Calculate_Tiles_Hit_by_Ability|<nowiki>Calculate_Tiles_Hit_by_Ability</nowiki>}} Spread AoE on Targetable grid panels
  0017bb00: 02002021 addu r4,r16,r0
+
  0017bad8: a0e20000 sb r2,0x0000(r7)                                      |{{f/store|<nowiki>Store AoE +1 At Other Elevation Panel AoE (grid)</nowiki>}}
  0017bb04: 00021880 sll r3,r2,0x02
+
  0017badc: 324400ff andi r4,r18,0x00ff                                    |{{f/std|<nowiki>r4 = Target Tile Total Height</nowiki>}}
0017bb08: 00621821 addu r3,r3,r2
+
  0017bae0: 02a02821 addu r5,r21,r0                                        |{{f/std|<nowiki>r5 = Attacker used Ability vertical tolerance</nowiki>}}
  0017bb0c: 3c128019 lui r18,0x8019
+
  0017bae4: 00113142 srl r6,r17,0x05                                      |{{f/std|<nowiki>r6 = Attacker used Ability Top Down, Hit Enemy/Ally flags</nowiki>}}
  0017bb10: 26522dd8 addiu r18,r18,0x2dd8
+
  0017bae8: 0c05e4a9 jal 0x001792a4                                        |{{f/jal| Check Vert Tolerance and if Tiles can be Chosen|<nowiki> Check Vert Tolerance and if Tiles can be Chosen</nowiki>}}  Nullify panel AoE and 0x01 flag if vertical tolerance is overwhelmed
  0017bb14: 32220001 andi r2,r17,0x0001
+
0017baec: 30c60001 andi r6,r6,0x0001                                     |{{f/std|<nowiki>r6 = 0x01 if Attacker used Ability Top Down flag is ON</nowiki>}}
  0017bb18: 10400002 beq r2,r0,0x0017bb24
+
  0017baf0: 87a40012 lh r4,0x0012(r29)                                    |{{f/load|<nowiki>r4 = Attacker used Ability ID</nowiki>}}
  0017bb1c: 00721821 addu r3,r3,r18
+
  0017baf4: 0c05e481 jal 0x00179204                                        |{{f/jal|Moldball Virus Depth Check|<nowiki>Moldball Virus Depth Check</nowiki>}}  Nullify panel AoE and 0x01 flag if target tile depht <> 0x00
0017bb20: a0600000 sb r0,0x0000(r3)
+
  0017baf8: 00000000 nop                                                  |
  0017bb24: 32220004 andi r2,r17,0x0004
+
0017bafc: 0c060428 jal 0x001810a0                                |{{f/jal|Map_Location_Calculation|<nowiki>Map Location Calculation (Caster)</nowiki>}} return r2 = Attacker Tile ID
  0017bb28: 10400003 beq r2,r0,0x0017bb38
+
  0017bb00: 02002021 addu r4,r16,r0                               |{{f/adr|<nowiki>r4 = Attacker data pointer</nowiki>}}
  0017bb2c: 27a40010 addiu r4,r29,0x0010
+
  0017bb04: 00021880 sll r3,r2,0x02                                |{{f/std|<nowiki>r3 = caster tile ID * 4</nowiki>}}
0017bb30: 0c05ef9a jal 0x0017be68
+
  0017bb08: 00621821 addu r3,r3,r2                                |{{f/std|<nowiki>r3 = caster tile ID * 5</nowiki>}}
  0017bb34: 34050001 ori r5,r0,0x0001
+
  0017bb0c: 3c128019 lui r18,0x8019                                |{{f/std|<nowiki>r18 = 0x80190000</nowiki>}}
  0017bb38: 32220002 andi r2,r17,0x0002
+
  0017bb10: 26522dd8 addiu r18,r18,0x2dd8                          |{{f/std|<nowiki>r18 = Targetable grid data pointer (0x80192dd8)</nowiki>}}
  0017bb3c: 10400004 beq r2,r0,0x0017bb50
+
  0017bb14: 32220001 andi r2,r17,0x0001                            |{{f/std|<nowiki>r2 = 0x01 if Attacker used Ability hit caster is not checked</nowiki>}}
  0017bb40: 323000c0 andi r16,r17,0x00c0
+
  0017bb18: 10400002 beq r2,r0,0x0017bb24                          {{f/Cond|<nowiki>If Attacker used Ability do not hit caster</nowiki>}}
0017bb44: 27a40010 addiu r4,r29,0x0010
+
  0017bb1c: 00721821 addu r3,r3,r18                                |{{f/std|<nowiki>r3 = Attacker Targetable panel data pointer</nowiki>}}
  0017bb48: 0c05ef9a jal 0x0017be68
+
  0017bb20: a0600000 sb r0,0x0000(r3)                                  |{{f/store|<nowiki>Nullify Targetable panel AoE flag</nowiki>}}
0017bb4c: 34050003 ori r5,r0,0x0003
+
  0017bb24: 32220004 andi r2,r17,0x0004                            |{{f/std|<nowiki>r2 = 0x04 if Attacker used Ability is linear</nowiki>}}
  0017bb50: 12000006 beq r16,r0,0x0017bb6c
+
  0017bb28: 10400003 beq r2,r0,0x0017bb38                          {{f/Cond|<nowiki>If Attacker used Ability is a linear attack </nowiki>}} /Else branch to 3 direction check
  0017bb54: 02802021 addu r4,r20,r0
+
  0017bb2c: 27a40010 addiu r4,r29,0x0010                              |{{f/adr|<nowiki>r4 = Stack 0x10</nowiki>}}
  0017bb58: 32250080 andi r5,r17,0x0080
+
  0017bb30: 0c05ef9a jal 0x0017be68                                    |{{f/jal|Linear/3-direction_AoE_Calculation|<nowiki>Linear/3-direction_AoE_Calculation</nowiki>}} Only keep AoE of lined up panels
  0017bb5c: 32260040 andi r6,r17,0x0040
+
  0017bb34: 34050001 ori r5,r0,0x0001                                  |{{f/std|<nowiki>r5 = 0x01 (linear ability)</nowiki>}}
  0017bb60: 3a6700ff xori r7,r19,0x00ff
+
  0017bb38: 32220002 andi r2,r17,0x0002                            |{{f/std|<nowiki>r2 = 0x02 if Attacker used Ability is 3 directions</nowiki>}}
  0017bb64: 0c05ef1e jal 0x0017bc78
+
  0017bb3c: 10400004 beq r2,r0,0x0017bb50                          {{f/Cond|<nowiki>If Attacker used Ability is a 3 directional attack</nowiki>}} /Else branch toAvoid unit check
0017bb68: 2ce70001 sltiu r7,r7,0x0001
+
  0017bb40: 323000c0 andi r16,r17,0x00c0                          |{{f/std|<nowiki>r16 <> 0x00 if Ability avoid enemy or ally (when hit ally or hit enemy is checked in patcher, the flag is set to 0x00)</nowiki>}}
  0017bb6c: 1600001d bne r16,r0,0x0017bbe4
+
  0017bb44: 27a40010 addiu r4,r29,0x0010                              |{{f/adr|<nowiki>r4 = Stack 0x10</nowiki>}}
  0017bb70: 00003021 addu r6,r0,r0
+
  0017bb48: 0c05ef9a jal 0x0017be68                                    |{{f/jal|Linear/3-direction_AoE_Calculation|<nowiki>Linear/3-direction_AoE_Calculation</nowiki>}} Only keep AoE of lined up panels
  0017bb74: 00002021 addu r4,r0,r0
+
  0017bb4c: 34050003 ori r5,r0,0x0003                                  |{{f/std|<nowiki>r5 = 0x03 (3 direction ability)</nowiki>}}
  0017bb78: 02402821 addu r5,r18,r0
+
  0017bb50: 12000006 beq r16,r0,0x0017bb6c                        {{f/Cond|<nowiki>If Ability Ignore Ally or Enemy unit</nowiki>}}
  0017bb7c: 3c038019 lui r3,0x8019
+
  0017bb54: 02802021 addu r4,r20,r0                                   |{{f/std|<nowiki>r4 = Attacker ID</nowiki>}}
  0017bb80: 2463f8cc addiu r3,r3,0xf8cc
+
  0017bb58: 32250080 andi r5,r17,0x0080                                |{{f/std|<nowiki>r5 = 0x80 if Ability avoid enemy units</nowiki>}}
  0017bb84: 90a20000 lbu r2,0x0000(r5)
+
  0017bb5c: 32260040 andi r6,r17,0x0040                                |{{f/std|<nowiki>r6 = 0x40 if Ability avoid ally units</nowiki>}}
  0017bb88: 00000000 nop
+
  0017bb60: 3a6700ff xori r7,r19,0x00ff                                |{{f/std|<nowiki>r7 = Ability not AoE (every bits but thoses in AoE value)</nowiki>}}
  0017bb8c: 1040000a beq r2,r0,0x0017bbb8
+
  0017bb64: 0c05ef1e jal 0x0017bc78                                    |{{f/jal|Check_Allies/Enemies_that_can_be_Targeted|<nowiki>Check_Allies/Enemies_that_can_be_Targeted</nowiki>}}
  0017bb90: 00000000 nop
+
  0017bb68: 2ce70001 sltiu r7,r7,0x0001                               |{{f/std|<nowiki>r7 = 0x01 if AoE was 255 (255 xor 255 = 0x00 (so < 0x01))</nowiki>}}
  0017bb94: 90620006 lbu r2,0x0006(r3)
+
  0017bb6c: 1600001d bne r16,r0,0x0017bbe4                        {{f/Cond|<nowiki>If Ability Hits everybody</nowiki>}}
  0017bb98: 00000000 nop
+
  0017bb70: 00003021 addu r6,r0,r0                                    |{{f/std|<nowiki>r6 = 0x00</nowiki>}} {{f/std|<nowiki>r6 = Targeted Panel Counter</nowiki>}}
  0017bb9c: 30420003 andi r2,r2,0x0003
+
  0017bb74: 00002021 addu r4,r0,r0                                    |{{f/std|<nowiki>r4 = 0x00</nowiki>}} {{f/std|<nowiki>r4 = Tile Counter</nowiki>}}
  0017bba0: 14400005 bne r2,r0,0x0017bbb8
+
  0017bb78: 02402821 addu r5,r18,r0                                    |{{f/adr|<nowiki>r5 = Targetable grid data pointer</nowiki>}} {{f/std|<nowiki> 0x80192dd8</nowiki>}}
  0017bba4: 00000000 nop
+
  0017bb7c: 3c038019 lui r3,0x8019                                    |
0017bba8: 90620005 lbu r2,0x0005(r3)
+
  0017bb80: 2463f8cc addiu r3,r3,-0x0734                              |{{f/adr|<nowiki>r3 = Tile data pointer</nowiki>}}
  0017bbac: 24c60001 addiu r6,r6,0x0001
+
  0017bb84: 90a20000 lbu r2,0x0000(r5)                                 {{f/bloop|<nowiki>LOOP through all tiles/panels</nowiki>}} {{f/load|<nowiki>r2 = This iteration panel AoE</nowiki>}}
  0017bbb0: 0805eef1 j 0x0017bbc4
+
  0017bb88: 00000000 nop                                                  |{{f/std|<nowiki> </nowiki>}}
0017bbb4: 34420080 ori r2,r2,0x0080
+
  0017bb8c: 1040000a beq r2,r0,0x0017bbb8                                  {{f/Cond|<nowiki>If This iteration panel AoE > 0x00</nowiki>}} /Else branch to nullify flag 0x01
  0017bbb8: 90620005 lbu r2,0x0005(r3)
+
  0017bb90: 00000000 nop                                                      |{{f/std|<nowiki> </nowiki>}}
  0017bbbc: 00000000 nop
+
0017bb94: 90620006 lbu r2,0x0006(r3)                                         |{{f/load|<nowiki>r2 = Tile 0x06</nowiki>}}
0017bbc0: 3042007f andi r2,r2,0x007f
+
  0017bb98: 00000000 nop                                                       |
  0017bbc4: a0620005 sb r2,0x0005(r3)
+
  0017bb9c: 30420003 andi r2,r2,0x0003                                        |{{f/std|<nowiki>r2 <> 0x00 if tile is unselectable or untargetable</nowiki>}}
  0017bbc8: 24a50005 addiu r5,r5,0x0005
+
  0017bba0: 14400005 bne r2,r0,0x0017bbb8                                      {{f/Cond|<nowiki>If tile is targetable/selectable</nowiki>}} /Else branch to nullify flag 0x01
0017bbcc: 24840001 addiu r4,r4,0x0001
+
  0017bba4: 00000000 nop                                                          |{{f/std|<nowiki> </nowiki>}}
  0017bbd0: 28820200 slti r2,r4,0x0200
+
  0017bba8: 90620005 lbu r2,0x0005(r3)                                            |{{f/load|<nowiki>r2 = Tile 0x05</nowiki>}}
  0017bbd4: 1440ffeb bne r2,r0,0x0017bb84
+
  0017bbac: 24c60001 addiu r6,r6,0x0001                                            |{{f/std|<nowiki>r6 = Targeted panel counter + 1</nowiki>}}
  0017bbd8: 24630008 addiu r3,r3,0x0008
+
  0017bbb0: 0805eef1 j 0x0017bbc4                                                  {{f/jump|<nowiki>jump to tile 0x05 flag update</nowiki>}}
  0017bbdc: 0805ef14 j 0x0017bc50
+
0017bbb4: 34420080 ori r2,r2,0x0080                                              |{{f/std|<nowiki>r2 = Tile 0x05 + "Green panel" enabled</nowiki>}}
0017bbe0: 00c01021 addu r2,r6,r0
+
  0017bbb8: 90620005 lbu r2,0x0005(r3)                                    {{f/Cond|<nowiki>Else (AoE = 0x00 or invalid tile)</nowiki>}} {{f/load|<nowiki>r2 = Tile 0x05</nowiki>}}
  0017bbe4: 00002021 addu r4,r0,r0
+
  0017bbbc: 00000000 nop                                                          |{{f/std|<nowiki> </nowiki>}}
  0017bbe8: 02402821 addu r5,r18,r0
+
  0017bbc0: 3042007f andi r2,r2,0x007f                                            |{{f/std|<nowiki>r2 = Tile 0x05 without "Green panel"</nowiki>}}
  0017bbec: 3c038019 lui r3,0x8019
+
0017bbc4: a0620005 sb r2,0x0005(r3)                                      |{{f/store|<nowiki>Store updated byte (with or without "Green panel") at tile 0x05</nowiki>}}
  0017bbf0: 2463f8cc addiu r3,r3,0xf8cc
+
0017bbc8: 24a50005 addiu r5,r5,0x0005                                    |{{f/std|<nowiki>r5 = Panel counter + 5 (5 = size of panels data)</nowiki>}}
  0017bbf4: 90a20001 lbu r2,0x0001(r5)
+
0017bbcc: 24840001 addiu r4,r4,0x0001                                    |{{f/std|<nowiki>r4 = loop counter</nowiki>}}
  0017bbf8: 00000000 nop
+
0017bbd0: 28820200 slti r2,r4,0x0200                                    |{{f/std|<nowiki>r2 = 0x01 if counter < 0x200</nowiki>}}
  0017bbfc: 1040000a beq r2,r0,0x0017bc28
+
0017bbd4: 1440ffeb bne r2,r0,0x0017bb84                              {{f/eloop|<nowiki>loop while counter < 0x200</nowiki>}}
  0017bc00: 00000000 nop
+
0017bbd8: 24630008 addiu r3,r3,0x0008                                    |{{f/std|<nowiki>r3 = Tile counter + 8 (8 = size of tiles data)</nowiki>}}
  0017bc04: 90620006 lbu r2,0x0006(r3)
+
0017bbdc: 0805ef14 j 0x0017bc50                                      {{f/jump|<nowiki>jump to </nowiki>{{f/loc|<nowiki>END</nowiki>}}<nowiki></nowiki>}}
0017bc08: 00000000 nop
+
0017bbe0: 00c01021 addu r2,r6,r0                                    |{{f/std|<nowiki>r2 = Number of targeted panels</nowiki>}}
  0017bc0c: 30420003 andi r2,r2,0x0003
+
0017bbe4: 00002021 addu r4,r0,r0                                {{f/Cond|<nowiki>Else (Ability ignores Allies or Enemies)</nowiki>}} {{f/std|<nowiki>r4 = Tile Counter</nowiki>}}
  0017bc10: 14400005 bne r2,r0,0x0017bc28
+
0017bbe8: 02402821 addu r5,r18,r0                                    |{{f/adr|<nowiki>r5 = Targetable grid data pointer</nowiki>}} {{f/std|<nowiki> 0x80192dd8</nowiki>}}
0017bc14: 00000000 nop
+
0017bbec: 3c038019 lui r3,0x8019                                    |
  0017bc18: 90620005 lbu r2,0x0005(r3)
+
0017bbf0: 2463f8cc addiu r3,r3,-0x0734                              |{{f/adr|<nowiki>r3 = Tile data pointer</nowiki>}}
  0017bc1c: 24c60001 addiu r6,r6,0x0001
+
0017bbf4: 90a20001 lbu r2,0x0001(r5)                                {{f/bloop|<nowiki>LOOP though all tile/panel</nowiki>}} {{f/load|<nowiki>r2 = This iteration targetable panel targeted flag</nowiki>}}
  0017bc20: 0805ef0d j 0x0017bc34
+
0017bbf8: 00000000 nop                                                  |{{f/std|<nowiki> </nowiki>}}
0017bc24: 34420080 ori r2,r2,0x0080
+
0017bbfc: 1040000a beq r2,r0,0x0017bc28                                  {{f/Cond|<nowiki>If this panel is targeted (flag 0x01 = 0x01)</nowiki>}}
  0017bc28: 90620005 lbu r2,0x0005(r3)
+
0017bc00: 00000000 nop                                                      |{{f/std|<nowiki> </nowiki>}}
  0017bc2c: 00000000 nop
+
0017bc04: 90620006 lbu r2,0x0006(r3)                                        |{{f/load|<nowiki>r2 = This iteration Tile 0x06 byte</nowiki>}}
  0017bc30: 3042007f andi r2,r2,0x007f
+
0017bc08: 00000000 nop                                                      |
  0017bc34: a0620005 sb r2,0x0005(r3)
+
0017bc0c: 30420003 andi r2,r2,0x0003                                        |{{f/std|<nowiki>r2 <> 0x00 if this tile is not selectable/targetable</nowiki>}}
  0017bc38: 24a50005 addiu r5,r5,0x0005
+
0017bc10: 14400005 bne r2,r0,0x0017bc28                                      {{f/Cond|<nowiki>If This tile is selectable/targetable</nowiki>}}
  0017bc3c: 24840001 addiu r4,r4,0x0001
+
0017bc14: 00000000 nop                                                          |{{f/std|<nowiki> </nowiki>}}
  0017bc40: 28820200 slti r2,r4,0x0200
+
0017bc18: 90620005 lbu r2,0x0005(r3)                                            |{{f/load|<nowiki>r2 = This tile 0x05 byte</nowiki>}}
  0017bc44: 1440ffeb bne r2,r0,0x0017bbf4
+
0017bc1c: 24c60001 addiu r6,r6,0x0001                                            |{{f/std|<nowiki>r6 = Targeted panel counter</nowiki>}}
  0017bc48: 24630008 addiu r3,r3,0x0008
+
0017bc20: 0805ef0d j 0x0017bc34                                                  {{f/jump|<nowiki>jump to tile 0x05 flag update</nowiki>}}
  0017bc4c: 00c01021 addu r2,r6,r0
+
0017bc24: 34420080 ori r2,r2,0x0080                                              |{{f/std|<nowiki>r2 = This tile 0x05 byte updated with "green panel" flag</nowiki>}}
  0017bc50: 8fbf0040 lw r31,0x0040(r29)
+
0017bc28: 90620005 lbu r2,0x0005(r3)                                    {{f/Cond|<nowiki>Else (panel not targeted or unvalid tile)</nowiki>}} {{f/load|<nowiki>r2 = This tile 0x05 byte</nowiki>}}
  0017bc54: 8fb5003c lw r21,0x003c(r29)
+
0017bc2c: 00000000 nop                                                      |{{f/std|<nowiki> </nowiki>}}
  0017bc58: 8fb40038 lw r20,0x0038(r29)
+
0017bc30: 3042007f andi r2,r2,0x007f                                        |{{f/std|<nowiki>r2 = Tile 0x05 without "Green panel"</nowiki>}}
  0017bc5c: 8fb30034 lw r19,0x0034(r29)
+
0017bc34: a0620005 sb r2,0x0005(r3)                                      |{{f/store|<nowiki>Store updated byte 0x05 on Tile data</nowiki>}}
  0017bc60: 8fb20030 lw r18,0x0030(r29)
+
0017bc38: 24a50005 addiu r5,r5,0x0005                                    |{{f/std|<nowiki>r5 = Panel counter + 5 (size of panels data)</nowiki>}}
  0017bc64: 8fb1002c lw r17,0x002c(r29)
+
0017bc3c: 24840001 addiu r4,r4,0x0001                                    |{{f/std|<nowiki>r4 = loop counter</nowiki>}}
  0017bc68: 8fb00028 lw r16,0x0028(r29)
+
0017bc40: 28820200 slti r2,r4,0x0200                                    |{{f/std|<nowiki>r2 = 1 while counter < 0x200</nowiki>}}
  0017bc6c: 27bd0048 addiu r29,r29,0x0048
+
0017bc44: 1440ffeb bne r2,r0,0x 0017bbf4                            {{f/eloop|<nowiki>Loop while counter < 0x200</nowiki>}}
  0017bc70: 03e00008 jr r31
+
0017bc48: 24630008 addiu r3,r3,0x0008                                    |{{f/std|<nowiki>r3 = Tile counter + 8 (8 = size of tiles data)</nowiki>}}
 +
0017bc4c: 00c01021 addu r2,r6,r0                                    |{{f/std|<nowiki>r2 = Targeted panel counter</nowiki>}}
 +
0017bc50: 8fbf0040 lw r31,0x0040(r29)      '''END'''                         
 +
  0017bc54: 8fb5003c lw r21,0x003c(r29)                              
 +
  0017bc58: 8fb40038 lw r20,0x0038(r29)                              
 +
  0017bc5c: 8fb30034 lw r19,0x0034(r29)                              
 +
  0017bc60: 8fb20030 lw r18,0x0030(r29)                              
 +
  0017bc64: 8fb1002c lw r17,0x002c(r29)                              
 +
  0017bc68: 8fb00028 lw r16,0x0028(r29)                              
 +
  0017bc6c: 27bd0048 addiu r29,r29,0x0048                            
 +
  0017bc70: 03e00008 jr r31                                          
 
  0017bc74: 00000000 nop
 
  0017bc74: 00000000 nop
 +
=== Notes ===
 +
Tile will refer at 0x8018f8cc data (size per tile = 0x08)
 +
Panel will refer at 0x80192dd8 data (size per panel = 0x05)
 +
 +
'''1st part : set targeted tile X, Y and elevation'''
 +
- if ability stops at obstacle : Force the weapon ranged flag ON
 +
                                  Force Hit caster, linear and 3 directions OFF
 +
- if Ability is linear or 3 direction : use Attacker coordinate instead of targeted tile
 +
                                        (in those abilities range = AoE, the Extra AoE will be deleted later)
 +
- if Ability is not linear nor 3 directions : uses Attacker 0x178 data.([[#Attacker 0x178 notes|see Attacker 0x178 notes]])
 +
      - if Attacker 0x178 = 0x06 : uses Targeted Tile Coordinates (Attacker 0x17a, 0x17c and 0x17e) 
 +
      - if Attacker 0x178 <> 0x06 : uses Target ID to get his coordinates (Target 0x47, 0x48, 0x49)
 +
 +
Exits if Targeted coordinates are invalid
 +
 +
'''2nd part : spread AoE'''
 +
- If AoE = 255 : Store AoE = 0x01 and Targeted = 0x00 in all panels
 +
- If AoE <> 255 : - first nullify all panels AoE and Targeted flag
 +
                  - Set Targeted panel AoE = Ability AoE + 1 (both elevation)
 +
                  - if Ability is not weapon ranged
 +
                        - Spread AoE on panels [[Calculate_Tiles_Hit_by_Ability]] (while spreading set panels 0x01 byte to 0x00)
 +
                        - Check for vertical tolerance (nullify AoE off panels out of range) [[ Check Vert Tolerance and if Tiles can be Chosen]]
 +
                        - If Moldball virus, nullify AoE if panel as depth > 0 [[Moldball Virus Depth Check]]
 +
 
 +
** At this point - Targetable valid panels have their AoE > 0 and targeted flag (0x01) set to 0x00 **
 +
 
 +
'''3rd part : adapt AoE on specific cases'''
 +
- if Ability do not hit caster : nullify caster panel AoE
 +
- if Ability is linear : Nullify AoE of panels not lined up with Attacker and Targeted tile [[Linear/3-direction_AoE_Calculation]]
 +
- if Ability is 3 direction : Same as linear, keep 2 other directions [[Linear/3-direction_AoE_Calculation]]
 +
- if Ability ignore allies/ennemies : [[Check_Allies/Enemies_that_can_be_Targeted]]
 +
        - Test all units : - if Unit on panel is ignored : AoE panel is set to 0x00
 +
                            - if Unit on panel is not ignored : panel 0x01 byte is set to 0x01 and kept this way
 +
        - Test all panels : if panel AoE > 1 set panel 0x01 byte to 0x01
 +
 +
'''4rd part : test all tiles :''' count targeted panel and activate "green panel" flag (tile 0x05 byte)
 +
- if Ability Hits every team : - if panel AoE > 0x00
 +
                                      - if Tile is not selectable/targetable (tile 0x06 byte) - Tile 0x05 is forced without the 0x80 value
 +
                                      - if Tile is valid Tile is counted and Tile 0x05 Green Panel flag is set (0x80)
 +
                                - if panel AoE = 0x00, matching Tile 0x05 is forced without the 0x80 value
 +
 +
- if Ability Ignores a team : - if panel 0x01 flag is <> 0x00
 +
                                  - if Tile is not selectable/targetable (tile 0x06 byte) then Tile 0x05 is forced without the 0x80 value
 +
                                  - if Tile is valid then Tile is counted and Tile 0x05 Green Panel flag is set (0x80)
 +
                              - if panel 0x01 flag = 0x00 then Tile 0x05 is forced without the 0x80 value
 +
 +
'''Panel state after routine'''
 +
- Valid Targetable Panels has their AoE > 0x00
 +
- Panels keeps their 0x01 flags only if Ability ignores a team
 +
- When ability ignore a team : Panels beyond range, may have their 0x01 flags = 0x01 and AoE = 0
 +
 +
'''Notes :'''
 +
- AoE value is higher at the center and decrease while spreading. Panel with AoE = 0x01 are on the borders of the AoE
 +
  or at the end of the "beam" of a linear attack. This could be used to decrease damage or anything else.
 +
  The only exception is for Ability with AoE = 255 where all the panel has their AoE = 0x01.
  
 +
=== Attacker 0x178 notes ===
 +
'''In the actual table data location page''' this byte is known as reaction ID ?.
 +
  - The value 0x06 seems to be related to Target specific ability (follow target)
 +
  - The value 0x05 might be for Tile specific ability (cast on a tile, do not follow unit)
 +
 +
'''Here are the notes i found on this routine '''page before formatting it. I'm not able yet to determine if it's accurate.
 +
*0x001a - Modified in (0074308) where value is set to 05 if Unit is under player control (ENTD 08) or if Unit ID = 2 (0x0168 of Misc Unit Data (0b7308)).
 +
I have no idea if 0x0168 is actually Unit ID and I suspect not (doesn't really seem to coordinate with Unit IDs in ENTD), but it is cycled through and changed constantly during the AI's decision making process. It could otherwise very well be the decision value or the AI derived Unit ID aka Battle ID?
 +
Otherwise 0x001a is usually 06. I don't know the significance of 04 (Miming action?), but 02 = Player Control, 01 = AI Control. I've only ever seen 05 or 06 when the process comes here. Perhaps if it's not 04, it doesn't come here at all?
 +
Complete guesswork on my part here, but 04 might be tied to Action Menu flags (If not Default/Elemental/Monster/etc., or any skillset type that doesn't normally take AoE, then don't even go to (0074308)?
 +
  Anyways, 0x001a is important because the AI has to get the targeted unit, then determine it's X,Y. Player Controlled Units already have the X,Y loaded into the stack.
  
== Return Locations ==
+
=== Return location ===
0017ac38: - [[Routine at 17aaf8]]
+
0017ac40: [[Calculate_Targeting_for_Menu_Types]]

Latest revision as of 19:14, 18 May 2023

0017b874 - 0017bc74     Notes

Parameters : r4 = Pointer to Attacker 0x16e to 0x181 data

Returns : r2 = number of Tiles with "green panel" flag
          r2 = -0x01 (invalid coordinates, unselectable tile)

This routine will set the "green panel" flag (Tile byte 0x05 - flag 0x80) on tile targeted by ability
It will use the Targetable panel grid ( 0x80192dd8 ), using AoE (byte 0x00) and Targeted flag (byte 0x01) See notes
------------------------------------------------------------------------------------------------------

0017b874: 27bdffb8 addiu r29,r29,-0x0048    
0017b878: 27a50010 addiu r5,r29,0x0010           |r5 = Stack 0x10
0017b87c: afbf0040 sw r31,0x0040(r29)            |
0017b880: afb5003c sw r21,0x003c(r29)            |
0017b884: afb40038 sw r20,0x0038(r29)            |
0017b888: afb30034 sw r19,0x0034(r29)            |
0017b88c: afb20030 sw r18,0x0030(r29)            |
0017b890: afb1002c sw r17,0x002c(r29)            |
0017b894: 0c01788b jal 0x0005e22c                |-->Copy_Byte_Data_(20_Bytes) Copy Attacker 0x16e to 0x181 on Stack r29 0x10 to 0x23
0017b898: afb00028 sw r16,0x0028(r29)            |
0017b89c: 3c058019 lui r5,0x8019                 |r5 = 0x80190000
0017b8a0: 24a508cc addiu r5,r5,0x08cc            |r5 = Start of unit data
0017b8a4: 87a20012 lh r2,0x0012(r29)             |r2 = Attacker's used ability ID
0017b8a8: 93b40010 lbu r20,0x0010(r29)           |r20 = Attacker ID
0017b8ac: 000218c0 sll r3,r2,0x03                |r3 = Attacker's used ability ID * 8
0017b8b0: 00621823 subu r3,r3,r2                 |r3 = Attacker's used ability ID * 7
0017b8b4: 00031840 sll r3,r3,0x01                |r3 = Attacker's used ability ID * 14
0017b8b8: 3c028006 lui r2,0x8006                 |r2 = 0x80060000
0017b8bc: 2442fbf0 addiu r2,r2,-0x0410           |r2 = 0x8005fbf0 (start of ability data 2)
0017b8c0: 00621821 addu r3,r3,r2                 |r3 = Start of Attacker'd used ability data 2
0017b8c4: 001410c0 sll r2,r20,0x03               |r2 = Attacker's ID * 8
0017b8c8: 00541023 subu r2,r2,r20                |r2 = Attacker's ID * 7
0017b8cc: 00021180 sll r2,r2,0x06                |r2 = Attacker's ID * 448 (448 = unot data size)
0017b8d0: 90690003 lbu r9,0x0003(r3)             |r9 = Attacker used Ability flag 1
0017b8d4: 90710004 lbu r17,0x0004(r3)            |r17 = Attacker used Ability flags 2
0017b8d8: 90640006 lbu r4,0x0006(r3)             |r4 = Attacker used Ability flags 4
0017b8dc: 90730001 lbu r19,0x0001(r3)            |r19 = Attacker used Ability  AoE (Effect area in patcher)
0017b8e0: 90750002 lbu r21,0x0002(r3)            |r21 = Attacker used Ability vertical
0017b8e4: 30840020 andi r4,r4,0x0020             |r4 = 0x20 if Attacker used Ability stop at obstacle is checked
0017b8e8: 10800003 beq r4,r0,0x0017b8f8          #If Attacker used Ability stops at obstacle  / Else avoid flags manipulation
0017b8ec: 00458021 addu r16,r2,r5                |r16 =  Attacker Unit Data Pointer
0017b8f0: 35290020 ori r9,r9,0x0020                  |r9 = Attacker used Ability flag 1 with Weapon range forced ON
0017b8f4: 32310039 andi r17,r17,0x0039               |r17 = Attacker used Ability flags 2 with Hit caster, 3 direction, Linear AoE and follow target forced OFF
0017b8f8: 32220006 andi r2,r17,0x0006            |r2 <> 0x00 if Attacker used Ability Is a linear attack or 3 directions attack
0017b8fc: 10400006 beq r2,r0,0x0017b918          #If Attacker used Ability is linear and/or 3 directions
0017b900: 34020006 ori r2,r0,0x0006              |r2 = 0x06
0017b904: 92050047 lbu r5,0x0047(r16)                |r5 = Attacker X coordinate
0017b908: 96020048 lhu r2,0x0048(r16)                |r2 = Attacker Y & Elevation/facing
0017b90c: 92040048 lbu r4,0x0048(r16)                |r4 = Attacker Y coordinate
0017b910: 0805ee59 j 0x0017b964                      >>jump to Coordinates validation section keeping Attacker coordinate as Targeted coordinates
0017b914: 00021bc2 srl r3,r2,0x0f                    |r3 = 0x01 if Higher elevation was checked (0x80) else 0x00
0017b918: 93a3001a lbu r3,0x001a(r29)            #Else (not linear/3Di) r3 = Attacker 0x178
0017b91c: 00000000 nop                               | 
0017b920: 10620006 beq r3,r2,0x0017b93c              #If Attacker used Ability is not  a Target specific ability (player ?)
0017b924: 00000000 nop                                   | 
0017b928: 93a5001c lbu r5,0x001c(r29)                    |r5 = Targeted tile X coord
0017b92c: 93a40020 lbu r4,0x0020(r29)                    |r4 = Targeted tile Y coord
0017b930: 93a3001e lbu r3,0x001e(r29)                    |r3 = Targeted tile Elevation
0017b934: 0805ee59 j 0x0017b964                          >>jump to Coordinates control
0017b938: 00000000 nop                                   | 
0017b93c: 93a2001b lbu r2,0x001b(r29)                # Else (Attacker used Ability is Target specific) r2 = Target ID (AI ?)
0017b940: 00000000 nop                                   |      
0017b944: 000218c0 sll r3,r2,0x03                        |r3 = Target ID * 8
0017b948: 00621823 subu r3,r3,r2                         |r3 = Target ID * 7
0017b94c: 00031980 sll r3,r3,0x06                        |r3 = Target ID * 448
0017b950: 00651821 addu r3,r3,r5                         |r5 = Target data pointer
0017b954: 90650047 lbu r5,0x0047(r3)                     |r5 = Target X
0017b958: 94620048 lhu r2,0x0048(r3)                     |r2 = TargetY & Elevation/facing
0017b95c: 90640048 lbu r4,0x0048(r3)                     |r4 = Target Y
0017b960: 00021bc2 srl r3,r2,0x0f                        |r3 = 0x01 if Higher elevation was checked (0x80) else 0x00
0017b964: 3c06800e lui r6,0x800e                 |r6 = 0x800e0000
0017b968: 90c64e9c lbu r6,0x4e9c(r6)             |r6 = Map Max X
0017b96c: 00000000 nop                           |
0017b970: 00a6102a slt r2,r5,r6                  |r2 = 0x01 if Target X < Max X
0017b974: 104000b6 beq r2,r0,0x0017bc50          #If Target X is valid /Else branch to END (r2 = -0x01)
0017b978: 2402ffff addiu r2,r0,-0x0001           |r2 = -0x01
0017b97c: 3c02800e lui r2,0x800e                     |r2 = 0x800e
0017b980: 90424ea0 lbu r2,0x4ea0(r2)                 |r2 = Map Max Y
0017b984: 00000000 nop                               |
0017b988: 0082102a slt r2,r4,r2                      |r2 = 0x01 if Target Y < Max Y
0017b98c: 10400010 beq r2,r0,0x0017b9d0              #If Target Y is valid  /Else branch to END (via a jump setting r2 to -0x01)
0017b990: 28620002 slti r2,r3,0x0002                     |r2 = 0x01 if Elevation < 0x02
0017b994: 1040000e beq r2,r0,0x0017b9d0                  #If Target elevation is valid /Else branch to END (via a jump setting r2 to -0x01)
0017b998: 00860018 mult r4,r6                                |Target Y * Map Max X
0017b99c: 00031200 sll r2,r3,0x08                            |r2 = Elevation  * 256
0017b9a0: 00001812 mflo r3                                   |r3 = Target Y * Map Max X
0017b9a4: 00431021 addu r2,r2,r3                             |r3 = Target Y * Map Max X + Elevation*256
0017b9a8: 00453021 addu r6,r2,r5                             |r6 = Tile ID = Target X + Target Y * Map Max X + Elevation*256
0017b9ac: 000618c0 sll r3,r6,0x03                            |r3 = Tile ID* 8  (8 = size of tile data)
0017b9b0: 3c028019 lui r2,0x8019                             |r2 = 0x80190000
0017b9b4: 2442f8cc addiu r2,r2,-0x0734                       |r2 = 0x8018f8cc (Start of Tiles data)
0017b9b8: 00622821 addu r5,r3,r2                             |r5 = Target's Tile data pointer
0017b9bc: 90a20006 lbu r2,0x0006(r5)                         |r2 = Target's Tile 0x06 byte
0017b9c0: 00000000 nop                                       |
0017b9c4: 30420001 andi r2,r2,0x0001                         |r2 = 0x01 if tile is unselectable
0017b9c8: 10400003 beq r2,r0,0x0017b9d8                      #If tile is unselectable /Else branch to avoid routine exit
0017b9cc: 00000000 nop                                           | 
0017b9d0: 0805ef14 j 0x0017bc50                                  >>jump to END  (with r2 = -0x01)
0017b9d4: 2402ffff addiu r2,r0,-0x0001                           |r2 = -0x01
0017b9d8: 90a40002 lbu r4,0x0002(r5)                         #Else (Tile is valid) r4 = Target tile Height
0017b9dc: 90a30003 lbu r3,0x0003(r5)                             |r3 = Target tile halves + depht
0017b9e0: 90a20003 lbu r2,0x0003(r5)                             |r2 = Target tile halves + depht
0017b9e4: 00042040 sll r4,r4,0x01                                |r4 = Target tile Height * 2
0017b9e8: 3063001f andi r3,r3,0x001f                             |r3 = Target tile halves
0017b9ec: 00832021 addu r4,r4,r3                                 |r4 = Target Tile  (height*2) +  halves
0017b9f0: 00021142 srl r2,r2,0x05                                |r2 = Target Tile effective depht (0x20 becomes 0x01 / 0x80 becomes 0x04)
0017b9f4: 00021040 sll r2,r2,0x01                                |r2 = Target Tile depht * 2
0017b9f8: 00829021 addu r18,r4,r2                                |r18 = Target Tile Total Height
0017b9fc: 326300ff andi r3,r19,0x00ff                            |r3 = Attacker used Ability AoE last byte (=AoE)
0017ba00: 340200ff ori r2,r0,0x00ff                              |r2 = 0xff
0017ba04: 1462000c bne r3,r2,0x0017ba38                          #If AoE = 255
0017ba08: 00002021 addu r4,r0,r0                                     |r4 = 0x00 (loop counter)
0017ba0c: 34050001 ori r5,r0,0x0001                                  |r5 = 0x01
0017ba10: 3c038019 lui r3,0x8019                                     |r3 = 0x80190000
0017ba14: 24632dd8 addiu r3,r3,0x2dd8                                |r3 = Targetable grid data pointer  0x80192dd8
0017ba18: a0650000 sb r5,0x0000(r3)                                  @Loop (all grid panels) Store AoE = 0x01
0017ba1c: a0600001 sb r0,0x0001(r3)                                      |Nullify Targetable panel targeted flag (byte 0x01 = 0x00)
0017ba20: 24840001 addiu r4,r4,0x0001                                    |r4 = Counter + 1
0017ba24: 28820200 slti r2,r4,0x0200                                     |r2 = 0x01 while r4 <0x200
0017ba28: 1440fffb bne r2,r0,0x0017ba18                              Λ Loop While Counter < 0x200 #(All tiles)
0017ba2c: 24630005 addiu r3,r3,0x0005                                    |r3 = Targetable grid panel counter
0017ba30: 0805eebf j 0x0017bafc                                      >>jump after AoE < 255 section
0017ba34: 00000000 nop                                               |
0017ba38: 3c038019 lui r3,0x8019                                 #Else (AoE < 255) r3 = 0x80190000
0017ba3c: 24632dd8 addiu r3,r3,0x2dd8                                |r3 = Targetable grid data pointer  0x80192dd8
0017ba40: a0600000 sb r0,0x0000(r3)                                  @LOOP (all grid panels) Store AoE = 0x00
0017ba44: a0600001 sb r0,0x0001(r3)                                      |Store panel targeted flag = 0x00
0017ba48: 24840001 addiu r4,r4,0x0001                                    |r4 = counter + 1
0017ba4c: 28820200 slti r2,r4,0x0200                                     |r2 = 0x01 while counter < 0x200
0017ba50: 1440fffb bne r2,r0,0x0017ba40                              Λ Loop while counter < 0x200
0017ba54: 24630005 addiu r3,r3,0x0005                                    |r3 = Targetable grid tile counter
0017ba58: 00061080 sll r2,r6,0x02                                    |r2 = Targeted Tile ID *4
0017ba5c: 00461821 addu r3,r2,r6                                     |r2 = Targeted Tile ID *5
0017ba60: 3c048019 lui r4,0x8019                                     |r4 = 0x80190000
0017ba64: 24842dd8 addiu r4,r4,0x2dd8                                |r4 = 0x80192dd8 Moveable/Targetable Panel Grid
0017ba68: 00644021 addu r8,r3,r4                                     |r8 = Targeted Panel grid data pointer
0017ba6c: 26620001 addiu r2,r19,0x0001                               |r2 =AoE + 1
0017ba70: a1020000 sb r2,0x0000(r8)                                  |Store AoE +1 in at Targeted Panel 0x00
0017ba74: 28c20100 slti r2,r6,0x0100                                 |r2 = 0x01 if Targeted panel is on lower elevation
0017ba78: 10400005 beq r2,r0,0x0017ba90                              #If Target panel is on lower elevation
0017ba7c: 24820500 addiu r2,r4,0x0500                                    |r2 = 0x801932d8 Start of higher elevation grid on Targetable panel grid (0x100 * 5)
0017ba80: 00623821 addu r7,r3,r2                                         |r7 = Above panel data pointer
0017ba84: 34020001 ori r2,r0,0x0001                                      |r2 = 0x01 
0017ba88: 0805eea8 j 0x0017baa0                                          >>jump just after Else section
0017ba8c: a1020001 sb r2,0x0001(r8)                                      |Flag lower Targeted panel 0x0001 (= green flag)
0017ba90: 2482fb00 addiu r2,r4,-0x0500                               #Else (Targeted panel is on higher elevation) r2 = 0x801928d8  (0x500 byte before start of Targetable grid data)
0017ba94: 00623821 addu r7,r3,r2                                         |r7 = Below panel data pointer
0017ba98: 34020001 ori r2,r0,0x0001                                      |r2 = 0x01
0017ba9c: a0e20001 sb r2,0x0001(r7)                                      |Flag lower Targeted panel 0x0001 (= green flag)
0017baa0: 30c300ff andi r3,r6,0x00ff                                 |r3 = Tile coordinates without elevation (+ 0x100) = [Tile ground coordinate]
0017baa4: 00031080 sll r2,r3,0x02                                    |r2 = [Tile ground coordinate] * 4
0017baa8: 00431021 addu r2,r2,r3                                     |r2 = [Tile ground coordinate] * 5
0017baac: 34030001 ori r3,r0,0x0001                                  |r3 = 0x01
0017bab0: 3c018019 lui r1,0x8019                                     |r1 = 0x80190000
0017bab4: 00220821 addu r1,r1,r2                                     |r1 = 0x80190000 + Offset for targetable grid
0017bab8: a0232dd9 sb r3,0x2dd9(r1)                                  |Store 0x01 at Lower high targeted panel 0x01 (redundant ?)
0017babc: 31220020 andi r2,r9,0x0020                                 |r2 = 0x20 if Attacker used Ability has flag weapon range
0017bac0: 1440000e bne r2,r0,0x0017bafc                              #If Attacker used ability is NOT weapon ranged
0017bac4: 02602021 addu r4,r19,r0                                        |r4 = AoE
0017bac8: 00002821 addu r5,r0,r0                                         |r5 = 0x00
0017bacc: 26620001 addiu r2,r19,0x0001                                   |r2 = AoE + 1
0017bad0: a1020000 sb r2,0x0000(r8)                                      |Store AoE +1 At Targeted panel AoE (grid)
0017bad4: 0c05e546 jal 0x00179518                                        |-->Calculate_Tiles_Hit_by_Ability Spread AoE on Targetable grid panels
0017bad8: a0e20000 sb r2,0x0000(r7)                                      |Store AoE +1 At Other Elevation Panel AoE (grid)
0017badc: 324400ff andi r4,r18,0x00ff                                    |r4 = Target Tile Total Height
0017bae0: 02a02821 addu r5,r21,r0                                        |r5 = Attacker used Ability vertical tolerance
0017bae4: 00113142 srl r6,r17,0x05                                       |r6 = Attacker used Ability Top Down, Hit Enemy/Ally flags
0017bae8: 0c05e4a9 jal 0x001792a4                                        |--> Check Vert Tolerance and if Tiles can be Chosen  Nullify panel AoE and 0x01 flag if vertical tolerance is overwhelmed
0017baec: 30c60001 andi r6,r6,0x0001                                     |r6 = 0x01 if Attacker used Ability Top Down flag is ON
0017baf0: 87a40012 lh r4,0x0012(r29)                                     |r4 = Attacker used Ability ID
0017baf4: 0c05e481 jal 0x00179204                                        |-->Moldball Virus Depth Check  Nullify panel AoE and 0x01 flag if target tile depht <> 0x00
0017baf8: 00000000 nop                                                   |
0017bafc: 0c060428 jal 0x001810a0                                |-->Map Location Calculation (Caster) return r2 = Attacker Tile ID
0017bb00: 02002021 addu r4,r16,r0                                |r4 = Attacker data pointer
0017bb04: 00021880 sll r3,r2,0x02                                |r3 = caster tile ID * 4
0017bb08: 00621821 addu r3,r3,r2                                 |r3 = caster tile ID * 5
0017bb0c: 3c128019 lui r18,0x8019                                |r18 = 0x80190000
0017bb10: 26522dd8 addiu r18,r18,0x2dd8                          |r18 = Targetable grid data pointer (0x80192dd8)
0017bb14: 32220001 andi r2,r17,0x0001                            |r2 = 0x01 if Attacker used Ability hit caster is not checked
0017bb18: 10400002 beq r2,r0,0x0017bb24                          #If Attacker used Ability do not hit caster
0017bb1c: 00721821 addu r3,r3,r18                                |r3 = Attacker Targetable panel data pointer
0017bb20: a0600000 sb r0,0x0000(r3)                                  |Nullify Targetable panel AoE flag
0017bb24: 32220004 andi r2,r17,0x0004                            |r2 = 0x04 if Attacker used Ability is linear
0017bb28: 10400003 beq r2,r0,0x0017bb38                          #If Attacker used Ability is a linear attack  /Else branch to 3 direction check
0017bb2c: 27a40010 addiu r4,r29,0x0010                               |r4 = Stack 0x10
0017bb30: 0c05ef9a jal 0x0017be68                                    |-->Linear/3-direction_AoE_Calculation Only keep AoE of lined up panels
0017bb34: 34050001 ori r5,r0,0x0001                                  |r5 = 0x01 (linear ability)
0017bb38: 32220002 andi r2,r17,0x0002                            |r2 = 0x02 if Attacker used Ability is 3 directions
0017bb3c: 10400004 beq r2,r0,0x0017bb50                          #If Attacker used Ability is a 3 directional attack /Else branch toAvoid unit check
0017bb40: 323000c0 andi r16,r17,0x00c0                           |r16 <> 0x00 if Ability avoid enemy or ally (when hit ally or hit enemy is checked in patcher, the flag is set to 0x00)
0017bb44: 27a40010 addiu r4,r29,0x0010                               |r4 = Stack 0x10
0017bb48: 0c05ef9a jal 0x0017be68                                    |-->Linear/3-direction_AoE_Calculation Only keep AoE of lined up panels
0017bb4c: 34050003 ori r5,r0,0x0003                                  |r5 = 0x03 (3 direction ability)
0017bb50: 12000006 beq r16,r0,0x0017bb6c                         #If Ability Ignore Ally or Enemy unit
0017bb54: 02802021 addu r4,r20,r0                                    |r4 = Attacker ID
0017bb58: 32250080 andi r5,r17,0x0080                                |r5 = 0x80 if Ability avoid enemy units
0017bb5c: 32260040 andi r6,r17,0x0040                                |r6 = 0x40 if Ability avoid ally units
0017bb60: 3a6700ff xori r7,r19,0x00ff                                |r7 = Ability not AoE (every bits but thoses in AoE value)
0017bb64: 0c05ef1e jal 0x0017bc78                                    |-->Check_Allies/Enemies_that_can_be_Targeted
0017bb68: 2ce70001 sltiu r7,r7,0x0001                                |r7 = 0x01 if AoE was 255 (255 xor 255 = 0x00 (so < 0x01))
0017bb6c: 1600001d bne r16,r0,0x0017bbe4                         #If Ability Hits everybody
0017bb70: 00003021 addu r6,r0,r0                                     |r6 = 0x00 r6 = Targeted Panel Counter
0017bb74: 00002021 addu r4,r0,r0                                     |r4 = 0x00 r4 = Tile Counter
0017bb78: 02402821 addu r5,r18,r0                                    |r5 = Targetable grid data pointer  0x80192dd8
0017bb7c: 3c038019 lui r3,0x8019                                     |
0017bb80: 2463f8cc addiu r3,r3,-0x0734                               |r3 = Tile data pointer
0017bb84: 90a20000 lbu r2,0x0000(r5)                                 @LOOP through all tiles/panels r2 = This iteration panel AoE
0017bb88: 00000000 nop                                                   | 
0017bb8c: 1040000a beq r2,r0,0x0017bbb8                                  #If This iteration panel AoE > 0x00 /Else branch to nullify flag 0x01
0017bb90: 00000000 nop                                                       | 
0017bb94: 90620006 lbu r2,0x0006(r3)                                         |r2 = Tile 0x06
0017bb98: 00000000 nop                                                       |
0017bb9c: 30420003 andi r2,r2,0x0003                                         |r2 <> 0x00 if tile is unselectable or untargetable
0017bba0: 14400005 bne r2,r0,0x0017bbb8                                      #If tile is targetable/selectable /Else branch to nullify flag 0x01
0017bba4: 00000000 nop                                                           | 
0017bba8: 90620005 lbu r2,0x0005(r3)                                             |r2 = Tile 0x05
0017bbac: 24c60001 addiu r6,r6,0x0001                                            |r6 = Targeted panel counter + 1
0017bbb0: 0805eef1 j 0x0017bbc4                                                  >>jump to tile 0x05 flag update
0017bbb4: 34420080 ori r2,r2,0x0080                                              |r2 = Tile 0x05 + "Green panel" enabled
0017bbb8: 90620005 lbu r2,0x0005(r3)                                     #Else (AoE = 0x00 or invalid tile) r2 = Tile 0x05
0017bbbc: 00000000 nop                                                           | 
0017bbc0: 3042007f andi r2,r2,0x007f                                             |r2 = Tile 0x05 without "Green panel"
0017bbc4: a0620005 sb r2,0x0005(r3)                                      |Store updated byte (with or without "Green panel") at tile 0x05
0017bbc8: 24a50005 addiu r5,r5,0x0005                                    |r5 = Panel counter + 5 (5 = size of panels data)
0017bbcc: 24840001 addiu r4,r4,0x0001                                    |r4 = loop counter
0017bbd0: 28820200 slti r2,r4,0x0200                                     |r2 = 0x01 if counter < 0x200
0017bbd4: 1440ffeb bne r2,r0,0x0017bb84                              Λ loop while counter < 0x200
0017bbd8: 24630008 addiu r3,r3,0x0008                                    |r3 = Tile counter + 8 (8 = size of tiles data)
0017bbdc: 0805ef14 j 0x0017bc50                                      >>jump to END
0017bbe0: 00c01021 addu r2,r6,r0                                     |r2 = Number of targeted panels
0017bbe4: 00002021 addu r4,r0,r0                                 #Else (Ability ignores Allies or Enemies) r4 = Tile Counter
0017bbe8: 02402821 addu r5,r18,r0                                    |r5 = Targetable grid data pointer  0x80192dd8
0017bbec: 3c038019 lui r3,0x8019                                     |
0017bbf0: 2463f8cc addiu r3,r3,-0x0734                               |r3 = Tile data pointer
0017bbf4: 90a20001 lbu r2,0x0001(r5)                                 @LOOP though all tile/panel r2 = This iteration targetable panel targeted flag
0017bbf8: 00000000 nop                                                   | 
0017bbfc: 1040000a beq r2,r0,0x0017bc28                                  #If this panel is targeted (flag 0x01 = 0x01)
0017bc00: 00000000 nop                                                       | 
0017bc04: 90620006 lbu r2,0x0006(r3)                                         |r2 = This iteration Tile 0x06 byte
0017bc08: 00000000 nop                                                       |
0017bc0c: 30420003 andi r2,r2,0x0003                                         |r2 <> 0x00 if this tile is not selectable/targetable
0017bc10: 14400005 bne r2,r0,0x0017bc28                                      #If This tile is selectable/targetable
0017bc14: 00000000 nop                                                           | 
0017bc18: 90620005 lbu r2,0x0005(r3)                                             |r2 = This tile 0x05 byte
0017bc1c: 24c60001 addiu r6,r6,0x0001                                            |r6 = Targeted panel counter
0017bc20: 0805ef0d j 0x0017bc34                                                  >>jump to tile 0x05 flag update
0017bc24: 34420080 ori r2,r2,0x0080                                              |r2 = This tile 0x05 byte updated with "green panel" flag
0017bc28: 90620005 lbu r2,0x0005(r3)                                     #Else (panel not targeted or unvalid tile) r2 = This tile 0x05 byte
0017bc2c: 00000000 nop                                                       | 
0017bc30: 3042007f andi r2,r2,0x007f                                         |r2 = Tile 0x05 without "Green panel"
0017bc34: a0620005 sb r2,0x0005(r3)                                      |Store updated byte 0x05 on Tile data
0017bc38: 24a50005 addiu r5,r5,0x0005                                    |r5 = Panel counter + 5 (size of panels data)
0017bc3c: 24840001 addiu r4,r4,0x0001                                    |r4 = loop counter
0017bc40: 28820200 slti r2,r4,0x0200                                     |r2 = 1 while counter < 0x200
0017bc44: 1440ffeb bne r2,r0,0x 0017bbf4                             Λ Loop while counter < 0x200
0017bc48: 24630008 addiu r3,r3,0x0008                                    |r3 = Tile counter + 8 (8 = size of tiles data)
0017bc4c: 00c01021 addu r2,r6,r0                                     |r2 = Targeted panel counter
0017bc50: 8fbf0040 lw r31,0x0040(r29)      END                           
0017bc54: 8fb5003c lw r21,0x003c(r29)                                
0017bc58: 8fb40038 lw r20,0x0038(r29)                                
0017bc5c: 8fb30034 lw r19,0x0034(r29)                                
0017bc60: 8fb20030 lw r18,0x0030(r29)                                
0017bc64: 8fb1002c lw r17,0x002c(r29)                                
0017bc68: 8fb00028 lw r16,0x0028(r29)                                
0017bc6c: 27bd0048 addiu r29,r29,0x0048                              
0017bc70: 03e00008 jr r31                                            
0017bc74: 00000000 nop

Notes

Tile will refer at 0x8018f8cc data (size per tile = 0x08)
Panel will refer at 0x80192dd8 data (size per panel = 0x05)

1st part : set targeted tile X, Y and elevation
- if ability stops at obstacle : Force the weapon ranged flag ON
                                 Force Hit caster, linear and 3 directions OFF
- if Ability is linear or 3 direction : use Attacker coordinate instead of targeted tile 
                                        (in those abilities range = AoE, the Extra AoE will be deleted later)
- if Ability is not linear nor 3 directions : uses Attacker 0x178 data.(see Attacker 0x178 notes)
     - if Attacker 0x178 = 0x06 : uses Targeted Tile Coordinates (Attacker 0x17a, 0x17c and 0x17e)   
     - if Attacker 0x178 <> 0x06 : uses Target ID to get his coordinates (Target 0x47, 0x48, 0x49)

Exits if Targeted coordinates are invalid

2nd part : spread AoE
- If AoE = 255 : Store AoE = 0x01 and Targeted = 0x00 in all panels
- If AoE <> 255 : - first nullify all panels AoE and Targeted flag
                  - Set Targeted panel AoE = Ability AoE + 1 (both elevation)
                  - if Ability is not weapon ranged
                        - Spread AoE on panels Calculate_Tiles_Hit_by_Ability (while spreading set panels 0x01 byte to 0x00)
                        - Check for vertical tolerance (nullify AoE off panels out of range) Check Vert Tolerance and if Tiles can be Chosen
                        - If Moldball virus, nullify AoE if panel as depth > 0 Moldball Virus Depth Check
 
** At this point - Targetable valid panels have their AoE > 0 and targeted flag (0x01) set to 0x00 **
 
3rd part : adapt AoE on specific cases
- if Ability do not hit caster : nullify caster panel AoE
- if Ability is linear : Nullify AoE of panels not lined up with Attacker and Targeted tile Linear/3-direction_AoE_Calculation
- if Ability is 3 direction : Same as linear, keep 2 other directions Linear/3-direction_AoE_Calculation
- if Ability ignore allies/ennemies : Check_Allies/Enemies_that_can_be_Targeted
        - Test all units : - if Unit on panel is ignored : AoE panel is set to 0x00
                           - if Unit on panel is not ignored : panel 0x01 byte is set to 0x01 and kept this way
        - Test all panels : if panel AoE > 1 set panel 0x01 byte to 0x01
		 
4rd part : test all tiles : count targeted panel and activate "green panel" flag (tile 0x05 byte)
- if Ability Hits every team : - if panel AoE > 0x00
                                      - if Tile is not selectable/targetable (tile 0x06 byte) - Tile 0x05 is forced without the 0x80 value
                                      - if Tile is valid Tile is counted and Tile 0x05 Green Panel flag is set (0x80)
                               - if panel AoE = 0x00, matching Tile 0x05 is forced without the 0x80 value
								
- if Ability Ignores a team : - if panel 0x01 flag is <> 0x00
                                 - if Tile is not selectable/targetable (tile 0x06 byte) then Tile 0x05 is forced without the 0x80 value	
                                 - if Tile is valid then Tile is counted and Tile 0x05 Green Panel flag is set (0x80)
                              - if panel 0x01 flag = 0x00 then Tile 0x05 is forced without the 0x80 value

Panel state after routine
- Valid Targetable Panels has their AoE > 0x00
- Panels keeps their 0x01 flags only if Ability ignores a team
- When ability ignore a team : Panels beyond range, may have their 0x01 flags = 0x01 and AoE = 0

Notes :
- AoE value is higher at the center and decrease while spreading. Panel with AoE = 0x01 are on the borders of the AoE
 or at the end of the "beam" of a linear attack. This could be used to decrease damage or anything else.
 The only exception is for Ability with AoE = 255 where all the panel has their AoE = 0x01.

Attacker 0x178 notes

In the actual table data location page this byte is known as reaction ID ?. 
 - The value 0x06 seems to be related to Target specific ability (follow target)
 - The value 0x05 might be for Tile specific ability (cast on a tile, do not follow unit)

Here are the notes i found on this routine page before formatting it. I'm not able yet to determine if it's accurate.
*0x001a - Modified in (0074308) where value is set to 05 if Unit is under player control (ENTD 08) or if Unit ID = 2 (0x0168 of Misc Unit Data (0b7308)).
I have no idea if 0x0168 is actually Unit ID and I suspect not (doesn't really seem to coordinate with Unit IDs in ENTD), but it is cycled through and changed constantly during the AI's decision making process. It could otherwise very well be the decision value or the AI derived Unit ID aka Battle ID?
Otherwise 0x001a is usually 06. I don't know the significance of 04 (Miming action?), but 02 = Player Control, 01 = AI Control. I've only ever seen 05 or 06 when the process comes here. Perhaps if it's not 04, it doesn't come here at all?
Complete guesswork on my part here, but 04 might be tied to Action Menu flags (If not Default/Elemental/Monster/etc., or any skillset type that doesn't normally take AoE, then don't even go to (0074308)?
 Anyways, 0x001a is important because the AI has to get the targeted unit, then determine it's X,Y. Player Controlled Units already have the X,Y loaded into the stack.

Return location

0017ac40: Calculate_Targeting_for_Menu_Types