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/>.
8 /** @file currency.h Functions to handle different currencies. */
13 #include "timer/timer_game_calendar.h"
14 #include "settings_type.h"
15 #include "strings_type.h"
17 static constexpr TimerGameCalendar::Year CF_NOEURO
= 0; ///< Currency never switches to the Euro (as far as known).
18 static constexpr TimerGameCalendar::Year CF_ISEURO
= 1; ///< Currency _is_ the Euro.
19 static constexpr TimerGameCalendar::Year MIN_EURO_YEAR
= 2000; ///< The earliest year custom currencies may switch to the Euro.
22 * This enum gives the currencies a unique id which must be maintained for
23 * savegame compatibility and in order to refer to them quickly, especially
24 * for referencing the custom one.
27 CURRENCY_GBP
, ///< British Pound
28 CURRENCY_USD
, ///< US Dollar
29 CURRENCY_EUR
, ///< Euro
30 CURRENCY_JPY
, ///< Japanese Yen
31 CURRENCY_ATS
, ///< Austrian Schilling
32 CURRENCY_BEF
, ///< Belgian Franc
33 CURRENCY_CHF
, ///< Swiss Franc
34 CURRENCY_CZK
, ///< Czech Koruna
35 CURRENCY_DEM
, ///< Deutsche Mark
36 CURRENCY_DKK
, ///< Danish Krona
37 CURRENCY_ESP
, ///< Spanish Peseta
38 CURRENCY_FIM
, ///< Finish Markka
39 CURRENCY_FRF
, ///< French Franc
40 CURRENCY_GRD
, ///< Greek Drachma
41 CURRENCY_HUF
, ///< Hungarian Forint
42 CURRENCY_ISK
, ///< Icelandic Krona
43 CURRENCY_ITL
, ///< Italian Lira
44 CURRENCY_NLG
, ///< Dutch Gulden
45 CURRENCY_NOK
, ///< Norwegian Krone
46 CURRENCY_PLN
, ///< Polish Zloty
47 CURRENCY_RON
, ///< Romenian Leu
48 CURRENCY_RUR
, ///< Russian Rouble
49 CURRENCY_SIT
, ///< Slovenian Tolar
50 CURRENCY_SEK
, ///< Swedish Krona
51 CURRENCY_YTL
, ///< Turkish Lira
52 CURRENCY_SKK
, ///< Slovak Kornuna
53 CURRENCY_BRL
, ///< Brazilian Real
54 CURRENCY_EEK
, ///< Estonian Krooni
55 CURRENCY_LTL
, ///< Lithuanian Litas
56 CURRENCY_KRW
, ///< South Korean Won
57 CURRENCY_ZAR
, ///< South African Rand
58 CURRENCY_CUSTOM
, ///< Custom currency
59 CURRENCY_GEL
, ///< Georgian Lari
60 CURRENCY_IRR
, ///< Iranian Rial
61 CURRENCY_RUB
, ///< New Russian Ruble
62 CURRENCY_MXN
, ///< Mexican Peso
63 CURRENCY_NTD
, ///< New Taiwan Dollar
64 CURRENCY_CNY
, ///< Chinese Renminbi
65 CURRENCY_HKD
, ///< Hong Kong Dollar
66 CURRENCY_INR
, ///< Indian Rupee
67 CURRENCY_IDR
, ///< Indonesian Rupiah
68 CURRENCY_MYR
, ///< Malaysian Ringgit
69 CURRENCY_LVL
, ///< Latvian Lats
70 CURRENCY_PTE
, ///< Portuguese Escudo
71 CURRENCY_END
, ///< always the last item
74 /** Specification of a currency. */
76 uint16_t rate
; ///< The conversion rate compared to the base currency.
77 std::string separator
; ///< The thousands separator for this currency.
78 TimerGameCalendar::Year to_euro
; ///< Year of switching to the Euro. May also be #CF_NOEURO or #CF_ISEURO.
79 std::string prefix
; ///< Prefix to apply when formatting money in this currency.
80 std::string suffix
; ///< Suffix to apply when formatting money in this currency.
81 std::string code
; ///< 3 letter untranslated code to identify the currency.
83 * The currency symbol is represented by two possible values, prefix and suffix
84 * Usage of one or the other is determined by #symbol_pos.
87 * 2 = both : Special case only for custom currency.
88 * It is not a spec from Newgrf,
89 * rather a way to let users do what they want with custom currency
94 CurrencySpec() = default;
96 CurrencySpec(uint16_t rate
, const char *separator
, TimerGameCalendar::Year to_euro
, const char *prefix
, const char *suffix
, const char *code
, uint8_t symbol_pos
, StringID name
) :
97 rate(rate
), separator(separator
), to_euro(to_euro
), prefix(prefix
), suffix(suffix
), code(code
), symbol_pos(symbol_pos
), name(name
)
102 extern std::array
<CurrencySpec
, CURRENCY_END
> _currency_specs
;
105 * Get the custom currency.
106 * @return Reference to custom currency.
108 inline CurrencySpec
&GetCustomCurrency()
110 return _currency_specs
[CURRENCY_CUSTOM
];
114 * Get the currently selected currency.
115 * @return Read-only reference to the current currency.
117 inline const CurrencySpec
&GetCurrency()
119 return _currency_specs
[GetGameSettings().locale
.currency
];
122 uint64_t GetMaskOfAllowedCurrencies();
123 void ResetCurrencies(bool preserve_custom
= true);
124 uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id
);
126 #endif /* CURRENCY_H */