OpenTTD Source: src/order_cmd.cpp Source File

OpenTTD Source 1.11.0-RC1

order_cmd.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "debug.h"
12 #include "cmd_helper.h"
13 #include "command_func.h"
14 #include "company_func.h"
15 #include "news_func.h"
16 #include "strings_func.h"
17 #include "timetable.h"
18 #include "vehicle_func.h"
19 #include "depot_base.h"
20 #include "core/pool_func.hpp"
21 #include "core/random_func.hpp"
22 #include "aircraft.h"
23 #include "roadveh.h"
24 #include "station_base.h"
25 #include "waypoint_base.h"
26 #include "company_base.h"
27 #include "order_backup.h"
28 #include "cheat_type.h"
29
30 #include "table/strings.h"
31
32 #include "safeguards.h"
33
34 /* DestinationID must be at least as large as every these below, because it can
35 * be any of them
36 */
37 static_assert(sizeof(DestinationID) >= sizeof(DepotID));
38 static_assert(sizeof(DestinationID) >= sizeof(StationID));
39
40 OrderPool _order_pool("Order");
41 INSTANTIATE_POOL_METHODS(Order)
42 OrderListPool _orderlist_pool("OrderList");
43 INSTANTIATE_POOL_METHODS(OrderList)
44
45
46 Order::~Order()
47 {
48 if (CleaningPool()) return;
49
50 /* We can visit oil rigs and buoys that are not our own. They will be shown in
51 * the list of stations. So, we need to invalidate that window if needed. */
52 if (this->IsType(OT_GOTO_STATION) || this->IsType(OT_GOTO_WAYPOINT)) {
53 BaseStation *bs = BaseStation::GetIfValid(this->GetDestination());
54 if (bs != nullptr && bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
55 }
56 }
57
62 void Order::Free()
63 {
64 this->type = OT_NOTHING;
65 this->flags = 0;
66 this->dest = 0;
67 this->next = nullptr;
68 }
69
74 void Order::MakeGoToStation(StationID destination)
75 {
76 this->type = OT_GOTO_STATION;
77 this->flags = 0;
78 this->dest = destination;
79 }
80
89 void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo)
90 {
91 this->type = OT_GOTO_DEPOT;
92 this->SetDepotOrderType(order);
93 this->SetDepotActionType(action);
94 this->SetNonStopType(non_stop_type);
95 this->dest = destination;
96 this->SetRefit(cargo);
97 }
98
103 void Order::MakeGoToWaypoint(StationID destination)
104 {
105 this->type = OT_GOTO_WAYPOINT;
106 this->flags = 0;
107 this->dest = destination;
108 }
109
114 void Order::MakeLoading(bool ordered)
115 {
116 this->type = OT_LOADING;
117 if (!ordered) this->flags = 0;
118 }
119
123 void Order::MakeLeaveStation()
124 {
125 this->type = OT_LEAVESTATION;
126 this->flags = 0;
127 }
128
132 void Order::MakeDummy()
133 {
134 this->type = OT_DUMMY;
135 this->flags = 0;
136 }
137
142 void Order::MakeConditional(VehicleOrderID order)
143 {
144 this->type = OT_CONDITIONAL;
145 this->flags = order;
146 this->dest = 0;
147 }
148
153 void Order::MakeImplicit(StationID destination)
154 {
155 this->type = OT_IMPLICIT;
156 this->dest = destination;
157 }
158
164 void Order::SetRefit(CargoID cargo)
165 {
166 this->refit_cargo = cargo;
167 }
168
174 bool Order::Equals(const Order &other) const
175 {
176 /* In case of go to nearest depot orders we need "only" compare the flags
177 * with the other and not the nearest depot order bit or the actual
178 * destination because those get clear/filled in during the order
179 * evaluation. If we do not do this the order will continuously be seen as
180 * a different order and it will try to find a "nearest depot" every tick. */
181 if ((this->IsType(OT_GOTO_DEPOT) && this->type == other.type) &&
182 ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0 ||
183 (other.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0)) {
184 return this->GetDepotOrderType() == other.GetDepotOrderType() &&
185 (this->GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) == (other.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT);
186 }
187
188 return this->type == other.type && this->flags == other.flags && this->dest == other.dest;
189 }
190
197 uint32 Order::Pack() const
198 {
199 return this->dest << 16 | this->flags << 8 | this->type;
200 }
201
207 uint16 Order::MapOldOrder() const
208 {
209 uint16 order = this->GetType();
210 switch (this->type) {
211 case OT_GOTO_STATION:
212 if (this->GetUnloadType() & OUFB_UNLOAD) SetBit(order, 5);
213 if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
214 if (this->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) SetBit(order, 7);
215 order |= GB(this->GetDestination(), 0, 8) << 8;
216 break;
217 case OT_GOTO_DEPOT:
218 if (!(this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) SetBit(order, 6);
219 SetBit(order, 7);
220 order |= GB(this->GetDestination(), 0, 8) << 8;
221 break;
222 case OT_LOADING:
223 if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
224 break;
225 }
226 return order;
227 }
228
233 Order::Order(uint32 packed)
234 {
235 this->type = (OrderType)GB(packed, 0, 8);
236 this->flags = GB(packed, 8, 8);
237 this->dest = GB(packed, 16, 16);
238 this->next = nullptr;
239 this->refit_cargo = CT_NO_REFIT;
240 this->wait_time = 0;
241 this->travel_time = 0;
242 this->max_speed = UINT16_MAX;
243 }
244
250 void InvalidateVehicleOrder(const Vehicle *v, int data)
251 {
252 SetWindowDirty(WC_VEHICLE_VIEW, v->index);
253
254 if (data != 0) {
255 /* Calls SetDirty() too */
256 InvalidateWindowData(WC_VEHICLE_ORDERS, v->index, data);
257 InvalidateWindowData(WC_VEHICLE_TIMETABLE, v->index, data);
258 return;
259 }
260
261 SetWindowDirty(WC_VEHICLE_ORDERS, v->index);
262 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
263 }
264
272 void Order::AssignOrder(const Order &other)
273 {
274 this->type = other.type;
275 this->flags = other.flags;
276 this->dest = other.dest;
277
278 this->refit_cargo = other.refit_cargo;
279
280 this->wait_time = other.wait_time;
281 this->travel_time = other.travel_time;
282 this->max_speed = other.max_speed;
283 }
284
290 void OrderList::Initialize(Order *chain, Vehicle *v)
291 {
292 this->first = chain;
293 this->first_shared = v;
294
295 this->num_orders = 0;
296 this->num_manual_orders = 0;
297 this->num_vehicles = 1;
298 this->timetable_duration = 0;
299
300 for (Order *o = this->first; o != nullptr; o = o->next) {
301 ++this->num_orders;
302 if (!o->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
303 this->total_duration += o->GetWaitTime() + o->GetTravelTime();
304 }
305
306 this->RecalculateTimetableDuration();
307
308 for (Vehicle *u = this->first_shared->PreviousShared(); u != nullptr; u = u->PreviousShared()) {
309 ++this->num_vehicles;
310 this->first_shared = u;
311 }
312
313 for (const Vehicle *u = v->NextShared(); u != nullptr; u = u->NextShared()) ++this->num_vehicles;
314 }
315
320 void OrderList::RecalculateTimetableDuration()
321 {
322 this->timetable_duration = 0;
323 for (Order *o = this->first; o != nullptr; o = o->next) {
324 this->timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
325 }
326 }
327
333 void OrderList::FreeChain(bool keep_orderlist)
334 {
335 Order *next;
336 for (Order *o = this->first; o != nullptr; o = next) {
337 next = o->next;
338 delete o;
339 }
340
341 if (keep_orderlist) {
342 this->first = nullptr;
343 this->num_orders = 0;
344 this->num_manual_orders = 0;
345 this->timetable_duration = 0;
346 } else {
347 delete this;
348 }
349 }
350
356 Order *OrderList::GetOrderAt(int index) const
357 {
358 if (index < 0) return nullptr;
359
360 Order *order = this->first;
361
362 while (order != nullptr && index-- > 0) {
363 order = order->next;
364 }
365 return order;
366 }
367
379 const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops) const
380 {
381 if (hops > this->GetNumOrders() || next == nullptr) return nullptr;
382
383 if (next->IsType(OT_CONDITIONAL)) {
384 if (next->GetConditionVariable() != OCV_UNCONDITIONALLY) return next;
385
386 /* We can evaluate trivial conditions right away. They're conceptually
387 * the same as regular order progression. */
388 return this->GetNextDecisionNode(
389 this->GetOrderAt(next->GetConditionSkipToOrder()),
390 hops + 1);
391 }
392
393 if (next->IsType(OT_GOTO_DEPOT)) {
394 if (next->GetDepotActionType() == ODATFB_HALT) return nullptr;
395 if (next->IsRefit()) return next;
396 }
397
398 if (!next->CanLoadOrUnload()) {
399 return this->GetNextDecisionNode(this->GetNext(next), hops + 1);
400 }
401
402 return next;
403 }
404
414 StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order *first, uint hops) const
415 {
416
417 const Order *next = first;
418 if (first == nullptr) {
419 next = this->GetOrderAt(v->cur_implicit_order_index);
420 if (next == nullptr) {
421 next = this->GetFirstOrder();
422 if (next == nullptr) return INVALID_STATION;
423 } else {
424 /* GetNext never returns nullptr if there is a valid station in the list.
425 * As the given "next" is already valid and a station in the list, we
426 * don't have to check for nullptr here. */
427 next = this->GetNext(next);
428 assert(next != nullptr);
429 }
430 }
431
432 do {
433 next = this->GetNextDecisionNode(next, ++hops);
434
435 /* Resolve possibly nested conditionals by estimation. */
436 while (next != nullptr && next->IsType(OT_CONDITIONAL)) {
437 /* We return both options of conditional orders. */
438 const Order *skip_to = this->GetNextDecisionNode(
439 this->GetOrderAt(next->GetConditionSkipToOrder()), hops);
440 const Order *advance = this->GetNextDecisionNode(
441 this->GetNext(next), hops);
442 if (advance == nullptr || advance == first || skip_to == advance) {
443 next = (skip_to == first) ? nullptr : skip_to;
444 } else if (skip_to == nullptr || skip_to == first) {
445 next = (advance == first) ? nullptr : advance;
446 } else {
447 StationIDStack st1 = this->GetNextStoppingStation(v, skip_to, hops);
448 StationIDStack st2 = this->GetNextStoppingStation(v, advance, hops);
449 while (!st2.IsEmpty()) st1.Push(st2.Pop());
450 return st1;
451 }
452 ++hops;
453 }
454
455 /* Don't return a next stop if the vehicle has to unload everything. */
456 if (next == nullptr || ((next->IsType(OT_GOTO_STATION) || next->IsType(OT_IMPLICIT)) &&
457 next->GetDestination() == v->last_station_visited &&
458 (next->GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) != 0)) {
459 return INVALID_STATION;
460 }
461 } while (next->IsType(OT_GOTO_DEPOT) || next->GetDestination() == v->last_station_visited);
462
463 return next->GetDestination();
464 }
465
471 void OrderList::InsertOrderAt(Order *new_order, int index)
472 {
473 if (this->first == nullptr) {
474 this->first = new_order;
475 } else {
476 if (index == 0) {
477 /* Insert as first or only order */
478 new_order->next = this->first;
479 this->first = new_order;
480 } else if (index >= this->num_orders) {
481 /* index is after the last order, add it to the end */
482 this->GetLastOrder()->next = new_order;
483 } else {
484 /* Put the new order in between */
485 Order *order = this->GetOrderAt(index - 1);
486 new_order->next = order->next;
487 order->next = new_order;
488 }
489 }
490 ++this->num_orders;
491 if (!new_order->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
492 this->timetable_duration += new_order->GetTimetabledWait() + new_order->GetTimetabledTravel();
493 this->total_duration += new_order->GetWaitTime() + new_order->GetTravelTime();
494
495 /* We can visit oil rigs and buoys that are not our own. They will be shown in
496 * the list of stations. So, we need to invalidate that window if needed. */
497 if (new_order->IsType(OT_GOTO_STATION) || new_order->IsType(OT_GOTO_WAYPOINT)) {
498 BaseStation *bs = BaseStation::Get(new_order->GetDestination());
499 if (bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
500 }
501
502 }
503
504
509 void OrderList::DeleteOrderAt(int index)
510 {
511 if (index >= this->num_orders) return;
512
513 Order *to_remove;
514
515 if (index == 0) {
516 to_remove = this->first;
517 this->first = to_remove->next;
518 } else {
519 Order *prev = GetOrderAt(index - 1);
520 to_remove = prev->next;
521 prev->next = to_remove->next;
522 }
523 --this->num_orders;
524 if (!to_remove->IsType(OT_IMPLICIT)) --this->num_manual_orders;
525 this->timetable_duration -= (to_remove->GetTimetabledWait() + to_remove->GetTimetabledTravel());
526 this->total_duration -= (to_remove->GetWaitTime() + to_remove->GetTravelTime());
527 delete to_remove;
528 }
529
535 void OrderList::MoveOrder(int from, int to)
536 {
537 if (from >= this->num_orders || to >= this->num_orders || from == to) return;
538
539 Order *moving_one;
540
541 /* Take the moving order out of the pointer-chain */
542 if (from == 0) {
543 moving_one = this->first;
544 this->first = moving_one->next;
545 } else {
546 Order *one_before = GetOrderAt(from - 1);
547 moving_one = one_before->next;
548 one_before->next = moving_one->next;
549 }
550
551 /* Insert the moving_order again in the pointer-chain */
552 if (to == 0) {
553 moving_one->next = this->first;
554 this->first = moving_one;
555 } else {
556 Order *one_before = GetOrderAt(to - 1);
557 moving_one->next = one_before->next;
558 one_before->next = moving_one;
559 }
560 }
561
567 void OrderList::RemoveVehicle(Vehicle *v)
568 {
569 --this->num_vehicles;
570 if (v == this->first_shared) this->first_shared = v->NextShared();
571 }
572
577 bool OrderList::IsVehicleInSharedOrdersList(const Vehicle *v) const
578 {
579 for (const Vehicle *v_shared = this->first_shared; v_shared != nullptr; v_shared = v_shared->NextShared()) {
580 if (v_shared == v) return true;
581 }
582
583 return false;
584 }
585
591 int OrderList::GetPositionInSharedOrderList(const Vehicle *v) const
592 {
593 int count = 0;
594 for (const Vehicle *v_shared = v->PreviousShared(); v_shared != nullptr; v_shared = v_shared->PreviousShared()) count++;
595 return count;
596 }
597
602 bool OrderList::IsCompleteTimetable() const
603 {
604 for (Order *o = this->first; o != nullptr; o = o->next) {
605 /* Implicit orders are, by definition, not timetabled. */
606 if (o->IsType(OT_IMPLICIT)) continue;
607 if (!o->IsCompletelyTimetabled()) return false;
608 }
609 return true;
610 }
611
615 void OrderList::DebugCheckSanity() const
616 {
617 VehicleOrderID check_num_orders = 0;
618 VehicleOrderID check_num_manual_orders = 0;
619 uint check_num_vehicles = 0;
620 Ticks check_timetable_duration = 0;
621 Ticks check_total_duration = 0;
622
623 DEBUG(misc, 6, "Checking OrderList %hu for sanity...", this->index);
624
625 for (const Order *o = this->first; o != nullptr; o = o->next) {
626 ++check_num_orders;
627 if (!o->IsType(OT_IMPLICIT)) ++check_num_manual_orders;
628 check_timetable_duration += o->GetTimetabledWait() + o->GetTimetabledTravel();
629 check_total_duration += o->GetWaitTime() + o->GetTravelTime();
630 }
631 assert(this->num_orders == check_num_orders);
632 assert(this->num_manual_orders == check_num_manual_orders);
633 assert(this->timetable_duration == check_timetable_duration);
634 assert(this->total_duration == check_total_duration);
635
636 for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) {
637 ++check_num_vehicles;
638 assert(v->orders.list == this);
639 }
640 assert(this->num_vehicles == check_num_vehicles);
641 DEBUG(misc, 6, "... detected %u orders (%u manual), %u vehicles, %i timetabled, %i total",
642 (uint)this->num_orders, (uint)this->num_manual_orders,
643 this->num_vehicles, this->timetable_duration, this->total_duration);
644 }
645
653 static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
654 {
655 return o->IsType(OT_GOTO_STATION) ||
656 (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
657 }
658
665 static void DeleteOrderWarnings(const Vehicle *v)
666 {
667 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS);
668 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_VOID_ORDER);
669 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY);
670 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_INVALID_ENTRY);
671 DeleteVehicleNews(v->index, STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY);
672 }
673
680 TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
681 {
682 switch (this->GetType()) {
683 case OT_GOTO_WAYPOINT:
684 case OT_GOTO_STATION:
685 case OT_IMPLICIT:
686 if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination())->airport.tile;
687 return BaseStation::Get(this->GetDestination())->xy;
688
689 case OT_GOTO_DEPOT:
690 if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE;
691 return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy;
692
693 default:
694 return INVALID_TILE;
695 }
696 }
697
707 uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
708 {
709 if (cur->IsType(OT_CONDITIONAL)) {
710 if (conditional_depth > v->GetNumOrders()) return 0;
711
712 conditional_depth++;
713
714 int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
715 int dist2 = GetOrderDistance(prev, cur->next == nullptr ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
716 return std::max(dist1, dist2);
717 }
718
719 TileIndex prev_tile = prev->GetLocation(v, true);
720 TileIndex cur_tile = cur->GetLocation(v, true);
721 if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
722 return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
723 }
724
738 CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
739 {
740 VehicleID veh = GB(p1, 0, 20);
741 VehicleOrderID sel_ord = GB(p1, 20, 8);
742 Order new_order(p2);
743
744 Vehicle *v = Vehicle::GetIfValid(veh);
745 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
746
747 CommandCost ret = CheckOwnership(v->owner);
748 if (ret.Failed()) return ret;
749
750 /* Check if the inserted order is to the correct destination (owner, type),
751 * and has the correct flags if any */
752 switch (new_order.GetType()) {
753 case OT_GOTO_STATION: {
754 const Station *st = Station::GetIfValid(new_order.GetDestination());
755 if (st == nullptr) return CMD_ERROR;
756
757 if (st->owner != OWNER_NONE) {
758 CommandCost ret = CheckOwnership(st->owner);
759 if (ret.Failed()) return ret;
760 }
761
762 if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
763 for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
764 if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
765 }
766
767 /* Non stop only allowed for ground vehicles. */
768 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
769
770 /* Filter invalid load/unload types. */
771 switch (new_order.GetLoadType()) {
772 case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break;
773 default: return CMD_ERROR;
774 }
775 switch (new_order.GetUnloadType()) {
776 case OUF_UNLOAD_IF_POSSIBLE: case OUFB_UNLOAD: case OUFB_TRANSFER: case OUFB_NO_UNLOAD: break;
777 default: return CMD_ERROR;
778 }
779
780 /* Filter invalid stop locations */
781 switch (new_order.GetStopLocation()) {
782 case OSL_PLATFORM_NEAR_END:
783 case OSL_PLATFORM_MIDDLE:
784 if (v->type != VEH_TRAIN) return CMD_ERROR;
785 FALLTHROUGH;
786
787 case OSL_PLATFORM_FAR_END:
788 break;
789
790 default:
791 return CMD_ERROR;
792 }
793
794 break;
795 }
796
797 case OT_GOTO_DEPOT: {
798 if ((new_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) == 0) {
799 if (v->type == VEH_AIRCRAFT) {
800 const Station *st = Station::GetIfValid(new_order.GetDestination());
801
802 if (st == nullptr) return CMD_ERROR;
803
804 CommandCost ret = CheckOwnership(st->owner);
805 if (ret.Failed()) return ret;
806
807 if (!CanVehicleUseStation(v, st) || !st->airport.HasHangar()) {
808 return CMD_ERROR;
809 }
810 } else {
811 const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
812
813 if (dp == nullptr) return CMD_ERROR;
814
815 CommandCost ret = CheckOwnership(GetTileOwner(dp->xy));
816 if (ret.Failed()) return ret;
817
818 switch (v->type) {
819 case VEH_TRAIN:
820 if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
821 break;
822
823 case VEH_ROAD:
824 if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
825 break;
826
827 case VEH_SHIP:
828 if (!IsShipDepotTile(dp->xy)) return CMD_ERROR;
829 break;
830
831 default: return CMD_ERROR;
832 }
833 }
834 }
835
836 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
837 if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
838 if (new_order.GetDepotActionType() & ~(ODATFB_HALT | ODATFB_NEAREST_DEPOT)) return CMD_ERROR;
839 if ((new_order.GetDepotOrderType() & ODTFB_SERVICE) && (new_order.GetDepotActionType() & ODATFB_HALT)) return CMD_ERROR;
840 break;
841 }
842
843 case OT_GOTO_WAYPOINT: {
844 const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
845 if (wp == nullptr) return CMD_ERROR;
846
847 switch (v->type) {
848 default: return CMD_ERROR;
849
850 case VEH_TRAIN: {
851 if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
852
853 CommandCost ret = CheckOwnership(wp->owner);
854 if (ret.Failed()) return ret;
855 break;
856 }
857
858 case VEH_SHIP:
859 if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
860 if (wp->owner != OWNER_NONE) {
861 CommandCost ret = CheckOwnership(wp->owner);
862 if (ret.Failed()) return ret;
863 }
864 break;
865 }
866
867 /* Order flags can be any of the following for waypoints:
868 * [non-stop]
869 * non-stop orders (if any) are only valid for trains */
870 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
871 break;
872 }
873
874 case OT_CONDITIONAL: {
875 VehicleOrderID skip_to = new_order.GetConditionSkipToOrder();
876 if (skip_to != 0 && skip_to >= v->GetNumOrders()) return CMD_ERROR; // Always allow jumping to the first (even when there is no order).
877 if (new_order.GetConditionVariable() >= OCV_END) return CMD_ERROR;
878
879 OrderConditionComparator occ = new_order.GetConditionComparator();
880 if (occ >= OCC_END) return CMD_ERROR;
881 switch (new_order.GetConditionVariable()) {
882 case OCV_REQUIRES_SERVICE:
883 if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) return CMD_ERROR;
884 break;
885
886 case OCV_UNCONDITIONALLY:
887 if (occ != OCC_EQUALS) return CMD_ERROR;
888 if (new_order.GetConditionValue() != 0) return CMD_ERROR;
889 break;
890
891 case OCV_LOAD_PERCENTAGE:
892 case OCV_RELIABILITY:
893 if (new_order.GetConditionValue() > 100) return CMD_ERROR;
894 FALLTHROUGH;
895
896 default:
897 if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR;
898 break;
899 }
900 break;
901 }
902
903 default: return CMD_ERROR;
904 }
905
906 if (sel_ord > v->GetNumOrders()) return CMD_ERROR;
907
908 if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS);
909 if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
910 if (v->orders.list == nullptr && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
911
912 if (flags & DC_EXEC) {
913 Order *new_o = new Order();
914 new_o->AssignOrder(new_order);
915 InsertOrder(v, new_o, sel_ord);
916 }
917
918 return CommandCost();
919 }
920
927 void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
928 {
929 /* Create new order and link in list */
930 if (v->orders.list == nullptr) {
931 v->orders.list = new OrderList(new_o, v);
932 } else {
933 v->orders.list->InsertOrderAt(new_o, sel_ord);
934 }
935
936 Vehicle *u = v->FirstShared();
937 DeleteOrderWarnings(u);
938 for (; u != nullptr; u = u->NextShared()) {
939 assert(v->orders.list == u->orders.list);
940
941 /* If there is added an order before the current one, we need
942 * to update the selected order. We do not change implicit/real order indices though.
943 * If the new order is between the current implicit order and real order, the implicit order will
944 * later skip the inserted order. */
945 if (sel_ord <= u->cur_real_order_index) {
946 uint cur = u->cur_real_order_index + 1;
947 /* Check if we don't go out of bound */
948 if (cur < u->GetNumOrders()) {
949 u->cur_real_order_index = cur;
950 }
951 }
952 if (sel_ord == u->cur_implicit_order_index && u->IsGroundVehicle()) {
953 /* We are inserting an order just before the current implicit order.
954 * We do not know whether we will reach current implicit or the newly inserted order first.
955 * So, disable creation of implicit orders until we are on track again. */
956 uint16 &gv_flags = u->GetGroundVehicleFlags();
957 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
958 }
959 if (sel_ord <= u->cur_implicit_order_index) {
960 uint cur = u->cur_implicit_order_index + 1;
961 /* Check if we don't go out of bound */
962 if (cur < u->GetNumOrders()) {
963 u->cur_implicit_order_index = cur;
964 }
965 }
966 /* Update any possible open window of the vehicle */
967 InvalidateVehicleOrder(u, INVALID_VEH_ORDER_ID | (sel_ord << 8));
968 }
969
970 /* As we insert an order, the order to skip to will be 'wrong'. */
971 VehicleOrderID cur_order_id = 0;
972 for (Order *order : v->Orders()) {
973 if (order->IsType(OT_CONDITIONAL)) {
974 VehicleOrderID order_id = order->GetConditionSkipToOrder();
975 if (order_id >= sel_ord) {
976 order->SetConditionSkipToOrder(order_id + 1);
977 }
978 if (order_id == cur_order_id) {
979 order->SetConditionSkipToOrder((order_id + 1) % v->GetNumOrders());
980 }
981 }
982 cur_order_id++;
983 }
984
985 /* Make sure to rebuild the whole list */
986 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
987 }
988
994 static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
995 {
996 if (flags & DC_EXEC) {
997 DeleteVehicleOrders(dst);
998 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
999 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
1000 }
1001 return CommandCost();
1002 }
1003
1013 CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1014 {
1015 VehicleID veh_id = GB(p1, 0, 20);
1016 VehicleOrderID sel_ord = GB(p2, 0, 8);
1017
1018 Vehicle *v = Vehicle::GetIfValid(veh_id);
1019
1020 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1021
1022 CommandCost ret = CheckOwnership(v->owner);
1023 if (ret.Failed()) return ret;
1024
1025 /* If we did not select an order, we maybe want to de-clone the orders */
1026 if (sel_ord >= v->GetNumOrders()) return DecloneOrder(v, flags);
1027
1028 if (v->GetOrder(sel_ord) == nullptr) return CMD_ERROR;
1029
1030 if (flags & DC_EXEC) DeleteOrder(v, sel_ord);
1031 return CommandCost();
1032 }
1033
1038 static void CancelLoadingDueToDeletedOrder(Vehicle *v)
1039 {
1040 assert(v->current_order.IsType(OT_LOADING));
1041 /* NON-stop flag is misused to see if a train is in a station that is
1042 * on his order list or not */
1043 v->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
1044 /* When full loading, "cancel" that order so the vehicle doesn't
1045 * stay indefinitely at this station anymore. */
1046 if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) v->current_order.SetLoadType(OLF_LOAD_IF_POSSIBLE);
1047 }
1048
1054 void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
1055 {
1056 v->orders.list->DeleteOrderAt(sel_ord);
1057
1058 Vehicle *u = v->FirstShared();
1059 DeleteOrderWarnings(u);
1060 for (; u != nullptr; u = u->NextShared()) {
1061 assert(v->orders.list == u->orders.list);
1062
1063 if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) {
1064 CancelLoadingDueToDeletedOrder(u);
1065 }
1066
1067 if (sel_ord < u->cur_real_order_index) {
1068 u->cur_real_order_index--;
1069 } else if (sel_ord == u->cur_real_order_index) {
1070 u->UpdateRealOrderIndex();
1071 }
1072
1073 if (sel_ord < u->cur_implicit_order_index) {
1074 u->cur_implicit_order_index--;
1075 } else if (sel_ord == u->cur_implicit_order_index) {
1076 /* Make sure the index is valid */
1077 if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
1078
1079 /* Skip non-implicit orders for the implicit-order-index (e.g. if the current implicit order was deleted */
1080 while (u->cur_implicit_order_index != u->cur_real_order_index && !u->GetOrder(u->cur_implicit_order_index)->IsType(OT_IMPLICIT)) {
1081 u->cur_implicit_order_index++;
1082 if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
1083 }
1084 }
1085
1086 /* Update any possible open window of the vehicle */
1087 InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8));
1088 }
1089
1090 /* As we delete an order, the order to skip to will be 'wrong'. */
1091 VehicleOrderID cur_order_id = 0;
1092 for (Order *order : v->Orders()) {
1093 if (order->IsType(OT_CONDITIONAL)) {
1094 VehicleOrderID order_id = order->GetConditionSkipToOrder();
1095 if (order_id >= sel_ord) {
1096 order_id = std::max(order_id - 1, 0);
1097 }
1098 if (order_id == cur_order_id) {
1099 order_id = (order_id + 1) % v->GetNumOrders();
1100 }
1101 order->SetConditionSkipToOrder(order_id);
1102 }
1103 cur_order_id++;
1104 }
1105
1106 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
1107 }
1108
1118 CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1119 {
1120 VehicleID veh_id = GB(p1, 0, 20);
1121 VehicleOrderID sel_ord = GB(p2, 0, 8);
1122
1123 Vehicle *v = Vehicle::GetIfValid(veh_id);
1124
1125 if (v == nullptr || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
1126
1127 CommandCost ret = CheckOwnership(v->owner);
1128 if (ret.Failed()) return ret;
1129
1130 if (flags & DC_EXEC) {
1131 if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
1132
1133 v->cur_implicit_order_index = v->cur_real_order_index = sel_ord;
1134 v->UpdateRealOrderIndex();
1135
1136 InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
1137 }
1138
1139 /* We have an aircraft/ship, they have a mini-schedule, so update them all */
1140 if (v->type == VEH_AIRCRAFT) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
1141 if (v->type == VEH_SHIP) SetWindowClassesDirty(WC_SHIPS_LIST);
1142
1143 return CommandCost();
1144 }
1145
1159 CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1160 {
1161 VehicleID veh = GB(p1, 0, 20);
1162 VehicleOrderID moving_order = GB(p2, 0, 16);
1163 VehicleOrderID target_order = GB(p2, 16, 16);
1164
1165 Vehicle *v = Vehicle::GetIfValid(veh);
1166 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1167
1168 CommandCost ret = CheckOwnership(v->owner);
1169 if (ret.Failed()) return ret;
1170
1171 /* Don't make senseless movements */
1172 if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
1173 moving_order == target_order || v->GetNumOrders() <= 1) return CMD_ERROR;
1174
1175 Order *moving_one = v->GetOrder(moving_order);
1176 /* Don't move an empty order */
1177 if (moving_one == nullptr) return CMD_ERROR;
1178
1179 if (flags & DC_EXEC) {
1180 v->orders.list->MoveOrder(moving_order, target_order);
1181
1182 /* Update shared list */
1183 Vehicle *u = v->FirstShared();
1184
1185 DeleteOrderWarnings(u);
1186
1187 for (; u != nullptr; u = u->NextShared()) {
1188 /* Update the current order.
1189 * There are multiple ways to move orders, which result in cur_implicit_order_index
1190 * and cur_real_order_index to not longer make any sense. E.g. moving another
1191 * real order between them.
1192 *
1193 * Basically one could choose to preserve either of them, but not both.
1194 * While both ways are suitable in this or that case from a human point of view, neither
1195 * of them makes really sense.
1196 * However, from an AI point of view, preserving cur_real_order_index is the most
1197 * predictable and transparent behaviour.
1198 *
1199 * With that decision it basically does not matter what we do to cur_implicit_order_index.
1200 * If we change orders between the implicit- and real-index, the implicit orders are mostly likely
1201 * completely out-dated anyway. So, keep it simple and just keep cur_implicit_order_index as well.
1202 * The worst which can happen is that a lot of implicit orders are removed when reaching current_order.
1203 */
1204 if (u->cur_real_order_index == moving_order) {
1205 u->cur_real_order_index = target_order;
1206 } else if (u->cur_real_order_index > moving_order && u->cur_real_order_index <= target_order) {
1207 u->cur_real_order_index--;
1208 } else if (u->cur_real_order_index < moving_order && u->cur_real_order_index >= target_order) {
1209 u->cur_real_order_index++;
1210 }
1211
1212 if (u->cur_implicit_order_index == moving_order) {
1213 u->cur_implicit_order_index = target_order;
1214 } else if (u->cur_implicit_order_index > moving_order && u->cur_implicit_order_index <= target_order) {
1215 u->cur_implicit_order_index--;
1216 } else if (u->cur_implicit_order_index < moving_order && u->cur_implicit_order_index >= target_order) {
1217 u->cur_implicit_order_index++;
1218 }
1219
1220 assert(v->orders.list == u->orders.list);
1221 /* Update any possible open window of the vehicle */
1222 InvalidateVehicleOrder(u, moving_order | (target_order << 8));
1223 }
1224
1225 /* As we move an order, the order to skip to will be 'wrong'. */
1226 for (Order *order : v->Orders()) {
1227 if (order->IsType(OT_CONDITIONAL)) {
1228 VehicleOrderID order_id = order->GetConditionSkipToOrder();
1229 if (order_id == moving_order) {
1230 order_id = target_order;
1231 } else if (order_id > moving_order && order_id <= target_order) {
1232 order_id--;
1233 } else if (order_id < moving_order && order_id >= target_order) {
1234 order_id++;
1235 }
1236 order->SetConditionSkipToOrder(order_id);
1237 }
1238 }
1239
1240 /* Make sure to rebuild the whole list */
1241 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
1242 }
1243
1244 return CommandCost();
1245 }
1246
1262 CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1263 {
1264 VehicleOrderID sel_ord = GB(p1, 20, 8);
1265 VehicleID veh = GB(p1, 0, 20);
1266 ModifyOrderFlags mof = Extract<ModifyOrderFlags, 0, 4>(p2);
1267 uint16 data = GB(p2, 4, 11);
1268
1269 if (mof >= MOF_END) return CMD_ERROR;
1270
1271 Vehicle *v = Vehicle::GetIfValid(veh);
1272 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1273
1274 CommandCost ret = CheckOwnership(v->owner);
1275 if (ret.Failed()) return ret;
1276
1277 /* Is it a valid order? */
1278 if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
1279
1280 Order *order = v->GetOrder(sel_ord);
1281 switch (order->GetType()) {
1282 case OT_GOTO_STATION:
1283 if (mof != MOF_NON_STOP && mof != MOF_STOP_LOCATION && mof != MOF_UNLOAD && mof != MOF_LOAD) return CMD_ERROR;
1284 break;
1285
1286 case OT_GOTO_DEPOT:
1287 if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR;
1288 break;
1289
1290 case OT_GOTO_WAYPOINT:
1291 if (mof != MOF_NON_STOP) return CMD_ERROR;
1292 break;
1293
1294 case OT_CONDITIONAL:
1295 if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE && mof != MOF_COND_DESTINATION) return CMD_ERROR;
1296 break;
1297
1298 default:
1299 return CMD_ERROR;
1300 }
1301
1302 switch (mof) {
1303 default: NOT_REACHED();
1304
1305 case MOF_NON_STOP:
1306 if (!v->IsGroundVehicle()) return CMD_ERROR;
1307 if (data >= ONSF_END) return CMD_ERROR;
1308 if (data == order->GetNonStopType()) return CMD_ERROR;
1309 break;
1310
1311 case MOF_STOP_LOCATION:
1312 if (v->type != VEH_TRAIN) return CMD_ERROR;
1313 if (data >= OSL_END) return CMD_ERROR;
1314 break;
1315
1316 case MOF_UNLOAD:
1317 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CMD_ERROR;
1318 if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER | OUFB_NO_UNLOAD)) != 0) return CMD_ERROR;
1319 /* Unload and no-unload are mutual exclusive and so are transfer and no unload. */
1320 if (data != 0 && ((data & (OUFB_UNLOAD | OUFB_TRANSFER)) != 0) == ((data & OUFB_NO_UNLOAD) != 0)) return CMD_ERROR;
1321 if (data == order->GetUnloadType()) return CMD_ERROR;
1322 break;
1323
1324 case MOF_LOAD:
1325 if (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) return CMD_ERROR;
1326 if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR;
1327 if (data == order->GetLoadType()) return CMD_ERROR;
1328 break;
1329
1330 case MOF_DEPOT_ACTION:
1331 if (data >= DA_END) return CMD_ERROR;
1332 break;
1333
1334 case MOF_COND_VARIABLE:
1335 if (data >= OCV_END) return CMD_ERROR;
1336 break;
1337
1338 case MOF_COND_COMPARATOR:
1339 if (data >= OCC_END) return CMD_ERROR;
1340 switch (order->GetConditionVariable()) {
1341 case OCV_UNCONDITIONALLY: return CMD_ERROR;
1342
1343 case OCV_REQUIRES_SERVICE:
1344 if (data != OCC_IS_TRUE && data != OCC_IS_FALSE) return CMD_ERROR;
1345 break;
1346
1347 default:
1348 if (data == OCC_IS_TRUE || data == OCC_IS_FALSE) return CMD_ERROR;
1349 break;
1350 }
1351 break;
1352
1353 case MOF_COND_VALUE:
1354 switch (order->GetConditionVariable()) {
1355 case OCV_UNCONDITIONALLY:
1356 case OCV_REQUIRES_SERVICE:
1357 return CMD_ERROR;
1358
1359 case OCV_LOAD_PERCENTAGE:
1360 case OCV_RELIABILITY:
1361 if (data > 100) return CMD_ERROR;
1362 break;
1363
1364 default:
1365 if (data > 2047) return CMD_ERROR;
1366 break;
1367 }
1368 break;
1369
1370 case MOF_COND_DESTINATION:
1371 if (data >= v->GetNumOrders()) return CMD_ERROR;
1372 break;
1373 }
1374
1375 if (flags & DC_EXEC) {
1376 switch (mof) {
1377 case MOF_NON_STOP:
1378 order->SetNonStopType((OrderNonStopFlags)data);
1379 if (data & ONSF_NO_STOP_AT_DESTINATION_STATION) {
1380 order->SetRefit(CT_NO_REFIT);
1381 order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
1382 order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
1383 }
1384 break;
1385
1386 case MOF_STOP_LOCATION:
1387 order->SetStopLocation((OrderStopLocation)data);
1388 break;
1389
1390 case MOF_UNLOAD:
1391 order->SetUnloadType((OrderUnloadFlags)data);
1392 break;
1393
1394 case MOF_LOAD:
1395 order->SetLoadType((OrderLoadFlags)data);
1396 if (data & OLFB_NO_LOAD) order->SetRefit(CT_NO_REFIT);
1397 break;
1398
1399 case MOF_DEPOT_ACTION: {
1400 switch (data) {
1401 case DA_ALWAYS_GO:
1402 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
1403 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
1404 break;
1405
1406 case DA_SERVICE:
1407 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
1408 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
1409 order->SetRefit(CT_NO_REFIT);
1410 break;
1411
1412 case DA_STOP:
1413 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
1414 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
1415 order->SetRefit(CT_NO_REFIT);
1416 break;
1417
1418 default:
1419 NOT_REACHED();
1420 }
1421 break;
1422 }
1423
1424 case MOF_COND_VARIABLE: {
1425 order->SetConditionVariable((OrderConditionVariable)data);
1426
1427 OrderConditionComparator occ = order->GetConditionComparator();
1428 switch (order->GetConditionVariable()) {
1429 case OCV_UNCONDITIONALLY:
1430 order->SetConditionComparator(OCC_EQUALS);
1431 order->SetConditionValue(0);
1432 break;
1433
1434 case OCV_REQUIRES_SERVICE:
1435 if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE);
1436 order->SetConditionValue(0);
1437 break;
1438
1439 case OCV_LOAD_PERCENTAGE:
1440 case OCV_RELIABILITY:
1441 if (order->GetConditionValue() > 100) order->SetConditionValue(100);
1442 FALLTHROUGH;
1443
1444 default:
1445 if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS);
1446 break;
1447 }
1448 break;
1449 }
1450
1451 case MOF_COND_COMPARATOR:
1452 order->SetConditionComparator((OrderConditionComparator)data);
1453 break;
1454
1455 case MOF_COND_VALUE:
1456 order->SetConditionValue(data);
1457 break;
1458
1459 case MOF_COND_DESTINATION:
1460 order->SetConditionSkipToOrder(data);
1461 break;
1462
1463 default: NOT_REACHED();
1464 }
1465
1466 /* Update the windows and full load flags, also for vehicles that share the same order list */
1467 Vehicle *u = v->FirstShared();
1468 DeleteOrderWarnings(u);
1469 for (; u != nullptr; u = u->NextShared()) {
1470 /* Toggle u->current_order "Full load" flag if it changed.
1471 * However, as the same flag is used for depot orders, check
1472 * whether we are not going to a depot as there are three
1473 * cases where the full load flag can be active and only
1474 * one case where the flag is used for depot orders. In the
1475 * other cases for the OrderType the flags are not used,
1476 * so do not care and those orders should not be active
1477 * when this function is called.
1478 */
1479 if (sel_ord == u->cur_real_order_index &&
1480 (u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) &&
1481 u->current_order.GetLoadType() != order->GetLoadType()) {
1482 u->current_order.SetLoadType(order->GetLoadType());
1483 }
1484 InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
1485 }
1486 }
1487
1488 return CommandCost();
1489 }
1490
1498 static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order, const Order *first)
1499 {
1500 if (first == nullptr || v_new->acache.cached_max_range == 0) return true;
1501
1502 /* Iterate over all orders to check the distance between all
1503 * 'goto' orders and their respective next order (of any type). */
1504 for (const Order *o = first; o != nullptr; o = o->next) {
1505 switch (o->GetType()) {
1506 case OT_GOTO_STATION:
1507 case OT_GOTO_DEPOT:
1508 case OT_GOTO_WAYPOINT:
1509 /* If we don't have a next order, we've reached the end and must check the first order instead. */
1510 if (GetOrderDistance(o, o->next != nullptr ? o->next : first, v_order) > v_new->acache.cached_max_range_sqr) return false;
1511 break;
1512
1513 default: break;
1514 }
1515 }
1516
1517 return true;
1518 }
1519
1531 CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1532 {
1533 VehicleID veh_src = GB(p2, 0, 20);
1534 VehicleID veh_dst = GB(p1, 0, 20);
1535
1536 Vehicle *dst = Vehicle::GetIfValid(veh_dst);
1537 if (dst == nullptr || !dst->IsPrimaryVehicle()) return CMD_ERROR;
1538
1539 CommandCost ret = CheckOwnership(dst->owner);
1540 if (ret.Failed()) return ret;
1541
1542 switch (GB(p1, 30, 2)) {
1543 case CO_SHARE: {
1544 Vehicle *src = Vehicle::GetIfValid(veh_src);
1545
1546 /* Sanity checks */
1547 if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
1548
1549 CommandCost ret = CheckOwnership(src->owner);
1550 if (ret.Failed()) return ret;
1551
1552 /* Trucks can't share orders with busses (and visa versa) */
1553 if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
1554 return CMD_ERROR;
1555 }
1556
1557 /* Is the vehicle already in the shared list? */
1558 if (src->FirstShared() == dst->FirstShared()) return CMD_ERROR;
1559
1560 for (const Order *order : src->Orders()) {
1561 if (!OrderGoesToStation(dst, order)) continue;
1562
1563 /* Allow copying unreachable destinations if they were already unreachable for the source.
1564 * This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
1565 * are temporarily invalid due to reconstruction. */
1566 const Station *st = Station::Get(order->GetDestination());
1567 if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
1568 return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
1569 }
1570 }
1571
1572 /* Check for aircraft range limits. */
1573 if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
1574 return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
1575 }
1576
1577 if (src->orders.list == nullptr && !OrderList::CanAllocateItem()) {
1578 return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
1579 }
1580
1581 if (flags & DC_EXEC) {
1582 /* If the destination vehicle had a OrderList, destroy it.
1583 * We only reset the order indices, if the new orders are obviously different.
1584 * (We mainly do this to keep the order indices valid and in range.) */
1585 DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders());
1586
1587 dst->orders.list = src->orders.list;
1588
1589 /* Link this vehicle in the shared-list */
1590 dst->AddToShared(src);
1591
1592 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
1593 InvalidateVehicleOrder(src, VIWD_MODIFY_ORDERS);
1594
1595 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
1596 }
1597 break;
1598 }
1599
1600 case CO_COPY: {
1601 Vehicle *src = Vehicle::GetIfValid(veh_src);
1602
1603 /* Sanity checks */
1604 if (src == nullptr || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
1605
1606 CommandCost ret = CheckOwnership(src->owner);
1607 if (ret.Failed()) return ret;
1608
1609 /* Trucks can't copy all the orders from busses (and visa versa),
1610 * and neither can helicopters and aircraft. */
1611 for (const Order *order : src->Orders()) {
1612 if (OrderGoesToStation(dst, order) &&
1613 !CanVehicleUseStation(dst, Station::Get(order->GetDestination()))) {
1614 return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
1615 }
1616 }
1617
1618 /* Check for aircraft range limits. */
1619 if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
1620 return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
1621 }
1622
1623 /* make sure there are orders available */
1624 if (!Order::CanAllocateItem(src->GetNumOrders()) || !OrderList::CanAllocateItem()) {
1625 return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
1626 }
1627
1628 if (flags & DC_EXEC) {
1629 Order *first = nullptr;
1630 Order **order_dst;
1631
1632 /* If the destination vehicle had an order list, destroy the chain but keep the OrderList.
1633 * We only reset the order indices, if the new orders are obviously different.
1634 * (We mainly do this to keep the order indices valid and in range.) */
1635 DeleteVehicleOrders(dst, true, dst->GetNumOrders() != src->GetNumOrders());
1636
1637 order_dst = &first;
1638 for (const Order *order : src->Orders()) {
1639 *order_dst = new Order();
1640 (*order_dst)->AssignOrder(*order);
1641 order_dst = &(*order_dst)->next;
1642 }
1643 if (dst->orders.list == nullptr) {
1644 dst->orders.list = new OrderList(first, dst);
1645 } else {
1646 assert(dst->orders.list->GetFirstOrder() == nullptr);
1647 assert(!dst->orders.list->IsShared());
1648 delete dst->orders.list;
1649 assert(OrderList::CanAllocateItem());
1650 dst->orders.list = new OrderList(first, dst);
1651 }
1652
1653 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
1654
1655 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
1656 }
1657 break;
1658 }
1659
1660 case CO_UNSHARE: return DecloneOrder(dst, flags);
1661 default: return CMD_ERROR;
1662 }
1663
1664 return CommandCost();
1665 }
1666
1678 CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1679 {
1680 VehicleID veh = GB(p1, 0, 20);
1681 VehicleOrderID order_number = GB(p2, 16, 8);
1682 CargoID cargo = GB(p2, 0, 8);
1683
1684 if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
1685
1686 const Vehicle *v = Vehicle::GetIfValid(veh);
1687 if (v == nullptr || !v->IsPrimaryVehicle()) return CMD_ERROR;
1688
1689 CommandCost ret = CheckOwnership(v->owner);
1690 if (ret.Failed()) return ret;
1691
1692 Order *order = v->GetOrder(order_number);
1693 if (order == nullptr) return CMD_ERROR;
1694
1695 /* Automatic refit cargo is only supported for goto station orders. */
1696 if (cargo == CT_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
1697
1698 if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
1699
1700 if (flags & DC_EXEC) {
1701 order->SetRefit(cargo);
1702
1703 /* Make the depot order an 'always go' order. */
1704 if (cargo != CT_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
1705 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
1706 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
1707 }
1708
1709 for (Vehicle *u = v->FirstShared(); u != nullptr; u = u->NextShared()) {
1710 /* Update any possible open window of the vehicle */
1711 InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
1712
1713 /* If the vehicle already got the current depot set as current order, then update current order as well */
1714 if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
1715 u->current_order.SetRefit(cargo);
1716 }
1717 }
1718 }
1719
1720 return CommandCost();
1721 }
1722
1723
1729 void CheckOrders(const Vehicle *v)
1730 {
1731 /* Does the user wants us to check things? */
1732 if (_settings_client.gui.order_review_system == 0) return;
1733
1734 /* Do nothing for crashed vehicles */
1735 if (v->vehstatus & VS_CRASHED) return;
1736
1737 /* Do nothing for stopped vehicles if setting is '1' */
1738 if (_settings_client.gui.order_review_system == 1 && (v->vehstatus & VS_STOPPED)) return;
1739
1740 /* do nothing we we're not the first vehicle in a share-chain */
1741 if (v->FirstShared() != v) return;
1742
1743 /* Only check every 20 days, so that we don't flood the message log */
1744 if (v->owner == _local_company && v->day_counter % 20 == 0) {
1745 StringID message = INVALID_STRING_ID;
1746
1747 /* Check the order list */
1748 int n_st = 0;
1749
1750 for (const Order *order : v->Orders()) {
1751 /* Dummy order? */
1752 if (order->IsType(OT_DUMMY)) {
1753 message = STR_NEWS_VEHICLE_HAS_VOID_ORDER;
1754 break;
1755 }
1756 /* Does station have a load-bay for this vehicle? */
1757 if (order->IsType(OT_GOTO_STATION)) {
1758 const Station *st = Station::Get(order->GetDestination());
1759
1760 n_st++;
1761 if (!CanVehicleUseStation(v, st)) {
1762 message = STR_NEWS_VEHICLE_HAS_INVALID_ENTRY;
1763 } else if (v->type == VEH_AIRCRAFT &&
1764 (AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
1765 (st->airport.GetFTA()->flags & AirportFTAClass::SHORT_STRIP) &&
1766 !_cheats.no_jetcrash.value &&
1767 message == INVALID_STRING_ID) {
1768 message = STR_NEWS_PLANE_USES_TOO_SHORT_RUNWAY;
1769 }
1770 }
1771 }
1772
1773 /* Check if the last and the first order are the same */
1774 if (v->GetNumOrders() > 1) {
1775 const Order *last = v->GetLastOrder();
1776
1777 if (v->orders.list->GetFirstOrder()->Equals(*last)) {
1778 message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
1779 }
1780 }
1781
1782 /* Do we only have 1 station in our order list? */
1783 if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
1784
1785 #ifndef NDEBUG
1786 if (v->orders.list != nullptr) v->orders.list->DebugCheckSanity();
1787 #endif
1788
1789 /* We don't have a problem */
1790 if (message == INVALID_STRING_ID) return;
1791
1792 SetDParam(0, v->index);
1793 AddVehicleAdviceNewsItem(message, v->index);
1794 }
1795 }
1796
1805 void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
1806 {
1807 /* Aircraft have StationIDs for depot orders and never use DepotIDs
1808 * This fact is handled specially below
1809 */
1810
1811 /* Go through all vehicles */
1812 for (Vehicle *v : Vehicle::Iterate()) {
1813 Order *order;
1814
1815 order = &v->current_order;
1816 if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) && !hangar ? OT_GOTO_STATION : order->GetType()) == type &&
1817 (!hangar || v->type == VEH_AIRCRAFT) && v->current_order.GetDestination() == destination) {
1818 order->MakeDummy();
1819 SetWindowDirty(WC_VEHICLE_VIEW, v->index);
1820 }
1821
1822 /* Clear the order from the order-list */
1823 int id = -1;
1824 for (Order *order : v->Orders()) {
1825 id++;
1826 restart:
1827
1828 OrderType ot = order->GetType();
1829 if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
1830 if (ot == OT_GOTO_DEPOT && hangar && v->type != VEH_AIRCRAFT) continue; // Not an aircraft? Can't have a hangar order.
1831 if (ot == OT_IMPLICIT || (v->type == VEH_AIRCRAFT && ot == OT_GOTO_DEPOT && !hangar)) ot = OT_GOTO_STATION;
1832 if (ot == type && order->GetDestination() == destination) {
1833 /* We want to clear implicit orders, but we don't want to make them
1834 * dummy orders. They should just vanish. Also check the actual order
1835 * type as ot is currently OT_GOTO_STATION. */
1836 if (order->IsType(OT_IMPLICIT)) {
1837 order = order->next; // DeleteOrder() invalidates current order
1838 DeleteOrder(v, id);
1839 if (order != nullptr) goto restart;
1840 break;
1841 }
1842
1843 /* Clear wait time */
1844 v->orders.list->UpdateTotalDuration(-order->GetWaitTime());
1845 if (order->IsWaitTimetabled()) {
1846 v->orders.list->UpdateTimetableDuration(-order->GetTimetabledWait());
1847 order->SetWaitTimetabled(false);
1848 }
1849 order->SetWaitTime(0);
1850
1851 /* Clear order, preserving travel time */
1852 bool travel_timetabled = order->IsTravelTimetabled();
1853 order->MakeDummy();
1854 order->SetTravelTimetabled(travel_timetabled);
1855
1856 for (const Vehicle *w = v->FirstShared(); w != nullptr; w = w->NextShared()) {
1857 /* In GUI, simulate by removing the order and adding it back */
1858 InvalidateVehicleOrder(w, id | (INVALID_VEH_ORDER_ID << 8));
1859 InvalidateVehicleOrder(w, (INVALID_VEH_ORDER_ID << 8) | id);
1860 }
1861 }
1862 }
1863 }
1864
1865 OrderBackup::RemoveOrder(type, destination, hangar);
1866 }
1867
1872 bool Vehicle::HasDepotOrder() const
1873 {
1874 for (const Order *order : this->Orders()) {
1875 if (order->IsType(OT_GOTO_DEPOT)) return true;
1876 }
1877
1878 return false;
1879 }
1880
1890 void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
1891 {
1892 DeleteOrderWarnings(v);
1893
1894 if (v->IsOrderListShared()) {
1895 /* Remove ourself from the shared order list. */
1896 v->RemoveFromShared();
1897 v->orders.list = nullptr;
1898 } else if (v->orders.list != nullptr) {
1899 /* Remove the orders */
1900 v->orders.list->FreeChain(keep_orderlist);
1901 if (!keep_orderlist) v->orders.list = nullptr;
1902 }
1903
1904 if (reset_order_indices) {
1905 v->cur_implicit_order_index = v->cur_real_order_index = 0;
1906 if (v->current_order.IsType(OT_LOADING)) {
1907 CancelLoadingDueToDeletedOrder(v);
1908 }
1909 }
1910 }
1911
1918 uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
1919 {
1920 return ispercent ? Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
1921 }
1922
1931 static bool CheckForValidOrders(const Vehicle *v)
1932 {
1933 for (const Order *order : v->Orders()) {
1934 switch (order->GetType()) {
1935 case OT_GOTO_STATION:
1936 case OT_GOTO_DEPOT:
1937 case OT_GOTO_WAYPOINT:
1938 return true;
1939
1940 default:
1941 break;
1942 }
1943 }
1944
1945 return false;
1946 }
1947
1951 static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value)
1952 {
1953 switch (occ) {
1954 case OCC_EQUALS: return variable == value;
1955 case OCC_NOT_EQUALS: return variable != value;
1956 case OCC_LESS_THAN: return variable < value;
1957 case OCC_LESS_EQUALS: return variable <= value;
1958 case OCC_MORE_THAN: return variable > value;
1959 case OCC_MORE_EQUALS: return variable >= value;
1960 case OCC_IS_TRUE: return variable != 0;
1961 case OCC_IS_FALSE: return variable == 0;
1962 default: NOT_REACHED();
1963 }
1964 }
1965
1972 VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
1973 {
1974 if (order->GetType() != OT_CONDITIONAL) return INVALID_VEH_ORDER_ID;
1975
1976 bool skip_order = false;
1977 OrderConditionComparator occ = order->GetConditionComparator();
1978 uint16 value = order->GetConditionValue();
1979
1980 switch (order->GetConditionVariable()) {
1981 case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, nullptr), value); break;
1982 case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
1983 case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break;
1984 case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
1985 case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
1986 case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
1987 case OCV_UNCONDITIONALLY: skip_order = true; break;
1988 case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
1989 default: NOT_REACHED();
1990 }
1991
1992 return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
1993 }
1994
2002 bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
2003 {
2004 if (conditional_depth > v->GetNumOrders()) {
2005 v->current_order.Free();
2006 v->SetDestTile(0);
2007 return false;
2008 }
2009
2010 switch (order->GetType()) {
2011 case OT_GOTO_STATION:
2012 v->SetDestTile(v->GetOrderStationLocation(order->GetDestination()));
2013 return true;
2014
2015 case OT_GOTO_DEPOT:
2016 if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
2017 assert(!pbs_look_ahead);
2018 UpdateVehicleTimetable(v, true);
2019 v->IncrementRealOrderIndex();
2020 break;
2021 }
2022
2023 if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
2024 /* We need to search for the nearest depot (hangar). */
2025 TileIndex location;
2026 DestinationID destination;
2027 bool reverse;
2028
2029 if (v->FindClosestDepot(&location, &destination, &reverse)) {
2030 /* PBS reservations cannot reverse */
2031 if (pbs_look_ahead && reverse) return false;
2032
2033 v->SetDestTile(location);
2034 v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
2035
2036 /* If there is no depot in front, reverse automatically (trains only) */
2037 if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
2038
2039 if (v->type == VEH_AIRCRAFT) {
2040 Aircraft *a = Aircraft::From(v);
2041 if (a->state == FLYING && a->targetairport != destination) {
2042 /* The aircraft is now heading for a different hangar than the next in the orders */
2043 extern void AircraftNextAirportPos_and_Order(Aircraft *a);
2044 AircraftNextAirportPos_and_Order(a);
2045 }
2046 }
2047 return true;
2048 }
2049
2050 /* If there is no depot, we cannot help PBS either. */
2051 if (pbs_look_ahead) return false;
2052
2053 UpdateVehicleTimetable(v, true);
2054 v->IncrementRealOrderIndex();
2055 } else {
2056 if (v->type != VEH_AIRCRAFT) {
2057 v->SetDestTile(Depot::Get(order->GetDestination())->xy);
2058 } else {
2059 Aircraft *a = Aircraft::From(v);
2060 DestinationID destination = a->current_order.GetDestination();
2061 if (a->targetairport != destination) {
2062 /* The aircraft is now heading for a different hangar than the next in the orders */
2063 a->SetDestTile(a->GetOrderStationLocation(destination));
2064 }
2065 }
2066 return true;
2067 }
2068 break;
2069
2070 case OT_GOTO_WAYPOINT:
2071 v->SetDestTile(Waypoint::Get(order->GetDestination())->xy);
2072 return true;
2073
2074 case OT_CONDITIONAL: {
2075 assert(!pbs_look_ahead);
2076 VehicleOrderID next_order = ProcessConditionalOrder(order, v);
2077 if (next_order != INVALID_VEH_ORDER_ID) {
2078 /* Jump to next_order. cur_implicit_order_index becomes exactly that order,
2079 * cur_real_order_index might come after next_order. */
2080 UpdateVehicleTimetable(v, false);
2081 v->cur_implicit_order_index = v->cur_real_order_index = next_order;
2082 v->UpdateRealOrderIndex();
2083 v->current_order_time += v->GetOrder(v->cur_real_order_index)->GetTimetabledTravel();
2084
2085 /* Disable creation of implicit orders.
2086 * When inserting them we do not know that we would have to make the conditional orders point to them. */
2087 if (v->IsGroundVehicle()) {
2088 uint16 &gv_flags = v->GetGroundVehicleFlags();
2089 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
2090 }
2091 } else {
2092 UpdateVehicleTimetable(v, true);
2093 v->IncrementRealOrderIndex();
2094 }
2095 break;
2096 }
2097
2098 default:
2099 v->SetDestTile(0);
2100 return false;
2101 }
2102
2103 assert(v->cur_implicit_order_index < v->GetNumOrders());
2104 assert(v->cur_real_order_index < v->GetNumOrders());
2105
2106 /* Get the current order */
2107 order = v->GetOrder(v->cur_real_order_index);
2108 if (order != nullptr && order->IsType(OT_IMPLICIT)) {
2109 assert(v->GetNumManualOrders() == 0);
2110 order = nullptr;
2111 }
2112
2113 if (order == nullptr) {
2114 v->current_order.Free();
2115 v->SetDestTile(0);
2116 return false;
2117 }
2118
2119 v->current_order = *order;
2120 return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
2121 }
2122
2130 bool ProcessOrders(Vehicle *v)
2131 {
2132 switch (v->current_order.GetType()) {
2133 case OT_GOTO_DEPOT:
2134 /* Let a depot order in the orderlist interrupt. */
2135 if (!(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return false;
2136 break;
2137
2138 case OT_LOADING:
2139 return false;
2140
2141 case OT_LEAVESTATION:
2142 if (v->type != VEH_AIRCRAFT) return false;
2143 break;
2144
2145 default: break;
2146 }
2147
2155 bool may_reverse = v->current_order.IsType(OT_NOTHING);
2156
2157 /* Check if we've reached a 'via' destination. */
2158 if (((v->current_order.IsType(OT_GOTO_STATION) && (v->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION)) || v->current_order.IsType(OT_GOTO_WAYPOINT)) &&
2159 IsTileType(v->tile, MP_STATION) &&
2160 v->current_order.GetDestination() == GetStationIndex(v->tile)) {
2161 v->DeleteUnreachedImplicitOrders();
2162 /* We set the last visited station here because we do not want
2163 * the train to stop at this 'via' station if the next order
2164 * is a no-non-stop order; in that case not setting the last
2165 * visited station will cause the vehicle to still stop. */
2166 v->last_station_visited = v->current_order.GetDestination();
2167 UpdateVehicleTimetable(v, true);
2168 v->IncrementImplicitOrderIndex();
2169 }
2170
2171 /* Get the current order */
2172 assert(v->cur_implicit_order_index == 0 || v->cur_implicit_order_index < v->GetNumOrders());
2173 v->UpdateRealOrderIndex();
2174
2175 const Order *order = v->GetOrder(v->cur_real_order_index);
2176 if (order != nullptr && order->IsType(OT_IMPLICIT)) {
2177 assert(v->GetNumManualOrders() == 0);
2178 order = nullptr;
2179 }
2180
2181 /* If no order, do nothing. */
2182 if (order == nullptr || (v->type == VEH_AIRCRAFT && !CheckForValidOrders(v))) {
2183 if (v->type == VEH_AIRCRAFT) {
2184 /* Aircraft do something vastly different here, so handle separately */
2185 extern void HandleMissingAircraftOrders(Aircraft *v);
2186 HandleMissingAircraftOrders(Aircraft::From(v));
2187 return false;
2188 }
2189
2190 v->current_order.Free();
2191 v->SetDestTile(0);
2192 return false;
2193 }
2194
2195 /* If it is unchanged, keep it. */
2196 if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) &&
2197 (v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination())->ship_station.tile != INVALID_TILE)) {
2198 return false;
2199 }
2200
2201 /* Otherwise set it, and determine the destination tile. */
2202 v->current_order = *order;
2203
2204 InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
2205 switch (v->type) {
2206 default:
2207 NOT_REACHED();
2208
2209 case VEH_ROAD:
2210 case VEH_TRAIN:
2211 break;
2212
2213 case VEH_AIRCRAFT:
2214 case VEH_SHIP:
2215 SetWindowClassesDirty(GetWindowClassForVehicleType(v->type));
2216 break;
2217 }
2218
2219 return UpdateOrderDest(v, order) && may_reverse;
2220 }
2221
2229 bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
2230 {
2231 bool is_dest_station = this->IsType(OT_GOTO_STATION) && this->dest == station;
2232
2233 return (!this->IsType(OT_GOTO_DEPOT) || (this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0) &&
2234 v->last_station_visited != station && // Do stop only when we've not just been there
2235 /* Finally do stop when there is no non-stop flag set for this type of station. */
2236 !(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
2237 }
2238
2239 bool Order::CanLoadOrUnload() const
2240 {
2241 return (this->IsType(OT_GOTO_STATION) || this->IsType(OT_IMPLICIT)) &&
2242 (this->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0 &&
2243 ((this->GetLoadType() & OLFB_NO_LOAD) == 0 ||
2244 (this->GetUnloadType() & OUFB_NO_UNLOAD) == 0);
2245 }
2246
2253 bool Order::CanLeaveWithCargo(bool has_cargo) const
2254 {
2255 return (this->GetLoadType() & OLFB_NO_LOAD) == 0 || (has_cargo &&
2256 (this->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == 0);
2257 }
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition: vehicle_type.h:27
OrderList::first_shared
Vehicle * first_shared
NOSAVE: pointer to the first vehicle in the shared order chain.
Definition: order_base.h:261
DA_STOP
@ DA_STOP
Go to the depot and stop there.
Definition: order_type.h:163
CmdDeleteOrder
CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Delete an order from the orderlist of a vehicle.
Definition: order_cmd.cpp:1013
BaseStation::facilities
StationFacility facilities
The facilities that this station has.
Definition: base_station_base.h:63
Aircraft::targetairport
StationID targetairport
Airport to go to next.
Definition: aircraft.h:78
BaseConsist::cur_implicit_order_index
VehicleOrderID cur_implicit_order_index
The index to the current implicit order.
Definition: base_consist.h:29
VehicleOrderID
byte VehicleOrderID
The index of an order within its current vehicle (not pool related)
Definition: order_type.h:15
Order::IsRefit
bool IsRefit() const
Is this order a refit order.
Definition: order_base.h:108
Cheats::no_jetcrash
Cheat no_jetcrash
no jet will crash on small airports anymore
Definition: cheat_type.h:32
DeleteOrder
void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
Delete an order but skip the parameter validation.
Definition: order_cmd.cpp:1054
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3321
Order::GetWaitTime
uint16 GetWaitTime() const
Get the time in ticks a vehicle will probably wait at the destination (timetabled or not).
Definition: order_base.h:183
Order::MakeDummy
void MakeDummy()
Makes this order a Dummy order.
Definition: order_cmd.cpp:132
SmallStack
Minimal stack that uses a pool to avoid pointers.
Definition: smallstack_type.hpp:136
UpdateVehicleTimetable
void UpdateVehicleTimetable(Vehicle *v, bool travelling)
Update the timetable for the vehicle.
Definition: timetable_cmd.cpp:372
ModifyOrderFlags
ModifyOrderFlags
Enumeration for the data to set in CmdModifyOrder.
Definition: order_type.h:143
SmallStack::Pop
Titem Pop()
Pop an item from the stack.
Definition: smallstack_type.hpp:213
AircraftNextAirportPos_and_Order
void AircraftNextAirportPos_and_Order(Aircraft *v)
set the right pos when heading to other airports after takeoff
Definition: aircraft_cmd.cpp:1431
OUFB_UNLOAD
@ OUFB_UNLOAD
Force unloading all cargo onto the platform, possibly not getting paid.
Definition: order_type.h:54
DoCommand
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:450
CMD_REVERSE_TRAIN_DIRECTION
@ CMD_REVERSE_TRAIN_DIRECTION
turn a train around
Definition: command_type.h:222
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:61
Pool::PoolItem<&_station_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
Order::GetTimetabledWait
uint16 GetTimetabledWait() const
Get the time in ticks a vehicle should wait at the destination or 0 if it's not timetabled.
Definition: order_base.h:179
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3220
Vehicle::PreviousShared
Vehicle * PreviousShared() const
Get the previous vehicle of the shared vehicle chain.
Definition: vehicle_base.h:680
Order::SetLoadType
void SetLoadType(OrderLoadFlags load_type)
Set how the consist must be loaded.
Definition: order_base.h:148
GetServiceIntervalClamped
uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
Clamp the service interval to the correct min/max.
Definition: order_cmd.cpp:1918
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
Vehicle::GetNumManualOrders
VehicleOrderID GetNumManualOrders() const
Get the number of manually added orders this vehicle has.
Definition: vehicle_base.h:704
MOF_DEPOT_ACTION
@ MOF_DEPOT_ACTION
Selects the OrderDepotAction.
Definition: order_type.h:148
OCC_NOT_EQUALS
@ OCC_NOT_EQUALS
Skip if both values are not equal.
Definition: order_type.h:129
command_func.h
SmallStack::Push
void Push(const Titem &item)
Pushes a new item onto the stack if there is still space in the underlying pool.
Definition: smallstack_type.hpp:193
MOF_LOAD
@ MOF_LOAD
Passes an OrderLoadType.
Definition: order_type.h:147
Pool::PoolItem<&_station_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:340
ODTFB_SERVICE
@ ODTFB_SERVICE
This depot order is because of the servicing limit.
Definition: order_type.h:95
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
Vehicle::GetGroundVehicleFlags
uint16 & GetGroundVehicleFlags()
Access the ground vehicle flags of the vehicle.
Definition: vehicle.cpp:2913
MOF_COND_VALUE
@ MOF_COND_VALUE
The value to set the condition to.
Definition: order_type.h:151
CheckOrders
void CheckOrders(const Vehicle *v)
Check the orders of a vehicle, to see if there are invalid orders and stuff.
Definition: order_cmd.cpp:1729
GVF_SUPPRESS_IMPLICIT_ORDERS
@ GVF_SUPPRESS_IMPLICIT_ORDERS
Disable insertion and removal of automatic orders until the vehicle completes the real order.
Definition: ground_vehicle.hpp:54
OrderLoadFlags
OrderLoadFlags
Flags related to the loading order.
Definition: order_type.h:62
Order::MakeLoading
void MakeLoading(bool ordered)
Makes this order a Loading order.
Definition: order_cmd.cpp:114
Order::MakeLeaveStation
void MakeLeaveStation()
Makes this order a Leave Station order.
Definition: order_cmd.cpp:123
Vehicle::LeaveStation
void LeaveStation()
Perform all actions when leaving a station.
Definition: vehicle.cpp:2239
company_base.h
OUFB_TRANSFER
@ OUFB_TRANSFER
Transfer all cargo onto the platform.
Definition: order_type.h:55
Vehicle::GetDisplayMaxSpeed
virtual int GetDisplayMaxSpeed() const
Gets the maximum speed in km-ish/h that can be sent into SetDParam for string processing.
Definition: vehicle_base.h:497
OLFB_FULL_LOAD
@ OLFB_FULL_LOAD
Full load all cargoes of the consist.
Definition: order_type.h:64
Station
Station data structure.
Definition: station_base.h:450
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:94
ProcessConditionalOrder
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
Process a conditional order and determine the next order.
Definition: order_cmd.cpp:1972
InsertOrder
void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
Insert a new order but skip the validation.
Definition: order_cmd.cpp:927
OrderList::total_duration
Ticks total_duration
NOSAVE: Total (timetabled or not) duration of the order list.
Definition: order_base.h:264
Order::GetTimetabledTravel
uint16 GetTimetabledTravel() const
Get the time in ticks a vehicle should take to reach the destination or 0 if it's not timetabled.
Definition: order_base.h:181
Order::GetConditionValue
uint16 GetConditionValue() const
Get the value to base the skip on.
Definition: order_base.h:145
IsRoadDepotTile
static bool IsRoadDepotTile(TileIndex t)
Return whether a tile is a road depot tile.
Definition: road_map.h:115
Vehicle::vehstatus
byte vehstatus
Status.
Definition: vehicle_base.h:326
OrderList::MoveOrder
void MoveOrder(int from, int to)
Move an order to another position within the order list.
Definition: order_cmd.cpp:535
DepotID
uint16 DepotID
Type for the unique identifier of depots.
Definition: depot_type.h:13
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
AirportFTAClass::SHORT_STRIP
@ SHORT_STRIP
This airport has a short landing strip, dangerous for fast aircraft.
Definition: airport.h:150
Order::wait_time
uint16 wait_time
How long in ticks to wait at the destination.
Definition: order_base.h:44
MOF_UNLOAD
@ MOF_UNLOAD
Passes an OrderUnloadType.
Definition: order_type.h:146
OSL_PLATFORM_MIDDLE
@ OSL_PLATFORM_MIDDLE
Stop at the middle of the platform.
Definition: order_type.h:85
Order::Free
void Free()
'Free' the order
Definition: order_cmd.cpp:62
DeleteVehicleNews
void DeleteVehicleNews(VehicleID vid, StringID news)
Delete a news item type about a vehicle.
Definition: news_gui.cpp:902
Order::SetTravelTimetabled
void SetTravelTimetabled(bool timetabled)
Set if the travel time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:197
Order::GetUnloadType
OrderUnloadFlags GetUnloadType() const
How must the consist be unloaded?
Definition: order_base.h:129
Waypoint
Representation of a waypoint.
Definition: waypoint_base.h:16
aircraft.h
OrderDepotTypeFlags
OrderDepotTypeFlags
Reasons that could cause us to go to the depot.
Definition: order_type.h:93
OCC_MORE_THAN
@ OCC_MORE_THAN
Skip if the value is more than the limit.
Definition: order_type.h:132
SpecializedStation< Station, false >::Get
static Station * Get(size_t index)
Gets station with given index.
Definition: base_station_base.h:219
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
Order::AssignOrder
void AssignOrder(const Order &other)
Assign data to an order (from another order) This function makes sure that the index is maintained co...
Definition: order_cmd.cpp:272
OrderList::IsCompleteTimetable
bool IsCompleteTimetable() const
Checks whether all orders of the list have a filled timetable.
Definition: order_cmd.cpp:602
WC_VEHICLE_TIMETABLE
@ WC_VEHICLE_TIMETABLE
Vehicle timetable; Window numbers:
Definition: window_type.h:217
MOF_COND_DESTINATION
@ MOF_COND_DESTINATION
Change the destination of a conditional order.
Definition: order_type.h:152
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
Vehicle
Vehicle data structure.
Definition: vehicle_base.h:222
Vehicle::IsPrimaryVehicle
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:444
Vehicle::IsGroundVehicle
bool IsGroundVehicle() const
Check if the vehicle is a ground vehicle.
Definition: vehicle_base.h:482
OrderList::IsShared
bool IsShared() const
Is this a shared order list?
Definition: order_base.h:331
Vehicle::owner
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:283
MOF_COND_COMPARATOR
@ MOF_COND_COMPARATOR
A comparator changes.
Definition: order_type.h:150
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:348
BaseStation::owner
Owner owner
The owner of this station.
Definition: base_station_base.h:62
DecloneOrder
static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
Declone an order-list.
Definition: order_cmd.cpp:994
OrderList::RemoveVehicle
void RemoveVehicle(Vehicle *v)
Removes the vehicle from the shared order list.
Definition: order_cmd.cpp:567
DeleteVehicleOrders
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
Delete all orders from a vehicle.
Definition: order_cmd.cpp:1890
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
OrderStopLocation
OrderStopLocation
Where to stop the trains.
Definition: order_type.h:83
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
Vehicle::UpdateRealOrderIndex
void UpdateRealOrderIndex()
Skip implicit orders until cur_real_order_index is a non-implicit order.
Definition: vehicle_base.h:851
OrderList::GetNextDecisionNode
const Order * GetNextDecisionNode(const Order *next, uint hops) const
Get the next order which will make the given vehicle stop at a station or refit at a depot or evaluat...
Definition: order_cmd.cpp:379
Order::Pack
uint32 Pack() const
Pack this order into a 32 bits integer, or actually only the type, flags and destination.
Definition: order_cmd.cpp:197
Airport::GetFTA
const AirportFTAClass * GetFTA() const
Get the finite-state machine for this airport or the finite-state machine for the dummy airport in ca...
Definition: station_base.h:332
OrderList::timetable_duration
Ticks timetable_duration
NOSAVE: Total timetabled duration of the order list.
Definition: order_base.h:263
Order::MakeGoToDepot
void MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type=ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, OrderDepotActionFlags action=ODATF_SERVICE_ONLY, CargoID cargo=CT_NO_REFIT)
Makes this order a Go To Depot order.
Definition: order_cmd.cpp:89
Order::GetType
OrderType GetType() const
Get the type of order of this order.
Definition: order_base.h:67
Aircraft
Aircraft, helicopters, rotors and their shadows belong to this class.
Definition: aircraft.h:74
Order::GetStopLocation
OrderStopLocation GetStopLocation() const
Where must we stop at the platform?
Definition: order_base.h:133
GetOrderDistance
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
Get the distance between two orders of a vehicle.
Definition: order_cmd.cpp:707
ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
@ ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS
The vehicle will not stop at any stations it passes except the destination.
Definition: order_type.h:74
Order::GetNonStopType
OrderNonStopFlags GetNonStopType() const
At which stations must we stop?
Definition: order_base.h:131
Vehicle::Orders
IterateWrapper Orders() const
Returns an iterable ensemble of orders of a vehicle.
Definition: vehicle_base.h:1034
Airport::HasHangar
bool HasHangar() const
Check if this airport has at least one hangar.
Definition: station_base.h:338
UpdateOrderDest
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
Update the vehicle's destination tile from an order.
Definition: order_cmd.cpp:2002
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
depot_base.h
OrderConditionCompare
static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value)
Compare the variable and value based on the given comparator.
Definition: order_cmd.cpp:1951
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition: company_cmd.cpp:311
OLF_FULL_LOAD_ANY
@ OLF_FULL_LOAD_ANY
Full load a single cargo of the consist.
Definition: order_type.h:65
Vehicle::dest_tile
TileIndex dest_tile
Heading for this tile.
Definition: vehicle_base.h:247
return_cmd_error
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:33
Order::GetRefitCargo
CargoID GetRefitCargo() const
Get the cargo to to refit to.
Definition: order_base.h:122
timetable.h
CalcPercentVehicleFilled
uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour)
Calculates how full a vehicle is.
Definition: vehicle.cpp:1413
CommandCost
Common return value for all commands.
Definition: command_type.h:23
ONSF_STOP_EVERYWHERE
@ ONSF_STOP_EVERYWHERE
The vehicle will stop at any station it passes and the destination.
Definition: order_type.h:73
cmd_helper.h
WC_VEHICLE_VIEW
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
Definition: window_type.h:332
Vehicle::AddToShared
void AddToShared(Vehicle *shared_chain)
Adds this vehicle to a shared vehicle chain.
Definition: vehicle.cpp:2747
INVALID_VEH_ORDER_ID
static const VehicleOrderID INVALID_VEH_ORDER_ID
Invalid vehicle order index (sentinel)
Definition: order_type.h:21
Vehicle::RemoveFromShared
void RemoveFromShared()
Removes the vehicle from the shared order list.
Definition: vehicle.cpp:2770
Vehicle::tile
TileIndex tile
Current tile index.
Definition: vehicle_base.h:240
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
CancelLoadingDueToDeletedOrder
static void CancelLoadingDueToDeletedOrder(Vehicle *v)
Cancel the current loading order of the vehicle as the order was deleted.
Definition: order_cmd.cpp:1038
Order::MakeGoToWaypoint
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:103
Vehicle::engine_type
EngineID engine_type
The type of engine used for this vehicle.
Definition: vehicle_base.h:297
VS_CRASHED
@ VS_CRASHED
Vehicle is crashed.
Definition: vehicle_base.h:37
OUF_UNLOAD_IF_POSSIBLE
@ OUF_UNLOAD_IF_POSSIBLE
Unload all cargo that the station accepts.
Definition: order_type.h:53
_cheats
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
CmdModifyOrder
CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Modify an order in the orderlist of a vehicle.
Definition: order_cmd.cpp:1262
Vehicle::last_station_visited
StationID last_station_visited
The last station we stopped at.
Definition: vehicle_base.h:311
CheckForValidOrders
static bool CheckForValidOrders(const Vehicle *v)
Check if a vehicle has any valid orders.
Definition: order_cmd.cpp:1931
Order::GetTravelTime
uint16 GetTravelTime() const
Get the time in ticks a vehicle will probably take to reach the destination (timetabled or not).
Definition: order_base.h:185
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
Vehicle::current_order
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:327
Vehicle::max_age
Date max_age
Maximum age.
Definition: vehicle_base.h:269
Station::airport
Airport airport
Tile area the airport covers.
Definition: station_base.h:464
DeleteOrderWarnings
static void DeleteOrderWarnings(const Vehicle *v)
Delete all news items regarding defective orders about a vehicle This could kill still valid warnings...
Definition: order_cmd.cpp:665
CmdInsertOrder
CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add an order to the orderlist of a vehicle.
Definition: order_cmd.cpp:738
AirportFTAClass::flags
Flags flags
Flags for this airport type.
Definition: airport.h:180
Vehicle::GetLastOrder
Order * GetLastOrder() const
Returns the last order of a vehicle, or nullptr if it doesn't exists.
Definition: vehicle_base.h:881
ODATFB_NEAREST_DEPOT
@ ODATFB_NEAREST_DEPOT
Send the vehicle to the nearest depot.
Definition: order_type.h:105
OrderList::DeleteOrderAt
void DeleteOrderAt(int index)
Remove an order from the order list and delete it.
Definition: order_cmd.cpp:509
OCC_IS_TRUE
@ OCC_IS_TRUE
Skip if the variable is true.
Definition: order_type.h:134
VS_STOPPED
@ VS_STOPPED
Vehicle is stopped by the player.
Definition: vehicle_base.h:31
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Vehicle::GetEngine
const Engine * GetEngine() const
Retrieves the engine of the vehicle.
Definition: vehicle.cpp:741
safeguards.h
IsRailDepotTile
static bool IsRailDepotTile(TileIndex t)
Is this tile rail tile and a rail depot?
Definition: rail_map.h:105
OCC_LESS_EQUALS
@ OCC_LESS_EQUALS
Skip if the value is less or equal to the limit.
Definition: order_type.h:131
DA_ALWAYS_GO
@ DA_ALWAYS_GO
Always go to the depot.
Definition: order_type.h:161
WC_SHIPS_LIST
@ WC_SHIPS_LIST
Ships list; Window numbers:
Definition: window_type.h:313
OrderList::Initialize
void Initialize(Order *chain, Vehicle *v)
Recomputes everything.
Definition: order_cmd.cpp:290
OrderList::num_manual_orders
VehicleOrderID num_manual_orders
NOSAVE: How many manually added orders are there in the list.
Definition: order_base.h:259
ODTFB_PART_OF_ORDERS
@ ODTFB_PART_OF_ORDERS
This depot order is because of a regular order.
Definition: order_type.h:96
Ticks
int32 Ticks
The type to store ticks in.
Definition: date_type.h:16
Order::GetConditionComparator
OrderConditionComparator GetConditionComparator() const
What is the comparator to use?
Definition: order_base.h:141
OrderList::FreeChain
void FreeChain(bool keep_orderlist=false)
Free a complete order chain.
Definition: order_cmd.cpp:333
OrderList::GetPositionInSharedOrderList
int GetPositionInSharedOrderList(const Vehicle *v) const
Gets the position of the given vehicle within the shared order vehicle list.
Definition: order_cmd.cpp:591
CmdMoveOrder
CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Move an order inside the orderlist.
Definition: order_cmd.cpp:1159
Order::SetConditionValue
void SetConditionValue(uint16 value)
Set the value to base the skip on.
Definition: order_base.h:166
OCC_MORE_EQUALS
@ OCC_MORE_EQUALS
Skip if the value is more or equal to the limit.
Definition: order_type.h:133
Vehicle::FindClosestDepot
virtual bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse)
Find the closest depot for this vehicle and tell us the location, DestinationID and whether we should...
Definition: vehicle_base.h:761
FACIL_DOCK
@ FACIL_DOCK
Station with a dock.
Definition: station_type.h:56
Vehicle::HasDepotOrder
bool HasDepotOrder() const
Checks if a vehicle has a depot in its order list.
Definition: order_cmd.cpp:1872
Order::MakeGoToStation
void MakeGoToStation(StationID destination)
Makes this order a Go To Station order.
Definition: order_cmd.cpp:74
DAYS_IN_LEAP_YEAR
static const int DAYS_IN_LEAP_YEAR
sometimes, you need one day more...
Definition: date_type.h:30
OrderList::GetNextStoppingStation
StationIDStack GetNextStoppingStation(const Vehicle *v, const Order *first=nullptr, uint hops=0) const
Recursively determine the next deterministic station to stop at.
Definition: order_cmd.cpp:414
Order::GetConditionSkipToOrder
VehicleOrderID GetConditionSkipToOrder() const
Get the order to skip to.
Definition: order_base.h:143
CmdCloneOrder
CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Clone/share/copy an order-list of another vehicle.
Definition: order_cmd.cpp:1531
stdafx.h
Order::max_speed
uint16 max_speed
How fast the vehicle may go on the way to the destination.
Definition: order_base.h:46
Vehicle::IsOrderListShared
bool IsOrderListShared() const
Check if we share our orders with another vehicle.
Definition: vehicle_base.h:692
Cheat::value
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
OLF_LOAD_IF_POSSIBLE
@ OLF_LOAD_IF_POSSIBLE
Load as long as there is cargo that fits in the train.
Definition: order_type.h:63
Order::SetStopLocation
void SetStopLocation(OrderStopLocation stop_location)
Set where we must stop at the platform.
Definition: order_base.h:154
OSL_PLATFORM_NEAR_END
@ OSL_PLATFORM_NEAR_END
Stop at the near end of the platform.
Definition: order_type.h:84
OrderList::GetOrderAt
Order * GetOrderAt(int index) const
Get a certain order of the order chain.
Definition: order_cmd.cpp:356
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
ODATFB_HALT
@ ODATFB_HALT
Service the vehicle and then halt it.
Definition: order_type.h:104
Vehicle::IncrementRealOrderIndex
void IncrementRealOrderIndex()
Advanced cur_real_order_index to the next real order, keeps care of the wrap-around and invalidates t...
Definition: vehicle_base.h:836
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
Order::IsTravelTimetabled
bool IsTravelTimetabled() const
Does this order have an explicit travel time set?
Definition: order_base.h:176
Vehicle::list
OrderList * list
Pointer to the order list for this vehicle.
Definition: vehicle_base.h:330
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:174
BaseConsist::cur_real_order_index
VehicleOrderID cur_real_order_index
The index to the current real (non-implicit) order.
Definition: base_consist.h:28
ONSF_NO_STOP_AT_DESTINATION_STATION
@ ONSF_NO_STOP_AT_DESTINATION_STATION
The vehicle will stop at any station it passes except the destination.
Definition: order_type.h:75
Aircraft::GetOrderStationLocation
TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: aircraft_cmd.cpp:1287
GetWindowClassForVehicleType
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
Definition: vehicle_gui.h:91
ProcessOrders
bool ProcessOrders(Vehicle *v)
Handle the orders of a vehicle and determine the next place to go to if needed.
Definition: order_cmd.cpp:2130
CmdSkipToOrder
CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Goto order of order-list.
Definition: order_cmd.cpp:1118
Vehicle::FirstShared
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
Definition: vehicle_base.h:686
CmdOrderRefit
CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Add/remove refit orders from an order.
Definition: order_cmd.cpp:1678
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Order::SetRefit
void SetRefit(CargoID cargo)
Make this depot/station order also a refit order.
Definition: order_cmd.cpp:164
OrderUnloadFlags
OrderUnloadFlags
Flags related to the unloading order.
Definition: order_type.h:52
OrderNonStopFlags
OrderNonStopFlags
Non-stop order flags.
Definition: order_type.h:72
OrderList::DebugCheckSanity
void DebugCheckSanity() const
Checks for internal consistency of order list.
Definition: order_cmd.cpp:615
vehicle_func.h
station_base.h
AircraftCache::cached_max_range_sqr
uint32 cached_max_range_sqr
Cached squared maximum range.
Definition: aircraft.h:67
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
Pool::PoolItem<&_vehicle_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
strings_func.h
Pool
Base class for all pools.
Definition: pool_type.hpp:81
Order::SetConditionVariable
void SetConditionVariable(OrderConditionVariable condition_variable)
Set variable we have to compare.
Definition: order_base.h:160
OCC_EQUALS
@ OCC_EQUALS
Skip if both values are equal.
Definition: order_type.h:128
OCV_MAX_SPEED
@ OCV_MAX_SPEED
Skip based on the maximum speed.
Definition: order_type.h:115
OSL_PLATFORM_FAR_END
@ OSL_PLATFORM_FAR_END
Stop at the far end of the platform.
Definition: order_type.h:86
Order::refit_cargo
CargoID refit_cargo
Refit CargoID.
Definition: order_base.h:42
Vehicle::IncrementImplicitOrderIndex
void IncrementImplicitOrderIndex()
Increments cur_implicit_order_index, keeps care of the wrap-around and invalidates the GUI.
Definition: vehicle_base.h:812
OCV_RELIABILITY
@ OCV_RELIABILITY
Skip based on the reliability.
Definition: order_type.h:114
MOF_STOP_LOCATION
@ MOF_STOP_LOCATION
Passes an OrderStopLocation.
Definition: order_type.h:145
FACIL_TRAIN
@ FACIL_TRAIN
Station with train station.
Definition: station_type.h:52
Vehicle::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the vehicles order list.
Definition: vehicle_base.h:665
SpecializedVehicle< RoadVehicle, Type >::From
static RoadVehicle * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
Definition: vehicle_base.h:1162
OrderList::RecalculateTimetableDuration
void RecalculateTimetableDuration()
Recomputes Timetable duration.
Definition: order_cmd.cpp:320
OCV_REMAINING_LIFETIME
@ OCV_REMAINING_LIFETIME
Skip based on the remaining lifetime.
Definition: order_type.h:119
OUFB_NO_UNLOAD
@ OUFB_NO_UNLOAD
Totally no unloading will be done.
Definition: order_type.h:56
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
RemoveOrderFromAllVehicles
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_cmd.cpp:1805
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3339
Order::MapOldOrder
uint16 MapOldOrder() const
Pack this order into a 16 bits integer as close to the TTD representation as possible.
Definition: order_cmd.cpp:207
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:250
cheat_type.h
BaseConsist::current_order_time
uint32 current_order_time
How many ticks have passed since this order started.
Definition: base_consist.h:22
Order::SetConditionSkipToOrder
void SetConditionSkipToOrder(VehicleOrderID order_id)
Get the order to skip to.
Definition: order_base.h:164
Vehicle::NextShared
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
Definition: vehicle_base.h:674
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
Vehicle::orders
union Vehicle::@51 orders
The orders currently assigned to the vehicle.
CT_AUTO_REFIT
@ CT_AUTO_REFIT
Automatically choose cargo type when doing auto refitting.
Definition: cargo_type.h:66
OrderList::GetLastOrder
Order * GetLastOrder() const
Get the last order of the order chain.
Definition: order_base.h:298
MP_STATION
@ MP_STATION
A tile of a station.
Definition: tile_type.h:46
Vehicle::age
Date age
Age in days.
Definition: vehicle_base.h:268
MOF_NON_STOP
@ MOF_NON_STOP
Passes an OrderNonStopFlags.
Definition: order_type.h:144
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
GetStationIndex
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:28
waypoint_base.h
Pool::PoolItem<&_order_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition: pool_type.hpp:299
Order::SetWaitTime
void SetWaitTime(uint16 time)
Set the time in ticks to wait at the destination.
Definition: order_base.h:203
Order::SetDepotOrderType
void SetDepotOrderType(OrderDepotTypeFlags depot_order_type)
Set the cause to go to the depot.
Definition: order_base.h:156
BaseStation::xy
TileIndex xy
Base tile of the station.
Definition: base_station_base.h:53
OrderList::first
Order * first
First order of the order list.
Definition: order_base.h:257
OrderBackup::RemoveOrder
static void RemoveOrder(OrderType type, DestinationID destination, bool hangar)
Removes an order from all vehicles.
Definition: order_backup.cpp:249
BaseStation
Base class for all station-ish types.
Definition: base_station_base.h:52
MAX_VEH_ORDER_ID
static const VehicleOrderID MAX_VEH_ORDER_ID
Last valid VehicleOrderID.
Definition: order_type.h:23
GUISettings::order_review_system
uint8 order_review_system
perform order reviews on vehicles
Definition: settings_type.h:95
Order::SetDepotActionType
void SetDepotActionType(OrderDepotActionFlags depot_service_type)
Set what we are going to do in the depot.
Definition: order_base.h:158
company_func.h
OCV_LOAD_PERCENTAGE
@ OCV_LOAD_PERCENTAGE
Skip based on the amount of load.
Definition: order_type.h:113
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition: pool_func.hpp:224
Order::MakeConditional
void MakeConditional(VehicleOrderID order)
Makes this order an conditional order.
Definition: order_cmd.cpp:142
Order::ShouldStopAtStation
bool ShouldStopAtStation(const Vehicle *v, StationID station) const
Check whether the given vehicle should stop at the given station based on this order and the non-stop...
Definition: order_cmd.cpp:2229
VehicleID
uint32 VehicleID
The type all our vehicle IDs have.
Definition: vehicle_type.h:16
OrderType
OrderType
Order types.
Definition: order_type.h:35
Vehicle::NeedsServicing
bool NeedsServicing() const
Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for ser...
Definition: vehicle.cpp:184
Order::GetDepotOrderType
OrderDepotTypeFlags GetDepotOrderType() const
What caused us going to the depot?
Definition: order_base.h:135
OrderList::GetNext
const Order * GetNext(const Order *curr) const
Get the order after the given one or the first one, if the given one is the last one.
Definition: order_base.h:306
AddVehicleAdviceNewsItem
static void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
Adds a vehicle-advice news item.
Definition: news_func.h:40
OrderList::GetFirstOrder
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:290
Vehicle::day_counter
byte day_counter
Increased by one for each day.
Definition: vehicle_base.h:322
Order::GetConditionVariable
OrderConditionVariable GetConditionVariable() const
What variable do we have to compare?
Definition: order_base.h:139
Depot
Definition: depot_base.h:19
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
OrderList::num_vehicles
uint num_vehicles
NOSAVE: Number of vehicles that share this order list.
Definition: order_base.h:260
random_func.hpp
SmallStack::IsEmpty
bool IsEmpty() const
Check if the stack is empty.
Definition: smallstack_type.hpp:244
SpecializedStation< Station, false >::GetIfValid
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
Definition: base_station_base.h:228
Order::SetConditionComparator
void SetConditionComparator(OrderConditionComparator condition_comparator)
Set the comparator to use.
Definition: order_base.h:162
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
OrderConditionVariable
OrderConditionVariable
Variables (of a vehicle) to 'cause' skipping on.
Definition: order_type.h:112
ToPercent16
static uint ToPercent16(uint i)
Converts a "fract" value 0..65535 to "percent" value 0..100.
Definition: math_func.hpp:238
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
RoadVehicle::IsBus
bool IsBus() const
Check whether a roadvehicle is a bus.
Definition: roadveh_cmd.cpp:79
Order::GetLocation
TileIndex GetLocation(const Vehicle *v, bool airport=false) const
Returns a tile somewhat representing the order destination (not suitable for pathfinding).
Definition: order_cmd.cpp:680
AircraftCache::cached_max_range
uint16 cached_max_range
Cached maximum range.
Definition: aircraft.h:68
Aircraft::state
byte state
State of the airport.
Definition: aircraft.h:79
Order::SetUnloadType
void SetUnloadType(OrderUnloadFlags unload_type)
Set how the consist must be unloaded.
Definition: order_base.h:150
OCV_REQUIRES_SERVICE
@ OCV_REQUIRES_SERVICE
Skip when the vehicle requires service.
Definition: order_type.h:117
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
OrderList::IsVehicleInSharedOrdersList
bool IsVehicleInSharedOrdersList(const Vehicle *v) const
Checks whether a vehicle is part of the shared vehicle chain.
Definition: order_cmd.cpp:577
Vehicle::GetOrder
Order * GetOrder(int index) const
Returns order 'index' of a vehicle or nullptr when it doesn't exists.
Definition: vehicle_base.h:872
BaseVehicle::type
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
Vehicle::reliability
uint16 reliability
Reliability.
Definition: vehicle_base.h:271
VIWD_MODIFY_ORDERS
@ VIWD_MODIFY_ORDERS
Other order modifications.
Definition: vehicle_gui.h:33
CheckAircraftOrderDistance
static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order, const Order *first)
Check if an aircraft has enough range for an order list.
Definition: order_cmd.cpp:1498
CanVehicleUseStation
bool CanVehicleUseStation(EngineID engine_type, const Station *st)
Can this station be used by the given engine type?
Definition: vehicle.cpp:2838
pool_func.hpp
order_backup.h
OrderGoesToStation
static bool OrderGoesToStation(const Vehicle *v, const Order *o)
Checks whether the order goes to a station or not, i.e.
Definition: order_cmd.cpp:653
Order::travel_time
uint16 travel_time
How long in ticks the journey to this destination should take.
Definition: order_base.h:45
Order::CanLeaveWithCargo
bool CanLeaveWithCargo(bool has_cargo) const
A vehicle can leave the current station with cargo if:
Definition: order_cmd.cpp:2253
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition: vehicle_type.h:26
OCV_MAX_RELIABILITY
@ OCV_MAX_RELIABILITY
Skip based on the maximum reliability.
Definition: order_type.h:120
IsShipDepotTile
static bool IsShipDepotTile(TileIndex t)
Is it a ship depot tile?
Definition: water_map.h:226
OCC_IS_FALSE
@ OCC_IS_FALSE
Skip if the variable is false.
Definition: order_type.h:135
Vehicle::GetNumOrders
VehicleOrderID GetNumOrders() const
Get the number of orders this vehicle has.
Definition: vehicle_base.h:698
InvalidateVehicleOrder
void InvalidateVehicleOrder(const Vehicle *v, int data)
Updates the widgets of a vehicle which contains the order-data.
Definition: order_cmd.cpp:250
OrderDepotActionFlags
OrderDepotActionFlags
Actions that can be performed when the vehicle enters the depot.
Definition: order_type.h:102
VIWD_REMOVE_ALL_ORDERS
@ VIWD_REMOVE_ALL_ORDERS
Removed / replaced all orders (after deleting / sharing).
Definition: vehicle_gui.h:32
CT_NO_REFIT
@ CT_NO_REFIT
Do not refit cargo of a vehicle (used in vehicle orders and auto-replace/auto-new).
Definition: cargo_type.h:67
SetWindowClassesDirty
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3248
Order::GetDepotActionType
OrderDepotActionFlags GetDepotActionType() const
What are we going to do when in the depot.
Definition: order_base.h:137
WC_AIRCRAFT_LIST
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers:
Definition: window_type.h:319
Vehicle::DeleteUnreachedImplicitOrders
void DeleteUnreachedImplicitOrders()
Delete all implicit orders which were not reached.
Definition: vehicle.cpp:2053
WC_STATION_LIST
@ WC_STATION_LIST
Station list; Window numbers:
Definition: window_type.h:295
Order::next
Order * next
Pointer to next order. If nullptr, end of list.
Definition: order_base.h:49
Order::flags
uint8 flags
Load/unload types, depot order/action types.
Definition: order_base.h:39
Order
Definition: order_base.h:32
DA_SERVICE
@ DA_SERVICE
Service only if needed.
Definition: order_type.h:162
Order::type
uint8 type
The type of order + non-stop flags.
Definition: order_base.h:38
OrderList::GetNumOrders
VehicleOrderID GetNumOrders() const
Get number of orders in the order list.
Definition: order_base.h:312
Station::ship_station
TileArea ship_station
Tile area the ship 'station' part covers.
Definition: station_base.h:465
Order::Equals
bool Equals(const Order &other) const
Does this order have the same type, flags and destination?
Definition: order_cmd.cpp:174
OCV_AGE
@ OCV_AGE
Skip based on the age.
Definition: order_type.h:116
OrderList::InsertOrderAt
void InsertOrderAt(Order *new_order, int index)
Insert a new order into the order chain.
Definition: order_cmd.cpp:471
Order::IsWaitTimetabled
bool IsWaitTimetabled() const
Does this order have an explicit wait time set?
Definition: order_base.h:174
Order::SetNonStopType
void SetNonStopType(OrderNonStopFlags non_stop_type)
Set whether we must stop at stations or not.
Definition: order_base.h:152
Order::dest
DestinationID dest
The destination of the order.
Definition: order_base.h:40
Order::MakeImplicit
void MakeImplicit(StationID destination)
Makes this order an implicit order.
Definition: order_cmd.cpp:153
FLYING
@ FLYING
Vehicle is flying in the air.
Definition: airport.h:75
OrderConditionComparator
OrderConditionComparator
Comparator for the skip reasoning.
Definition: order_type.h:127
Vehicle::GetOrderStationLocation
virtual TileIndex GetOrderStationLocation(StationID station)
Determine the location for the station where the vehicle goes to next.
Definition: vehicle_base.h:751
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
WC_VEHICLE_ORDERS
@ WC_VEHICLE_ORDERS
Vehicle orders; Window numbers:
Definition: window_type.h:205
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
Engine::reliability
uint16 reliability
Current reliability of the engine.
Definition: engine_base.h:25
OCC_LESS_THAN
@ OCC_LESS_THAN
Skip if the value is less than the limit.
Definition: order_type.h:130
debug.h
OCV_UNCONDITIONALLY
@ OCV_UNCONDITIONALLY
Always skip.
Definition: order_type.h:118
OLFB_NO_LOAD
@ OLFB_NO_LOAD
Do not load anything.
Definition: order_type.h:66
OrderList::num_orders
VehicleOrderID num_orders
NOSAVE: How many orders there are in the list.
Definition: order_base.h:258
Order::GetLoadType
OrderLoadFlags GetLoadType() const
How must the consist be loaded?
Definition: order_base.h:127
MOF_COND_VARIABLE
@ MOF_COND_VARIABLE
A conditional variable changes.
Definition: order_type.h:149
news_func.h
roadveh.h
Order::SetWaitTimetabled
void SetWaitTimetabled(bool timetabled)
Set if the wait time is explicitly timetabled (unless the order is conditional).
Definition: order_base.h:195