Difference between revisions of "Usable Ability Setting/ENTD AI Calculations"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
Line 304: Line 304:
 
         - Store Silence Mod (4*Silencable/Total)
 
         - Store Silence Mod (4*Silencable/Total)
 
         - Store MP usage mod (4*Use MP/Total)
 
         - Store MP usage mod (4*Use MP/Total)
 +
Note : 4th Monster Abilities are ignored (not available 100% of the time)
 
   
 
   
  '''2nd Part''' : determines if [0x04 Use Weapon flag] should be enabled.
+
  '''2nd Part''' : Set AI 0x182c Byte 0x04 flags 0x01 0x02 and 0x04 (based on ability type)
     - First turn the flag OFF
+
     - First disable the 3 flags
     - If [Longbow Attack] or [Stop at obstacle] are ON : [Use Weapon Range] remains OFF (??)
+
     - If [Longbow Attack] or [Stop at obstacle] are ON : keep flags OFF
     - If [Linear Attack], [3-Direction Melee], [3 Direction Ranged] ar ON : [Use Weapon Range] is set ON
+
     - If [Linear Attack], [3-Direction Melee], [3 Direction Ranged] ar ON : Enable flag 0x04
     - If [Non Spear-Target] is OFF : [Use Weapon Range] is set ON
+
     - If [Non Spear-Target] is OFF : Enable Flag 0x04 (i didn't find any ability matching these conditions - All non spear ability stop at obstacles)
     - If Ability Range < 3 and Ability is Evadable : [Use Weapon Range] is set ON
+
     - If Ability Range < 3 and Ability is Evadable : Enable flag 0x04 - WARNING : i wonder if this is not a bug, and if this section were not meant to check 3 Directional in Ability data 2)
     - If Range >3 (or <3 non evadable) :
+
     - If Range >3 (or <3 non evadable / not 3 directional) :
             - If Ability can't hit Caster/Ally ; Enable flag [0x02 Unknwon] (no collateral Dmg ?)
+
             - If Ability can't hit Caster/Ally : Enable flag [0x02 Unknwon] (no collateral Dmg ?)
 
             - If Ability can Hit Caster/Allies but AoE = 0 : Enable flag [0x02 Unknwon]
 
             - If Ability can Hit Caster/Allies but AoE = 0 : Enable flag [0x02 Unknwon]
            - If Ability ID > 0x169 : [0x02 Unknow] is enabled if AoE = 0 (?? No AoE data for these abilities)         
+
                            -
 
 
  '''3rd Part'''                          -  
 
  '''3rd Part'''                          -  
 
  The AI setting flag 0x08 at Unit 0x167 is labeled [Defensive] in Patcher or [Coward-like] in wiki. In this routine, it seems to be a flag for a peculiar AI behavior.
 
  The AI setting flag 0x08 at Unit 0x167 is labeled [Defensive] in Patcher or [Coward-like] in wiki. In this routine, it seems to be a flag for a peculiar AI behavior.
 
  If this flag is OFF, the last part of this routine will be ignored.
 
  If this flag is OFF, the last part of this routine will be ignored.
 
  Check ENTD AI flags (Unit 0x167 and 0x168) :
 
  Check ENTD AI flags (Unit 0x167 and 0x168) :
   - No [Defensive] --> Nothing done
+
   - No [Defensive] flag --> Nothing done (AI 0x19a1 is not updated)
 
   - [Defensive] + [Preserve CT] --> Store 0x11 at 0x8019f3c4 + 0x19a1
 
   - [Defensive] + [Preserve CT] --> Store 0x11 at 0x8019f3c4 + 0x19a1
 
   - [Defensive] without [Focus unit] --> Nothing
 
   - [Defensive] without [Focus unit] --> Nothing
 
   - [Defensive] + [Focus Unit] without valid Target --> Disable [Defensive]
 
   - [Defensive] + [Focus Unit] without valid Target --> Disable [Defensive]
   - [Defensive] + [Focus Unit] wihout [Agressive] --> Unit ID in AI decision 0x05
+
   - [Defensive] + [Focus Unit] wihout [Agressive] --> Unit ID in AI 0x182c byte 0x05
 
   - [Defensive] + [Focus Unit] + [Agressive] --> Unit ID in AI decision 0x05 + in Unit Battle 0x1b9
 
   - [Defensive] + [Focus Unit] + [Agressive] --> Unit ID in AI decision 0x05 + in Unit Battle 0x1b9
 
           - If focused unit is an Ally --> store 0x0e at 0x8019f3c4 + 0x19a1
 
           - If focused unit is an Ally --> store 0x0e at 0x8019f3c4 + 0x19a1
 
           - If focused unit is an enemy --> store 0x0c at 0x8019f3c4 + 0x19a1
 
           - If focused unit is an enemy --> store 0x0c at 0x8019f3c4 + 0x19a1
 +
 +
