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: // | | | | | | | tron@5023: static const CurrencySpec origin_currency_specs[NUM_CURRENCY] = { peter1138@5108: { 1, ',', CF_NOEURO, "£", "", 0, STR_CURR_GBP }, // british pounds belugas@4377: { 2, ',', CF_NOEURO, "$", "", 0, STR_CURR_USD }, // us dollars peter1138@5108: { 2, ',', CF_ISEURO, "€", "", 0, STR_CURR_EUR }, // Euro peter1138@5108: { 220, ',', CF_NOEURO, "¥", "", 0, STR_CURR_YEN }, // yen Darkvater@5092: { 20, ',', 2002, "", " S.", 1, STR_CURR_ATS }, // austrian schilling Darkvater@5092: { 59, ',', 2002, "BEF ", "", 0, STR_CURR_BEF }, // belgian franc belugas@4377: { 2, ',', CF_NOEURO, "CHF ", "", 0, STR_CURR_CHF }, // swiss franc peter1138@5108: { 41, ',', CF_NOEURO, "", " Kč", 1, STR_CURR_CZK }, // czech koruna Darkvater@5092: { 3, '.', 2002, "DM ", "", 0, STR_CURR_DEM }, // deutsche mark Darkvater@5092: { 11, '.', CF_NOEURO, "", " kr", 1, STR_CURR_DKK }, // danish krone Darkvater@5092: { 245, '.', 2002, "Pts ", "", 0, STR_CURR_ESP }, // spanish pesetas Darkvater@5092: { 9, ',', 2002, "", " mk", 1, STR_CURR_FIM }, // finnish markka belugas@4377: { 10, '.', 2002, "FF ", "", 0, STR_CURR_FRF }, // french francs Darkvater@5092: { 500, ',', 2002, "", "Dr.", 1, STR_CURR_GRD }, // greek drachma Darkvater@5092: { 378, ',', 2010, "", " Ft", 1, STR_CURR_HUF }, // hungarian forint belugas@4377: { 130, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_ISK }, // icelandic krona Darkvater@5092: { 2850, ',', 2002, "", " L.", 1, STR_CURR_ITL }, // italian lira belugas@4377: { 3, ',', 2002, "NLG ", "", 0, STR_CURR_NLG }, // dutch gulden Darkvater@5092: { 12, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_NOK }, // norwegian krone belugas@4377: { 6, ' ', CF_NOEURO, "", " zl", 1, STR_CURR_PLN }, // polish zloty Darkvater@5092: { 5, '.', CF_NOEURO, "", " Lei", 1, STR_CURR_ROL }, // romanian Lei Darkvater@5092: { 50, ' ', CF_NOEURO, "", " p", 1, STR_CURR_RUR }, // russian rouble Darkvater@5092: { 352, '.', CF_NOEURO, "", " SIT", 1, STR_CURR_SIT }, // slovenian tolar belugas@4377: { 13, '.', CF_NOEURO, "", " Kr", 1, STR_CURR_SEK }, // swedish krona Darkvater@5092: { 3, '.', CF_NOEURO, "", " YTL", 1, STR_CURR_YTL }, // turkish lira Darkvater@5092: { 52, ',', CF_NOEURO, "", " Sk", 1, STR_CURR_SKK }, // slovak koruna Darkvater@5092: { 4, ',', CF_NOEURO, "R$ ", "", 0, STR_CURR_BRR }, // brazil real 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@4625: /** belugas@4625: * These enums are only declared in order to make sens belugas@4625: * out of the TTDPatch_To_OTTDIndex array that will follow belugas@4625: * Every currency used by Ottd is there, just in case TTDPatch will belugas@4625: * add those missing in its code belugas@4625: **/ belugas@4625: enum { belugas@4625: CURR_GBP, belugas@4625: CURR_USD, belugas@4625: CURR_EUR, belugas@4625: CURR_YEN, belugas@4625: CURR_ATS, belugas@4625: CURR_BEF, belugas@4625: CURR_CHF, belugas@4625: CURR_CZK, belugas@4625: CURR_DEM, belugas@4625: CURR_DKK, belugas@4625: CURR_ESP, belugas@4625: CURR_FIM, belugas@4625: CURR_FRF, belugas@4625: CURR_GRD, belugas@4625: CURR_HUF, belugas@4625: CURR_ISK, belugas@4625: CURR_ITL, belugas@4625: CURR_NLG, belugas@4625: CURR_NOK, belugas@4625: CURR_PLN, belugas@4625: CURR_ROL, belugas@4625: CURR_RUR, belugas@4625: CURR_SIT, belugas@4625: CURR_SEK, belugas@4625: CURR_YTL, belugas@4625: }; belugas@4625: belugas@4625: /** belugas@4625: * This array represent the position of OpenTTD's currencies, belugas@4625: * compared to TTDPatch's ones. belugas@4625: * When a grf sends currencies, they are based on the order defined by TTDPatch. belugas@4625: * So, we must reindex them to our own order. belugas@4625: **/ belugas@4625: const byte TTDPatch_To_OTTDIndex[] = belugas@4625: { belugas@4625: CURR_GBP, belugas@4625: CURR_USD, belugas@4625: CURR_FRF, belugas@4625: CURR_DEM, belugas@4625: CURR_YEN, belugas@4625: CURR_ESP, belugas@4625: CURR_HUF, belugas@4625: CURR_PLN, belugas@4625: CURR_ATS, belugas@4625: CURR_BEF, belugas@4625: CURR_DKK, belugas@4625: CURR_FIM, belugas@4625: CURR_GRD, belugas@4625: CURR_CHF, belugas@4625: CURR_NLG, belugas@4625: CURR_ITL, belugas@4625: CURR_SEK, belugas@4625: CURR_RUR, belugas@4625: CURR_EUR, belugas@4625: }; belugas@4625: belugas@4625: /** belugas@4625: * Will return the ottd's index correspondance to belugas@4625: * the ttdpatch's id. If the id is bigger then the array, belugas@4625: * it is a grf written for ottd, thus returning the same id. belugas@4625: * Only called from newgrf.c belugas@4625: * @param grfcurr_id currency id coming from newgrf belugas@4625: * @return the corrected index belugas@4625: **/ belugas@4625: byte GetNewgrfCurrencyIdConverted(byte grfcurr_id) belugas@4625: { glx@4626: return (grfcurr_id >= lengthof(TTDPatch_To_OTTDIndex)) ? grfcurr_id : TTDPatch_To_OTTDIndex[grfcurr_id]; belugas@4625: } belugas@4625: 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: }