(svn r13953) -Add [YAPP]: Free track reservations of crashed trains. (michi_cc)

This commit is contained in:
rubidium 2008-08-02 22:54:07 +00:00
parent 10d8fb6456
commit d06fb949ff
2 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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;