diff options
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r-- | src/train_cmd.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 3176b7fe1..6f52554ee 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3068,6 +3068,21 @@ static void SetVehicleCrashed(Vehicle *v) { if (v->u.rail.crash_anim_pos != 0) return; + /* Free a possible path reservation and try to mark all tiles occupied by the train reserved. */ + if (IsFrontEngine(v)) { + /* Remove all reservations, also the ones currently under the train + * and any railway station paltform reservation. */ + FreeTrainTrackReservation(v); + 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 */ TileIndex crossing = TrainApproachingCrossingTile(v); @@ -3452,6 +3467,12 @@ static void DeleteLastWagon(Vehicle *v) MarkSingleVehicleDirty(v); + /* Clear a possible path reservation */ + if ((IsFrontEngine(v) && !(v->u.rail.track & TRACK_BIT_DEPOT)) + || ((v->u.rail.track & ~TRACK_BIT_MASK) == TRACK_BIT_NONE && (v->tile != u->tile || (u->u.rail.track & ~TRACK_BIT_MASK) != TRACK_BIT_NONE))) { + if (HasReservedTracks(v->tile, v->u.rail.track)) UnreserveRailTrack(v->tile, TrackBitsToTrack(v->u.rail.track)); + } + /* 'v' shouldn't be accessed after it has been deleted */ TrackBits track = v->u.rail.track; TileIndex tile = v->tile; |