From 7cf03d3e412397d09e0f0c09ad4eaa35fa59d2bf Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Sat, 4 Jan 2020 08:33:19 -0300 Subject: [PATCH] Use CoordsXY on footpath_remove_edges_at() --- src/openrct2/actions/FootpathPlaceAction.hpp | 4 ++-- src/openrct2/actions/FootpathRemoveAction.hpp | 2 +- .../actions/RideEntranceExitRemoveAction.hpp | 2 +- src/openrct2/actions/TrackRemoveAction.hpp | 2 +- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/world/Footpath.cpp | 12 +++++++----- src/openrct2/world/Footpath.h | 2 +- src/openrct2/world/Location.hpp | 6 ++++++ src/openrct2/world/Map.cpp | 2 +- 10 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index f72a0f2b67..6d37b04859 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -182,7 +182,7 @@ private: if (!(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)) { - footpath_remove_edges_at(_loc.x, _loc.y, (TileElement*)pathElement); + footpath_remove_edges_at(_loc, reinterpret_cast(pathElement)); } pathElement->SetPathEntryIndex(_type); @@ -358,7 +358,7 @@ private: if (!(GetFlags() & GAME_COMMAND_FLAG_PATH_SCENERY)) { - footpath_remove_edges_at(_loc.x, _loc.y, tileElement); + footpath_remove_edges_at(_loc, tileElement); } if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index 5ad5749bbb..f3b3df8898 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -91,7 +91,7 @@ public: { res->Cost += bannerRes->Cost; } - footpath_remove_edges_at(_loc.x, _loc.y, footpathElement); + footpath_remove_edges_at(_loc, footpathElement); map_invalidate_tile_full(_loc); tile_element_remove(footpathElement); footpath_update_queue_chains(); diff --git a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp index 9298c7f1f6..a1b2d86d79 100644 --- a/src/openrct2/actions/RideEntranceExitRemoveAction.hpp +++ b/src/openrct2/actions/RideEntranceExitRemoveAction.hpp @@ -172,7 +172,7 @@ public: footpath_queue_chain_reset(); maze_entrance_hedge_replacement(_loc.x, _loc.y, tileElement); - footpath_remove_edges_at(_loc.x, _loc.y, tileElement); + footpath_remove_edges_at(_loc, tileElement); tile_element_remove(tileElement); diff --git a/src/openrct2/actions/TrackRemoveAction.hpp b/src/openrct2/actions/TrackRemoveAction.hpp index ea757e56b4..6517abd375 100644 --- a/src/openrct2/actions/TrackRemoveAction.hpp +++ b/src/openrct2/actions/TrackRemoveAction.hpp @@ -434,7 +434,7 @@ public: footpath_queue_chain_reset(); if (!gCheatsDisableClearanceChecks || !(tileElement->IsGhost())) { - footpath_remove_edges_at(mapLoc.x, mapLoc.y, tileElement); + footpath_remove_edges_at(mapLoc, tileElement); } tile_element_remove(tileElement); sub_6CB945(ride); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index c8bc435f6e..09bd2c100f 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7089,7 +7089,7 @@ void sub_6CB945(Ride* ride) { footpath_queue_chain_reset(); maze_entrance_hedge_replacement(location.x, location.y, tileElement); - footpath_remove_edges_at(location.x, location.y, tileElement); + footpath_remove_edges_at(location, tileElement); footpath_update_queue_chains(); map_invalidate_tile_full(location); tile_element_remove(tileElement); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index a8ed22297c..797d7c265b 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1192,7 +1192,7 @@ static bool TrackDesignPlaceSceneryElement( } footpath_queue_chain_reset(); - footpath_remove_edges_at(mapCoord.x, mapCoord.y, reinterpret_cast(pathElement)); + footpath_remove_edges_at(mapCoord, reinterpret_cast(pathElement)); flags = GAME_COMMAND_FLAG_APPLY; if (_trackDesignPlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 44e3d907d9..c787f0d683 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -2130,7 +2130,7 @@ static void footpath_fix_corners_around(int32_t x, int32_t y, TileElement* pathE * @param x x-coordinate in units (not tiles) * @param y y-coordinate in units (not tiles) */ -void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) +void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement) { if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK) { @@ -2140,7 +2140,7 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) return; } - footpath_update_queue_entrance_banner({ x, y }, tileElement); + footpath_update_queue_entrance_banner(footpathPos, tileElement); bool fixCorners = false; for (uint8_t direction = 0; direction < 4; direction++) @@ -2163,12 +2163,13 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) // When clearance checks were disabled a neighbouring path can be connected to both the path-ghost and to something // else, so before removing edges from neighbouring paths we have to make sure there is nothing else they are connected // to. - if (!tile_element_wants_path_connection_towards({ x / 32, y / 32, z1, direction }, tileElement)) + if (!tile_element_wants_path_connection_towards({ TileCoordsXY{ footpathPos }, z1, direction }, tileElement)) { bool isQueue = tileElement->GetType() == TILE_ELEMENT_TYPE_PATH ? tileElement->AsPath()->IsQueue() : false; int32_t z0 = z1 - 2; footpath_remove_edges_towards( - x + CoordsDirectionDelta[direction].x, y + CoordsDirectionDelta[direction].y, z0, z1, direction, isQueue); + footpathPos.x + CoordsDirectionDelta[direction].x, footpathPos.y + CoordsDirectionDelta[direction].y, z0, z1, + direction, isQueue); } else { @@ -2180,7 +2181,8 @@ void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement) // Only fix corners when needed, to avoid changing corners that have been set for its looks. if (fixCorners && tileElement->IsGhost()) { - footpath_fix_corners_around(x / 32, y / 32, tileElement); + auto tileFootpathPos = TileCoordsXY{ footpathPos }; + footpath_fix_corners_around(tileFootpathPos.x, tileFootpathPos.y, tileElement); } if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH) diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 00897b36aa..107ededa12 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -197,7 +197,7 @@ void footpath_update_path_wide_flags(int32_t x, int32_t y); bool footpath_is_blocked_by_vehicle(const TileCoordsXYZ& position); int32_t footpath_is_connected_to_map_edge(int32_t x, int32_t y, int32_t z, int32_t direction, int32_t flags); -void footpath_remove_edges_at(int32_t x, int32_t y, TileElement* tileElement); +void footpath_remove_edges_at(const CoordsXY& footpathPos, TileElement* tileElement); int32_t entrance_get_directions(const TileElement* tileElement); PathSurfaceEntry* get_path_surface_entry(int32_t entryIndex); diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 50ac431104..ee95940285 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -475,6 +475,12 @@ struct TileCoordsXYZD : public TileCoordsXYZ { } + TileCoordsXYZD(TileCoordsXY t_, int32_t z_, Direction d_) + : TileCoordsXYZ(t_, z_) + , direction(d_) + { + } + TileCoordsXYZD(CoordsXY c_, int32_t z_, Direction d_) : TileCoordsXYZ(c_, z_) , direction(d_) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 1eb5fccbce..e17b1660b8 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -964,7 +964,7 @@ void map_remove_all_rides() [[fallthrough]]; case TILE_ELEMENT_TYPE_TRACK: footpath_queue_chain_reset(); - footpath_remove_edges_at(it.x * 32, it.y * 32, it.element); + footpath_remove_edges_at(TileCoordsXY{ it.x, it.y }.ToCoordsXY(), it.element); tile_element_remove(it.element); tile_element_iterator_restart_for_tile(&it); break;