From 6c6ea169f1e1dd7dd19cda3a5a1413d0ec0091a1 Mon Sep 17 00:00:00 2001 From: Rik Smeets <30838294+rik-smeets@users.noreply.github.com> Date: Sat, 24 Sep 2022 07:44:19 +0200 Subject: [PATCH] Add railway crossing behaviour for staff (#18057) --- distribution/changelog.txt | 1 + src/openrct2/entity/Guest.cpp | 12 +++--------- src/openrct2/entity/Peep.cpp | 12 ++++++++++++ src/openrct2/entity/Peep.h | 1 + src/openrct2/entity/Staff.cpp | 17 +++++++++++++++++ src/openrct2/entity/Staff.h | 1 + src/openrct2/network/NetworkBase.cpp | 2 +- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 686171df05..48ee7cd861 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -11,6 +11,7 @@ - Feature: [#17821] [Plugin] Add API for track subpositions and vehicle subposition. - Feature: [#17877] Add three real-life flying roller coaster colour schemes. - Feature: [#17900] Add “Classic Wooden Coaster” with shallow banked turns. +- Feature: [#18057] Staff members now wait for passing or stalled vehicles before crossing railway tracks. - Feature: [objects#198] Add additional pirate roofs. - Feature: [objects#205] Add additional glass roofs. - Feature: [objects#209] Add the Steel Roller Coaster train and 2-across Inverted Train from RollerCoaster Tycoon 1. diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index d6ab075e3c..5c5ef0f0d6 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -5299,16 +5299,10 @@ void Guest::UpdateWalking() } } - // Check if vehicle is blocking the destination tile - auto curPos = TileCoordsXYZ(GetLocation()); - auto dstPos = TileCoordsXYZ(CoordsXYZ{ GetDestination(), NextLoc.z }); - if (curPos.x != dstPos.x || curPos.y != dstPos.y) + if (PathIsBlockedByVehicle()) { - if (footpath_is_blocked_by_vehicle(dstPos)) - { - // Wait for vehicle to pass - return; - } + // Wait for vehicle to pass + return; } uint8_t pathingResult; diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 50dcbd4c1c..370e7db5db 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -321,6 +321,18 @@ bool Peep::CheckForPath() return false; } +bool Peep::PathIsBlockedByVehicle() +{ + auto curPos = TileCoordsXYZ(GetLocation()); + auto dstPos = TileCoordsXYZ(CoordsXYZ{ GetDestination(), NextLoc.z }); + if ((curPos.x != dstPos.x || curPos.y != dstPos.y) && footpath_is_blocked_by_vehicle(dstPos)) + { + return true; + } + + return false; +} + PeepActionSpriteType Peep::GetActionSpriteType() { if (IsActionInterruptable()) diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index 362a8d633f..396b0bfef9 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -412,6 +412,7 @@ public: // Peep // TODO: Make these private again when done refactoring public: // Peep [[nodiscard]] bool CheckForPath(); + bool PathIsBlockedByVehicle(); void PerformNextAction(uint8_t& pathing_result); void PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result); [[nodiscard]] int32_t GetZOnSlope(int32_t tile_x, int32_t tile_y); diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index 2f4367080e..121846019a 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -862,6 +862,14 @@ bool Staff::DoMiscPathFinding() return false; } +bool Staff::IsMechanicHeadingToFixRideBlockingPath() +{ + auto trackElement = map_get_track_element_at(CoordsXYZ{ GetDestination(), NextLoc.z }); + auto ride = get_ride(trackElement->GetRideIndex()); + return AssignedStaffType == StaffType::Mechanic && ride->id == CurrentRide + && ride->breakdown_reason == BREAKDOWN_SAFETY_CUT_OUT; +} + /** * * rct2: 0x006C086D @@ -1323,6 +1331,9 @@ void Staff::UpdateHeadingToInspect() if (!CheckForPath()) return; + if (PathIsBlockedByVehicle() && !IsMechanicHeadingToFixRideBlockingPath()) + return; + uint8_t pathingResult; TileElement* rideEntranceExitElement; PerformNextAction(pathingResult, rideEntranceExitElement); @@ -1428,6 +1439,9 @@ void Staff::UpdateAnswering() if (!CheckForPath()) return; + if (PathIsBlockedByVehicle() && !IsMechanicHeadingToFixRideBlockingPath()) + return; + uint8_t pathingResult; TileElement* rideEntranceExitElement; PerformNextAction(pathingResult, rideEntranceExitElement); @@ -1760,6 +1774,9 @@ void Staff::UpdatePatrolling() if (!CheckForPath()) return; + if (PathIsBlockedByVehicle() && !IsMechanicHeadingToFixRideBlockingPath()) + return; + uint8_t pathingResult; PerformNextAction(pathingResult); if (!(pathingResult & PATHING_DESTINATION_REACHED)) diff --git a/src/openrct2/entity/Staff.h b/src/openrct2/entity/Staff.h index ecbf4eb6d3..c7f6d7f3ba 100644 --- a/src/openrct2/entity/Staff.h +++ b/src/openrct2/entity/Staff.h @@ -94,6 +94,7 @@ private: bool DoMechanicPathFinding(); bool DoEntertainerPathFinding(); bool DoMiscPathFinding(); + bool IsMechanicHeadingToFixRideBlockingPath(); Direction HandymanDirectionRandSurface(uint8_t validDirections) const; diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 0b559d32d5..89bdc2cf54 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -42,7 +42,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "16" +#define NETWORK_STREAM_VERSION "17" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr;