Linear Attack Tile Calculation

From Final Fantasy Hacktics Wiki
Revision as of 21:42, 8 February 2022 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
0017c044 - 0017c154

Parameters: r4 = Set value = Attack direction
            r5 = Attacker X coord
            r6 = Attacker Y coord

The routine Will loop through 32 panels (max) in attack direction, setting their targeted flag (byte 0x01) "ON"  (= 0x01) if their AoE is > 0.
Note that the Ability using linear attack has their AoE = their range
----------------------------------------------------------------------------------------
0017c044: 34020002 ori r2,r0,0x0002         |r2 = 0x02 r6 = Attacker's Y coord
0017c048: 10820010 beq r4,r2,0x0017c08c     #If Direction <> 0x02 #Branch if Direction = 2
0017c04c: 28820003 slti r2,r4,0x0003             |r2 = 0x01 if r4 < 0x03
0017c050: 10400005 beq r2,r0,0x0017c068          #If Direction < 0x03 (0X00 or 0x01) #Branch if Direction >= 3
0017c054: 00000000 nop                               | 
0017c058: 1080000a beq r4,r0,0x0017c084              #If Direction <> 0x00 (= 0x01) #Branch if Direction = 0
0017c05c: 34090001 ori r9,r0,0x0001                  |r9 = 0x01 
0017c060: 0805f054 j 0x0017c150                          >>Jump to END
0017c064: 00000000 nop                                   |
0017c068: 34020004 ori r2,r0,0x0004              #Else (Direction > 0x03) r2 = 0x04
0017c06c: 1082000c beq r4,r2,0x0017c0a0              #If Direction <> 0x04 #Branch if Direction = 4
0017c070: 34020006 ori r2,r0,0x0006                  |r2 = 0x06
0017c074: 10820008 beq r4,r2,0x0017c098                  #If direction <> 0x06 (= 0x03 or 0x05) #Branch if Direction = 6
0017c078: 00004821 addu r9,r0,r0                         |r9 = 0x00
0017c07c: 0805f054 j 0x0017c150                              >>Jump to END
0017c080: 00000000 nop                                       |

                            --- Direction is set (0x00, 0x02, 0x04 or 0x06) : Now set X and Y mod ---

0017c084: 0805f02a j 0x0017c0a8             #Direction = 0x00 >>Jump to LOOP ( X mod = +1 / Y mod = 0)
0017c088: 00004021 addu r8,r0,r0                 |r8 = 0x00
0017c08c: 2409ffff addiu r9,r0,-0x0001      #Direction = 0x02 r9 = -0x01
0017c090: 0805f02a j 0x0017c0a8                  >>Jump to LOOP ( X mod = -1 / Y mod = 0)
0017c094: 00004021 addu r8,r0,r0                 |r8 = 0x00
0017c098: 0805f02a j 0x0017c0a8             #Direction = 0x06 >>Jump to LOOP ( X mod = 0 / Y mod = 1)
0017c09c: 34080001 ori r8,r0,0x0001              |r8 = 0x00
0017c0a0: 00004821 addu r9,r0,r0            #Direction = 0x04 r9 = 0x00 (X mod)
0017c0a4: 2408ffff addiu r8,r0,-0x0001           |r8 = -0x01 (Y mod)

                            --- X mod and Y mod are set : Now loop in the right direction ---

