Difference between revisions of "AI movement/panel data setting"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m
m
 
Line 5: Line 5:
 
  Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move
 
  Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move
 
           r2 = 0x00 if Unit Can move but has berserk or confuse
 
           r2 = 0x00 if Unit Can move but has berserk or confuse
 +
          r2 = 0x00 At the end of the routine
 
           r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?)
 
           r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?)
 
    
 
    

Latest revision as of 20:00, 5 April 2024

BATTLE.BIN - AI movement/panel data setting
------------------------------------------------------------------------------------------------
Parameters : r4 = Acting Unit Battle 0x187 (movement taken flag)

Returns : r2 = 0x00 if 0x19b7 = 0x00 and Unit has moved / can't move
          r2 = 0x00 if Unit Can move but has berserk or confuse
          r2 = 0x00 At the end of the routine
          r2 = -0x01 if 0001dba8 returns r2 > 0x1b8 (?)
 
This routine handles some Tables of Tiles flags.
If 0x19b7 = 0x00 : initialize pathfing and set flag in Table 0x0C24 (walkable tiles)
                   Enable Flag 0x20 on Tile's Byte 0x05 (in data at 8018f8cc)
If Unit can Move or 0x19b7 != 0x00 
   Set Flags in Table 0x0a74 (for unit not using teleport)
-------------------------------------------------------------------------------------------------
00194944: 3c02801a lui r2,0x801a            |
00194948: 90420d7b lbu r2,0x0d7b(r2)        |Load [801a0d7b] aka 8019f3c4 + 0x19b7
0019494c: 27bdffc0 addiu r29,r29,-0x0040    |
00194950: afb10034 sw r17,0x0034(r29)       |
00194954: 00808821 addu r17,r4,r0           |r17 = Acting Unit movement taken flag
00194958: afb00030 sw r16,0x0030(r29)       |
0019495c: 3c10801a lui r16,0x801a           |
00194960: 2610f3c4 addiu r16,r16,-0x0c3c    |AI data pointer ( 8019f3c4 )
00194964: 14400080 bne r2,r0,0x00194b68     #If [0x19b7] = 0x00
00194968: afbf0038 sw r31,0x0038(r29)           |
0019496c: 3c03801a lui r3,0x801a                |
00194970: 8c630bbc lw r3,0x0bbc(r3)             |Load Acting Unit's Data pointer
00194974: 00000000 nop                          |
00194978: 90620095 lbu r2,0x0095(r3)            |Load Movement set 3
0019497c: 00000000 nop                          |
00194980: 304200c8 andi r2,r2,0x00c8            |Check [Move on Water] [Move in Water] and [Float]
00194984: 14400006 bne r2,r0,0x001949a0         #If Acting unit do not use [Float], [Move on water] nor [Move in water]
00194988: 26040c24 addiu r4,r16,0x0c24          |AI pointer to 8019f3c4 + 0xc24
0019498c: 9062005a lbu r2,0x005a(r3)                |Load Acting unit Current status set 3
00194990: 00000000 nop                              |
00194994: 30420040 andi r2,r2,0x0040                |check [Float]
00194998: 10400005 beq r2,r0,0x001949b0             #If Unit has float
0019499c: 34020001 ori r2,r0,0x0001                     |
001949a0: 3c01801a lui r1,0x801a                #E      | 
001949a4: a0200d7d sb r0,0x0d7d(r1)                     |Water Penalty = False (Move on water, move in water or Float)
001949a8: 0806526f j 0x001949bc                         >>Avoid water penalty section
001949ac: 00000000 nop                                  |
                                                Else : No float status nor any Move allowing water move
