File diff r26089:2283e9229bb0 → r26090:5a592dbf1c28
src/town_cmd.cpp
Show inline comments
 
@@ -938,8 +938,8 @@ static bool IsRoadAllowedHere(Town *t, T
 
		 * If that fails clear the land, and if that fails exit.
 
		 * This is to make sure that we can build a road here later. */
 
		RoadType rt = GetTownRoadType(t);
 
		if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Failed() &&
 
				DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Failed()) {
 
		if (DoCommand(DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0).Failed() &&
 
				DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Failed()) {
 
			return false;
 
		}
 
	}
 
@@ -956,8 +956,8 @@ 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);
 
				res = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND,
 
						tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0);
 
			}
 
			if (res.Failed() && Chance16(1, 3)) {
 
				/* We can consider building on the slope, though. */
 
@@ -973,9 +973,9 @@ static bool TerraformTownTile(TileIndex 
 
{
 
	assert(tile < MapSize());
 

	
 
	CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
	CommandCost r = DoCommand(DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND, tile, edges, dir);
 
	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);
 
	DoCommand(DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND, tile, edges, dir);
 
	return true;
 
}
 

	
 
@@ -1107,7 +1107,7 @@ static bool GrowTownWithExtraHouse(Town 
 
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
 
{
 
	RoadType rt = GetTownRoadType(t);
 
	if (DoCommand(tile, rcmd | (rt << 4), t->index, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded()) {
 
	if (DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, tile, rcmd | (rt << 4), t->index).Succeeded()) {
 
		_grow_town_result = GROWTH_SUCCEED;
 
		return true;
 
	}
 
@@ -1154,7 +1154,7 @@ static bool CanRoadContinueIntoNextTile(
 
	if (IsTileType(next_tile, MP_RAILWAY) && !_settings_game.economy.allow_town_level_crossings) return false;
 

	
 
	/* If a road tile can be built, the construction is allowed. */
 
	return DoCommand(next_tile, rcmd | (rt << 4), t->index, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded();
 
	return DoCommand(DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD, next_tile, rcmd | (rt << 4), t->index).Succeeded();
 
}
 

	
 
/**
 
@@ -1222,8 +1222,8 @@ static bool GrowTownWithBridge(const Tow
 

	
 
		/* Can we actually build the bridge? */
 
		RoadType rt = GetTownRoadType(t);
 
		if (DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE).Succeeded()) {
 
			DoCommand(tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE);
 
		if (DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE, tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15).Succeeded()) {
 
			DoCommand(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_BRIDGE)), CMD_BUILD_BRIDGE, tile, bridge_tile, bridge_type | rt << 8 | TRANSPORT_ROAD << 15);
 
			_grow_town_result = GROWTH_SUCCEED;
 
			return true;
 
		}
 
@@ -1293,8 +1293,8 @@ static bool GrowTownWithTunnel(const Tow
 

	
 
	/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
 
	RoadType rt = GetTownRoadType(t);
 
	if (DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL).Succeeded()) {
 
		DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL);
 
	if (DoCommand(CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL, tile, rt | (TRANSPORT_ROAD << 8), 0).Succeeded()) {
 
		DoCommand(DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL, tile, rt | (TRANSPORT_ROAD << 8), 0);
 
		_grow_town_result = GROWTH_SUCCEED;
 
		return true;
 
	}
 
@@ -1732,9 +1732,9 @@ static bool GrowTown(Town *t)
 
		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) && IsTileFlat(tile)) {
 
				if (DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
				if (DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded()) {
 
					RoadType rt = GetTownRoadType(t);
 
					DoCommand(tile, GenRandomRoadBits() | (rt << 4), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
 
					DoCommand(DC_EXEC | DC_AUTO, CMD_BUILD_ROAD, tile, GenRandomRoadBits() | (rt << 4), t->index);
 
					cur_company.Restore();
 
					return true;
 
				}
 
@@ -2179,7 +2179,7 @@ static Town *CreateRandomTown(uint attem
 
		if (t->cache.population > 0) return t;
 

	
 
		Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 
		[[maybe_unused]] CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
 
		[[maybe_unused]] CommandCost rc = DoCommand(DC_EXEC, CMD_DELETE_TOWN, t->xy, t->index, 0);
 
		cur_company.Restore();
 
		assert(rc.Succeeded());
 

	
 
@@ -2280,7 +2280,7 @@ HouseZonesBits GetTownRadiusGroup(const 
 
 */
 
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
 
{
 
	[[maybe_unused]] CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
 
	[[maybe_unused]] CommandCost cc = DoCommand(DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	assert(cc.Succeeded());
 

	
 
	IncreaseBuildingCount(t, type);
 
@@ -2337,7 +2337,7 @@ static inline bool CanBuildHouseHere(Til
 
	if (IsBridgeAbove(tile)) return false;
 

	
 
	/* can we clear the land? */
 
	return DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR).Succeeded();
 
	return DoCommand(DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR, tile, 0, 0).Succeeded();
 
}
 

	
 

	
 
@@ -2972,7 +2972,7 @@ CommandCost CmdDeleteTown(TileIndex tile
 
			/* Non-oil rig stations are always a problem. */
 
			if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR;
 
			/* We can only automatically delete oil rigs *if* there's no vehicle on them. */
 
			CommandCost ret = DoCommand(st->airport.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, st->airport.tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 
@@ -2988,7 +2988,7 @@ CommandCost CmdDeleteTown(TileIndex tile
 
	 * tile was already deleted earlier in the loop. */
 
	for (TileIndex current_tile = 0; current_tile < MapSize(); ++current_tile) {
 
		if (IsTileType(current_tile, MP_TUNNELBRIDGE) && TestTownOwnsBridge(current_tile, t)) {
 
			CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 
@@ -3031,7 +3031,7 @@ CommandCost CmdDeleteTown(TileIndex tile
 
				break;
 
		}
 
		if (try_clear) {
 
			CommandCost ret = DoCommand(current_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			CommandCost ret = DoCommand(flags, CMD_LANDSCAPE_CLEAR, current_tile, 0, 0);
 
			if (ret.Failed()) return ret;
 
		}
 
	}
 
@@ -3107,7 +3107,7 @@ static CommandCost TownActionRoadRebuild
 
static bool TryClearTile(TileIndex tile)
 
{
 
	Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
	CommandCost r = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
	CommandCost r = DoCommand(DC_NONE, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
	cur_company.Restore();
 
	return r.Succeeded();
 
}
 
@@ -3179,7 +3179,7 @@ static CommandCost TownActionBuildStatue
 

	
 
	if (flags & DC_EXEC) {
 
		Backup<CompanyID> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 
		DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		DoCommand(DC_EXEC, CMD_LANDSCAPE_CLEAR, statue_data.best_position, 0, 0);
 
		cur_company.Restore();
 
		BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t);
 
		SetBit(t->statues, _current_company); // Once found and built, "inform" the Town.
 
@@ -3786,7 +3786,7 @@ static CommandCost TerraformTile_Town(Ti
 
		}
 
	}
 

	
 
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	return DoCommand(flags, CMD_LANDSCAPE_CLEAR, tile, 0, 0);
 
}
 

	
 
/** Tile callback functions for a town */