tron@2186: /* $Id$ */ tron@2186: tron@2291: #include "stdafx.h" tron@2291: #include "openttd.h" tron@2291: #include "currency.h" tron@2306: #include "news.h" tron@2291: #include "variables.h" tron@2291: #include "table/strings.h" rubidium@4261: #include "date.h" tron@2291: belugas@4377: // exchange rate prefix symbol_pos belugas@4377: // | separator | postfix | belugas@4377: // | | Euro year | | | name belugas@4377: // | | | | | | | belugas@4377: const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { belugas@4377: { 1, ',', CF_NOEURO, "\xA3", "", 0, STR_CURR_GBP }, // british pounds belugas@4377: { 2, ',', CF_NOEURO, "$", "", 0, STR_CURR_USD }, // us dollars belugas@4377: { 2, ',', CF_ISEURO, "¤", "", 0, STR_CURR_EUR }, // Euro belugas@4377: { 200, ',', CF_NOEURO, "\xA5", "", 0, STR_CURR_YEN }, // yen belugas@4377: { 19, ',', 2002, "", " S.", 1, STR_CURR_ATS }, // austrian schilling belugas@4377: { 57, ',', 2002, "BEF ", "", 0, STR_CURR_BEF }, // belgian franc belugas@4377: { 2, ',', CF_NOEURO, "CHF ", "", 0, STR_CURR_CHF }, // swiss franc belugas@4377: { 50, ',', CF_NOEURO, "", " Kc", 1, STR_CURR_CZK }, // czech koruna // TODO: Should use the "c" with an upside down "^" belugas@4377: { 4, '.', 2002, "DM ", "", 0, STR_CURR_DEM }, // deutsche mark belugas@4377: { 10, '.', CF_NOEURO, "", " kr", 1, STR_CURR_DKK }, // danish krone belugas@4377: { 200, '.', 2002, "Pts ", "", 0, STR_CURR_ESP }, // spanish pesetas belugas@4377: { 8, ',', 2002, "", " mk", 1, STR_CURR_FIM }, // finnish markka belugas@4377: { 10, '.', 2002, "FF ", "", 0, STR_CURR_FRF }, // french francs belugas@4377: { 480, ',', 2002, "", "Dr.", 1, STR_CURR_GRD }, // greek drachma belugas@4377: { 376, ',', 2002, "", " Ft", 1, STR_CURR_HUF }, // hungarian forint belugas@4377: { 130, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_ISK }, // icelandic krona belugas@4377: { 2730, ',', 2002, "", " L.", 1, STR_CURR_ITL }, // italian lira belugas@4377: { 3, ',', 2002, "NLG ", "", 0, STR_CURR_NLG }, // dutch gulden belugas@4377: { 11, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_NOK }, // norwegian krone belugas@4377: { 6, ' ', CF_NOEURO, "", " zl", 1, STR_CURR_PLN }, // polish zloty belugas@4377: { 6, '.', CF_NOEURO, "", " Lei", 1, STR_CURR_ROL }, // romanian Lei belugas@4377: { 5, ' ', CF_NOEURO, "", " p", 1, STR_CURR_RUR }, // russian rouble belugas@4377: { 350, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar belugas@4377: { 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona belugas@4601: { 2, '.', CF_NOEURO, "", " YTL", 1, STR_CURR_YTL }, // turkish lira belugas@4602: { 1, ' ', CF_NOEURO, "", "", 2, STR_CURR_CUSTOM }, // custom currency dominik@759: }; dominik@768: belugas@4377: /* Array of currencies used by the system */ belugas@4377: CurrencySpec _currency_specs[NUM_CURRENCY]; tron@2291: belugas@4377: /* get a mask of the allowed currencies depending on the year */ tron@2291: uint GetMaskOfAllowedCurrencies(void) tron@2291: { tron@2291: uint mask = 0; tron@2291: uint i; tron@2291: belugas@4377: for (i = 0; i < NUM_CURRENCY; i++) { rubidium@4297: Year to_euro = _currency_specs[i].to_euro; tron@2291: rubidium@4293: if (to_euro != CF_NOEURO && to_euro != CF_ISEURO && _cur_year >= to_euro) continue; rubidium@4293: if (to_euro == CF_ISEURO && _cur_year < 2000) continue; tron@2291: mask |= (1 << i); tron@2291: } peter1138@3596: mask |= (1 << CUSTOM_CURRENCY_ID); // always allow custom currency tron@2291: return mask; tron@2291: } tron@2291: belugas@4377: /** belugas@4377: * Verify if the currency chosen by the user is about to be converted to Euro belugas@4377: **/ tron@2306: void CheckSwitchToEuro(void) tron@2306: { tron@2306: if (_currency_specs[_opt.currency].to_euro != CF_NOEURO && tron@2306: _currency_specs[_opt.currency].to_euro != CF_ISEURO && rubidium@4293: _cur_year >= _currency_specs[_opt.currency].to_euro) { tron@2306: _opt.currency = 2; // this is the index of euro above. tron@2306: AddNewsItem(STR_EURO_INTRODUCE, NEWS_FLAGS(NM_NORMAL, 0, NT_ECONOMY, 0), 0, 0); tron@2306: } tron@2306: } belugas@4138: belugas@4377: /** belugas@4377: * Called only from newgrf.c. Will fill _currency_specs array with belugas@4377: * default values from origin_currency_specs belugas@4377: **/ belugas@4377: void ResetCurrencies(void) belugas@4377: { belugas@4377: memcpy(&_currency_specs, &origin_currency_specs, sizeof(origin_currency_specs)); belugas@4377: } belugas@4377: belugas@4377: /** belugas@4377: * Build a list of currency names StringIDs to use in a dropdown list belugas@4377: * @return Pointer to a (static) array of StringIDs belugas@4377: */ belugas@4377: StringID* BuildCurrencyDropdown(void) belugas@4377: { belugas@4377: /* Allow room for all currencies, plus a terminator entry */ belugas@4377: static StringID names[CUSTOM_CURRENCY_ID]; belugas@4377: uint i; belugas@4377: belugas@4377: /* Add each name */ belugas@4377: for (i = 0; i < NUM_CURRENCY; i++) { belugas@4377: names[i] = _currency_specs[i].name; belugas@4377: } belugas@4377: /* Terminate the list */ belugas@4377: names[i] = INVALID_STRING_ID; belugas@4377: belugas@4377: return names; belugas@4377: }