MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / MapGRFStringID

Function MapGRFStringID

src/newgrf/newgrf_stringmapping.cpp:129–154  ·  view source on GitHub ↗

* 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 * @param grfid Id of the grf file. * @param str GRF-local GRFStringID that we want to have the equivalent in OpenTTD. * @return The properly adjusted StringID. */

Source from the content-addressed store, hash-verified

127 * @return The properly adjusted StringID.
128 */
129StringID MapGRFStringID(uint32_t grfid, GRFStringID str)
130{
131 if (IsInsideMM(str.base(), 0xD800, 0x10000)) {
132 /* General text provided by NewGRF.
133 * In the specs this is called the 0xDCxx range (misc persistent texts),
134 * but we meanwhile extended the range to 0xD800-0xFFFF.
135 * Note: We are not involved in the "persistent" business, since we do not store
136 * any NewGRF strings in savegames. */
137 return GetGRFStringID(grfid, str);
138 } else if (IsInsideMM(str.base(), 0xD000, 0xD800)) {
139 /* Callback text provided by NewGRF.
140 * In the specs this is called the 0xD0xx range (misc graphics texts).
141 * These texts can be returned by various callbacks.
142 *
143 * Due to how TTDP implements the GRF-local- to global-textid translation
144 * texts included via 0x80 or 0x81 control codes have to add 0x400 to the textid.
145 * We do not care about that difference and just mask out the 0x400 bit.
146 */
147 str = GRFStringID(str.base() & ~0x400);
148 return GetGRFStringID(grfid, str);
149 } else {
150 /* The NewGRF wants to include/reference an original TTD string.
151 * Try our best to find an equivalent one. */
152 return TTDPStringIDToOTTDStringIDMapping(str);
153 }
154}
155
156/**
157 * Finalise all string mappings.

Callers 4

ChangeIndustryProductionFunction · 0.85
TranslateTTDPatchCodesFunction · 0.85
FinaliseStringMappingFunction · 0.85

Calls 4

IsInsideMMFunction · 0.85
GetGRFStringIDFunction · 0.85
baseMethod · 0.45

Tested by

no test coverage detected