Small refactor on climate_update

* Extracted the logic of stepping "weather level" variables.
* Simplified the rain stepping code, as "rain level" is always between 0 and 2.
This commit is contained in:
Marco Costa 2014-07-21 23:50:17 -04:00
parent 54933646f1
commit 73dda39374
1 changed files with 12 additions and 19 deletions

View File

@ -83,6 +83,14 @@ void climate_reset(int climate)
climate_determine_future_weather();
}
sint8 step_weather_level(sint8 cur_weather_level, sint8 next_weather_level) {
if (next_weather_level > cur_weather_level) {
return cur_weather_level + 1;
} else {
return cur_weather_level - 1;
}
}
/**
* Weather & climate update iteration.
@ -121,31 +129,16 @@ void climate_update()
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8) = gClimateNextWeather;
climate_determine_future_weather();
RCT2_GLOBAL(0x009A9804, uint32) |= 8; // climate dirty flag?
} else {
if (next_rain == 3) {
cur_rain = 3;
} else {
sint8 next_rain_step = cur_rain + 1;
if (cur_rain > next_rain)
next_rain_step = cur_rain - 1;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RAIN_LEVEL, sint8) = next_rain_step;
}
} else if (next_rain <= 2) { // Safe-guard
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_RAIN_LEVEL, sint8) = step_weather_level(cur_rain, next_rain);
}
} else {
sint8 next_gloom_step = cur_gloom + 1;
if (cur_gloom > next_gloom)
next_gloom_step = cur_gloom - 1;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_GLOOM, sint8) = next_gloom_step;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER_GLOOM, sint8) = step_weather_level(cur_gloom, next_gloom);
gfx_invalidate_screen();
}
} else {
sint8 newtemp = temperature + 1;
if (temperature > target_temperature)
newtemp = temperature - 1;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TEMPERATURE, sint8) = newtemp;
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TEMPERATURE, sint8) = step_weather_level(temperature, target_temperature);
RCT2_GLOBAL(0x009A9804, uint32) |= 8; // climate dirty flag?
}
}