currency.c
author tron
Tue, 22 Aug 2006 20:39:18 +0000
changeset 4353 2b941f2c325c
parent 4311 c4a53bd6d5b3
child 4377 0fb9077b8173
permissions -rw-r--r--
(svn r6054) Change the sign sorter in a similar way as the other sorters: Remember a list of pointers to signs instead of a list of SignIDs - This removes a layer of indirection
Also make the sign list static
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
4311
c4a53bd6d5b3 (svn r5964) -Feature: FS#131 Slovenian currency (MeusH)
bjarni
parents: 4297
diff changeset
    38
	{  350, '.', CF_NOEURO, "",     " SIT" }, // slovenian tolar
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
    39
	{   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
    40
	{    1, ' ', CF_NOEURO, "",     ""     }, // 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
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
    43
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
    44
	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
    45
	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
    46
	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
    47
	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
    48
	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
    49
	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
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	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
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	STR_CURR_RUR,
4311
c4a53bd6d5b3 (svn r5964) -Feature: FS#131 Slovenian currency (MeusH)
bjarni
parents: 4297
diff changeset
    66
	STR_CURR_SIT,
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
    67
	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
    68
	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
    69
	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
    70
};
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
// 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
    73
// + 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
    74
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
    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
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
// 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
    78
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
    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
	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
    81
	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
    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
	for (i = 0; i != lengthof(_currency_specs); i++) {
4297
47ce9665b4af (svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents: 4293
diff changeset
    84
		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
    85
4293
2c24234a7aec (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4286
diff changeset
    86
		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
    87
		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
    88
		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
    89
	}
3596
443a7377c67e (svn r4487) - Codechange: replace the custom currency magic number 23 with a define
peter1138
parents: 2495
diff changeset
    90
	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
    91
	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
    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
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
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
    95
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
    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
	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
    98
			_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
    99
			_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
   100
		_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
   101
		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
   102
	}
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
}
4138
15f4aa024ad4 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 3596
diff changeset
   104