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

Function RealOrderPositionToScriptOrderPosition

src/script/api/script_order.cpp:103–112  ·  view source on GitHub ↗

* Convert an order index from OpenTTD to a ScriptOrder::OrderPosition (which is the manual order index) * @param order_position The OpenTTD-internal index to convert. * @return An OrderPosition for the same order. */

Source from the content-addressed store, hash-verified

101 * @return An OrderPosition for the same order.
102 */
103static ScriptOrder::OrderPosition RealOrderPositionToScriptOrderPosition(VehicleID vehicle_id, int order_position)
104{
105 const Vehicle *v = ::Vehicle::Get(vehicle_id);
106
107 auto orders = v->Orders();
108 auto first = std::begin(orders);
109 auto last = std::ranges::next(first, order_position, std::end(orders));
110 int num_implicit = static_cast<int>(std::count_if(first, last, [](const Order &order) { return order.IsType(OT_IMPLICIT); }));
111 return static_cast<ScriptOrder::OrderPosition>(order_position - num_implicit);
112}
113
114/* static */ bool ScriptOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
115{

Callers 2

ResolveOrderPositionMethod · 0.85
GetOrderJumpToMethod · 0.85

Calls 4

OrdersMethod · 0.80
IsTypeMethod · 0.80
beginFunction · 0.50
endFunction · 0.50

Tested by

no test coverage detected