From bd8c633ea3b0fdafccb01c08a2fd9002467aee70 Mon Sep 17 00:00:00 2001 From: Vinicius Sa Date: Mon, 5 Oct 2020 22:13:44 -0300 Subject: [PATCH] Close #12394: Refactor PeepNauseaTolerance to use strong enum (#13106) --- src/openrct2-ui/windows/Cheats.cpp | 4 ++-- src/openrct2-ui/windows/Guest.cpp | 2 +- src/openrct2/actions/SetCheatAction.hpp | 4 ++-- src/openrct2/peep/Guest.cpp | 8 ++++---- src/openrct2/peep/Peep.cpp | 10 +++++----- src/openrct2/peep/Peep.h | 12 ++++++------ src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Exporter.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scripting/ScEntity.hpp | 5 +++-- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index f2d551179e..8d9e96ff2a 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -758,10 +758,10 @@ static void window_cheats_guests_mouseup(rct_window* w, rct_widgetindex widgetIn CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_NAUSEA, 0); break; case WIDX_GUEST_NAUSEA_TOLERANCE_MAX: - CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_NAUSEA_TOLERANCE, PEEP_NAUSEA_TOLERANCE_HIGH); + CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_NAUSEA_TOLERANCE, EnumValue(PeepNauseaTolerance::High)); break; case WIDX_GUEST_NAUSEA_TOLERANCE_MIN: - CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_NAUSEA_TOLERANCE, PEEP_NAUSEA_TOLERANCE_NONE); + CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_NAUSEA_TOLERANCE, EnumValue(PeepNauseaTolerance::None)); break; case WIDX_GUEST_TOILET_MAX: CheatsSet(CheatType::SetGuestParameter, GUEST_PARAMETER_TOILET, PEEP_MAX_TOILET); diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 2349227c2d..a894b173a3 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1480,7 +1480,7 @@ void window_guest_stats_paint(rct_window* w, rct_drawpixelinfo* dpi) STR_PEEP_STAT_NAUSEA_TOLERANCE_HIGH, }; screenCoords.y += LIST_ROW_HEIGHT; - int32_t nausea_tolerance = peep->NauseaTolerance & 0x3; + auto nausea_tolerance = EnumValue(peep->NauseaTolerance) & 0x3; auto ft = Formatter(); ft.Add(nauseaTolerances[nausea_tolerance]); gfx_draw_string_left(dpi, STR_GUEST_STAT_NAUSEA_TOLERANCE, ft.Data(), COLOUR_BLACK, screenCoords); diff --git a/src/openrct2/actions/SetCheatAction.hpp b/src/openrct2/actions/SetCheatAction.hpp index a5497d8ef0..562471a337 100644 --- a/src/openrct2/actions/SetCheatAction.hpp +++ b/src/openrct2/actions/SetCheatAction.hpp @@ -341,7 +341,7 @@ private: { 0, PEEP_MAX_NAUSEA } }; case GUEST_PARAMETER_NAUSEA_TOLERANCE: return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, - { PEEP_NAUSEA_TOLERANCE_NONE, PEEP_NAUSEA_TOLERANCE_HIGH } }; + { EnumValue(PeepNauseaTolerance::None), EnumValue(PeepNauseaTolerance::High) } }; case GUEST_PARAMETER_TOILET: return { { GUEST_PARAMETER_HAPPINESS, GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY }, { 0, PEEP_MAX_TOILET } }; @@ -599,7 +599,7 @@ private: peep->NauseaTarget = value; break; case GUEST_PARAMETER_NAUSEA_TOLERANCE: - peep->NauseaTolerance = value; + peep->NauseaTolerance = static_cast(value); break; case GUEST_PARAMETER_TOILET: peep->Toilet = value; diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 1f3622b0aa..4bdd24d42f 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -2154,7 +2154,7 @@ bool Guest::ShouldGoOnRide(Ride* ride, int32_t entranceNum, bool atQueue, bool t } // Nausea calculations. - ride_rating maxNausea = NauseaMaximumThresholds[(NauseaTolerance & 3)] + Happiness; + ride_rating maxNausea = NauseaMaximumThresholds[(EnumValue(NauseaTolerance) & 3)] + Happiness; if (ride->nausea > maxNausea) { @@ -2798,8 +2798,8 @@ static int16_t peep_calculate_ride_intensity_nausea_satisfaction(Peep* peep, Rid // Although it's not shown in the interface, a peep with Average or High nausea tolerance // has a minimum preferred nausea value. (For peeps with None or Low, this is set to zero.) - ride_rating minNausea = NauseaMinimumThresholds[(peep->NauseaTolerance & 3)]; - ride_rating maxNausea = NauseaMaximumThresholds[(peep->NauseaTolerance & 3)]; + ride_rating minNausea = NauseaMinimumThresholds[(EnumValue(peep->NauseaTolerance) & 3)]; + ride_rating maxNausea = NauseaMaximumThresholds[(EnumValue(peep->NauseaTolerance) & 3)]; if (minNausea <= ride->nausea && maxNausea >= ride->nausea) { nauseaSatisfaction--; @@ -2873,7 +2873,7 @@ static void peep_update_ride_nausea_growth(Peep* peep, Ride* ride) uint32_t nauseaMultiplier = std::clamp(256 - peep->HappinessTarget, 64, 200); uint32_t nauseaGrowthRateChange = (ride->nausea * nauseaMultiplier) / 512; nauseaGrowthRateChange *= std::max(static_cast(128), peep->Hunger) / 64; - nauseaGrowthRateChange >>= (peep->NauseaTolerance & 3); + nauseaGrowthRateChange >>= (EnumValue(peep->NauseaTolerance) & 3); peep->NauseaTarget = static_cast(std::min(peep->NauseaTarget + nauseaGrowthRateChange, 255u)); } diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index a17b0ea01e..2ab4a99361 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -1446,11 +1446,11 @@ void peep_update_days_in_queue() // clang-format off /** rct2: 0x009823A0 */ -static constexpr const enum PeepNauseaTolerance nausea_tolerance_distribution[] = { - PEEP_NAUSEA_TOLERANCE_NONE, - PEEP_NAUSEA_TOLERANCE_LOW, PEEP_NAUSEA_TOLERANCE_LOW, - PEEP_NAUSEA_TOLERANCE_AVERAGE, PEEP_NAUSEA_TOLERANCE_AVERAGE, PEEP_NAUSEA_TOLERANCE_AVERAGE, - PEEP_NAUSEA_TOLERANCE_HIGH, PEEP_NAUSEA_TOLERANCE_HIGH, PEEP_NAUSEA_TOLERANCE_HIGH, PEEP_NAUSEA_TOLERANCE_HIGH, PEEP_NAUSEA_TOLERANCE_HIGH, PEEP_NAUSEA_TOLERANCE_HIGH, +static constexpr const PeepNauseaTolerance nausea_tolerance_distribution[] = { + PeepNauseaTolerance::None, + PeepNauseaTolerance::Low, PeepNauseaTolerance::Low, + PeepNauseaTolerance::Average, PeepNauseaTolerance::Average, PeepNauseaTolerance::Average, + PeepNauseaTolerance::High, PeepNauseaTolerance::High, PeepNauseaTolerance::High, PeepNauseaTolerance::High, PeepNauseaTolerance::High, PeepNauseaTolerance::High, }; /** rct2: 0x009823BC */ diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 6dc9e78d13..4a323c89f5 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -406,12 +406,12 @@ enum PeepNextFlags PEEP_NEXT_FLAG_UNUSED = (1 << 4), }; -enum PeepNauseaTolerance +enum class PeepNauseaTolerance : uint8_t { - PEEP_NAUSEA_TOLERANCE_NONE, - PEEP_NAUSEA_TOLERANCE_LOW, - PEEP_NAUSEA_TOLERANCE_AVERAGE, - PEEP_NAUSEA_TOLERANCE_HIGH, + None, + Low, + Average, + High }; enum PeepItem @@ -645,7 +645,7 @@ struct Peep : SpriteBase uint8_t Mass; uint8_t TimeToConsume; IntensityRange Intensity; - uint8_t NauseaTolerance; + PeepNauseaTolerance NauseaTolerance; uint8_t WindowInvalidateFlags; money16 PaidOnDrink; uint8_t RideTypesBeenOn[16]; diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index a200c9a830..9aabc18155 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1473,7 +1473,7 @@ private: dst->DisgustingCount = src->disgusting_count; dst->Intensity = static_cast(src->intensity); - dst->NauseaTolerance = src->nausea_tolerance; + dst->NauseaTolerance = static_cast(src->nausea_tolerance); dst->WindowInvalidateFlags = 0; dst->CurrentRide = src->current_ride; diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 0a86d675b1..9ae0ce8d0f 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -1165,7 +1165,7 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src) dst->mass = src->Mass; dst->time_to_consume = src->TimeToConsume; dst->intensity = static_cast(src->Intensity); - dst->nausea_tolerance = src->NauseaTolerance; + dst->nausea_tolerance = EnumValue(src->NauseaTolerance); dst->window_invalidate_flags = src->WindowInvalidateFlags; dst->paid_on_drink = src->PaidOnDrink; for (size_t i = 0; i < std::size(src->RideTypesBeenOn); i++) diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 0ff6aadbcb..b17ff483c8 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -1454,7 +1454,7 @@ public: dst->Mass = src->mass; dst->TimeToConsume = src->time_to_consume; dst->Intensity = static_cast(src->intensity); - dst->NauseaTolerance = src->nausea_tolerance; + dst->NauseaTolerance = static_cast(src->nausea_tolerance); dst->WindowInvalidateFlags = src->window_invalidate_flags; dst->PaidOnDrink = src->paid_on_drink; for (size_t i = 0; i < std::size(src->ride_types_been_on); i++) diff --git a/src/openrct2/scripting/ScEntity.hpp b/src/openrct2/scripting/ScEntity.hpp index 747d8d0ffa..87ea98fd8d 100644 --- a/src/openrct2/scripting/ScEntity.hpp +++ b/src/openrct2/scripting/ScEntity.hpp @@ -15,6 +15,7 @@ # include "../common.h" # include "../peep/Peep.h" # include "../peep/Staff.h" +# include "../util/Util.h" # include "../world/Sprite.h" # include "Duktape.hpp" # include "ScRide.hpp" @@ -1024,7 +1025,7 @@ namespace OpenRCT2::Scripting uint8_t nauseaTolerance_get() const { auto peep = GetPeep(); - return peep != nullptr ? peep->NauseaTolerance : 0; + return peep != nullptr ? EnumValue(peep->NauseaTolerance) : 0; } void nauseaTolerance_set(uint8_t value) { @@ -1032,7 +1033,7 @@ namespace OpenRCT2::Scripting auto peep = GetPeep(); if (peep != nullptr) { - peep->NauseaTolerance = std::min(value, 3); + peep->NauseaTolerance = static_cast(std::min(value, 3)); } }