mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-27 06:04:25 +01:00
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:
@@ -240,7 +240,7 @@ static CommandCost EnsureNoTrainOnTrack(TileIndex tile, Track track)
|
||||
*/
|
||||
static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build)
|
||||
{
|
||||
if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
|
||||
if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
|
||||
|
||||
/* So, we have a tile with tracks on it (and possibly signals). Let's see
|
||||
* what tracks first */
|
||||
@@ -250,7 +250,7 @@ static CommandCost CheckTrackCombination(TileIndex tile, TrackBits to_build)
|
||||
/* Are we really building something new? */
|
||||
if (current == future) {
|
||||
/* Nothing new is being built */
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
return CommandCost(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
|
||||
/* Normally, we may overlap and any combination is valid */
|
||||
@@ -393,7 +393,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex
|
||||
{
|
||||
/* don't allow building on the lower side of a coast */
|
||||
if (GetFloodingBehaviour(tile) != FLOOD_NONE) {
|
||||
if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (!IsSteepSlope(tileh) && ((~_valid_tracks_on_leveled_foundation[tileh] & (rail_bits | existing)) != 0)) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
}
|
||||
|
||||
Foundation f_new = GetRailFoundation(tileh, rail_bits | existing);
|
||||
@@ -401,7 +401,7 @@ static CommandCost CheckRailSlope(Slope tileh, TrackBits rail_bits, TrackBits ex
|
||||
/* check track/slope combination */
|
||||
if ((f_new == FOUNDATION_INVALID) ||
|
||||
((f_new != FOUNDATION_NONE) && (!_settings_game.construction.build_on_slopes))) {
|
||||
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
}
|
||||
|
||||
Foundation f_old = GetRailFoundation(tileh, existing);
|
||||
@@ -439,7 +439,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
if (!IsPlainRail(tile)) return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); // just get appropriate error message
|
||||
|
||||
if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
|
||||
if (!IsCompatibleRail(GetRailType(tile), railtype)) return CommandCost(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
|
||||
|
||||
ret = CheckTrackCombination(tile, trackbit);
|
||||
if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
|
||||
@@ -451,7 +451,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
|
||||
/* If adding the new track causes any overlap, all signals must be removed first */
|
||||
if (!auto_remove_signals) return_cmd_error(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
|
||||
if (!auto_remove_signals) return CommandCost(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
|
||||
|
||||
for (Track track_it = TRACK_BEGIN; track_it < TRACK_END; track_it++) {
|
||||
if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) {
|
||||
@@ -494,7 +494,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
case MP_ROAD: {
|
||||
/* Level crossings may only be built on these slopes */
|
||||
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
if (!HasBit(VALID_LEVEL_CROSSING_SLOPES, tileh)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
|
||||
|
||||
if (!_settings_game.construction.crossing_with_competitor && _current_company != OWNER_DEITY) {
|
||||
CommandCost ret = CheckTileOwnership(tile);
|
||||
@@ -505,17 +505,17 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
if (IsNormalRoad(tile)) {
|
||||
if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
|
||||
if (HasRoadWorks(tile)) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
|
||||
|
||||
if (GetDisallowedRoadDirections(tile) != DRD_NONE) return_cmd_error(STR_ERROR_CROSSING_ON_ONEWAY_ROAD);
|
||||
if (GetDisallowedRoadDirections(tile) != DRD_NONE) return CommandCost(STR_ERROR_CROSSING_ON_ONEWAY_ROAD);
|
||||
|
||||
if (RailNoLevelCrossings(railtype)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_RAIL);
|
||||
if (RailNoLevelCrossings(railtype)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_RAIL);
|
||||
|
||||
RoadType roadtype_road = GetRoadTypeRoad(tile);
|
||||
RoadType roadtype_tram = GetRoadTypeTram(tile);
|
||||
|
||||
if (roadtype_road != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_road)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
|
||||
if (roadtype_tram != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_tram)) return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
|
||||
if (roadtype_road != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_road)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
|
||||
if (roadtype_tram != INVALID_ROADTYPE && RoadNoLevelCrossing(roadtype_tram)) return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
|
||||
|
||||
RoadBits road = GetRoadBits(tile, RTT_ROAD);
|
||||
RoadBits tram = GetRoadBits(tile, RTT_TRAM);
|
||||
@@ -560,7 +560,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
}
|
||||
|
||||
if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) {
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
return CommandCost(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
@@ -630,7 +630,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_ROAD: {
|
||||
if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
|
||||
if (_current_company != OWNER_WATER) {
|
||||
CommandCost ret = CheckTileOwnership(tile);
|
||||
@@ -664,7 +664,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
case MP_RAILWAY: {
|
||||
TrackBits present;
|
||||
/* There are no rails present at depots. */
|
||||
if (!IsPlainRail(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
if (!IsPlainRail(tile)) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
|
||||
if (_current_company != OWNER_WATER) {
|
||||
CommandCost ret = CheckTileOwnership(tile);
|
||||
@@ -675,7 +675,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
present = GetTrackBits(tile);
|
||||
if ((present & trackbit) == 0) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
if ((present & trackbit) == 0) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
if (present == (TRACK_BIT_X | TRACK_BIT_Y)) crossing = true;
|
||||
|
||||
cost.AddCost(RailClearCost(GetRailType(tile)));
|
||||
@@ -723,7 +723,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
|
||||
break;
|
||||
}
|
||||
|
||||
default: return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
default: return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
@@ -978,7 +978,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
|
||||
if (tileh != SLOPE_FLAT) {
|
||||
if (!_settings_game.construction.build_on_slopes || !CanBuildDepotByTileh(dir, tileh)) {
|
||||
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
|
||||
return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
|
||||
}
|
||||
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
|
||||
}
|
||||
@@ -1001,7 +1001,7 @@ CommandCost CmdBuildTrainDepot(DoCommandFlag flags, TileIndex tile, RailType rai
|
||||
cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
|
||||
if (cost.Failed()) return cost;
|
||||
|
||||
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
|
||||
if (!Depot::CanAllocateItem()) return CMD_ERROR;
|
||||
}
|
||||
@@ -1059,7 +1059,7 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
|
||||
/* You can only build signals on plain rail tiles, and the selected track must exist */
|
||||
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) ||
|
||||
!HasTrack(tile, track)) {
|
||||
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
}
|
||||
/* Protect against invalid signal copying */
|
||||
if (signals_copy != 0 && (signals_copy & SignalOnTrack(track)) == 0) return CMD_ERROR;
|
||||
@@ -1068,13 +1068,13 @@ CommandCost CmdBuildSingleSignal(DoCommandFlag flags, TileIndex tile, Track trac
|
||||
if (ret.Failed()) return ret;
|
||||
|
||||
/* See if this is a valid track combination for signals (no overlap) */
|
||||
if (TracksOverlap(GetTrackBits(tile))) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
|
||||
if (TracksOverlap(GetTrackBits(tile))) return CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
|
||||
|
||||
/* In case we don't want to change an existing signal, return without error. */
|
||||
if (skip_existing_signals && HasSignalOnTrack(tile, track)) return CommandCost();
|
||||
|
||||
/* you can not convert a signal if no signal is on track */
|
||||
if (convert_signal && !HasSignalOnTrack(tile, track)) return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
|
||||
if (convert_signal && !HasSignalOnTrack(tile, track)) return CommandCost(STR_ERROR_THERE_ARE_NO_SIGNALS);
|
||||
|
||||
CommandCost cost;
|
||||
if (!HasSignalOnTrack(tile, track)) {
|
||||
@@ -1263,7 +1263,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlag flags, TileIndex tile, Til
|
||||
if (signal_density == 0 || signal_density > 20) return CMD_ERROR;
|
||||
if (!remove && (sigtype > SIGTYPE_LAST || sigvar > SIG_SEMAPHORE)) return CMD_ERROR;
|
||||
|
||||
if (!IsPlainRailTile(tile)) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
if (!IsPlainRailTile(tile)) return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
TileIndex start_tile = tile;
|
||||
|
||||
/* Interpret signal_density as the logical length of said amount of tiles in X/Y direction. */
|
||||
@@ -1461,10 +1461,10 @@ CommandCost CmdBuildSignalTrack(DoCommandFlag flags, TileIndex tile, TileIndex e
|
||||
CommandCost CmdRemoveSingleSignal(DoCommandFlag flags, TileIndex tile, Track track)
|
||||
{
|
||||
if (!ValParamTrackOrientation(track) || !IsPlainRailTile(tile) || !HasTrack(tile, track)) {
|
||||
return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
return CommandCost(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK);
|
||||
}
|
||||
if (!HasSignalOnTrack(tile, track)) {
|
||||
return_cmd_error(STR_ERROR_THERE_ARE_NO_SIGNALS);
|
||||
return CommandCost(STR_ERROR_THERE_ARE_NO_SIGNALS);
|
||||
}
|
||||
|
||||
/* Only water can remove signals from anyone */
|
||||
@@ -1803,13 +1803,13 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlag flags)
|
||||
|
||||
if (flags & DC_AUTO) {
|
||||
if (!IsTileOwner(tile, _current_company)) {
|
||||
return_cmd_error(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
||||
return CommandCost(STR_ERROR_AREA_IS_OWNED_BY_ANOTHER);
|
||||
}
|
||||
|
||||
if (IsPlainRail(tile)) {
|
||||
return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
} else {
|
||||
return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
||||
return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2993,10 +2993,10 @@ static VehicleEnterTileStatus VehicleEnter_Track(Vehicle *u, TileIndex tile, int
|
||||
*/
|
||||
static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old, Slope tileh_old, int z_new, Slope tileh_new, TrackBits rail_bits)
|
||||
{
|
||||
if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
if (!_settings_game.construction.build_on_slopes || !AutoslopeEnabled()) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
|
||||
/* Is the slope-rail_bits combination valid in general? I.e. is it safe to call GetRailFoundation() ? */
|
||||
if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
if (CheckRailSlope(tileh_new, rail_bits, TRACK_BIT_NONE, tile).Failed()) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
|
||||
/* Get the slopes on top of the foundations */
|
||||
z_old += ApplyFoundationToSlope(GetRailFoundation(tileh_old, rail_bits), tileh_old);
|
||||
@@ -3011,14 +3011,14 @@ static CommandCost TestAutoslopeOnRailTile(TileIndex tile, uint flags, int z_old
|
||||
|
||||
/* Surface slope must not be changed */
|
||||
default:
|
||||
if (z_old != z_new || tileh_old != tileh_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
if (z_old != z_new || tileh_old != tileh_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
|
||||
}
|
||||
|
||||
/* The height of the track_corner must not be changed. The rest ensures GetRailFoundation() already. */
|
||||
z_old += GetSlopeZInCorner(RemoveHalftileSlope(tileh_old), track_corner);
|
||||
z_new += GetSlopeZInCorner(RemoveHalftileSlope(tileh_new), track_corner);
|
||||
if (z_old != z_new) return_cmd_error(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
if (z_old != z_new) return CommandCost(STR_ERROR_MUST_REMOVE_RAILROAD_TRACK);
|
||||
|
||||
CommandCost cost = CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
|
||||
/* Make the ground dirty, if surface slope has changed */
|
||||
@@ -3047,7 +3047,7 @@ static CommandCost TerraformTile_Track(TileIndex tile, DoCommandFlag flags, int
|
||||
bool was_water = (GetRailGroundType(tile) == RAIL_GROUND_WATER && IsSlopeWithOneCornerRaised(tileh_old));
|
||||
|
||||
/* Allow clearing the water only if there is no ship */
|
||||
if (was_water && HasVehicleOnPos(tile, nullptr, &EnsureNoShipProc)) return_cmd_error(STR_ERROR_SHIP_IN_THE_WAY);
|
||||
if (was_water && HasVehicleOnPos(tile, nullptr, &EnsureNoShipProc)) return CommandCost(STR_ERROR_SHIP_IN_THE_WAY);
|
||||
|
||||
/* First test autoslope. However if it succeeds we still have to test the rest, because non-autoslope terraforming is cheaper. */
|
||||
CommandCost autoslope_result = TestAutoslopeOnRailTile(tile, flags, z_old, tileh_old, z_new, tileh_new, rail_bits);
|
||||
|
||||
Reference in New Issue
Block a user