currency.c
author tron
Sat, 06 Aug 2005 14:59:54 +0000
changeset 2291 2b064aa97f91
parent 2186 table/currency.h@461a2aff3486
child 2306 3d4efe849dd9
permissions -rw-r--r--
(svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
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"
2b064aa97f91 (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents: 2186
diff changeset
     6
#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
     7
#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
     8
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
     9
// 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
    10
// |  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
    11
// |   |    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
    12
// |   |    |          |       |
759
6d087784a08a (svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff changeset
    13
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
    14
	{    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
    15
	{    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
    16
	{    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
    17
	{  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
    18
	{   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
    19
	{   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
    20
	{    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
    21
	{   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
    22
	{    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
    23
	{   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
    24
	{  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
    25
	{    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
    26
	{   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
    27
	{  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
    28
	{  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
    29
	{  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
    30
	{ 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
    31
	{    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
    32
	{   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
    33
	{    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
    34
	{    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
    35
	{    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
    36
	{   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
    37
	{    1, ' ', CF_NOEURO, "",     ""     }, // custom currency
759
6d087784a08a (svn r1215) Feature: You can now make a custom currency by chosing "Custom..."
dominik
parents:
diff changeset
    38
};
768
deb40d3554a2 (svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents: 762
diff changeset
    39
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
    40
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
    41
	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
    42
	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
    43
	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
    44
	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
    45
	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
    46
	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
    47
	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
    48
	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
    49
	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
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	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
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
};
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
// 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
    69
// + 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
    70
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
    71
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
// 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
    74
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
    75
{
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 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
    77
	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
    78
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
	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
    80
		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
    81
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
		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
    83
		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
    84
		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
    85
	}
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 << 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
    87
	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
    88
}
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
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
    92
{
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
	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
    94
}