currency.c
author Darkvater
Tue, 15 Aug 2006 14:38:43 +0000
changeset 4284 adbca0e65aaa
parent 4261 2ec8f5a9747b
child 4286 a040bf5c203d
permissions -rw-r--r--
(svn r5914) -Fix [FS#235]: Bugfix for errors in FindNearestHangar function in aircraft_cmd.c (mart3p).
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 768
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 768
diff changeset
     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
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
    11
// 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
    12
// |  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
    13
// |   |    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
    14
// |   |    |          |       |
759
6d087784a08a (svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff changeset
    15
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
    16
	{    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
    17
	{    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
    18
	{    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
    19
	{  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
    20
	{   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
    21
	{   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
    22
	{    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
    23
	{   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
    24
	{    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
    25
	{   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
    26
	{  200, '.', 2002,      "Pts ", ""     }, // spanish pesetas
2495
460b334444a5 (svn r3021) -Fix: "The finnish markka was never abbreviated with capital letters." (ln-)
tron
parents: 2468
diff changeset
    27
	{    8, ',', 2002,      "",     " mk"  }, // finnish markka
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
    28
	{   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
    29
	{  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
    30
	{  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
    31
	{  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
    32
	{ 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
    33
	{    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
    34
	{   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
    35
	{    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
    36
	{    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
    37
	{    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
    38
	{   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
    39
	{    1, ' ', CF_NOEURO, "",     ""     }, // custom currency
759
6d087784a08a (svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff changeset
    40
};
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
    41
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
    42
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
    43
	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
    44
	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
    45
	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
    46
	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
    47
	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
    48
	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
    49
	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
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	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
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
	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
    67
	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
    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
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
// 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
    71
// + 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
    72
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
    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
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
// 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
    76
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
    77
{
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 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
    79
	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
    80
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
	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
    82
		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
    83
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_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
    85
		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
    86
		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
    87
	}
3596
443a7377c67e (svn r4487) - Codechange: replace the custom currency magic number 23 with a define
peter1138
parents: 2495
diff changeset
    88
	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
    89
	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
    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
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
    93
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
    94
{
3d4efe849dd9 (svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents: 2291
diff changeset
    95
	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
    96
			_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
    97
			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
    98
		_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
    99
		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
   100
	}
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
}
4138
15f4aa024ad4 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 3596
diff changeset
   102