Difference between revisions of "Check if another unit is on the same Tile"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m (Add duplicated link)
m (Notes Formatting, return location)
Line 1: Line 1:
  Duplicated here [[Find_Unit_at_Specified_Coordinates]]
+
  Duplicated here [[Find_Unit_at_Specified_Coordinates]] (programmers friendly formatting)
 
  ----------------------------------------------------------------
 
  ----------------------------------------------------------------
 +
Parameters : r4 = X coordinate
 +
              r5 = Y coordinates
 +
              r6 = Elevation (0x00 or 0x01)
 +
              r7 = Preset value - specify conditions to check
 +
                    0x80 - check for mountable chocobo
 +
                    0x41 - check for crystal and treasure
 +
                    0x10 - check for transparent unit
 +
                    0x00 - check for a unit without conditions
 +
 +
Returns : r2 = -0x02 if coordinates are invalid  
 +
          r2 = -0x01 if there's no unit matching r7 at coordinates
 +
          r2 = Unit ID if there's a unit matching r7
 +
------------------------------------------------------------------------------
 +
r4 = X r5 = Y r6 = elevation r7 = preset value
 
  0017dca8: 27bdffd0 addiu r29,r29,0xffd0
 
  0017dca8: 27bdffd0 addiu r29,r29,0xffd0
  0017dcac: afb40020 sw r20,0x0020(r29)
+
  0017dcac: afb40020 sw r20,0x0020(r29)       |
  0017dcb0: 0080a021 addu r20,r4,r0 r20 = Unit's X Coordinate
+
  0017dcb0: 0080a021 addu r20,r4,r0           |{{f/std|<nowiki>r20 = Attacker current action target  X Coordinate</nowiki>}}
  0017dcb4: afb50024 sw r21,0x0024(r29)
+
  0017dcb4: afb50024 sw r21,0x0024(r29)       |
  0017dcb8: 00a0a821 addu r21,r5,r0 r21 = Unit's Y Coordinate
+
  0017dcb8: 00a0a821 addu r21,r5,r0           |{{f/std|<nowiki>r21 = Attacker current action target  y Coordinate</nowiki>}}
  0017dcbc: afb60028 sw r22,0x0028(r29)
+
  0017dcbc: afb60028 sw r22,0x0028(r29)       |
  0017dcc0: 00c0b021 addu r22,r6,r0 r22 = Unit's Map Level
+
  0017dcc0: 00c0b021 addu r22,r6,r0           |{{f/std|<nowiki>r22 =  Attacker current action target map elevation</nowiki>}}
  0017dcc4: afb20018 sw r18,0x0018(r29)
+
0017dcc4: afb20018 sw r18,0x0018(r29)       |
  0017dcc8: 00e09021 addu r18,r7,r0 r18 = Preset Value
+
  0017dcc8: 00e09021 addu r18,r7,r0           |{{f/std|<nowiki>r18 = Preset Value</nowiki>}}
  0017dccc: afbf002c sw r31,0x002c(r29)
+
  0017dccc: afbf002c sw r31,0x002c(r29)       |
  0017dcd0: afb3001c sw r19,0x001c(r29)
+
  0017dcd0: afb3001c sw r19,0x001c(r29)       |
  0017dcd4: afb10014 sw r17,0x0014(r29)
+
  0017dcd4: afb10014 sw r17,0x0014(r29)       |
  0017dcd8: 0680002c bltz r20,0x0017dd8c Branch if Unit's X Coordinate < 0
+
  0017dcd8: 0680002c bltz r20,0x0017dd8c     {{f/Cond|<nowiki>If Target X coordinate >= 0</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}}  {{f/std|<nowiki>(branch to a jump to end with r2 = -0x02)</nowiki>}}
0017dcdc: afb00010 sw r16,0x0010(r29)
+
0017dcdc: afb00010 sw r16,0x0010(r29)           |{{f/store|<nowiki>  </nowiki>}}
  0017dce0: 3c03800e lui r3,0x800e
+
  0017dce0: 3c03800e lui r3,0x800e                 |
  0017dce4: 90634e9c lbu r3,0x4e9c(r3) Load Map Max X Coordinate
+
  0017dce4: 90634e9c lbu r3,0x4e9c(r3)             |{{f/load|<nowiki>r3 = Map Max X Coordinate</nowiki>}}
  0017dce8: 00000000 nop
+
  0017dce8: 00000000 nop                           |
  0017dcec: 0283102a slt r2,r20,r3
+
  0017dcec: 0283102a slt r2,r20,r3                 |{{f/std|<nowiki>r2 = 0x01 if Unit X coord. < Map max X</nowiki>}}
  0017dcf0: 10400026 beq r2,r0,0x0017dd8c Branch if X Coordinate >= Max X
+
  0017dcf0: 10400026 beq r2,r0,0x0017dd8c         {{f/Cond|<nowiki>If Unit X is in the map</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}} {{f/std|<nowiki>(branch to a jump to end with r2 = -0x02)</nowiki>}}
  0017dcf4: 00000000 nop
+
  0017dcf4: 00000000 nop                               |{{f/std|<nowiki> </nowiki>}}
0017dcf8: 06a0006a bltz r21,0x0017dea4 Branch if Y Coordinate < 0
+
0017dcf8: 06a0006a bltz r21,0x0017dea4               {{f/Cond|<nowiki>If Unit Y coord. >= 0x00</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}} with r2 = -0x02
  0017dcfc: 2402fffe addiu r2,r0,0xfffe r2 = -2
+
  0017dcfc: 2402fffe addiu r2,r0,-0x0002              |{{f/std|<nowiki>r2 = -0x02</nowiki>}}
  0017dd00: 3c02800e lui r2,0x800e
+
  0017dd00: 3c02800e lui r2,0x800e                         |{{f/std|<nowiki> </nowiki>}}
  0017dd04: 90424ea0 lbu r2,0x4ea0(r2) Load Map Max Y Coordinate
+
  0017dd04: 90424ea0 lbu r2,0x4ea0(r2)                     |{{f/load|<nowiki>r4 =Map Max Y Coordinate</nowiki>}}
  0017dd08: 00000000 nop
