@@ -1651,10 +1651,11 @@ static void MakeTownHouse(TileIndex t, T
* 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(Til
/* 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(Til
/**
* Checks if a house can be built at this tile, must have the same max z as parameter.
* @param z max z of this tile so more parts of a house are at the same height (with foundation)
* @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(
* Checks if a house of size 2x2 can be built at this tile
* @param tile tile, N corner
* @param z maximum tile z so all tile have the same max z
* @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);
return true;
@@ -1782,10 +1788,10 @@ static bool CheckTownBuild2House(TileInd
/* '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;
@@ -1807,7 +1813,7 @@ static bool CheckTownBuild2x2House(TileI
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)) {
@@ -1831,7 +1837,7 @@ static bool BuildTownHouse(Town *t, 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);
Status change: