summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
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) {