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

Function GetRailTypeTranslation

src/newgrf_railtype.cpp:151–165  ·  view source on GitHub ↗

* Translate an index to the GRF-local railtype-translation table into a RailType. * @param railtype Index into GRF-local translation table. * @param grffile Originating GRF file. * @return RailType or INVALID_RAILTYPE if the railtype is unknown. */

Source from the content-addressed store, hash-verified

149 * @return RailType or INVALID_RAILTYPE if the railtype is unknown.
150 */
151RailType GetRailTypeTranslation(uint8_t railtype, const GRFFile *grffile)
152{
153 if (grffile == nullptr || grffile->railtype_list.empty()) {
154 /* No railtype table present. Return railtype as-is (if valid), so it works for original railtypes. */
155 if (railtype >= RAILTYPE_END || GetRailTypeInfo(static_cast<RailType>(railtype))->label == 0) return INVALID_RAILTYPE;
156
157 return static_cast<RailType>(railtype);
158 } else {
159 /* Railtype table present, but invalid index, return invalid type. */
160 if (railtype >= grffile->railtype_list.size()) return INVALID_RAILTYPE;
161
162 /* Look up railtype including alternate labels. */
163 return GetRailTypeByLabel(grffile->railtype_list[railtype]);
164 }
165}
166
167/**
168 * Perform a reverse railtype lookup to get the GRF internal ID.

Callers 1

VehicleGetVariableFunction · 0.85

Calls 4

GetRailTypeInfoFunction · 0.85
GetRailTypeByLabelFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected