From 088b476dc5cc26bada46dad1713c9294c6a8ed7f Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 11 May 2021 10:07:01 +0300 Subject: [PATCH] Add IsActionWalking getter and refactor uses --- src/openrct2/peep/Guest.cpp | 8 ++++---- src/openrct2/peep/Peep.cpp | 9 +++++++-- src/openrct2/peep/Peep.h | 1 + src/openrct2/peep/Staff.cpp | 16 ++++++++-------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index c967a28100..0acdc2f222 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -3290,7 +3290,7 @@ void Guest::UpdateBuying() if (SubState == 1) { - if (Action != PeepActionType::Walking) + if (!IsWalking()) { UpdateAction(); Invalidate(); @@ -5655,7 +5655,7 @@ void Guest::UpdateWatching() // 6917F6 UpdateAction(); Invalidate(); - if (Action != PeepActionType::Walking) + if (!IsWalking()) return; Action = PeepActionType::Idle; } @@ -5736,7 +5736,7 @@ void Guest::UpdateUsingBin() } case PeepUsingBinSubState::GoingBack: { - if (Action != PeepActionType::Walking) + if (!IsWalking()) { UpdateAction(); Invalidate(); @@ -7273,7 +7273,7 @@ bool Guest::UpdateQueuePosition(PeepActionType previous_action) if (Action < PeepActionType::Idle) UpdateAction(); - if (Action != PeepActionType::Walking) + if (!IsWalking()) return true; Action = PeepActionType::Idle; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 70821ffbb6..de6fc30878 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -405,7 +405,7 @@ std::optional Peep::UpdateAction(int16_t& xy_distance) xy_distance = x_delta + y_delta; - if (Action == PeepActionType::Walking) + if (IsWalking()) { if (xy_distance <= DestinationTolerance) { @@ -930,7 +930,7 @@ void Peep::Update() stepsToTake = 95; if ((PeepFlags & PEEP_FLAGS_SLOW_WALK) && State != PeepState::Queuing) stepsToTake /= 2; - if (Action == PeepActionType::Walking && (GetNextIsSloped())) + if (IsWalking() && GetNextIsSloped()) { stepsToTake /= 2; if (State == PeepState::Queuing) @@ -1528,6 +1528,11 @@ bool Peep::SetName(std::string_view value) return false; } +bool Peep::IsWalking() const +{ + return Action == PeepActionType::Walking; +} + void peep_set_map_tooltip(Peep* peep) { auto ft = Formatter(); diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 0eff61e9eb..c7fdf51cbe 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -743,6 +743,7 @@ public: // Peep void FormatNameTo(Formatter&) const; std::string GetName() const; bool SetName(std::string_view value); + bool IsWalking() const; // Reset the peep's stored goal, which means they will forget any stored pathfinding history // on the next peep_pathfind_choose_direction call. diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 9c37c3d5fd..ae2a9ee8e4 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -1213,7 +1213,7 @@ void Staff::UpdateWatering() } else if (SubState == 1) { - if (Action != PeepActionType::Walking) + if (!IsWalking()) { UpdateAction(); Invalidate(); @@ -1277,7 +1277,7 @@ void Staff::UpdateEmptyingBin() } else if (SubState == 1) { - if (Action == PeepActionType::Walking) + if (IsWalking()) { StateReset(); return; @@ -1496,7 +1496,7 @@ void Staff::UpdateAnswering() } else if (SubState == 1) { - if (Action == PeepActionType::Walking) + if (IsWalking()) { SubState = 2; peep_window_state_update(this); @@ -2184,7 +2184,7 @@ bool Staff::UpdateFixingFixVehicle(bool firstRun, const Ride* ride) UpdateCurrentActionSpriteType(); } - if (Action == PeepActionType::Walking) + if (IsWalking()) { return true; } @@ -2226,7 +2226,7 @@ bool Staff::UpdateFixingFixVehicleMalfunction(bool firstRun, const Ride* ride) UpdateCurrentActionSpriteType(); } - if (Action == PeepActionType::Walking) + if (IsWalking()) { return true; } @@ -2331,7 +2331,7 @@ bool Staff::UpdateFixingFixStationEnd(bool firstRun) UpdateCurrentActionSpriteType(); } - if (Action == PeepActionType::Walking) + if (IsWalking()) { return true; } @@ -2472,7 +2472,7 @@ bool Staff::UpdateFixingFixStationBrakes(bool firstRun, Ride* ride) UpdateCurrentActionSpriteType(); } - if (Action == PeepActionType::Walking) + if (IsWalking()) { return true; } @@ -2564,7 +2564,7 @@ bool Staff::UpdateFixingFinishFixOrInspect(bool firstRun, int32_t steps, Ride* r UpdateCurrentActionSpriteType(); } - if (Action != PeepActionType::Walking) + if (!IsWalking()) { UpdateAction(); Invalidate();