Some height/Map coordinate calculation for all units

From Final Fantasy Hacktics Wiki
(Redirected from 0019cb94 - 0019cd98)
Jump to navigation Jump to search
BATTLE.BIN :  - Some height/Map coordinate calculation for all units
Reset AI Table 0xb4c then enable Tile adjacent to an Ally with Monster Skill in AI 0xb4c Table (if delta Height is less than 2)
Bug ? The last loop checking both elevation seems to not doing it. The way the counter is handled seems wrong to me.
------------------------------------------------------------------------------------------
Parameter : Nothing
Return : Nothing
------------------------------------------------------------------------------------------
0019cb94: 27bdffd8 addiu r29,r29,-0x0028     |
0019cb98: 00002021 addu r4,r0,r0             |Initialize Y counter
0019cb9c: afb10014 sw r17,0x0014(r29)        |
0019cba0: 3c11801a lui r17,0x801a            |
0019cba4: 2631f3c4 addiu r17,r17,-0x0c3c     |8019f3c4
0019cba8: 02201821 addu r3,r17,r0            |Prepare Dynamic pointer to 0x8019f3c4 (1 halfword per iteration)
0019cbac: afbf0024 sw r31,0x0024(r29)        |
0019cbb0: afb40020 sw r20,0x0020(r29)        |
0019cbb4: afb3001c sw r19,0x001c(r29)        |
0019cbb8: afb20018 sw r18,0x0018(r29)        |
0019cbbc: afb00010 sw r16,0x0010(r29)        |
                                            @LOOP - Initialize AI 0xab4c
0019cbc0: a4600b4c sh r0,0x0b4c(r3)              |Initialize AI 0xb4c
0019cbc4: a4600b70 sh r0,0x0b70(r3)              |Initialize AI 0xb4c  High Elevation
0019cbc8: 24840001 addiu r4,r4,0x0001            |Y counter
0019cbcc: 28820012 slti r2,r4,0x0012             |
0019cbd0: 1440fffb bne r2,r0,0x0019cbc0      Λ Loop 0x12 times
0019cbd4: 24630002 addiu r3,r3,0x0002            |Halfword offset
0019cbd8: 00009821 addu r19,r0,r0            |Initialize Unit counter
0019cbdc: 34148000 ori r20,r0,0x8000         |Prepare Bitmask base
0019cbe0: 00009021 addu r18,r0,r0            |Initialize Unit offset for battle data
                                            @LOOP - All Units (Seek an Ally with monster skill support)
