|
@@ -777,14 +777,14 @@ static bool IsRoadAllowedHere(Town *t, T
|
|
|
for (;;) {
|
|
|
/* Check if there already is a road at this point? */
|
|
|
if (GetTownRoadBits(tile) == ROAD_NONE) {
|
|
|
/* No, try if we are able to build a road piece there.
|
|
|
* 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 == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD)) &&
|
|
|
CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
|
|
|
if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD).Failed() &&
|
|
|
DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR).Failed())
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
cur_slope = _settings_game.construction.build_on_slopes ? GetFoundationSlope(tile, NULL) : GetTileSlope(tile, NULL);
|
|
|
bool ret = !IsNeighborRoadTile(tile, dir, t->layout == TL_ORIGINAL ? 1 : 2);
|
|
|
if (cur_slope == SLOPE_FLAT) return ret;
|
|
@@ -797,13 +797,13 @@ static bool IsRoadAllowedHere(Town *t, T
|
|
|
CommandCost res = CMD_ERROR;
|
|
|
if (!_generating_world && Chance16(1, 10)) {
|
|
|
/* Note: Do not replace "^ SLOPE_ELEVATED" with ComplementSlope(). The slope might be steep. */
|
|
|
res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0,
|
|
|
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
|
|
}
|
|
|
if (CmdFailed(res) && Chance16(1, 3)) {
|
|
|
if (res.Failed() && Chance16(1, 3)) {
|
|
|
/* We can consider building on the slope, though. */
|
|
|
return ret;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -813,13 +813,13 @@ static bool IsRoadAllowedHere(Town *t, T
|
|
|
|
|
|
static bool TerraformTownTile(TileIndex tile, int edges, int dir)
|
|
|
{
|
|
|
assert(tile < MapSize());
|
|
|
|
|
|
CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
|
|
if (CmdFailed(r) || r.GetCost() >= (_price[PR_TERRAFORM] + 2) * 8) return false;
|
|
|
if (r.Failed() || r.GetCost() >= (_price[PR_TERRAFORM] + 2) * 8) return false;
|
|
|
DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static void LevelTownLand(TileIndex tile)
|
|
|
{
|
|
@@ -945,13 +945,13 @@ static bool GrowTownWithExtraHouse(Town
|
|
|
* @param tile The current tile
|
|
|
* @param rcmd The RoadBits we want to build on the tile
|
|
|
* @return true if the RoadBits have been added else false
|
|
|
*/
|
|
|
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
|
|
|
{
|
|
|
if (CmdSucceeded(DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD))) {
|
|
|
if (DoCommand(tile, rcmd, t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded()) {
|
|
|
_grow_town_result = GROWTH_SUCCEED;
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -997,13 +997,13 @@ static bool GrowTownWithBridge(const Tow
|
|
|
if (bridge_length == 1) return false;
|
|
|
|
|
|
for (uint8 times = 0; times <= 22; times++) {
|
|
|
byte bridge_type = RandomRange(MAX_BRIDGES - 1);
|
|
|
|
|
|
/* Can we actually build the bridge? */
|
|
|
if (CmdSucceeded(DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_AUTO, CMD_BUILD_BRIDGE))) {
|
|
|
if (DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_AUTO, CMD_BUILD_BRIDGE).Succeeded()) {
|
|
|
DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
|
|
|
_grow_town_result = GROWTH_SUCCEED;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
/* Quit if it selecting an appropiate bridge type fails a large number of times. */
|
|
@@ -1314,13 +1314,13 @@ static bool GrowTown(Town *t)
|
|
|
* clearing some land and then building a road there. */
|
|
|
if (_settings_game.economy.allow_town_roads || _generating_world) {
|
|
|
tile = t->xy;
|
|
|
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
|
|
|
/* Only work with plain land that not already has a house */
|
|
|
if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) {
|
|
|
if (CmdSucceeded(DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR))) {
|
|
|
if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded()) {
|
|
|
DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
|
|
|
_current_company = old_company;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
|
|
@@ -1549,13 +1549,13 @@ CommandCost CmdFoundTown(TileIndex tile,
|
|
|
|
|
|
/* Allocate town struct */
|
|
|
if (!Town::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_TOWNS);
|
|
|
|
|
|
if (!random) {
|
|
|
CommandCost ret = TownCanBePlacedHere(tile);
|
|
|
if (CmdFailed(ret)) return ret;
|
|
|
if (ret.Failed()) return ret;
|
|
|
}
|
|
|
|
|
|
static const byte price_mult[][TS_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }};
|
|
|
/* multidimensional arrays have to have defined length of non-first dimension */
|
|
|
assert_compile(lengthof(price_mult[0]) == 4);
|
|
|
|
|
@@ -1737,13 +1737,13 @@ static Town *CreateRandomTown(uint attem
|
|
|
if (IsTileType(tile, MP_WATER)) {
|
|
|
tile = FindNearestGoodCoastalTownSpot(tile, layout);
|
|
|
if (tile == INVALID_TILE) continue;
|
|
|
}
|
|
|
|
|
|
/* Make sure town can be placed here */
|
|
|
if (CmdFailed(TownCanBePlacedHere(tile))) continue;
|
|
|
if (TownCanBePlacedHere(tile).Failed()) continue;
|
|
|
|
|
|
/* Allocate a town struct */
|
|
|
Town *t = new Town(tile);
|
|
|
|
|
|
DoCreateTown(t, tile, townnameparts, size, city, layout, false);
|
|
|
|
|
@@ -1834,13 +1834,13 @@ HouseZonesBits GetTownRadiusGroup(const
|
|
|
* @pre house can be built here
|
|
|
*/
|
|
|
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
|
|
|
{
|
|
|
CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
|
|
|
|
|
|
assert(CmdSucceeded(cc));
|
|
|
assert(cc.Succeeded());
|
|
|
|
|
|
IncreaseBuildingCount(t, type);
|
|
|
MakeHouseTile(tile, t->index, counter, stage, type, random_bits);
|
|
|
if (HouseSpec::Get(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(tile);
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
@@ -1886,13 +1886,13 @@ static inline bool CanBuildHouseHere(Til
|
|
|
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));
|
|
|
return DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Checks if a house can be built at this tile, must have the same max z as parameter.
|
|
|
* @param tile tile to check
|
|
@@ -2379,13 +2379,13 @@ static bool DoBuildStatueOfCompany(TileI
|
|
|
|
|
|
CompanyID old = _current_company;
|
|
|
_current_company = OWNER_NONE;
|
|
|
CommandCost r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
|
|
_current_company = old;
|
|
|
|
|
|
if (CmdFailed(r)) return false;
|
|
|
if (r.Failed()) return false;
|
|
|
|
|
|
MakeStatue(tile, _current_company, town_id);
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
|
|
|
return true;
|
|
|
}
|