Set AI flags for target consideration

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
BATTLE.BIN : Setting AI Flags for Target Consideration
-----------------------------------------------------------------------------------------
Parameters : r4 = Acting Unit ID

Returns : Nothing
Set Target for unit without special behavior 
----------------------------------------------------------------------------------------- 
0019471c: 3c02801a lui r2,0x801a            |
00194720: 904201fd lbu r2,0x01fd(r2)        |Load Acting Unit Team
00194724: 27bdffe0 addiu r29,r29,-0x0020    |
00194728: afb00010 sw r16,0x0010(r29)       |
0019472c: 3c10801a lui r16,0x801a           |
00194730: 8e1001f8 lw r16,0x01f8(r16)       |Load Acting Unit's AI Decision Pointer
00194734: afb10014 sw r17,0x0014(r29)       |
00194738: 3c11801a lui r17,0x801a           |
0019473c: 2631f3c4 addiu r17,r17,0xf3c4     |Start of AI data
00194740: 1440000e bne r2,r0,0x0019477c     #If Acting unit is in Player Team
00194744: afbf0018 sw r31,0x0018(r29)           |
00194748: 3c03801a lui r3,0x801a                |
0019474c: 8c630bbc lw r3,0x0bbc(r3)             |Load Acting Unit Data Pointer
00194750: 00000000 nop                          |
00194754: 90620005 lbu r2,0x0005(r3)            |Load Acting Unit ENTD Flags
00194758: 00000000 nop                          |
0019475c: 30420008 andi r2,r2,0x0008            |Check [Control] Flag
00194760: 10400006 beq r2,r0,0x0019477c         #If Acting unit is controled by Player
00194764: 00000000 nop                              |
00194768: 906201b8 lbu r2,0x01b8(r3)                |Load Auto Battle Flag (From Current Action Data)
0019476c: 3c01801a lui r1,0x801a                    |
00194770: a0220d7a sb r2,0x0d7a(r1)                 |Store Acting unit Auto Battle Flag  at 801a0d7a aka 8019f3c4 + 0x19b6
00194774: 0806523d j 0x001948f4                     >>Jump to END
00194778: 00000000 nop                              |
                                            Else : Unit is not controled by player
0019477c: 92220e2e lbu r2,0x0e2e(r17)       |Load Acting Unit's ID
00194780: 00000000 nop                      |
00194784: 02221021 addu r2,r17,r2           |8019f3c4 + Unit offset
00194788: 904219a1 lbu r2,0x19a1(r2)        |Load AI Special Behavior flags/(Match Auto Battle flags ?)  Set in  Usable_Ability_Setting/ENTD_AI_Calculations
0019478c: 00000000 nop                      |
00194790: a22219b6 sb r2,0x19b6(r17)        |Store on Acting Unit AutoBattle Flags
00194794: 92030004 lbu r3,0x0004(r16)       |Load AI ENTD flags (From unit 0x167)
00194798: 00000000 nop                      |
0019479c: 30620008 andi r2,r3,0x0008        |Check for [Defensive] Mislabeled ? It's more a special behavior flag
001947a0: 10400023 beq r2,r0,0x00194830     #If Unit has a special behavior /Else go to Default targeting section
001947a4: 00000000 nop                          |
001947a8: 8e2217f8 lw r2,0x17f8(r17)            |Load Acting Unit's Data Pointer
001947ac: 00000000 nop                          |
001947b0: 90420059 lbu r2,0x0059(r2)            |Load Current Status 2
001947b4: 00000000 nop                          |
001947b8: 30420040 andi r2,r2,0x0040            |Check Invite
001947bc: 14400018 bne r2,r0,0x00194820         #If Unit do not have invite /Else disable [defensive] and go to default targeting
001947c0: 00000000 nop                              |
001947c4: 92020007 lbu r2,0x0007(r16)               |Load AI Targeting Flags 2 From Unit 0x16a
001947c8: 00000000 nop                              |
001947cc: 30420004 andi r2,r2,0x0004                |Check [Conserve CT] Self preservation
001947d0: 14400048 bne r2,r0,0x001948f4             #If [Conserve CT] is OFF Else Branch to END If [Conserve CT] is ON
001947d4: 00000000 nop                                  |
001947d8: 922219b6 lbu r2,0x19b6(r17)                   |Load AI settings/AutoBattle Flags
001947dc: 00000000 nop                                  |
001947e0: 14400044 bne r2,r0,0x001948f4                 #If There is no flags ON Else Branch to END If Some Auto Battle flags are ON
001947e4: 30620040 andi r2,r3,0x0040                        |Check [Focus Unit]
001947e8: 10400009 beq r2,r0,0x00194810                     #If [Focus Unit] is ON
001947ec: 00000000 nop                                          |
001947f0: 92040005 lbu r4,0x0005(r16)                           |Load Load Main Target ID
001947f4: 0c067ca9 jal 0x0019f2a4                               |-->Transfer_Unit_Coordinates_to_AI  Transfer Unit X, Y and elevation in AI decision data
001947f8: 02002821 addu r5,r16,r0                               |
001947fc: 92040005 lbu r4,0x0005(r16)                           |Load Main Target ID
00194800: 0c065b23 jal 0x00196c8c                               |-->Check_target_type  r2 = 0x00 if unit is worth to be considered
00194804: 00000000 nop                                          |
00194808: 08065205 j 0x00194814                                 >>Avoid No Focus section
0019480c: 00000000 nop                                          |
                                                            Else : [Focus Unit] is OFF
00194810: 922219bb lbu r2,0x19bb(r17)                           |Load Unit Targetable Flag (?)  8019f3c4 + 0x19bb
00194814: 00000000 nop                                          |
00194818: 10400036 beq r2,r0,0x001948f4                     #If Focus Unit is targetable or There's at least 2 enemies : branch to END
0019481c: 00000000 nop                                      |
                                                Here if : Unit has a special Behavior and has Invite / Focus an Untargetable Target / Last Foe standing
00194820: 92020004 lbu r2,0x0004(r16)           |Load AI Decision 0x04 ( ENTD behavior flag)
00194824: 00000000 nop                          |
00194828: 304200f7 andi r2,r2,0x00f7            |Force [Defensive]OFF Remove special behavior ?
0019482c: a2020004 sb r2,0x0004(r16)            |Store Updated Flag

                                            Here if : Unit has no Special Behavior (innately or disabled)
--- Default Targeting section ---
00194830: 92220e39 lbu r2,0x0e39(r17)       |Load Acting Unit's Team
00194834: 00000000 nop                      |
00194838: 14400015 bne r2,r0,0x00194890     #If Acting unit is From player Team  But [Control flag] is OFF
0019483c: 00000000 nop                          |
00194840: 8e2317f8 lw r3,0x17f8(r17)            |Load Acting Unit's Data Pointer
00194844: a22019b6 sb r0,0x19b6(r17)            |Empty AI/Autobattle setting
00194848: 94620028 lhu r2,0x0028(r3)            |Load CurHP
0019484c: 9463002a lhu r3,0x002a(r3)            |Load MaxHP
00194850: 000211c0 sll r2,r2,0x07               |CurHP * 0x80
00194854: 0043001a div r2,r3                    |(CurHP * 0x80) / MaxHP
00194858: 00001012 mflo r2                      |Get CurHP Hex% (base of 128)
0019485c: 00000000 nop                          |
00194860: 2842002d slti r2,r2,0x002d            |Check if HP < 35,16%
00194864: 1440001c bne r2,r0,0x001948d8         #If Current HP > 35% #Jump to routines
00194868: 34040005 ori r4,r0,0x0005             |r4 = 0x05 128
0019486c: 34040001 ori r4,r0,0x0001                 |r4 = 0x01 (Targetable flag)
00194870: 34020014 ori r2,r0,0x0014                 |Initialize Loop Counter (countdown)
00194874: 26230014 addiu r3,r17,0x0014              |End of Targetable list pointer
                                                    @LOOP - Set all units as targetable in AI targetable list
00194878: a0640c8d sb r4,0x0c8d(r3)                     |Set unit as targetable in Targetable Unit List
0019487c: 2442ffff addiu r2,r2,-0x0001                  |Counter - 1
00194880: 0441fffd bgez r2,0x00194878               Λ Loop 0x15 times (All the list)
00194884: 2463ffff addiu r3,r3,-0x0001                  |Targetable List offset - 1
00194888: 08065236 j 0x001948d8                     >>Jump to routines
0019488c: 34040004 ori r4,r0,0x0004                 |r4 = 0x04
                                            Else - Unit is not in player Team
00194890: 92020006 lbu r2,0x0006(r16)           |Load AI Targeting Flags 1 Come from Unit 0x169 (the byte used by snowflakes ?)
00194894: 00000000 nop                          |
00194898: 30420004 andi r2,r2,0x0004            |Check [Flag 0x04] - Largest # of usable helpfull abilities ?
0019489c: 10400006 beq r2,r0,0x001948b8         #If Unit have largest # of usable helpfull abilities
001948a0: 34040001 ori r4,r0,0x0001             |r4 = 0x01 (Flag for below loop)
001948a4: 92020007 lbu r2,0x0007(r16)               |Load AI Targeting Flags 2
001948a8: 00000000 nop                              |
001948ac: 30420008 andi r2,r2,0x0008                |Check [Allied Targeted] - Panic Mod ?
001948b0: 1040000f beq r2,r0,0x001948f0             #If Allied Targeted is ON /Else branch to END without Target ID
001948b4: 34020010 ori r2,r0,0x0010                 |r2 = 0x10
001948b8: a22019b6 sb r0,0x19b6(r17)            #E      |Empty AI/Autobattle setting
001948bc: 34020014 ori r2,r0,0x0014                     |Initialize Loop Counter (countdown)
001948c0: 26230014 addiu r3,r17,0x0014                  |End of Targetable list pointer
                                                        @LOOP - Set all units as targetable
001948c4: a0640c8d sb r4,0x0c8d(r3)                         |Set unit as targetable in Targetable Unit List Set unit as targetable in Targetable Unit List
001948c8: 2442ffff addiu r2,r2,-0x0001                      |Counter - 1
001948cc: 0441fffd bgez r2,0x001948c4                   Λ Loop 0x15 Times
001948d0: 2463ffff addiu r3,r3,-0x0001                      |Targetable List offset - 1
001948d4: 34040004 ori r4,r0,0x0004                     |r4 = 0x04
Last routines Section
001948d8: 0c066449 jal 0x00199124                       |-->Calculate_Physical%3F_Target Returns r2 = Unit ID fulfilling conditions (r4)
001948dc: 00000000 nop                                  |
001948e0: 0c065243 jal 0x0019490c                       |-->Store_main_target_ID_and_focus_on_target_flag
001948e4: 00402021 addu r4,r2,r0                        |
001948e8: 0806523d j 0x001948f4                         |
001948ec: 00000000 nop                                  |
                                                    Else [Largest Nb of Abilities] and [Allied Targeted] is OFF
001948f0: a22219b6 sb r2,0x19b6(r17)                    |Set Auto Battle Flag as [Save fading Life]
001948f4: 8fbf0018 lw r31,0x0018(r29)       END
001948f8: 8fb10014 lw r17,0x0014(r29)
001948fc: 8fb00010 lw r16,0x0010(r29)
00194900: 27bd0020 addiu r29,r29,0x0020
00194904: 03e00008 jr r31
00194908: 00000000 nop

Notes

Ignores Unit controled by player (deals with AI and player in auto battle mod)
Check unit AI decision data : 0x8019f3c4 + 0x182c - Byte 0x04 - Flag 0x08 aka [defensive] 
Forces [defensive] OFF if : 
   - Unit has invite
   - Unit has [Focus Unit] but the Target is untargetable
   - Unit don't [Focus Unit] but 0x8019f3c4 + 0x19bb flag is ON (Set to 0x01 if there is one Foe left (see Some_targetability_setting)

[Defensive] ON   
  - Conserve CT --> Exit routine 
  - No Auto battle flags --> Exit routine (?)   [0x8019f3c4 + 0x19b6]
  - Focus Unit : Exit if Target is Targetable
  - No Unit Focus : if 0x8019f3c4 + 0x19bb is OFF then exit routine
  Other cases --> disable [defensive] and go to default
  
[Defensive] OFF
   Player Unit in AutoBattle mod :
     - HP < 35 % --> Target Nearest Ally Healer
     - HP > 35 % --> Target Nearest Active enemy
   
   Not in player team : Set unit Behavior based on some flags in AI decision data (8019f3c4 + 0x182c)
   Check [Byte 0x06 - Flag 0x40] : 
       - ON :  Check nearest Active enemy
       - OFF : Check [Byte 0x07 - Flag 0x08] - AI Panic Mod ? ( see Some_targetability_setting)
                    - ON : Check nearest Active enemy
                    - OFF : Set Auto Battle Flag as [Save fading life]- No targets    

Return Locations

BATTLE.BIN
0c0651c7 : Main_AI_action_setup