diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index af5c3c8500..18bfbb9be4 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3616,13 +3616,12 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords) && ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP)) { TileElement* pathsByDir[4]; - constexpr TileCoordsXY DirOffsets[4] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } }; bool keepOrientation = false; for (int8_t i = 0; i < 4; i++) { - pathsByDir[i] = map_get_footpath_element( - (mapCoords->x >> 5) + DirOffsets[i].x, (mapCoords->y >> 5) + DirOffsets[i].y, z >> 3); + pathsByDir[i] = map_get_footpath_element({ mapCoords->x + (DirectionOffsets[i].x * COORDS_XY_STEP), + mapCoords->y + (DirectionOffsets[i].y * COORDS_XY_STEP), z }); if (pathsByDir[i] && (pathsByDir[i])->AsPath()->IsSloped() && (pathsByDir[i])->AsPath()->GetSlopeDirection() != i) { @@ -3632,8 +3631,9 @@ void ride_construction_toolupdate_construct(ScreenCoordsXY screenCoords) // Sloped path on the level below if (!pathsByDir[i]) { - pathsByDir[i] = map_get_footpath_element( - (mapCoords->x >> 5) + DirOffsets[i].x, (mapCoords->y >> 5) + DirOffsets[i].y, (z >> 3) - 2); + pathsByDir[i] = map_get_footpath_element({ mapCoords->x + (DirectionOffsets[i].x * COORDS_XY_STEP), + mapCoords->y + (DirectionOffsets[i].y * COORDS_XY_STEP), + z - PATH_HEIGHT_STEP }); if (pathsByDir[i] && (!(pathsByDir[i])->AsPath()->IsSloped() diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index ed72ff7cb6..67eeb5df84 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -413,10 +413,10 @@ private: { auto direction = pathElement->GetSlopeDirection(); int32_t z = pathElement->GetBaseZ(); - wall_remove_intersecting_walls({ _loc, z, z + (6 * 8) }, direction_reverse(direction)); - wall_remove_intersecting_walls({ _loc, z, z + (6 * 8) }, direction); + wall_remove_intersecting_walls({ _loc, z, z + (6 * COORDS_Z_STEP) }, direction_reverse(direction)); + wall_remove_intersecting_walls({ _loc, z, z + (6 * COORDS_Z_STEP) }, direction); // Removing walls may have made the pointer invalid, so find it again - auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, z); + auto tileElement = map_get_footpath_element(CoordsXYZ(_loc, z)); if (tileElement == nullptr) { log_error("Something went wrong. Could not refind footpath."); diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index e2bac14c88..89d296bb22 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -111,7 +111,7 @@ private: { bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST; - TileElement* tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); + TileElement* tileElement = map_get_footpath_element(_loc); TileElement* footpathElement = nullptr; if (tileElement != nullptr) { diff --git a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp index a7332b03bc..b5580b8f2e 100644 --- a/src/openrct2/actions/FootpathSceneryPlaceAction.hpp +++ b/src/openrct2/actions/FootpathSceneryPlaceAction.hpp @@ -73,7 +73,7 @@ public: return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_POSITION_THIS_HERE, STR_TOO_HIGH); } - auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); + auto tileElement = map_get_footpath_element(_loc); if (tileElement == nullptr) { log_error("Could not find path element."); @@ -143,7 +143,7 @@ public: res->Position = _loc; res->Expenditure = ExpenditureType::Landscaping; - auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); + auto tileElement = map_get_footpath_element(_loc); auto pathElement = tileElement->AsPath(); if (pathElement == nullptr) diff --git a/src/openrct2/actions/FootpathSceneryRemoveAction.hpp b/src/openrct2/actions/FootpathSceneryRemoveAction.hpp index 14e68b21d2..1c4ceb225f 100644 --- a/src/openrct2/actions/FootpathSceneryRemoveAction.hpp +++ b/src/openrct2/actions/FootpathSceneryRemoveAction.hpp @@ -67,7 +67,7 @@ public: return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_REMOVE_THIS, STR_TOO_HIGH); } - auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); + auto tileElement = map_get_footpath_element(_loc); if (tileElement == nullptr) { log_warning("Could not find path element."); @@ -94,7 +94,7 @@ public: GameActionResult::Ptr Execute() const override { - auto tileElement = map_get_footpath_element(_loc.x / 32, _loc.y / 32, _loc.z / 8); + auto tileElement = map_get_footpath_element(_loc); auto pathElement = tileElement->AsPath(); if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index ebe91e2359..c8bc435f6e 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1175,7 +1175,8 @@ void ride_clear_blocked_tiles(Ride* ride) if (element->GetType() == TILE_ELEMENT_TYPE_TRACK && element->AsTrack()->GetRideIndex() == ride->id) { // Unblock footpath element that is at same position - auto footpathElement = map_get_footpath_element(x, y, element->base_height); + auto footpathElement = map_get_footpath_element( + TileCoordsXYZ{ x, y, element->base_height }.ToCoordsXYZ()); if (footpathElement != nullptr) { footpathElement->AsPath()->SetIsBlockedByVehicle(false); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3602b7f0db..2d42a5b897 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -111,14 +111,14 @@ static bool entrance_has_direction(TileElement* tileElement, int32_t direction) return entrance_get_directions(tileElement) & (1 << (direction & 3)); } -TileElement* map_get_footpath_element(int32_t x, int32_t y, int32_t z) +TileElement* map_get_footpath_element(CoordsXYZ coords) { - TileElement* tileElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY()); + TileElement* tileElement = map_get_first_element_at(coords); do { if (tileElement == nullptr) break; - if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->base_height == z) + if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH && tileElement->GetBaseZ() == coords.z) return tileElement; } while (!(tileElement++)->IsLastForTile()); diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 42a6552f2b..8d4eabc7cd 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -174,7 +174,7 @@ extern const CoordsXY DirectionOffsets[NumOrthogonalDirections]; extern const LocationXY16 BinUseOffsets[NumOrthogonalDirections]; extern const LocationXY16 BenchUseOffsets[NumOrthogonalDirections * 2]; -TileElement* map_get_footpath_element(int32_t x, int32_t y, int32_t z); +TileElement* map_get_footpath_element(CoordsXYZ coords); struct PathElement; PathElement* map_get_footpath_element_slope(int32_t x, int32_t y, int32_t z, int32_t slope); void footpath_interrupt_peeps(int32_t x, int32_t y, int32_t z); diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index 8dd01ae916..01a2146fbb 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -117,7 +117,7 @@ protected: // Check that the peep is still on a footpath. Use next_z instead of pos->z here because pos->z will change // when the peep is halfway up a slope, but next_z will not change until they move to the next tile. - EXPECT_NE(map_get_footpath_element(pos->x, pos->y, peep->next_z), nullptr); + EXPECT_NE(map_get_footpath_element(TileCoordsXYZ{ pos->x, pos->y, peep->next_z }.ToCoordsXYZ()), nullptr); } // Clean up the peep, because we're reusing this loaded context for all tests. diff --git a/test/tests/TileElements.cpp b/test/tests/TileElements.cpp index c75e07f19d..ecf7ead5e9 100644 --- a/test/tests/TileElements.cpp +++ b/test/tests/TileElements.cpp @@ -51,7 +51,7 @@ std::shared_ptr TileElementWantsFootpathConnection::_context; TEST_F(TileElementWantsFootpathConnection, FlatPath) { // Flat paths want to connect to other paths in any direction - const TileElement* const pathElement = map_get_footpath_element(19, 18, 14); + const TileElement* const pathElement = map_get_footpath_element(TileCoordsXYZ{ 19, 18, 14 }.ToCoordsXYZ()); ASSERT_NE(pathElement, nullptr); EXPECT_TRUE(tile_element_wants_path_connection_towards({ 19, 18, 14, 0 }, nullptr)); EXPECT_TRUE(tile_element_wants_path_connection_towards({ 19, 18, 14, 1 }, nullptr)); @@ -63,7 +63,7 @@ TEST_F(TileElementWantsFootpathConnection, FlatPath) TEST_F(TileElementWantsFootpathConnection, SlopedPath) { // Sloped paths only want to connect in two directions, of which is one at a higher offset - const TileElement* const slopedPathElement = map_get_footpath_element(18, 18, 14); + const TileElement* const slopedPathElement = map_get_footpath_element(TileCoordsXYZ{ 18, 18, 14 }.ToCoordsXYZ()); ASSERT_NE(slopedPathElement, nullptr); ASSERT_TRUE(slopedPathElement->AsPath()->IsSloped()); // Bottom and top of sloped path want a path connection