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

Function ResolveOrder

src/script/api/script_order.cpp:62–77  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

60 * was a manual order, return the current order.
61 */
62static 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

Callers 14

IsGotoStationOrderMethod · 0.85
IsGotoDepotOrderMethod · 0.85
IsGotoWaypointOrderMethod · 0.85
IsVoidOrderMethod · 0.85
IsRefitOrderMethod · 0.85
GetOrderDestinationMethod · 0.85
GetOrderFlagsMethod · 0.85
GetOrderJumpToMethod · 0.85
GetOrderConditionMethod · 0.85
GetOrderCompareValueMethod · 0.85
GetStopLocationMethod · 0.85

Calls 8

filterFunction · 0.85
TestMethod · 0.80
GetDepotOrderTypeMethod · 0.80
OrdersMethod · 0.80
IsTypeMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
GetTypeMethod · 0.45

Tested by

no test coverage detected