summaryrefslogtreecommitdiff
path: root/src/newgrf_railtype.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2021-01-10 14:37:40 +0100
committerfrosch <github@elsenhans.name>2021-01-10 21:24:38 +0100
commit868d84bbfc8d2c1471ef713854dd05ebc872615a (patch)
treeeaad084698335fd20cd31e01729fa6e0eec9fa47 /src/newgrf_railtype.cpp
parent5b089605606ecbf6d7e9996b49f6cb0605deaa68 (diff)
downloadopenttd-868d84bbfc8d2c1471ef713854dd05ebc872615a.tar.xz
Add: [NewGRF] vehicle variable 63 to test the tracktype of the current tile against a given tracktype.
Diffstat (limited to 'src/newgrf_railtype.cpp')
-rw-r--r--src/newgrf_railtype.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp
index 2a98948e7..326ee80ba 100644
--- a/src/newgrf_railtype.cpp
+++ b/src/newgrf_railtype.cpp
@@ -139,6 +139,28 @@ SpriteID GetCustomSignalSprite(const RailtypeInfo *rti, TileIndex tile, SignalTy
}
/**
+ * 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.
* @param grffile The GRF to do the lookup for.