# currency.cpp File Reference

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "currency.h"`
`#include "news.h"`
`#include "settings_type.h"`
`#include "date_func.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_ROL, CURR_RUR, CURR_SIT, CURR_SEK, CURR_YTL }
| 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

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

uint GetMaskOfAllowedCurrencies | ( |  | ) |

get a mask of the allowed currencies depending on the year

Returns:
  mask of currencies

Definition at line 132 of file currency.cpp.

byte GetNewgrfCurrencyIdConverted | ( | byte | grfcurr_id | ) |

Will return the ottd's index correspondance to the ttdpatch's id.

If the id is bigger then the array, it is a grf written for ottd, thus returning the same id. Only called from newgrf.c

Parameters:

  | grfcurr_id | currency id coming from newgrf

Returns:
  the corrected index

Definition at line 123 of file currency.cpp.

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

Referenced by LoadFromConfig(), and ResetNewGRFData().

## Variable Documentation

const CurrencySpec origin_currency_specs[NUM_CURRENCY]`[static]`

Initial value:

     {
      {    1, ',', CF_NOEURO, "£",    "",      0,  STR_CURR_GBP    },
      {    2, ',', CF_NOEURO, "$",    "",      0,  STR_CURR_USD    },
      {    2, ',', CF_ISEURO, "€",    "",      0,  STR_CURR_EUR    },
      {  220, ',', CF_NOEURO, "¥",    "",      0,  STR_CURR_YEN    },
      {   20, ',', 2002,      "",     " S.",   1,  STR_CURR_ATS    },
      {   59, ',', 2002,      "BEF ", "",      0,  STR_CURR_BEF    },
      {    2, ',', CF_NOEURO, "CHF ", "",      0,  STR_CURR_CHF    },
      {   41, ',', CF_NOEURO, "",     " Kč",   1,  STR_CURR_CZK    },
      {    3, '.', 2002,      "DM ",  "",      0,  STR_CURR_DEM    },
      {   11, '.', CF_NOEURO, "",     " kr",   1,  STR_CURR_DKK    },
      {  245, '.', 2002,      "Pts ", "",      0,  STR_CURR_ESP    },
      {    9, ',', 2002,      "",     " mk",   1,  STR_CURR_FIM    },
      {   10, '.', 2002,      "FF ",  "",      0,  STR_CURR_FRF    },
      {  500, ',', 2002,      "",     "Dr.",   1,  STR_CURR_GRD    },
      {  378, ',', 2010,      "",     " Ft",   1,  STR_CURR_HUF    },
      {  130, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_ISK    },
      { 2850, ',', 2002,      "",     " L.",   1,  STR_CURR_ITL    },
      {    3, ',', 2002,      "NLG ", "",      0,  STR_CURR_NLG    },
      {   12, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_NOK    },
      {    6, ' ', CF_NOEURO, "",     " zl",   1,  STR_CURR_PLN    },
      {    5, '.', CF_NOEURO, "",     " Lei",  1,  STR_CURR_ROL    },
      {   50, ' ', CF_NOEURO, "",     " p",    1,  STR_CURR_RUR    },
      {  352, '.', CF_NOEURO, "",     " SIT",  1,  STR_CURR_SIT    },
      {   13, '.', CF_NOEURO, "",     " Kr",   1,  STR_CURR_SEK    },
      {    3, '.', CF_NOEURO, "",     " YTL",  1,  STR_CURR_YTL    },
      {   52, ',', CF_NOEURO, "",     " Sk",   1,  STR_CURR_SKK    },
      {    4, ',', CF_NOEURO, "R$ ",  "",      0,  STR_CURR_BRR    },
      {    1, ' ', CF_NOEURO, "",     "",      2,  STR_CURR_CUSTOM },
    }

Definition at line 18 of file currency.cpp.

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

Referenced by GetNewgrfCurrencyIdConverted().