src/currency.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:32:07 +0200
changeset 10438 51bff16a04c9
parent 10344 c33159ae992a
permissions -rw-r--r--
initial mini-map stuff
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
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8763
diff changeset
     3
/** @file currency.cpp Support for different currencies. */
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
     4
2291
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 "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
     6
#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
     7
#include "currency.h"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8270
diff changeset
     8
#include "news_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
     9
#include "settings_type.h"
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8140
diff changeset
    10
#include "date_func.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8140
diff changeset
    11
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    12
#include "table/strings.h"
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    13
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    14
	//   exchange rate    prefix             symbol_pos
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    15
	//   |  separator        |     postfix   |
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    16
	//   |   |    Euro year  |       |       |    name
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    17
	//   |   |    |          |       |       |    |
5023
4c9b3eabcafa (svn r7064) static
tron
parents: 4626
diff changeset
    18
static const CurrencySpec origin_currency_specs[NUM_CURRENCY] = {
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    19
	{    1, ',', CF_NOEURO, "£",    "",      0,  STR_CURR_GBP    }, ///< british pounds
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    20
	{    2, ',', CF_NOEURO, "$",    "",      0,  STR_CURR_USD    }, ///< us dollars
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    21
	{    2, ',', CF_ISEURO, "€",    "",      0,  STR_CURR_EUR    }, ///< Euro
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    22
	{  220, ',', CF_NOEURO, "¥",    "",      0,  STR_CURR_YEN    }, ///< yen
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    23
	{   20, ',', 2002,      "",     " S.",   1,  STR_CURR_ATS    }, ///< austrian schilling
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    24
	{   59, ',', 2002,      "BEF ", "",      0,  STR_CURR_BEF    }, ///< belgian franc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    25
	{    2, ',', CF_NOEURO, "CHF ", "",      0,  STR_CURR_CHF    }, ///< swiss franc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    26
	{   41, ',', CF_NOEURO, "",     " Kč",   1,  STR_CURR_CZK    }, ///< czech koruna
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    27
	{    3, '.', 2002,      "DM ",  "",      0,  STR_CURR_DEM    }, ///< deutsche mark
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    28
	{   11, '.', CF_NOEURO, "",     " kr",   1,  STR_CURR_DKK    }, ///< danish krone
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    29
	{  245, '.', 2002,      "Pts ", "",      0,  STR_CURR_ESP    }, ///< spanish pesetas
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    30
	{    9, ',', 2002,      "",     " mk",   1,  STR_CURR_FIM    }, ///< finnish markka
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    31
	{   10, '.', 2002,      "FF ",  "",      0,  STR_CURR_FRF    }, ///< french francs
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    32
	{  500, ',', 2002,      "",     "Dr.",   1,  STR_CURR_GRD    }, ///< greek drachma
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    33
	{  378, ',', 2010,      "",     " Ft",   1,  STR_CURR_HUF    }, ///< hungarian forint
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    34
	{  130, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_ISK    }, ///< icelandic krona
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    35
	{ 2850, ',', 2002,      "",     " L.",   1,  STR_CURR_ITL    }, ///< italian lira
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    36
	{    3, ',', 2002,      "NLG ", "",      0,  STR_CURR_NLG    }, ///< dutch gulden
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    37
	{   12, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_NOK    }, ///< norwegian krone
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    38
	{    6, ' ', CF_NOEURO, "",     " zl",   1,  STR_CURR_PLN    }, ///< polish zloty
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    39
	{    5, '.', CF_NOEURO, "",     " Lei",  1,  STR_CURR_ROL    }, ///< romanian Lei
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    40
	{   50, ' ', CF_NOEURO, "",     " p",    1,  STR_CURR_RUR    }, ///< russian rouble
10344
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    41
	{  352, '.', 2007,      "",     " SIT",  1,  STR_CURR_SIT    }, ///< slovenian tolar
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    42
	{   13, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_SEK    }, ///< swedish krona
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    43
	{    3, '.', CF_NOEURO, "",     " YTL",  1,  STR_CURR_YTL    }, ///< turkish lira
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    44
	{   52, ',', CF_NOEURO, "",     " Sk",   1,  STR_CURR_SKK    }, ///< slovak koruna
10344
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    45
	{    4, ',', CF_NOEURO, "R$ ",  "",      0,  STR_CURR_BRL    }, ///< brazil real
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    46
	{   20, '.', CF_NOEURO, "",     " EEK",  1,  STR_CURR_EEK    }, ///< estonian krooni
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
    47
	{    1, ' ', CF_NOEURO, "",     "",      2,  STR_CURR_CUSTOM }, ///< 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
    48
};
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
    49
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    50
/* Array of currencies used by the system */
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
    51
CurrencySpec _currency_specs[NUM_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
    52
4625
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    53
/**
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    54
 * These enums are only declared in order to make sens
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    55
 * out of the TTDPatch_To_OTTDIndex array that will follow
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    56
 * Every currency used by Ottd is there, just in case TTDPatch will
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    57
 * add those missing in its code
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    58
 **/
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    59
enum {
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    60
	CURR_GBP,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    61
	CURR_USD,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    62
	CURR_EUR,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    63
	CURR_YEN,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    64
	CURR_ATS,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    65
	CURR_BEF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    66
	CURR_CHF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    67
	CURR_CZK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    68
	CURR_DEM,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    69
	CURR_DKK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    70
	CURR_ESP,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    71
	CURR_FIM,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    72
	CURR_FRF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    73
	CURR_GRD,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    74
	CURR_HUF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    75
	CURR_ISK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    76
	CURR_ITL,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    77
	CURR_NLG,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    78
	CURR_NOK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    79
	CURR_PLN,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    80
	CURR_ROL,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    81
	CURR_RUR,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    82
	CURR_SIT,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    83
	CURR_SEK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    84
	CURR_YTL,
10344
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    85
	CURR_SKK,
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    86
	CURR_BRL,
c33159ae992a (svn r14595) -Add: Estonian currency.
rubidium
parents: 9950
diff changeset
    87
	CURR_EEK,
4625
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    88
};
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    89
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    90
/**
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    91
 * This array represent the position of OpenTTD's currencies,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    92
 * compared to TTDPatch's ones.
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    93
 * When a grf sends currencies, they are based on the order defined by TTDPatch.
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    94
 * So, we must reindex them to our own order.
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    95
 **/
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    96
const byte TTDPatch_To_OTTDIndex[] =
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    97
{
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    98
	CURR_GBP,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
    99
	CURR_USD,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   100
	CURR_FRF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   101
	CURR_DEM,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   102
	CURR_YEN,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   103
	CURR_ESP,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   104
	CURR_HUF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   105
	CURR_PLN,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   106
	CURR_ATS,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   107
	CURR_BEF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   108
	CURR_DKK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   109
	CURR_FIM,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   110
	CURR_GRD,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   111
	CURR_CHF,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   112
	CURR_NLG,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   113
	CURR_ITL,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   114
	CURR_SEK,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   115
	CURR_RUR,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   116
	CURR_EUR,
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   117
};
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   118
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   119
/**
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   120
 * Will return the ottd's index correspondance to
9950
2a0d0769c0e3 (svn r14105) -Fix: Some typos that are more grammatical errors, as it seems.
belugas
parents: 9466
diff changeset
   121
 * the ttdpatch's id.  If the id is bigger than the array,
2a0d0769c0e3 (svn r14105) -Fix: Some typos that are more grammatical errors, as it seems.
belugas
parents: 9466
diff changeset
   122
 * it is a grf written for ottd, thus returning the same id.
2a0d0769c0e3 (svn r14105) -Fix: Some typos that are more grammatical errors, as it seems.
belugas
parents: 9466
diff changeset
   123
 * Only called from newgrf.cpp
4625
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   124
 * @param grfcurr_id currency id coming from newgrf
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   125
 * @return the corrected index
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   126
 **/
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   127
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id)
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   128
{
4626
ce414b54bfc3 (svn r6486) -Fix (r6485): wrong variable name used in GetNewgrfCurrencyIdConverted()
glx
parents: 4625
diff changeset
   129
	return (grfcurr_id >= lengthof(TTDPatch_To_OTTDIndex)) ? grfcurr_id : TTDPatch_To_OTTDIndex[grfcurr_id];
4625
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   130
}
f365b341a330 (svn r6485) -NewGRF Feature: Match the order of TTDPatch's currencies with those used in OTTD.
belugas
parents: 4602
diff changeset
   131
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
   132
/**
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
   133
 * get a mask of the allowed currencies depending on the year
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
   134
 * @return mask of currencies
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5584
diff changeset
   135
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6226
diff changeset
   136
uint GetMaskOfAllowedCurrencies()
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
   137
{
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
   138
	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
   139
	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
   140
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   141
	for (i = 0; i < NUM_CURRENCY; i++) {
4297
d0311b62255c (svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents: 4293
diff changeset
   142
		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
   143
4293
4b7006c1b5eb (svn r5926) -Codechange: make _cur_year contain the full year, instead of the offset since 1920
rubidium
parents: 4286
diff changeset
   144
		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
   145
		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
   146
		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
   147
	}
3596
6654541a3958 (svn r4487) - Codechange: replace the custom currency magic number 23 with a define
peter1138
parents: 2495
diff changeset
   148
	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
   149
	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
   150
}
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents:
diff changeset
   151
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   152
/**
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   153
 * Verify if the currency chosen by the user is about to be converted to Euro
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   154
 **/
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6226
diff changeset
   155
void CheckSwitchToEuro()
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
   156
{
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   157
	if (_currency_specs[_settings_game.locale.currency].to_euro != CF_NOEURO &&
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   158
			_currency_specs[_settings_game.locale.currency].to_euro != CF_ISEURO &&
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   159
			_cur_year >= _currency_specs[_settings_game.locale.currency].to_euro) {
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   160
		_settings_game.locale.currency = 2; // this is the index of euro above.
9234
bfc9d27d3d0d (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium
parents: 9111
diff changeset
   161
		AddNewsItem(STR_EURO_INTRODUCE, NS_ECONOMY, 0, 0);
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
   162
	}
adb71c055afb (svn r2830) Move CheckSwitchToEuro() to currency.[ch] and hide the truth about the custom currency behind a #define
tron
parents: 2291
diff changeset
   163
}
4138
8640f25e2510 (svn r5496) -CodeChange: Removed two compiler warnings
belugas
parents: 3596
diff changeset
   164
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   165
/**
6379
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   166
 * Will fill _currency_specs array with
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   167
 * default values from origin_currency_specs
6379
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   168
 * Called only from newgrf.cpp and settings.cpp.
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   169
 * @param preserve_custom will not reset custom currency (the latest one on the list)
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   170
 *        if ever it is flagged to true. In which case, the total size of the memory to move
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   171
 *        will be one currency spec less, thus preserving the custom curreny from been
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   172
 *        overwritten.
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   173
 **/
6379
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   174
void ResetCurrencies(bool preserve_custom)
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   175
{
6379
e3cb84b60342 (svn r9467) -Fix(FS#703,6108): When resetting the array of currencies, the custom currency was reset too, thus loosing the setting a user could have used for it.(glx)
belugas
parents: 6247
diff changeset
   176
	memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs) - (preserve_custom ? sizeof(_custom_currency) : 0));
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   177
}
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   178
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   179
/**
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   180
 * Build a list of currency names StringIDs to use in a dropdown list
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   181
 * @return Pointer to a (static) array of StringIDs
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   182
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6226
diff changeset
   183
StringID* BuildCurrencyDropdown()
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   184
{
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   185
	/* Allow room for all currencies, plus a terminator entry */
6226
e2e9607ea3cc (svn r9027) -Fix [FS#664]: desync caused by buffer overrun.
rubidium
parents: 6123
diff changeset
   186
	static StringID names[NUM_CURRENCY + 1];
4377
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   187
	uint i;
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   188
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   189
	/* Add each name */
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   190
	for (i = 0; i < NUM_CURRENCY; i++) {
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   191
		names[i] = _currency_specs[i].name;
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   192
	}
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   193
	/* Terminate the list */
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   194
	names[i] = INVALID_STRING_ID;
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   195
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   196
	return names;
f04bcf6f9a04 (svn r6108) -NewGRF Feature: Implement currencies replacment via grf file.
belugas
parents: 4311
diff changeset
   197
}