# strings_func.h File Reference

Functions related to OTTD's strings. More...

`#include "strings_type.h"`

Go to the source code of this file.

## Data Structures
struct | StringIDCompare
| Key comparison function for std::map. More...
## Functions
char * | InlineString (char *buf, StringID string)
char * | GetString (char *buffr, StringID string, const char *last)
char * | GetStringWithArgs (char *buffr, uint string, int64 *argv, const char *last)
| The highest 8 bits of string contain the "case index".
const char * | GetStringPtr (StringID string)
void | InjectDParam (uint amount)
| Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.
static void | SetDParamX (uint64 *s, uint n, uint64 v)
| Set a string parameter v at index n in a given array s.
static void | SetDParam (uint n, uint64 v)
| Set a string parameter v at index n in the global string parameter array.
void | SetDParamStr (uint n, const char *str)
| This function is used to "bind" a C string to a OpenTTD dparam slot.
static uint64 | GetDParamX (const uint64 *s, uint n)
| Get the current string parameter at index n from parameter array s.
static uint64 | GetDParam (uint n)
| Get the current string parameter at index n from the global string parameter array.
static void | CopyInDParam (int offs, const uint64 *src, int num)
| Copy num string parameters from array src into the global string parameter array.
static void | CopyOutDParam (uint64 *dst, int offs, int num)
| Copy num string parameters from the global string parameter array to the dst array.
bool | ReadLanguagePack (int index)
void | InitializeLanguagePacks ()
| Make a list of the available language packs.
const char * | GetCurrentLanguageIsoCode ()
| Get the ISO language code of the currently loaded language.
int CDECL | StringIDSorter (const StringID *a, const StringID *b)
void | CheckForMissingGlyphsInLoadedLanguagePack ()
| Check whether the currently loaded language pack uses characters that the currently loaded font does not support.
## Variables
DynamicLanguages | _dynlang
| Language information of the program.

## Detailed Description

Functions related to OTTD's strings.

Definition in file strings_func.h.

## Function Documentation

void CheckForMissingGlyphsInLoadedLanguagePack | ( |  | ) |

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.

Definition at line 1503 of file strings.cpp.

References FS_NORMAL, GetGlyph(), INVALID_STRING_ID, LoadStringWidthTable(), SetDParamStr(), ShowErrorMessage(), TD_LTR, and DynamicLanguages::text_dir.

static void CopyInDParam | ( | int | offs,
|  | const uint64 * | src,
|  | int | num |
| ) |  |  | `[inline, static]`

Copy num string parameters from array src into the global string parameter array.

Parameters:

  | offs | Index in the global array to copy the first string parameter to.
  | src | Source array of string parameters.
  | num | Number of string parameters to copy.

Definition at line 80 of file strings_func.h.

References _decode_parameters.

Referenced by DrawNewsString(), NewsWindow::DrawWidget(), ErrmsgWindow::DrawWidget(), QueryWindow::SetStringParameters(), ErrmsgWindow::SetStringParameters(), NewsWindow::UpdateWidgetSize(), and ErrmsgWindow::UpdateWidgetSize().

static void CopyOutDParam | ( | uint64 * | dst,
|  | int | offs,
|  | int | num |
| ) |  |  | `[inline, static]`

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

Parameters:

  | dst | Destination array of string parameters.
  | offs | Index in the global array to copy the first string parameter from.
  | num | Number of string parameters to copy.

Definition at line 92 of file strings_func.h.

References _decode_parameters.

Referenced by AddNewsItem().

const char* GetCurrentLanguageIsoCode | ( |  | ) |

Get the ISO language code of the currently loaded language.

Returns:
  the ISO code.

Definition at line 1488 of file strings.cpp.

static uint64 GetDParam | ( | uint | n | ) | `[inline, static]`

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 66 of file strings_func.h.

References _decode_parameters, and lengthof.

Referenced by ShowErrorMessage().

