# newgrf_text.h File Reference

Header of Action 04 "universal holder" structure and functions. More...

`#include "string_type.h"`
`#include "strings_type.h"`
`#include "core/smallvec_type.hpp"`

Go to the source code of this file.

## Data Structures
struct | LanguageMap
| Mapping of language data between a NewGRF and OpenTTD. More...
struct | LanguageMap::Mapping
| Mapping between NewGRF and OpenTTD IDs. More...
## Functions
StringID | AddGRFString (uint32 grfid, uint16 stringid, byte langid, bool new_scheme, const char *text_to_add, StringID def_string)
| Add the new read string into our structure.
StringID | GetGRFStringID (uint32 grfid, uint16 stringid)
| Returns the index for this stringid associated with its grfID.
const char * | GetGRFStringFromGRFText (const struct GRFText *text)
const char * | GetGRFStringPtr (uint16 stringid)
| Get a C-string from a stringid set by a newgrf.
void | CleanUpStrings ()
| House cleaning.
void | SetCurrentGrfLangID (byte language_id)
| Equivalence Setter function between game and newgrf langID.
char * | TranslateTTDPatchCodes (uint32 grfid, uint8 language_id, const char *str, int *olen=NULL)
| Translate TTDPatch string codes into something OpenTTD can handle (better).
struct GRFText * | DuplicateGRFText (struct GRFText *orig)
| Create a copy of this GRFText list.
void | AddGRFTextToList (struct GRFText **list, struct GRFText *text_to_add)
| Add a GRFText to a GRFText list.
void | AddGRFTextToList (struct GRFText **list, byte langid, uint32 grfid, const char *text_to_add)
| Add a string to a GRFText list.
void | AddGRFTextToList (struct GRFText **list, const char *text_to_add)
| Add a GRFText to a GRFText list.
void | CleanUpGRFText (struct GRFText *grftext)
| Delete all items of a linked GRFText list.
bool | CheckGrfLangID (byte lang_id, byte grf_version)
void | PrepareTextRefStackUsage (byte numEntries)
| Prepare the TTDP compatible string code parsing.
void | StopTextRefStackUsage ()
| Stop using the TTDP compatible string code parsing.
void | SwitchToNormalRefStack ()
void | SwitchToErrorRefStack ()
void | RewindTextRefStack ()
bool | UsingNewGRFTextStack ()
| Check whether the NewGRF text stack is in use.
struct TextRefStack * | CreateTextRefStackBackup ()
| Create a backup of the current NewGRF text stack.
void | RestoreTextRefStackBackup (struct TextRefStack *backup)
| Restore a copy of the text stack to the used stack.
uint | RemapNewGRFStringControlCode (uint scc, char *buf_start, char **buff, const char **str, int64 *argv)
| FormatString for NewGRF specific "magic" string control codes.
StringID | TTDPStringIDToOTTDStringIDMapping (StringID string)
| Perform a mapping from TTDPatch's string IDs to OpenTTD's string IDs, but only for the ones we are aware off; the rest like likely unused and will show a warning.
## Variables
static const WChar | NFO_UTF8_IDENTIFIER = 0x00DE
| This character, the thorn ('þ'), indicates a unicode string to NFO.

## Detailed Description

Header of Action 04 "universal holder" structure and functions.

Definition in file newgrf_text.h.

## Function Documentation

void AddGRFTextToList | ( | struct GRFText ** | list,
|  | const char * | text_to_add |
| ) |  |  |

Add a GRFText to a GRFText list.

The text should not contain any text-codes. The text will be added as a 'default language'-text.

Parameters:

  | list | The list where the text should be added to.
  | text_to_add | The text to add to the list.

Definition at line 658 of file newgrf_text.cpp.

References AddGRFTextToList(), and GRFText::New().

void AddGRFTextToList | ( | struct GRFText ** | list,
|  | byte | langid,
|  | uint32 | grfid,
|  | const char * | text_to_add |
| ) |  |  |

Add a string to a GRFText list.

Parameters:

  | list | The list where the text should be added to.
  | langid | The language of the new text.
  | grfid | The grfid where this string is defined.
  | text_to_add | The text to add to the list.

Note:
  All text-codes will be translated.

