src/town_cmd.cpp
branchNewGRF_ports
changeset 6868 7eb395287b3d
parent 6800 6c09e1e86fcb
child 6870 ca3fd1fbe311
--- a/src/town_cmd.cpp	Mon Aug 27 16:28:33 2007 +0000
+++ b/src/town_cmd.cpp	Sun Sep 02 11:58:58 2007 +0000
@@ -647,7 +647,7 @@
  * @return true if one of the neighboring tiles at the
  *  given distance is a road tile else
  */
-static bool NeighborIsRoadTile(TileIndex tile, int dir, RoadBlockTitleDistance dist_multi)
+static bool IsNeighborRoadTile(TileIndex tile, int dir, RoadBlockTitleDistance dist_multi)
 {
 	return (HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 1]))), dir ^ 2) ||
 			HASBIT(GetTownRoadMask(TILE_ADD(tile, dist_multi * ToTileIndexDiff(_roadblock_tileadd[dir + 3]))), dir ^ 2) ||
@@ -672,7 +672,7 @@
 			/* No, try to build one in the direction.
 			 * if that fails clear the land, and if that fails exit.
 			 * This is to make sure that we can build a road here later. */
-			if (CmdFailed(DoCommand(tile, (dir & 1 ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) &&
+			if (CmdFailed(DoCommand(tile, (dir & ROAD_NW ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) &&
 					CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
 				return false;
 		}
@@ -685,17 +685,17 @@
 				default: NOT_REACHED();
 
 				case TL_ORIGINAL: /* Disallow the road if any neighboring tile has a road (distance: 1) */
-					return !NeighborIsRoadTile(tile, dir, RB_TILE_DIST1);
+					return !IsNeighborRoadTile(tile, dir, RB_TILE_DIST1);
 
 				case TL_BETTER_ROADS: /* Disallow the road if any neighboring tile has a road (distance: 1 and 2). */
-					return !(NeighborIsRoadTile(tile, dir, RB_TILE_DIST1) ||
-							NeighborIsRoadTile(tile, dir, RB_TILE_DIST2));
+					return !(IsNeighborRoadTile(tile, dir, RB_TILE_DIST1) ||
+							IsNeighborRoadTile(tile, dir, RB_TILE_DIST2));
 			}
 		}
 
 		/* If the tile is not a slope in the right direction, then
 		 * maybe terraform some. */
-		k = (dir & 1) ? SLOPE_NE : SLOPE_NW;
+		k = (dir & ROAD_NW) ? SLOPE_NE : SLOPE_NW;
 		if (k != slope && ComplementSlope(k) != slope) {
 			uint32 r = Random();
 
@@ -706,6 +706,7 @@
 					res = DoCommand(tile, slope, 0, DC_EXEC | DC_AUTO | DC_NO_WATER,
 					                      CMD_TERRAFORM_LAND);
 				} else {
+					/* Note: Do not replace " ^ 0xF" with ComplementSlope(). The slope might be steep. */
 					res = DoCommand(tile, slope ^ 0xF, 1, DC_EXEC | DC_AUTO | DC_NO_WATER,
 					                      CMD_TERRAFORM_LAND);
 				}
@@ -829,7 +830,7 @@
  * @return true if there are more than 2 house tiles next
  *  to the current one
  */
-static bool NeighborsAreHouseTiles(TileIndex tile)
+static bool AreNeighborsHouseTiles(TileIndex tile)
 {
 	uint counter = 0; ///< counts the house neighbor tiles
 
@@ -938,7 +939,7 @@
 					 *  at any side of the new road. */
 				}
 
-				rcmd = (RoadBits)((1 << a) + (1 << b));
+				rcmd = (RoadBits)((ROAD_NW << a) + (ROAD_NW << b));
 				break;
 		}
 
@@ -960,7 +961,7 @@
 
 			case TL_BETTER_ROADS:
 			case TL_ORIGINAL:
-				rcmd = (RoadBits)(1 << (block ^ 2));
+				rcmd = (RoadBits)(ROAD_NW << (block ^ 2));
 				break;
 		}
 	} else {
@@ -999,7 +1000,7 @@
 			case TL_3X3_GRID: /* Use 2x2 grid afterwards! */
 				/* Fill gap if house has enougth neighbors */
 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
-				if (NeighborsAreHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
+				if (AreNeighborsHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
 					_grow_town_result = -1;
 				}
 
@@ -1011,7 +1012,7 @@
 			case TL_BETTER_ROADS: /* Use original afterwards! */
 				/* Fill gap if house has enougth neighbors */
 				tmptile2 = TILE_ADD(tmptile, ToTileIndexDiff(_roadblock_tileadd[i]));
-				if (NeighborsAreHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
+				if (AreNeighborsHouseTiles(tmptile2) && BuildTownHouse(t1, tmptile2)) {
 					_grow_town_result = -1;
 				}
 
@@ -1039,7 +1040,7 @@
 		}
 
 		_grow_town_result = 0;
-		rcmd = (RoadBits)(1 << i);
+		rcmd = (RoadBits)(ROAD_NW << i);
 	}
 
 	/* Return if a water tile */
@@ -1083,19 +1084,17 @@
 
 	/* Quit if it selecting an appropiate bridge type fails a large number of times. */
 	j = 22;
-	{
-		int32 bridge_len = GetBridgeLength(tile, tmptile);
-		do {
-			byte bridge_type = RandomRange(MAX_BRIDGES - 1);
-			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
-				if (CmdSucceeded(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE)))
-					_grow_town_result = -1;
-
-				/* obviously, if building any bridge would fail, there is no need to try other bridge-types */
-				return;
-			}
-		} while (--j != 0);
-	}
+	do {
+		byte bridge_type = RandomRange(MAX_BRIDGES - 1);
+		/* Can we actually build the bridge? */
+		if (CmdSucceeded(DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_AUTO, CMD_BUILD_BRIDGE))) {
+			DoCommand(tile, tmptile, bridge_type | ((0x80 | ROADTYPES_ROAD) << 8), DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
+				_grow_town_result = -1;
+
+			/* obviously, if building any bridge would fail, there is no need to try other bridge-types */
+			return;
+		}
+	} while (--j != 0);
 }
 
 /** Returns "growth" if a house was built, or no if the build failed.
@@ -1137,7 +1136,7 @@
 		/* Exclude the source position from the bitmask
 		 * and return if no more road blocks available */
 		ClrBitT(mask, (block ^ 2));
-		if (mask == 0)
+		if (mask == ROAD_NONE)
 			return _grow_town_result;
 
 		/* Select a random bit from the blockmask, walk a step
@@ -2302,6 +2301,11 @@
 	_town_sort_dirty = true;
 }
 
+static CommandCost TerraformTile_Town(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
+{
+	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+}
+
 extern const TileTypeProcs _tile_type_town_procs = {
 	DrawTile_Town,           /* draw_tile_proc */
 	GetSlopeZ_Town,          /* get_slope_z_proc */
@@ -2316,6 +2320,7 @@
 	NULL,                    /* get_produced_cargo_proc */
 	NULL,                    /* vehicle_enter_tile_proc */
 	GetFoundation_Town,      /* get_foundation_proc */
+	TerraformTile_Town,      /* terraform_tile_proc */
 };