mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
-Codechange : Divide rate of conversion from grf by 1000, to match OTTD internal system
This commit is contained in:
parent
79971ac119
commit
f9ea48bf3d
@ -38,7 +38,7 @@ const CurrencySpec origin_currency_specs[NUM_CURRENCY] = {
|
|||||||
{ 350, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar
|
{ 350, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar
|
||||||
{ 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona
|
{ 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona
|
||||||
{ 2, '.', CF_NOEURO, "", " YTL", 1, STR_CURR_YTL }, // turkish lira
|
{ 2, '.', CF_NOEURO, "", " YTL", 1, STR_CURR_YTL }, // turkish lira
|
||||||
{ 1, ' ', CF_NOEURO, "", "", 0, STR_CURR_CUSTOM }, // custom currency
|
{ 1, ' ', CF_NOEURO, "", "", 2, STR_CURR_CUSTOM }, // custom currency
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Array of currencies used by the system */
|
/* Array of currencies used by the system */
|
||||||
|
@ -17,8 +17,13 @@ typedef struct {
|
|||||||
char prefix[16];
|
char prefix[16];
|
||||||
char suffix[16];
|
char suffix[16];
|
||||||
/**
|
/**
|
||||||
* Position of the currency symbol on the amount string.
|
* The currency symbol is represented by two possible values, prefix and suffix
|
||||||
* 0 = placed before, 1 = placed after
|
* Usage of one or the other is determined by symbol_pos.
|
||||||
|
* 0 = prefix
|
||||||
|
* 1 = suffix
|
||||||
|
* 2 = both : Special case only for custom currency.
|
||||||
|
* It is not a spec from Newgrf,
|
||||||
|
* rather a way to let users do what they want with custom curency
|
||||||
*/
|
*/
|
||||||
byte symbol_pos;
|
byte symbol_pos;
|
||||||
StringID name;
|
StringID name;
|
||||||
|
13
newgrf.c
13
newgrf.c
@ -1105,7 +1105,10 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i
|
|||||||
uint32 rate = grf_load_dword(&buf);
|
uint32 rate = grf_load_dword(&buf);
|
||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < NUM_CURRENCY) {
|
||||||
_currency_specs[curidx].rate = rate;
|
/* 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 */
|
||||||
|
_currency_specs[curidx].rate = rate / 1000;
|
||||||
} else {
|
} else {
|
||||||
grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring.", curidx);
|
grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency multipliers %d out of range, ignoring.", curidx);
|
||||||
}
|
}
|
||||||
@ -1119,14 +1122,16 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i
|
|||||||
|
|
||||||
if (curidx < NUM_CURRENCY) {
|
if (curidx < NUM_CURRENCY) {
|
||||||
_currency_specs[curidx].separator = GB(options, 0, 8);
|
_currency_specs[curidx].separator = GB(options, 0, 8);
|
||||||
_currency_specs[curidx].symbol_pos = GB(options, 8, 8);
|
/* By specifying only one bit, we prevent errors,
|
||||||
|
* since newgrf specs said that only 0 and 1 can be set for symbol_pos */
|
||||||
|
_currency_specs[curidx].symbol_pos = GB(options, 8, 1);
|
||||||
} else {
|
} else {
|
||||||
grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency option %d out of range, ignoring.", curidx);
|
grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency option %d out of range, ignoring.", curidx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0D: // Currency symbols
|
case 0x0D: // Currency prefix symbol
|
||||||
FOR_EACH_OBJECT {
|
FOR_EACH_OBJECT {
|
||||||
uint curidx = gvid +i;
|
uint curidx = gvid +i;
|
||||||
uint32 tempfix = grf_load_dword(&buf);
|
uint32 tempfix = grf_load_dword(&buf);
|
||||||
@ -1140,7 +1145,7 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0E: // Currency symbols
|
case 0x0E: // Currency suffix symbol
|
||||||
FOR_EACH_OBJECT {
|
FOR_EACH_OBJECT {
|
||||||
uint curidx = gvid +i;
|
uint curidx = gvid +i;
|
||||||
uint32 tempfix = grf_load_dword(&buf);
|
uint32 tempfix = grf_load_dword(&buf);
|
||||||
|
10
strings.c
10
strings.c
@ -381,8 +381,10 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n
|
|||||||
number = -number;
|
number = -number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add prefix part, only if it is specified by symbol_pos */
|
/* Add prefix part, folowing symbol_pos specification.
|
||||||
if (spec->symbol_pos == 0) {
|
* Here, it can can be either 0 (prefix) or 2 (both prefix anf suffix).
|
||||||
|
* The only remaining value is 1 (suffix), so everything that is not 1 */
|
||||||
|
if (spec->symbol_pos != 1){
|
||||||
s = spec->prefix;
|
s = spec->prefix;
|
||||||
while (s != spec->prefix + lengthof(spec->prefix) && (c = *(s++)) != '\0') *(buff)++ = c;
|
while (s != spec->prefix + lengthof(spec->prefix) && (c = *(s++)) != '\0') *(buff)++ = c;
|
||||||
}
|
}
|
||||||
@ -413,7 +415,9 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n
|
|||||||
|
|
||||||
if (compact) *buff++ = compact;
|
if (compact) *buff++ = compact;
|
||||||
|
|
||||||
/* add suffix part, only if it is specified by symbol_pos */
|
/* Add suffix part, folowing symbol_pos specification.
|
||||||
|
* Here, it can can be either 1 (suffix) or 2 (both prefix anf suffix).
|
||||||
|
* The only remaining value is 1 (prefix), so everything that is not 0 */
|
||||||
if (spec->symbol_pos != 0) {
|
if (spec->symbol_pos != 0) {
|
||||||
s = spec->suffix;
|
s = spec->suffix;
|
||||||
while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c;
|
while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c;
|
||||||
|
Loading…
Reference in New Issue
Block a user