+
  0017dd08: 00000000 nop                                   |
  0017dd0c: 02a2102a slt r2,r21,r2
+
  0017dd0c: 02a2102a slt r2,r21,r2                         |{{f/std|<nowiki>r2 = 0x01 if Unit Y coord < map max Y</nowiki>}}
0017dd10: 1040001e beq r2,r0,0x0017dd8c Branch if Y Coordinate >= Max Y
+
  0017dd10: 1040001e beq r2,r0,0x0017dd8c                  {{f/Cond|<nowiki>If unit is in the map</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}} {{f/std|<nowiki>(branch to a jump to end with r2 = -0x02)</nowiki>}}
  0017dd14: 2ec20002 sltiu r2,r22,0x0002
+
  0017dd14: 2ec20002 sltiu r2,r22,0x0002                      |{{f/std|<nowiki>r2 = 0x01 if Unit Map elevation < 0x02</nowiki>}}
  0017dd18: 1040001c beq r2,r0,0x0017dd8c Branch if Unit's Map Level >= 2
+
  0017dd18: 1040001c beq r2,r0,0x0017dd8c                      {{f/Cond|<nowiki>If Unit Map Elevation < 0x02</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}} {{f/std|<nowiki>(branch to a jump to end with r2 = -0x02)</nowiki>}}
  0017dd1c: 02a30018 mult r21,r3 Max X * Y
+
  0017dd1c: 02a30018 mult r21,r3                                   |{{f/std|<nowiki>Max X * Y</nowiki>}}
0017dd20: 00161200 sll r2,r22,0x08 Map Level * 0x100
+
  0017dd20: 00161200 sll r2,r22,0x08                              |{{f/std|<nowiki>r2 = Map elevation * 0x100</nowiki>}}
  0017dd24: 00001812 mflo r3 r3 = Max X * Y
+
  0017dd24: 00001812 mflo r3                                       |{{f/std|<nowiki>r3 = Map Max X *Unit  Y coord (Y modified)</nowiki>}}
  0017dd28: 00431021 addu r2,r2,r3 Y Mod = Max X * Y + Map Level * 0x100
+
  0017dd28: 00431021 addu r2,r2,r3                                 |{{f/std|<nowiki>r2 = Y modified + Map elevation * 0x100</nowiki>}}
  0017dd2c: 00541021 addu r2,r2,r20 Tile ID = Y Mod + X
+
  0017dd2c: 00541021 addu r2,r2,r20                                |{{f/std|<nowiki>r2 = Tile ID</nowiki>}} {{f/std|<nowiki>r2 = Y modified + X + Map elevation * 0x100</nowiki>}}
0017dd30: 000210c0 sll r2,r2,0x03 Tile ID * 8
+
  0017dd30: 000210c0 sll r2,r2,0x03                                |{{f/std|<nowiki>r2=Tile ID * 8 (size of tiles data)</nowiki>}}
  0017dd34: 3c038019 lui r3,0x8019
+
  0017dd34: 3c038019 lui r3,0x8019                                |
  0017dd38: 2463f8cc addiu r3,r3,0xf8cc
+
  0017dd38: 2463f8cc addiu r3,r3,-0x0734                      |{{f/std|<nowiki>r3 = 0x8018f8cc (start of tiles data)</nowiki>}}
  0017dd3c: 00431821 addu r3,r2,r3
+
0017dd3c: 00431821 addu r3,r2,r3                            |{{f/adr|<nowiki>r3 = Target tile data</nowiki>}}
0017dd40: 90620006 lbu r2,0x0006(r3) Load misc. Tile Data
+
  0017dd40: 90620006 lbu r2,0x0006(r3)                        |{{f/load|<nowiki>r2 = Tile data byte 0x06 (shadow and targetable)</nowiki>}}
  0017dd44: 00000000 nop
+
  0017dd44: 00000000 nop                                      |
0017dd48: 30420003 andi r2,r2,0x0003
+
0017dd48: 30420003 andi r2,r2,0x0003                        |{{f/std|<nowiki>r2 <> 0x00 if tile is unselectable and/or not targetable</nowiki>}}
  0017dd4c: 14400055 bne r2,r0,0x0017dea4 Branch if Tile is unable to be selected
+
  0017dd4c: 14400055 bne r2,r0,0x0017dea4                      {{f/Cond|<nowiki>If tile is targetable/selectable</nowiki>}} /Else branch to {{f/loc|<nowiki>End</nowiki>}} With r2 = -0x02
  0017dd50: 2402fffe addiu r2,r0,0xfffe r2 = -2
+
  0017dd50: 2402fffe addiu r2,r0,0xfffe                        |{{f/std|<nowiki>r2 = -0x02</nowiki>}}
0017dd54: 30e20002 andi r2,r7,0x0002
+
  0017dd54: 30e20002 andi r2,r7,0x0002                            |{{f/std|<nowiki> r2 <> 0x00 if preset value has 0x02 enabled</nowiki>}} {{f/std|<nowiki>Slope check ? </nowiki>}}
  0017dd58: 10400010 beq r2,r0,0x0017dd9c Branch if Check isn't Slope
+
  0017dd58: 10400010 beq r2,r0,0x0017dd9c                          {{f/Cond|<nowiki>if r7 contains 0x02 flag</nowiki>}} /Else branch to loop
  0017dd5c: 00008821 addu r17,r0,r0 Counter = 0
+
  0017dd5c: 00008821 addu r17,r0,r0                                |{{f/std|<nowiki>r17 = 0x00 (counter for next loop)</nowiki>}}
  0017dd60: 90620003 lbu r2,0x0003(r3) Load Tile Height (slope + Depth)
+
  0017dd60: 90620003 lbu r2,0x0003(r3)                                |{{f/load|<nowiki>r2 = Load Tile Height + Depth byte</nowiki>}}
0017dd64: 00000000 nop
+
  0017dd64: 00000000 nop                                              |
