Some type of checking algorithm

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
BATTLE.BIN :  - Some_type_of_checking_algorithm
Unflag Ability from being Usable if it only adds an undesired status. This routine is to prevent the AI from using unnecessary status adding abilities if they are not needed, such as Shell vs a team that has no Magic damage whatsoever. 
------------------------------------------------------------------------------------------
Parameter : r4 = Ability pointer  (Unit usable AbilityList  8019f3c4 - 0x0ef0 Table )
            r5 = Undesired status
------------------------------------------------------------------------------------------
001957c0: 3c02801a lui r2,0x801a             |
001957c4: 8c42f3d0 lw r2,-0x0c30(r2)         |Load Ability AI flags 1,2,3 et 4  8019f3c4 + 0x0c
001957c8: 00000000 nop                       |
001957cc: 30420010 andi r2,r2,0x0010         |
001957d0: 10400027 beq r2,r0,0x00195870      #If this ability do not have [inflict status] flag :  Exit routine
001957d4: 00000000 nop                       |
001957d8: 3c02801a lui r2,0x801a             |
001957dc: 9042f3d0 lbu r2,-0x0c30(r2)        | Ability AI flags 1
001957e0: 00000000 nop                       |
001957e4: 304200ee andi r2,r2,0x00ee         |Everything but Target Ally and add Status
001957e8: 14400021 bne r2,r0,0x00195870      #If This ability do anything more than  [Add Status] and [Target Ally] Exit routine
001957ec: 00000000 nop                       |
001957f0: 00003821 addu r7,r0,r0             |Initialize status set counter
001957f4: 34090080 ori r9,r0,0x0080          |Base bitmask for status
001957f8: 3c06801a lui r6,0x801a             |
001957fc: 24c6f3c4 addiu r6,r6,-0x0c3c       |8019f3c4
00195800: 00a04021 addu r8,r5,r0             |r8 = Status of interest (will decrase by 8 each iteration)
                                            @LOOP
00195804: 00a01021 addu r2,r5,r0                 |Status ID
00195808: 04410002 bgez r2,0x00195814            #If Passed Status is invalid (< 0)
0019580c: 00000000 nop                               |
00195810: 24420007 addiu r2,r2,0x0007                |Force value to 7
00195814: 000210c3 sra r2,r2,0x03                |Passed status set Status ID / 8
00195818: 14e20008 bne r7,r2,0x0019583c          #If this is the set of desired status
0019581c: 01091007 srav r2,r9,r8                     |Bitmask for status of interest
00195820: 90c30007 lbu r3,0x0007(r6)                 |Ability inflicted status set Dynamic AI 0x07 to 0x0b
00195824: 384200ff xori r2,r2,0x00ff                 |Everything but desired status
00195828: 00621824 and r3,r3,r2                      |
0019582c: 14600010 bne r3,r0,0x00195870              #If this ability is inflicting any others status than status of interest Exit routine
00195830: 00000000 nop                                   |
00195834: 08065614 j 0x00195850                      >>Jump to next iteration (check other sets)
00195838: 24c60001 addiu r6,r6,0x0001                    |
                                                Else Not Status set of interest
0019583c: 90c20007 lbu r2,0x0007(r6)                 |Ability inflicted status set Dynamic AI 0x07 to 0x0b
00195840: 00000000 nop                               |
00195844: 1440000a bne r2,r0,0x00195870              #If this ability is inflicting any others status than status of interest Exit routine
00195848: 00000000 nop                                   |
0019584c: 24c60001 addiu r6,r6,0x0001            |Offset for 8019f3c4 status infliction set
00195850: 24e70001 addiu r7,r7,0x0001            |Status set counter +1
00195854: 28e20005 slti r2,r7,0x0005             |
00195858: 1440ffea bne r2,r0,0x00195804      #Loop 5 times (each status set)
0019585c: 2508fff8 addiu r8,r8,0xfff8            |Passed status ID - 8 Will be less than 8 when the loop reached the right set
00195860: 94820002 lhu r2,0x0002(r4)         |Load Ability Address
00195864: 00000000 nop                       |
00195868: 30427fff andi r2,r2,0x7fff         |
0019586c: a4820002 sh r2,0x0002(r4)          |Set Ability as unusable (if you reach the end of loop only)
00195870: 03e00008 jr r31
00195874: 00000000 nop

Return locations

BATTLE.BIN
 001954f0: Set_AI_ability_considerations_for_all_units_and_self   0x1b (Shell)
 0019550c: Set_AI_ability_considerations_for_all_units_and_self   0x1a (Protect)
 00195528: Set_AI_ability_considerations_for_all_units_and_self   0x26 (Reflect)
 00195540: Set_AI_ability_considerations_for_all_units_and_self   0x11 (Float)