001949b0: 3c01801a lui r1,0x801a                    |
001949b4: a0220d7d sb r2,0x0d7d(r1)                 |Water Penalty = True  aka 8019f3c4 + 0x19b9
001949b8: 26040c24 addiu r4,r16,0x0c24              |AI pointer to 8019f3c4 + 0xc24
001949bc: 0c066ade jal 0x0019ab78               |-->Word_Nulling Nullify Walkable Tile flags
001949c0: 34050048 ori r5,r0,0x0048             |size of data to nullify
001949c4: 00005021 addu r10,r0,r0               |Initialize elevation counter
001949c8: 3c0c8019 lui r12,0x8019               |
001949cc: 258cf8cc addiu r12,r12,0xf8cc         |Tile Data pointer
001949d0: 340b003f ori r11,r0,0x003f            |r11 = Cross Section Tile
001949d4: 02004021 addu r8,r16,r0               |AI data pointer ( 8019f3c4 )
                                                LOOP - Elevation (Loop through all tiles to set walkable tile's flag)
001949d8: 92020e3b lbu r2,0x0e3b(r16)               |Load Map Max Y
001949dc: 00000000 nop                              |
001949e0: 18400027 blez r2,0x00194a80               #If Max Y is invalid : branch to  Next elevation iteration
001949e4: 00003821 addu r7,r0,r0                    |Initialize Y counter
001949e8: 000a4a00 sll r9,r10,0x08                  |Elevation Offset in tiles data
                                                    LOOP through each Y rows
001949ec: 92040e3a lbu r4,0x0e3a(r16)                   |Load Map Max X
001949f0: 00000000 nop                                  |
001949f4: 1080001d beq r4,r0,0x00194a6c                 #If Max X is invalid : branch to  next Y row iteration
001949f8: 00003021 addu r6,r0,r0                        |Initialize X counter
001949fc: 25030c24 addiu r3,r8,0x0c24                   |Pointer to AI 0xc24 +0x24 if high elevation
00194a00: 00071040 sll r2,r7,0x01                       |Y counter * 2 (an Halfword of flags for each Y row)
00194a04: 00432821 addu r5,r2,r3                        |Pointer to AI 0xc24 + Row offset  + 0x2 each Y iteration
00194a08: 00e40018 mult r7,r4                           |
                                                        LOOP through each tiles of the row
00194a0c: 00001012 mflo r2                                  |Y counter * Max X
00194a10: 01221021 addu r2,r9,r2                            |
00194a14: 00461021 addu r2,r2,r6                            |This iteration Tile's ID (X + Y*Max X) + 0x100 if upper elevation
00194a18: 000210c0 sll r2,r2,0x03                           |Tiles offset in Tiles Table
00194a1c: 004c2021 addu r4,r2,r12                           |This iteration Tile's data pointer
00194a20: 90820006 lbu r2,0x0006(r4)                        |Load Tile's Byte 0x06
00194a24: 00000000 nop                                      |
00194a28: 30420001 andi r2,r2,0x0001                        |check [Unselectable by cursor]
00194a2c: 1440000a bne r2,r0,0x00194a58                     #If Tile is selectable / Else branch to Next Tile
00194a30: 00000000 nop                                          |
00194a34: 90820000 lbu r2,0x0000(r4)                            |Load Current Tile Terrain type
00194a38: 00000000 nop                                          |
00194a3c: 3042003f andi r2,r2,0x003f                            |Check [Cross Tile]
00194a40: 104b0005 beq r2,r11,0x00194a58                        #If Tile is not a Cross Tile (unplayable wall)
00194a44: 34028000 ori r2,r0,0x8000                                 |Prepare Tile's bitmask
00194a48: 94a30000 lhu r3,0x0000(r5)                                |Load Y row halfword of flags
00194a4c: 00c21007 srav r2,r2,r6                                    |r2 = Bitmask of this tile in the row
00194a50: 00621825 or r3,r3,r2                                      |Enable Tile's Flag (as playable ?) Not untargetable nor Cross section
00194a54: a4a30000 sh r3,0x0000(r5)                                 |Store updated Tile is Walkable flags (Y row)
00194a58: 92040e3a lbu r4,0x0e3a(r16)                       |Max X
00194a5c: 24c60001 addiu r6,r6,0x0001                       |X counter +1
00194a60: 00c4102a slt r2,r6,r4                             |Check limit
00194a64: 1440ffe9 bne r2,r0,0x00194a0c                 Λ Loop while not at max X
00194a68: 00e40018 mult r7,r4                               |Y counter * Max X
00194a6c: 92020e3b lbu r2,0x0e3b(r16)                   |Max Y
00194a70: 24e70001 addiu r7,r7,0x0001                   |Y counter + 1
00194a74: 00e2102a slt r2,r7,r2                         |Check limit
00194a78: 1440ffdc bne r2,r0,0x001949ec             Λ Loop while not at max Y
00194a7c: 00000000 nop                                  |
00194a80: 254a0001 addiu r10,r10,0x0001             |Elevation counter +1
00194a84: 29420002 slti r2,r10,0x0002               |Check limit
00194a88: 1440ffd3 bne r2,r0,0x001949d8         Λ Loop 2 times
00194a8c: 25080024 addiu r8,r8,0x0024               |Elevation offset in AI walkable tiles Table
00194a90: a2000e2d sb r0,0x0e2d(r16)            |Nullify 0xe2d (?) Will be used as offset for the next loop Table 
00194a94: 00002821 addu r5,r0,r0                |initialize counter
                                                @LOOP - Initialize Reachable tiles flags
00194a98: 92030e2d lbu r3,0x0e2d(r16)               |0x00 1st instance of 0xa74 Table ?
00194a9c: 00052040 sll r4,r5,0x01                   |counter * 2  Halfword offset
00194aa0: 000310c0 sll r2,r3,0x03                   |0xe2d * 8
00194aa4: 00431021 addu r2,r2,r3                    |0xe2d * 9
00194aa8: 000210c0 sll r2,r2,0x03                   |0xe2d * 0x48
00194aac: 02021021 addu r2,r16,r2                   |8019f3c4 + Some 0x48 offset 0x2ed is a offset of table of flags ?
00194ab0: 00821021 addu r2,r4,r2                    |Same + Halfword offset
00194ab4: a4400a74 sh r0,0x0a74(r2)                 |Nullify Y row halfword
00194ab8: 92030e2d lbu r3,0x0e2d(r16)               |
00194abc: 24a50001 addiu r5,r5,0x0001               |Y row counter + 1
00194ac0: 000310c0 sll r2,r3,0x03                   |0xe2d * 8
00194ac4: 00431021 addu r2,r2,r3                    |0xe2d * 9
00194ac8: 000210c0 sll r2,r2,0x03                   |0xe2d * 0x48
00194acc: 02021021 addu r2,r16,r2                   |8019f3c4 + Some 0x48 offset
00194ad0: 00822021 addu r4,r4,r2                    |Same + Halfword offset
00194ad4: 28a20012 slti r2,r5,0x0012                |Limit
00194ad8: 1440ffef bne r2,r0,0x00194a98         Λ Loop 0x12 Time (0x12 rows of tiles)
00194adc: a4800a98 sh r0,0x0a98(r4)                 |Nullify higher elevation row
00194ae0: 16200008 bne r17,r0,0x00194b04        #If Target didn't take his move yet
00194ae4: 00001021 addu r2,r0,r0                    |
00194ae8: 8e0317f8 lw r3,0x17f8(r16)                |Acting Unit Data pointer
00194aec: 00000000 nop                              |
00194af0: 9062005c lbu r2,0x005c(r3)                |Acting unit Current Status 5
00194af4: 00000000 nop                              |
00194af8: 30420008 andi r2,r2,0x0008                |Check [Don't Move]
00194afc: 1040000f beq r2,r0,0x00194b3c             #Avoid section if Unit can move
                                                Unit has moved or can't move
00194b00: 00001021 addu r2,r0,r0                        |r2 = 0x00 (returned value)
00194b04: 92040e31 lbu r4,0x0e31(r16)                   |Acting Unit Elevation
00194b08: 92050e30 lbu r5,0x0e30(r16)                   |Acting Unit X coord
00194b0c: 000418c0 sll r3,r4,0x03                       |Elevation * 8
00194b10: 00641821 addu r3,r3,r4                        |Elevation * 9
00194b14: 00031880 sll r3,r3,0x02                       |Elevation * 0x24
00194b18: 00701821 addu r3,r3,r16                       |AI pointer + Elevation offset (0 or 0x24)
00194b1c: 92040e32 lbu r4,0x0e32(r16)                   |Acting Unit Y coord
00194b20: 24630a74 addiu r3,r3,0x0a74                   |Pointer to AI 0xa74 (+ elevation offset)
00194b24: 00042040 sll r4,r4,0x01                       |Y offset (halfword)
00194b28: 00832021 addu r4,r4,r3                        |Pointer to AI 0xa74 + Row Offset + elevation 
00194b2c: 34038000 ori r3,r0,0x8000                     |Prepare bitmask
00194b30: 00a31807 srav r3,r3,r5                        |Bitmask for Acting Unit Tile (based on X) in Y row
00194b34: 08065390 j 0x00194e40                         >>Exit and   Returns 0x00 
00194b38: a4830000 sh r3,0x0000(r4)                     |Set acting Unit Tile's flag to 0x01 in 0x0a74 Table (reachable tiles)
                                                Unit Can move
                                                    Else : Unit can move
00194b3c: 90640182 lbu r4,0x0182(r3)                    |Acting Unit Mount Data
00194b40: 00000000 nop                                  |
00194b44: 30820080 andi r2,r4,0x0080                    |Check [Is riding]
00194b48: 14400002 bne r2,r0,0x00194b54                 #Branch if Riding a Unit
00194b4c: 3088001f andi r8,r4,0x001f                    |Get Mount ID
00194b50: 92080e2e lbu r8,0x0e2e(r16)                       |Acting Unit ID
00194b54: 92050e30 lbu r5,0x0e30(r16)                   |Acting Unit X
00194b58: 92060e32 lbu r6,0x0e32(r16)                   |Acting Unit Y
00194b5c: 92070e31 lbu r7,0x0e31(r16)                   |Acting Unit Elevation
00194b60: 0c05d2e3 jal 0x00174b8c                       |-->Set_Reachable_Tiles
00194b64: 01002021 addu r4,r8,r0                        |r4 = Moving Unit ID (Self or Mount)
                                        0x19b7 <> 0x00 - Or 0x00 and Unit can move
00194b68: 0c0076ea jal 0x0001dba8           |-->0001dba8_-_0001dcec
00194b6c: 34040001 ori r4,r0,0x0001         |Preset value = 0x1
00194b70: 284201b9 slti r2,r2,0x01b9        |Check returned value Vs 0x1b9
00194b74: 14400003 bne r2,r0,0x00194b84     #If returned Value > 0x1b8
00194b78: 00005021 addu r10,r0,r0           |Initialize Elevation counter
00194b7c: 08065390 j 0x00194e40                 >>Exit and  Return -0x01
00194b80: 2402ffff addiu r2,r0,0xffff           |
00194b84: a20019b7 sb r0,0x19b7(r16)        |Reset 0x19b7
00194b88: 02005821 addu r11,r16,r0          |AI data pointer
                                            @LOOP - through all tiles to set tile flag in 0x0a74 
00194b8c: 92020e3b lbu r2,0x0e3b(r16)           |Map Max Y
00194b90: 00000000 nop                          |
00194b94: 18400040 blez r2,0x00194c98           #If Max Y is invalid : Branch to   Next elevation iteration
00194b98: 00003821 addu r7,r0,r0                |Initialize Y counter
00194b9c: 000a6200 sll r12,r10,0x08             |Elevation Offset in Tiles Data (0 or 0x100)
00194ba0: 01606821 addu r13,r11,r0              |AI data pointer
                                                @LOOP through Y rows
00194ba4: 92040e3a lbu r4,0x0e3a(r16)               |Map Max X
00194ba8: 00000000 nop                              |
00194bac: 10800035 beq r4,r0,0x00194c84             #If Max X is invalid : Branch to   Next Y iteration
00194bb0: 00003021 addu r6,r0,r0                    |Initialize X counter
00194bb4: 25a30a74 addiu r3,r13,0x0a74              |AI Pointer to Table of reachable tiles flag
00194bb8: 00071040 sll r2,r7,0x01                   |Y counter * 2 (Halfword for each Y row)
00194bbc: 00434821 addu r9,r2,r3                    |Pointer to this Y row data (0x0a74 table)
00194bc0: 00e40018 mult r7,r4                       |
                                                    @LOOP through each tiles of the row
00194bc4: 8e0517f8 lw r5,0x17f8(r16)                    |Acting Unit's Data data pointer
00194bc8: 00000000 nop                                  |
00194bcc: 90a30094 lbu r3,0x0094(r5)                    |Acting Unit Movement 2
00194bd0: 3c048019 lui r4,0x8019                        |
00194bd4: 2484f8cc addiu r4,r4,0xf8cc                   |Tiles data pointer
00194bd8: 30630008 andi r3,r3,0x0008                    |Check [Teleport]
00194bdc: 00001012 mflo r2                              |Y*Max X
00194be0: 01821021 addu r2,r12,r2                       |Y*Max X + Elevation offset
00194be4: 00461021 addu r2,r2,r6                        |This iteration Tile ID Y*MaxX + X + Elevation offset
00194be8: 000210c0 sll r2,r2,0x03                       |Tile's ID * 8 Tile Offset in Tile's data
00194bec: 10600017 beq r3,r0,0x00194c4c                 #If Acting Unit can teleport
00194bf0: 00442021 addu r4,r2,r4                        |This iteration Tile data pointer
00194bf4: 90a20182 lbu r2,0x0182(r5)                        |Load Mount Data
00194bf8: 00000000 nop                                      |
00194bfc: 30420080 andi r2,r2,0x0080                        |Check [Is Riding]
00194c00: 14400012 bne r2,r0,0x00194c4c                     #If Unit is not Riding
00194c04: 00000000 nop                                          |
                                                        Teleport is active
00194c08: 92020e30 lbu r2,0x0e30(r16)                           |Acting Unit X coord
00194c0c: 00000000 nop                                          |
00194c10: 00464023 subu r8,r2,r6                                |Delta X (Acting Unit - This iteration tile)
00194c14: 05010002 bgez r8,0x00194c20                           #If delta X is negative
00194c18: 00000000 nop                                              |
00194c1c: 00084023 subu r8,r0,r8                                    |Make delta X positive
00194c20: 92020e32 lbu r2,0x0e32(r16)                           |Acting Unit Y
00194c24: 00000000 nop                                          |
00194c28: 00472823 subu r5,r2,r7                                |Delta Y (Acting unit - This iteration tile)
00194c2c: 04a10002 bgez r5,0x00194c38                           #If delta Y is negative
00194c30: 00000000 nop                                              |
00194c34: 00052823 subu r5,r0,r5                                    |Make delta Y positive
00194c38: 92030e38 lbu r3,0x0e38(r16)                           |Acting Unit Move
00194c3c: 01051021 addu r2,r8,r5                                |This Tile's distance to Acting unit
00194c40: 0062182a slt r3,r3,r2                                 |Check if reachable
00194c44: 1460000a bne r3,r0,0x00194c70                         #if Unit teleport and tile is in move range, branch to  Next Tile iteration 
00194c48: 00000000 nop                                          |
                                                        No Teleport - Teleport but beyond reach
00194c4c: 90820005 lbu r2,0x0005(r4)                        |Tile's Targeting data
00194c50: 00000000 nop                                      |
00194c54: 30420020 andi r2,r2,0x0020                        |check [0x20] - Reachable tile flag
00194c58: 10400005 beq r2,r0,0x00194c70                     #If Tile is set as reachable (pathfinding result)
00194c5c: 34028000 ori r2,r0,0x8000                             |Prepare bitmask
00194c60: 95230000 lhu r3,0x0000(r9)                            |This Row hallword (AI 0x0a74)
00194c64: 00c21007 srav r2,r2,r6                                |Bitmask for this Tile
00194c68: 00621825 or r3,r3,r2                                  |Enable this tile flag
00194c6c: a5230000 sh r3,0x0000(r9)                             |Store New flags (this tile enabled)
00194c70: 92040e3a lbu r4,0x0e3a(r16)                   |Map max X
00194c74: 24c60001 addiu r6,r6,0x0001                   |X counter +1
00194c78: 00c4102a slt r2,r6,r4                         |Check if next X is in map
00194c7c: 1440ffd1 bne r2,r0,0x00194bc4             Λ Loop While X counter is valid
00194c80: 00e40018 mult r7,r4                           |Y*MapX
00194c84: 92020e3b lbu r2,0x0e3b(r16)               |Map Max Y
00194c88: 24e70001 addiu r7,r7,0x0001               |Y counter +1
00194c8c: 00e2102a slt r2,r7,r2                     |Check if next Y is valid
00194c90: 1440ffc4 bne r2,r0,0x00194ba4         Λ Loop While Y counter is valid
00194c94: 00000000 nop                              |
00194c98: 254a0001 addiu r10,r10,0x0001         |Elevation counter +1
00194c9c: 29420002 slti r2,r10,0x0002           |Check limit
00194ca0: 1440ffba bne r2,r0,0x00194b8c     Λ Loop 2 times (each elevation)
00194ca4: 256b0024 addiu r11,r11,0x0024         |AI data pointer + elevation offset For 0x0a74 table
00194ca8: 00004021 addu r8,r0,r0            |Initialize unit counter
00194cac: 340900ff ori r9,r0,0x00ff         |
00194cb0: 34078000 ori r7,r0,0x8000         |Prep bitmask
00194cb4: 3c068019 lui r6,0x8019            |
00194cb8: 24c608cc addiu r6,r6,0x08cc       |Pointer to start of unit data
                                            @LOOP - Through all units
00194cbc: 90c20001 lbu r2,0x0001(r6)            |Unit ID
00194cc0: 00000000 nop                          |
00194cc4: 1049001a beq r2,r9,0x00194d30         #If Unit don't exist : branch  to next unit iteration
00194cc8: 00000000 nop                              |
00194ccc: 92020e2e lbu r2,0x0e2e(r16)           |Acting unit ID
00194cd0: 00000000 nop                          |
00194cd4: 11020016 beq r8,r2,0x00194d30         #If Unit is acting unit : branch  to next unit iteration
00194cd8: 00000000 nop                              |
00194cdc: 94c20058 lhu r2,0x0058(r6)            |Load this iteration unit Current Status 1 and 2
00194ce0: 00000000 nop                          |
00194ce4: 30420140 andi r2,r2,0x0140            |Check [Crystal] and [Treasure]
00194ce8: 14400011 bne r2,r0,0x00194d30         #If unit is not a crystal nor a treasure
00194cec: 00000000 nop                              |
00194cf0: 94c20048 lhu r2,0x0048(r6)                |Unit Y and elevatio
00194cf4: 90c50048 lbu r5,0x0048(r6)                |Unit Y Coord
00194cf8: 90c40047 lbu r4,0x0047(r6)                |Unit X Coord
00194cfc: 000213c2 srl r2,r2,0x0f                   |Shift elevation flag to 0x01
00194d00: 000218c0 sll r3,r2,0x03                   |Elevation * 8
00194d04: 00621821 addu r3,r3,r2                    |Elevation * 9
00194d08: 00031880 sll r3,r3,0x02                   |Elevation * 0x24
00194d0c: 00701821 addu r3,r3,r16                   |8019f3c4 + elevation offset
00194d10: 24630a74 addiu r3,r3,0x0a74               |Pointer to Reachable tile flag Table + elevation offset
00194d14: 00052840 sll r5,r5,0x01                   |Y*2
00194d18: 00a32821 addu r5,r5,r3                    |Pointer to Reachable tile flag Table + elevation and Y row offset
00194d1c: 00872007 srav r4,r7,r4                    |Shift 0x8000 by X coordinate
00194d20: 94a20000 lhu r2,0x0000(r5)                |Load This iteration Unit's, Y row halfword of flags
00194d24: 00042027 nor r4,r0,r4                     |All flags but the unit one
00194d28: 00441024 and r2,r2,r4                     |
00194d2c: a4a20000 sh r2,0x0000(r5)                 |Disable unit's tile reachable flag
00194d30: 25080001 addiu r8,r8,0x0001           |Unit counter + 1
00194d34: 29020015 slti r2,r8,0x0015            |check unit limit
00194d38: 1440ffe0 bne r2,r0,0x00194cbc     Λ Loop through all units
00194d3c: 24c601c0 addiu r6,r6,0x01c0           |Unit Battle stat offset
00194d40: 92030e31 lbu r3,0x0e31(r16)       |Acting Unit elevation
00194d44: 92040e32 lbu r4,0x0e32(r16)       |Active unit Y
00194d48: 92050e30 lbu r5,0x0e30(r16)       |Active unit X
00194d4c: 000310c0 sll r2,r3,0x03           |
00194d50: 00431021 addu r2,r2,r3            |
00194d54: 00021080 sll r2,r2,0x02           |Elevation * 0x24
00194d58: 00501021 addu r2,r2,r16           |
00194d5c: 24420a74 addiu r2,r2,0x0a74       |Pointer to Reachable tile flag Table + elevation offset
00194d60: 00042040 sll r4,r4,0x01           |
00194d64: 00822021 addu r4,r4,r2            |Pointer to Reachable tile flag Table + elevation and Y row offset
00194d68: 34038000 ori r3,r0,0x8000         |Prep bitmask
00194d6c: 94820000 lhu r2,0x0000(r4)        |Load Acting Unit's, Y row halfword of flags
00194d70: 00a31807 srav r3,r3,r5            |
00194d74: 00431025 or r2,r2,r3              |
00194d78: a4820000 sh r2,0x0000(r4)         |Enable acting unit's tile reachable flag
00194d7c: 8e0217f8 lw r2,0x17f8(r16)        |Load Acting Unit Data
00194d80: 3c030008 lui r3,0x0008            |
00194d84: 8c420058 lw r2,0x0058(r2)         |Load Current Statuses 1-4
00194d88: 34631000 ori r3,r3,0x1000         |0x00081000
00194d8c: 00431024 and r2,r2,r3             |Check [Confusion] and [Berserk]
00194d90: 1440002b bne r2,r0,0x00194e40     #If Acting unit is Confuse/Berserk :   Exit routine and returns 0x00 
00194d94: 00001021 addu r2,r0,r0                |r2 = 0x00

                                            Else - not confuse nor berserk
00194d98: 00004021 addu r8,r0,r0                |Initialize counter
00194d9c: 340900ff ori r9,r0,0x00ff             |
00194da0: 34078000 ori r7,r0,0x8000             |
00194da4: 3406181c ori r6,r0,0x181c             |
                                                @LOOP
00194da8: 02062021 addu r4,r16,r6                   |Pointer to AI ? (some coordinates data) 8019f3c4 + 0x181c + 0x04 Each iteration
00194dac: 90850000 lbu r5,0x0000(r4)                |Load ? X coordinates
00194db0: 00000000 nop                              |
00194db4: 10a90012 beq r5,r9,0x00194e00             #If Entry is invalid (0xff) : branch  Exit Loop
00194db8: 24c60004 addiu r6,r6,0x0004                   |0x181c offset counter + 4
00194dbc: 25080001 addiu r8,r8,0x0001                   |Existing unit counter + 1
00194dc0: 90830001 lbu r3,0x0001(r4)                    |Load Unit Elevation
00194dc4: 90840002 lbu r4,0x0002(r4)                    |Load Unit Y
00194dc8: 000310c0 sll r2,r3,0x03                       |
00194dcc: 00431021 addu r2,r2,r3                        |
00194dd0: 00021080 sll r2,r2,0x02                       |Elevation * 0x24
00194dd4: 00501021 addu r2,r2,r16                       |
00194dd8: 24420a74 addiu r2,r2,0x0a74                   |Pointer to Reachable tile flag Table + elevation offset
00194ddc: 00042040 sll r4,r4,0x01                       |
00194de0: 00822021 addu r4,r4,r2                        |Pointer to Reachable tile flag Table + elevation and Y row offset
00194de4: 00a71007 srav r2,r7,r5                        |Bitmask Tile flag
00194de8: 94830000 lhu r3,0x0000(r4)                    |Load this Tile Row flags
00194dec: 00021027 nor r2,r0,r2                         |Everything but tile flag
00194df0: 00621824 and r3,r3,r2                         |
00194df4: 29020004 slti r2,r8,0x0004                |Check limit
00194df8: 1440ffeb bne r2,r0,0x00194da8         Λ Loop 4 Times (4 coordinates ?)
00194dfc: a4830000 sh r3,0x0000(r4)                 |Disable this tile reachable flag
00194e00: 00001021 addu r2,r0,r0                | 
00194e04: 92040e31 lbu r4,0x0e31(r16)           |Acting Unit Elevation
00194e08: 92050e32 lbu r5,0x0e32(r16)           |Acting Unit Y Coord
00194e0c: 92060e30 lbu r6,0x0e30(r16)           |Acting Unit X Coord
00194e10: 000418c0 sll r3,r4,0x03               |
00194e14: 00641821 addu r3,r3,r4                |
00194e18: 00031880 sll r3,r3,0x02               |Elevation * 0x24
00194e1c: 00701821 addu r3,r3,r16               |
00194e20: 24630a74 addiu r3,r3,0x0a74           |Pointer to Reachable tile flag Table + elevation offset
00194e24: 00052840 sll r5,r5,0x01               |
00194e28: 00a32821 addu r5,r5,r3                |Pointer to Reachable tile flag Table + elevation and Y row offset
00194e2c: 34048000 ori r4,r0,0x8000             |
00194e30: 94a30000 lhu r3,0x0000(r5)            |Load Row of tiles flag
00194e34: 00c42007 srav r4,r4,r6                |
00194e38: 00641825 or r3,r3,r4                  |
00194e3c: a4a30000 sh r3,0x0000(r5)             |Enable acting unit's tile reachable flag Again ? 
00194e40: 8fbf0038 lw r31,0x0038(r29)       END
00194e44: 8fb10034 lw r17,0x0034(r29)
00194e48: 8fb00030 lw r16,0x0030(r29)
00194e4c: 27bd0040 addiu r29,r29,0x0040
00194e50: 03e00008 jr r31
00194e54: 00000000 nop

Notes

If AI 0x19b7  = 0x00 : initialize some movement data              ( 0x801a0d7b )
 - Set 0x19b9 (water movement penality)                           ( 0x801a0d7d )
 - Reset AI 0x0C24 Table (Walkable tile flag)
 - Set AI 0x0C24 Table flags (0x1 if not unselectable nor a cross section)
 - Nullify 0x0e2d (seems to be some offset for Table 0x0a74 (size is 0x48 bytes)
 - Reset AI 0x0A74 Table (reachable Tiles)
 - If Unit can't move/has moved : set Acting unit Tile flag to 1 in 0x0a74 Table and returns 0x00
 - If Unit can move : Set reachable tile flag - Byte 0x05 flag 0x20 (via heavy pathfinding routines)  
                      Go in 0x19b7 != 0x00 Section

If AI 0x19b7 != 0x00  
 - Exit if 0001dba8 returns r2 > 0x1b8
 - Else :
     - Reset 0x19b7 (this is just preventing some infinite loop due to 0001dba8 ?)
     - Enable Tile flag in AI Table 0xa74 if Tile is reachable (byte 0x05 flag 0x20) 
     Note : Unit using teleport seems to not use this table and skip the section
     - Disable Tile flag (Table 0x0a74) if there is another living unit on tile 
     - Enable acting Unit Tile's flag (0xa74)
     - Exit if acting unit has berserk or confuse
     - Else :
       - Disable Tile's flag is the tile is present in 0x181c List (4 words for 4 coordinates. Don't know which one yet)
       - Enable acting Unit Tile's flag (0xa74) (? force flag even if tile is in above list)

Return location

Battle.bin
00194070: Main_AI_action_setup