mirror of https://github.com/OpenTTD/OpenTTD
(svn r25072) -Codechange: Don't require the custom currency to be the last defined one
parent
54915063f0
commit
c22bbf5293
|
@ -23,7 +23,7 @@
|
||||||
* | | Euro year | | | name
|
* | | Euro year | | | name
|
||||||
* | | | | | | | */
|
* | | | | | | | */
|
||||||
/** The original currency specifications. */
|
/** 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
|
{ 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_NOEURO, "$", "", 0, STR_GAME_OPTIONS_CURRENCY_USD }, ///< american dollar
|
||||||
{ 2, "", CF_ISEURO, "\xE2\x82\xAC", "", 0, STR_GAME_OPTIONS_CURRENCY_EUR }, ///< euro
|
{ 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
|
{ 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
|
{ 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
|
{ 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 */
|
/** Array of currencies used by the system */
|
||||||
CurrencySpec _currency_specs[NUM_CURRENCY];
|
CurrencySpec _currency_specs[CURRENCY_END];
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This array represent the position of OpenTTD's currencies,
|
* This array represent the position of OpenTTD's currencies,
|
||||||
|
@ -107,25 +69,25 @@ enum Currencies {
|
||||||
*/
|
*/
|
||||||
const byte TTDPatch_To_OTTDIndex[] =
|
const byte TTDPatch_To_OTTDIndex[] =
|
||||||
{
|
{
|
||||||
CURR_GBP,
|
CURRENCY_GBP,
|
||||||
CURR_USD,
|
CURRENCY_USD,
|
||||||
CURR_FRF,
|
CURRENCY_FRF,
|
||||||
CURR_DEM,
|
CURRENCY_DEM,
|
||||||
CURR_JPY,
|
CURRENCY_JPY,
|
||||||
CURR_ESP,
|
CURRENCY_ESP,
|
||||||
CURR_HUF,
|
CURRENCY_HUF,
|
||||||
CURR_PLN,
|
CURRENCY_PLN,
|
||||||
CURR_ATS,
|
CURRENCY_ATS,
|
||||||
CURR_BEF,
|
CURRENCY_BEF,
|
||||||
CURR_DKK,
|
CURRENCY_DKK,
|
||||||
CURR_FIM,
|
CURRENCY_FIM,
|
||||||
CURR_GRD,
|
CURRENCY_GRD,
|
||||||
CURR_CHF,
|
CURRENCY_CHF,
|
||||||
CURR_NLG,
|
CURRENCY_NLG,
|
||||||
CURR_ITL,
|
CURRENCY_ITL,
|
||||||
CURR_SEK,
|
CURRENCY_SEK,
|
||||||
CURR_RUR,
|
CURRENCY_RUR,
|
||||||
CURR_EUR,
|
CURRENCY_EUR,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,14 +112,14 @@ uint GetMaskOfAllowedCurrencies()
|
||||||
uint mask = 0;
|
uint mask = 0;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_CURRENCY; i++) {
|
for (i = 0; i < CURRENCY_END; i++) {
|
||||||
Year to_euro = _currency_specs[i].to_euro;
|
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_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue;
|
||||||
if (to_euro == CF_ISEURO && _cur_year < 2000) continue;
|
if (to_euro == CF_ISEURO && _cur_year < 2000) continue;
|
||||||
mask |= (1 << i);
|
mask |= (1 << i);
|
||||||
}
|
}
|
||||||
mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency
|
mask |= (1 << CURRENCY_CUSTOM); // always allow custom currency
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +157,11 @@ void ResetCurrencies(bool preserve_custom)
|
||||||
StringID *BuildCurrencyDropdown()
|
StringID *BuildCurrencyDropdown()
|
||||||
{
|
{
|
||||||
/* Allow room for all currencies, plus a terminator entry */
|
/* Allow room for all currencies, plus a terminator entry */
|
||||||
static StringID names[NUM_CURRENCY + 1];
|
static StringID names[CURRENCY_END + 1];
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
/* Add each name */
|
/* Add each name */
|
||||||
for (i = 0; i < NUM_CURRENCY; i++) {
|
for (i = 0; i < CURRENCY_END; i++) {
|
||||||
names[i] = _currency_specs[i].name;
|
names[i] = _currency_specs[i].name;
|
||||||
}
|
}
|
||||||
/* Terminate the list */
|
/* 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_NOEURO = 0; ///< Currency never switches to the Euro (as far as known).
|
||||||
static const int CF_ISEURO = 1; ///< Currency _is_ the Euro.
|
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. */
|
/** Specification of a currency. */
|
||||||
struct CurrencySpec {
|
struct CurrencySpec {
|
||||||
|
@ -40,11 +78,10 @@ struct CurrencySpec {
|
||||||
StringID name;
|
StringID name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern CurrencySpec _currency_specs[CURRENCY_END];
|
||||||
extern CurrencySpec _currency_specs[NUM_CURRENCY];
|
|
||||||
|
|
||||||
/* XXX small hack, but makes the rest of the code a bit nicer to read */
|
/* 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])
|
#define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency])
|
||||||
|
|
||||||
uint GetMaskOfAllowedCurrencies();
|
uint GetMaskOfAllowedCurrencies();
|
||||||
|
|
|
@ -2487,7 +2487,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||||
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
StringID newone = GetGRFStringID(_cur.grffile->grfid, buf->ReadWord());
|
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;
|
_currency_specs[curidx].name = newone;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -2497,7 +2497,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||||
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
uint32 rate = buf->ReadDWord();
|
uint32 rate = buf->ReadDWord();
|
||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < CURRENCY_END) {
|
||||||
/* TTDPatch uses a multiple of 1000 for its conversion calculations,
|
/* TTDPatch uses a multiple of 1000 for its conversion calculations,
|
||||||
* which OTTD does not. For this reason, divide grf value by 1000,
|
* which OTTD does not. For this reason, divide grf value by 1000,
|
||||||
* to be compatible */
|
* to be compatible */
|
||||||
|
@ -2512,7 +2512,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||||
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
uint16 options = buf->ReadWord();
|
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[0] = GB(options, 0, 8);
|
||||||
_currency_specs[curidx].separator[1] = '\0';
|
_currency_specs[curidx].separator[1] = '\0';
|
||||||
/* By specifying only one bit, we prevent errors,
|
/* 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);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
uint32 tempfix = buf->ReadDWord();
|
uint32 tempfix = buf->ReadDWord();
|
||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < CURRENCY_END) {
|
||||||
memcpy(_currency_specs[curidx].prefix, &tempfix, 4);
|
memcpy(_currency_specs[curidx].prefix, &tempfix, 4);
|
||||||
_currency_specs[curidx].prefix[4] = 0;
|
_currency_specs[curidx].prefix[4] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2541,7 +2541,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||||
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
uint32 tempfix = buf->ReadDWord();
|
uint32 tempfix = buf->ReadDWord();
|
||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < CURRENCY_END) {
|
||||||
memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
|
memcpy(&_currency_specs[curidx].suffix, &tempfix, 4);
|
||||||
_currency_specs[curidx].suffix[4] = 0;
|
_currency_specs[curidx].suffix[4] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2554,7 +2554,7 @@ static ChangeInfoResult GlobalVarChangeInfo(uint gvid, int numinfo, int prop, By
|
||||||
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
uint curidx = GetNewgrfCurrencyIdConverted(gvid + i);
|
||||||
Year year_euro = buf->ReadWord();
|
Year year_euro = buf->ReadWord();
|
||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < CURRENCY_END) {
|
||||||
_currency_specs[curidx].to_euro = year_euro;
|
_currency_specs[curidx].to_euro = year_euro;
|
||||||
} else {
|
} else {
|
||||||
grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
|
grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
|
||||||
|
|
|
@ -496,7 +496,7 @@ struct GameOptionsWindow : Window {
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_GO_CURRENCY_DROPDOWN: // Currency
|
case WID_GO_CURRENCY_DROPDOWN: // Currency
|
||||||
if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
|
if (index == CURRENCY_CUSTOM) ShowCustCurrency();
|
||||||
this->opt->locale.currency = index;
|
this->opt->locale.currency = index;
|
||||||
ReInitAllWindows();
|
ReInitAllWindows();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -108,7 +108,7 @@ var = locale.currency
|
||||||
type = SLE_UINT8
|
type = SLE_UINT8
|
||||||
flags = SLF_NO_NETWORK_SYNC
|
flags = SLF_NO_NETWORK_SYNC
|
||||||
def = 0
|
def = 0
|
||||||
max = CUSTOM_CURRENCY_ID
|
max = CURRENCY_END - 1
|
||||||
full = _locale_currencies
|
full = _locale_currencies
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
||||||
|
|
|
@ -2185,7 +2185,7 @@ type = SLE_UINT8
|
||||||
from = 97
|
from = 97
|
||||||
flags = SLF_NO_NETWORK_SYNC
|
flags = SLF_NO_NETWORK_SYNC
|
||||||
def = 0
|
def = 0
|
||||||
max = CUSTOM_CURRENCY_ID
|
max = CURRENCY_END - 1
|
||||||
full = _locale_currencies
|
full = _locale_currencies
|
||||||
proc = RedrawScreen
|
proc = RedrawScreen
|
||||||
cat = SC_BASIC
|
cat = SC_BASIC
|
||||||
|
|
Loading…
Reference in New Issue