summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/train_cmd.cpp21
-rw-r--r--src/water_cmd.cpp5
2 files changed, 25 insertions, 1 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;
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index f409c250e..3ad2b235f 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -887,7 +887,10 @@ static void FloodVehicle(Vehicle *v)
switch (v->type) {
default: NOT_REACHED();
case VEH_TRAIN:
- if (IsFrontEngine(v)) pass += 4; // driver
+ if (IsFrontEngine(v)) {
+ pass += 4; // driver
+ FreeTrainTrackReservation(v);
+ }
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
break;