See if able to move to target

From Final Fantasy Hacktics Wiki
Revision as of 18:46, 13 April 2024 by Orkney (talk | contribs)
Jump to navigation Jump to search
BATTLE.BIN :  - See if able to move to target?
Fill Table at 8019f3c4 + 0x3b4 : 1 byte per tile. For Each Tile store distance between this Tile and Acting Unit Tile
------------------------------------------------------------------------------------------
Parameter : r4 = Acting Unit AI decision pointer ( 0x8019f3c4 + 0x182c)
Return : r2 = 0x00 if data are stored in Table at 8019f3c4 + 0x3b4
         r2 = -0x01 if Find_Tiles_for_the_AI_to_move_to_(00178ca4) don't return 0x00
         
------------------------------------------------------------------------------------------
001994f8: 3c02801a lui r2,0x801a             |
001994fc: 90420d7b lbu r2,0x0d7b(r2)         |AI ACTION STATE ?  801a0d7b aka 8019f3c4 + 0x19b7
00199500: 27bdffb8 addiu r29,r29,-0x0048     |
00199504: afb1003c sw r17,0x003c(r29)        |
00199508: 00808821 addu r17,r4,r0            |Acting Unit AI decision data pointer 0x8019f3c4 + 0x182c + Acting Unit offset
0019950c: afb00038 sw r16,0x0038(r29)        |
00199510: 3c10801a lui r16,0x801a            |
00199514: 2610f3c4 addiu r16,r16,0xf3c4      |0x8019f3c4
00199518: afbf0044 sw r31,0x0044(r29)        |
0019951c: afb20040 sw r18,0x0040(r29)        |
00199520: 10400005 beq r2,r0,0x00199538      #If AI 0x19b7 <> 0x00 
00199524: afa00020 sw r0,0x0020(r29)             |
00199528: 3c01801a lui r1,0x801a                 |
0019952c: a0200036 sb r0,0x0036(r1)              |Reset 801a0036 
00199530: 08066551 j 0x00199544                  >>Avoid opposite section
00199534: 00000000 nop                           |
                                            Else : AI 0x19b7 = 0x00
00199538: 34020001 ori r2,r0,0x0001              |
0019953c: 3c01801a lui r1,0x801a                 |
00199540: a0220036 sb r2,0x0036(r1)              |Set 801a0036 = 0x1
00199544: 8e0317f8 lw r3,0x17f8(r16)         |Acting Unit Battle data pointer 801908cc
00199548: 00000000 nop                       |
0019954c: 90620182 lbu r2,0x0182(r3)         |Acting Unit Mount Info
00199550: 00000000 nop                       |
00199554: 30420080 andi r2,r2,0x0080         |
00199558: 14400008 bne r2,r0,0x0019957c      #If Acting Unit is not riding a Unit
0019955c: 00009021 addu r18,r0,r0            |initialize normal movement flag
00199560: 90620094 lbu r2,0x0094(r3)             |Acting Unit Movement 2
00199564: 00000000 nop                           |
00199568: 3042000c andi r2,r2,0x000c             |
0019956c: 10400003 beq r2,r0,0x0019957c          #If Acting Unit  is not Using teleport nor teleport 2
00199570: 00000000 nop                               |
00199574: 0806657e j 0x001995f8                      >>Avoid below : r18 = 0x1
00199578: 34120001 ori r18,r0,0x0001                 |
                                            Else : Acting Unit is riding or use telport 