0019cbe4: 3c028019 lui r2,0x8019                 |
0019cbe8: 244208cc addiu r2,r2,0x08cc            |
0019cbec: 02428021 addu r16,r18,r2               |Dynamic Pointer to Battle data
0019cbf0: 92030001 lbu r3,0x0001(r16)            |This Unit ID
0019cbf4: 340200ff ori r2,r0,0x00ff              |
0019cbf8: 1062005b beq r3,r2,0x0019cd68          #If Unit do not exist : branch to next unit
0019cbfc: 00000000 nop                           |
0019cc00: 92020092 lbu r2,0x0092(r16)            |This Unit Support 4
0019cc04: 00000000 nop                           |
0019cc08: 30420080 andi r2,r2,0x0080             |
0019cc0c: 10400056 beq r2,r0,0x0019cd68          #If This Unit do not use [Monster Skill] : branch to next unit
0019cc10: 00000000 nop                           |
0019cc14: 920201ba lbu r2,0x01ba(r16)            |This Unit modified ENTD
0019cc18: 92230e39 lbu r3,0x0e39(r17)            |Acting Unit Team
0019cc1c: 30420030 andi r2,r2,0x0030             |This Unit Team
0019cc20: 14430051 bne r2,r3,0x0019cd68          #If This Unit is not an Ally : branch to  next unit
0019cc24: 00000000 nop                               |
0019cc28: 02002021 addu r4,r16,r0                |Send Battle Pointer
0019cc2c: 0c01786c jal 0x0005e1b0                |-->Status_Checks_(r5_%3D_set_to_check)
0019cc30: 34050004 ori r5,r0,0x0004              |Check Set 0x04 (Unit can act/react)
0019cc34: 1440004c bne r2,r0,0x0019cd68          #If Unit is somehow disabled : branch to  next unit
0019cc38: 00000000 nop                           |
0019cc3c: 92030048 lbu r3,0x0048(r16)            |Load This Ally Unit with Monster skill Y coordinates
0019cc40: 92220e3a lbu r2,0x0e3a(r17)            |Map Max X
0019cc44: 00000000 nop                           |
0019cc48: 00620018 mult r3,r2                    |
0019cc4c: 00004021 addu r8,r0,r0                 |Initialize Battle data loop offset
0019cc50: 96020048 lhu r2,0x0048(r16)            |Unit Y coordinates + Elevation
0019cc54: 92040047 lbu r4,0x0047(r16)            |Unit X coordinates
0019cc58: 000213c2 srl r2,r2,0x0f                |Keep only elevation
0019cc5c: 00021200 sll r2,r2,0x08                |0x100 or 0x00
0019cc60: 00001812 mflo r3                       |Y*Max X
0019cc64: 00431021 addu r2,r2,r3                 |
0019cc68: 00441021 addu r2,r2,r4                 |Tile ID   X + YMaxX +/-Elevation offset
0019cc6c: 000210c0 sll r2,r2,0x03                |Size of Tile data
0019cc70: 3c018019 lui r1,0x8019                 |
0019cc74: 00220821 addu r1,r1,r2                 |
0019cc78: 902bf8ce lbu r11,-0x0732(r1)           |Unit Tile Height 0x8018f8cc + 0x02 + Tile offset
                                                @LOOP - Check Tiles around Unit with Monster skill
0019cc7c: 92030047 lbu r3,0x0047(r16)                |Unit X coordinates
0019cc80: 3c01801a lui r1,0x801a                     |
0019cc84: 00280821 addu r1,r1,r8                     |+2 each iteration
0019cc88: 9022f358 lbu r2,-0x0ca8(r1)                |This iteration X offset around Unit 0x8019f358
0019cc8c: 00000000 nop                               |
0019cc90: 00623821 addu r7,r3,r2                     |Unit X + offset
0019cc94: 04e00030 bltz r7,0x0019cd58                #if This Tile is not in the map : branch to  Next Tile
0019cc98: 00000000 nop                               |
0019cc9c: 92220e3a lbu r2,0x0e3a(r17)                |Map Max X
0019cca0: 00000000 nop                               |
0019cca4: 00e2102a slt r2,r7,r2                      |
0019cca8: 1040002b beq r2,r0,0x0019cd58              #if This Tile is not in the map : branch to  Next Tile
0019ccac: 00000000 nop                               |
0019ccb0: 92030048 lbu r3,0x0048(r16)                |Unit Y coordinates
0019ccb4: 3c01801a lui r1,0x801a                     |
0019ccb8: 00280821 addu r1,r1,r8                     |
0019ccbc: 9022f359 lbu r2,-0x0ca7(r1)                |This iteration Y offset around Unit 0x8019f358 + 0x01
0019ccc0: 00000000 nop                               |
0019ccc4: 00622821 addu r5,r3,r2                     |Unit Y + Offset
0019ccc8: 04a00023 bltz r5,0x0019cd58                #if This Tile is not in the map : branch to  Next Tile
0019cccc: 00000000 nop                               |
0019ccd0: 92220e3b lbu r2,0x0e3b(r17)                |Map Max Y
0019ccd4: 00000000 nop                               |
0019ccd8: 00a2102a slt r2,r5,r2                      |
0019ccdc: 1040001e beq r2,r0,0x0019cd58              #if This Tile is not in the map : branch to  Next Tile
0019cce0: 00000000 nop                               |
0019cce4: 00002021 addu r4,r0,r0                     |Initialize Elevation counter
0019cce8: 00055040 sll r10,r5,0x01                   |Y Offset * 2
0019ccec: 00f44807 srav r9,r20,r7                    |Bitmask for This Tile in AI Table 0xb4c
0019ccf0: 02203021 addu r6,r17,r0                    |Prepare Dynamic pointer to AI 0xb4c
                                                    @LOOP - both elevation (test height)
