(svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
authorpeter1138
Tue, 13 Mar 2007 21:31:09 +0000
changeset 6630 4fa4f6d883ba
parent 6629 b35b983c6cdb
child 6631 dc3480a670cc
(svn r9147) -Fix (r1770, r8161): when loadin games, enroute_from and enroute_from_xy were updated in the wrong place, causing issues with TTD savegames/scenarios.
src/openttd.cpp
src/station_cmd.cpp
--- a/src/openttd.cpp	Tue Mar 13 21:04:22 2007 +0000
+++ b/src/openttd.cpp	Tue Mar 13 21:31:09 2007 +0000
@@ -1792,6 +1792,25 @@
 		FOR_ALL_VEHICLES(v) {
 			v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile;
 		}
+
+		/* Store position of the station where the goods come from, so there
+		 * are no very high payments when stations get removed. However, if the
+		 * station where the goods came from is already removed, the source
+		 * information is lost. In that case we set it to the position of this
+		 * station */
+		Station *st;
+		FOR_ALL_STATIONS(st) {
+			for (CargoID c = 0; c < NUM_CARGO; c++) {
+				GoodsEntry *ge = &st->goods[c];
+
+				/* In old versions, enroute_from used 0xFF as INVALID_STATION */
+				if (CheckSavegameVersion(7) && ge->enroute_from == 0xFF) {
+					ge->enroute_from = INVALID_STATION;
+				}
+
+				ge->enroute_from_xy = IsValidStationID(ge->enroute_from) ? GetStation(ge->enroute_from)->xy : st->xy;
+			}
+		}
 	}
 
 	if (CheckSavegameVersion(45)) {
--- a/src/station_cmd.cpp	Tue Mar 13 21:04:22 2007 +0000
+++ b/src/station_cmd.cpp	Tue Mar 13 21:31:09 2007 +0000
@@ -2797,18 +2797,6 @@
 	SlObject(st, _station_desc);
 	for (uint i = 0; i != NUM_CARGO; i++) {
 		SlObject(&st->goods[i], _goods_desc);
-
-		/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
-		if (CheckSavegameVersion(7) && st->goods[i].enroute_from == 0xFF) {
-			st->goods[i].enroute_from = INVALID_STATION;
-		}
-		if (CheckSavegameVersion(44)) {
-			/* Store position of the station where the goods come from, so there are no
-			 * very high payments when stations get removed. However, if the station
-			 * where the goods came from is already removed, the source information is
-			 * lost. In that case we set it to the position of this station */
-			st->goods[i].enroute_from_xy = IsValidStationID(st->goods[i].enroute_from) ? GetStation(st->goods[i].enroute_from)->xy : st->xy;
-		}
 	}
 
 	if (st->num_specs != 0) {