1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Move item temperature thresholds to climate objects

This commit is contained in:
Aaron van Geffen
2025-03-07 18:57:00 +01:00
parent fb9df58e1c
commit 2ce206ed03
5 changed files with 45 additions and 21 deletions

View File

@@ -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<ClimateObject>(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)

View File

@@ -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"

View File

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

View File

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

View File

@@ -49,7 +49,17 @@ struct WeatherPattern
WeatherType distribution[kWeatherDistSize];
};
using Climate = std::array<WeatherPattern, kNumClimateMonths>;
struct TemperatureThresholds
{
int8_t cold;
int8_t warm;
};
struct Climate
{
std::array<WeatherPattern, kNumClimateMonths> patterns;
TemperatureThresholds itemThresholds;
};
enum class WeatherEffectType : uint8_t
{