diff options
author | planetmaker <planetmaker@openttd.org> | 2013-03-09 16:16:17 +0000 |
---|---|---|
committer | planetmaker <planetmaker@openttd.org> | 2013-03-09 16:16:17 +0000 |
commit | c22bbf5293d5727a061ed9839d8ab397710b81d0 (patch) | |
tree | 4cecdc676abac4ad4e40c898a73e18c7f479c94c /src | |
parent | 54915063f041d552f2eb86e39bd1637cacbaa32b (diff) | |
download | openttd-c22bbf5293d5727a061ed9839d8ab397710b81d0.tar.xz |
(svn r25072) -Codechange: Don't require the custom currency to be the last defined one
Diffstat (limited to 'src')
-rw-r--r-- | src/currency.cpp | 90 | ||||
-rw-r--r-- | src/currency.h | 47 | ||||
-rw-r--r-- | src/newgrf.cpp | 12 | ||||
-rw-r--r-- | src/settings_gui.cpp | 2 | ||||
-rw-r--r-- | src/table/gameopt_settings.ini | 2 | ||||
-rw-r--r-- | src/table/settings.ini | 2 |
6 files changed, 77 insertions, 78 deletions
diff --git a/src/currency.cpp b/src/currency.cpp index 44cd6dd01..bae5f08d1 100644 --- a/src/currency.cpp +++ b/src/currency.cpp @@ -23,7 +23,7 @@ * | | Euro year | | | name * | | | | | | | */ /** The original currency specifications. */ -static const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { +static const CurrencySpec origin_currency_specs[CURRENCY_END] = { { 1, "", CF_NOEURO, "\xC2\xA3", "", 0, STR_GAME_OPTIONS_CURRENCY_GBP }, ///< british pound { 2, "", CF_NOEURO, "$", "", 0, STR_GAME_OPTIONS_CURRENCY_USD }, ///< american dollar { 2, "", CF_ISEURO, "\xE2\x82\xAC", "", 0, STR_GAME_OPTIONS_CURRENCY_EUR }, ///< euro @@ -55,49 +55,11 @@ static const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { { 4, "", 2014, "", NBSP "Lt", 1, STR_GAME_OPTIONS_CURRENCY_LTL }, ///< lithuanian litas { 1850, "", CF_NOEURO, "\xE2\x82\xA9", "", 0, STR_GAME_OPTIONS_CURRENCY_KRW }, ///< south korean won { 13, "", CF_NOEURO, "R" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_ZAR }, ///< south african rand - { 1, "", CF_NOEURO, "", "", 2, STR_GAME_OPTIONS_CURRENCY_CUSTOM }, ///< custom currency + { 1, "", CF_NOEURO, "", "", 2, STR_GAME_OPTIONS_CURRENCY_CUSTOM }, ///< custom currency (add further languages below) }; /** Array of currencies used by the system */ -CurrencySpec _currency_specs[NUM_CURRENCY]; - -/** - * These enums are only declared in order to make sense - * out of the TTDPatch_To_OTTDIndex array that will follow - * Every currency used by Ottd is there, just in case TTDPatch will - * add those missing in its code - */ -enum Currencies { - CURR_GBP, - CURR_USD, - CURR_EUR, - CURR_JPY, - CURR_ATS, - CURR_BEF, - CURR_CHF, - CURR_CZK, - CURR_DEM, - CURR_DKK, - CURR_ESP, - CURR_FIM, - CURR_FRF, - CURR_GRD, - CURR_HUF, - CURR_ISK, - CURR_ITL, - CURR_NLG, - CURR_NOK, - CURR_PLN, - CURR_RON, - CURR_RUR, - CURR_SIT, - CURR_SEK, - CURR_YTL, - CURR_SKK, - CURR_BRL, - CURR_EEK, - CURR_LTL, -}; +CurrencySpec _currency_specs[CURRENCY_END]; /** * This array represent the position of OpenTTD's currencies, @@ -107,25 +69,25 @@ enum Currencies { */ const byte TTDPatch_To_OTTDIndex[] = { - CURR_GBP, - CURR_USD, - CURR_FRF, - CURR_DEM, - CURR_JPY, - CURR_ESP, - CURR_HUF, - CURR_PLN, - CURR_ATS, - CURR_BEF, - CURR_DKK, - CURR_FIM, - CURR_GRD, - CURR_CHF, - CURR_NLG, - CURR_ITL, - CURR_SEK, - CURR_RUR, - CURR_EUR, + CURRENCY_GBP, + CURRENCY_USD, + CURRENCY_FRF, + CURRENCY_DEM, + CURRENCY_JPY, + CURRENCY_ESP, + CURRENCY_HUF, + CURRENCY_PLN, + CURRENCY_ATS, + CURRENCY_BEF, + CURRENCY_DKK, + CURRENCY_FIM, + CURRENCY_GRD, + CURRENCY_CHF, + CURRENCY_NLG, + CURRENCY_ITL, + CURRENCY_SEK, + CURRENCY_RUR, + CURRENCY_EUR, }; /** @@ -150,14 +112,14 @@ uint GetMaskOfAllowedCurrencies() uint mask = 0; uint i; - for (i = 0; i < NUM_CURRENCY; i++) { + for (i = 0; i < CURRENCY_END; i++) { Year to_euro = _currency_specs[i].to_euro; if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue; if (to_euro == CF_ISEURO && _cur_year < 2000) continue; mask |= (1 << i); } - mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency + mask |= (1 << CURRENCY_CUSTOM); // always allow custom currency return mask; } @@ -195,11 +157,11 @@ void ResetCurrencies(bool preserve_custom) StringID *BuildCurrencyDropdown() { /* Allow room for all currencies, plus a terminator entry */ - static StringID names[NUM_CURRENCY + 1]; + static StringID names[CURRENCY_END + 1]; uint i; /* Add each name */ - for (i = 0; i < NUM_CURRENCY; i++) { + for (i = 0; i < CURRENCY_END; i++) { names[i] = _currency_specs[i].name; } /* Terminate the list */ diff --git a/src/currency.h b/src/currency.h index 40a110968..586b6197c 100644 --- a/src/currency.h +++ b/src/currency.h @@ -17,8 +17,46 @@ static const int CF_NOEURO = 0; ///< Currency never switches to the Euro (as far as known). static const int CF_ISEURO = 1; ///< Currency _is_ the Euro. -static const uint NUM_CURRENCY = 32; ///< Number of currencies. -static const int CUSTOM_CURRENCY_ID = NUM_CURRENCY - 1; ///< Index of the custom currency. + +/** + * This enum gives the currencies a unique id in order to refer + * quickly to them, especially the custom one. And to ensure + */ +enum Currencies { + CURRENCY_GBP, ///< British Pound + CURRENCY_USD, ///< US Dollar + CURRENCY_EUR, ///< Euro + CURRENCY_JPY, ///< Japanese Yen + CURRENCY_ATS, ///< Austrian Schilling + CURRENCY_BEF, ///< Belgian Franc + CURRENCY_CHF, ///< Swiss Franc + CURRENCY_CZK, ///< Czech Koruna + CURRENCY_DEM, ///< Deutsche Mark + CURRENCY_DKK, ///< Danish Krona + CURRENCY_ESP, ///< Spanish Peseta + CURRENCY_FIM, ///< Finish Markka + CURRENCY_FRF, ///< French Franc + CURRENCY_GRD, ///< Greek Drachma + CURRENCY_HUF, ///< Hungarian Forint + CURRENCY_ISK, ///< Icelandic Krona + CURRENCY_ITL, ///< Italian Lira + CURRENCY_NLG, ///< Dutch Gulden + CURRENCY_NOK, ///< Norwegian Krone + CURRENCY_PLN, ///< Polish Zloty + CURRENCY_RON, ///< Romenian Leu + CURRENCY_RUR, ///< Russian Rouble + CURRENCY_SIT, ///< Slovenian Tolar + CURRENCY_SEK, ///< Swedish Krona + CURRENCY_YTL, ///< Turkish Lira + CURRENCY_SKK, ///< Slovak Kornuna + CURRENCY_BRL, ///< Brazilian Real + CURRENCY_EEK, ///< Estonian Krooni + CURRENCY_LTL, ///< Lithuanian Litas + CURRENCY_KRW, ///< South Korean Won + CURRENCY_ZAR, ///< South African Rand + CURRENCY_CUSTOM, ///< Custom currency + CURRENCY_END, ///< always the last item +}; /** Specification of a currency. */ struct CurrencySpec { @@ -40,11 +78,10 @@ struct CurrencySpec { StringID name; }; - -extern CurrencySpec _currency_specs[NUM_CURRENCY]; +extern CurrencySpec _currency_specs[CURRENCY_END]; /* XXX small hack, but makes the rest of the code a bit nicer to read */ -#define _custom_currency (_currency_specs[CUSTOM_CURRENCY_ID]) +#define _custom_currency (_currency_specs[CURRENCY_CUSTOM]) #define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency]) uint GetMaskOfAllowedCurrencies(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index a1dfd7917..f56b99899 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2487,7 +2487,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); StringID newone = GetGRFStringID(_cur.grffile->grfid, buf->ReadWord()); - if ((newone != STR_UNDEFINED) && (curidx < NUM_CURRENCY)) { + if ((newone != STR_UNDEFINED) && (curidx < CURRENCY_END)) { _currency_specs[curidx].name = newone; } break; @@ -2497,7 +2497,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); uint32 rate = buf->ReadDWord(); - if (curidx < NUM_CURRENCY) { + if (curidx < CURRENCY_END) { /* TTDPatch uses a multiple of 1000 for its conversion calculations, * which OTTD does not. For this reason, divide grf value by 1000, * to be compatible */ @@ -2512,7 +2512,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); uint16 options = buf->ReadWord(); - if (curidx < NUM_CURRENCY) { + if (curidx < CURRENCY_END) { _currency_specs[curidx].separator[0] = GB(options, 0, 8); _currency_specs[curidx].separator[1] = '\0'; /* By specifying only one bit, we prevent errors, @@ -2528,7 +2528,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); uint32 tempfix = buf->ReadDWord(); - if (curidx < NUM_CURRENCY) { + if (curidx < CURRENCY_END) { memcpy(_currency_specs[curidx].prefix, &tempfix, 4); _currency_specs[curidx].prefix[4] = 0; } else { @@ -2541,7 +2541,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); uint32 tempfix = buf->ReadDWord(); - if (curidx < NUM_CURRENCY) { + if (curidx < CURRENCY_END) { memcpy(&_currency_specs[curidx].suffix, &tempfix, 4); _currency_specs[curidx].suffix[4] = 0; } else { @@ -2554,7 +2554,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By uint curidx = GetNewgrfCurrencyIdConverted(gvid + i); Year year_euro = buf->ReadWord(); - if (curidx < NUM_CURRENCY) { + if (curidx < CURRENCY_END) { _currency_specs[curidx].to_euro = year_euro; } else { grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0b5917490..c7229430d 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -496,7 +496,7 @@ struct GameOptionsWindow : Window { { switch (widget) { case WID_GO_CURRENCY_DROPDOWN: // Currency - if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency(); + if (index == CURRENCY_CUSTOM) ShowCustCurrency(); this->opt->locale.currency = index; ReInitAllWindows(); break; diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index 8f7861942..42f906d32 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -108,7 +108,7 @@ var = locale.currency type = SLE_UINT8 flags = SLF_NO_NETWORK_SYNC def = 0 -max = CUSTOM_CURRENCY_ID +max = CURRENCY_END - 1 full = _locale_currencies cat = SC_BASIC diff --git a/src/table/settings.ini b/src/table/settings.ini index b39d29a54..1b26db9a0 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2185,7 +2185,7 @@ type = SLE_UINT8 from = 97 flags = SLF_NO_NETWORK_SYNC def = 0 -max = CUSTOM_CURRENCY_ID +max = CURRENCY_END - 1 full = _locale_currencies proc = RedrawScreen cat = SC_BASIC |