2005-08-06 14:59:54 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
|
|
|
#include "openttd.h"
|
|
|
|
#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"
|
2005-08-06 14:59:54 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
// exchange rate prefix symbol_pos
|
|
|
|
// | separator | postfix |
|
|
|
|
// | | Euro year | | | name
|
|
|
|
// | | | | | | |
|
2006-11-05 08:24:09 +00:00
|
|
|
static const CurrencySpec origin_currency_specs[NUM_CURRENCY] = {
|
2007-02-23 11:50:43 +00:00
|
|
|
{ 1, ',', CF_NOEURO, "£", "", 0, STR_CURR_GBP }, ///< british pounds
|
|
|
|
{ 2, ',', CF_NOEURO, "$", "", 0, STR_CURR_USD }, ///< us dollars
|
|
|
|
{ 2, ',', CF_ISEURO, "€", "", 0, STR_CURR_EUR }, ///< Euro
|
|
|
|
{ 220, ',', CF_NOEURO, "¥", "", 0, STR_CURR_YEN }, ///< yen
|
|
|
|
{ 20, ',', 2002, "", " S.", 1, STR_CURR_ATS }, ///< austrian schilling
|
|
|
|
{ 59, ',', 2002, "BEF ", "", 0, STR_CURR_BEF }, ///< belgian franc
|
|
|
|
{ 2, ',', CF_NOEURO, "CHF ", "", 0, STR_CURR_CHF }, ///< swiss franc
|
|
|
|
{ 41, ',', CF_NOEURO, "", " Kč", 1, STR_CURR_CZK }, ///< czech koruna
|
|
|
|
{ 3, '.', 2002, "DM ", "", 0, STR_CURR_DEM }, ///< deutsche mark
|
|
|
|
{ 11, '.', CF_NOEURO, "", " kr", 1, STR_CURR_DKK }, ///< danish krone
|
|
|
|
{ 245, '.', 2002, "Pts ", "", 0, STR_CURR_ESP }, ///< spanish pesetas
|
|
|
|
{ 9, ',', 2002, "", " mk", 1, STR_CURR_FIM }, ///< finnish markka
|
|
|
|
{ 10, '.', 2002, "FF ", "", 0, STR_CURR_FRF }, ///< french francs
|
|
|
|
{ 500, ',', 2002, "", "Dr.", 1, STR_CURR_GRD }, ///< greek drachma
|
|
|
|
{ 378, ',', 2010, "", " Ft", 1, STR_CURR_HUF }, ///< hungarian forint
|
|
|
|
{ 130, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_ISK }, ///< icelandic krona
|
|
|
|
{ 2850, ',', 2002, "", " L.", 1, STR_CURR_ITL }, ///< italian lira
|
|
|
|
{ 3, ',', 2002, "NLG ", "", 0, STR_CURR_NLG }, ///< dutch gulden
|
|
|
|
{ 12, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_NOK }, ///< norwegian krone
|
|
|
|
{ 6, ' ', CF_NOEURO, "", " zl", 1, STR_CURR_PLN }, ///< polish zloty
|
|
|
|
{ 5, '.', CF_NOEURO, "", " Lei", 1, STR_CURR_ROL }, ///< romanian Lei
|
|
|
|
{ 50, ' ', CF_NOEURO, "", " p", 1, STR_CURR_RUR }, ///< russian rouble
|
|
|
|
{ 352, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, ///< slovenian tolar
|
|
|
|
{ 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, ///< swedish krona
|
|
|
|
{ 3, '.', CF_NOEURO, "", " YTL", 1, STR_CURR_YTL }, ///< turkish lira
|
|
|
|
{ 52, ',', CF_NOEURO, "", " Sk", 1, STR_CURR_SKK }, ///< slovak koruna
|
|
|
|
{ 4, ',', CF_NOEURO, "R$ ", "", 0, STR_CURR_BRR }, ///< brazil real
|
|
|
|
{ 1, ' ', CF_NOEURO, "", "", 2, STR_CURR_CUSTOM }, ///< custom currency
|
2005-08-06 14:59:54 +00:00
|
|
|
};
|
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
/* Array of currencies used by the system */
|
|
|
|
CurrencySpec _currency_specs[NUM_CURRENCY];
|
2005-08-06 14:59:54 +00:00
|
|
|
|
2006-09-20 00:34:06 +00:00
|
|
|
/**
|
|
|
|
* These enums are only declared in order to make sens
|
|
|
|
* out of the TTDPatch_To_OTTDIndex array that will follow
|
|
|
|
* Every currency used by Ottd is there, just in case TTDPatch will
|
|
|
|
* add those missing in its code
|
|
|
|
**/
|
|
|
|
enum {
|
|
|
|
CURR_GBP,
|
|
|
|
CURR_USD,
|
|
|
|
CURR_EUR,
|
|
|
|
CURR_YEN,
|
|
|
|
CURR_ATS,
|
|
|
|
CURR_BEF,
|
|
|
|
CURR_CHF,
|
|
|
|
CURR_CZK,
|
|
|
|
CURR_DEM,
|
|
|
|
CURR_DKK,
|
|
|
|
CURR_ESP,
|
|
|
|
CURR_FIM,
|
|
|
|
CURR_FRF,
|
|
|
|
CURR_GRD,
|
|
|
|
CURR_HUF,
|
|
|
|
CURR_ISK,
|
|
|
|
CURR_ITL,
|
|
|
|
CURR_NLG,
|
|
|
|
CURR_NOK,
|
|
|
|
CURR_PLN,
|
|
|
|
CURR_ROL,
|
|
|
|
CURR_RUR,
|
|
|
|
CURR_SIT,
|
|
|
|
CURR_SEK,
|
|
|
|
CURR_YTL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
**/
|
|
|
|
const byte TTDPatch_To_OTTDIndex[] =
|
|
|
|
{
|
|
|
|
CURR_GBP,
|
|
|
|
CURR_USD,
|
|
|
|
CURR_FRF,
|
|
|
|
CURR_DEM,
|
|
|
|
CURR_YEN,
|
|
|
|
CURR_ESP,
|
|
|
|
CURR_HUF,
|
|
|
|
CURR_PLN,
|
|
|
|
CURR_ATS,
|
|
|
|
CURR_BEF,
|
|
|
|
CURR_DKK,
|
|
|
|
CURR_FIM,
|
|
|
|
CURR_GRD,
|
|
|
|
CURR_CHF,
|
|
|
|
CURR_NLG,
|
|
|
|
CURR_ITL,
|
|
|
|
CURR_SEK,
|
|
|
|
CURR_RUR,
|
|
|
|
CURR_EUR,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will return the ottd's index correspondance to
|
|
|
|
* the ttdpatch's id. If the id is bigger then the array,
|
|
|
|
* it is a grf written for ottd, thus returning the same id.
|
|
|
|
* Only called from newgrf.c
|
|
|
|
* @param grfcurr_id currency id coming from newgrf
|
|
|
|
* @return the corrected index
|
|
|
|
**/
|
|
|
|
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
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
uint GetMaskOfAllowedCurrencies()
|
2005-08-06 14:59:54 +00:00
|
|
|
{
|
|
|
|
uint mask = 0;
|
|
|
|
uint i;
|
|
|
|
|
2006-08-25 00:41:10 +00:00
|
|
|
for (i = 0; i < NUM_CURRENCY; 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;
|
2005-08-06 14:59:54 +00:00
|
|
|
mask |= (1 << i);
|
|
|
|
}
|
2006-04-20 21:13:08 +00:00
|
|
|
mask |= (1 << CUSTOM_CURRENCY_ID); // 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
|
|
|
|
**/
|
2007-03-07 11:47:46 +00:00
|
|
|
void CheckSwitchToEuro()
|
2005-08-07 12:41:57 +00:00
|
|
|
{
|
|
|
|
if (_currency_specs[_opt.currency].to_euro != CF_NOEURO &&
|
|
|
|
_currency_specs[_opt.currency].to_euro != CF_ISEURO &&
|
2006-08-16 11:39:55 +00:00
|
|
|
_cur_year >= _currency_specs[_opt.currency].to_euro) {
|
2005-08-07 12:41:57 +00:00
|
|
|
_opt.currency = 2; // this is the index of euro above.
|
2008-03-28 08:53:36 +00:00
|
|
|
AddNewsItem(STR_EURO_INTRODUCE, NM_NORMAL, NF_NONE, NT_ECONOMY, DNC_NONE, 0, 0);
|
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.
|
|
|
|
* @param preserve_custom will not reset custom currency (the latest one on the list)
|
|
|
|
* if ever it is flagged to true. In which case, the total size of the memory to move
|
|
|
|
* will be one currency spec less, thus preserving the custom curreny from been
|
|
|
|
* overwritten.
|
2006-08-25 00:41:10 +00:00
|
|
|
**/
|
2007-03-25 23:42:55 +00:00
|
|
|
void ResetCurrencies(bool preserve_custom)
|
2006-08-25 00:41:10 +00:00
|
|
|
{
|
2007-03-25 23:42:55 +00:00
|
|
|
memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs) - (preserve_custom ? sizeof(_custom_currency) : 0));
|
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
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
StringID* BuildCurrencyDropdown()
|
2006-08-25 00:41:10 +00:00
|
|
|
{
|
|
|
|
/* Allow room for all currencies, plus a terminator entry */
|
2007-03-06 18:03:06 +00:00
|
|
|
static StringID names[NUM_CURRENCY + 1];
|
2006-08-25 00:41:10 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
/* Add each name */
|
|
|
|
for (i = 0; i < NUM_CURRENCY; i++) {
|
|
|
|
names[i] = _currency_specs[i].name;
|
|
|
|
}
|
|
|
|
/* Terminate the list */
|
|
|
|
names[i] = INVALID_STRING_ID;
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|