From bc1f2f62cfdee270d5912ff44d1861013601e943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:53:12 +0300 Subject: [PATCH] Rename IsValidPathZAndDirection and move to more appropriate place --- src/openrct2/entity/Staff.cpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 33 +++----------------------- src/openrct2/peep/GuestPathfinding.h | 2 -- src/openrct2/world/Footpath.cpp | 27 +++++++++++++++++++++ src/openrct2/world/Footpath.h | 1 + 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index 4cdbb2daa9..d6467c1eba 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -183,7 +183,7 @@ bool Staff::CanIgnoreWideFlag(const CoordsXYZ& staffPos, TileElement* path) cons } /* test_element is a path */ - if (!PathFinding::IsValidPathZAndDirection(test_element, adjacPos.z / kCoordsZStep, adjac_dir)) + if (!FootpathIsZAndDirectionValid(test_element, adjacPos.z / kCoordsZStep, adjac_dir)) continue; /* test_element is a connected path */ diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 193c7f8401..18cb488b92 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -359,7 +359,7 @@ namespace OpenRCT2::PathFinding continue; if (nextTileElement->GetType() != TileElementType::Path) continue; - if (!IsValidPathZAndDirection(nextTileElement, loc.z, chosenDirection)) + if (!FootpathIsZAndDirectionValid(nextTileElement, loc.z, chosenDirection)) continue; if (nextTileElement->AsPath()->IsWide()) return PathSearchResult::Wide; @@ -453,7 +453,7 @@ namespace OpenRCT2::PathFinding break; case TileElementType::Path: { - if (!IsValidPathZAndDirection(tileElement, loc.z, chosenDirection)) + if (!FootpathIsZAndDirectionValid(tileElement, loc.z, chosenDirection)) continue; if (tileElement->AsPath()->IsWide()) return PathSearchResult::Wide; @@ -845,7 +845,7 @@ namespace OpenRCT2::PathFinding * queue path. * Otherwise, peeps walk on path tiles to get to the goal. */ - if (!IsValidPathZAndDirection(tileElement, loc.z, testEdge)) + if (!FootpathIsZAndDirectionValid(tileElement, loc.z, testEdge)) continue; // Path may be sloped, so set z to path base height. @@ -2134,31 +2134,4 @@ namespace OpenRCT2::PathFinding return PeepMoveOneTile(direction, peep); } - bool IsValidPathZAndDirection(TileElement* tileElement, int32_t currentZ, int32_t currentDirection) - { - if (tileElement->AsPath()->IsSloped()) - { - int32_t slopeDirection = tileElement->AsPath()->GetSlopeDirection(); - if (slopeDirection == currentDirection) - { - if (currentZ != tileElement->BaseHeight) - return false; - } - else - { - slopeDirection = DirectionReverse(slopeDirection); - if (slopeDirection != currentDirection) - return false; - if (currentZ != tileElement->BaseHeight + 2) - return false; - } - } - else - { - if (currentZ != tileElement->BaseHeight) - return false; - } - return true; - } - } // namespace OpenRCT2::PathFinding diff --git a/src/openrct2/peep/GuestPathfinding.h b/src/openrct2/peep/GuestPathfinding.h index 7b691ee384..d098dc6df5 100644 --- a/src/openrct2/peep/GuestPathfinding.h +++ b/src/openrct2/peep/GuestPathfinding.h @@ -43,6 +43,4 @@ namespace OpenRCT2::PathFinding int32_t GuestPathFindParkEntranceLeaving(Peep& peep, uint8_t edges); - bool IsValidPathZAndDirection(TileElement* tileElement, int32_t currentZ, int32_t currentDirection); - }; // namespace OpenRCT2::PathFinding diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 7a1d796c56..ab04c066f1 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -2328,3 +2328,30 @@ bool PathElement::IsLevelCrossing(const CoordsXY& coords) const return ride->GetRideTypeDescriptor().HasFlag(RtdFlag::supportsLevelCrossings); } + +bool FootpathIsZAndDirectionValid(TileElement* tileElement, int32_t currentZ, int32_t currentDirection) +{ + if (tileElement->AsPath()->IsSloped()) + { + int32_t slopeDirection = tileElement->AsPath()->GetSlopeDirection(); + if (slopeDirection == currentDirection) + { + if (currentZ != tileElement->BaseHeight) + return false; + } + else + { + slopeDirection = DirectionReverse(slopeDirection); + if (slopeDirection != currentDirection) + return false; + if (currentZ != tileElement->BaseHeight + 2) + return false; + } + } + else + { + if (currentZ != tileElement->BaseHeight) + return false; + } + return true; +} diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 7096449aff..a0430b323e 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -186,3 +186,4 @@ const FootpathRailingsObject* GetPathRailingsEntry(ObjectEntryIndex entryIndex); void FootpathQueueChainReset(); void FootpathQueueChainPush(RideId rideIndex); +bool FootpathIsZAndDirectionValid(TileElement* tileElement, int32_t currentZ, int32_t currentDirection);