Difference between revisions of "Targeting validation (weapon flags)"

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

Latest revision as of 21:31, 30 September 2022

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