'''Bug ?''' : The evadable check at 0x0019a0d4 is odd. It could be a missed 3-Directional check.
 +
 
=== Hard Coding ===
 
=== Hard Coding ===
 
  Ability Flag [0x01 - Evade with Motion], [0x02 Unknown] [0x04 Use Weapon flag] are disabled in AI move list ( 0x8019f3c4 + 0x0ef0)
 
  Ability Flag [0x01 - Evade with Motion], [0x02 Unknown] [0x04 Use Weapon flag] are disabled in AI move list ( 0x8019f3c4 + 0x0ef0)

Revision as of 16:17, 14 July 2024

BATTLE.BIN : Usable Ability Setting/ENTD AI Calculations
---------------------------------------------------------------------------
Parameters - r4 : Unit ID

Returns Nothing

Set AI move List - Some AI decision/behavior flags
---------------------------------------------------------------------------
 00199ec8: 27bdffc0 addiu r29,r29,-0x0040     |
00199ecc: afb5002c sw r21,0x002c(r29)        |
00199ed0: 0080a821 addu r21,r4,r0            |r21 = Unit's ID
00199ed4: afb30024 sw r19,0x0024(r29)        |
00199ed8: 3c13801a lui r19,0x801a            |
00199edc: 2673f3c4 addiu r19,r19,0xf3c4      |r19 = Pointer to AI Data  8019f3c4
00199ee0: 001510c0 sll r2,r21,0x03           |ID  8
00199ee4: 00551023 subu r2,r2,r21            |ID  7
00199ee8: 00021180 sll r2,r2,0x06            |ID  0x1c0 - Unit offset
00199eec: 3c038019 lui r3,0x8019             |
00199ef0: 246308cc addiu r3,r3,0x08cc        |
00199ef4: afb60030 sw r22,0x0030(r29)        |
00199ef8: 0043b021 addu r22,r2,r3            |r22 = Pointer to Unit's Data
00199efc: afbf003c sw r31,0x003c(r29)        |
00199f00: afbe0038 sw r30,0x0038(r29)        |
00199f04: afb70034 sw r23,0x0034(r29)        |
00199f08: afb40028 sw r20,0x0028(r29)        |
00199f0c: afb20020 sw r18,0x0020(r29)        |
00199f10: afb1001c sw r17,0x001c(r29)        |
00199f14: afb00018 sw r16,0x0018(r29)        |
00199f18: 92c30001 lbu r3,0x0001(r22)        |Load Unit's ID
00199f1c: 340200ff ori r2,r0,0x00ff          |
00199f20: 106200dd beq r3,r2,0x0019a298      #If Unit doesn't exist : Exit
00199f24: 02b31021 addu r2,r21,r19           |AI pointer + Unit offset (1 byte)
00199f28: 9042198c lbu r2,0x198c(r2)         |Load Unit's Battle ID?
00199f2c: 00000000 nop                       |
00199f30: 2c420010 sltiu r2,r2,0x0010        |Check if ID is valid (<0x10)
00199f34: 104000d8 beq r2,r0,0x0019a298      #If Unit ID is invalid  Exit
00199f38: 00000000 nop                       |
00199f3c: 0c0668bc jal 0x0019a2f0            |-->Set AI Flags/Usable Abilities Set Unit List of usable moves (0x8019f3c4 - 0x0ef0)
00199f40: 0000a021 addu r20,r0,r0            |Number of Abilities = 0
00199f44: 0000f021 addu r30,r0,r0            |MP Using Abilities = 0
00199f48: 0000b821 addu r23,r0,r0            |Silence Blocked Abilities = 0
00199f4c: 00009021 addu r18,r0,r0            |Counter = 0
00199f50: 00151100 sll r2,r21,0x04           |Unit's ID  16 (unit offset)
00199f54: 2442182c addiu r2,r2,0x182c        |+ AI decision data offset
00199f58: 00538821 addu r17,r2,r19           |Unit's AI decision data pointer (AI 0x182c)
00199f5c: 340200ff ori r2,r0,0x00ff          |r2 = 0x0ff
00199f60: afa00010 sw r0,0x0010(r29)         |Store Evadeable Abilities = 0   On stack
00199f64: a2200009 sb r0,0x0009(r17)         |Store Highest MP Cost = 0   AI decision data (AI 0x182c)
00199f68: a222000a sb r2,0x000a(r17)         |Store Lowest MP Cost = 0xFF  AI decision data (AI 0x182c)
00199f6c: 02751021 addu r2,r19,r21           |

=== ABILITY LOOP ===
                                            @LOOP through all abilities from unit list of usable abilities (AI 0xef0)
00199f70: 9043198c lbu r3,0x198c(r2)             |Load Considered Unit's Battle ID AI 0x198c + Unit Offset
00199f74: 00000000 nop                           |
00199f78: 00031100 sll r2,r3,0x04                |ID  16
00199f7c: 00431021 addu r2,r2,r3                 |ID  17
00199f80: 000210c0 sll r2,r2,0x03                |ID  0x88 (Unit offset)
00199f84: 24420ef0 addiu r2,r2,0x0ef0            |+ List of usable moves offset
00199f88: 02621021 addu r2,r19,r2                |Pointer to unit list of usable moves (AI 0xef0 + Considered Unit offset)
00199f8c: 00121880 sll r3,r18,0x02               |Counter  4
00199f90: 00438021 addu r16,r2,r3                |Pointer to this iteration Ability in unit list of usable moves (AI 0xef0 + Unit offset + This Ability Offset)
00199f94: 92030002 lbu r3,0x0002(r16)            |Load Ability's Skillset
00199f98: 340200ff ori r2,r0,0x00ff              |r2 = 0xFF
00199f9c: 1062006b beq r3,r2,0x0019a14c          #If The code reach the end of the list : Exit loop Skillset 0xff is a end marker
00199fa0: 02802021 addu r4,r20,r0                |r4 = Number of Abilities
00199fa4: 0c06561e jal 0x00195878                |-->AI Ability Data Setting  Transfer data from r4 to AI used Ability data ( 8019f3c4 )
00199fa8: 02002021 addu r4,r16,r0                |Send Ability pointer (AI 0xef0)
00199fac: 96020002 lhu r2,0x0002(r16)            |Load Ability's Skillset From Move List 0x8019f3c4 + 0x0ef0
00199fb0: 00000000 nop                           |
00199fb4: 30420800 andi r2,r2,0x0800             |Check [Requires Monster Skill]
00199fb8: 14400022 bne r2,r0,0x0019a044          #If Monster skill is needed Ignore Evade, Silence and MP mods Since ability won't be available 100% of the time ? 
00199fbc: 26940001 addiu r20,r20,0x0001          |Total Abilities + 1

                  -=- Set Silence and Evade mods and MP thresholds -=-
00199fc0: 8e63000c lw r3,0x000c(r19)             |Load AI Behavior Flags   8019f3c4 + 0x0c
00199fc4: 00000000 nop                           |
00199fc8: 30620100 andi r2,r3,0x0100             |Check [Ignore Silence]  It is a reversed flag - 0 for ignoring silence, 1 for not ignoring
00199fcc: 10400002 beq r2,r0,0x00199fd8          #If Ability is affected by silence
00199fd0: 30620200 andi r2,r3,0x0200             |Check [Evadable]
00199fd4: 26f70001 addiu r23,r23,0x0001              |Silencable Abilities + 1
00199fd8: 10400005 beq r2,r0,0x00199ff0          #If Ability is Evadable
00199fdc: 00000000 nop                               |
00199fe0: 8fa80010 lw r8,0x0010(r29)                 |Load Evadable abilities counter
00199fe4: 00000000 nop                               |
00199fe8: 25080001 addiu r8,r8,0x0001                |Counter + 1
00199fec: afa80010 sw r8,0x0010(r29)                 |Store new Evadeable Abilities counter
00199ff0: 92630011 lbu r3,0x0011(r19)            |Load Ability's MP Cost   8019f3c4 + 0x11
00199ff4: 00000000 nop                           |
00199ff8: 10600012 beq r3,r0,0x0019a044          #If Ability has a MP cost
00199ffc: 00000000 nop                               |
0019a000: 92220009 lbu r2,0x0009(r17)                |Load Highest MP Cost  In AI decision data - 8019f3c4 + 0x182c + 0x09
0019a004: 00000000 nop                               |
0019a008: 0043102b sltu r2,r2,r3                     |Check MP cost vs Highest MP cost
0019a00c: 10400004 beq r2,r0,0x0019a020              #If This iteration Ability has the highest MP cost
0019a010: 27de0001 addiu r30,r30,0x0001                  |MP Using Abilities + 1
0019a014: 92620011 lbu r2,0x0011(r19)                    |Load Ability's MP Cost
0019a018: 00000000 nop                                   |
0019a01c: a2220009 sb r2,0x0009(r17)                     |Store new Highest MP Cost  In AI decision data - 8019f3c4 + 0x182c + 0x09
0019a020: 92620011 lbu r2,0x0011(r19)                |Load Ability's MP Cost
0019a024: 9223000a lbu r3,0x000a(r17)                |Load Lowest MP Cost
0019a028: 00000000 nop                               |
0019a02c: 0043102b sltu r2,r2,r3                     |Check if tAbility has the lowest MP cost
0019a030: 10400004 beq r2,r0,0x0019a044              #If This iteration Ability has the lowest MP cost
0019a034: 00000000 nop                                   |
0019a038: 92620011 lbu r2,0x0011(r19)                    |Load Ability's MP Cost
0019a03c: 00000000 nop                                   |
0019a040: a222000a sb r2,0x000a(r17)                     |Store new Lowest MP Cost  In AI decision data - 8019f3c4 + 0x182c + 0x0a

                  -=-  Manage AI 0xef0 Byte 0x04's Flags 0x01 0x02 and 0x04 -=-
