(svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
authorglx
Sat, 13 Oct 2007 02:23:11 +0000
changeset 8213 fc7a2b3164dd
parent 8212 4a6936f108a3
child 8214 854acef589c8
(svn r11252) -Revert r11239, Fix r9620: cargo translation was not done correctly
src/newgrf.cpp
src/newgrf_cargo.cpp
src/newgrf_cargo.h
--- a/src/newgrf.cpp	Sat Oct 13 00:49:13 2007 +0000
+++ b/src/newgrf.cpp	Sat Oct 13 02:23:11 2007 +0000
@@ -1762,7 +1762,7 @@
 			case 0x0B:
 			case 0x0C: {
 				uint16 acctp = grf_load_word(&buf);
-				tsp->accepts_cargo[prop - 0x0A] = GB(acctp, 0, 8);
+				tsp->accepts_cargo[prop - 0x0A] = GetCargoTranslation(GB(acctp, 0, 8), _cur_grffile);
 				tsp->acceptance[prop - 0x0A] = GB(acctp, 8, 8);
 			} break;
 
@@ -1963,13 +1963,13 @@
 
 			case 0x10: // Production cargo types
 				for (byte j = 0; j < 2; j++) {
-					indsp->produced_cargo[j] = grf_load_byte(&buf);
+					indsp->produced_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
 				}
 				break;
 
 			case 0x11: // Acceptance cargo types
 				for (byte j = 0; j < 3; j++) {
-					indsp->accepts_cargo[j] = grf_load_byte(&buf);
+					indsp->accepts_cargo[j] = GetCargoTranslation(grf_load_byte(&buf), _cur_grffile);
 				}
 				grf_load_byte(&buf); // Unnused, eat it up
 				break;
@@ -5237,15 +5237,6 @@
 					strid = GetGRFStringID(indsp->grf_prop.grffile->grfid, indsp->new_industry_text);
 					if (strid != STR_UNDEFINED) indsp->new_industry_text = strid;
 
-					for (byte j = 0; j < 2; j++) {
-						CargoID c = GetCargoTranslation(indsp->produced_cargo[j], indsp->grf_prop.grffile);
-						indsp->produced_cargo[j] = c;
-					}
-					for (byte j = 0; j < 3; j++) {
-						CargoID c = GetCargoTranslation(indsp->accepts_cargo[j], indsp->grf_prop.grffile);
-						indsp->accepts_cargo[j] = c;
-					}
-
 					_industry_mngr.SetEntitySpec(indsp);
 					_loaded_newgrf_features.has_newindustries = true;
 				}
@@ -5256,10 +5247,6 @@
 			for (int i = 0; i < NUM_INDUSTRYTILES; i++) {
 				IndustryTileSpec *indtsp = file->indtspec[i];
 				if (indtsp != NULL) {
-					for (byte j = 0; j < 3; j++) {
-						CargoID c = GetCargoTranslation(indtsp->accepts_cargo[j], indtsp->grf_prop.grffile);
-						indtsp->accepts_cargo[j] = c;
-					}
 					_industile_mngr.SetEntitySpec(indtsp);
 				}
 			}
--- a/src/newgrf_cargo.cpp	Sat Oct 13 00:49:13 2007 +0000
+++ b/src/newgrf_cargo.cpp	Sat Oct 13 02:23:11 2007 +0000
@@ -98,17 +98,19 @@
 }
 
 
-CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile)
+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) return HASBIT(_cargo_mask, cargo) ? cargo : (CargoID) CT_INVALID;
-
-	/* 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]);
-
-	/* Else the cargo value is a 'climate independent' 'bitnum' */
-	return GetCargoIDByBitnum(cargo);
+	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);
+	} 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]);
+	}
+	return CT_INVALID;
 }
 
 uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile)
--- a/src/newgrf_cargo.h	Sat Oct 13 00:49:13 2007 +0000
+++ b/src/newgrf_cargo.h	Sat Oct 13 02:23:11 2007 +0000
@@ -29,7 +29,7 @@
 
 SpriteID GetCustomCargoSprite(const CargoSpec *cs);
 uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs);
-CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile);
+CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit = false);
 uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile);
 
 #endif /* NEWGRF_CARGO_H */