Difference between revisions of "Reaction Target/Hit Calculation"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m
m
 
Line 154: Line 154:
 
  0017ccd8: 30620004 andi r2,r3,0x0004        |{{f/std|<nowiki>r2 = 0x04 if this flag is enabled (target self ?)</nowiki>}}
 
  0017ccd8: 30620004 andi r2,r3,0x0004        |{{f/std|<nowiki>r2 = 0x04 if this flag is enabled (target self ?)</nowiki>}}
 
  0017ccdc: 10400004 beq r2,r0,0x0017ccf0    {{f/Cond|<nowiki>If self targetting is enabled</nowiki>}} /Else skip {{f/Cond|<nowiki>Branch if ? doesn't have 0x4</nowiki>}}
 
  0017ccdc: 10400004 beq r2,r0,0x0017ccf0    {{f/Cond|<nowiki>If self targetting is enabled</nowiki>}} /Else skip {{f/Cond|<nowiki>Branch if ? doesn't have 0x4</nowiki>}}
  0017cce0: 34020001 ori r2,r0,0x0001              |{{f/std|<nowiki>r2 = 0x01</nowiki>}} {{f/std|<nowiki>r2 = 1</nowiki>}}
+
  0017cce0: 34020001 ori r2,r0,0x0001              |{{f/std|<nowiki>r2 = 0x01</nowiki>}}  
 
  0017cce4: ae220000 sw r2,0x0000(r17)            |{{f/store|<nowiki>Store 0x01 on stack pointer 1 (1 unit hit)</nowiki>}} {{f/store|<nowiki>Store #Targets = 1</nowiki>}}
 
  0017cce4: ae220000 sw r2,0x0000(r17)            |{{f/store|<nowiki>Store 0x01 on stack pointer 1 (1 unit hit)</nowiki>}} {{f/store|<nowiki>Store #Targets = 1</nowiki>}}
 
  0017cce8: 0805f341 j 0x0017cd04                  {{f/jump|<nowiki>Jump to </nowiki>{{f/loc|<nowiki>End</nowiki>}}<nowiki> </nowiki>}} r2 will is set to 0x01
 
  0017cce8: 0805f341 j 0x0017cd04                  {{f/jump|<nowiki>Jump to </nowiki>{{f/loc|<nowiki>End</nowiki>}}<nowiki> </nowiki>}} r2 will is set to 0x01
 
  0017ccec: a2440000 sb r4,0x0000(r18)            |{{f/store|<nowiki>Store Attacker ID on Stack 2 (hitted unit ID)</nowiki>}} {{f/store|<nowiki>Store ID on Stack 3</nowiki>}}
 
  0017ccec: a2440000 sb r4,0x0000(r18)            |{{f/store|<nowiki>Store Attacker ID on Stack 2 (hitted unit ID)</nowiki>}} {{f/store|<nowiki>Store ID on Stack 3</nowiki>}}
 
  0017ccf0: 30620008 andi r2,r3,0x0008        |{{f/std|<nowiki>r2 = 0x08 is enabled (counter ?)</nowiki>}}
 
  0017ccf0: 30620008 andi r2,r3,0x0008        |{{f/std|<nowiki>r2 = 0x08 is enabled (counter ?)</nowiki>}}
  0017ccf4: 14400003 bne r2,r0,0x0017cd04    {{f/Cond|<nowiki>If 0x08 isn't enabled</nowiki>}} / Else Branch to end with r2 = 0x00 (and nothing stored on stack pointer 1) {{f/Cond|<nowiki>Branch if ? has 0x8</nowiki>}}
+
  0017ccf4: 14400003 bne r2,r0,0x0017cd04    {{f/Cond|<nowiki>If 0x08 isn't enabled</nowiki>}} / Else Branch to end with r2 = 0x00 (and nothing stored on stack pointer 1)
  0017ccf8: 00001021 addu r2,r0,r0            |{{f/std|<nowiki>r2 = 0x00</nowiki>}} {{f/std|<nowiki>r2 = 0</nowiki>}}
+
  0017ccf8: 00001021 addu r2,r0,r0            |{{f/std|<nowiki>r2 = 0x00</nowiki>}}
 
  0017ccfc: ae200000 sw r0,0x0000(r17)            |{{f/store|<nowiki>Store 0x00 on stack pointer 1 (0 units hitted)</nowiki>}}
 
  0017ccfc: ae200000 sw r0,0x0000(r17)            |{{f/store|<nowiki>Store 0x00 on stack pointer 1 (0 units hitted)</nowiki>}}
 
  0017cd00: 34020001 ori r2,r0,0x0001              |{{f/std|<nowiki>r2 = 0x01</nowiki>}}
 
  0017cd00: 34020001 ori r2,r0,0x0001              |{{f/std|<nowiki>r2 = 0x01</nowiki>}}

Latest revision as of 20:49, 5 December 2021

Set Targets number and targets ID list for most of reaction abilities (except counter abilities and auto potion - not supported here and flag 0x08 enabled)
------------------------------------------------------------------------------
Parameters: r5 = Attacker misc action data (misc 0x18c) r4 = Attacker ID	
            r6 = Main ability inner stack pointer 1 (r29 0x28)	
            r7 = Main ability inner stack pointer 2 (r29 0x10) 
 	
Returns :   r2 = 0x01 if reaction is reflect distribute or damage split (failed or not) 	
            r2 = 0x01 if other reaction with flag 0x04 enabled	
            r2 = 0x00 if other reaction with flag 0x08 enabled
	
Store :     If Reflect : Target coordinates in misc attacker data 0x1c 0x1d 0x1e 
            List of targets ID at previous routine r29 0x10
            Number of units hitted at previous routine r29 0x28
------------------------------------------------------------------------------
0017cacc: 27bdffd0 addiu r29,r29,0xffd0     |
0017cad0: 00a04021 addu r8,r5,r0            |r8 = Attacker misc action data (misc 0x18c)
0017cad4: afb1001c sw r17,0x001c(r29)       |
0017cad8: 00c08821 addu r17,r6,r0           |r17 = Stack Pointer 1 
0017cadc: afb20020 sw r18,0x0020(r29)       |
0017cae0: 00e09021 addu r18,r7,r0           |r18 = Stack Pointer 2
0017cae4: 000410c0 sll r2,r4,0x03           |r2 = Attacker ID *8
0017cae8: 00441023 subu r2,r2,r4            |r2 = Attacker ID *7
0017caec: 00021180 sll r2,r2,0x06           |r2 = Attacker ID *448  - = 0x1c0 (size of units data)
0017caf0: afb30024 sw r19,0x0024(r29)       |
0017caf4: 3c138019 lui r19,0x8019           |
0017caf8: 267308cc addiu r19,r19,0x08cc     |r19 = 0x801908cc (start of 1st unit data)
0017cafc: 00533821 addu r7,r2,r19           |r7 = Attacker data pointer
0017cb00: 3c038019 lui r3,0x8019            |
0017cb04: 84632d9c lh r3,0x2d9c(r3)         |r3 = Reaction ID
0017cb08: 340201bc ori r2,r0,0x01bc         |r2 = 0x01bc (distribute ability ID)
0017cb0c: afbf0028 sw r31,0x0028(r29)       |
0017cb10: 1062002a beq r3,r2,0x0017cbbc     #If Reaction ID <> Distribute /Else branch to distribute section
0017cb14: afb00018 sw r16,0x0018(r29)            |  
0017cb18: 286201bd slti r2,r3,0x01bd             |r2 = 1 if reaction ID < 0x1bd (MP switch ID)
0017cb1c: 10400005 beq r2,r0,0x0017cb34          #If reaction ID < MP switch
0017cb20: 340201b8 ori r2,r0,0x01b8                  |r2 = 0x1b8 (reflect ID)
0017cb24: 10620008 beq r3,r2,0x0017cb48              #If Reaction ID <> reflect /Else branch to reflect section
0017cb28: 00000000 nop                                   |  
0017cb2c: 0805f330 j 0x0017ccc0                          >>Jump to Other reaction section
0017cb30: 00000000 nop                                   |
0017cb34: 340201be ori r2,r0,0x01be              #Else - Reaction >= MP switch r2 = 0x1be (Damage split ID)
0017cb38: 10620051 beq r3,r2,0x0017cc80          #If reaction ID <> Damage split / Else branch to Damage split section
0017cb3c: 00000000 nop                               |  
0017cb40: 0805f330 j 0x0017ccc0                      >>Jump to Other reaction section
0017cb44: 00000000 nop                               |

                                            --- REFLECT SECTION ---
0017cb48: 90e4017a lbu r4,0x017a(r7)        |r4 = Attacker current action (ACA) Target tile X (position)
0017cb4c: 00000000 nop                      |
0017cb50: a104001c sb r4,0x001c(r8)         |Store ACA Target tile pos. X in Attacker misc. Current action tile pos. X
0017cb54: 90e5017e lbu r5,0x017e(r7)        |r5 = Attacker current action (ACA) Target tile Y (position)
0017cb58: 00000000 nop                      |
0017cb5c: a105001d sb r5,0x001d(r8)         |Store ACA Target tile pos. Y in Attacker misc. Current action tile pos. Y
0017cb60: 90e6017c lbu r6,0x017c(r7)        |r6 = Attacker current action (ACA) Target tile elevation
0017cb64: 0c05f722 jal 0x0017dc88           |-->Get_ID_of_Unit_if_Tile_is_Targetable retruns r2 = Unit ID if Theres a unit at coordinates / Else r2 < 0x00
0017cb68: a106001e sb r6,0x001e(r8)         |Store ACA Target tile elevation in Attacker misc. Current action tile elevation Store Target's Map Level
0017cb6c: 00408021 addu r16,r2,r0           |r16 = Target ID (or -0x01 if no units or -0x02 if coordinates are invalid)
0017cb70: 06000062 bltz r16,0x0017ccfc      #If Target is valid /Else jump to near end setting 0x00 on stack pointer 1 (hit counter) - r2 will be set to 0x01
0017cb74: 001010c0 sll r2,r16,0x03               |ID * 8
0017cb78: 00501023 subu r2,r2,r16                |ID * 7
0017cb7c: 00021180 sll r2,r2,0x06                |ID * 448 (0x1c0)
0017cb80: 00532821 addu r5,r2,r19                |r5 = Target's Data Pointer
0017cb84: 90a30182 lbu r3,0x0182(r5)             |r3 = Target mount info
0017cb88: 00000000 nop                           |
0017cb8c: 30620040 andi r2,r3,0x0040             |r2 = 0x40 if target is been ridden / Else 0x00
0017cb90: 10400003 beq r2,r0,0x0017cba0          #If target is being ridden /Else branch with r4 = Target ID
0017cb94: 02002021 addu r4,r16,r0                |r4 = Target ID
0017cb98: 3070001f andi r16,r3,0x001f                |r16 = Target Rider ID
0017cb9c: 02002021 addu r4,r16,r0                    |r4 = Target Rider ID
0017cba0: 0c05ef74 jal 0x0017bdd0                |-->Check_if_Unit_can_be_Targeted -returns r2 = 0x00 if unit can be targeted (else 0x01)
0017cba4: 27a50010 addiu r5,r29,0x0010           |r5 = Stack pointer for above jal  (routine will store here Target Tile ID - no use here ?)
0017cba8: 14400054 bne r2,r0,0x0017ccfc          #If Unit can be targeted /Else jump to near end setting 0x00 on stack pointer 1 (hit counter) - r2 will be set to 0x01
0017cbac: 34020001 ori r2,r0,0x0001                  |r2 = 0x01
0017cbb0: ae220000 sw r2,0x0000(r17)                 |Store 0x01 at stack pointer 1 (number of target ?)
0017cbb4: 0805f341 j 0x0017cd04                      >>Jump to End - r2 set to 0x01
0017cbb8: a2500000 sb r16,0x0000(r18)                |Store unit ID  on previous routine stack pointer 2

                                            --- Distribute section ---
0017cbbc: 00008021 addu r16,r0,r0           |r16 = 0x00 (will be hit counter)
0017cbc0: 00003021 addu r6,r0,r0            |r6 = 0x00 (will be routine counter)
0017cbc4: 340a00ff ori r10,r0,0x00ff        |r10 = 0xff
0017cbc8: 02604021 addu r8,r19,r0           |r8 = 1st Unit Data Pointer (0x801908cc)
0017cbcc: 90e20005 lbu r2,0x0005(r7)        |r2 = Attacker ENTD flags
0017cbd0: 02403821 addu r7,r18,r0           |r7 = Stack pointer 2 (list of units targeted (ID))
0017cbd4: 30490030 andi r9,r2,0x0030        |r9 = Attacker Unit's Team (filtered from ENTD byte)
0017cbd8: 10c40021 beq r6,r4,0x0017cc60     @LOOP  #If Counter <> acting unit ID /Else branch to next loop iteration Check all units
0017cbdc: 01002821 addu r5,r8,r0                     |r5 = Unit Data Pointer (r8 gains 0x1c0 each loop iteration)
0017cbe0: 90a20001 lbu r2,0x0001(r5)                 |r2 = Unit's ID
0017cbe4: 00000000 nop                               |
0017cbe8: 104a001d beq r2,r10,0x0017cc60             #If Unit's ID <> 0xff (unit exists) /Else branch to next loop iteration
0017cbec: 00000000 nop                                   | 
0017cbf0: 90a20182 lbu r2,0x0182(r5)                     |r2 = Unit's Mount info
0017cbf4: 00000000 nop                                   |
0017cbf8: 30420040 andi r2,r2,0x0040                     |r2 = 0x40 if unit is being ridden
0017cbfc: 14400018 bne r2,r0,0x0017cc60                  #If Unit is not ridden (?) /Else branch to next loop iteration
0017cc00: 00000000 nop                                       | 
0017cc04: 94a30028 lhu r3,0x0028(r5)                         |r3 = Unit's Current HP
0017cc08: 94a2002a lhu r2,0x002a(r5)                         |r2 =  Unit's Max HP
0017cc0c: 00000000 nop                                       |
0017cc10: 10620013 beq r3,r2,0x0017cc60                      #If Unit is not at Max HP /Else branch to next loop iteration
0017cc14: 00000000 nop                                           | 
0017cc18: 90a20058 lbu r2,0x0058(r5)                             |r2 = Unit's Current Statuses 1
0017cc1c: 00000000 nop                                           |
0017cc20: 30420064 andi r2,r2,0x0064                             |r2 <> 0x00 if unit has dead, crystal or is jumping
0017cc24: 1440000e bne r2,r0,0x0017cc60                          #If Unit has neither dead, crystal nor jump /Else branch to next loop iteration
0017cc28: 00000000 nop                                               | 
0017cc2c: 90a20059 lbu r2,0x0059(r5)                                 |r2 =  Unit's Current Statuses 2
0017cc30: 00000000 nop                                                   | 
0017cc34: 30420081 andi r2,r2,0x0081                                     |r2 <> 0x00 if unit has petrify or treasure
0017cc38: 14400009 bne r2,r0,0x0017cc60                                  #If unit has neither petrify nor treasure /Else branch to next loop iteration
0017cc3c: 00000000 nop                                                       | 
0017cc40: 90a201ba lbu r2,0x01ba(r5)                                         |r2 = Unit's modified ENTD flags ( 0x1ba )
0017cc44: 00000000 nop                                                       |
0017cc48: 30420030 andi r2,r2,0x0030                                         |r2 = Unit's team
0017cc4c: 14490004 bne r2,r9,0x0017cc60                                      #If unit's team = attacker team /Else branch to next loop iteration
0017cc50: afa20010 sw r2,0x0010(r29)                                         |Store unit team to stack (r29 0x10) (why ? It's unused…)
0017cc54: a0e60000 sb r6,0x0000(r7)                                              |Store counter (= unit ID) in stack pointer 2 + offset  (each time a unit is stored, r7 gain 0x01)
0017cc58: 24e70001 addiu r7,r7,0x0001                                            |r7 = Stack pointer + 0x01
0017cc5c: 26100001 addiu r16,r16,0x0001                                          |r16 = Hit counter + 0x01 (number of unit stored in r7)
0017cc60: 24c60001 addiu r6,r6,0x0001            |r6 = Loop counter + 0x01
0017cc64: 28c20015 slti r2,r6,0x0015             |r2 = 0x01 if loop counter < 0x15
0017cc68: 1440ffdb bne r2,r0,0x0017cbd8     Λ Loop while counter < 0x15
0017cc6c: 250801c0 addiu r8,r8,0x01c0            |r8 = Unit data pointer += 0x1c0  (used in loop)
0017cc70: 3c018019 lui r1,0x8019            | 
0017cc74: ac303878 sw r16,0x3878(r1)        |Store number of units hitted at 0x80193878
0017cc78: 0805f340 j 0x0017cd00             >>Jump to End  r2 will be set to 0x01
0017cc7c: ae300000 sw r16,0x0000(r17)       |Store number of units hitted on stack pointer 1

                                            --- Damage split section ---
0017cc80: 3c038019 lui r3,0x8019            |
0017cc84: 8c63f8c8 lw r3,-0x0738(r3)        |r3 =  Acting Unit's ID
0017cc88: 00000000 nop                      |
0017cc8c: 000310c0 sll r2,r3,0x03           |r2 =  Acting Unit's ID *8 ID * 8
0017cc90: 00431023 subu r2,r2,r3            |r2 =  Acting Unit's ID *7 ID * 7
0017cc94: 00021180 sll r2,r2,0x06           |r2 =  Acting Unit's ID *448 ID * 448
0017cc98: 00532821 addu r5,r2,r19           |r5 = Acting Unit's Data Pointer r5 = Unit's Data Pointer
0017cc9c: 90a30001 lbu r3,0x0001(r5)        |r3 = Acting unit ID (?) Load Unit's ID
0017cca0: 340200ff ori r2,r0,0x00ff         |r2 = 0xff
0017cca4: 10620015 beq r3,r2,0x0017ccfc     #If acting unit exists /Else jump to near end setting 0x00 on stack pointer 1 (hit counter) - r2 will be set to 0x01
0017cca8: 34020001 ori r2,r0,0x0001              |r2 = 0x01
0017ccac: ae220000 sw r2,0x0000(r17)             |Store 0x01 on stack pointer 1 (1 unit hit)
0017ccb0: 3c028019 lui r2,0x8019                 |
0017ccb4: 9042f8c8 lbu r2,-0x0738(r2)            |r2 = Acting unit ID
0017ccb8: 0805f340 j 0x0017cd00                  >>Jump to End  r2 will be set to 0x01
0017ccbc: a2420000 sb r2,0x0000(r18)             |Store Acting unit ID on Stack 2 (hitted unit ID list)

                                            --- Other Reactions ---
0017ccc0: 3c028019 lui r2,0x8019            |
0017ccc4: 84422d9c lh r2,0x2d9c(r2)         |r2 = Reaction ID
0017ccc8: 3c018006 lui r1,0x8006            |
0017cccc: 00220821 addu r1,r1,r2            |
0017ccd0: 9023ea2a lbu r3,-0x15d6(r1)       |r3 = Reaction Flags -->Reaction_Flags
0017ccd4: 00000000 nop                      |
0017ccd8: 30620004 andi r2,r3,0x0004        |r2 = 0x04 if this flag is enabled (target self ?)
0017ccdc: 10400004 beq r2,r0,0x0017ccf0     #If self targetting is enabled /Else skip #Branch if ? doesn't have 0x4
0017cce0: 34020001 ori r2,r0,0x0001              |r2 = 0x01 
0017cce4: ae220000 sw r2,0x0000(r17)             |Store 0x01 on stack pointer 1 (1 unit hit) Store #Targets = 1
0017cce8: 0805f341 j 0x0017cd04                  >>Jump to End  r2 will is set to 0x01
0017ccec: a2440000 sb r4,0x0000(r18)             |Store Attacker ID on Stack 2 (hitted unit ID) Store ID on Stack 3
0017ccf0: 30620008 andi r2,r3,0x0008        |r2 = 0x08 is enabled (counter ?)
0017ccf4: 14400003 bne r2,r0,0x0017cd04     #If 0x08 isn't enabled / Else Branch to end with r2 = 0x00 (and nothing stored on stack pointer 1)
0017ccf8: 00001021 addu r2,r0,r0            |r2 = 0x00
0017ccfc: ae200000 sw r0,0x0000(r17)             |Store 0x00 on stack pointer 1 (0 units hitted)
0017cd00: 34020001 ori r2,r0,0x0001              |r2 = 0x01
0017cd04: 8fbf0028 lw r31,0x0028(r29)       #END
0017cd08: 8fb30024 lw r19,0x0024(r29)       
0017cd0c: 8fb20020 lw r18,0x0020(r29)       
0017cd10: 8fb1001c lw r17,0x001c(r29)       
0017cd14: 8fb00018 lw r16,0x0018(r29)       
0017cd18: 27bd0030 addiu r29,r29,0x0030     
0017cd1c: 03e00008 jr r31                   
0017cd20: 00000000 nop

Return location

0017cf34: Main_ability_loading_routine?