OpenTTD Source 20260711-master-g3fb3006dff
currency.cpp File Reference

Support for different currencies. More...

#include "stdafx.h"
#include "core/bitmath_func.hpp"
#include "currency_func.h"
#include "news_func.h"
#include "settings_type.h"
#include "string_type.h"
#include "strings_func.h"
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "table/strings.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

Currency GetNewgrfCurrencyIdConverted (uint8_t grfcurr_id)
 Will return the ottd's index correspondence to the ttdpatch's id.
Currencies GetMaskOfAllowedCurrencies ()
 get a mask of the allowed currencies depending on the year
void ResetCurrencies (bool preserve_custom)
 Will fill _currency_specs array with default values from _origin_currency_specs Called only from newgrf.cpp and settings.cpp.

Variables

static const EnumIndexArray< CurrencySpec, Currency, Currency::End_origin_currency_specs
 The original currency specifications.
EnumIndexArray< CurrencySpec, Currency, Currency::End_currency_specs
 Array of currencies used by the system.
const Currency _ttdpatch_to_ottd_currency []
 This array represent the position of OpenTTD's currencies, compared to TTDPatch's ones.
static const IntervalTimer< TimerGameCalendar_check_switch_to_euro ({TimerGameCalendar::Trigger::Year, TimerGameCalendar::Priority::None}, [](auto) { if(_currency_specs[_settings_game.locale.currency].to_euro !=CF_NOEURO &&_currency_specs[_settings_game.locale.currency].to_euro !=CF_ISEURO &&TimerGameCalendar::year >=_currency_specs[_settings_game.locale.currency].to_euro) { _settings_game.locale.currency=Currency::EUR;AddNewsItem(GetEncodedString(STR_NEWS_EURO_INTRODUCTION), NewsType::Economy, NewsStyle::Normal, {});} })
 Verify if the currency chosen by the user is about to be converted to Euro.

Detailed Description

Support for different currencies.

Definition in file currency.cpp.

Function Documentation

◆ GetMaskOfAllowedCurrencies()

Currencies GetMaskOfAllowedCurrencies ( )

get a mask of the allowed currencies depending on the year

Returns
mask of currencies

Definition at line 128 of file currency.cpp.

References _currency_specs, CF_ISEURO, CF_NOEURO, Custom, End, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), and TimerGameCalendar::year.

Referenced by GameOptionsWindow::BuildDropDownList().

◆ GetNewgrfCurrencyIdConverted()

Currency GetNewgrfCurrencyIdConverted ( uint8_t grfcurr_id)

Will return the ottd's index correspondence to 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

Parameters
grfcurr_idcurrency id coming from newgrf
Returns
The corrected index, or Currency::End when invalid.

Definition at line 118 of file currency.cpp.

References _ttdpatch_to_ottd_currency, and End.

Referenced by GlobalVarChangeInfo().

◆ ResetCurrencies()

void ResetCurrencies ( bool preserve_custom)

Will fill _currency_specs array with default values from _origin_currency_specs Called only from newgrf.cpp and settings.cpp.

Parameters
preserve_customwill not reset custom currency

Definition at line 162 of file currency.cpp.

References _currency_specs, _origin_currency_specs, Custom, and End.

Referenced by LoadFromConfig(), and ResetNewGRFData().

Variable Documentation

◆ _currency_specs

◆ _origin_currency_specs

const EnumIndexArray<CurrencySpec, Currency, Currency::End> _origin_currency_specs
static

The original currency specifications.

Definition at line 30 of file currency.cpp.

Referenced by ResetCurrencies().

◆ _ttdpatch_to_ottd_currency

const Currency _ttdpatch_to_ottd_currency[]
Initial value:
= {
}
@ JPY
Japanese Yen.
@ RUR
Russian Rouble.
@ NLG
Dutch Gulden.
@ CHF
Swiss Franc.
@ USD
US Dollar.
@ DEM
Deutsche Mark.
@ GBP
British Pound.
@ ESP
Spanish Peseta.
@ PLN
Polish Zloty.
@ ITL
Italian Lira.
@ DKK
Danish Krona.
@ ATS
Austrian Schilling.
@ GRD
Greek Drachma.
@ FIM
Finish Markka.
@ EUR
Euro.
@ BEF
Belgian Franc.
@ SEK
Swedish Krona.
@ HUF
Hungarian Forint.
@ FRF
French Franc.

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.

Definition at line 88 of file currency.cpp.

Referenced by GetNewgrfCurrencyIdConverted().