Difference between revisions of "Map calculations for attack"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<font face='Courier New'>
+
'''0017cd24 - 0017ce40'''  [[#Notes|Notes]]
0017cd24: 27bdffe0 addiu r29,r29,0xffe0
+
 
  0017cd28: 00004021 addu r8,r0,r0
+
'''Parameters''' : r4 = Attacker 0x16e data pointer
  0017cd2c: afbf0018 sw r31,0x0018(r29)
+
              r5 = Previous routine stack pointer
  0017cd30: afb10014 sw r17,0x0014(r29)
+
  0017cd34: afb00010 sw r16,0x0010(r29)
+
'''Returns''' : r2 = -0x01 if something is invalid (weapon, ability coordinates..)
  0017cd38: 90820001 lbu r2,0x0001(r4) load skillset of last attack byte
+
          r2 = 0x00 if classic targeting
  0017cd3c: 00003821 addu r7,r0,r0
+
          r2 = 0x01 if mathematic targeting
  0017cd40: 3c018006 lui r1,0x8006
+
          r2 = 0x02 if non offensive action menu was used
  0017cd44: 00220821 addu r1,r1,r2
+
'''Store''' : Ability data 2 flags 3 on r5 (previous routine stack) - Only if action menu is default or monster
  0017cd48: 90265cb4 lbu r6,0x5cb4(r1) load action menu byte
+
-------------------------------------------------------------------------------------------------------------
  0017cd4c: 00008821 addu r17,r0,r0
+
0017cd24: 27bdffe0 addiu r29,r29,0xffe0     |
  0017cd50: 30c300ff andi r3,r6,0x00ff
+
  0017cd28: 00004021 addu r8,r0,r0           |{{f/std|<nowiki>r8 = 0x00</nowiki>}}
  0017cd54: 10600004 beq r3,r0,0x0017cd68 branch if [Default]
+
  0017cd2c: afbf0018 sw r31,0x0018(r29)       |
  0017cd58: a0a00000 sb r0,0x0000(r5) store 0x00 on the stack
+
  0017cd30: afb10014 sw r17,0x0014(r29)       |
  0017cd5c: 34020006 ori r2,r0,0x0006
+
  0017cd34: afb00010 sw r16,0x0010(r29)       |
  0017cd60: 14620013 bne r3,r2,0x0017cdb0 branch if not [Monster]
+
  0017cd38: 90820001 lbu r2,0x0001(r4)       |{{f/load|<nowiki>r2 =  skillset of last attack </nowiki>}}
  0017cd64: 34020008 ori r2,r0,0x0008
+
  0017cd3c: 00003821 addu r7,r0,r0           |{{f/std|<nowiki>r7 = 0x00 </nowiki>}}
  0017cd68: 84830002 lh r3,0x0002(r4) load last attack used
+
  0017cd40: 3c018006 lui r1,0x8006           |
  0017cd6c: 00000000 nop
+
  0017cd44: 00220821 addu r1,r1,r2           |{{f/std|<nowiki>r1 = 0x 80060000 + Skillset ID</nowiki>}}
  0017cd70: 28620170 slti r2,r3,0x0170 set if last attack was an action ability
+
  0017cd48: 90265cb4 lbu r6,0x5cb4(r1)       |{{f/load|<nowiki>r6 = action menu of skillset </nowiki>}} {{f/std|<nowiki> 0x80065cb4 + Skillset ID</nowiki>}}
  0017cd74: 1040000c beq r2,r0,0x0017cda8 branch if not
+
  0017cd4c: 00008821 addu r17,r0,r0           |{{f/std|<nowiki>r17 = 0x00</nowiki>}}
  0017cd78: 000310c0 sll r2,r3,0x03
+
  0017cd50: 30c300ff andi r3,r6,0x00ff       |{{f/std|<nowiki>r3 = Action menu last byte</nowiki>}}
  0017cd7c: 00431023 subu r2,r2,r3
+
  0017cd54: 10600004 beq r3,r0,0x0017cd68     {{f/Cond|<nowiki>If not [Default]</nowiki>}} /If [Default] branch to Ability data 2 loading section
  0017cd80: 00021040 sll r2,r2,0x01
+
  0017cd58: a0a00000 sb r0,0x0000(r5)         |{{f/store|<nowiki>store 0x00 on PR stack</nowiki>}}
  0017cd84: 3c038006 lui r3,0x8006
+
  0017cd5c: 34020006 ori r2,r0,0x0006             |{{f/std|<nowiki>r2 = 0x06</nowiki>}}
  0017cd88: 2463fbf0 addiu r3,r3,0xfbf0
+
  0017cd60: 14620013 bne r3,r2,0x0017cdb0         {{f/Cond|<nowiki>If action menu is [Monster]</nowiki>}} {{f/Cond|<nowiki>Else branch to Attack check section</nowiki>}}
  0017cd8c: 00431021 addu r2,r2,r3 r2 = ability data pointer
+
  0017cd64: 34020008 ori r2,r0,0x0008             |{{f/std|<nowiki>r2 = 0x08 (action menu [Attack] ID)</nowiki>}}
  0017cd90: 90430005 lbu r3,0x0005(r2) load flags 3
+
  0017cd68: 84830002 lh r3,0x0002(r4)         {{f/Cond|<nowiki>E  </nowiki>}}    | {{f/load|<nowiki>r3 = Attacker last attack used</nowiki>}}
  0017cd94: 00000000 nop
+
  0017cd6c: 00000000 nop                               |
  0017cd98: a0a30000 sb r3,0x0000(r5) store on the stack?
+
  0017cd70: 28620170 slti r2,r3,0x0170                 |{{f/std|<nowiki>r2 = 0x01 if last used ability ID < 0x170 ([Potion] ID)</nowiki>}}
  0017cd9c: 90480006 lbu r8,0x0006(r2) load flags 4
+
  0017cd74: 1040000c beq r2,r0,0x0017cda8             {{f/Cond|<nowiki>If Ability ID < [Potion] ID</nowiki>}} {{f/Cond|<nowiki>branch if not</nowiki>}}
  0017cda0: 90470003 lbu r7,0x0003(r2) load flags 1
+
  0017cd78: 000310c0 sll r2,r3,0x03                       |{{f/std|<nowiki>r2 = Last ability ID * 8</nowiki>}}
  0017cda4: 90510004 lbu r17,0x0004(r2) load flags 2
+
  0017cd7c: 00431023 subu r2,r2,r3                         |{{f/std|<nowiki>r2 = Last ability ID * 7</nowiki>}}
  0017cda8: 30c300ff andi r3,r6,0x00ff
+
  0017cd80: 00021040 sll r2,r2,0x01                       |{{f/std|<nowiki>r2 = Last ability ID * 14</nowiki>}}
  0017cdac: 34020008 ori r2,r0,0x0008
+
  0017cd84: 3c038006 lui r3,0x8006                         |
  0017cdb0: 1062000a beq r3,r2,0x0017cddc branch if action menu = attack
+
  0017cd88: 2463fbf0 addiu r3,r3,-0x0410                  |{{f/std|<nowiki>r3 = 0x8005fbf0 </nowiki>}} {{f/std|<nowiki>(Ability Data 2 - Exists only for abilities 0x000 to 0x16F)</nowiki>}}
  0017cdb4: 3402000a ori r2,r0,0x000a
+
  0017cd8c: 00431021 addu r2,r2,r3                         |{{f/adr|<nowiki>r2 = Attacker last used Ability data 2 pointer</nowiki>}}
  0017cdb8: 10620008 beq r3,r2,0x0017cddc branch if action menu = charge
+
  0017cd90: 90430005 lbu r3,0x0005(r2)                     |{{f/load|<nowiki>r3 = Attacker last used ability flags 3</nowiki>}}
  0017cdbc: 24c2ffff addiu r2,r6,0xffff
+
  0017cd94: 00000000 nop                                   |
  0017cdc0: 2c420002 sltiu r2,r2,0x0002
+
  0017cd98: a0a30000 sb r3,0x0000(r5)                     |{{f/store|<nowiki>store Attacker last used ability flags 3 on the stack</nowiki>}}
  0017cdc4: 14400005 bne r2,r0,0x0017cddc branch if item/weapon inventory
+
  0017cd9c: 90480006 lbu r8,0x0006(r2)                     |{{f/load|<nowiki>r8 = Attacker last used ability flags 4</nowiki>}}
  0017cdc8: 31020020 andi r2,r8,0x0020
+
  0017cda0: 90470003 lbu r7,0x0003(r2)                     |{{f/load|<nowiki>r7 = Attacker last used ability flags 1</nowiki>}}
  0017cdcc: 14400003 bne r2,r0,0x0017cddc branch if direct attack flag is true
+
  0017cda4: 90510004 lbu r17,0x0004(r2)                   |{{f/load|<nowiki>r17 = Attacker last used ability flags 2</nowiki>}}
  0017cdd0: 30e20020 andi r2,r7,0x0020
+
  0017cda8: 30c300ff andi r3,r6,0x00ff                 |{{f/std|<nowiki>r3 = Action menu last byte</nowiki>}}
  0017cdd4: 10400005 beq r2,r0,0x0017cdec branch if not ranged weapon  
+
  0017cdac: 34020008 ori r2,r0,0x0008                 |{{f/std|<nowiki>r2 = 0x08 (action menu [Attack] ID)</nowiki>}}
  0017cdd8: 00000000 nop
+
  0017cdb0: 1062000a beq r3,r2,0x0017cddc     {{f/Cond|<nowiki>If action menu <> [Attack]</nowiki>}} / if action menu = [attack] branch to  Targeting_validation_(weapon_flags)
  0017cddc: 0c05eb24 jal 0x0017ac90 [[Targeting validation (weapon flags)]]
+
  0017cdb4: 3402000a ori r2,r0,0x000a             |{{f/std|<nowiki>r2 = 0x0a ([Charge] ID</nowiki>}}
  0017cde0: 00000000 nop returns 0x00 -success, 0xff - fail
+
  0017cdb8: 10620008 beq r3,r2,0x0017cddc         {{f/Cond|<nowiki>If action menu <> [Charge]</nowiki>}} / if action menu = [charge] branch to Targeting_validation_(weapon_flags)
  0017cde4: 0805f38a j 0x0017ce28 jump to end,
+
  0017cdbc: 24c2ffff addiu r2,r6,-0x0001              |{{f/std|<nowiki>r2 = action menu ID - 0x01</nowiki>}}
  0017cde8: 00408021 addu r16,r2,r0
+
  0017cdc0: 2c420002 sltiu r2,r2,0x0002               |{{f/std|<nowiki>r2 = 0x01 if action menu is [Item] or [Weapon inventory]</nowiki>}}
  0017cdec: 0c05eabe jal 0x0017aaf8                     [[Calculate Targeting for Menu Types]]
+
  0017cdc4: 14400005 bne r2,r0,0x0017cddc             {{f/Cond|<nowiki>If action menu is not [Item] nor [Weapon inventory]</nowiki>}} / if action menu = [Item] or [Weapon inventory] branch to Targeting_validation_(weapon_flags)
  0017cdf0: 00000000 nop
+
  0017cdc8: 31020020 andi r2,r8,0x0020                     |{{f/std|<nowiki>r2 = 0x20 if action menu is [Default] or [Monster] and stop at obstacle is checked</nowiki>}}
  0017cdf4: 00408021 addu r16,r2,r0
+
  0017cdcc: 14400003 bne r2,r0,0x0017cddc                 {{f/Cond|<nowiki>If Stop at obstacle is not checked (only [Default] and [Monster] action menus)</nowiki>}}
  0017cdf8: 2402ffff addiu r2,r0,0xffff
+
  0017cdd0: 30e20020 andi r2,r7,0x0020                         |{{f/std|<nowiki>r2 = 0x20 if action menu is [Default] or [Monster] and ranged weapon  is checked</nowiki>}}
  0017cdfc: 1202000a beq r16,r2,0x0017ce28
+
  0017cdd4: 10400005 beq r2,r0,0x0017cdec                     {{f/Cond|<nowiki>If ranged weapon is checked (only [Default] and [Monster] action menus)</nowiki>}}
  0017ce00: 32220008 andi r2,r17,0x0008
+
  0017cdd8: 00000000 nop                                           |
  0017ce04: 10400009 beq r2,r0,0x0017ce2c
+
  0017ce08: 02001021 addu r2,r16,r0
+
                                            {{f/com|<nowiki>*** Attack, Charge, Item, weapon inventory // Default and Monster if Stops at obstacle or weapon ranged</nowiki>}}
  0017ce0c: 3c028019 lui r2,0x8019
+
  0017cddc: 0c05eb24 jal 0x0017ac90           {{f/Cond|<nowiki>E  </nowiki>}} {{f/Cond|<nowiki>E  </nowiki>}} {{f/Cond|<nowiki>E  </nowiki>}} {{f/Cond|<nowiki>E  </nowiki>}} {{f/jal|Targeting_validation_(weapon_flags)|<nowiki>Targeting_validation_(weapon_flags)</nowiki>}} Returns r2 = 0x00 if Green flag is updated, -0x01 if target/weapon are invalids
  0017ce10: 8c42f5fc lw r2,-0x0a04(r2)
+
  0017cde0: 00000000 nop                                           |{{f/std|<nowiki> </nowiki>}}
  0017ce14: 00000000 nop
+
  0017cde4: 0805f38a j 0x0017ce28                                 {{f/jump|<nowiki>jump to </nowiki>}} {{f/loc|<nowiki>END</nowiki>}}
  0017ce18: 14400004 bne r2,r0,0x0017ce2c
+
  0017cde8: 00408021 addu r16,r2,r0                               |{{f/std|<nowiki>r16 = 0x00 or -0x01</nowiki>}}
  0017ce1c: 02001021 addu r2,r16,r0
+
  0017ce20: 0c05f5c2 jal 0x0017d708                     [[0017d708 - 0017d84c]]
+
                                            {{f/com|<nowiki>*** All Other Action menus (Elements, katana inventory, Mathematics, jump etc...) and Monster and Default if don't stops at obstacle nor weapon ranged</nowiki>}}
  0017ce24: 00000000 nop
+
  0017cdec: 0c05eabe jal 0x0017aaf8                           {{f/Cond|<nowiki>Else </nowiki>}} {{f/jal|Calculate Targeting for Menu Types|<nowiki>Calculate Targeting for Menu Types</nowiki>}} Return r2 = 0x00 or 0x01 if a tile has been hitted (0x02 or -0x01 if not)
  0017ce28: 02001021 addu r2,r16,r0 return value
+
  0017cdf0: 00000000 nop                                           |
  0017ce2c: 8fbf0018 lw r31,0x0018(r29)
+
  0017cdf4: 00408021 addu r16,r2,r0                               |{{f/std|<nowiki>r16 = Targeting result</nowiki>}}
  0017ce30: 8fb10014 lw r17,0x0014(r29)
+
  0017cdf8: 2402ffff addiu r2,r0-0x0001                            |{{f/std|<nowiki>r2 = -0x01</nowiki>}}
  0017ce34: 8fb00010 lw r16,0x0010(r29)
+
  0017cdfc: 1202000a beq r16,r2,0x0017ce28                         {{f/Cond|<nowiki>If Targeting routine returns something valid</nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (with r2 =-0x01)
  0017ce38: 27bd0020 addiu r29,r29,0x0020
+
  0017ce00: 32220008 andi r2,r17,0x0008                           |{{f/std|<nowiki>r2<> 0x00 if Used ability is random fire</nowiki>}}
  0017ce3c: 03e00008 jr r31
+
  0017ce04: 10400009 beq r2,r0,0x0017ce2c                             {{f/Cond|<nowiki>If Last used Ability is random fire</nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (with r2 = hitted tiles counter)
  0017ce40: 00000000 nop</font>
+
  0017ce08: 02001021 addu r2,r16,r0                                   |{{f/std|<nowiki>r2 = Targeting result</nowiki>}}
 +
  0017ce0c: 3c028019 lui r2,0x8019                                         |{{f/std|<nowiki>r2 = 0x80190000</nowiki>}}
 +
  0017ce10: 8c42f5fc lw r2,-0x0a04(r2)                                     |{{f/adr|<nowiki>r2 = Action State</nowiki>}} {{f/std|<nowiki> 0x8018f5fc</nowiki>}}
 +
  0017ce14: 00000000 nop                                                   |
 +
  0017ce18: 14400004 bne r2,r0,0x0017ce2c                                 {{f/Cond|<nowiki>If Action is executing (not AI nor preview)</nowiki>}} /Else branch to {{f/loc|<nowiki>END</nowiki>}} (with r2 = hitted tiles counter)
 +
  0017ce1c: 02001021 addu r2,r16,r0                                       |{{f/std|<nowiki>r2 = Targeting result</nowiki>}}
 +
  0017ce20: 0c05f5c2 jal 0x0017d708                                           |{{f/jal|Select_Random_Tile_For_Random_Fire_Abilities|<nowiki>Select_Random_Tile_For_Random_Fire_Abilities</nowiki>}} Keeps only one random tile with green panel
 +
  0017ce24: 00000000 nop                                                       |
 +
  0017ce28: 02001021 addu r2,r16,r0                               {{f/Cond|<nowiki>E  </nowiki>}}        |{{f/std|<nowiki>r2 = Targeting result</nowiki>}}
 +
  0017ce2c: 8fbf0018 lw r31,0x0018(r29)                          
 +
  0017ce30: 8fb10014 lw r17,0x0014(r29)                          
 +
  0017ce34: 8fb00010 lw r16,0x0010(r29)                          
 +
  0017ce38: 27bd0020 addiu r29,r29,0x0020                        
 +
  0017ce3c: 03e00008 jr r31                                      
 +
  0017ce40: 00000000
 +
=== Notes ===
 +
If Action menu is default or monster AND ability ID < Potion
 +
--> Load last used ability data 2 flag 1 to 4
 +
--> Store last used ability flag 3 on r5
 +
(Other Action menu : Ability flag 1,2 and 4 are stays to 0x00)
 +
 +
Action menu = Attack, Charge, Item, weapon inventory
 +
If Ability stops at obstacle or is ranged weapon (monster default)
 +
  --> Jal to [[Targeting_validation_(weapon_flags)]]
 +
  Jump to end
 +
 +
 
 +
If Monster or Default without stop at obstacle nor weapon ranged
 +
Others Action menus (Elements, katana inventory, Mathematics, jump etc...)
 +
--> jal [[Calculate Targeting for Menu Types]]
 +
=== Return loaction ===
 +
'''Battle.bin'''
 +
0017cf8c: [[Main_ability_loading_routine%3F]]
 +
0017f1fc: [[Calculate_Projected_Action_Effect]]

Latest revision as of 19:49, 13 February 2022

0017cd24 - 0017ce40  Notes
 
Parameters : r4 = Attacker 0x16e data pointer
             r5 = Previous routine stack pointer

Returns : r2 = -0x01 if something is invalid (weapon, ability coordinates..)
          r2 = 0x00 if classic targeting
          r2 = 0x01 if mathematic targeting
          r2 = 0x02 if non offensive action menu was used
Store : Ability data 2 flags 3 on r5 (previous routine stack) - Only if action menu is default or monster
-------------------------------------------------------------------------------------------------------------
0017cd24: 27bdffe0 addiu r29,r29,0xffe0     |
0017cd28: 00004021 addu r8,r0,r0            |r8 = 0x00
0017cd2c: afbf0018 sw r31,0x0018(r29)       |
0017cd30: afb10014 sw r17,0x0014(r29)       |
0017cd34: afb00010 sw r16,0x0010(r29)       |
0017cd38: 90820001 lbu r2,0x0001(r4)        |r2 =  skillset of last attack 
0017cd3c: 00003821 addu r7,r0,r0            |r7 = 0x00 
0017cd40: 3c018006 lui r1,0x8006            |
0017cd44: 00220821 addu r1,r1,r2            |r1 = 0x 80060000 + Skillset ID
0017cd48: 90265cb4 lbu r6,0x5cb4(r1)        |r6 = action menu of skillset   0x80065cb4 + Skillset ID
0017cd4c: 00008821 addu r17,r0,r0           |r17 = 0x00
0017cd50: 30c300ff andi r3,r6,0x00ff        |r3 = Action menu last byte
0017cd54: 10600004 beq r3,r0,0x0017cd68     #If not [Default] /If [Default] branch to Ability data 2 loading section
0017cd58: a0a00000 sb r0,0x0000(r5)         |store 0x00 on PR stack
0017cd5c: 34020006 ori r2,r0,0x0006              |r2 = 0x06
0017cd60: 14620013 bne r3,r2,0x0017cdb0          #If action menu is [Monster] #Else branch to Attack check section
0017cd64: 34020008 ori r2,r0,0x0008              |r2 = 0x08 (action menu [Attack] ID)
0017cd68: 84830002 lh r3,0x0002(r4)         #E       | r3 = Attacker last attack used
0017cd6c: 00000000 nop                               |
0017cd70: 28620170 slti r2,r3,0x0170                 |r2 = 0x01 if last used ability ID < 0x170 ([Potion] ID)
0017cd74: 1040000c beq r2,r0,0x0017cda8              #If Ability ID < [Potion] ID #branch if not
0017cd78: 000310c0 sll r2,r3,0x03                        |r2 = Last ability ID * 8
0017cd7c: 00431023 subu r2,r2,r3                         |r2 = Last ability ID * 7
0017cd80: 00021040 sll r2,r2,0x01                        |r2 = Last ability ID * 14
0017cd84: 3c038006 lui r3,0x8006                         |
0017cd88: 2463fbf0 addiu r3,r3,-0x0410                   |r3 = 0x8005fbf0  (Ability Data 2 - Exists only for abilities 0x000 to 0x16F)
0017cd8c: 00431021 addu r2,r2,r3                         |r2 = Attacker last used Ability data 2 pointer
0017cd90: 90430005 lbu r3,0x0005(r2)                     |r3 = Attacker last used ability flags 3
0017cd94: 00000000 nop                                   |
0017cd98: a0a30000 sb r3,0x0000(r5)                      |store Attacker last used ability flags 3 on the stack
0017cd9c: 90480006 lbu r8,0x0006(r2)                     |r8 = Attacker last used ability flags 4
0017cda0: 90470003 lbu r7,0x0003(r2)                     |r7 = Attacker last used ability flags 1
0017cda4: 90510004 lbu r17,0x0004(r2)                    |r17 = Attacker last used ability flags 2
0017cda8: 30c300ff andi r3,r6,0x00ff                 |r3 = Action menu last byte
0017cdac: 34020008 ori r2,r0,0x0008                  |r2 = 0x08 (action menu [Attack] ID)
0017cdb0: 1062000a beq r3,r2,0x0017cddc     #If action menu <> [Attack] / if action menu = [attack] branch to  Targeting_validation_(weapon_flags)
0017cdb4: 3402000a ori r2,r0,0x000a              |r2 = 0x0a ([Charge] ID
0017cdb8: 10620008 beq r3,r2,0x0017cddc          #If action menu <> [Charge] / if action menu = [charge] branch to Targeting_validation_(weapon_flags)
0017cdbc: 24c2ffff addiu r2,r6,-0x0001               |r2 = action menu ID - 0x01
0017cdc0: 2c420002 sltiu r2,r2,0x0002                |r2 = 0x01 if action menu is [Item] or [Weapon inventory]
0017cdc4: 14400005 bne r2,r0,0x0017cddc              #If action menu is not [Item] nor [Weapon inventory] / if action menu = [Item] or [Weapon inventory] branch to Targeting_validation_(weapon_flags)
0017cdc8: 31020020 andi r2,r8,0x0020                     |r2 = 0x20 if action menu is [Default] or [Monster] and stop at obstacle is checked
0017cdcc: 14400003 bne r2,r0,0x0017cddc                  #If Stop at obstacle is not checked (only [Default] and [Monster] action menus) 
0017cdd0: 30e20020 andi r2,r7,0x0020                         |r2 = 0x20 if action menu is [Default] or [Monster] and ranged weapon  is checked
0017cdd4: 10400005 beq r2,r0,0x0017cdec                      #If ranged weapon is checked (only [Default] and [Monster] action menus) 
0017cdd8: 00000000 nop                                           |

                                            *** Attack, Charge, Item, weapon inventory // Default and Monster if Stops at obstacle or weapon ranged
0017cddc: 0c05eb24 jal 0x0017ac90           #E   #E   #E    #E   -->Targeting_validation_(weapon_flags) Returns r2 = 0x00 if Green flag is updated, -0x01 if target/weapon are invalids
0017cde0: 00000000 nop                                           | 
0017cde4: 0805f38a j 0x0017ce28                                  >>jump to  END
0017cde8: 00408021 addu r16,r2,r0                                |r16 = 0x00 or -0x01

                                            *** All Other Action menus (Elements, katana inventory, Mathematics, jump etc...) and Monster and Default if don't stops at obstacle nor weapon ranged
0017cdec: 0c05eabe jal 0x0017aaf8                            #Else  -->Calculate Targeting for Menu Types Return r2 = 0x00 or 0x01 if a tile has been hitted (0x02 or -0x01 if not)
0017cdf0: 00000000 nop                                           |
0017cdf4: 00408021 addu r16,r2,r0                                |r16 = Targeting result
0017cdf8: 2402ffff addiu r2,r0-0x0001                            |r2 = -0x01
0017cdfc: 1202000a beq r16,r2,0x0017ce28                         #If Targeting routine returns something valid /Else branch to END (with r2 =-0x01)
0017ce00: 32220008 andi r2,r17,0x0008                            |r2<> 0x00 if Used ability is random fire
0017ce04: 10400009 beq r2,r0,0x0017ce2c                              #If Last used Ability is random fire /Else branch to END (with r2 = hitted tiles counter)
0017ce08: 02001021 addu r2,r16,r0                                    |r2 = Targeting result
0017ce0c: 3c028019 lui r2,0x8019                                         |r2 = 0x80190000
0017ce10: 8c42f5fc lw r2,-0x0a04(r2)                                     |r2 = Action State  0x8018f5fc
0017ce14: 00000000 nop                                                   |
0017ce18: 14400004 bne r2,r0,0x0017ce2c                                  #If Action is executing (not AI nor preview) /Else branch to END (with r2 = hitted tiles counter)
0017ce1c: 02001021 addu r2,r16,r0                                        |r2 = Targeting result
0017ce20: 0c05f5c2 jal 0x0017d708                                            |-->Select_Random_Tile_For_Random_Fire_Abilities Keeps only one random tile with green panel
0017ce24: 00000000 nop                                                       |
0017ce28: 02001021 addu r2,r16,r0                                #E          |r2 = Targeting result
0017ce2c: 8fbf0018 lw r31,0x0018(r29)                            
0017ce30: 8fb10014 lw r17,0x0014(r29)                            
0017ce34: 8fb00010 lw r16,0x0010(r29)                            
0017ce38: 27bd0020 addiu r29,r29,0x0020                          
0017ce3c: 03e00008 jr r31                                        
0017ce40: 00000000

Notes

If Action menu is default or monster AND ability ID < Potion
--> Load last used ability data 2 flag 1 to 4
--> Store last used ability flag 3 on r5
(Other Action menu : Ability flag 1,2 and 4 are stays to 0x00)

Action menu = Attack, Charge, Item, weapon inventory
If Ability stops at obstacle or is ranged weapon (monster default)
 --> Jal to Targeting_validation_(weapon_flags)
 Jump to end

 
If Monster or Default without stop at obstacle nor weapon ranged
Others Action menus (Elements, katana inventory, Mathematics, jump etc...)
--> jal Calculate Targeting for Menu Types

Return loaction

Battle.bin
0017cf8c: Main_ability_loading_routine?
0017f1fc: Calculate_Projected_Action_Effect