Difference between revisions of "Start searching for Highest Target Priority (0019c280)"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Updated documentation)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
  Find Highest Target Priority
+
'''BATTLE.BIN''' :  - Start_searching_for_Highest_Target_Priority_(0019c280)
 
+
  Find the best Tile (Score based on priority and ennemy proximity) in AI 0xb94 Table (Potential destination)
  0019c280: 27bdfff0 addiu r29,r29,0xfff0
+
------------------------------------------------------------------------------------------
  0019c284: 3c0d7fff lui r13,0x7fff
+
Parameter :
  0019c288: 35adffff ori r13,r13,0xffff r13 = Highest Current Target Priority (default value is 0x7fffffff)
+
Return :
  0019c28c: 00005821 addu r11,r0,r0
+
------------------------------------------------------------------------------------------
  0019c290: 0000c021 addu r24,r0,r0
+
  0019c280: 27bdfff0 addiu r29,r29,-0x0010    |
  0019c294: 3c08801a lui r8,0x801a
+
  0019c284: 3c0d7fff lui r13,0x7fff           |
  0019c298: 2508f3c4 addiu r8,r8,0xf3c4 r8 = Unit AI Data Pointer
+
  0019c288: 35adffff ori r13,r13,0xffff       |{{f/std|Default Score to beat}}
  0019c29c: 01007821 addu r15,r8,r0
+
  0019c28c: 00005821 addu r11,r0,r0           |{{f/std|Initialize elevation counter}}
  0019c2a0: 01007021 addu r14,r8,r0
+
  0019c290: 0000c021 addu r24,r0,r0           |{{f/std|Initialize elevation offset}}
 
+
  0019c294: 3c08801a lui r8,0x801a             |
<Map Level Loop>
+
  0019c298: 2508f3c4 addiu r8,r8,0xf3c4       |{{f/adr|0x8019f3c4}}
  0019c2a4: 91020e3b lbu r2,0x0e3b(r8) Load Max Y
+
  0019c29c: 01007821 addu r15,r8,r0           |
  0019c2a8: 00000000 nop
+
  0019c2a0: 01007021 addu r14,r8,r0           |
  0019c2ac: 1840002d blez r2,0x0019c364 <Map Level++> if Max Y is negative
+
                                            {{f/bloop|LOOP - Elevation}}
  0019c2b0: 00003821 addu r7,r0,r0
+
  0019c2a4: 91020e3b lbu r2,0x0e3b(r8)             |{{f/load|Load Max Y}}
  0019c2b4: 0300c821 addu r25,r24,r0
+
  0019c2a8: 00000000 nop                           |
  0019c2b8: 25ea05f4 addiu r10,r15,0x05f4 r10 =
+
  0019c2ac: 1840002d blez r2,0x0019c364           {{f/Cond|If Max Y is invalid : branch to }} {{f/loc|Next elevation }}
  0019c2bc: 25c90b94 addiu r9,r14,0x0b94 r9 = Current Unit Target Priority
+
  0019c2b0: 00003821 addu r7,r0,r0                     |{{f/std|Initilialize Y counter}}
 
+
  0019c2b4: 0300c821 addu r25,r24,r0                   |{{f/std|Elevation offset}}
<Y Loop>
+
  0019c2b8: 25ea05f4 addiu r10,r15,0x05f4             |{{f/adr|Dynamic pointer to AI 0x5f4 (+ 0x240 each elevation iteration)}}
  0019c2c0: 95230000 lhu r3,0x0000(r9) Load Target Priority
+
  0019c2bc: 25c90b94 addiu r9,r14,0x0b94               |{{f/adr|Dynamic pointer to AI 0x0b94 (+0x24 each elevation iteration)}} {{f/std|Table of destination Tiles (from where Caster can hit a target)}}
  0019c2c4: 00000000 nop
+
                                                {{f/bloop|LOOP - Y rows}}
  0019c2c8: 10600020 beq r3,r0,0x0019c34c <Y++> if Priority hasn't been set
+
  0019c2c0: 95230000 lhu r3,0x0000(r9)                 |{{f/load|Load this Y row flags}} {{f/std|AI 0xb94 Table}}
  0019c2cc: 00000000 nop
+
  0019c2c4: 00000000 nop                               |
 
+
  0019c2c8: 10600020 beq r3,r0,0x0019c34c             {{f/Cond|If there is no tiles to move on in this row : branch to }} {{f/loc|Next Y row}}
  0019c2d0: 91020e3a lbu r2,0x0e3a(r8) Load Max X
+
  0019c2cc: 00000000 nop                               |
  0019c2d4: 00000000 nop
+
  0019c2d0: 91020e3a lbu r2,0x0e3a(r8)                 |{{f/load|Load Max X}}
  0019c2d8: 1840001c blez r2,0x0019c34c Branch if Max X is negative
+
  0019c2d4: 00000000 nop                               |
  0019c2dc: 00002821 addu r5,r0,r0
+
  0019c2d8: 1840001c blez r2,0x0019c34c               {{f/Cond|If Max X is invalid branch to }} {{f/loc|Next Y row}}
 
+
  0019c2dc: 00002821 addu r5,r0,r0                     |{{f/std|Initilialize X counter}}
  0019c2e0: 00606021 addu r12,r3,r0 r12 = Current Unit Target Priority
+
  0019c2e0: 00606021 addu r12,r3,r0                   |{{f/std|This Y row halfword of X tiles Flags}}
  0019c2e4: 03281021 addu r2,r25,r8
+
  0019c2e4: 03281021 addu r2,r25,r8                   |{{f/std|AI pointer + elevation offset (0x120)}}
  0019c2e8: 24420174 addiu r2,r2,0x0174
+
  0019c2e8: 24420174 addiu r2,r2,0x0174               |
  0019c2ec: 00071900 sll r3,r7,0x04
+
  0019c2ec: 00071900 sll r3,r7,0x04                   |
  0019c2f0: 00621821 addu r3,r3,r2
+
  0019c2f0: 00621821 addu r3,r3,r2                     |{{f/adr|Dynamic pointer AI 0x0174 + Y offset + Elevation offset}} {{f/std|Tiles proximity score Table ( byte per tile)}}
  0019c2f4: 01403021 addu r6,r10,r0
+
  0019c2f4: 01403021 addu r6,r10,r0                   |{{f/adr|Dynamic pointer to AI 0x5f4 (+ 0x240 each elevation iteration)}}
 
+
                                                    {{f/bloop|LOOP - All Tiles in row}}
<X Loop>
+
  0019c2f8: 00ac1004 sllv r2,r12,r5                       |{{f/std|Shift Y row of flag by X counter (bit of interest is in 0x8000 position)}}
  0019c2f8: 00ac1004 sllv r2,r12,r5 Target Priority >> Current X
+
  0019c2fc: 30428000 andi r2,r2,0x8000                     |
  0019c2fc: 30428000 andi r2,r2,0x8000
+
  0019c300: 1040000c beq r2,r0,0x0019c334                 {{f/Cond|If This Tile is not a potential destination : branch to }} {{f/loc|Next X tile}}
  0019c300: 1040000c beq r2,r0,0x0019c334 Branch if this cell is not the current unit's cell
+
  0019c304: 00000000 nop                                   |
  0019c304: 00000000 nop
+
  0019c308: 84c40000 lh r4,0x0000(r6)                     |{{f/load|This Tile priority score}} {{f/adr|Dynamic pointer to AI 0x5f4 (with Elevation, Y and X offset)}}
 
+
  0019c30c: 90620000 lbu r2,0x0000(r3)                     |{{f/load|This Tile proximity score (the more units around, the higher)}} {{f/adr|Dynamic pointer to AI 0xa74 (with Elevation, Y and X offset)}}
  0019c308: 84c40000 lh r4,0x0000(r6)
+
  0019c310: 00042400 sll r4,r4,0x10                       |{{f/std|Priority score in upper part of a word (0x8000 becomes signed)}}
  0019c30c: 90620000 lbu r2,0x0000(r3)
+
  0019c314: 00822021 addu r4,r4,r2                         |{{f/std|Priority + Proximity}}
  0019c310: 00042400 sll r4,r4,0x10
+
  0019c318: 01a4102a slt r2,r13,r4                         |
  0019c314: 00822021 addu r4,r4,r2
