Move gClimate to GameState_t

This commit is contained in:
Harry Hopkinson 2024-01-21 21:05:22 +00:00
parent 7ca5b1cd65
commit 0f283dc2a9
11 changed files with 24 additions and 15 deletions

View File

@ -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<uint8_t>(ClimateType::Count), dropdownWidget.width() - 3);
Dropdown::SetChecked(static_cast<uint8_t>(gClimate), true);
Dropdown::SetChecked(static_cast<uint8_t>(GetGameState().Climate), true);
}
void FinancialMouseDown(WidgetIndex widgetIndex)
@ -1110,7 +1110,7 @@ private:
break;
}
case WIDX_CLIMATE_DROPDOWN:
if (static_cast<uint8_t>(gClimate) != static_cast<uint8_t>(dropdownIndex))
if (static_cast<uint8_t>(GetGameState().Climate) != static_cast<uint8_t>(dropdownIndex))
{
auto gameAction = ClimateSetAction(ClimateType{ static_cast<uint8_t>(dropdownIndex) });
GameActions::Execute(&gameAction);
@ -1255,7 +1255,7 @@ private:
// Climate value
screenCoords = windowPos + ScreenCoordsXY{ climateWidget.left + 1, climateWidget.top };
auto ft = Formatter();
ft.Add<StringId>(ClimateNames[static_cast<uint8_t>(gClimate)]);
ft.Add<StringId>(ClimateNames[static_cast<uint8_t>(GetGameState().Climate)]);
DrawTextBasic(dpi, screenCoords, STR_WINDOW_COLOUR_2_STRINGID, ft);
}

View File

@ -313,6 +313,8 @@ namespace Editor
staff->SetName({});
}
auto& gameState = GetGameState();
ResetAllEntities();
UpdateConsolidatedPatrolAreas();
gNumGuestsInPark = 0;
@ -346,7 +348,7 @@ namespace Editor
gBankLoanInterestRate = std::clamp<uint8_t>(gBankLoanInterestRate, 5, MaxBankLoanInterestRate);
}
ClimateReset(gClimate);
ClimateReset(gameState.Climate);
News::InitQueue();
}

View File

@ -25,6 +25,7 @@ namespace OpenRCT2
struct GameState_t
{
uint32_t CurrentTicks{};
ClimateType Climate;
ClimateState ClimateNext;
money64 Cash;
money64 InitialCash;

View File

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

View File

@ -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<uint8_t>(gClimate)], static_cast<uint8_t>(gClimate));
"climate %s (%d)", ClimateNames[static_cast<uint8_t>(gameState.Climate)],
static_cast<uint8_t>(gameState.Climate));
}
else if (argv[0] == "game_speed")
{

View File

@ -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 })

View File

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

View File

@ -451,7 +451,7 @@ namespace RCT2
// unk_13CA73E
// Pad13CA73F
// unk_13CA740
gClimate = ClimateType{ _s6.Climate };
gameState.Climate = ClimateType{ _s6.Climate };
// Pad13CA741;
// Byte13CA742
// Pad013CA747

View File

@ -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<ScClimateState> current_get() const

View File

@ -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<uint8_t>(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<uint8_t>(gClimate)][month];
const WeatherTransition* transition = &ClimateTransitions[static_cast<uint8_t>(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<uint8_t>(gClimate)][month];
const WeatherTransition* transition = &ClimateTransitions[static_cast<uint8_t>(gameState.Climate)][month];
WeatherType nextWeather = (transition->Distribution[((randomDistribution & 0xFF) * transition->DistributionSize) >> 8]);
gameState.ClimateNext.Weather = nextWeather;

View File

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