1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-23 20:24:12 +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

@@ -128,7 +128,7 @@ CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID c
if (closest_station == INVALID_STATION) {
closest_station = t;
} else if (closest_station != t) {
return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
}
}
}
@@ -705,14 +705,14 @@ static CommandCost BuildStationPart(Station **st, DoCommandFlag flags, bool reus
if (*st != nullptr) {
if ((*st)->owner != _current_company) {
return_cmd_error(CMD_ERROR);
return CommandCost(CMD_ERROR);
}
CommandCost ret = (*st)->rect.BeforeAddRect(area.tile, area.w, area.h, StationRect::ADD_TEST);
if (ret.Failed()) return ret;
} else {
/* allocate and initialize new station */
if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
if (!Station::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING);
if (flags & DC_EXEC) {
*st = new Station(area.tile);
@@ -803,7 +803,7 @@ CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags);
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge = true)
{
if (check_bridge && IsBridgeAbove(tile)) {
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
}
CommandCost ret = EnsureNoVehicleOnGround(tile);
@@ -817,7 +817,7 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
*/
if ((!allow_steep && IsSteepSlope(tileh)) ||
((!_settings_game.construction.build_on_slopes) && tileh != SLOPE_FLAT)) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
}
CommandCost cost(EXPENSES_CONSTRUCTION);
@@ -826,7 +826,7 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
/* Forbid building if the tile faces a slope in a invalid direction. */
for (DiagDirection dir = DIAGDIR_BEGIN; dir != DIAGDIR_END; dir++) {
if (HasBit(invalid_dirs, dir) && !CanBuildDepotByTileh(dir, tileh)) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
}
}
cost.AddCost(_price[PR_BUILD_FOUNDATION]);
@@ -837,7 +837,7 @@ CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z
/* First tile. */
allowed_z = flat_z;
} else if (allowed_z != flat_z) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
}
return cost;
@@ -912,14 +912,14 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
if (*station == INVALID_STATION) {
*station = st;
} else if (*station != st) {
return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
}
}
} else {
/* If we are building a station with a valid railtype, we may be able to overbuild an existing rail tile. */
if (rt != INVALID_RAILTYPE && IsPlainRailTile(tile_cur)) {
/* Don't overbuild signals. */
if (HasSignals(tile_cur)) return_cmd_error(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
if (HasSignals(tile_cur)) return CommandCost(STR_ERROR_MUST_REMOVE_SIGNALS_FIRST);
/* The current rail type must have power on the to-be-built type (e.g. convert normal rail to electrified rail). */
if (HasPowerOnRail(GetRailType(tile_cur), rt)) {
@@ -986,13 +986,13 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
}
/* Drive-through station in the wrong direction. */
if (is_drive_through && IsDriveThroughStopTile(cur_tile) && GetDriveThroughStopAxis(cur_tile) != axis) {
return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
return CommandCost(STR_ERROR_DRIVE_THROUGH_DIRECTION);
}
StationID st = GetStationIndex(cur_tile);
if (*station == INVALID_STATION) {
*station = st;
} else if (*station != st) {
return_cmd_error(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING);
}
}
} else {
@@ -1003,14 +1003,14 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
/* Someone was pedantic and *NEEDED* three fracking different error messages. */
switch (CountBits(rb)) {
case 1:
return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
return CommandCost(STR_ERROR_DRIVE_THROUGH_DIRECTION);
case 2:
if (rb == ROAD_X || rb == ROAD_Y) return_cmd_error(STR_ERROR_DRIVE_THROUGH_DIRECTION);
return_cmd_error(STR_ERROR_DRIVE_THROUGH_CORNER);
if (rb == ROAD_X || rb == ROAD_Y) return CommandCost(STR_ERROR_DRIVE_THROUGH_DIRECTION);
return CommandCost(STR_ERROR_DRIVE_THROUGH_CORNER);
default: // 3 or 4
return_cmd_error(STR_ERROR_DRIVE_THROUGH_JUNCTION);
return CommandCost(STR_ERROR_DRIVE_THROUGH_JUNCTION);
}
}
@@ -1020,14 +1020,14 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
if (road_rt != INVALID_ROADTYPE) {
Owner road_owner = GetRoadOwner(cur_tile, RTT_ROAD);
if (road_owner == OWNER_TOWN) {
if (!_settings_game.construction.road_stop_on_town_road) return_cmd_error(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
if (!_settings_game.construction.road_stop_on_town_road) return CommandCost(STR_ERROR_DRIVE_THROUGH_ON_TOWN_ROAD);
} else if (!_settings_game.construction.road_stop_on_competitor_road && road_owner != OWNER_NONE) {
ret = CheckOwnership(road_owner);
if (ret.Failed()) return ret;
}
uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_ROAD));
if (rt != INVALID_ROADTYPE && RoadTypeIsRoad(rt) && !HasPowerOnRoad(rt, road_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
if (rt != INVALID_ROADTYPE && RoadTypeIsRoad(rt) && !HasPowerOnRoad(rt, road_rt)) return CommandCost(STR_ERROR_NO_SUITABLE_ROAD);
if (GetDisallowedRoadDirections(cur_tile) != DRD_NONE && road_owner != OWNER_TOWN) {
ret = CheckOwnership(road_owner);
@@ -1053,14 +1053,14 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
}
uint num_pieces = CountBits(GetRoadBits(cur_tile, RTT_TRAM));
if (rt != INVALID_ROADTYPE && RoadTypeIsTram(rt) && !HasPowerOnRoad(rt, tram_rt)) return_cmd_error(STR_ERROR_NO_SUITABLE_ROAD);
if (rt != INVALID_ROADTYPE && RoadTypeIsTram(rt) && !HasPowerOnRoad(rt, tram_rt)) return CommandCost(STR_ERROR_NO_SUITABLE_ROAD);
cost.AddCost(RoadBuildCost(tram_rt) * (2 - num_pieces));
} else if (rt != INVALID_ROADTYPE && RoadTypeIsTram(rt)) {
cost.AddCost(RoadBuildCost(rt) * 2);
}
} else if (rt == INVALID_ROADTYPE) {
return_cmd_error(STR_ERROR_THERE_IS_NO_ROAD);
return CommandCost(STR_ERROR_THERE_IS_NO_ROAD);
} else {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile);
if (ret.Failed()) return ret;
@@ -1091,7 +1091,7 @@ CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta)
/* make sure the final size is not too big. */
if (new_ta.w > _settings_game.station.station_spread || new_ta.h > _settings_game.station.station_spread) {
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
}
return CommandCost();
@@ -1169,7 +1169,7 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station
if (adjacent && existing_station != station_to_join) {
/* You can't build an adjacent station over the top of one that
* already exists. */
return_cmd_error(error_message);
return CommandCost(error_message);
} else {
/* Extend the current station, and don't check whether it will
* be near any other stations. */
@@ -1398,14 +1398,14 @@ CommandCost CmdBuildRailStation(DoCommandFlag flags, TileIndex tile_org, RailTyp
/* Check if we can allocate a custom stationspec to this station */
const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
if (specindex == -1) return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
if (statspec != nullptr) {
/* Perform NewStation checks */
/* Check if the station size is permitted */
if (HasBit(statspec->disallowed_platforms, std::min(numtracks - 1, 7))) return_cmd_error(STR_ERROR_STATION_DISALLOWED_NUMBER_TRACKS);
if (HasBit(statspec->disallowed_lengths, std::min(plat_len - 1, 7))) return_cmd_error(STR_ERROR_STATION_DISALLOWED_LENGTH);
if (HasBit(statspec->disallowed_platforms, std::min(numtracks - 1, 7))) return CommandCost(STR_ERROR_STATION_DISALLOWED_NUMBER_TRACKS);
if (HasBit(statspec->disallowed_lengths, std::min(plat_len - 1, 7))) return CommandCost(STR_ERROR_STATION_DISALLOWED_LENGTH);
/* Check if the station is buildable */
if (HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) {
@@ -1983,7 +1983,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8_t width,
}
/* Check if the requested road stop is too big */
if (width > _settings_game.station.station_spread || length > _settings_game.station.station_spread) return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
if (width > _settings_game.station.station_spread || length > _settings_game.station.station_spread) return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
/* Check for incorrect width / length. */
if (width == 0 || length == 0) return CMD_ERROR;
/* Check if the first tile and the last tile are valid */
@@ -2019,14 +2019,14 @@ CommandCost CmdBuildRoadStop(DoCommandFlag flags, TileIndex tile, uint8_t width,
if (ret.Failed()) return ret;
/* Check if this number of road stops can be allocated. */
if (!RoadStop::CanAllocateItem(static_cast<size_t>(roadstop_area.w) * roadstop_area.h)) return_cmd_error(is_truck_stop ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
if (!RoadStop::CanAllocateItem(static_cast<size_t>(roadstop_area.w) * roadstop_area.h)) return CommandCost(is_truck_stop ? STR_ERROR_TOO_MANY_TRUCK_STOPS : STR_ERROR_TOO_MANY_BUS_STOPS);
ret = BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
if (ret.Failed()) return ret;
/* Check if we can allocate a custom stationspec to this station */
int specindex = AllocateSpecToRoadStop(roadstopspec, st, (flags & DC_EXEC) != 0);
if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
if (specindex == -1) return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS);
if (roadstopspec != nullptr) {
/* Perform NewGRF checks */
@@ -2550,7 +2550,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
TileArea airport_area = TileArea(tile, w, h);
if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
}
AirportTileTableIterator tile_iter(as->layouts[layout].tiles.data(), tile);
@@ -2586,7 +2586,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
if (authority_refuse_message != STR_NULL) {
SetDParam(0, authority_refuse_town->index);
return_cmd_error(authority_refuse_message);
return CommandCost(authority_refuse_message);
}
Station *st = nullptr;
@@ -2600,7 +2600,7 @@ CommandCost CmdBuildAirport(DoCommandFlag flags, TileIndex tile, uint8_t airport
if (ret.Failed()) return ret;
if (st != nullptr && st->airport.tile != INVALID_TILE) {
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
}
for (AirportTileTableIterator iter(as->layouts[layout].tiles.data(), tile); iter != INVALID_TILE; ++iter) {
@@ -2670,7 +2670,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
for (const Aircraft *a : Aircraft::Iterate()) {
if (!a->IsNormalAircraft()) continue;
if (a->targetairport == st->index && a->state != FLYING) {
return_cmd_error(STR_ERROR_AIRCRAFT_IN_THE_WAY);
return CommandCost(STR_ERROR_AIRCRAFT_IN_THE_WAY);
}
}
@@ -2801,16 +2801,16 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_
if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile));
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (direction == INVALID_DIAGDIR) return CommandCost(STR_ERROR_SITE_UNSUITABLE);
direction = ReverseDiagDir(direction);
/* Docks cannot be placed on rapids */
if (HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
if (HasTileWaterGround(tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE);
CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
if (ret.Failed()) return ret;
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
@@ -2820,10 +2820,10 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
if (!HasTileWaterGround(tile_cur) || !IsTileFlat(tile_cur)) {
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
return CommandCost(STR_ERROR_SITE_UNSUITABLE);
}
if (IsBridgeAbove(tile_cur)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (IsBridgeAbove(tile_cur)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
/* Get the water class of the water tile before it is cleared.*/
WaterClass wc = GetWaterClass(tile_cur);
@@ -2835,7 +2835,7 @@ CommandCost CmdBuildDock(DoCommandFlag flags, TileIndex tile, StationID station_
tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {
return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
return CommandCost(STR_ERROR_SITE_UNSUITABLE);
}
TileArea dock_area = TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
@@ -4326,7 +4326,7 @@ CommandCost CmdRenameStation(DoCommandFlag flags, StationID station_id, const st
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueStationName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
if (!IsUniqueStationName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
if (flags & DC_EXEC) {
@@ -4702,17 +4702,17 @@ CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)
if (flags & DC_AUTO) {
switch (GetStationType(tile)) {
default: break;
case STATION_RAIL: return_cmd_error(STR_ERROR_MUST_DEMOLISH_RAILROAD);
case STATION_WAYPOINT: return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
case STATION_AIRPORT: return_cmd_error(STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST);
case STATION_TRUCK: return_cmd_error(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_CARGO_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST);
case STATION_BUS: return_cmd_error(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_PASSENGER_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST);
case STATION_ROADWAYPOINT: return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
case STATION_BUOY: return_cmd_error(STR_ERROR_BUOY_IN_THE_WAY);
case STATION_DOCK: return_cmd_error(STR_ERROR_MUST_DEMOLISH_DOCK_FIRST);
case STATION_RAIL: return CommandCost(STR_ERROR_MUST_DEMOLISH_RAILROAD);
case STATION_WAYPOINT: return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
case STATION_AIRPORT: return CommandCost(STR_ERROR_MUST_DEMOLISH_AIRPORT_FIRST);
case STATION_TRUCK: return CommandCost(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_CARGO_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_TRUCK_STATION_FIRST);
case STATION_BUS: return CommandCost(HasTileRoadType(tile, RTT_TRAM) ? STR_ERROR_MUST_DEMOLISH_PASSENGER_TRAM_STATION_FIRST : STR_ERROR_MUST_DEMOLISH_BUS_STATION_FIRST);
case STATION_ROADWAYPOINT: return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED);
case STATION_BUOY: return CommandCost(STR_ERROR_BUOY_IN_THE_WAY);
case STATION_DOCK: return CommandCost(STR_ERROR_MUST_DEMOLISH_DOCK_FIRST);
case STATION_OILRIG:
SetDParam(1, STR_INDUSTRY_NAME_OIL_RIG);
return_cmd_error(STR_ERROR_GENERIC_OBJECT_IN_THE_WAY);
return CommandCost(STR_ERROR_GENERIC_OBJECT_IN_THE_WAY);
}
}