Check AI Target Type (00196adc)

From Final Fantasy Hacktics Wiki
(Redirected from 00196adc - 00196c88)
Jump to navigation Jump to search
BATTLE.BIN :  - Check_AI_Target_Type_(00196adc)
Reset and refill AI Table at 0x8019f3c4 + 0a74 + 0xe2d offset if Tiles are reachable and match preset value condition)
------------------------------------------------------------------------------------------
Parameter : r4
Return : r2 = 0x1 if at least one tile meet the conditions
         r2 = x00 if no tiles found
------------------------------------------------------------------------------------------
00196adc: 27bdffd0 addiu r29,r29,-0x0030     |
00196ae0: afb10024 sw r17,0x0024(r29)        |
00196ae4: 00808821 addu r17,r4,r0            |r17 = Ability/Move Range
00196ae8: afb00020 sw r16,0x0020(r29)        |
00196aec: 00008021 addu r16,r0,r0            |
00196af0: 3c05801a lui r5,0x801a             |
00196af4: 24a5f3c4 addiu r5,r5,-0x0c3c       |0x8019f3c4
00196af8: 00003021 addu r6,r0,r0             |reset Y row counter
00196afc: afbf0028 sw r31,0x0028(r29)        |
                                            @Loop - Initialize Tile's Data at AI Table  (AI 0xa74 + 0xe2d offset)
00196b00: 90a30e2d lbu r3,0x0e2d(r5)             |Load AI 0xe2d Offset for some Tile's Table
00196b04: 00062040 sll r4,r6,0x01                |This iteration Y * 2
00196b08: 000310c0 sll r2,r3,0x03                |
00196b0c: 00431021 addu r2,r2,r3                 |
00196b10: 000210c0 sll r2,r2,0x03                |0xe2d * 0x48
00196b14: 00a21021 addu r2,r5,r2                 |
00196b18: 00821021 addu r2,r4,r2                 |Dynamic pointer to this Y row in Table 0xa74 (matching 0xe2d) Low elevation
00196b1c: a4400a74 sh r0,0x0a74(r2)              |
00196b20: 90a30e2d lbu r3,0x0e2d(r5)             |Load AI 0xe2d
00196b24: 24c60001 addiu r6,r6,0x0001            |Y counter + 1
00196b28: 000310c0 sll r2,r3,0x03                |
00196b2c: 00431021 addu r2,r2,r3                 |
00196b30: 000210c0 sll r2,r2,0x03                |0xe2d * 0x48
00196b34: 00a21021 addu r2,r5,r2                 |
00196b38: 00822021 addu r4,r4,r2                 |
00196b3c: 28c20012 slti r2,r6,0x0012             |
00196b40: 1440ffef bne r2,r0,0x00196b00      Λ Do 18 (0x12) times
00196b44: a4800a98 sh r0,0x0a98(r4)              |Dynamic pointer to this Y row in Table 0xa74 (matching 0xe2d) High elevation elevation

00196b48: 0000c821 addu r25,r0,r0            |Reset elevation counter
00196b4c: 00a0c021 addu r24,r5,r0            |0x8019f3c4
00196b50: 00a07821 addu r15,r5,r0            |0x8019f3c4
00196b54: 00007021 addu r14,r0,r0            |Initial elevation offset
                                            @LOOP  - Both elevation
00196b58: 90a20e3b lbu r2,0x0e3b(r5)             |Map max Y
00196b5c: 00000000 nop                           |
00196b60: 18400032 blez r2,0x00196c2c            #If Max Y is invalid : branch to  Next Elevation iteration
00196b64: 00004021 addu r8,r0,r0                 |Reset Y counter
00196b68: 01c06821 addu r13,r14,r0               |Elevation offset (0x24)
00196b6c: 00004821 addu r9,r0,r0                 |
00196b70: 270b03b4 addiu r11,r24,0x03b4          |Dynamic pointer to 0x8019f3c4 + 0x3b4   (+ elevation offset)
00196b74: 25ea0a74 addiu r10,r15,0x0a74          |Dynamic pointer to 0x8019f3c4 + 0xa074 + elevation offset  (offset 0x00 - not based on 0xe2d)
                                                @LOOP - All Y Rows
00196b78: 95430000 lhu r3,0x0000(r10)                |This Y Row halfword of flags  (offset 0x00 - not based on 0xe2d)
00196b7c: 00000000 nop                               |
00196b80: 10600023 beq r3,r0,0x00196c10              #If All Flags are OFF : branch to  Next Y
00196b84: 00000000 nop                                   |
00196b88: 90a20e3a lbu r2,0x0e3a(r5)                 |Map Max X
00196b8c: 00000000 nop                               |
00196b90: 1840001f blez r2,0x00196c10                #If Max X is invalid : branch to  Next Y
00196b94: 00003021 addu r6,r0,r0                     |Reset X counter
00196b98: 00606021 addu r12,r3,r0                    |Pass Y row's flags
00196b9c: 01603821 addu r7,r11,r0                    |Dynamic pointer to 0x8019f3c4 + 0x3b4   (+ elevation offset + Y offset) Will Take X offset at each X iteration

                                                    @LOOP - All X tiles in Y Rows
00196ba0: 00cc1004 sllv r2,r12,r6                        |This Tile bit is in 0x8000 position
00196ba4: 30428000 andi r2,r2,0x8000                     |
00196ba8: 10400014 beq r2,r0,0x00196bfc                  #if this Tile is not reachable : branch to  Next X
00196bac: 00000000 nop                                   |
00196bb0: 90e20000 lbu r2,0x0000(r7)                     |This Tile distance to Acting unit's Target
00196bb4: 00000000 nop                                   |
00196bb8: 0222102a slt r2,r17,r2                         |0x1 if Preset Value < this Tile distance to Target
00196bbc: 1440000f bne r2,r0,0x00196bfc                  #if Target is above Preset Value : branch to  Next X
00196bc0: 00000000 nop                                   |
00196bc4: 90a30e2d lbu r3,0x0e2d(r5)                     |Load 0xe2d
00196bc8: 34100001 ori r16,r0,0x0001                     |1 Tile in range Flag
00196bcc: 000310c0 sll r2,r3,0x03                        |
00196bd0: 00431021 addu r2,r2,r3                         |
00196bd4: 000210c0 sll r2,r2,0x03                        |0xe2d Offset (0x48)
00196bd8: 00451021 addu r2,r2,r5                         |
00196bdc: 24420a74 addiu r2,r2,0x0a74                    |0x8019f3c4 + 0xa74 + 0xe2d offset
00196be0: 01a21021 addu r2,r13,r2                        |+Elevation offset
00196be4: 01221021 addu r2,r9,r2                         |+Y offset
00196be8: 34038000 ori r3,r0,0x8000                      |Prepare Bitmask
00196bec: 94440000 lhu r4,0x0000(r2)                     |Load this Tile's Y row's flags
00196bf0: 00c31807 srav r3,r3,r6                         |This Tile Bitmask
00196bf4: 00832025 or r4,r4,r3                           |
00196bf8: a4440000 sh r4,0x0000(r2)                      |Enable this Tile flag
00196bfc: 90a20e3a lbu r2,0x0e3a(r5)                     |Map Max X
00196c00: 24c60001 addiu r6,r6,0x0001                    |X counter + 1
00196c04: 00c2102a slt r2,r6,r2                          |
00196c08: 1440ffe5 bne r2,r0,0x00196ba0              Λ Loop while X < max X
00196c0c: 24e70001 addiu r7,r7,0x0001                    |Dynamic pointer to 0x8019f3c4 + 0x3b4  (+0x01 each X iteration)
00196c10: 25290002 addiu r9,r9,0x0002                |Dynamic pointer to 0x8019f3c4 + 0xa074 + 0x2ed offset (+0x2 each Y iteration)
00196c14: 256b0010 addiu r11,r11,0x0010              |Dynamic pointer to 0x8019f3c4 + 0x3b4   (+0x10 each Y iteration) 0x10 each iteration
00196c18: 90a20e3b lbu r2,0x0e3b(r5)                 |Map Max Y
00196c1c: 25080001 addiu r8,r8,0x0001                |Y counter +1
00196c20: 0102102a slt r2,r8,r2                      |
00196c24: 1440ffd4 bne r2,r0,0x00196b78          Λ Loop while Y counter < Max Y
00196c28: 254a0002 addiu r10,r10,0x0002              |Dynamic pointer to 0x8019f3c4 + 0xa074  (+0x2 each Y iteration) Table at offset 0x00
00196c2c: 27180120 addiu r24,r24,0x0120          |Elevation offset for Table 0x3b4
00196c30: 25ef0024 addiu r15,r15,0x0024          |Elevation offset for Table 0xa74
00196c34: 27390001 addiu r25,r25,0x0001          |Elevation counter +1
00196c38: 2b220002 slti r2,r25,0x0002            |
00196c3c: 1440ffc6 bne r2,r0,0x00196b58      Λ Loop 2 times
00196c40: 25ce0024 addiu r14,r14,0x0024          |Elevation offset

00196c44: 1600000b bne r16,r0,0x00196c74     #If At least One Tile Matches the Preset conditions Exit  Returns 0x01
00196c48: 34020001 ori r2,r0,0x0001              |
                                            Else : No Tiles Found
00196c4c: 90a20e2d lbu r2,0x0e2d(r5)             |Laod 0xe2d
00196c50: 34060048 ori r6,r0,0x0048              |Send Size of data
00196c54: 000220c0 sll r4,r2,0x03                |
00196c58: 00822021 addu r4,r4,r2                 |
00196c5c: 000420c0 sll r4,r4,0x03                |0xe2d Offset (0x48)
00196c60: 24840a74 addiu r4,r4,0x0a74            |
00196c64: 00a42021 addu r4,r5,r4                 |0x8019f3c4 + 0xa74 + 0x2ed offset
00196c68: 0c066ac2 jal 0x0019ab08                |-->Transfer Halfword Values Transfer data from r5 to r4
00196c6c: 24a50a74 addiu r5,r5,0x0a74            |0x8019f3c4 + 0xa74
00196c70: 00001021 addu r2,r0,r0                 |Return 0x00
00196c74: 8fbf0028 lw r31,0x0028(r29)
00196c78: 8fb10024 lw r17,0x0024(r29)
00196c7c: 8fb00020 lw r16,0x0020(r29)
00196c80: 27bd0030 addiu r29,r29,0x0030
00196c84: 03e00008 jr r31
00196c88: 00000000 nop

Return locations

BATTLE.BIN
 00196680: Map_movement_decision/data_setting   Condition Value = Target distance -1 (one case)
 00198420: 001982d8_-_001984e8