Difference between revisions of "AI ability processing"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m
 
Line 223: Line 223:
 
  0019e0ac: 16c00002 bne r22,r0,0x0019e0b8                {{f/Cond|If Self Targeting}} {{f/loc|Avoid AI e4e}}
 
  0019e0ac: 16c00002 bne r22,r0,0x0019e0b8                {{f/Cond|If Self Targeting}} {{f/loc|Avoid AI e4e}}
 
  0019e0b0: 34020001 ori r2,r0,0x0001                      |
 
  0019e0b0: 34020001 ori r2,r0,0x0001                      |
  0019e0b4: a2220e4e sb r2,0x0e4e(r17)             |{{f/store|<nowiki>Update 0xe4e = 0x1</nowiki>}} {{f/std|If Usefull on caster and self-targeting or Adverse on caster but not self Targeting}}
+
  0019e0b4: a2220e4e sb r2,0x0e4e(r17)                 |{{f/store|<nowiki>Update 0xe4e = 0x1</nowiki>}} {{f/std|If Usefull on caster and self-targeting or Adverse on caster but not self Targeting}}
 
  0019e0b8: 92820000 lbu r2,0x0000(r20)        |{{f/load|Load Acting Unit's ID}}
 
  0019e0b8: 92820000 lbu r2,0x0000(r20)        |{{f/load|Load Acting Unit's ID}}
 
  0019e0bc: 3c108019 lui r16,0x8019            |
 
  0019e0bc: 3c108019 lui r16,0x8019            |

Latest revision as of 19:48, 6 June 2024

BATTLE.BIN :  - AI_ability_processing
Handles Ability simulation (including potential reflect) - Set some AI flags (hostility check, Effect on acting unit) - Change priority (mostly for Ability that affect stats)
------------------------------------------------------------------------------------------
Parameter : r4 : Pointer to Action Data (Battle 0x16e format) - Acting Unit or Targeted Unit with reflect
            r5 = 0x00 if Acting Unit Action / 0x01 if Target with Reflect (recursive call)
Return : Nothing
------------------------------------------------------------------------------------------
0019dd8c: 27bdff90 addiu r29,r29,-0x0070     |
0019dd90: afb40058 sw r20,0x0058(r29)        |
0019dd94: 0080a021 addu r20,r4,r0            |Pointer to Action Data (Battle 0x16e format)
0019dd98: afb1004c sw r17,0x004c(r29)        |
0019dd9c: 3c11801a lui r17,0x801a            |
0019dda0: 2631f3c4 addiu r17,r17,-0x0c3c     |AI data pointer  ( 0x8019f3c4 )
0019dda4: afbf006c sw r31,0x006c(r29)        |
0019dda8: afbe0068 sw r30,0x0068(r29)        |
0019ddac: afb70064 sw r23,0x0064(r29)        |
0019ddb0: afb60060 sw r22,0x0060(r29)        |
0019ddb4: afb5005c sw r21,0x005c(r29)        |
0019ddb8: afb30054 sw r19,0x0054(r29)        |
0019ddbc: afb20050 sw r18,0x0050(r29)        |
0019ddc0: afb00048 sw r16,0x0048(r29)        |
0019ddc4: 14a00006 bne r5,r0,0x0019dde0      #If Preset Value = 0x00 (Acting Unit Action)
0019ddc8: afa50040 sw r5,0x0040(r29)         |Store Preset Value (PV)
0019ddcc: 92840000 lbu r4,0x0000(r20)            |Load Acting Unit's ID
0019ddd0: 0c05f26e jal 0x0017c9b8                |-->Prep_Current_Action_Data returns 0x00 if Ability can be used
0019ddd4: 00000000 nop                           |
0019ddd8: 144000d4 bne r2,r0,0x0019e12c          #If Ability cannot be used :  Exit returns r2 (not 0x00 value depends of incapacity)
0019dddc: 00000000 nop                           |
0019dde0: 86820002 lh r2,0x0002(r20)         |Load Unit's Used Ability ID
0019dde4: 3c038006 lui r3,0x8006             |
0019dde8: 2463ebf4 addiu r3,r3,-0x140c       |
0019ddec: 000210c0 sll r2,r2,0x03            |ID * 8
0019ddf0: 00439821 addu r19,r2,r3            |Pointer to considered Ability AI behavior  8005ebf0 + 0x04
0019ddf4: 3c03801a lui r3,0x801a             |
0019ddf8: 9063007e lbu r3,0x007e(r3)         |Load 801a007e ( AI 0xcba)
0019ddfc: 340200ff ori r2,r0,0x00ff          |r2 = 0xff
0019de00: 1062000a beq r3,r2,0x0019de2c      #If Target/Hit counter <> 0xff Is Set and did not reach his limit ? If 0xff the routine will ignore priority aspect
0019de04: 341500ff ori r21,r0,0x00ff         |r21 = 0xff
0019de08: 0000b021 addu r22,r0,r0                |Initialize self Targeting flag
0019de0c: 0000f021 addu r30,r0,r0                |Set default positive priority (in this routine)
0019de10: 92620000 lbu r2,0x0000(r19)            |Load Ability's AI Behavior 1
0019de14: 00000000 nop                           |
0019de18: 30420008 andi r2,r2,0x0008             |
0019de1c: 10400003 beq r2,r0,0x0019de2c          #If Ability has [Affect stats]
0019de20: 34170001 ori r23,r0,0x0001             |Set default negative priority (in this routine)
0019de24: 341e0003 ori r30,r0,0x0003                 |Hardcoded [Affect stats] positive priority
0019de28: 34170004 ori r23,r0,0x0004                 |Hardcoded [Affect stats] negative priority  (undesired effect)

                  MAIN TARGET/STRIKE LOOP
                                            @LOOP - Until end of action (all strikes)
0019de2c: 92840000 lbu r4,0x0000(r20)            |r4 = Acting Unit's ID
0019de30: 0c05f391 jal 0x0017ce44                |-->Main_ability_loading_routine%3F Mimic action
0019de34: 27a50010 addiu r5,r29,0x0010           |r5 = Stack Pointer + 0x10 (will mimic miscellaneous Unit pointer 0x18c)
0019de38: 14400083 bne r2,r0,0x0019e048          #If ability is not hitting a unit Exit Loop
0019de3c: 00000000 nop                           |
0019de40: 93a20011 lbu r2,0x0011(r29)            |Number of Targets pseudo AU misc 0x18d
0019de44: 00000000 nop                           |
0019de48: 1040007f beq r2,r0,0x0019e048          #If there's no Targets  Exit Loop
0019de4c: 27a30012 addiu r3,r29,0x0012           |Pointer to Stack 0x12 (list of Targets ID) Pseudo Misc 0x18e
0019de50: 93a20012 lbu r2,0x0012(r29)            |Load This iteration Target ID
0019de54: 00000000 nop                           |
0019de58: 1055007b beq r2,r21,0x0019e048         #If This is the end of Targets list Exit Loop
0019de5c: afa00038 sw r0,0x0038(r29)             |Initialize Target counter
                                                @LOOP - Each Target in List
0019de60: 8fa20038 lw r2,0x0038(r29)                 |Target Counter
0019de64: 00000000 nop                               |
0019de68: 00621021 addu r2,r3,r2                     |Dynamic Pointer to Target list+ Offset (1 byte)
0019de6c: 90500000 lbu r16,0x0000(r2)                |This iteration Target ID
0019de70: 3c038019 lui r3,0x8019                     |
0019de74: 24630a58 addiu r3,r3,0x0a58                |801908cc + 0x18c
0019de78: 001010c0 sll r2,r16,0x03                   |
0019de7c: 00501023 subu r2,r2,r16                    |
0019de80: 00021180 sll r2,r2,0x06                    |Unit ID * 0x1c0
0019de84: 00439021 addu r18,r2,r3                    |This Unit Current Action data pointer 801908cc + 0x18c + Unit offset
0019de88: 8642002a lh r2,0x002a(r18)                 |Load Hit % (Displayed Amount)
0019de8c: 00000000 nop                               |
0019de90: 18400064 blez r2,0x0019e024                #If Target Current Action Hit% is 0 (or less) branch to Next Target
0019de94: 00000000 nop                               |
0019de98: 92620001 lbu r2,0x0001(r19)                |Load AI Ability Behavior Flag 2
0019de9c: 00000000 nop                               |
0019dea0: 30420080 andi r2,r2,0x0080                 |
0019dea4: 1440001d bne r2,r0,0x0019df1c              #If Ability has [Target Map]  Branch to  Finalization All Targets will be hit, no matter what
0019dea8: 00000000 nop                               |
                                                     Else : Not [Target Map]
0019deac: 0c065b3a jal 0x00196ce8                        |-->Check_if_Unit_can_be_Targeted_(Cryst/Trea/Mount/Trans) r2 = 0x00 if Unit can be hit
0019deb0: 02002021 addu r4,r16,r0                        |Send Unit ID
0019deb4: 1440005b bne r2,r0,0x0019e024                  #If Unit cannot be hit : branch to Next Target
0019deb8: 34020006 ori r2,r0,0x0006                      |
0019debc: 9283000a lbu r3,0x000a(r20)                    |Load Targeting type  8019f3c4 + 0x26
0019dec0: 00000000 nop                                   |
0019dec4: 1462000c bne r3,r2,0x0019def8                  #If Targeting Type = 0x06 (Target Specific) AI 0x26 or Battle 0x16e + 0xa
0019dec8: 00000000 nop                                       |
0019decc: 9283000b lbu r3,0x000b(r20)                        |Main Target  ID
0019ded0: 00000000 nop                                       |
0019ded4: 02231021 addu r2,r17,r3                            |AI pointer  + Main Target offset
0019ded8: 90420e18 lbu r2,0x0e18(r2)                         |Load Considered Target flag in  AI 0x0e18 Table Enabled when a unit will have an active Turn right after acting Unit ( AI_End_of_turn,_in_between_turn,_etc.)
0019dedc: 00000000 nop                                       |
0019dee0: 10400005 beq r2,r0,0x0019def8                      #If AI Main Target is  disabled in AI 0xe18 Table : branch to  Tile targeting section
0019dee4: 00000000 nop                                       |
                                                             Else : AI Target is Enabled in AI 0xe18
0019dee8: 1070000c beq r3,r16,0x0019df1c                         #If This Unit is the considered Target Go on Finalization  (will be targeted even if moving away)
0019deec: 00000000 nop                                           |
0019def0: 08067809 j 0x0019e024                                  >>Else :  Next Unit iteration Ignore this unit, because AI cannot be sure it will be in AoE ?
0019def4: 00000000 nop                                           |
                                                         Else : Targeting Type <> 0x06 / Unit in AoE around Main Target
0019def8: 92620000 lbu r2,0x0000(r19)                        |Load Ability AI Behavior Flag 1
0019defc: 00000000 nop                                       |
0019df00: 30420001 andi r2,r2,0x0001                         |
0019df04: 14400005 bne r2,r0,0x0019df1c                      #If Ability has [Target Enemies]
0019df08: 02301021 addu r2,r17,r16                               |
0019df0c: 90420e18 lbu r2,0x0e18(r2)                             |This iteration Unit flag in AI 0xe18 Table
0019df10: 00000000 nop                                           |
0019df14: 14400043 bne r2,r0,0x0019e024                          #If This iteration Unit is enabled in AI 0xe18 : branch to  Next Unit iteration This enemy will might move outside the AoE
0019df18: 00000000 nop                                           |

                                            --- This Unit will be hit Section ---
0019df1c: 0c062f82 jal 0x0018be08                    |-->Attack_Finalisation_%26_Reaction_Flagging
0019df20: 02002021 addu r4,r16,r0                    |Send This iteration Target ID
0019df24: 92220cba lbu r2,0x0cba(r17)                |Load Hit counter (strikes + Target) AI 0xcba
0019df28: 00000000 nop                               |
0019df2c: 1055003d beq r2,r21,0x0019e024             #If counter = 0xff : branch to  Next Unit iteration Not Set ? Reach a limit ?
0019df30: 00000000 nop                               |
                                                HOSTILITY CHECK
0019df34: 92630000 lbu r3,0x0000(r19)                |Load Ability AI Behavior Flag 1
0019df38: 00000000 nop                               |
0019df3c: 30620002 andi r2,r3,0x0002                 |
0019df40: 10400006 beq r2,r0,0x0019df5c              #If This Ability has [Target Enemies]
0019df44: 00101100 sll r2,r16,0x04                       |
0019df48: 02221021 addu r2,r17,r2                        |
0019df4c: 90421834 lbu r2,0x1834(r2)                     |This iteration Unit Enemy flag Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)
0019df50: 00000000 nop                                   |
0019df54: 14400009 bne r2,r0,0x0019df7c                  #If This Unit is an Enemy : branch to Add positive priority
0019df58: 00000000 nop                                       |
0019df5c: 30620001 andi r2,r3,0x0001                 |
0019df60: 10400009 beq r2,r0,0x0019df88              #If This Ability has [Target Allies]
0019df64: 00101100 sll r2,r16,0x04                       |
0019df68: 02221021 addu r2,r17,r2                        |
0019df6c: 90421834 lbu r2,0x1834(r2)                     |This iteration Unit Enemy flag Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)
0019df70: 00000000 nop                                   |
0019df74: 14400004 bne r2,r0,0x0019df88                  #If this Unit is an Enemy  Avoid Positive priority
0019df78: 00000000 nop                                       |
                                                    Positive Priority section
0019df7c: 96220032 lhu r2,0x0032(r17)                    |Load Considered Ability Priority score
0019df80: 080677f7 j 0x0019dfdc                          >>Jump and Save Priority
0019df84: 005e1021 addu r2,r2,r30                        |Add +3/other value to Target Priority Will Increase priority only if Affect Stats (if not r30 = 0x00)
                                                     Else : No positive priority found
0019df88: 92630000 lbu r3,0x0000(r19)                    |Load Ability AI Behavior Flag 1
0019df8c: 00000000 nop                                   |
0019df90: 30620002 andi r2,r3,0x0002                     |
0019df94: 10400006 beq r2,r0,0x0019dfb0                  #If This Ability has [Target Enemies]
0019df98: 00101100 sll r2,r16,0x04                           |
0019df9c: 02221021 addu r2,r17,r2                            |
0019dfa0: 90421834 lbu r2,0x1834(r2)                         |This iteration Unit Enemy flag Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)
0019dfa4: 00000000 nop                                       |
0019dfa8: 10400009 beq r2,r0,0x0019dfd0                      #If This Unit is an Ally : branch to Decrease Priority
0019dfac: 00000000 nop                                       |
0019dfb0: 30620001 andi r2,r3,0x0001                     |
0019dfb4: 1040000a beq r2,r0,0x0019dfe0                  #If This Ability has [Target Allies]
0019dfb8: 00101100 sll r2,r16,0x04                           |
0019dfbc: 02221021 addu r2,r17,r2                            |
0019dfc0: 90421834 lbu r2,0x1834(r2)                         |This iteration Unit Enemy flag Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)
0019dfc4: 00000000 nop                                       |
0019dfc8: 10400005 beq r2,r0,0x0019dfe0                      #If This Unit is an Ally :  Avoid negative priority 
0019dfcc: 00000000 nop                                           |
                                                    Decrease Priority section 
