summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-01-18 22:57:21 +0000
committerrubidium <rubidium@openttd.org>2010-01-18 22:57:21 +0000
commit4d93b704d9f0e6e58dac1d97f79a05bd4320c43f (patch)
treef80050fa083b86d7a7d75efd1ae49a04b358666d
parentd8e126d98ddc35df0ac97bd35a076edf1cf172c8 (diff)
downloadopenttd-4d93b704d9f0e6e58dac1d97f79a05bd4320c43f.tar.xz
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
-rw-r--r--src/ai/api/ai_object.cpp2
-rw-r--r--src/ai/api/ai_vehicle.cpp2
-rw-r--r--src/aircraft_cmd.cpp2
-rw-r--r--src/bridge_gui.cpp2
-rw-r--r--src/command.cpp14
-rw-r--r--src/command_func.h24
-rw-r--r--src/industry_cmd.cpp6
-rw-r--r--src/landscape.cpp2
-rw-r--r--src/misc_gui.cpp2
-rw-r--r--src/rail_cmd.cpp24
-rw-r--r--src/road_cmd.cpp16
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/station_cmd.cpp26
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/terraform_cmd.cpp14
-rw-r--r--src/town_cmd.cpp24
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/tree_cmd.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp22
-rw-r--r--src/unmovable_cmd.cpp4
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_cmd.cpp14
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/water_cmd.cpp18
24 files changed, 104 insertions, 128 deletions
diff --git a/src/ai/api/ai_object.cpp b/src/ai/api/ai_object.cpp
index eb9e247e7..7282ba927 100644
--- a/src/ai/api/ai_object.cpp
+++ b/src/ai/api/ai_object.cpp
@@ -213,7 +213,7 @@ bool AIObject::DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint cmd, const c
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;
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp
index 6784ee4b8..123e2f1dd 100644
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -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)
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 719fc971d..03048134c 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -1219,7 +1219,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
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();
}
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 0651c63d0..6ea3396d1 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -386,7 +386,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
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 */
diff --git a/src/command.cpp b/src/command.cpp
index 5a81751e0..6d5484458 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -411,7 +411,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
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, uint32 p1, uint32 p2, DoCommandFlag flags,
/* 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 p1, uint32 p2, uint32 cmd, CommandCallbac
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 p1, uint32 p2, uint32 cmd, CommandCallbac
callback(res, tile, p1, p2);
}
- return CmdSucceeded(res);
+ return res.Succeeded();
}
@@ -621,7 +621,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd,
* (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 tile, uint32 p1, uint32 p2, uint32 cmd,
* 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);
}
diff --git a/src/command_func.h b/src/command_func.h
index 69464509b..f5a25d67c 100644
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -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".
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index b2eb905f5..e30f339d8 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1333,13 +1333,13 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
/* 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 CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
}
/* 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;
}
diff --git a/src/landscape.cpp b/src/landscape.cpp
index 68faf74b1..f122c0c30 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -629,7 +629,7 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
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) {
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 56e757d91..1b71828f4 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -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
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 205cd2ce2..98909f38f 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -340,7 +340,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
}
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 tile, DoCommandFlag flags, uint32 p1, u
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 tile, DoCommandFlag flags, uint32 p1, u
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(TileIndex tile, DoCommandFlag flags, uint3
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 tile, DoCommandFlag flags, uint32 p1, u
}
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(TileIndex tile, DoCommandFlag flags, uin
* 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(TileIndex tile, DoCommandFlag flags, uin
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(TileIndex tile, DoCommandFlag flags)
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 TestAutoslopeOnRailTile(TileIndex tile, uint flags, uint z_ol
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);
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 56ae78847..0df105778 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -599,7 +599,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
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 start_tile, DoCommandFlag flags, uint32 p
_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 end_tile, DoCommandFlag flags, uint32 p1
/* 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 tile, DoCommandFlag flags, uint32 p1, ui
}
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(TileIndex tile, DoCommandFlag flags)
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(TileIndex tile, DoCommandFlag flags)
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(TileIndex tile, DoCommandFlag flags, uint
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;
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 9f87022ea..4bf84953d 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1156,7 +1156,7 @@ static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r)
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)
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index e029573d6..1a0caa1e9 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -748,14 +748,14 @@ CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, DoCommandFlag fla
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(TileIndex tile_org, DoCommandFlag flags, uint32
* 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(TileIndex tile_org, DoCommandFlag flags, uint32
* 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 tile, DoCommandFlag flags, uint32 p1, uin
}
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 tile, DoCommandFlag flags, uint32 p1, ui
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 tile, DoCommandFlag flags, uint32 p1, uint
}
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 tile, DoCommandFlag flags, uint32 p1, uint
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, DoCommandFlag flags, uint32 p1, uint32
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, DoCommandFlag flags, uint32 p1, uint32
/* 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, DoCommandFlag flags, uint32 p1, uint32
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);
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 3bf2cf233..377642b86 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -1499,7 +1499,7 @@ static bool StationJoinerNeeded(CommandContainer cmd, TileArea ta)
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.
diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp
index 7ad1ad923..61df82d1f 100644
--- a/src/terraform_cmd.cpp
+++ b/src/terraform_cmd.cpp
@@ -218,7 +218,7 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int
/* 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 tile, DoCommandFlag flags, uint32 p1, uin
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 tile, DoCommandFlag flags, uint32 p1, uin
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, DoCommandFlag flags, uint32 p1, uint32
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();
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 7e00409b2..6ab50c3ff 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -780,8 +780,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
/* 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, TileIndex tile, DiagDirection dir)
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 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;
}
@@ -948,7 +948,7 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
*/
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 Town *t, const TileIndex tile, const DiagDi
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, DoCommandFlag flags, uint32 p1, uint32
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 attempts, uint32 townnameparts, TownSize size
}
/* 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(TileIndex tile, Town *t, byte counter, byt
{
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(TileIndex tile, TownID town, bool noslope)
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(TileIndex tile, TownID town_id)
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);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 614ce7b12..fe730b44b 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -763,8 +763,8 @@ static void NormalizeTrainVehInDepot(const Train *u)
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;
}
}
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index 7ea424727..94eb3f067 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -386,7 +386,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
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;
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 6b3c8b976..a9d24c7a2 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -306,20 +306,20 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
/* 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_tile, DoCommandFlag flags, uint32 p1, u
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 start_tile, DoCommandFlag flags, uint32 p1,
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 start_tile, DoCommandFlag flags, uint32 p1,
* 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(TileIndex tile, Owner old_owner, Owner
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_TunnelBridge(TileIndex tile, DoCommandFlag flag
}
/* 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);
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index 598088a0f..8044354fc 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -114,7 +114,7 @@ CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
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(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
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);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 49a5a0a75..f2cecfe68 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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 */
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 325737255..fde7f0b4a 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -160,7 +160,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32
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(TileIndex tile, DoCommandFlag flags, uint32
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(TileIndex tile, DoCommandFlag flags, uint32
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 tile, DoCommandFlag flags, uint32 p1, uint
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 tile, DoCommandFlag flags, uint32 p1, uint
/* 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 tile, DoCommandFlag flags, uint32 p1, uint
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(VehicleType type, DoCommandFlag flags, bool s
* 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();
}
}
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 75d5a56b3..53bc2a263 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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());
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 03db78f15..2f7d8b82b 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -126,9 +126,9 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
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(TileIndex tile, DiagDirection dir, DoCommandF
/* 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(TileIndex tile, DiagDirection dir, DoCommandF
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, DoCommandFlag flags, uint32 p1, uint32
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);
}