currency.c
author rubidium
Thu, 24 Aug 2006 10:19:59 +0000
changeset 4369 3812b4335df9
parent 4311 2ac86c9c0ced
child 4377 f04bcf6f9a04
permissions -rw-r--r--
(svn r6086) -Fix: InteractiveRandom was not seeded properly resulting in the dedicated server always generating the same map. Thanks to the #openttdcoop team for detecting.
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     1
/* $Id$ */
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     2
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     3
#include "stdafx.h"
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     4
#include "openttd.h"
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     5
#include "currency.h"
2306
adb71c055afb (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
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     7
#include "variables.h"
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
     8
#include "table/strings.h"
4261
28670f743746 (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 4138
diff changeset
     9
#include "date.h"
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    10
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    11
// exchange rate    prefix
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    12
// |  separator        |     postfix
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    13
// |   |    Euro year  |       |
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    14
// |   |    |          |       |
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    15
CurrencySpec _currency_specs[] = {
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    16
	{    1, ',', CF_NOEURO, "\xA3", ""     }, // british pounds
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    17
	{    2, ',', CF_NOEURO, "$",    ""     }, // us dollars
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    18
	{    2, ',', CF_ISEURO, "¤",    ""     }, // Euro
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    19
	{  200, ',', CF_NOEURO, "\xA5", ""     }, // yen
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    20
	{   19, ',', 2002,      "",     " S."  }, // austrian schilling
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    21
	{   57, ',', 2002,      "BEF ", ""     }, // belgian franc
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    22
	{    2, ',', CF_NOEURO, "CHF ", ""     }, // swiss franc
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    23
	{   50, ',', CF_NOEURO, "",     " Kc"  }, // czech koruna // TODO: Should use the "c" with an upside down "^"
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    24
	{    4, '.', 2002,      "DM ",  ""     }, // deutsche mark
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    25
	{   10, '.', CF_NOEURO, "",     " kr"  }, // danish krone
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    26
	{  200, '.', 2002,      "Pts ", ""     }, // spanish pesetas
2495
b9864001ab31 (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
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    28
	{   10, '.', 2002,      "FF ",  ""     }, // french francs
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    29
	{  480, ',', 2002,      "",     "Dr."  }, // greek drachma
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    30
	{  376, ',', 2002,      "",     " Ft"  }, // hungarian forint
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    31
	{  130, '.', CF_NOEURO, "",     " Kr"  }, // icelandic krona
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    32
	{ 2730, ',', 2002,      "",     " L."  }, // italian lira
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    33
	{    3, ',', 2002,      "NLG ", ""     }, // dutch gulden
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    34
	{   11, '.', CF_NOEURO, "",     " Kr"  }, // norwegian krone
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    35
	{    6, ' ', CF_NOEURO, "",     " zl"  }, // polish zloty
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    36
	{    6, '.', CF_NOEURO, "",     " Lei" }, // romanian Lei
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    37
	{    5, ' ', CF_NOEURO, "",     " p"   }, // russian rouble
4311
2ac86c9c0ced (svn r5964) -Feature: FS#131 Slovenian currency (MeusH)
bjarni
parents: 4297
diff changeset
    38
	{  350, '.', CF_NOEURO, "",     " SIT" }, // slovenian tolar
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    39
	{   13, '.', CF_NOEURO, "",     " Kr"  }, // swedish krona
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    40
	{    1, ' ', CF_NOEURO, "",     ""     }, // custom currency
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    41
};
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    42
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    43
const StringID _currency_string_list[] = {
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    44
	STR_CURR_GBP,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    45
	STR_CURR_USD,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    46
	STR_CURR_EUR,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    47
	STR_CURR_YEN,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    48
	STR_CURR_ATS,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    49
	STR_CURR_BEF,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    50
	STR_CURR_CHF,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    51
	STR_CURR_CZK,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    52
	STR_CURR_DEM,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    53
	STR_CURR_DKK,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    54
	STR_CURR_ESP,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    55
	STR_CURR_FIM,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    56
	STR_CURR_FRF,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    57
	STR_CURR_GRD,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    58
	STR_CURR_HUF,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    59
	STR_CURR_ISK,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    60
	STR_CURR_ITL,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    61
	STR_CURR_NLG,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    62
	STR_CURR_NOK,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    63
	STR_CURR_PLN,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    64
	STR_CURR_ROL,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    65
	STR_CURR_RUR,
4311
2ac86c9c0ced (svn r5964) -Feature: FS#131 Slovenian currency (MeusH)
bjarni
parents: 4297
diff changeset
    66
	STR_CURR_SIT,
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    67
	STR_CURR_SEK,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    68
	STR_CURR_CUSTOM,
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    69
	INVALID_STRING_ID
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    70
};
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    71
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    72
// NOTE: Make sure both lists are in the same order
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    73
// + 1 string list terminator
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    74
assert_compile(lengthof(_currency_specs) + 1 == lengthof(_currency_string_list));
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    75
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    76
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    77
// get a mask of the allowed currencies depending on the year
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    78
uint GetMaskOfAllowedCurrencies(void)
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    79
{
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    80
	uint mask = 0;
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    81
	uint i;
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    82
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    83
	for (i = 0; i != lengthof(_currency_specs); i++) {
4297
d0311b62255c (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
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    85
4293
4b7006c1b5eb (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;
4b7006c1b5eb (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
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    88
		mask |= (1 << i);
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    89
	}
3596
6654541a3958 (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
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    91
	return mask;
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    92
}
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    93
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    94
2306
adb71c055afb (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)
adb71c055afb (svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents: 2291
diff changeset
    96
{
adb71c055afb (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 &&
adb71c055afb (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
4b7006c1b5eb (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
adb71c055afb (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.
adb71c055afb (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);
adb71c055afb (svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents: 2291
diff changeset
   102
	}
adb71c055afb (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
8640f25e2510 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 3596
diff changeset
   104