(svn r3813) Simplify strange control flow
authortron
Fri, 10 Mar 2006 12:57:42 +0000
changeset 3177 b392738ba194
parent 3176 c125ec95763a
child 3178 c275826135da
(svn r3813) Simplify strange control flow
water_cmd.c
--- a/water_cmd.c	Fri Mar 10 11:27:52 2006 +0000
+++ b/water_cmd.c	Fri Mar 10 12:57:42 2006 +0000
@@ -210,7 +210,7 @@
  */
 int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 {
-	int32 ret, cost;
+	int32 cost;
 	int size_x, size_y;
 	int sx, sy;
 
@@ -234,7 +234,6 @@
 
 	cost = 0;
 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
-		ret = 0;
 		if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
 
 			// can't make water of water!
@@ -246,28 +245,29 @@
 					if (_m[tile].m5 & 0x20) // transport route under bridge
 						return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
 
-					if (_m[tile].m5 & 0x18) // already water under bridge
+					if (_m[tile].m5 & 0x18) { // already water under bridge
 						return_cmd_error(STR_1007_ALREADY_BUILT);
-				/* no bridge? then try to clear it. */
-				} else
-					ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+					}
 
-				if (CmdFailed(ret)) return CMD_ERROR;
-				cost += ret;
-
-				/* execute modifications */
-				if (flags & DC_EXEC) {
-					if (IsTileType(tile, MP_TUNNELBRIDGE)) {
+					if (flags & DC_EXEC) {
 						// change owner to OWNER_WATER and set land under bridge bit to water
 						ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
-					} else {
+					}
+				} else {
+					/* no bridge, try to clear it. */
+					int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+
+					if (CmdFailed(ret)) return CMD_ERROR;
+					cost += ret;
+
+					if (flags & DC_EXEC) {
 						MakeWater(tile);
 						MarkTileDirtyByTile(tile);
 					}
-					// mark the tiles around dirty too
-					MarkTilesAroundDirty(tile);
 				}
 
+				if (flags & DC_EXEC) MarkTilesAroundDirty(tile);
+
 				cost += _price.clear_water;
 			}
 	} END_TILE_LOOP(tile, size_x, size_y, 0);