OpenTTD Source: src/currency.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
currency.cpp File Reference

Support for different currencies. More...

`#include "stdafx.h"`
`#include "core/bitmath_func.hpp"`
`#include "currency.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
uint8_t | GetNewgrfCurrencyIdConverted (uint8_t grfcurr_id)
| Will return the ottd's index correspondence to the ttdpatch's id.
uint64_t | 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 std::array< CurrencySpec, CURRENCY_END > | origin_currency_specs
| The original currency specifications.
std::array< CurrencySpec, CURRENCY_END > | _currency_specs
| Array of currencies used by the system.
const uint8_t | TTDPatch_To_OTTDIndex []
| This array represent the position of OpenTTD's currencies, compared to TTDPatch's ones.
static const IntervalTimer< TimerGameCalendar > | _check_switch_to_euro ({TimerGameCalendar::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=2;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()

uint64_t 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, CURRENCY_CUSTOM, CURRENCY_END, SetBit(), and TimerGameCalendar::year.

## ◆ GetNewgrfCurrencyIdConverted()

uint8_t 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_id | currency id coming from newgrf

Returns
  the corrected index

Definition at line 119 of file currency.cpp.

References lengthof, and TTDPatch_To_OTTDIndex.

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_custom | will not reset custom currency

Definition at line 163 of file currency.cpp.

References _currency_specs, CURRENCY_CUSTOM, CURRENCY_END, and origin_currency_specs.

Referenced by LoadFromConfig(), and ResetNewGRFData().

## Variable Documentation

## ◆ _currency_specs

std::array<CurrencySpec, CURRENCY_END> _currency_specs

Array of currencies used by the system.

Definition at line 80 of file currency.cpp.

Referenced by GameOptionsWindow::BuildDropDownList(), GetCurrency(), GetCustomCurrency(), GetMaskOfAllowedCurrencies(), GameOptionsWindow::GetWidgetString(), GlobalVarChangeInfo(), and ResetCurrencies().

## ◆ origin_currency_specs

const std::array<CurrencySpec, CURRENCY_END> origin_currency_specs
| static

The original currency specifications.

Definition at line 30 of file currency.cpp.

Referenced by ResetCurrencies().

## ◆ TTDPatch_To_OTTDIndex

const uint8_t TTDPatch_To_OTTDIndex[]

Initial value:
=
{
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,
}
CURRENCY_GBP
@ CURRENCY_GBP
British Pound.
Definition currency.h:27
CURRENCY_ESP
@ CURRENCY_ESP
Spanish Peseta.
Definition currency.h:37
CURRENCY_FRF
@ CURRENCY_FRF
French Franc.
Definition currency.h:39
CURRENCY_SEK
@ CURRENCY_SEK
Swedish Krona.
Definition currency.h:50
CURRENCY_GRD
@ CURRENCY_GRD
Greek Drachma.
Definition currency.h:40
CURRENCY_JPY
@ CURRENCY_JPY
Japanese Yen.
Definition currency.h:30
CURRENCY_DKK
@ CURRENCY_DKK
Danish Krona.
Definition currency.h:36
CURRENCY_ATS
@ CURRENCY_ATS
Austrian Schilling.
Definition currency.h:31
CURRENCY_USD
@ CURRENCY_USD
US Dollar.
Definition currency.h:28
CURRENCY_EUR
@ CURRENCY_EUR
Euro.
Definition currency.h:29
CURRENCY_FIM
@ CURRENCY_FIM
Finish Markka.
Definition currency.h:38
CURRENCY_DEM
@ CURRENCY_DEM
Deutsche Mark.
Definition currency.h:35
CURRENCY_BEF
@ CURRENCY_BEF
Belgian Franc.
Definition currency.h:32
CURRENCY_ITL
@ CURRENCY_ITL
Italian Lira.
Definition currency.h:43
CURRENCY_PLN
@ CURRENCY_PLN
Polish Zloty.
Definition currency.h:46
CURRENCY_RUR
@ CURRENCY_RUR
Russian Rouble.
Definition currency.h:48
CURRENCY_CHF
@ CURRENCY_CHF
Swiss Franc.
Definition currency.h:33
CURRENCY_NLG
@ CURRENCY_NLG
Dutch Gulden.
Definition currency.h:44
CURRENCY_HUF
@ CURRENCY_HUF
Hungarian Forint.
Definition currency.h:41

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().