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);
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;
replacement.cost = ret.GetCost();
if (replacement.new_veh != nullptr) *nothing_to_do = false;
}
Vehicle *new_head = replacements.front().GetVehicle();
@ -602,7 +602,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlags flags, bool wago
break;
}
cost.AddCost(res);
cost.AddCost(std::move(res));
if (cost.Failed()) break;
} else {
/* 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.
* @param ret The command to add the cost of.
*/
void CommandCost::AddCost(const CommandCost &ret)
void CommandCost::AddCost(CommandCost &&ret)
{
this->AddCost(ret.cost);
if (this->success && !ret.success) {
this->message = ret.message;
this->encoded_message = std::move(ret.encoded_message);
this->success = false;
}
}

View File

@ -100,7 +100,7 @@ public:
this->cost += cost;
}
void AddCost(const CommandCost &cmd_cost);
void AddCost(CommandCost &&cmd_cost);
/**
* 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. */
if (ret.GetCost() != 0 && --limit <= 0) break;
}
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
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;
Command<CMD_BUILD_OBJECT>::Do(flags, t, type, view);
}
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
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);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
if (HasSignals(tile) && TracksOverlap(GetTrackBits(tile) | TrackToTrackBits(track))) {
/* 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)) {
CommandCost ret_remove_signals = Command<CMD_REMOVE_SINGLE_SIGNAL>::Do(flags, tile, track_it);
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)) {
ret = Command<CMD_CONVERT_RAIL>::Do(flags, tile, tile, railtype, false);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
} else {
return CMD_ERROR;
}
@ -571,11 +571,11 @@ CommandCost CmdBuildSingleRail(DoCommandFlags flags, TileIndex tile, RailType ra
CommandCost ret = CheckRailSlope(tileh, trackbit, TRACK_BIT_NONE, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
if (water_ground) {
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;
} else {
had_success = true;
total_cost.AddCost(ret);
total_cost.AddCost(ret.GetCost());
}
if (tile == end_tile) break;
@ -1330,7 +1330,7 @@ static CommandCost CmdSignalTrackHelper(DoCommandFlags flags, TileIndex tile, Ti
if (ret.Succeeded()) {
had_success = true;
total_cost.AddCost(ret);
total_cost.AddCost(ret.GetCost());
} else {
/* The "No railway" error is the least important one. */
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);
CommandCost ret = Command<CMD_REMOVE_SINGLE_RAIL>::Do(flags, tile, track);
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.

View File

