Calculate Possible AoE Tiles

From Final Fantasy Hacktics Wiki
Revision as of 22:10, 5 February 2022 by Orkney (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
0017963c - 001797b0 : This routine will spread the AoE out of the center, storing the original AoE value - 1 in the surrounding tiles (see Notes)

Parameters : r4 = AoE Origin Y
             r5 = AoE Origin X

Returns : r2 = 0x01 if AoE is not ended yet
          r2 = 0x00 if AoE has ended to spread out
------------------------------------------------------------------------------------------------------
0017963c: 3c02800e lui r2,0x800e            |r2 = 0x800e
00179640: 90424e9c lbu r2,0x4e9c(r2)        |r2 = Map Max X
00179644: 00000000 nop                      |
00179648: 00820018 mult r4,r2               |Max X * Y coord
0017964c: 00007021 addu r14,r0,r0           |r14 = 0x00 (will be set to 0x01 and returned via r2 if AoE is not finished)
00179650: 00004821 addu r9,r0,r0            |r9 = 0x00 (Loop counter)
00179654: 00001812 mflo r3                  |r3 = Max X * Y coord
00179658: 00651821 addu r3,r3,r5            |(Max X * Y coord) + X coord   (Tile ID without elevation)
0017965c: 00031080 sll r2,r3,0x02           |r2 = Tile ID *4
00179660: 00431021 addu r2,r2,r3            |r2 = Tile ID * 5 (offset of data on targetable grid)
00179664: 3c018019 lui r1,0x8019            |r1 = 0x80190000
00179668: 00220821 addu r1,r1,r2            |r1 = 0x80190000 + Tile offset
0017966c: 902c2dd8 lbu r12,0x2dd8(r1)       |r12 = AoE of targetable pannel matching Tile coordinates (will spread from here = Origin Panel)
00179670: 340f0001 ori r15,r0,0x0001        |r15 = 0x01 (will be stored at panel 0x01 while looping)
00179674: 258dffff addiu r13,r12,-0x0001    |r13 = AoE from Origin Panel - 0x01
00179678: 112f0011 beq r9,r15,0x001796c0    @LOOP 4 times (4 panels around origin) #If r9 <> 0x01 (Start of the loop is a mess, just to check counter value)
0017967c: 29220002 slti r2,r9,0x0002             |r2 = 0x01 if r9 < 0x02
00179680: 10400005 beq r2,r0,0x00179698              #If r9 <0x02 (=< 0x00)
00179684: 00000000 nop                               |
00179688: 1120000a beq r9,r0,0x001796b4                  #if r9<> 0x00 (not 0x00 not 0x01 and <0x02) ? < 0x00 ? Never met ? (resolution is strange)
0017968c: 00ab4021 addu r8,r5,r11                            |r8 = Origin X + r11 (not set yet or = 0x00)
00179690: 0805e5b9 j 0x001796e4                              >>jump to offset attribution ( X already done)
00179694: 00000000 nop                                       |
00179698: 34020002 ori r2,r0,0x0002                  #Else (r9 >=0x02)  r2 = 0x02
0017969c: 1122000b beq r9,r2,0x001796cc                      #if r9 <> 0x02
001796a0: 34020003 ori r2,r0,0x0003                              |r2 = 0x03
001796a4: 1122000c beq r9,r2,0x001796d8                          #if r9 <> 0x03
001796a8: 00ab4021 addu r8,r5,r11                                    |r8 = Origin X + r11 (not set yet or = 0x00)
001796ac: 0805e5b9 j 0x001796e4                                      >>jump
001796b0: 00000000 nop                                               |
001796b4: 340b0001 ori r11,r0,0x0001             #>jump here if r9 = 0x00 X offset = 0x01
001796b8: 0805e5b8 j 0x001796e0                      >>jump to offset attribution (X+1)
001796bc: 00005021 addu r10,r0,r0                    |Y offset = 0x00
001796c0: 00005821 addu r11,r0,r0                #>jump here if r9 = 0x01 X offset = 0
001796c4: 0805e5b8 j 0x001796e0                      >>jump to offset attribution (Y+1)
001796c8: 340a0001 ori r10,r0,0x0001                 |Y offset= 0x01
001796cc: 240bffff addiu r11,r0,0xffff           #>jump here if r9 = 0x02 X offset = -0x01
001796d0: 0805e5b8 j 0x001796e0                      >>jump to offset attribution X-1)
001796d4: 00005021 addu r10,r0,r0                    |Y offset = 0x00
001796d8: 00005821 addu r11,r0,r0                #>jump here if r9 = 0x03 (Y-1) X offset = 0
001796dc: 240affff addiu r10,r0,0xffff               |Y offset = -0x01

                              ---  Coordinates checking and AoE attribution ---
001796e0: 00ab4021 addu r8,r5,r11                |r8 = Origin X + X offset
001796e4: 0500002d bltz r8,0x0017979c            #if Xcoord is valid (>= 0x00) /Else branch to next loop iteration
001796e8: 008a3821 addu r7,r4,r10                |r7 = Origin Y + Y offset
001796ec: 04e0002b bltz r7,0x0017979c                #if Y coord is valid (>= 0x00) /Else branch to next loop iteration
001796f0: 00000000 nop                                   |
001796f4: 3c03800e lui r3,0x800e                         |r3 = 0x800e0000
001796f8: 90634e9c lbu r3,0x4e9c(r3)                     |r3 = Map Max X
001796fc: 00000000 nop                                   |
00179700: 0103102a slt r2,r8,r3                          |r2 = 0x01 if r8 < Map Max X
00179704: 10400025 beq r2,r0,0x0017979c                  #If X coord is valid (< Map Max X) /Else branch to next loop iteration
00179708: 00000000 nop                                       |
0017970c: 3c02800e lui r2,0x800e                             |r2 = 0x800e0000
00179710: 90424ea0 lbu r2,0x4ea0(r2)                         |r2 = Map Max Y
00179714: 00000000 nop                                       |
00179718: 00e2102a slt r2,r7,r2                              |r2 = 0x01 if r7 < Map Max Y
0017971c: 1040001f beq r2,r0,0x0017979c                      #If Y coord is valid (< Map Max Y)
00179720: 00e30018 mult r7,r3                                    |Y coord * Max X
00179724: 00001012 mflo r2                                       |r2 = Y coord * Max X
00179728: 00481021 addu r2,r2,r8                                 |r2 =(Y * Max X) + X = Tile ID (with elevation 0)
0017972c: 00021880 sll r3,r2,0x02                                |r3 = Tile ID * 4
00179730: 00621821 addu r3,r3,r2                                 |r3 = Tile ID * 5 (offset of panel data in targetable grid)
00179734: 3c028019 lui r2,0x8019                                 |
00179738: 24422dd8 addiu r2,r2,0x2dd8                            |r2 = 0x80192dd8
0017973c: 00623021 addu r6,r3,r2                                 |r6 = Targetable grid panel data pointer
00179740: 90c20000 lbu r2,0x0000(r6)                             |r2 = AoE from this panel
00179744: 00000000 nop                                           |
00179748: 004c102a slt r2,r2,r12                                 |r2 =0x01 if AoE is < origin panel AoE
0017974c: 10400013 beq r2,r0,0x0017979c                          #if AoE is < Origin Panel AoE (AoE spread out, this is for not overwriting data toward the center of large AoE) /Else next loop iteration
00179750: 00000000 nop                                               |
00179754: a0cd0000 sb r13,0x0000(r6)                                 |Store AoE = Origin AoE - 1
00179758: 3c02800e lui r2,0x800e                                     |r2 = 0x800e
0017975c: 90424e9c lbu r2,0x4e9c(r2)                                 |r2 = Map Max X
00179760: 00000000 nop                                               |
00179764: 00e20018 mult r7,r2                                        |Y coord * Max X
00179768: 25020100 addiu r2,r8,0x0100                                |r2 =  X coord+ 0x100 (higher elevation offset)
0017976c: 00001812 mflo r3                                           |r3 = Y coord * Max X
00179770: 00621821 addu r3,r3,r2                                     |r3 = (Y coord * Max X) + X coord+ 0x100 = Tile ID (with elevation 1)
00179774: 00031080 sll r2,r3,0x02                                    |Higher Tile ID * 4
00179778: 00431021 addu r2,r2,r3                                     |Higher Tile ID * 5 (offset of panel data in targetable grid)
0017977c: 3c018019 lui r1,0x8019                                     |r1 = 0x80190000
00179780: 00220821 addu r1,r1,r2                                     |r1 = 0x80190000 + offset of panel data in targetable grid
00179784: a02d2dd8 sb r13,0x2dd8(r1)                                 |Store AoE = Origin AoE - 1
00179788: 29820003 slti r2,r12,0x0003                                |r2 = 0x01 if Origin AoE is < 0x03
0017978c: 14400003 bne r2,r0,0x0017979c                              #If Origin AoE is > 0x02 /Else AoE has ended spreading
00179790: 00000000 nop                                                   |
00179794: a0cf0001 sb r15,0x0001(r6)                                     |Store lower panel Targeted Flag = 0x01
00179798: 340e0001 ori r14,r0,0x0001                                     |r14 = 0x01 (will be returned, AoE is not ended yet)
0017979c: 25290001 addiu r9,r9,0x0001            |Counter +1
001797a0: 29220004 slti r2,r9,0x0004             |r2 = 0x01 while r9 < 0x04
001797a4: 1440ffb4 bne r2,r0,0x00179678     Λ LOOP while counter < 0x04
001797a8: 00000000 nop                      |
001797ac: 03e00008 jr r31                   |
001797b0: 01c01021 addu r2,r14,r0           |r2 = 0x01 (not ended) or 0x00 (ended)

Notes

Loop 4 times (4 surrounding tiles)
The first part seems messy, and check the loop counter, then determine X and Y offset arround the original tile
Second part check if the surrounding tiles are valid (in the map)
If Tile is in the map, the AoE (- 0x01) will be stored in the panel 0x00 byte (lower and higher elevation)

If Aoe is not finished, the target flag of the panel (panel 0x01) will be set to 0x01 and r2 will be set to 0x01
If AoE is finished, r2 is set to 0x00

Return location

001795cc: Calculate_Tiles_Hit_by_Ability