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

Function GetRailTypeByLabel

src/rail.cpp:195–210  ·  view source on GitHub ↗

* Get the rail type for a given label. * @param label the railtype label. * @param allow_alternate_labels Search in the alternate label lists as well. * @return the railtype. */

Source from the content-addressed store, hash-verified

193 * @return the railtype.
194 */
195RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels)
196{
197 extern RailTypeInfo _railtypes[RAILTYPE_END];
198 if (label == 0) return INVALID_RAILTYPE;
199
200 auto it = std::ranges::find(_railtypes, label, &RailTypeInfo::label);
201 if (it == std::end(_railtypes) && allow_alternate_labels) {
202 /* Test if any rail type defines the label as an alternate. */
203 it = std::ranges::find_if(_railtypes, [label](const RailTypeInfo &rti) { return rti.alternate_labels.contains(label); });
204 }
205
206 if (it != std::end(_railtypes)) return it->Index();
207
208 /* No matching label was found, so it is invalid */
209 return INVALID_RAILTYPE;
210}

Callers 6

GetRailTypeTranslationFunction · 0.85
ConvertRailTypesFunction · 0.85
AfterLoadGRFsFunction · 0.85
SkipIfFunction · 0.85
RailTypeChangeInfoFunction · 0.85
RailTypeReserveInfoFunction · 0.85

Calls 4

containsMethod · 0.80
findFunction · 0.50
endFunction · 0.50
IndexMethod · 0.45

Tested by

no test coverage detected