AI Initial Targeting Selection

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
BATTLE.BIN :  - AI_Initial_Targeting_Selection
Initialize Action Tables (used for priority scoring) - Choose AI behavior (might be non native based on Status) - Set AI 0x17fc (selected action)
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : r2 = 0x00 Routine ends as intended
         r2 = -0x01 Routine Aborts on V_Sync alert (memory variable is updated)
------------------------------------------------------------------------------------------
00195d94: 3c02801a lui r2,0x801a             |
00195d98: 90420d7b lbu r2,0x0d7b(r2)         |AI 0x19b7
00195d9c: 27bdffe0 addiu r29,r29,-0x0020     |
00195da0: afb20018 sw r18,0x0018(r29)        |
00195da4: 3c12801a lui r18,0x801a            |
00195da8: 2652f3c4 addiu r18,r18,-0x0c3c     |0x8019f3c4
00195dac: afbf001c sw r31,0x001c(r29)        |
00195db0: afb10014 sw r17,0x0014(r29)        |

=== Return to where the code left off ===
00195db4: 10400011 beq r2,r0,0x00195dfc      #If [0x19b7] <> 0x00 : 
00195db8: afb00010 sw r16,0x0010(r29)            |
00195dbc: 3c03801a lui r3,0x801a                 |
00195dc0: 90630031 lbu r3,0x0031(r3)             |AI 0xc6d (this routine memory variable) 0x801a0031
00195dc4: 34020002 ori r2,r0,0x0002              |
00195dc8: 10620044 beq r3,r2,0x00195edc          #If [0x0c6d] = 0x02 Return to non native AI run like a rabbit section
00195dcc: 28620003 slti r2,r3,0x0003             |
00195dd0: 10400005 beq r2,r0,0x00195de8          #If AI 0xc6d < 0x02
00195dd4: 00000000 nop                               |
00195dd8: 1060001a beq r3,r0,0x00195e44              #If AI 0xc6d = 0x00 Return to checking status affecting behavior
00195ddc: 00000000 nop                               |
00195de0: 080657cc j 0x00195f30                      >>Else AI 0xc6d = 0x01 Return to Non specific behavior routine (should not happen)
00195de4: 00000000 nop                               |
                                                 Else : 0xc6d > 0x02
00195de8: 34020003 ori r2,r0,0x0003                  |
00195dec: 10620047 beq r3,r2,0x00195f0c              #If [0x0c6d] = 0x03 Return to Native Auto-Battle routine
00195df0: 00000000 nop                               |
00195df4: 080657cc j 0x00195f30                      >>Else >0x03 (0x07) Return to Non specific behavior routine
00195df8: 00000000 nop                               |

=== Start from beginning ===
00195dfc: 00008021 addu r16,r0,r0            |Initialize loop counter
00195e00: 34110054 ori r17,r0,0x0054         |

                  --- Initialize Action Data ---
                                            @LOOP  8 times - initialize Action from 0x54 to 0x134 (used to preserve best action)
00195e04: 0c0657db jal 0x00195f6c                |-->Initialize some AI Data (mount, base hit %) Initialize Action data
00195e08: 02512021 addu r4,r18,r17               |Dynamic pointer to Action data 8019f3c4 + 0x0054 + 0x20 each iteration
00195e0c: 26100001 addiu r16,r16,0x0001          |counter + 1
00195e10: 2a020008 slti r2,r16,0x0008            |
00195e14: 1440fffb bne r2,r0,0x00195e04      Λ Loop 8 times
00195e18: 26310020 addiu r17,r17,0x0020          |Offset for Dynamic pointer + 0x20 each iteration
00195e1c: 0c0657db jal 0x00195f6c            |-->Initialize some AI Data (mount, base hit %) initialize Action Table at 0x14 (temporary data while testing action)
00195e20: 26440014 addiu r4,r18,0x0014       |
00195e24: 0c0657db jal 0x00195f6c            |-->Initialize some AI Data (mount, base hit %) initialize Action Table at 0x34 (temporary data)
00195e28: 26440034 addiu r4,r18,0x0034       |
00195e2c: 0c0657db jal 0x00195f6c            |-->Initialize some AI Data (mount, base hit %) initialize Action Table at 0x154 (score for moving only)
00195e30: 26440154 addiu r4,r18,0x0154       |AI data + 0x154?
00195e34: 0c0657db jal 0x00195f6c            |-->Initialize some AI Data (mount, base hit %) Initialize Selected Action data
00195e38: 264417fc addiu r4,r18,0x17fc       |AI data + 0x17fc?
00195e3c: 0c0665c7 jal 0x0019971c            |-->Check for good units to target (based on distance,status,coordinate) Fill AI 0xc8d (List of targtable unit) and AI 0x174 (proximity score)
00195e40: 00000000 nop                       |

                  --- Check and run non Native behavior (status - critical) ---
