* 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
| 325 | * \li INVALID_VEH_ORDER_ID if the vehicle won't stop anymore. |
| 326 | */ |
| 327 | VehicleOrderID 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. |
no test coverage detected