* Delete an order from the orderlist of a vehicle. * @param flags operation to perform * @param veh_id the ID of the vehicle * @param sel_ord the order to delete (max 255) * @return the cost of this operation or an error */
| 932 | * @return the cost of this operation or an error |
| 933 | */ |
| 934 | CommandCost CmdDeleteOrder(DoCommandFlags flags, VehicleID veh_id, VehicleOrderID sel_ord) |
| 935 | { |
| 936 | Vehicle *v = Vehicle::GetIfValid(veh_id); |
| 937 | |
| 938 | if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR; |
| 939 | |
| 940 | CommandCost ret = CheckOwnership(v->owner); |
| 941 | if (ret.Failed()) return ret; |
| 942 | |
| 943 | /* If we did not select an order, we maybe want to de-clone the orders */ |
| 944 | if (sel_ord >= v->GetNumOrders()) return DecloneOrder(v, flags); |
| 945 | |
| 946 | if (v->GetOrder(sel_ord) == nullptr) return CMD_ERROR; |
| 947 | |
| 948 | if (flags.Test(DoCommandFlag::Execute)) DeleteOrder(v, sel_ord); |
| 949 | return CommandCost(); |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Cancel the current loading order of the vehicle as the order was deleted. |
nothing calls this directly
no test coverage detected