(svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
authorbelugas
Fri, 15 Sep 2006 02:52:17 +0000
changeset 4602 43c44f7df615
parent 4601 8e75de247b94
child 4603 20c816f664de
(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
currency.c
currency.h
newgrf.c
strings.c
--- a/currency.c	Fri Sep 15 02:33:40 2006 +0000
+++ b/currency.c	Fri Sep 15 02:52:17 2006 +0000
@@ -38,7 +38,7 @@
 	{  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 */
--- a/currency.h	Fri Sep 15 02:33:40 2006 +0000
+++ b/currency.h	Fri Sep 15 02:52:17 2006 +0000
@@ -17,8 +17,13 @@
 	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;
--- a/newgrf.c	Fri Sep 15 02:33:40 2006 +0000
+++ b/newgrf.c	Fri Sep 15 02:52:17 2006 +0000
@@ -1105,7 +1105,10 @@
 				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 @@
 
 				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 @@
 			}
 			break;
 
-		case 0x0E: // Currency symbols
+		case 0x0E: // Currency suffix symbol
 			FOR_EACH_OBJECT {
 				uint curidx = gvid +i;
 				uint32 tempfix = grf_load_dword(&buf);
--- a/strings.c	Fri Sep 15 02:33:40 2006 +0000
+++ b/strings.c	Fri Sep 15 02:52:17 2006 +0000
@@ -381,8 +381,10 @@
 		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 @@
 
 	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;