Definition at line 642 of file newgrf_text.cpp.

References AddGRFTextToList(), GRFText::New(), and TranslateTTDPatchCodes().

void AddGRFTextToList | ( | GRFText ** | list,
|  | GRFText * | text_to_add |
| ) |  |  |

Add a GRFText to a GRFText list.

Parameters:

  | list | The list where the text should be added to.
  | text_to_add | The GRFText to add to the list.

Definition at line 616 of file newgrf_text.cpp.

References GRFText::langid, and GRFText::next.

Referenced by AddGRFString(), AddGRFTextToList(), ChangeGRFDescription(), ChangeGRFName(), ChangeGRFParamDescription(), ChangeGRFParamName(), ChangeGRFParamValueNames(), DEF_UDP_RECEIVE_COMMAND(), and FindUnknownGRFName().

void CleanUpGRFText | ( | GRFText * | grftext | ) |

Delete all items of a linked GRFText list.

Parameters:

  | grftext | the head of the list to delete

Definition at line 832 of file newgrf_text.cpp.

References GRFText::next.

Referenced by CleanUpStrings(), GRFParameterInfo::~GRFParameterInfo(), and GRFTextWrapper::~GRFTextWrapper().

void CleanUpStrings | ( |  | ) |

House cleaning.

Remove all strings and reset the text counter.

Definition at line 845 of file newgrf_text.cpp.

References CleanUpGRFText().

Referenced by ResetNewGRFData().

struct TextRefStack* CreateTextRefStackBackup | ( |  | ) | `[read]`

Create a backup of the current NewGRF text stack.

Returns:
  A copy of the current text stack.

Definition at line 942 of file newgrf_text.cpp.

Referenced by FormatString().

struct GRFText* DuplicateGRFText | ( | GRFText * | orig | ) | `[read]`

Create a copy of this GRFText list.

Parameters:

  | orig | The GRFText list to copy.

Returns:
  A duplicate of the given GRFText.

Definition at line 668 of file newgrf_text.cpp.

References GRFText::Copy(), and GRFText::next.

Referenced by GRFParameterInfo::GRFParameterInfo().

void PrepareTextRefStackUsage | ( | byte | numEntries | ) |

Prepare the TTDP compatible string code parsing.

Parameters:

  | numEntries | number of entries to copy from the registers

Definition at line 961 of file newgrf_text.cpp.

References GB(), and TemporaryStorageArray< TYPE, SIZE >::Get().

Referenced by CheckIfCallBackAllowsCreation(), IndustryViewWindow::DrawInfo(), BuildObjectWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), GetCargoSuffix(), PerformIndustryTileSlopeCheck(), and ShowAdditionalText().

uint RemapNewGRFStringControlCode | ( | uint | scc,
|  | char * | buf_start,
|  | char ** | buff,
|  | const char ** | str,
|  | int64 * | argv |
| ) |  |  |

FormatString for NewGRF specific "magic" string control codes.

Parameters:

  | scc | the string control code that has been read
  | buff | the buffer we're writing to
  | str | the string that we need to write
  | argv | the OpenTTD stack of values

Returns:
  the string control code to "execute" now

Definition at line 1005 of file newgrf_text.cpp.

References DAYS_TILL_ORIGINAL_BASE_YEAR, max(), TextRefStack::RotateTop4Words(), SCC_NEWGRF_DISCARD_WORD, SCC_NEWGRF_PRINT_DATE, SCC_NEWGRF_PRINT_DWORD, SCC_NEWGRF_PRINT_DWORD_CURRENCY, SCC_NEWGRF_PRINT_HEX_BYTE, SCC_NEWGRF_PRINT_HEX_DWORD, SCC_NEWGRF_PRINT_HEX_QWORD, SCC_NEWGRF_PRINT_HEX_WORD, SCC_NEWGRF_PRINT_MONTH_YEAR, SCC_NEWGRF_PRINT_QWORD_CURRENCY, SCC_NEWGRF_PRINT_SIGNED_BYTE, SCC_NEWGRF_PRINT_SIGNED_WORD, SCC_NEWGRF_PRINT_STRING_ID, SCC_NEWGRF_PRINT_UNSIGNED_WORD, SCC_NEWGRF_PRINT_WORD_SPEED, SCC_NEWGRF_PRINT_WORD_STATION_NAME, SCC_NEWGRF_PRINT_WORD_VOLUME, SCC_NEWGRF_PRINT_WORD_WEIGHT, SCC_NEWGRF_PUSH_WORD, SCC_NEWGRF_ROTATE_TOP_4_WORDS, SCC_NEWGRF_UNPRINT, and TTDPStringIDToOTTDStringIDMapping().

Referenced by FormatString().

void RestoreTextRefStackBackup | ( | struct TextRefStack * | backup | ) |

Restore a copy of the text stack to the used stack.

Parameters:

  | backup | The copy to restore.

Definition at line 951 of file newgrf_text.cpp.

Referenced by FormatString().

void SetCurrentGrfLangID | ( | byte | language_id | ) |

Equivalence Setter function between game and newgrf langID.

This function will adjust _currentLangID as to what is the LangID of the current language set by the user. This function is called after the user changed language, from strings.cpp:ReadLanguagePack

Parameters:

  | language_id | iso code of current selection

Definition at line 809 of file newgrf_text.cpp.

References _currentLangID.

char* TranslateTTDPatchCodes | ( | uint32 | grfid,
|  | uint8 | language_id,
|  | const char * | str,
|  | int * | olen |
| ) |  |  |

Translate TTDPatch string codes into something OpenTTD can handle (better).

Parameters:

  | grfid | The (NewGRF) ID associated with this string
  | language_id | The (NewGRF) language ID associated with this string.
  | str | The string to translate.
  `[out]` | olen | The length of the final string.

Returns:
  The translated string.

Definition at line 391 of file newgrf_text.cpp.

References SmallMap< T, U, S >::Contains(), CS_ALPHANUMERAL, UnmappedChoiceList::Flush(), GB(), LanguageMap::GetLanguageMap(), LanguageMap::GetMapping(), grfmsg(), IsValidChar(), MapGRFStringID(), NFO_UTF8_IDENTIFIER, ReallocT(), SCC_BIGFONT, SCC_NEWGRF_DISCARD_WORD, SCC_NEWGRF_PRINT_DATE, SCC_NEWGRF_PRINT_DWORD, SCC_NEWGRF_PRINT_HEX_BYTE, SCC_NEWGRF_PRINT_HEX_DWORD, SCC_NEWGRF_PRINT_HEX_QWORD, SCC_NEWGRF_PRINT_HEX_WORD, SCC_NEWGRF_PRINT_QWORD_CURRENCY, SCC_NEWGRF_PRINT_WORD_STATION_NAME, SCC_NEWGRF_PRINT_WORD_VOLUME, SCC_NEWGRF_PRINT_WORD_WEIGHT, SCC_NEWGRF_PUSH_WORD, SCC_NEWGRF_ROTATE_TOP_4_WORDS, SCC_NEWGRF_STRINL, SCC_NEWGRF_UNPRINT, SCC_TINYFONT, UnmappedChoiceList::strings, Utf8Decode(), Utf8Encode(), and Utf8EncodedCharLen().

Referenced by AddGRFString(), and AddGRFTextToList().

StringID TTDPStringIDToOTTDStringIDMapping | ( | StringID | str | ) |

Perform a mapping from TTDPatch's string IDs to OpenTTD's string IDs, but only for the ones we are aware off; the rest like likely unused and will show a warning.

Parameters:

  | str | the string ID to convert

Returns:
  the converted string ID

Definition at line 45 of file newgrf_text.cpp.

References DEBUG, and IsInsideMM().

Referenced by MapGRFStringID(), and RemapNewGRFStringControlCode().

bool UsingNewGRFTextStack | ( |  | ) |

Check whether the NewGRF text stack is in use.

Returns:
  True iff the NewGRF text stack is used.

Definition at line 933 of file newgrf_text.cpp.

Referenced by FormatString().

## Variable Documentation

const WChar NFO_UTF8_IDENTIFIER = 0x00DE`[static]`

This character, the thorn ('þ'), indicates a unicode string to NFO.

Definition at line 20 of file newgrf_text.h.

Referenced by TranslateTTDPatchCodes().