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

Function GetRoadTypeTranslation

src/newgrf_roadtype.cpp:171–193  ·  view source on GitHub ↗

* Translate an index to the GRF-local road/tramtype-translation table into a RoadType. * @param rtt Whether to index the road- or tramtype-table. * @param tracktype Index into GRF-local translation table. * @param grffile Originating GRF file. * @return RoadType or INVALID_ROADTYPE if the roadtype is unknown. */

Source from the content-addressed store, hash-verified

169 * @return RoadType or INVALID_ROADTYPE if the roadtype is unknown.
170 */
171RoadType GetRoadTypeTranslation(RoadTramType rtt, uint8_t tracktype, const GRFFile *grffile)
172{
173 /* Because OpenTTD mixes RoadTypes and TramTypes into the same type,
174 * the mapping of the original road- and tramtypes does not match the default GRF-local mapping.
175 * So, this function cannot provide any similar behavior to GetCargoTranslation() and GetRailTypeTranslation()
176 * when the GRF defines no translation table.
177 * But since there is only one default road/tram-type, this makes little sense anyway.
178 * So for GRF without translation table, we always return INVALID_ROADTYPE.
179 */
180
181 if (grffile == nullptr) return INVALID_ROADTYPE;
182
183 const auto &list = rtt == RTT_TRAM ? grffile->tramtype_list : grffile->roadtype_list;
184 if (tracktype >= list.size()) return INVALID_ROADTYPE;
185
186 /* Look up roadtype including alternate labels. */
187 RoadType result = GetRoadTypeByLabel(list[tracktype]);
188
189 /* Check whether the result is actually the wanted road/tram-type */
190 if (result != INVALID_ROADTYPE && GetRoadTramType(result) != rtt) return INVALID_ROADTYPE;
191
192 return result;
193}
194
195/**
196 * Perform a reverse roadtype lookup to get the GRF internal ID.

Callers 1

VehicleGetVariableFunction · 0.85

Calls 3

GetRoadTypeByLabelFunction · 0.85
GetRoadTramTypeFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected