Linear/3-direction AoE Calculation

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
0017be68 - 0017c040   ( Bad setup - over 50 lines to save i think )

Parameters : r4 = Pointer to previous routine (hold Attackers 0x16e to 0x181 data)
             r5 = 0x01 if Ability is linear, 0x03 if 3 directions
       Note : Only 3 directions is tested, linear is a condition tu jump here, but not tested again
	
This routine will erase AoE flags of targetable panels that are not lined up with the attacker (see notes)

----------------------------------------------------------------------------------------------- 
0017be68: 27bdffc0 addiu r29,r29,-0x0040    |
0017be6c: afb30034 sw r19,0x0034(r29)       |
0017be70: 00a09821 addu r19,r5,r0           |r19 = Direction Type (linear or 3 directions)
0017be74: 27a50010 addiu r5,r29,0x0010      |r5 = Stack Pointer
0017be78: afbf003c sw r31,0x003c(r29)       |
0017be7c: afb40038 sw r20,0x0038(r29)       |
0017be80: afb20030 sw r18,0x0030(r29)       |
0017be84: afb1002c sw r17,0x002c(r29)       |
0017be88: 0c01788b jal 0x0005e22c           |-->Copy_Byte_Data_(20_Bytes) Copy Attacker 0x16e to 0x181 from r4 on Stack r29 0x10 to 0x23
0017be8c: afb00028 sw r16,0x0028(r29)       |
0017be90: 93a30010 lbu r3,0x0010(r29)       |r3 = Attacker ID
0017be94: 87b2001c lh r18,0x001c(r29)       |r18 = Targeted X
0017be98: 87b40020 lh r20,0x0020(r29)       |r20 = Targeted Y
0017be9c: 34020001 ori r2,r0,0x0001         |r2 = 0x01
0017bea0: 3c018019 lui r1,0x8019            |r1 = 0x80190000
0017bea4: ac22f4f8 sw r2,-0x0b08(r1)        |Store 0x01 at 0x8018f4f8. Checked later to run List_and_Sort_Targeted_Units - hitting close targets first.
0017bea8: 000310c0 sll r2,r3,0x03           |r2 = Attacker ID *8
0017beac: 00431023 subu r2,r2,r3            |r2 = Attacker ID *7
0017beb0: 00021180 sll r2,r2,0x06           |r2 = Attacker ID *448 (size of unit's data)
0017beb4: 3c038019 lui r3,0x8019            |
0017beb8: 246308cc addiu r3,r3,0x08cc       |r3 = 0x801908cc (start of units data)
0017bebc: 00431021 addu r2,r2,r3            |r2 = Attacker data pointer
0017bec0: 90510047 lbu r17,0x0047(r2)       |r17 = Attacker's X coord
0017bec4: 90500048 lbu r16,0x0048(r2)       |r16 = Attacker's Y coord
0017bec8: 0232182a slt r3,r17,r18           |r3 = 0x01 if Attacker's X coord < Targeted X coord
0017becc: 10600010 beq r3,r0,0x0017bf10     #If Attacker's X coord < Targeted X coord /Else branch to next testing direction section
0017bed0: 00002021 addu r4,r0,r0                 |r4 = 0x00 (direction for jal below)
0017bed4: 02202821 addu r5,r17,r0                |r5 = Attacker's X coord
0017bed8: 0c05f011 jal 0x0017c044                |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bedc: 02003021 addu r6,r16,r0                |r6 = Attacker's Y coord
0017bee0: 326300ff andi r3,r19,0x00ff            |r3 = Ability's attack type
0017bee4: 34020003 ori r2,r0,0x0003              |r2 = 0x03
0017bee8: 1462000a bne r3,r2,0x0017bf14          #if Ability type is 3 directions (do the others 2 directions) /Else branch to next testing direction section
0017beec: 0251102a slt r2,r18,r17                |r2 = 0x01 if Targeted X < Attacker X
0017bef0: 34040006 ori r4,r0,0x0006                  |r4 = 0x06 (direction for jal below)
0017bef4: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bef8: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017befc: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bf00: 34040004 ori r4,r0,0x0004                  |r4 = 0x04 (direction for jal below)
0017bf04: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bf08: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf0c: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bf10: 0251102a slt r2,r18,r17           #E       | r2 = 0x01 if Targeted X < Attacker X
0017bf14: 10400010 beq r2,r0,0x0017bf58     #If Targeted X < Attacker X /Else branch to next testing direction section
0017bf18: 34040002 ori r4,r0,0x0002              |r4 = 0x02 (direction for jal below)
0017bf1c: 02202821 addu r5,r17,r0                |r5 = Attacker's X coord
0017bf20: 0c05f011 jal 0x0017c044                |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf24: 02003021 addu r6,r16,r0                |r6 = Attacker's Y coord
0017bf28: 326300ff andi r3,r19,0x00ff            |r3 = Directions
0017bf2c: 34020003 ori r2,r0,0x0003              |r2 = 0x03
0017bf30: 1462000a bne r3,r2,0x0017bf5c          #if Ability type is 3 directions (do the others 2 directions) /Else branch to next testing direction section
0017bf34: 0214102a slt r2,r16,r20                |r2 = 0x01 if Attacker's Y < Targetd Y
0017bf38: 34040006 ori r4,r0,0x0006                  |r4 = 0x06 (direction for jal below)
0017bf3c: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bf40: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf44: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bf48: 34040004 ori r4,r0,0x0004                  |r4 = 0x04 (direction for jal below)
0017bf4c: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bf50: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf54: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bf58: 0214102a slt r2,r16,r20           #E       | r2 = 0x01 if Attacker's Y < Targetd Y
0017bf5c: 10400010 beq r2,r0,0x0017bfa0     #If  Attacker's Y < Targeted Y /Else branch to next testing direction section
0017bf60: 34040006 ori r4,r0,0x0006              |r4 = 0x06 (direction for jal below)
0017bf64: 02202821 addu r5,r17,r0                |r5 = Attacker's X coord
0017bf68: 0c05f011 jal 0x0017c044                |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf6c: 02003021 addu r6,r16,r0                |r6 = Attacker's Y coord
0017bf70: 326300ff andi r3,r19,0x00ff            |r3 = Directions
0017bf74: 34020003 ori r2,r0,0x0003              |r2 = 0x03
0017bf78: 1462000a bne r3,r2,0x0017bfa4          #if Ability type is 3 directions (do the others 2 directions) /Else branch to next testing direction section
0017bf7c: 0290102a slt r2,r20,r16                |r2 = 0x01 if targeted Y < Attacker's Y
0017bf80: 00002021 addu r4,r0,r0                     |r4 = 0x00 (direction for jal below)
0017bf84: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bf88: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf8c: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bf90: 34040002 ori r4,r0,0x0002                  |r4 = 0x02 (direction for jal below)
0017bf94: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bf98: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bf9c: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bfa0: 0290102a slt r2,r20,r16           #E       | r2 = 0x01 if targeted Y < Attacker's Y
0017bfa4: 10400010 beq r2,r0,0x0017bfe8     #If Targeted Y < Attacker's Y /Else branch to loop
0017bfa8: 34040004 ori r4,r0,0x0004              |r4 = 0x04 (direction for jal below)
0017bfac: 02202821 addu r5,r17,r0                |r5 = Attacker's X coord
0017bfb0: 0c05f011 jal 0x0017c044                |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bfb4: 02003021 addu r6,r16,r0                |r6 = Attacker's Y coord
0017bfb8: 326300ff andi r3,r19,0x00ff            |r3 = Directions
0017bfbc: 34020003 ori r2,r0,0x0003              |r2 = 0x03
0017bfc0: 1462000a bne r3,r2,0x0017bfec          #if Ability type is 3 directions (do the others 2 directions) /Else branch to loop
0017bfc4: 00002021 addu r4,r0,r0                 |r4 = 0x00 (loop counter)
0017bfc8: 34040002 ori r4,r0,0x0002                  |r4 = 0x02 (direction for jal below)
0017bfcc: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bfd0: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bfd4: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bfd8: 00002021 addu r4,r0,r0                     |r4 = 0x00 (direction for jal below)
0017bfdc: 02202821 addu r5,r17,r0                    |r5 = Attacker's X coord
0017bfe0: 0c05f011 jal 0x0017c044                    |-->Linear Attack Tile Calculation Set Targeted panel flag ON
0017bfe4: 02003021 addu r6,r16,r0                    |r6 = Attacker's Y coord
0017bfe8: 00002021 addu r4,r0,r0            #E       | r4 = 0x00 (loop counter)
0017bfec: 3c038019 lui r3,0x8019            |r3 = 0x80190000
0017bff0: 24632dd8 addiu r3,r3,0x2dd8       |r3 = 0x80192dd8 (Targetable grid data pointer)
0017bff4: 90620001 lbu r2,0x0001(r3)        @LOOP through targetable panels r2 = Panel Targeted flag
0017bff8: 00000000 nop                           | 
0017bffc: 14400003 bne r2,r0,0x0017c00c          #If Panel targeted flag is = 0x00
0017c000: 00000000 nop                               | 
0017c004: 0805f004 j 0x0017c010                      >>jump to next iteration
0017c008: a0600000 sb r0,0x0000(r3)                  |Nullify panel AoE flag
0017c00c: a0600001 sb r0,0x0001(r3)              #Else (Targeted Panel) Nullify targeted flag (keep AoE flag)
0017c010: 24840001 addiu r4,r4,0x0001            |r4 = loop counter + 1
0017c014: 28820200 slti r2,r4,0x0200             |r2 = 0x01 if counter < 0x200
0017c018: 1440fff6 bne r2,r0,0x0017bff4     #Branch if Counter < 0x200
0017c01c: 24630005 addiu r3,r3,0x0005            |r3 = Panel data pointer offset for loop
0017c020: 8fbf003c lw r31,0x003c(r29)            
0017c024: 8fb40038 lw r20,0x0038(r29)            
0017c028: 8fb30034 lw r19,0x0034(r29)            
0017c02c: 8fb20030 lw r18,0x0030(r29)            
0017c030: 8fb1002c lw r17,0x002c(r29)            
0017c034: 8fb00028 lw r16,0x0028(r29)            
0017c038: 27bd0040 addiu r29,r29,0x0040          
0017c03c: 03e00008 jr r31                        
0017c040: 00000000 nop

Notes

What's happening here is tied to the way the AoE is set.
Before jumping here, the ability AoE has been spread out and the all the targtable panel targeted flag have been turned off.
Since a linear (and three direction) ability has range = AoE, there's a lot of panel AoE to turn OFF.

This routine will set the direction(s) of the attacks then jal to Linear Attack Tile Calculation. 
 - During this Jal the lined up panel will have their targeted flag turn ON again.

After returning, the routine will loop through all panels
 - all the panel with their targeted flag = 0x00 will have their AoE nullified
 - The panel with the targeted flag = 0x01 will have their AoE kept and their targeted flag turned off again

Bad setup : Direction could be set better, and jal section should be written only one time (not 4 times)

Rq : At the beginning of targeting routine, the Attacker X,Y and elevation are used in place of Targeted coordinates. So the initial AoE is all around the caster, and then most of it is nullified here

Return locations

Battle.bin
0017bb38: Targeting_routine (linear)
0017bb50: Targeting_routine (three directions)