0019dfd0: 96220032 lhu r2,0x0032(r17)                    |Load Target Priority
0019dfd4: 00000000 nop                                   |
0019dfd8: 00571023 subu r2,r2,r23                        |Subtract 1 or 4 from Priority 4 if Ability has [Affect stats]
0019dfdc: a6220032 sh r2,0x0032(r17)                     |Update Unit Target Priority

                                                POST HOSTILITY
0019dfe0: 92220cba lbu r2,0x0cba(r17)                |Strike counter
0019dfe4: 00000000 nop                               |
0019dfe8: 24420001 addiu r2,r2,0x0001                |
0019dfec: a2220cba sb r2,0x0cba(r17)                 |Increase AI 0xcba
0019dff0: 96220cb8 lhu r2,0x0cb8(r17)                |AI 0xcb8 Sum of Hit% ?
0019dff4: 9643002a lhu r3,0x002a(r18)                |This iteration Unit  Current Action displayed Hit %
0019dff8: 92240e2e lbu r4,0x0e2e(r17)                |Load Acting Unit ID
0019dffc: 00431021 addu r2,r2,r3                     |AI 0x0cb8 + This iteration action Hit%
0019e000: 16040002 bne r16,r4,0x0019e00c             #If This Iteration Unit is the Caster (Self Targeting)
0019e004: a6220cb8 sh r2,0x0cb8(r17)                 |Increment Total Hit%
0019e008: 34160001 ori r22,r0,0x0001                     |r22 = 1 Self Targeting flag 
0019e00c: 02301021 addu r2,r17,r16                   |
0019e010: 90420c8d lbu r2,0x0c8d(r2)                 |This iteration Unit's byte in AI 0xc8d Table 0x8019f3c4 + 0xc8d + Unit Offset (byte)
0019e014: 00000000 nop                               |
0019e018: 10400002 beq r2,r0,0x0019e024              #If This Unit is in the AI Target of interest list
0019e01c: 34020001 ori r2,r0,0x0001                      |
0019e020: a22219ba sb r2,0x19ba(r17)                     |Enable AI 0x19ba 
0019e024: 8fa20038 lw r2,0x0038(r29)                 |Target counter
0019e028: 27a30012 addiu r3,r29,0x0012               |
0019e02c: 24420001 addiu r2,r2,0x0001                |Counter + 1
0019e030: afa20038 sw r2,0x0038(r29)                 |Increment Target Counter
0019e034: 00621021 addu r2,r3,r2                     |Pointer to Stack 0x10 + 0x02 + Counter offset  (Next unit in Target list)
0019e038: 90420000 lbu r2,0x0000(r2)                 |Load Next Unit ID
0019e03c: 00000000 nop                               |
0019e040: 1455ff87 bne r2,r21,0x0019de60         #Loop While not at the end of the list (0xff)
0019e044: 00000000 nop                               |
0019e048: 92840000 lbu r4,0x0000(r20)            |Send Acting Unit ID
0019e04c: 0c0635c3 jal 0x0018d70c                |-->Store target stats pointer data Resolve Caster results (from 0x80192da0) recoil and absorption ? 
0019e050: 00000000 nop                           |
0019e054: 93a20028 lbu r2,0x0028(r29)            |Load Continue Action byte ?  Pseudo Misc 1a4 (Continue action)
0019e058: 00000000 nop                           |
0019e05c: 1440ff73 bne r2,r0,0x0019de2c      #Loop while current action is not ended (additionnal strike ?)
0019e060: 340200ff ori r2,r0,0x00ff          |
0019e064: 92230cba lbu r3,0x0cba(r17)        |Nb of strikes
0019e068: 00000000 nop                       |
0019e06c: 10620012 beq r3,r2,0x0019e0b8      #If Nb of strike is valid 0xff if not set or limit reached ?
0019e070: 00000000 nop                           |
0019e074: 92220e4d lbu r2,0x0e4d(r17)            |AI 0xe4d Enabled if AI 0x000f flag 0x04 is ON (copy of Ability 0xef0 byte 0x03 flag 0x04) - close range ? Linear ?
0019e078: 00000000 nop                           |
0019e07c: 1040000e beq r2,r0,0x0019e0b8          #If AI 0xe4d <> 0x00
0019e080: 34020001 ori r2,r0,0x0001                  |
0019e084: 92230e4c lbu r3,0x0e4c(r17)                |AI 0xe4c
0019e088: 00000000 nop                               |
0019e08c: 14620004 bne r3,r2,0x0019e0a0              #if AI 0xe4c = 0x01 (Ability is usefull on Caster)
0019e090: 00000000 nop                                   |
0019e094: 16c00007 bne r22,r0,0x0019e0b4                 #If Self Targeting : Branch  and set AI e4e = 0x01
0019e098: 34020001 ori r2,r0,0x0001                      |
0019e09c: 92230e4c lbu r3,0x0e4c(r17)                |AI 0xe4c
0019e0a0: 34020002 ori r2,r0,0x0002                  |
0019e0a4: 14620004 bne r3,r2,0x0019e0b8              #if AI 0xe4c = 0x02 (Adverse effect on Caster)
0019e0a8: 00000000 nop                                   |
0019e0ac: 16c00002 bne r22,r0,0x0019e0b8                 #If Self Targeting Avoid AI e4e
0019e0b0: 34020001 ori r2,r0,0x0001                      |
0019e0b4: a2220e4e sb r2,0x0e4e(r17)                 |Update 0xe4e = 0x1 If Usefull on caster and self-targeting or Adverse on caster but not self Targeting
0019e0b8: 92820000 lbu r2,0x0000(r20)        |Load Acting Unit's ID
0019e0bc: 3c108019 lui r16,0x8019            |
0019e0c0: 261008cc addiu r16,r16,0x08cc      |
0019e0c4: 000220c0 sll r4,r2,0x03            |
0019e0c8: 00822023 subu r4,r4,r2             |
0019e0cc: 00042180 sll r4,r4,0x06            |Unit ID *0x 1c0
0019e0d0: 0c05f6f2 jal 0x0017dbc8            |-->Store Some Acting Unit Data Set Acting Unit as Target and roll reactions / apply attacker current action results?
0019e0d4: 00902021 addu r4,r4,r16            |Pointer to Acting Unit Battle Data
0019e0d8: 8fa60040 lw r6,0x0040(r29)         |Preset Value (r5)
0019e0dc: 00000000 nop                       |

