summaryrefslogtreecommitdiff
path: root/src/newgrf_cargo.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-02-07 22:46:26 +0000
committerfrosch <frosch@openttd.org>2012-02-07 22:46:26 +0000
commitb1a3a31a8389aa90fc42c81e7b8cf7df0d7b7b31 (patch)
tree8a91dfaa131f81e5bddac13c1503a7c250ea921f /src/newgrf_cargo.cpp
parent1c84468b5d58a2ca5385dbc8c7b57f498616bb6a (diff)
downloadopenttd-b1a3a31a8389aa90fc42c81e7b8cf7df0d7b7b31.tar.xz
(svn r23914) -Fix (r11252, r13855): Don't test validity of cargobits using a mask of cargoslots.
Diffstat (limited to 'src/newgrf_cargo.cpp')
-rw-r--r--src/newgrf_cargo.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp
index 9847a72c1..da463d4ff 100644
--- a/src/newgrf_cargo.cpp
+++ b/src/newgrf_cargo.cpp
@@ -100,14 +100,22 @@ uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const
return group->GetCallbackResult();
}
-
+/**
+ * Translate a GRF-local cargo slot/bitnum into a CargoID.
+ * @param cargo GRF-local cargo slot/bitnum.
+ * @param grffile Originating GRF file.
+ * @param usebit Defines the meaning of \a cargo for GRF version < 7.
+ * If true, then \a cargo is a bitnum. If false, then \a cargo is a cargoslot.
+ * For GRF version >= 7 \a cargo is always a translated cargo bit.
+ * @return CargoID or CT_INVALID if the cargo is not available.
+ */
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
{
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */
if (grffile->grf_version < 7) {
if (!usebit) return cargo;
/* Else the cargo value is a 'climate independent' 'bitnum' */
- if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
+ return GetCargoIDByBitnum(cargo);
} else {
/* If the GRF contains a translation table... */
if (grffile->cargo_max > 0) {
@@ -116,7 +124,7 @@ CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
} else {
/* Else the cargo value is a 'climate independent' 'bitnum' */
- if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
+ return GetCargoIDByBitnum(cargo);
}
}
return CT_INVALID;