Difference between revisions of "AI ability processing"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(New Documentation)
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
  Unit Reactions Evaluation Routine
+
  '''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)
  0019dd8c: 27bdff90 addiu r29,r29,0xff90
+
  ------------------------------------------------------------------------------------------
  0019dd90: afb40058 sw r20,0x0058(r29)
+
  Parameter : r4 : Pointer to Action Data (Battle 0x16e format) - Acting Unit or Targeted Unit with reflect
0019dd94: 0080a021 addu r20,r4,r0 r20 = Acting Unit ID Pointer
+
            r5 = 0x00 if Acting Unit Action / 0x01 if Target with Reflect (recursive call)
0019dd98: afb1004c sw r17,0x004c(r29)
+
  Return : Nothing
  0019dd9c: 3c11801a lui r17,0x801a
+
------------------------------------------------------------------------------------------
0019dda0: 2631f3c4 addiu r17,r17,0xf3c4 r17 = AI Data Pointer
+
  0019dd8c: 27bdff90 addiu r29,r29,-0x0070    |
0019dda4: afbf006c sw r31,0x006c(r29)
+
  0019dd90: afb40058 sw r20,0x0058(r29)        |
0019dda8: afbe0068 sw r30,0x0068(r29)
+
  0019dd94: 0080a021 addu r20,r4,r0            |{{f/adr|Pointer to Action Data (Battle 0x16e format)}}
0019ddac: afb70064 sw r23,0x0064(r29)
+
  0019dd98: afb1004c sw r17,0x004c(r29)        |
0019ddb0: afb60060 sw r22,0x0060(r29)
+
0019dd9c: 3c11801a lui r17,0x801a            |
  0019ddb4: afb5005c sw r21,0x005c(r29)
+
  0019dda0: 2631f3c4 addiu r17,r17,-0x0c3c    |{{f/adr|AI data pointer  ( 0x8019f3c4 )}}
0019ddb8: afb30054 sw r19,0x0054(r29)
+
  0019dda4: afbf006c sw r31,0x006c(r29)        |
  0019ddbc: afb20050 sw r18,0x0050(r29)
+
  0019dda8: afbe0068 sw r30,0x0068(r29)        |
0019ddc0: afb00048 sw r16,0x0048(r29)
+
  0019ddac: afb70064 sw r23,0x0064(r29)        |
0019ddc4: 14a00006 bne r5,r0,0x0019dde0 Branch if Evaluating a Reacting Unit/Reaction
+
  0019ddb0: afb60060 sw r22,0x0060(r29)       |
0019ddc8: afa50040 sw r5,0x0040(r29) Store PV
+
  0019ddb4: afb5005c sw r21,0x005c(r29)        |
0019ddcc: 92840000 lbu r4,0x0000(r20) Load Acting Unit's ID
+
  0019ddb8: afb30054 sw r19,0x0054(r29)        |
0019ddd0: 0c05f26e jal 0x0017c9b8 Prep Current Action Data
+
  0019ddbc: afb20050 sw r18,0x0050(r29)        |
  0019ddd4: 00000000 nop
+
  0019ddc0: afb00048 sw r16,0x0048(r29)        |
0019ddd8: 144000d4 bne r2,r0,0x0019e12c Branch if Usage Result != 0
+
  0019ddc4: 14a00006 bne r5,r0,0x0019dde0      {{f/Cond|<nowiki>If Preset Value = 0x00 (Acting Unit Action)</nowiki>}}
  0019dddc: 00000000 nop
+
0019ddc8: afa50040 sw r5,0x0040(r29)        |{{f/store|Store Preset Value (PV)}}
  0019dde0: 86820002 lh r2,0x0002(r20) Load Acting Unit's Used Ability ID
+
  0019ddcc: 92840000 lbu r4,0x0000(r20)           |{{f/load|Load Acting Unit's ID}}
  0019dde4: 3c038006 lui r3,0x8006
+
  0019ddd0: 0c05f26e jal 0x0017c9b8                |{{f/jal|Prep_Current_Action_Data|Prep_Current_Action_Data}} {{f/std|returns 0x00 if Ability can be used}}
  0019dde8: 2463ebf4 addiu r3,r3,0xebf4
+
  0019ddd4: 00000000 nop                          |
  0019ddec: 000210c0 sll r2,r2,0x03 ID * 8
+
  0019ddd8: 144000d4 bne r2,r0,0x0019e12c          {{f/Cond|If Ability cannot be used : }} {{f/loc|Exit}} {{f/Returns|returns r2 (not 0x00 value depends of incapacity)}}
  0019ddf0: 00439821 addu r19,r2,r3 r19 = Ability's AI Behavior Flags 1 Pointer
+
  0019dddc: 00000000 nop                          |
  0019ddf4: 3c03801a lui r3,0x801a
+
  0019dde0: 86820002 lh r2,0x0002(r20)        |{{f/load|Load Unit's Used Ability ID}}
  0019ddf8: 9063007e lbu r3,0x007e(r3) Load ?
+
0019dde4: 3c038006 lui r3,0x8006            |
  0019ddfc: 340200ff ori r2,r0,0x00ff r2 = FF
+
  0019dde8: 2463ebf4 addiu r3,r3,-0x140c      |
  0019de00: 1062000a beq r3,r2,0x0019de2c Branch if ? = FF
+
  0019ddec: 000210c0 sll r2,r2,0x03            |{{f/std|ID * 8}}
  0019de04: 341500ff ori r21,r0,0x00ff r21 = FF
+
  0019ddf0: 00439821 addu r19,r2,r3            |{{f/adr|Pointer to considered Ability AI behavior}} {{f/std| 8005ebf0 + 0x04}}
  0019de08: 0000b021 addu r22,r0,r0 r22 = 0
+
  0019ddf4: 3c03801a lui r3,0x801a            |
  0019de0c: 0000f021 addu r30,r0,r0 r30 = 0
+
  0019ddf8: 9063007e lbu r3,0x007e(r3)        |{{f/load|Load 801a007e ( AI 0xcba)}}
  0019de10: 92620000 lbu r2,0x0000(r19) Load Ability's AI Behavior Flags
+
  0019ddfc: 340200ff ori r2,r0,0x00ff          |{{f/std|<nowiki>r2 = 0xff</nowiki>}}
  0019de14: 00000000 nop
+
  0019de00: 1062000a beq r3,r2,0x0019de2c      {{f/Cond|If Target/Hit counter <> 0xff}} {{f/std|Is Set and did not reach his limit ? If 0xff the routine will ignore priority aspect}}
  0019de18: 30420008 andi r2,r2,0x0008
+
  0019de04: 341500ff ori r21,r0,0x00ff        |{{f/std|<nowiki>r21 = 0xff</nowiki>}}
  0019de1c: 10400003 beq r2,r0,0x0019de2c Branch if Ability doesn't have Stat Changes
+
  0019de08: 0000b021 addu r22,r0,r0                |{{f/std|Initialize self Targeting flag}}
  0019de20: 34170001 ori r23,r0,0x0001 r23 = Target Priority - 1
+
0019de0c: 0000f021 addu r30,r0,r0                |{{f/std|Set default positive priority (in this routine)}}
  0019de24: 341e0003 ori r30,r0,0x0003 r30 = Target Priority + 3
+
  0019de10: 92620000 lbu r2,0x0000(r19)           |{{f/load|Load Ability's AI Behavior 1}}
  0019de28: 34170004 ori r23,r0,0x0004 r23 = Target Priority - 4
+
  0019de14: 00000000 nop                           |
 
+
  0019de18: 30420008 andi r2,r2,0x0008            |
  <Begin Main Loop?>
+
  0019de1c: 10400003 beq r2,r0,0x0019de2c          {{f/Cond|If Ability has [Affect stats]}}
  0019de2c: 92840000 lbu r4,0x0000(r20) r4 = Acting Unit's ID
+
  0019de20: 34170001 ori r23,r0,0x0001            |{{f/std|Set default negative priority (in this routine)}}
  0019de30: 0c05f391 jal 0x0017ce44 Main Ability Routine (Check if ability is targeting a unit, then calculate damage)
+
  0019de24: 341e0003 ori r30,r0,0x0003                |{{f/std|Hardcoded [Affect stats] positive priority}}
  0019de34: 27a50010 addiu r5,r29,0x0010 r5 = Stack Pointer + 0x10
+
  0019de28: 34170004 ori r23,r0,0x0004                |{{f/std|Hardcoded [Affect stats] negative priority (undesired effect)}}
  0019de38: 14400083 bne r2,r0,0x0019e048 Branch if ability is not hitting a unit
+
   
  0019de3c: 00000000 nop
+
                  {{f/sec|MAIN TARGET/STRIKE LOOP}}
0019de40: 93a20011 lbu r2,0x0011(r29)
+
                                            {{f/bloop|LOOP - Until end of action (all strikes)}}
0019de44: 00000000 nop
+
  0019de2c: 92840000 lbu r4,0x0000(r20)            |{{f/load|<nowiki>r4 = Acting Unit's ID</nowiki>}}
  0019de48: 1040007f beq r2,r0,0x0019e048 Branch if false
+
  0019de30: 0c05f391 jal 0x0017ce44                |{{f/jal|Main_ability_loading_routine%3F|Main_ability_loading_routine%3F}} {{f/std|Mimic action}}
  0019de4c: 27a30012 addiu r3,r29,0x0012
+
  0019de34: 27a50010 addiu r5,r29,0x0010          |{{f/std|<nowiki>r5 = Stack Pointer + 0x10 (will mimic miscellaneous Unit pointer 0x18c)</nowiki>}}
  0019de50: 93a20012 lbu r2,0x0012(r29) Load Ability Counter
+
  0019de38: 14400083 bne r2,r0,0x0019e048          {{f/Cond|If ability is not hitting a unit}} {{f/loc|Exit Loop}}
  0019de54: 00000000 nop
+
0019de3c: 00000000 nop                          |
  0019de58: 1055007b beq r2,r21,0x0019e048 Branch if ? = FF (Skip Ability Loop)
+
  0019de40: 93a20011 lbu r2,0x0011(r29)           |{{f/load|Number of Targets}} {{f/std|pseudo AU misc 0x18d}}
  0019de5c: afa00038 sw r0,0x0038(r29) Empty Ability Counter
+
  0019de44: 00000000 nop                           |
 
+
  0019de48: 1040007f beq r2,r0,0x0019e048          {{f/Cond|If there's no Targets }} {{f/loc|Exit Loop}}
  <Begin Ability Loop>
+
  0019de4c: 27a30012 addiu r3,r29,0x0012          |{{f/adr|Pointer to Stack 0x12 (list of Targets ID)}} {{f/std|Pseudo Misc 0x18e}}
0019de60: 8fa20038 lw r2,0x0038(r29) Load Ability Counter
+
  0019de50: 93a20012 lbu r2,0x0012(r29)           |{{f/load|Load This iteration Target ID}}
  0019de64: 00000000 nop
+
  0019de54: 00000000 nop                           |
  0019de68: 00621021 addu r2,r3,r2
+
  0019de58: 1055007b beq r2,r21,0x0019e048        {{f/Cond|If This is the end of Targets list}} {{f/loc|Exit Loop}}
  0019de6c: 90500000 lbu r16,0x0000(r2) Load Acting Unit ID?
+
  0019de5c: afa00038 sw r0,0x0038(r29)            |{{f/store|Initialize Target counter}}
  0019de70: 3c038019 lui r3,0x8019
+
                                                {{f/bloop|LOOP - Each Target in List}}
0019de74: 24630a58 addiu r3,r3,0x0a58 Load Current Action Data (0x018c)
+
  0019de60: 8fa20038 lw r2,0x0038(r29)                |{{f/load|Target Counter}}
  0019de78: 001010c0 sll r2,r16,0x03
+
  0019de64: 00000000 nop                              |
  0019de7c: 00501023 subu r2,r2,r16
+
  0019de68: 00621021 addu r2,r3,r2                    |{{f/adr|Dynamic Pointer to Target list+ Offset (1 byte)}}
  0019de80: 00021180 sll r2,r2,0x06
+
  0019de6c: 90500000 lbu r16,0x0000(r2)                |{{f/load|This iteration Target ID}}
  0019de84: 00439021 addu r18,r2,r3
+
  0019de70: 3c038019 lui r3,0x8019                    |
 
+
  0019de74: 24630a58 addiu r3,r3,0x0a58                |{{f/std|801908cc + 0x18c}}
<Can this ability hit this unit?>
+
  0019de78: 001010c0 sll r2,r16,0x03                  |
  0019de88: 8642002a lh r2,0x002a(r18) Load Hit % (Displayed Amount)
+
  0019de7c: 00501023 subu r2,r2,r16                    |
  0019de8c: 00000000 nop
+
  0019de80: 00021180 sll r2,r2,0x06                    |{{f/std|Unit ID * 0x1c0}}
  0019de90: 18400064 blez r2,0x0019e024 Branch if negative
+
  0019de84: 00439021 addu r18,r2,r3                   |{{f/adr|This Unit Current Action data pointer}} {{f/std|801908cc + 0x18c + Unit offset}}
  0019de94: 00000000 nop
+
0019de88: 8642002a lh r2,0x002a(r18)                 |{{f/load|Load Hit % (Displayed Amount)}}
  0019de98: 92620001 lbu r2,0x0001(r19) Load AI Ability Behavior Flag 2
+
  0019de8c: 00000000 nop                               |
  0019de9c: 00000000 nop
+
  0019de90: 18400064 blez r2,0x0019e024                {{f/Cond|If Target Current Action Hit% is 0 (or less) branch to}} {{f/loc|Next Target}}
  0019dea0: 30420080 andi r2,r2,0x0080
+
0019de94: 00000000 nop                              |
  0019dea4: 1440001d bne r2,r0,0x0019df1c Branch if Ignore Range
+
  0019de98: 92620001 lbu r2,0x0001(r19)               |{{f/load|Load AI Ability Behavior Flag 2}}
  0019dea8: 00000000 nop
+
  0019de9c: 00000000 nop                               |
  0019deac: 0c065b3a jal 0x00196ce8 Check if Unit can be hit (Crystal/Treasure/Transparent/Mounted)
+
  0019dea0: 30420080 andi r2,r2,0x0080                |
  0019deb0: 02002021 addu r4,r16,r0
+
  0019dea4: 1440001d bne r2,r0,0x0019df1c             {{f/Cond|If Ability has [Target Map]  Branch to }} {{f/loc|Finalization}} {{f/std|All Targets will be hit, no matter what}}
  0019deb4: 1440005b bne r2,r0,0x0019e024 Branch if Unit cannot be hit
+
  0019dea8: 00000000 nop                               |
  0019deb8: 34020006 ori r2,r0,0x0006
+
                                                      '''Else : Not [Target Map]'''
  0019debc: 9283000a lbu r3,0x000a(r20) Load TargetUnitorPanel
+
  0019deac: 0c065b3a jal 0x00196ce8                        |{{f/jal|Check_if_Unit_can_be_Targeted_(Cryst/Trea/Mount/Trans)|Check_if_Unit_can_be_Targeted_(Cryst/Trea/Mount/Trans)}} {{f/std|<nowiki>r2 = 0x00 if Unit can be hit</nowiki>}}
  0019dec0: 00000000 nop
+
  0019deb0: 02002021 addu r4,r16,r0                        |{{f/std|Send Unit ID}}
  0019dec4: 1462000c bne r3,r2,0x0019def8 Branch if ability is targeting Unit (as opposed to Tile)
+
  0019deb4: 1440005b bne r2,r0,0x0019e024                  {{f/Cond|If Unit cannot be hit : branch to}} {{f/loc|Next Target}}
  0019dec8: 00000000 nop
+
  0019deb8: 34020006 ori r2,r0,0x0006                      |
  0019decc: 9283000b lbu r3,0x000b(r20) Load Target ID?
+
  0019debc: 9283000a lbu r3,0x000a(r20)                   |{{f/load|Load Targeting type}} {{f/adr| 8019f3c4 + 0x26}}
  0019ded0: 00000000 nop
+
  0019dec0: 00000000 nop                                   |
  0019ded4: 02231021 addu r2,r17,r3
+
  0019dec4: 1462000c bne r3,r2,0x0019def8                  {{f/Cond|<nowiki>If Targeting Type = 0x06 (Target Specific)</nowiki>}} {{f/std|AI 0x26 or Battle 0x16e + 0xa}}
  0019ded8: 90420e18 lbu r2,0x0e18(r2) Load Targetable Unit List
+
  0019dec8: 00000000 nop                                       |
  0019dedc: 00000000 nop
+
  0019decc: 9283000b lbu r3,0x000b(r20)                        |{{f/load|Main Target  ID}}
  0019dee0: 10400005 beq r2,r0,0x0019def8 Branch if Unit is targeting self/not targeting anything?
+
  0019ded0: 00000000 nop                                      |
  0019dee4: 00000000 nop
+
0019ded4: 02231021 addu r2,r17,r3                            |{{f/adr|AI pointer  + Main Target offset}}
0019dee8: 1070000c beq r3,r16,0x0019df1c Branch if targeting own panel
+
  0019ded8: 90420e18 lbu r2,0x0e18(r2)                         |{{f/load|Load Considered Target flag in AI 0x0e18 Table}} {{f/std|Enabled when a unit will have an active Turn right after acting Unit ( [[AI_End_of_turn,_in_between_turn,_etc.]])}}
  0019deec: 00000000 nop
+
0019dedc: 00000000 nop                                       |
0019def0: 08067809 j 0x0019e024
+
  0019dee0: 10400005 beq r2,r0,0x0019def8                      {{f/Cond|If AI Main Target is disabled in AI 0xe18 Table : branch to }} {{f/loc|Tile targeting section}}
  0019def4: 00000000 nop
+
0019dee4: 00000000 nop                                       |
 
+
                                                              '''Else : AI Target is Enabled in AI 0xe18'''
<Targeting Unit>
+
  0019dee8: 1070000c beq r3,r16,0x0019df1c                        {{f/Cond|If This Unit is the considered Target}} {{f/loc|Go on Finalization }} {{f/std|(will be targeted even if moving away)}}
  0019def8: 92620000 lbu r2,0x0000(r19) Load Ability AI Behavior Flag 1
+
  0019deec: 00000000 nop                                           |
  0019defc: 00000000 nop
+
  0019def0: 08067809 j 0x0019e024                                  {{f/jump|Else : }} {{f/loc|Next Unit iteration}} {{f/std|Ignore this unit, because AI cannot be sure it will be in AoE ?}}
0019df00: 30420001 andi r2,r2,0x0001
+
  0019def4: 00000000 nop                                          |
  0019df04: 14400005 bne r2,r0,0x0019df1c <Reaction Routine> if Ability Targets Allies
+
                                                          '''Else : Targeting Type <> 0x06 / Unit in AoE around Main Target'''
  0019df08: 02301021 addu r2,r17,r16
+
  0019def8: 92620000 lbu r2,0x0000(r19)                       |{{f/load|Load Ability AI Behavior Flag 1}}
0019df0c: 90420e18 lbu r2,0x0e18(r2) Load Targetable Unit List?
+
  0019defc: 00000000 nop                                       |
  0019df10: 00000000 nop
+
  0019df00: 30420001 andi r2,r2,0x0001                        |
  0019df14: 14400043 bne r2,r0,0x0019e024 Branch if Unit isn't targeting anything?
+
  0019df04: 14400005 bne r2,r0,0x0019df1c                      {{f/Cond|If Ability has [Target Enemies]}}
  0019df18: 00000000 nop
+
  0019df08: 02301021 addu r2,r17,r16                              |
  0019df1c: 0c062f82 jal 0x0018be08 Main Reaction Routine
+
  0019df0c: 90420e18 lbu r2,0x0e18(r2)                            |{{f/load|This iteration Unit flag in AI 0xe18 Table}}
  0019df20: 02002021 addu r4,r16,r0
+
  0019df10: 00000000 nop                                          |
  0019df24: 92220cba lbu r2,0x0cba(r17) Load Usable Ability Counter
+
  0019df14: 14400043 bne r2,r0,0x0019e024                          {{f/Cond|If This iteration Unit is enabled in AI 0xe18 : branch to }} {{f/loc|Next Unit iteration}} {{f/std|This enemy will might move outside the AoE}}
  0019df28: 00000000 nop
+
  0019df18: 00000000 nop                                           |
  0019df2c: 1055003d beq r2,r21,0x0019e024 Loop if No Usable Abilities Yet
+
   
  0019df30: 00000000 nop
+
                                            {{f/sec|--- This Unit will be hit Section ---}}
 
+
  0019df1c: 0c062f82 jal 0x0018be08                    |{{f/jal|Attack_Finalisation_%26_Reaction_Flagging|Attack_Finalisation_%26_Reaction_Flagging}}
<Target Allies>
+
  0019df20: 02002021 addu r4,r16,r0                    |{{f/std|Send This iteration Target ID}}
  0019df34: 92630000 lbu r3,0x0000(r19) Load Ability AI Behavior Flag 1
+
0019df24: 92220cba lbu r2,0x0cba(r17)               |{{f/load|Load Hit counter (strikes + Target)}} {{f/std|AI 0xcba}}
  0019df38: 00000000 nop
+
  0019df28: 00000000 nop                              |
  0019df3c: 30620002 andi r2,r3,0x0002
+
  0019df2c: 1055003d beq r2,r21,0x0019e024            {{f/Cond|<nowiki>If counter = 0xff : branch to </nowiki>}} {{f/loc|Next Unit iteration}} {{f/std|Not Set ? Reach a limit ?}}
0019df40: 10400006 beq r2,r0,0x0019df5c Branch if Ability does not target Enemies
+
  0019df30: 00000000 nop                              |
  0019df44: 00101100 sll r2,r16,0x04
+
                                                {{f/sec|HOSTILITY CHECK}}
0019df48: 02221021 addu r2,r17,r2
+
0019df34: 92630000 lbu r3,0x0000(r19)               |{{f/load|Load Ability AI Behavior Flag 1}}
  0019df4c: 90421834 lbu r2,0x1834(r2) Load Enemy Flag
+
  0019df38: 00000000 nop                               |
  0019df50: 00000000 nop
+
  0019df3c: 30620002 andi r2,r3,0x0002                 |
  0019df54: 14400009 bne r2,r0,0x0019df7c Branch to modify Priority if Enemy
+
  0019df40: 10400006 beq r2,r0,0x0019df5c              {{f/Cond|If This Ability has [Target Enemies]}}
  0019df58: 00000000 nop
+
  0019df44: 00101100 sll r2,r16,0x04                       |
  0019df5c: 30620001 andi r2,r3,0x0001
+
  0019df48: 02221021 addu r2,r17,r2                       |
  0019df60: 10400009 beq r2,r0,0x0019df88 Branch if Ability is not Target Allies
+
  0019df4c: 90421834 lbu r2,0x1834(r2)                     |{{f/load|This iteration Unit Enemy flag}} {{f/adr|Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)}}
  0019df64: 00101100 sll r2,r16,0x04
+
0019df50: 00000000 nop                                   |
  0019df68: 02221021 addu r2,r17,r2
+
  0019df54: 14400009 bne r2,r0,0x0019df7c                  {{f/Cond|If This Unit is an Enemy : branch to}} {{f/loc|Add positive priority}}
0019df6c: 90421834 lbu r2,0x1834(r2) Load Enemy Flag
+
  0019df58: 00000000 nop                                       |
  0019df70: 00000000 nop
+
  0019df5c: 30620001 andi r2,r3,0x0001                 |
  0019df74: 14400004 bne r2,r0,0x0019df88 Branch if Enemy
+
  0019df60: 10400009 beq r2,r0,0x0019df88              {{f/Cond|If This Ability has [Target Allies]}}
  0019df78: 00000000 nop
+
  0019df64: 00101100 sll r2,r16,0x04                       |
  0019df7c: 96220032 lhu r2,0x0032(r17) Load Target Priority
+
  0019df68: 02221021 addu r2,r17,r2                       |
  0019df80: 080677f7 j 0x0019dfdc Jump and Save Priority (For Allied Unit)
+
  0019df6c: 90421834 lbu r2,0x1834(r2)                     |{{f/load|This iteration Unit Enemy flag}} {{f/adr|Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)}}
  0019df84: 005e1021 addu r2,r2,r30 Add +3/other value to Target Priority
+
  0019df70: 00000000 nop                                   |
 
+
  0019df74: 14400004 bne r2,r0,0x0019df88                  {{f/Cond|If this Unit is an Enemy }} {{f/loc|Avoid Positive priority}}
<If Target Enemy>
+
  0019df78: 00000000 nop                                       |
  0019df88: 92630000 lbu r3,0x0000(r19) Load Ability AI Behavior Flag 1
+
                                                    {{f/sec|Positive Priority section}}
  0019df8c: 00000000 nop
+
  0019df7c: 96220032 lhu r2,0x0032(r17)                   |{{f/load|Load Considered Ability Priority score}}
  0019df90: 30620002 andi r2,r3,0x0002
+
  0019df80: 080677f7 j 0x0019dfdc                          {{f/jump|Jump and Save Priority}}
  0019df94: 10400006 beq r2,r0,0x0019dfb0 Branch if Ability is not Target Enemies
+
  0019df84: 005e1021 addu r2,r2,r30                        |{{f/std|Add +3/other value to Target Priority}} {{f/std|<nowiki>Will Increase priority only if Affect Stats (if not r30 = 0x00)</nowiki>}}
  0019df98: 00101100 sll r2,r16,0x04
+
                                                      '''Else : No positive priority found'''
  0019df9c: 02221021 addu r2,r17,r2
+
  0019df88: 92630000 lbu r3,0x0000(r19)                   |{{f/load|Load Ability AI Behavior Flag 1}}
  0019dfa0: 90421834 lbu r2,0x1834(r2) Load Enemy Flag
+
  0019df8c: 00000000 nop                                   |
0019dfa4: 00000000 nop
+
  0019df90: 30620002 andi r2,r3,0x0002                    |
  0019dfa8: 10400009 beq r2,r0,0x0019dfd0 Branch if Ally
+
  0019df94: 10400006 beq r2,r0,0x0019dfb0                  {{f/Cond|If This Ability has [Target Enemies]}}
  0019dfac: 00000000 nop
+
  0019df98: 00101100 sll r2,r16,0x04                          |
  0019dfb0: 30620001 andi r2,r3,0x0001
+
  0019df9c: 02221021 addu r2,r17,r2                            |
  0019dfb4: 1040000a beq r2,r0,0x0019dfe0 Branch if Ability is not Target Allies
+
  0019dfa0: 90421834 lbu r2,0x1834(r2)                         |{{f/load|This iteration Unit Enemy flag}} {{f/adr|Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)}}
  0019dfb8: 00101100 sll r2,r16,0x04
+
  0019dfa4: 00000000 nop                                      |
  0019dfbc: 02221021 addu r2,r17,r2
+
  0019dfa8: 10400009 beq r2,r0,0x0019dfd0                      {{f/Cond|If This Unit is an Ally : branch to}} {{f/loc|Decrease Priority}}
  0019dfc0: 90421834 lbu r2,0x1834(r2) Load Enemy Flag
+
  0019dfac: 00000000 nop                                      |
  0019dfc4: 00000000 nop
+
0019dfb0: 30620001 andi r2,r3,0x0001                     |
  0019dfc8: 10400005 beq r2,r0,0x0019dfe0 Branch if Ally
+
  0019dfb4: 1040000a beq r2,r0,0x0019dfe0                  {{f/Cond|If This Ability has [Target Allies]}}
  0019dfcc: 00000000 nop
+
  0019dfb8: 00101100 sll r2,r16,0x04                          |
  0019dfd0: 96220032 lhu r2,0x0032(r17) Load Target Priority
+
  0019dfbc: 02221021 addu r2,r17,r2                            |
  0019dfd4: 00000000 nop
+
  0019dfc0: 90421834 lbu r2,0x1834(r2)                        |{{f/load|This iteration Unit Enemy flag}} {{f/adr|Pointer to 0x8019f3c4 + 0x182c + 0x08 + Unit offset (0x10 Bytes)}}
  0019dfd8: 00571023 subu r2,r2,r23 Subtract 1 or 4 from Priority
+
  0019dfc4: 00000000 nop                                      |
0019dfdc: a6220032 sh r2,0x0032(r17) Save Unit Target Priority
+
  0019dfc8: 10400005 beq r2,r0,0x0019dfe0                      {{f/Cond|If This Unit is an Ally : }} {{f/loc|Avoid negative priority }}
 
+
0019dfcc: 00000000 nop                                          |
  <If Target Neither>
+
                                                    {{f/sec|Decrease Priority section }}
0019dfe0: 92220cba lbu r2,0x0cba(r17) Usable Ability Counter
+
  0019dfd0: 96220032 lhu r2,0x0032(r17)                   |{{f/load|Load Target Priority}}
  0019dfe4: 00000000 nop
+
  0019dfd4: 00000000 nop                                  |
  0019dfe8: 24420001 addiu r2,r2,0x0001
+
  0019dfd8: 00571023 subu r2,r2,r23                        |{{f/std|Subtract 1 or 4 from Priority}} {{f/std|4 if Ability has [Affect stats]}}
  0019dfec: a2220cba sb r2,0x0cba(r17) Usable Ability Counter++
+
0019dfdc: a6220032 sh r2,0x0032(r17)                     |{{f/store|Update Unit Target Priority}}
  0019dff0: 96220cb8 lhu r2,0x0cb8(r17) Load AI Hit %
+
   
  0019dff4: 9643002a lhu r3,0x002a(r18) Load Hit % (Displayed Amount)
+
                                                {{f/sec|POST HOSTILITY}}
  0019dff8: 92240e2e lbu r4,0x0e2e(r17) Load Acting Unit ID
+
0019dfe0: 92220cba lbu r2,0x0cba(r17)               |{{f/load|Strike counter}}
  0019dffc: 00431021 addu r2,r2,r3
+
  0019dfe4: 00000000 nop                               |
  0019e000: 16040002 bne r16,r4,0x0019e00c Branch if not Targeting Self? Not the current acting unit this turn?
+
  0019dfe8: 24420001 addiu r2,r2,0x0001                |
  0019e004: a6220cb8 sh r2,0x0cb8(r17) Save Hit %
+
  0019dfec: a2220cba sb r2,0x0cba(r17)                |{{f/store|Increase AI 0xcba}}
0019e008: 34160001 ori r22,r0,0x0001 r22 = 1
+
  0019dff0: 96220cb8 lhu r2,0x0cb8(r17)                |{{f/load|AI 0xcb8}} {{f/std|Sum of Hit% ?}}
  0019e00c: 02301021 addu r2,r17,r16
+
  0019dff4: 9643002a lhu r3,0x002a(r18)               |{{f/load|This iteration Unit  Current Action displayed Hit %}}
  0019e010: 90420c8d lbu r2,0x0c8d(r2) Load Calculator Type ID?
+
  0019dff8: 92240e2e lbu r4,0x0e2e(r17)               |{{f/load|Load Acting Unit ID}}
  0019e014: 00000000 nop
+
  0019dffc: 00431021 addu r2,r2,r3                    |{{f/std|AI 0x0cb8 + This iteration action Hit%}}
  0019e018: 10400002 beq r2,r0,0x0019e024 Branch if not planning on using a Math Skill?
+
  0019e000: 16040002 bne r16,r4,0x0019e00c            {{f/Cond|If This Iteration Unit is the Caster (Self Targeting)}}
  0019e01c: 34020001 ori r2,r0,0x0001
+
  0019e004: a6220cb8 sh r2,0x0cb8(r17)                 |{{f/store|Increment Total Hit%}}
  0019e020: a22219ba sb r2,0x19ba(r17) Ability can hit because it's a math skill?
+
  0019e008: 34160001 ori r22,r0,0x0001                    |{{f/std|<nowiki>r22 = 1</nowiki>}} {{f/std|Self Targeting flag }}
 
+
  0019e00c: 02301021 addu r2,r17,r16                  |
<Next Ability?>
+
  0019e010: 90420c8d lbu r2,0x0c8d(r2)                |{{f/load|This iteration Unit's byte in AI 0xc8d Table}} {{f/adr|0x8019f3c4 + 0xc8d + Unit Offset (byte)}}
  0019e024: 8fa20038 lw r2,0x0038(r29) Load Ability Counter
+
  0019e014: 00000000 nop                               |
  0019e028: 27a30012 addiu r3,r29,0x0012
+
  0019e018: 10400002 beq r2,r0,0x0019e024              {{f/Cond|If This Unit is in the AI Target of interest list}}
  0019e02c: 24420001 addiu r2,r2,0x0001
+
  0019e01c: 34020001 ori r2,r0,0x0001                     |
0019e030: afa20038 sw r2,0x0038(r29)
+
  0019e020: a22219ba sb r2,0x19ba(r17)                     |{{f/store|Enable AI 0x19ba }}
  0019e034: 00621021 addu r2,r3,r2
+
  0019e024: 8fa20038 lw r2,0x0038(r29)                |{{f/adr|Target counter}}
0019e038: 90420000 lbu r2,0x0000(r2) Load Ability List?
+
  0019e028: 27a30012 addiu r3,r29,0x0012              |
  0019e03c: 00000000 nop
+
  0019e02c: 24420001 addiu r2,r2,0x0001                |{{f/std|Counter + 1}}
  0019e040: 1455ff87 bne r2,r21,0x0019de60 Loop until End of Ability List
+
  0019e030: afa20038 sw r2,0x0038(r29)                |{{f/store|Increment Target Counter}}
  0019e044: 00000000 nop
+
  0019e034: 00621021 addu r2,r3,r2                    |{{f/adr|Pointer to Stack 0x10 + 0x02 + Counter offset }} {{f/std|(Next unit in Target list)}}
 
+
  0019e038: 90420000 lbu r2,0x0000(r2)                 |{{f/load|Load Next Unit ID}}
  <Next ?>
+
  0019e03c: 00000000 nop                              |
  0019e048: 92840000 lbu r4,0x0000(r20) Load Unit Data
+
  0019e040: 1455ff87 bne r2,r21,0x0019de60        {{f/Cond|Loop While not at the end of the list (0xff)}}
  0019e04c: 0c0635c3 jal 0x0018d70c Store target stats pointer data
+
  0019e044: 00000000 nop                               |
  0019e050: 00000000 nop
+
  0019e048: 92840000 lbu r4,0x0000(r20)            |{{f/load|Send Acting Unit ID}}
0019e054: 93a20028 lbu r2,0x0028(r29) Load ?
+
  0019e04c: 0c0635c3 jal 0x0018d70c                |{{f/jal|Store target stats pointer data|Store target stats pointer data}} {{f/std|Resolve Caster results (from 0x80192da0) recoil and absorption ? }}
  0019e058: 00000000 nop
+
0019e050: 00000000 nop                          |
0019e05c: 1440ff73 bne r2,r0,0x0019de2c Loop until False
+
  0019e054: 93a20028 lbu r2,0x0028(r29)           |{{f/load|Load Continue Action byte ? }} {{f/std|Pseudo Misc 1a4 (Continue action)}}
 
+
  0019e058: 00000000 nop                          |
  0019e060: 340200ff ori r2,r0,0x00ff
+
  0019e05c: 1440ff73 bne r2,r0,0x0019de2c      {{f/Cond|Loop while current action is not ended (additionnal strike ?)}}
  0019e064: 92230cba lbu r3,0x0cba(r17) Load # of Usable Abilities
+
  0019e060: 340200ff ori r2,r0,0x00ff          |
  0019e068: 00000000 nop
+
  0019e064: 92230cba lbu r3,0x0cba(r17)        |{{f/load|Nb of strikes}}
0019e06c: 10620012 beq r3,r2,0x0019e0b8 Branch if no usable abilities (FF = default)
+
  0019e068: 00000000 nop                      |
  0019e070: 00000000 nop
+
  0019e06c: 10620012 beq r3,r2,0x0019e0b8      {{f/Cond|If Nb of strike is valid}} {{f/std|0xff if not set or limit reached ?}}
  0019e074: 92220e4d lbu r2,0x0e4d(r17) Acting units ID?
+
  0019e070: 00000000 nop                          |
  0019e078: 00000000 nop
+
  0019e074: 92220e4d lbu r2,0x0e4d(r17)            |{{f/load|AI 0xe4d}} {{f/std|Enabled if AI 0x000f flag 0x04 is ON (copy of Ability 0xef0 byte 0x03 flag 0x04) - close range ? Linear ?}}
  0019e07c: 1040000e beq r2,r0,0x0019e0b8 Branch if self?
+
  0019e078: 00000000 nop                           |
  0019e080: 34020001 ori r2,r0,0x0001
+
  0019e07c: 1040000e beq r2,r0,0x0019e0b8          {{f/Cond|If AI 0xe4d <> 0x00}}
  0019e084: 92230e4c lbu r3,0x0e4c(r17) Load ?
+
  0019e080: 34020001 ori r2,r0,0x0001                  |
  0019e088: 00000000 nop
+
  0019e084: 92230e4c lbu r3,0x0e4c(r17)                |{{f/load|AI 0xe4c}}
  0019e08c: 14620004 bne r3,r2,0x0019e0a0 Branch if not 1
+
  0019e088: 00000000 nop                              |
  0019e090: 00000000 nop
+
  0019e08c: 14620004 bne r3,r2,0x0019e0a0              {{f/Cond|<nowiki>if AI 0xe4c = 0x01 (Ability is usefull on Caster)</nowiki>}}
  0019e094: 16c00007 bne r22,r0,0x0019e0b4 Branch if able to hit target
+
  0019e090: 00000000 nop                                  |
  0019e098: 34020001 ori r2,r0,0x0001
+
  0019e094: 16c00007 bne r22,r0,0x0019e0b4                {{f/Cond|If Self Targeting : Branch }} {{f/loc|<nowiki>and set AI e4e = 0x01</nowiki>}}
  0019e09c: 92230e4c lbu r3,0x0e4c(r17) Load ?
+
  0019e098: 34020001 ori r2,r0,0x0001                      |
  0019e0a0: 34020002 ori r2,r0,0x0002
+
  0019e09c: 92230e4c lbu r3,0x0e4c(r17)               |{{f/load|AI 0xe4c}}
  0019e0a4: 14620004 bne r3,r2,0x0019e0b8 Branch if not 2
+
  0019e0a0: 34020002 ori r2,r0,0x0002                  |
  0019e0a8: 00000000 nop
+
  0019e0a4: 14620004 bne r3,r2,0x0019e0b8              {{f/Cond|<nowiki>if AI 0xe4c = 0x02 (Adverse effect on Caster)</nowiki>}}
  0019e0ac: 16c00002 bne r22,r0,0x0019e0b8 Branch if able to hit Target
+
0019e0a8: 00000000 nop                                  |
  0019e0b0: 34020001 ori r2,r0,0x0001
+
  0019e0ac: 16c00002 bne r22,r0,0x0019e0b8                {{f/Cond|If Self Targeting}} {{f/loc|Avoid AI e4e}}
  0019e0b4: a2220e4e sb r2,0x0e4e(r17) Can effect target = True?
+
  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}}
  <Evaluate Reactions to Ability>
+
0019e0b8: 92820000 lbu r2,0x0000(r20)        |{{f/load|Load Acting Unit's ID}}
  0019e0b8: 92820000 lbu r2,0x0000(r20) Load Acting Unit's ID
+
0019e0bc: 3c108019 lui r16,0x8019            |
  0019e0bc: 3c108019 lui r16,0x8019
+
0019e0c0: 261008cc addiu r16,r16,0x08cc      |
  0019e0c0: 261008cc addiu r16,r16,0x08cc r16 = Unit Data Pointer
+
0019e0c4: 000220c0 sll r4,r2,0x03            |
  0019e0c4: 000220c0 sll r4,r2,0x03
+
0019e0c8: 00822023 subu r4,r4,r2            |
  0019e0c8: 00822023 subu r4,r4,r2
+
0019e0cc: 00042180 sll r4,r4,0x06            |{{f/std|Unit ID *0x 1c0}}
  0019e0cc: 00042180 sll r4,r4,0x06 Unit ID * 1c0
+
0019e0d0: 0c05f6f2 jal 0x0017dbc8            |{{f/jal|Store Some Acting Unit Data|Store Some Acting Unit Data}} {{f/std|Set Acting Unit as Target and roll reactions / apply attacker current action results?}}
  0019e0d0: 0c05f6f2 jal 0x0017dbc8 Store Some Acting Unit Data
+
0019e0d4: 00902021 addu r4,r4,r16            |{{f/adr|Pointer to Acting Unit Battle Data}}
0019e0d4: 00902021 addu r4,r4,r16 Get Acting Unit Data
+
0019e0d8: 8fa60040 lw r6,0x0040(r29)        |{{f/adr|Preset Value (r5)}}
0019e0d8: 8fa60040 lw r6,0x0040(r29) Load isEvaluatingReactingUnit
+
0019e0dc: 00000000 nop                      |
  0019e0dc: 00000000 nop
+
  0019e0e0: 14c00012 bne r6,r0,0x0019e12c Exit if routine was evaluating reacting unit (and to prevent an infinite loop)
+
{{f/sec|Check if any Target use Reflect}}
  0019e0e4: 2413ffff addiu r19,r0,0xffff
+
0019e0e0: 14c00012 bne r6,r0,0x0019e12c      {{f/Cond|If Preset Value is not 0x00 : }} {{f/loc|Exit routine}}
  0019e0e8: 2612016e addiu r18,r16,0x016e Point to Target Action Data
+
0019e0e4: 2413ffff addiu r19,r0,-0x0001      |
 
+
0019e0e8: 2612016e addiu r18,r16,0x016e      |{{f/std|0x801908cc + 0x16e}}
  0019e0ec: 0c05f85e jal 0x0017e178 Check if any unit can react
+
                                            {{f/bloop|LOOP}}
  0019e0f0: 27a40038 addiu r4,r29,0x0038
+
0019e0ec: 0c05f85e jal 0x0017e178                |{{f/jal|Check if any unit can react|Check if any unit can react}} {{f/std| Test if Targets have reflect - return Unit ID if so}}
0019e0f4: 00408021 addu r16,r2,r0 r16 = Reactor ID?
+
0019e0f0: 27a40038 addiu r4,r29,0x0038          |{{f/std|Send pointer to Nb of Strikes}}
  0019e0f8: 1213000c beq r16,r19,0x0019e12c Exit if no unit reacted
+
0019e0f4: 00408021 addu r16,r2,r0                |{{f/std|ID of Unit with reflect}}
  <Ability can be reacted to>
+
0019e0f8: 1213000c beq r16,r19,0x0019e12c        {{f/Cond|If returned value is -0x01}} {{f/loc|Exit routine}} {{f/std|No reaction}}
  0019e0fc: 02301021 addu r2,r17,r16
+
0019e0fc: 02301021 addu r2,r17,r16                  |
  0019e100: 90420e18 lbu r2,0x0e18(r2) Load Targetable Unit List?
+
0019e100: 90420e18 lbu r2,0x0e18(r2)            |{{f/load|This Unit AI 0xe18 flag}} {{f/adr|0x8019f3c4 + 0xe18 + Unit ID}}
  0019e104: 00000000 nop
+
0019e104: 00000000 nop                          |
0019e108: 1440fff8 bne r2,r0,0x0019e0ec Branch if Reactor isn't hitting anyone?
+
0019e108: 1440fff8 bne r2,r0,0x0019e0ec          {{f/Cond|If This Unit will could move out of AoE before attack resolution}} {{f/loc|go to next unit}} {{f/std|Seek another reflected Unit}}
  0019e10c: 001020c0 sll r4,r16,0x03 Next Unit
+
0019e10c: 001020c0 sll r4,r16,0x03              |{{f/std|ID * 8}}
  0019e110: 00902023 subu r4,r4,r16 r4 = Pointer - Reactor ID
+
0019e110: 00902023 subu r4,r4,r16                |{{f/std|ID * 7}}
  0019e114: 00042180 sll r4,r4,0x06 Unit Target ID Pointer
+
0019e114: 00042180 sll r4,r4,0x06                |{{f/std|ID * 0x1c0}}
  0019e118: 00922021 addu r4,r4,r18 Get Target Data for Reactor
+
0019e118: 00922021 addu r4,r4,r18                |{{f/adr|0x801908cc + 0x16e + Unit with reflect offset}}
  0019e11c: 0c067763 jal 0x0019dd8c Loop through this entire current routine again (!)
+
  0019e11c: 0c067763 jal 0x0019dd8c                |{{f/jal|AI_ability_processing|AI_ability_processing}} {{f/std|Simulate reflect}}
0019e120: 34050001 ori r5,r0,0x0001 isEvaluatingReactingUnit = True
+
0019e120: 34050001 ori r5,r0,0x0001              |{{f/std|Send 0x01}}
0019e124: 0806783b j 0x0019e0ec Loop for all effected units
+
0019e124: 0806783b j 0x0019e0ec              {{f/jump|Loop until no reaction left}}
  0019e128: 00000000 nop
+
  0019e128: 00000000 nop                       |
 
 
<Exit>
 
 
  0019e12c: 8fbf006c lw r31,0x006c(r29)
 
  0019e12c: 8fbf006c lw r31,0x006c(r29)
 
  0019e130: 8fbe0068 lw r30,0x0068(r29)
 
  0019e130: 8fbe0068 lw r30,0x0068(r29)
Line 271: Line 269:
 
  0019e158: 03e00008 jr r31
 
  0019e158: 03e00008 jr r31
 
  0019e15c: 00000000 nop
 
  0019e15c: 00000000 nop
 +
===Return locations===
 +
'''BATTLE.BIN'''
 +
  0019dd2c: [[Call AI Ability Processing]]
 +
  0019e124: [[AI_ability_processing]] recursive call

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