0019ccf4: 92220e3a lbu r2,0x0e3a(r17)                    |Map Max X
0019ccf8: 00000000 nop                                   |
0019ccfc: 00a20018 mult r5,r2                            |
0019cd00: 00041200 sll r2,r4,0x08                        |Elevation offset
0019cd04: 00001812 mflo r3                               |
0019cd08: 00431021 addu r2,r2,r3                         |
0019cd0c: 00471021 addu r2,r2,r7                         |This Tile ID (X + Y*Max X +/- Elevation offset
0019cd10: 000210c0 sll r2,r2,0x03                        |Size Of Tile Data
0019cd14: 3c018019 lui r1,0x8019                         |
0019cd18: 00220821 addu r1,r1,r2                         |
0019cd1c: 9022f8ce lbu r2,-0x0732(r1)                    |This Tile Height 0x8018f8cc + 0x02 + Tile offset
0019cd20: 00000000 nop                                   |
0019cd24: 004b1023 subu r2,r2,r11                        |Delta Height (This Tile - Unit)
0019cd28: 24420002 addiu r2,r2,0x0002                    |
0019cd2c: 2c420005 sltiu r2,r2,0x0005                    |0x1 If Delta Height is between -2 and 2
0019cd30: 10400007 beq r2,r0,0x0019cd50                  #If Delta Height is ok
0019cd34: 24840001 addiu r4,r4,0x0001                    |Elevation counter +1
0019cd38: 24c30b4c addiu r3,r6,0x0b4c                        |
0019cd3c: 01431821 addu r3,r10,r3                            |8019f3c4 + 0xb4c + Y offset
0019cd40: 94620000 lhu r2,0x0000(r3)                         |Load this Tile's row in AI 0xb4c
0019cd44: 00000000 nop                                       |
0019cd48: 00491025 or r2,r2,r9                               |Use bitmask
0019cd4c: a4620000 sh r2,0x0000(r3)                          |Enable this Tile in AI 0xb4c Table
0019cd50: 1880ffe8 blez r4,0x0019ccf4                Λ loop 2 times ? ?? Bug ? does this realy loop two times ? 
0019cd54: 24c60024 addiu r6,r6,0x0024                    |Elevation offset (0x24)
0019cd58: 25080002 addiu r8,r8,0x0002                |Counter + 2 (halfword offset)
0019cd5c: 29020008 slti r2,r8,0x0008                 |
0019cd60: 1440ffc6 bne r2,r0,0x0019cc7c          Λ loop 4 times
0019cd64: 00000000 nop                               |
0019cd68: 26730001 addiu r19,r19,0x0001          |Unit Counter +1
0019cd6c: 2a620015 slti r2,r19,0x0015            |
0019cd70: 1440ff9c bne r2,r0,0x0019cbe4      Λ Do this for all units
0019cd74: 265201c0 addiu r18,r18,0x01c0          |Battle data offset
0019cd78: 8fbf0024 lw r31,0x0024(r29)
0019cd7c: 8fb40020 lw r20,0x0020(r29)
0019cd80: 8fb3001c lw r19,0x001c(r29)
0019cd84: 8fb20018 lw r18,0x0018(r29)
0019cd88: 8fb10014 lw r17,0x0014(r29)
0019cd8c: 8fb00010 lw r16,0x0010(r29)
0019cd90: 27bd0028 addiu r29,r29,0x0028
0019cd94: 03e00008 jr r31
0019cd98: 00000000 nop

Return locations

BATTLE.BIN
 0019c6bc: Evaluate_Linear_Ability_Behaviors