* 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 */
| 698 | * @return the cost of this operation or an error |
| 699 | */ |
| 700 | CommandCost 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 |
nothing calls this directly
no test coverage detected