# 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 | { CURR_GBP, CURR_USD, CURR_EUR, CURR_YEN, 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 }
| These enums are only declared in order to make sens 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 correspondance 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]
CurrencySpec | _currency_specs [NUM_CURRENCY]
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 190 of file currency.cpp.

References INVALID_STRING_ID.

Referenced by GameOptionsWindow::OnClick().

uint GetMaskOfAllowedCurrencies | ( |  | ) |

get a mask of the allowed currencies depending on the year

Returns:
  mask of currencies

Definition at line 143 of file currency.cpp.

References _cur_year.

Referenced by GameOptionsWindow::OnClick().

byte GetNewgrfCurrencyIdConverted | ( | byte | grfcurr_id | ) |

Will return the ottd's index correspondance 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 134 of file currency.cpp.

References lengthof, and TTDPatch_To_OTTDIndex.

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

Definition at line 181 of file currency.cpp.

Referenced by LoadFromConfig(), and ResetNewGRFData().

## Variable Documentation

const byte TTDPatch_To_OTTDIndex[]

Initial value:

    {
      CURR_GBP,
      CURR_USD,
      CURR_FRF,
      CURR_DEM,
      CURR_YEN,
      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 103 of file currency.cpp.

Referenced by GetNewgrfCurrencyIdConverted().