* Delete an order but skip the parameter validation. * @param v The vehicle to delete the order from. * @param sel_ord The id of the order to be deleted. */
| 970 | * @param sel_ord The id of the order to be deleted. |
| 971 | */ |
| 972 | void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord) |
| 973 | { |
| 974 | v->orders->DeleteOrderAt(sel_ord); |
| 975 | |
| 976 | Vehicle *u = v->FirstShared(); |
| 977 | DeleteOrderWarnings(u); |
| 978 | for (; u != nullptr; u = u->NextShared()) { |
| 979 | assert(v->orders == u->orders); |
| 980 | |
| 981 | if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) { |
| 982 | CancelLoadingDueToDeletedOrder(u); |
| 983 | } |
| 984 | |
| 985 | if (sel_ord < u->cur_real_order_index) { |
| 986 | u->cur_real_order_index--; |
| 987 | } else if (sel_ord == u->cur_real_order_index) { |
| 988 | u->UpdateRealOrderIndex(); |
| 989 | } |
| 990 | |
| 991 | if (sel_ord < u->cur_implicit_order_index) { |
| 992 | u->cur_implicit_order_index--; |
| 993 | } else if (sel_ord == u->cur_implicit_order_index) { |
| 994 | /* Make sure the index is valid */ |
| 995 | if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0; |
| 996 | |
| 997 | /* Skip non-implicit orders for the implicit-order-index (e.g. if the current implicit order was deleted */ |
| 998 | while (u->cur_implicit_order_index != u->cur_real_order_index && !u->GetOrder(u->cur_implicit_order_index)->IsType(OT_IMPLICIT)) { |
| 999 | u->cur_implicit_order_index++; |
| 1000 | if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0; |
| 1001 | } |
| 1002 | } |
| 1003 | /* Unbunching data is no longer valid. */ |
| 1004 | u->ResetDepotUnbunching(); |
| 1005 | |
| 1006 | /* Update any possible open window of the vehicle */ |
| 1007 | InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8)); |
| 1008 | } |
| 1009 | |
| 1010 | /* As we delete an order, the order to skip to will be 'wrong'. */ |
| 1011 | VehicleOrderID cur_order_id = 0; |
| 1012 | for (Order &order : v->Orders()) { |
| 1013 | if (order.IsType(OT_CONDITIONAL)) { |
| 1014 | VehicleOrderID order_id = order.GetConditionSkipToOrder(); |
| 1015 | if (order_id >= sel_ord) { |
| 1016 | order_id = std::max(order_id - 1, 0); |
| 1017 | } |
| 1018 | if (order_id == cur_order_id) { |
| 1019 | order_id = (order_id + 1) % v->GetNumOrders(); |
| 1020 | } |
| 1021 | order.SetConditionSkipToOrder(order_id); |
| 1022 | } |
| 1023 | cur_order_id++; |
| 1024 | } |
| 1025 | |
| 1026 | InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); |
| 1027 | } |
| 1028 | |
| 1029 | /** |
no test coverage detected