* Convert an ScriptOrder::OrderPosition (which is the manual order index) to an order index * as expected by the OpenTTD commands. * @param order_position The OrderPosition to convert. * @return An OpenTTD-internal index for the same order. */
| 83 | * @return An OpenTTD-internal index for the same order. |
| 84 | */ |
| 85 | static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOrder::OrderPosition order_position) |
| 86 | { |
| 87 | const Vehicle *v = ::Vehicle::Get(vehicle_id); |
| 88 | if (order_position == v->GetNumManualOrders()) return v->GetNumOrders(); |
| 89 | |
| 90 | assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position)); |
| 91 | |
| 92 | auto orders = v->Orders(); |
| 93 | auto real_orders = orders | std::views::filter([](const Order &order) { return !order.IsType(OT_IMPLICIT); }); |
| 94 | auto it = std::ranges::next(std::begin(real_orders), order_position, std::end(real_orders)); |
| 95 | return static_cast<int>(std::distance(std::begin(orders), it.base())); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Convert an order index from OpenTTD to a ScriptOrder::OrderPosition (which is the manual order index) |
no test coverage detected