Changeset - r14304:dc9cb5b9e881
[Not reviewed]
master
0 24 0
rubidium - 14 years ago 2010-01-18 22:57:21
rubidium@openttd.org
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
24 files changed with 104 insertions and 128 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_object.cpp
Show inline comments
 
@@ -210,13 +210,13 @@ bool AIObject::DoCommand(TileIndex tile,
 
	bool estimate_only = GetDoCommandMode() != NULL && !GetDoCommandMode()();
 

	
 
	/* Try to perform the command. */
 
	CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, _networking ? CcAI : NULL, text, false, estimate_only);
 

	
 
	/* We failed; set the error and bail out */
 
	if (::CmdFailed(res)) {
 
	if (res.Failed()) {
 
		res.SetGlobalErrorMessage();
 
		SetLastError(AIError::StringToError(_error_message));
 
		return false;
 
	}
 

	
 
	/* No error, then clear it. */
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -118,13 +118,13 @@
 
/* static */ int AIVehicle::GetRefitCapacity(VehicleID vehicle_id, CargoID cargo)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return -1;
 
	if (!AICargo::IsValidCargo(cargo)) return -1;
 

	
 
	CommandCost res = ::DoCommand(0, vehicle_id, cargo, DC_QUERY_COST, GetCmdRefitVeh(::Vehicle::Get(vehicle_id)));
 
	return CmdSucceeded(res) ? _returned_refit_capacity : -1;
 
	return res.Succeeded() ? _returned_refit_capacity : -1;
 
}
 

	
 
/* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo)
 
{
 
	EnforcePrecondition(false, IsValidVehicle(vehicle_id) && AICargo::IsValidCargo(cargo));
 

	
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1216,13 +1216,13 @@ void HandleMissingAircraftOrders(Aircraf
 
		CompanyID old_company = _current_company;
 

	
 
		_current_company = v->owner;
 
		ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		_current_company = old_company;
 

	
 
		if (CmdFailed(ret)) CrashAirplane(v);
 
		if (ret.Failed()) CrashAirplane(v);
 
	} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
 
		v->current_order.Free();
 
	}
 
}
 

	
 

	
src/bridge_gui.cpp
Show inline comments
 
@@ -383,13 +383,13 @@ void ShowBuildBridgeWindow(TileIndex sta
 
	/* only query bridge building possibility once, result is the same for all bridges!
 
	 * returns CMD_ERROR on failure, and price on success */
 
	StringID errmsg = INVALID_STRING_ID;
 
	CommandCost ret = DoCommand(end, start, type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
 

	
 
	GUIBridgeList *bl = NULL;
 
	if (CmdFailed(ret)) {
 
	if (ret.Failed()) {
 
		errmsg = _error_message;
 
	} else {
 
		/* check which bridges can be built */
 
		const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
 

	
 
		bl = new GUIBridgeList();
src/command.cpp
Show inline comments
 
@@ -408,13 +408,13 @@ CommandCost DoCommand(TileIndex tile, ui
 

	
 
	/* only execute the test call if it's toplevel, or we're not execing. */
 
	if (_docommand_recursive == 1 || !(flags & DC_EXEC) ) {
 
		SetTownRatingTestMode(true);
 
		res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
 
		SetTownRatingTestMode(false);
 
		if (CmdFailed(res)) {
 
		if (res.Failed()) {
 
			goto error;
 
		}
 

	
 
		if (_docommand_recursive == 1 &&
 
				!(flags & DC_QUERY_COST) &&
 
				!(flags & DC_BANKRUPT) &&
 
@@ -428,13 +428,13 @@ CommandCost DoCommand(TileIndex tile, ui
 
		}
 
	}
 

	
 
	/* Execute the command here. All cost-relevant functions set the expenses type
 
	 * themselves to the cost object at some point */
 
	res = proc(tile, flags, p1, p2, text);
 
	if (CmdFailed(res)) {
 
	if (res.Failed()) {
 
error:
 
		res.SetGlobalErrorMessage();
 
		_docommand_recursive--;
 
		return CMD_ERROR;
 
	}
 

	
 
@@ -504,13 +504,13 @@ bool DoCommandP(TileIndex tile, uint32 p
 

	
 
	/* Where to show the message? */
 
	int x = TileX(tile) * TILE_SIZE;
 
	int y = TileY(tile) * TILE_SIZE;
 

	
 
	CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only);
 
	if (CmdFailed(res)) {
 
	if (res.Failed()) {
 
		res.SetGlobalErrorMessage();
 

	
 
		/* Only show the error when it's for us. */
 
		StringID error_part1 = GB(cmd, 16, 16);
 
		if (estimate_only || (IsLocalCompany() && error_part1 != 0 && my_cmd)) {
 
			ShowErrorMessage(error_part1, _error_message, x, y);
 
@@ -527,13 +527,13 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	}
 

	
 
	if (!estimate_only && !only_sending && callback != NULL) {
 
		callback(res, tile, p1, p2);
 
	}
 

	
 
	return CmdSucceeded(res);
 
	return res.Succeeded();
 
}
 

	
 

	
 
/**
 
 * Helper to deduplicate the code for returning.
 
 * @param cmd   the command cost to return.
 
@@ -618,13 +618,13 @@ CommandCost DoCommandPInternal(TileIndex
 

	
 
		/* If the command fails, we're doing an estimate
 
		 * or the player does not have enough money
 
		 * (unless it's a command where the test and
 
		 * execution phase might return different costs)
 
		 * we bail out here. */
 
		if (CmdFailed(res) || estimate_only ||
 
		if (res.Failed() || estimate_only ||
 
				(!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
 
			return_dcpi(res, false);
 
		}
 
	}
 

	
 
#ifdef ENABLE_NETWORK
 
@@ -653,14 +653,14 @@ CommandCost DoCommandPInternal(TileIndex
 

	
 
	/* If the test and execution can differ, or we skipped the test
 
	 * we have to check the return of the command. Otherwise we can
 
	 * check whether the test and execution have yielded the same
 
	 * result, i.e. cost and error state are the same. */
 
	if (!test_and_exec_can_differ && !skip_test) {
 
		assert(res.GetCost() == res2.GetCost() && CmdFailed(res) == CmdFailed(res2)); // sanity check
 
	} else if (CmdFailed(res2)) {
 
		assert(res.GetCost() == res2.GetCost() && res.Failed() == res2.Failed()); // sanity check
 
	} else if (res2.Failed()) {
 
		return_dcpi(res2, false);
 
	}
 

	
 
	/* If we're needing more money and we haven't done
 
	 * anything yet, ask for the money! */
 
	if (_additional_cash_required != 0 && res2.GetCost() == 0) {
src/command_func.h
Show inline comments
 
@@ -13,36 +13,12 @@
 
#define COMMAND_FUNC_H
 

	
 
#include "command_type.h"
 
#include "company_type.h"
 

	
 
/**
 
 * Checks if a command failes.
 
 *
 
 * As you see the parameter is not a command but the return value of a command,
 
 * the CommandCost class. This function checks if the command executed by
 
 * the CommandProc function failed and returns true if it does.
 
 *
 
 * @param cost The return value of a CommandProc call
 
 * @return true if the command failes
 
 * @see CmdSucceded
 
 */
 
static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
 

	
 
/**
 
 * Checks if a command succeeded.
 
 *
 
 * As #CmdFailed this function checks if a command succeeded
 
 *
 
 * @param cost The return value of a CommandProc call
 
 * @return true if the command succeeded
 
 * @see CmdSucceeded
 
 */
 
static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
 

	
 
/**
 
 * Define a default return value for a failed command.
 
 *
 
 * This variable contains a CommandCost object with is declared as "failed".
 
 * Other functions just need to return this error if there is an error,
 
 * which doesn't need to specific by a StringID.
 
 */
src/industry_cmd.cpp
Show inline comments
 
@@ -1330,19 +1330,19 @@ static bool CheckIfIndustryTilesAreFree(
 
					return false;
 
				}
 

	
 
				/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
 
				CompanyID old_company = _current_company;
 
				_current_company = OWNER_TOWN;
 
				bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR));
 
				bool not_clearable = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR).Failed();
 
				_current_company = old_company;
 

	
 
				if (not_clearable) return false;
 
			} else {
 
				/* Clear the tiles, but do not affect town ratings */
 
				bool not_clearable = CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR));
 
				bool not_clearable = DoCommand(cur_tile, 0, 0, DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR).Failed();
 

	
 
				if (not_clearable) return false;
 
			}
 
		}
 
	} while ((++it)->ti.x != -0x80);
 

	
 
@@ -1448,13 +1448,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
 
				_current_company = old_company;
 
				return false;
 
			}
 
			/* This is not 100% correct check, but the best we can do without modifying the map.
 
			 *  What is missing, is if the difference in height is more than 1.. */
 
			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) {
 
			if (DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND).Failed()) {
 
				_current_company = old_company;
 
				return false;
 
			}
 
		}
 
	}
 

	
