changeset 8073:ab953ea59f2e draft

(svn r11634) -Fix: update signals when deleting crashed train on a bridge, update even when train is rotated
author smatz <smatz@openttd.org>
date Sat, 15 Dec 2007 00:04:01 +0000
parents 0cba7093ca14
children 5a1a58696b87
files src/train_cmd.cpp
diffstat 1 files changed, 11 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -3030,7 +3030,7 @@
  * Deletes/Clears the last wagon of a crashed train. It takes the engine of the
  * train, then goes to the last wagon and deletes that. Each call to this function
  * will remove the last wagon of a crashed train. If this wagon was on a crossing,
- * or inside a tunnel, recalculate the signals as they might need updating
+ * or inside a tunnel/bridge, recalculate the signals as they might need updating
  * @param v the Vehicle of which last wagon is to be removed
  */
 static void DeleteLastWagon(Vehicle *v)
@@ -3059,27 +3059,16 @@
 	 * others are on it */
 	DisableTrainCrossing(v->tile);
 
-	if ((v->u.rail.track == TRACK_BIT_WORMHOLE && v->vehstatus & VS_HIDDEN)) { // inside a tunnel
-		TileIndex endtile = GetOtherTunnelEnd(v->tile);
-
-		if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel is busy (error returned)
-
-		switch (v->direction) {
-			case 1:
-			case 5:
-				SetSignalsOnBothDir(v->tile, 0);
-				SetSignalsOnBothDir(endtile, 0);
-				break;
-
-			case 3:
-			case 7:
-				SetSignalsOnBothDir(v->tile, 1);
-				SetSignalsOnBothDir(endtile, 1);
-				break;
-
-			default:
-				break;
-		}
+	if (v->u.rail.track == TRACK_BIT_WORMHOLE) { // inside a tunnel / bridge
+		TileIndex endtile = IsTunnel(v->tile) ? GetOtherTunnelEnd(v->tile) : GetOtherBridgeEnd(v->tile);
+
+		if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy
+
+		DiagDirection dir = IsTunnel(v->tile) ? GetTunnelDirection(v->tile) : GetBridgeRampDirection(v->tile);
+
+		/* v->direction is "random", so it cannot be used to determine the direction of the track */
+		UpdateSignalsOnSegment(v->tile, dir);
+		UpdateSignalsOnSegment(endtile, ReverseDiagDir(dir));
 	}
 }