2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file currency.cpp Support for different currencies. */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2005-08-06 14:59:54 +00:00
|
|
|
#include "stdafx.h"
|
2013-03-09 16:24:43 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
|
|
|
|
2005-08-06 14:59:54 +00:00
|
|
|
#include "currency.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2010-05-20 15:36:44 +00:00
|
|
|
#include "string_type.h"
|
2005-08-06 14:59:54 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2010-05-20 15:36:44 +00:00
|
|
|
/* exchange rate prefix symbol_pos
|
|
|
|
* | separator | postfix |
|
|
|
|
* | | Euro year | | | name
|
|
|
|
* | | | | | | | */
|
2011-05-02 17:42:12 +00:00
|
|
|
/** The original currency specifications. */
|
2013-03-09 16:16:17 +00:00
|
|
|
static const CurrencySpec origin_currency_specs[CURRENCY_END] = {
|
2011-11-12 10:21:00 +00:00
|
|
|
{ 1, "", CF_NOEURO, "\xC2\xA3", "", 0, STR_GAME_OPTIONS_CURRENCY_GBP }, ///< british pound
|
|
|
|
{ 2, "", CF_NOEURO, "$", "", 0, STR_GAME_OPTIONS_CURRENCY_USD }, ///< american dollar
|
|
|
|
{ 2, "", CF_ISEURO, "\xE2\x82\xAC", "", 0, STR_GAME_OPTIONS_CURRENCY_EUR }, ///< euro
|
|
|
|
{ 220, "", CF_NOEURO, "\xC2\xA5", "", 0, STR_GAME_OPTIONS_CURRENCY_JPY }, ///< japanese yen
|
|
|
|
{ 27, "", 2002, "", NBSP "S.", 1, STR_GAME_OPTIONS_CURRENCY_ATS }, ///< austrian schilling
|
|
|
|
{ 81, "", 2002, "BEF" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_BEF }, ///< belgian franc
|
|
|
|
{ 2, "", CF_NOEURO, "CHF" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_CHF }, ///< swiss franc
|
|
|
|
{ 41, "", CF_NOEURO, "", NBSP "K\xC4\x8D", 1, STR_GAME_OPTIONS_CURRENCY_CZK }, ///< czech koruna
|
|
|
|
{ 4, "", 2002, "DM" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_DEM }, ///< deutsche mark
|
|
|
|
{ 11, "", CF_NOEURO, "", NBSP "kr", 1, STR_GAME_OPTIONS_CURRENCY_DKK }, ///< danish krone
|
|
|
|
{ 333, "", 2002, "Pts" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_ESP }, ///< spanish peseta
|
|
|
|
{ 12, "", 2002, "", NBSP "mk", 1, STR_GAME_OPTIONS_CURRENCY_FIM }, ///< finnish markka
|
|
|
|
{ 13, "", 2002, "FF" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_FRF }, ///< french franc
|
|
|
|
{ 681, "", 2002, "", "Dr.", 1, STR_GAME_OPTIONS_CURRENCY_GRD }, ///< greek drachma
|
|
|
|
{ 378, "", CF_NOEURO, "", NBSP "Ft", 1, STR_GAME_OPTIONS_CURRENCY_HUF }, ///< hungarian forint
|
|
|
|
{ 130, "", CF_NOEURO, "", NBSP "Kr", 1, STR_GAME_OPTIONS_CURRENCY_ISK }, ///< icelandic krona
|
|
|
|
{ 3873, "", 2002, "", NBSP "L.", 1, STR_GAME_OPTIONS_CURRENCY_ITL }, ///< italian lira
|
|
|
|
{ 4, "", 2002, "NLG" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_NLG }, ///< dutch gulden
|
|
|
|
{ 12, "", CF_NOEURO, "", NBSP "Kr", 1, STR_GAME_OPTIONS_CURRENCY_NOK }, ///< norwegian krone
|
|
|
|
{ 6, "", CF_NOEURO, "", NBSP "z\xC5\x82", 1, STR_GAME_OPTIONS_CURRENCY_PLN }, ///< polish zloty
|
|
|
|
{ 5, "", CF_NOEURO, "", NBSP "Lei", 1, STR_GAME_OPTIONS_CURRENCY_RON }, ///< romanian leu
|
|
|
|
{ 50, "", CF_NOEURO, "", NBSP "p", 1, STR_GAME_OPTIONS_CURRENCY_RUR }, ///< russian rouble
|
|
|
|
{ 479, "", 2007, "", NBSP "SIT", 1, STR_GAME_OPTIONS_CURRENCY_SIT }, ///< slovenian tolar
|
|
|
|
{ 13, "", CF_NOEURO, "", NBSP "Kr", 1, STR_GAME_OPTIONS_CURRENCY_SEK }, ///< swedish krona
|
|
|
|
{ 3, "", CF_NOEURO, "", NBSP "TL", 1, STR_GAME_OPTIONS_CURRENCY_TRY }, ///< turkish lira
|
|
|
|
{ 60, "", 2009, "", NBSP "Sk", 1, STR_GAME_OPTIONS_CURRENCY_SKK }, ///< slovak koruna
|
|
|
|
{ 4, "", CF_NOEURO, "R$" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_BRL }, ///< brazil real
|
|
|
|
{ 31, "", 2011, "", NBSP "EEK", 1, STR_GAME_OPTIONS_CURRENCY_EEK }, ///< estonian krooni
|
2014-10-10 23:07:59 +00:00
|
|
|
{ 4, "", 2015, "", NBSP "Lt", 1, STR_GAME_OPTIONS_CURRENCY_LTL }, ///< lithuanian litas
|
2012-04-17 21:39:09 +00:00
|
|
|
{ 1850, "", CF_NOEURO, "\xE2\x82\xA9", "", 0, STR_GAME_OPTIONS_CURRENCY_KRW }, ///< south korean won
|
|
|
|
{ 13, "", CF_NOEURO, "R" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_ZAR }, ///< south african rand
|
2013-03-09 16:16:17 +00:00
|
|
|
{ 1, "", CF_NOEURO, "", "", 2, STR_GAME_OPTIONS_CURRENCY_CUSTOM }, ///< custom currency (add further languages below)
|
2013-03-09 16:31:56 +00:00
|
|
|
{ 3, "", CF_NOEURO, "", NBSP "GEL", 1, STR_GAME_OPTIONS_CURRENCY_GEL }, ///< Georgian Lari
|
|
|
|
{ 4901, "", CF_NOEURO, "", NBSP "Rls", 1, STR_GAME_OPTIONS_CURRENCY_IRR }, ///< Iranian Rial
|
2018-07-29 13:43:27 +00:00
|
|
|
{ 80, "", CF_NOEURO, "", NBSP "rub", 1, STR_GAME_OPTIONS_CURRENCY_RUB }, ///< New Russian Ruble
|
2019-01-11 03:27:37 +00:00
|
|
|
{ 24, "", CF_NOEURO, "$", "", 0, STR_GAME_OPTIONS_CURRENCY_MXN }, ///< Mexican peso
|
2019-05-16 06:16:45 +00:00
|
|
|
{ 40, "", CF_NOEURO, "NTD" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_NTD }, ///< new taiwan dollar
|
|
|
|
{ 8, "", CF_NOEURO, "\xC2\xA5", "", 0, STR_GAME_OPTIONS_CURRENCY_CNY }, ///< chinese renminbi
|
|
|
|
{ 10, "", CF_NOEURO, "HKD" NBSP, "", 0, STR_GAME_OPTIONS_CURRENCY_HKD }, ///< hong kong dollar
|
2020-05-11 13:31:03 +00:00
|
|
|
{ 90, "", CF_NOEURO, "\xE2\x82\xB9", "", 0, STR_GAME_OPTIONS_CURRENCY_INR }, ///< Indian Rupee
|
2005-08-06 14:59:54 +00:00
|
|
|
};
|
|
|
|
|
2011-05-02 17:42:12 +00:00
|
|
|
/** Array of currencies used by the system */
|
2013-03-09 16:16:17 +00:00
|
|
|
CurrencySpec _currency_specs[CURRENCY_END];
|
2006-09-20 00:34:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This array represent the position of OpenTTD's currencies,
|
|
|
|
* compared to TTDPatch's ones.
|
|
|
|
* When a grf sends currencies, they are based on the order defined by TTDPatch.
|
|
|
|
* So, we must reindex them to our own order.
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2006-09-20 00:34:06 +00:00
|
|
|
const byte TTDPatch_To_OTTDIndex[] =
|
|
|
|
{
|
2013-03-09 16:16:17 +00:00
|
|
|
CURRENCY_GBP,
|
|
|
|
CURRENCY_USD,
|
|
|
|
CURRENCY_FRF,
|
|
|
|
CURRENCY_DEM,
|
|
|
|
CURRENCY_JPY,
|
|
|
|
CURRENCY_ESP,
|
|
|
|
CURRENCY_HUF,
|
|
|
|
CURRENCY_PLN,
|
|
|
|
CURRENCY_ATS,
|
|
|
|
CURRENCY_BEF,
|
|
|
|
CURRENCY_DKK,
|
|
|
|
CURRENCY_FIM,
|
|
|
|
CURRENCY_GRD,
|
|
|
|
CURRENCY_CHF,
|
|
|
|
CURRENCY_NLG,
|
|
|
|
CURRENCY_ITL,
|
|
|
|
CURRENCY_SEK,
|
|
|
|
CURRENCY_RUR,
|
|
|
|
CURRENCY_EUR,
|
2006-09-20 00:34:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-08 22:46:42 +00:00
|
|
|
* Will return the ottd's index correspondence to
|
2008-08-20 01:38:12 +00:00
|
|
|
* the ttdpatch's id. If the id is bigger than the array,
|
|
|
|
* it is a grf written for ottd, thus returning the same id.
|
|
|
|
* Only called from newgrf.cpp
|
2006-09-20 00:34:06 +00:00
|
|
|
* @param grfcurr_id currency id coming from newgrf
|
|
|
|
* @return the corrected index
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2006-09-20 00:34:06 +00:00
|
|
|
byte GetNewgrfCurrencyIdConverted(byte grfcurr_id)
|
|
|
|
{
|
2006-09-20 01:08:50 +00:00
|
|
|
return (grfcurr_id >= lengthof(TTDPatch_To_OTTDIndex)) ? grfcurr_id : TTDPatch_To_OTTDIndex[grfcurr_id];
|
2006-09-20 00:34:06 +00:00
|
|
|
}
|
|
|
|
|
2007-02-23 11:50:43 +00:00
|
|
|
/**
|
|
|
|
* get a mask of the allowed currencies depending on the year
|
|
|
|
* @return mask of currencies
|
|
|
|
*/
|
2013-03-09 16:24:43 +00:00
|
|
|
uint64 GetMaskOfAllowedCurrencies()
|
2005-08-06 14:59:54 +00:00
|
|
|
{
|
2013-03-09 16:24:43 +00:00
|
|
|
uint64 mask = 0LL;
|
2005-08-06 14:59:54 +00:00
|
|
|
uint i;
|
|
|
|
|
2013-03-09 16:16:17 +00:00
|
|
|
for (i = 0; i < CURRENCY_END; i++) {
|
2006-08-17 20:22:35 +00:00
|
|
|
Year to_euro = _currency_specs[i].to_euro;
|
2005-08-06 14:59:54 +00:00
|
|
|
|
2006-08-16 11:39:55 +00:00
|
|
|
if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue;
|
|
|
|
if (to_euro == CF_ISEURO && _cur_year < 2000) continue;
|
2013-03-09 16:24:43 +00:00
|
|
|
SetBit(mask, i);
|
2005-08-06 14:59:54 +00:00
|
|
|
}
|
2013-03-09 16:24:43 +00:00
|
|
|
SetBit(mask, CURRENCY_CUSTOM); // always allow custom currency
|
2005-08-06 14:59:54 +00:00
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
/**
|
|
|
|
* Verify if the currency chosen by the user is about to be converted to Euro
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void CheckSwitchToEuro()
|
2005-08-07 12:41:57 +00:00
|
|
|
{
|
2008-06-05 11:26:38 +00:00
|
|
|
if (_currency_specs[_settings_game.locale.currency].to_euro != CF_NOEURO &&
|
|
|
|
_currency_specs[_settings_game.locale.currency].to_euro != CF_ISEURO &&
|
|
|
|
_cur_year >= _currency_specs[_settings_game.locale.currency].to_euro) {
|
|
|
|
_settings_game.locale.currency = 2; // this is the index of euro above.
|
2012-05-26 14:16:03 +00:00
|
|
|
AddNewsItem(STR_NEWS_EURO_INTRODUCTION, NT_ECONOMY, NF_NORMAL);
|
2005-08-07 12:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-14 17:54:04 +00:00
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
/**
|
2007-03-25 23:42:55 +00:00
|
|
|
* Will fill _currency_specs array with
|
2006-08-25 00:41:10 +00:00
|
|
|
* default values from origin_currency_specs
|
2007-03-25 23:42:55 +00:00
|
|
|
* Called only from newgrf.cpp and settings.cpp.
|
2014-01-15 21:52:22 +00:00
|
|
|
* @param preserve_custom will not reset custom currency
|
2010-08-01 19:44:49 +00:00
|
|
|
*/
|
2007-03-25 23:42:55 +00:00
|
|
|
void ResetCurrencies(bool preserve_custom)
|
2006-08-25 00:41:10 +00:00
|
|
|
{
|
2014-01-15 21:52:22 +00:00
|
|
|
for (uint i = 0; i < CURRENCY_END; i++) {
|
|
|
|
if (preserve_custom && i == CURRENCY_CUSTOM) continue;
|
|
|
|
_currency_specs[i] = origin_currency_specs[i];
|
|
|
|
}
|
2006-08-25 00:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build a list of currency names StringIDs to use in a dropdown list
|
|
|
|
* @return Pointer to a (static) array of StringIDs
|
|
|
|
*/
|
2009-01-10 00:31:47 +00:00
|
|
|
StringID *BuildCurrencyDropdown()
|
2006-08-25 00:41:10 +00:00
|
|
|
{
|
|
|
|
/* Allow room for all currencies, plus a terminator entry */
|
2013-03-09 16:16:17 +00:00
|
|
|
static StringID names[CURRENCY_END + 1];
|
2006-08-25 00:41:10 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
/* Add each name */
|
2013-03-09 16:16:17 +00:00
|
|
|
for (i = 0; i < CURRENCY_END; i++) {
|
2006-08-25 00:41:10 +00:00
|
|
|
names[i] = _currency_specs[i].name;
|
|
|
|
}
|
|
|
|
/* Terminate the list */
|
|
|
|
names[i] = INVALID_STRING_ID;
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|