From fe4e93cf0e54736420742c2149185eb5cdd87f44 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Fri, 4 Sep 2026 19:50:47 +0200 Subject: [PATCH] Split determining peep action and display --- src/openrct2-ui/windows/Guest.cpp | 3 +- src/openrct2-ui/windows/GuestList.cpp | 5 +- src/openrct2-ui/windows/Staff.cpp | 3 +- src/openrct2-ui/windows/StaffList.cpp | 3 +- src/openrct2/entity/Peep.cpp | 172 +++++++------------------ src/openrct2/entity/Peep.h | 38 +++++- src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/peep/PeepActionFormat.cpp | 60 +++++++++ src/openrct2/peep/PeepActionFormat.h | 19 +++ 9 files changed, 172 insertions(+), 133 deletions(-) create mode 100644 src/openrct2/peep/PeepActionFormat.cpp create mode 100644 src/openrct2/peep/PeepActionFormat.h diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 8f81e95b57..46341ee11d 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -807,7 +808,7 @@ namespace OpenRCT2::Ui::Windows { auto ft = Formatter(); - peep->formatActionTo(ft); + formatPeepActionTo(*peep, ft); int32_t textWidth = actionLabelWidget.width() - 1; drawTextEllipsised(rt, screenPos, textWidth, STR_BLACK_STRING, ft, { TextAlignment::centre }); } diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 08145b49f1..6fd44bccd8 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -677,7 +678,7 @@ namespace OpenRCT2::Ui::Windows // Action ft = Formatter(); - peep->formatActionTo(ft); + formatPeepActionTo(*peep, ft); drawTextEllipsised(rt, { 133, y }, 314, format, ft); break; case GuestViewType::thoughts: @@ -867,7 +868,7 @@ namespace OpenRCT2::Ui::Windows switch (type) { case GuestViewType::actions: - peep.formatActionTo(ft); + formatPeepActionTo(peep, ft); break; case GuestViewType::thoughts: { diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index b4c0a8b600..44586af2a4 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -559,7 +560,7 @@ namespace OpenRCT2::Ui::Windows return; } auto ft = Formatter(); - staff->formatActionTo(ft); + formatPeepActionTo(*staff, ft); const auto& widget = widgets[WIDX_BTM_LABEL]; auto screenPos = windowPos + ScreenCoordsXY{ widget.midX(), widget.top }; int32_t widgetWidth = widget.width() - 1; diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index cc4941bb70..1696008512 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -413,7 +414,7 @@ namespace OpenRCT2::Ui::Windows drawTextEllipsised(rt, { 0, y }, nameColumnSize, format, ft); ft = Formatter(); - peep->formatActionTo(ft); + formatPeepActionTo(*peep, ft); drawTextEllipsised(rt, { actionOffset, y }, actionColumnSize, format, ft); // True if a patrol path is set for the worker diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index c3afcb0959..83c07694fc 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -37,6 +37,7 @@ #include "../object/ObjectManager.h" #include "../object/PeepAnimationsObject.h" #include "../peep/GuestPathfinding.h" +#include "../peep/PeepActionFormat.h" #include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../ride/RideData.h" @@ -1278,47 +1279,31 @@ namespace OpenRCT2 } } - void Peep::formatActionTo(Formatter& ft) const + PeepActionDescription Peep::getActionDescription() const { switch (state) { case PeepState::falling: - ft.Add(action == PeepActionType::drowning ? STR_DROWNING : STR_WALKING); - break; + if (action == PeepActionType::drowning) + return { PeepActionDescriptionType::drowning }; + + return { PeepActionDescriptionType::walking }; case PeepState::one: - ft.Add(STR_WALKING); - break; + return { PeepActionDescriptionType::walking }; case PeepState::onRide: case PeepState::leavingRide: case PeepState::enteringRide: { - auto ride = GetRide(currentRide); - if (ride != nullptr) + const auto ride = GetRide(currentRide); + if (ride != nullptr && ride->getRideTypeDescriptor().flags.has(RtdFlag::describeAsInside)) { - ft.Add( - ride->getRideTypeDescriptor().flags.has(RtdFlag::describeAsInside) ? STR_IN_RIDE : STR_ON_RIDE); - ride->formatNameTo(ft); + return { PeepActionDescriptionType::inRide, currentRide }; } - else - { - ft.Add(STR_ON_RIDE).Add(kStringIdNone); - } - break; + + return { PeepActionDescriptionType::onRide, currentRide }; } case PeepState::buying: - { - ft.Add(STR_AT_RIDE); - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ride->formatNameTo(ft); - } - else - { - ft.Add(kStringIdNone); - } - break; - } + return { PeepActionDescriptionType::atShop, currentRide }; case PeepState::walking: case PeepState::usingBin: { @@ -1326,135 +1311,68 @@ namespace OpenRCT2 { if (!guest->guestHeadingToRideId.IsNull()) { - auto ride = GetRide(guest->guestHeadingToRideId); - if (ride != nullptr) - { - ft.Add(STR_HEADING_FOR); - ride->formatNameTo(ft); - } - } - else - { - ft.Add(peepFlags.has(PeepFlag::leavingPark) ? STR_LEAVING_PARK : STR_WALKING); + return { PeepActionDescriptionType::headingFor, guest->guestHeadingToRideId }; } } - break; + + if (peepFlags.has(PeepFlag::leavingPark)) + return { PeepActionDescriptionType::leavingPark }; + + return { PeepActionDescriptionType::walking }; } case PeepState::queuingFront: case PeepState::queuing: - { - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ft.Add(STR_QUEUING_FOR); - ride->formatNameTo(ft); - } - break; - } + return { PeepActionDescriptionType::queuingFor, currentRide }; case PeepState::sitting: - ft.Add(STR_SITTING); - break; + return { PeepActionDescriptionType::sitting }; case PeepState::watching: if (!currentRide.IsNull()) { auto ride = GetRide(currentRide); if (ride != nullptr) { - ft.Add((standingFlags & 0x1) ? STR_WATCHING_CONSTRUCTION_OF : STR_WATCHING_RIDE); - ride->formatNameTo(ft); + auto baseType = (standingFlags & 0x1) ? PeepActionDescriptionType::watchingRideConstruction + : PeepActionDescriptionType::watchingRide; + return { baseType, currentRide }; } } - else - { - ft.Add((standingFlags & 0x1) ? STR_WATCHING_NEW_RIDE_BEING_CONSTRUCTED : STR_LOOKING_AT_SCENERY); - } - break; + + return { (standingFlags & 0x1) ? PeepActionDescriptionType::watchingRideConstructionUnspecific + : PeepActionDescriptionType::watchingScenery }; case PeepState::picked: - ft.Add(STR_SELECT_LOCATION); - break; + return { PeepActionDescriptionType::pickedUp }; case PeepState::patrolling: case PeepState::enteringPark: case PeepState::leavingPark: - ft.Add(STR_WALKING); - break; + return { PeepActionDescriptionType::walking }; case PeepState::mowing: - ft.Add(STR_MOWING_GRASS); - break; + return { PeepActionDescriptionType::mowingGrass }; case PeepState::sweeping: - ft.Add(STR_SWEEPING_FOOTPATH); - break; + return { PeepActionDescriptionType::sweepingFootpath }; case PeepState::watering: - ft.Add(STR_WATERING_GARDENS); - break; + return { PeepActionDescriptionType::wateringGardens }; case PeepState::emptyingBin: - ft.Add(STR_EMPTYING_LITTER_BIN); - break; + return { PeepActionDescriptionType::emptyingBin }; case PeepState::answering: if (subState == 0) { - ft.Add(STR_WALKING); + return { PeepActionDescriptionType::walking }; } - else if (subState == 1) + if (subState == 1) { - ft.Add(STR_ANSWERING_RADIO_CALL); + return { PeepActionDescriptionType::answeringRadioCall }; } - else - { - ft.Add(STR_RESPONDING_TO_RIDE_BREAKDOWN_CALL); - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ride->formatNameTo(ft); - } - else - { - ft.Add(kStringIdNone); - } - } - break; + + return { PeepActionDescriptionType::respondingToBreakdownCall, currentRide }; case PeepState::fixing: - { - ft.Add(STR_FIXING_RIDE); - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ride->formatNameTo(ft); - } - else - { - ft.Add(kStringIdNone); - } - break; - } + return { PeepActionDescriptionType::fixingRide, currentRide }; case PeepState::headingToInspection: - { - ft.Add(STR_HEADING_TO_RIDE_FOR_INSPECTION); - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ride->formatNameTo(ft); - } - else - { - ft.Add(kStringIdNone); - } - break; - } + return { PeepActionDescriptionType::headingToInspectRide, currentRide }; case PeepState::inspecting: - { - ft.Add(STR_INSPECTING_RIDE); - auto ride = GetRide(currentRide); - if (ride != nullptr) - { - ride->formatNameTo(ft); - } - else - { - ft.Add(kStringIdNone); - } - break; - } + return { PeepActionDescriptionType::inspectingRide, currentRide }; } + + return { PeepActionDescriptionType::walking }; } static constexpr StringId kStaffNames[] = { @@ -1569,13 +1487,13 @@ namespace OpenRCT2 ft.Add(peep->peepFlags.has(PeepFlag::tracking) ? STR_TRACKED_GUEST_MAP_TIP : STR_GUEST_MAP_TIP); ft.Add(GetPeepFaceSpriteSmall(guest)); guest->formatNameTo(ft); - guest->formatActionTo(ft); + formatPeepActionTo(*peep, ft); } else { ft.Add(STR_STAFF_MAP_TIP); peep->formatNameTo(ft); - peep->formatActionTo(ft); + formatPeepActionTo(*peep, ft); } auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP); diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index 06bbd2901d..b34678671d 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -303,6 +303,42 @@ namespace OpenRCT2 PEEP_INVALIDATE_PEEP_ACTION = 1 << 5, // Currently set only when guestHeadingToRideId is changed }; + enum class PeepActionDescriptionType : uint8_t + { + walking, + sitting, + watchingScenery, + drowning, + pickedUp, + headingFor, + watchingRide, + watchingRideConstruction, + watchingRideConstructionUnspecific, + queuingFor, + onRide, + inRide, + atShop, + leavingPark, + sweepingFootpath, + emptyingBin, + wateringGardens, + mowingGrass, + headingToInspectRide, + inspectingRide, + fixingRide, + answeringRadioCall, + respondingToBreakdownCall, + + count, + }; + constexpr size_t kNumPeepActionDescriptionTypes = static_cast(PeepActionDescriptionType::count); + + struct PeepActionDescription + { + PeepActionDescriptionType type; + RideId rideId = RideId::GetNull(); + }; + struct Guest; struct Peep : EntityBase @@ -400,7 +436,7 @@ namespace OpenRCT2 void pickupAbort(int32_t old_x); [[nodiscard]] GameActions::Result place(const TileCoordsXYZ& location, bool apply); void removeFromRide(); - void formatActionTo(Formatter&) const; + PeepActionDescription getActionDescription() const; void formatNameTo(Formatter&) const; [[nodiscard]] std::string getName() const; bool setName(std::string_view value); diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 9cd0795813..3d4381de50 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -448,6 +448,7 @@ + @@ -1153,6 +1154,7 @@ + diff --git a/src/openrct2/peep/PeepActionFormat.cpp b/src/openrct2/peep/PeepActionFormat.cpp new file mode 100644 index 0000000000..d072dbc914 --- /dev/null +++ b/src/openrct2/peep/PeepActionFormat.cpp @@ -0,0 +1,60 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "PeepActionFormat.h" + +#include "../entity/Peep.h" +#include "../localisation/StringIds.h" +#include "../ride/Ride.h" + +namespace OpenRCT2 +{ + constexpr auto kPeepActionToStringMapping = std::to_array({ + STR_WALKING, // PeepActionDescriptionType::walking + STR_SITTING, // PeepActionDescriptionType::sitting + STR_LOOKING_AT_SCENERY, // PeepActionDescriptionType::watchingScenery + STR_DROWNING, // PeepActionDescriptionType::drowning + STR_SELECT_LOCATION, // PeepActionDescriptionType::pickedUp + STR_HEADING_FOR, // PeepActionDescriptionType::headingFor + STR_WATCHING_RIDE, // PeepActionDescriptionType::watchingRide + STR_WATCHING_CONSTRUCTION_OF, // PeepActionDescriptionType::watchingRideConstruction + STR_WATCHING_NEW_RIDE_BEING_CONSTRUCTED, // PeepActionDescriptionType::watchingRideConstructionUnspecific + STR_QUEUING_FOR, // PeepActionDescriptionType::queuingFor + STR_ON_RIDE, // PeepActionDescriptionType::onRide + STR_IN_RIDE, // PeepActionDescriptionType::inRide + STR_AT_RIDE, // PeepActionDescriptionType::atShop + STR_LEAVING_PARK, // PeepActionDescriptionType::leavingPark + STR_SWEEPING_FOOTPATH, // PeepActionDescriptionType::sweepingFootpath + STR_EMPTYING_LITTER_BIN, // PeepActionDescriptionType::emptyingBin + STR_WATERING_GARDENS, // PeepActionDescriptionType::wateringGardens + STR_MOWING_GRASS, // PeepActionDescriptionType::mowingGrass + STR_HEADING_TO_RIDE_FOR_INSPECTION, // PeepActionDescriptionType::headingToInspectRide + STR_INSPECTING_RIDE, // PeepActionDescriptionType::inspectingRide + STR_FIXING_RIDE, // PeepActionDescriptionType::fixingRide + STR_ANSWERING_RADIO_CALL, // PeepActionDescriptionType::answeringRadioCall + STR_RESPONDING_TO_RIDE_BREAKDOWN_CALL, // PeepActionDescriptionType::respondingToBreakdownCall + }); + static_assert(std::size(kPeepActionToStringMapping) == kNumPeepActionDescriptionTypes); + + void formatPeepActionTo(const Peep& peep, Formatter& ft) + { + auto description = peep.getActionDescription(); + auto stringId = kPeepActionToStringMapping[EnumValue(description.type)]; + ft.Add(stringId); + + if (!description.rideId.IsNull()) + { + const auto* ride = GetRide(description.rideId); + if (ride != nullptr) + { + ride->formatNameTo(ft); + } + } + } +} // namespace OpenRCT2 diff --git a/src/openrct2/peep/PeepActionFormat.h b/src/openrct2/peep/PeepActionFormat.h new file mode 100644 index 0000000000..848687ca52 --- /dev/null +++ b/src/openrct2/peep/PeepActionFormat.h @@ -0,0 +1,19 @@ +/***************************************************************************** + * Copyright (c) 2014-2026 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +namespace OpenRCT2 +{ + class Formatter; + struct Peep; + + void formatPeepActionTo(const Peep& peep, Formatter&); + +} // namespace OpenRCT2