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;
787 case OT_GOTO_DEPOT: {
795 if (ret.
Failed())
return ret;
806 if (ret.
Failed())
return ret;
833 case OT_GOTO_WAYPOINT: {
844 if (ret.
Failed())
return ret;
852 if (ret.
Failed())
return ret;
864 case OT_CONDITIONAL: {
904 const Order *prev = NULL;
911 FOR_VEHICLE_ORDERS(v, o) {
913 case OT_GOTO_STATION:
915 case OT_GOTO_WAYPOINT:
921 if (++n == sel_ord && prev != NULL)
break;
925 if (new_order.
IsType(OT_CONDITIONAL)) {
971 if (sel_ord <= u->cur_real_order_index) {
974 if (cur < u->GetNumOrders()) {
985 if (sel_ord <= u->cur_implicit_order_index) {
988 if (cur < u->GetNumOrders()) {
999 FOR_VEHICLE_ORDERS(v, order) {
1000 if (order->
IsType(OT_CONDITIONAL)) {
1002 if (order_id >= sel_ord) {
1005 if (order_id == cur_order_id) {
1050 if (ret.
Failed())
return ret;
1094 if (sel_ord < u->cur_real_order_index) {
1100 if (sel_ord < u->cur_implicit_order_index) {
1119 Order *order = NULL;
1120 FOR_VEHICLE_ORDERS(v, order) {
1121 if (order->
IsType(OT_CONDITIONAL)) {
1123 if (order_id >= sel_ord) {
1124 order_id =
max(order_id - 1, 0);
1126 if (order_id == cur_order_id) {
1156 if (ret.
Failed())
return ret;
1197 if (ret.
Failed())
return ret;
1205 if (moving_one == NULL)
return CMD_ERROR;
1255 FOR_VEHICLE_ORDERS(v, order) {
1256 if (order->
IsType(OT_CONDITIONAL)) {
1258 if (order_id == moving_order) {
1259 order_id = target_order;
1260 }
else if (order_id > moving_order && order_id <= target_order) {
1262 }
else if (order_id < moving_order && order_id >= target_order) {
1296 uint16 data =
GB(p2, 4, 11);
1304 if (ret.
Failed())
return ret;
1311 case OT_GOTO_STATION:
1319 case OT_GOTO_WAYPOINT:
1323 case OT_CONDITIONAL:
1332 default: NOT_REACHED();
1492 default: NOT_REACHED();
1533 for (
const Order *o = first; o != NULL; o = o->
next) {
1534 switch (o->GetType()) {
1535 case OT_GOTO_STATION:
1537 case OT_GOTO_WAYPOINT:
1569 if (ret.
Failed())
return ret;
1571 switch (
GB(p1, 30, 2)) {
1579 if (ret.
Failed())
return ret;
1591 FOR_VEHICLE_ORDERS(src, order) {
1638 if (ret.
Failed())
return ret;
1643 FOR_VEHICLE_ORDERS(src, order) {
1662 Order *first = NULL;
1671 FOR_VEHICLE_ORDERS(src, order) {
1672 *order_dst =
new Order();
1673 (*order_dst)->AssignOrder(*order);
1674 order_dst = &(*order_dst)->next;
1723 if (ret.
Failed())
return ret;
1747 if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() &
ODTFB_PART_OF_ORDERS)) {
1748 u->current_order.SetRefit(cargo);
1784 FOR_VEHICLE_ORDERS(v, order) {
1786 if (order->
IsType(OT_DUMMY)) {
1787 message = STR_NEWS_VEHICLE_HAS_VOID_ORDER;
1791 if (order->
IsType(OT_GOTO_STATION)) {
1796 message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
1798 (AircraftVehInfo(v->
engine_type)->subtype & AIR_FAST) &&
1803 message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY;
1813 message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
1818 if (n_st < 2 && message ==
INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
1858 FOR_VEHICLE_ORDERS(v, order) {
1864 if (ot == OT_IMPLICIT || (v->
type ==
VEH_AIRCRAFT && ot == OT_GOTO_DEPOT)) ot = OT_GOTO_STATION;
1869 if (order->
IsType(OT_IMPLICIT)) {
1870 order = order->
next;
1872 if (order != NULL)
goto restart;
1909 FOR_VEHICLE_ORDERS(
this, order) {
1910 if (order->
IsType(OT_GOTO_DEPOT))
return true;
1939 if (reset_order_indices) {
1956 return ispercent ?
Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) :
Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
1971 FOR_VEHICLE_ORDERS(v, order) {
1973 case OT_GOTO_STATION:
1975 case OT_GOTO_WAYPOINT:
2000 default: NOT_REACHED();
2014 bool skip_order =
false;
2026 default: NOT_REACHED();
2048 case OT_GOTO_STATION:
2054 assert(!pbs_look_ahead);
2063 DestinationID destination;
2068 if (pbs_look_ahead && reverse)
return false;
2088 if (pbs_look_ahead)
return false;
2100 case OT_GOTO_WAYPOINT:
2104 case OT_CONDITIONAL: {
2105 assert(!pbs_look_ahead);
2138 if (order != NULL && order->IsType(OT_IMPLICIT)) {
2143 if (order == NULL) {
2150 return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
2171 case OT_LEAVESTATION:
2206 if (order != NULL && order->
IsType(OT_IMPLICIT)) {
2215 extern void HandleMissingAircraftOrders(
Aircraft *v);
2261 bool is_dest_station = this->
IsType(OT_GOTO_STATION) && this->
dest == station;
2269 bool Order::CanLoadOrUnload()
const
2271 return (this->
IsType(OT_GOTO_STATION) || this->
IsType(OT_IMPLICIT)) &&