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

Function GetRoadTypeByLabel

src/road.cpp:265–280  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

263 * @return the roadtype.
264 */
265RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels)
266{
267 extern RoadTypeInfo _roadtypes[ROADTYPE_END];
268 if (label == 0) return INVALID_ROADTYPE;
269
270 auto it = std::ranges::find(_roadtypes, label, &RoadTypeInfo::label);
271 if (it == std::end(_roadtypes) && allow_alternate_labels) {
272 /* Test if any road type defines the label as an alternate. */
273 it = std::ranges::find_if(_roadtypes, [label](const RoadTypeInfo &rti) { return rti.alternate_labels.contains(label); });
274 }
275
276 if (it != std::end(_roadtypes)) return it->Index();
277
278 /* No matching label was found, so it is invalid */
279 return INVALID_ROADTYPE;
280}

Callers 7

AfterLoadGRFsFunction · 0.85
GetFeatureMethod · 0.85
GetRoadTypeTranslationFunction · 0.85
ConvertRoadTypesFunction · 0.85
RoadTypeChangeInfoFunction · 0.85
RoadTypeReserveInfoFunction · 0.85
SkipIfFunction · 0.85

Calls 4

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

Tested by

no test coverage detected