1
0
Fork 0

Fix #13838: Formatted error message of sub-errors may be lost. (#13840)

pull/13846/head
Peter Nelson 2025-03-18 08:39:40 +00:00 committed by GitHub
parent 5255aabe4d
commit 17f7d0950e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 70 additions and 69 deletions

View File

@ -538,10 +538,10 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago
ReplaceChainItem &replacement = replacements.emplace_back(w, nullptr, 0); ReplaceChainItem &replacement = replacements.emplace_back(w, nullptr, 0);
CommandCost ret = BuildReplacementVehicle(replacement.old_veh, &replacement.new_veh, true, flags); CommandCost ret = BuildReplacementVehicle(replacement.old_veh, &replacement.new_veh, true, flags);
cost.AddCost(ret); replacement.cost = ret.GetCost();
cost.AddCost(std::move(ret));
if (cost.Failed()) break; if (cost.Failed()) break;
replacement.cost = ret.GetCost();
if (replacement.new_veh != nullptr) *nothing_to_do = false; if (replacement.new_veh != nullptr) *nothing_to_do = false;
} }
Vehicle *new_head = replacements.front().GetVehicle(); Vehicle *new_head = replacements.front().GetVehicle();
@ -602,7 +602,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago
break; break;
} }
cost.AddCost(res); cost.AddCost(std::move(res));
if (cost.Failed()) break; if (cost.Failed()) break;
} else { } else {
/* We have reached 'last_engine', continue with the next engine towards the front */ /* We have reached 'last_engine', continue with the next engine towards the front */

View File

@ -398,11 +398,12 @@ CommandCost CommandHelperBase::InternalExecuteProcessResult(Commands cmd, Comman
* Also takes a possible error message when it is set. * Also takes a possible error message when it is set.
* @param ret The command to add the cost of. * @param ret The command to add the cost of.
*/ */
void CommandCost::AddCost(const CommandCost &ret) void CommandCost::AddCost(CommandCost &&ret)
{ {
this->AddCost(ret.cost); this->AddCost(ret.cost);
if (this->success && !ret.success) { if (this->success && !ret.success) {
this->message = ret.message; this->message = ret.message;
this->encoded_message = std::move(ret.encoded_message);
this->success = false; this->success = false;
} }
} }

View File

@ -100,7 +100,7 @@ public:
this->cost += cost; this->cost += cost;
} }
void AddCost(const CommandCost &cmd_cost); void AddCost(CommandCost &&cmd_cost);
/** /**
* Multiplies the cost of the command by the given factor. * Multiplies the cost of the command by the given factor.

View File

@ -744,7 +744,7 @@ std::tuple<CommandCost, Money> CmdClearArea(DoCommandFlags flags, TileIndex tile
/* When we're at the clearing limit we better bail (unneed) testing as well. */ /* When we're at the clearing limit we better bail (unneed) testing as well. */
if (ret.GetCost() != 0 && --limit <= 0) break; if (ret.GetCost() != 0 && --limit <= 0) break;
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
return { had_success ? cost : last_error, 0 }; return { had_success ? cost : last_error, 0 };

View File

