diff options
author | frosch <frosch@openttd.org> | 2008-08-03 14:16:57 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2008-08-03 14:16:57 +0000 |
commit | ba1b3c7f1106e0ea8e29b6324e413aa1e411ac03 (patch) | |
tree | 91aa49f7db5969ec5f76576c6d2f900a65774dd8 /src/train_cmd.cpp | |
parent | 98bb9ffada60531d9c0e698831f224bb98ca9bc2 (diff) | |
download | openttd-ba1b3c7f1106e0ea8e29b6324e413aa1e411ac03.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.cpp | 11 |
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) { |