Difference between revisions of "Set AI flags for target consideration"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Uploading Routine - Didn't document yet)
 
m
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Setting AI Flags for Target Consideration
+
BATTLE.BIN : Setting AI Flags for Target Consideration
 
+
-----------------------------------------------------------------------------------------
  0019471c: 3c02801a lui r2,0x801a
+
Parameters : r4 = Acting Unit ID
  00194720: 904201fd lbu r2,0x01fd(r2)
+
  00194724: 27bdffe0 addiu r29,r29,0xffe0
+
Returns : Nothing
  00194728: afb00010 sw r16,0x0010(r29)
+
Set Target for unit without special behavior
  0019472c: 3c10801a lui r16,0x801a
+
-----------------------------------------------------------------------------------------
  00194730: 8e1001f8 lw r16,0x01f8(r16)
+
  0019471c: 3c02801a lui r2,0x801a           |
  00194734: afb10014 sw r17,0x0014(r29)
+
  00194720: 904201fd lbu r2,0x01fd(r2)       |{{f/load|Load Acting Unit Team}}
  00194738: 3c11801a lui r17,0x801a
+
  00194724: 27bdffe0 addiu r29,r29,-0x0020    |
  0019473c: 2631f3c4 addiu r17,r17,0xf3c4
+
  00194728: afb00010 sw r16,0x0010(r29)       |
  00194740: 1440000e bne r2,r0,0x0019477c
+
  0019472c: 3c10801a lui r16,0x801a           |
  00194744: afbf0018 sw r31,0x0018(r29)
+
  00194730: 8e1001f8 lw r16,0x01f8(r16)       |{{f/adr|Load Acting Unit's AI Decision Pointer}}
  00194748: 3c03801a lui r3,0x801a
+
  00194734: afb10014 sw r17,0x0014(r29)       |
  0019474c: 8c630bbc lw r3,0x0bbc(r3)
+
  00194738: 3c11801a lui r17,0x801a           |
  00194750: 00000000 nop
+
  0019473c: 2631f3c4 addiu r17,r17,0xf3c4     |{{f/adr|Start of AI data}}
  00194754: 90620005 lbu r2,0x0005(r3)
+
  00194740: 1440000e bne r2,r0,0x0019477c     {{f/Cond|If Acting unit is in Player Team}}
  00194758: 00000000 nop
+
  00194744: afbf0018 sw r31,0x0018(r29)           |
  0019475c: 30420008 andi r2,r2,0x0008
+
  00194748: 3c03801a lui r3,0x801a               |
  00194760: 10400006 beq r2,r0,0x0019477c
+
  0019474c: 8c630bbc lw r3,0x0bbc(r3)             |{{f/adr|Load Acting Unit Data Pointer}}
  00194764: 00000000 nop
+
  00194750: 00000000 nop                         |
  00194768: 906201b8 lbu r2,0x01b8(r3)
+
  00194754: 90620005 lbu r2,0x0005(r3)           |{{f/load|Load Acting Unit ENTD Flags}}
  0019476c: 3c01801a lui r1,0x801a
+
  00194758: 00000000 nop                         |
  00194770: a0220d7a sb r2,0x0d7a(r1)
+
  0019475c: 30420008 andi r2,r2,0x0008           |{{f/std|Check [Control] Flag}}
  00194774: 0806523d j 0x001948f4
+
  00194760: 10400006 beq r2,r0,0x0019477c         {{f/Cond|If Acting unit is controled by Player}}
  00194778: 00000000 nop
+
  00194764: 00000000 nop                             |
  0019477c: 92220e2e lbu r2,0x0e2e(r17)
+
  00194768: 906201b8 lbu r2,0x01b8(r3)               |{{f/load|Load Auto Battle Flag (From Current Action Data)}}
  00194780: 00000000 nop
+
  0019476c: 3c01801a lui r1,0x801a                   |
  00194784: 02221021 addu r2,r17,r2
+
  00194770: a0220d7a sb r2,0x0d7a(r1)                 |{{f/store|Store Acting unit Auto Battle Flag}} {{f/std| at 801a0d7a aka 8019f3c4 + 0x19b6}}
  00194788: 904219a1 lbu r2,0x19a1(r2)
+
  00194774: 0806523d j 0x001948f4                     {{f/jump|Jump to}} {{f/loc|END}}
  0019478c: 00000000 nop
+
  00194778: 00000000 nop                             |
  00194790: a22219b6 sb r2,0x19b6(r17)
+
                                            '''Else : Unit is not controled by player'''
  00194794: 92030004 lbu r3,0x0004(r16)
+
  0019477c: 92220e2e lbu r2,0x0e2e(r17)       |{{f/load|Load Acting Unit's ID}}
  00194798: 00000000 nop
+
  00194780: 00000000 nop                     |
  0019479c: 30620008 andi r2,r3,0x0008
+
  00194784: 02221021 addu r2,r17,r2           |{{f/adr|8019f3c4 + Unit offset}}
  001947a0: 10400023 beq r2,r0,0x00194830
+
  00194788: 904219a1 lbu r2,0x19a1(r2)       |{{f/load|Load AI Special Behavior flags/(Match Auto Battle flags ?)}} {{f/std| Set in }} [[Usable_Ability_Setting/ENTD_AI_Calculations]]
  001947a4: 00000000 nop
+
  0019478c: 00000000 nop                     |
  001947a8: 8e2217f8 lw r2,0x17f8(r17)
+
  00194790: a22219b6 sb r2,0x19b6(r17)       |{{f/store|Store on Acting Unit AutoBattle Flags}}
  001947ac: 00000000 nop
+
  00194794: 92030004 lbu r3,0x0004(r16)       |{{f/load|Load AI ENTD flags (From unit 0x167)}}
  001947b0: 90420059 lbu r2,0x0059(r2)
+
  00194798: 00000000 nop                     |
  001947b4: 00000000 nop
+
  0019479c: 30620008 andi r2,r3,0x0008       |{{f/std|Check for [Defensive]}} {{f/std|Mislabeled ? It's more a special behavior flag}}
  001947b8: 30420040 andi r2,r2,0x0040
+
  001947a0: 10400023 beq r2,r0,0x00194830     {{f/Cond|If Unit has a special behavior}} {{f/std|/Else go to Default targeting section}}
  001947bc: 14400018 bne r2,r0,0x00194820
+
  001947a4: 00000000 nop                         |
  001947c0: 00000000 nop
+
  001947a8: 8e2217f8 lw r2,0x17f8(r17)           |{{f/adr|Load Acting Unit's Data Pointer}}
  001947c4: 92020007 lbu r2,0x0007(r16)
+
  001947ac: 00000000 nop                         |
  001947c8: 00000000 nop
+
  001947b0: 90420059 lbu r2,0x0059(r2)           |{{f/load|Load Current Status 2}}
  001947cc: 30420004 andi r2,r2,0x0004
+
  001947b4: 00000000 nop                         |
  001947d0: 14400048 bne r2,r0,0x001948f4
+
  001947b8: 30420040 andi r2,r2,0x0040           |{{f/std|Check Invite}}
  001947d4: 00000000 nop
+
  001947bc: 14400018 bne r2,r0,0x00194820         {{f/Cond|If Unit do not have invite}} /Else disable [defensive] and go to default targeting
  001947d8: 922219b6 lbu r2,0x19b6(r17)
+
  001947c0: 00000000 nop                             |
  001947dc: 00000000 nop
+
  001947c4: 92020007 lbu r2,0x0007(r16)               |{{f/load|Load AI Targeting Flags 2}} {{f/std|From Unit 0x16a}}
  001947e0: 14400044 bne r2,r0,0x001948f4
+
  001947c8: 00000000 nop                             |
  001947e4: 30620040 andi r2,r3,0x0040
+
  001947cc: 30420004 andi r2,r2,0x0004               |{{f/std|Check [Conserve CT]}} {{f/std|Self preservation}}
  001947e8: 10400009 beq r2,r0,0x00194810
+
  001947d0: 14400048 bne r2,r0,0x001948f4             {{f/Cond|If [Conserve CT] is OFF}} Else Branch to {{f/loc|END}} If [Conserve CT] is ON
  001947ec: 00000000 nop
+
  001947d4: 00000000 nop                                 |
  001947f0: 92040005 lbu r4,0x0005(r16)
+
  001947d8: 922219b6 lbu r2,0x19b6(r17)                   |{{f/load|Load AI settings/AutoBattle Flags}}
  001947f4: 0c067ca9 jal 0x0019f2a4
+
  001947dc: 00000000 nop                                 |
  001947f8: 02002821 addu r5,r16,r0
+
  001947e0: 14400044 bne r2,r0,0x001948f4                 {{f/Cond|If There is no flags ON}} Else Branch to {{f/loc|END}} If Some Auto Battle flags are ON
  001947fc: 92040005 lbu r4,0x0005(r16)
+
  001947e4: 30620040 andi r2,r3,0x0040                       |{{f/std|Check [Focus Unit]}}
  00194800: 0c065b23 jal 0x00196c8c
+
  001947e8: 10400009 beq r2,r0,0x00194810                     {{f/Cond|If [Focus Unit] is ON}}
  00194804: 00000000 nop
+
  001947ec: 00000000 nop                                         |
  00194808: 08065205 j 0x00194814
+
  001947f0: 92040005 lbu r4,0x0005(r16)                           |{{f/load|Load Load Main Target ID}}
  0019480c: 00000000 nop
+
  001947f4: 0c067ca9 jal 0x0019f2a4                               |{{f/jal|Transfer_Unit_Coordinates_to_AI|Transfer_Unit_Coordinates_to_AI}} {{f/std| Transfer Unit X, Y and elevation in AI decision data}}
  00194810: 922219bb lbu r2,0x19bb(r17)
+
  001947f8: 02002821 addu r5,r16,r0                               |
  00194814: 00000000 nop
+
  001947fc: 92040005 lbu r4,0x0005(r16)                           |{{f/load|Load Main Target ID}}
  00194818: 10400036 beq r2,r0,0x001948f4
+
  00194800: 0c065b23 jal 0x00196c8c                               |{{f/jal|Check_target_type|Check_target_type}} {{f/std|<nowiki> r2 = 0x00 if unit is worth to be considered</nowiki>}}
  0019481c: 00000000 nop
+
  00194804: 00000000 nop                                         |
  00194820: 92020004 lbu r2,0x0004(r16)
+
  00194808: 08065205 j 0x00194814                                 {{f/jump|Avoid No Focus section}}
  00194824: 00000000 nop
+
  0019480c: 00000000 nop                                         |
  00194828: 304200f7 andi r2,r2,0x00f7
+
                                                            '''Else : [Focus Unit] is OFF'''
  0019482c: a2020004 sb r2,0x0004(r16)
+
  00194810: 922219bb lbu r2,0x19bb(r17)                           |{{f/load|Load Unit Targetable Flag (?)}} {{f/std| 8019f3c4 + 0x19bb}}
  00194830: 92220e39 lbu r2,0x0e39(r17)
+
  00194814: 00000000 nop                                         |
  00194834: 00000000 nop
+
  00194818: 10400036 beq r2,r0,0x001948f4                     {{f/Cond|If Focus Unit is targetable or There's at least 2 enemies : branch to}} {{f/loc|END}}
  00194838: 14400015 bne r2,r0,0x00194890
+
  0019481c: 00000000 nop                                     |
  0019483c: 00000000 nop
+
                                                '''Here if : Unit has a special Behavior and has Invite / Focus an Untargetable Target / Last Foe standing'''
  00194840: 8e2317f8 lw r3,0x17f8(r17)
+
  00194820: 92020004 lbu r2,0x0004(r16)           |{{f/load|Load AI Decision 0x04 ( ENTD behavior flag)}}
  00194844: a22019b6 sb r0,0x19b6(r17)
+
  00194824: 00000000 nop                         |
  00194848: 94620028 lhu r2,0x0028(r3)
+
  00194828: 304200f7 andi r2,r2,0x00f7           |{{f/std|Force [Defensive]OFF}} {{f/std|Remove special behavior ?}}
  0019484c: 9463002a lhu r3,0x002a(r3)
+
  0019482c: a2020004 sb r2,0x0004(r16)           |{{f/store|Store Updated Flag}}
  00194850: 000211c0 sll r2,r2,0x07
+
  00194854: 0043001a div r2,r3
+
                                            '''Here if : Unit has no Special Behavior (innately or disabled)'''
  00194858: 00001012 mflo r2
+
{{f/sec|--- Default Targeting section ---}}
  0019485c: 00000000 nop
+
  00194830: 92220e39 lbu r2,0x0e39(r17)       |{{f/load|Load Acting Unit's Team}}
  00194860: 2842002d slti r2,r2,0x002d
+
  00194834: 00000000 nop                     |
  00194864: 1440001c bne r2,r0,0x001948d8
+
  00194838: 14400015 bne r2,r0,0x00194890     {{f/Cond|If Acting unit is From player Team }} {{f/std|But [Control flag] is OFF}}
  00194868: 34040005 ori r4,r0,0x0005
+
  0019483c: 00000000 nop                         |
  0019486c: 34040001 ori r4,r0,0x0001
+
  00194840: 8e2317f8 lw r3,0x17f8(r17)           |{{f/adr|Load Acting Unit's Data Pointer}}
  00194870: 34020014 ori r2,r0,0x0014
+
  00194844: a22019b6 sb r0,0x19b6(r17)           |{{f/store|Empty AI/Autobattle setting}}
  00194874: 26230014 addiu r3,r17,0x0014
+
  00194848: 94620028 lhu r2,0x0028(r3)           |{{f/load|Load CurHP}}
  00194878: a0640c8d sb r4,0x0c8d(r3)
+
  0019484c: 9463002a lhu r3,0x002a(r3)           |{{f/load|Load MaxHP}}
  0019487c: 2442ffff addiu r2,r2,0xffff
+
  00194850: 000211c0 sll r2,r2,0x07               |{{f/std|CurHP * 0x80}}
  00194880: 0441fffd bgez r2,0x00194878
+
  00194854: 0043001a div r2,r3                   |{{f/std|(CurHP * 0x80) / MaxHP}}
  00194884: 2463ffff addiu r3,r3,0xffff
+
  00194858: 00001012 mflo r2                     |{{f/std|Get CurHP Hex% (base of 128)}}
  00194888: 08065236 j 0x001948d8
+
  0019485c: 00000000 nop                         |
  0019488c: 34040004 ori r4,r0,0x0004
+
  00194860: 2842002d slti r2,r2,0x002d           |{{f/std|Check if HP < 35,16%}}
  00194890: 92020006 lbu r2,0x0006(r16)
+
  00194864: 1440001c bne r2,r0,0x001948d8         {{f/Cond|If Current HP > 35%}} {{f/Cond|Jump to routines}}
  00194894: 00000000 nop
+
  00194868: 34040005 ori r4,r0,0x0005             |{{f/std|<nowiki>r4 = 0x05</nowiki>}} {{f/std|128}}
  00194898: 30420004 andi r2,r2,0x0004
+
  0019486c: 34040001 ori r4,r0,0x0001                 |{{f/std|<nowiki>r4 = 0x01 (Targetable flag)</nowiki>}}
  0019489c: 10400006 beq r2,r0,0x001948b8
+
  00194870: 34020014 ori r2,r0,0x0014                 |{{f/std|Initialize Loop Counter (countdown)}}
  001948a0: 34040001 ori r4,r0,0x0001
+
  00194874: 26230014 addiu r3,r17,0x0014             |{{f/adr|End of Targetable list pointer}}
  001948a4: 92020007 lbu r2,0x0007(r16)
+
                                                    {{f/bloop|LOOP - Set all units as targetable in AI targetable list}}
  001948a8: 00000000 nop
+
  00194878: a0640c8d sb r4,0x0c8d(r3)                     |{{f/store|Set unit as targetable in Targetable Unit List}}
  001948ac: 30420008 andi r2,r2,0x0008
+
  0019487c: 2442ffff addiu r2,r2,-0x0001                  |{{f/std|Counter - 1}}
  001948b0: 1040000f beq r2,r0,0x001948f0
+
  00194880: 0441fffd bgez r2,0x00194878               {{f/eloop|Loop 0x15 times (All the list)}}
  001948b4: 34020010 ori r2,r0,0x0010
+
  00194884: 2463ffff addiu r3,r3,-0x0001                  |{{f/std|Targetable List offset - 1}}
  001948b8: a22019b6 sb r0,0x19b6(r17)
+
  00194888: 08065236 j 0x001948d8                     {{f/jump|Jump to routines}}
  001948bc: 34020014 ori r2,r0,0x0014
+
  0019488c: 34040004 ori r4,r0,0x0004                 |{{f/std|<nowiki>r4 = 0x04</nowiki>}}
  001948c0: 26230014 addiu r3,r17,0x0014
+
                                            '''Else - Unit is not in player Team'''
  001948c4: a0640c8d sb r4,0x0c8d(r3)
+
  00194890: 92020006 lbu r2,0x0006(r16)           |{{f/load|Load AI Targeting Flags 1}} {{f/std|Come from Unit 0x169 (the byte used by snowflakes ?)}}
  001948c8: 2442ffff addiu r2,r2,0xffff
+
  00194894: 00000000 nop                         |
  001948cc: 0441fffd bgez r2,0x001948c4
+
  00194898: 30420004 andi r2,r2,0x0004           |{{f/std|Check [Flag 0x04] - Largest # of usable helpfull abilities ?}}
  001948d0: 2463ffff addiu r3,r3,0xffff
+
  0019489c: 10400006 beq r2,r0,0x001948b8         {{f/Cond|If Unit have largest # of usable helpfull abilities}}
  001948d4: 34040004 ori r4,r0,0x0004
+
  001948a0: 34040001 ori r4,r0,0x0001             |{{f/std|<nowiki>r4 = 0x01 (Flag for below loop)</nowiki>}}
  001948d8: 0c066449 jal 0x00199124
+
  001948a4: 92020007 lbu r2,0x0007(r16)               |{{f/load|Load AI Targeting Flags 2}}
  001948dc: 00000000 nop
+
  001948a8: 00000000 nop                             |
  001948e0: 0c065243 jal 0x0019490c
+
  001948ac: 30420008 andi r2,r2,0x0008               |{{f/std|Check [Allied Targeted] - Panic Mod ?}}
  001948e4: 00402021 addu r4,r2,r0
+
  001948b0: 1040000f beq r2,r0,0x001948f0             {{f/Cond|If Allied Targeted is ON}} /Else branch to {{f/loc|END}} without Target ID
  001948e8: 0806523d j 0x001948f4
+
  001948b4: 34020010 ori r2,r0,0x0010                 |{{f/std|<nowiki>r2 = 0x10</nowiki>}}
  001948ec: 00000000 nop
+
  001948b8: a22019b6 sb r0,0x19b6(r17)           {{f/Cond|E    }} |{{f/store|Empty AI/Autobattle setting}}
  001948f0: a22219b6 sb r2,0x19b6(r17)
+
  001948bc: 34020014 ori r2,r0,0x0014                     |{{f/std|Initialize Loop Counter (countdown)}}
  001948f4: 8fbf0018 lw r31,0x0018(r29)
+
  001948c0: 26230014 addiu r3,r17,0x0014                 |{{f/adr|End of Targetable list pointer}}
 +
                                                        {{f/bloop|LOOP - Set all units as targetable}}
 +
  001948c4: a0640c8d sb r4,0x0c8d(r3)                         |{{f/store|Set unit as targetable in Targetable Unit List}} {{f/store|Set unit as targetable in Targetable Unit List}}
 +
  001948c8: 2442ffff addiu r2,r2,-0x0001                      |{{f/std|Counter - 1}}
 +
  001948cc: 0441fffd bgez r2,0x001948c4                   {{f/eloop|Loop 0x15 Times}}
 +
  001948d0: 2463ffff addiu r3,r3,-0x0001                      |{{f/std|Targetable List offset - 1}}
 +
  001948d4: 34040004 ori r4,r0,0x0004                     |{{f/std|<nowiki>r4 = 0x04</nowiki>}}
 +
{{f/sec|Last routines Section}}
 +
  001948d8: 0c066449 jal 0x00199124                       |{{f/jal|Calculate_Physical%3F_Target|Calculate_Physical%3F_Target}} {{f/std|<nowiki>Returns r2 = Unit ID fulfilling conditions (r4)</nowiki>}}
 +
  001948dc: 00000000 nop                                 |
 +
  001948e0: 0c065243 jal 0x0019490c                       |{{f/jal|Store_main_target_ID_and_focus_on_target_flag|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)                   |{{f/store|Set Auto Battle Flag as [Save fading Life]}}
 +
  001948f4: 8fbf0018 lw r31,0x0018(r29)       END
 
  001948f8: 8fb10014 lw r17,0x0014(r29)
 
  001948f8: 8fb10014 lw r17,0x0014(r29)
 
  001948fc: 8fb00010 lw r16,0x0010(r29)
 
  001948fc: 8fb00010 lw r16,0x0010(r29)
Line 125: Line 141:
 
  00194904: 03e00008 jr r31
 
  00194904: 03e00008 jr r31
 
  00194908: 00000000 nop
 
  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]]

Latest revision as of 07:30, 8 April 2024

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