summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2008-08-03 14:16:57 +0000
committerfrosch <frosch@openttd.org>2008-08-03 14:16:57 +0000
commit983e297ff0836199d6544a3201ea51c7525bd849 (patch)
tree91aa49f7db5969ec5f76576c6d2f900a65774dd8 /src/train_cmd.cpp
parent9a1958be91096d77294c196fa543d6e45b7c9873 (diff)
downloadopenttd-983e297ff0836199d6544a3201ea51c7525bd849.tar.xz
(svn r13974) -Fix [YAPP]: A train crash could lead to stale reservations. (michi_cc)
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index efdbd5c2a..dc7ff694c 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3059,7 +3059,8 @@ bool TryPathReserve(Vehicle *v, bool mark_as_stuck, bool first_tile_okay)
}
}
- PBSTileInfo origin = FollowTrainReservation(v);
+ Vehicle *other_train = NULL;
+ PBSTileInfo origin = FollowTrainReservation(v, &other_train);
/* If we have a reserved path and the path ends at a safe tile, we are finished already. */
if (origin.okay && (v->tile != origin.tile || first_tile_okay)) {
/* Can't be stuck then. */
@@ -3067,6 +3068,14 @@ bool TryPathReserve(Vehicle *v, bool mark_as_stuck, bool first_tile_okay)
ClrBit(v->u.rail.flags, VRF_TRAIN_STUCK);
return true;
}
+ /* The path we are driving on is alread blocked by some other train.
+ * This can only happen when tracks and signals are changed. A crash
+ * is probably imminent, don't do any further reservation because
+ * it might cause stale reservations. */
+ if (other_train != NULL && v->tile != origin.tile) {
+ if (mark_as_stuck) MarkTrainAsStuck(v);
+ return false;
+ }
/* If we are in a depot, tentativly reserve the depot. */
if (v->u.rail.track & TRACK_BIT_DEPOT) {