Calculate Tiles Hit by Ability

From Final Fantasy Hacktics Wiki
Revision as of 13:59, 6 February 2022 by Orkney (talk | contribs)
Jump to navigation Jump to search
00179518 - 00179638
Parameters : r4 = Ability AoE             

This routine will spread the AoE out of the targeted tile (see Notes)
--------------------------------------------------------------------
00179518: 27bdffb8 addiu r29,r29,-0x0048    |
0017951c: afb40038 sw r20,0x0038(r29)       |
00179520: 0080a021 addu r20,r4,r0           |r20 = AoE r20 = Range
00179524: 328200ff andi r2,r20,0x00ff       |r2 = AoE r2 = Range if non-zero (negative?)
00179528: afbf0040 sw r31,0x0040(r29)       |
0017952c: afb5003c sw r21,0x003c(r29)       |
00179530: afb30034 sw r19,0x0034(r29)       |
00179534: afb20030 sw r18,0x0030(r29)       |
00179538: afb1002c sw r17,0x002c(r29)       |
0017953c: 14400005 bne r2,r0,0x00179554     #If AoE = 0 /Else avoid nullification and exit
00179540: afb00028 sw r16,0x0028(r29)            | 
00179544: 0c05e500 jal 0x00179400                |-->Null_some_Tile_Data_(192dd9) Set all targetable panel's 0x01 flag to 0x00 (green flag)
00179548: 00000000 nop                           |
0017954c: 0805e585 j 0x00179614                  >>Jump to END
00179550: 00000000 nop                           |
00179554: 34120001 ori r18,r0,0x0001        #Else (AoE <> 0) r18 = 0x01 (r18 is set to 0x00 when AoE is completely spread)
00179558: 1040002e beq r2,r0,0x00179614          #If AoE <> 0 (redundant ?) / Else branch to END
0017955c: 00009821 addu r19,r0,r0                    |r19 = 0x00 - AoE loop counter
00179560: 3c158019 lui r21,0x8019                    |r21 = 0x80190000
00179564: 26b52dd8 addiu r21,r21,0x2dd8              |r21 = 0x801902dd8 Moveable/Targetable Panel Grid
00179568: 1240002a beq r18,r0,0x00179614             @LOOP Spread AoE #If r18 <> 0x00 / Else branch to END
0017956c: 00009021 addu r18,r0,r0                        |r18 = 0
00179570: 3c02800e lui r2,0x800e                         |r2 =0x800e0000
00179574: 90424ea0 lbu r2,0x4ea0(r2)                     |r2 = Max Map Y
00179578: 00000000 nop                                   |
0017957c: 18400020 blez r2,0x00179600                    #If Map Max Y > 0x00 /Else branch to next loop 1 iteration
00179580: 00008821 addu r17,r0,r0                        |r17 = 0x00 (Y Counter)
00179584: 3c03800e lui r3,0x800e                             @LOOP through Y coord r3 = 0x800e0000
00179588: 90634e9c lbu r3,0x4e9c(r3)                             |r3 = Map Max X
0017958c: 00000000 nop                                           |
00179590: 10600015 beq r3,r0,0x001795e8                          #If Map Max X <> 0x00
00179594: 00008021 addu r16,r0,r0                                |r16 = 0x00 (X Counter)
00179598: 02230018 mult r17,r3                                   |Y Counter * Max X
0017959c: 00001012 mflo r2                                       @LOOP through X coord r2 = Y counter * Max X
001795a0: 00501021 addu r2,r2,r16                                    |r2 = Y Counter * Max X + X Counter (= Tile ID without elevation)
001795a4: 00021880 sll r3,r2,0x02                                    |r3 = Tile ID *4
001795a8: 00621821 addu r3,r3,r2                                     |r3 = Tile ID *5
001795ac: 00751821 addu r3,r3,r21                                    |r3 = Tile ID *5 + Targetable grid offset
001795b0: 90620001 lbu r2,0x0001(r3)                                 |r2 = Targetable grid panel 0x01 data corresponding to tile ID
001795b4: 00000000 nop                                               |
001795b8: 10400005 beq r2,r0,0x001795d0                              #If pannel is targeted (=0x01) /Else branch
001795bc: 02202021 addu r4,r17,r0                                        |r4 = Y Counter (Y coord of tile matching targeted panel)
001795c0: a0600001 sb r0,0x0001(r3)                                      |Store 0x00 at panel 0x01 (Remove Targeting flag)
001795c4: 0c05e58f jal 0x0017963c                                        |-->Calculate_Possible_AoE_Tiles Spread AoE in surrounding tiles, return r2 = 0x01 is AoE is not ended
001795c8: 02002821 addu r5,r16,r0                                        |r5 = X Counter (X coord of tile matching targeted panel)
001795cc: 02429021 addu r18,r18,r2                                       |r18 = 0x01 if AoE need to spread again
001795d0: 3c03800e lui r3,0x800e                                     |r3 = 0x800e0000
001795d4: 90634e9c lbu r3,0x4e9c(r3)                                 |r3 = Map Max X
001795d8: 26100001 addiu r16,r16,0x0001                              |r16 = X Counter + 1
001795dc: 0203102a slt r2,r16,r3                                     |r3 = 0x01 if counter < Map Max X
001795e0: 1440ffee bne r2,r0,0x0017959c                          Λ Loop while X counter < Map Max X
001795e4: 02230018 mult r17,r3                                       |Y Counter * Max X (mflo at the beginning of the loop)
001795e8: 3c02800e lui r2,0x800e                                 |r2 = 0x800e0000
001795ec: 90424ea0 lbu r2,0x4ea0(r2)                             |r2 = Map Max Y
001795f0: 26310001 addiu r17,r17,0x0001                          |r1 = Y counter + 1
001795f4: 0222102a slt r2,r17,r2                                 |r2 = 0x01 If Y Counter < Max Y
001795f8: 1440ffe2 bne r2,r0,0x00179584                      Λ Loop while Y counter < max Y
001795fc: 00000000 nop                                           | 
00179600: 26730001 addiu r19,r19,0x0001                  |r19 = AoE counter + 1
00179604: 328200ff andi r2,r20,0x00ff                    |r2 = Base AoE
00179608: 0262102a slt r2,r19,r2                         |r2 = 0x01 While Counter < AoE value
0017960c: 1440ffd6 bne r2,r0,0x00179568              Λ Loop until AoE is spread
00179610: 00000000 nop                               | 
00179614: 8fbf0040 lw r31,0x0040(r29)                |
00179618: 8fb5003c lw r21,0x003c(r29)                |
0017961c: 8fb40038 lw r20,0x0038(r29)                |
00179620: 8fb30034 lw r19,0x0034(r29)                |
00179624: 8fb20030 lw r18,0x0030(r29)                |
00179628: 8fb1002c lw r17,0x002c(r29)                |
0017962c: 8fb00028 lw r16,0x0028(r29)                |
00179630: 27bd0048 addiu r29,r29,0x0048              |
00179634: 03e00008 jr r31                            |
00179638: 00000000 nop                               |

Notes

This routine will spread the AoE around the targeted tile.
It will use the  targetable grid to store AoE (0x00) and targeted status (0x01)
Each time the AoE spread, it will decrease the AoE value stored in the panel 0x00 by one. (via Calculate_Possible_AoE_Tiles)

1st Loop : test each panel of the targetable grid. Each iteration of this loop increase a counter.Loop occurs while counter < Base AoE value
While looping each X coord is tested for each Y coord (elevation is handled in Calculate_Possible_AoE_Tiles)
If the targeted flag is on (panel 0x01 <> 0x00) AoE spreads via Calculate_Possible_AoE_Tiles

Note : this is Calculate_Possible_AoE_Tiles routine which set the targeted flag ON, while there's still AoE to spread.

Rq : if thoses infos are not deleted before the formula execution, the AoE value could be used for decreasing damage, or allow evasion

Return location

00179b14: Set_targeting_for_weapon_attack?
00179fa4: Set_Ability_Targeting? 
0017a1f0: Calculate_ability_range_with_map_parameters?
0017a444: Set_panels_affected_by_ability?
0017badc: Targeting_routine