From a325bcc8569c83cb0370d590aa6e9d224162d99f Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 29 Apr 2014 12:35:37 +0100 Subject: [PATCH] define next climate variables, all refs rewritten --- src/climate.c | 28 +++++++++++++++++----------- src/climate.h | 1 + src/window_game_bottom_toolbar.c | 4 ++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/climate.c b/src/climate.c index 061ddd1bbb..e56938f550 100644 --- a/src/climate.c +++ b/src/climate.c @@ -30,11 +30,17 @@ typedef struct { sint8 distribution[24]; } rct_weather_transition; +int gClimateNextWeather; + +static int _climateNextTemperature; +static int _climateNextWeatherEffect; +static int _climateNextWeatherGloom; +static int _climateNextRainLevel; + static const rct_weather_transition* climate_transitions[4]; static void climate_determine_future_weather(); - int climate_celcius_to_fahrenheit(int celcius) { return (celcius * 29) / 16 + 32; @@ -61,11 +67,11 @@ void climate_update() { uint8 screen_flags = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8); sint8 temperature = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TEMPERATURE, sint8), - target_temperature = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_TEMPERATURE, sint8), + target_temperature = _climateNextTemperature, cur_gloom = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_GLOOM, sint8), - next_gloom = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_GLOOM, sint8), + next_gloom = _climateNextWeatherGloom, cur_rain = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RAIN_LEVEL, sint8), - next_rain = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_RAIN_LEVEL, sint8); + next_rain = _climateNextRainLevel; if (screen_flags & (~SCREEN_FLAGS_PLAYING)) // only normal play mode gets climate @@ -82,10 +88,10 @@ void climate_update() if (temperature == target_temperature) { if (cur_gloom == next_gloom) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_EFFECT, sint8) = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_EFFECT, sint8); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_EFFECT, sint8) = _climateNextWeatherEffect; if (cur_rain == next_rain) { - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8) = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8); + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8) = gClimateNextWeather; climate_determine_future_weather(); RCT2_GLOBAL(0x009A9804, uint32) |= 8; // climate dirty flag? } else { @@ -136,12 +142,12 @@ static void climate_determine_future_weather() // Generate a random variable with values 0 upto distribution_size-1 and chose weather from the distribution table accordingly sint8 next_weather = transition.distribution[ ((rand() & 0xFF) * transition.distribution_size) >> 8 ]; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8) = next_weather; + gClimateNextWeather = next_weather; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_TEMPERATURE, sint8) = transition.base_temperature + climate_weather_data[next_weather].temp_delta; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_EFFECT, sint8) = climate_weather_data[next_weather].effect_level; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_GLOOM, sint8) = climate_weather_data[next_weather].gloom_level; - RCT2_GLOBAL(RCT2_ADDRESS_NEXT_RAIN_LEVEL, sint8) = climate_weather_data[next_weather].rain_level; + _climateNextTemperature = transition.base_temperature + climate_weather_data[next_weather].temp_delta; + _climateNextWeatherEffect = climate_weather_data[next_weather].effect_level; + _climateNextWeatherGloom = climate_weather_data[next_weather].gloom_level; + _climateNextRainLevel = climate_weather_data[next_weather].rain_level; RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE_UPDATE_TIMER, sint16) = 1920; } diff --git a/src/climate.h b/src/climate.h index 5d1bd23ab8..ac04df7eb8 100644 --- a/src/climate.h +++ b/src/climate.h @@ -38,6 +38,7 @@ typedef struct { uint32 sprite_id; } rct_weather; +extern int gClimateNextWeather; extern const rct_weather climate_weather_data[6]; int climate_celcius_to_fahrenheit(int celcius); diff --git a/src/window_game_bottom_toolbar.c b/src/window_game_bottom_toolbar.c index 7bc65b8654..c161165956 100644 --- a/src/window_game_bottom_toolbar.c +++ b/src/window_game_bottom_toolbar.c @@ -483,10 +483,10 @@ static void window_game_bottom_toolbar_draw_right_panel(rct_drawpixelinfo *dpi, gfx_draw_sprite(dpi, climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id, x, y); // Next weather - if (climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id != climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8)].sprite_id) { + if (climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id != climate_weather_data[gClimateNextWeather].sprite_id) { if (RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE_UPDATE_TIMER, sint16) < 960) { gfx_draw_sprite(dpi, SPR_NEXT_WEATHER, x + 27, y + 5); - gfx_draw_sprite(dpi, climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8)].sprite_id, x + 40, y); + gfx_draw_sprite(dpi, climate_weather_data[gClimateNextWeather].sprite_id, x + 40, y); } } }