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

Method SwitchToNextOrder

src/train_cmd.cpp:2679–2723  ·  view source on GitHub ↗

* Set the current vehicle order to the next order in the order list. * @param skip_first Shall the first (i.e. active) order be skipped? * @return True if a suitable next order could be found. */

Source from the content-addressed store, hash-verified

2677 * @return True if a suitable next order could be found.
2678 */
2679 bool SwitchToNextOrder(bool skip_first)
2680 {
2681 if (this->v->GetNumOrders() == 0) return false;
2682
2683 if (skip_first) ++this->index;
2684
2685 int depth = 0;
2686
2687 do {
2688 /* Wrap around. */
2689 if (this->index >= this->v->GetNumOrders()) this->index = 0;
2690
2691 Order *order = this->v->GetOrder(this->index);
2692 assert(order != nullptr);
2693
2694 switch (order->GetType()) {
2695 case OT_GOTO_DEPOT:
2696 /* Skip service in depot orders when the train doesn't need service. */
2697 if (order->GetDepotOrderType().Test(OrderDepotTypeFlag::Service) && !this->v->NeedsServicing()) break;
2698 [[fallthrough]];
2699 case OT_GOTO_STATION:
2700 case OT_GOTO_WAYPOINT:
2701 this->v->current_order = *order;
2702 return UpdateOrderDest(this->v, order, 0, true);
2703 case OT_CONDITIONAL: {
2704 VehicleOrderID next = ProcessConditionalOrder(order, this->v);
2705 if (next != INVALID_VEH_ORDER_ID) {
2706 depth++;
2707 this->index = next;
2708 /* Don't increment next, so no break here. */
2709 continue;
2710 }
2711 break;
2712 }
2713 default:
2714 break;
2715 }
2716 /* Don't increment inside the while because otherwise conditional
2717 * orders can lead to an infinite loop. */
2718 ++this->index;
2719 depth++;
2720 } while (this->index != this->v->cur_real_order_index && depth < this->v->GetNumOrders());
2721
2722 return false;
2723 }
2724};
2725
2726/* choose a track */

Callers 1

ChooseTrainTrackFunction · 0.80

Calls 8

UpdateOrderDestFunction · 0.85
ProcessConditionalOrderFunction · 0.85
GetOrderMethod · 0.80
TestMethod · 0.80
GetDepotOrderTypeMethod · 0.80
NeedsServicingMethod · 0.80
GetNumOrdersMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected