mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor peep.intensity into new strict struct
This commit is contained in:
parent
fa0dd4e0d6
commit
7b8ffdb865
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1528,15 +1528,15 @@ void window_guest_stats_paint(rct_window* w, rct_drawpixelinfo* dpi)
|
|||
y += LIST_ROW_HEIGHT;
|
||||
|
||||
// Intensity
|
||||
int32_t intensity = peep->intensity / 16;
|
||||
set_format_arg(0, uint16_t, intensity);
|
||||
auto maxIntensity = peep->intensity.GetMaximum();
|
||||
set_format_arg(0, uint16_t, maxIntensity);
|
||||
int32_t string_id = STR_GUEST_STAT_PREFERRED_INTESITY_BELOW;
|
||||
if (peep->intensity & 0xF)
|
||||
if (peep->intensity.GetMinimum() != 0)
|
||||
{
|
||||
set_format_arg(0, uint16_t, peep->intensity & 0xF);
|
||||
set_format_arg(2, uint16_t, intensity);
|
||||
set_format_arg(0, uint16_t, peep->intensity.GetMinimum());
|
||||
set_format_arg(2, uint16_t, maxIntensity);
|
||||
string_id = STR_GUEST_STAT_PREFERRED_INTESITY_BETWEEN;
|
||||
if (intensity == 15)
|
||||
if (maxIntensity == 15)
|
||||
string_id = STR_GUEST_STAT_PREFERRED_INTESITY_ABOVE;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -605,7 +605,7 @@ private:
|
|||
peep->toilet = value;
|
||||
break;
|
||||
case GUEST_PARAMETER_PREFERRED_RIDE_INTENSITY:
|
||||
peep->intensity = (15 << 4) | value;
|
||||
peep->intensity = IntensityRange(value, 15);
|
||||
break;
|
||||
}
|
||||
peep->UpdateSpriteType();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1808,9 +1808,9 @@ void Guest::OnExitRide(ride_id_t rideIndex)
|
|||
|
||||
if (peep_should_preferred_intensity_increase(this))
|
||||
{
|
||||
if (intensity <= 255 - 16)
|
||||
if (intensity.GetMaximum() < 15)
|
||||
{
|
||||
intensity += 16;
|
||||
intensity = intensity.WithMaximum(intensity.GetMaximum() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2124,8 +2124,8 @@ bool Guest::ShouldGoOnRide(Ride* ride, int32_t entranceNum, bool atQueue, bool t
|
|||
// Intensity calculations. Even though the max intensity can go up to 15, it's capped
|
||||
// at 10.0 (before happiness calculations). A full happiness bar will increase the max
|
||||
// intensity and decrease the min intensity by about 2.5.
|
||||
ride_rating maxIntensity = std::min((intensity >> 4) * 100, 1000) + happiness;
|
||||
ride_rating minIntensity = ((intensity & 0x0F) * 100) - happiness;
|
||||
ride_rating maxIntensity = std::min(intensity.GetMaximum() * 100, 1000) + happiness;
|
||||
ride_rating minIntensity = (intensity.GetMinimum() * 100) - happiness;
|
||||
if (ride->intensity < minIntensity)
|
||||
{
|
||||
if (peepAtRide)
|
||||
|
@ -2765,8 +2765,8 @@ static int16_t peep_calculate_ride_intensity_nausea_satisfaction(Peep* peep, Rid
|
|||
|
||||
uint8_t intensitySatisfaction = 3;
|
||||
uint8_t nauseaSatisfaction = 3;
|
||||
ride_rating maxIntensity = (peep->intensity >> 4) * 100;
|
||||
ride_rating minIntensity = (peep->intensity & 0xF) * 100;
|
||||
ride_rating maxIntensity = peep->intensity.GetMaximum() * 100;
|
||||
ride_rating minIntensity = peep->intensity.GetMinimum() * 100;
|
||||
if (minIntensity <= ride->intensity && maxIntensity >= ride->intensity)
|
||||
{
|
||||
intensitySatisfaction--;
|
||||
|
@ -2905,7 +2905,7 @@ static bool peep_should_preferred_intensity_increase(Peep* peep)
|
|||
if (peep->happiness < 200)
|
||||
return false;
|
||||
|
||||
return (scenario_rand() & 0xFF) >= peep->intensity;
|
||||
return (scenario_rand() & 0xFF) >= static_cast<uint8_t>(peep->intensity);
|
||||
}
|
||||
|
||||
static bool peep_really_liked_ride(Peep* peep, Ride* ride)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1680,7 +1680,7 @@ Peep* Peep::Generate(const CoordsXYZ& coords)
|
|||
intensityHighest = 15;
|
||||
}
|
||||
|
||||
peep->intensity = (intensityHighest << 4) | intensityLowest;
|
||||
peep->intensity = IntensityRange(intensityLowest, intensityHighest);
|
||||
|
||||
uint8_t nauseaTolerance = scenario_rand() & 0x7;
|
||||
if (gParkFlags & PARK_FLAGS_PREF_MORE_INTENSE_RIDES)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -18,6 +18,7 @@
|
|||
#include "../world/Location.hpp"
|
||||
#include "../world/SpriteBase.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <optional>
|
||||
|
||||
|
@ -541,6 +542,58 @@ struct rct_peep_thought
|
|||
struct Guest;
|
||||
struct Staff;
|
||||
|
||||
struct IntensityRange
|
||||
{
|
||||
private:
|
||||
uint8_t _value{};
|
||||
|
||||
public:
|
||||
explicit IntensityRange(uint8_t value)
|
||||
: _value(value)
|
||||
{
|
||||
}
|
||||
|
||||
IntensityRange(uint8_t min, uint8_t max)
|
||||
: _value(std::min<uint8_t>(min, 15) | (std::min<uint8_t>(max, 15) << 4))
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t GetMinimum() const
|
||||
{
|
||||
return _value & 0x0F;
|
||||
}
|
||||
|
||||
uint8_t GetMaximum() const
|
||||
{
|
||||
return _value >> 4;
|
||||
}
|
||||
|
||||
IntensityRange WithMinimum(uint8_t value) const
|
||||
{
|
||||
return IntensityRange(value, GetMaximum());
|
||||
}
|
||||
|
||||
IntensityRange WithMaximum(uint8_t value) const
|
||||
{
|
||||
return IntensityRange(GetMinimum(), value);
|
||||
}
|
||||
|
||||
explicit operator uint8_t() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
friend bool operator==(const IntensityRange& lhs, const IntensityRange& rhs)
|
||||
{
|
||||
return lhs._value == rhs._value;
|
||||
}
|
||||
|
||||
friend bool operator!=(const IntensityRange& lhs, const IntensityRange& rhs)
|
||||
{
|
||||
return lhs._value != rhs._value;
|
||||
}
|
||||
};
|
||||
|
||||
struct Peep : SpriteBase
|
||||
{
|
||||
char* name;
|
||||
|
@ -573,7 +626,7 @@ struct Peep : SpriteBase
|
|||
uint8_t toilet;
|
||||
uint8_t mass;
|
||||
uint8_t time_to_consume;
|
||||
uint8_t intensity; // The max intensity is stored in the first 4 bits, and the min intensity in the second 4 bits
|
||||
IntensityRange intensity;
|
||||
uint8_t nausea_tolerance;
|
||||
uint8_t window_invalidate_flags;
|
||||
money16 paid_on_drink;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1463,7 +1463,7 @@ private:
|
|||
dst->litter_count = src->litter_count;
|
||||
dst->disgusting_count = src->disgusting_count;
|
||||
|
||||
dst->intensity = src->intensity;
|
||||
dst->intensity = static_cast<IntensityRange>(src->intensity);
|
||||
dst->nausea_tolerance = src->nausea_tolerance;
|
||||
dst->window_invalidate_flags = 0;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1160,7 +1160,7 @@ void S6Exporter::ExportSpritePeep(RCT2SpritePeep* dst, const Peep* src)
|
|||
dst->toilet = src->toilet;
|
||||
dst->mass = src->mass;
|
||||
dst->time_to_consume = src->time_to_consume;
|
||||
dst->intensity = src->intensity;
|
||||
dst->intensity = static_cast<uint8_t>(src->intensity);
|
||||
dst->nausea_tolerance = src->nausea_tolerance;
|
||||
dst->window_invalidate_flags = src->window_invalidate_flags;
|
||||
dst->paid_on_drink = src->paid_on_drink;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2014-2019 OpenRCT2 developers
|
||||
* Copyright (c) 2014-2020 OpenRCT2 developers
|
||||
*
|
||||
* For a complete list of all authors, please refer to contributors.md
|
||||
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||
|
@ -1425,7 +1425,7 @@ public:
|
|||
dst->toilet = src->toilet;
|
||||
dst->mass = src->mass;
|
||||
dst->time_to_consume = src->time_to_consume;
|
||||
dst->intensity = src->intensity;
|
||||
dst->intensity = static_cast<IntensityRange>(src->intensity);
|
||||
dst->nausea_tolerance = src->nausea_tolerance;
|
||||
dst->window_invalidate_flags = src->window_invalidate_flags;
|
||||
dst->paid_on_drink = src->paid_on_drink;
|
||||
|
|
|
@ -336,7 +336,7 @@ namespace OpenRCT2::Scripting
|
|||
uint8_t minIntensity_get() const
|
||||
{
|
||||
auto peep = GetPeep();
|
||||
return peep != nullptr ? peep->intensity & 0x0F : 0;
|
||||
return peep != nullptr ? peep->intensity.GetMinimum() : 0;
|
||||
}
|
||||
void minIntensity_set(uint8_t value)
|
||||
{
|
||||
|
@ -344,16 +344,14 @@ namespace OpenRCT2::Scripting
|
|||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
auto minIntensity = std::min<uint8_t>(value, 15);
|
||||
auto maxIntensity = peep->intensity >> 4;
|
||||
peep->intensity = (maxIntensity << 4) | minIntensity;
|
||||
peep->intensity = peep->intensity.WithMinimum(value);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t maxIntensity_get() const
|
||||
{
|
||||
auto peep = GetPeep();
|
||||
return peep != nullptr ? peep->intensity >> 4 : 0;
|
||||
return peep != nullptr ? peep->intensity.GetMaximum() : 0;
|
||||
}
|
||||
void maxIntensity_set(uint8_t value)
|
||||
{
|
||||
|
@ -361,9 +359,7 @@ namespace OpenRCT2::Scripting
|
|||
auto peep = GetPeep();
|
||||
if (peep != nullptr)
|
||||
{
|
||||
auto minIntensity = peep->intensity & 0x0F;
|
||||
auto maxIntensity = std::min<uint8_t>(value, 15);
|
||||
peep->intensity = (maxIntensity << 4) | minIntensity;
|
||||
peep->intensity = peep->intensity.WithMaximum(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue