32 #include "table/strings.h"
39 assert_compile(
sizeof(DestinationID) >=
sizeof(
DepotID));
40 assert_compile(
sizeof(DestinationID) >=
sizeof(StationID));
50 if (CleaningPool())
return;
54 if (this->IsType(OT_GOTO_STATION) || this->IsType(OT_GOTO_WAYPOINT)) {
66 this->
type = OT_NOTHING;
78 this->
type = OT_GOTO_STATION;
80 this->
dest = destination;
93 this->
type = OT_GOTO_DEPOT;
97 this->
dest = destination;
107 this->
type = OT_GOTO_WAYPOINT;
109 this->
dest = destination;
118 this->
type = OT_LOADING;
119 if (!ordered) this->
flags = 0;
127 this->
type = OT_LEAVESTATION;
136 this->
type = OT_DUMMY;
146 this->
type = OT_CONDITIONAL;
157 this->
type = OT_IMPLICIT;
158 this->
dest = destination;
211 uint16 order = this->
GetType();
212 switch (this->
type) {
213 case OT_GOTO_STATION:
235 Order::Order(uint32 packed)
238 this->
flags =
GB(packed, 8, 8);
239 this->
dest =
GB(packed, 16, 16);
326 for (
Order *o = this->
first; o != NULL; o = next) {
331 if (keep_orderlist) {
348 if (index < 0)
return NULL;
352 while (order != NULL && index-- > 0) {
371 if (hops > this->
GetNumOrders() || next == NULL)
return NULL;
373 if (next->
IsType(OT_CONDITIONAL)) {
383 if (next->
IsType(OT_GOTO_DEPOT)) {
385 if (next->
IsRefit())
return next;
388 if (!next->CanLoadOrUnload()) {
412 if (next == NULL)
return INVALID_STATION;
418 assert(next != NULL);
426 while (next != NULL && next->
IsType(OT_CONDITIONAL)) {
432 if (advance == NULL || advance == first || skip_to == advance) {
433 next = (skip_to ==
first) ? NULL : skip_to;
434 }
else if (skip_to == NULL || skip_to == first) {
435 next = (advance ==
first) ? NULL : advance;
446 if (next == NULL || ((next->
IsType(OT_GOTO_STATION) || next->
IsType(OT_IMPLICIT)) &&
449 return INVALID_STATION;
463 if (this->
first == NULL) {
464 this->
first = new_order;
469 this->
first = new_order;
477 order->
next = new_order;
487 if (new_order->
IsType(OT_GOTO_STATION) || new_order->
IsType(OT_GOTO_WAYPOINT)) {
506 to_remove = this->
first;
510 to_remove = prev->
next;
533 moving_one = this->
first;
537 moving_one = one_before->
next;
538 one_before->
next = moving_one->
next;
544 this->
first = moving_one;
547 moving_one->
next = one_before->
next;
548 one_before->
next = moving_one;
570 if (v_shared == v)
return true;
596 if (o->IsType(OT_IMPLICIT))
continue;
597 if (!o->IsCompletelyTimetabled())
return false;
609 uint check_num_vehicles = 0;
610 Ticks check_timetable_duration = 0;
611 Ticks check_total_duration = 0;
613 DEBUG(misc, 6,
"Checking OrderList %hu for sanity...", this->
index);
617 if (!o->IsType(OT_IMPLICIT)) ++check_num_manual_orders;
618 check_timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
619 check_total_duration += o->GetWaitTime() + o->GetTravelTime();
627 ++check_num_vehicles;
628 assert(v->orders.list ==
this);
631 DEBUG(misc, 6,
"... detected %u orders (%u manual), %u vehicles, %i timetabled, %i total",
645 return o->
IsType(OT_GOTO_STATION) ||
673 case OT_GOTO_WAYPOINT:
674 case OT_GOTO_STATION:
699 if (cur->
IsType(OT_CONDITIONAL)) {
706 return max(dist1, dist2);
738 if (ret.
Failed())
return ret;
743 case OT_GOTO_STATION: {
749 if (ret.
Failed())
return ret;
786 case OT_GOTO_DEPOT: {
794 if (ret.
Failed())
return ret;
805 if (ret.
Failed())
return ret;
832 case OT_GOTO_WAYPOINT: {
843 if (ret.
Failed())
return ret;
851 if (ret.
Failed())
return ret;
863 case OT_CONDITIONAL: {
902 const Order *prev = NULL;
909 FOR_VEHICLE_ORDERS(v, o) {
911 case OT_GOTO_STATION:
913 case OT_GOTO_WAYPOINT:
919 if (++n == sel_ord && prev != NULL)
break;
923 if (new_order.
IsType(OT_CONDITIONAL)) {
969 if (sel_ord <= u->cur_real_order_index) {
972 if (cur < u->GetNumOrders()) {
983 if (sel_ord <= u->cur_implicit_order_index) {
986 if (cur < u->GetNumOrders()) {
997 FOR_VEHICLE_ORDERS(v, order) {
998 if (order->
IsType(OT_CONDITIONAL)) {
1000 if (order_id >= sel_ord) {
1003 if (order_id == cur_order_id) {
1048 if (ret.
Failed())
return ret;
1092 if (sel_ord < u->cur_real_order_index) {
1098 if (sel_ord < u->cur_implicit_order_index) {
1117 Order *order = NULL;
1118 FOR_VEHICLE_ORDERS(v, order) {
1119 if (order->
IsType(OT_CONDITIONAL)) {
1121 if (order_id >= sel_ord) {
1122 order_id =
max(order_id - 1, 0);
1124 if (order_id == cur_order_id) {
1154 if (ret.
Failed())
return ret;
1195 if (ret.
Failed())
return ret;
1203 if (moving_one == NULL)
return CMD_ERROR;
1253 FOR_VEHICLE_ORDERS(v, order) {
1254 if (order->
IsType(OT_CONDITIONAL)) {
1256 if (order_id == moving_order) {
1257 order_id = target_order;
1258 }
else if (order_id > moving_order && order_id <= target_order) {
1260 }
else if (order_id < moving_order && order_id >= target_order) {
1294 uint16 data =
GB(p2, 4, 11);
1302 if (ret.
Failed())
return ret;
1309 case OT_GOTO_STATION:
1317 case OT_GOTO_WAYPOINT:
1321 case OT_CONDITIONAL:
1330 default: NOT_REACHED();
1489 default: NOT_REACHED();
1530 for (
const Order *o = first; o != NULL; o = o->
next) {
1531 switch (o->GetType()) {
1532 case OT_GOTO_STATION:
1534 case OT_GOTO_WAYPOINT:
1566 if (ret.
Failed())
return ret;
1568 switch (
GB(p1, 30, 2)) {
1576 if (ret.
Failed())
return ret;
1588 FOR_VEHICLE_ORDERS(src, order) {
1635 if (ret.
Failed())
return ret;
1640 FOR_VEHICLE_ORDERS(src, order) {
1659 Order *first = NULL;
1668 FOR_VEHICLE_ORDERS(src, order) {
1669 *order_dst =
new Order();
1670 (*order_dst)->AssignOrder(*order);
1671 order_dst = &(*order_dst)->next;
1720 if (ret.
Failed())
return ret;
1744 if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() &
ODTFB_PART_OF_ORDERS)) {
1745 u->current_order.SetRefit(cargo);
1781 FOR_VEHICLE_ORDERS(v, order) {
1783 if (order->
IsType(OT_DUMMY)) {
1784 message = STR_NEWS_VEHICLE_HAS_VOID_ORDER;
1788 if (order->
IsType(OT_GOTO_STATION)) {
1793 message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
1795 (AircraftVehInfo(v->
engine_type)->subtype & AIR_FAST) &&
1800 message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY;
1810 message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
1815 if (n_st < 2 && message ==
INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
1855 FOR_VEHICLE_ORDERS(v, order) {
1861 if (ot == OT_IMPLICIT || (v->
type ==
VEH_AIRCRAFT && ot == OT_GOTO_DEPOT)) ot = OT_GOTO_STATION;
1866 if (order->
IsType(OT_IMPLICIT)) {
1867 order = order->
next;
1869 if (order != NULL)
goto restart;
1906 FOR_VEHICLE_ORDERS(
this, order) {
1907 if (order->
IsType(OT_GOTO_DEPOT))
return true;
1936 if (reset_order_indices) {
1953 return ispercent ?
Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) :
Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
1968 FOR_VEHICLE_ORDERS(v, order) {
1970 case OT_GOTO_STATION:
1972 case OT_GOTO_WAYPOINT:
1997 default: NOT_REACHED();
2011 bool skip_order =
false;
2023 default: NOT_REACHED();
2045 case OT_GOTO_STATION:
2051 assert(!pbs_look_ahead);
2060 DestinationID destination;
2065 if (pbs_look_ahead && reverse)
return false;
2085 if (pbs_look_ahead)
return false;
2097 case OT_GOTO_WAYPOINT:
2101 case OT_CONDITIONAL: {
2102 assert(!pbs_look_ahead);
2135 if (order != NULL && order->IsType(OT_IMPLICIT)) {
2140 if (order == NULL) {
2147 return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
2168 case OT_LEAVESTATION:
2203 if (order != NULL && order->
IsType(OT_IMPLICIT)) {
2212 extern void HandleMissingAircraftOrders(
Aircraft *v);
2258 bool is_dest_station = this->
IsType(OT_GOTO_STATION) && this->
dest == station;
2266 bool Order::CanLoadOrUnload()
const
2268 return (this->
IsType(OT_GOTO_STATION) || this->
IsType(OT_IMPLICIT)) &&