0017c0a8: 00003821 addu r7,r0,r0            |r7 = 0x00 (Loop counter)
0017c0ac: 3c0b8019 lui r11,0x8019           |
0017c0b0: 256b2dd8 addiu r11,r11,0x2dd8     |r11 = Targetable grid data pointer
0017c0b4: 340a0001 ori r10,r0,0x0001        |r10 = 0x01
0017c0b8: 04a00025 bltz r5,0x0017c150       @LOOP #If Attacker X coord is >= 0x00 /Else branch to END First iteration, it's Attacker coordinates
0017c0bc: 00000000 nop                               | 
0017c0c0: 3c03800e lui r3,0x800e                     |
0017c0c4: 90634e9c lbu r3,0x4e9c(r3)                 |r3 = Map Max X  0x800e49ec
0017c0c8: 00000000 nop                               |
0017c0cc: 00a3102a slt r2,r5,r3                      |r2 = 0x01 if Attacker X coord < Map Max X
0017c0d0: 1040001f beq r2,r0,0x0017c150              #If Attack X coord < Map Max X /Else Branch to END 
0017c0d4: 00000000 nop                                   | 
0017c0d8: 04c0001d bltz r6,0x0017c150                    #If Attack Y coord < 0x00 /Else Branch to END 
0017c0dc: 00000000 nop                                       | 
0017c0e0: 3c02800e lui r2,0x800e                             | 
0017c0e4: 90424ea0 lbu r2,0x4ea0(r2)                         |r2 = Map Max Y 0x800e4ea0
0017c0e8: 00000000 nop                                       |
0017c0ec: 00c2102a slt r2,r6,r2                              |r2 = 0x01 if Attack Y coord < Map Max Y
0017c0f0: 10400017 beq r2,r0,0x0017c150                      #If Attack Y coord < Map Max Y /Else Branch to END 
0017c0f4: 00c30018 mult r6,r3                                    |Attack Y coord * Max X
0017c0f8: 00001012 mflo r2                                       |r2 =  Attack Y coord * Max X
0017c0fc: 00452021 addu r4,r2,r5                                 |r4 =  Attack X coord + Attack Y coord * Max X = Lower elevation tile ID
0017c100: 00041080 sll r2,r4,0x02                                |r2 = Lower Tile ID * 4
0017c104: 00441021 addu r2,r2,r4                                 |r2 = Lower Tile ID * 5 (5 = Size of targetable panel data)
0017c108: 004b1821 addu r3,r2,r11                                |r3 = Lower Targetable panel data pointer
0017c10c: 90620000 lbu r2,0x0000(r3)                             |r2 =  Lower elevation panel's AoE
0017c110: 00000000 nop                                           |
0017c114: 10400002 beq r2,r0,0x0017c120                          #If Lower elevation panel's AoE <> 0x00 /Else Avoid update of panel targeted flag
0017c118: 24840100 addiu r4,r4,0x0100                            |r4 = Tile ID + 0x100 (higher elevation tile ID)
0017c11c: a06a0001 sb r10,0x0001(r3)                                 |Set Lower Targetable panel targeted flag "ON" (byte [0x01] = 0x01)
0017c120: 00041080 sll r2,r4,0x02                                |r2 = Higher Tile ID *4
0017c124: 00441021 addu r2,r2,r4                                 |r2 = Higher Tile ID *5  (5 = Size of targetable panel data)
0017c128: 004b1821 addu r3,r2,r11                                |r3 = Higher Targetable panel data pointer
0017c12c: 90620000 lbu r2,0x0000(r3)                             |r2 =  Higher elevation panel's AoE
0017c130: 00000000 nop                                           |
0017c134: 10400002 beq r2,r0,0x0017c140                          #If Lower elevation panel's AoE <> 0x00 #Branch if High AoE = 0
0017c138: 00c83021 addu r6,r6,r8                                 |r6 = Attack Y + Y mod
0017c13c: a06a0001 sb r10,0x0001(r3)                                 |Set Higher Targetable panel targeted flag "ON" (byte [0x01] = 0x01)
0017c140: 24e70001 addiu r7,r7,0x0001                            |r7 = loop counter + 1
0017c144: 28e20020 slti r2,r7,0x0020                             |r2 = 0x01 if counter < 0x20 
0017c148: 1440ffdb bne r2,r0,0x0017c0b8     Λ Loop while counter < 0x20
0017c14c: 00a92821 addu r5,r5,r9                                 |r5 = Attack X coord + X mod
0017c150: 03e00008 jr r31                   END
0017c154: 00000000 nop                      

Return location

0017bee0: Linear/3-direction_AoE_Calculation
0017bf00: Linear/3-direction_AoE_Calculation
0017bf10: Linear/3-direction_AoE_Calculation
0017bf28: Linear/3-direction_AoE_Calculation
0017bf48: Linear/3-direction_AoE_Calculation
0017bf58: Linear/3-direction_AoE_Calculation
0017bf70: Linear/3-direction_AoE_Calculation
0017bf90: Linear/3-direction_AoE_Calculation
0017bfa0: Linear/3-direction_AoE_Calculation
0017bfb8: Linear/3-direction_AoE_Calculation
0017bfd8: Linear/3-direction_AoE_Calculation
0017bfe8: Linear/3-direction_AoE_Calculation