refactor climate

This commit is contained in:
IntelOrca 2014-04-29 12:18:50 +01:00
parent 702674f13e
commit 1dcfdbe355
4 changed files with 47 additions and 46 deletions

View File

@ -24,8 +24,15 @@
#include "gfx.h"
#include "rct2.h"
typedef struct {
sint8 base_temperature;
sint8 distribution_size;
sint8 distribution[24];
} rct_weather_transition;
void determine_future_weather();
static const rct_weather_transition* climate_transitions[4];
static void climate_determine_future_weather();
int climate_celcius_to_fahrenheit(int celcius)
@ -40,16 +47,17 @@ int climate_celcius_to_fahrenheit(int celcius)
void climate_reset(int climate)
{
RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8) = climate;
determine_future_weather();
climate_determine_future_weather();
}
/**
* Weather & climate update iteration.
* Gradually changes the weather parameters towards their determined next values.
*
* rct2: 0x006C46B1
**/
void update_climate()
*/
void climate_update()
{
uint8 screen_flags = RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8);
sint8 temperature = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TEMPERATURE, sint8),
@ -78,13 +86,12 @@ void update_climate()
if (cur_rain == next_rain) {
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8) = RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8);
determine_future_weather();
climate_determine_future_weather();
RCT2_GLOBAL(0x009A9804, uint32) |= 8; // climate dirty flag?
}
else {
if (next_rain == 3)
} else {
if (next_rain == 3) {
cur_rain = 3;
else {
} else {
sint8 next_rain_step = cur_rain + 1;
if (cur_rain > next_rain)
next_rain_step = cur_rain - 1;
@ -113,38 +120,39 @@ void update_climate()
/**
* Calculates future weather development.
* RCT2 implements this as discrete probability distributions dependant on month and climate
* for next_weather. The other weather parameters are then looked up depending only on the
* next weather.
*
* rct2: 0x006C461C
**/
void determine_future_weather()
* Calculates future weather development.
* RCT2 implements this as discrete probability distributions dependant on month and climate
* for next_weather. The other weather parameters are then looked up depending only on the
* next weather.
*
* rct2: 0x006C461C
*/
static void climate_determine_future_weather()
{
sint8 climate = RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8);
const rct_weather_transition* climate_table = climate_transitions[climate];
sint8 month = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, sint16) & 7;
rct_weather_transition transition = climate_table[month];
// generate a random variable with values 0 upto distribution_size-1 and chose weather from the distribution table accordingly
// 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;
RCT2_GLOBAL(RCT2_ADDRESS_NEXT_TEMPERATURE, sint8) = transition.base_temperature + weather_data[next_weather].temp_delta;
RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_EFFECT, sint8) = weather_data[next_weather].effect_level;
RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER_GLOOM, sint8) = weather_data[next_weather].gloom_level;
RCT2_GLOBAL(RCT2_ADDRESS_NEXT_RAIN_LEVEL, sint8) = weather_data[next_weather].rain_level;
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;
RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE_UPDATE_TIMER, sint16) = 1920;
}
#pragma region Climate/Weather data tables
#pragma region Climate / Weather data tables
// rct2: 0x00993C94
// There is actually a sprite at 0x5A9C for snow but only these weather types seem to be fully implemented
const rct_weather weather_data[6] = {
const rct_weather climate_weather_data[6] = {
{ .temp_delta = 10, .effect_level = 0, .gloom_level = 0, .rain_level = 0, .sprite_id = 0x5A96 }, // Sunny
{ .temp_delta = 5, .effect_level = 0, .gloom_level = 0, .rain_level = 0, .sprite_id = 0x5A97 }, // Partially Cloudy
{ .temp_delta = 0, .effect_level = 0, .gloom_level = 0, .rain_level = 0, .sprite_id = 0x5A98 }, // Cloudy
@ -155,7 +163,7 @@ const rct_weather weather_data[6] = {
// rct2: 00993998
const rct_weather_transition cool_and_wet_climate_transitions[] = {
static const rct_weather_transition climate_cool_and_wet_transitions[] = {
{ .base_temperature = 8, .distribution_size = 18,
.distribution = { 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 0, 0, 0, 0, 0 } },
{ .base_temperature = 10, .distribution_size = 21,
@ -173,7 +181,7 @@ const rct_weather_transition cool_and_wet_climate_transitions[] = {
{ .base_temperature = 13, .distribution_size = 16,
.distribution = { 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0 } }
};
const rct_weather_transition warm_climate_transitions[] = {
static const rct_weather_transition climate_warm_transitions[] = {
{ .base_temperature = 12, .distribution_size = 21,
.distribution = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 4, 0, 0 } },
{ .base_temperature = 13, .distribution_size = 22,
@ -191,7 +199,7 @@ const rct_weather_transition warm_climate_transitions[] = {
{ .base_temperature = 16, .distribution_size = 17,
.distribution = { 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 0, 0, 0, 0, 0, 0 } }
};
const rct_weather_transition hot_and_dry_climate_transitions[] = {
static const rct_weather_transition climate_hot_and_dry_transitions[] = {
{ .base_temperature = 12, .distribution_size = 15,
.distribution = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0 } },
{ .base_temperature = 14, .distribution_size = 12,
@ -209,7 +217,7 @@ const rct_weather_transition hot_and_dry_climate_transitions[] = {
{ .base_temperature = 16, .distribution_size = 13,
.distribution = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
};
const rct_weather_transition cold_climate_transitions[] = {
static const rct_weather_transition climate_cold_transitions[] = {
{ .base_temperature = 4, .distribution_size = 18,
.distribution = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 4, 0, 0, 0, 0, 0 } },
{ .base_temperature = 5, .distribution_size = 21,
@ -228,11 +236,11 @@ const rct_weather_transition cold_climate_transitions[] = {
.distribution = { 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0 } }
};
const rct_weather_transition* climate_transitions[] = {
cool_and_wet_climate_transitions,
warm_climate_transitions,
hot_and_dry_climate_transitions,
cold_climate_transitions
static const rct_weather_transition* climate_transitions[] = {
climate_cool_and_wet_transitions,
climate_warm_transitions,
climate_hot_and_dry_transitions,
climate_cold_transitions
};
#pragma endregion

View File

@ -30,12 +30,6 @@ enum {
CLIMATE_COLD
};
typedef struct {
sint8 base_temperature;
sint8 distribution_size;
sint8 distribution[24];
} rct_weather_transition;
typedef struct {
sint8 temp_delta;
sint8 effect_level;
@ -44,11 +38,10 @@ typedef struct {
uint32 sprite_id;
} rct_weather;
extern const rct_weather weather_data[6];
extern const rct_weather_transition* climate_transitions[4];
extern const rct_weather climate_weather_data[6];
int climate_celcius_to_fahrenheit(int celcius);
void climate_reset(int climate);
void update_climate();
void climate_update();
#endif

View File

@ -137,7 +137,7 @@ void game_logic_update()
RCT2_CALLPROC_EBPSAFE(0x0068B089);
RCT2_CALLPROC_EBPSAFE(0x006C44B1); // update_objective
update_climate();
climate_update();
RCT2_CALLPROC_EBPSAFE(0x006646E1);
RCT2_CALLPROC_EBPSAFE(0x006A876D);
peep_update_all();

View File

@ -480,13 +480,13 @@ static void window_game_bottom_toolbar_draw_right_panel(rct_drawpixelinfo *dpi,
x += 30;
// Current weather
gfx_draw_sprite(dpi, weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id, x, y);
gfx_draw_sprite(dpi, climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id, x, y);
// Next weather
if (weather_data[RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_WEATHER, sint8)].sprite_id != 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[RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8)].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, weather_data[RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8)].sprite_id, x + 40, y);
gfx_draw_sprite(dpi, climate_weather_data[RCT2_GLOBAL(RCT2_ADDRESS_NEXT_WEATHER, sint8)].sprite_id, x + 40, y);
}
}
}