(svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.

pull/155/head
rubidium 16 years ago
parent ecfac35ccc
commit e8767f730a

@ -150,10 +150,10 @@ uint GetMaskOfAllowedCurrencies()
**/
void CheckSwitchToEuro()
{
if (_currency_specs[_settings_client.gui.currency].to_euro != CF_NOEURO &&
_currency_specs[_settings_client.gui.currency].to_euro != CF_ISEURO &&
_cur_year >= _currency_specs[_settings_client.gui.currency].to_euro) {
_settings_client.gui.currency = 2; // this is the index of euro above.
if (_currency_specs[_settings_game.locale.currency].to_euro != CF_NOEURO &&
_currency_specs[_settings_game.locale.currency].to_euro != CF_ISEURO &&
_cur_year >= _currency_specs[_settings_game.locale.currency].to_euro) {
_settings_game.locale.currency = 2; // this is the index of euro above.
AddNewsItem(STR_EURO_INTRODUCE, NS_ECONOMY, 0, 0);
}
}

@ -39,7 +39,7 @@ extern CurrencySpec _currency_specs[NUM_CURRENCY];
// XXX small hack, but makes the rest of the code a bit nicer to read
#define _custom_currency (_currency_specs[CUSTOM_CURRENCY_ID])
#define _currency ((const CurrencySpec*)&_currency_specs[_settings_client.gui.currency])
#define _currency ((const CurrencySpec*)&_currency_specs[_game_mode == GM_MENU ? _settings_newgame.locale.currency : _settings_game.locale.currency])
uint GetMaskOfAllowedCurrencies();
void CheckSwitchToEuro();

@ -1572,8 +1572,8 @@ static const OldChunks main_chunk[] = {
OCL_VAR ( OC_FILE_U8 | OC_VAR_U16, 1, &_station_tick_ctr ),
OCL_VAR ( OC_UINT8, 1, &_settings_client.gui.currency ),
OCL_VAR ( OC_UINT8, 1, &_settings_client.gui.units ),
OCL_VAR ( OC_UINT8, 1, &_settings_game.locale.currency ),
OCL_VAR ( OC_UINT8, 1, &_settings_game.locale.units ),
OCL_VAR ( OC_FILE_U8 | OC_VAR_U32, 1, &_cur_player_tick_index ),
OCL_NULL( 2 ), ///< Date stuff, calculated automatically

@ -1178,7 +1178,7 @@ static const byte convert_currency[] = {
/* since savegame version 4.2 the currencies are arranged differently */
static void UpdateCurrencies()
{
_settings_client.gui.currency = convert_currency[_settings_client.gui.currency];
_settings_game.locale.currency = convert_currency[_settings_game.locale.currency];
}
/* Up to revision 1413 the invisible tiles at the southern border have not been

@ -1552,8 +1552,8 @@ static const SettingDesc _gameopt_settings[] = {
SDTG_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, SLE_UINT16, C, 0, _old_diff_custom, 18, 0, 0, 0, 0, NULL, STR_NULL, NULL, 4, 96),
SDT_VAR(GameSettings, difficulty.diff_level, SLE_UINT8, 0, 0, 0, 0, 3, 0, STR_NULL, NULL),
SDTC_OMANY( gui.currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL),
SDTC_OMANY( gui.units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL),
SDT_OMANY(GameSettings, locale.currency, SLE_UINT8, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
SDT_OMANY(GameSettings, locale.units, SLE_UINT8, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL),
/* There are only 21 predefined town_name values (0-20), but you can have more with newgrf action F so allow these bigger values (21-255). Invalid values will fallback to english on use and (undefined string) in GUI. */
SDT_OMANY(GameSettings, game_creation.town_name, SLE_UINT8, 0, 0, 0, 255, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss|danish|turkish|italian|catalan", STR_NULL, NULL, NULL),
SDT_OMANY(GameSettings, game_creation.landscape, SLE_UINT8, 0, 0, 0, 3, "temperate|arctic|tropic|toyland", STR_NULL, NULL, ConvertLandscape),
@ -1744,8 +1744,8 @@ const SettingDesc _patch_settings[] = {
SDT_VAR(GameSettings, game_creation.map_x, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_X, NULL),
SDT_VAR(GameSettings, game_creation.map_y, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_Y, NULL),
SDTC_CONDOMANY( gui.currency, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL),
SDTC_CONDOMANY( gui.units, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL),
SDT_CONDOMANY(GameSettings, locale.currency, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
SDT_CONDOMANY(GameSettings, locale.units, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL),
/***************************************************************************/
/* Unsaved patch variables. */

@ -162,8 +162,8 @@ struct GameOptionsWindow : Window {
this->SetWidgetDisabledState(GAMEOPT_VEHICLENAME_SAVE, !(_vehicle_design_names & 1));
if (!this->IsWidgetDisabled(GAMEOPT_VEHICLENAME_SAVE)) str = STR_02BF_CUSTOM;
SetDParam(0, str);
SetDParam(1, _currency_specs[_settings_client.gui.currency].name);
SetDParam(2, STR_UNITS_IMPERIAL + _settings_client.gui.units);
SetDParam(1, _currency_specs[this->opt->locale.currency].name);
SetDParam(2, STR_UNITS_IMPERIAL + this->opt->locale.units);
SetDParam(3, STR_02E9_DRIVE_ON_LEFT + this->opt->vehicle.road_side);
SetDParam(4, TownName(this->opt->game_creation.town_name));
SetDParam(5, _autosave_dropdown[_settings_client.gui.autosave]);
@ -181,11 +181,11 @@ struct GameOptionsWindow : Window {
{
switch (widget) {
case GAMEOPT_CURRENCY_BTN: // Setup currencies dropdown
ShowDropDownMenu(this, BuildCurrencyDropdown(), _settings_client.gui.currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
ShowDropDownMenu(this, BuildCurrencyDropdown(), this->opt->locale.currency, GAMEOPT_CURRENCY_BTN, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
break;
case GAMEOPT_DISTANCE_BTN: // Setup distance unit dropdown
ShowDropDownMenu(this, _units_dropdown, _settings_client.gui.units, GAMEOPT_DISTANCE_BTN, 0, 0);
ShowDropDownMenu(this, _units_dropdown, this->opt->locale.units, GAMEOPT_DISTANCE_BTN, 0, 0);
break;
case GAMEOPT_ROADSIDE_BTN: { // Setup road-side dropdown
@ -265,12 +265,12 @@ struct GameOptionsWindow : Window {
case GAMEOPT_CURRENCY_BTN: /* Currency */
if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
_settings_client.gui.currency = index;
this->opt->locale.currency = index;
MarkWholeScreenDirty();
break;
case GAMEOPT_DISTANCE_BTN: // Measuring units
_settings_client.gui.units = index;
this->opt->locale.units = index;
MarkWholeScreenDirty();
break;

@ -78,9 +78,13 @@ struct GUISettings {
bool autorenew; ///< should autorenew be enabled for new companies?
int16 autorenew_months; ///< how many months from EOL of vehicles should autorenew trigger for new companies?
int32 autorenew_money; ///< how much money before autorenewing for new companies?
byte news_message_timeout; ///< how much longer than the news message "age" should we keep the message in the history
};
/** Settings related to currency/unit systems. */
struct LocaleSettings {
byte currency; ///< currency we currently use
byte units; ///< unit system we show everything
byte news_message_timeout; ///< how much longer than the news message "age" should we keep the message in the history
};
/** All settings related to the network. */
@ -311,6 +315,7 @@ struct GameSettings {
VehicleSettings vehicle; ///< options for vehicles
EconomySettings economy; ///< settings to change the economy
StationSettings station; ///< settings related to station management
LocaleSettings locale; ///< settings related to used currency/unit system in the current game
};
/** All settings that are only important for the local client. */

@ -546,7 +546,7 @@ static const Units units[] = {
*/
uint ConvertSpeedToDisplaySpeed(uint speed)
{
return (speed * units[_settings_client.gui.units].s_m) >> units[_settings_client.gui.units].s_s;
return (speed * units[_settings_game.locale.units].s_m) >> units[_settings_game.locale.units].s_s;
}
/**
@ -556,7 +556,7 @@ uint ConvertSpeedToDisplaySpeed(uint speed)
*/
uint ConvertDisplaySpeedToSpeed(uint speed)
{
return ((speed << units[_settings_client.gui.units].s_s) + units[_settings_client.gui.units].s_m / 2) / units[_settings_client.gui.units].s_m;
return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m;
}
static char* FormatString(char* buff, const char* str, const int64* argv, uint casei, const char* last)
@ -602,9 +602,9 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
case SCC_VELOCITY: {// {VELOCITY}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
assert(_settings_game.locale.units < lengthof(units));
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv));
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].velocity), args, modifier >> 24, last);
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, modifier >> 24, last);
modifier = 0;
break;
}
@ -625,18 +625,18 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
switch (cargo_str) {
case STR_TONS: {
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].w_m >> units[_settings_client.gui.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].l_weight), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
modifier = 0;
break;
}
case STR_LITERS: {
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].v_m >> units[_settings_client.gui.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].l_volume), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
modifier = 0;
break;
}
@ -718,9 +718,9 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
case SCC_VOLUME: { // {VOLUME}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].v_m >> units[_settings_client.gui.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].l_volume), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
modifier = 0;
break;
}
@ -763,45 +763,45 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c
case SCC_POWER: { // {POWER}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].p_m >> units[_settings_client.gui.units].p_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].power), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, modifier >> 24, last);
modifier = 0;
break;
}
case SCC_VOLUME_SHORT: { // {VOLUME_S}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].v_m >> units[_settings_client.gui.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].s_volume), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_volume), args, modifier >> 24, last);
modifier = 0;
break;
}
case SCC_WEIGHT: { // {WEIGHT}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].w_m >> units[_settings_client.gui.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].l_weight), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
modifier = 0;
break;
}
case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].w_m >> units[_settings_client.gui.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].s_weight), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_weight), args, modifier >> 24, last);
modifier = 0;
break;
}
case SCC_FORCE: { // {FORCE}
int64 args[1];
assert(_settings_client.gui.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_client.gui.units].f_m >> units[_settings_client.gui.units].f_s;
buff = FormatString(buff, GetStringPtr(units[_settings_client.gui.units].force), args, modifier >> 24, last);
assert(_settings_game.locale.units < lengthof(units));
args[0] = GetInt32(&argv) * units[_settings_game.locale.units].f_m >> units[_settings_game.locale.units].f_s;
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].force), args, modifier >> 24, last);
modifier = 0;
break;
}

Loading…
Cancel
Save