OpenTTD Source: src/order_cmd.cpp Source File

OpenTTD Source 14.0-beta1

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