author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2306 | 3d4efe849dd9 |
child 2468 | 15753a8438ba |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
3 |
#include "stdafx.h" |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
4 |
#include "openttd.h" |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
5 |
#include "currency.h" |
2306
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
6 |
#include "news.h" |
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
7 |
#include "variables.h" |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
8 |
#include "table/strings.h" |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
9 |
|
762
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
10 |
// exchange rate prefix |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
11 |
// | separator | postfix |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
12 |
// | | Euro year | | |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
759
diff
changeset
|
13 |
// | | | | | |
759
6d087784a08a
(svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff
changeset
|
14 |
CurrencySpec _currency_specs[] = { |
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
15 |
{ 1, ',', CF_NOEURO, "\xA3", "" }, // british pounds |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
16 |
{ 2, ',', CF_NOEURO, "$", "" }, // us dollars |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
17 |
{ 2, ',', CF_ISEURO, "¤", "" }, // Euro |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
18 |
{ 200, ',', CF_NOEURO, "\xA5", "" }, // yen |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
19 |
{ 19, ',', 2002, "", " S." }, // austrian schilling |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
20 |
{ 57, ',', 2002, "BEF ", "" }, // belgian franc |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
21 |
{ 2, ',', CF_NOEURO, "CHF ", "" }, // swiss franc |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
22 |
{ 50, ',', CF_NOEURO, "", " Kc" }, // czech koruna // TODO: Should use the "c" with an upside down "^" |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
23 |
{ 4, '.', 2002, "DM ", "" }, // deutsche mark |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
24 |
{ 10, '.', CF_NOEURO, "", " kr" }, // danish krone |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
25 |
{ 200, '.', 2002, "Pts ", "" }, // spanish pesetas |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
26 |
{ 8, ',', 2002, "", " MK" }, // finnish markka |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
27 |
{ 10, '.', 2002, "FF ", "" }, // french francs |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
28 |
{ 480, ',', 2002, "", "Dr." }, // greek drachma |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
29 |
{ 376, ',', 2002, "", " Ft" }, // hungarian forint |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
30 |
{ 130, '.', CF_NOEURO, "", " Kr" }, // icelandic krona |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
31 |
{ 2730, ',', 2002, "", " L." }, // italian lira |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
32 |
{ 3, ',', 2002, "NLG ", "" }, // dutch gulden |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
33 |
{ 11, '.', CF_NOEURO, "", " Kr" }, // norwegian krone |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
34 |
{ 6, ' ', CF_NOEURO, "", " zl" }, // polish zloty |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
35 |
{ 6, '.', CF_NOEURO, "", " Lei" }, // romanian Lei |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
36 |
{ 5, ' ', CF_NOEURO, "", " p" }, // russian rouble |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
37 |
{ 13, '.', CF_NOEURO, "", " Kr" }, // swedish krona |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
38 |
{ 1, ' ', CF_NOEURO, "", "" }, // custom currency |
759
6d087784a08a
(svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff
changeset
|
39 |
}; |
768
deb40d3554a2
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
40 |
|
2291
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
41 |
const StringID _currency_string_list[] = { |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
42 |
STR_CURR_GBP, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
43 |
STR_CURR_USD, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
44 |
STR_CURR_EUR, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
45 |
STR_CURR_YEN, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
46 |
STR_CURR_ATS, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
47 |
STR_CURR_BEF, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
48 |
STR_CURR_CHF, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
49 |
STR_CURR_CZK, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
50 |
STR_CURR_DEM, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
51 |
STR_CURR_DKK, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
52 |
STR_CURR_ESP, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
53 |
STR_CURR_FIM, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
54 |
STR_CURR_FRF, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
55 |
STR_CURR_GRD, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
56 |
STR_CURR_HUF, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
57 |
STR_CURR_ISK, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
58 |
STR_CURR_ITL, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
59 |
STR_CURR_NLG, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
60 |
STR_CURR_NOK, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
61 |
STR_CURR_PLN, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
62 |
STR_CURR_ROL, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
63 |
STR_CURR_RUR, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
64 |
STR_CURR_SEK, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
65 |
STR_CURR_CUSTOM, |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
66 |
INVALID_STRING_ID |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
67 |
}; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
68 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
69 |
// NOTE: Make sure both lists are in the same order |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
70 |
// + 1 string list terminator |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
71 |
assert_compile(lengthof(_currency_specs) + 1 == lengthof(_currency_string_list)); |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
72 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
73 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
74 |
// get a mask of the allowed currencies depending on the year |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
75 |
uint GetMaskOfAllowedCurrencies(void) |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
76 |
{ |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
77 |
uint mask = 0; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
78 |
uint i; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
79 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
80 |
for (i = 0; i != lengthof(_currency_specs); i++) { |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
81 |
uint16 to_euro = _currency_specs[i].to_euro; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
82 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
83 |
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro - MAX_YEAR_BEGIN_REAL) continue; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
84 |
if (to_euro == CF_ISEURO && _cur_year < 2000 - MAX_YEAR_BEGIN_REAL) continue; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
85 |
mask |= (1 << i); |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
86 |
} |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
87 |
mask |= (1 << 23); // always allow custom currency |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
88 |
return mask; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
89 |
} |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
90 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
91 |
|
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
92 |
uint GetCurrentCurrencyRate(void) |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
93 |
{ |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
94 |
return _currency_specs[_opt_ptr->currency].rate; |
2b064aa97f91
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
2186
diff
changeset
|
95 |
} |
2306
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
96 |
|
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
97 |
|
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
98 |
void CheckSwitchToEuro(void) |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
99 |
{ |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
100 |
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO && |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
101 |
_currency_specs[_opt.currency].to_euro != CF_ISEURO && |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
102 |
MAX_YEAR_BEGIN_REAL + _cur_year >= _currency_specs[_opt.currency].to_euro) { |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
103 |
_opt.currency = 2; // this is the index of euro above. |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
104 |
AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0); |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
105 |
} |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
106 |
} |