0019957c: 92250000 lbu r5,0x0000(r17)            |
00199580: 92260002 lbu r6,0x0002(r17)            |
00199584: 92270001 lbu r7,0x0001(r17)            |
00199588: 27a20020 addiu r2,r29,0x0020           |
0019958c: afa20014 sw r2,0x0014(r29)             |
00199590: 92040e2e lbu r4,0x0e2e(r16)            |
00199594: 92030c72 lbu r3,0x0c72(r16)            |
00199598: 34020001 ori r2,r0,0x0001              |
0019959c: afa20018 sw r2,0x0018(r29)             |
001995a0: 0c05e329 jal 0x00178ca4                |-->Find_Tiles_for_the_AI_to_move_to_(00178ca4)
001995a4: afa30010 sw r3,0x0010(r29)             |
001995a8: 8fa20020 lw r2,0x0020(r29)             |
001995ac: 00000000 nop                           |
001995b0: 14400053 bne r2,r0,0x00199700          #if r2 <> 0x00 Exit and  Return -0x0001
001995b4: 2402ffff addiu r2,r0,0xffff            |
001995b8: a20019b7 sb r0,0x19b7(r16)             |
001995bc: 92230002 lbu r3,0x0002(r17)            |
001995c0: 92020e3a lbu r2,0x0e3a(r16)            |
001995c4: 00000000 nop                           |
001995c8: 00620018 mult r3,r2                    |
001995cc: 92230001 lbu r3,0x0001(r17)            |
001995d0: 92240000 lbu r4,0x0000(r17)            |
001995d4: 00031a00 sll r3,r3,0x08                |
001995d8: 00001012 mflo r2                       |
001995dc: 00621821 addu r3,r3,r2                 |
001995e0: 00641821 addu r3,r3,r4                 |
001995e4: 00031080 sll r2,r3,0x02                |
001995e8: 00431021 addu r2,r2,r3                 |
001995ec: 3c018019 lui r1,0x8019                 |
001995f0: 00220821 addu r1,r1,r2                 |
001995f4: 902d2dd8 lbu r13,0x2dd8(r1)            |

001995f8: 00004821 addu r9,r0,r0             |Reset elevation counter
001995fc: 02006021 addu r12,r16,r0           |Dynamic Pointer to AI 0x3b4 Table
00199600: 02005821 addu r11,r16,r0           |Dynamic Pointer to AI Reachable Tiles Table
                                            @Loop - Both elevation
00199604: 92020e3b lbu r2,0x0e3b(r16)            |Map Max Y
00199608: 00000000 nop                           |
0019960c: 18400036 blez r2,0x001996e8            #If Map Max Y is invalid : branch to  Next elevation iteration
00199610: 00002821 addu r5,r0,r0                 |reset Y counter
00199614: 00095200 sll r10,r9,0x08               |Elevation Offset for Tile data (0x100)
00199618: 258803b4 addiu r8,r12,0x03b4           |Dynamic Pointer to AI 0x3b4 Table 8019f3c4 + 0x3b4
0019961c: 25670a74 addiu r7,r11,0x0a74           |Dynamic Pointer to AI Reachable Tiles Table 8019f3c4 + 0xa74
                                                @Loop - All Y rows
00199620: 94e20000 lhu r2,0x0000(r7)                 |This Y row Halfword in Reachable Tiles table
00199624: 00000000 nop                               |
00199628: 10400029 beq r2,r0,0x001996d0              #If All Tiles flags are OFF : branch to  Next Y iteration
0019962c: 00000000 nop                               |
00199630: 92020e3a lbu r2,0x0e3a(r16)                |Map Max X
00199634: 00000000 nop                               |
00199638: 18400025 blez r2,0x001996d0                #If Map Max X is invalid : branch to  Next Y iteration
0019963c: 00002021 addu r4,r0,r0                     |reset X counter
00199640: 01003021 addu r6,r8,r0                     |Dynamic Pointer of this Y row  AI 0x3b4 Table
                                                    @Loop - All X Tiles in Y row
00199644: 1240000f beq r18,r0,0x00199684                 #If Unit is not Riding nor teleporting
00199648: 00000000 nop                                       |
0019964c: 92220000 lbu r2,0x0000(r17)                        |Acting Unit X coordinate
00199650: 00000000 nop                                       |
00199654: 00441823 subu r3,r2,r4                             |Delta X (between this tile and Acting Unit)
00199658: 04610002 bgez r3,0x00199664                        #If Delta X < 0x00
0019965c: 00000000 nop                                           |
00199660: 00031823 subu r3,r0,r3                                 |Make Delta X positive)
00199664: 92220002 lbu r2,0x0002(r17)                        |Acting Unit Y coordinates
00199668: 00000000 nop                                       |
0019966c: 00451023 subu r2,r2,r5                             |Delta Y
00199670: 04410002 bgez r2,0x0019967c                        #if Delta Y < 0x00
00199674: 00000000 nop                                           |
00199678: 00021023 subu r2,r0,r2                                 |Make delta Y positive
0019967c: 080665ae j 0x001996b8                              >>Jump to  Next X iteration
00199680: 00621821 addu r3,r3,r2                             |Distance between Acting Unit and This iteration tile (Delta X + Delta Y)
                                                        Else : Acting Unit is riding or teleporting
00199684: 92020e3a lbu r2,0x0e3a(r16)                        |Map Max X
00199688: 00000000 nop                                       |
0019968c: 00a20018 mult r5,r2                                |
00199690: 00001812 mflo r3                                   |Max X * Y
00199694: 01431821 addu r3,r10,r3                            |Max X * Y    + 0x100 if high elevation
00199698: 00641821 addu r3,r3,r4                             |Tile ID     (X  + Max X * Y    + 0x100 if high elevation)
0019969c: 00031080 sll r2,r3,0x02                            |
001996a0: 00431021 addu r2,r2,r3                             |ID * 5
001996a4: 3c018019 lui r1,0x8019                             |
001996a8: 00220821 addu r1,r1,r2                             |Part of Targetable grid  pointer  0x8019 + Tile ID  5
001996ac: 90222dd8 lbu r2,0x2dd8(r1)                         |This Tile AoE to highlight value
001996b0: 00000000 nop                                       |
001996b4: 01a21823 subu r3,r13,r2                            |Acting Unit AoE value - This Tile Value
001996b8: a0c30000 sb r3,0x0000(r6)                      |Store Distance with Acting Unit
001996bc: 92020e3a lbu r2,0x0e3a(r16)                    |Map Max X
001996c0: 24840001 addiu r4,r4,0x0001                    |X counter +1
001996c4: 0082102a slt r2,r4,r2                          |
001996c8: 1440ffde bne r2,r0,0x00199644              Λ Loop While X < Max X
001996cc: 24c60001 addiu r6,r6,0x0001                    |Dynamic Pointer of this Y row  AI 0x3b4 Table (+0x01 per X tiles)
001996d0: 25080010 addiu r8,r8,0x0010                |Dynamic Pointer to AI 0x3b4 Table (+0x10 per Y row)
001996d4: 92020e3b lbu r2,0x0e3b(r16)                |Map Max Y
001996d8: 24a50001 addiu r5,r5,0x0001                |Y counter +1
001996dc: 00a2102a slt r2,r5,r2                      |
001996e0: 1440ffcf bne r2,r0,0x00199620          Λ Loop while Y < Max Y
001996e4: 24e70002 addiu r7,r7,0x0002            |Dynamic Pointer to AI Reachable Tiles Table (+0x2 per Y row) 1 Halfword of flags per row
001996e8: 258c0120 addiu r12,r12,0x0120          |Dynamic Pointer to AI 0x3b4 Table (+0x120 per elevation)
001996ec: 25290001 addiu r9,r9,0x0001            |Elevation counter +1
001996f0: 29220002 slti r2,r9,0x0002             |
001996f4: 1440ffc3 bne r2,r0,0x00199604      Λ Loop for both elevation
001996f8: 256b0024 addiu r11,r11,0x0024          |Dynamic Pointer to AI Reachable Tiles Table (+0x24 per elevation)
001996fc: 00001021 addu r2,r0,r0             |Returns 0x00
00199700: 8fbf0044 lw r31,0x0044(r29)
00199704: 8fb20040 lw r18,0x0040(r29)
00199708: 8fb1003c lw r17,0x003c(r29)
0019970c: 8fb00038 lw r16,0x0038(r29)
00199710: 27bd0048 addiu r29,r29,0x0048
00199714: 03e00008 jr r31
00199718: 00000000 nop

Return locations

BATTLE.BIN
 00196448: Map_movement_decision/data_setting
 001972ec: Set_chosen_ability/target_for_AI_status
 00198364: 001982d8_-_001984e8
 001990d0: 0019905c_-_00199120