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

Function ScriptOrderPositionToRealOrderPosition

src/script/api/script_order.cpp:85–96  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

83 * @return An OpenTTD-internal index for the same order.
84 */
85static 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)

Callers 13

IsConditionalOrderMethod · 0.85
SetOrderJumpToMethod · 0.85
SetOrderConditionMethod · 0.85
SetOrderCompareValueMethod · 0.85
SetStopLocationMethod · 0.85
SetOrderRefitMethod · 0.85
InsertOrderMethod · 0.85
RemoveOrderMethod · 0.85
SkipToOrderMethod · 0.85
_SetOrderFlagsMethod · 0.85

Calls 8

filterFunction · 0.85
OrdersMethod · 0.80
IsTypeMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
GetNumManualOrdersMethod · 0.45
GetNumOrdersMethod · 0.45
baseMethod · 0.45

Tested by

no test coverage detected