0019a044: 92020003 lbu r2,0x0003(r16)            |Load Usage Type (AI 0xef0 byte 0x03)
0019a048: 00000000 nop                           |
0019a04c: 304200f8 andi r2,r2,0x00f8             |
0019a050: a2020003 sb r2,0x0003(r16)             |Disable 0x01 (Evade with motion) 0x02 (unknown) and 0x04 (Use weapon range)
0019a054: 8e62000c lw r2,0x000c(r19)             |Load Ability's AI Flags   8019f3c4 + 0x0c
0019a058: 3c0300c0 lui r3,0x00c0                 |
0019a05c: 00431024 and r2,r2,r3                  |Check [Longbow] and [Stop at Obstacle]
0019a060: 14400035 bne r2,r0,0x0019a138          #If Ability is  Arcing or Stop at Obstacle next Ability
0019a064: 00000000 nop                           |
0019a068: 9262000e lbu r2,0x000e(r19)            |Load Ability's AI Flags 3  8019f3c4 + 0x0e
0019a06c: 00000000 nop                           |
0019a070: 3042003c andi r2,r2,0x003c             |Check [Linear Attack] , [Non Spear], [3 direction melee], [3 Direction ranged]   Non spear is a reverted flag (0x1 if unchecked)
0019a074: 10400004 beq r2,r0,0x0019a088          #If Ability has [Linear Attack], [3 direction melee], [3 direction ranged] or not  [Non spear Target]
0019a078: 00000000 nop                               |
0019a07c: 96020002 lhu r2,0x0002(r16)                |Load Ability's Skillset/Usage Type?  From Ability List 0x8019f3c4 + 0x0ef0 (0x02 and 0x03)
0019a080: 0806684d j 0x0019a134                      >>Jump to  Update AI 0xef0 byte 0x04  (enable flag 0x04)
0019a084: 34420400 ori r2,r2,0x0400                  |Enable 0x04 
                                                 Else : Ability is not a Linear attack, a spear attack nor a 3 directionnal attack
