* Get the current order the vehicle is executing. If the current order is in * the order list, return the order from the orderlist. If the current order * was a manual order, return the current order. */
| 60 | * was a manual order, return the current order. |
| 61 | */ |
| 62 | static const Order *ResolveOrder(VehicleID vehicle_id, ScriptOrder::OrderPosition order_position) |
| 63 | { |
| 64 | const Vehicle *v = ::Vehicle::Get(vehicle_id); |
| 65 | if (order_position == ScriptOrder::ORDER_CURRENT) { |
| 66 | const Order *order = &v->current_order; |
| 67 | if (order->GetType() == OT_GOTO_DEPOT && !order->GetDepotOrderType().Test(OrderDepotTypeFlag::PartOfOrders)) return order; |
| 68 | order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position); |
| 69 | if (order_position == ScriptOrder::ORDER_INVALID) return nullptr; |
| 70 | } |
| 71 | |
| 72 | auto real_orders = v->Orders() | std::views::filter([](const Order &order) { return !order.IsType(OT_IMPLICIT); }); |
| 73 | auto it = std::ranges::next(std::begin(real_orders), order_position, std::end(real_orders)); |
| 74 | if (it != std::end(real_orders)) return &*it; |
| 75 | |
| 76 | return nullptr; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Convert an ScriptOrder::OrderPosition (which is the manual order index) to an order index |
no test coverage detected