OpenTTD Source: src/strings.cpp File Reference

OpenTTD Source 14.0-beta3

Data Structures | Functions | Variables
strings.cpp File Reference
`#include "stdafx.h"`
`#include "currency.h"`
`#include "station_base.h"`
`#include "town.h"`
`#include "waypoint_base.h"`
`#include "depot_base.h"`
`#include "industry.h"`
`#include "newgrf_text.h"`
`#include "fileio_func.h"`
`#include "signs_base.h"`
`#include "fontdetection.h"`
`#include "error.h"`
`#include "error_func.h"`
`#include "strings_func.h"`
`#include "rev.h"`
`#include "core/endian_func.hpp"`
`#include "timer/timer_game_calendar.h"`
`#include "vehicle_base.h"`
`#include "engine_base.h"`
`#include "language.h"`
`#include "townname_func.h"`
`#include "string_func.h"`
`#include "company_base.h"`
`#include "smallmap_gui.h"`
`#include "window_func.h"`
`#include "debug.h"`
`#include "game/game_text.hpp"`
`#include "network/network_content_gui.h"`
`#include "newgrf_engine.h"`
`#include "core/backup_type.hpp"`
`#include "gfx_layout.h"`
`#include <stack>`
`#include <charconv>`
`#include "table/strings.h"`
`#include "table/control_codes.h"`
`#include "3rdparty/fmt/std.h"`
`#include "strings_internal.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | LanguagePack
struct | LanguagePackDeleter
struct | LoadedLanguagePack
struct | UnitConversion
| Helper for unit conversion. More...
struct | Units
| Information about a specific unit system. More...
struct | UnitsLong
| Information about a specific unit system with a long variant. More...
class | LanguagePackGlyphSearcher
| Helper for searching through the language pack. More...

## Functions
void | SetDParam (size_t n, uint64_t v)
| Set a string parameter v at index n in the global string parameter array. More...
uint64_t | GetDParam (size_t n)
| Get the current string parameter at index n from the global string parameter array. More...
void | SetDParamMaxValue (size_t n, uint64_t max_value, uint min_count, FontSize size)
| Set DParam n to some number that is suitable for string size computations. More...
void | SetDParamMaxDigits (size_t n, uint count, FontSize size)
| Set DParam n to some number that is suitable for string size computations. More...
void | CopyInDParam (const std::span< const StringParameterBackup > backup)
| Copy the parameters from the backup into the global string parameter array. More...
void | CopyOutDParam (std::vector< StringParameterBackup > &backup, size_t num)
| Copy num string parameters from the global string parameter array to the backup. More...
bool | HaveDParamChanged (const std::vector< StringParameterBackup > &backup)
| Checks whether the global string parameters have changed compared to the given backup. More...
static void | StationGetSpecialString (StringBuilder &builder, StationFacility x)
static void | GetSpecialTownNameString (StringBuilder &builder, int ind, uint32_t seed)
static void | GetSpecialNameString (StringBuilder &builder, int ind, StringParameters &args)
static void | FormatString (StringBuilder &builder, const char *str_arg, StringParameters &args, uint case_index, bool game_script, bool dry_run)
| Parse most format codes within a string and write the result to a buffer. More...
const char * | GetStringPtr (StringID string)
void | GetStringWithArgs (StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
| Get a parsed string with most special stringcodes replaced by the string parameters. More...
std::string | GetString (StringID string)
| Resolve the given StringID into a std::string with all the associated DParam lookups and formatting. More...
std::string | GetStringWithArgs (StringID string, StringParameters &args)
| Get a parsed string with most special stringcodes replaced by the string parameters. More...
void | SetDParamStr (size_t n, const char *str)
| This function is used to "bind" a C string to a OpenTTD dparam slot. More...
void | SetDParamStr (size_t n, const std::string &str)
| This function is used to "bind" the C string of a std::string to a OpenTTD dparam slot. More...
void | SetDParamStr (size_t n, std::string &&str)
| This function is used to "bind" the std::string to a OpenTTD dparam slot. More...
static void | FormatNumber (StringBuilder &builder, int64_t number, const char *separator, int zerofill=1, int fractional_digits=0)
| Format a number into a string. More...
static void | FormatCommaNumber (StringBuilder &builder, int64_t number, int fractional_digits=0)
static void | FormatNoCommaNumber (StringBuilder &builder, int64_t number)
static void | FormatZerofillNumber (StringBuilder &builder, int64_t number, int count)
static void | FormatHexNumber (StringBuilder &builder, uint64_t number)
static void | FormatBytes (StringBuilder &builder, int64_t number)
| Format a given number as a number of bytes with the SI prefix. More...
static void | FormatYmdString (StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
static void | FormatMonthAndYear (StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
static void | FormatTinyOrISODate (StringBuilder &builder, TimerGameCalendar::Date date, StringID str)
static void | FormatGenericCurrency (StringBuilder &builder, const CurrencySpec *spec, Money number, bool compact)
static int | DeterminePluralForm (int64_t count, int plural_form)
| Determine the "plural" index given a plural form and a number. More...
static const char * | ParseStringChoice (const char *b, uint form, StringBuilder &builder)
static const Units | GetVelocityUnits (VehicleType type)
| Get the correct velocity units depending on the vehicle type and whether we're using real-time units. More...
uint | ConvertSpeedToDisplaySpeed (uint speed, VehicleType type)
| Convert the given (internal) speed to the display speed. More...
uint | ConvertDisplaySpeedToSpeed (uint speed, VehicleType type)
| Convert the given display speed to the (internal) speed. More...
uint | ConvertKmhishSpeedToDisplaySpeed (uint speed, VehicleType type)
| Convert the given km/h-ish speed to the display speed. More...
uint | ConvertDisplaySpeedToKmhishSpeed (uint speed, VehicleType type)
| Convert the given display speed to the km/h-ish speed. More...
static void | GenAndCoName (StringBuilder &builder, uint32_t arg)
static void | GenPresidentName (StringBuilder &builder, uint32_t x)
bool | ReadLanguagePack (const LanguageMetadata *lang)
| Read a particular language. More...
const char * | GetCurrentLocale (const char *param)
| Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG. More...
const LanguageMetadata * | GetLanguage (byte newgrflangid)
| Get the language with the given NewGRF language ID. More...
static bool | GetLanguageFileHeader (const char *file, LanguagePackHeader *hdr)
| Reads the language file header and checks compatibility. More...
static void | FillLanguageList (const std::string &path)
| Search for the languages in the given directory and add them to the _languages list. More...
void | InitializeLanguagePacks ()
| Make a list of the available language packs. More...
const char * | GetCurrentLanguageIsoCode ()
| Get the ISO language code of the currently loaded language. More...
void | CheckForMissingGlyphs (bool base_font, MissingGlyphSearcher *searcher)
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support. More...

## Variables
std::string | _config_language_file
| The file (name) stored in the configuration.
LanguageList | _languages
| The actual list of language meta data.
const LanguageMetadata * | _current_language = nullptr
| The currently loaded language.
TextDirection | _current_text_dir
| Text direction of the currently selected language.
std::unique_ptr< icu::Collator > | _current_collator
| Collator for the language currently in use.
ArrayStringParameters< 20 > | _global_string_params
static LoadedLanguagePack | _langpack
static bool | _scan_for_gender_data = false
| Are we scanning for the gender of the current string? (instead of formatting it)
static const Units | _units_velocity_calendar []
| Unit conversions for velocity. More...
static const Units | _units_velocity_realtime []
| Unit conversions for velocity. More...
static const Units | _units_power []
| Unit conversions for power. More...
static const Units | _units_power_to_weight []
| Unit conversions for power to weight. More...
static const UnitsLong | _units_weight []
| Unit conversions for weight. More...
static const UnitsLong | _units_volume []
| Unit conversions for volume. More...
static const Units | _units_force []
| Unit conversions for force. More...
static const Units | _units_height []
| Unit conversions for height. More...
static const Units | _units_time_days_or_seconds []
| Unit conversions for time in calendar days or wallclock seconds. More...
static const Units | _units_time_months_or_minutes []
| Unit conversions for time in calendar months or wallclock minutes. More...
static const Units | _units_time_years_or_periods []
| Unit conversions for time in calendar years or economic periods. More...
static const Units | _units_time_years_or_minutes []
| Unit conversions for time in calendar years or wallclock minutes. More...
static const char *const | _silly_company_names []
static const char *const | _surname_list []
static const char *const | _silly_surname_list []
static const char | _initial_name_letters []

## Detailed Description

Handling of translated strings.

Definition in file strings.cpp.

## Function Documentation

## ◆ CheckForMissingGlyphs()

void CheckForMissingGlyphs | ( | bool | base_font,
|  | MissingGlyphSearcher * | searcher
| ) |  |

Check whether the currently loaded language pack uses characters that the currently loaded font does not support.

If this is the case an error message will be shown in English. The error message will not be localized because that would mean it might use characters that are not in the font, which is the whole reason this check has been added.

Parameters

  base_font | Whether to look at the base font as well.
  searcher | The methods to use to search for strings to check. If nullptr the loaded language pack searcher is used.

Definition at line 2268 of file strings.cpp.

References MissingGlyphSearcher::FindMissingGlyphs().

Referenced by TextfileWindow::LoadText().

## ◆ ConvertDisplaySpeedToKmhishSpeed()

uint ConvertDisplaySpeedToKmhishSpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given display speed to the km/h-ish speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 904 of file strings.cpp.

References Units::c, UnitConversion::FromDisplay(), and GetVelocityUnits().

## ◆ ConvertDisplaySpeedToSpeed()

uint ConvertDisplaySpeedToSpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given display speed to the (internal) speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 884 of file strings.cpp.

References Units::c, UnitConversion::FromDisplay(), and GetVelocityUnits().

## ◆ ConvertKmhishSpeedToDisplaySpeed()

uint ConvertKmhishSpeedToDisplaySpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given km/h-ish speed to the display speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 894 of file strings.cpp.

References Units::c, GetVelocityUnits(), and UnitConversion::ToDisplay().

## ◆ ConvertSpeedToDisplaySpeed()

uint ConvertSpeedToDisplaySpeed | ( | uint | speed,
|  | VehicleType | type
| ) |  |

Convert the given (internal) speed to the display speed.

Parameters

  speed | the speed to convert

Returns
  the converted speed.

Definition at line 871 of file strings.cpp.

References Units::c, GetVelocityUnits(), and UnitConversion::ToDisplay().

## ◆ CopyInDParam()

void CopyInDParam | ( | const std::span< const StringParameterBackup > | backup | ) |

Copy the parameters from the backup into the global string parameter array.

Parameters

  backup | The backup to copy from.

Definition at line 159 of file strings.cpp.

## ◆ CopyOutDParam()

void CopyOutDParam | ( | std::vector< StringParameterBackup > & | backup,
|  | size_t | num
| ) |  |

Copy num string parameters from the global string parameter array to the backup.

Parameters

  backup | The backup to write to.
  num | Number of string parameters to copy.

Definition at line 176 of file strings.cpp.

Referenced by NewsItem::NewsItem().

## ◆ DeterminePluralForm()

static int DeterminePluralForm | ( | int64_t | count,
|  | int | plural_form
| ) |  |
| static

Determine the "plural" index given a plural form and a number.

Parameters

  count | The number to get the plural index of.
  plural_form | The plural form we want an index for.

Returns
  The plural index for the given form.

Definition at line 575 of file strings.cpp.

## ◆ FillLanguageList()

static void FillLanguageList | ( | const std::string & | path | ) |
| static

Search for the languages in the given directory and add them to the _languages list.

Parameters

  path | the base directory to search in

Definition at line 2078 of file strings.cpp.

References ttd_opendir().

## ◆ FormatBytes()

static void FormatBytes | ( | StringBuilder & | builder,
|  | int64_t | number
| ) |  |
| static

Format a given number as a number of bytes with the SI prefix.

Parameters

  builder | the string builder to write to
  number | the number of bytes to write down

Definition at line 452 of file strings.cpp.

References _settings_game, LocaleSettings::digit_decimal_separator, GameSettings::locale, and StrEmpty().

## ◆ FormatNumber()

static void FormatNumber | ( | StringBuilder & | builder,
|  | int64_t | number,
|  | const char * | separator,
|  | int | zerofill = `1`,
|  | int | fractional_digits = `0`
| ) |  |
| static

Format a number into a string.

Parameters

  builder | the string builder to write to
  number | the number to write down
  last | the last element in the buffer
  separator | the thousands-separator to use
  zerofill | minimum number of digits to print for the integer part. The number will be filled with zeros at the front if necessary.
  fractional_digits | number of fractional digits to display after a decimal separator. The decimal separator is inserted in front of the fractional_digits last digit of number.

Definition at line 390 of file strings.cpp.

References _settings_game, LocaleSettings::digit_decimal_separator, GameSettings::locale, and StrEmpty().

## ◆ FormatString()

static void FormatString | ( | StringBuilder & | builder,
|  | const char * | str_arg,
|  | StringParameters & | args,
|  | uint | case_index,
|  | bool | game_script,
|  | bool | dry_run
| ) |  |
| static

Parse most format codes within a string and write the result to a buffer.

Parameters

  builder | The string builder to write the final string to.
  str_arg | The original string with format codes.
  args | Pointer to extra arguments used by various string codes.
  dry_run | True when the args' type data is not yet initialized.

Definition at line 916 of file strings.cpp.

References CreateTextRefStackBackup(), StringParameters::GetOffset(), RestoreTextRefStackBackup(), StringParameters::SetOffset(), and UsingNewGRFTextStack().

## ◆ GetCurrentLanguageIsoCode()

const char* GetCurrentLanguageIsoCode | ( |  | ) |

Get the ISO language code of the currently loaded language.

Returns
  the ISO code.

Definition at line 2157 of file strings.cpp.

## ◆ GetCurrentLocale()

const char* GetCurrentLocale | ( | const char * | param | ) |

Determine the current charset based on the environment First check some default values, after this one we passed ourselves and if none exist return the value for $LANG.

Parameters

  param | environment variable to check conditionally if default ones are not set. Pass nullptr if you don't want additional checks.

Returns
  return string containing current charset, or nullptr if not-determinable

Definition at line 2015 of file strings.cpp.

## ◆ GetDParam()

uint64_t GetDParam | ( | size_t | n | ) |

Get the current string parameter at index n from the global string parameter array.

Parameters

  n | Index of the string parameter.

Returns
  Value of the requested string parameter.

Definition at line 114 of file strings.cpp.

## ◆ GetLanguage()

const LanguageMetadata* GetLanguage | ( | byte | newgrflangid | ) |

Get the language with the given NewGRF language ID.

Parameters

  newgrflangid | NewGRF languages ID to check.

Returns
  The language's metadata, or nullptr if it is not known.

Definition at line 2041 of file strings.cpp.

References _languages.

## ◆ GetLanguageFileHeader()

static bool GetLanguageFileHeader | ( | const char * | file,
|  | LanguagePackHeader * | hdr
| ) |  |
| static

Reads the language file header and checks compatibility.

Parameters

  file | the file to read
  hdr | the place to write the header information to

Returns
  true if and only if the language file is of a compatible version

Definition at line 2056 of file strings.cpp.

References LanguagePackHeader::IsValid(), and LanguagePackHeader::missing.

## ◆ GetString()

std::string GetString | ( | StringID | string | ) |

Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.

Parameters

  string | The unique identifier of the translatable string.

Returns
  The std::string of the translated string.

Definition at line 327 of file strings.cpp.

Referenced by StringFilter::AddLine(), Textbuf::Assign(), Subsidy::AwardTo(), BuildContentTypeStringList(), VehicleGroupWindow::BuildGroupList(), CargoSpecNameSorter(), NetworkChatWindow::ChatTabCompletionNextItem(), CompanyNewsInformation::CompanyNewsInformation(), DrawString(), DrawStringMultiLine(), BuildVehicleWindow::FilterByText(), GetKeyboardLayout(), BaseSet< GraphicsSet, MAX_GFT, true >::GetListLabel(), GetSaveLoadErrorString(), GetStringBoundingBox(), GetStringHeight(), GetStringLineCount(), IndustryTypeNameSorter(), BuildIndustryWindow::MakeCargoListString(), SignListWindow::OnInit(), SelectGameWindow::OnResize(), ServerNetworkGameSocketHandler::Receive_CLIENT_ERROR(), StoryBookWindow::RefreshSelectedPage(), SaveHighScoreValueNetwork(), Script_CreateDummy(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), ServerNetworkAdminSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), ShowNewGrfVehicleError(), BuildObjectWindow::TagNameFilter(), BuildRailStationWindow::TagNameFilter(), BuildRoadStationWindow::TagNameFilter(), TownActionRoadRebuild(), ScanProgressWindow::UpdateNewGRFScanStatus(), and ViewportSign::UpdatePosition().

## ◆ GetStringWithArgs() [1/2]

void GetStringWithArgs | ( | StringBuilder & | builder,
|  | StringID | string,
|  | StringParameters & | args,
|  | uint | case_index,
|  | bool | game_script
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  builder | The builder of the string.
  string | The ID of the string to parse.
  args | Arguments for the string.
  case_index | The "case index". This will only be set when FormatString wants to print the string in a different case.
  game_script | The string is coming directly from a game script.

Definition at line 261 of file strings.cpp.

References GetStringIndex(), and GetStringTab().

Referenced by GetTownName().

## ◆ GetStringWithArgs() [2/2]

std::string GetStringWithArgs | ( | StringID | string,
|  | StringParameters & | args
| ) |  |

Get a parsed string with most special stringcodes replaced by the string parameters.

Parameters

  string | The ID of the string to parse.
  args | Arguments for the string.

Returns
  The parsed string.

Definition at line 339 of file strings.cpp.

## ◆ GetVelocityUnits()

static const Units GetVelocityUnits | ( | VehicleType | type | ) |
| static

Get the correct velocity units depending on the vehicle type and whether we're using real-time units.

Parameters

  type | VehicleType to convert velocity for.

Returns
  The Units for the proper vehicle and time mode.

Definition at line 854 of file strings.cpp.

References _settings_game, _units_velocity_calendar, _units_velocity_realtime, lengthof, GameSettings::locale, LocaleSettings::units_velocity, LocaleSettings::units_velocity_nautical, TimerGameEconomy::UsingWallclockUnits(), VEH_AIRCRAFT, and VEH_SHIP.

Referenced by ConvertDisplaySpeedToKmhishSpeed(), ConvertDisplaySpeedToSpeed(), ConvertKmhishSpeedToDisplaySpeed(), and ConvertSpeedToDisplaySpeed().

## ◆ HaveDParamChanged()

bool HaveDParamChanged | ( | const std::vector< StringParameterBackup > & | backup | ) |

Checks whether the global string parameters have changed compared to the given backup.

Parameters

  backup | The backup to check against.

Returns
  True when the parameters have changed, otherwise false.

Definition at line 194 of file strings.cpp.

## ◆ InitializeLanguagePacks()

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

Put the data in _languages list.

< Matching the language in the configuration file or the current locale

< Using pt_PT for pt_BR locale when pt_BR is not available

< Fallback when no locale-matching language has been found

Definition at line 2110 of file strings.cpp.

## ◆ ReadLanguagePack()

bool ReadLanguagePack | ( | const LanguageMetadata * | lang | ) |

Read a particular language.

Parameters

  lang | The metadata about the language.

Returns
  Whether the loading went okay or not.

Definition at line 1907 of file strings.cpp.

References LanguageMetadata::file, ReadFileToMem(), and TEXT_TAB_END.

## ◆ SetDParam()

void SetDParam | ( | size_t | n,
|  | uint64_t | v
| ) |  |

Set a string parameter v at index n in the global string parameter array.

Parameters

  n | Index of the string parameter.
  v | Value of the string parameter.

Definition at line 104 of file strings.cpp.

Referenced by AdvertiseIndustryOpening(), AgeVehicle(), AircraftHandleDestTooFar(), Subsidy::AwardTo(), VehicleGroupWindow::BuildGroupList(), BuildReplacementVehicle(), NetworkChatWindow::ChatTabCompletionNextItem(), CheckCompanyHasMoney(), ClientNetworkGameSocketHandler::CheckConnection(), CheckEngines(), CheckforTownRating(), CheckIndustries(), CheckTrainCollision(), CheckTrainsLengths(), CmdCompanyCtrl(), CmdIncreaseLoan(), CompanyCheckBankrupt(), CompanyNewsInformation::CompanyNewsInformation(), CrashAirplane(), StationViewWindow::DrawAcceptedCargo(), TimetableWindow::DrawArrivalDeparturePanel(), StationViewWindow::DrawCargoRatings(), DrawPrice(), TownAuthorityWindow::DrawRatings(), BuildVehicleWindow::FilterByText(), FloodVehicle(), GenerateDefaultSaveName(), BuildBridgeWindow::GetBridgeSelectString(), RefitWindow::GetCapacityString(), IndustryDirectoryWindow::GetIndustryString(), BaseSet< GraphicsSet, MAX_GFT, true >::GetListLabel(), GetSaveLoadErrorString(), BaseGraphWindow::GetYLabelWidth(), GRFLoadConfig(), Vehicle::HandlePathfindingResult(), CommandHelperBase::InternalExecuteProcessResult(), BuildIndustryWindow::MakeCargoListString(), MakeScreenshotWithConfirm(), NetworkHandlePauseChange(), NewVehicleAvailable(), SelectCompanyManagerFaceWindow::OnInit(), GameSettingsWindow::OnPaint(), SelectGameWindow::OnResize(), StoryBookWindow::RefreshSelectedPage(), RoadVehArrivesAt(), SaveHighScoreValueNetwork(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), SetDParamMaxDigits(), SetDParamsForOwnedBy(), SelectCompanyManagerFaceWindow::SetFaceStringParameters(), NIHelper::SetObjectAtStringParameters(), NIHelper::SetSimpleStringParameters(), SettingsValueAbsolute(), SetupSubsidyDecodeParam(), IntSettingDesc::SetValueDParams(), ShipArrivesAt(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), ToolbarScenDatePanel(), TownActionRoadRebuild(), TrainEnterStation(), UpdateFillingPercent(), SettingEntry::UpdateFilterState(), Waypoint::UpdateVirtCoord(), Sign::UpdateVirtCoord(), and Town::UpdateVirtCoord().

## ◆ SetDParamMaxDigits()

void SetDParamMaxDigits | ( | size_t | n,
|  | uint | count,
|  | FontSize | size
| ) |  |

Set DParam n to some number that is suitable for string size computations.

Parameters

  n | Index of the string parameter.
  count | Number of digits which shall be displayable.
  size | Font of the number

Definition at line 143 of file strings.cpp.

References GetBroadestDigit(), and SetDParam().

Referenced by SetDParamMaxValue().

## ◆ SetDParamMaxValue()

void SetDParamMaxValue | ( | size_t | n,
|  | uint64_t | max_value,
|  | uint | min_count,
|  | FontSize | size
| ) |  |

Set DParam n to some number that is suitable for string size computations.

Parameters

  n | Index of the string parameter.
  max_value | The biggest value which shall be displayed. For the result only the number of digits of max_value matter.
  min_count | Minimum number of digits independent of max.
  size | Font of the number

Definition at line 127 of file strings.cpp.

References SetDParamMaxDigits().

Referenced by TimetableWindow::DrawTimetablePanel().

## ◆ SetDParamStr() [1/3]

void SetDParamStr | ( | size_t | n,
|  | const char * | str
| ) |  |

This function is used to "bind" a C string to a OpenTTD dparam slot.

Parameters

  n | slot of the string
  str | string to bind

Definition at line 352 of file strings.cpp.

Referenced by Subsidy::AwardTo(), CmdCompanyCtrl(), CmdCustomNewsItem(), CompanyCheckBankrupt(), GoalListWindow::DrawListColumn(), StoryBookWindow::GetHeadHeight(), BaseSet< GraphicsSet, MAX_GFT, true >::GetListLabel(), StoryBookWindow::GetPageElementHeight(), GetSavegameFormat(), GetSaveLoadErrorString(), GraphicsSetLoadConfig(), GRFLoadConfig(), BuildIndustryWindow::MakeCargoListString(), IConsoleWindow::OnPaint(), GoalListWindow::OnPaint(), SaveFileError(), ShowNewGrfVehicleError(), TownActionRoadRebuild(), and WarnCorruptSprite().

## ◆ SetDParamStr() [2/3]

void SetDParamStr | ( | size_t | n,
|  | const std::string & | str
| ) |  |

This function is used to "bind" the C string of a std::string to a OpenTTD dparam slot.

The caller has to ensure that the std::string reference remains valid while the string is shown.

Parameters

  n | slot of the string
  str | string to bind

Definition at line 363 of file strings.cpp.

## ◆ SetDParamStr() [3/3]

void SetDParamStr | ( | size_t | n,
|  | std::string && | str
| ) |  |

This function is used to "bind" the std::string to a OpenTTD dparam slot.

Contrary to the other `SetDParamStr` functions, this moves the string into the parameter slot.

Parameters

  n | slot of the string
  str | string to bind

Definition at line 375 of file strings.cpp.

## Variable Documentation

## ◆ _initial_name_letters

const char _initial_name_letters[]
| static

Initial value:
= {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
}

Definition at line 1797 of file strings.cpp.

## ◆ _silly_company_names

const char* const _silly_company_names[]
| static

Initial value:
= {
"Bloggs Brothers",
"Tiny Transport Ltd.",
"Express Travel",
"Comfy-Coach & Co.",
"Crush & Bump Ltd.",
"Broken & Late Ltd.",
"Sam Speedy & Son",
"Supersonic Travel",
"Mike's Motors",
"Lightning International",
"Pannik & Loozit Ltd.",
"Inter-City Transport",
"Getout & Pushit Ltd."
}

Definition at line 1734 of file strings.cpp.

## ◆ _silly_surname_list

const char* const _silly_surname_list[]
| static

Initial value:
= {
"Grumpy",
"Dozy",
"Speedy",
"Nosey",
"Dribble",
"Mushroom",
"Cabbage",
"Sniffle",
"Fishy",
"Swindle",
"Sneaky",
"Nutkins"
}

Definition at line 1782 of file strings.cpp.

## ◆ _units_force

const Units _units_force[]
| static

Initial value:
= {
{ { 0.224809 }, STR_UNITS_FORCE_IMPERIAL, 0 },
{ { 0.101972 }, STR_UNITS_FORCE_METRIC, 0 },
{ { 0.001 }, STR_UNITS_FORCE_SI, 0 },
}

Unit conversions for force.

Definition at line 812 of file strings.cpp.

## ◆ _units_height

const Units _units_height[]
| static

Initial value:
= {
{ { 3.0 }, STR_UNITS_HEIGHT_IMPERIAL, 0 },
{ { 1.0 }, STR_UNITS_HEIGHT_METRIC, 0 },
{ { 1.0 }, STR_UNITS_HEIGHT_SI, 0 },
}

Unit conversions for height.

Definition at line 819 of file strings.cpp.

## ◆ _units_power

const Units _units_power[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL, 0 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC, 0 },
{ { 0.745699 }, STR_UNITS_POWER_SI, 0 },
}

Unit conversions for power.

Definition at line 778 of file strings.cpp.

## ◆ _units_power_to_weight

const Units _units_power_to_weight[]
| static

Initial value:
= {
{ { 0.907185 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_IMPERIAL, 1 },
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_METRIC, 1 },
{ { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_SI, 1 },
{ { 0.919768 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_IMPERIAL, 1 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_METRIC, 1 },
{ { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_SI, 1 },
{ { 0.676487 }, STR_UNITS_POWER_SI_TO_WEIGHT_IMPERIAL, 1 },
{ { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_METRIC, 1 },
{ { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_SI, 1 },
}

Unit conversions for power to weight.

Definition at line 785 of file strings.cpp.

## ◆ _units_time_days_or_seconds

const Units _units_time_days_or_seconds[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_DAYS, 0 },
{ { 2 }, STR_UNITS_SECONDS, 0 },
}

Unit conversions for time in calendar days or wallclock seconds.

Definition at line 826 of file strings.cpp.

## ◆ _units_time_months_or_minutes

const Units _units_time_months_or_minutes[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_MONTHS, 0 },
{ { 1 }, STR_UNITS_MINUTES, 0 },
}

Unit conversions for time in calendar months or wallclock minutes.

Definition at line 832 of file strings.cpp.

## ◆ _units_time_years_or_minutes

const Units _units_time_years_or_minutes[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_YEARS, 0 },
{ { 12 }, STR_UNITS_MINUTES, 0 },
}

Unit conversions for time in calendar years or wallclock minutes.

Definition at line 844 of file strings.cpp.

## ◆ _units_time_years_or_periods

const Units _units_time_years_or_periods[]
| static

Initial value:
= {
{ { 1 }, STR_UNITS_YEARS, 0 },
{ { 1 }, STR_UNITS_PERIODS, 0 },
}

Unit conversions for time in calendar years or economic periods.

Definition at line 838 of file strings.cpp.

## ◆ _units_velocity_calendar

const Units _units_velocity_calendar[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS_DAY, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
}

Unit conversions for velocity.

Definition at line 760 of file strings.cpp.

Referenced by GetVelocityUnits().

## ◆ _units_velocity_realtime

const Units _units_velocity_realtime[]
| static

Initial value:
= {
{ { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
{ { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
{ { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
{ { 0.289352 }, STR_UNITS_VELOCITY_GAMEUNITS_SEC, 1 },
{ { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
}

Unit conversions for velocity.

Definition at line 769 of file strings.cpp.

Referenced by GetVelocityUnits().

## ◆ _units_volume

const UnitsLong _units_volume[]
| static

Initial value:
= {
{ { 264.172 }, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL, 0 },
{ { 1000.0 }, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 0 },
{ { 1.0 }, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, 0 },
}

Unit conversions for volume.

Definition at line 805 of file strings.cpp.

## ◆ _units_weight

const UnitsLong _units_weight[]
| static

Initial value:
= {
{ { 1.102311 }, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL, 0 },
{ { 1.0 }, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 0 },
{ { 1000.0 }, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, 0 },
}

Unit conversions for weight.

Definition at line 798 of file strings.cpp.