Map calculations for attack

From Final Fantasy Hacktics Wiki
(Redirected from Map Calculations for Action)
Jump to navigation Jump to search
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