(svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
authorpeter1138
Mon, 28 Jul 2008 06:16:34 +0000
changeset 9728 60bc400cb942
parent 9727 3c06f03dadbe
child 9729 9f30f91062c6
(svn r13855) -Fix [FS#2157]: Cargo type lookup was incorrect for GRFv7 files without a translation table.
src/newgrf_cargo.cpp
--- a/src/newgrf_cargo.cpp	Sun Jul 27 20:43:21 2008 +0000
+++ b/src/newgrf_cargo.cpp	Mon Jul 28 06:16:34 2008 +0000
@@ -109,9 +109,15 @@
 		/* Else the cargo value is a 'climate independent' 'bitnum' */
 		if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo);
 	} else {
-		/* If the GRF contains a translation table (and the cargo is in bounds)
-		 * then get the cargo ID for the label */
-		if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
+		/* If the GRF contains a translation table... */
+		if (grffile->cargo_max > 0) {
+			/* ...and the cargo is in bounds, then get the cargo ID for
+			 * the label */
+			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 CT_INVALID;
 }