(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
authorglx
Thu, 27 Sep 2007 21:39:13 +0000
changeset 7645 efa25fcf7917
parent 7644 a7ff5c8ae47e
child 7646 dc8c0fa95dae
(svn r11176) -Revert (r9867): as it is needed for newgrf callbacks 14B and 14C
src/ai/default/default.cpp
src/ai/trolly/trolly.cpp
src/economy.cpp
src/industry.h
src/industry_cmd.cpp
src/industry_gui.cpp
src/newgrf_industries.cpp
src/openttd.cpp
src/saveload.cpp
src/station_cmd.cpp
--- a/src/ai/default/default.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/ai/default/default.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -533,7 +533,6 @@
 static void AiFindRandomIndustryRoute(FoundRoute *fr)
 {
 	Industry* i;
-	const IndustrySpec *indsp;
 	uint32 r;
 	CargoID cargo;
 
@@ -547,9 +546,8 @@
 	if (i == NULL) return;
 
 	// pick a random produced cargo
-	indsp = GetIndustrySpec(i->type);
-	cargo = indsp->produced_cargo[0];
-	if (r & 1 && indsp->produced_cargo[1] != CT_INVALID) cargo = indsp->produced_cargo[1];
+	cargo = i->produced_cargo[0];
+	if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1];
 
 	fr->cargo = cargo;
 
@@ -559,16 +557,10 @@
 	if (cargo != CT_GOODS && cargo != CT_FOOD) {
 		// pick a dest, and see if it can receive
 		Industry* i2 = AiFindRandomIndustry();
-		if (i2 == NULL) {
-			return;
-		}
-
-		indsp = GetIndustrySpec(i2->type);
-
-		if (i == i2 ||
-				(indsp->accepts_cargo[0] != cargo &&
-				indsp->accepts_cargo[1] != cargo &&
-				indsp->accepts_cargo[2] != cargo)) {
+		if (i2 == NULL || i == i2 ||
+				(i2->accepts_cargo[0] != cargo &&
+				i2->accepts_cargo[1] != cargo &&
+				i2->accepts_cargo[2] != cargo)) {
 			return;
 		}
 
@@ -671,10 +663,9 @@
 		}
 	} else {
 		const Industry* i = (const Industry*)fr->from;
-		const IndustrySpec *indsp = GetIndustrySpec(i->type);
-
-		if (i->last_month_pct_transported[fr->cargo != indsp->produced_cargo[0]] > 0x99 ||
-				i->last_month_production[fr->cargo != indsp->produced_cargo[0]] == 0) {
+
+		if (i->last_month_pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
+				i->last_month_production[fr->cargo != i->produced_cargo[0]] == 0) {
 			return false;
 		}
 	}
--- a/src/ai/trolly/trolly.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/ai/trolly/trolly.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -270,7 +270,6 @@
 	}
 	if (type == AI_INDUSTRY) {
 		const Industry* i = GetIndustry(ic);
-		const IndustrySpec *indsp = GetIndustrySpec(i->type);
 		const Station* st;
 		int count = 0;
 		int j = 0;
@@ -279,7 +278,7 @@
 
 		// No limits on delevering stations!
 		//  Or for industry that does not give anything yet
-		if (indsp->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true;
+		if (i->produced_cargo[0] == CT_INVALID || i->last_month_production[0] == 0) return true;
 
 		if (i->last_month_production[0] - i->last_month_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
 
@@ -302,13 +301,13 @@
 				//  we want to know if this station gets the same good. If so,
 				//  we want to know its rating. If it is too high, we are not going
 				//  to build there
-				if (indsp->produced_cargo[0] == CT_INVALID) continue;
+				if (i->produced_cargo[0] == CT_INVALID) continue;
 				// It does not take this cargo
-				if (!st->goods[indsp->produced_cargo[0]].last_speed) continue;
+				if (!st->goods[i->produced_cargo[0]].last_speed) continue;
 				// Is it around our industry
 				if (DistanceManhattan(st->xy, i->xy) > 5) continue;
 				// It does take this cargo.. what is his rating?
-				if (st->goods[indsp->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
+				if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
 				j++;
 				// The rating is high.. a little chance that we still continue
 				//  But if there are 2 stations of this size, we never go on...
@@ -458,19 +457,17 @@
 			}
 		} else if (p->ainew.tbt == AI_TRUCK) {
 			const Industry* ind_from = GetIndustry(p->ainew.from_ic);
-			const IndustrySpec *indsp_from = GetIndustrySpec(ind_from->type);
 			const Industry* ind_temp = GetIndustry(p->ainew.temp);
-			const IndustrySpec *indsp_temp = GetIndustrySpec(ind_temp->type);
 			bool found = false;
 			int max_cargo = 0;
 			uint i;
 
 			// TODO: in max_cargo, also check other cargo (beside [0])
 			// First we check if the from_ic produces cargo that this ic accepts
-			if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) {
-				for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
-					if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
-					if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
+			if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->last_month_production[0] != 0) {
+				for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) {
+					if (ind_temp->accepts_cargo[i] == CT_INVALID) break;
+					if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[i]) {
 						// Found a compatible industry
 						max_cargo = ind_from->last_month_production[0] - ind_from->last_month_transported[0];
 						found = true;
@@ -480,11 +477,11 @@
 					}
 				}
 			}
-			if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) {
+			if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->last_month_production[0] != 0) {
 				// If not check if the current ic produces cargo that the from_ic accepts
-				for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
-					if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
-					if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
+				for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) {
+					if (ind_from->accepts_cargo[i] == CT_INVALID) break;
+					if (ind_from->produced_cargo[0] == ind_from->accepts_cargo[i]) {
 						// Found a compatbiel industry
 						found = true;
 						max_cargo = ind_temp->last_month_production[0] - ind_temp->last_month_transported[0];
@@ -503,9 +500,9 @@
 						distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) {
 					p->ainew.to_ic = p->ainew.temp;
 					if (p->ainew.from_deliver) {
-						p->ainew.cargo = indsp_from->produced_cargo[0];
+						p->ainew.cargo = ind_from->produced_cargo[0];
 					} else {
-						p->ainew.cargo = indsp_temp->produced_cargo[0];
+						p->ainew.cargo = ind_temp->produced_cargo[0];
 					}
 					p->ainew.state = AI_STATE_FIND_STATION;
 
--- a/src/economy.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/economy.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -973,7 +973,6 @@
 static void FindSubsidyCargoRoute(FoundRoute *fr)
 {
 	Industry *i;
-	const IndustrySpec *ind;
 	int trans, total;
 	CargoID cargo;
 
@@ -981,15 +980,14 @@
 
 	fr->from = i = GetRandomIndustry();
 	if (i == NULL) return;
-	ind = GetIndustrySpec(i->type);
 
 	/* Randomize cargo type */
-	if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) {
-		cargo = ind->produced_cargo[1];
+	if (HASBIT(Random(), 0) && i->produced_cargo[1] != CT_INVALID) {
+		cargo = i->produced_cargo[1];
 		trans = i->last_month_pct_transported[1];
 		total = i->last_month_production[1];
 	} else {
-		cargo = ind->produced_cargo[0];
+		cargo = i->produced_cargo[0];
 		trans = i->last_month_pct_transported[0];
 		total = i->last_month_production[0];
 	}
@@ -1016,17 +1014,12 @@
 	} else {
 		/* The destination is an industry */
 		Industry *i2 = GetRandomIndustry();
-		if (i2 == NULL) {
-			return;
-		}
-
-		ind = GetIndustrySpec(i2->type);
 
 		/* The industry must accept the cargo */
-		if (i == i2 ||
-				(cargo != ind->accepts_cargo[0] &&
-				cargo != ind->accepts_cargo[1] &&
-				cargo != ind->accepts_cargo[2])) {
+		if (i2 == NULL || i == i2 ||
+				(cargo != i2->accepts_cargo[0] &&
+				cargo != i2->accepts_cargo[1] &&
+				cargo != i2->accepts_cargo[2])) {
 			return;
 		}
 		fr->distance = DistanceManhattan(i->xy, i2->xy);
@@ -1227,12 +1220,12 @@
 		indspec = GetIndustrySpec(ind->type);
 		uint i;
 
-		for (i = 0; i < lengthof(indspec->accepts_cargo); i++) {
-			if (cargo_type == indspec->accepts_cargo[i]) break;
+		for (i = 0; i < lengthof(ind->accepts_cargo); i++) {
+			if (cargo_type == ind->accepts_cargo[i]) break;
 		}
 
 		/* Check if matching cargo has been found */
-		if (i == lengthof(indspec->accepts_cargo)) continue;
+		if (i == lengthof(ind->accepts_cargo)) continue;
 
 		if (HASBIT(indspec->callback_flags, CBM_IND_REFUSE_CARGO)) {
 			uint16 res = GetIndustryCallback(CBID_INDUSTRY_REFUSE_CARGO, 0, GetReverseCargoTranslation(cargo_type, indspec->grf_prop.grffile), ind, ind->type, ind->xy);
--- a/src/industry.h	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/industry.h	Thu Sep 27 21:39:13 2007 +0000
@@ -105,10 +105,12 @@
 	byte width;
 	byte height;
 	const Town *town;                   ///< Nearest town
+	CargoID produced_cargo[2];          ///< 2 production cargo slots
 	uint16 produced_cargo_waiting[2];   ///< amount of cargo produced per cargo
 	uint16 incoming_cargo_waiting[3];   ///< incoming cargo waiting to be processed
 	byte production_rate[2];            ///< production rate for each cargo
 	byte prod_level;                    ///< general production level
+	CargoID accepts_cargo[3];           ///< 3 input cargo slots
 	uint16 this_month_production[2];    ///< stats of this month's production per cargo
 	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
 	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
--- a/src/industry_cmd.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/industry_cmd.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -410,7 +410,7 @@
 
 		i->this_month_production[0] += cw;
 
-		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
+		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
 		i->this_month_transported[0] += am;
 		if (am != 0 && !StartStopIndustryTileAnimation(i, IAT_INDUSTRY_DISTRIBUTES_CARGO)) {
 			uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
@@ -432,7 +432,7 @@
 
 		i->this_month_production[1] += cw;
 
-		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
+		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
 		i->this_month_transported[1] += am;
 	}
 }
@@ -820,7 +820,7 @@
 
 static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
 {
-	const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
+	const Industry *i = GetIndustryByTile(tile);
 
 	b[0] = i->produced_cargo[0];
 	b[1] = i->produced_cargo[1];
@@ -1391,7 +1391,7 @@
 		/* check if an industry that accepts the same goods is nearby */
 		if (DistanceMax(tile, i->xy) <= 14 &&
 				indspec->accepts_cargo[0] != CT_INVALID &&
-				indspec->accepts_cargo[0] == GetIndustrySpec(i->type)->accepts_cargo[0] && (
+				indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
 					_game_mode != GM_EDITOR ||
 					!_patches.same_industry_close ||
 					!_patches.multiple_industry_per_town
@@ -1421,6 +1421,11 @@
 	i->type = type;
 	IncIndustryTypeCount(type);
 
+	i->produced_cargo[0] = indspec->produced_cargo[0];
+	i->produced_cargo[1] = indspec->produced_cargo[1];
+	i->accepts_cargo[0] = indspec->accepts_cargo[0];
+	i->accepts_cargo[1] = indspec->accepts_cargo[1];
+	i->accepts_cargo[2] = indspec->accepts_cargo[2];
 	i->production_rate[0] = indspec->production_rate[0];
 	i->production_rate[1] = indspec->production_rate[1];
 
@@ -1713,10 +1718,9 @@
 {
 	byte pct;
 	bool refresh = false;
-	const IndustrySpec *indsp = GetIndustrySpec(i->type);
 
-	for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
-		if (indsp->produced_cargo[j] != CT_INVALID) {
+	for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+		if (i->produced_cargo[j] != CT_INVALID) {
 			pct = 0;
 			if (i->this_month_production[j] != 0) {
 				i->last_prod_year = _cur_year;
@@ -1859,7 +1863,7 @@
 
 		if (_patches.smooth_economy) {
 			closeit = true;
-			for (byte j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
+			for (byte j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
 				uint32 r = Random();
 				int old_prod, new_prod, percent;
 				int mag;
@@ -1888,7 +1892,7 @@
 				mag = abs(percent);
 				if (mag >= 10) {
 					SetDParam(2, mag);
-					SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
+					SetDParam(0, GetCargo(i->produced_cargo[j])->name);
 					SetDParam(1, i->index);
 					AddNewsItem(
 						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
@@ -2059,10 +2063,12 @@
 	    SLE_VAR(Industry, height,                     SLE_UINT8),
 	    SLE_REF(Industry, town,                       REF_TOWN),
 	SLE_CONDNULL( 2, 2, 60),       ///< used to be industry's produced_cargo
+	SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,  2,              78, SL_MAX_VERSION),
 	SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 3,              70, SL_MAX_VERSION),
 	    SLE_ARR(Industry, produced_cargo_waiting,     SLE_UINT16, 2),
 	    SLE_ARR(Industry, production_rate,            SLE_UINT8,  2),
 	SLE_CONDNULL( 3, 2, 60),       ///< used to be industry's accepts_cargo
+	SLE_CONDARR(Industry, accepts_cargo,              SLE_UINT8,  3,              78, SL_MAX_VERSION),
 	    SLE_VAR(Industry, prod_level,                 SLE_UINT8),
 	    SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
 	    SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
--- a/src/industry_gui.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/industry_gui.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -390,9 +390,8 @@
 
 static inline bool IsProductionAlterable(const Industry *i)
 {
-	const IndustrySpec *ind = GetIndustrySpec(i->type);
 	return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
-			(ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES));
+			(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
 }
 
 /** Information to store about the industry window */
@@ -410,21 +409,22 @@
 	switch (e->event) {
 	case WE_CREATE: {
 		/* Count the number of lines that we need to resize the GUI with */
-		const IndustrySpec *ind = GetIndustrySpec(GetIndustry(w->window_number)->type);
+		const Industry *i = GetIndustry(w->window_number);
+		const IndustrySpec *ind = GetIndustrySpec(i->type);
 		int lines = -3;
 
 		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
-			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
+			for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) {
 				if (j == 0) lines++;
 				lines++;
 			}
-		} else if (ind->accepts_cargo[0] != CT_INVALID) {
+		} else if (i->accepts_cargo[0] != CT_INVALID) {
 			lines++;
 		}
 
-		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
+		for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) {
 			if (j == 0) {
-				if (ind->accepts_cargo[0] != CT_INVALID) lines++;
+				if (i->accepts_cargo[0] != CT_INVALID) lines++;
 				lines++;
 			}
 			lines++;
@@ -448,26 +448,26 @@
 		DrawWindowWidgets(w);
 
 		if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) {
-			for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) {
+			for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) {
 				if (j == 0) {
 					DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0);
 					y += 10;
 				}
-				SetDParam(0, ind->accepts_cargo[j]);
+				SetDParam(0, i->accepts_cargo[j]);
 				SetDParam(1, i->incoming_cargo_waiting[j]);
 				DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0);
 				y += 10;
 			}
-		} else if (ind->accepts_cargo[0] != CT_INVALID) {
+		} else if (i->accepts_cargo[0] != CT_INVALID) {
 			StringID str;
 
-			SetDParam(0, GetCargo(ind->accepts_cargo[0])->name);
+			SetDParam(0, GetCargo(i->accepts_cargo[0])->name);
 			str = STR_4827_REQUIRES;
-			if (ind->accepts_cargo[1] != CT_INVALID) {
-				SetDParam(1, GetCargo(ind->accepts_cargo[1])->name);
+			if (i->accepts_cargo[1] != CT_INVALID) {
+				SetDParam(1, GetCargo(i->accepts_cargo[1])->name);
 				str = STR_4828_REQUIRES;
-				if (ind->accepts_cargo[2] != CT_INVALID) {
-					SetDParam(2, GetCargo(ind->accepts_cargo[2])->name);
+				if (i->accepts_cargo[2] != CT_INVALID) {
+					SetDParam(2, GetCargo(i->accepts_cargo[2])->name);
 					str = STR_4829_REQUIRES;
 				}
 			}
@@ -475,15 +475,15 @@
 			y += 10;
 		}
 
-		for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) {
+		for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) {
 			if (j == 0) {
-				if (ind->accepts_cargo[0] != CT_INVALID) y += 10;
+				if (i->accepts_cargo[0] != CT_INVALID) y += 10;
 				DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0);
 				y += 10;
 				WP(w, indview_d).production_offset_y = y;
 			}
 
-			SetDParam(0, ind->produced_cargo[j]);
+			SetDParam(0, i->produced_cargo[j]);
 			SetDParam(1, i->last_month_production[j]);
 
 			SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8);
@@ -527,8 +527,7 @@
 			if (!IsProductionAlterable(i)) return;
 			x = e->we.click.pt.x;
 			line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10;
-			if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) &&
-					GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) {
+			if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
 				if (IS_INT_INSIDE(x, 5, 25) ) {
 					/* Clicked buttons, decrease or increase production */
 					if (x < 15) {
@@ -579,10 +578,8 @@
 
 static void UpdateIndustryProduction(Industry *i)
 {
-	const IndustrySpec *ind = GetIndustrySpec(i->type);
-
-	for (byte j = 0; j < lengthof(ind->produced_cargo); j++) {
-		if (ind->produced_cargo[j] != CT_INVALID) {
+	for (byte j = 0; j < lengthof(i->produced_cargo); j++) {
+		if (i->produced_cargo[j] != CT_INVALID) {
 			i->last_month_production[j] = 8 * i->production_rate[j];
 		}
 	}
@@ -655,8 +652,6 @@
 {
 	const Industry* i = *(const Industry**)a;
 	const Industry* j = *(const Industry**)b;
-	const IndustrySpec *ind_i = GetIndustrySpec(i->type);
-	const IndustrySpec *ind_j = GetIndustrySpec(j->type);
 	int r;
 
 	switch (_industry_sort_order >> 1) {
@@ -670,10 +665,10 @@
 			break;
 
 		case 2: /* Sort by Production */
-			if (ind_i->produced_cargo[0] == CT_INVALID) {
-				r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
+			if (i->produced_cargo[0] == CT_INVALID) {
+				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 			} else {
-				if (ind_j->produced_cargo[0] == CT_INVALID) {
+				if (j->produced_cargo[0] == CT_INVALID) {
 					r = 1;
 				} else {
 					r =
@@ -684,23 +679,23 @@
 			break;
 
 		case 3: /* Sort by transported fraction */
-			if (ind_i->produced_cargo[0] == CT_INVALID) {
-				r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
+			if (i->produced_cargo[0] == CT_INVALID) {
+				r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
 			} else {
-				if (ind_j->produced_cargo[0] == CT_INVALID) {
+				if (j->produced_cargo[0] == CT_INVALID) {
 					r = 1;
 				} else {
 					int pi;
 					int pj;
 
 					pi = i->last_month_pct_transported[0] * 100 >> 8;
-					if (ind_i->produced_cargo[1] != CT_INVALID) {
+					if (i->produced_cargo[1] != CT_INVALID) {
 						int p = i->last_month_pct_transported[1] * 100 >> 8;
 						if (p < pi) pi = p;
 					}
 
 					pj = j->last_month_pct_transported[0] * 100 >> 8;
-					if (ind_j->produced_cargo[1] != CT_INVALID) {
+					if (j->produced_cargo[1] != CT_INVALID) {
 						int p = j->last_month_pct_transported[1] * 100 >> 8;
 						if (p < pj) pj = p;
 					}
@@ -781,15 +776,14 @@
 
 		while (p < _num_industry_sort) {
 			const Industry* i = _industry_sort[p];
-			const IndustrySpec *ind = GetIndustrySpec(i->type);
 
 			SetDParam(0, i->index);
-			if (ind->produced_cargo[0] != CT_INVALID) {
-				SetDParam(1, ind->produced_cargo[0]);
+			if (i->produced_cargo[0] != CT_INVALID) {
+				SetDParam(1, i->produced_cargo[0]);
 				SetDParam(2, i->last_month_production[0]);
 
-				if (ind->produced_cargo[1] != CT_INVALID) {
-					SetDParam(3, ind->produced_cargo[1]);
+				if (i->produced_cargo[1] != CT_INVALID) {
+					SetDParam(3, i->produced_cargo[1]);
 					SetDParam(4, i->last_month_production[1]);
 					SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8);
 					SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8);
--- a/src/newgrf_industries.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/newgrf_industries.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -257,7 +257,7 @@
 		case 0x87: return industry->height;// xy dimensions
 		/*  */
 		case 0x88:
-		case 0x89: return indspec->produced_cargo[variable - 0x88];
+		case 0x89: return industry->produced_cargo[variable - 0x88];
 		case 0x8A: return industry->produced_cargo_waiting[0];
 		case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8);
 		case 0x8C: return industry->produced_cargo_waiting[1];
@@ -266,7 +266,7 @@
 		case 0x8F: return industry->production_rate[variable - 0x8E];
 		case 0x90:
 		case 0x91:
-		case 0x92: return indspec->accepts_cargo[variable - 0x90];
+		case 0x92: return industry->accepts_cargo[variable - 0x90];
 		case 0x93: return industry->prod_level;
 		/* amount of cargo produced so far THIS month. */
 		case 0x94: return industry->this_month_production[0];
--- a/src/openttd.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/openttd.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -2182,6 +2182,19 @@
 		}
 	}
 
+	if (CheckSavegameVersion(78)) {
+		Industry *i;
+		uint j;
+		FOR_ALL_INDUSTRIES(i) {
+			const IndustrySpec *indsp = GetIndustrySpec(i->type);
+			for (j = 0; j < lengthof(i->produced_cargo); j++) {
+				i->produced_cargo[j] = indsp->produced_cargo[j];
+			}
+			for (j = 0; j < lengthof(i->accepts_cargo); j++) {
+				i->accepts_cargo[j] = indsp->accepts_cargo[j];
+			}
+		}
+	}
 
 	return true;
 }
--- a/src/saveload.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/saveload.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -29,7 +29,7 @@
 #include "strings.h"
 #include <list>
 
-extern const uint16 SAVEGAME_VERSION = 77;
+extern const uint16 SAVEGAME_VERSION = 78;
 uint16 _sl_version;       ///< the major savegame version identifier
 byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
--- a/src/station_cmd.cpp	Thu Sep 27 20:39:46 2007 +0000
+++ b/src/station_cmd.cpp	Thu Sep 27 21:39:13 2007 +0000
@@ -165,14 +165,14 @@
 	/* No industry */
 	if (!IsTileType(tile, MP_INDUSTRY)) return false;
 
-	const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type);
+	const Industry *ind = GetIndustryByTile(tile);
 
 	/* No extractive industry */
-	if ((indsp->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
-
-	for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
+	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_EXTRACTIVE) == 0) return false;
+
+	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
 		/* The industry extracts something non-liquid, i.e. no oil or plastic, so it is a mine */
-		if (indsp->produced_cargo[i] != CT_INVALID && (GetCargo(indsp->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
+		if (ind->produced_cargo[i] != CT_INVALID && (GetCargo(ind->produced_cargo[i])->classes & CC_LIQUID) == 0) return true;
 	}
 
 	return false;
@@ -208,14 +208,14 @@
 	/* No industry */
 	if (!IsTileType(tile, MP_INDUSTRY)) return false;
 
-	const IndustrySpec *indsp = GetIndustrySpec(GetIndustryByTile(tile)->type);
+	const Industry *ind = GetIndustryByTile(tile);
 
 	/* No extractive industry */
-	if ((indsp->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
-
-	for (uint i = 0; i < lengthof(indsp->produced_cargo); i++) {
+	if ((GetIndustrySpec(ind->type)->life_type & INDUSTRYLIFE_ORGANIC) == 0) return false;
+
+	for (uint i = 0; i < lengthof(ind->produced_cargo); i++) {
 		/* The industry produces wood. */
-		if (indsp->produced_cargo[i] != CT_INVALID && GetCargo(indsp->produced_cargo[i])->label == 'WOOD') return true;
+		if (ind->produced_cargo[i] != CT_INVALID && GetCargo(ind->produced_cargo[i])->label == 'WOOD') return true;
 	}
 
 	return false;