OpenTTD Source: src/newgrf/newgrf_stringmapping.cpp File Reference

OpenTTD Source 15.3

Data Structures | Macros | Functions | Variables
newgrf_stringmapping.cpp File Reference

NewGRF string mapping implementation. More...

`#include "../stdafx.h"`
`#include "../debug.h"`
`#include "../newgrf.h"`
`#include "../newgrf_text.h"`
`#include "../newgrf_text_type.h"`
`#include "../strings_type.h"`
`#include "newgrf_internal.h"`
`#include "newgrf_stringmapping.h"`
`#include "table/strings.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | StringIDMapping
| Information for mapping static StringIDs. More...

## Macros
#define | TEXTID_TO_STRINGID(begin, end, stringid, stringend)

## Functions
void | AddStringForMapping (GRFStringID source, std::function< void(StringID)> &&func)
| Record a static StringID for getting translated later.
void | AddStringForMapping (GRFStringID source, StringID *target)
| Record a static StringID for getting translated later.
static StringID | TTDPStringIDToOTTDStringIDMapping (GRFStringID 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.
StringID | MapGRFStringID (uint32_t grfid, GRFStringID str)
| Used when setting an object's property to map to the GRF's strings while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one.
void | FinaliseStringMapping ()
| Finalise all string mappings.

## Variables
static std::vector< StringIDMapping > | _string_to_grf_mapping
| Strings to be mapped during load.

## Detailed Description

NewGRF string mapping implementation.

Definition in file newgrf_stringmapping.cpp.

## Macro Definition Documentation

## ◆ TEXTID_TO_STRINGID

#define TEXTID_TO_STRINGID | ( |  | begin,
|  |  | end,
|  |  | stringid,
|  |  | stringend
| ) |  |

Value:
static_assert(stringend - stringid == end - begin); \
if (str.base() >= begin && str.base() <= end) return StringID{str.base() + (stringid - begin)}
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19

## Function Documentation

## ◆ AddStringForMapping() [1/2]

void AddStringForMapping | ( | GRFStringID | source,
|  | std::function< void(StringID)> && | func
| ) |  |

Record a static StringID for getting translated later.

Parameters

  source | Source grf-local GRFStringID.
  func | Function to call to set the mapping result.

Definition at line 42 of file newgrf_stringmapping.cpp.

References _string_to_grf_mapping, and GrfProcessingState::grffile.

Referenced by AddStringForMapping(), AirportChangeInfo(), CargoReserveInfo(), GlobalVarChangeInfo(), IndustriesChangeInfo(), ObjectChangeInfo(), RailTypeChangeInfo(), RoadTypeChangeInfo(), StationChangeInfo(), and TownHouseChangeInfo().

## ◆ AddStringForMapping() [2/2]

void AddStringForMapping | ( | GRFStringID | source,
|  | StringID * | target
| ) |  |

Record a static StringID for getting translated later.

Parameters

  source | Source grf-local GRFStringID.
  target | Destination for the mapping result.

Definition at line 53 of file newgrf_stringmapping.cpp.

References AddStringForMapping().

## ◆ FinaliseStringMapping()

void FinaliseStringMapping | ( |  | ) |

Finalise all string mappings.

Definition at line 159 of file newgrf_stringmapping.cpp.

References _string_to_grf_mapping, and MapGRFStringID().

Referenced by AfterLoadGRFs().

## ◆ MapGRFStringID()

StringID MapGRFStringID | ( | uint32_t | grfid,
|  | GRFStringID | str
| ) |  |

Used when setting an object's property to map to the GRF's strings while taking in consideration the "drift" between TTDPatch string system and OpenTTD's one.

Parameters

  grfid | Id of the grf file.
  str | GRF-local GRFStringID that we want to have the equivalent in OpenTTD.

Returns
  The properly adjusted StringID.

Definition at line 129 of file newgrf_stringmapping.cpp.

References GetGRFStringID(), IsInsideMM(), and TTDPStringIDToOTTDStringIDMapping().

Referenced by ChangeIndustryProduction(), FinaliseStringMapping(), ProcessNewGRFStringControlCode(), and TranslateTTDPatchCodes().

## ◆ TTDPStringIDToOTTDStringIDMapping()

static StringID TTDPStringIDToOTTDStringIDMapping | ( | GRFStringID | str | ) |
| static

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 | Grf-local GRFStringID to convert.

Returns
  the converted string ID

Definition at line 65 of file newgrf_stringmapping.cpp.

References Debug, and IsInsideMM().

Referenced by MapGRFStringID().

## Variable Documentation

## ◆ _string_to_grf_mapping

std::vector<StringIDMapping> _string_to_grf_mapping
| static

Strings to be mapped during load.

Definition at line 35 of file newgrf_stringmapping.cpp.

Referenced by AddStringForMapping(), and FinaliseStringMapping().