summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.cpp4
-rw-r--r--src/rail_cmd.cpp20
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/unmovable_cmd.cpp2
-rw-r--r--src/water_cmd.cpp10
6 files changed, 27 insertions, 19 deletions
diff --git a/src/command.cpp b/src/command.cpp
index ccea6821d..c716d7970 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -416,7 +416,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
if (_docommand_recursive == 1 &&
!(flags & DC_QUERY_COST) &&
!(flags & DC_BANKRUPT) &&
- !CheckCompanyHasMoney(res)) {
+ !CheckCompanyHasMoney(res)) { // CheckCompanyHasMoney() modifies 'res' to an error if it fails.
goto error;
}
@@ -433,7 +433,7 @@ CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags,
error:
res.SetGlobalErrorMessage();
_docommand_recursive--;
- return CMD_ERROR;
+ return res;
}
/* if toplevel, subtract the money. */
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 4f020f4f0..4d2580b98 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -741,7 +741,7 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd
*/
static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
+ CommandCost total_cost(EXPENSES_CONSTRUCTION);
Track track = (Track)GB(p2, 4, 3);
bool remove = HasBit(p2, 7);
RailType railtype = (RailType)GB(p2, 0, 4);
@@ -751,12 +751,14 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3
TileIndex end_tile = p1;
Trackdir trackdir = TrackToTrackdir(track);
- if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
+ CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
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);
+ CommandCost ret = DoCommand(tile, railtype, TrackdirToTrack(trackdir), flags, remove ? CMD_REMOVE_SINGLE_RAIL : CMD_BUILD_SINGLE_RAIL);
if (ret.Failed()) {
if (_error_message != STR_ERROR_ALREADY_BUILT && !remove) {
@@ -851,7 +853,7 @@ CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
}
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (cost.Failed()) return CMD_ERROR;
+ if (cost.Failed()) return cost;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -1122,7 +1124,7 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
*/
static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- CommandCost ret, total_cost(EXPENSES_CONSTRUCTION);
+ CommandCost total_cost(EXPENSES_CONSTRUCTION);
bool err = true;
TileIndex start_tile = tile;
@@ -1144,7 +1146,9 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
* since the original amount will be too dense (shorter tracks) */
signal_density *= 2;
- if (ValidateAutoDrag(&trackdir, tile, end_tile).Failed()) return CMD_ERROR;
+ CommandCost ret = ValidateAutoDrag(&trackdir, tile, end_tile);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
track = TrackdirToTrack(trackdir); // trackdir might have changed, keep track in sync
Trackdir start_trackdir = trackdir;
@@ -1198,7 +1202,7 @@ static CommandCost CmdSignalTrackHelper(TileIndex tile, DoCommandFlag flags, uin
if (HasBit(signal_dir, 0)) signals |= SignalAlongTrackdir(trackdir);
if (HasBit(signal_dir, 1)) signals |= SignalAgainstTrackdir(trackdir);
- ret = DoCommand(tile, p1, signals, flags, remove ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
+ CommandCost 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 (ret.Succeeded()) {
@@ -1606,7 +1610,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
while (tracks != TRACK_BIT_NONE) {
Track track = RemoveFirstTrack(&tracks);
CommandCost ret = DoCommand(tile, 0, track, flags, CMD_REMOVE_SINGLE_RAIL);
- if (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
cost.AddCost(ret);
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index ca711f747..d76dba933 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -904,7 +904,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
}
CommandCost cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (cost.Failed()) return CMD_ERROR;
+ if (cost.Failed()) return cost;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 40efc314c..956079d42 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2383,7 +2383,9 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
- if (DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
+ ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
@@ -2396,7 +2398,9 @@ 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 (DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
+ ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index d3a97b5f3..4098c179c 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -152,7 +152,7 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (cost.Failed()) return CMD_ERROR;
+ if (cost.Failed()) return cost;
if (flags & DC_EXEC) {
MakeOwnedLand(tile, _current_company);
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index a37d296d2..2882ac80e 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 (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
ret = DoCommand(tile2, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
if (!Depot::CanAllocateItem()) return CMD_ERROR;
@@ -204,14 +204,14 @@ static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, DoCommandF
/* middle tile */
ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- if (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
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 (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
if (GetTileSlope(tile - delta, NULL) != SLOPE_FLAT) {
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
@@ -220,7 +220,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 (ret.Failed()) return CMD_ERROR;
+ if (ret.Failed()) return ret;
if (GetTileSlope(tile + delta, NULL) != SLOPE_FLAT) {
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}