From 2ce206ed03e041e7a2feb8c18f6fbd20182c18cf Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 7 Mar 2025 18:57:00 +0100 Subject: [PATCH] Move item temperature thresholds to climate objects --- src/openrct2/entity/Guest.cpp | 39 +++++++++++-------- src/openrct2/interface/InteractiveConsole.cpp | 1 - src/openrct2/object/ClimateObject.cpp | 13 ++++++- src/openrct2/object/ClimateObject.h | 1 + src/openrct2/world/Climate.h | 12 +++++- 5 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 9eeae4be97..c1fc65b194 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -33,6 +33,7 @@ #include "../management/Marketing.h" #include "../management/NewsItem.h" #include "../network/Network.h" +#include "../object/ClimateObject.h" #include "../object/LargeSceneryEntry.h" #include "../object/MusicObject.h" #include "../object/ObjectManager.h" @@ -1486,6 +1487,24 @@ void Guest::CheckCantFindExit() GuestIsLostCountdown = 90; } +static money64 getItemValue(const ShopItemDescriptor& shopItemDescriptor) +{ + auto& objManager = GetContext()->GetObjectManager(); + auto* climateObj = objManager.GetLoadedObject(0); + if (climateObj == nullptr) + return shopItemDescriptor.BaseValue; + + const auto& thresholds = climateObj->getItemThresholds(); + const auto& gameState = GetGameState(); + + if (gameState.WeatherCurrent.temperature >= thresholds.warm) + return shopItemDescriptor.HotValue; + else if (gameState.WeatherCurrent.temperature <= thresholds.cold) + return shopItemDescriptor.ColdValue; + else + return shopItemDescriptor.BaseValue; +} + /** Main logic to decide whether a peep should buy an item in question * * Also handles the purchase as well, so once it returns, the peep will have the @@ -1501,14 +1520,11 @@ void Guest::CheckCantFindExit() */ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) { - money64 itemValue; - - bool hasVoucher = false; - const bool isPrecipitating = ClimateIsRaining() || ClimateIsSnowingHeavily(); const bool isUmbrella = shopItem == ShopItem::Umbrella; const bool isRainingAndUmbrella = isPrecipitating && isUmbrella; + bool hasVoucher = false; if ((HasItem(ShopItem::Voucher)) && (VoucherType == VOUCHER_TYPE_FOOD_OR_DRINK_FREE) && (VoucherShopItem == shopItem)) { hasVoucher = true; @@ -1581,13 +1597,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) } } - if (gameState.WeatherCurrent.temperature >= 21) - itemValue = shopItemDescriptor.HotValue; - else if (gameState.WeatherCurrent.temperature <= 11) - itemValue = shopItemDescriptor.ColdValue; - else - itemValue = shopItemDescriptor.BaseValue; - + money64 itemValue = getItemValue(shopItemDescriptor); if (itemValue < price) { itemValue -= price; @@ -1629,12 +1639,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) } // reset itemValue for satisfaction calculation - if (gameState.WeatherCurrent.temperature >= 21) - itemValue = shopItemDescriptor.HotValue; - else if (gameState.WeatherCurrent.temperature <= 11) - itemValue = shopItemDescriptor.ColdValue; - else - itemValue = shopItemDescriptor.BaseValue; + itemValue = getItemValue(shopItemDescriptor); itemValue -= price; uint8_t satisfaction = 0; if (itemValue > -8) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index e9b25e2eb0..138093cb60 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -64,7 +64,6 @@ #include "../ui/WindowManager.h" #include "../util/Util.h" #include "../windows/Intent.h" -#include "../world/Climate.h" #include "../world/Park.h" #include "../world/Scenery.h" #include "Viewport.h" diff --git a/src/openrct2/object/ClimateObject.cpp b/src/openrct2/object/ClimateObject.cpp index 4510934cc7..7fafcd3273 100644 --- a/src/openrct2/object/ClimateObject.cpp +++ b/src/openrct2/object/ClimateObject.cpp @@ -82,11 +82,20 @@ void ClimateObject::ReadJson(IReadObjectContext* context, json_t& root) _climate = convertRawClimate(rawClimate); _scriptName = Json::GetString(root["scriptName"], std::string(GetIdentifier())); + + Guard::Assert(root["properties"].is_object(), "ClimateObject::ReadJson expects properties key to be an object"); + _climate.itemThresholds.cold = Json::GetNumber(root["properties"]["coldItemTempThreshold"], 11); + _climate.itemThresholds.warm = Json::GetNumber(root["properties"]["warmItemTempThreshold"], 21); +} + +const TemperatureThresholds& ClimateObject::getItemThresholds() const +{ + return _climate.itemThresholds; } const WeatherPattern& ClimateObject::getPatternForMonth(uint8_t month) const { - return _climate[month]; + return _climate.patterns[month]; } std::string ClimateObject::getScriptName() const @@ -124,7 +133,7 @@ static Climate convertRawClimate(const RawClimate& rawClimate) for (auto m = 0; m < kNumClimateMonths; m++) { auto& srcMonth = rawClimate[m]; - auto& dstMonth = climate[m]; + auto& dstMonth = climate.patterns[m]; dstMonth.baseTemperature = srcMonth.baseTemperature; dstMonth.randomBias = srcMonth.randomBias; diff --git a/src/openrct2/object/ClimateObject.h b/src/openrct2/object/ClimateObject.h index b900292781..a8f2637f18 100644 --- a/src/openrct2/object/ClimateObject.h +++ b/src/openrct2/object/ClimateObject.h @@ -31,6 +31,7 @@ public: void DrawPreview(DrawPixelInfo& dpi, int32_t width, int32_t height) const override; + const TemperatureThresholds& getItemThresholds() const; const WeatherPattern& getPatternForMonth(uint8_t month) const; std::string getScriptName() const; YearlyDistribution getYearlyDistribution() const; diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index 1bf2794e13..7c2e2ca40f 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -49,7 +49,17 @@ struct WeatherPattern WeatherType distribution[kWeatherDistSize]; }; -using Climate = std::array; +struct TemperatureThresholds +{ + int8_t cold; + int8_t warm; +}; + +struct Climate +{ + std::array patterns; + TemperatureThresholds itemThresholds; +}; enum class WeatherEffectType : uint8_t {