From 0f283dc2a922698ea73e75371d56a1024042c9ae Mon Sep 17 00:00:00 2001 From: Harry Hopkinson Date: Sun, 21 Jan 2024 21:05:22 +0000 Subject: [PATCH] Move gClimate to GameState_t --- src/openrct2-ui/windows/EditorScenarioOptions.cpp | 6 +++--- src/openrct2/Editor.cpp | 4 +++- src/openrct2/GameState.h | 1 + src/openrct2/actions/ClimateSetAction.cpp | 4 +++- src/openrct2/interface/InteractiveConsole.cpp | 5 ++++- src/openrct2/park/ParkFile.cpp | 2 +- src/openrct2/rct1/S4Importer.cpp | 2 +- src/openrct2/rct2/S6Importer.cpp | 2 +- src/openrct2/scripting/bindings/world/ScClimate.hpp | 3 ++- src/openrct2/world/Climate.cpp | 9 +++++---- src/openrct2/world/Climate.h | 1 - 11 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp index 4d1ac035e0..039f882f18 100644 --- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp +++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp @@ -428,7 +428,7 @@ private: WindowDropdownShowTextCustomWidth( { windowPos.x + dropdownWidget.left, windowPos.y + dropdownWidget.top }, dropdownWidget.height() + 1, colours[1], 0, Dropdown::Flag::StayOpen, static_cast(ClimateType::Count), dropdownWidget.width() - 3); - Dropdown::SetChecked(static_cast(gClimate), true); + Dropdown::SetChecked(static_cast(GetGameState().Climate), true); } void FinancialMouseDown(WidgetIndex widgetIndex) @@ -1110,7 +1110,7 @@ private: break; } case WIDX_CLIMATE_DROPDOWN: - if (static_cast(gClimate) != static_cast(dropdownIndex)) + if (static_cast(GetGameState().Climate) != static_cast(dropdownIndex)) { auto gameAction = ClimateSetAction(ClimateType{ static_cast(dropdownIndex) }); GameActions::Execute(&gameAction); @@ -1255,7 +1255,7 @@ private: // Climate value screenCoords = windowPos + ScreenCoordsXY{ climateWidget.left + 1, climateWidget.top }; auto ft = Formatter(); - ft.Add(ClimateNames[static_cast(gClimate)]); + ft.Add(ClimateNames[static_cast(GetGameState().Climate)]); DrawTextBasic(dpi, screenCoords, STR_WINDOW_COLOUR_2_STRINGID, ft); } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 471efc0ef2..897f27c4d5 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -313,6 +313,8 @@ namespace Editor staff->SetName({}); } + auto& gameState = GetGameState(); + ResetAllEntities(); UpdateConsolidatedPatrolAreas(); gNumGuestsInPark = 0; @@ -346,7 +348,7 @@ namespace Editor gBankLoanInterestRate = std::clamp(gBankLoanInterestRate, 5, MaxBankLoanInterestRate); } - ClimateReset(gClimate); + ClimateReset(gameState.Climate); News::InitQueue(); } diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 3a7ef1e5c2..2b042dc1b2 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -25,6 +25,7 @@ namespace OpenRCT2 struct GameState_t { uint32_t CurrentTicks{}; + ClimateType Climate; ClimateState ClimateNext; money64 Cash; money64 InitialCash; diff --git a/src/openrct2/actions/ClimateSetAction.cpp b/src/openrct2/actions/ClimateSetAction.cpp index a5819e0e82..0ed19d5dc2 100644 --- a/src/openrct2/actions/ClimateSetAction.cpp +++ b/src/openrct2/actions/ClimateSetAction.cpp @@ -9,6 +9,8 @@ #include "ClimateSetAction.h" +#include "../GameState.h" + ClimateSetAction::ClimateSetAction(ClimateType climate) : _climate(climate) { @@ -43,7 +45,7 @@ GameActions::Result ClimateSetAction::Query() const GameActions::Result ClimateSetAction::Execute() const { - gClimate = ClimateType{ _climate }; + OpenRCT2::GetGameState().Climate = ClimateType{ _climate }; GfxInvalidateScreen(); diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 870d10ee2a..84295d9db8 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -551,6 +551,8 @@ static int32_t ConsoleCommandStaff(InteractiveConsole& console, const arguments_ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& argv) { + auto& gameState = GetGameState(); + if (!argv.empty()) { if (argv[0] == "park_rating") @@ -669,7 +671,8 @@ static int32_t ConsoleCommandGet(InteractiveConsole& console, const arguments_t& else if (argv[0] == "climate") { console.WriteFormatLine( - "climate %s (%d)", ClimateNames[static_cast(gClimate)], static_cast(gClimate)); + "climate %s (%d)", ClimateNames[static_cast(gameState.Climate)], + static_cast(gameState.Climate)); } else if (argv[0] == "game_speed") { diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 8b576d70b5..d5bf6047b6 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -781,7 +781,7 @@ namespace OpenRCT2 void ReadWriteClimateChunk(GameState_t& gameState, OrcaStream& os) { os.ReadWriteChunk(ParkFileChunkType::CLIMATE, [&gameState](OrcaStream::ChunkStream& cs) { - cs.ReadWrite(gClimate); + cs.ReadWrite(gameState.Climate); cs.ReadWrite(gClimateUpdateTimer); for (auto* cl : { &gClimateCurrent, &gameState.ClimateNext }) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index ed681a0344..06daf4df56 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2278,7 +2278,7 @@ namespace RCT1 void ImportClimate(GameState_t& gameState) { - gClimate = ClimateType{ _s4.Climate }; + gameState.Climate = ClimateType{ _s4.Climate }; gClimateUpdateTimer = _s4.ClimateTimer; gClimateCurrent.Temperature = _s4.Temperature; gClimateCurrent.Weather = WeatherType{ _s4.Weather }; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 8b863b73cc..e8068f4d46 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -451,7 +451,7 @@ namespace RCT2 // unk_13CA73E // Pad13CA73F // unk_13CA740 - gClimate = ClimateType{ _s6.Climate }; + gameState.Climate = ClimateType{ _s6.Climate }; // Pad13CA741; // Byte13CA742 // Pad013CA747 diff --git a/src/openrct2/scripting/bindings/world/ScClimate.hpp b/src/openrct2/scripting/bindings/world/ScClimate.hpp index 11bb0f96ed..6c3ad6a379 100644 --- a/src/openrct2/scripting/bindings/world/ScClimate.hpp +++ b/src/openrct2/scripting/bindings/world/ScClimate.hpp @@ -102,7 +102,8 @@ namespace OpenRCT2::Scripting std::string type_get() const { - return ClimateTypeToString(gClimate); + auto& gameState = OpenRCT2::GetGameState(); + return ClimateTypeToString(gameState.Climate); } std::shared_ptr current_get() const diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index a6f15858c9..176df0ad84 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -54,7 +54,6 @@ extern const WeatherState ClimateWeatherData[EnumValue(WeatherType::Count)]; extern const FilterPaletteID ClimateWeatherGloomColours[4]; // Climate data -ClimateType gClimate; ClimateState gClimateCurrent; uint16_t gClimateUpdateTimer; uint16_t gClimateLightningFlash; @@ -91,12 +90,13 @@ int32_t ClimateCelsiusToFahrenheit(int32_t celsius) */ void ClimateReset(ClimateType climate) { + auto& gameState = GetGameState(); auto weather = WeatherType::PartiallyCloudy; int32_t month = GetDate().GetMonth(); const WeatherTransition* transition = &ClimateTransitions[static_cast(climate)][month]; const WeatherState* weatherState = &ClimateWeatherData[EnumValue(weather)]; - gClimate = climate; + gameState.Climate = climate; gClimateCurrent.Weather = weather; gClimateCurrent.Temperature = transition->BaseTemperature + weatherState->TemperatureDelta; gClimateCurrent.WeatherEffect = weatherState->EffectLevel; @@ -201,8 +201,9 @@ void ClimateUpdate() void ClimateForceWeather(WeatherType weather) { + auto& gameState = GetGameState(); int32_t month = GetDate().GetMonth(); - const WeatherTransition* transition = &ClimateTransitions[static_cast(gClimate)][month]; + const WeatherTransition* transition = &ClimateTransitions[static_cast(gameState.Climate)][month]; const auto weatherState = &ClimateWeatherData[EnumValue(weather)]; gClimateCurrent.Weather = weather; @@ -304,7 +305,7 @@ static void ClimateDetermineFutureWeather(int32_t randomDistribution) // Generate a random variable with values 0 up to DistributionSize-1 and chose weather from the distribution table // accordingly - const WeatherTransition* transition = &ClimateTransitions[static_cast(gClimate)][month]; + const WeatherTransition* transition = &ClimateTransitions[static_cast(gameState.Climate)][month]; WeatherType nextWeather = (transition->Distribution[((randomDistribution & 0xFF) * transition->DistributionSize) >> 8]); gameState.ClimateNext.Weather = nextWeather; diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index 5d33db6c74..0160ca7c08 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -70,7 +70,6 @@ struct ClimateState WeatherLevel Level; }; -extern ClimateType gClimate; extern ClimateState gClimateCurrent; extern uint16_t gClimateUpdateTimer; extern uint16_t gClimateLightningFlash;