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

Method GetNextDecisionNode

src/order_cmd.cpp:327–352  ·  view source on GitHub ↗

* Get the next order which will make the given vehicle stop at a station * or refit at a depot or evaluate a non-trivial condition. * @param next The order to start looking at. * @param hops The number of orders we have already looked at. * @return Either of * \li a station order * \li a refitting depot order * \li a non-trivial conditional order * \li INVAL

Source from the content-addressed store, hash-verified

325 * \li INVALID_VEH_ORDER_ID if the vehicle won't stop anymore.
326 */
327VehicleOrderID OrderList::GetNextDecisionNode(VehicleOrderID next, uint hops) const
328{
329 if (hops > this->GetNumOrders() || next >= this->GetNumOrders()) return INVALID_VEH_ORDER_ID;
330
331 const Order &order_next = this->orders[next];
332 if (order_next.IsType(OT_CONDITIONAL)) {
333 if (order_next.GetConditionVariable() != OrderConditionVariable::Unconditionally) return next;
334
335 /* We can evaluate trivial conditions right away. They're conceptually
336 * the same as regular order progression. */
337 return this->GetNextDecisionNode(
338 order_next.GetConditionSkipToOrder(),
339 hops + 1);
340 }
341
342 if (order_next.IsType(OT_GOTO_DEPOT)) {
343 if (order_next.GetDepotActionType().Test(OrderDepotActionFlag::Halt)) return INVALID_VEH_ORDER_ID;
344 if (order_next.IsRefit()) return next;
345 }
346
347 if (!order_next.CanLoadOrUnload()) {
348 return this->GetNextDecisionNode(this->GetNext(next), hops + 1);
349 }
350
351 return next;
352}
353
354/**
355 * Recursively determine the next deterministic station to stop at.

Callers 3

RunMethod · 0.80
PredictNextOrderMethod · 0.80

Calls 9

GetNumOrdersMethod · 0.95
GetNextMethod · 0.95
IsTypeMethod · 0.80
GetConditionVariableMethod · 0.80
TestMethod · 0.80
GetDepotActionTypeMethod · 0.80
IsRefitMethod · 0.80
CanLoadOrUnloadMethod · 0.80

Tested by

no test coverage detected