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

Function SendAllVehiclesToDepot

src/vehicle_cmd.cpp:1022–1046  ·  view source on GitHub ↗

* Send all vehicles of type to depots * @param flags the flags used for DoCommand() * @param service should the vehicles only get service in the depots * @param vli identifier of the vehicle list * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot */

Source from the content-addressed store, hash-verified

1020 * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
1021 */
1022static CommandCost SendAllVehiclesToDepot(DoCommandFlags flags, bool service, const VehicleListIdentifier &vli)
1023{
1024 VehicleList list;
1025
1026 if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
1027
1028 /* Send all the vehicles to a depot */
1029 bool had_success = false;
1030 for (uint i = 0; i < list.size(); i++) {
1031 const Vehicle *v = list[i];
1032 CommandCost ret = Command<CMD_SEND_VEHICLE_TO_DEPOT>::Do(flags, v->index, (service ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::DontCancel, {});
1033
1034 if (ret.Succeeded()) {
1035 had_success = true;
1036
1037 /* Return 0 if DoCommandFlag::Execute is not set this is a valid goto depot command)
1038 * In this case we know that at least one vehicle can be sent to a depot
1039 * and we will issue the command. We can now safely quit the loop, knowing
1040 * it will succeed at least once. With DoCommandFlag::Execute we really need to send them to the depot */
1041 if (!flags.Test(DoCommandFlag::Execute)) break;
1042 }
1043 }
1044
1045 return had_success ? CommandCost() : CMD_ERROR;
1046}
1047
1048/**
1049 * Send a vehicle to the depot.

Callers 1

CmdSendVehicleToDepotFunction · 0.85

Calls 5

GenerateVehicleSortListFunction · 0.85
CommandCostClass · 0.85
SucceededMethod · 0.80
TestMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected