1
0
Fork 0

(svn r12162) -Fix [FS#1757]: towns shouldn't build over houses owned by another town

release/0.6
smatz 2008-02-16 17:54:29 +00:00
parent 4b7a812e55
commit ebe03109ad
1 changed files with 16 additions and 10 deletions

View File

@ -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 * Checks if a house can be built here. Important is slope, bridge above
* and ability to clear the land. * and ability to clear the land.
* @param tile tile to check * @param tile tile to check
* @param town town that is checking
* @param noslope are slopes (foundations) allowed? * @param noslope are slopes (foundations) allowed?
* @return true iff house can be built here * @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... */ /* cannot build on these slopes... */
Slope slope = GetTileSlope(tile, NULL); Slope slope = GetTileSlope(tile, NULL);
@ -1663,6 +1664,9 @@ static inline bool CanBuildHouseHere(TileIndex tile, bool noslope)
/* building under a bridge? */ /* building under a bridge? */
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return false; 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? */ /* can we clear the land? */
return CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR)); 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. * Checks if a house can be built at this tile, must have the same max z as parameter.
* @param tile tile to check * @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 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? * @param noslope are slopes (foundations) allowed?
* @return true iff house can be built here * @return true iff house can be built here
* @see CanBuildHouseHere() * @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 building on slopes is allowed, there will be flattening foundation (to tile max z) */
if (GetTileMaxZ(tile) != z) return false; 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 * Checks if a house of size 2x2 can be built at this tile
* @param tile tile, N corner * @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 z maximum tile z so all tile have the same max z
* @param noslope are slopes (foundations) allowed? * @param noslope are slopes (foundations) allowed?
* @return true iff house can be built * @return true iff house can be built
* @see CheckBuildHouseSameZ() * @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 */ /* 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++) { for (DiagDirection d = DIAGDIR_SE; d < DIAGDIR_END; d++) {
tile += TileOffsByDiagDir(d); tile += TileOffsByDiagDir(d);
if (!CheckBuildHouseSameZ(tile, z, noslope)) return false; if (!CheckBuildHouseSameZ(tile, town, z, noslope)) return false;
} }
return true; 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 */ /* 'tile' is already checked in BuildTownHouse() - CanBuildHouseHere() and slope test */
TileIndex tile2 = *tile + TileOffsByDiagDir(second); 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)); 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; *tile = tile2;
return true; return true;
} }
@ -1807,7 +1813,7 @@ static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, uint maxz, bool nos
TileIndex tile2 = *tile; TileIndex tile2 = *tile;
for (DiagDirection d = DIAGDIR_SE;;d++) { // 'd' goes through DIAGDIR_SE, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_END 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; *tile = tile2;
return true; return true;
} }
@ -1831,7 +1837,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
if (!TownLayoutAllowsHouseHere(t, tile)) return false; if (!TownLayoutAllowsHouseHere(t, tile)) return false;
/* no house allowed at all, bail out */ /* no house allowed at all, bail out */
if (!CanBuildHouseHere(tile, false)) return false; if (!CanBuildHouseHere(tile, t->index, false)) return false;
uint z; uint z;
Slope slope = GetTileSlope(tile, &z); Slope slope = GetTileSlope(tile, &z);