diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index d6467c1eba..8e959f9ae0 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -713,11 +713,8 @@ Direction Staff::MechanicDirectionPath(uint8_t validDirections, PathElement* pat } } - gPeepPathFindIgnoreForeignQueues = false; - gPeepPathFindQueueRideIndex = RideId::GetNull(); - const auto goalPos = TileCoordsXYZ{ location }; - Direction pathfindDirection = PathFinding::ChooseDirection(TileCoordsXYZ{ NextLoc }, goalPos, *this); + Direction pathfindDirection = PathFinding::ChooseDirection(TileCoordsXYZ{ NextLoc }, goalPos, *this, false, RideId::GetNull()); if (pathfindDirection == INVALID_DIRECTION) { /* Heuristic search failed for all directions. diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 18cb488b92..0b2b111f4d 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -28,9 +28,6 @@ #include #include -bool gPeepPathFindIgnoreForeignQueues; -RideId gPeepPathFindQueueRideIndex; - namespace OpenRCT2::PathFinding { // The search limits the maximum junctions by certain conditions. @@ -49,7 +46,9 @@ namespace OpenRCT2::PathFinding int8_t junctionCount; int8_t maxJunctions; int32_t countTilesChecked; - + // TODO: Move them, those are query parameters not really state, but for now its easier to pass it down. + bool ignoreForeignQueues; + RideId queueRideIndex; // A junction history for the peep path finding heuristic search. struct { @@ -877,9 +876,9 @@ namespace OpenRCT2::PathFinding else { // numEdges == 2 if (tileElement->AsPath()->IsQueue() - && tileElement->AsPath()->GetRideIndex() != gPeepPathFindQueueRideIndex) + && tileElement->AsPath()->GetRideIndex() != state.queueRideIndex) { - if (gPeepPathFindIgnoreForeignQueues && !tileElement->AsPath()->GetRideIndex().IsNull()) + if (state.ignoreForeignQueues && !tileElement->AsPath()->GetRideIndex().IsNull()) { // Path is a queue we aren't interested in /* The rideIndex will be useful for @@ -1226,12 +1225,16 @@ namespace OpenRCT2::PathFinding * * rct2: 0x0069A5F0 */ - Direction ChooseDirection(const TileCoordsXYZ& loc, const TileCoordsXYZ& goal, Peep& peep) + Direction ChooseDirection( + const TileCoordsXYZ& loc, const TileCoordsXYZ& goal, Peep& peep, bool ignoreForeignQueues, RideId queueRideIndex) { PROFILED_FUNCTION(); PathFindingState state{}; + state.ignoreForeignQueues = ignoreForeignQueues; + state.queueRideIndex = queueRideIndex; + // The max number of thin junctions searched - a per-search-path limit. state.maxJunctions = PeepPathfindGetMaxNumberJunctions(peep); @@ -1590,11 +1593,8 @@ namespace OpenRCT2::PathFinding if (!chosenEntrance.has_value()) return GuestPathfindAimless(peep, edges); - gPeepPathFindIgnoreForeignQueues = true; - gPeepPathFindQueueRideIndex = RideId::GetNull(); - const auto goalPos = TileCoordsXYZ(chosenEntrance.value()); - Direction chosenDirection = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, goalPos, peep); + Direction chosenDirection = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, goalPos, peep, true, RideId::GetNull()); if (chosenDirection == INVALID_DIRECTION) return GuestPathfindAimless(peep, edges); @@ -1647,11 +1647,8 @@ namespace OpenRCT2::PathFinding return PeepMoveOneTile(direction, peep); } - gPeepPathFindIgnoreForeignQueues = true; - gPeepPathFindQueueRideIndex = RideId::GetNull(); - const auto goalPos = TileCoordsXYZ(peepSpawnLoc); - direction = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, goalPos, peep); + direction = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, goalPos, peep, true, RideId::GetNull()); if (direction == INVALID_DIRECTION) return GuestPathfindAimless(peep, edges); @@ -1687,10 +1684,7 @@ namespace OpenRCT2::PathFinding entranceGoal = TileCoordsXYZ(*chosenEntrance); } - gPeepPathFindIgnoreForeignQueues = true; - gPeepPathFindQueueRideIndex = RideId::GetNull(); - - Direction chosenDirection = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, entranceGoal, peep); + Direction chosenDirection = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, entranceGoal, peep, true, RideId::GetNull()); if (chosenDirection == INVALID_DIRECTION) return GuestPathfindAimless(peep, edges); @@ -2049,9 +2043,6 @@ namespace OpenRCT2::PathFinding return GuestPathfindAimless(peep, edges); } - // The ride is open. - gPeepPathFindQueueRideIndex = rideIndex; - /* Find the ride's closest entrance station to the peep. * At the same time, count how many entrance stations there are and * which stations are entrance stations. */ @@ -2110,9 +2101,7 @@ namespace OpenRCT2::PathFinding GetRideQueueEnd(loc); - gPeepPathFindIgnoreForeignQueues = true; - - direction = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, loc, peep); + direction = ChooseDirection(TileCoordsXYZ{ peep.NextLoc }, loc, peep, true, rideIndex); if (direction == INVALID_DIRECTION) { diff --git a/src/openrct2/peep/GuestPathfinding.h b/src/openrct2/peep/GuestPathfinding.h index d098dc6df5..11a986e2ed 100644 --- a/src/openrct2/peep/GuestPathfinding.h +++ b/src/openrct2/peep/GuestPathfinding.h @@ -18,22 +18,10 @@ struct Peep; struct Guest; struct TileElement; -// When the heuristic pathfinder is examining neighboring tiles, one possibility is that it finds a -// queue tile; furthermore, this queue tile may or may not be for the ride that the peep is trying -// to get to, if any. This first var is used to store the ride that the peep is currently headed to. -extern RideId gPeepPathFindQueueRideIndex; - -// Furthermore, staff members don't care about this stuff; even if they are e.g. a mechanic headed -// to a particular ride, they have no issues with walking over queues for other rides to get there. -// This bool controls that behaviour - if true, the peep will not path over queues for rides other -// than their target ride, and if false, they will treat it like a regular path. -// -// In practice, if this is false, gPeepPathFindQueueRideIndex is always RIDE_ID_NULL. -extern bool gPeepPathFindIgnoreForeignQueues; - namespace OpenRCT2::PathFinding { - Direction ChooseDirection(const TileCoordsXYZ& loc, const TileCoordsXYZ& goal, Peep& peep); + Direction ChooseDirection( + const TileCoordsXYZ& loc, const TileCoordsXYZ& goal, Peep& peep, bool ignoreForeignQueues, RideId queueRideIndex); int32_t CalculateNextDestination(Guest& peep); diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index 6efaec4f6a..a9d84a5407 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -85,7 +85,7 @@ protected: // Pick the direction the peep should initially move in, given the goal position. // This will also store the goal position and initialize pathfinding data for the peep. - const Direction moveDir = PathFinding::ChooseDirection(*pos, goal, *peep); + const Direction moveDir = PathFinding::ChooseDirection(*pos, goal, *peep, false, RideId::GetNull()); if (moveDir == INVALID_DIRECTION) { // Couldn't determine a direction to move off in