Codechange: Remove unnecessary 'return_cmd_error` macro. (#13160)
This macro is a leftover from when errors used to be packed into a single int32_t. `return CommandCost` is clearer, and doesn't need a macro.
This commit is contained in:
+30
-30
@@ -201,7 +201,7 @@ CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoC
|
||||
{
|
||||
if (flags & DC_QUERY_COST) {
|
||||
if (bridge_len <= _settings_game.construction.max_bridge_length) return CommandCost();
|
||||
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
return CommandCost(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
}
|
||||
|
||||
if (bridge_type >= MAX_BRIDGES) return CMD_ERROR;
|
||||
@@ -213,7 +213,7 @@ CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoC
|
||||
|
||||
if (b->min_length > bridge_len) return CMD_ERROR;
|
||||
if (bridge_len <= max) return CommandCost();
|
||||
return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
return CommandCost(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +265,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
RailType railtype = INVALID_RAILTYPE;
|
||||
RoadType roadtype = INVALID_ROADTYPE;
|
||||
|
||||
if (!IsValidTile(tile_start)) return_cmd_error(STR_ERROR_BRIDGE_THROUGH_MAP_BORDER);
|
||||
if (!IsValidTile(tile_start)) return CommandCost(STR_ERROR_BRIDGE_THROUGH_MAP_BORDER);
|
||||
|
||||
/* type of bridge */
|
||||
switch (transport_type) {
|
||||
@@ -300,7 +300,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
}
|
||||
|
||||
if (tile_start == tile_end) {
|
||||
return_cmd_error(STR_ERROR_CAN_T_START_AND_END_ON);
|
||||
return CommandCost(STR_ERROR_CAN_T_START_AND_END_ON);
|
||||
}
|
||||
|
||||
Axis direction;
|
||||
@@ -309,7 +309,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
} else if (TileY(tile_start) == TileY(tile_end)) {
|
||||
direction = AXIS_X;
|
||||
} else {
|
||||
return_cmd_error(STR_ERROR_START_AND_END_MUST_BE_IN);
|
||||
return CommandCost(STR_ERROR_START_AND_END_MUST_BE_IN);
|
||||
}
|
||||
|
||||
if (tile_end < tile_start) Swap(tile_start, tile_end);
|
||||
@@ -320,7 +320,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
CommandCost ret = CheckBridgeAvailability(bridge_type, bridge_len, flags);
|
||||
if (ret.Failed()) return ret;
|
||||
} else {
|
||||
if (bridge_len > _settings_game.construction.max_bridge_length) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
if (bridge_len > _settings_game.construction.max_bridge_length) return CommandCost(STR_ERROR_BRIDGE_TOO_LONG);
|
||||
}
|
||||
bridge_len += 2; // begin and end tiles/ramps
|
||||
|
||||
@@ -332,8 +332,8 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
CommandCost terraform_cost_south = CheckBridgeSlope(BRIDGE_PIECE_SOUTH, direction, tileh_end, z_end);
|
||||
|
||||
/* Aqueducts can't be built of flat land. */
|
||||
if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
if (z_start != z_end) return_cmd_error(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
|
||||
if (transport_type == TRANSPORT_WATER && (tileh_start == SLOPE_FLAT || tileh_end == SLOPE_FLAT)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
if (z_start != z_end) return CommandCost(STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT);
|
||||
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
Owner owner;
|
||||
@@ -362,21 +362,21 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
|
||||
/* If this is a railway bridge, make sure the railtypes match. */
|
||||
if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
|
||||
/* If this is a road bridge, make sure the roadtype matches. */
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
RoadType existing_rt = RoadTypeIsRoad(roadtype) ? road_rt : tram_rt;
|
||||
if (existing_rt != roadtype && existing_rt != INVALID_ROADTYPE) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(flags & DC_QUERY_COST)) {
|
||||
/* Do not replace the bridge with the same bridge type. */
|
||||
if ((bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || road_rt == roadtype || tram_rt == roadtype)) {
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
return CommandCost(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
|
||||
/* Do not replace town bridges with lower speed bridges, unless in scenario editor. */
|
||||
@@ -386,7 +386,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
|
||||
if (GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed) {
|
||||
SetDParam(0, t->index);
|
||||
return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
|
||||
return CommandCost(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
|
||||
} else {
|
||||
ChangeTownRating(t, RATING_TUNNEL_BRIDGE_UP_STEP, RATING_MAXIMUM, flags);
|
||||
}
|
||||
@@ -395,7 +395,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
|
||||
/* Do not allow replacing another company's bridges. */
|
||||
if (!IsTileOwner(tile_start, company) && !IsTileOwner(tile_start, OWNER_TOWN) && !IsTileOwner(tile_start, OWNER_NONE)) {
|
||||
return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
||||
return CommandCost(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
||||
}
|
||||
|
||||
/* The cost of clearing the current bridge. */
|
||||
@@ -415,7 +415,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
if (ret.Failed()) return ret;
|
||||
cost = ret;
|
||||
|
||||
if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
cost.AddCost(terraform_cost_north);
|
||||
|
||||
/* Try and clear the end landscape */
|
||||
@@ -424,7 +424,7 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
cost.AddCost(ret);
|
||||
|
||||
/* false - end tile slope check */
|
||||
if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
cost.AddCost(terraform_cost_south);
|
||||
|
||||
const TileIndex heads[] = {tile_start, tile_end};
|
||||
@@ -432,17 +432,17 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
if (IsBridgeAbove(heads[i])) {
|
||||
TileIndex north_head = GetNorthernBridgeEnd(heads[i]);
|
||||
|
||||
if (direction == GetBridgeAxis(heads[i])) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
if (direction == GetBridgeAxis(heads[i])) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
|
||||
if (z_start + 1 == GetBridgeHeight(north_head)) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TileIndexDiff delta = TileOffsByAxis(direction);
|
||||
for (TileIndex tile = tile_start + delta; tile != tile_end; tile += delta) {
|
||||
if (GetTileMaxZ(tile) > z_start) return_cmd_error(STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN);
|
||||
if (GetTileMaxZ(tile) > z_start) return CommandCost(STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN);
|
||||
|
||||
if (z_start >= (GetTileZ(tile) + _settings_game.construction.max_bridge_height)) {
|
||||
/*
|
||||
@@ -451,12 +451,12 @@ CommandCost CmdBuildBridge(DoCommandFlag flags, TileIndex tile_end, TileIndex ti
|
||||
* See http://www.tt-forums.net/viewtopic.php?f=33&t=40844&start=980#p1131762
|
||||
* for a detailed discussion. z_start here is one heightlevel below the bridge level.
|
||||
*/
|
||||
return_cmd_error(STR_ERROR_BRIDGE_TOO_HIGH_FOR_TERRAIN);
|
||||
return CommandCost(STR_ERROR_BRIDGE_TOO_HIGH_FOR_TERRAIN);
|
||||
}
|
||||
|
||||
if (IsBridgeAbove(tile)) {
|
||||
/* Disallow crossing bridges for the time being */
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
|
||||
switch (GetTileType(tile)) {
|
||||
@@ -656,9 +656,9 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportT
|
||||
|
||||
auto [start_tileh, start_z] = GetTileSlopeZ(start_tile);
|
||||
DiagDirection direction = GetInclinedSlopeDirection(start_tileh);
|
||||
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
|
||||
if (direction == INVALID_DIAGDIR) return CommandCost(STR_ERROR_SITE_UNSUITABLE_FOR_TUNNEL);
|
||||
|
||||
if (HasTileWaterGround(start_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (HasTileWaterGround(start_tile)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
|
||||
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, start_tile);
|
||||
if (ret.Failed()) return ret;
|
||||
@@ -690,13 +690,13 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportT
|
||||
int end_z;
|
||||
for (;;) {
|
||||
end_tile += delta;
|
||||
if (!IsValidTile(end_tile)) return_cmd_error(STR_ERROR_TUNNEL_THROUGH_MAP_BORDER);
|
||||
if (!IsValidTile(end_tile)) return CommandCost(STR_ERROR_TUNNEL_THROUGH_MAP_BORDER);
|
||||
std::tie(end_tileh, end_z) = GetTileSlopeZ(end_tile);
|
||||
|
||||
if (start_z == end_z) break;
|
||||
|
||||
if (!_cheats.crossing_tunnels.value && IsTunnelInWayDir(end_tile, start_z, tunnel_in_way_dir)) {
|
||||
return_cmd_error(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
|
||||
return CommandCost(STR_ERROR_ANOTHER_TUNNEL_IN_THE_WAY);
|
||||
}
|
||||
|
||||
tiles++;
|
||||
@@ -716,13 +716,13 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportT
|
||||
/* if the command fails from here on we want the end tile to be highlighted */
|
||||
_build_tunnel_endtile = end_tile;
|
||||
|
||||
if (tiles > _settings_game.construction.max_tunnel_length) return_cmd_error(STR_ERROR_TUNNEL_TOO_LONG);
|
||||
if (tiles > _settings_game.construction.max_tunnel_length) return CommandCost(STR_ERROR_TUNNEL_TOO_LONG);
|
||||
|
||||
if (HasTileWaterGround(end_tile)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (HasTileWaterGround(end_tile)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
|
||||
/* Clear the tile in any case */
|
||||
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile);
|
||||
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
||||
if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
||||
cost.AddCost(ret);
|
||||
|
||||
/* slope of end tile must be complementary to the slope of the start tile */
|
||||
@@ -755,7 +755,7 @@ CommandCost CmdBuildTunnel(DoCommandFlag flags, TileIndex start_tile, TransportT
|
||||
|
||||
ret = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, false));
|
||||
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
|
||||
if (ret.Failed()) return_cmd_error(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
||||
if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
|
||||
cost.AddCost(ret);
|
||||
}
|
||||
cost.AddCost(_price[PR_BUILD_TUNNEL]);
|
||||
@@ -1017,10 +1017,10 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
||||
static CommandCost ClearTile_TunnelBridge(TileIndex tile, DoCommandFlag flags)
|
||||
{
|
||||
if (IsTunnel(tile)) {
|
||||
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST);
|
||||
if (flags & DC_AUTO) return CommandCost(STR_ERROR_MUST_DEMOLISH_TUNNEL_FIRST);
|
||||
return DoClearTunnel(tile, flags);
|
||||
} else { // IsBridge(tile)
|
||||
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
if (flags & DC_AUTO) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
return DoClearBridge(tile, flags);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user