+
  0019c31c: 14400005 bne r2,r0,0x0019c334                 {{f/Cond|If This Tile has a lower score (Priority + Proximity)}}
  0019c318: 01a4102a slt r2,r13,r4
+
  0019c320: 00000000 nop                                       |
  0019c31c: 14400005 bne r2,r0,0x0019c334 Branch if this unit has a higher priority then the current highest
+
  0019c324: 00806821 addu r13,r4,r0                           |{{f/std|Update best Score found}}
  0019c320: 00000000 nop
+
  0019c328: a1050018 sb r5,0x0018(r8)                         |{{f/store|Save New X Coordinates}}
  0019c324: 00806821 addu r13,r4,r0 Set Current Unit as Current Highest Unit Priority
+
  0019c32c: a107001a sb r7,0x001a(r8)                         |{{f/store|Save New Y Coordinates}}
  0019c328: a1050018 sb r5,0x0018(r8) Save New Coordinates
+
  0019c330: a10b0019 sb r11,0x0019(r8)                         |{{f/store|Save New Elevation}}
  0019c32c: a107001a sb r7,0x001a(r8)
+
  0019c334: 24630001 addiu r3,r3,0x0001                   |{{f/std|Offset for AI 0x174}}
  0019c330: a10b0019 sb r11,0x0019(r8)
+
  0019c338: 91020e3a lbu r2,0x0e3a(r8)                     |{{f/load|Max X}}
 
+
  0019c33c: 24a50001 addiu r5,r5,0x0001                   |{{f/std|X counter + 1}}
<X++>
+
  0019c340: 00a2102a slt r2,r5,r2                         |
  0019c334: 24630001 addiu r3,r3,0x0001
+
  0019c344: 1440ffec bne r2,r0,0x0019c2f8             {{f/Cond|Loop while X < Max X}}
  0019c338: 91020e3a lbu r2,0x0e3a(r8)
+
  0019c348: 24c60002 addiu r6,r6,0x0002                   |{{f/std|AI Table 0x5f4 Tile offset (halfword)}}
  0019c33c: 24a50001 addiu r5,r5,0x0001
+
  0019c34c: 254a0020 addiu r10,r10,0x0020             |{{f/std|AI Table0x5f4 offset}}
  0019c340: 00a2102a slt r2,r5,r2
+
  0019c350: 91020e3b lbu r2,0x0e3b(r8)                 |{{f/load|max Y}}
  0019c344: 1440ffec bne r2,r0,0x0019c2f8 Loop Max X times
+
  0019c354: 24e70001 addiu r7,r7,0x0001               |{{f/std|Y counter +1}}
  0019c348: 24c60002 addiu r6,r6,0x0002
+
  0019c358: 00e2102a slt r2,r7,r2                     |
 
+
  0019c35c: 1440ffd8 bne r2,r0,0x0019c2c0         {{f/Cond|Loop While Y < Max Y}}
<Y++>
+
  0019c360: 25290002 addiu r9,r9,0x0002               |{{f/std|AI Table 0xb4c offset}}
  0019c34c: 254a0020 addiu r10,r10,0x0020
+
  0019c364: 27180120 addiu r24,r24,0x0120         |{{f/std|AI 0x174 elevation offset}}
  0019c350: 91020e3b lbu r2,0x0e3b(r8)
+
  0019c368: 25ef0240 addiu r15,r15,0x0240         |{{f/std|AI 0x5f4 elevation offset}}
  0019c354: 24e70001 addiu r7,r7,0x0001
+
  0019c36c: 256b0001 addiu r11,r11,0x0001         |{{f/std|Elevation counter +1}}
  0019c358: 00e2102a slt r2,r7,r2
+
  0019c370: 29620002 slti r2,r11,0x0002           |
  0019c35c: 1440ffd8 bne r2,r0,0x0019c2c0 Loop Max Y times
+
  0019c374: 1440ffcb bne r2,r0,0x0019c2a4     {{f/Cond|Loop twice}}
  0019c360: 25290002 addiu r9,r9,0x0002
+
  0019c378: 25ce0024 addiu r14,r14,0x0024         |{{f/std|AI 0xb4c elevation offset}}
 
