(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
authorfrosch
Sun, 03 Aug 2008 17:16:39 +0000
changeset 9833 af950053ecfe
parent 9832 200ded94a1c3
child 9834 7474149531c1
(svn r13976) -Fix (r13953) [YAPP]: A crashing train could sometimes free the reservation of another train. (assisted by michi_cc)
src/train_cmd.cpp
--- a/src/train_cmd.cpp	Sun Aug 03 14:58:26 2008 +0000
+++ b/src/train_cmd.cpp	Sun Aug 03 17:16:39 2008 +0000
@@ -3437,11 +3437,6 @@
 		for (const Vehicle *u = v; u != NULL; u = u->Next()) {
 			ClearPathReservation(u->tile, GetVehicleTrackdir(u));
 		}
-		/* Try to reserve all tiles directly under the train, but not the whole
-		 * railway station platform or both tunnel/bridge ends. */
-		for (const Vehicle *u = v; u != NULL; u = u->Next()) {
-			TryReserveRailTrack(u->tile, TrackdirToTrack(GetVehicleTrackdir(u)));
-		}
 	}
 
 	/* we may need to update crossing we were approaching */
@@ -3511,6 +3506,15 @@
 			tcc->num += 2 + CountPassengersInTrain(coll);
 			SetVehicleCrashed(coll);
 		}
+
+		/* Try to reserve all tiles directly under the crashed trains.
+		 * As there might be more than two trains involved, we have to do that for all vehicles */
+		const Vehicle *u;
+		FOR_ALL_VEHICLES(u) {
+			if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED)) {
+				TryReserveRailTrack(u->tile, TrackBitsToTrack(u->u.rail.track));
+			}
+		}
 	}
 
 	return NULL;