1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-21 19:32:54 +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:
Peter Nelson
2024-12-08 18:02:30 +00:00
committed by GitHub
parent 369e8a6fe9
commit 1e77fd0b61
27 changed files with 276 additions and 286 deletions

View File

@@ -304,7 +304,7 @@ CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, R
/* you can remove all kind of roads with extra dynamite */
if (!_settings_game.construction.extra_dynamite) {
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);
}
rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
}
@@ -328,7 +328,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
RoadType existing_rt = MayHaveRoad(tile) ? GetRoadType(tile, rtt) : INVALID_ROADTYPE;
/* The tile doesn't have the given road type */
if (existing_rt == INVALID_ROADTYPE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
if (existing_rt == INVALID_ROADTYPE) return CommandCost((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
switch (GetTileType(tile)) {
case MP_ROAD: {
@@ -366,7 +366,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
CommandCost cost(EXPENSES_CONSTRUCTION);
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
/* Removing any roadbit in the bridge axis removes the roadtype (that's the behaviour remove-long-roads needs) */
if ((AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) & pieces) == ROAD_NONE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
if ((AxisToRoadBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) & pieces) == ROAD_NONE) return CommandCost((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
/* Pay for *every* tile of the bridge or tunnel */
@@ -421,7 +421,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
const RoadBits other = GetRoadBits(tile, OtherRoadTramType(rtt));
const Foundation f = GetRoadFoundation(tileh, present);
if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
if (HasRoadWorks(tile) && _current_company != OWNER_WATER) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
/* Autocomplete to a straight road
* @li if the bits of the other roadtypes result in another foundation
@@ -433,7 +433,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
/* limit the bits to delete to the existing bits. */
pieces &= present;
if (pieces == ROAD_NONE) return_cmd_error((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
if (pieces == ROAD_NONE) return CommandCost((rtt == RTT_TRAM) ? STR_ERROR_THERE_IS_NO_TRAMWAY : STR_ERROR_THERE_IS_NO_ROAD);
/* Now set present what it will be after the remove */
present ^= pieces;
@@ -644,7 +644,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
case MP_ROAD:
switch (GetRoadTileType(tile)) {
case ROAD_TILE_NORMAL: {
if (HasRoadWorks(tile)) return_cmd_error(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
if (HasRoadWorks(tile)) return CommandCost(STR_ERROR_ROAD_WORKS_IN_PROGRESS);
other_bits = GetRoadBits(tile, OtherRoadTramType(rtt));
if (!HasTileRoadType(tile, rtt)) break;
@@ -653,12 +653,12 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
bool crossing = !IsStraightRoad(existing | pieces);
if (rtt == RTT_ROAD && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
/* Junctions cannot be one-way */
return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
return CommandCost(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
}
if ((existing & pieces) == pieces) {
/* We only want to set the (dis)allowed road directions */
if (toggle_drd != DRD_NONE && rtt == RTT_ROAD) {
if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
if (crossing) return CommandCost(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
Owner owner = GetRoadOwner(tile, rtt);
if (owner != OWNER_NONE) {
@@ -685,7 +685,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
}
return CommandCost();
}
return_cmd_error(STR_ERROR_ALREADY_BUILT);
return CommandCost(STR_ERROR_ALREADY_BUILT);
}
/* Disallow breaking end-of-line of someone else
* so trams can still reverse on this tile. */
@@ -701,18 +701,18 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
case ROAD_TILE_CROSSING:
if (RoadNoLevelCrossing(rt)) {
return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
}
other_bits = GetCrossingRoadBits(tile);
if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
pieces = other_bits; // we need to pay for both roadbits
if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
break;
case ROAD_TILE_DEPOT:
if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return CommandCost(STR_ERROR_ALREADY_BUILT);
goto do_clear;
default: NOT_REACHED();
@@ -721,12 +721,12 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
case MP_RAILWAY: {
if (IsSteepSlope(tileh)) {
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
/* 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);
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
if (!_settings_game.construction.crossing_with_competitor && company != OWNER_TOWN && company != OWNER_DEITY) {
@@ -737,11 +737,11 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
if (GetRailTileType(tile) != RAIL_TILE_NORMAL) goto do_clear;
if (RoadNoLevelCrossing(rt)) {
return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_ROAD);
return CommandCost(STR_ERROR_CROSSING_DISALLOWED_ROAD);
}
if (RailNoLevelCrossings(GetRailType(tile))) {
return_cmd_error(STR_ERROR_CROSSING_DISALLOWED_RAIL);
return CommandCost(STR_ERROR_CROSSING_DISALLOWED_RAIL);
}
Axis roaddir;
@@ -788,14 +788,14 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
}
case MP_STATION: {
if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if ((GetAnyRoadBits(tile, rtt) & pieces) == pieces) return CommandCost(STR_ERROR_ALREADY_BUILT);
if (!IsDriveThroughStopTile(tile)) goto do_clear;
RoadBits curbits = AxisToRoadBits(GetDriveThroughStopAxis(tile));
if (pieces & ~curbits) goto do_clear;
pieces = curbits; // we need to pay for both roadbits
if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
break;
}
@@ -803,7 +803,7 @@ CommandCost CmdBuildRoad(DoCommandFlag flags, TileIndex tile, RoadBits pieces, R
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) goto do_clear;
/* Only allow building the outern roadbit, so building long roads stops at existing bridges */
if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
if (HasTileRoadType(tile, rtt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
if (HasTileRoadType(tile, rtt)) return CommandCost(STR_ERROR_ALREADY_BUILT);
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile));
if (ret.Failed()) return ret;
@@ -829,7 +829,7 @@ do_clear:;
/* Return an error if we need to build a foundation (ret != 0) but the
* current setting is turned off */
if (ret.Failed() || (ret.GetCost() != 0 && !_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);
}
cost.AddCost(ret);
}
@@ -847,7 +847,7 @@ do_clear:;
RoadBits bits = GetRoadBits(tile, OtherRoadTramType(rtt));
/* do not check if there are not road bits of given type */
if (bits != ROAD_NONE && GetRoadFoundation(slope, bits) != found_new) {
return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
}
}
@@ -1155,7 +1155,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt,
Slope tileh = GetTileSlope(tile);
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]);
}
@@ -1179,7 +1179,7 @@ CommandCost CmdBuildRoadDepot(DoCommandFlag flags, TileIndex tile, RoadType rt,
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;
}
@@ -1249,13 +1249,13 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
}
return ret;
}
return_cmd_error(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
}
case ROAD_TILE_CROSSING: {
CommandCost ret(EXPENSES_CONSTRUCTION);
if (flags & DC_AUTO) return_cmd_error(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
if (flags & DC_AUTO) return CommandCost(STR_ERROR_MUST_REMOVE_ROAD_FIRST);
/* Must iterate over the roadtypes in a reverse manner because
* tram tracks must be removed before the road bits. */
@@ -1276,7 +1276,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlag flags)
default:
case ROAD_TILE_DEPOT:
if (flags & DC_AUTO) {
return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
}
return RemoveRoadDepot(tile, flags);
}