* 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. */
| 193 | * @return the railtype. |
| 194 | */ |
| 195 | RailType 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 | } |
no test coverage detected