(svn r11112) -Fix (r11107) [FS#1229]: in some cases one could destroy (parts of) buildings when building tunnels.
authorrubidium
Sat, 15 Sep 2007 09:39:23 +0000
changeset 8083 afe0c1088793
parent 8082 15235b938558
child 8084 07d54cc15596
(svn r11112) -Fix (r11107) [FS#1229]: in some cases one could destroy (parts of) buildings when building tunnels.
src/tunnelbridge_cmd.cpp
--- a/src/tunnelbridge_cmd.cpp	Sat Sep 15 00:49:44 2007 +0000
+++ b/src/tunnelbridge_cmd.cpp	Sat Sep 15 09:39:23 2007 +0000
@@ -532,17 +532,29 @@
 
 	/* slope of end tile must be complementary to the slope of the start tile */
 	if (end_tileh != ComplementSlope(start_tileh)) {
-		/* Some (rail) track bits might be terraformed into the correct direction,
-		 * but that would still leave tracks on foundation. Therefor excavation will
-		 * always fail for rail tiles. On the other hand, for road tiles it might
-		 * succeed when there is only one road bit on the tile, but then that road
-		 * bit is removed leaving a clear tile.
-		 * This therefor preserves the behaviour that half road tiles are always removable.
+		/*
+		 * A lot of things can be autosloped, but then there is still a structure with
+		 * on top of a tunnel entrance which is bad. Therefor we disallow those.
+		 * Furthermore half road bits (not tram bits) can always be removed, so we
+		 * need to preserve that behaviour here too.
 		 */
-		if (IsTileType(end_tile, MP_RAILWAY)) return_cmd_error(STR_1008_MUST_REMOVE_RAILROAD_TRACK);
+		switch (GetTileType(end_tile)) {
+			default: return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
 
-		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
-		if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
+			/* Tiles that can be (safely) "auto" terraformed for tunnels */
+			case MP_ROAD:
+				if (GetRoadTileType(end_tile) != ROAD_TILE_NORMAL ||       // Depots and crossings can't be removed
+						(GetRoadTypes(end_tile) & ROADTYPES_TRAMHWAY) != 0 ||      // Half tram bits must not be removed
+						COUNTBITS(GetRoadBits(end_tile, ROADTYPE_ROAD)) > 1) { // Non-half road bits must not be removed either
+					return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
+				}
+				/* FALL THROUGH */
+			case MP_CLEAR:
+			case MP_TREES:
+				ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
+				if (CmdFailed(ret)) return_cmd_error(STR_5005_UNABLE_TO_EXCAVATE_LAND);
+				break;
+		}
 	} else {
 		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 		if (CmdFailed(ret)) return ret;