From 1e77fd0b61a560ef09c571945709aa0df9a2a951 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 8 Dec 2024 18:02:30 +0000 Subject: [PATCH] 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. --- src/command_func.h | 10 ---- src/company_cmd.cpp | 10 ++-- src/depot_cmd.cpp | 2 +- src/economy.cpp | 2 +- src/engine.cpp | 2 +- src/group_cmd.cpp | 2 +- src/industry_cmd.cpp | 42 ++++++++-------- src/landscape.cpp | 6 +-- src/misc_cmd.cpp | 6 +-- src/newgrf_industrytiles.cpp | 4 +- src/object_cmd.cpp | 28 +++++------ src/order_cmd.cpp | 26 +++++----- src/rail_cmd.cpp | 66 ++++++++++++------------- src/road_cmd.cpp | 52 ++++++++++---------- src/roadveh_cmd.cpp | 2 +- src/station.cpp | 2 +- src/station_cmd.cpp | 94 ++++++++++++++++++------------------ src/timetable_cmd.cpp | 4 +- src/town_cmd.cpp | 30 ++++++------ src/train_cmd.cpp | 22 ++++----- src/tree_cmd.cpp | 2 +- src/tunnelbridge_cmd.cpp | 60 +++++++++++------------ src/vehicle.cpp | 8 +-- src/vehicle_cmd.cpp | 16 +++--- src/void_cmd.cpp | 4 +- src/water_cmd.cpp | 28 +++++------ src/waypoint_cmd.cpp | 32 ++++++------ 27 files changed, 276 insertions(+), 286 deletions(-) diff --git a/src/command_func.h b/src/command_func.h index 69cb9ebcac94c..7a65950c6af30 100644 --- a/src/command_func.h +++ b/src/command_func.h @@ -27,16 +27,6 @@ */ static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID); -/** - * Returns from a function with a specific StringID as error. - * - * This macro is used to return from a function. The parameter contains the - * StringID which will be returned. - * - * @param errcode The StringID to return - */ -#define return_cmd_error(errcode) return CommandCost(errcode); - void NetworkSendCommand(Commands cmd, StringID err_message, CommandCallback *callback, CompanyID company, const CommandDataBuffer &cmd_data); bool IsValidCommand(Commands cmd); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 25bdf3328700f..7f37cc585e7eb 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -368,7 +368,7 @@ CommandCost CheckOwnership(Owner owner, TileIndex tile) if (owner == _current_company) return CommandCost(); SetDParamsForOwnedBy(owner, tile); - return_cmd_error(STR_ERROR_OWNED_BY); + return CommandCost(STR_ERROR_OWNED_BY); } /** @@ -388,7 +388,7 @@ CommandCost CheckTileOwnership(TileIndex tile) /* no need to get the name of the owner unless we're the local company (saves some time) */ if (IsLocalCompany()) SetDParamsForOwnedBy(owner, tile); - return_cmd_error(STR_ERROR_OWNED_BY); + return CommandCost(STR_ERROR_OWNED_BY); } /** @@ -1172,7 +1172,7 @@ CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text) if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_COMPANY_NAME_CHARS) return CMD_ERROR; - if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniqueCompanyName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { @@ -1215,7 +1215,7 @@ CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text) if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) return CMD_ERROR; - if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniquePresidentName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { @@ -1301,7 +1301,7 @@ CommandCost CmdGiveMoney(DoCommandFlag flags, Money money, CompanyID dest_compan CommandCost amount(EXPENSES_OTHER, std::min(money, 20000000LL)); /* You can only transfer funds that is in excess of your loan */ - if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return_cmd_error(STR_ERROR_INSUFFICIENT_FUNDS); + if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CommandCost(STR_ERROR_INSUFFICIENT_FUNDS); if (!Company::IsValidID(dest_company)) return CMD_ERROR; if (flags & DC_EXEC) { diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp index 294de69e32ea7..2ac1f190cd4df 100644 --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -55,7 +55,7 @@ CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::str if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR; - if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniqueDepotName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { diff --git a/src/economy.cpp b/src/economy.cpp index d71940e5ccef6..2f214ce5cc62e 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -2064,7 +2064,7 @@ CommandCost CmdBuyCompany(DoCommandFlag flags, CompanyID target_company, bool ho if (target_company == _current_company) return CMD_ERROR; /* Do not allow takeover if the resulting company would have too many vehicles. */ - if (!CheckTakeoverVehicleLimit(_current_company, target_company)) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); + if (!CheckTakeoverVehicleLimit(_current_company, target_company)) return CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); /* Get the cost here as the company is deleted in DoAcquireCompany. * For bankruptcy this amount is calculated when the offer was made; diff --git a/src/engine.cpp b/src/engine.cpp index 63761c7e8e044..6e920d87f684e 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -1226,7 +1226,7 @@ CommandCost CmdRenameEngine(DoCommandFlag flags, EngineID engine_id, const std:: if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_ENGINE_NAME_CHARS) return CMD_ERROR; - if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniqueEngineName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 1bc3c6621d326..6adde37974129 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -462,7 +462,7 @@ CommandCost CmdAlterGroup(DoCommandFlag flags, AlterGroupMode mode, GroupID grou /* Ensure request parent isn't child of group. * This is the only place that infinite loops are prevented. */ - if (GroupIsInGroup(pg->index, g->index)) return_cmd_error(STR_ERROR_GROUP_CAN_T_SET_PARENT_RECURSION); + if (GroupIsInGroup(pg->index, g->index)) return CommandCost(STR_ERROR_GROUP_CAN_T_SET_PARENT_RECURSION); } if (flags & DC_EXEC) { diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 56dfcbc430385..f0863216b7b4f 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -505,7 +505,7 @@ static CommandCost ClearTile_Industry(TileIndex tile, DoCommandFlag flags) ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) || HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) { SetDParam(1, indspec->name); - return_cmd_error(flags & DC_AUTO ? STR_ERROR_GENERIC_OBJECT_IN_THE_WAY : INVALID_STRING_ID); + return CommandCost(flags & DC_AUTO ? STR_ERROR_GENERIC_OBJECT_IN_THE_WAY : INVALID_STRING_ID); } if (flags & DC_EXEC) { @@ -1273,7 +1273,7 @@ static CommandCost CheckNewIndustry_Forest(TileIndex tile) { if (_settings_game.game_creation.landscape == LT_ARCTIC) { if (GetTileZ(tile) < HighestSnowLine() + 2) { - return_cmd_error(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED); + return CommandCost(STR_ERROR_FOREST_CAN_ONLY_BE_PLANTED); } } return CommandCost(); @@ -1313,7 +1313,7 @@ static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile) if (CheckScaledDistanceFromEdge(TileAddXY(tile, 1, 1), _settings_game.game_creation.oil_refinery_limit)) return CommandCost(); - return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED); + return CommandCost(STR_ERROR_CAN_ONLY_BE_POSITIONED); } extern bool _ignore_restrictions; @@ -1330,7 +1330,7 @@ static CommandCost CheckNewIndustry_OilRig(TileIndex tile) if (TileHeight(tile) == 0 && CheckScaledDistanceFromEdge(TileAddXY(tile, 1, 1), _settings_game.game_creation.oil_refinery_limit)) return CommandCost(); - return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED); + return CommandCost(STR_ERROR_CAN_ONLY_BE_POSITIONED); } /** @@ -1342,7 +1342,7 @@ static CommandCost CheckNewIndustry_Farm(TileIndex tile) { if (_settings_game.game_creation.landscape == LT_ARCTIC) { if (GetTileZ(tile) + 2 >= HighestSnowLine()) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } } return CommandCost(); @@ -1356,7 +1356,7 @@ static CommandCost CheckNewIndustry_Farm(TileIndex tile) static CommandCost CheckNewIndustry_Plantation(TileIndex tile) { if (GetTropicZone(tile) == TROPICZONE_DESERT) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } return CommandCost(); } @@ -1369,7 +1369,7 @@ static CommandCost CheckNewIndustry_Plantation(TileIndex tile) static CommandCost CheckNewIndustry_Water(TileIndex tile) { if (GetTropicZone(tile) != TROPICZONE_DESERT) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_DESERT); } return CommandCost(); } @@ -1382,7 +1382,7 @@ static CommandCost CheckNewIndustry_Water(TileIndex tile) static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile) { if (GetTropicZone(tile) != TROPICZONE_RAINFOREST) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_RAINFOREST); } return CommandCost(); } @@ -1395,7 +1395,7 @@ static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile) static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile) { if (GetTileZ(tile) > 4) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_LOW_AREAS); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_LOW_AREAS); } return CommandCost(); } @@ -1439,7 +1439,7 @@ static CommandCost FindTownForIndustry(TileIndex tile, IndustryType type, Town * for (const IndustryID &industry : Industry::industries[type]) { if (Industry::Get(industry)->town == *t) { *t = nullptr; - return_cmd_error(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN); + return CommandCost(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN); } } @@ -1479,28 +1479,28 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil TileIndex cur_tile = TileAddWrap(tile, it.ti.x, it.ti.y); if (!IsValidTile(cur_tile)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } if (gfx == GFX_WATERTILE_SPECIALCHECK) { if (!IsWaterTile(cur_tile) || !IsTileFlat(cur_tile)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } } else { CommandCost ret = EnsureNoVehicleOnGround(cur_tile); if (ret.Failed()) return ret; - if (IsBridgeAbove(cur_tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + if (IsBridgeAbove(cur_tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE); const IndustryTileSpec *its = GetIndustryTileSpec(gfx); /* Perform land/water check if not disabled */ - if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + if (!HasBit(its->slopes_refused, 5) && ((HasTileWaterClass(cur_tile) && IsTileOnWater(cur_tile)) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return CommandCost(STR_ERROR_SITE_UNSUITABLE); if ((ind_behav & (INDUSTRYBEH_ONLY_INTOWN | INDUSTRYBEH_TOWN1200_MORE)) || // Tile must be a house ((ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) && IsTileType(cur_tile, MP_HOUSE))) { // Tile is allowed to be a house (and it is a house) if (!IsTileType(cur_tile, MP_HOUSE)) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS); } /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ @@ -1564,7 +1564,7 @@ static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileL if (!refused_slope || (_settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !custom_shape && !_ignore_restrictions)) { return CommandCost(); } - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } /** @@ -1577,11 +1577,11 @@ static CommandCost CheckIfIndustryTileSlopes(TileIndex tile, const IndustryTileL static CommandCost CheckIfIndustryIsAllowed(TileIndex tile, IndustryType type, const Town *t) { if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->cache.population < 1200) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_IN_TOWNS_WITH_POPULATION_OF_1200); } if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) { - return_cmd_error(STR_ERROR_CAN_ONLY_BE_BUILT_NEAR_TOWN_CENTER); + return CommandCost(STR_ERROR_CAN_ONLY_BE_BUILT_NEAR_TOWN_CENTER); } return CommandCost(); @@ -1702,7 +1702,7 @@ static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, Indus /* Within 14 tiles from another industry is considered close */ if (DistanceMax(tile, Industry::Get(industry)->location.tile) > 14) continue; - return_cmd_error(STR_ERROR_INDUSTRY_TOO_CLOSE); + return CommandCost(STR_ERROR_INDUSTRY_TOO_CLOSE); } } return CommandCost(); @@ -2021,10 +2021,10 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do if (!custom_shape_check && _settings_game.game_creation.land_generator == LG_TERRAGENESIS && _generating_world && !_ignore_restrictions && !CheckIfCanLevelIndustryPlatform(tile, DC_NO_WATER, layout)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } - if (!Industry::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_INDUSTRIES); + if (!Industry::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_INDUSTRIES); if (flags & DC_EXEC) { *ip = new Industry(tile); diff --git a/src/landscape.cpp b/src/landscape.cpp index 936f0af4cab5b..a76e9d01c68e6 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -656,14 +656,14 @@ CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile) bool do_clear = false; /* Test for stuff which results in water when cleared. Then add the cost to also clear the water. */ if ((flags & DC_FORCE_CLEAR_TILE) && HasTileWaterClass(tile) && IsTileOnWater(tile) && !IsWaterTile(tile) && !IsCoastTile(tile)) { - if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST); + if ((flags & DC_AUTO) && GetWaterClass(tile) == WATER_CLASS_CANAL) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST); do_clear = true; cost.AddCost(GetWaterClass(tile) == WATER_CLASS_CANAL ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]); } Company *c = (flags & (DC_AUTO | DC_BANKRUPT)) ? nullptr : Company::GetIfValid(_current_company); if (c != nullptr && (int)GB(c->clear_limit, 16, 16) < 1) { - return_cmd_error(STR_ERROR_CLEARING_LIMIT_REACHED); + return CommandCost(STR_ERROR_CLEARING_LIMIT_REACHED); } const ClearedObjectArea *coa = FindClearedObject(tile); @@ -677,7 +677,7 @@ CommandCost CmdLandscapeClear(DoCommandFlag flags, TileIndex tile) /* If a object is removed, it leaves either bare land or water. */ if ((flags & DC_NO_WATER) && HasTileWaterClass(tile) && IsTileOnWater(tile)) { - return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER); } } else { cost.AddCost(_tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags)); diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index 04cc7e8f963c3..4a12fad2a5b93 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -42,7 +42,7 @@ CommandCost CmdIncreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount) Money max_loan = c->GetMaxLoan(); if (c->current_loan >= max_loan) { SetDParam(0, max_loan); - return_cmd_error(STR_ERROR_MAXIMUM_PERMITTED_LOAN); + return CommandCost(STR_ERROR_MAXIMUM_PERMITTED_LOAN); } Money loan; @@ -87,7 +87,7 @@ CommandCost CmdDecreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount) { Company *c = Company::Get(_current_company); - if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED); + if (c->current_loan == 0) return CommandCost(STR_ERROR_LOAN_ALREADY_REPAYED); Money loan; switch (cmd) { @@ -107,7 +107,7 @@ CommandCost CmdDecreaseLoan(DoCommandFlag flags, LoanCommand cmd, Money amount) if (GetAvailableMoneyForCommand() < loan) { SetDParam(0, loan); - return_cmd_error(STR_ERROR_CURRENCY_REQUIRED); + return CommandCost(STR_ERROR_CURRENCY_REQUIRED); } if (flags & DC_EXEC) { diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index bafd2a57311a2..18a398521a42f 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -240,11 +240,11 @@ CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind uint16_t callback_res = GetIndustryTileCallback(CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | (uint32_t)layout_index, gfx, &ind, ind_tile); if (callback_res == CALLBACK_FAILED) { if (!IsSlopeRefused(GetTileSlope(ind_tile), its->slopes_refused)) return CommandCost(); - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } if (its->grf_prop.grffile->grf_version < 7) { if (callback_res != 0) return CommandCost(); - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } return GetErrorMessageFromLocationCallbackResult(callback_res, its->grf_prop.grffile, STR_ERROR_SITE_UNSUITABLE); diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 5338fe5036d72..d4f28477b95f2 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -220,14 +220,14 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, if ((spec->flags & OBJECT_FLAG_ONLY_IN_GAME) != 0 && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR; if (view >= spec->views) return CMD_ERROR; - if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS); - if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST); + if (!Object::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_OBJECTS); + if (Town::GetNumItems() == 0) return CommandCost(STR_ERROR_MUST_FOUND_TOWN_FIRST); int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4); int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4); TileArea ta(tile, size_x, size_y); for (TileIndex t : ta) { - if (!IsValidTile(t)) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map + if (!IsValidTile(t)) return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map } if (type == OBJECT_OWNED_LAND) { @@ -241,7 +241,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0; for (TileIndex t : ta) { if (HasTileWaterGround(t)) { - if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + if (!allow_water) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER); if (!IsWaterTile(t)) { /* Normal water tiles don't have to be cleared. For all other tile types clear * the tile but leave the water. */ @@ -255,7 +255,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, cost.AddCost(EnsureNoVehicleOnGround(t)); } } else { - if (!allow_ground) return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER); + if (!allow_ground) return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER); /* For non-water tiles, we'll have to clear it before building. */ /* When relocating HQ, allow it to be relocated (partial) on itself. */ @@ -310,7 +310,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, if (IsBridgeAbove(t) && ( !(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) || (GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) { - return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); } } @@ -319,14 +319,14 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, switch (type) { case OBJECT_TRANSMITTER: case OBJECT_LIGHTHOUSE: - if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + if (!IsTileFlat(tile)) return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); break; case OBJECT_OWNED_LAND: if (IsTileType(tile, MP_OBJECT) && IsTileOwner(tile, _current_company) && IsObjectType(tile, OBJECT_OWNED_LAND)) { - return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT); + return CommandCost(STR_ERROR_YOU_ALREADY_OWN_IT); } break; @@ -334,7 +334,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, Company *c = Company::Get(_current_company); if (c->location_of_HQ != INVALID_TILE) { /* Don't relocate HQ on the same location. */ - if (c->location_of_HQ == tile) return_cmd_error(STR_ERROR_ALREADY_BUILT); + if (c->location_of_HQ == tile) return CommandCost(STR_ERROR_ALREADY_BUILT); /* We need to persuade a bit harder to remove the old HQ. */ _current_company = OWNER_WATER; cost.AddCost(ClearTile_Object(c->location_of_HQ, flags)); @@ -361,7 +361,7 @@ CommandCost CmdBuildObject(DoCommandFlag flags, TileIndex tile, ObjectType type, /* Don't allow building more objects if the company has reached its limit. */ Company *c = Company::GetIfValid(_current_company); if (c != nullptr && GB(c->build_object_limit, 16, 16) < build_object_size) { - return_cmd_error(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED); + return CommandCost(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED); } if (flags & DC_EXEC) { @@ -558,10 +558,10 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags) if (_current_company != OWNER_WATER) { if ((flags & DC_NO_WATER) && IsTileOnWater(tile)) { /* There is water under the object, treat it as water tile. */ - return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER); } else if (!(spec->flags & OBJECT_FLAG_AUTOREMOVE) && (flags & DC_AUTO)) { /* No automatic removal by overbuilding stuff. */ - return_cmd_error(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY); + return CommandCost(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY); } else if (_game_mode == GM_EDITOR) { /* No further limitations for the editor. */ } else if (GetTileOwner(tile) == OWNER_NONE) { @@ -569,11 +569,11 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags) if (!_cheats.magic_bulldozer.value && (spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0) return CMD_ERROR; } else if (CheckTileOwnership(tile).Failed()) { /* We don't own it!. */ - return_cmd_error(STR_ERROR_OWNED_BY); + return CommandCost(STR_ERROR_OWNED_BY); } else if ((spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0 && (spec->flags & OBJECT_FLAG_AUTOREMOVE) == 0) { /* In the game editor or with cheats we can remove, otherwise we can't. */ if (!_cheats.magic_bulldozer.value) { - if (type == OBJECT_HQ) return_cmd_error(STR_ERROR_COMPANY_HEADQUARTERS_IN); + if (type == OBJECT_HQ) return CommandCost(STR_ERROR_COMPANY_HEADQUARTERS_IN); return CMD_ERROR; } diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 1d6743106efe2..61bd5e17b9af5 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -733,7 +733,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: - if (v->HasUnbunchingOrder()) return_cmd_error(STR_ERROR_UNBUNCHING_NO_FULL_LOAD); + if (v->HasUnbunchingOrder()) return CommandCost(STR_ERROR_UNBUNCHING_NO_FULL_LOAD); break; default: @@ -859,7 +859,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se VehicleOrderID skip_to = new_order.GetConditionSkipToOrder(); if (skip_to != 0 && skip_to >= v->GetNumOrders()) return CMD_ERROR; // Always allow jumping to the first (even when there is no order). if (new_order.GetConditionVariable() >= OCV_END) return CMD_ERROR; - if (v->HasUnbunchingOrder()) return_cmd_error(STR_ERROR_UNBUNCHING_NO_CONDITIONAL); + if (v->HasUnbunchingOrder()) return CommandCost(STR_ERROR_UNBUNCHING_NO_CONDITIONAL); OrderConditionComparator occ = new_order.GetConditionComparator(); if (occ >= OCC_END) return CMD_ERROR; @@ -890,9 +890,9 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se if (sel_ord > v->GetNumOrders()) return CMD_ERROR; - if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS); - if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); - if (v->orders == nullptr && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); + if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return CommandCost(STR_ERROR_TOO_MANY_ORDERS); + if (!Order::CanAllocateItem()) return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); + if (v->orders == nullptr && !OrderList::CanAllocateItem()) return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); if (flags & DC_EXEC) { Order *new_o = new Order(); @@ -1296,7 +1296,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CMD_ERROR; if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR; if (data == order->GetLoadType()) return CMD_ERROR; - if ((data & (OLFB_FULL_LOAD | OLF_FULL_LOAD_ANY)) && v->HasUnbunchingOrder()) return_cmd_error(STR_ERROR_UNBUNCHING_NO_FULL_LOAD); + if ((data & (OLFB_FULL_LOAD | OLF_FULL_LOAD_ANY)) && v->HasUnbunchingOrder()) return CommandCost(STR_ERROR_UNBUNCHING_NO_FULL_LOAD); break; case MOF_DEPOT_ACTION: @@ -1304,11 +1304,11 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se /* Check if we are allowed to add unbunching. We are always allowed to remove it. */ if (data == DA_UNBUNCH) { /* Only one unbunching order is allowed in a vehicle's orders. If this order already has an unbunching action, no error is needed. */ - if (v->HasUnbunchingOrder() && !(order->GetDepotActionType() & ODATFB_UNBUNCH)) return_cmd_error(STR_ERROR_UNBUNCHING_ONLY_ONE_ALLOWED); + if (v->HasUnbunchingOrder() && !(order->GetDepotActionType() & ODATFB_UNBUNCH)) return CommandCost(STR_ERROR_UNBUNCHING_ONLY_ONE_ALLOWED); /* We don't allow unbunching if the vehicle has a conditional order. */ - if (v->HasConditionalOrder()) return_cmd_error(STR_ERROR_UNBUNCHING_NO_UNBUNCHING_CONDITIONAL); + if (v->HasConditionalOrder()) return CommandCost(STR_ERROR_UNBUNCHING_NO_UNBUNCHING_CONDITIONAL); /* We don't allow unbunching if the vehicle has a full load order. */ - if (v->HasFullLoadOrder()) return_cmd_error(STR_ERROR_UNBUNCHING_NO_UNBUNCHING_FULL_LOAD); + if (v->HasFullLoadOrder()) return CommandCost(STR_ERROR_UNBUNCHING_NO_UNBUNCHING_FULL_LOAD); } break; @@ -1559,11 +1559,11 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve /* Check for aircraft range limits. */ if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) { - return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE); + return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE); } if (src->orders == nullptr && !OrderList::CanAllocateItem()) { - return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); + return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); } if (flags & DC_EXEC) { @@ -1606,12 +1606,12 @@ CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID ve /* Check for aircraft range limits. */ if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) { - return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE); + return CommandCost(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE); } /* make sure there are orders available */ if (!Order::CanAllocateItem(src->GetNumOrders()) || !OrderList::CanAllocateItem()) { - return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); + return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); } if (flags & DC_EXEC) { diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 0429661eda40c..11833a4b158e2 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -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::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::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); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index f29f778f3b9d7..8bbfc28bdcfc4 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -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::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); } diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index a56c92cd22407..528b849c7355e 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -263,7 +263,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin /* Check that the vehicle can drive on the road in question */ RoadType rt = e->u.road.roadtype; const RoadTypeInfo *rti = GetRoadTypeInfo(rt); - if (!HasTileAnyRoadType(tile, rti->powered_roadtypes)) return_cmd_error(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE); + if (!HasTileAnyRoadType(tile, rti->powered_roadtypes)) return CommandCost(STR_ERROR_DEPOT_WRONG_DEPOT_TYPE); if (flags & DC_EXEC) { const RoadVehicleInfo *rvi = &e->u.road; diff --git a/src/station.cpp b/src/station.cpp index 91438777ce8c2..802ccd236b668 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -588,7 +588,7 @@ CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode) int h = new_rect.Height(); if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) { assert(mode != ADD_TRY); - return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT); + return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT); } /* spread-out ok, return true */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 8a49d618646c6..38373f38e9428 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -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::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(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(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::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); } } diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index b53d923913e04..71cfd8907f8a4 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -167,13 +167,13 @@ CommandCost CmdChangeTimetable(DoCommandFlag flags, VehicleID veh, VehicleOrderI if (wait_time != order->GetWaitTime()) { switch (order->GetType()) { case OT_GOTO_STATION: - if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return_cmd_error(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE); + if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CommandCost(STR_ERROR_TIMETABLE_NOT_STOPPING_HERE); break; case OT_CONDITIONAL: break; - default: return_cmd_error(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS); + default: return CommandCost(STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS); } } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index dc9a17e7ccdf4..08e7d787cdae9 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -716,7 +716,7 @@ static void TileLoop_Town(TileIndex tile) */ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) { - if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); + if (flags & DC_AUTO) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); if (!CanDeleteHouse(tile)) return CMD_ERROR; const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); @@ -731,7 +731,7 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags) if (rating > t->ratings[_current_company] && !(flags & DC_NO_TEST_TOWN_RATING) && !_cheats.magic_bulldozer.value && _settings_game.difficulty.town_council_tolerance != TOWN_COUNCIL_PERMISSIVE) { 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); } } @@ -2097,17 +2097,17 @@ static CommandCost TownCanBePlacedHere(TileIndex tile) { /* Check if too close to the edge of map */ if (DistanceFromEdge(tile) < 12) { - return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); + return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); } /* Check distance to all other towns. */ if (IsCloseToTown(tile, 20)) { - return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_TOWN); + return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_TOWN); } /* Can only build on clear flat areas, possibly with trees. */ if ((!IsTileType(tile, MP_CLEAR) && !IsTileType(tile, MP_TREES)) || !IsTileFlat(tile)) { - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } return CommandCost(EXPENSES_OTHER); @@ -2880,7 +2880,7 @@ static bool TryBuildTownHouse(Town *t, TileIndex tile) CommandCost CmdPlaceHouse(DoCommandFlag flags, TileIndex tile, HouseID house) { if (_game_mode != GM_EDITOR) return CMD_ERROR; - if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST); + if (Town::GetNumItems() == 0) return CommandCost(STR_ERROR_MUST_FOUND_TOWN_FIRST); if (static_cast(house) >= HouseSpec::Specs().size()) return CMD_ERROR; const HouseSpec *hs = HouseSpec::Get(house); @@ -2890,10 +2890,10 @@ CommandCost CmdPlaceHouse(DoCommandFlag flags, TileIndex tile, HouseID house) /* cannot build on these slopes... */ Slope slope = GetTileSlope(tile); - if (IsSteepSlope(slope)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + if (IsSteepSlope(slope)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); /* building under a bridge? */ - if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); /* can we clear the land? */ CommandCost cost = Command::Do(DC_AUTO | DC_NO_WATER, tile); @@ -2903,7 +2903,7 @@ CommandCost CmdPlaceHouse(DoCommandFlag flags, TileIndex tile, HouseID house) /* Make sure there is no slope? */ bool noslope = (hs->building_flags & TILE_NOT_SLOPED) != 0; - if (noslope && slope != SLOPE_FLAT) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + if (noslope && slope != SLOPE_FLAT) return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); TileArea ta = tile; if (hs->building_flags & TILE_SIZE_2x2) ta.Add(TileAddXY(tile, 1, 1)); @@ -2915,7 +2915,7 @@ CommandCost CmdPlaceHouse(DoCommandFlag flags, TileIndex tile, HouseID house) cost = Command::Do(DC_AUTO | DC_NO_WATER, subtile); if (!cost.Succeeded()) return cost; - if (!CheckBuildHouseSameZ(subtile, maxz, noslope)) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + if (!CheckBuildHouseSameZ(subtile, maxz, noslope)) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); } if (flags & DC_EXEC) { @@ -3025,7 +3025,7 @@ CommandCost CmdRenameTown(DoCommandFlag flags, TownID town_id, const std::string if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR; - if (!IsUniqueTownName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniqueTownName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { @@ -3459,11 +3459,11 @@ static bool SearchTileForStatue(TileIndex tile, void *user_data) */ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags) { - if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS); + if (!Object::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_OBJECTS); TileIndex tile = t->xy; StatueBuildSearchData statue_data(INVALID_TILE, 0); - if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE); + if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return CommandCost(STR_ERROR_STATUE_NO_SUITABLE_PLACE); if (flags & DC_EXEC) { Backup cur_company(_current_company, OWNER_NONE); @@ -3865,7 +3865,7 @@ CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags if (t->ratings[_current_company] > RATING_VERYPOOR) return CommandCost(); 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); } /** @@ -4035,7 +4035,7 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType if (GetRating(t) < needed) { 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); } return CommandCost(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 43d82fb1881d8..267ceab29e13f 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -982,7 +982,7 @@ static CommandCost CheckNewTrain(Train *original_dst, Train *dst, Train *origina * There will always be a maximum of one new train. */ if (GetFreeUnitNumber(VEH_TRAIN) <= _settings_game.vehicle.max_trains) return CommandCost(); - return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); + return CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); } /** @@ -1008,7 +1008,7 @@ static CommandCost CheckTrainAttachment(Train *t) t = t->Next(); } - if (allowed_len < 0) return_cmd_error(STR_ERROR_TRAIN_TOO_LONG); + if (allowed_len < 0) return CommandCost(STR_ERROR_TRAIN_TOO_LONG); return CommandCost(); } @@ -1075,7 +1075,7 @@ static CommandCost CheckTrainAttachment(Train *t) } } - if (error != STR_NULL) return_cmd_error(error); + if (error != STR_NULL) return CommandCost(error); } } @@ -1085,7 +1085,7 @@ static CommandCost CheckTrainAttachment(Train *t) t = next; } - if (allowed_len < 0) return_cmd_error(STR_ERROR_TRAIN_TOO_LONG); + if (allowed_len < 0) return CommandCost(STR_ERROR_TRAIN_TOO_LONG); return CommandCost(); } @@ -1237,7 +1237,7 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID dst_head = nullptr; } - if (src->IsRearDualheaded()) return_cmd_error(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); + if (src->IsRearDualheaded()) return CommandCost(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); /* When moving all wagons, we can't have the same src_head and dst_head */ if (move_chain && src_head == dst_head) return CommandCost(); @@ -1246,10 +1246,10 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID if (!move_chain && dst != nullptr && dst->IsRearDualheaded() && src == dst->other_multiheaded_part) return CommandCost(); /* Check if all vehicles in the source train are stopped inside a depot. */ - if (!src_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); + if (!src_head->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); /* Check if all vehicles in the destination train are stopped inside a depot. */ - if (dst_head != nullptr && !dst_head->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); + if (dst_head != nullptr && !dst_head->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); /* First make a backup of the order of the trains. That way we can do * whatever we want with the order and later on easily revert. */ @@ -1393,7 +1393,7 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, b Train *v = Train::From(t)->GetFirstEnginePart(); Train *first = v->First(); - if (v->IsRearDualheaded()) return_cmd_error(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); + if (v->IsRearDualheaded()) return CommandCost(STR_ERROR_REAR_ENGINE_FOLLOW_FRONT); /* First make a backup of the order of the train. That way we can do * whatever we want with the order and later on easily revert. */ @@ -1418,7 +1418,7 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *t, bool sell_chain, b if (first->orders == nullptr && !OrderList::CanAllocateItem()) { /* Restore the train we had. */ RestoreTrainBackup(original); - return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); + return CommandCost(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS); } CommandCost cost(EXPENSES_NEW_VEHICLES); @@ -2068,13 +2068,13 @@ CommandCost CmdReverseTrainDirection(DoCommandFlag flags, VehicleID veh_id, bool /* turn a single unit around */ if (v->IsMultiheaded() || HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) { - return_cmd_error(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS); + return CommandCost(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS); } Train *front = v->First(); /* make sure the vehicle is stopped in the depot */ if (!front->IsStoppedInDepot()) { - return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); + return CommandCost(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT); } if (flags & DC_EXEC) { diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 87d5685f4e49c..0aa14016cf22f 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -506,7 +506,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti } if (cost.GetCost() == 0) { - return_cmd_error(msg); + return CommandCost(msg); } else { return cost; } diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 7efdfed1e2206..94e04eefb33a6 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -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::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::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::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); } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index cff919b9753c7..aecc7138f78d3 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -552,7 +552,7 @@ CommandCost EnsureNoVehicleOnGround(TileIndex tile) * Such a message does not affect MP synchronisation. */ Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true); - if (v != nullptr) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); + if (v != nullptr) return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type); return CommandCost(); } @@ -581,7 +581,7 @@ CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle Vehicle *v = VehicleFromPos(tile, const_cast(ignore), &GetVehicleTunnelBridgeProc, true); if (v == nullptr) v = VehicleFromPos(endtile, const_cast(ignore), &GetVehicleTunnelBridgeProc, true); - if (v != nullptr) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); + if (v != nullptr) return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type); return CommandCost(); } @@ -612,7 +612,7 @@ CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits) * Such a message does not affect MP synchronisation. */ Vehicle *v = VehicleFromPos(tile, &track_bits, &EnsureNoTrainOnTrackProc, true); - if (v != nullptr) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); + if (v != nullptr) return CommandCost(STR_ERROR_TRAIN_IN_THE_WAY + v->type); return CommandCost(); } @@ -2624,7 +2624,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) ClosestDepot closestDepot = this->FindClosestDepot(); static const StringID no_depot[] = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR}; - if (!closestDepot.found) return_cmd_error(no_depot[this->type]); + if (!closestDepot.found) return CommandCost(no_depot[this->type]); if (flags & DC_EXEC) { if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index afccfd9faaa8a..dba8e733af014 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -230,9 +230,9 @@ CommandCost CmdSellVehicle(DoCommandFlag flags, VehicleID v_id, bool sell_chain, CommandCost ret = CheckOwnership(front->owner); if (ret.Failed()) return ret; - if (front->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED); + if (front->vehstatus & VS_CRASHED) return CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED); - if (!front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type); + if (!front->IsStoppedInDepot()) return CommandCost(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type); /* Can we actually make the order backup, i.e. are there enough orders? */ if (backup_order && @@ -580,11 +580,11 @@ CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool eval CommandCost ret = CheckOwnership(v->owner); if (ret.Failed()) return ret; - if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED); + if (v->vehstatus & VS_CRASHED) return CommandCost(STR_ERROR_VEHICLE_IS_DESTROYED); switch (v->type) { case VEH_TRAIN: - if ((v->vehstatus & VS_STOPPED) && Train::From(v)->gcache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_POWER); + if ((v->vehstatus & VS_STOPPED) && Train::From(v)->gcache.cached_power == 0) return CommandCost(STR_ERROR_TRAIN_START_NO_POWER); break; case VEH_SHIP: @@ -594,8 +594,8 @@ CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool eval case VEH_AIRCRAFT: { Aircraft *a = Aircraft::From(v); /* cannot stop airplane when in flight, or when taking off / landing */ - if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); - if (HasBit(a->flags, VAF_HELI_DIRECT_DESCENT)) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); + if (a->state >= STARTTAKEOFF && a->state < TERM7) return CommandCost(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); + if (HasBit(a->flags, VAF_HELI_DIRECT_DESCENT)) return CommandCost(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); break; } @@ -625,7 +625,7 @@ CommandCost CmdStartStopVehicle(DoCommandFlag flags, VehicleID veh_id, bool eval } } } - if (error != STR_NULL) return_cmd_error(error); + if (error != STR_NULL) return CommandCost(error); } if (flags & DC_EXEC) { @@ -1078,7 +1078,7 @@ CommandCost CmdRenameVehicle(DoCommandFlag flags, VehicleID veh_id, const std::s if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_VEHICLE_NAME_CHARS) return CMD_ERROR; - if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) { diff --git a/src/void_cmd.cpp b/src/void_cmd.cpp index 5e35a1f883750..732814cfbe95b 100644 --- a/src/void_cmd.cpp +++ b/src/void_cmd.cpp @@ -41,7 +41,7 @@ static Foundation GetFoundation_Void(TileIndex, Slope) static CommandCost ClearTile_Void(TileIndex, DoCommandFlag) { - return_cmd_error(STR_ERROR_OFF_EDGE_OF_MAP); + return CommandCost(STR_ERROR_OFF_EDGE_OF_MAP); } @@ -69,7 +69,7 @@ static TrackStatus GetTileTrackStatus_Void(TileIndex, TransportType, uint, DiagD static CommandCost TerraformTile_Void(TileIndex, DoCommandFlag, int, Slope) { - return_cmd_error(STR_ERROR_OFF_EDGE_OF_MAP); + return CommandCost(STR_ERROR_OFF_EDGE_OF_MAP); } extern const TileTypeProcs _tile_type_void_procs = { diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 318f56a076911..f15c15666b1d3 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -115,14 +115,14 @@ CommandCost CmdBuildShipDepot(DoCommandFlag flags, TileIndex tile, Axis axis) TileIndex tile2 = tile + TileOffsByAxis(axis); if (!HasTileWaterGround(tile) || !HasTileWaterGround(tile2)) { - return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER); + return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER); } - if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + if (IsBridgeAbove(tile) || IsBridgeAbove(tile2)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); if (!IsTileFlat(tile) || !IsTileFlat(tile2)) { /* Prevent depots on rapids */ - return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + return CommandCost(STR_ERROR_SITE_UNSUITABLE); } if (!Depot::CanAllocateItem()) return CMD_ERROR; @@ -333,7 +333,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag cost.AddCost(_price[PR_BUILD_CANAL]); } if (!IsTileFlat(tile - delta)) { - return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); } WaterClass wc_lower = IsWaterTile(tile - delta) ? GetWaterClass(tile - delta) : WATER_CLASS_CANAL; @@ -345,12 +345,12 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlag cost.AddCost(_price[PR_BUILD_CANAL]); } if (!IsTileFlat(tile + delta)) { - return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); } WaterClass wc_upper = IsWaterTile(tile + delta) ? GetWaterClass(tile + delta) : WATER_CLASS_CANAL; if (IsBridgeAbove(tile) || IsBridgeAbove(tile - delta) || IsBridgeAbove(tile + delta)) { - return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); } if (flags & DC_EXEC) { @@ -435,7 +435,7 @@ static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags) CommandCost CmdBuildLock(DoCommandFlag flags, TileIndex tile) { DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile)); - if (dir == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); + if (dir == INVALID_DIAGDIR) return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); return DoBuildLock(tile, dir, flags); } @@ -485,7 +485,7 @@ CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_t Slope slope = GetTileSlope(current_tile); if (slope != SLOPE_FLAT && (wc != WATER_CLASS_RIVER || !IsInclinedSlope(slope))) { - return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); } bool water = IsWaterTile(current_tile); @@ -540,7 +540,7 @@ CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_t } if (cost.GetCost() == 0) { - return_cmd_error(STR_ERROR_ALREADY_BUILT); + return CommandCost(STR_ERROR_ALREADY_BUILT); } else { return cost; } @@ -551,13 +551,13 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) { switch (GetWaterTileType(tile)) { case WATER_TILE_CLEAR: { - if (flags & DC_NO_WATER) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER); + if (flags & DC_NO_WATER) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER); Money base_cost = IsCanal(tile) ? _price[PR_CLEAR_CANAL] : _price[PR_CLEAR_WATER]; /* Make sure freeform edges are allowed or it's not an edge tile. */ if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(tile), 1, Map::MaxX() - 1) || !IsInsideMM(TileY(tile), 1, Map::MaxY() - 1))) { - return_cmd_error(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP); + return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP); } /* Make sure no vehicle is on the tile */ @@ -610,14 +610,14 @@ static CommandCost ClearTile_Water(TileIndex tile, DoCommandFlag flags) { { 1, 0}, {0, -1}, {-1, 0}, {0, 1} }, // LOCK_PART_UPPER }; - if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); + if (flags & DC_AUTO) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); if (_current_company == OWNER_WATER) return CMD_ERROR; /* move to the middle tile.. */ return RemoveLock(tile + ToTileIndexDiff(_lock_tomiddle_offs[GetLockPart(tile)][GetLockDirection(tile)]), flags); } case WATER_TILE_DEPOT: - if (flags & DC_AUTO) return_cmd_error(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); + if (flags & DC_AUTO) return CommandCost(STR_ERROR_BUILDING_MUST_BE_DEMOLISHED); return RemoveShipDepot(tile, flags); default: @@ -1412,7 +1412,7 @@ static VehicleEnterTileStatus VehicleEnter_Water(Vehicle *, TileIndex, int, int) static CommandCost TerraformTile_Water(TileIndex tile, DoCommandFlag flags, int, Slope) { /* Canals can't be terraformed */ - if (IsWaterTile(tile) && IsCanal(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST); + if (IsWaterTile(tile) && IsCanal(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_CANAL_FIRST); return Command::Do(flags, tile); } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index b6796b25a32ca..668cffa10d934 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -157,12 +157,12 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID * if (*waypoint == INVALID_STATION) { *waypoint = wp; } else if (*waypoint != wp) { - return_cmd_error(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING); + return CommandCost(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING); } } } - if (GetAxisForNewRailWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); + if (GetAxisForNewRailWaypoint(tile) != axis) return CommandCost(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK); Owner owner = GetTileOwner(tile); CommandCost ret = CheckOwnership(owner); @@ -172,10 +172,10 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID * Slope tileh = GetTileSlope(tile); if (tileh != SLOPE_FLAT && (!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) { - return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED); + return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED); } - if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); return CommandCost(); } @@ -250,7 +250,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis if (wp != nullptr) { /* Reuse an existing waypoint. */ - if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); + if (wp->owner != _current_company) return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); /* Check if we want to expand an already existing waypoint. */ if (wp->train_station.tile != INVALID_TILE) { @@ -262,7 +262,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis if (ret.Failed()) return ret; } else { /* Check if we can create a new waypoint. */ - if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); + if (!Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING); } if (flags & DC_EXEC) { @@ -379,17 +379,17 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis if (wp != nullptr) { /* Reuse an existing waypoint. */ if (!HasBit(wp->waypoint_flags, WPF_ROAD)) return CMD_ERROR; - if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); + if (wp->owner != _current_company) return CommandCost(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST); if (ret.Failed()) return ret; } else { /* Check if we can create a new waypoint. */ - if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); + if (!Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING); } /* Check if we can allocate a custom stationspec to this station */ - if (AllocateSpecToRoadStop(roadstopspec, wp, false) == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS); + if (AllocateSpecToRoadStop(roadstopspec, wp, false) == -1) return CommandCost(STR_ERROR_TOO_MANY_STATION_SPECS); if (flags & DC_EXEC) { if (wp == nullptr) { @@ -467,14 +467,14 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlag flags, TileIndex start_tile, Axis */ CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile) { - if (tile == 0 || !HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); - if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); + if (tile == 0 || !HasTileWaterGround(tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE); + if (IsBridgeAbove(tile)) return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST); - if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); + if (!IsTileFlat(tile)) return CommandCost(STR_ERROR_SITE_UNSUITABLE); /* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */ Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE, false); - if (wp == nullptr && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); + if (wp == nullptr && !Waypoint::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING); CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]); if (!IsWaterTile(tile)) { @@ -524,11 +524,11 @@ CommandCost CmdBuildBuoy(DoCommandFlag flags, TileIndex tile) CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags) { /* XXX: strange stuff, allow clearing as invalid company when clearing landscape */ - if (!Company::IsValidID(_current_company) && !(flags & DC_BANKRUPT)) return_cmd_error(INVALID_STRING_ID); + if (!Company::IsValidID(_current_company) && !(flags & DC_BANKRUPT)) return CommandCost(INVALID_STRING_ID); Waypoint *wp = Waypoint::GetByTile(tile); - if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE); + if (HasStationInUse(wp->index, false, _current_company)) return CommandCost(STR_ERROR_BUOY_IS_IN_USE); /* remove the buoy if there is a ship on tile when company goes bankrupt... */ if (!(flags & DC_BANKRUPT)) { CommandCost ret = EnsureNoVehicleOnGround(tile); @@ -589,7 +589,7 @@ CommandCost CmdRenameWaypoint(DoCommandFlag flags, StationID waypoint_id, const if (!reset) { if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR; - if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); + if (!IsUniqueWaypointName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE); } if (flags & DC_EXEC) {