src/clear_cmd.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6683 7ec558346172
child 6720 35756db7e577
--- a/src/clear_cmd.cpp	Tue Mar 27 23:27:27 2007 +0000
+++ b/src/clear_cmd.cpp	Sat Jun 02 19:59:29 2007 +0000
@@ -79,7 +79,7 @@
 
 	if (count >= 625) return;
 
-	for (t = ts->tile_table; count != 0; count--,t++) {
+	for (t = ts->tile_table; count != 0; count--, t++) {
 		if (*t == tile) return;
 	}
 
@@ -141,7 +141,7 @@
 		}
 	}
 
-	ret = DoCommand(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
+	ret = DoCommand(tile, 0, 0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
 	if (CmdFailed(ret)) {
 		_terraform_err_tile = tile;
@@ -215,8 +215,8 @@
 			tile += ToTileIndexDiff(*ttm);
 
 			r = TerraformGetHeightOfTile(ts, tile);
-			if (r != height && r-direction != height && r+direction != height) {
-				if (!TerraformTileHeight(ts, tile, r+direction))
+			if (r != height && r - direction != height && r + direction != height) {
+				if (!TerraformTileHeight(ts, tile, r + direction))
 					return false;
 			}
 		}
@@ -291,24 +291,24 @@
 		for (count = ts.tile_table_count; count != 0; count--, ti++) {
 			TileIndex tile = *ti;
 
-			if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) {
+			uint z_min = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
+			uint z_max = z_min;
+			uint t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
+			z_min = min(z_min, t);
+			z_max = max(z_max, t);
+			t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
+			z_min = min(z_min, t);
+			z_max = max(z_max, t);
+			t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
+			z_min = min(z_min, t);
+			z_max = max(z_max, t);
+
+			if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) &&
+					GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) {
 				return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
 			}
-
-			if (direction == -1) {
-				uint z, t;
-
-				z = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
-				t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
-				if (t <= z) z = t;
-				t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
-				if (t <= z) z = t;
-				t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
-				if (t <= z) z = t;
-
-				if (IsTunnelInWay(tile, z * TILE_HEIGHT)) {
-					return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
-				}
+			if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) {
+				return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
 			}
 		}
 	}
@@ -382,8 +382,8 @@
 	if (ey < sy) Swap(ey, sy);
 	tile = TileXY(sx, sy);
 
-	size_x = ex-sx+1;
-	size_y = ey-sy+1;
+	size_x = ex - sx + 1;
+	size_y = ey - sy + 1;
 
 	money = GetAvailableMoneyForCommand();
 	cost = 0;
@@ -764,7 +764,7 @@
 	/* not used */
 }
 
-static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode)
+static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_mode)
 {
 	return 0;
 }