Add: [NewGRF] vehicle variable 63 to test the tracktype of the current tile against a given tracktype.

This commit is contained in:
frosch
2021-01-10 14:37:40 +01:00
committed by frosch
parent 5b08960560
commit 868d84bbfc
6 changed files with 87 additions and 1 deletions

View File

@@ -138,6 +138,28 @@ SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalTy
return group->GetResult();
}
/**
* 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.
*/
RailType GetRailTypeTranslation(uint8 railtype, const GRFFile *grffile)
{
if (grffile == nullptr || grffile->railtype_list.size() == 0) {
/* No railtype table present. Return railtype as-is (if valid), so it works for original railtypes. */
if (railtype >= RAILTYPE_END || GetRailTypeInfo(static_cast<RailType>(railtype))->label == 0) return INVALID_RAILTYPE;
return static_cast<RailType>(railtype);
} else {
/* Railtype table present, but invalid index, return invalid type. */
if (railtype >= grffile->railtype_list.size()) return INVALID_RAILTYPE;
/* Look up railtype including alternate labels. */
return GetRailTypeByLabel(grffile->railtype_list[railtype]);
}
}
/**
* Perform a reverse railtype lookup to get the GRF internal ID.
* @param railtype The global (OpenTTD) railtype.