diff src/openttd.cpp @ 5683:809a5610092f draft

(svn r8144) -Fix: [FS#163] When a station is removed, vehicles do not get excessive payment any longer, as the origin TILE is now stored as long as the origin STATION for the transported cargos. Basically this is only a temporary fix until cargopackets are implemented, but it fixes one of the oldest known bugs (Special Thanks to Darkvater for lots of testing)
author celestar <celestar@openttd.org>
date Mon, 15 Jan 2007 14:42:24 +0000
parents 2eb2392c2550
children 47e97da9c104
line wrap: on
line diff
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1689,6 +1689,19 @@
 		} END_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0)
 	}
 
+	if (CheckSavegameVersion(44)) {
+		Vehicle *v;
+		/* If we remove a station while cargo from it is still enroute, payment calculation will assume
+		 * 0, 0 to be the origin of the cargo, resulting in very high payments usually. v->cargo_source_xy
+		 * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
+		 * where this situation exists, the cargo-source information is lost. in this case, we set the origin
+		 * to the current tile of the vehicle to prevent excessive profits
+		 */
+		FOR_ALL_VEHICLES(v) {
+			v->cargo_source_xy = IsValidStationID(v->cargo_source) ? GetStation(v->cargo_source)->xy : v->tile;
+		}
+	}
+
 	return true;
 }