author | Darkvater |
Sat, 26 Aug 2006 20:54:30 +0000 | |
changeset 4405 | 262b9ef8ab8f |
parent 4377 | 0fb9077b8173 |
child 4601 | fff5a0884ce8 |
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" |
4261
2ec8f5a9747b
(svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents:
4138
diff
changeset
|
9 |
#include "date.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
|
10 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
11 |
// exchange rate prefix symbol_pos |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
12 |
// | separator | postfix | |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
13 |
// | | Euro year | | | name |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
14 |
// | | | | | | | |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
15 |
const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
16 |
{ 1, ',', CF_NOEURO, "\xA3", "", 0, STR_CURR_GBP }, // british pounds |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
17 |
{ 2, ',', CF_NOEURO, "$", "", 0, STR_CURR_USD }, // us dollars |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
18 |
{ 2, ',', CF_ISEURO, "¤", "", 0, STR_CURR_EUR }, // Euro |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
19 |
{ 200, ',', CF_NOEURO, "\xA5", "", 0, STR_CURR_YEN }, // yen |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
20 |
{ 19, ',', 2002, "", " S.", 1, STR_CURR_ATS }, // austrian schilling |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
21 |
{ 57, ',', 2002, "BEF ", "", 0, STR_CURR_BEF }, // belgian franc |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
22 |
{ 2, ',', CF_NOEURO, "CHF ", "", 0, STR_CURR_CHF }, // swiss franc |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
23 |
{ 50, ',', CF_NOEURO, "", " Kc", 1, STR_CURR_CZK }, // czech koruna // TODO: Should use the "c" with an upside down "^" |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
24 |
{ 4, '.', 2002, "DM ", "", 0, STR_CURR_DEM }, // deutsche mark |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
25 |
{ 10, '.', CF_NOEURO, "", " kr", 1, STR_CURR_DKK }, // danish krone |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
26 |
{ 200, '.', 2002, "Pts ", "", 0, STR_CURR_ESP }, // spanish pesetas |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
27 |
{ 8, ',', 2002, "", " mk", 1, STR_CURR_FIM }, // finnish markka |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
28 |
{ 10, '.', 2002, "FF ", "", 0, STR_CURR_FRF }, // french francs |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
29 |
{ 480, ',', 2002, "", "Dr.", 1, STR_CURR_GRD }, // greek drachma |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
30 |
{ 376, ',', 2002, "", " Ft", 1, STR_CURR_HUF }, // hungarian forint |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
31 |
{ 130, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_ISK }, // icelandic krona |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
32 |
{ 2730, ',', 2002, "", " L.", 1, STR_CURR_ITL }, // italian lira |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
33 |
{ 3, ',', 2002, "NLG ", "", 0, STR_CURR_NLG }, // dutch gulden |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
34 |
{ 11, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_NOK }, // norwegian krone |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
35 |
{ 6, ' ', CF_NOEURO, "", " zl", 1, STR_CURR_PLN }, // polish zloty |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
36 |
{ 6, '.', CF_NOEURO, "", " Lei", 1, STR_CURR_ROL }, // romanian Lei |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
37 |
{ 5, ' ', CF_NOEURO, "", " p", 1, STR_CURR_RUR }, // russian rouble |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
38 |
{ 350, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
39 |
{ 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
40 |
{ 1, ' ', CF_NOEURO, "", "", 0, STR_CURR_CUSTOM }, // custom currency |
759
6d087784a08a
(svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff
changeset
|
41 |
}; |
768
deb40d3554a2
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
42 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
43 |
/* Array of currencies used by the system */ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
44 |
CurrencySpec _currency_specs[NUM_CURRENCY]; |
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
|
45 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
46 |
/* get a mask of the allowed currencies depending on the year */ |
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
|
47 |
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
|
48 |
{ |
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 |
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
|
50 |
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
|
51 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
52 |
for (i = 0; i < NUM_CURRENCY; i++) { |
4297
47ce9665b4af
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
53 |
Year to_euro = _currency_specs[i].to_euro; |
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
|
54 |
|
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
55 |
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue; |
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
56 |
if (to_euro == CF_ISEURO && _cur_year < 2000) continue; |
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
|
57 |
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
|
58 |
} |
3596
443a7377c67e
(svn r4487) - Codechange: replace the custom currency magic number 23 with a define
peter1138
parents:
2495
diff
changeset
|
59 |
mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency |
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
|
60 |
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
|
61 |
} |
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 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
63 |
/** |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
64 |
* Verify if the currency chosen by the user is about to be converted to Euro |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
65 |
**/ |
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
|
66 |
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
|
67 |
{ |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
68 |
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
|
69 |
_currency_specs[_opt.currency].to_euro != CF_ISEURO && |
4293
2c24234a7aec
(svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents:
4286
diff
changeset
|
70 |
_cur_year >= _currency_specs[_opt.currency].to_euro) { |
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
|
71 |
_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
|
72 |
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
|
73 |
} |
3d4efe849dd9
(svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents:
2291
diff
changeset
|
74 |
} |
4138
15f4aa024ad4
(svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents:
3596
diff
changeset
|
75 |
|
4377
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
76 |
/** |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
77 |
* Called only from newgrf.c. Will fill _currency_specs array with |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
78 |
* default values from origin_currency_specs |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
79 |
**/ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
80 |
void ResetCurrencies(void) |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
81 |
{ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
82 |
memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs)); |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
83 |
} |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
84 |
|
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
85 |
/** |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
86 |
* Build a list of currency names StringIDs to use in a dropdown list |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
87 |
* @return Pointer to a (static) array of StringIDs |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
88 |
*/ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
89 |
StringID* BuildCurrencyDropdown(void) |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
90 |
{ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
91 |
/* Allow room for all currencies, plus a terminator entry */ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
92 |
static StringID names[CUSTOM_CURRENCY_ID]; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
93 |
uint i; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
94 |
|
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
95 |
/* Add each name */ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
96 |
for (i = 0; i < NUM_CURRENCY; i++) { |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
97 |
names[i] = _currency_specs[i].name; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
98 |
} |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
99 |
/* Terminate the list */ |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
100 |
names[i] = INVALID_STRING_ID; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
101 |
|
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
102 |
return names; |
0fb9077b8173
(svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents:
4311
diff
changeset
|
103 |
} |