src/landscape.cpp
Show inline comments
 
@@ -626,13 +626,13 @@ CommandCost CmdClearArea(TileIndex tile,
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	bool success = false;
 

	
 
	for (int x = sx; x <= ex; ++x) {
 
		for (int y = sy; y <= ey; ++y) {
 
			CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) continue;
 
			if (ret.Failed()) continue;
 
			success = true;
 

	
 
			if (flags & DC_EXEC) {
 
				money -= ret.GetCost();
 
				if (ret.GetCost() > 0 && money < 0) {
 
					_additional_cash_required = ret.GetCost();
src/misc_gui.cpp
Show inline comments
 
@@ -186,13 +186,13 @@ public:
 
		Company *c = Company::GetIfValid(_local_company);
 
		if (c != NULL) {
 
			Money old_money = c->money;
 
			c->money = INT64_MAX;
 
			CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
 
			c->money = old_money;
 
			if (CmdSucceeded(costclear)) {
 
			if (costclear.Succeeded()) {
 
				Money cost = costclear.GetCost();
 
				if (cost < 0) {
 
					cost = -cost; // Negate negative cost to a positive revenue
 
					str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
 
				} else {
 
					str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
src/rail_cmd.cpp
Show inline comments
 
@@ -337,22 +337,22 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			if (!CheckTrackCombination(tile, trackbit, flags) ||
 
					!EnsureNoTrainOnTrack(tile, track)) {
 
				return CMD_ERROR;
 
			}
 

	
 
			ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
 
			if (CmdFailed(ret)) return ret;
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 

	
 
			/* If the rail types don't match, try to convert only if engines of
 
			 * the new rail type are not powered on the present rail type and engines of
 
			 * the present rail type are powered on the new rail type. */
 
			if (GetRailType(tile) != railtype && !HasPowerOnRail(railtype, GetRailType(tile))) {
 
				if (HasPowerOnRail(GetRailType(tile), railtype)) {
 
					ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
 
					if (CmdFailed(ret)) return ret;
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
				} else {
 
					return CMD_ERROR;
 
				}
 
			}
 

	
 
@@ -412,17 +412,17 @@ CommandCost CmdBuildSingleRail(TileIndex
 

	
 
		default:
 
			/* Will there be flat water on the lower halftile? */
 
			bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
 

	
 
			ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
 
			if (CmdFailed(ret)) return ret;
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 

	
 
			ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 

	
 
			if (water_ground) {
 
				cost.AddCost(-_price[PR_CLEAR_WATER]);
 
				cost.AddCost(_price[PR_CLEAR_ROUGH]);
 
			}
 
@@ -578,13 +578,13 @@ bool FloodHalftile(TileIndex t)
 
	if (IsSlopeWithOneCornerRaised(tileh)) {
 
		TrackBits lower_track = CornerToTrackBits(OppositeCorner(GetHighestSlopeCorner(tileh)));
 

	
 
		TrackBits to_remove = lower_track & rail_bits;
 
		if (to_remove != 0) {
 
			_current_company = OWNER_WATER;
 
			if (CmdFailed(DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL))) return flooded; // not yet floodable
 
			if (DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Failed()) return flooded; // not yet floodable
 
			flooded = true;
 
			rail_bits = rail_bits & ~to_remove;
 
			if (rail_bits == 0) {
 
				MakeShore(t);
 
				MarkTileDirtyByTile(t);
 
				return flooded;
 
@@ -690,20 +690,20 @@ static CommandCost CmdRailTrackHelper(Ti
 

	
 
	if (!ValParamRailtype(railtype) || !ValParamTrackOrientation(track)) return CMD_ERROR;
 
	if (p1 >= MapSize()) return CMD_ERROR;
 
	TileIndex end_tile = p1;
 
	Trackdir trackdir = TrackToTrackdir(track);
 

	
 
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
 
	if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
 

	
 
	for (;;) {
 
		ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
 

	
 
		if (CmdFailed(ret)) {
 
		if (ret.Failed()) {
 
			if (_error_message != STR_ERROR_ALREADY_BUILT && !remove) break;
 
			_error_message = INVALID_STRING_ID;
 
		} else {
 
			total_cost.AddCost(ret);
 
		}
 

	
 
@@ -789,13 +789,13 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
				!CanBuildDepotByTileh(dir, tileh)
 
			)) {
 
		return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
	}
 

	
 
	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 
	if (cost.Failed()) return CMD_ERROR;
 

	
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -1079,13 +1079,13 @@ static CommandCost CmdSignalTrackHelper(
 
	if (!IsPlainRailTile(tile)) return CMD_ERROR;
 

	
 
	/* for vertical/horizontal tracks, double the given signals density
 
	 * since the original amount will be too dense (shorter tracks) */
 
	signal_density *= 2;
 

	
 
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
 
	if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
 

	
 
	track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
 
	Trackdir start_trackdir = trackdir;
 

	
 
	/* Must start on a valid track to be able to avoid loops */
 
	if (!HasTrack(tile, track)) return CMD_ERROR;
 
@@ -1135,13 +1135,13 @@ static CommandCost CmdSignalTrackHelper(
 
			if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
 
			if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
 

	
 
			ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
 

	
 
			/* Be user-friendly and try placing signals as much as possible */
 
			if (CmdSucceeded(ret)) {
 
			if (ret.Succeeded()) {
 
				err = false;
 
				total_cost.AddCost(ret);
 
			}
 
		}
 

	
 
		if (autofill) {
 
@@ -1518,13 +1518,13 @@ static CommandCost ClearTile_Track(TileI
 
			bool water_ground = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh));
 

	
 
			TrackBits tracks = GetTrackBits(tile);
 
			while (tracks != TRACK_BIT_NONE) {
 
				Track track = RemoveFirstTrack(&tracks);
 
				ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
 
				if (CmdFailed(ret)) return CMD_ERROR;
 
				if (ret.Failed()) return CMD_ERROR;
 
				cost.AddCost(ret);
 
			}
 

	
 
			/* when bankrupting, don't make water dirty, there could be a ship on lower halftile */
 
			if (water_ground && !(flags & DC_BANKRUPT)) {
 
				if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 
@@ -2451,13 +2451,13 @@ static VehicleEnterTileStatus VehicleEnt
 
 */
 
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_old, Slope tileh_old, uint z_new, Slope tileh_new, TrackBits rail_bits)
 
{
 
	if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return CMD_ERROR;
 

	
 
	/* Is the slope-rail_bits combination valid in general? I.e. is it safe to call GetRailFoundation() ? */
 
	if (CmdFailed(CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile))) return CMD_ERROR;
 
	if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return CMD_ERROR;
 

	
 
	/* Get the slopes on top of the foundations */
 
	z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
 
	z_new += ApplyFoundationToSlope(GetRailFoundation(tileh_new, rail_bits), &tileh_new);
 

	
 
	Corner track_corner;
src/road_cmd.cpp
Show inline comments
 
@@ -596,23 +596,23 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
			if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR;
 
			break;
 

	
 
		default: {
 
do_clear:;
 
			CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 
		} break;
 
	}
 

	
 
	if (other_bits != pieces) {
 
		/* Check the foundation/slopes when adding road/tram bits */
 
		CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
 
		/* Return an error if we need to build a foundation (ret != 0) but the
 
		 * current setting is turned off */
 
		if (CmdFailed(ret) || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
 
		if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
 
			return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		}
 
		cost.AddCost(ret);
 
	}
 

	
 
	if (IsTileType(tile, MP_ROAD)) {
 
@@ -755,13 +755,13 @@ CommandCost CmdBuildLongRoad(TileIndex s
 
		/* Road parts only have to be built at the start tile or at the end tile. */
 
		if (tile == end_tile && !HasBit(p2, 1)) bits &= DiagDirToRoadBits(ReverseDiagDir(dir));
 
		if (tile == start_tile && HasBit(p2, 0)) bits &= DiagDirToRoadBits(dir);
 

	
 
		_error_message = INVALID_STRING_ID;
 
		CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
 
		if (CmdFailed(ret)) {
 
		if (ret.Failed()) {
 
			if (_error_message != STR_ERROR_ALREADY_BUILT) break;
 
		} else {
 
			had_success = true;
 
			/* Only pay for the upgrade on one side of the bridges and tunnels */
 
			if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
				if (IsBridge(tile)) {
 
@@ -832,13 +832,13 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
		if (tile == end_tile && !HasBit(p2, 1)) bits &= ROAD_NW | ROAD_NE;
 
		if (tile == start_tile && HasBit(p2, 0)) bits &= ROAD_SE | ROAD_SW;
 

	
 
		/* try to remove the halves. */
 
		if (bits != 0) {
 
			CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
 
			if (CmdSucceeded(ret)) {
 
			if (ret.Succeeded()) {
 
				if (flags & DC_EXEC) {
 
					money -= ret.GetCost();
 
					if (money < 0) {
 
						_additional_cash_required = DoCommand(end_tile, start_tile, p2, flags & ~DC_EXEC, CMD_REMOVE_LONG_ROAD).GetCost();
 
						return cost;
 
					}
 
@@ -882,13 +882,13 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
				!CanBuildDepotByTileh(dir, tileh)
 
			)) {
 
		return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
	}
 

	
 
	CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 
	if (cost.Failed()) return CMD_ERROR;
 

	
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
@@ -925,13 +925,13 @@ static CommandCost ClearTile_Road(TileIn
 
			if ((CountBits(b) == 1 && GetRoadBits(tile, ROADTYPE_TRAM) == ROAD_NONE) || !(flags & DC_AUTO)) {
 
				RoadTypes rts = GetRoadTypes(tile);
 
				CommandCost ret(EXPENSES_CONSTRUCTION);
 
				for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
 
					if (HasBit(rts, rt)) {
 
						CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
 
						if (CmdFailed(tmp_ret)) return tmp_ret;
 
						if (tmp_ret.Failed()) return tmp_ret;
 
						ret.AddCost(tmp_ret);
 
					}
 
				}
 
				return ret;
 
			}
 
			return_cmd_error(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
 
@@ -946,13 +946,13 @@ static CommandCost ClearTile_Road(TileIn
 
			/* Must iterate over the roadtypes in a reverse manner because
 
			 * tram tracks must be removed before the road bits. */
 
			RoadType rt = ROADTYPE_TRAM;
 
			do {
 
				if (HasBit(rts, rt)) {
 
					CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false);
 
					if (CmdFailed(tmp_ret)) return tmp_ret;
 
					if (tmp_ret.Failed()) return tmp_ret;
 
					ret.AddCost(tmp_ret);
 
				}
 
			} while (rt-- != ROADTYPE_ROAD);
 

	
 
			if (flags & DC_EXEC) {
 
				DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
@@ -1593,13 +1593,13 @@ static CommandCost TerraformTile_Road(Ti
 
				break;
 

	
 
			case ROAD_TILE_NORMAL: {
 
				RoadBits bits = GetAllRoadBits(tile);
 
				RoadBits bits_copy = bits;
 
				/* Check if the slope-road_bits combination is valid at all, i.e. it is safe to call GetRoadFoundation(). */
 
				if (!CmdFailed(CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE))) {
 
				if (CheckRoadSlope(tileh_new, &bits_copy, ROAD_NONE, ROAD_NONE).Succeeded()) {
 
					/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
 
					if (bits == bits_copy) {
 
						uint z_old;
 
						Slope tileh_old = GetTileSlope(tile, &z_old);
 

	
 
						/* Get the slope on top of the foundation */
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1153,13 +1153,13 @@ static bool CanBuildTramTrackOnTile(Comp
 
	CompanyID original_company = _current_company;
 
	_current_company = c;
 

	
 
	CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NONE, CMD_BUILD_ROAD);
 

	
 
	_current_company = original_company;
 
	return CmdSucceeded(ret);
 
	return ret.Succeeded();
 
}
 

	
 
static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
 
{
 
	if (v->overtaking != 0)  {
 
		if (IsTileType(v->tile, MP_STATION)) {
src/station_cmd.cpp
Show inline comments
 
@@ -745,20 +745,20 @@ CommandCost CheckFlatLandBelow(TileIndex
 
				TrackBits tracks = GetTrackBits(tile_cur);
 
				Track track = RemoveFirstTrack(&tracks);
 
				Track expected_track = HasBit(invalid_dirs, DIAGDIR_NE) ? TRACK_X : TRACK_Y;
 

	
 
				if (tracks == TRACK_BIT_NONE && track == expected_track) {
 
					CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
 
					if (CmdFailed(ret)) return ret;
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
					/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
 
					continue;
 
				}
 
			}
 
			CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 
		}
 
	}
 

	
 
	return cost;
 
}
 
@@ -1006,18 +1006,18 @@ CommandCost CmdBuildRailStation(TileInde
 
	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
 
	StationID est = INVALID_STATION;
 
	/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
 
	 * for detail info, see:
 
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
 
	CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, true, rt);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 
	CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
 

	
 
	Station *st = NULL;
 
	ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 

	
 
	/* See if there is a deleted station close to us. */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
 

	
 
	if (st != NULL) {
 
		/* Reuse an existing station. */
 
@@ -1076,13 +1076,13 @@ CommandCost CmdBuildRailStation(TileInde
 
		Track track;
 

	
 
		/* Now really clear the land below the station
 
		 * It should never return CMD_ERROR.. but you never know ;)
 
		 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
 
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, true, rt);
 
		if (CmdFailed(ret)) return ret;
 
		if (ret.Failed()) return ret;
 

	
 
		st->train_station = new_location;
 
		st->AddFacility(FACIL_TRAIN, new_location.tile);
 

	
 
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
 

	
 
@@ -1575,19 +1575,19 @@ CommandCost CmdBuildRoadStop(TileIndex t
 

	
 
		/* Do not remove roadtypes! */
 
		rts |= cur_rts;
 
	}
 

	
 
	CommandCost cost = CheckFlatLandBelow(tile, 1, 1, flags, is_drive_through ? 5 << p1 : 1 << p1, NULL, !build_over_road);
 
	if (CmdFailed(cost)) return cost;
 
	if (cost.Failed()) return cost;
 
	uint roadbits_to_build = CountBits(rts) * 2 - num_roadbits;
 
	cost.AddCost(_price[PR_BUILD_ROAD] * roadbits_to_build);
 

	
 
	Station *st = NULL;
 
	CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 5), TileArea(tile, 1, 1), &st);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	/* give us a road stop in the list, and check if something went wrong */
 
	if (!RoadStop::CanAllocateItem()) return_cmd_error(type ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
 
@@ -1780,13 +1780,13 @@ CommandCost CmdRemoveRoadStop(TileIndex 
 

	
 
	Owner road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
 
	Owner tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
 
	CommandCost ret = RemoveRoadStop(tile, flags);
 

	
 
	/* If the stop was a drive-through stop replace the road */
 
	if ((flags & DC_EXEC) && CmdSucceeded(ret) && is_drive_through) {
 
	if ((flags & DC_EXEC) && ret.Succeeded() && is_drive_through) {
 
		/* Rebuild the drive throuhg road stop. As a road stop can only be
 
		 * removed by the owner of the roadstop, _current_company is the
 
		 * owner of the road stop. */
 
		MakeRoadNormal(tile, road_bits, rts, ClosestTownFromTile(tile, UINT_MAX)->index,
 
				road_owner, tram_owner);
 
	}
 
@@ -1932,13 +1932,13 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
 
		_error_message = STR_ERROR_STATION_TOO_SPREAD_OUT;
 
		return CMD_ERROR;
 
	}
 

	
 
	CommandCost cost = CheckFlatLandBelow(tile, w, h, flags, 0, NULL);
 
	if (CmdFailed(cost)) return cost;
 
	if (cost.Failed()) return cost;
 

	
 
	/* Go get the final noise level, that is base noise minus factor from distance to town center */
 
	Town *nearest = AirportGetNearestTown(as, tile);
 
	uint newnoise_level = GetAirportNoiseLevelForTown(as, nearest->xy, tile);
 

	
 
	/* Check if local auth would allow a new airport */
 
@@ -1964,13 +1964,13 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		SetDParam(0, t->index);
 
		return_cmd_error(authority_refuse_message);
 
	}
 

	
 
	Station *st = NULL;
 
	CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), TileArea(tile, w, h), &st);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 
@@ -2175,38 +2175,38 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	if (IsWaterTile(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 

	
 
	if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
 

	
 
	if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	if (CmdFailed(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
 
	if (DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
 

	
 
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
 

	
 
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 

	
 
	if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 

	
 
	/* Get the water class of the water tile before it is cleared.*/
 
	WaterClass wc = GetWaterClass(tile_cur);
 

	
 
	if (CmdFailed(DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR))) return CMD_ERROR;
 
	if (DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
 

	
 
	tile_cur += TileOffsByDiagDir(direction);
 
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 

	
 
	/* middle */
 
	Station *st = NULL;
 
	CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0),
 
			TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
 
					_dock_w_chk[direction], _dock_h_chk[direction]), &st);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
src/station_gui.cpp
Show inline comments
 
@@ -1496,13 +1496,13 @@ static bool StationJoinerNeeded(CommandC
 
	}
 

	
 
	/* only show the popup, if we press ctrl */
 
	if (!_ctrl_pressed) return false;
 

	
 
	/* Now check if we could build there */
 
	if (CmdFailed(DoCommand(&cmd, CommandFlagsToDCFlags(GetCommandFlags(cmd.cmd))))) return false;
 
	if (DoCommand(&cmd, CommandFlagsToDCFlags(GetCommandFlags(cmd.cmd))).Failed()) return false;
 

	
 
	/* Test for adjacent station or station below selection.
 
	 * If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
 
	 * but join the other station immediatelly. */
 
	const T *st = FindStationsNearby<T>(ta, false);
 
	return st == NULL && (_settings_game.station.adjacent_stations || _stations_nearby_list.Length() == 0);
src/terraform_cmd.cpp
Show inline comments
 
@@ -215,13 +215,13 @@ static CommandCost TerraformTileHeight(T
 

	
 
			/* Is the height difference to the neighboured corner greater than 1? */
 
			if (abs(height_diff) > 1) {
 
				/* Terraform the neighboured corner. The resulting height difference should be 1. */
 
				height_diff += (height_diff < 0 ? 1 : -1);
 
				CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
 
				if (CmdFailed(cost)) return cost;
 
				if (cost.Failed()) return cost;
 
				total_cost.AddCost(cost);
 
			}
 
		}
 
	}
 

	
 
	return total_cost;
 
@@ -246,34 +246,34 @@ CommandCost CmdTerraformLand(TileIndex t
 
	ts.modheight_count = ts.tile_table_count = 0;
 

	
 
	/* Compute the costs and the terraforming result in a model of the landscape */
 
	if ((p1 & SLOPE_W) != 0 && tile + TileDiffXY(1, 0) < MapSize()) {
 
		TileIndex t = tile + TileDiffXY(1, 0);
 
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
 
		if (CmdFailed(cost)) return cost;
 
		if (cost.Failed()) return cost;
 
		total_cost.AddCost(cost);
 
	}
 

	
 
	if ((p1 & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < MapSize()) {
 
		TileIndex t = tile + TileDiffXY(1, 1);
 
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
 
		if (CmdFailed(cost)) return cost;
 
		if (cost.Failed()) return cost;
 
		total_cost.AddCost(cost);
 
	}
 

	
 
	if ((p1 & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < MapSize()) {
 
		TileIndex t = tile + TileDiffXY(0, 1);
 
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
 
		if (CmdFailed(cost)) return cost;
 
		if (cost.Failed()) return cost;
 
		total_cost.AddCost(cost);
 
	}
 

	
 
	if ((p1 & SLOPE_N) != 0) {
 
		TileIndex t = tile + TileDiffXY(0, 0);
 
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
 
		if (CmdFailed(cost)) return cost;
 
		if (cost.Failed()) return cost;
 
		total_cost.AddCost(cost);
 
	}
 

	
 
	/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */
 
	{
 
		TileIndex *ti = ts.tile_table;
 
@@ -316,13 +316,13 @@ CommandCost CmdTerraformLand(TileIndex t
 
			}
 
			/* Check tiletype-specific things, and add extra-cost */
 
			const bool curr_gen = _generating_world;
 
			if (_game_mode == GM_EDITOR) _generating_world = true; // used to create green terraformed land
 
			CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, tileh);
 
			_generating_world = curr_gen;
 
			if (CmdFailed(cost)) {
 
			if (cost.Failed()) {
 
				_terraform_err_tile = tile;
 
				return cost;
 
			}
 
			total_cost.AddCost(cost);
 
		}
 
	}
 
@@ -383,13 +383,13 @@ CommandCost CmdLevelLand(TileIndex tile,
 

	
 
	TileArea ta(tile, p1);
 
	TILE_AREA_LOOP(tile, ta) {
 
		uint curh = TileHeight(tile);
 
		while (curh != h) {
 
			CommandCost ret = DoCommand(tile, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
 
			if (CmdFailed(ret)) break;
 
			if (ret.Failed()) break;
 

	
 
			if (flags & DC_EXEC) {
 
				money -= ret.GetCost();
 
				if (money < 0) {
 
					_additional_cash_required = ret.GetCost();
 
					return cost;
src/town_cmd.cpp
Show inline comments
 
@@ -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;
 
}
src/train_cmd.cpp
Show inline comments
 
@@ -760,14 +760,14 @@ static CommandCost CmdBuildRailWagon(Eng
 
static void NormalizeTrainVehInDepot(const Train *u)
 
{
 
	const Train *v;
 
	FOR_ALL_TRAINS(v) {
 
		if (v->IsFreeWagon() && v->tile == u->tile &&
 
				v->track == TRACK_BIT_DEPOT) {
 
			if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
 
					CMD_MOVE_RAIL_VEHICLE)))
 
			if (DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
 
					CMD_MOVE_RAIL_VEHICLE).Failed())
 
				break;
 
		}
 
	}
 
}
 

	
 
static void AddRearEngineToMultiheadedTrain(Train *v)
src/tree_cmd.cpp
Show inline comments
 
@@ -383,13 +383,13 @@ CommandCost CmdPlantTree(TileIndex tile,
 
				if (IsTileType(tile, MP_CLEAR)) {
 
					/* Remove fields or rocks. Note that the ground will get barrened */
 
					switch (GetRawClearGround(tile)) {
 
						case CLEAR_FIELDS:
 
						case CLEAR_ROCKS: {
 
							CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
							if (CmdFailed(ret)) return ret;
 
							if (ret.Failed()) return ret;
 
							cost.AddCost(ret);
 
							break;
 
						}
 

	
 
						default: break;
 
					}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -303,26 +303,26 @@ CommandCost CmdBuildBridge(TileIndex end
 
		/* Build a new bridge. */
 

	
 
		bool allow_on_slopes = (_settings_game.construction.build_on_slopes && transport_type != TRANSPORT_WATER);
 

	
 
		/* Try and clear the start landscape */
 
		CommandCost ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return ret;
 
		if (ret.Failed()) return ret;
 
		cost = ret;
 

	
 
		if (CmdFailed(terraform_cost_north) || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes))
 
		if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes))
 
			return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_north);
 

	
 
		/* Try and clear the end landscape */
 
		ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return ret;
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		/* false - end tile slope check */
 
		if (CmdFailed(terraform_cost_south) || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes))
 
		if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes))
 
			return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
		cost.AddCost(terraform_cost_south);
 

	
 
		if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 

	
 
		const TileIndex heads[] = {tile_start, tile_end};
 
@@ -376,13 +376,13 @@ CommandCost CmdBuildBridge(TileIndex end
 
					break;
 

	
 
				default:
 
	not_valid_below:;
 
					/* try and clear the middle landscape */
 
					ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
					if (CmdFailed(ret)) return ret;
 
					if (ret.Failed()) return ret;
 
					cost.AddCost(ret);
 
					break;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				/* We do this here because when replacing a bridge with another
 
@@ -479,13 +479,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
 

	
 
	if (IsWaterTile(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 

	
 
	CommandCost ret = DoCommand(start_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return ret;
 
	if (ret.Failed()) return ret;
 

	
 
	/* XXX - do NOT change 'ret' in the loop, as it is used as the price
 
	 * for the clearing of the entrance of the tunnel. Assigning it to
 
	 * cost before the loop will yield different costs depending on start-
 
	 * position, because of increased-cost-by-length: 'cost += cost >> 3' */
 

	
 
@@ -541,19 +541,19 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	if (end_tileh != ComplementSlope(start_tileh)) {
 
		/* Check if there is a structure on the terraformed tile. Do not add the cost, that will be done by the terraforming
 
		 * Note: Currently the town rating is also affected by this clearing-test. So effectivly the player is punished twice for clearing
 
		 *       the tree on end_tile.
 
		 */
 
		ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
		if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 

	
 
		ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
 
		if (CmdFailed(ret)) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
		if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
 
	} else {
 
		ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return ret;
 
		if (ret.Failed()) return ret;
 
	}
 
	cost.AddCost(_price[PR_BUILD_TUNNEL]);
 
	cost.AddCost(ret);
 

	
 
	if (flags & DC_EXEC) {
 
		if (transport_type == TRANSPORT_RAIL) {
 
@@ -1316,13 +1316,13 @@ static void ChangeTileOwner_TunnelBridge
 

	
 
	if (!IsTileOwner(tile, old_owner)) return;
 

	
 
	if (new_owner != INVALID_OWNER) {
 
		SetTileOwner(tile, new_owner);
 
	} else {
 
		if (CmdFailed(DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR))) {
 
		if (DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR).Failed()) {
 
			/* When clearing the bridge/tunnel failed there are still vehicles on/in
 
			 * the bridge/tunnel. As all *our* vehicles are already removed, they
 
			 * must be of another owner. Therefore this can't be rail tunnel/bridge.
 
			 * In that case we can safely reassign the ownership to OWNER_NONE. */
 
			assert(GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL);
 
			SetTileOwner(tile, OWNER_NONE);
 
@@ -1506,13 +1506,13 @@ static CommandCost TerraformTile_TunnelB
 
		} else {
 
			CheckBridgeSlopeNorth(axis, &tileh_old, &z_old);
 
			res = CheckBridgeSlopeNorth(axis, &tileh_new, &z_new);
 
		}
 

	
 
		/* Surface slope is valid and remains unchanged? */
 
		if (!CmdFailed(res) && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
		if (res.Succeeded() && (z_old == z_new) && (tileh_old == tileh_new)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
 
	}
 

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

	
 
extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
src/unmovable_cmd.cpp
Show inline comments
 
@@ -111,13 +111,13 @@ extern CommandCost CheckFlatLandBelow(Ti
 
CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	Company *c = Company::Get(_current_company);
 
	CommandCost cost(EXPENSES_PROPERTY);
 

	
 
	cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
 
	if (CmdFailed(cost)) return cost;
 
	if (cost.Failed()) return cost;
 

	
 
	if (c->location_of_HQ != INVALID_TILE) { // Moving HQ
 
		cost.AddCost(DestroyCompanyHQ(_current_company, flags));
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
@@ -149,13 +149,13 @@ CommandCost CmdPurchaseLandArea(TileInde
 

	
 
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_company)) {
 
		return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
 
	}
 

	
 
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(cost)) return CMD_ERROR;
 
	if (cost.Failed()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		MakeOwnedLand(tile, _current_company);
 
		MarkTileDirtyByTile(tile);
 
	}
 

	
src/vehicle.cpp
Show inline comments
 
@@ -1054,13 +1054,13 @@ void VehicleEnterDepot(Vehicle *v)
 
		}
 

	
 
		if (t.IsRefit()) {
 
			_current_company = v->owner;
 
			CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
 

	
 
			if (CmdFailed(cost)) {
 
			if (cost.Failed()) {
 
				_vehicles_to_autoreplace[v] = false;
 
				if (v->owner == _local_company) {
 
					/* Notify the user that we stopped the vehicle */
 
					SetDParam(0, v->index);
 
					AddVehicleNewsItem(STR_NEWS_ORDER_REFIT_FAILED, NS_ADVICE, v->index);
 
				}
src/vehicle_cmd.cpp
Show inline comments
 
@@ -157,13 +157,13 @@ CommandCost CmdMassStartStopVehicle(Tile
 
				if (!(v->vehstatus & VS_HIDDEN)) continue;
 
			}
 
		}
 

	
 
		CommandCost ret = DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
 

	
 
		if (CmdSucceeded(ret)) {
 
		if (ret.Succeeded()) {
 
			return_value = CommandCost();
 
			/* We know that the command is valid for at least one vehicle.
 
			 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */
 
			if (!(flags & DC_EXEC)) break;
 
		}
 
	}
 
@@ -189,13 +189,13 @@ CommandCost CmdDepotSellAllVehicles(Tile
 

	
 
	/* Get the list of vehicles in the depot */
 
	BuildDepotVehicleList(vehicle_type, tile, &list, &list);
 

	
 
	for (uint i = 0; i < list.Length(); i++) {
 
		CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command);
 
		if (CmdSucceeded(ret)) cost.AddCost(ret);
 
		if (ret.Succeeded()) cost.AddCost(ret);
 
	}
 

	
 
	if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell
 
	return cost;
 
}
 

	
 
@@ -229,13 +229,13 @@ CommandCost CmdDepotMassAutoReplace(Tile
 

	
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!v->IsInDepot()) continue;
 

	
 
		CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
 

	
 
		if (CmdSucceeded(ret)) {
 
		if (ret.Succeeded()) {
 
			did_something = true;
 
			cost.AddCost(ret);
 
		} else {
 
			if (ret.GetErrorMessage() != STR_ERROR_AUTOREPLACE_NOTHING_TO_DO && all_or_nothing) {
 
				/* We failed to replace a vehicle even though we set all or nothing.
 
				 * We should never reach this if DC_EXEC is set since then it should
 
@@ -470,13 +470,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		DoCommandFlag build_flags = flags;
 
		if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE;
 

	
 
		CommandCost cost = DoCommand(tile, v->engine_type, build_argument, build_flags, GetCmdBuildVeh(v));
 
		build_argument = 3; // ensure that we only assign a number to the first engine
 

	
 
		if (CmdFailed(cost)) {
 
		if (cost.Failed()) {
 
			/* Can't build a part, then sell the stuff we already made; clear up the mess */
 
			if (w_front != NULL) DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
 
			return cost;
 
		}
 

	
 
		total_cost.AddCost(cost);
 
@@ -489,13 +489,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
			}
 

	
 
			if (v->type == VEH_TRAIN && !Train::From(v)->IsFrontEngine()) {
 
				/* this s a train car
 
				 * add this unit to the end of the train */
 
				CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE);
 
				if (CmdFailed(result)) {
 
				if (result.Failed()) {
 
					/* The train can't be joined to make the same consist as the original.
 
					 * Sell what we already made (clean up) and return an error.           */
 
					DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
 
					DoCommand(w_front->tile, w->index,       1, flags, GetCmdSellVeh(w));
 
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
 
				}
 
@@ -535,13 +535,13 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
				assert(w != NULL);
 

	
 
				/* Find out what's the best sub type */
 
				byte subtype = GetBestFittingSubType(v, w);
 
				if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
 
					CommandCost cost = DoCommand(0, w->index, v->cargo_type | (subtype << 8) | 1U << 16, flags, GetCmdRefitVeh(v));
 
					if (CmdSucceeded(cost)) total_cost.AddCost(cost);
 
					if (cost.Succeeded()) total_cost.AddCost(cost);
 
				}
 

	
 
				if (w->type == VEH_TRAIN && Train::From(w)->HasArticulatedPart()) {
 
					w = Train::From(w)->GetNextArticPart();
 
				} else if (w->type == VEH_ROAD && RoadVehicle::From(w)->HasArticulatedPart()) {
 
					w = w->Next();
 
@@ -616,13 +616,13 @@ CommandCost SendAllVehiclesToDepot(Vehic
 
		CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type));
 

	
 
		/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
 
		 * In this case we know that at least one vehicle can be sent to a depot
 
		 * and we will issue the command. We can now safely quit the loop, knowing
 
		 * it will succeed at least once. With DC_EXEC we really need to send them to the depot */
 
		if (CmdSucceeded(ret) && !(flags & DC_EXEC)) {
 
		if (ret.Succeeded() && !(flags & DC_EXEC)) {
 
			return CommandCost();
 
		}
 
	}
 

	
 
	return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR;
 
}
src/vehicle_gui.cpp
Show inline comments
 
@@ -423,13 +423,13 @@ struct RefitWindow : public Window {
 
				break;
 

	
 
			case VRW_INFOPANEL:
 
				if (this->cargo != NULL) {
 
					Vehicle *v = Vehicle::Get(this->window_number);
 
					CommandCost cost = DoCommand(v->tile, v->index, this->cargo->cargo | this->cargo->subtype << 8, DC_QUERY_COST, GetCmdRefitVeh(v->type));
 
					if (CmdSucceeded(cost)) {
 
					if (cost.Succeeded()) {
 
						SetDParam(0, this->cargo->cargo);
 
						SetDParam(1, _returned_refit_capacity);
 
						SetDParam(2, cost.GetCost());
 
						DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT,
 
								r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, STR_REFIT_NEW_CAPACITY_COST_OF_REFIT);
 
					}
src/water_cmd.cpp
Show inline comments
 
@@ -123,15 +123,15 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 

	
 
	WaterClass wc1 = GetWaterClass(tile);
 
	WaterClass wc2 = GetWaterClass(tile2);
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 
	if (ret.Failed()) return CMD_ERROR;
 
	ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 
	if (ret.Failed()) return CMD_ERROR;
 

	
 
	if (!Depot::CanAllocateItem()) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		Depot *depot = new Depot(tile);
 
		depot->town_index = ClosestTownFromTile(tile, UINT_MAX)->index;
 
@@ -195,29 +195,29 @@ static CommandCost DoBuildShiplift(TileI
 
{
 
	CommandCost ret;
 
	int delta;
 

	
 
	/* middle tile */
 
	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 
	if (ret.Failed()) return CMD_ERROR;
 

	
 
	delta = TileOffsByDiagDir(dir);
 
	/* lower tile */
 
	WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
 

	
 
	ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 
	if (ret.Failed()) return CMD_ERROR;
 
	if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
 
		return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
	}
 

	
 
	/* upper tile */
 
	WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
 

	
 
	ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
	if (CmdFailed(ret)) return CMD_ERROR;
 
	if (ret.Failed()) return CMD_ERROR;
 
	if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
 
		return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
 
	}
 

	
 
	if ((MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) ||
 
	    (MayHaveBridgeAbove(tile - delta) && IsBridgeAbove(tile - delta)) ||
 
@@ -310,13 +310,13 @@ CommandCost CmdBuildCanal(TileIndex tile
 
		}
 

	
 
		/* can't make water of water! */
 
		if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;
 

	
 
		ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
		if (CmdFailed(ret)) return ret;
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		if (flags & DC_EXEC) {
 
			if (TileHeight(tile) == 0 && p2 == 1) {
 
				MakeSea(tile);
 
			} else if (p2 == 2) {
 
@@ -865,13 +865,13 @@ void DoFloodTile(TileIndex target)
 
					MarkTileDirtyByTile(target);
 
					flooded = true;
 
					break;
 
				}
 
			/* FALL THROUGH */
 
			case MP_CLEAR:
 
				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 
				if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
					MakeShore(target);
 
					MarkTileDirtyByTile(target);
 
					flooded = true;
 
				}
 
				break;
 

	
 
@@ -880,13 +880,13 @@ void DoFloodTile(TileIndex target)
 
		}
 
	} else {
 
		/* Flood vehicles */
 
		FloodVehicles(target);
 

	
 
		/* flood flat tile */
 
		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 
		if (DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
			MakeSea(target);
 
			MarkTileDirtyByTile(target);
 
			flooded = true;
 
		}
 
	}
 

	
 
@@ -930,13 +930,13 @@ static void DoDryUp(TileIndex tile)
 
			MarkTileDirtyByTile(tile);
 
			break;
 

	
 
		case MP_WATER:
 
			assert(IsCoast(tile));
 

	
 
			if (CmdSucceeded(DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 
			if (DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR).Succeeded()) {
 
				MakeClear(tile, CLEAR_GRASS, 3);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 

	
 
		default: NOT_REACHED();
0 comments (0 inline, 0 general)