(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
authortron
Sat, 06 Aug 2005 14:59:54 +0000
changeset 2291 2b064aa97f91
parent 2290 3283963c5422
child 2292 c5a944e9bcae
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
Makefile
currency.c
currency.h
economy.c
settings.c
settings_gui.c
strings.c
strings.h
table/currency.h
variables.h
--- a/Makefile	Sat Aug 06 14:58:06 2005 +0000
+++ b/Makefile	Sat Aug 06 14:59:54 2005 +0000
@@ -591,6 +591,7 @@
 C_SOURCES += command.c
 C_SOURCES += console.c
 C_SOURCES += console_cmds.c
+C_SOURCES += currency.c
 C_SOURCES += debug.c
 C_SOURCES += dedicated.c
 C_SOURCES += depot.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/currency.c	Sat Aug 06 14:59:54 2005 +0000
@@ -0,0 +1,94 @@
+/* $Id$ */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "currency.h"
+#include "variables.h"
+#include "table/strings.h"
+
+// exchange rate    prefix
+// |  separator        |     postfix
+// |   |    Euro year  |       |
+// |   |    |          |       |
+CurrencySpec _currency_specs[] = {
+	{    1, ',', CF_NOEURO, "\xA3", ""     }, // british pounds
+	{    2, ',', CF_NOEURO, "$",    ""     }, // us dollars
+	{    2, ',', CF_ISEURO, "¤",    ""     }, // Euro
+	{  200, ',', CF_NOEURO, "\xA5", ""     }, // yen
+	{   19, ',', 2002,      "",     " S."  }, // austrian schilling
+	{   57, ',', 2002,      "BEF ", ""     }, // belgian franc
+	{    2, ',', CF_NOEURO, "CHF ", ""     }, // swiss franc
+	{   50, ',', CF_NOEURO, "",     " Kc"  }, // czech koruna // TODO: Should use the "c" with an upside down "^"
+	{    4, '.', 2002,      "DM ",  ""     }, // deutsche mark
+	{   10, '.', CF_NOEURO, "",     " kr"  }, // danish krone
+	{  200, '.', 2002,      "Pts ", ""     }, // spanish pesetas
+	{    8, ',', 2002,      "",     " MK"  }, // finnish markka
+	{   10, '.', 2002,      "FF ",  ""     }, // french francs
+	{  480, ',', 2002,      "",     "Dr."  }, // greek drachma
+	{  376, ',', 2002,      "",     " Ft"  }, // hungarian forint
+	{  130, '.', CF_NOEURO, "",     " Kr"  }, // icelandic krona
+	{ 2730, ',', 2002,      "",     " L."  }, // italian lira
+	{    3, ',', 2002,      "NLG ", ""     }, // dutch gulden
+	{   11, '.', CF_NOEURO, "",     " Kr"  }, // norwegian krone
+	{    6, ' ', CF_NOEURO, "",     " zl"  }, // polish zloty
+	{    6, '.', CF_NOEURO, "",     " Lei" }, // romanian Lei
+	{    5, ' ', CF_NOEURO, "",     " p"   }, // russian rouble
+	{   13, '.', CF_NOEURO, "",     " Kr"  }, // swedish krona
+	{    1, ' ', CF_NOEURO, "",     ""     }, // custom currency
+};
+
+const StringID _currency_string_list[] = {
+	STR_CURR_GBP,
+	STR_CURR_USD,
+	STR_CURR_EUR,
+	STR_CURR_YEN,
+	STR_CURR_ATS,
+	STR_CURR_BEF,
+	STR_CURR_CHF,
+	STR_CURR_CZK,
+	STR_CURR_DEM,
+	STR_CURR_DKK,
+	STR_CURR_ESP,
+	STR_CURR_FIM,
+	STR_CURR_FRF,
+	STR_CURR_GRD,
+	STR_CURR_HUF,
+	STR_CURR_ISK,
+	STR_CURR_ITL,
+	STR_CURR_NLG,
+	STR_CURR_NOK,
+	STR_CURR_PLN,
+	STR_CURR_ROL,
+	STR_CURR_RUR,
+	STR_CURR_SEK,
+	STR_CURR_CUSTOM,
+	INVALID_STRING_ID
+};
+
+// NOTE: Make sure both lists are in the same order
+// + 1 string list terminator
+assert_compile(lengthof(_currency_specs) + 1 == lengthof(_currency_string_list));
+
+
+// get a mask of the allowed currencies depending on the year
+uint GetMaskOfAllowedCurrencies(void)
+{
+	uint mask = 0;
+	uint i;
+
+	for (i = 0; i != lengthof(_currency_specs); i++) {
+		uint16 to_euro = _currency_specs[i].to_euro;
+
+		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro - MAX_YEAR_BEGIN_REAL) continue;
+		if (to_euro == CF_ISEURO && _cur_year < 2000 - MAX_YEAR_BEGIN_REAL) continue;
+		mask |= (1 << i);
+	}
+	mask |= (1 << 23); // always allow custom currency
+	return mask;
+}
+
+
+uint GetCurrentCurrencyRate(void)
+{
+	return _currency_specs[_opt_ptr->currency].rate;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/currency.h	Sat Aug 06 14:59:54 2005 +0000
@@ -0,0 +1,23 @@
+#ifndef CURRENCY_H
+#define CURRENCY_H
+
+enum {
+	CF_NOEURO = 0,
+	CF_ISEURO = 1,
+};
+
+typedef struct {
+	uint16 rate;
+	char separator;
+	uint16 to_euro;
+	char prefix[16];
+	char suffix[16];
+} CurrencySpec;
+
+extern CurrencySpec _currency_specs[];
+extern const StringID _currency_string_list[];
+
+uint GetMaskOfAllowedCurrencies(void);
+uint GetCurrentCurrencyRate(void);
+
+#endif
--- a/economy.c	Sat Aug 06 14:58:06 2005 +0000
+++ b/economy.c	Sat Aug 06 14:59:54 2005 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "currency.h"
 #include "functions.h"
 #include "strings.h" // XXX InjectDParam()
 #include "table/strings.h"
@@ -41,22 +42,6 @@
 
 int _score_part[MAX_PLAYERS][NUM_SCORE];
 
-
-// get a mask of the allowed currencies depending on the year
-uint GetMaskOfAllowedCurrencies(void)
-{
-	int i;
-	uint mask = 0;
-	for (i = 0; i != lengthof(_currency_specs); i++) {
-		uint16 to_euro = _currency_specs[i].to_euro;
-		if (i == 23) mask |= (1 << 23); // always allow custom currency
-		if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= (to_euro-MAX_YEAR_BEGIN_REAL)) continue;
-		if (_cur_year < (2000-MAX_YEAR_BEGIN_REAL) && (to_euro == CF_ISEURO)) continue;
-		mask |= (1 << i);
-	}
-	return mask;
-}
-
 void CheckSwitchToEuro(void)
 {
 	if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
--- a/settings.c	Sat Aug 06 14:58:06 2005 +0000
+++ b/settings.c	Sat Aug 06 14:59:54 2005 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "currency.h"
 #include "functions.h"
 #include "macros.h"
 #include "screenshot.h"
@@ -9,7 +10,6 @@
 #include "spritecache.h"
 #include "string.h"
 #include "variables.h"
-#include "table/currency.h"
 #include "network.h"
 #include "settings.h"
 
--- a/settings_gui.c	Sat Aug 06 14:58:06 2005 +0000
+++ b/settings_gui.c	Sat Aug 06 14:59:54 2005 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "currency.h"
 #include "functions.h"
 #include "string.h"
 #include "strings.h" // XXX GetCurrentCurrencyRate()
@@ -23,9 +24,6 @@
 static uint32 _difficulty_click_b;
 static byte _difficulty_timeout;
 
-extern const StringID _currency_string_list[];
-extern uint GetMaskOfAllowedCurrencies(void);
-
 static const StringID _distances_dropdown[] = {
 	STR_0139_IMPERIAL_MILES,
 	STR_013A_METRIC_KILOMETERS,
--- a/strings.c	Sat Aug 06 14:58:06 2005 +0000
+++ b/strings.c	Sat Aug 06 14:59:54 2005 +0000
@@ -2,6 +2,7 @@
 
 #include "stdafx.h"
 #include "openttd.h"
+#include "currency.h"
 #include "functions.h"
 #include "string.h"
 #include "strings.h"
@@ -43,34 +44,6 @@
 static uint _langtab_num[32]; // Offset into langpack offs
 static uint _langtab_start[32]; // Offset into langpack offs
 
-const StringID _currency_string_list[] = {
-	STR_CURR_GBP,
-	STR_CURR_USD,
-	STR_CURR_EUR,
-	STR_CURR_YEN,
-	STR_CURR_ATS,
-	STR_CURR_BEF,
-	STR_CURR_CHF,
-	STR_CURR_CZK,
-	STR_CURR_DEM,
-	STR_CURR_DKK,
-	STR_CURR_ESP,
-	STR_CURR_FIM,
-	STR_CURR_FRF,
-	STR_CURR_GRD,
-	STR_CURR_HUF,
-	STR_CURR_ISK,
-	STR_CURR_ITL,
-	STR_CURR_NLG,
-	STR_CURR_NOK,
-	STR_CURR_PLN,
-	STR_CURR_ROL,
-	STR_CURR_RUR,
-	STR_CURR_SEK,
-	STR_CURR_CUSTOM,
-	INVALID_STRING_ID
-};
-
 static const StringID _cargo_string_list[NUM_LANDSCAPE][NUM_CARGO] = {
 	{ /* LT_NORMAL */
 		STR_PASSENGERS,
@@ -372,11 +345,6 @@
 	return buff;
 }
 
-uint GetCurrentCurrencyRate(void)
-{
-	return _currency_specs[_opt_ptr->currency].rate;
-}
-
 static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
 {
 	const char *s;
--- a/strings.h	Sat Aug 06 14:58:06 2005 +0000
+++ b/strings.h	Sat Aug 06 14:59:54 2005 +0000
@@ -18,6 +18,5 @@
 
 void InjectDParam(int amount);
 int32 GetParamInt32(void);
-uint GetCurrentCurrencyRate(void);
 
 #endif
--- a/table/currency.h	Sat Aug 06 14:58:06 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/* $Id$ */
-
-// exchange rate    prefix
-// |  separator        |     postfix
-// |   |    Euro year  |       |
-// |   |    |          |       |
-CurrencySpec _currency_specs[] = {
-{ 1,   ',', CF_NOEURO, "\xA3",   "" }, // british pounds
-{ 2,   ',', CF_NOEURO, "$",      "" }, // us dollars
-{ 2,   ',', CF_ISEURO, "¤",      "" }, // Euro
-{ 200, ',', CF_NOEURO, "\xA5",   "" }, // yen
-
-{ 19,  ',', 2002,         "", " S." }, // austrian schilling
-{ 57,  ',', 2002,     "BEF ",    "" }, // belgian franc
-{ 2,   ',', CF_NOEURO,"CHF ",    "" }, // swiss franc
-{ 50,  ',', CF_NOEURO,    "", " Kc" }, // czech koruna // TODO: Should use the "c" with an upside down "^"
-{ 4,   '.', 2002,      "DM ",    "" }, // deutsche mark
-{ 10,  '.', CF_NOEURO,    "", " kr" }, // danish krone
-{ 200, '.', 2002,     "Pts ",    "" }, // spanish pesetas
-{ 8,   ',', 2002,         "", " MK" }, // finnish markka
-{ 10,  '.', 2002,      "FF ",    "" }, // french francs
-{ 480, ',', 2002,         "", "Dr." }, // greek drachma
-{ 376, ',', 2002,         "", " Ft" }, // forint
-{ 130, '.', CF_NOEURO,    "", " Kr" }, // icelandic krona
-{ 2730,',', 2002,         "", " L." }, // italian lira
-{ 3,   ',', 2002,     "NLG ",    "" }, // dutch gulden
-{ 11,  '.', CF_NOEURO,    "", " Kr" }, // norwegian krone
-{ 6,   ' ', CF_NOEURO,    "", " zl" }, // polish zloty
-{ 6,   '.', CF_NOEURO,    ""," Lei" }, // romanian Lei
-{ 5,   ' ', CF_NOEURO,    "",  " p" }, // russian rouble
-{ 13,  '.', CF_NOEURO,    "", " Kr" }, // swedish krona
-{ 1,   ' ', CF_NOEURO,    "",    "" }, // custom currency
-};
-
--- a/variables.h	Sat Aug 06 14:58:06 2005 +0000
+++ b/variables.h	Sat Aug 06 14:59:54 2005 +0000
@@ -37,21 +37,6 @@
 // Pointer to one of the two _opt OR _opt_newgame structs
 VARDEF GameOptions *_opt_ptr;
 
-enum {
-	CF_NOEURO = 0,
-	CF_ISEURO = 1,
-};
-
-typedef struct {
-	uint16 rate;
-	char separator;
-	uint16 to_euro;
-	char prefix[16];
-	char suffix[16];
-} CurrencySpec;
-
-VARDEF CurrencySpec _currency_specs[24];
-
 // Current date
 VARDEF uint16 _date;
 VARDEF uint16 _date_fract;