Enumerations | Functions | Variables

# currency.cpp File Reference

Support for different currencies. More...

`#include "stdafx.h"`
`#include "currency.h"`
`#include "news_func.h"`
`#include "settings_type.h"`
`#include "date_func.h"`
`#include "string_type.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Enumerations
enum | Currencies { CURR_GBP, CURR_USD, CURR_EUR, CURR_JPY, 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_RON, CURR_RUR, CURR_SIT, CURR_SEK, CURR_YTL, CURR_SKK, CURR_BRL, CURR_EEK, CURR_LTL }
| These enums are only declared in order to make sense 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.
## Functions
byte | GetNewgrfCurrencyIdConverted (byte grfcurr_id)
| Will return the ottd's index correspondence to the ttdpatch's id.
uint | GetMaskOfAllowedCurrencies ()
| get a mask of the allowed currencies depending on the year
void | CheckSwitchToEuro ()
| Verify if the currency chosen by the user is about to be converted to Euro.
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.
StringID * | BuildCurrencyDropdown ()
| Build a list of currency names StringIDs to use in a dropdown list.
## Variables
static const CurrencySpec | origin_currency_specs [NUM_CURRENCY]
| The original currency specifications.
CurrencySpec | _currency_specs [NUM_CURRENCY]
| Array of currencies used by the system.
const byte | TTDPatch_To_OTTDIndex []
| This array represent the position of OpenTTD's currencies, compared to TTDPatch's ones.

## Detailed Description

Support for different currencies.

Definition in file currency.cpp.

## Function Documentation

StringID* BuildCurrencyDropdown | ( |  | ) |

Build a list of currency names StringIDs to use in a dropdown list.

Returns:
  Pointer to a (static) array of StringIDs

Definition at line 195 of file currency.cpp.

References INVALID_STRING_ID, and NUM_CURRENCY.

Referenced by GameOptionsWindow::BuildDropDownList().

uint GetMaskOfAllowedCurrencies | ( |  | ) |

get a mask of the allowed currencies depending on the year

Returns:
  mask of currencies

Definition at line 148 of file currency.cpp.

References _cur_year, CF_ISEURO, CF_NOEURO, CUSTOM_CURRENCY_ID, NUM_CURRENCY, and CurrencySpec::to_euro.

Referenced by GameOptionsWindow::BuildDropDownList().

byte GetNewgrfCurrencyIdConverted | ( | byte | 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 139 of file currency.cpp.

References lengthof, and TTDPatch_To_OTTDIndex.

Referenced by GlobalVarChangeInfo().

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 (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 currency from been overwritten.

Definition at line 186 of file currency.cpp.

Referenced by LoadFromConfig(), and ResetNewGRFData().

## Variable Documentation

const CurrencySpec origin_currency_specs[NUM_CURRENCY]`[static]`

The original currency specifications.

Definition at line 26 of file currency.cpp.

const byte TTDPatch_To_OTTDIndex[]

Initial value:

    {
      CURR_GBP,
      CURR_USD,
      CURR_FRF,
      CURR_DEM,
      CURR_JPY,
      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,
    }

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 108 of file currency.cpp.

Referenced by GetNewgrfCurrencyIdConverted().