Move gClimateCurrent to GameState_t

This commit is contained in:
Harry Hopkinson 2024-01-24 10:18:54 +00:00 committed by GitHub
parent ab80a9b007
commit 42336915cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 76 additions and 67 deletions

View File

@ -25,7 +25,6 @@
#include <openrct2/network/network.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <openrct2/world/Climate.h>
#include <openrct2/world/Park.h>
#include <openrct2/world/Surface.h>
@ -509,7 +508,8 @@ public:
}
// Current weather
window_cheats_misc_widgets[WIDX_WEATHER].text = WeatherTypes[EnumValue(gClimateCurrent.Weather)];
window_cheats_misc_widgets[WIDX_WEATHER].text = WeatherTypes[EnumValue(
OpenRCT2::GetGameState().ClimateCurrent.Weather)];
// Staff speed
window_cheats_misc_widgets[WIDX_STAFF_SPEED].text = _staffSpeedNames[EnumValue(gCheatsSelectedStaffSpeed)];
@ -834,7 +834,7 @@ private:
{ windowPos.x + dropdownWidget->left, windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1,
colours[1], 0, Dropdown::Flag::StayOpen, std::size(WeatherTypes), dropdownWidget->width() - 3);
auto currentWeather = gClimateCurrent.Weather;
auto currentWeather = OpenRCT2::GetGameState().ClimateCurrent.Weather;
Dropdown::SetChecked(EnumValue(currentWeather), true);
}
break;

View File

@ -27,7 +27,6 @@
#include <openrct2/management/Finance.h>
#include <openrct2/management/NewsItem.h>
#include <openrct2/sprites.h>
#include <openrct2/world/Climate.h>
#include <openrct2/world/Park.h>
using namespace OpenRCT2;
@ -206,7 +205,7 @@ private:
screenCoords = { windowPos.x + window_game_bottom_toolbar_widgets[WIDX_RIGHT_OUTSET].left + 15,
static_cast<int32_t>(screenCoords.y + line_height + 1) };
int32_t temperature = gClimateCurrent.Temperature;
int32_t temperature = OpenRCT2::GetGameState().ClimateCurrent.Temperature;
StringId format = STR_CELSIUS_VALUE;
if (gConfigGeneral.TemperatureFormat == TemperatureUnit::Fahrenheit)
{
@ -219,7 +218,7 @@ private:
screenCoords.x += 30;
// Current weather
auto currentWeatherSpriteId = ClimateGetWeatherSpriteId(gClimateCurrent);
auto currentWeatherSpriteId = ClimateGetWeatherSpriteId(OpenRCT2::GetGameState().ClimateCurrent);
GfxDrawSprite(dpi, ImageId(currentWeatherSpriteId), screenCoords);
// Next weather

View File

@ -214,7 +214,7 @@ void UpdatePaletteEffects()
uint32_t shade = 0;
if (gConfigGeneral.RenderWeatherGloom)
{
auto paletteId = ClimateGetWeatherGloomPaletteId(gClimateCurrent);
auto paletteId = ClimateGetWeatherGloomPaletteId(GetGameState().ClimateCurrent);
if (paletteId != FilterPaletteID::PaletteNull)
{
shade = 1;

View File

@ -28,6 +28,7 @@ namespace OpenRCT2
uint64_t ParkFlags;
uint16_t ParkRating;
ClimateType Climate;
ClimateState ClimateCurrent;
ClimateState ClimateNext;
money64 Cash;
money64 InitialCash;

View File

@ -10,6 +10,7 @@
#include "LightFX.h"
#include "../Game.h"
#include "../GameState.h"
#include "../common.h"
#include "../config/Config.h"
#include "../entity/EntityRegistry.h"
@ -21,7 +22,6 @@
#include "../ride/RideData.h"
#include "../ride/Vehicle.h"
#include "../util/Util.h"
#include "../world/Climate.h"
#include "../world/Map.h"
#include "Drawing.h"
@ -838,6 +838,8 @@ void LightFxAddShopLights(const CoordsXY& mapPosition, const uint8_t direction,
void LightFXApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b)
{
auto& gameState = OpenRCT2::GetGameState();
float night = static_cast<float>(pow(gDayNightCycle, 1.5));
float natLightR = 1.0f;
@ -867,9 +869,9 @@ void LightFXApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b)
// overExpose += ((lightMax - lightAvg) / lightMax) * 0.01f;
if (gClimateCurrent.Temperature > 20)
if (gameState.ClimateCurrent.Temperature > 20)
{
float offset = (static_cast<float>(gClimateCurrent.Temperature - 20)) * 0.04f;
float offset = (static_cast<float>(gameState.ClimateCurrent.Temperature - 20)) * 0.04f;
offset *= 1.0f - night;
lightAvg /= 1.0f + offset;
// overExpose += offset * 0.1f;
@ -891,12 +893,12 @@ void LightFXApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b)
natLightB *= 1.0f + overExpose;
overExpose *= 255.0f;
float targetFogginess = static_cast<float>(gClimateCurrent.Level) / 8.0f;
float targetFogginess = static_cast<float>(gameState.ClimateCurrent.Level) / 8.0f;
targetFogginess += (night * night) * 0.15f;
if (gClimateCurrent.Temperature < 10)
if (gameState.ClimateCurrent.Temperature < 10)
{
targetFogginess += (static_cast<float>(10 - gClimateCurrent.Temperature)) * 0.01f;
targetFogginess += (static_cast<float>(10 - gameState.ClimateCurrent.Temperature)) * 0.01f;
}
fogginess -= (fogginess - targetFogginess) * 0.00001f;
@ -934,7 +936,7 @@ void LightFXApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b)
natLightG /= 1.0f + lightPolution;
natLightB /= 1.0f + lightPolution;
reduceColourLit += static_cast<float>(gClimateCurrent.Level) / 2.0f;
reduceColourLit += static_cast<float>(gameState.ClimateCurrent.Level) / 2.0f;
reduceColourNat /= 1.0f + fogginess;
reduceColourLit /= 1.0f + fogginess;

View File

@ -63,7 +63,7 @@ void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer)
viewFlags = viewport->flags;
// Get weather draw function and draw weather
auto weatherLevel = gClimateCurrent.Level;
auto weatherLevel = GetGameState().ClimateCurrent.Level;
if (weatherLevel != WeatherLevel::None && !gTrackDesignSaveMode && !(viewFlags & VIEWPORT_FLAG_HIGHLIGHT_PATH_ISSUES))
{
auto drawFunc = DrawRainFunctions[static_cast<int8_t>(weatherLevel)];

View File

@ -1513,7 +1513,9 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price)
return false;
}
if ((shopItem == ShopItem::Sunglasses || shopItem == ShopItem::IceCream) && gClimateCurrent.Temperature < 12)
auto& gameState = GetGameState();
if ((shopItem == ShopItem::Sunglasses || shopItem == ShopItem::IceCream) && gameState.ClimateCurrent.Temperature < 12)
{
return false;
}
@ -1552,9 +1554,9 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price)
}
}
if (gClimateCurrent.Temperature >= 21)
if (gameState.ClimateCurrent.Temperature >= 21)
itemValue = shopItemDescriptor.HotValue;
else if (gClimateCurrent.Temperature <= 11)
else if (gameState.ClimateCurrent.Temperature <= 11)
itemValue = shopItemDescriptor.ColdValue;
else
itemValue = shopItemDescriptor.BaseValue;
@ -1600,9 +1602,9 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price)
}
// reset itemValue for satisfaction calculation
if (gClimateCurrent.Temperature >= 21)
if (gameState.ClimateCurrent.Temperature >= 21)
itemValue = shopItemDescriptor.HotValue;
else if (gClimateCurrent.Temperature <= 11)
else if (gameState.ClimateCurrent.Temperature <= 11)
itemValue = shopItemDescriptor.ColdValue;
else
itemValue = shopItemDescriptor.BaseValue;
@ -3053,7 +3055,7 @@ static void PeepDecideWhetherToLeavePark(Guest* peep)
peep->EnergyTarget -= 2;
}
if (gClimateCurrent.Temperature >= 21 && peep->Thirst >= 5)
if (GetGameState().ClimateCurrent.Temperature >= 21 && peep->Thirst >= 5)
{
peep->Thirst--;
}

View File

@ -11,6 +11,7 @@
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../Input.h"
#include "../OpenRCT2.h"
#include "../config/Config.h"
@ -1018,7 +1019,7 @@ void ViewportPaint(const Viewport* viewport, DrawPixelInfo& dpi, const ScreenRec
static void ViewportPaintWeatherGloom(DrawPixelInfo& dpi)
{
auto paletteId = ClimateGetWeatherGloomPaletteId(gClimateCurrent);
auto paletteId = ClimateGetWeatherGloomPaletteId(GetGameState().ClimateCurrent);
if (paletteId != FilterPaletteID::PaletteNull)
{
// Only scale width if zoomed in more than 1:1

View File

@ -784,7 +784,7 @@ namespace OpenRCT2
cs.ReadWrite(gameState.Climate);
cs.ReadWrite(gClimateUpdateTimer);
for (auto* cl : { &gClimateCurrent, &gameState.ClimateNext })
for (auto* cl : { &gameState.ClimateCurrent, &gameState.ClimateNext })
{
cs.ReadWrite(cl->Weather);
cs.ReadWrite(cl->Temperature);

View File

@ -2280,11 +2280,11 @@ namespace RCT1
{
gameState.Climate = ClimateType{ _s4.Climate };
gClimateUpdateTimer = _s4.ClimateTimer;
gClimateCurrent.Temperature = _s4.Temperature;
gClimateCurrent.Weather = WeatherType{ _s4.Weather };
gClimateCurrent.WeatherEffect = WeatherEffectType::None;
gClimateCurrent.WeatherGloom = _s4.WeatherGloom;
gClimateCurrent.Level = static_cast<WeatherLevel>(_s4.Rain);
gameState.ClimateCurrent.Temperature = _s4.Temperature;
gameState.ClimateCurrent.Weather = WeatherType{ _s4.Weather };
gameState.ClimateCurrent.WeatherEffect = WeatherEffectType::None;
gameState.ClimateCurrent.WeatherGloom = _s4.WeatherGloom;
gameState.ClimateCurrent.Level = static_cast<WeatherLevel>(_s4.Rain);
gameState.ClimateNext.Temperature = _s4.TargetTemperature;
gameState.ClimateNext.Weather = WeatherType{ _s4.TargetWeather };
gameState.ClimateNext.WeatherEffect = WeatherEffectType::None;

View File

@ -456,15 +456,15 @@ namespace RCT2
// Byte13CA742
// Pad013CA747
gClimateUpdateTimer = _s6.ClimateUpdateTimer;
gClimateCurrent.Weather = WeatherType{ _s6.CurrentWeather };
gameState.ClimateCurrent.Weather = WeatherType{ _s6.CurrentWeather };
gameState.ClimateNext.Weather = WeatherType{ _s6.NextWeather };
gClimateCurrent.Temperature = _s6.Temperature;
gameState.ClimateCurrent.Temperature = _s6.Temperature;
gameState.ClimateNext.Temperature = _s6.NextTemperature;
gClimateCurrent.WeatherEffect = WeatherEffectType{ _s6.CurrentWeatherEffect };
gameState.ClimateCurrent.WeatherEffect = WeatherEffectType{ _s6.CurrentWeatherEffect };
gameState.ClimateNext.WeatherEffect = WeatherEffectType{ _s6.NextWeatherEffect };
gClimateCurrent.WeatherGloom = _s6.CurrentWeatherGloom;
gameState.ClimateCurrent.WeatherGloom = _s6.CurrentWeatherGloom;
gameState.ClimateNext.WeatherGloom = _s6.NextWeatherGloom;
gClimateCurrent.Level = static_cast<WeatherLevel>(_s6.CurrentWeatherLevel);
gameState.ClimateCurrent.Level = static_cast<WeatherLevel>(_s6.CurrentWeatherLevel);
gameState.ClimateNext.Level = static_cast<WeatherLevel>(_s6.NextWeatherLevel);
// News items

View File

@ -108,8 +108,9 @@ namespace OpenRCT2::Scripting
std::shared_ptr<ScClimateState> current_get() const
{
std::string weatherType = WeatherTypeToString(gClimateCurrent.Weather);
return std::make_shared<ScClimateState>(weatherType, gClimateCurrent.Temperature);
auto& gameState = OpenRCT2::GetGameState();
std::string weatherType = WeatherTypeToString(gameState.ClimateCurrent.Weather);
return std::make_shared<ScClimateState>(weatherType, gameState.ClimateCurrent.Temperature);
}
std::shared_ptr<ScClimateState> future_get() const

View File

@ -54,7 +54,6 @@ extern const WeatherState ClimateWeatherData[EnumValue(WeatherType::Count)];
extern const FilterPaletteID ClimateWeatherGloomColours[4];
// Climate data
ClimateState gClimateCurrent;
uint16_t gClimateUpdateTimer;
uint16_t gClimateLightningFlash;
@ -97,11 +96,11 @@ void ClimateReset(ClimateType climate)
const WeatherState* weatherState = &ClimateWeatherData[EnumValue(weather)];
gameState.Climate = climate;
gClimateCurrent.Weather = weather;
gClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta;
gClimateCurrent.WeatherEffect = weatherState->EffectLevel;
gClimateCurrent.WeatherGloom = weatherState->GloomLevel;
gClimateCurrent.Level = weatherState->Level;
gameState.ClimateCurrent.Weather = weather;
gameState.ClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta;
gameState.ClimateCurrent.WeatherEffect = weatherState->EffectLevel;
gameState.ClimateCurrent.WeatherGloom = weatherState->GloomLevel;
gameState.ClimateCurrent.Level = weatherState->Level;
_lightningTimer = 0;
_thunderTimer = 0;
@ -141,38 +140,39 @@ void ClimateUpdate()
}
else if (!(gameState.CurrentTicks & 0x7F))
{
if (gClimateCurrent.Temperature == gameState.ClimateNext.Temperature)
if (gameState.ClimateCurrent.Temperature == gameState.ClimateNext.Temperature)
{
if (gClimateCurrent.WeatherGloom == gameState.ClimateNext.WeatherGloom)
if (gameState.ClimateCurrent.WeatherGloom == gameState.ClimateNext.WeatherGloom)
{
gClimateCurrent.WeatherEffect = gameState.ClimateNext.WeatherEffect;
gameState.ClimateCurrent.WeatherEffect = gameState.ClimateNext.WeatherEffect;
_thunderTimer = 0;
_lightningTimer = 0;
if (gClimateCurrent.Level == gameState.ClimateNext.Level)
if (gameState.ClimateCurrent.Level == gameState.ClimateNext.Level)
{
gClimateCurrent.Weather = gameState.ClimateNext.Weather;
gameState.ClimateCurrent.Weather = gameState.ClimateNext.Weather;
ClimateDetermineFutureWeather(ScenarioRand());
auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE);
ContextBroadcastIntent(&intent);
}
else if (gameState.ClimateNext.Level <= WeatherLevel::Heavy)
{
gClimateCurrent.Level = static_cast<WeatherLevel>(ClimateStepWeatherLevel(
static_cast<int8_t>(gClimateCurrent.Level), static_cast<int8_t>(gameState.ClimateNext.Level)));
gameState.ClimateCurrent.Level = static_cast<WeatherLevel>(ClimateStepWeatherLevel(
static_cast<int8_t>(gameState.ClimateCurrent.Level),
static_cast<int8_t>(gameState.ClimateNext.Level)));
}
}
else
{
gClimateCurrent.WeatherGloom = ClimateStepWeatherLevel(
gClimateCurrent.WeatherGloom, gameState.ClimateNext.WeatherGloom);
gameState.ClimateCurrent.WeatherGloom = ClimateStepWeatherLevel(
gameState.ClimateCurrent.WeatherGloom, gameState.ClimateNext.WeatherGloom);
GfxInvalidateScreen();
}
}
else
{
gClimateCurrent.Temperature = ClimateStepWeatherLevel(
gClimateCurrent.Temperature, gameState.ClimateNext.Temperature);
gameState.ClimateCurrent.Temperature = ClimateStepWeatherLevel(
gameState.ClimateCurrent.Temperature, gameState.ClimateNext.Temperature);
auto intent = Intent(INTENT_ACTION_UPDATE_CLIMATE);
ContextBroadcastIntent(&intent);
}
@ -185,8 +185,8 @@ void ClimateUpdate()
ClimateUpdateThunder();
}
else if (
gClimateCurrent.WeatherEffect == WeatherEffectType::Storm
|| gClimateCurrent.WeatherEffect == WeatherEffectType::Blizzard)
gameState.ClimateCurrent.WeatherEffect == WeatherEffectType::Storm
|| gameState.ClimateCurrent.WeatherEffect == WeatherEffectType::Blizzard)
{
// Create new thunder and lightning
uint32_t randomNumber = UtilRand();
@ -206,11 +206,11 @@ void ClimateForceWeather(WeatherType weather)
const WeatherTransition* transition = &ClimateTransitions[static_cast<uint8_t>(gameState.Climate)][month];
const auto weatherState = &ClimateWeatherData[EnumValue(weather)];
gClimateCurrent.Weather = weather;
gClimateCurrent.WeatherGloom = weatherState->GloomLevel;
gClimateCurrent.Level = weatherState->Level;
gClimateCurrent.WeatherEffect = weatherState->EffectLevel;
gClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta;
gameState.ClimateCurrent.Weather = weather;
gameState.ClimateCurrent.WeatherGloom = weatherState->GloomLevel;
gameState.ClimateCurrent.Level = weatherState->Level;
gameState.ClimateCurrent.WeatherEffect = weatherState->EffectLevel;
gameState.ClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta;
gClimateUpdateTimer = 1920;
ClimateUpdate();
@ -235,8 +235,9 @@ void ClimateUpdateSound()
bool ClimateIsRaining()
{
if (gClimateCurrent.Weather == WeatherType::Rain || gClimateCurrent.Weather == WeatherType::HeavyRain
|| gClimateCurrent.Weather == WeatherType::Thunder)
auto& gameState = GetGameState();
if (gameState.ClimateCurrent.Weather == WeatherType::Rain || gameState.ClimateCurrent.Weather == WeatherType::HeavyRain
|| gameState.ClimateCurrent.Weather == WeatherType::Thunder)
{
return true;
}
@ -246,8 +247,9 @@ bool ClimateIsRaining()
bool ClimateIsSnowing()
{
if (gClimateCurrent.Weather == WeatherType::Snow || gClimateCurrent.Weather == WeatherType::HeavySnow
|| gClimateCurrent.Weather == WeatherType::Blizzard)
auto& gameState = GetGameState();
if (gameState.ClimateCurrent.Weather == WeatherType::Snow || gameState.ClimateCurrent.Weather == WeatherType::HeavySnow
|| gameState.ClimateCurrent.Weather == WeatherType::Blizzard)
{
return true;
}
@ -320,7 +322,8 @@ static void ClimateDetermineFutureWeather(int32_t randomDistribution)
static void ClimateUpdateWeatherSound()
{
if (gClimateCurrent.WeatherEffect == WeatherEffectType::Rain || gClimateCurrent.WeatherEffect == WeatherEffectType::Storm)
if (GetGameState().ClimateCurrent.WeatherEffect == WeatherEffectType::Rain
|| GetGameState().ClimateCurrent.WeatherEffect == WeatherEffectType::Storm)
{
// Start playing the weather sound
if (_weatherSoundChannel == nullptr || _weatherSoundChannel->IsDone())

View File

@ -70,7 +70,6 @@ struct ClimateState
WeatherLevel Level;
};
extern ClimateState gClimateCurrent;
extern uint16_t gClimateUpdateTimer;
extern uint16_t gClimateLightningFlash;

View File

@ -12,6 +12,7 @@
#include "../Cheats.h"
#include "../Context.h"
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../actions/BannerRemoveAction.h"
#include "../actions/FootpathAdditionRemoveAction.h"
@ -33,7 +34,6 @@
#include "../object/SmallSceneryEntry.h"
#include "../object/WallSceneryEntry.h"
#include "../scenario/Scenario.h"
#include "Climate.h"
#include "Footpath.h"
#include "Map.h"
#include "Park.h"
@ -184,7 +184,8 @@ void SmallSceneryElement::UpdateAge(const CoordsXY& sceneryPos)
return;
}
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED) || WeatherIsDry(gClimateCurrent.Weather) || GetAge() < 5)
if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED)
|| WeatherIsDry(OpenRCT2::GetGameState().ClimateCurrent.Weather) || GetAge() < 5)
{
IncreaseAge(sceneryPos);
return;