changeset 14795:ca2563247d8d draft

(svn r19384) -Fix: Overbuilding plain rail with stations did not update PBS reservation.
author frosch <frosch@openttd.org>
date Wed, 10 Mar 2010 20:45:23 +0000
parents a1410dd4d9da
children 715fc4899dfd
files src/station_cmd.cpp
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -741,9 +741,10 @@
  * @param invalid_dirs Prohibited directions (set of #DiagDirection).
  * @param station StationID to be queried and returned if available.
  * @param rt The rail type to check for (overbuilding rail stations over rail).
+ * @param affected_vehicles List of trains with PBS reservations on the tiles
  * @return The cost in case of success, or an error code if it failed.
  */
-static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, StationID *station, RailType rt = INVALID_RAILTYPE)
+static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, StationID *station, RailType rt, SmallVector<Train *, 4> &affected_vehicles)
 {
 	CommandCost cost(EXPENSES_CONSTRUCTION);
 	int allowed_z = -1;
@@ -784,6 +785,13 @@
 				Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
 
 				if (tracks == TRACK_BIT_NONE && track == expected_track) {
+					/* Check for trains having a reservation for this tile. */
+					if (HasBit(GetRailReservationTrackBits(tile_cur), track)) {
+						Train *v = GetTrainForReservation(tile_cur, track);
+						if (v != NULL) {
+							*affected_vehicles.Append() = v;
+						}
+					}
 					CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
 					if (ret.Failed()) return ret;
 					cost.AddCost(ret);
@@ -1130,8 +1138,9 @@
 
 	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
 	StationID est = INVALID_STATION;
+	SmallVector<Train *, 4> affected_vehicles;
 	/* Clear the land below the station. */
-	CommandCost cost = CheckFlatLandRailStation(TileArea(tile_org, w_org, h_org), flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, rt);
+	CommandCost cost = CheckFlatLandRailStation(TileArea(tile_org, w_org, h_org), flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, rt, affected_vehicles);
 	if (cost.Failed()) return cost;
 	/* Add construction expenses. */
 	cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
@@ -1222,7 +1231,6 @@
 
 		numtracks_orig = numtracks;
 
-		SmallVector<Train*, 4> affected_vehicles;
 		do {
 			TileIndex tile = tile_org;
 			int w = plat_len;