static uint64 GetDParamX | ( | const uint64 * | s,
|  | uint | n |
| ) |  |  | `[inline, static]`

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

Parameters:

  | s | Array of string parameters.
  | n | Index of the string parameter.

Returns:
  Value of the requested string parameter.

Definition at line 56 of file strings_func.h.

Referenced by ErrmsgWindow::DrawWidget(), and ErrmsgWindow::OnInitialPosition().

char* GetStringWithArgs | ( | char * | buffr,
|  | uint | string,
|  | int64 * | argv,
|  | const char * | last |
| ) |  |  |

The highest 8 bits of string contain the "case index".

These 8 bits will only be set when FormatString wants to print the string in a different case. No one else except FormatString should set those bits, therefore string CANNOT be StringID, but uint32.

Parameters:

  | buffr |
  | string |
  | argv |
  | last |

Returns:
  a formatted string of char

Definition at line 104 of file strings.cpp.

References error(), GB(), GetGRFStringID(), GetInt32(), GetStringWithArgs(), and HasBit().

Referenced by GetStringWithArgs(), and GetTownName().

void InitializeLanguagePacks | ( |  | ) |

Make a list of the available language packs.

put the data in _dynlang struct.

< Matching the language in the configuartion 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 1426 of file strings.cpp.

References DynamicLanguages::curr_file, DynamicLanguages::ent, Language::file, FOR_ALL_SEARCHPATHS, GetCurrentLocale(), GetLanguageFileHeader(), GetLanguageList(), LANG_DIR, lengthof, MAX_LANG, Language::name, DynamicLanguages::num, and usererror().

void InjectDParam | ( | uint | amount | ) |

Shift the string parameters in the global string parameter array by amount positions, making room at the beginning.

Parameters:

  | amount | Number of positions to shift.

Definition at line 181 of file strings.cpp.

References _decode_parameters, and lengthof.

Referenced by Subsidy::AwardTo().

static void SetDParam | ( | uint | n,
|  | uint64 | v |
| ) |  |  | `[inline, static]`

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 40 of file strings_func.h.

References _decode_parameters, and lengthof.

