From a0688e8d8575e2e5ae268fca01e221063f2b1896 Mon Sep 17 00:00:00 2001 From: belugas Date: Mon, 26 Mar 2007 00:20:22 +0000 Subject: [PATCH] (svn r9471) [0.5] -Backport from trunk (r9467 & r9469): Reset the whole currency array while preserving custom one. Also, max data of to_euro is now 300, not 1000, disabling any proper loading of the patch setting --- currency.c | 13 +++++++++---- currency.h | 2 +- newgrf.c | 2 +- settings.c | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/currency.c b/currency.c index f2658d9d63..e3fc933515 100644 --- a/currency.c +++ b/currency.c @@ -153,12 +153,17 @@ void CheckSwitchToEuro(void) } /** - * Called only from newgrf.c. Will fill _currency_specs array with + * Will fill _currency_specs array with * default values from origin_currency_specs - **/ -void ResetCurrencies(void) + * Called only from newgrf.c and settings.c. + * @param preserve_custom will not reset custom currency (the latest one on the list) + * if ever it is flagged to true. In which case, the total size of the memory to move + * will be one currency spec less, thus preserving the custom curreny from been + * overwritten.void ResetCurrencies(bool preserve_custom) +*/ +void ResetCurrencies(bool preserve_custom) { - memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs)); + memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs) - (preserve_custom ? sizeof(_custom_currency) : 0)); } /** diff --git a/currency.h b/currency.h index 40fb553a4c..3eba17edaa 100644 --- a/currency.h +++ b/currency.h @@ -38,7 +38,7 @@ extern CurrencySpec _currency_specs[NUM_CURRENCY]; uint GetMaskOfAllowedCurrencies(void); void CheckSwitchToEuro(void); -void ResetCurrencies(void); +void ResetCurrencies(bool preserve_custom); StringID* BuildCurrencyDropdown(void); byte GetNewgrfCurrencyIdConverted(byte grfcurr_id); diff --git a/newgrf.c b/newgrf.c index 781ab62aaf..2e56e889d0 100644 --- a/newgrf.c +++ b/newgrf.c @@ -3505,7 +3505,7 @@ static void ResetNewGRFData(void) ResetPriceBaseMultipliers(); /* Reset the curencies array */ - ResetCurrencies(); + ResetCurrencies(false); // Reset station classes ResetStationClasses(); diff --git a/settings.c b/settings.c index f3360df701..a9b013f35f 100644 --- a/settings.c +++ b/settings.c @@ -1478,7 +1478,7 @@ const SettingDesc _patch_settings[] = { static const SettingDesc _currency_settings[] = { SDT_VAR(CurrencySpec, rate, SLE_UINT16, S, 0, 1, 0, 100, 0, STR_NULL, NULL), SDT_CHR(CurrencySpec, separator, S, 0, ".", STR_NULL, NULL), - SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, 0,1000, 0, STR_NULL, NULL), + SDT_VAR(CurrencySpec, to_euro, SLE_INT32, S, 0, 0, 0,3000, 0, STR_NULL, NULL), SDT_STR(CurrencySpec, prefix, SLE_STRBQ, S, 0, NULL, STR_NULL, NULL), SDT_STR(CurrencySpec, suffix, SLE_STRBQ, S, 0, " credits", STR_NULL, NULL), SDT_END() @@ -1654,6 +1654,7 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP void LoadFromConfig(void) { IniFile *ini = ini_load(_config_file); + ResetCurrencies(false); HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list); _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);