Check if another unit is on the same Tile
Jump to navigation
Jump to search
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)