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
 
@@ -213,7 +213,7 @@ bool AIObject::DoCommand(TileIndex tile,
 
	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;
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -121,7 +121,7 @@
 
	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)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1219,7 +1219,7 @@ void HandleMissingAircraftOrders(Aircraf
 
		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
 
@@ -386,7 +386,7 @@ void ShowBuildBridgeWindow(TileIndex sta
 
	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 */
src/command.cpp
Show inline comments
 
@@ -411,7 +411,7 @@ CommandCost DoCommand(TileIndex tile, ui
 
		SetTownRatingTestMode(true);
 
		res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
 
		SetTownRatingTestMode(false);
 
		if (CmdFailed(res)) {
 
		if (res.Failed()) {
 
			goto error;
 
		}
 

	
 
@@ -431,7 +431,7 @@ 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--;
 
@@ -507,7 +507,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	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. */
 
@@ -530,7 +530,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		callback(res, tile, p1, p2);
 
	}
 

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

	
 

	
 
@@ -621,7 +621,7 @@ CommandCost DoCommandPInternal(TileIndex
 
		 * (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);
 
		}
 
@@ -656,8 +656,8 @@ CommandCost DoCommandPInternal(TileIndex
 
	 * 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);
 
	}
 

	
src/command_func.h
Show inline comments
 
@@ -16,30 +16,6 @@
 
#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".
src/industry_cmd.cpp
Show inline comments
 
@@ -1333,13 +1333,13 @@ static bool CheckIfIndustryTilesAreFree(
 
				/* 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;
 
			}
 
@@ -1451,7 +1451,7 @@ static bool CheckIfCanLevelIndustryPlatf
 
			}
 
			/* 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
 
@@ -629,7 +629,7 @@ CommandCost CmdClearArea(TileIndex tile,
 
	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) {
src/misc_gui.cpp
Show inline comments
 
@@ -189,7 +189,7 @@ public:
 
			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
src/rail_cmd.cpp
Show inline comments
 
@@ -340,7 +340,7 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			}
 

	
 
			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
 
@@ -349,7 +349,7 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			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;
 
@@ -415,11 +415,11 @@ CommandCost CmdBuildSingleRail(TileIndex
 
			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) {
 
@@ -581,7 +581,7 @@ bool FloodHalftile(TileIndex t)
 
		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) {
 
@@ -693,14 +693,14 @@ static CommandCost CmdRailTrackHelper(Ti
 
	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 {
 
@@ -792,7 +792,7 @@ CommandCost CmdBuildTrainDepot(TileIndex
 
	}
 

	
 
	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);
 

	
 
@@ -1082,7 +1082,7 @@ static CommandCost CmdSignalTrackHelper(
 
	 * 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;
 
@@ -1138,7 +1138,7 @@ static CommandCost CmdSignalTrackHelper(
 
			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);
 
			}
 
@@ -1521,7 +1521,7 @@ static CommandCost ClearTile_Track(TileI
 
			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);
 
			}
 

	
 
@@ -2454,7 +2454,7 @@ static CommandCost TestAutoslopeOnRailTi
 
	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);
src/road_cmd.cpp
Show inline comments
 
@@ -599,7 +599,7 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
		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;
 
	}
 
@@ -609,7 +609,7 @@ do_clear:;
 
		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);
 
@@ -758,7 +758,7 @@ CommandCost CmdBuildLongRoad(TileIndex s
 

	
 
		_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;
 
@@ -835,7 +835,7 @@ CommandCost CmdRemoveLongRoad(TileIndex 
 
		/* 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) {
 
@@ -885,7 +885,7 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 
	}
 

	
 
	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);
 

	
 
@@ -928,7 +928,7 @@ static CommandCost ClearTile_Road(TileIn
 
				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);
 
					}
 
				}
 
@@ -949,7 +949,7 @@ static CommandCost ClearTile_Road(TileIn
 
			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);
 
@@ -1596,7 +1596,7 @@ static CommandCost TerraformTile_Road(Ti
 
				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;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -1156,7 +1156,7 @@ static bool CanBuildTramTrackOnTile(Comp
 
	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)
src/station_cmd.cpp
Show inline comments
 
@@ -748,14 +748,14 @@ CommandCost CheckFlatLandBelow(TileIndex
 

	
 
				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);
 
		}
 
	}
 
@@ -1009,12 +1009,12 @@ CommandCost CmdBuildRailStation(TileInde
 
	 * 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);
 
@@ -1079,7 +1079,7 @@ CommandCost CmdBuildRailStation(TileInde
 
		 * 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);
 
@@ -1578,13 +1578,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
 
	}
 

	
 
	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);
 
@@ -1783,7 +1783,7 @@ CommandCost CmdRemoveRoadStop(TileIndex 
 
	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. */
 
@@ -1935,7 +1935,7 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	}
 

	
 
	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);
 
@@ -1967,7 +1967,7 @@ CommandCost CmdBuildAirport(TileIndex ti
 

	
 
	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);
 
@@ -2178,7 +2178,7 @@ CommandCost CmdBuildDock(TileIndex tile,
 

	
 
	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);
 

	
 
@@ -2191,7 +2191,7 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	/* 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) {
 
@@ -2203,7 +2203,7 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	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);
src/station_gui.cpp
Show inline comments
 
@@ -1499,7 +1499,7 @@ static bool StationJoinerNeeded(CommandC
 
	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.
src/terraform_cmd.cpp
Show inline comments
 
@@ -218,7 +218,7 @@ static CommandCost TerraformTileHeight(T
 
				/* 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);
 
			}
 
		}
 
@@ -249,28 +249,28 @@ CommandCost CmdTerraformLand(TileIndex t
 
	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);
 
	}
 

	
 
@@ -319,7 +319,7 @@ CommandCost CmdTerraformLand(TileIndex t
 
			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;
 
			}
 
@@ -386,7 +386,7 @@ CommandCost CmdLevelLand(TileIndex tile,
 
		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();
src/town_cmd.cpp
Show inline comments
 
@@ -780,8 +780,8 @@ static bool IsRoadAllowedHere(Town *t, T
 
			/* 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;
 
		}
 

	
 
@@ -800,7 +800,7 @@ static bool IsRoadAllowedHere(Town *t, T
 
					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;
 
				}
 
@@ -816,7 +816,7 @@ static bool TerraformTownTile(TileIndex 
 
	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;
 
}
 
@@ -948,7 +948,7 @@ static bool GrowTownWithExtraHouse(Town 
 
 */
 
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;
 
	}
 
