MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdDepotSellAllVehicles

Function CmdDepotSellAllVehicles

src/vehicle_cmd.cpp:700–725  ·  view source on GitHub ↗

* Sells all vehicles in a depot * @param flags type of operation * @param tile Tile of the depot where the depot is * @param vehicle_type Vehicle type * @return the cost of this operation or an error */

Source from the content-addressed store, hash-verified

698 * @return the cost of this operation or an error
699 */
700CommandCost CmdDepotSellAllVehicles(DoCommandFlags flags, TileIndex tile, VehicleType vehicle_type)
701{
702 VehicleList list;
703
704 CommandCost cost(EXPENSES_NEW_VEHICLES);
705
706 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
707 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;
708
709 /* Get the list of vehicles in the depot */
710 BuildDepotVehicleList(vehicle_type, tile, &list, &list);
711
712 CommandCost last_error = CMD_ERROR;
713 bool had_success = false;
714 for (const Vehicle *v : list) {
715 CommandCost ret = Command<CMD_SELL_VEHICLE>::Do(flags, v->index, true, false, INVALID_CLIENT_ID);
716 if (ret.Succeeded()) {
717 cost.AddCost(ret.GetCost());
718 had_success = true;
719 } else {
720 last_error = std::move(ret);
721 }
722 }
723
724 return had_success ? cost : last_error;
725}
726
727/**
728 * Autoreplace all vehicles in the depot

Callers

nothing calls this directly

Calls 7

IsDepotTileFunction · 0.85
IsTileOwnerFunction · 0.85
BuildDepotVehicleListFunction · 0.85
SucceededMethod · 0.80
AddCostMethod · 0.45
GetCostMethod · 0.45

Tested by

no test coverage detected