0019a088: 86640002 lh r4,0x0002(r19)                 |Load Ability ID  From 0x80193fc4 + 0x02
0019a08c: 00000000 nop                               |
0019a090: 28820170 slti r2,r4,0x0170                 |Check if Ability has a second data table
0019a094: 10400020 beq r2,r0,0x0019a118              #If Ability do not have a second data table : branch to  AoE check
0019a098: 00000000 nop                               |
0019a09c: 92620004 lbu r2,0x0004(r19)                |Load Ability's Range  From 0x80193fc4 + 0x04
0019a0a0: 92630005 lbu r3,0x0005(r19)                |Load Ability's AoE  From 0x80193fc4 + 0x05
0019a0a4: 00000000 nop                               |
0019a0a8: 00431021 addu r2,r2,r3                     |Max Reach = Range + AoE
0019a0ac: 28420003 slti r2,r2,0x0003                 |0x01 if max reach is < 0x3
0019a0b0: 1040000d beq r2,r0,0x0019a0e8              #If Max reach < 3 I don't really get what's happening here...
0019a0b4: 000410c0 sll r2,r4,0x03                        |
0019a0b8: 00441023 subu r2,r2,r4                         |
0019a0bc: 00021040 sll r2,r2,0x01                        |Ability ID  0x0e (Ability offset)
0019a0c0: 3c018006 lui r1,0x8006                         |
0019a0c4: 00220821 addu r1,r1,r2                         |
0019a0c8: 9022fbf6 lbu r2,-0x040a(r1)                    |Load Ability's Flags 4  SCUS data : 0x8005fbf0 + 0x06 + Ability offset
0019a0cc: 00000000 nop                                   |
0019a0d0: 30420002 andi r2,r2,0x0002                     |Check [Evadable]
0019a0d4: 10400004 beq r2,r0,0x0019a0e8                  #If Ability has  [evadable] flag in data 2 Error while  3 Direction check ? (would make more sense)
0019a0d8: 00000000 nop                                       |
0019a0dc: 96020002 lhu r2,0x0002(r16)                        |Load Ability's Skillset/Usage Type?  From Ability List 0x8019f3c4 + 0x0ef0 (0x02 and 0x03)
0019a0e0: 0806684d j 0x0019a134                              >>Jump to  Update AI 0xef0 byte 0x04  (enable flag 0x04)
0019a0e4: 34420400 ori r2,r2,0x0400                          |Enable 0x04 ( Evadable flag ?)
                                                     Else : Reach > 3 or not 3 direction
0019a0e8: 86620002 lh r2,0x0002(r19)                     |Load Ability ID 8019f3c4 + 0x02
0019a0ec: 00000000 nop                                   |
0019a0f0: 000218c0 sll r3,r2,0x03                        |
0019a0f4: 00621823 subu r3,r3,r2                         |
0019a0f8: 00031840 sll r3,r3,0x01                        |Ability ID  0x0e (Ability offset)
0019a0fc: 3c018006 lui r1,0x8006                         |
0019a100: 00230821 addu r1,r1,r3                         |
0019a104: 9022fbf4 lbu r2,-0x040c(r1)                    |Load Ability's Flags 2 SCUS data : 0x8005fbf0 + 0x04 + Ability offset
0019a108: 00000000 nop                                   |
0019a10c: 30420041 andi r2,r2,0x0041                     |Check [Hit Ally] and [Hit Caster] 
0019a110: 14400005 bne r2,r0,0x0019a128                  #If Ability cannot hit Caster team : branch to  Enable flag 0x02  Two reverted flags (0 if can hit)
0019a114: 00000000 nop                                       |
                                                 Else : No second Table or Can Hit Allies
0019a118: 92620005 lbu r2,0x0005(r19)                    |Load AoE  From 0x80193fc4 + 0x05
0019a11c: 00000000 nop                                   |
0019a120: 14400005 bne r2,r0,0x0019a138                  #If AoE > 0  Next iteration (Can Hit Allies but no AoE = no risk of collateral damage ?)
0019a124: 00000000 nop                                   |

                                            --- Enable flag 0x02 (No risk of hitting Ally and not 3 directional nor linear
0019a128: 96020002 lhu r2,0x0002(r16)            |Load Skillset/Usage Type?
0019a12c: 00000000 nop                           |
0019a130: 34420200 ori r2,r2,0x0200              |Enable 0x02

                                            --- Update AI 0xef0 - Byte 0x04 ---
0019a134: a6020002 sh r2,0x0002(r16)             |Store new Skillset/Usage Type?

0019a138: 26520001 addiu r18,r18,0x0001          |LOOP counter + 1
0019a13c: 2a420022 slti r2,r18,0x0022            |Check counter vs limit
0019a140: 1440ff8b bne r2,r0,0x00199f70      Λ LOOP Branch if Counter < 34
0019a144: 02751021 addu r2,r19,r21           |r2 = AI Data Pointer + unit offset (load Battle ID at 0x198c when the loop starts)

=== Update Unit AI 0x182c data ===
0019a148: 02802021 addu r4,r20,r0            |Divisor = Number of Abilities
0019a14c: 0c0668b3 jal 0x0019a2cc            |-->Dividend * 4 / Divisor  Returns r2 = r54/r4
0019a150: 02e02821 addu r5,r23,r0            |Dividend = Nb Of Ability affected by silence
0019a154: 02802021 addu r4,r20,r0            |Divisor = Number of Abilities
0019a158: 03c02821 addu r5,r30,r0            |Dividend = Nb Of Ability with a MP cost
0019a15c: 0c0668b3 jal 0x0019a2cc            |-->Dividend * 4 / Divisor
0019a160: a222000c sb r2,0x000c(r17)         |Store Silence effectivness Mod AI 0x182c + 0x0c
0019a164: 8fa50010 lw r5,0x0010(r29)         |Dividend - load Evadable Abilities
0019a168: 02802021 addu r4,r20,r0            |Divisor = Number of Abilities
0019a16c: 0c0668b3 jal 0x0019a2cc            |-->Dividend * 4 / Divisor Return Evade mod (stored below)
0019a170: a222000b sb r2,0x000b(r17)         |Store MP Using Mod AI 0x182c + 0x0b

=== Store ENTD Data ===
0019a174: 26240004 addiu r4,r17,0x0004       |AI decision + 0x04 (ENTD - settings)
0019a178: 26c50167 addiu r5,r22,0x0167       |r5 = Pointer to Unit's ENTD AI setting  0x801908cc + 0x167
0019a17c: 34060005 ori r6,r0,0x0005          |Limit = 5
0019a180: 0c066ad2 jal 0x0019ab48            |-->Transfer Byte Values  Transfer Bytes from 0x167 to 16b to AI decision 0x04 to 0x8
0019a184: a222000d sb r2,0x000d(r17)         |Store Evade Mod AI 0x182c + 0x0d
0019a188: 92c20165 lbu r2,0x0165(r22)        |Load ENTD X Location Battle data
0019a18c: 92230004 lbu r3,0x0004(r17)        |Load AI Setting - Behavior Just filled with battle 0x167 in routine above
0019a190: a2220000 sb r2,0x0000(r17)         |Store X Location to stay near AI 0x182c + 0x00
0019a194: 92c20166 lbu r2,0x0166(r22)        |Load AI Y Location Battle data
0019a198: 00000000 nop                       |
0019a19c: a2220002 sb r2,0x0002(r17)         |Store Y Location to stay near AI 0x182c + 0x02
0019a1a0: 92c20167 lbu r2,0x0167(r22)        |Load Unit 0x167 (elevation + behavior) Battle data
0019a1a4: a2200003 sb r0,0x0003(r17)         |Nullify/Initialize AI decision 0x03 AI 0x182c + 0x03
0019a1a8: 000211c2 srl r2,r2,0x07            |0x80 (if Higher Elevation)
0019a1ac: a2220001 sb r2,0x0001(r17)         |Store Higher Elevation Flag AI 0x182c + 0x01

=== BEHAVIOR HANDLING ===
0019a1b0: 30620008 andi r2,r3,0x0008         |Check [Defensive]  Defensive in Patcher - Coward-like in Wiki
0019a1b4: 10400038 beq r2,r0,0x0019a298      #If [Defensive] if OFF Exit routine Seems to be a "peculiar behavior" flag
0019a1b8: 00000000 nop                       |
0019a1bc: 92220007 lbu r2,0x0007(r17)        |Load AI Targeting flag (Copied from Unit battle 0x16a)
0019a1c0: 00000000 nop                       |
0019a1c4: 30420004 andi r2,r2,0x0004         |Check [Save-CT Protect Self]
0019a1c8: 10400007 beq r2,r0,0x0019a1e8      #If Unit setting do not have [Conserve CT] : branch to Focus section

                  -=- CONSERVE CT -=-
0019a1cc: 34020011 ori r2,r0,0x0011          |r2 = 0x11
0019a1d0: 02751821 addu r3,r19,r21           |r2 = AI Data Pointer + unit offset 
0019a1d4: 080668a6 j 0x0019a298              >>Else if [Conserve CT] : set Unit AI 0x19a1 == 0x11 and EXIT
0019a1d8: a06219a1 sb r2,0x19a1(r3)          |Store  0x11 at 0x8019f34c4 + 0x19a1 + Unit offset (1 byte per unit)

                                            --- Backward branch section - Focus On Enemy - Aggressive ---
0019a1dc: 3402000c ori r2,r0,0x000c              |r2 = 0x0c
0019a1e0: 080668a6 j 0x0019a298                  |Set AI 0x19a1 = 0x0c and Exit
0019a1e4: a06219a1 sb r2,0x19a1(r3)              |Store 0x0c at 0x8019f34c4 + 0x19a1 + Unit offset (1 byte per unit)

                  -=- FOCUS Section -=-
0019a1e8: 30620040 andi r2,r3,0x0040         |check [Focus Unit] r3 = Battle 0x167 via AI 0x182c + 0x04
0019a1ec: 1040002a beq r2,r0,0x0019a298      #If Unit is not Focusing a Unit Exit routine
0019a1f0: 00009021 addu r18,r0,r0            |Counter = 0
0019a1f4: 340600ff ori r6,r0,0x00ff          |r6 = 0xff
0019a1f8: 02752821 addu r5,r19,r21           |r5 = AI Pointer + Unit's ID
0019a1fc: 3407000e ori r7,r0,0x000e          |r7 = 0x0e
0019a200: 00002021 addu r4,r0,r0             |Unit Offset (+0x01c0 each iteration)
                                            @LOOP through all units 
0019a204: 3c018019 lui r1,0x8019             |
0019a208: 00240821 addu r1,r1,r4                 |
0019a20c: 902208cd lbu r2,0x08cd(r1)             |Load Unit's ID   0x801908cc + 0x01 + unit offset
0019a210: 00000000 nop                           |
0019a214: 10460018 beq r2,r6,0x0019a278          #If Unit do not exist : branch to  Next unit iteration
0019a218: 00000000 nop                           |
0019a21c: 3c018019 lui r1,0x8019                 |
0019a220: 00240821 addu r1,r1,r4                 |
0019a224: 90230a2d lbu r3,0x0a2d(r1)             |Load this iteration Unit's ENTD ID 0x81908cc + 0x161 + unit offset
0019a228: 92220005 lbu r2,0x0005(r17)            |Load Acting Unit Main Target ID AI 0x182c + 0x05 filled with Battle 0x168 in this routine
0019a22c: 00000000 nop                           |
0019a230: 14620011 bne r3,r2,0x0019a278          #If This iteration unit is the Targeted Unit
0019a234: 00000000 nop                               |
0019a238: 92220004 lbu r2,0x0004(r17)                |Load AI Behavior 
0019a23c: 00000000 nop                               |
0019a240: 30420010 andi r2,r2,0x0010                 |Check [Aggressive]
0019a244: 10400014 beq r2,r0,0x0019a298              #If Unit AI setting is not  [Aggressive] :  Update AI 0x182c + 0x05 and Exit routine
0019a248: a2320005 sb r18,0x0005(r17)                |Store Unit Counter as Main target ID It should be already the case no ? 
                                                     Else : Unit is [Aggressive]
0019a24c: a2d201b9 sb r18,0x01b9(r22)                    |Store Main Target ID in acting unit data (0x1b9)
0019a250: 3c018019 lui r1,0x8019                         |
0019a254: 00240821 addu r1,r1,r4                         |Part of pointer to unit battle stats
0019a258: 90230a86 lbu r3,0x0a86(r1)                     |LoadThis iteration Unit's Modified ENTD Flags
0019a25c: 92c201ba lbu r2,0x01ba(r22)                    |Load Unit's Modified ENTD Flags
0019a260: 30630030 andi r3,r3,0x0030                     |Check this iteration unit Team
0019a264: 30420030 andi r2,r2,0x0030                     |Check Acting unit Team
0019a268: 1462ffdc bne r3,r2,0x0019a1dc                  #If Acting Unit target a foe : branch to Aggresive Enemy focus section (backward section)
0019a26c: 02751821 addu r3,r19,r21                           |r3 = AI Pointer + Unit ID
                                                         Else : Focus Ally
0019a270: 080668a6 j 0x0019a298                              >>Jump to   Set AI 0x19a1 = 0x0e and Exit routine
0019a274: a0a719a1 sb r7,0x19a1(r5)                          |Store 0x0e at 0x8019f34c4 + 0x19a1 + Unit offset (1 byte per unit)
                                                 Else : This unit is not the targeted unit
0019a278: 26520001 addiu r18,r18,0x0001          |Unit ID + 1
0019a27c: 2a420015 slti r2,r18,0x0015            |
0019a280: 1440ffe0 bne r2,r0,0x0019a204      #Loop to next unit (0x15 times)
0019a284: 248401c0 addiu r4,r4,0x01c0            |Unit Data Offset (+0x01c0 each iteration)

                  --- Unit has [Focus] and [Aggressive] But the targeted Unit is missing
0019a288: 92220004 lbu r2,0x0004(r17)        |Load AI Behavior
0019a28c: 00000000 nop                       |
0019a290: 304200f7 andi r2,r2,0x00f7         |
0019a294: a2220004 sb r2,0x0004(r17)         |Disable flag 0x08 (no peculiar behavior) AI 0x182c + 0x04
0019a298: 8fbf003c lw r31,0x003c(r29)
0019a29c: 8fbe0038 lw r30,0x0038(r29)
0019a2a0: 8fb70034 lw r23,0x0034(r29)
0019a2a4: 8fb60030 lw r22,0x0030(r29)
0019a2a8: 8fb5002c lw r21,0x002c(r29)
0019a2ac: 8fb40028 lw r20,0x0028(r29)
0019a2b0: 8fb30024 lw r19,0x0024(r29)
0019a2b4: 8fb20020 lw r18,0x0020(r29)
0019a2b8: 8fb1001c lw r17,0x001c(r29)
0019a2bc: 8fb00018 lw r16,0x0018(r29)
0019a2c0: 27bd0040 addiu r29,r29,0x0040
0019a2c4: 03e00008 jr r31
0019a2c8: 00000000 nop

Notes

1st Part : Loop through all abilities in Unit List of Moves (8019f3c4 - 0x0ef0) and store some data in AI Decision data ( 8019f3c4 + 182c)
    - Determines if ability is evadable, silencable, has a MP cost.
    - Store the Highest and Lowest MP cost in AI decision data
        - Store Evade Mod (4*Evadable abilities/ Total abilities)
        - Store Silence Mod (4*Silencable/Total)
        - Store MP usage mod (4*Use MP/Total)
Note : 4th Monster Abilities are ignored (not available 100% of the time)

2nd Part : Set AI 0x182c Byte 0x04 flags 0x01 0x02 and 0x04 (based on ability type)
    - First disable the 3 flags
    - If [Longbow Attack] or [Stop at obstacle] are ON : keep flags OFF
    - If [Linear Attack], [3-Direction Melee], [3 Direction Ranged] ar ON : Enable flag 0x04
    - If [Non Spear-Target] is OFF : Enable Flag 0x04 (i didn't find any ability matching these conditions - All non spear ability stop at obstacles)
    - If Ability Range < 3 and Ability is Evadable : Enable flag 0x04 - WARNING : i wonder if this is not a bug, and if this section were not meant to check 3 Directional in Ability data 2)
    - If Range >3 (or <3 non evadable / not 3 directional) :
            - If Ability can't hit Caster/Ally : Enable flag [0x02 Unknwon] (no collateral Dmg ?)
            - If Ability can Hit Caster/Allies but AoE = 0 : Enable flag [0x02 Unknwon]

3rd Part                           - 
The AI setting flag 0x08 at Unit 0x167 is labeled [Defensive] in Patcher or [Coward-like] in wiki. In this routine, it seems to be a flag for a peculiar AI behavior.
If this flag is OFF, the last part of this routine will be ignored.
Check ENTD AI flags (Unit 0x167 and 0x168) :
  - No [Defensive] flag --> Nothing done (AI 0x19a1 is not updated)
  - [Defensive] + [Preserve CT] --> Store 0x11 at 0x8019f3c4 + 0x19a1
  - [Defensive] without [Focus unit] --> Nothing
  - [Defensive] + [Focus Unit] without valid Target --> Disable [Defensive]
  - [Defensive] + [Focus Unit] wihout [Agressive] --> Unit ID in AI 0x182c byte 0x05
  - [Defensive] + [Focus Unit] + [Agressive] --> Unit ID in AI decision 0x05 + in Unit Battle 0x1b9
          - If focused unit is an Ally --> store 0x0e at 0x8019f3c4 + 0x19a1
          - If focused unit is an enemy --> store 0x0c at 0x8019f3c4 + 0x19a1

Bug ? : The evadable check at 0x0019a0d4 is odd. It could be a missed 3-Directional check.

Hard Coding

Ability Flag [0x01 - Evade with Motion], [0x02 Unknown] [0x04 Use Weapon flag] are disabled in AI move list ( 0x8019f3c4 + 0x0ef0)
the [0x04 Use Weapon] and [0x02 Unknown] flags could be restored under condition (see notes)

Return locations

Battle.bin
00068f3c: Special_Status_Flag_Enabling - Remove Frog
00069040: Special_Status_Flag_Enabling - Inflict Frog
000751a8: Decide_what_to_do_based_on_skillset/ability_selections?
00075514: Set_move/act_based_on_skillset - Equip change
0008355c: Poach/Morbol_Transformation
00083bf8: Set_targets_animation_based_on_attack_type - Broken item 
00083c20: Set_targets_animation_based_on_attack_type - Stolen item
00199e20: Store_hardcoded_AI_stuff_(blood_suck,_frog,_berserk_abilities)