@@ -1000,7 +1000,7 @@ static bool GrowTownWithBridge(const Tow
 
		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;
 
@@ -1317,7 +1317,7 @@ 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) && 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;
 
@@ -1552,7 +1552,7 @@ CommandCost CmdFoundTown(TileIndex tile,
 

	
 
	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 }};
 
@@ -1740,7 +1740,7 @@ static Town *CreateRandomTown(uint attem
 
		}
 

	
 
		/* 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);
 
@@ -1837,7 +1837,7 @@ static inline void ClearMakeHouseTile(Ti
 
{
 
	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);
 
@@ -1889,7 +1889,7 @@ static inline bool CanBuildHouseHere(Til
 
	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();
 
}
 

	
 

	
 
@@ -2382,7 +2382,7 @@ static bool DoBuildStatueOfCompany(TileI
 
	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);
src/train_cmd.cpp
Show inline comments
 
@@ -763,8 +763,8 @@ static void NormalizeTrainVehInDepot(con
 
	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;
 
		}
 
	}
src/tree_cmd.cpp
Show inline comments
 
@@ -386,7 +386,7 @@ CommandCost CmdPlantTree(TileIndex 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;
 
						}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -306,20 +306,20 @@ CommandCost CmdBuildBridge(TileIndex end
 

	
 
		/* 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);
 

	
 
@@ -379,7 +379,7 @@ CommandCost CmdBuildBridge(TileIndex end
 
	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;
 
			}
 
@@ -482,7 +482,7 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
	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
 
@@ -544,13 +544,13 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
		 *       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);
 
@@ -1319,7 +1319,7 @@ static void ChangeTileOwner_TunnelBridge
 
	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.
 
@@ -1509,7 +1509,7 @@ static CommandCost TerraformTile_TunnelB
 
		}
 

	
 
		/* 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);
src/unmovable_cmd.cpp
Show inline comments
 
@@ -114,7 +114,7 @@ CommandCost CmdBuildCompanyHQ(TileIndex 
 
	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));
 
@@ -152,7 +152,7 @@ CommandCost CmdPurchaseLandArea(TileInde
 
	}
 

	
 
	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);
src/vehicle.cpp
Show inline comments
 
@@ -1057,7 +1057,7 @@ void VehicleEnterDepot(Vehicle *v)
 
			_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 */
src/vehicle_cmd.cpp
Show inline comments
 
@@ -160,7 +160,7 @@ CommandCost CmdMassStartStopVehicle(Tile
 

	
 
		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 */
 
@@ -192,7 +192,7 @@ CommandCost CmdDepotSellAllVehicles(Tile
 

	
 
	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
 
@@ -232,7 +232,7 @@ CommandCost CmdDepotMassAutoReplace(Tile
 

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

	
 
		if (CmdSucceeded(ret)) {
 
		if (ret.Succeeded()) {
 
			did_something = true;
 
			cost.AddCost(ret);
 
		} else {
 
@@ -473,7 +473,7 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
		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;
 
@@ -492,7 +492,7 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
				/* 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));
 
@@ -538,7 +538,7 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
				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()) {
 
@@ -619,7 +619,7 @@ CommandCost SendAllVehiclesToDepot(Vehic
 
		 * 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();
 
		}
 
	}
src/vehicle_gui.cpp
Show inline comments
 
@@ -426,7 +426,7 @@ struct RefitWindow : public Window {
 
				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());
src/water_cmd.cpp
Show inline comments
 
@@ -126,9 +126,9 @@ CommandCost CmdBuildShipDepot(TileIndex 
 
	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;
 

	
 
@@ -198,14 +198,14 @@ static CommandCost DoBuildShiplift(TileI
 

	
 
	/* 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);
 
	}
 
@@ -214,7 +214,7 @@ static CommandCost DoBuildShiplift(TileI
 
	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);
 
	}
 
@@ -313,7 +313,7 @@ CommandCost CmdBuildCanal(TileIndex tile
 
		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) {
 
@@ -868,7 +868,7 @@ void DoFloodTile(TileIndex target)
 
				}
 
			/* 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;
 
@@ -883,7 +883,7 @@ void DoFloodTile(TileIndex target)
 
		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;
 
@@ -933,7 +933,7 @@ static void DoDryUp(TileIndex tile)
 
		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);
 
			}
0 comments (0 inline, 0 general)