Targeting validation (weapon flags)

From Final Fantasy Hacktics Wiki
Revision as of 21:51, 1 February 2022 by Orkney (talk | contribs)
Jump to navigation Jump to search
0017ac90 - 0017afbc

Parameters : r4 = Pointer to attacker data 0x16e              	  

Returns : r2 = 0x00 green flags have been updated
          r2 = -0x01 if invalid Attacker ID or Weapon ID >=0x80 (shields)
          r2 = -0x01 if invalid Target ID for not weapon ranged ability (see summary)
------------------------------------------------------------------- 
0017ac90: 27bdffb0  addiu r29,r29,-0x0050   |
0017ac94: 27a50018 addiu r5,r29,0x0018      |r5 =Inner stack pointer
0017ac98: afbf004c sw r31,0x004c(r29)       |
0017ac9c: afb60048 sw r22,0x0048(r29)       |
0017aca0: afb50044 sw r21,0x0044(r29)       |
0017aca4: afb40040 sw r20,0x0040(r29)       |
0017aca8: afb3003c sw r19,0x003c(r29)       |
0017acac: afb20038 sw r18,0x0038(r29)       |
0017acb0: afb10034 sw r17,0x0034(r29)       |
0017acb4: 0c01788b jal 0x0005e22c           |-->Copy_Byte_Data_(20_Bytes) Copy attacker data 0x16e - 0x181 on inner stack pointer
0017acb8: afb00030 sw r16,0x0030(r29)       |
0017acbc: 93b50018 lbu r21,0x0018(r29)      |r21 =Attacker ID (Attacker 0x16e on inner stack)
0017acc0: 00000000 nop                      |
0017acc4: 32a300ff andi r3,r21,0x00ff       |r3 = Attacker ID last byte
0017acc8: 2c620015 sltiu r2,r3,0x0015       |r2 = 0x01 if attacker ID < 0x15 (21)
0017accc: 10400050 beq r2,r0,0x0017ae10     #If  Attacker ID is valid / Branch to jump to End  (r2 = -0x01) if not
0017acd0: 000310c0 sll r2,r3,0x03                |Attacker ID * 8
0017acd4: 00431023 subu r2,r2,r3                 |Attacker ID * 7
0017acd8: 00021180 sll r2,r2,0x06                |Attacker ID * 448 (0x1c0)
0017acdc: 3c038019 lui r3,0x8019                 |
0017ace0: 246308cc addiu r3,r3,0x08cc            |r3 = 0x801908cc
0017ace4: 00439021 addu r18,r2,r3                |r18 = attacker data pointer
0017ace8: 92430001 lbu r3,0x0001(r18)            |r3 = Attacker ID
0017acec: 340200ff ori r2,r0,0x00ff              |r2 = 0x00ff
0017acf0: 106200a8 beq r3,r2,0x0017af94          #If Attacker ID <> 0xff  / Branch to jump to End (r2 = -0x01)
0017acf4: 2402ffff addiu r2,r0,-0x0001           |r2 = -0x01
0017acf8: 93a20019 lbu r2,0x0019(r29)                |r2 =  skillset ID of last used attack?  (Attacker 0x16f via inner stack)
0017acfc: 3c018006 lui r1,0x8006                     |r1 = 0x80060000
0017ad00: 00220821 addu r1,r1,r2                     |r1 = 0x80060000 + Skillset ID
0017ad04: 90365cb4 lbu r22,0x5cb4(r1)                |r22 = action menu of skillset   0x80065cb4 + Skillset ID
0017ad08: 00000000 nop                               |
0017ad0c: 32c300ff andi r3,r22,0x00ff                |r3 = last byte of skillset's action menu
0017ad10: 10600004 beq r3,r0,0x0017ad24              #If action menu is not [Default] / Else branch to ability [weapon range] flag search
0017ad14: 00002021 addu r4,r0,r0                         |r4 = 0x00
0017ad18: 34020006 ori r2,r0,0x0006                      |r2 = 0x06
0017ad1c: 1462000b bne r3,r2,0x0017ad4c                  #If action menu = [Monster] / Branch if not monster (avoid ability [weapon range] flag search)
0017ad20: 34020008 ori r2,r0,0x0008                      |r2 = 0x08 (Action menu [Attack] ID
                                             --- [Default] [Monster] ---- (load used ability [weapon range] flag)
0017ad24: 93a3001a lbu r3,0x001a(r29)                #E      |r3 = Attacker last attack ID  (Attacker 0x170 via inner stack)
0017ad28: 00000000 nop                                       |
0017ad2c: 000310c0 sll r2,r3,0x03                            |r2 = Attacker last used ability ID * 8
0017ad30: 00431023 subu r2,r2,r3                             |r2 = Attacker last used ability ID * 7
0017ad34: 00021040 sll r2,r2,0x01                            |r2 = Attacker last used ability ID * 14
0017ad38: 3c018006 lui r1,0x8006                             |
0017ad3c: 00220821 addu r1,r1,r2                             |r2 = 8006 0000  + Ability ID * 14
0017ad40: 9024fbf3 lbu r4,-0x040d(r1)                        |r4 = Attacker last used ability data 2 flags 1  0x8005fbf0 + 0x03 + ability offset
0017ad44: 32c300ff andi r3,r22,0x00ff                        |r3 = last byte of last used skillset ID
0017ad48: 34020008 ori r2,r0,0x0008                          |r2 = 0x08 (Action menu [Attack] ID
                                             ---All --- Check action menu [Attack], [Charge] and used ability [weapon range] flag (only have value if defalut or monster action menu)
0017ad4c: 10620006 beq r3,r2,0x0017ad68                  #If Action menu <> [Attack] #branch if attack
0017ad50: 340500ff ori r5,r0,0x00ff                      |r5 = 0xff
0017ad54: 3402000a ori r2,r0,0x000a                          |r2 = 0x0a ([Action menu Charge ID]
0017ad58: 10620003 beq r3,r2,0x0017ad68                      #If Action menu <> [Charge] #branch if charge
0017ad5c: 30820020 andi r2,r4,0x0020                             |r2 = 0x20 if ranged weapon is checked (and action menu is [Default] or [Monster]
0017ad60: 10400022 beq r2,r0,0x0017adec                          #If weapon range is checked ([Default]pr  #branch if weapon range = false
0017ad64: 34020006 ori r2,r0,0x0006                              |r2 = 0x06 (for Attacker 0x178 check)
                                             --- [Charge] , [Attack], [ Default or Monster if ability flag weapon range is checked] ----
0017ad68: 9243001f lbu r3,0x001f(r18)                    #E  #E      |r3 = Attacker left hand weapon
0017ad6c: 00000000 nop                                               |
0017ad70: 386200ff xori r2,r3,0x00ff                                 |r2 = 0x00 if weapon ID is 0xff (doesn't exist)
0017ad74: 0002102b sltu r2,r0,r2                                     |r2 = 0x01 if weapon exist / else 0x00 (r0 < everything but 0x00)
0017ad78: 00021023 subu r2,r0,r2                                     |r2 = -0x01 if weapon exist /else 0x00
0017ad7c: 00622024 and r4,r3,r2                                      |r4 = Attacker left hand weapon ID if weapon exist / Else 0x00
0017ad80: 9243001d lbu r3,0x001d(r18)                                |r3 = Attacker right hand weapon
0017ad84: 00000000 nop                                               |
0017ad88: 10650002 beq r3,r5,0x0017ad94                              #If Attacker has a right weapon # / Else branch  (r4 keeping left weapon ID or 0x00)
0017ad8c: 00000000 nop                                                   | 
0017ad90: 00602021 addu r4,r3,r0                                         |r4 = Attacker right hand ID
0017ad94: 9242005a lbu r2,0x005a(r18)                                |r2 = Attacker current status 3
0017ad98: 00000000 nop                                               |
0017ad9c: 30420002 andi r2,r2,0x0002                                 |r2 = 0x02 if attacker is a frog
0017ada0: 14400008 bne r2,r0,0x0017adc4                              #If attacker is not a frog / Branch if frog (weapon will be set to 0x00)
0017ada4: 00000000 nop                                                   | 
0017ada8: 92420006 lbu r2,0x0006(r18)                                    |r2 = Attacker gender
0017adac: 00000000 nop                                                   |
0017adb0: 30420020 andi r2,r2,0x0020                                     |r2 = 0x20 if attacker is a monster
0017adb4: 14400003 bne r2,r0,0x0017adc4                                  #If attacker is not a monster / Branch if monster (weapon will be set to 0x00)
0017adb8: 00000000 nop                                                       | 
0017adbc: 14850003 bne r4,r5,0x0017adcc                                      #If weapon ID = 0xff / branch if right weapon exist (not monster not frog) avoid weapon ID nullification
0017adc0: 308300ff andi r3,r4,0x00ff                                         |r3 = weapon ID 
0017adc4: 00002021 addu r4,r0,r0                                     #E #E r4 = 0x00 (if frog or monster or if r4 = 0xff (not possible at this stade ?)
0017adc8: 308300ff andi r3,r4,0x00ff                                             |r3 = 0x00
0017adcc: 2c620080 sltiu r2,r3,0x0080                                |r2 = 0x01 if weapon ID < 0x80 ( 0x80 and above are shields)
0017add0: 1040000f beq r2,r0,0x0017ae10                              #If Weapon ID < 0x80 #branch if not, return r2 = -0x01
0017add4: 000310c0 sll r2,r3,0x03                                        |r2 = weapon ID * 8 (secondary data size - per weapon)
0017add8: 3c018006 lui r1,0x8006                                         |
0017addc: 00220821 addu r1,r1,r2                                         |r2 = 0x80060000 + weapon ID * 8 
0017ade0: 90303ab9 lbu r16,0x3ab9(r1)                                    |r16 =  item secondary data - attack flags ( 0x80063ab8 + 0x01 + weapon ID *8)
0017ade4: 0805eb96 j 0x0017ae58                                          >>jump avoiding next
0017ade8: 00000000 nop                                                   |
                                             --- Not [Charge] - Not [Attack] - [Default or Monster if ability flag weapon range is NOT checked]---
0017adec: 93a30022 lbu r3,0x0022(r29)                            # Else (see section title) r3 =  Attacker reaction ID ?  (Attacker 0x178  via inner stack)
0017adf0: 00000000 nop                                               |
0017adf4: 14620018 bne r3,r2,0x0017ae58                              #if Attacker 0x178 = 0x06 (Target-Specific Ability?) / Else avoid Target ID and coord. checking
0017adf8: 34100020 ori r16,r0,0x0020                                 |r16 = 0x20 (forced direct attack flag ?)
0017adfc: 93a30023 lbu r3,0x0023(r29)                                    |r3 = Attacker target ID ?  (Attacker 0x179 via inner stack)
0017ae00: 00000000 nop                                                   |
0017ae04: 2c620015 sltiu r2,r3,0x0015                                    |r2 = 0x01 if Target is valid (< 0x15) / Else 0x00
0017ae08: 14400003 bne r2,r0,0x0017ae18                                  #If Target is not valid /Else avoid ending routine
0017ae0c: 000310c0 sll r2,r3,0x03                                        |r2 = Attacker Target ID * 8
0017ae10: 0805ebe5 j 0x0017af94             #Else                    #E       >>Jump to  end With r2 = -0x01  Invalid Attacker ID, Target ID or Weapon ID
0017ae14: 2402ffff addiu r2,r0,-0x0001                                       |r2 = -0x01
0017ae18: 00431023 subu r2,r2,r3                                         #Else Target is valid r2 = Attacker Target ID * 7
0017ae1c: 00021180 sll r2,r2,0x06                                        |r2 = Attacker Target ID * 448 (Attacker data 0x179)
0017ae20: 3c038019 lui r3,0x8019                                         |
0017ae24: 246308cc addiu r3,r3,0x08cc                                    |r3 = 0x801908cc
0017ae28: 00431821 addu r3,r2,r3                                         |r3 = Attacker target data pointer
0017ae2c: 90620047 lbu r2,0x0047(r3)                                     |r2 = Target X coord.
0017ae30: 00000000 nop                                                   |
0017ae34: a7a20024 sh r2,0x0024(r29)                                     |Store target X coord. on inner stack  (in place of Attacker 0x17a)
0017ae38: 90620048 lbu r2,0x0048(r3)                                     |r2 = Target Y coord.
0017ae3c: 00000000 nop                                                   |
0017ae40: a7a20028 sh r2,0x0028(r29)                                     |Store target Y coord. on inner stack  (in place of Attacker 0x17e)
0017ae44: 94620048 lhu r2,0x0048(r3)                                     |r2 = Target Y coord. + Target 0x49 (Half word)
0017ae48: 00000000 nop                                                   |
0017ae4c: 000213c2 srl r2,r2,0x0f                                        |r2 = Elevation bit (0 if not elevated, 1 if elevated)
0017ae50: a7a20026 sh r2,0x0026(r29)                                     |store Target elevation on inner stack  (in place of Attacker 0x17c)
0017ae54: 34100020 ori r16,r0,0x0020                                     |r16 = 0x20
                                             --- ALL---
0017ae58: 8651017a lh r17,0x017a(r18)                |r17 =Target X coord (from attacker data) Not modified by above section
0017ae5c: 8653017e lh r19,0x017e(r18)                |r19 = Target Y coord (from attacker data) Not modified by above section
0017ae60: 8654017c lh r20,0x017c(r18)                |r20 = Target elevation (from attacker data) Not modified by above section
0017ae64: 02202021 addu r4,r17,r0                    |r4 =Target X coord (from attacker data)
0017ae68: 02602821 addu r5,r19,r0                    |r5 = Target Y coord (from attacker data)
0017ae6c: 0c05f722 jal 0x0017dc88                    |-->Get ID of unit if tile is targetable returns r2 = Unit ID if tile is targetable
0017ae70: 02803021 addu r6,r20,r0                    |r6 = Target elevation (from attacker data)
0017ae74: 00403021 addu r6,r2,r0                     |r6 = target ID or < 0x00 (fail to find target) (from jal)
0017ae78: 04c10002 bgez r6,0x0017ae84                #If Tile is invalid or target is not found #branch if target found
0017ae7c: 32020010 andi r2,r16,0x0010                |r2 = 0x10 if Arc is checked in weapon data
0017ae80: 2406ffff addiu r6,r0,-0x01                     |r6 = -0x01
0017ae84: 10400005 beq r2,r0,0x0017ae9c              #If Weapon is arcing / Branch if not arcing (always false if not [Attack], [Charge] or [Default with weapon range flag]
0017ae88: 02a02021 addu r4,r21,r0                        |r4 = attacker ID
0017ae8c: 0c06bfc6 jal 0x001aff18                        |-->Set_and_Validate_Arc_Trajectory Return r2 = Target ID (-0x01 if trajectory ends in an obstacle)
0017ae90: 2645017a addiu r5,r18,0x017a                   |r5 = attacker unit data + 0x17a (target X coord)
0017ae94: 0805ebd0 j 0x0017af40                          >>Jump to green flag update skiping other weapon type
0017ae98: 00408021 addu r16,r2,r0                        |r16 = Target ID
0017ae9c: 32020020 andi r2,r16,0x0020                |r2 <> 0x00 if direct is checked
0017aea0: 10400018 beq r2,r0,0x0017af04              #Else If weapon is direct
0017aea4: 32020040 andi r2,r16,0x0040                |r2<> 0x00 if lunging
0017aea8: 92420047 lbu r2,0x0047(r18)                    |r2 = Attacker X coord.
0017aeac: 00000000 nop                                   |
0017aeb0: 02222023 subu r4,r17,r2                        |r4 = DeltaX (Target X coord-Attacker X coord )
0017aeb4: 04810002 bgez r4,0x0017aec0                    #If Delta X < 0x00
0017aeb8: 00000000 nop                                       | 
0017aebc: 00042023 subu r4,r0,r4                             |DeltaX = Absolute value of DeltaX
0017aec0: 92420048 lbu r2,0x0048(r18)                    |r2 = Attacker Y ccord.
0017aec4: 00000000 nop                                   |
0017aec8: 02621023 subu r2,r19,r2                        |r2 = Delta Y (Target Y coord-Attacker Y coord )
0017aecc: 04410002 bgez r2,0x0017aed8                    #If Delta Y < 0x00
0017aed0: 32c300ff andi r3,r22,0x00ff                    |r3 = last byte of last used skillset ID
0017aed4: 00021023 subu r2,r0,r2                             |r2 = Absolute value of DeltaY
0017aed8: 00822021 addu r4,r4,r2                         |r4 = DeltaX + DeltaY
0017aedc: 34020001 ori r2,r0,0x0001                      |r2 = 0x01
0017aee0: 14620003 bne r3,r2,0x0017aef0                  #If Action menu is Attack /Else avoid melee range check
0017aee4: 28820002 slti r2,r4,0x0002                     |r2 = 0x01 if Target is in melee range ( DeltaX + DeltaY <0x02)
0017aee8: 14400015 bne r2,r0,0x0017af40                      #If Target is not in melee range
0017aeec: 00c08021 addu r16,r6,r0                            |r16 = Target ID
0017aef0: 02a02021 addu r4,r21,r0                        #E      | r4 = Attacker ID
0017aef4: 0c06c206 jal 0x001b0818                                |-->001b0818_-_001b0a8c Might return r2 = Target ID (with obstacle calculation)
0017aef8: 2645017a addiu r5,r18,0x017a                           |r5 = Attacker data pointer 0x17a (Target X coord)
0017aefc: 0805ebd0 j 0x0017af40                                  >>Jump to green flag update skiping other weapon type
0017af00: 00408021 addu r16,r2,r0                                |r16 = Target ID
0017af04: 10400008 beq r2,r0,0x0017af28              #Else If weapon is lunging
0017af08: 02a02021 addu r4,r21,r0                        |r4 = Attacker ID
0017af0c: afa60010 sw r6,0x0010(r29)                     |Store target ID at stack 0x10
0017af10: 02202821 addu r5,r17,r0                        |r5 = Target X coord
0017af14: 02603021 addu r6,r19,r0                        |r6 = Target Y coord
0017af18: 0c05ebf0 jal 0x0017afc0                        |-->Auxilary_targeting_validation Might return r2 = Target ID (with obstacle calculation)
0017af1c: 02803821 addu r7,r20,r0                        |r7 = Target elevation
0017af20: 0805ebd0 j 0x0017af40                          >>Jump to green flag update skiping other weapon type
0017af24: 00408021 addu r16,r2,r0                        |r16 = Target ID
0017af28: afa60010 sw r6,0x0010(r29)                 #Else Store target ID at stack 0x10
0017af2c: 02202821 addu r5,r17,r0                        |r5 = Target X coord
0017af30: 02603021 addu r6,r19,r0                        |r6 = Target Y coord
0017af34: 0c05ecfd jal 0x0017b3f4                        |-->Height/coordinate_validation Returns r2 = Target ID
0017af38: 02803821 addu r7,r20,r0                        |r7 = Target elevation
0017af3c: 00408021 addu r16,r2,r0                        |r16 = Target ID
0017af40: 0c05ed28 jal 0x0017b4a0           >j       -->Disable_Green_Panel_Flags Disable flag 0x80 from all tiles 0x05 bytes
0017af44: 00000000 nop                               |
0017af48: 2e020015 sltiu r2,r16,0x0015               |r2 = 0x01 if Target ID < 0x15
0017af4c: 10400011 beq r2,r0,0x0017af94              #If Target ID is valid (< 0x15) /Else branch to end With r2 = 0x00
0017af50: 00001021 addu r2,r0,r0                     |r2 = 0x00
0017af54: 001020c0 sll r4,r16,0x03                       |r4 = Target ID * 8
0017af58: 00902023 subu r4,r4,r16                        |r4 = Target ID*7
0017af5c: 00042180 sll r4,r4,0x06                        |r4 = Target ID * 448 
0017af60: 3c028019 lui r2,0x8019                         |r2 = 0x80190000
0017af64: 244208cc addiu r2,r2,0x08cc                    |r2 = 0x801908cc (start of unit data)
0017af68: 0c060428 jal 0x001810a0                        |-->Map_Location_Calculation returns r2 = Target unit Tile ID
0017af6c: 00822021 addu r4,r4,r2                         |r4 = Start of Target unit data 0x801908cc + Unit offset
0017af70: 000210c0 sll r2,r2,0x03                        |r2 = Target Tile ID * 8
0017af74: 3c038019 lui r3,0x8019                         |r3 = 0x80190000
0017af78: 2463f8cc addiu r3,r3,-0x0734                   |r3 = 0x8018f8cc (Start of Tiles data)
0017af7c: 00431021 addu r2,r2,r3                         |r2 = Start of Target Tile data (0x8018f8cc + Tile offset)
0017af80: 90430005 lbu r3,0x0005(r2)                     |r3 = Target Tile 0x05 byte
0017af84: 00000000 nop                                   |
0017af88: 34630080 ori r3,r3,0x0080                      |r3 = Target Tile 0x05 byte with flag 0x80 enabled
0017af8c: a0430005 sb r3,0x0005(r2)                      |Store updated target Tile 0x05 byte with 0x80 enabled
0017af90: 00001021 addu r2,r0,r0                         |r2 = 0x00
0017af94: 8fbf004c lw r31,0x004c(r29)            END
0017af98: 8fb60048 lw r22,0x0048(r29)            
0017af9c: 8fb50044 lw r21,0x0044(r29)            
0017afa0: 8fb40040 lw r20,0x0040(r29)            
0017afa4: 8fb3003c lw r19,0x003c(r29)            
0017afa8: 8fb20038 lw r18,0x0038(r29)            
0017afac: 8fb10034 lw r17,0x0034(r29)            
0017afb0: 8fb00030 lw r16,0x0030(r29)            
0017afb4: 27bd0050 addiu r29,r29,0x0050          
0017afb8: 03e00008 jr r31                        
0017afbc: 00000000 nop

Summary

Check Attacker ID (<0x15 and not 0x00ff) - If not OK Exit with r2 = -0x01

1st Skillset Action menu
    - For Default and monster - check the [weapon range] flag of the ability
 
2nd Skillset Action menu check : 
    - Attack, Charge or Default + [weapon range] or monster + [weapon range] 
             - Choose right or left hand weapon 
             - 0x00 if Monster or frog
             - Right weapon ID if exists else left. (Not a shield checked)
             - Load Item secondary data attack type (arcing, direct and lunging will have specific routines)
    - Else 
             - Force Attack to a direct flag
             - If Attacker 0x178 = 0x06 (Target-Specific Ability?)
                    - Check Target ID validity - if not OK, exit with r2 = -0x01
                    - Update Target Coord on stack 0x24 0x28 and 0x26 (not found for which purpose)                          

Weapon attack type check
    - Arcing weapon : set trajectory and update target if obstacle
    - Direct trajectory : not investigated, return a Target ID (might check obstacle)
    - Lunging :  - check if Target is close to attacker 
                         if not : routine not investigated, return a Target ID (might check obstacle)
    - Else check Attacker and target delta height	: Target invalided if difference is too high

Disable all tiles green flag (Tile 0x05 byte, flag 0x80)
If target ID is valid : enable green flag of target tile

Return locations

Battle.bin
0017cde4: Map_calculations_for_attack
0017e010: Big..._Contains_Hamedo_check