AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
BATTLE.BIN : AI Check Options - Stop/Don't Act/Sleep/Chicken/Charm 
------------------------------------------------------------------------------------------
Parameters : r4 = Considered Unit ID

Returns : r2 = 0x00 if all checked statuses can/should be added
             = 0x01 if one of them is not an option
Note : seems to be used to determine if the unit is/will be able to Act or not
-----------------------------------------------------------------------------------------
001998c8: 27bdffe0 addiu r29,r29,-0x0020    |
001998cc: 00041100 sll r2,r4,0x04           |Unit ID * 16 (Unit offset for AI decision data)
001998d0: afbf0018 sw r31,0x0018(r29)       |
001998d4: afb10014 sw r17,0x0014(r29)       |
001998d8: afb00010 sw r16,0x0010(r29)       |
001998dc: 3c01801a lui r1,0x801a            |
001998e0: 00220821 addu r1,r1,r2            |Start of AI data + Unit offset
001998e4: 90220bf8 lbu r2,0x0bf8(r1)        |Load AI Enemy Flag 8019f3c4 + 0x182c + 0x08 + Unit offset
001998e8: 00000000 nop                      |
001998ec: 10400029 beq r2,r0,0x00199994     #If Unit is an enemy / Else : returns 0x01
001998f0: 000410c0 sll r2,r4,0x03               |ID * 8
001998f4: 00441023 subu r2,r2,r4                |ID * 7
001998f8: 00021180 sll r2,r2,0x06               |Unit ID * 0x1c0 Unit offset in Battle data
001998fc: 3c038019 lui r3,0x8019                |
00199900: 246308cc addiu r3,r3,0x08cc           |
00199904: 00438821 addu r17,r2,r3               |r17 = Unit's Data Pointer (Battle stats)
00199908: 3c10801a lui r16,0x801a               |
0019990c: 92100213 lbu r16,0x0213(r16)          |Load ClockTicks left before acting unit next turn Set in Acting_Unit's_Data_Setup
00199910: 0c0666e6 jal 0x00199b98               |-->Calculate Clockticks Until Unit Acts Returns r2 = Ticks left before unit turns
00199914: 02202021 addu r4,r17,r0               |r4 = Unit's Data Pointer
00199918: 0202802a slt r16,r16,r2               |Check Ticks left : Acting unit Vs Considered Unit
0019991c: 16000024 bne r16,r0,0x001999b0        #If Acting unit won't get another turn before considered unit 
00199920: 34020001 ori r2,r0,0x0001             |r2 = 0x1 (Fail)
00199924: 3c04801a lui r4,0x801a                    |
00199928: 90840213 lbu r4,0x0213(r4)                |Load Clockticks Before Acting unit next turn
0019992c: 02202821 addu r5,r17,r0                   |r5 = Unit's Data Pointer
00199930: 0c067bc9 jal 0x0019ef24                   |-->Check if Status Should/Can be Added Returns r2 = 0x00 if worth to be added
00199934: 3406001e ori r6,r0,0x001e                 |r6 = 0x1e (Stop)
00199938: 1440001d bne r2,r0,0x001999b0             #If Stop is an option
0019993c: 34020001 ori r2,r0,0x0001                 |r2 = 0x1 (Fail)
00199940: 3c04801a lui r4,0x801a                        |
00199944: 90840213 lbu r4,0x0213(r4)                    |Load Clockticks Before Acting unit next turn
00199948: 02202821 addu r5,r17,r0                       |r5 = Unit's Data Pointer
0019994c: 0c067bc9 jal 0x0019ef24                       |-->Check if Status Should/Can be Added Returns r2 = 0x00 if worth to be added
00199950: 34060025 ori r6,r0,0x0025                     |r6 = 0x25 (Don't Act)
00199954: 14400016 bne r2,r0,0x001999b0                 #If Don't Act is an option
00199958: 34020001 ori r2,r0,0x0001                     |r2 = 0x1 (Fail)
0019995c: 3c04801a lui r4,0x801a                            |
00199960: 90840213 lbu r4,0x0213(r4)                        |Load Clockticks Required
00199964: 02202821 addu r5,r17,r0                           |r5 = Unit's Data Pointer
00199968: 0c067bc9 jal 0x0019ef24                           |-->Check if Status Should/Can be Added Returns r2 = 0x00 if worth to be added
0019996c: 34060023 ori r6,r0,0x0023                         |r6 = 0x23 (Sleep)
00199970: 1440000f bne r2,r0,0x001999b0                     #If Sleep is an option
00199974: 34020001 ori r2,r0,0x0001                         |r2 = 0x1 (Fail)
00199978: 3c04801a lui r4,0x801a                                |
0019997c: 90840213 lbu r4,0x0213(r4)                            |Load Clockticks Required
00199980: 02202821 addu r5,r17,r0                               |r5 = Unit's Data Pointer
00199984: 0c067bc9 jal 0x0019ef24                               |-->Check if Status Should/Can be Added Returns r2 = 0x00 if worth to be added
00199988: 34060015 ori r6,r0,0x0015                             |r6 = 0x15 (Chicken)
0019998c: 10400003 beq r2,r0,0x0019999c                         #Branch if Chicken isn't an option
00199990: 02202821 addu r5,r17,r0                               |r5 = Unit's Data Pointer
00199994: 0806666c j 0x001999b0                                     >>Jump to END and  returns r2 = 0x01
00199998: 34020001 ori r2,r0,0x0001             #E  #E  #E  #E      |r2 = 0x1 (Fail)

-- Every status checked above can/should be added --
0019999c: 3c04801a lui r4,0x801a            |
001999a0: 90840213 lbu r4,0x0213(r4)        |Load Clockticks Required
001999a4: 0c067bc9 jal 0x0019ef24           |-->Check if Status Should/Can be Added Returns r2 = 0x00 if worth to be added
001999a8: 34060022 ori r6,r0,0x0022         |r6 = 0x22 (Charm)
001999ac: 0002102b sltu r2,r0,r2            |Keep r2 unchanged (…)
001999b0: 8fbf0018 lw r31,0x0018(r29)       END
001999b4: 8fb10014 lw r17,0x0014(r29)
001999b8: 8fb00010 lw r16,0x0010(r29)
001999bc: 27bd0020 addiu r29,r29,0x0020
001999c0: 03e00008 jr r31
001999c4: 00000000 nop

Return Locations

BATTLE.BIN
00199258: Calculate_Physical?_Target
00199764: Check_for_good_units_to_target_(based_on_distance,status,coordinate)