(svn r25072) -Codechange: Don't require the custom currency to be the last defined one

pull/155/head
planetmaker 11 years ago
parent 0192957e6b
commit 7aa0712644

@ -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 */

@ -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();

@ -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);

@ -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;

@ -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

@ -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

Loading…
Cancel
Save