mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-26 08:14:38 +01:00
Refactor FootpathIsZAndDirectionValid and its uses, more constness
This commit is contained in:
@@ -183,7 +183,8 @@ bool Staff::CanIgnoreWideFlag(const CoordsXYZ& staffPos, TileElement* path) cons
|
||||
}
|
||||
|
||||
/* test_element is a path */
|
||||
if (!FootpathIsZAndDirectionValid(test_element, adjacPos.z / kCoordsZStep, adjac_dir))
|
||||
const auto* adjacentPathElement = test_element->AsPath();
|
||||
if (!FootpathIsZAndDirectionValid(*adjacentPathElement, adjacPos.z / kCoordsZStep, adjac_dir))
|
||||
continue;
|
||||
|
||||
/* test_element is a connected path */
|
||||
@@ -193,7 +194,7 @@ bool Staff::CanIgnoreWideFlag(const CoordsXYZ& staffPos, TileElement* path) cons
|
||||
pathcount++;
|
||||
}
|
||||
|
||||
if (test_element->AsPath()->IsWide())
|
||||
if (adjacentPathElement->IsWide())
|
||||
{
|
||||
if (!widefound)
|
||||
{
|
||||
@@ -714,7 +715,8 @@ Direction Staff::MechanicDirectionPath(uint8_t validDirections, PathElement* pat
|
||||
}
|
||||
|
||||
const auto goalPos = TileCoordsXYZ{ location };
|
||||
Direction pathfindDirection = PathFinding::ChooseDirection(TileCoordsXYZ{ NextLoc }, goalPos, *this, false, RideId::GetNull());
|
||||
Direction pathfindDirection = PathFinding::ChooseDirection(
|
||||
TileCoordsXYZ{ NextLoc }, goalPos, *this, false, RideId::GetNull());
|
||||
if (pathfindDirection == INVALID_DIRECTION)
|
||||
{
|
||||
/* Heuristic search failed for all directions.
|
||||
|
||||
@@ -140,14 +140,14 @@ namespace OpenRCT2::PathFinding
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
static TileElement* GetBannerOnPath(TileElement* pathElement)
|
||||
static const TileElement* GetBannerOnPath(const TileElement* pathElement)
|
||||
{
|
||||
// This is an improved version of original.
|
||||
// That only checked for one fence in the way.
|
||||
if (pathElement->IsLastForTile())
|
||||
return nullptr;
|
||||
|
||||
TileElement* bannerElement = pathElement + 1;
|
||||
const TileElement* bannerElement = pathElement + 1;
|
||||
do
|
||||
{
|
||||
// Path on top, so no banners
|
||||
@@ -165,11 +165,11 @@ namespace OpenRCT2::PathFinding
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int32_t BannerClearPathEdges(bool ignoreBanners, PathElement* pathElement, int32_t edges)
|
||||
static int32_t BannerClearPathEdges(bool ignoreBanners, const PathElement* pathElement, int32_t edges)
|
||||
{
|
||||
if (ignoreBanners)
|
||||
return edges;
|
||||
TileElement* bannerElement = GetBannerOnPath(reinterpret_cast<TileElement*>(pathElement));
|
||||
const TileElement* bannerElement = GetBannerOnPath(reinterpret_cast<const TileElement*>(pathElement));
|
||||
if (bannerElement != nullptr)
|
||||
{
|
||||
do
|
||||
@@ -183,7 +183,7 @@ namespace OpenRCT2::PathFinding
|
||||
/**
|
||||
* Gets the connected edges of a path that are permitted (i.e. no 'no entry' signs)
|
||||
*/
|
||||
static int32_t PathGetPermittedEdges(bool ignoreBanners, PathElement* pathElement)
|
||||
static int32_t PathGetPermittedEdges(bool ignoreBanners, const PathElement* pathElement)
|
||||
{
|
||||
return BannerClearPathEdges(ignoreBanners, pathElement, pathElement->GetEdgesAndCorners()) & 0x0F;
|
||||
}
|
||||
@@ -358,12 +358,13 @@ namespace OpenRCT2::PathFinding
|
||||
continue;
|
||||
if (nextTileElement->GetType() != TileElementType::Path)
|
||||
continue;
|
||||
if (!FootpathIsZAndDirectionValid(nextTileElement, loc.z, chosenDirection))
|
||||
const auto* nextPathElement = nextTileElement->AsPath();
|
||||
if (!FootpathIsZAndDirectionValid(*nextPathElement, loc.z, chosenDirection))
|
||||
continue;
|
||||
if (nextTileElement->AsPath()->IsWide())
|
||||
if (nextPathElement->IsWide())
|
||||
return PathSearchResult::Wide;
|
||||
// Only queue tiles that are connected to a ride are returned as ride queues.
|
||||
if (nextTileElement->AsPath()->IsQueue() && !nextTileElement->AsPath()->GetRideIndex().IsNull())
|
||||
if (nextPathElement->IsQueue() && !nextPathElement->GetRideIndex().IsNull())
|
||||
return PathSearchResult::RideQueue;
|
||||
|
||||
return PathSearchResult::Other;
|
||||
@@ -452,12 +453,13 @@ namespace OpenRCT2::PathFinding
|
||||
break;
|
||||
case TileElementType::Path:
|
||||
{
|
||||
if (!FootpathIsZAndDirectionValid(tileElement, loc.z, chosenDirection))
|
||||
const auto* pathElement = tileElement->AsPath();
|
||||
if (!FootpathIsZAndDirectionValid(*pathElement, loc.z, chosenDirection))
|
||||
continue;
|
||||
if (tileElement->AsPath()->IsWide())
|
||||
return PathSearchResult::Wide;
|
||||
|
||||
uint8_t edges = PathGetPermittedEdges(ignoreBanners, tileElement->AsPath());
|
||||
uint8_t edges = PathGetPermittedEdges(ignoreBanners, pathElement);
|
||||
edges &= ~(1 << DirectionReverse(chosenDirection));
|
||||
loc.z = tileElement->BaseHeight;
|
||||
|
||||
@@ -840,17 +842,17 @@ namespace OpenRCT2::PathFinding
|
||||
break;
|
||||
case TileElementType::Path:
|
||||
{
|
||||
const auto* pathElement = tileElement->AsPath();
|
||||
/* For peeps heading for a ride with a queue, the goal is the last
|
||||
* queue path.
|
||||
* Otherwise, peeps walk on path tiles to get to the goal. */
|
||||
|
||||
if (!FootpathIsZAndDirectionValid(tileElement, loc.z, testEdge))
|
||||
if (!FootpathIsZAndDirectionValid(*pathElement, loc.z, testEdge))
|
||||
continue;
|
||||
|
||||
// Path may be sloped, so set z to path base height.
|
||||
loc.z = tileElement->BaseHeight;
|
||||
|
||||
if (tileElement->AsPath()->IsWide())
|
||||
if (pathElement->IsWide())
|
||||
{
|
||||
/* Check if staff can ignore this wide flag. */
|
||||
if (staff == nullptr || !staff->CanIgnoreWideFlag(loc.ToCoordsXYZ(), tileElement))
|
||||
@@ -863,7 +865,7 @@ namespace OpenRCT2::PathFinding
|
||||
|
||||
searchResult = PathSearchResult::Thin;
|
||||
|
||||
uint8_t numEdges = std::popcount(tileElement->AsPath()->GetEdges());
|
||||
uint8_t numEdges = std::popcount(pathElement->GetEdges());
|
||||
|
||||
if (numEdges < 2)
|
||||
{
|
||||
@@ -875,15 +877,14 @@ namespace OpenRCT2::PathFinding
|
||||
}
|
||||
else
|
||||
{ // numEdges == 2
|
||||
if (tileElement->AsPath()->IsQueue()
|
||||
&& tileElement->AsPath()->GetRideIndex() != state.queueRideIndex)
|
||||
if (pathElement->IsQueue() && pathElement->GetRideIndex() != state.queueRideIndex)
|
||||
{
|
||||
if (state.ignoreForeignQueues && !tileElement->AsPath()->GetRideIndex().IsNull())
|
||||
if (state.ignoreForeignQueues && !pathElement->GetRideIndex().IsNull())
|
||||
{
|
||||
// Path is a queue we aren't interested in
|
||||
/* The rideIndex will be useful for
|
||||
* adding transport rides later. */
|
||||
rideIndex = tileElement->AsPath()->GetRideIndex();
|
||||
rideIndex = pathElement->GetRideIndex();
|
||||
searchResult = PathSearchResult::RideQueue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2329,14 +2329,14 @@ bool PathElement::IsLevelCrossing(const CoordsXY& coords) const
|
||||
return ride->GetRideTypeDescriptor().HasFlag(RtdFlag::supportsLevelCrossings);
|
||||
}
|
||||
|
||||
bool FootpathIsZAndDirectionValid(TileElement* tileElement, int32_t currentZ, int32_t currentDirection)
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& pathElement, int32_t currentZ, int32_t currentDirection)
|
||||
{
|
||||
if (tileElement->AsPath()->IsSloped())
|
||||
if (pathElement.IsSloped())
|
||||
{
|
||||
int32_t slopeDirection = tileElement->AsPath()->GetSlopeDirection();
|
||||
int32_t slopeDirection = pathElement.GetSlopeDirection();
|
||||
if (slopeDirection == currentDirection)
|
||||
{
|
||||
if (currentZ != tileElement->BaseHeight)
|
||||
if (currentZ != pathElement.BaseHeight)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@@ -2344,13 +2344,13 @@ bool FootpathIsZAndDirectionValid(TileElement* tileElement, int32_t currentZ, in
|
||||
slopeDirection = DirectionReverse(slopeDirection);
|
||||
if (slopeDirection != currentDirection)
|
||||
return false;
|
||||
if (currentZ != tileElement->BaseHeight + 2)
|
||||
if (currentZ != pathElement.BaseHeight + 2)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentZ != tileElement->BaseHeight)
|
||||
if (currentZ != pathElement.BaseHeight)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -186,4 +186,4 @@ const FootpathRailingsObject* GetPathRailingsEntry(ObjectEntryIndex entryIndex);
|
||||
|
||||
void FootpathQueueChainReset();
|
||||
void FootpathQueueChainPush(RideId rideIndex);
|
||||
bool FootpathIsZAndDirectionValid(TileElement* tileElement, int32_t currentZ, int32_t currentDirection);
|
||||
bool FootpathIsZAndDirectionValid(const PathElement& tileElement, int32_t currentZ, int32_t currentDirection);
|
||||
|
||||
Reference in New Issue
Block a user