@ -817,7 +817,7 @@ do_clear:;
if (need_to_clear) {
CommandCost ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
if (other_bits != pieces) {
@ -828,7 +828,7 @@ do_clear:;
if (ret.Failed() || (ret.GetCost() != 0 && !_settings_game.construction.build_on_slopes)) {
return CommandCost(STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
}
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
if (!need_to_clear) {
@ -863,7 +863,7 @@ do_clear:;
} else if (HasPowerOnRoad(existing_rt, rt)) {
ret = Command<CMD_CONVERT_ROAD>::Do(flags, tile, tile, rt);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
} else {
return CMD_ERROR;
}
@ -1036,17 +1036,17 @@ CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (IsBridge(tile)) {
if (!had_bridge || GetTunnelBridgeDirection(tile) == dir) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
had_bridge = true;
} else { // IsTunnel(tile)
if (!had_tunnel || GetTunnelBridgeDirection(tile) == dir) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
had_tunnel = true;
}
} 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);
}
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
had_success = true;
} else {
/* 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);
if (tmp_ret.Failed()) return tmp_ret;
ret.AddCost(tmp_ret);
ret.AddCost(tmp_ret.GetCost());
}
return ret;
}
@ -1260,7 +1260,7 @@ static CommandCost ClearTile_Road(TileIndex tile, DoCommandFlags flags)
CommandCost tmp_ret = RemoveRoad(tile, flags, GetCrossingRoadBits(tile), rtt, true);
if (tmp_ret.Failed()) return tmp_ret;
ret.AddCost(tmp_ret);
ret.AddCost(tmp_ret.GetCost());
}
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) {
CommandCost ret = CheckBuildableTile(tile_iter, 0, allowed_z, true);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_iter);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
return cost;
@ -889,7 +889,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
if (slope_cb) {
/* 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);
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 */
return cost;
}
@ -942,7 +942,7 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_
}
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
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);
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.
* 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 {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, cur_tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
cost.AddCost(RoadBuildCost(rt) * 2);
}
}
@ -1283,7 +1283,7 @@ static CommandCost CalculateRailStationCost(TileArea tile_area, DoCommandFlags f
/* AddCost for new or rotated rail stations. */
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(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 */
CommandCost ret = EnsureNoVehicleOnGround(tile);
error.AddCost(ret);
if (ret.Failed()) continue;
error.AddCost(std::move(ret));
if (error.Failed()) continue;
/* Check ownership of station */
T *st = T::GetByTile(tile);
@ -1661,8 +1661,8 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
if (_current_company != OWNER_WATER) {
ret = CheckOwnership(st->owner);
error.AddCost(ret);
if (ret.Failed()) continue;
error.AddCost(std::move(ret));
if (error.Failed()) continue;
}
/* 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
CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
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 */
if (!is_preexisting_roadstop) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
cost.AddCost(unit_cost);
}
}
@ -2346,7 +2346,7 @@ static CommandCost RemoveGenericRoadStop(DoCommandFlags flags, const TileArea &r
last_error = std::move(ret);
continue;
}
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
had_success = true;
/* Restore roads. */
@ -2806,7 +2806,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_STATION_DOCK]);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
@ -2822,7 +2822,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station
bool add_cost = !IsWaterTile(tile_cur);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_cur);
if (ret.Failed()) return ret;
if (add_cost) cost.AddCost(ret);
if (add_cost) cost.AddCost(ret.GetCost());
tile_cur += TileOffsByDiagDir(direction);
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);
auto [cost, err_tile] = TerraformTileHeight(ts, neighbour_tile, r + height_diff);
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);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
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()) {
TileIndex t = tile + TileDiffXY(1, 1);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
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()) {
TileIndex t = tile + TileDiffXY(0, 1);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
if (cost.Failed()) return { cost, 0, err_tile };
total_cost.AddCost(cost);
total_cost.AddCost(cost.GetCost());
}
if ((slope & SLOPE_N) != 0) {
TileIndex t = tile + TileDiffXY(0, 0);
auto [cost, err_tile] = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
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
@ -271,7 +271,7 @@ std::tuple<CommandCost, Money, TileIndex> CmdTerraformLand(DoCommandFlags flags,
if (cost.Failed()) {
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;
had_success = true;
}

View File

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

View File

@ -402,16 +402,16 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t
cost = ret;
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 */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile_end);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
/* 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);
cost.AddCost(terraform_cost_south);
cost.AddCost(terraform_cost_south.GetCost());
const TileIndex heads[] = {tile_start, tile_end};
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 */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
break;
}
@ -697,7 +697,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
/* Add the cost of the entrance */
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 */
_build_tunnel_endtile = end_tile;
@ -709,7 +709,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
/* Clear the tile in any case */
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, end_tile);
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 */
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));
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
if (ret.Failed()) return CommandCost(STR_ERROR_UNABLE_TO_EXCAVATE_LAND);
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
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. */
CommandCost cc;
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 {
/* Fill in non-refitted capacities */
if (e->type == VEH_TRAIN || e->type == VEH_ROAD) {
@ -452,7 +452,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
}
continue;
}
cost.AddCost(refit_cost);
cost.AddCost(std::move(refit_cost));
/* Record the refitting.
* 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) {
CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, v->index, true, false, INVALID_CLIENT_ID);
if (ret.Succeeded()) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
had_success = true;
} else {
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);
if (ret.Succeeded()) cost.AddCost(ret);
if (ret.Succeeded()) cost.AddCost(ret.GetCost());
}
return cost;
}
@ -900,7 +900,7 @@ std::tuple<CommandCost, VehicleID> CmdCloneVehicle(DoCommandFlags flags, TileInd
return { cost, VehicleID::Invalid() };
}
total_cost.AddCost(cost);
total_cost.AddCost(cost.GetCost());
if (flags.Test(DoCommandFlag::Execute)) {
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);
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));
if (cost.Succeeded()) total_cost.AddCost(cost);
if (cost.Succeeded()) total_cost.AddCost(cost.GetCost());
}
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);
if (ret.Failed()) return ret;
if (add_cost) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
add_cost = !IsWaterTile(tile2);
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags | DoCommandFlag::Auto, tile2);
if (ret.Failed()) return ret;
if (add_cost) {
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
}
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;
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
/* lower tile */
if (!IsWaterTile(tile - delta)) {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile - delta);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
cost.AddCost(_price[PR_BUILD_CANAL]);
}
if (!IsTileFlat(tile - delta)) {
@ -340,7 +340,7 @@ static CommandCost DoBuildLock(TileIndex tile, DiagDirection dir, DoCommandFlags
if (!IsWaterTile(tile + delta)) {
ret = Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile + delta);
if (ret.Failed()) return ret;
cost.AddCost(ret);
cost.AddCost(ret.GetCost());
cost.AddCost(_price[PR_BUILD_CANAL]);
}
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);
if (ret.Failed()) return ret;
if (!water) cost.AddCost(ret);
if (!water) cost.AddCost(ret.GetCost());
if (flags.Test(DoCommandFlag::Execute)) {
if (IsTileType(current_tile, MP_WATER) && IsCanal(current_tile)) {

View File

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