0017dd68: 304200e0 andi r2,r2,0x00e0
+
  0017dd68: 304200e0 andi r2,r2,0x00e0                                |{{f/std|<nowiki>r2 <> 0 if tile has depth</nowiki>}}
  0017dd6c: 1440004d bne r2,r0,0x0017dea4 Branch if Tile has water
+
  0017dd6c: 1440004d bne r2,r0,0x0017dea4                              {{f/Cond|<nowiki>If tile has no depth</nowiki>}} /Else Branch to {{f/loc|<nowiki>End</nowiki>}} if Tile has water (with r2 = -0x02)
0017dd70: 2402fffe addiu r2,r0,0xfffe r2 = -2
+
  0017dd70: 2402fffe addiu r2,r0,0xfffe                                |{{f/std|<nowiki>r2 = -0x02</nowiki>}}
  0017dd74: 90620003 lbu r2,0x0003(r3) Load Tile Height (slope + Depth)
+
  0017dd74: 90620003 lbu r2,0x0003(r3)                                    |{{f/load|<nowiki>r2 = Load Tile Height + Depth byte</nowiki>}}
  0017dd78: 00000000 nop
+
  0017dd78: 00000000 nop                                                  |
0017dd7c: 3042001f andi r2,r2,0x001f Leave only slope
+
  0017dd7c: 3042001f andi r2,r2,0x001f                                    |{{f/std|<nowiki>r2 = Target height/2 only</nowiki>}}
  0017dd80: 28420003 slti r2,r2,0x0003
+
  0017dd80: 28420003 slti r2,r2,0x0003                                    |{{f/std|<nowiki>r2 = 0x01 if slope < 0x03</nowiki>}}
  0017dd84: 14400006 bne r2,r0,0x0017dda0 Branch if slope < 3
+
  0017dd84: 14400006 bne r2,r0,0x0017dda0                                  {{f/Cond|<nowiki>If slope >= 0x03 (not reachable ?)</nowiki>}} /Else branch to unit loop
  0017dd88: 00009821 addu r19,r0,r0 Unit Counter = 0
+
  0017dd88: 00009821 addu r19,r0,r0                                        |{{f/std|<nowiki>r19 = 0x00 (some counter for next loop)</nowiki>}}
  0017dd8c: 0805f7a9 j 0x0017dea4
+
  0017dd8c: 0805f7a9 j 0x0017dea4                  {{f/Cond|<nowiki>E</nowiki>}} {{f/Cond|<nowiki>E</nowiki>}} {{f/Cond|<nowiki>E</nowiki>}} {{f/jump|<nowiki>Jump to end (r2 = -0x02)</nowiki>}}
  0017dd90: 2402fffe addiu r2,r0,0xfffe r2 = -2
+
  0017dd90: 2402fffe addiu r2,r0,-0x0002                                      |{{f/std|<nowiki>r2 = -0x02</nowiki>}}
  0017dd94: 0805f7a9 j 0x0017dea4
+
  0017dd94: 0805f7a9 j 0x0017dea4                  {{f/std|<nowiki> Weird section - landing site of a branch command at 0x17dd94</nowiki>}}
0017dd98: 3082001f andi r2,r4,0x001f r2 = Mount ID
+
0017dd98: 3082001f andi r2,r4,0x001f            {{f/std|<nowiki> routine will return r2 = ridden unit</nowiki>}}
  0017dd9c: 00009821 addu r19,r0,r0 Unit Counter = 0
+
  0017dd9c: 00009821 addu r19,r0,r0                                {{f/Cond|<nowiki>Else</nowiki>}} {{f/std|<nowiki>r19 =0x00 (loop counter, refers to unit ID)</nowiki>}}
  0017dda0: 3c028019 lui r2,0x8019
+
  0017dda0: 3c028019 lui r2,0x8019                                    {{f/bloop|<nowiki>LOOP (Each unit) </nowiki>}}
  0017dda4: 244208cc addiu r2,r2,0x08cc
+
  0017dda4: 244208cc addiu r2,r2,0x08cc                                    |{{f/std|<nowiki>r2 = 0x801908cc (start of unit ID)</nowiki>}}
  0017dda8: 02628021 addu r16,r19,r2
+
  0017dda8: 02628021 addu r16,r19,r2                                       |{{f/std|<nowiki>r16 = Start of unit data + unit offset</nowiki>}}
  0017ddac: 92030001 lbu r3,0x0001(r16) Load Unit's Unit ID
+
  0017ddac: 92030001 lbu r3,0x0001(r16)                                    |{{f/load|<nowiki>r3 = Unit ID</nowiki>}}
0017ddb0: 340200ff ori r2,r0,0x00ff r2 = FF
+
  0017ddb0: 340200ff ori r2,r0,0x00ff                                      |{{f/std|<nowiki>r2 = 0xff</nowiki>}}
  0017ddb4: 10620036 beq r3,r2,0x0017de90 Branch if Unit doesn't exist
+
  0017ddb4: 10620036 beq r3,r2,0x0017de90                                  {{f/Cond|<nowiki>If unit Exist</nowiki>}} {{f/Cond|<nowiki>Else branch to </nowiki>{{f/loc|<nowiki>next unit</nowiki>}}<nowiki> (loop)</nowiki>}}
  0017ddb8: 32420051 andi r2,r18,0x0051
+
0017ddb8: 32420051 andi r2,r18,0x0051                                        |{{f/std|<nowiki>r2 = Preset and 0x51 (0x40 crystal, 0x10 transparent, 0x01 treasure)</nowiki>}}
0017ddbc: 10400018 beq r2,r0,0x0017de20 Branch if Check isn't Cryst/Trans/Treas
+
  0017ddbc: 10400018 beq r2,r0,0x0017de20                                      {{f/Cond|<nowiki>If Preset checks crystal/transparent treasure</nowiki>}} /Else Branch to chocobo section
0017ddc0: 32420040 andi r2,r18,0x0040
+
  0017ddc0: 32420040 andi r2,r18,0x0040                                            |{{f/std|<nowiki>r2 = Preset and 0x40 (crystal check)</nowiki>}}
  0017ddc4: 10400007 beq r2,r0,0x0017dde4 Branch if Check isn't Crystal
