mirror of https://github.com/OpenTTD/OpenTTD
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
parent
d8e126d98d
commit
4d93b704d9
|
@ -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);
|
CommandCost res = ::DoCommandPInternal(tile, p1, p2, cmd, _networking ? CcAI : NULL, text, false, estimate_only);
|
||||||
|
|
||||||
/* We failed; set the error and bail out */
|
/* We failed; set the error and bail out */
|
||||||
if (::CmdFailed(res)) {
|
if (res.Failed()) {
|
||||||
res.SetGlobalErrorMessage();
|
res.SetGlobalErrorMessage();
|
||||||
SetLastError(AIError::StringToError(_error_message));
|
SetLastError(AIError::StringToError(_error_message));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
if (!AICargo::IsValidCargo(cargo)) return -1;
|
if (!AICargo::IsValidCargo(cargo)) return -1;
|
||||||
|
|
||||||
CommandCost res = ::DoCommand(0, vehicle_id, cargo, DC_QUERY_COST, GetCmdRefitVeh(::Vehicle::Get(vehicle_id)));
|
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)
|
/* static */ bool AIVehicle::RefitVehicle(VehicleID vehicle_id, CargoID cargo)
|
||||||
|
|
|
@ -1219,7 +1219,7 @@ void HandleMissingAircraftOrders(Aircraft *v)
|
||||||
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
|
||||||
_current_company = old_company;
|
_current_company = old_company;
|
||||||
|
|
||||||
if (CmdFailed(ret)) CrashAirplane(v);
|
if (ret.Failed()) CrashAirplane(v);
|
||||||
} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
|
} else if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
|
||||||
v->current_order.Free();
|
v->current_order.Free();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
CommandCost ret = DoCommand(end, start, type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
|
||||||
|
|
||||||
GUIBridgeList *bl = NULL;
|
GUIBridgeList *bl = NULL;
|
||||||
if (CmdFailed(ret)) {
|
if (ret.Failed()) {
|
||||||
errmsg = _error_message;
|
errmsg = _error_message;
|
||||||
} else {
|
} else {
|
||||||
/* check which bridges can be built */
|
/* check which bridges can be built */
|
||||||
|
|
|
@ -411,7 +411,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
|
||||||
SetTownRatingTestMode(true);
|
SetTownRatingTestMode(true);
|
||||||
res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
|
res = proc(tile, flags & ~DC_EXEC, p1, p2, text);
|
||||||
SetTownRatingTestMode(false);
|
SetTownRatingTestMode(false);
|
||||||
if (CmdFailed(res)) {
|
if (res.Failed()) {
|
||||||
goto error;
|
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
|
/* Execute the command here. All cost-relevant functions set the expenses type
|
||||||
* themselves to the cost object at some point */
|
* themselves to the cost object at some point */
|
||||||
res = proc(tile, flags, p1, p2, text);
|
res = proc(tile, flags, p1, p2, text);
|
||||||
if (CmdFailed(res)) {
|
if (res.Failed()) {
|
||||||
error:
|
error:
|
||||||
res.SetGlobalErrorMessage();
|
res.SetGlobalErrorMessage();
|
||||||
_docommand_recursive--;
|
_docommand_recursive--;
|
||||||
|
@ -507,7 +507,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
|
||||||
int y = TileY(tile) * TILE_SIZE;
|
int y = TileY(tile) * TILE_SIZE;
|
||||||
|
|
||||||
CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only);
|
CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only);
|
||||||
if (CmdFailed(res)) {
|
if (res.Failed()) {
|
||||||
res.SetGlobalErrorMessage();
|
res.SetGlobalErrorMessage();
|
||||||
|
|
||||||
/* Only show the error when it's for us. */
|
/* 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);
|
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
|
* (unless it's a command where the test and
|
||||||
* execution phase might return different costs)
|
* execution phase might return different costs)
|
||||||
* we bail out here. */
|
* we bail out here. */
|
||||||
if (CmdFailed(res) || estimate_only ||
|
if (res.Failed() || estimate_only ||
|
||||||
(!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
|
(!test_and_exec_can_differ && !CheckCompanyHasMoney(res))) {
|
||||||
return_dcpi(res, false);
|
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
|
* check whether the test and execution have yielded the same
|
||||||
* result, i.e. cost and error state are the same. */
|
* result, i.e. cost and error state are the same. */
|
||||||
if (!test_and_exec_can_differ && !skip_test) {
|
if (!test_and_exec_can_differ && !skip_test) {
|
||||||
assert(res.GetCost() == res2.GetCost() && CmdFailed(res) == CmdFailed(res2)); // sanity check
|
assert(res.GetCost() == res2.GetCost() && res.Failed() == res2.Failed()); // sanity check
|
||||||
} else if (CmdFailed(res2)) {
|
} else if (res2.Failed()) {
|
||||||
return_dcpi(res2, false);
|
return_dcpi(res2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,30 +15,6 @@
|
||||||
#include "command_type.h"
|
#include "command_type.h"
|
||||||
#include "company_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.
|
* Define a default return value for a failed command.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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 */
|
/* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */
|
||||||
CompanyID old_company = _current_company;
|
CompanyID old_company = _current_company;
|
||||||
_current_company = OWNER_TOWN;
|
_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;
|
_current_company = old_company;
|
||||||
|
|
||||||
if (not_clearable) return false;
|
if (not_clearable) return false;
|
||||||
} else {
|
} else {
|
||||||
/* Clear the tiles, but do not affect town ratings */
|
/* 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;
|
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.
|
/* 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.. */
|
* 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;
|
_current_company = old_company;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -629,7 +629,7 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
for (int x = sx; x <= ex; ++x) {
|
for (int x = sx; x <= ex; ++x) {
|
||||||
for (int y = sy; y <= ey; ++y) {
|
for (int y = sy; y <= ey; ++y) {
|
||||||
CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) continue;
|
if (ret.Failed()) continue;
|
||||||
success = true;
|
success = true;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
|
|
@ -189,7 +189,7 @@ public:
|
||||||
c->money = INT64_MAX;
|
c->money = INT64_MAX;
|
||||||
CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
|
||||||
c->money = old_money;
|
c->money = old_money;
|
||||||
if (CmdSucceeded(costclear)) {
|
if (costclear.Succeeded()) {
|
||||||
Money cost = costclear.GetCost();
|
Money cost = costclear.GetCost();
|
||||||
if (cost < 0) {
|
if (cost < 0) {
|
||||||
cost = -cost; // Negate negative cost to a positive revenue
|
cost = -cost; // Negate negative cost to a positive revenue
|
||||||
|
|
|
@ -340,7 +340,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
|
||||||
/* If the rail types don't match, try to convert only if engines of
|
/* 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 (GetRailType(tile) != railtype && !HasPowerOnRail(railtype, GetRailType(tile))) {
|
||||||
if (HasPowerOnRail(GetRailType(tile), railtype)) {
|
if (HasPowerOnRail(GetRailType(tile), railtype)) {
|
||||||
ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
|
ret = DoCommand(tile, tile, railtype, flags, CMD_CONVERT_RAIL);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
} else {
|
} else {
|
||||||
return CMD_ERROR;
|
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);
|
bool water_ground = IsTileType(tile, MP_WATER) && IsSlopeWithOneCornerRaised(tileh);
|
||||||
|
|
||||||
ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
|
ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
|
||||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
|
||||||
if (water_ground) {
|
if (water_ground) {
|
||||||
|
@ -581,7 +581,7 @@ bool FloodHalftile(TileIndex t)
|
||||||
TrackBits to_remove = lower_track & rail_bits;
|
TrackBits to_remove = lower_track & rail_bits;
|
||||||
if (to_remove != 0) {
|
if (to_remove != 0) {
|
||||||
_current_company = OWNER_WATER;
|
_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;
|
flooded = true;
|
||||||
rail_bits = rail_bits & ~to_remove;
|
rail_bits = rail_bits & ~to_remove;
|
||||||
if (rail_bits == 0) {
|
if (rail_bits == 0) {
|
||||||
|
@ -693,14 +693,14 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
|
||||||
TileIndex end_tile = p1;
|
TileIndex end_tile = p1;
|
||||||
Trackdir trackdir = TrackToTrackdir(track);
|
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);
|
if (flags & DC_EXEC) SndPlayTileFx(SND_20_SPLAT_2, tile);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
|
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;
|
if (_error_message != STR_ERROR_ALREADY_BUILT && !remove) break;
|
||||||
_error_message = INVALID_STRING_ID;
|
_error_message = INVALID_STRING_ID;
|
||||||
} else {
|
} else {
|
||||||
|
@ -792,7 +792,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
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 (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) */
|
* since the original amount will be too dense (shorter tracks) */
|
||||||
signal_density *= 2;
|
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
|
track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
|
||||||
Trackdir start_trackdir = trackdir;
|
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);
|
ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
|
||||||
|
|
||||||
/* Be user-friendly and try placing signals as much as possible */
|
/* Be user-friendly and try placing signals as much as possible */
|
||||||
if (CmdSucceeded(ret)) {
|
if (ret.Succeeded()) {
|
||||||
err = false;
|
err = false;
|
||||||
total_cost.AddCost(ret);
|
total_cost.AddCost(ret);
|
||||||
}
|
}
|
||||||
|
@ -1521,7 +1521,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
|
||||||
while (tracks != TRACK_BIT_NONE) {
|
while (tracks != TRACK_BIT_NONE) {
|
||||||
Track track = RemoveFirstTrack(&tracks);
|
Track track = RemoveFirstTrack(&tracks);
|
||||||
ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
|
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);
|
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;
|
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() ? */
|
/* 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 */
|
/* Get the slopes on top of the foundations */
|
||||||
z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
|
z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), &tileh_old);
|
||||||
|
|
|
@ -599,7 +599,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
default: {
|
default: {
|
||||||
do_clear:;
|
do_clear:;
|
||||||
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ do_clear:;
|
||||||
CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
|
CommandCost ret = CheckRoadSlope(tileh, &pieces, existing, other_bits);
|
||||||
/* Return an error if we need to build a foundation (ret != 0) but the
|
/* Return an error if we need to build a foundation (ret != 0) but the
|
||||||
* current setting is turned off */
|
* 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);
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
}
|
}
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
@ -758,7 +758,7 @@ CommandCost CmdBuildLongRoad(TileIndex start_tile, DoCommandFlag flags, uint32 p
|
||||||
|
|
||||||
_error_message = INVALID_STRING_ID;
|
_error_message = INVALID_STRING_ID;
|
||||||
CommandCost ret = DoCommand(tile, drd << 6 | rt << 4 | bits, 0, flags, CMD_BUILD_ROAD);
|
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;
|
if (_error_message != STR_ERROR_ALREADY_BUILT) break;
|
||||||
} else {
|
} else {
|
||||||
had_success = true;
|
had_success = true;
|
||||||
|
@ -835,7 +835,7 @@ CommandCost CmdRemoveLongRoad(TileIndex end_tile, DoCommandFlag flags, uint32 p1
|
||||||
/* try to remove the halves. */
|
/* try to remove the halves. */
|
||||||
if (bits != 0) {
|
if (bits != 0) {
|
||||||
CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
|
CommandCost ret = RemoveRoad(tile, flags & ~DC_EXEC, bits, rt, true);
|
||||||
if (CmdSucceeded(ret)) {
|
if (ret.Succeeded()) {
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
money -= ret.GetCost();
|
money -= ret.GetCost();
|
||||||
if (money < 0) {
|
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);
|
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 (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++) {
|
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
||||||
if (HasBit(rts, rt)) {
|
if (HasBit(rts, rt)) {
|
||||||
CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rt), rt, true);
|
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);
|
ret.AddCost(tmp_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -949,7 +949,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
|
||||||
do {
|
do {
|
||||||
if (HasBit(rts, rt)) {
|
if (HasBit(rts, rt)) {
|
||||||
CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rt, false);
|
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);
|
ret.AddCost(tmp_ret);
|
||||||
}
|
}
|
||||||
} while (rt-- != ROADTYPE_ROAD);
|
} while (rt-- != ROADTYPE_ROAD);
|
||||||
|
@ -1596,7 +1596,7 @@ static CommandCost TerraformTile_Road(TileIndex tile, DoCommandFlag flags, uint
|
||||||
RoadBits bits = GetAllRoadBits(tile);
|
RoadBits bits = GetAllRoadBits(tile);
|
||||||
RoadBits bits_copy = bits;
|
RoadBits bits_copy = bits;
|
||||||
/* Check if the slope-road_bits combination is valid at all, i.e. it is safe to call GetRoadFoundation(). */
|
/* 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. */
|
/* CheckRoadSlope() sometimes changes the road_bits, if it does not agree with them. */
|
||||||
if (bits == bits_copy) {
|
if (bits == bits_copy) {
|
||||||
uint z_old;
|
uint z_old;
|
||||||
|
|
|
@ -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);
|
CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NONE, CMD_BUILD_ROAD);
|
||||||
|
|
||||||
_current_company = original_company;
|
_current_company = original_company;
|
||||||
return CmdSucceeded(ret);
|
return ret.Succeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
|
static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
|
||||||
|
|
|
@ -748,14 +748,14 @@ CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, DoCommandFlag fla
|
||||||
|
|
||||||
if (tracks == TRACK_BIT_NONE && track == expected_track) {
|
if (tracks == TRACK_BIT_NONE && track == expected_track) {
|
||||||
CommandCost ret = DoCommand(tile_cur, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
|
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);
|
cost.AddCost(ret);
|
||||||
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
|
/* With flags & ~DC_EXEC CmdLandscapeClear would fail since the rail still exists */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1009,12 +1009,12 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
|
||||||
* for detail info, see:
|
* for detail info, see:
|
||||||
* https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
|
* 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);
|
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);
|
CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
|
||||||
|
|
||||||
Station *st = NULL;
|
Station *st = NULL;
|
||||||
ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
|
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. */
|
/* See if there is a deleted station close to us. */
|
||||||
if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
|
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 ;)
|
* 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) */
|
* (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);
|
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->train_station = new_location;
|
||||||
st->AddFacility(FACIL_TRAIN, new_location.tile);
|
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);
|
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;
|
uint roadbits_to_build = CountBits(rts) * 2 - num_roadbits;
|
||||||
cost.AddCost(_price[PR_BUILD_ROAD] * roadbits_to_build);
|
cost.AddCost(_price[PR_BUILD_ROAD] * roadbits_to_build);
|
||||||
|
|
||||||
Station *st = NULL;
|
Station *st = NULL;
|
||||||
CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 5), TileArea(tile, 1, 1), &st);
|
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 */
|
/* Find a deleted station close to us */
|
||||||
if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
|
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);
|
CommandCost ret = RemoveRoadStop(tile, flags);
|
||||||
|
|
||||||
/* If the stop was a drive-through stop replace the road */
|
/* 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
|
/* Rebuild the drive throuhg road stop. As a road stop can only be
|
||||||
* removed by the owner of the roadstop, _current_company is the
|
* removed by the owner of the roadstop, _current_company is the
|
||||||
* owner of the road stop. */
|
* 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);
|
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 */
|
/* Go get the final noise level, that is base noise minus factor from distance to town center */
|
||||||
Town *nearest = AirportGetNearestTown(as, tile);
|
Town *nearest = AirportGetNearestTown(as, tile);
|
||||||
|
@ -1967,7 +1967,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
|
|
||||||
Station *st = NULL;
|
Station *st = NULL;
|
||||||
CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), TileArea(tile, w, h), &st);
|
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 */
|
/* Distant join */
|
||||||
if (st == NULL && distant_join) st = Station::GetIfValid(station_to_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 (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);
|
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.*/
|
/* Get the water class of the water tile before it is cleared.*/
|
||||||
WaterClass wc = GetWaterClass(tile_cur);
|
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);
|
tile_cur += TileOffsByDiagDir(direction);
|
||||||
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
|
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),
|
CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0),
|
||||||
TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
|
TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
|
||||||
_dock_w_chk[direction], _dock_h_chk[direction]), &st);
|
_dock_w_chk[direction], _dock_h_chk[direction]), &st);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
/* Distant join */
|
/* Distant join */
|
||||||
if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
|
if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
|
||||||
|
|
|
@ -1499,7 +1499,7 @@ static bool StationJoinerNeeded(CommandContainer cmd, TileArea ta)
|
||||||
if (!_ctrl_pressed) return false;
|
if (!_ctrl_pressed) return false;
|
||||||
|
|
||||||
/* Now check if we could build there */
|
/* 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.
|
/* 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.
|
* If adjacent-stations is disabled and we are building next to a station, do not show the selection window.
|
||||||
|
|
|
@ -218,7 +218,7 @@ static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int
|
||||||
/* Terraform the neighboured corner. The resulting height difference should be 1. */
|
/* Terraform the neighboured corner. The resulting height difference should be 1. */
|
||||||
height_diff += (height_diff < 0 ? 1 : -1);
|
height_diff += (height_diff < 0 ? 1 : -1);
|
||||||
CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
|
CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
|
||||||
if (CmdFailed(cost)) return cost;
|
if (cost.Failed()) return cost;
|
||||||
total_cost.AddCost(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()) {
|
if ((p1 & SLOPE_W) != 0 && tile + TileDiffXY(1, 0) < MapSize()) {
|
||||||
TileIndex t = tile + TileDiffXY(1, 0);
|
TileIndex t = tile + TileDiffXY(1, 0);
|
||||||
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
||||||
if (CmdFailed(cost)) return cost;
|
if (cost.Failed()) return cost;
|
||||||
total_cost.AddCost(cost);
|
total_cost.AddCost(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p1 & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < MapSize()) {
|
if ((p1 & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < MapSize()) {
|
||||||
TileIndex t = tile + TileDiffXY(1, 1);
|
TileIndex t = tile + TileDiffXY(1, 1);
|
||||||
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
||||||
if (CmdFailed(cost)) return cost;
|
if (cost.Failed()) return cost;
|
||||||
total_cost.AddCost(cost);
|
total_cost.AddCost(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p1 & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < MapSize()) {
|
if ((p1 & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < MapSize()) {
|
||||||
TileIndex t = tile + TileDiffXY(0, 1);
|
TileIndex t = tile + TileDiffXY(0, 1);
|
||||||
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
||||||
if (CmdFailed(cost)) return cost;
|
if (cost.Failed()) return cost;
|
||||||
total_cost.AddCost(cost);
|
total_cost.AddCost(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p1 & SLOPE_N) != 0) {
|
if ((p1 & SLOPE_N) != 0) {
|
||||||
TileIndex t = tile + TileDiffXY(0, 0);
|
TileIndex t = tile + TileDiffXY(0, 0);
|
||||||
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
|
||||||
if (CmdFailed(cost)) return cost;
|
if (cost.Failed()) return cost;
|
||||||
total_cost.AddCost(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
|
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);
|
CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, tileh);
|
||||||
_generating_world = curr_gen;
|
_generating_world = curr_gen;
|
||||||
if (CmdFailed(cost)) {
|
if (cost.Failed()) {
|
||||||
_terraform_err_tile = tile;
|
_terraform_err_tile = tile;
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ CommandCost CmdLevelLand(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
uint curh = TileHeight(tile);
|
uint curh = TileHeight(tile);
|
||||||
while (curh != h) {
|
while (curh != h) {
|
||||||
CommandCost ret = DoCommand(tile, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
money -= ret.GetCost();
|
money -= ret.GetCost();
|
||||||
|
|
|
@ -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.
|
/* No, try if we are able to build a road piece there.
|
||||||
* If that fails clear the land, and if that fails exit.
|
* If that fails clear the land, and if that fails exit.
|
||||||
* This is to make sure that we can build a road here later. */
|
* 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)) &&
|
if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_X : ROAD_Y), 0, DC_AUTO, CMD_BUILD_ROAD).Failed() &&
|
||||||
CmdFailed(DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
|
DoCommand(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR).Failed())
|
||||||
return false;
|
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,
|
res = DoCommand(tile, Chance16(1, 16) ? cur_slope : cur_slope ^ SLOPE_ELEVATED, 0,
|
||||||
DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
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. */
|
/* We can consider building on the slope, though. */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ static bool TerraformTownTile(TileIndex tile, int edges, int dir)
|
||||||
assert(tile < MapSize());
|
assert(tile < MapSize());
|
||||||
|
|
||||||
CommandCost r = DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
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);
|
DoCommand(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -948,7 +948,7 @@ static bool GrowTownWithExtraHouse(Town *t, TileIndex tile)
|
||||||
*/
|
*/
|
||||||
static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
|
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;
|
_grow_town_result = GROWTH_SUCCEED;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +1000,7 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
|
||||||
byte bridge_type = RandomRange(MAX_BRIDGES - 1);
|
byte bridge_type = RandomRange(MAX_BRIDGES - 1);
|
||||||
|
|
||||||
/* Can we actually build the bridge? */
|
/* 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);
|
DoCommand(tile, bridge_tile, bridge_type | ROADTYPES_ROAD << 8 | TRANSPORT_ROAD << 15, DC_EXEC | DC_AUTO, CMD_BUILD_BRIDGE);
|
||||||
_grow_town_result = GROWTH_SUCCEED;
|
_grow_town_result = GROWTH_SUCCEED;
|
||||||
return true;
|
return true;
|
||||||
|
@ -1317,7 +1317,7 @@ static bool GrowTown(Town *t)
|
||||||
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
|
for (ptr = _town_coord_mod; ptr != endof(_town_coord_mod); ++ptr) {
|
||||||
/* Only work with plain land that not already has a house */
|
/* Only work with plain land that not already has a house */
|
||||||
if (!IsTileType(tile, MP_HOUSE) && GetTileSlope(tile, NULL) == SLOPE_FLAT) {
|
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);
|
DoCommand(tile, GenRandomRoadBits(), t->index, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
|
||||||
_current_company = old_company;
|
_current_company = old_company;
|
||||||
return true;
|
return true;
|
||||||
|
@ -1552,7 +1552,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
|
|
||||||
if (!random) {
|
if (!random) {
|
||||||
CommandCost ret = TownCanBePlacedHere(tile);
|
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 }};
|
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 */
|
/* Make sure town can be placed here */
|
||||||
if (CmdFailed(TownCanBePlacedHere(tile))) continue;
|
if (TownCanBePlacedHere(tile).Failed()) continue;
|
||||||
|
|
||||||
/* Allocate a town struct */
|
/* Allocate a town struct */
|
||||||
Town *t = new Town(tile);
|
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);
|
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);
|
IncreaseBuildingCount(t, type);
|
||||||
MakeHouseTile(tile, t->index, counter, stage, type, random_bits);
|
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;
|
if (IsTileType(tile, MP_HOUSE) && GetTownIndex(tile) != town) return false;
|
||||||
|
|
||||||
/* can we clear the land? */
|
/* 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);
|
CommandCost r = DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
_current_company = old;
|
_current_company = old;
|
||||||
|
|
||||||
if (CmdFailed(r)) return false;
|
if (r.Failed()) return false;
|
||||||
|
|
||||||
MakeStatue(tile, _current_company, town_id);
|
MakeStatue(tile, _current_company, town_id);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
|
|
|
@ -763,8 +763,8 @@ static void NormalizeTrainVehInDepot(const Train *u)
|
||||||
FOR_ALL_TRAINS(v) {
|
FOR_ALL_TRAINS(v) {
|
||||||
if (v->IsFreeWagon() && v->tile == u->tile &&
|
if (v->IsFreeWagon() && v->tile == u->tile &&
|
||||||
v->track == TRACK_BIT_DEPOT) {
|
v->track == TRACK_BIT_DEPOT) {
|
||||||
if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
|
if (DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
|
||||||
CMD_MOVE_RAIL_VEHICLE)))
|
CMD_MOVE_RAIL_VEHICLE).Failed())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,7 +386,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
case CLEAR_FIELDS:
|
case CLEAR_FIELDS:
|
||||||
case CLEAR_ROCKS: {
|
case CLEAR_ROCKS: {
|
||||||
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,20 +306,20 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
|
|
||||||
/* Try and clear the start landscape */
|
/* Try and clear the start landscape */
|
||||||
CommandCost ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(tile_start, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost = 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);
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
cost.AddCost(terraform_cost_north);
|
cost.AddCost(terraform_cost_north);
|
||||||
|
|
||||||
/* Try and clear the end landscape */
|
/* Try and clear the end landscape */
|
||||||
ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommand(tile_end, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
|
||||||
/* false - end tile slope check */
|
/* 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);
|
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||||
cost.AddCost(terraform_cost_south);
|
cost.AddCost(terraform_cost_south);
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||||
not_valid_below:;
|
not_valid_below:;
|
||||||
/* try and clear the middle landscape */
|
/* try and clear the middle landscape */
|
||||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
break;
|
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);
|
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);
|
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
|
/* 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
|
* 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.
|
* the tree on end_tile.
|
||||||
*/
|
*/
|
||||||
ret = DoCommand(end_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR);
|
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);
|
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 {
|
} else {
|
||||||
ret = DoCommand(end_tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
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(_price[PR_BUILD_TUNNEL]);
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
@ -1319,7 +1319,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
|
||||||
if (new_owner != INVALID_OWNER) {
|
if (new_owner != INVALID_OWNER) {
|
||||||
SetTileOwner(tile, new_owner);
|
SetTileOwner(tile, new_owner);
|
||||||
} else {
|
} 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
|
/* When clearing the bridge/tunnel failed there are still vehicles on/in
|
||||||
* the bridge/tunnel. As all *our* vehicles are already removed, they
|
* the bridge/tunnel. As all *our* vehicles are already removed, they
|
||||||
* must be of another owner. Therefore this can't be rail tunnel/bridge.
|
* 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? */
|
/* 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);
|
return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
|
|
|
@ -114,7 +114,7 @@ CommandCost CmdBuildCompanyHQ(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
||||||
CommandCost cost(EXPENSES_PROPERTY);
|
CommandCost cost(EXPENSES_PROPERTY);
|
||||||
|
|
||||||
cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL);
|
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
|
if (c->location_of_HQ != INVALID_TILE) { // Moving HQ
|
||||||
cost.AddCost(DestroyCompanyHQ(_current_company, flags));
|
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);
|
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) {
|
if (flags & DC_EXEC) {
|
||||||
MakeOwnedLand(tile, _current_company);
|
MakeOwnedLand(tile, _current_company);
|
||||||
|
|
|
@ -1057,7 +1057,7 @@ void VehicleEnterDepot(Vehicle *v)
|
||||||
_current_company = v->owner;
|
_current_company = v->owner;
|
||||||
CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v));
|
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;
|
_vehicles_to_autoreplace[v] = false;
|
||||||
if (v->owner == _local_company) {
|
if (v->owner == _local_company) {
|
||||||
/* Notify the user that we stopped the vehicle */
|
/* Notify the user that we stopped the vehicle */
|
||||||
|
|
|
@ -160,7 +160,7 @@ CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32
|
||||||
|
|
||||||
CommandCost ret = DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
|
CommandCost ret = DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
|
||||||
|
|
||||||
if (CmdSucceeded(ret)) {
|
if (ret.Succeeded()) {
|
||||||
return_value = CommandCost();
|
return_value = CommandCost();
|
||||||
/* We know that the command is valid for at least one vehicle.
|
/* 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 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++) {
|
for (uint i = 0; i < list.Length(); i++) {
|
||||||
CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command);
|
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
|
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);
|
CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
|
||||||
|
|
||||||
if (CmdSucceeded(ret)) {
|
if (ret.Succeeded()) {
|
||||||
did_something = true;
|
did_something = true;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
} else {
|
} 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));
|
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
|
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 */
|
/* 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));
|
if (w_front != NULL) DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front));
|
||||||
return cost;
|
return cost;
|
||||||
|
@ -492,7 +492,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
||||||
/* this s a train car
|
/* this s a train car
|
||||||
* add this unit to the end of the train */
|
* 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);
|
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.
|
/* 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. */
|
* 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_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);
|
byte subtype = GetBestFittingSubType(v, w);
|
||||||
if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
|
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));
|
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()) {
|
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
|
* 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
|
* 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 */
|
* 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 CommandCost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,7 +426,7 @@ struct RefitWindow : public Window {
|
||||||
if (this->cargo != NULL) {
|
if (this->cargo != NULL) {
|
||||||
Vehicle *v = Vehicle::Get(this->window_number);
|
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));
|
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(0, this->cargo->cargo);
|
||||||
SetDParam(1, _returned_refit_capacity);
|
SetDParam(1, _returned_refit_capacity);
|
||||||
SetDParam(2, cost.GetCost());
|
SetDParam(2, cost.GetCost());
|
||||||
|
|
|
@ -126,9 +126,9 @@ CommandCost CmdBuildShipDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
||||||
WaterClass wc1 = GetWaterClass(tile);
|
WaterClass wc1 = GetWaterClass(tile);
|
||||||
WaterClass wc2 = GetWaterClass(tile2);
|
WaterClass wc2 = GetWaterClass(tile2);
|
||||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
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);
|
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 (!Depot::CanAllocateItem()) return CMD_ERROR;
|
||||||
|
|
||||||
|
@ -198,14 +198,14 @@ static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandF
|
||||||
|
|
||||||
/* middle tile */
|
/* middle tile */
|
||||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (ret.Failed()) return CMD_ERROR;
|
||||||
|
|
||||||
delta = TileOffsByDiagDir(dir);
|
delta = TileOffsByDiagDir(dir);
|
||||||
/* lower tile */
|
/* lower tile */
|
||||||
WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
|
WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL;
|
||||||
|
|
||||||
ret = DoCommand(tile - delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
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) {
|
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
|
||||||
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
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;
|
WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL;
|
||||||
|
|
||||||
ret = DoCommand(tile + delta, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
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) {
|
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
|
||||||
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
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;
|
if (IsTileType(tile, MP_WATER) && (!IsTileOwner(tile, OWNER_WATER) || p2 == 1)) continue;
|
||||||
|
|
||||||
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
if (CmdFailed(ret)) return ret;
|
if (ret.Failed()) return ret;
|
||||||
cost.AddCost(ret);
|
cost.AddCost(ret);
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
@ -868,7 +868,7 @@ void DoFloodTile(TileIndex target)
|
||||||
}
|
}
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
case MP_CLEAR:
|
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);
|
MakeShore(target);
|
||||||
MarkTileDirtyByTile(target);
|
MarkTileDirtyByTile(target);
|
||||||
flooded = true;
|
flooded = true;
|
||||||
|
@ -883,7 +883,7 @@ void DoFloodTile(TileIndex target)
|
||||||
FloodVehicles(target);
|
FloodVehicles(target);
|
||||||
|
|
||||||
/* flood flat tile */
|
/* 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);
|
MakeSea(target);
|
||||||
MarkTileDirtyByTile(target);
|
MarkTileDirtyByTile(target);
|
||||||
flooded = true;
|
flooded = true;
|
||||||
|
@ -933,7 +933,7 @@ static void DoDryUp(TileIndex tile)
|
||||||
case MP_WATER:
|
case MP_WATER:
|
||||||
assert(IsCoast(tile));
|
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);
|
MakeClear(tile, CLEAR_GRASS, 3);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue