Get unit that matches coordinates

From Final Fantasy Hacktics Wiki
Revision as of 16:26, 31 July 2023 by Orkney (talk | contribs)
Jump to navigation Jump to search
BATTLE.BIN - Get unit that matches coordinates         ALTERNATIVE VERSION Find Unit at Coordinates (0x19d294)
------------------------------------------------------------------------------------
Parameters : pointer to some tile coordinates
Returns : r2 = Unit counter (position in Battle stats) if unit share Tile coordinates
------------------------------------------------------------------------------------
0019d294: 00003021 addu r6,r0,r0            |
0019d298: 340700ff ori r7,r0,0x00ff         |
0019d29c: 3c058019 lui r5,0x8019            |
0019d2a0: 24a508cc addiu r5,r5,0x08cc       |Start of Unit Data
                                            @LOOP - All units
0019d2a4: 90a20001 lbu r2,0x0001(r5)            |Unit ID
0019d2a8: 00000000 nop                          |
0019d2ac: 10470010 beq r2,r7,0x0019d2f0         #If Unit do not exist : branch to   Next unit
0019d2b0: 00000000 nop                              |
0019d2b4: 90a30047 lbu r3,0x0047(r5)            |This Unit X
0019d2b8: 90820000 lbu r2,0x0000(r4)            |Tile of interest X
0019d2bc: 00000000 nop                          |
0019d2c0: 1462000b bne r3,r2,0x0019d2f0         #If Unit and Tile of interest share same X
0019d2c4: 00000000 nop                              |
0019d2c8: 90a30048 lbu r3,0x0048(r5)                |This Unit Y
0019d2cc: 90820002 lbu r2,0x0002(r4)                |Tile of interest Y
0019d2d0: 00000000 nop                              |
0019d2d4: 14620006 bne r3,r2,0x0019d2f0             #If Unit and Tile of interest share sameY
0019d2d8: 00000000 nop                                  |
0019d2dc: 94a20048 lhu r2,0x0048(r5)                    |Y + Elevation
0019d2e0: 90830001 lbu r3,0x0001(r4)                    |Tile of interest Elevation
0019d2e4: 000213c2 srl r2,r2,0x0f                       |This Unit Elevation
0019d2e8: 10430005 beq r2,r3,0x0019d300                 #If This unit is on Tile of interest :   Returns Counter
0019d2ec: 00000000 nop                                      |
0019d2f0: 24c60001 addiu r6,r6,0x0001           |Unit counter + 1
0019d2f4: 28c20015 slti r2,r6,0x0015            |
0019d2f8: 1440ffea bne r2,r0,0x0019d2a4     Λ Loop 0x15 Times
0019d2fc: 24a501c0 addiu r5,r5,0x01c0           |Unit Battle stats offset
0019d300: 03e00008 jr r31
0019d304: 00c01021 addu r2,r6,r0

Returns locations

BATTLE.BIN
001965d4: Map_movement_decision/data_setting
00197878: Store_ability/skillset_data,_set_AI_settings_for_ability?
0019bb40: AI_Check_if_Unit_is_a_Crystal/Treasure_(0019bb20)