diff options
-rw-r--r-- | currency.c | 2 | ||||
-rw-r--r-- | currency.h | 9 | ||||
-rw-r--r-- | newgrf.c | 13 | ||||
-rw-r--r-- | strings.c | 10 |
4 files changed, 24 insertions, 10 deletions
diff --git a/currency.c b/currency.c index e31972d81..7d2594647 100644 --- a/currency.c +++ b/currency.c @@ -38,7 +38,7 @@ const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { { 350, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar { 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona { 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 */ diff --git a/currency.h b/currency.h index c097c4b81..9a76b1495 100644 --- a/currency.h +++ b/currency.h @@ -17,8 +17,13 @@ typedef struct { char prefix[16]; char suffix[16]; /** - * Position of the currency symbol on the amount string. - * 0 = placed before, 1 = placed after + * The currency symbol is represented by two possible values, prefix and suffix + * 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; StringID name; @@ -1105,7 +1105,10 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i uint32 rate = grf_load_dword(&buf); 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 { 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) { _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 { grfmsg(GMS_WARN, "GlobalVarChangeInfo: Currency option %d out of range, ignoring.", curidx); } } break; - case 0x0D: // Currency symbols + case 0x0D: // Currency prefix symbol FOR_EACH_OBJECT { uint curidx = gvid +i; uint32 tempfix = grf_load_dword(&buf); @@ -1140,7 +1145,7 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i } break; - case 0x0E: // Currency symbols + case 0x0E: // Currency suffix symbol FOR_EACH_OBJECT { uint curidx = gvid +i; uint32 tempfix = grf_load_dword(&buf); @@ -381,8 +381,10 @@ static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 n number = -number; } - /* add prefix part, only if it is specified by symbol_pos */ - if (spec->symbol_pos == 0) { + /* Add prefix part, folowing symbol_pos specification. + * 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; 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; - /* 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) { s = spec->suffix; while (s != spec->suffix + lengthof(spec->suffix) && (c = *(s++)) != '\0') *(buff++) = c; |