00195e44: 0c065c6e jal 0x001971b8            |-->Set chosen ability/target for AI status  Check if Acting Unit has some changing behavior status
00195e48: 00000000 nop                       |
00195e4c: 00408021 addu r16,r2,r0            |Preserve returned Value
00195e50: 2402ffff addiu r2,r0,-0x0001       |
00195e54: 16020003 bne r16,r2,0x00195e64     #If returned Value is -0x0001 V_Sync alert (time to refresh animations) ?
00195e58: 00000000 nop                           |
00195e5c: 080657d4 j 0x00195f50                  |Set Memory variable = 0x00 then Exit Return -0x01 AI 0xc6d
00195e60: a2400c6d sb r0,0x0c6d(r18)             |
                                             '
00195e64: 1600003a bne r16,r0,0x00195f50     #If Acting Unit is  under status influence : Exit Return 0x00  Special status behavior is done
00195e68: 00001021 addu r2,r0,r0             |
00195e6c: 8e4417f8 lw r4,0x17f8(r18)         |Acting unit battle data pointer
00195e70: 00000000 nop                       |
00195e74: 9082005a lbu r2,0x005a(r4)         |Acting Unit current Status 3
00195e78: 00000000 nop                       |
00195e7c: 30420003 andi r2,r2,0x0003         |
00195e80: 10400006 beq r2,r0,0x00195e9c      #If Acting unit has [Frog] or [Critical]
00195e84: 3c034000 lui r3,0x4000                 |
00195e88: 8e420cb4 lw r2,0x0cb4(r18)             |Load AI 0xcb4  Labeled as AI processing order
00195e8c: 00000000 nop                           |
00195e90: 00431024 and r2,r2,r3                  |
00195e94: 1440000d bne r2,r0,0x00195ecc          #If Caster is not the last standing Unit in his team go to Run Away section If last man standing, die quickly please
00195e98: 00000000 nop                           |
00195e9c: 9082005c lbu r2,0x005c(r4)         |Acting Unit Current  Status 5
00195ea0: 00000000 nop                       |
00195ea4: 30420004 andi r2,r2,0x0004         |
00195ea8: 10400018 beq r2,r0,0x00195f0c      #If Acting unit do not have  [Don't Act] : branch to  Native Behavior
00195eac: 00000000 nop                       |
                                             Else : Caster has don't Act