Check if any Target use Reflect
0019e0e0: 14c00012 bne r6,r0,0x0019e12c      #If Preset Value is not 0x00 :  Exit routine
0019e0e4: 2413ffff addiu r19,r0,-0x0001      |
0019e0e8: 2612016e addiu r18,r16,0x016e      |0x801908cc + 0x16e
                                            @LOOP
0019e0ec: 0c05f85e jal 0x0017e178                |-->Check if any unit can react  Test if Targets have reflect - return Unit ID if so
0019e0f0: 27a40038 addiu r4,r29,0x0038           |Send pointer to Nb of Strikes
0019e0f4: 00408021 addu r16,r2,r0                |ID of Unit with reflect
0019e0f8: 1213000c beq r16,r19,0x0019e12c        #If returned value is -0x01 Exit routine No reaction
0019e0fc: 02301021 addu r2,r17,r16                   |
0019e100: 90420e18 lbu r2,0x0e18(r2)             |This Unit AI 0xe18 flag 0x8019f3c4 + 0xe18 + Unit ID
0019e104: 00000000 nop                           |
0019e108: 1440fff8 bne r2,r0,0x0019e0ec          #If This Unit will could move out of AoE before attack resolution go to next unit Seek another reflected Unit
0019e10c: 001020c0 sll r4,r16,0x03               |ID * 8
0019e110: 00902023 subu r4,r4,r16                |ID * 7
0019e114: 00042180 sll r4,r4,0x06                |ID * 0x1c0
0019e118: 00922021 addu r4,r4,r18                |0x801908cc + 0x16e + Unit with reflect offset
0019e11c: 0c067763 jal 0x0019dd8c                |-->AI_ability_processing Simulate reflect
0019e120: 34050001 ori r5,r0,0x0001              |Send 0x01
0019e124: 0806783b j 0x0019e0ec              >>Loop until no reaction left
0019e128: 00000000 nop                       |
0019e12c: 8fbf006c lw r31,0x006c(r29)
0019e130: 8fbe0068 lw r30,0x0068(r29)
0019e134: 8fb70064 lw r23,0x0064(r29)
0019e138: 8fb60060 lw r22,0x0060(r29)
0019e13c: 8fb5005c lw r21,0x005c(r29)
0019e140: 8fb40058 lw r20,0x0058(r29)
0019e144: 8fb30054 lw r19,0x0054(r29)
0019e148: 8fb20050 lw r18,0x0050(r29)
0019e14c: 8fb1004c lw r17,0x004c(r29)
0019e150: 8fb00048 lw r16,0x0048(r29)
0019e154: 27bd0070 addiu r29,r29,0x0070
0019e158: 03e00008 jr r31
0019e15c: 00000000 nop

Return locations

BATTLE.BIN
 0019dd2c: Call AI Ability Processing
 0019e124: AI_ability_processing recursive call