summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-04 13:15:15 +0000
committerrubidium <rubidium@openttd.org>2008-08-04 13:15:15 +0000
commit33148eae6e4f3f563fbdf96ee159db20e89f8b85 (patch)
treee085a4620a0b16591285ed70f74f7b465f696b24
parenteb5fb4443a4ba00ad8e17fc8df80f6f9547326ad (diff)
downloadopenttd-33148eae6e4f3f563fbdf96ee159db20e89f8b85.tar.xz
(svn r13989) -Fix [FS#2186] (r13953): YAPP track reservation for crashed trains was broken for depots and wormholes (michi_cc).
-rw-r--r--src/train_cmd.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 5db19dcd9..94b708389 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3436,6 +3436,11 @@ static void SetVehicleCrashed(Vehicle *v)
FreeTrainTrackReservation(v);
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
ClearPathReservation(u->tile, GetVehicleTrackdir(u));
+ if (IsTileType(u->tile, MP_TUNNELBRIDGE)) {
+ /* ClearPathReservation will not free the wormhole exit
+ * if the train has just entered the wormhole. */
+ SetTunnelBridgeReservation(GetOtherTunnelBridgeEnd(u->tile), false);
+ }
}
}
@@ -3511,7 +3516,12 @@ static Vehicle *FindTrainCollideEnum(Vehicle *v, void *data)
* As there might be more than two trains involved, we have to do that for all vehicles */
const Vehicle *u;
FOR_ALL_VEHICLES(u) {
- if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED)) {
+ if (u->type == VEH_TRAIN && HASBITS(u->vehstatus, VS_CRASHED) && (u->u.rail.track & TRACK_BIT_DEPOT) == TRACK_BIT_NONE) {
+ TrackBits trackbits = u->u.rail.track;
+ if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
+ /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */
+ trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(u->tile));
+ }
TryReserveRailTrack(u->tile, TrackBitsToTrack(u->u.rail.track));
}
}
@@ -3843,7 +3853,14 @@ static Vehicle *CollectTrackbitsFromCrashedVehiclesEnum(Vehicle *v, void *data)
{
TrackBits *trackbits = (TrackBits *)data;
- if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) *trackbits |= v->u.rail.track;
+ if (v->type == VEH_TRAIN && (v->vehstatus & VS_CRASHED) != 0) {
+ if ((v->u.rail.track & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
+ /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */
+ *trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(v->tile));
+ } else {
+ *trackbits |= v->u.rail.track;
+ }
+ }
return NULL;
}
@@ -3886,13 +3903,18 @@ static void DeleteLastWagon(Vehicle *v)
/* 'v' shouldn't be accessed after it has been deleted */
TrackBits trackbits = v->u.rail.track;
- Track track = TrackBitsToTrack(trackbits);
TileIndex tile = v->tile;
Owner owner = v->owner;
delete v;
v = NULL; // make sure nobody will try to read 'v' anymore
+ if ((trackbits & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
+ /* Vehicle is inside a wormhole, v->u.rail.track contains no useful value then. */
+ trackbits |= DiagDirToDiagTrackBits(GetTunnelBridgeDirection(tile));
+ }
+
+ Track track = TrackBitsToTrack(trackbits);
if (HasReservedTracks(tile, trackbits)) {
UnreserveRailTrack(tile, track);