train_cmd.c
changeset 1048 edfc783f241d
parent 1035 0a170deb6e33
child 1049 df4df87f0a08
--- a/train_cmd.c	Mon Jan 17 09:16:43 2005 +0000
+++ b/train_cmd.c	Mon Jan 17 09:41:46 2005 +0000
@@ -1893,36 +1893,39 @@
 }
 
 /* Check if the vehicle is compatible with the specified tile */
-static bool CheckCompatibleRail(Vehicle *v, uint tile)
+static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
 {
-	if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION)) {
-		// normal tracks, jump to owner check
-	} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
-		if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part?
-			TileInfo ti;
-			FindLandscapeHeightByTile(&ti, tile);
-
-			// correct Z position of a train going under a bridge on slopes
-			if (CORRECT_Z(ti.tileh))
-				ti.z += 8;
-
-			if(v->z_pos != ti.z) // train is going over bridge
-				return true;
-		}
-	} else if (IsTileType(tile, MP_STREET)) { // train is going over a road-crossing
-		// tracks over roads, do owner check of tracks (_map_owner[tile])
-		if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype))
-			return false;
-
-		return true;
-	} else
-		return true;
-
-	if (_map_owner[tile] != v->owner ||
-			(v->subtype == 0 && (_map3_lo[tile] & 0xF) != v->u.rail.railtype))
-		return false;
-
-	return true;
+	switch (TileType(tile)) {
+		case MP_RAILWAY:
+		case MP_STATION:
+			// normal tracks, jump to owner check
+			break;
+
+		case MP_TUNNELBRIDGE:
+			if ((_map5[tile] & 0xC0) == 0xC0) { // is bridge middle part?
+				TileInfo ti;
+				FindLandscapeHeightByTile(&ti, tile);
+
+				// correct Z position of a train going under a bridge on slopes
+				if (CORRECT_Z(ti.tileh)) ti.z += 8;
+
+				if (v->z_pos != ti.z) return true; // train is going over bridge
+			}
+			break;
+
+		case MP_STREET:
+			// tracks over roads, do owner check of tracks (_map_owner[tile])
+			return
+				_map_owner[tile] == v->owner &&
+				(v->subtype != 0 || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
+
+		default:
+			return true;
+	}
+
+	return
+		_map_owner[tile] == v->owner &&
+		(v->subtype != 0 || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
 }
 
 typedef struct {