Referenced by AircraftEntersTerminal(), Subsidy::AwardTo(), ChangeIndustryProduction(), CheckAllowRemoveRoad(), CheckIfAuthorityAllowsNewStation(), CheckOrders(), CheckTrainCollision(), CheckTrainsLengths(), CmdBuildAirport(), CmdBuildBridge(), CmdBuildIndustry(), CmdCompanyCtrl(), CmdDecreaseLoan(), CmdFoundTown(), CmdIncreaseLoan(), Disaster_CoalMine_Init(), DisasterTick_Aircraft(), DisasterTick_Big_Ufo(), DisasterTick_Zeppeliner(), DoCommandP(), DrawAircraftDetails(), StationViewWindow::DrawCargoRatings(), DrawEngineList(), SelectCompanyManagerFaceWindow::DrawFaceStringLabel(), DrawOrderString(), DrawPrice(), TownAuthorityWindow::DrawRatings(), DrawRoadVehDetails(), SettingEntry::DrawSetting(), DrawShipDetails(), SmallMapWindow::DrawTowns(), DrawTrainDetails(), DrawVehiclePurchaseInfo(), DrawVehicleRefitWindow(), StationViewWindow::DrawWaitingCargo(), VehicleViewWindow::DrawWidget(), VehicleDetailsWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), CompanyStationsWindow::DrawWidget(), SmallMapWindow::DrawWidget(), OrdersWindow::DrawWidget(), TooltipsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyWindow::DrawWidget(), CompanyFinancesWindow::DrawWidget(), ReplaceVehicleWindow::DrawWidget(), AISettingsWindow::DrawWidget(), AIListWindow::DrawWidget(), DrawYearColumn(), GenerateDefaultSaveName(), IndustryDirectoryWindow::GetIndustryString(), AIVehicle::GetName(), AITown::GetName(), AISign::GetName(), AIIndustry::GetName(), AIGroup::GetName(), AIEventEnginePreview::GetName(), AIEngine::GetName(), AICompany::GetName(), AIBaseStation::GetName(), AICompany::GetPresidentName(), GetSaveLoadErrorString(), IndustryDirectoryWindow::IndustryNameSorter(), IndustryProductionCallback(), MaybeNewIndustry(), VehicleDetailsWindow::OnClick(), StationViewWindow::OnClick(), OrdersWindow::OnClick(), CompanyWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), AISettingsWindow::OnClick(), SmallMapWindow::OnInit(), SelectCompanyManagerFaceWindow::OnInit(), EndGameWindow::OnPaint(), ReplaceVehicleWindow::OnPaint(), BuildIndustryWindow::OnPlaceObject(), ReportNewsProductionChangeIndustry(), SaveHighScoreValue(), SetArrivalDepartParams(), SetDParamStr(), VehicleViewWindow::SetStringParameters(), VehicleDetailsWindow::SetStringParameters(), VehicleListWindow::SetStringParameters(), RefitWindow::SetStringParameters(), TownDirectoryWindow::SetStringParameters(), TownAuthorityWindow::SetStringParameters(), StationViewWindow::SetStringParameters(), CompanyStationsWindow::SetStringParameters(), SmallMapWindow::SetStringParameters(), OrdersWindow::SetStringParameters(), NewsWindow::SetStringParameters(), NewGRFWindow::SetStringParameters(), QueryWindow::SetStringParameters(), QueryStringWindow::SetStringParameters(), IndustryDirectoryWindow::SetStringParameters(), BuildIndustryWindow::SetStringParameters(), SetDateWindow::SetStringParameters(), CompanyWindow::SetStringParameters(), SelectCompanyLiveryWindow::SetStringParameters(), CompanyFinancesWindow::SetStringParameters(), ReplaceVehicleWindow::SetStringParameters(), AIConfigWindow::SetStringParameters(), SetTimetableParams(), ShowAdditionalText(), ShowNewGRFError(), ShowNewGrfVehicleError(), ShowRejectOrAcceptNews(), CompanyStationsWindow::StationNameSorter(), TownDirectoryWindow::TownNameSorter(), TrainDetailsCapacityTab(), TrainDetailsCargoTab(), TrainDetailsInfoTab(), Station::UpdateVirtCoord(), VehicleDetailsWindow::UpdateWidgetSize(), TownDirectoryWindow::UpdateWidgetSize(), TownAuthorityWindow::UpdateWidgetSize(), SelectStationWindow< T >::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), SetDateWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), CompanyFinancesWindow::UpdateWidgetSize(), ReplaceVehicleWindow::UpdateWidgetSize(), and VehicleNameSorter().

void SetDParamStr | ( | uint | 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 172 of file strings.cpp.

References SetDParam().

Referenced by Subsidy::AwardTo(), CheckForMissingGlyphsInLoadedLanguagePack(), CmdCompanyCtrl(), CmdFoundTown(), DrawCargoListText(), NewsWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AIListWindow::DrawWidget(), IndustryDirectoryWindow::GetIndustryString(), GetSaveLoadErrorString(), IndustryProductionCallback(), MakeScreenshot(), NewGRFWindow::OnClick(), SaveFileError(), NewGRFWindow::SetStringParameters(), ShowNewGRFError(), ShowNewGrfVehicleError(), ShowRefitOptionsList(), StartScenario(), NewGRFWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), and WarnCorruptSprite().

static void SetDParamX | ( | uint64 * | s,
|  | uint | n,
|  | uint64 | v |
| ) |  |  | `[inline, static]`

Set a string parameter v at index n in a given array s.

Parameters:

  | s | Array of string parameters.
  | n | Index of the string parameter.
  | v | Value of the string parameter.

Definition at line 30 of file strings_func.h.