00195eb0: 8e420e34 lw r2,0x0e34(r18)         |Pointer to Acting Unit Decision (8019f3c4 + 0x182c)
00195eb4: 00000000 nop                           |
00195eb8: 90420004 lbu r2,0x0004(r2)             |Decision Byte 0x04
00195ebc: 00000000 nop                           |
00195ec0: 30420040 andi r2,r2,0x0040             |
00195ec4: 10400011 beq r2,r0,0x00195f0c          #If Unit do not have [Focus Unit] flag Avoid Non Native Run Away section
00195ec8: 00000000 nop                           |

                                            --- Non Native Run Away  ( Frog , critical or Don't Act with [Focus Unit] setting )---
00195ecc: 2644197c addiu r4,r18,0x197c       |Pointer to AI 0x197c
00195ed0: 8e450e34 lw r5,0x0e34(r18)         |Pointer to Acting Unit Decision (8019f3c4 + 0x182c)
00195ed4: 0c066ac2 jal 0x0019ab08            |-->Transfer Halfword Values Transfer 0x10 byte from Caster 0x182c to AI 0x197c (preserve behavior data ?)
00195ed8: 34060010 ori r6,r0,0x0010          |
00195edc: 0c066398 jal 0x00198e60            |-->AI_Critical_or_Run_Like_Rabbit
00195ee0: 00000000 nop                       |
00195ee4: 2403ffff addiu r3,r0,-0x0001       |
00195ee8: 14430003 bne r2,r3,0x00195ef8      #If Returned Value = -0x01  (Abort on V_Sync alert)
00195eec: 2645197c addiu r5,r18,0x197c       |Pointer to AI 0x197c
00195ef0: 080657d2 j 0x00195f48                  |Set Memory Variable to 0x02 then exit Returns -0x01 AI 0xc6d
00195ef4: 34020002 ori r2,r0,0x0002              |
00195ef8: 8e440e34 lw r4,0x0e34(r18)         |Pointer to Acting Unit Decision (8019f3c4 + 0x182c)
00195efc: 0c066ac2 jal 0x0019ab08            |-->Transfer Halfword Values Restore Caster AI 0x182c 
00195f00: 34060010 ori r6,r0,0x0010          |
00195f04: 080657d4 j 0x00195f50              |Exit Returns 0x00 Behavior done
00195f08: 00001021 addu r2,r0,r0             |

                  --- Check and do Native AI Behavior ---
00195f0c: 0c065fc5 jal 0x00197f14            |-->Auto_Battle_Handling Handles special behavior
00195f10: 00000000 nop                       |
00195f14: 00408021 addu r16,r2,r0            |Preserves returned value
00195f18: 2402ffff addiu r2,r0,-0x0001       |
00195f1c: 1202000a beq r16,r2,0x00195f48     #If Returned Value = -0x01 :  Set Memory Variable (AI 0xc6d) to 0x03 then exit Returns -0x0001
00195f20: 34020003 ori r2,r0,0x0003          |
00195f24: 1600000a bne r16,r0,0x00195f50     #If Returned Value <> 0x00 Exit Returns 0x00 Auto Battle is done
00195f28: 00001021 addu r2,r0,r0             |

                                            Else  : proceed to non specific auto-battle (returned value = 0x00)
00195f2c: a24019b7 sb r0,0x19b7(r18)         |Reset AI 0x19b7
00195f30: 0c065867 jal 0x0019619c            |-->Non-Specific_AI_AutoBattle_(Enemies) Return selected action in AI 0x17fc
00195f34: 00000000 nop                       |
00195f38: 2403ffff addiu r3,r0,-0x0001       |
00195f3c: 14430004 bne r2,r3,0x00195f50      #If Returned Value <> -0x0001 Exit Returns 0x00
00195f40: 00001021 addu r2,r0,r0             |
00195f44: 34020007 ori r2,r0,0x0007          |Else : r2 = -0x0001 Store 0x07 in AI 0x0c6d and Returns -0x0001

=== Update memory variable and abort section ===
00195f48: a2420c6d sb r2,0x0c6d(r18)         |Update Memory variable (Ai 0xc6d)
00195f4c: 2402ffff addiu r2,r0,-0x0001       |Returns -0x01

00195f50: 8fbf001c lw r31,0x001c(r29)
00195f54: 8fb20018 lw r18,0x0018(r29)
00195f58: 8fb10014 lw r17,0x0014(r29)
00195f5c: 8fb00010 lw r16,0x0010(r29)
00195f60: 27bd0020 addiu r29,r29,0x0020
00195f64: 03e00008 jr r31
00195f68: 00000000 nop

Return locations

BATTLE.BIN
 00194070: Main_AI_action_setup