OpenTTD Source: src/currency.h Source File

OpenTTD Source 13.1

currency.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef CURRENCY_H
11 #define CURRENCY_H
12
13 #include "date_type.h"
14 #include "string_func.h"
15 #include "strings_type.h"
16
17 static const int CF_NOEURO = 0;
18 static const int CF_ISEURO = 1;
19
25 enum Currencies {
26 CURRENCY_GBP,
27 CURRENCY_USD,
28 CURRENCY_EUR,
29 CURRENCY_JPY,
30 CURRENCY_ATS,
31 CURRENCY_BEF,
32 CURRENCY_CHF,
33 CURRENCY_CZK,
34 CURRENCY_DEM,
35 CURRENCY_DKK,
36 CURRENCY_ESP,
37 CURRENCY_FIM,
38 CURRENCY_FRF,
39 CURRENCY_GRD,
40 CURRENCY_HUF,
41 CURRENCY_ISK,
42 CURRENCY_ITL,
43 CURRENCY_NLG,
44 CURRENCY_NOK,
45 CURRENCY_PLN,
46 CURRENCY_RON,
47 CURRENCY_RUR,
48 CURRENCY_SIT,
49 CURRENCY_SEK,
50 CURRENCY_YTL,
51 CURRENCY_SKK,
52 CURRENCY_BRL,
53 CURRENCY_EEK,
54 CURRENCY_LTL,
55 CURRENCY_KRW,
56 CURRENCY_ZAR,
57 CURRENCY_CUSTOM,
58 CURRENCY_GEL,
59 CURRENCY_IRR,
60 CURRENCY_RUB,
61 CURRENCY_MXN,
62 CURRENCY_NTD,
63 CURRENCY_CNY,
64 CURRENCY_HKD,
65 CURRENCY_INR,
66 CURRENCY_IDR,
67 CURRENCY_MYR,
68 CURRENCY_END,
69 };
70
72 struct CurrencySpec {
73 uint16 rate;
74 std::string separator;
75 Year to_euro;
76 std::string prefix;
77 std::string suffix;
78
87 byte symbol_pos;
88 StringID name;
89
90 CurrencySpec() = default;
91
92 CurrencySpec(uint16 rate, const char *separator, Year to_euro, const char *prefix, const char *suffix, byte symbol_pos, StringID name) :
93 rate(rate), separator(separator), to_euro(to_euro), prefix(prefix), suffix(suffix), symbol_pos(symbol_pos), name(name)
94 {
95 }
96 };
97
98 extern CurrencySpec _currency_specs[CURRENCY_END];
99
100 /* XXX small hack, but makes the rest of the code a bit nicer to read */
101 #define _custom_currency (_currency_specs[CURRENCY_CUSTOM])
102 #define _currency ((const CurrencySpec*)&_currency_specs[GetGameSettings().locale.currency])
103
104 uint64 GetMaskOfAllowedCurrencies();
105 void CheckSwitchToEuro();
106 void ResetCurrencies(bool preserve_custom = true);
107 StringID *BuildCurrencyDropdown();
108 byte GetNewgrfCurrencyIdConverted(byte grfcurr_id);
109
110 #endif /* CURRENCY_H */
_currency_specs
CurrencySpec _currency_specs[CURRENCY_END]
Array of currencies used by the system.
Definition: currency.cpp:74
CURRENCY_RON
@ CURRENCY_RON
Romenian Leu.
Definition: currency.h:46
CF_NOEURO
static const int CF_NOEURO
Currency never switches to the Euro (as far as known).
Definition: currency.h:17
CURRENCY_DEM
@ CURRENCY_DEM
Deutsche Mark.
Definition: currency.h:34
CURRENCY_HUF
@ CURRENCY_HUF
Hungarian Forint.
Definition: currency.h:40
GetMaskOfAllowedCurrencies
uint64 GetMaskOfAllowedCurrencies()
get a mask of the allowed currencies depending on the year
Definition: currency.cpp:122
CURRENCY_ZAR
@ CURRENCY_ZAR
South African Rand.
Definition: currency.h:56
CURRENCY_IDR
@ CURRENCY_IDR
Indonesian Rupiah.
Definition: currency.h:66
CURRENCY_RUR
@ CURRENCY_RUR
Russian Rouble.
Definition: currency.h:47
CurrencySpec::symbol_pos
byte symbol_pos
The currency symbol is represented by two possible values, prefix and suffix Usage of one or the othe...
Definition: currency.h:87
CURRENCY_MYR
@ CURRENCY_MYR
Malaysian Ringgit.
Definition: currency.h:67
CURRENCY_PLN
@ CURRENCY_PLN
Polish Zloty.
Definition: currency.h:45
Year
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
Currencies
Currencies
This enum gives the currencies a unique id which must be maintained for savegame compatibility and in...
Definition: currency.h:25
CURRENCY_BEF
@ CURRENCY_BEF
Belgian Franc.
Definition: currency.h:31
CURRENCY_SIT
@ CURRENCY_SIT
Slovenian Tolar.
Definition: currency.h:48
strings_type.h
CURRENCY_KRW
@ CURRENCY_KRW
South Korean Won.
Definition: currency.h:55
CURRENCY_GEL
@ CURRENCY_GEL
Georgian Lari.
Definition: currency.h:58
CURRENCY_SKK
@ CURRENCY_SKK
Slovak Kornuna.
Definition: currency.h:51
CURRENCY_GBP
@ CURRENCY_GBP
British Pound.
Definition: currency.h:26
CurrencySpec::suffix
std::string suffix
Suffix to apply when formatting money in this currency.
Definition: currency.h:77
CF_ISEURO
static const int CF_ISEURO
Currency is the Euro.
Definition: currency.h:18
ResetCurrencies
void ResetCurrencies(bool preserve_custom=true)
Will fill _currency_specs array with default values from origin_currency_specs Called only from newgr...
Definition: currency.cpp:157
CURRENCY_CHF
@ CURRENCY_CHF
Swiss Franc.
Definition: currency.h:32
CURRENCY_MXN
@ CURRENCY_MXN
Mexican Peso.
Definition: currency.h:61
CURRENCY_USD
@ CURRENCY_USD
US Dollar.
Definition: currency.h:27
BuildCurrencyDropdown
StringID * BuildCurrencyDropdown()
Build a list of currency names StringIDs to use in a dropdown list.
Definition: currency.cpp:169
CURRENCY_NOK
@ CURRENCY_NOK
Norwegian Krone.
Definition: currency.h:44
CURRENCY_YTL
@ CURRENCY_YTL
Turkish Lira.
Definition: currency.h:50
CURRENCY_DKK
@ CURRENCY_DKK
Danish Krona.
Definition: currency.h:35
CURRENCY_FIM
@ CURRENCY_FIM
Finish Markka.
Definition: currency.h:37
CheckSwitchToEuro
void CheckSwitchToEuro()
Verify if the currency chosen by the user is about to be converted to Euro.
Definition: currency.cpp:141
CurrencySpec
Specification of a currency.
Definition: currency.h:72
CURRENCY_ESP
@ CURRENCY_ESP
Spanish Peseta.
Definition: currency.h:36
CURRENCY_LTL
@ CURRENCY_LTL
Lithuanian Litas.
Definition: currency.h:54
CURRENCY_SEK
@ CURRENCY_SEK
Swedish Krona.
Definition: currency.h:49
date_type.h
CURRENCY_HKD
@ CURRENCY_HKD
Hong Kong Dollar.
Definition: currency.h:64
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
CURRENCY_END
@ CURRENCY_END
always the last item
Definition: currency.h:68
CURRENCY_GRD
@ CURRENCY_GRD
Greek Drachma.
Definition: currency.h:39
CURRENCY_BRL
@ CURRENCY_BRL
Brazilian Real.
Definition: currency.h:52
CURRENCY_CZK
@ CURRENCY_CZK
Czech Koruna.
Definition: currency.h:33
CurrencySpec::rate
uint16 rate
The conversion rate compared to the base currency.
Definition: currency.h:73
CURRENCY_CNY
@ CURRENCY_CNY
Chinese Renminbi.
Definition: currency.h:63
CURRENCY_ITL
@ CURRENCY_ITL
Italian Lira.
Definition: currency.h:42
CURRENCY_NLG
@ CURRENCY_NLG
Dutch Gulden.
Definition: currency.h:43
CURRENCY_INR
@ CURRENCY_INR
Indian Rupee.
Definition: currency.h:65
CURRENCY_ISK
@ CURRENCY_ISK
Icelandic Krona.
Definition: currency.h:41
CurrencySpec::to_euro
Year to_euro
Year of switching to the Euro. May also be CF_NOEURO or CF_ISEURO.
Definition: currency.h:75
CurrencySpec::separator
std::string separator
The thousands separator for this currency.
Definition: currency.h:74
CURRENCY_JPY
@ CURRENCY_JPY
Japanese Yen.
Definition: currency.h:29
CURRENCY_EEK
@ CURRENCY_EEK
Estonian Krooni.
Definition: currency.h:53
GetNewgrfCurrencyIdConverted
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id)
Will return the ottd's index correspondence to the ttdpatch's id.
Definition: currency.cpp:113
CURRENCY_IRR
@ CURRENCY_IRR
Iranian Rial.
Definition: currency.h:59
CURRENCY_EUR
@ CURRENCY_EUR
Euro.
Definition: currency.h:28
CURRENCY_NTD
@ CURRENCY_NTD
New Taiwan Dollar.
Definition: currency.h:62
CURRENCY_FRF
@ CURRENCY_FRF
French Franc.
Definition: currency.h:38
CurrencySpec::prefix
std::string prefix
Prefix to apply when formatting money in this currency.
Definition: currency.h:76
CURRENCY_RUB
@ CURRENCY_RUB
New Russian Ruble.
Definition: currency.h:60
CURRENCY_CUSTOM
@ CURRENCY_CUSTOM
Custom currency.
Definition: currency.h:57
CURRENCY_ATS
@ CURRENCY_ATS
Austrian Schilling.
Definition: currency.h:30