From 93ef28927f0f6445ce5b4668e4c4e6c9497e3b02 Mon Sep 17 00:00:00 2001 From: Sidney <27780930+autinerd@users.noreply.github.com> Date: Fri, 7 Aug 2020 18:10:59 +0200 Subject: [PATCH] Close #12447: Refactor WEATHER_EFFECT to use strong enum (#12548) --- src/openrct2/rct1/S4Importer.cpp | 4 ++-- src/openrct2/rct2/S6Exporter.cpp | 4 ++-- src/openrct2/rct2/S6Importer.cpp | 4 ++-- src/openrct2/world/Climate.cpp | 16 ++++++++-------- src/openrct2/world/Climate.h | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index bd84d97fdd..7f4f44d3f9 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2665,12 +2665,12 @@ private: gClimateUpdateTimer = _s4.climate_timer; gClimateCurrent.Temperature = _s4.temperature; gClimateCurrent.Weather = _s4.weather; - gClimateCurrent.WeatherEffect = WEATHER_EFFECT_NONE; + gClimateCurrent.WeatherEffect = WeatherEffectType::None; gClimateCurrent.WeatherGloom = _s4.weather_gloom; gClimateCurrent.Level = static_cast(_s4.rain); gClimateNext.Temperature = _s4.target_temperature; gClimateNext.Weather = _s4.target_weather; - gClimateNext.WeatherEffect = WEATHER_EFFECT_NONE; + gClimateNext.WeatherEffect = WeatherEffectType::None; gClimateNext.WeatherGloom = _s4.target_weather_gloom; gClimateNext.Level = static_cast(_s4.target_rain); } diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 909ad84bd9..5b40f2b508 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -387,8 +387,8 @@ void S6Exporter::Export() _s6.next_weather = gClimateNext.Weather; _s6.temperature = gClimateCurrent.Temperature; _s6.next_temperature = gClimateNext.Temperature; - _s6.current_weather_effect = gClimateCurrent.WeatherEffect; - _s6.next_weather_effect = gClimateNext.WeatherEffect; + _s6.current_weather_effect = static_cast(gClimateCurrent.WeatherEffect); + _s6.next_weather_effect = static_cast(gClimateNext.WeatherEffect); _s6.current_weather_gloom = gClimateCurrent.WeatherGloom; _s6.next_weather_gloom = gClimateNext.WeatherGloom; _s6.current_rain_level = static_cast(gClimateCurrent.Level); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index f2a11a9ffa..1d1379ab6d 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -414,8 +414,8 @@ public: gClimateNext.Weather = _s6.next_weather; gClimateCurrent.Temperature = _s6.temperature; gClimateNext.Temperature = _s6.next_temperature; - gClimateCurrent.WeatherEffect = _s6.current_weather_effect; - gClimateNext.WeatherEffect = _s6.next_weather_effect; + gClimateCurrent.WeatherEffect = WeatherEffectType{ _s6.current_weather_effect }; + gClimateNext.WeatherEffect = WeatherEffectType{ _s6.next_weather_effect }; gClimateCurrent.WeatherGloom = _s6.current_weather_gloom; gClimateNext.WeatherGloom = _s6.next_weather_gloom; gClimateCurrent.Level = static_cast(_s6.current_rain_level); diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index f47e013451..716cf024fe 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -169,7 +169,7 @@ void climate_update() climate_update_lightning(); climate_update_thunder(); } - else if (gClimateCurrent.WeatherEffect == WEATHER_EFFECT_STORM) + else if (gClimateCurrent.WeatherEffect == WeatherEffectType::Storm) { // Create new thunder and lightning uint32_t randomNumber = util_rand(); @@ -277,7 +277,7 @@ static void climate_determine_future_weather(int32_t randomDistribution) static void climate_update_rain_sound() { - if (gClimateCurrent.WeatherEffect == WEATHER_EFFECT_RAIN || gClimateCurrent.WeatherEffect == WEATHER_EFFECT_STORM) + if (gClimateCurrent.WeatherEffect == WeatherEffectType::Rain || gClimateCurrent.WeatherEffect == WeatherEffectType::Storm) { // Start playing the rain sound if (gRainSoundChannel == nullptr) @@ -412,12 +412,12 @@ const FILTER_PALETTE_ID ClimateWeatherGloomColours[4] = { // There is actually a sprite at 0x5A9C for snow but only these weather types seem to be fully implemented const WeatherState ClimateWeatherData[6] = { - { 10, WEATHER_EFFECT_NONE, 0, RainLevel::None, SPR_WEATHER_SUN }, // Sunny - { 5, WEATHER_EFFECT_NONE, 0, RainLevel::None, SPR_WEATHER_SUN_CLOUD }, // Partially Cloudy - { 0, WEATHER_EFFECT_NONE, 0, RainLevel::None, SPR_WEATHER_CLOUD }, // Cloudy - { -2, WEATHER_EFFECT_RAIN, 1, RainLevel::Light, SPR_WEATHER_LIGHT_RAIN }, // Rain - { -4, WEATHER_EFFECT_RAIN, 2, RainLevel::Heavy, SPR_WEATHER_HEAVY_RAIN }, // Heavy Rain - { 2, WEATHER_EFFECT_STORM, 2, RainLevel::Heavy, SPR_WEATHER_STORM }, // Thunderstorm + { 10, WeatherEffectType::None, 0, RainLevel::None, SPR_WEATHER_SUN }, // Sunny + { 5, WeatherEffectType::None, 0, RainLevel::None, SPR_WEATHER_SUN_CLOUD }, // Partially Cloudy + { 0, WeatherEffectType::None, 0, RainLevel::None, SPR_WEATHER_CLOUD }, // Cloudy + { -2, WeatherEffectType::Rain, 1, RainLevel::Light, SPR_WEATHER_LIGHT_RAIN }, // Rain + { -4, WeatherEffectType::Rain, 2, RainLevel::Heavy, SPR_WEATHER_HEAVY_RAIN }, // Heavy Rain + { 2, WeatherEffectType::Storm, 2, RainLevel::Heavy, SPR_WEATHER_STORM }, // Thunderstorm }; static constexpr const WeatherTransition ClimateTransitionsCoolAndWet[] = { diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index c549375379..4619e290b8 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -31,11 +31,11 @@ enum WEATHER WEATHER_THUNDER, }; -enum WEATHER_EFFECT +enum class WeatherEffectType : uint8_t { - WEATHER_EFFECT_NONE, - WEATHER_EFFECT_RAIN, - WEATHER_EFFECT_STORM, + None, + Rain, + Storm, }; enum class RainLevel @@ -48,7 +48,7 @@ enum class RainLevel struct WeatherState { int8_t TemperatureDelta; - int8_t EffectLevel; + WeatherEffectType EffectLevel; int8_t GloomLevel; RainLevel Level; uint32_t SpriteId; @@ -58,7 +58,7 @@ struct ClimateState { uint8_t Weather; int8_t Temperature; - uint8_t WeatherEffect; + WeatherEffectType WeatherEffect; uint8_t WeatherGloom; RainLevel Level; };