Close #12394: Refactor PeepNauseaTolerance to use strong enum (#13106)

This commit is contained in:
Vinicius Sa 2020-10-05 22:13:44 -03:00 committed by GitHub
parent 797fe48b0f
commit bd8c633ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 26 additions and 25 deletions

View File

@ -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);

View File

@ -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<rct_string_id>(nauseaTolerances[nausea_tolerance]);
gfx_draw_string_left(dpi, STR_GUEST_STAT_NAUSEA_TOLERANCE, ft.Data(), COLOUR_BLACK, screenCoords);

View File

@ -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<PeepNauseaTolerance>(value);
break;
case GUEST_PARAMETER_TOILET:
peep->Toilet = value;

View File

@ -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<uint8_t>(128), peep->Hunger) / 64;
nauseaGrowthRateChange >>= (peep->NauseaTolerance & 3);
nauseaGrowthRateChange >>= (EnumValue(peep->NauseaTolerance) & 3);
peep->NauseaTarget = static_cast<uint8_t>(std::min(peep->NauseaTarget + nauseaGrowthRateChange, 255u));
}

View File

@ -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 */

View File

@ -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];

View File

@ -1473,7 +1473,7 @@ private:
dst->DisgustingCount = src->disgusting_count;
dst->Intensity = static_cast<IntensityRange>(src->intensity);
dst->NauseaTolerance = src->nausea_tolerance;
dst->NauseaTolerance = static_cast<PeepNauseaTolerance>(src->nausea_tolerance);
dst->WindowInvalidateFlags = 0;
dst->CurrentRide = src->current_ride;

View File

@ -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<uint8_t>(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++)

View File

@ -1454,7 +1454,7 @@ public:
dst->Mass = src->mass;
dst->TimeToConsume = src->time_to_consume;
dst->Intensity = static_cast<IntensityRange>(src->intensity);
dst->NauseaTolerance = src->nausea_tolerance;
dst->NauseaTolerance = static_cast<PeepNauseaTolerance>(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++)

View File

@ -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<uint8_t>(value, 3);
peep->NauseaTolerance = static_cast<PeepNauseaTolerance>(std::min<uint8_t>(value, 3));
}
}