From 68202db51c52860d4317e3583943d64a2df34bff Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 6 Jan 2018 01:20:28 +0000 Subject: [PATCH] Make ClimateWeatherData and ClimateWeatherGloomColours internal to Climate.cpp --- src/openrct2-ui/windows/GameBottomToolbar.cpp | 8 ++-- src/openrct2/Game.cpp | 7 ++-- src/openrct2/drawing/Drawing.h | 2 + src/openrct2/interface/Viewport.cpp | 8 ++-- src/openrct2/world/Climate.cpp | 37 +++++++++++++++---- src/openrct2/world/Climate.h | 9 +++-- 6 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 0829109c04..20d5e34da2 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -585,15 +585,17 @@ static void window_game_bottom_toolbar_draw_right_panel(rct_drawpixelinfo *dpi, x += 30; // Current weather - gfx_draw_sprite(dpi, ClimateWeatherData[gClimateCurrent.Weather].SpriteId, x, y, 0); + auto currentWeatherSpriteId = climate_get_weather_sprite_id(gClimateCurrent); + gfx_draw_sprite(dpi, currentWeatherSpriteId, x, y, 0); // Next weather - if (ClimateWeatherData[gClimateCurrent.Weather].SpriteId != ClimateWeatherData[gClimateNext.Weather].SpriteId) + auto nextWeatherSpriteId = climate_get_weather_sprite_id(gClimateNext); + if (currentWeatherSpriteId != nextWeatherSpriteId) { if (gClimateUpdateTimer < 960) { gfx_draw_sprite(dpi, SPR_NEXT_WEATHER, x + 27, y + 5, 0); - gfx_draw_sprite(dpi, ClimateWeatherData[gClimateNext.Weather].SpriteId, x + 40, y, 0); + gfx_draw_sprite(dpi, nextWeatherSpriteId, x + 40, y, 0); } } } diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 87b3cfc07e..f2d7654941 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -231,12 +231,11 @@ void update_palette_effects() uint32 shade = 0; if (gConfigGeneral.render_weather_gloom) { - uint8 gloom = gClimateCurrent.WeatherGloom; - if (gloom != 0) + auto paletteId = climate_get_weather_gloom_palette_id(&gClimateCurrent); + if (paletteId != PALETTE_NULL) { - FILTER_PALETTE_ID weatherColour = ClimateWeatherGloomColours[gloom]; shade = 1; - if (weatherColour != PALETTE_DARKEN_1) + if (paletteId != PALETTE_DARKEN_1) { shade = 2; } diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 90b6e21f11..dee33ec8ab 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -80,6 +80,8 @@ enum { }; typedef enum { + PALETTE_NULL = 0, + PALETTE_WATER = 32, PALETTE_34 = 34, diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 5076b4ceb4..85936a5937 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -914,16 +914,16 @@ static void viewport_paint_column(rct_drawpixelinfo * dpi, uint32 viewFlags) static void viewport_paint_weather_gloom(rct_drawpixelinfo * dpi) { - uint8 gloom = gClimateCurrent.WeatherGloom; - if (gloom != 0) { + FILTER_PALETTE_ID paletteId = climate_get_weather_gloom_palette_id(&gClimateCurrent); + if (paletteId != PALETTE_NULL) + { gfx_filter_rect( dpi, dpi->x, dpi->y, dpi->width + dpi->x - 1, dpi->height + dpi->y - 1, - ClimateWeatherGloomColours[gloom] - ); + paletteId); } } diff --git a/src/openrct2/world/Climate.cpp b/src/openrct2/world/Climate.cpp index 4a1c6a18c0..215c45f3de 100644 --- a/src/openrct2/world/Climate.cpp +++ b/src/openrct2/world/Climate.cpp @@ -14,21 +14,21 @@ *****************************************************************************/ #pragma endregion -#include "../config/Config.h" -#include "../core/Math.hpp" -#include "../OpenRCT2.h" -#include "Climate.h" - #include "../audio/audio.h" #include "../audio/AudioMixer.h" #include "../Cheats.h" +#include "../config/Config.h" +#include "../core/Math.hpp" +#include "../core/Util.hpp" #include "../drawing/Drawing.h" #include "../Game.h" #include "../interface/Window.h" #include "../localisation/Date.h" +#include "../OpenRCT2.h" #include "../scenario/Scenario.h" #include "../sprites.h" #include "../util/Util.h" +#include "Climate.h" constexpr sint32 MAX_THUNDER_INSTANCES = 2; @@ -45,7 +45,9 @@ struct WeatherTransition sint8 Distribution[24]; }; -extern const WeatherTransition * ClimateTransitions[4]; +extern const WeatherTransition * ClimateTransitions[4]; +extern const WeatherState ClimateWeatherData[6]; +extern const FILTER_PALETTE_ID ClimateWeatherGloomColours[4]; // Climate data uint8 gClimate; @@ -206,6 +208,27 @@ extern "C" climate_update_rain_sound(); climate_update_thunder_sound(); } + + FILTER_PALETTE_ID climate_get_weather_gloom_palette_id(const ClimateState * state) + { + auto paletteId = PALETTE_NULL; + auto gloom = state->WeatherGloom; + if (gloom < Util::CountOf(ClimateWeatherGloomColours)) + { + paletteId = ClimateWeatherGloomColours[gloom]; + } + return paletteId; + } +} + +uint32 climate_get_weather_sprite_id(const ClimateState &state) +{ + uint32 spriteId = SPR_WEATHER_SUN; + if (state.Weather < Util::CountOf(ClimateWeatherData)) + { + spriteId = ClimateWeatherData[state.Weather].SpriteId; + } + return spriteId; } static sint8 climate_step_weather_level(sint8 currentWeatherLevel, sint8 nextWeatherLevel) @@ -371,7 +394,7 @@ static void climate_play_thunder(sint32 instanceIndex, sint32 soundId, sint32 vo const FILTER_PALETTE_ID ClimateWeatherGloomColours[4] = { - (FILTER_PALETTE_ID)0, + PALETTE_NULL, PALETTE_DARKEN_1, PALETTE_DARKEN_2, PALETTE_DARKEN_3, diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index 21d4bbfb33..ef7fc05a84 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -66,14 +66,17 @@ extern "C" extern uint16 gClimateUpdateTimer; extern uint16 gClimateLightningFlash; - extern const WeatherState ClimateWeatherData[6]; - extern const FILTER_PALETTE_ID ClimateWeatherGloomColours[4]; - sint32 climate_celsius_to_fahrenheit(sint32 celsius); void climate_reset(sint32 climate); void climate_update(); void climate_update_sound(); void climate_force_weather(uint8 weather); + + FILTER_PALETTE_ID climate_get_weather_gloom_palette_id(const ClimateState * state); + #ifdef __cplusplus } + +uint32 climate_get_weather_sprite_id(const ClimateState &state); + #endif