OpenTTD Source 20250331-master-g3c15e0c889
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 "../safeguards.h"
#include "../table/strings.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)}
uint32_t StringID
Numeric value that represents a string, independent of the selected language.

Function Documentation

◆ AddStringForMapping() [1/2]

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

Record a static StringID for getting translated later.

Parameters
sourceSource grf-local GRFStringID.
funcFunction 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
sourceSource grf-local GRFStringID.
targetDestination 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
grfidId of the grf file.
strGRF-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
strGrf-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().