Changeset - r4602:a4d40440a037
[Not reviewed]
master
0 4 0
belugas - 18 years ago 2006-09-15 02:52:17
belugas@openttd.org
(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
4 files changed with 24 insertions and 10 deletions:
0 comments (0 inline, 0 general)
currency.c
Show inline comments
 
@@ -38,7 +38,7 @@ const CurrencySpec origin_currency_specs
 
	{  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 */
currency.h
Show inline comments
 
@@ -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;
newgrf.c
Show inline comments
 
@@ -1105,7 +1105,10 @@ static bool GlobalVarChangeInfo(uint gvi
 
				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 gvi
 

	
 
				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 gvi
 
			}
 
			break;
 

	
 
		case 0x0E: // Currency symbols
 
		case 0x0E: // Currency suffix symbol
 
			FOR_EACH_OBJECT {
 
				uint curidx = gvid +i;
 
				uint32 tempfix = grf_load_dword(&buf);
strings.c
Show inline comments
 
@@ -381,8 +381,10 @@ static char *FormatGenericCurrency(char 
 
		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 
 

	
 
	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;
0 comments (0 inline, 0 general)