(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
authorsmatz
Sat, 16 Feb 2008 17:54:29 +0000
changeset 9077 dbb5f2dc2414
parent 9076 02117bd3ee61
child 9078 938677a99073
(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town
src/town_cmd.cpp
--- a/src/town_cmd.cpp	Sat Feb 16 17:10:14 2008 +0000
+++ b/src/town_cmd.cpp	Sat Feb 16 17:54:29 2008 +0000
@@ -1651,10 +1651,11 @@
  * Checks if a house can be built here. Important is slope, bridge above
  * and ability to clear the land.
  * @param tile tile to check
+ * @param town town that is checking
  * @param noslope are slopes (foundations) allowed?
  * @return true iff house can be built here
  */
-static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
+static inline bool CanBuildHouseHere(TileIndex tile, TownID town, bool noslope)
 {
 	/* cannot build on these slopes... */
 	Slope slope = GetTileSlope(tile, NULL);
@@ -1663,6 +1664,9 @@
 	/* building under a bridge? */
 	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false;
 
+	/* do not try to build over house owned by another town */
+	if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return false;
+
 	/* can we clear the land? */
 	return CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR));
 }
@@ -1671,14 +1675,15 @@
 /**
  * Checks if a house can be built at this tile, must have the same max z as parameter.
  * @param tile tile to check
+ * @param town town that is checking
  * @param z max z of this tile so more parts of a house are at the same height (with foundation)
  * @param noslope are slopes (foundations) allowed?
  * @return true iff house can be built here
  * @see CanBuildHouseHere()
  */
-static inline bool CheckBuildHouseSameZ(TileIndex tile, uint z, bool noslope)
+static inline bool CheckBuildHouseSameZ(TileIndex tile, TownID town, uint z, bool noslope)
 {
-	if (!CanBuildHouseHere(tile, noslope)) return false;
+	if (!CanBuildHouseHere(tile, town, noslope)) return false;
 
 	/* if building on slopes is allowed, there will be flattening foundation (to tile max z) */
 	if (GetTileMaxZ(tile) != z) return false;
@@ -1690,19 +1695,20 @@
 /**
  * Checks if a house of size 2x2 can be built at this tile
  * @param tile tile, N corner
+ * @param town town that is checking
  * @param z maximum tile z so all tile have the same max z
  * @param noslope are slopes (foundations) allowed?
  * @return true iff house can be built
  * @see CheckBuildHouseSameZ()
  */
-static bool CheckFree2x2Area(TileIndex tile, uint z, bool noslope)
+static bool CheckFree2x2Area(TileIndex tile, TownID town, uint z, bool noslope)
 {
 	/* we need to check this tile too because we can be at different tile now */
-	if (!CheckBuildHouseSameZ(tile, z, noslope)) return false;
+	if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false;
 
 	for (DiagDirection d = DIAGDIR_SE; d < DIAGDIR_END; d++) {
 		tile += TileOffsByDiagDir(d);
-		if (!CheckBuildHouseSameZ(tile, z, noslope)) return false;
+		if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false;
 	}
 
 	return true;
@@ -1782,10 +1788,10 @@
 	/* 'tile' is already checked in BuildTownHouse() - CanBuildHouseHere() and slope test */
 
 	TileIndex tile2 = *tile + TileOffsByDiagDir(second);
-	if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, maxz, noslope)) return true;
+	if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) return true;
 
 	tile2 = *tile + TileOffsByDiagDir(ReverseDiagDir(second));
-	if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, maxz, noslope)) {
+	if (TownLayoutAllowsHouseHere(t, tile2) && CheckBuildHouseSameZ(tile2, t->index, maxz, noslope)) {
 		*tile = tile2;
 		return true;
 	}
@@ -1807,7 +1813,7 @@
 	TileIndex tile2 = *tile;
 
 	for (DiagDirection d = DIAGDIR_SE;;d++) { // 'd' goes through DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_END
-		if (TownLayoutAllows2x2HouseHere(t, tile2) && CheckFree2x2Area(tile2, maxz, noslope)) {
+		if (TownLayoutAllows2x2HouseHere(t, tile2) && CheckFree2x2Area(tile2, t->index, maxz, noslope)) {
 			*tile = tile2;
 			return true;
 		}
@@ -1831,7 +1837,7 @@
 	if (!TownLayoutAllowsHouseHere(t, tile)) return false;
 
 	/* no house allowed at all, bail out */
-	if (!CanBuildHouseHere(tile, false)) return false;
+	if (!CanBuildHouseHere(tile, t->index, false)) return false;
 
 	uint z;
 	Slope slope = GetTileSlope(tile, &z);