mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-19 21:13:05 +01:00
Refactor the code that uses MapGetFootpathElement
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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>();
|
||||
TileElement* footpathElement = nullptr;
|
||||
if (tileElement != nullptr)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ void RideClearBlockedTiles(const Ride& ride)
|
||||
if (footpathElement == nullptr)
|
||||
continue;
|
||||
|
||||
footpathElement->AsPath()->SetIsBlockedByVehicle(false);
|
||||
footpathElement->SetIsBlockedByVehicle(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user