* 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. */
| 149 | * @return RailType or INVALID_RAILTYPE if the railtype is unknown. |
| 150 | */ |
| 151 | RailType 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. |
no test coverage detected