@ -422,7 +422,7 @@ CommandCost CmdBuildObjectArea(DoCommandFlags flags, TileIndex tile, TileIndex s
if (ret.GetCost() > 0 && money < 0) break; if (ret.GetCost() > 0 && money < 0) break;
Command<CMD_BUILD_OBJECT>::Do(flags, t, type, view); Command<CMD_BUILD_OBJECT>::Do(flags, t, type, view);
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
return had_success ? cost : last_error; return had_success ? cost : last_error;

View File

@ -447,7 +447,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra
ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile); ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) { if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
/* If adding the new track causes any overlap, all signals must be removed first */ /* If adding the new track causes any overlap, all signals must be removed first */
@ -457,7 +457,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra
if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) { if (HasTrack(tile, track_it) && HasSignalOnTrack(tile, track_it)) {
CommandCost ret_remove_signals = Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(flags, tile, track_it); CommandCost ret_remove_signals = Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(flags, tile, track_it);
if (ret_remove_signals.Failed()) return ret_remove_signals; if (ret_remove_signals.Failed()) return ret_remove_signals;
cost.AddCost(ret_remove_signals); cost.AddCost(ret_remove_signals.GetCost());
} }
} }
} }
@ -469,7 +469,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra
if (HasPowerOnRail(GetRailType(tile), railtype)) { if (HasPowerOnRail(GetRailType(tile), railtype)) {
ret = Command<CMD_CONVERT_RAIL>::Do(flags, tile, tile, railtype, false); ret = Command<CMD_CONVERT_RAIL>::Do(flags, tile, tile, railtype, false);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} else { } else {
return CMD_ERROR; return CMD_ERROR;
} }
@ -571,11 +571,11 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra
CommandCost ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile); CommandCost ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
if (water_ground) { if (water_ground) {
cost.AddCost(-_price[PR_CLEAR_WATER]); cost.AddCost(-_price[PR_CLEAR_WATER]);
@ -901,7 +901,7 @@ static CommandCost CmdRailTrackHelper(DoCommandFlags flags, TileIndex tile, Tile
if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break; if (last_error.GetErrorMessage() == STR_ERROR_OWNED_BY && remove) break;
} else { } else {
had_success = true; had_success = true;
total_cost.AddCost(ret); total_cost.AddCost(ret.GetCost());
} }
if (tile == end_tile) break; if (tile == end_tile) break;
@ -1330,7 +1330,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlags flags, TileIndex tile, Ti
if (ret.Succeeded()) { if (ret.Succeeded()) {
had_success = true; had_success = true;
total_cost.AddCost(ret); total_cost.AddCost(ret.GetCost());
} else { } else {
/* The "No railway" error is the least important one. */ /* The "No railway" error is the least important one. */
if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK || if (ret.GetErrorMessage() != STR_ERROR_THERE_IS_NO_RAILROAD_TRACK ||
@ -1824,7 +1824,7 @@ static CommandCost ClearTile_Track(TileIndex tile, DoCommandFlags flags)
Track track = RemoveFirstTrack(&tracks); Track track = RemoveFirstTrack(&tracks);
CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, track); CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, track);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
/* When bankrupting, don't make water dirty, there could be a ship on lower halftile. /* When bankrupting, don't make water dirty, there could be a ship on lower halftile.

View File

@ -817,7 +817,7 @@ do_clear:;
if (need_to_clear) { if (need_to_clear) {
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
if (other_bits != pieces) { if (other_bits != pieces) {
@ -828,7 +828,7 @@ do_clear:;
if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) { if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION); return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
if (!need_to_clear) { if (!need_to_clear) {
@ -863,7 +863,7 @@ do_clear:;
} else if (HasPowerOnRoad(existing_rt, rt)) { } else if (HasPowerOnRoad(existing_rt, rt)) {
ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt); ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} else { } else {
return CMD_ERROR; return CMD_ERROR;
} }
@ -1036,17 +1036,17 @@ CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex
if (IsTileType(tile, MP_TUNNELBRIDGE)) { if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsBridge(tile)) { if (IsBridge(tile)) {
if (!had_bridge || GetTunnelBridgeDirection(tile) == dir) { if (!had_bridge || GetTunnelBridgeDirection(tile) == dir) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
had_bridge = true; had_bridge = true;
} else { // IsTunnel(tile) } else { // IsTunnel(tile)
if (!had_tunnel || GetTunnelBridgeDirection(tile) == dir) { if (!had_tunnel || GetTunnelBridgeDirection(tile) == dir) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
had_tunnel = true; had_tunnel = true;
} }
} else { } else {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
} }
@ -1110,7 +1110,7 @@ std::tuple<CommandCost, Money> CmdRemoveLongRoad(DoCommandFlags flags, TileIndex
} }
RemoveRoad(tile, flags, bits, rtt, false); RemoveRoad(tile, flags, bits, rtt, false);
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
had_success = true; had_success = true;
} else { } else {
/* Some errors are more equal than others. */ /* Some errors are more equal than others. */
@ -1241,7 +1241,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true); CommandCost tmp_ret = RemoveRoad(tile, flags, GetRoadBits(tile, rtt), rtt, true);
if (tmp_ret.Failed()) return tmp_ret; if (tmp_ret.Failed()) return tmp_ret;
ret.AddCost(tmp_ret); ret.AddCost(tmp_ret.GetCost());
} }
return ret; return ret;
} }
@ -1260,7 +1260,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, true); CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, true);
if (tmp_ret.Failed()) return tmp_ret; if (tmp_ret.Failed()) return tmp_ret;
ret.AddCost(tmp_ret); ret.AddCost(tmp_ret.GetCost());
} }
if (flags.Test(DoCommandFlag::Execute)) { if (flags.Test(DoCommandFlag::Execute)) {

View File

@ -853,11 +853,11 @@ static CommandCost CheckFlatLandAirport(AirportTileTableIterator tile_iter, DoCo
for (; tile_iter != INVALID_TILE; ++tile_iter) { for (; tile_iter != INVALID_TILE; ++tile_iter) {
CommandCost ret = CheckBuildableTile(tile_iter, 0, allowed_z, true); CommandCost ret = CheckBuildableTile(tile_iter, 0, allowed_z, true);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_iter); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_iter);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
return cost; return cost;
@ -889,7 +889,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false); CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
if (slope_cb) { if (slope_cb) {
/* Do slope check if requested. */ /* Do slope check if requested. */
@ -934,7 +934,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
} }
ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track); ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile_cur, track);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* With DoCommandFlags{flags}.Reset(DoCommandFlag::Execute) CmdLandscapeClear would fail since the rail still exists */ /* With DoCommandFlags{flags}.Reset(DoCommandFlag::Execute) CmdLandscapeClear would fail since the rail still exists */
return cost; return cost;
} }
@ -942,7 +942,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
} }
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
return cost; return cost;
@ -967,7 +967,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through); CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* If station is set, then we have special handling to allow building on top of already existing stations. /* If station is set, then we have special handling to allow building on top of already existing stations.
* Station points to StationID::Invalid() if we can build on any station. * Station points to StationID::Invalid() if we can build on any station.
@ -1060,7 +1060,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF
} else { } else {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
cost.AddCost(RoadBuildCost(rt) * 2); cost.AddCost(RoadBuildCost(rt) * 2);
} }
} }
@ -1283,7 +1283,7 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlags f
/* AddCost for new or rotated rail stations. */ /* AddCost for new or rotated rail stations. */
if (!IsRailStationTile(cur_tile) || (IsRailStationTile(cur_tile) && GetRailStationAxis(cur_tile) != axis)) { if (!IsRailStationTile(cur_tile) || (IsRailStationTile(cur_tile) && GetRailStationAxis(cur_tile) != axis)) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
cost.AddCost(_price[PR_BUILD_STATION_RAIL]); cost.AddCost(_price[PR_BUILD_STATION_RAIL]);
cost.AddCost(RailBuildCost(rt)); cost.AddCost(RailBuildCost(rt));
@ -1652,8 +1652,8 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
/* If there is a vehicle on ground, do not allow to remove (flood) the tile */ /* If there is a vehicle on ground, do not allow to remove (flood) the tile */
CommandCost ret = EnsureNoVehicleOnGround(tile); CommandCost ret = EnsureNoVehicleOnGround(tile);
error.AddCost(ret); error.AddCost(std::move(ret));
if (ret.Failed()) continue; if (error.Failed()) continue;
/* Check ownership of station */ /* Check ownership of station */
T *st = T::GetByTile(tile); T *st = T::GetByTile(tile);
@ -1661,8 +1661,8 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
if (_current_company != OWNER_WATER) { if (_current_company != OWNER_WATER) {
ret = CheckOwnership(st->owner); ret = CheckOwnership(st->owner);
error.AddCost(ret); error.AddCost(std::move(ret));
if (ret.Failed()) continue; if (error.Failed()) continue;
} }
/* If we reached here, the tile is valid so increase the quantity of tiles we will remove */ /* If we reached here, the tile is valid so increase the quantity of tiles we will remove */
@ -1817,7 +1817,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlags flags, Money removal_cost)
std::vector<T*> affected_stations; // dummy std::vector<T*> affected_stations; // dummy
CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false); CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
} }
@ -1933,7 +1933,7 @@ CommandCost CalculateRoadStopCost(TileArea tile_area, DoCommandFlags flags, bool
/* Only add costs if a stop doesn't already exist in the location */ /* Only add costs if a stop doesn't already exist in the location */
if (!is_preexisting_roadstop) { if (!is_preexisting_roadstop) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
cost.AddCost(unit_cost); cost.AddCost(unit_cost);
} }
} }
@ -2346,7 +2346,7 @@ static CommandCost RemoveGenericRoadStop(DoCommandFlags flags, const TileArea &r
last_error = std::move(ret); last_error = std::move(ret);
continue; continue;
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
had_success = true; had_success = true;
/* Restore roads. */ /* Restore roads. */
@ -2806,7 +2806,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]); CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
TileIndex tile_cur = tile + TileOffsByDiagDir(direction); TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
@ -2822,7 +2822,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station
bool add_cost = !IsWaterTile(tile_cur); bool add_cost = !IsWaterTile(tile_cur);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
if (add_cost) cost.AddCost(ret); if (add_cost) cost.AddCost(ret.GetCost());
tile_cur += TileOffsByDiagDir(direction); tile_cur += TileOffsByDiagDir(direction);
if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) { if (!IsTileType(tile_cur, MP_WATER) || !IsTileFlat(tile_cur)) {

View File

@ -151,7 +151,7 @@ static std::tuple<CommandCost, TileIndex> TerraformTileHeight(TerraformerState *
height_diff += (height_diff < 0 ? 1 : -1); height_diff += (height_diff < 0 ? 1 : -1);
auto [cost, err_tile] = TerraformTileHeight(ts, neighbour_tile, r + height_diff); auto [cost, err_tile] = TerraformTileHeight(ts, neighbour_tile, r + height_diff);
if (cost.Failed()) return { cost, err_tile }; if (cost.Failed()) return { cost, err_tile };
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
} }
} }
@ -177,28 +177,28 @@ std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand(DoCommandFlags flags,
TileIndex t = tile + TileDiffXY(1, 0); TileIndex t = tile + TileDiffXY(1, 0);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction); auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
if (cost.Failed()) return { cost, 0, err_tile }; if (cost.Failed()) return { cost, 0, err_tile };
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
} }
if ((slope & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < Map::Size()) { if ((slope & SLOPE_S) != 0 && tile + TileDiffXY(1, 1) < Map::Size()) {
TileIndex t = tile + TileDiffXY(1, 1); TileIndex t = tile + TileDiffXY(1, 1);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction); auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
if (cost.Failed()) return { cost, 0, err_tile }; if (cost.Failed()) return { cost, 0, err_tile };
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
} }
if ((slope & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < Map::Size()) { if ((slope & SLOPE_E) != 0 && tile + TileDiffXY(0, 1) < Map::Size()) {
TileIndex t = tile + TileDiffXY(0, 1); TileIndex t = tile + TileDiffXY(0, 1);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction); auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
if (cost.Failed()) return { cost, 0, err_tile }; if (cost.Failed()) return { cost, 0, err_tile };
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
} }
if ((slope & SLOPE_N) != 0) { if ((slope & SLOPE_N) != 0) {
TileIndex t = tile + TileDiffXY(0, 0); TileIndex t = tile + TileDiffXY(0, 0);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction); auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
if (cost.Failed()) return { cost, 0, err_tile }; if (cost.Failed()) return { cost, 0, err_tile };
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
} }
/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface /* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface
@ -271,7 +271,7 @@ std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand(DoCommandFlags flags,
if (cost.Failed()) { if (cost.Failed()) {
return { cost, 0, t }; return { cost, 0, t };
} }
if (pass == 1) total_cost.AddCost(cost); if (pass == 1) total_cost.AddCost(cost.GetCost());
} }
} }
@ -374,7 +374,7 @@ std::tuple<CommandCost, Money, TileIndex> CmdLevelLand(DoCommandFlags flags, Til
} }
} }
cost.AddCost(ret); cost.AddCost(ret.GetCost());
curh += (curh > h) ? -1 : 1; curh += (curh > h) ? -1 : 1;
had_success = true; had_success = true;
} }

View File

@ -585,7 +585,7 @@ CommandCost CmdPlantTree(DoCommandFlags flags, TileIndex tile, TileIndex start_t
case CLEAR_ROCKS: { case CLEAR_ROCKS: {
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile); CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
break; break;
} }

View File

@ -402,16 +402,16 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t
cost = ret; cost = ret;
if (terraform_cost_north.Failed() || (terraform_cost_north.GetCost() != 0 && !allow_on_slopes)) return CommandCost(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); cost.AddCost(terraform_cost_north.GetCost());
/* Try and clear the end landscape */ /* Try and clear the end landscape */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* false - end tile slope check */ /* false - end tile slope check */
if (terraform_cost_south.Failed() || (terraform_cost_south.GetCost() != 0 && !allow_on_slopes)) return CommandCost(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); cost.AddCost(terraform_cost_south.GetCost());
const TileIndex heads[] = {tile_start, tile_end}; const TileIndex heads[] = {tile_start, tile_end};
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@ -479,7 +479,7 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t
/* try and clear the middle landscape */ /* try and clear the middle landscape */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
break; break;
} }
@ -697,7 +697,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
/* Add the cost of the entrance */ /* Add the cost of the entrance */
cost.AddCost(_price[PR_BUILD_TUNNEL]); cost.AddCost(_price[PR_BUILD_TUNNEL]);
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* if the command fails from here on we want the end tile to be highlighted */ /* if the command fails from here on we want the end tile to be highlighted */
_build_tunnel_endtile = end_tile; _build_tunnel_endtile = end_tile;
@ -709,7 +709,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
/* Clear the tile in any case */ /* Clear the tile in any case */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile);
if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND); if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* slope of end tile must be complementary to the slope of the start tile */ /* slope of end tile must be complementary to the slope of the start tile */
if (end_tileh != ComplementSlope(start_tileh)) { if (end_tileh != ComplementSlope(start_tileh)) {
@ -742,7 +742,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
ret = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, false)); ret = std::get<0>(Command<CMD_TERRAFORM_LAND>::Do(flags, end_tile, end_tileh & start_tileh, false));
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile; _cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND); if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
cost.AddCost(_price[PR_BUILD_TUNNEL]); cost.AddCost(_price[PR_BUILD_TUNNEL]);

View File

@ -171,7 +171,7 @@ std::tuple<CommandCost, VehicleID, uint, uint16_t, CargoArray> CmdBuildVehicle(D
/* Refit only one vehicle. If we purchased an engine, it may have gained free wagons. */ /* Refit only one vehicle. If we purchased an engine, it may have gained free wagons. */
CommandCost cc; CommandCost cc;
std::tie(cc, refitted_capacity, refitted_mail_capacity, cargo_capacities) = CmdRefitVehicle(flags, v->index, cargo, 0, false, false, 1); std::tie(cc, refitted_capacity, refitted_mail_capacity, cargo_capacities) = CmdRefitVehicle(flags, v->index, cargo, 0, false, false, 1);
value.AddCost(cc); value.AddCost(std::move(cc));
} else { } else {
/* Fill in non-refitted capacities */ /* Fill in non-refitted capacities */
if (e->type == VEH_TRAIN || e->type == VEH_ROAD) { if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
@ -452,7 +452,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
} }
continue; continue;
} }
cost.AddCost(refit_cost); cost.AddCost(std::move(refit_cost));
/* Record the refitting. /* Record the refitting.
* Do not execute the refitting immediately, so DetermineCapacity and GetRefitCost do the same in test and exec run. * Do not execute the refitting immediately, so DetermineCapacity and GetRefitCost do the same in test and exec run.
@ -720,7 +720,7 @@ CommandCost CmdDepotSellAllVehicles(DoCommandFlags flags, TileIndex tile, Vehicl
for (const Vehicle *v : list) { for (const Vehicle *v : list) {
CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, v->index, true, false, INVALID_CLIENT_ID); CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, v->index, true, false, INVALID_CLIENT_ID);
if (ret.Succeeded()) { if (ret.Succeeded()) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
had_success = true; had_success = true;
} else { } else {
last_error = std::move(ret); last_error = std::move(ret);
@ -754,7 +754,7 @@ CommandCost CmdDepotMassAutoReplace(DoCommandFlags flags, TileIndex tile, Vehicl
CommandCost ret = Command<CMD_AUTOREPLACE_VEHICLE>::Do(flags, v->index); CommandCost ret = Command<CMD_AUTOREPLACE_VEHICLE>::Do(flags, v->index);
if (ret.Succeeded()) cost.AddCost(ret); if (ret.Succeeded()) cost.AddCost(ret.GetCost());
} }
return cost; return cost;
} }
@ -900,7 +900,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
return { cost, VehicleID::Invalid() }; return { cost, VehicleID::Invalid() };
} }
total_cost.AddCost(cost); total_cost.AddCost(cost.GetCost());
if (flags.Test(DoCommandFlag::Execute)) { if (flags.Test(DoCommandFlag::Execute)) {
w = Vehicle::Get(new_veh_id); w = Vehicle::Get(new_veh_id);
@ -961,7 +961,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
uint8_t subtype = GetBestFittingSubType(v, w, v->cargo_type); uint8_t subtype = GetBestFittingSubType(v, w, v->cargo_type);
if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) { if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) {
CommandCost cost = std::get<0>(Command<CMD_REFIT_VEHICLE>::Do(flags, w->index, v->cargo_type, subtype, false, true, 0)); CommandCost cost = std::get<0>(Command<CMD_REFIT_VEHICLE>::Do(flags, w->index, v->cargo_type, subtype, false, true, 0));
if (cost.Succeeded()) total_cost.AddCost(cost); if (cost.Succeeded()) total_cost.AddCost(cost.GetCost());
} }
if (w->IsGroundVehicle() && w->HasArticulatedPart()) { if (w->IsGroundVehicle() && w->HasArticulatedPart()) {

View File

@ -135,13 +135,13 @@ CommandCost CmdBuildShipDepot(DoCommandFlags flags, TileIndex tile, Axis axis)
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile); CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
if (add_cost) { if (add_cost) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
add_cost = !IsWaterTile(tile2); add_cost = !IsWaterTile(tile2);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile2); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile2);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
if (add_cost) { if (add_cost) {
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
if (flags.Test(DoCommandFlag::Execute)) { if (flags.Test(DoCommandFlag::Execute)) {
@ -322,13 +322,13 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags
WaterClass wc_middle = HasTileWaterGround(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL; WaterClass wc_middle = HasTileWaterGround(tile) ? GetWaterClass(tile) : WATER_CLASS_CANAL;
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
/* lower tile */ /* lower tile */
if (!IsWaterTile(tile - delta)) { if (!IsWaterTile(tile - delta)) {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
cost.AddCost(_price[PR_BUILD_CANAL]); cost.AddCost(_price[PR_BUILD_CANAL]);
} }
if (!IsTileFlat(tile - delta)) { if (!IsTileFlat(tile - delta)) {
@ -340,7 +340,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags
if (!IsWaterTile(tile + delta)) { if (!IsWaterTile(tile + delta)) {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
cost.AddCost(_price[PR_BUILD_CANAL]); cost.AddCost(_price[PR_BUILD_CANAL]);
} }
if (!IsTileFlat(tile + delta)) { if (!IsTileFlat(tile + delta)) {
@ -495,7 +495,7 @@ CommandCost CmdBuildCanal(DoCommandFlags flags, TileIndex tile, TileIndex start_
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile); ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, current_tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
if (!water) cost.AddCost(ret); if (!water) cost.AddCost(ret.GetCost());
if (flags.Test(DoCommandFlag::Execute)) { if (flags.Test(DoCommandFlag::Execute)) {
if (IsTileType(current_tile, MP_WATER) && IsCanal(current_tile)) { if (IsTileType(current_tile, MP_WATER) && IsCanal(current_tile)) {

View File

@ -479,7 +479,7 @@ CommandCost CmdBuildBuoy(DoCommandFlags flags, TileIndex tile)
if (!IsWaterTile(tile)) { if (!IsWaterTile(tile)) {
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile); CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile);
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
cost.AddCost(ret); cost.AddCost(ret.GetCost());
} }
if (flags.Test(DoCommandFlag::Execute)) { if (flags.Test(DoCommandFlag::Execute)) {