diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index bad18d22e6..c5b3bffb82 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -3330,7 +3330,7 @@ void RideConstructionToolupdateConstruct(const ScreenCoordsXY& screenCoords) if (_autoRotatingShop && _rideConstructionState == RideConstructionState::Place && ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IS_SHOP_OR_FACILITY)) { - TileElement* pathsByDir[NumOrthogonalDirections]; + PathElement* pathsByDir[NumOrthogonalDirections]; bool keepOrientation = false; for (int8_t i = 0; i < NumOrthogonalDirections; i++) @@ -3344,8 +3344,7 @@ void RideConstructionToolupdateConstruct(const ScreenCoordsXY& screenCoords) pathsByDir[i] = MapGetFootpathElement(testLoc); - if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsSloped() - && (pathsByDir[i])->AsPath()->GetSlopeDirection() != i) + if (pathsByDir[i] != nullptr && pathsByDir[i]->IsSloped() && pathsByDir[i]->GetSlopeDirection() != i) { pathsByDir[i] = nullptr; } @@ -3356,14 +3355,13 @@ void RideConstructionToolupdateConstruct(const ScreenCoordsXY& screenCoords) pathsByDir[i] = MapGetFootpathElement({ *mapCoords + CoordsDirectionDelta[i], z - PATH_HEIGHT_STEP }); if (pathsByDir[i] != nullptr - && (!(pathsByDir[i])->AsPath()->IsSloped() - || (pathsByDir[i])->AsPath()->GetSlopeDirection() != DirectionReverse(i))) + && (!pathsByDir[i]->IsSloped() || pathsByDir[i]->GetSlopeDirection() != DirectionReverse(i))) { pathsByDir[i] = nullptr; } } - if (pathsByDir[i] != nullptr && (pathsByDir[i])->AsPath()->IsQueue()) + if (pathsByDir[i] != nullptr && pathsByDir[i]->IsQueue()) { pathsByDir[i] = nullptr; } diff --git a/src/openrct2/actions/FootpathAdditionRemoveAction.cpp b/src/openrct2/actions/FootpathAdditionRemoveAction.cpp index a14bb56589..1eab764375 100644 --- a/src/openrct2/actions/FootpathAdditionRemoveAction.cpp +++ b/src/openrct2/actions/FootpathAdditionRemoveAction.cpp @@ -91,9 +91,7 @@ GameActions::Result FootpathAdditionRemoveAction::Query() const GameActions::Result FootpathAdditionRemoveAction::Execute() const { - auto tileElement = MapGetFootpathElement(_loc); - auto pathElement = tileElement->AsPath(); - + auto* pathElement = MapGetFootpathElement(_loc); if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { FootpathInterruptPeeps(_loc); diff --git a/src/openrct2/actions/FootpathPlaceAction.cpp b/src/openrct2/actions/FootpathPlaceAction.cpp index 8b0216d16a..85e3943825 100644 --- a/src/openrct2/actions/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/FootpathPlaceAction.cpp @@ -493,13 +493,12 @@ void FootpathPlaceAction::RemoveIntersectingWalls(PathElement* pathElement) cons WallRemoveIntersectingWalls({ _loc, z, z + (6 * COORDS_Z_STEP) }, DirectionReverse(direction)); WallRemoveIntersectingWalls({ _loc, z, z + (6 * COORDS_Z_STEP) }, direction); // Removing walls may have made the pointer invalid, so find it again - auto tileElement = MapGetFootpathElement(CoordsXYZ(_loc, z)); - if (tileElement == nullptr) + pathElement = MapGetFootpathElement(CoordsXYZ(_loc, z)); + if (pathElement == nullptr) { LOG_ERROR("Something went wrong. Could not refind footpath."); return; } - pathElement = tileElement->AsPath(); } if (!(GetFlags() & GAME_COMMAND_FLAG_TRACK_DESIGN)) diff --git a/src/openrct2/actions/FootpathRemoveAction.cpp b/src/openrct2/actions/FootpathRemoveAction.cpp index bb8cada8eb..47cf11d79f 100644 --- a/src/openrct2/actions/FootpathRemoveAction.cpp +++ b/src/openrct2/actions/FootpathRemoveAction.cpp @@ -125,7 +125,8 @@ TileElement* FootpathRemoveAction::GetFootpathElement() const { bool getGhostPath = GetFlags() & GAME_COMMAND_FLAG_GHOST; - TileElement* tileElement = MapGetFootpathElement(_loc); + // FIXME: This is a hack to get the footpath element. It should be done in a better way. + TileElement* tileElement = MapGetFootpathElement(_loc)->as(); TileElement* footpathElement = nullptr; if (tileElement != nullptr) { diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 664f709294..9b67536538 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -472,9 +472,9 @@ GameActions::Result TrackPlaceAction::Execute() const if (crossingMode == CREATE_CROSSING_MODE_TRACK_OVER_PATH && !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { auto footpathElement = MapGetFootpathElement(mapLoc); - if (footpathElement != nullptr && footpathElement->AsPath()->HasAddition()) + if (footpathElement != nullptr && footpathElement->HasAddition()) { - footpathElement->AsPath()->SetAddition(0); + footpathElement->SetAddition(0); } } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index a812c86139..9ab451c44b 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -357,7 +357,7 @@ void RideClearBlockedTiles(const Ride& ride) if (footpathElement == nullptr) continue; - footpathElement->AsPath()->SetIsBlockedByVehicle(false); + footpathElement->SetIsBlockedByVehicle(false); } } } diff --git a/test/tests/TileElements.cpp b/test/tests/TileElements.cpp index a88f2e0062..fb04735167 100644 --- a/test/tests/TileElements.cpp +++ b/test/tests/TileElements.cpp @@ -59,7 +59,7 @@ uint8_t TileElementWantsFootpathConnection::_gScreenFlags; TEST_F(TileElementWantsFootpathConnection, FlatPath) { // Flat paths want to connect to other paths in any direction - const TileElement* const pathElement = MapGetFootpathElement(TileCoordsXYZ{ 19, 18, 14 }.ToCoordsXYZ()); + const auto* pathElement = MapGetFootpathElement(TileCoordsXYZ{ 19, 18, 14 }.ToCoordsXYZ()); ASSERT_NE(pathElement, nullptr); EXPECT_TRUE(TileElementWantsPathConnectionTowards({ 19, 18, 14, 0 }, nullptr)); EXPECT_TRUE(TileElementWantsPathConnectionTowards({ 19, 18, 14, 1 }, nullptr)); @@ -71,7 +71,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 = MapGetFootpathElement(TileCoordsXYZ{ 18, 18, 14 }.ToCoordsXYZ()); + const auto* slopedPathElement = MapGetFootpathElement(TileCoordsXYZ{ 18, 18, 14 }.ToCoordsXYZ()); ASSERT_NE(slopedPathElement, nullptr); ASSERT_TRUE(slopedPathElement->AsPath()->IsSloped()); // Bottom and top of sloped path want a path connection @@ -152,14 +152,15 @@ TEST_F(TileElementWantsFootpathConnection, MapEdge) { // Paths at the map edge should have edge flags turned on when placed in scenario editor // This tile is a single, unconnected footpath on the map edge - on load, GetEdges() returns 0 - TileElement* pathElement = MapGetFootpathElement(TileCoordsXYZ{ 1, 4, 14 }.ToCoordsXYZ()); + auto* pathElement = MapGetFootpathElement(TileCoordsXYZ{ 1, 4, 14 }.ToCoordsXYZ()); // Enable flag to simulate enabling the scenario editor gScreenFlags |= SCREEN_FLAGS_SCENARIO_EDITOR; // Calculate the connected edges and set the appropriate edge flags - FootpathConnectEdges({ 16, 64 }, pathElement, 0); - auto edges = pathElement->AsPath()->GetEdges(); + // FIXME: The footpath functions should only take PathElement and not TileElement. + FootpathConnectEdges({ 16, 64 }, pathElement->as(), 0); + auto edges = pathElement->GetEdges(); // The tiles alongside in the Y direction are both on the map edge so should be marked as an edge EXPECT_TRUE(edges & (1 << 1));