+
  0019c37c: 91030019 lbu r3,0x0019(r8)         |{{f/load|best Tile elevation}}
<Map Level++>
+
  0019c380: 9104001a lbu r4,0x001a(r8)         |{{f/load|best Tile Y coordinates}}
  0019c364: 27180120 addiu r24,r24,0x0120
+
  0019c384: 91050018 lbu r5,0x0018(r8)         |{{f/load|best Tile X coordinates}}
  0019c368: 25ef0240 addiu r15,r15,0x0240
+
  0019c388: 000310c0 sll r2,r3,0x03           |
  0019c36c: 256b0001 addiu r11,r11,0x0001
+
  0019c38c: 00431021 addu r2,r2,r3             |
  0019c370: 29620002 slti r2,r11,0x0002
+
  0019c390: 00021080 sll r2,r2,0x02           |
  0019c374: 1440ffcb bne r2,r0,0x0019c2a4 Loop twice
+
  0019c394: 00481021 addu r2,r2,r8             |
  0019c378: 25ce0024 addiu r14,r14,0x0024
+
  0019c398: 24420b94 addiu r2,r2,0x0b94       |
 
+
  0019c39c: 00042040 sll r4,r4,0x01           |
<Save ? to Unit Matrix Coordinates>
+
  0019c3a0: 00822021 addu r4,r4,r2             |{{f/adr|Pointer to AI 0xb94 best tile's Y row of flags}}
  0019c37c: 91030019 lbu r3,0x0019(r8) Load Unit Coordinates of highest Target Priority
+
  0019c3a4: 34038000 ori r3,r0,0x8000         |{{f/std|Prepare bitmask}}
  0019c380: 9104001a lbu r4,0x001a(r8)
+
  0019c3a8: 94820000 lhu r2,0x0000(r4)         |{{f/load|Best Tile Y row of flags}}
  0019c384: 91050018 lbu r5,0x0018(r8)
+
  0019c3ac: 00a31807 srav r3,r3,r5             |{{f/std|Set The bitmask in Tile position}}
  0019c388: 000310c0 sll r2,r3,0x03
+
  0019c3b0: 00431026 xor r2,r2,r3             |
  0019c38c: 00431021 addu r2,r2,r3
+
  0019c3b4: a4820000 sh r2,0x0000(r4)         |{{f/store|Disable best Tile flag}} {{f/std|Will be processed}}
  0019c390: 00021080 sll r2,r2,0x02
+
  0019c3b8: 91020cbc lbu r2,0x0cbc(r8)         |
  0019c394: 00481021 addu r2,r2,r8
+
  0019c3bc: 00000000 nop                       |
  0019c398: 24420b94 addiu r2,r2,0x0b94
+
  0019c3c0: 2442ffff addiu r2,r2,-0x0001      |
  0019c39c: 00042040 sll r4,r4,0x01
+
  0019c3c4: a1020cbc sb r2,0x0cbc(r8)         |{{f/store|Decrement Tile counter in AI 0xb94 Table}}
  0019c3a0: 00822021 addu r4,r4,r2
 
  0019c3a4: 34038000 ori r3,r0,0x8000
 
  0019c3a8: 94820000 lhu r2,0x0000(r4)
 
  0019c3ac: 00a31807 srav r3,r3,r5
 
  0019c3b0: 00431026 xor r2,r2,r3
 
  0019c3b4: a4820000 sh r2,0x0000(r4)
 
  0019c3b8: 91020cbc lbu r2,0x0cbc(r8)
 
  0019c3bc: 00000000 nop
 
  0019c3c0: 2442ffff addiu r2,r2,0xffff
 
  0019c3c4: a1020cbc sb r2,0x0cbc(r8)
 
 
  0019c3c8: 27bd0010 addiu r29,r29,0x0010
 
  0019c3c8: 27bd0010 addiu r29,r29,0x0010
 
  0019c3cc: 03e00008 jr r31
 
  0019c3cc: 03e00008 jr r31
 
  0019c3d0: 00000000 nop
 
  0019c3d0: 00000000 nop
 +
===Return locations===
 +
'''BATTLE.BIN'''
 +
  0019c0b4: [[Find_Highest_Target_Priority_in_Ability_Range_(0019bf2c)]]

Latest revision as of 08:28, 16 May 2024

BATTLE.BIN :  - Start_searching_for_Highest_Target_Priority_(0019c280)
Find the best Tile (Score based on priority and ennemy proximity) in AI 0xb94 Table (Potential destination)
------------------------------------------------------------------------------------------
Parameter : 
Return : 
------------------------------------------------------------------------------------------
0019c280: 27bdfff0 addiu r29,r29,-0x0010     |
0019c284: 3c0d7fff lui r13,0x7fff            |
0019c288: 35adffff ori r13,r13,0xffff        |Default Score to beat
0019c28c: 00005821 addu r11,r0,r0            |Initialize elevation counter
0019c290: 0000c021 addu r24,r0,r0            |Initialize elevation offset
0019c294: 3c08801a lui r8,0x801a             |
0019c298: 2508f3c4 addiu r8,r8,0xf3c4        |0x8019f3c4
0019c29c: 01007821 addu r15,r8,r0            |
0019c2a0: 01007021 addu r14,r8,r0            |
                                            @LOOP - Elevation
0019c2a4: 91020e3b lbu r2,0x0e3b(r8)             |Load Max Y
0019c2a8: 00000000 nop                           |
0019c2ac: 1840002d blez r2,0x0019c364            #If Max Y is invalid : branch to  Next elevation 
0019c2b0: 00003821 addu r7,r0,r0                     |Initilialize Y counter
0019c2b4: 0300c821 addu r25,r24,r0                   |Elevation offset
0019c2b8: 25ea05f4 addiu r10,r15,0x05f4              |Dynamic pointer to AI 0x5f4 (+ 0x240 each elevation iteration)
0019c2bc: 25c90b94 addiu r9,r14,0x0b94               |Dynamic pointer to AI 0x0b94 (+0x24 each elevation iteration) Table of destination Tiles (from where Caster can hit a target)
                                                @LOOP - Y rows
0019c2c0: 95230000 lhu r3,0x0000(r9)                 |Load this Y row flags AI 0xb94 Table
0019c2c4: 00000000 nop                               |
0019c2c8: 10600020 beq r3,r0,0x0019c34c              #If there is no tiles to move on in this row : branch to  Next Y row
0019c2cc: 00000000 nop                               |
0019c2d0: 91020e3a lbu r2,0x0e3a(r8)                 |Load Max X
0019c2d4: 00000000 nop                               |
0019c2d8: 1840001c blez r2,0x0019c34c                #If Max X is invalid branch to  Next Y row
0019c2dc: 00002821 addu r5,r0,r0                     |Initilialize X counter
0019c2e0: 00606021 addu r12,r3,r0                    |This Y row halfword of X tiles Flags
0019c2e4: 03281021 addu r2,r25,r8                    |AI pointer + elevation offset (0x120)
0019c2e8: 24420174 addiu r2,r2,0x0174                |
0019c2ec: 00071900 sll r3,r7,0x04                    |
0019c2f0: 00621821 addu r3,r3,r2                     |Dynamic pointer AI 0x0174 + Y offset + Elevation offset Tiles proximity score Table ( byte per tile)
0019c2f4: 01403021 addu r6,r10,r0                    |Dynamic pointer to AI 0x5f4 (+ 0x240 each elevation iteration)
                                                    @LOOP - All Tiles in row
0019c2f8: 00ac1004 sllv r2,r12,r5                        |Shift Y row of flag by X counter (bit of interest is in 0x8000 position)
0019c2fc: 30428000 andi r2,r2,0x8000                     |
0019c300: 1040000c beq r2,r0,0x0019c334                  #If This Tile is not a potential destination : branch to  Next X tile
0019c304: 00000000 nop                                   |
0019c308: 84c40000 lh r4,0x0000(r6)                      |This Tile priority score Dynamic pointer to AI 0x5f4 (with Elevation, Y and X offset)
0019c30c: 90620000 lbu r2,0x0000(r3)                     |This Tile proximity score (the more units around, the higher) Dynamic pointer to AI 0xa74 (with Elevation, Y and X offset)
0019c310: 00042400 sll r4,r4,0x10                        |Priority score in upper part of a word (0x8000 becomes signed)
0019c314: 00822021 addu r4,r4,r2                         |Priority + Proximity
0019c318: 01a4102a slt r2,r13,r4                         |
0019c31c: 14400005 bne r2,r0,0x0019c334                  #If This Tile has a lower score (Priority + Proximity)
0019c320: 00000000 nop                                       |
0019c324: 00806821 addu r13,r4,r0                            |Update best Score found
0019c328: a1050018 sb r5,0x0018(r8)                          |Save New X Coordinates
0019c32c: a107001a sb r7,0x001a(r8)                          |Save New Y Coordinates
0019c330: a10b0019 sb r11,0x0019(r8)                         |Save New Elevation
0019c334: 24630001 addiu r3,r3,0x0001                    |Offset for AI 0x174
0019c338: 91020e3a lbu r2,0x0e3a(r8)                     |Max X
0019c33c: 24a50001 addiu r5,r5,0x0001                    |X counter + 1
0019c340: 00a2102a slt r2,r5,r2                          |
0019c344: 1440ffec bne r2,r0,0x0019c2f8              #Loop while X < Max X
0019c348: 24c60002 addiu r6,r6,0x0002                    |AI Table 0x5f4 Tile offset (halfword)
0019c34c: 254a0020 addiu r10,r10,0x0020              |AI Table0x5f4 offset
0019c350: 91020e3b lbu r2,0x0e3b(r8)                 |max Y
0019c354: 24e70001 addiu r7,r7,0x0001                |Y counter +1
0019c358: 00e2102a slt r2,r7,r2                      |
0019c35c: 1440ffd8 bne r2,r0,0x0019c2c0          #Loop While Y < Max Y
0019c360: 25290002 addiu r9,r9,0x0002                |AI Table 0xb4c offset
0019c364: 27180120 addiu r24,r24,0x0120          |AI 0x174 elevation offset
0019c368: 25ef0240 addiu r15,r15,0x0240          |AI 0x5f4 elevation offset
0019c36c: 256b0001 addiu r11,r11,0x0001          |Elevation counter +1
0019c370: 29620002 slti r2,r11,0x0002            |
0019c374: 1440ffcb bne r2,r0,0x0019c2a4      #Loop twice
0019c378: 25ce0024 addiu r14,r14,0x0024          |AI 0xb4c elevation offset
0019c37c: 91030019 lbu r3,0x0019(r8)         |best Tile elevation
0019c380: 9104001a lbu r4,0x001a(r8)         |best Tile Y coordinates
0019c384: 91050018 lbu r5,0x0018(r8)         |best Tile X coordinates
0019c388: 000310c0 sll r2,r3,0x03            |
0019c38c: 00431021 addu r2,r2,r3             |
0019c390: 00021080 sll r2,r2,0x02            |
0019c394: 00481021 addu r2,r2,r8             |
0019c398: 24420b94 addiu r2,r2,0x0b94        |
0019c39c: 00042040 sll r4,r4,0x01            |
0019c3a0: 00822021 addu r4,r4,r2             |Pointer to AI 0xb94 best tile's Y row of flags
0019c3a4: 34038000 ori r3,r0,0x8000          |Prepare bitmask
0019c3a8: 94820000 lhu r2,0x0000(r4)         |Best Tile Y row of flags
0019c3ac: 00a31807 srav r3,r3,r5             |Set The bitmask in Tile position
0019c3b0: 00431026 xor r2,r2,r3              |
0019c3b4: a4820000 sh r2,0x0000(r4)          |Disable best Tile flag Will be processed
0019c3b8: 91020cbc lbu r2,0x0cbc(r8)         |
0019c3bc: 00000000 nop                       |
0019c3c0: 2442ffff addiu r2,r2,-0x0001       |
0019c3c4: a1020cbc sb r2,0x0cbc(r8)          |Decrement Tile counter in AI 0xb94 Table
0019c3c8: 27bd0010 addiu r29,r29,0x0010
0019c3cc: 03e00008 jr r31
0019c3d0: 00000000 nop

Return locations

BATTLE.BIN
 0019c0b4: Find_Highest_Target_Priority_in_Ability_Range_(0019bf2c)