summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/town_cmd.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 7ffbeaf9e..6ef67f03e 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1651,10 +1651,11 @@ static void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, Hou
* 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 @@ static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
/* 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 @@ static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
/**
* 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 @@ static inline bool CheckBuildHouseSameZ(TileIndex tile, uint z, bool noslope)
/**
* 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 @@ static bool CheckTownBuild2House(TileIndex *tile, Town *t, uint maxz, bool noslo
/* '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 @@ static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, uint maxz, bool nos
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 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
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);