Check Allies/Enemies that can be Targeted

From Final Fantasy Hacktics Wiki
Revision as of 20:22, 10 February 2022 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Parameters : r4 = Attacker ID
             r5 = 0x80 if Ability ignores enemy unit
             r6 = 0x40 if Ability ignores allies
             r7 = 0x01 if Ability AoE is 255

Nullify AoE of targetable panel if unit is in a team to ignores
Set targetable panel 0x01 flag "ON" (= 0x01) if unit is not in the team to ignore (does not take AoE into account)
If Targetable panel AoE is > 0x00 set targetable panel 0x01 flag ON
----------------------------------------------------------------------------------
0017bc78: 27bdffc0 addiu r29,r29,-0x0040    |
0017bc7c: afb5002c sw r21,0x002c(r29)       |
0017bc80: 00a0a821 addu r21,r5,r0           |r21 = Ignore enemy Flag
0017bc84: afb60030 sw r22,0x0030(r29)       |
0017bc88: 00c0b021 addu r22,r6,r0           |r22 = Ignore ally Flag
0017bc8c: afb70034 sw r23,0x0034(r29)       |
0017bc90: 00e0b821 addu r23,r7,r0           |r23 = 0x01 if Ability AoE is 255
0017bc94: 308400ff andi r4,r4,0x00ff        |r4 = clean Attacker ID
0017bc98: 000410c0 sll r2,r4,0x03           |r2 = Attacker ID * 8
0017bc9c: 00441023 subu r2,r2,r4            |r2 = Attacker ID * 7
0017bca0: 00021180 sll r2,r2,0x06           |r2 = Attacker ID * 448  (size of unit data)
0017bca4: afb30024 sw r19,0x0024(r29)       |
0017bca8: 00809821 addu r19,r4,r0           |r19 = Attacker ID
0017bcac: afb00018 sw r16,0x0018(r29)       |
0017bcb0: 00008021 addu r16,r0,r0           |r16 = 0x00 (loop counter)
0017bcb4: afb20020 sw r18,0x0020(r29)       |
0017bcb8: 34120001 ori r18,r0,0x0001        |r18 = 0x01
0017bcbc: afb1001c sw r17,0x001c(r29)       |
0017bcc0: 00008821 addu r17,r0,r0           |r17 = 0x00 (unit pointer in unit data, +0x1c0 each loop iteration)
0017bcc4: afbf0038 sw r31,0x0038(r29)       |
0017bcc8: afb40028 sw r20,0x0028(r29)       |
0017bccc: 3c018019 lui r1,0x8019            |
0017bcd0: 00220821 addu r1,r1,r2            |r1 = 0x80190000 + Attacker ID*448
0017bcd4: 903408d1 lbu r20,0x08d1(r1)       |r20 = Attacker ENTD's flag  ( 0x801908cc + 0x05 = 0x801908d1 )
0017bcd8: 02002021 addu r4,r16,r0           @LOOP through all units r4 = Loop counter (unit counter)
0017bcdc: 0c05ef74 jal 0x0017bdd0                |-->Check_if_Unit_can_be_Targeted Return 0x00 if can be targeted + unit tile ID on r5
0017bce0: 27a50010 addiu r5,r29,0x0010           |r5 = Stack Pointer
0017bce4: 1440001c bne r2,r0,0x0017bd58          #If unit can be targeted
0017bce8: 00000000 nop                               | 
0017bcec: 3c018019 lui r1,0x8019                     |r1 = 0x80190000
0017bcf0: 00310821 addu r1,r1,r17                    |r1 = 0x80190000 + unit data offset (0x1c0 each iteration)
0017bcf4: 90220a86 lbu r2,0x0a86(r1)                 |r2 = This iteration unit modified ENTD flag
0017bcf8: 00000000 nop                               |
0017bcfc: 02821026 xor r2,r20,r2                     |r2 = every differences between attacker and this iteration unit ENTD flags - (Team ID in it) (0x00 if same ENTD's flag)
0017bd00: 16700002 bne r19,r16,0x0017bd0c            #If This iteration unit is Attacker
0017bd04: 00402021 addu r4,r2,r0                     |r4 = Differing ENTD Flags
0017bd08: 00002021 addu r4,r0,r0                         |r4 = 0x00 (nullify ENTD difference)
0017bd0c: 8fa30010 lw r3,0x0010(r29)                 |r3 = This iteration Unit's Tile ID
0017bd10: 00000000 nop                               |
0017bd14: 00031080 sll r2,r3,0x02                    |r2 = This iteration Unit's Tile ID * 4
0017bd18: 00431021 addu r2,r2,r3                     |r2 = This iteration Unit's Tile ID * 5
0017bd1c: 3c038019 lui r3,0x8019                     |
0017bd20: 24632dd8 addiu r3,r3,0x2dd8                |r3 = Targetable grid data pointer
0017bd24: 00431821 addu r3,r2,r3                     |r3 = This iteration Unit's Targetable panel data pointer
0017bd28: 90620000 lbu r2,0x0000(r3)                 |r2 = This iteration Unit's Targetable panel AoE
0017bd2c: 00000000 nop                               |
0017bd30: 10400009 beq r2,r0,0x0017bd58              #If This iteration Unit's Targetable panel AoE > 0x00
0017bd34: 30820030 andi r2,r4,0x0030                     |r2  <> 0x00 if Attacker and this iteration Unit are not in the same Team (Differing ENTD flag filtered on Team difference)
0017bd38: 14400002 bne r2,r0,0x0017bd44                  #If No team difference /Else branch keeping r2 = Avoid ally flag
0017bd3c: 32c200ff andi r2,r22,0x00ff                    |r2 = Ignore ally flag
0017bd40: 32a200ff andi r2,r21,0x00ff                        |r2 = Ignore enemy flag
0017bd44: 10400003 beq r2,r0,0x0017bd54                  #If This iteration unit is not in the team to ignore /Else , ignore Team (do not restore the targeted flag and nullify AoE)
0017bd48: 00000000 nop                                       |
0017bd4c: 0805ef56 j 0x0017bd58                              >>jump to next iteration (after set the panel targeted flag ON)
0017bd50: a0720001 sb r18,0x0001(r3)                         |Turn targetable panel targeted flag ON (= 0x01)  * panel 0x01 byte
0017bd54: a0600000 sb r0,0x0000(r3)                      #Else (Team to avoid) Nullify Targetable panel AoE 
0017bd58: 26100001 addiu r16,r16,0x0001          |r16 = loop counter + 1
0017bd5c: 2a020015 slti r2,r16,0x0015            |r2 = 0x01 if counter < 0x15
0017bd60: 1440ffdd bne r2,r0,0x0017bcd8     Λ loop while unit counter < 0x15
0017bd64: 263101c0 addiu r17,r17,0x01c0          |r1 = unit data Pointer Mod += 0x1c0
0017bd68: 32e200ff andi r2,r23,0x00ff       |r2 = 0x01 if Ability AoE is 255
0017bd6c: 1440000c bne r2,r0,0x0017bda0     #If Ability AoE is not 255 /Else branch to END
0017bd70: 00008021 addu r16,r0,r0                |r16 = 0x00 (loop counter)
0017bd74: 34040001 ori r4,r0,0x0001              |r4 = 0x01
0017bd78: 3c038019 lui r3,0x8019                 |
0017bd7c: 24632dd8 addiu r3,r3,0x2dd8            |r3 = 0x80192dd8 ( targetable panel grid)
0017bd80: 90620000 lbu r2,0x0000(r3)             @LOOP through all targetable panel r2 = Targetable panel AoE
0017bd84: 00000000 nop                               |
0017bd88: 10400002 beq r2,r0,0x0017bd94              #If This iteration panel AoE > 0x00
0017bd8c: 26100001 addiu r16,r16,0x0001              |r16 = counter + 1
0017bd90: a0640001 sb r4,0x0001(r3)                      |Set Targetable panel targeted flag ON (= 0x01)
0017bd94: 2a020200 slti r2,r16,0x0200                |r2 = 0x01 if counter < 0x200
0017bd98: 1440fff9 bne r2,r0,0x0017bd80          Λ loop while counter < 0x200
0017bd9c: 24630005 addiu r3,r3,0x0005                |Pointer += 5
0017bda0: 8fbf0038 lw r31,0x0038(r29)                
0017bda4: 8fb70034 lw r23,0x0034(r29)                
0017bda8: 8fb60030 lw r22,0x0030(r29)                
0017bdac: 8fb5002c lw r21,0x002c(r29)                
0017bdb0: 8fb40028 lw r20,0x0028(r29)                
0017bdb4: 8fb30024 lw r19,0x0024(r29)                
0017bdb8: 8fb20020 lw r18,0x0020(r29)                
0017bdbc: 8fb1001c lw r17,0x001c(r29)                
0017bdc0: 8fb00018 lw r16,0x0018(r29)                
0017bdc4: 27bd0040 addiu r29,r29,0x0040              
0017bdc8: 03e00008 jr r31                            
0017bdcc: 00000000 nop                               

Return location

Battle.bin
 0017bb6c: Targeting_routine