+
  0017ddc4: 10400007 beq r2,r0,0x0017dde4                                          {{f/Cond|<nowiki>If preset checks crystal</nowiki>}} /Else branch to treasure section
  0017ddc8: 32420001 andi r2,r18,0x0001
+
  0017ddc8: 32420001 andi r2,r18,0x0001                                            |{{f/std|<nowiki>r2 = preset and 0x01 (treasure check)</nowiki>}}
0017ddcc: 92020058 lbu r2,0x0058(r16) Load Unit's Current Statuses 1
+
  0017ddcc: 92020058 lbu r2,0x0058(r16)                                                |{{f/load|<nowiki>r2 = Units current status set 1</nowiki>}}
  0017ddd0: 00000000 nop
+
  0017ddd0: 00000000 nop                                                               |
0017ddd4: 30420040 andi r2,r2,0x0040
+
  0017ddd4: 30420040 andi r2,r2,0x0040                                                |{{f/std|<nowiki>r2 = 0x40 if unit has crystal</nowiki>}}
  0017ddd8: 14400012 bne r2,r0,0x0017de24 Branch if Unit has Crystal
+
  0017ddd8: 14400012 bne r2,r0,0x0017de24                                              {{f/Cond|<nowiki>If unit don't have crystal </nowiki>}} /Else branch to chocobo section
  0017dddc: 32420080 andi r2,r18,0x0080
+
  0017dddc: 32420080 andi r2,r18,0x0080                                                |{{f/std|<nowiki>r2 = 0x80 if preset check chocobo / Else 0x00</nowiki>}}
  0017dde0: 32420001 andi r2,r18,0x0001
+
  0017dde0: 32420001 andi r2,r18,0x0001                                                    |{{f/std|<nowiki>r2 = 0x01 if preset contains treasure check</nowiki>}}
0017dde4: 10400007 beq r2,r0,0x0017de04 Branch if Check isn't Treasure
+
  0017dde4: 10400007 beq r2,r0,0x0017de04                                          {{f/Cond|<nowiki>Else if preset check Treasure</nowiki>}} /Else branch to transparent section
  0017dde8: 32420010 andi r2,r18,0x0010
+
  0017dde8: 32420010 andi r2,r18,0x0010                                            |{{f/std|<nowiki>r2 = 0x10 if preset checks transparent</nowiki>}}
  0017ddec: 92020059 lbu r2,0x0059(r16) Load Unit's Current Statuses 2
+
  0017ddec: 92020059 lbu r2,0x0059(r16)                                                |{{f/load|<nowiki>r2 = Unit status set 2</nowiki>}}
  0017ddf0: 00000000 nop
+
  0017ddf0: 00000000 nop                                                               |
0017ddf4: 30420001 andi r2,r2,0x0001
+
  0017ddf4: 30420001 andi r2,r2,0x0001                                                |{{f/std|<nowiki>r2 = 0x01 if unit is treasure</nowiki>}}
0017ddf8: 1440000a bne r2,r0,0x0017de24 Branch if Unit has Treasure
+
  0017ddf8: 1440000a bne r2,r0,0x0017de24                                              {{f/Cond|<nowiki>If unit is not treasure</nowiki>}} /Else branch to chocobo section
0017ddfc: 32420080 andi r2,r18,0x0080
+
  0017ddfc: 32420080 andi r2,r18,0x0080                                                |{{f/std|<nowiki>r2 0x80 if preset check chocobo / Else 0x00</nowiki>}}
0017de00: 32420010 andi r2,r18,0x0010
+
  0017de00: 32420010 andi r2,r18,0x0010                                                    |{{f/std|<nowiki>r2 = 0x10 if preset checks transparent</nowiki>}}
  0017de04: 10400022 beq r2,r0,0x0017de90 Branch if Check isn't Transparent
+
  0017de04: 10400022 beq r2,r0,0x0017de90                                          {{f/Cond|<nowiki>Else if preset check transparent</nowiki>}} /Else goto {{f/loc|<nowiki>next unit</nowiki>}} (loop) - fail to find crystal/treasure while looking for it
  0017de08: 00000000 nop
+
  0017de08: 00000000 nop                                                              |
0017de0c: 9202005a lbu r2,0x005a(r16) Load Unit's Current Statuses 3
+
  0017de0c: 9202005a lbu r2,0x005a(r16)                                                |{{f/load|<nowiki>r2 = units current status set 3</nowiki>}}
  0017de10: 00000000 nop
+
  0017de10: 00000000 nop                                                               |
0017de14: 30420010 andi r2,r2,0x0010
+
  0017de14: 30420010 andi r2,r2,0x0010                                                |{{f/std|<nowiki>r2 = 0x10 is unit has transparent /else 0x00</nowiki>}}
  0017de18: 1040001d beq r2,r0,0x0017de90 Branch if Unit doesn't have Transparent
+
0017de18: 1040001d beq r2,r0,0x0017de90                                              {{f/Cond|<nowiki>If unit has transparent</nowiki>}} /Else goto {{f/loc|<nowiki>next unit</nowiki>}} (loop) - fail to find transparent  while looking for it
  0017de1c: 00000000 nop
+
0017de1c: 00000000 nop                                                              |
0017de20: 32420080 andi r2,r18,0x0080
+
0017de20: 32420080 andi r2,r18,0x0080                                        {{f/Cond|<nowiki>ELSE  - Not checking for status or Unit has the status checked for</nowiki>}} {{f/std|<nowiki> r2 = 0x80 if checking chocobo</nowiki>}}
0017de24: 10400005 beq r2,r0,0x0017de3c Branch if Check isn't Chocobo
+
0017de24: 10400005 beq r2,r0,0x0017de3c                                      {{f/Cond|<nowiki>If Checking for chocobo</nowiki>}} /Else branch to
  0017de28: 00000000 nop
+
0017de28: 00000000 nop                                                          |{{f/std|<nowiki> </nowiki>}}
  0017de2c: 0c05d0f2 jal 0x001743c8 Check if Unit can be Mounted
+
0017de2c: 0c05d0f2 jal 0x001743c8                                                |{{f/jal|Chocobo_Check|<nowiki>Chocobo_Check</nowiki>}}  returns r2 = 0x00 if not chocobo/not mountable
  0017de30: 02002021 addu r4,r16,r0 r4 = Unit's Data Pointer
+
0017de30: 02002021 addu r4,r16,r0                                                |{{f/std|<nowiki>r4 = unit data pointer</nowiki>}}
  0017de34: 10400016 beq r2,r0,0x0017de90 Branch if Unit isn't Mountable
+
0017de34: 10400016 beq r2,r0,0x0017de90                                          {{f/Cond|<nowiki>If unit is a mountable chocobo (may be already ridden)</nowiki>}} /Else Go to {{f/loc|<nowiki>next unit</nowiki>}} (loop)
  0017de38: 00000000 nop
+
0017de38: 00000000 nop                                                              |{{f/std|<nowiki> </nowiki>}}
  0017de3c: 92020047 lbu r2,0x0047(r16) Load Unit's X Coordinate
+
0017de3c: 92020047 lbu r2,0x0047(r16)                                        {{f/Cond|<nowiki>Else</nowiki>}} {{f/load|<nowiki>r2 = Unit X coord.</nowiki>}}  (You're here if you check nothing or have found what you're checking)
  0017de40: 00000000 nop
+
0017de40: 00000000 nop                                                      |
0017de44: 14540012 bne r2,r20,0x0017de90 Branch if X != Moving Unit's X
+
0017de44: 14540012 bne r2,r20,0x0017de90                                    {{f/Cond|<nowiki>If Unit X coord = Attacker X target coord.</nowiki>}} /Else goto {{f/loc|<nowiki>next unit</nowiki>}} (loop)
  0017de48: 00000000 nop
+
0017de48: 00000000 nop                                                          |{{f/std|<nowiki> </nowiki>}}
0017de4c: 92020048 lbu r2,0x0048(r16) Load Unit's Y Coordinate
+
0017de4c: 92020048 lbu r2,0x0048(r16)                                            |{{f/load|<nowiki>r2 = Units Y coord.</nowiki>}}
  0017de50: 00000000 nop
+
0017de50: 00000000 nop                                                          |
0017de54: 1455000e bne r2,r21,0x0017de90 Branch if Y != Moving Unit's Y
+
0017de54: 1455000e bne r2,r21,0x0017de90                                        {{f/Cond|<nowiki>If Unit Y coord = Attacker Y target coord.</nowiki>}} /Else goto {{f/loc|<nowiki>next unit</nowiki>}} (loop)
  0017de58: 00000000 nop
+
0017de58: 00000000 nop                                                              |{{f/std|<nowiki> </nowiki>}}
  0017de5c: 96020048 lhu r2,0x0048(r16) Load Unit's Y + Map Level/Facing
+
0017de5c: 96020048 lhu r2,0x0048(r16)                                                |{{f/load|<nowiki>r2 = Unit's Y + Map elevation/Facing (halfword)</nowiki>}}
  0017de60: 00000000 nop
+
0017de60: 00000000 nop                                                              |
0017de64: 000213c2 srl r2,r2,0x0f Y Data / 0x8000 (Map Level)
+
0017de64: 000213c2 srl r2,r2,0x0f                                                    |{{f/std|<nowiki>r2 = higher bit of the halfword (elevation)</nowiki>}}
  0017de68: 14560009 bne r2,r22,0x0017de90 Branch if Map Level != Map Level
+
0017de68: 14560009 bne r2,r22,0x0017de90                                            {{f/Cond|<nowiki> If unit elevation = Attacker target elevation</nowiki>}} /Else goto {{f/loc|<nowiki>next unit</nowiki>}} (loop)
  0017de6c: 00000000 nop
+
0017de6c: 00000000 nop                                                                  |{{f/std|<nowiki> </nowiki>}}
  0017de70: 92040182 lbu r4,0x0182(r16) Load Unit's Mount Data
+
0017de70: 92040182 lbu r4,0x0182(r16)                                                    |{{f/load|<nowiki>r4 = Unit's mount data</nowiki>}}
  0017de74: 00000000 nop
+
0017de74: 00000000 nop                                                                  |
0017de78: 308200ff andi r2,r4,0x00ff
+
0017de78: 308200ff andi r2,r4,0x00ff                                                    |{{f/std|<nowiki>r4 = last byte of r4 (security check ?)</nowiki>}}
0017de7c: 2c420080 sltiu r2,r2,0x0080
+
0017de7c: 2c420080 sltiu r2,r2,0x0080                                                    |{{f/std|<nowiki>r2 = 0x01 if mount info < 0x80 - everything but "is riding")</nowiki>}}
  0017de80: 1040ffc4 beq r2,r0,0x0017dd94 Branch if Riding a Unit is present
+
0017de80: 1040ffc4 beq r2,r0,0x0017dd94                                                  {{f/Cond|<nowiki>If Unit is not riding</nowiki>}} /Else branch (above) then jump to end with r2 = ID of ridden unit
  0017de84: 02201021 addu r2,r17,r0 r2 = Counter
+
0017de84: 02201021 addu r2,r17,r0                                                            |{{f/std|<nowiki>r2 = counter (unit ID)</nowiki>}}
0017de88: 0805f7a9 j 0x0017dea4
+
0017de88: 0805f7a9 j 0x0017dea4                                                              {{f/jump|<nowiki>Jump to </nowiki>{{f/loc|<nowiki>End</nowiki>}}<nowiki> - abort looping</nowiki>}}
  0017de8c: 00000000 nop
+
0017de8c: 00000000 nop                                                                      |
  0017de90: 26310001 addiu r17,r17,0x0001 Counter ++
+
0017de90: 26310001 addiu r17,r17,0x0001                                  {{f/Cond|<nowiki>Else (unit don' exist or none of the checks find the good unit)</nowiki>}}
0017de94: 2a220015 slti r2,r17,0x0015
+
0017de94: 2a220015 slti r2,r17,0x0015                                    |
0017de98: 1440ffc1 bne r2,r0,0x0017dda0 Branch if Counter < 21
+
0017de98: 1440ffc1 bne r2,r0,0x0017dda0                              {{f/eloop|<nowiki>Loop (next unit)</nowiki>}}
0017de9c: 267301c0 addiu r19,r19,0x01c0 Unit Data Pointer += 0x1c0
+
0017de9c: 267301c0 addiu r19,r19,0x01c0                                  |{{f/std|<nowiki>r19 = next unit data pointer</nowiki>}}
0017dea0: 2402ffff addiu r2,r0,0xffff r2 = -1 (unit doesn't exist)
+
0017dea0: 2402ffff addiu r2,r0,0xffff                                |{{f/std|<nowiki>r2 = -1 (unit doesn't exist)</nowiki>}}
  0017dea4: 8fbf002c lw r31,0x002c(r29)
+
  0017dea4: 8fbf002c lw r31,0x002c(r29)       END
  0017dea8: 8fb60028 lw r22,0x0028(r29)
+
  0017dea8: 8fb60028 lw r22,0x0028(r29)                              
  0017deac: 8fb50024 lw r21,0x0024(r29)
+
  0017deac: 8fb50024 lw r21,0x0024(r29)                              
  0017deb0: 8fb40020 lw r20,0x0020(r29)
+
  0017deb0: 8fb40020 lw r20,0x0020(r29)                              
  0017deb4: 8fb3001c lw r19,0x001c(r29)
+
  0017deb4: 8fb3001c lw r19,0x001c(r29)                              
  0017deb8: 8fb20018 lw r18,0x0018(r29)
+
  0017deb8: 8fb20018 lw r18,0x0018(r29)                              
  0017debc: 8fb10014 lw r17,0x0014(r29)
+
  0017debc: 8fb10014 lw r17,0x0014(r29)                              
  0017dec0: 8fb00010 lw r16,0x0010(r29)
+
  0017dec0: 8fb00010 lw r16,0x0010(r29)                              
  0017dec4: 27bd0030 addiu r29,r29,0x0030
+
  0017dec4: 27bd0030 addiu r29,r29,0x0030                            
  0017dec8: 03e00008 jr r31
+
  0017dec8: 03e00008 jr r31                                          
 
  0017decc: 00000000 nop
 
  0017decc: 00000000 nop
 +
=== Return locations ===
 +
0017dc98: [[Get_ID_of_Unit_if_Tile_is_Targetable]]              r7 = 0x00 (just looking for Unit ID at location)
 +
0017fe48: [[Set_Rider/Mount%27s_X/Y_Data]]                        r7 = 0x80 (chocobo)
 +
0017fff0: [[Set_target_for_mounted_unit,_move_find_item/trap]]  r7 = 0x41 (Crystal - treasure)
 +
00180314: [[Set_map_Item/trap_data]]                            r7 = 0x10 (transparent)
 +
00180578: [[Generate_Crystal_or_Treasure]]                      r7 = 0x41 (crystal - treasure)

Revision as of 13:11, 4 December 2021

Duplicated here Find_Unit_at_Specified_Coordinates (programmers friendly formatting)
----------------------------------------------------------------
Parameters : r4 = X coordinate
             r5 = Y coordinates
             r6 = Elevation (0x00 or 0x01)	
             r7 = Preset value - specify conditions to check
                   0x80 - check for mountable chocobo
                   0x41 - check for crystal and treasure
                   0x10 - check for transparent unit
                   0x00 - check for a unit without conditions	
					
Returns : r2 = -0x02 if coordinates are invalid			  
          r2 = -0x01 if there's no unit matching r7 at coordinates
          r2 = Unit ID if there's a unit matching r7
------------------------------------------------------------------------------
r4 = X r5 = Y r6 = elevation r7 = preset value
0017dca8: 27bdffd0 addiu r29,r29,0xffd0
0017dcac: afb40020 sw r20,0x0020(r29)       |
0017dcb0: 0080a021 addu r20,r4,r0           |r20 = Attacker current action target  X Coordinate
0017dcb4: afb50024 sw r21,0x0024(r29)       |
0017dcb8: 00a0a821 addu r21,r5,r0           |r21 = Attacker current action target  y Coordinate
0017dcbc: afb60028 sw r22,0x0028(r29)       |
0017dcc0: 00c0b021 addu r22,r6,r0           |r22 =  Attacker current action target map elevation
0017dcc4: afb20018 sw r18,0x0018(r29)       |
0017dcc8: 00e09021 addu r18,r7,r0           |r18 = Preset Value
0017dccc: afbf002c sw r31,0x002c(r29)       |
0017dcd0: afb3001c sw r19,0x001c(r29)       |
0017dcd4: afb10014 sw r17,0x0014(r29)       |
0017dcd8: 0680002c bltz r20,0x0017dd8c      #If Target X coordinate >= 0 /Else branch to End  (branch to a jump to end with r2 = -0x02)
0017dcdc: afb00010 sw r16,0x0010(r29)            |  
0017dce0: 3c03800e lui r3,0x800e                 |
0017dce4: 90634e9c lbu r3,0x4e9c(r3)             |r3 = Map Max X Coordinate
0017dce8: 00000000 nop                           |
0017dcec: 0283102a slt r2,r20,r3                 |r2 = 0x01 if Unit X coord. < Map max X
0017dcf0: 10400026 beq r2,r0,0x0017dd8c          #If Unit X is in the map /Else branch to End (branch to a jump to end with r2 = -0x02)
0017dcf4: 00000000 nop                               | 
0017dcf8: 06a0006a bltz r21,0x0017dea4               #If Unit Y coord. >= 0x00 /Else branch to End with r2 = -0x02
0017dcfc: 2402fffe addiu r2,r0,-0x0002               |r2 = -0x02
0017dd00: 3c02800e lui r2,0x800e                         | 
0017dd04: 90424ea0 lbu r2,0x4ea0(r2)                     |r4 =Map Max Y Coordinate
0017dd08: 00000000 nop                                   |
0017dd0c: 02a2102a slt r2,r21,r2                         |r2 = 0x01 if Unit Y coord < map max Y
0017dd10: 1040001e beq r2,r0,0x0017dd8c                  #If unit is in the map /Else branch to End (branch to a jump to end with r2 = -0x02)
0017dd14: 2ec20002 sltiu r2,r22,0x0002                       |r2 = 0x01 if Unit Map elevation < 0x02
0017dd18: 1040001c beq r2,r0,0x0017dd8c                      #If Unit Map Elevation  < 0x02 /Else branch to End (branch to a jump to end with r2 = -0x02)
0017dd1c: 02a30018 mult r21,r3                                   |Max X * Y
0017dd20: 00161200 sll r2,r22,0x08                               |r2 = Map elevation * 0x100
0017dd24: 00001812 mflo r3                                       |r3 = Map Max X *Unit  Y coord (Y modified)
0017dd28: 00431021 addu r2,r2,r3                                 |r2 = Y modified + Map elevation * 0x100
0017dd2c: 00541021 addu r2,r2,r20                                |r2 = Tile ID r2 = Y modified + X + Map elevation * 0x100
0017dd30: 000210c0 sll r2,r2,0x03                                |r2=Tile ID * 8 (size of tiles data)
0017dd34: 3c038019 lui r3,0x8019                                 |
0017dd38: 2463f8cc addiu r3,r3,-0x0734                       |r3 = 0x8018f8cc (start of tiles data)
0017dd3c: 00431821 addu r3,r2,r3                             |r3 = Target tile data
0017dd40: 90620006 lbu r2,0x0006(r3)                         |r2 = Tile data byte 0x06 (shadow and targetable)
0017dd44: 00000000 nop                                       |
0017dd48: 30420003 andi r2,r2,0x0003                         |r2 <> 0x00 if tile is unselectable and/or not targetable
0017dd4c: 14400055 bne r2,r0,0x0017dea4                      #If tile is targetable/selectable /Else branch to End With r2 = -0x02
0017dd50: 2402fffe addiu r2,r0,0xfffe                        |r2 = -0x02
0017dd54: 30e20002 andi r2,r7,0x0002                             | r2 <> 0x00 if preset value has 0x02 enabled Slope check ? 
0017dd58: 10400010 beq r2,r0,0x0017dd9c                          #if r7 contains 0x02 flag /Else branch to loop
0017dd5c: 00008821 addu r17,r0,r0                                |r17 = 0x00 (counter for next loop)
0017dd60: 90620003 lbu r2,0x0003(r3)                                 |r2 = Load Tile Height + Depth byte
0017dd64: 00000000 nop                                               |
0017dd68: 304200e0 andi r2,r2,0x00e0                                 |r2 <> 0 if tile has depth
0017dd6c: 1440004d bne r2,r0,0x0017dea4                              #If tile has no depth /Else Branch to End if Tile has water (with r2 = -0x02)
0017dd70: 2402fffe addiu r2,r0,0xfffe                                |r2 = -0x02
0017dd74: 90620003 lbu r2,0x0003(r3)                                     |r2 = Load Tile Height + Depth byte
0017dd78: 00000000 nop                                                   |
0017dd7c: 3042001f andi r2,r2,0x001f                                     |r2 = Target height/2 only
0017dd80: 28420003 slti r2,r2,0x0003                                     |r2 = 0x01 if slope < 0x03
0017dd84: 14400006 bne r2,r0,0x0017dda0                                  #If slope >= 0x03 (not reachable ?) /Else branch to unit loop
0017dd88: 00009821 addu r19,r0,r0                                        |r19 = 0x00 (some counter for next loop)
0017dd8c: 0805f7a9 j 0x0017dea4                  #E #E #E >>Jump to end (r2 = -0x02)
0017dd90: 2402fffe addiu r2,r0,-0x0002                                       |r2 = -0x02
0017dd94: 0805f7a9 j 0x0017dea4                   Weird section - landing site of a branch command at 0x17dd94
0017dd98: 3082001f andi r2,r4,0x001f              routine will return r2 = ridden unit
0017dd9c: 00009821 addu r19,r0,r0                                #Else r19 =0x00 (loop counter, refers to unit ID)
0017dda0: 3c028019 lui r2,0x8019                                     @LOOP (Each unit) 
0017dda4: 244208cc addiu r2,r2,0x08cc                                    |r2 = 0x801908cc (start of unit ID)
0017dda8: 02628021 addu r16,r19,r2                                       |r16 = Start of unit data + unit offset
0017ddac: 92030001 lbu r3,0x0001(r16)                                    |r3 = Unit ID
0017ddb0: 340200ff ori r2,r0,0x00ff                                      |r2 = 0xff
0017ddb4: 10620036 beq r3,r2,0x0017de90                                  #If unit Exist #Else branch to next unit (loop)
0017ddb8: 32420051 andi r2,r18,0x0051                                        |r2 = Preset and 0x51 (0x40 crystal, 0x10 transparent, 0x01 treasure)
0017ddbc: 10400018 beq r2,r0,0x0017de20                                      #If Preset checks crystal/transparent treasure /Else Branch to chocobo section
0017ddc0: 32420040 andi r2,r18,0x0040                                            |r2 = Preset and 0x40 (crystal check)
0017ddc4: 10400007 beq r2,r0,0x0017dde4                                          #If preset checks crystal /Else branch to treasure section
0017ddc8: 32420001 andi r2,r18,0x0001                                            |r2 = preset and 0x01 (treasure check)
0017ddcc: 92020058 lbu r2,0x0058(r16)                                                |r2 = Units current status set 1
0017ddd0: 00000000 nop                                                               |
0017ddd4: 30420040 andi r2,r2,0x0040                                                 |r2 = 0x40 if unit has crystal
0017ddd8: 14400012 bne r2,r0,0x0017de24                                              #If unit don't have crystal  /Else branch to chocobo section
0017dddc: 32420080 andi r2,r18,0x0080                                                |r2 =  0x80 if preset check chocobo / Else 0x00
0017dde0: 32420001 andi r2,r18,0x0001                                                    |r2 = 0x01 if preset contains treasure check
0017dde4: 10400007 beq r2,r0,0x0017de04                                          #Else if preset check Treasure /Else branch to transparent section
0017dde8: 32420010 andi r2,r18,0x0010                                            |r2 = 0x10 if preset checks transparent
0017ddec: 92020059 lbu r2,0x0059(r16)                                                |r2 = Unit status set 2
0017ddf0: 00000000 nop                                                               |
0017ddf4: 30420001 andi r2,r2,0x0001                                                 |r2 = 0x01 if unit is treasure
0017ddf8: 1440000a bne r2,r0,0x0017de24                                              #If unit is not treasure /Else branch to chocobo section
0017ddfc: 32420080 andi r2,r18,0x0080                                                |r2 =  0x80 if preset check chocobo / Else 0x00
0017de00: 32420010 andi r2,r18,0x0010                                                    |r2 = 0x10 if preset checks transparent
0017de04: 10400022 beq r2,r0,0x0017de90                                          #Else if preset check transparent /Else goto next unit (loop) - fail to find crystal/treasure while looking for it
0017de08: 00000000 nop                                                               |
0017de0c: 9202005a lbu r2,0x005a(r16)                                                |r2 = units current status set 3
0017de10: 00000000 nop                                                               |
0017de14: 30420010 andi r2,r2,0x0010                                                 |r2 = 0x10 is unit has transparent /else 0x00
0017de18: 1040001d beq r2,r0,0x0017de90                                              #If unit has transparent /Else goto next unit (loop) - fail to find transparent  while looking for it
0017de1c: 00000000 nop                                                               |
0017de20: 32420080 andi r2,r18,0x0080                                        #ELSE  - Not checking for status or Unit has the status checked for  r2 = 0x80 if checking chocobo
0017de24: 10400005 beq r2,r0,0x0017de3c                                      #If Checking for chocobo /Else branch to 
0017de28: 00000000 nop                                                           | 
0017de2c: 0c05d0f2 jal 0x001743c8                                                |-->Chocobo_Check  returns r2 = 0x00 if not chocobo/not mountable
0017de30: 02002021 addu r4,r16,r0                                                |r4 = unit data pointer
0017de34: 10400016 beq r2,r0,0x0017de90                                          #If unit is a mountable chocobo (may be already ridden) /Else Go to next unit (loop)
0017de38: 00000000 nop                                                               | 
0017de3c: 92020047 lbu r2,0x0047(r16)                                        #Else r2 = Unit X coord.  (You're here if you check nothing or have found what you're checking)
0017de40: 00000000 nop                                                       |
0017de44: 14540012 bne r2,r20,0x0017de90                                     #If Unit X coord = Attacker X target coord. /Else goto next unit (loop) 
0017de48: 00000000 nop                                                           | 
0017de4c: 92020048 lbu r2,0x0048(r16)                                            |r2 = Units Y coord.
0017de50: 00000000 nop                                                           |
0017de54: 1455000e bne r2,r21,0x0017de90                                         #If Unit Y coord = Attacker Y target coord. /Else goto next unit (loop) 
0017de58: 00000000 nop                                                               | 
0017de5c: 96020048 lhu r2,0x0048(r16)                                                |r2 = Unit's Y + Map elevation/Facing (halfword)
0017de60: 00000000 nop                                                               |
0017de64: 000213c2 srl r2,r2,0x0f                                                    |r2 = higher bit of the halfword (elevation)
0017de68: 14560009 bne r2,r22,0x0017de90                                             # If unit elevation = Attacker target elevation /Else goto next unit (loop) 
0017de6c: 00000000 nop                                                                   | 
0017de70: 92040182 lbu r4,0x0182(r16)                                                    |r4 = Unit's mount data
0017de74: 00000000 nop                                                                   |
0017de78: 308200ff andi r2,r4,0x00ff                                                     |r4 = last byte of r4 (security check ?)
0017de7c: 2c420080 sltiu r2,r2,0x0080                                                    |r2 = 0x01 if mount info < 0x80 - everything but "is riding")
0017de80: 1040ffc4 beq r2,r0,0x0017dd94                                                  #If Unit is not riding /Else branch (above) then jump to end with r2 = ID of ridden unit
0017de84: 02201021 addu r2,r17,r0                                                            |r2 = counter (unit ID)
0017de88: 0805f7a9 j 0x0017dea4                                                              >>Jump to End - abort looping
0017de8c: 00000000 nop                                                                       |
0017de90: 26310001 addiu r17,r17,0x0001                                  #Else (unit don' exist or none of the checks find the good unit)
0017de94: 2a220015 slti r2,r17,0x0015                                    |
0017de98: 1440ffc1 bne r2,r0,0x0017dda0                              Λ Loop (next unit)
0017de9c: 267301c0 addiu r19,r19,0x01c0                                  |r19 = next unit data pointer
0017dea0: 2402ffff addiu r2,r0,0xffff                                |r2 = -1 (unit doesn't exist)
0017dea4: 8fbf002c lw r31,0x002c(r29)        END
0017dea8: 8fb60028 lw r22,0x0028(r29)                                
0017deac: 8fb50024 lw r21,0x0024(r29)                                
0017deb0: 8fb40020 lw r20,0x0020(r29)                                
0017deb4: 8fb3001c lw r19,0x001c(r29)                                
0017deb8: 8fb20018 lw r18,0x0018(r29)                                
0017debc: 8fb10014 lw r17,0x0014(r29)                                
0017dec0: 8fb00010 lw r16,0x0010(r29)                                
0017dec4: 27bd0030 addiu r29,r29,0x0030                              
0017dec8: 03e00008 jr r31                                            
0017decc: 00000000 nop

Return locations

0017dc98: Get_ID_of_Unit_if_Tile_is_Targetable              r7 = 0x00 (just looking for Unit ID at location)
0017fe48: Set_Rider/Mount's_X/Y_Data                        r7 = 0x80 (chocobo)
0017fff0: Set_target_for_mounted_unit,_move_find_item/trap  r7 = 0x41 (Crystal - treasure)
00180314: Set_map_Item/trap_data                            r7 = 0x10 (transparent) 
00180578: Generate_Crystal_or_Treasure                      r7 = 0x41 (crystal - treasure)