annotate src/order_cmd.cpp @ 20706:79930f9362c3 draft

-Change: [Win32] Position the IME composition window at the caret position.
author Michael Lutz <michi@icosahedron.de>
date Sun, 07 Apr 2013 17:10:38 +0200
parents 8f28ee9b2502
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1 /* $Id$ */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2
12778
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
3 /*
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
4 * This file is part of OpenTTD.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
5 * 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.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
6 * 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.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
7 * 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/>.
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
8 */
bc7926153e19 (svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents: 12705
diff changeset
9
9111
d48433370037 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents: 9090
diff changeset
10 /** @file order_cmd.cpp Handling of orders. */
6351
1dcf39ea9b9b (svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas <belugas@openttd.org>
parents: 6337
diff changeset
11
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
12 #include "stdafx.h"
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
13 #include "debug.h"
15037
ae5f1c6f349c (svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents: 14898
diff changeset
14 #include "cmd_helper.h"
8116
9cc845deddfe (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents: 8114
diff changeset
15 #include "command_func.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
16 #include "company_func.h"
8763
d6e363672edb (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents: 8679
diff changeset
17 #include "news_func.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 8064
diff changeset
18 #include "strings_func.h"
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
19 #include "timetable.h"
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
20 #include "vehicle_func.h"
8962
322e2779f67a (svn r12754) -Codechange: split depot.h into depot_map.h, depot_func.h and depot_base.h and remove quite a lot of unneeded (before this) includes of depot.h.
rubidium <rubidium@openttd.org>
parents: 8961
diff changeset
21 #include "depot_base.h"
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
22 #include "core/pool_func.hpp"
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
23 #include "core/random_func.hpp"
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11972
diff changeset
24 #include "aircraft.h"
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12082
diff changeset
25 #include "roadveh.h"
12228
240adc64d01a (svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents: 12225
diff changeset
26 #include "station_base.h"
12475
c133b51890f4 (svn r16912) -Codechange: split waypoint.h in waypoint_base.h and waypoint_func.h
rubidium <rubidium@openttd.org>
parents: 12472
diff changeset
27 #include "waypoint_base.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 14256
diff changeset
28 #include "company_base.h"
18617
31037ca54d3d (svn r23464) -Fix [FS#4876]: clear the backed up orders of a removed station as well, otherwise one could create orders to a station that was never in the original backupped orders. For example a road vehicle trying to go to a buoy.
rubidium <rubidium@openttd.org>
parents: 18363
diff changeset
29 #include "order_backup.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
31 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
32
8767
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
33 /* DestinationID must be at least as large as every these below, because it can
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
34 * be any of them
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
35 */
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
36 assert_compile(sizeof(DestinationID) >= sizeof(DepotID));
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
37 assert_compile(sizeof(DestinationID) >= sizeof(StationID));
c0458cd19987 (svn r12466) -Codechange: move DestinationID to a more logical location.
rubidium <rubidium@openttd.org>
parents: 8763
diff changeset
38
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
39 OrderPool _order_pool("Order");
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
40 INSTANTIATE_POOL_METHODS(Order)
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
41 OrderListPool _orderlist_pool("OrderList");
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
42 INSTANTIATE_POOL_METHODS(OrderList)
8848
066a8010467f (svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium <rubidium@openttd.org>
parents: 8847
diff changeset
43
18363
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
44 /** Clean everything up. */
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
45 Order::~Order()
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
46 {
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
47 if (CleaningPool()) return;
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
48
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
49 /* We can visit oil rigs and buoys that are not our own. They will be shown in
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
50 * the list of stations. So, we need to invalidate that window if needed. */
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
51 if (this->IsType(OT_GOTO_STATION) || this->IsType(OT_GOTO_WAYPOINT)) {
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
52 BaseStation *bs = BaseStation::GetIfValid(this->GetDestination());
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
53 if (bs != NULL && bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
54 }
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
55 }
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
56
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
57 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
58 * 'Free' the order
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
59 * @note ONLY use on "current_order" vehicle orders!
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
60 */
8834
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
61 void Order::Free()
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
62 {
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
63 this->type = OT_NOTHING;
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
64 this->flags = 0;
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
65 this->dest = 0;
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
66 this->next = NULL;
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
67 }
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
68
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
69 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
70 * Makes this order a Go To Station order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
71 * @param destination the station to go to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
72 */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
73 void Order::MakeGoToStation(StationID destination)
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
74 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
75 this->type = OT_GOTO_STATION;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
76 this->flags = 0;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
77 this->dest = destination;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
78 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
79
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
80 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
81 * Makes this order a Go To Depot order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
82 * @param destination the depot to go to.
19968
0dba7f49118c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents: 19900
diff changeset
83 * @param order is this order a 'default' order, or an overridden vehicle order?
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
84 * @param non_stop_type how to get to the depot?
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
85 * @param action what to do in the depot?
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
86 * @param cargo the cargo type to change to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
87 */
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
88 void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo)
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
89 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
90 this->type = OT_GOTO_DEPOT;
8853
02787d6f3834 (svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium <rubidium@openttd.org>
parents: 8851
diff changeset
91 this->SetDepotOrderType(order);
10350
7de8b332e3f9 (svn r14601) -Fix: the nearest depot and stop in depot orders didn't work together (the vehicle didn't stop).
rubidium <rubidium@openttd.org>
parents: 10327
diff changeset
92 this->SetDepotActionType(action);
11809
57fd0a8c36cb (svn r16199) -Codechange: Pass OrderNonStopFlags also to MakeGoToDepotOrder().
frosch <frosch@openttd.org>
parents: 11730
diff changeset
93 this->SetNonStopType(non_stop_type);
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
94 this->dest = destination;
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
95 this->SetRefit(cargo);
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
96 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
97
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
98 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
99 * Makes this order a Go To Waypoint order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
100 * @param destination the waypoint to go to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
101 */
12538
6e39a114ed49 (svn r16976) -Codechange: remove WaypointID and MAX_LENGTH constants in favour of their Station variants
rubidium <rubidium@openttd.org>
parents: 12510
diff changeset
102 void Order::MakeGoToWaypoint(StationID destination)
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
103 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
104 this->type = OT_GOTO_WAYPOINT;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
105 this->flags = 0;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
106 this->dest = destination;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
107 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
108
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
109 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
110 * Makes this order a Loading order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
111 * @param ordered is this an ordered stop?
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
112 */
8843
1f412a20da48 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents: 8840
diff changeset
113 void Order::MakeLoading(bool ordered)
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
114 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
115 this->type = OT_LOADING;
8843
1f412a20da48 (svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents: 8840
diff changeset
116 if (!ordered) this->flags = 0;
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
117 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
118
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
119 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
120 * Makes this order a Leave Station order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
121 */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
122 void Order::MakeLeaveStation()
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
123 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
124 this->type = OT_LEAVESTATION;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
125 this->flags = 0;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
126 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
127
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
128 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
129 * Makes this order a Dummy order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
130 */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
131 void Order::MakeDummy()
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
132 {
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
133 this->type = OT_DUMMY;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
134 this->flags = 0;
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
135 }
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
136
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
137 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
138 * Makes this order an conditional order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
139 * @param order the order to jump to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
140 */
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
141 void Order::MakeConditional(VehicleOrderID order)
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
142 {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
143 this->type = OT_CONDITIONAL;
8901
f30afabf2b45 (svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium <rubidium@openttd.org>
parents: 8900
diff changeset
144 this->flags = order;
f30afabf2b45 (svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium <rubidium@openttd.org>
parents: 8900
diff changeset
145 this->dest = 0;
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
146 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
147
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
148 /**
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
149 * Makes this order an implicit order.
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
150 * @param destination the station to go to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
151 */
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
152 void Order::MakeImplicit(StationID destination)
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
153 {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
154 this->type = OT_IMPLICIT;
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
155 this->dest = destination;
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
156 }
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
157
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
158 /**
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
159 * Make this depot/station order also a refit order.
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
160 * @param cargo the cargo type to change to.
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
161 * @pre IsType(OT_GOTO_DEPOT) || IsType(OT_GOTO_STATION).
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
162 */
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
163 void Order::SetRefit(CargoID cargo)
8838
db9c6b0c9f07 (svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents: 8836
diff changeset
164 {
db9c6b0c9f07 (svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents: 8836
diff changeset
165 this->refit_cargo = cargo;
db9c6b0c9f07 (svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents: 8836
diff changeset
166 }
db9c6b0c9f07 (svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents: 8836
diff changeset
167
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
168 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
169 * Does this order have the same type, flags and destination?
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
170 * @param other the second order to compare to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
171 * @return true if the type, flags and destination match.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
172 */
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
173 bool Order::Equals(const Order &other) const
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
174 {
10365
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
175 /* In case of go to nearest depot orders we need "only" compare the flags
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
176 * with the other and not the nearest depot order bit or the actual
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
177 * destination because those get clear/filled in during the order
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
178 * evaluation. If we do not do this the order will continuously be seen as
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
179 * a different order and it will try to find a "nearest depot" every tick. */
15819
6a1b604d137f (svn r20498) -Fix [FS#4030]: ignore the non-stop state when comparing one order type to another order type
rubidium <rubidium@openttd.org>
parents: 15767
diff changeset
180 if ((this->IsType(OT_GOTO_DEPOT) && this->type == other.type) &&
10365
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
181 ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0 ||
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
182 (other.GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0)) {
16547
a11cd939c335 (svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents: 15916
diff changeset
183 return this->GetDepotOrderType() == other.GetDepotOrderType() &&
a11cd939c335 (svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents: 15916
diff changeset
184 (this->GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) == (other.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT);
10365
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
185 }
8a6982cd3a55 (svn r14616) -Fix [FS#2424]: a nearest depot order should be "equal" to the resolved nearest depot order; otherwise we keep resolving the nearest depot order every tick.
rubidium <rubidium@openttd.org>
parents: 10350
diff changeset
186
16547
a11cd939c335 (svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents: 15916
diff changeset
187 return this->type == other.type && this->flags == other.flags && this->dest == other.dest;
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
188 }
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
189
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
190 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
191 * Pack this order into a 32 bits integer, or actually only
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
192 * the type, flags and destination.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
193 * @return the packed representation.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
194 * @note unpacking is done in the constructor.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
195 */
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
196 uint32 Order::Pack() const
8834
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
197 {
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
198 return this->dest << 16 | this->flags << 8 | this->type;
8834
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
199 }
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
200
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
201 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
202 * Pack this order into a 16 bits integer as close to the TTD
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
203 * representation as possible.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
204 * @return the TTD-like packed representation.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
205 */
12199
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
206 uint16 Order::MapOldOrder() const
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
207 {
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
208 uint16 order = this->GetType();
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
209 switch (this->type) {
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
210 case OT_GOTO_STATION:
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
211 if (this->GetUnloadType() & OUFB_UNLOAD) SetBit(order, 5);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
212 if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
213 if (this->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) SetBit(order, 7);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
214 order |= GB(this->GetDestination(), 0, 8) << 8;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
215 break;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
216 case OT_GOTO_DEPOT:
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
217 if (!(this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) SetBit(order, 6);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
218 SetBit(order, 7);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
219 order |= GB(this->GetDestination(), 0, 8) << 8;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
220 break;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
221 case OT_LOADING:
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
222 if (this->GetLoadType() & OLFB_FULL_LOAD) SetBit(order, 6);
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
223 break;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
224 }
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
225 return order;
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
226 }
8e20cb543b87 (svn r16613) -Fix [NewGRF]: some of the var action 2 80+ variables contained wrong results due to OpenTTD codechanges
yexo <yexo@openttd.org>
parents: 12114
diff changeset
227
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
228 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
229 * Create an order based on a packed representation of that order.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
230 * @param packed the packed representation.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
231 */
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
232 Order::Order(uint32 packed)
8834
a2a57c9df9c9 (svn r12582) -Codechange: move some (needlessly) static inlined functions from order_base.h to order_cmd.cpp.
rubidium <rubidium@openttd.org>
parents: 8833
diff changeset
233 {
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
234 this->type = (OrderType)GB(packed, 0, 8);
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
235 this->flags = GB(packed, 8, 8);
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
236 this->dest = GB(packed, 16, 16);
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
237 this->next = NULL;
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
238 this->refit_cargo = CT_NO_REFIT;
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
239 this->wait_time = 0;
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
240 this->travel_time = 0;
19093
38652cadf0fe (svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents: 19003
diff changeset
241 this->max_speed = UINT16_MAX;
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
242 }
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
243
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
244 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
245 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
246 * Updates the widgets of a vehicle which contains the order-data
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
247 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
248 */
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
249 void InvalidateVehicleOrder(const Vehicle *v, int data)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
250 {
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
251 SetWindowDirty(WC_VEHICLE_VIEW, v->index);
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
252
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
253 if (data != 0) {
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
254 /* Calls SetDirty() too */
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
255 InvalidateWindowData(WC_VEHICLE_ORDERS, v->index, data);
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
256 InvalidateWindowData(WC_VEHICLE_TIMETABLE, v->index, data);
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
257 return;
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
258 }
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
259
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
260 SetWindowDirty(WC_VEHICLE_ORDERS, v->index);
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
261 SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
262 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 *
14136
54dfd3720fa1 (svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents: 14113
diff changeset
266 * Assign data to an order (from another order)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
267 * This function makes sure that the index is maintained correctly
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
268 * @param other the data to copy (except next pointer).
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
269 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
270 */
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
271 void Order::AssignOrder(const Order &other)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272 {
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
273 this->type = other.type;
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
274 this->flags = other.flags;
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
275 this->dest = other.dest;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
276
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
277 this->refit_cargo = other.refit_cargo;
6980
cb6b3e277df0 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents: 6950
diff changeset
278
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
279 this->wait_time = other.wait_time;
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
280 this->travel_time = other.travel_time;
19093
38652cadf0fe (svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents: 19003
diff changeset
281 this->max_speed = other.max_speed;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
282 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
284 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
285 * Recomputes everything.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
286 * @param chain first order in the chain
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
287 * @param v one of vehicle that is using this orderlist
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
288 */
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
289 void OrderList::Initialize(Order *chain, Vehicle *v)
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
290 {
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
291 this->first = chain;
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
292 this->first_shared = v;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
294 this->num_orders = 0;
16909
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
295 this->num_manual_orders = 0;
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
296 this->num_vehicles = 1;
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
297 this->timetable_duration = 0;
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
298
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
299 for (Order *o = this->first; o != NULL; o = o->next) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
300 ++this->num_orders;
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
301 if (!o->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
302 this->timetable_duration += o->wait_time + o->travel_time;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
303 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
304
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
305 for (Vehicle *u = this->first_shared->PreviousShared(); u != NULL; u = u->PreviousShared()) {
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
306 ++this->num_vehicles;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
307 this->first_shared = u;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
308 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
309
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
310 for (const Vehicle *u = v->NextShared(); u != NULL; u = u->NextShared()) ++this->num_vehicles;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
311 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
312
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
313 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
314 * Free a complete order chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
315 * @param keep_orderlist If this is true only delete the orders, otherwise also delete the OrderList.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
316 * @note do not use on "current_order" vehicle orders!
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
317 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
318 void OrderList::FreeChain(bool keep_orderlist)
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
319 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
320 Order *next;
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
321 for (Order *o = this->first; o != NULL; o = next) {
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
322 next = o->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
323 delete o;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
324 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
325
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
326 if (keep_orderlist) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
327 this->first = NULL;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
328 this->num_orders = 0;
16909
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
329 this->num_manual_orders = 0;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
330 this->timetable_duration = 0;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
331 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
332 delete this;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
333 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
334 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
335
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
336 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
337 * Get a certain order of the order chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
338 * @param index zero-based index of the order within the chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
339 * @return the order at position index.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
340 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
341 Order *OrderList::GetOrderAt(int index) const
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
342 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
343 if (index < 0) return NULL;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
344
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
345 Order *order = this->first;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
346
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15040
diff changeset
347 while (order != NULL && index-- > 0) {
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
348 order = order->next;
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15040
diff changeset
349 }
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
350 return order;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
351 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
352
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
353 /**
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
354 * Choose between the two possible next orders so that the given consist can
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
355 * load most cargo.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
356 * @param v Head of the consist.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
357 * @param o1 First order to choose from.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
358 * @param o2 Second order to choose from.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
359 * @return Either o1 or o2, depending on the amounts of cargo waiting at the
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
360 * vehicle's current station for each.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
361 */
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
362 const Order *OrderList::GetBestLoadableNext(const Vehicle *v, const Order *o2, const Order *o1) const
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
363 {
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
364 SmallMap<CargoID, uint> capacities;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
365 v->GetConsistFreeCapacities(capacities);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
366 uint loadable1 = 0;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
367 uint loadable2 = 0;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
368 StationID st1 = o1->GetDestination();
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
369 StationID st2 = o2->GetDestination();
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
370 const Station *cur_station = Station::Get(v->last_station_visited);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
371 for (SmallPair<CargoID, uint> *i = capacities.Begin(); i != capacities.End(); ++i) {
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
372 const StationCargoPacketMap *loadable_packets = cur_station->goods[i->first].cargo.Packets();
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
373 uint loadable_cargo = 0;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
374 std::pair<StationCargoPacketMap::const_iterator, StationCargoPacketMap::const_iterator> p =
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
375 loadable_packets->equal_range(st1);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
376 for (StationCargoPacketMap::const_iterator j = p.first; j != p.second; ++j) {
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
377 loadable_cargo = (*j)->Count();
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
378 }
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
379 loadable1 += min(i->second, loadable_cargo);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
380
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
381 loadable_cargo = 0;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
382 p = loadable_packets->equal_range(st2);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
383 for (StationCargoPacketMap::const_iterator j = p.first; j != p.second; ++j) {
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
384 loadable_cargo = (*j)->Count();
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
385 }
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
386 loadable2 += min(i->second, loadable_cargo);
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
387 }
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
388 if (loadable1 == loadable2) return RandomRange(2) == 0 ? o1 : o2;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
389 return loadable1 > loadable2 ? o1 : o2;
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
390 }
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
391
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
392 /**
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
393 * Get the next order which will make the given vehicle stop at a station
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
394 * or refit at a depot if its state doesn't change.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
395 * @param v The vehicle in question.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
396 * @param next The order to start looking at.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
397 * @param hops The number of orders we have already looked at.
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
398 * @param is_loading If the vehicle is loading. This triggers a different
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
399 * behaviour on conditional orders based on load percentage.
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
400 * @return Either an order or NULL if the vehicle won't stop anymore.
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
401 * @see OrderList::GetBestLoadableNext
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
402 */
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
403 const Order *OrderList::GetNextStoppingOrder(const Vehicle *v, const Order *next, uint hops, bool is_loading) const
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
404 {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
405 if (hops > this->GetNumOrders() || next == NULL) return NULL;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
406
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
407 if (next->IsType(OT_CONDITIONAL)) {
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
408 if (is_loading && next->GetConditionVariable() == OCV_LOAD_PERCENTAGE) {
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
409 /* If the condition is based on load percentage we can't
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
410 * tell what it will do. So we choose randomly. */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
411 const Order *skip_to = this->GetNextStoppingOrder(v,
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
412 this->GetOrderAt(next->GetConditionSkipToOrder()),
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
413 hops + 1);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
414 const Order *advance = this->GetNextStoppingOrder(v,
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
415 this->GetNext(next), hops + 1);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
416 if (advance == NULL) return skip_to;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
417 if (skip_to == NULL) return advance;
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
418 return this->GetBestLoadableNext(v, skip_to, advance);
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
419 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
420 /* Otherwise we're optimistic and expect that the
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
421 * condition value won't change until it's evaluated. */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
422 VehicleOrderID skip_to = ProcessConditionalOrder(next, v);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
423 if (skip_to != INVALID_VEH_ORDER_ID) {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
424 return this->GetNextStoppingOrder(v, this->GetOrderAt(skip_to),
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
425 hops + 1);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
426 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
427 return this->GetNextStoppingOrder(v, this->GetNext(next), hops + 1);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
428 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
429
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
430 if (next->IsType(OT_GOTO_DEPOT)) {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
431 if (next->GetDepotActionType() == ODATFB_HALT) return NULL;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
432 if (next->IsRefit()) return next;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
433 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
434
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
435 if (!next->CanLoadOrUnload()) {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
436 return this->GetNextStoppingOrder(v, this->GetNext(next), hops + 1);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
437 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
438
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
439 return next;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
440 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
441
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
442 /**
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
443 * Recursively determine the next deterministic station to stop at.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
444 * @param v The vehicle we're looking at.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
445 * @return Next stoppping station or INVALID_STATION.
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
446 * @pre The vehicle is currently loading and v->last_station_visited is meaningful.
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
447 * @note This function may draw a random number. Don't use it from the GUI.
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
448 */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
449 StationID OrderList::GetNextStoppingStation(const Vehicle *v) const
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
450 {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
451
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
452 const Order *next = this->GetOrderAt(v->cur_implicit_order_index);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
453 if (next == NULL) {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
454 next = this->GetFirstOrder();
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
455 if (next == NULL) return INVALID_STATION;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
456 } else {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
457 /* GetNext never returns NULL if there is a valid station in the list.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
458 * As the given "next" is already valid and a station in the list, we
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
459 * don't have to check for NULL here.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
460 */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
461 next = this->GetNext(next);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
462 assert(next != NULL);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
463 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
464
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
465 uint hops = 0;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
466 do {
20403
100fee8ec68e (svn r25361) -Feature: distribute cargo according to plan given by linkgraph
fonsinchen <fonsinchen@openttd.org>
parents: 20307
diff changeset
467 next = this->GetNextStoppingOrder(v, next, ++hops, true);
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
468 /* Don't return a next stop if the vehicle has to unload everything. */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
469 if (next == NULL || (next->GetDestination() == v->last_station_visited &&
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
470 (next->GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) == 0)) {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
471 return INVALID_STATION;
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
472 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
473 } while (next->IsType(OT_GOTO_DEPOT) || next->GetDestination() == v->last_station_visited);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
474
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
475 return next->GetDestination();
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
476 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
477
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
478 /**
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
479 * Insert a new order into the order chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
480 * @param new_order is the order to insert into the chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
481 * @param index is the position where the order is supposed to be inserted.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
482 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
483 void OrderList::InsertOrderAt(Order *new_order, int index)
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
484 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
485 if (this->first == NULL) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
486 this->first = new_order;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
487 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
488 if (index == 0) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
489 /* Insert as first or only order */
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
490 new_order->next = this->first;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
491 this->first = new_order;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
492 } else if (index >= this->num_orders) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
493 /* index is after the last order, add it to the end */
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
494 this->GetLastOrder()->next = new_order;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
495 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
496 /* Put the new order in between */
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
497 Order *order = this->GetOrderAt(index - 1);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
498 new_order->next = order->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
499 order->next = new_order;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
500 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
501 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
502 ++this->num_orders;
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
503 if (!new_order->IsType(OT_IMPLICIT)) ++this->num_manual_orders;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
504 this->timetable_duration += new_order->wait_time + new_order->travel_time;
18363
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
505
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
506 /* We can visit oil rigs and buoys that are not our own. They will be shown in
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
507 * the list of stations. So, we need to invalidate that window if needed. */
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
508 if (new_order->IsType(OT_GOTO_STATION) || new_order->IsType(OT_GOTO_WAYPOINT)) {
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
509 BaseStation *bs = BaseStation::Get(new_order->GetDestination());
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
510 if (bs->owner == OWNER_NONE) InvalidateWindowClassesData(WC_STATION_LIST, 0);
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
511 }
ca42abca1267 (svn r23199) -Fix [FS#4822]: oil rigs that "expired" did not get removed from the station list
rubidium <rubidium@openttd.org>
parents: 18251
diff changeset
512
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
513 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
514
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
515
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
516 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
517 * Remove an order from the order list and delete it.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
518 * @param index is the position of the order which is to be deleted.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
519 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
520 void OrderList::DeleteOrderAt(int index)
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
521 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
522 if (index >= this->num_orders) return;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
523
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
524 Order *to_remove;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
525
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
526 if (index == 0) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
527 to_remove = this->first;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
528 this->first = to_remove->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
529 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
530 Order *prev = GetOrderAt(index - 1);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
531 to_remove = prev->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
532 prev->next = to_remove->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
533 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
534 --this->num_orders;
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
535 if (!to_remove->IsType(OT_IMPLICIT)) --this->num_manual_orders;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
536 this->timetable_duration -= (to_remove->wait_time + to_remove->travel_time);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
537 delete to_remove;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
538 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
539
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
540 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
541 * Move an order to another position within the order list.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
542 * @param from is the zero-based position of the order to move.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
543 * @param to is the zero-based position where the order is moved to.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
544 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
545 void OrderList::MoveOrder(int from, int to)
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
546 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
547 if (from >= this->num_orders || to >= this->num_orders || from == to) return;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
548
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
549 Order *moving_one;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
550
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
551 /* Take the moving order out of the pointer-chain */
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
552 if (from == 0) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
553 moving_one = this->first;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
554 this->first = moving_one->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
555 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
556 Order *one_before = GetOrderAt(from - 1);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
557 moving_one = one_before->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
558 one_before->next = moving_one->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
559 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
560
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
561 /* Insert the moving_order again in the pointer-chain */
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
562 if (to == 0) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
563 moving_one->next = this->first;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
564 this->first = moving_one;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
565 } else {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
566 Order *one_before = GetOrderAt(to - 1);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
567 moving_one->next = one_before->next;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
568 one_before->next = moving_one;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
569 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
570 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
571
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
572 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
573 * Removes the vehicle from the shared order list.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
574 * @note This is supposed to be called when the vehicle is still in the chain
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
575 * @param v vehicle to remove from the list
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
576 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
577 void OrderList::RemoveVehicle(Vehicle *v)
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
578 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
579 --this->num_vehicles;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
580 if (v == this->first_shared) this->first_shared = v->NextShared();
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
581 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
582
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
583 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
584 * Checks whether a vehicle is part of the shared vehicle chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
585 * @param v is the vehicle to search in the shared vehicle chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
586 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
587 bool OrderList::IsVehicleInSharedOrdersList(const Vehicle *v) const
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
588 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
589 for (const Vehicle *v_shared = this->first_shared; v_shared != NULL; v_shared = v_shared->NextShared()) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
590 if (v_shared == v) return true;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
591 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
592
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
593 return false;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
594 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
595
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
596 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
597 * Gets the position of the given vehicle within the shared order vehicle list.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
598 * @param v is the vehicle of which to get the position
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
599 * @return position of v within the shared vehicle chain.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
600 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
601 int OrderList::GetPositionInSharedOrderList(const Vehicle *v) const
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
602 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
603 int count = 0;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
604 for (const Vehicle *v_shared = v->PreviousShared(); v_shared != NULL; v_shared = v_shared->PreviousShared()) count++;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
605 return count;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
606 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
607
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
608 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
609 * Checks whether all orders of the list have a filled timetable.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
610 * @return whether all orders have a filled timetable.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
611 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
612 bool OrderList::IsCompleteTimetable() const
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
613 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
614 for (Order *o = this->first; o != NULL; o = o->next) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
615 /* Implicit orders are, by definition, not timetabled. */
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
616 if (o->IsType(OT_IMPLICIT)) continue;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
617 if (!o->IsCompletelyTimetabled()) return false;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
618 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
619 return true;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
620 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
621
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
622 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
623 * Checks for internal consistency of order list. Triggers assertion if something is wrong.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
624 */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
625 void OrderList::DebugCheckSanity() const
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
626 {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
627 VehicleOrderID check_num_orders = 0;
16909
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
628 VehicleOrderID check_num_manual_orders = 0;
10556
bb3057c7eed7 (svn r14813) -Codechange: use uint instead of 'just' unsigned.
rubidium <rubidium@openttd.org>
parents: 10546
diff changeset
629 uint check_num_vehicles = 0;
13679
91229a735ec1 (svn r18204) -Codechange: introduce a type for Ticks and use it; furthermore document some related variables/functions
rubidium <rubidium@openttd.org>
parents: 13466
diff changeset
630 Ticks check_timetable_duration = 0;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
631
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
632 DEBUG(misc, 6, "Checking OrderList %hu for sanity...", this->index);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
633
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
634 for (const Order *o = this->first; o != NULL; o = o->next) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
635 ++check_num_orders;
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
636 if (!o->IsType(OT_IMPLICIT)) ++check_num_manual_orders;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
637 check_timetable_duration += o->wait_time + o->travel_time;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
638 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
639 assert(this->num_orders == check_num_orders);
16909
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
640 assert(this->num_manual_orders == check_num_manual_orders);
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
641 assert(this->timetable_duration == check_timetable_duration);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
642
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
643 for (const Vehicle *v = this->first_shared; v != NULL; v = v->NextShared()) {
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
644 ++check_num_vehicles;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
645 assert(v->orders.list == this);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
646 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
647 assert(this->num_vehicles == check_num_vehicles);
16909
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
648 DEBUG(misc, 6, "... detected %u orders (%u manual), %u vehicles, %i ticks",
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
649 (uint)this->num_orders, (uint)this->num_manual_orders,
c9e234b35f82 (svn r21644) -Change: keep showing "No orders" when the order list is filled with only automatic orders
rubidium <rubidium@openttd.org>
parents: 16907
diff changeset
650 this->num_vehicles, this->timetable_duration);
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
651 }
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
652
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
653 /**
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
654 * Checks whether the order goes to a station or not, i.e. whether the
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
655 * destination is a station
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
656 * @param v the vehicle to check for
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
657 * @param o the order to check
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
658 * @return true if the destination is a station
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
659 */
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
660 static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
661 {
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
662 return o->IsType(OT_GOTO_STATION) ||
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
663 (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
664 }
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
665
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
666 /**
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
667 * Delete all news items regarding defective orders about a vehicle
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
668 * This could kill still valid warnings (for example about void order when just
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10184
diff changeset
669 * another order gets added), but assume the company will notice the problems,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
670 * when (s)he's changing the orders.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
671 */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10582
diff changeset
672 static void DeleteOrderWarnings(const Vehicle *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
673 {
12619
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12538
diff changeset
674 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS);
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12538
diff changeset
675 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_VOID_ORDER);
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12538
diff changeset
676 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY);
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12538
diff changeset
677 DeleteVehicleNews(v->index, STR_NEWS_VEHICLE_HAS_INVALID_ENTRY);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
678 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
679
14638
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
680 /**
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
681 * Returns a tile somewhat representing the order destination (not suitable for pathfinding).
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
682 * @param v The vehicle to get the location for.
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
683 * @param airport Get the airport tile and not the station location for aircraft.
14638
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
684 * @return destination of order, or INVALID_TILE if none.
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
685 */
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
686 TileIndex Order::GetLocation(const Vehicle *v, bool airport) const
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
687 {
14638
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
688 switch (this->GetType()) {
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
689 case OT_GOTO_WAYPOINT:
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
690 case OT_GOTO_STATION:
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
691 case OT_IMPLICIT:
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
692 if (airport && v->type == VEH_AIRCRAFT) return Station::Get(this->GetDestination())->airport.tile;
14638
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
693 return BaseStation::Get(this->GetDestination())->xy;
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
694
14633
31e99b467d35 (svn r19210) -Fix: GetDestination() is invalid for nearest-depot orders.
frosch <frosch@openttd.org>
parents: 14258
diff changeset
695 case OT_GOTO_DEPOT:
14638
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
696 if ((this->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return INVALID_TILE;
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
697 return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination())->xy : Depot::Get(this->GetDestination())->xy;
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
698
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
699 default:
82bfab312c8e (svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents: 14633
diff changeset
700 return INVALID_TILE;
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
701 }
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
702 }
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
703
18657
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
704 /**
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
705 * Get the distance between two orders of a vehicle. Conditional orders are resolved
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
706 * and the bigger distance of the two order branches is returned.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
707 * @param prev Origin order.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
708 * @param cur Destination order.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
709 * @param v The vehicle to get the distance for.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
710 * @param conditional_depth Internal param for resolving conditional orders.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
711 * @return Maximum distance between the two orders.
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
712 */
599d7cf176cf (svn r23505) -Add: Indication in the order list if the next destination of an order is out of range.
michi_cc <michi_cc@openttd.org>
parents: 18656
diff changeset
713 uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
9609
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
714 {
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
715 if (cur->IsType(OT_CONDITIONAL)) {
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
716 if (conditional_depth > v->GetNumOrders()) return 0;
9609
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
717
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
718 conditional_depth++;
10131
31d04d81597e (svn r14317) -Fix (r13662) [FS#2298]: Order distance processing for conditional orders on ships treated v->orders as an array, and didn't use the correct next order.
peter1138 <peter1138@openttd.org>
parents: 10020
diff changeset
719
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11983
diff changeset
720 int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
721 int dist2 = GetOrderDistance(prev, cur->next == NULL ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
10131
31d04d81597e (svn r14317) -Fix (r13662) [FS#2298]: Order distance processing for conditional orders on ships treated v->orders as an array, and didn't use the correct next order.
peter1138 <peter1138@openttd.org>
parents: 10020
diff changeset
722 return max(dist1, dist2);
9609
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
723 }
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
724
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
725 TileIndex prev_tile = prev->GetLocation(v, true);
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
726 TileIndex cur_tile = cur->GetLocation(v, true);
14633
31e99b467d35 (svn r19210) -Fix: GetDestination() is invalid for nearest-depot orders.
frosch <frosch@openttd.org>
parents: 14258
diff changeset
727 if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
728 return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
9609
fe9766039f5b (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents: 9593
diff changeset
729 }
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
730
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
731 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
732 * Add an order to the orderlist of a vehicle.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
733 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
734 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
735 * @param p1 various bitstuffed elements
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
736 * - p1 = (bit 0 - 19) - ID of the vehicle
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
737 * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
738 * the order will be inserted before that one
10993
8bb5d1f28e00 (svn r15333) -Fix: AIs weren't restricted to a maximum length for ship orders.
Yexo <Yexo@openttd.org>
parents: 10969
diff changeset
739 * the maximum vehicle order id is 254.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
740 * @param p2 packed order to insert
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
741 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
742 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
743 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
744 CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
745 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
746 VehicleID veh = GB(p1, 0, 20);
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
747 VehicleOrderID sel_ord = GB(p1, 20, 8);
8839
ebb630745ebc (svn r12587) -Codechange: unduplicate some code in the Unpack*Order functions and move the 'normal' case Pack/Unpack to Order.
rubidium <rubidium@openttd.org>
parents: 8838
diff changeset
748 Order new_order(p2);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
749
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
750 Vehicle *v = Vehicle::GetIfValid(veh);
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
751 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
752
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
753 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
754 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
755
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
756 /* Check if the inserted order is to the correct destination (owner, type),
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
757 * and has the correct flags if any */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
758 switch (new_order.GetType()) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
759 case OT_GOTO_STATION: {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
760 const Station *st = Station::GetIfValid(new_order.GetDestination());
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
761 if (st == NULL) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
762
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
763 if (st->owner != OWNER_NONE) {
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
764 CommandCost ret = CheckOwnership(st->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
765 if (ret.Failed()) return ret;
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
766 }
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
767
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
768 if (!CanVehicleUseStation(v, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
769 for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
770 if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
771 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
772
16783
37b5683941fa (svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents: 16733
diff changeset
773 /* Non stop only allowed for ground vehicles. */
37b5683941fa (svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents: 16733
diff changeset
774 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
8845
bb04cb5677d8 (svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium <rubidium@openttd.org>
parents: 8843
diff changeset
775
8856
95480237d10c (svn r12618) -Codechange: as load and unload type are now split, some case statements got ugly.
rubidium <rubidium@openttd.org>
parents: 8855
diff changeset
776 /* Filter invalid load/unload types. */
8873
9780f2a6cd20 (svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents: 8872
diff changeset
777 switch (new_order.GetLoadType()) {
9090
eaa19756eb5b (svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium <rubidium@openttd.org>
parents: 9076
diff changeset
778 case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break;
8873
9780f2a6cd20 (svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents: 8872
diff changeset
779 default: return CMD_ERROR;
9780f2a6cd20 (svn r12640) -Codechange: let GetLoadType make a difference between full load and full load any based on the patch setting instead of using the patch setting directly.
rubidium <rubidium@openttd.org>
parents: 8872
diff changeset
780 }
9090
eaa19756eb5b (svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium <rubidium@openttd.org>
parents: 9076
diff changeset
781 switch (new_order.GetUnloadType()) {
eaa19756eb5b (svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium <rubidium@openttd.org>
parents: 9076
diff changeset
782 case OUF_UNLOAD_IF_POSSIBLE: case OUFB_UNLOAD: case OUFB_TRANSFER: case OUFB_NO_UNLOAD: break;
eaa19756eb5b (svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium <rubidium@openttd.org>
parents: 9076
diff changeset
783 default: return CMD_ERROR;
eaa19756eb5b (svn r12949) -Fix [FS#1978]: no loading/no unloading orders were 'forgotten' during manual replaces.
rubidium <rubidium@openttd.org>
parents: 9076
diff changeset
784 }
11657
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
785
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
786 /* Filter invalid stop locations */
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
787 switch (new_order.GetStopLocation()) {
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
788 case OSL_PLATFORM_NEAR_END:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
789 case OSL_PLATFORM_MIDDLE:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
790 if (v->type != VEH_TRAIN) return CMD_ERROR;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
791 /* FALL THROUGH */
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
792 case OSL_PLATFORM_FAR_END:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
793 break;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
794
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
795 default:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
796 return CMD_ERROR;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
797 }
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
798
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
799 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
800 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
801
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
802 case OT_GOTO_DEPOT: {
15767
293a91934c7d (svn r20441) -Fix [FS#4024]: adding "goto nearest depot and stop" orders in one go was denied. This caused both AI adding those orders and backed up order restoration to fail.
rubidium <rubidium@openttd.org>
parents: 15620
diff changeset
803 if ((new_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) == 0) {
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
804 if (v->type == VEH_AIRCRAFT) {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
805 const Station *st = Station::GetIfValid(new_order.GetDestination());
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
806
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
807 if (st == NULL) return CMD_ERROR;
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
808
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
809 CommandCost ret = CheckOwnership(st->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
810 if (ret.Failed()) return ret;
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
811
14867
d2be152e6d09 (svn r19463) -Codechange: add helper function to determine if an airport has at least one hangar
yexo <yexo@openttd.org>
parents: 14859
diff changeset
812 if (!CanVehicleUseStation(v, st) || !st->airport.HasHangar()) {
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
813 return CMD_ERROR;
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
814 }
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
815 } else {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
816 const Depot *dp = Depot::GetIfValid(new_order.GetDestination());
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
817
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
818 if (dp == NULL) return CMD_ERROR;
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
819
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
820 CommandCost ret = CheckOwnership(GetTileOwner(dp->xy));
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
821 if (ret.Failed()) return ret;
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
822
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
823 switch (v->type) {
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
824 case VEH_TRAIN:
8961
b33bcd7fa037 (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents: 8954
diff changeset
825 if (!IsRailDepotTile(dp->xy)) return CMD_ERROR;
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
826 break;
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
827
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
828 case VEH_ROAD:
8961
b33bcd7fa037 (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents: 8954
diff changeset
829 if (!IsRoadDepotTile(dp->xy)) return CMD_ERROR;
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
830 break;
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
831
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
832 case VEH_SHIP:
8961
b33bcd7fa037 (svn r12753) -Codechange: do not use IsDepotTypeTile() where simpler function can be used
smatz <smatz@openttd.org>
parents: 8954
diff changeset
833 if (!IsShipDepotTile(dp->xy)) return CMD_ERROR;
8894
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
834 break;
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
835
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
836 default: return CMD_ERROR;
2bcad37f1d27 (svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents: 8885
diff changeset
837 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
838 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
839 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
840
16783
37b5683941fa (svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents: 16733
diff changeset
841 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
9593
96017719e61f (svn r13633) -Fix: restoring 'service at depot X' orders from the order backup failed.
rubidium <rubidium@openttd.org>
parents: 9559
diff changeset
842 if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
11719
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11680
diff changeset
843 if (new_order.GetDepotActionType() & ~(ODATFB_HALT | ODATFB_NEAREST_DEPOT)) return CMD_ERROR;
15d3dd64a19b (svn r16107) -Add [NoAI]: AIOF_STOP_IN_DEPOT to the orderflags in AIOrder to allow stop-in-depot orders
yexo <yexo@openttd.org>
parents: 11680
diff changeset
844 if ((new_order.GetDepotOrderType() & ODTFB_SERVICE) && (new_order.GetDepotActionType() & ODATFB_HALT)) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
845 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
846 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
847
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
848 case OT_GOTO_WAYPOINT: {
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
849 const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
850 if (wp == NULL) return CMD_ERROR;
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
851
12361
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
852 switch (v->type) {
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
853 default: return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
854
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
855 case VEH_TRAIN: {
13883
8a9a3fcfabe6 (svn r18412) -Fix [FS#3350]: don't allow sending ships to rail waypoints and trains to buyos (Hirundo)
smatz <smatz@openttd.org>
parents: 13875
diff changeset
856 if (!(wp->facilities & FACIL_TRAIN)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
857
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
858 CommandCost ret = CheckOwnership(wp->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
859 if (ret.Failed()) return ret;
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
860 break;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
861 }
12361
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
862
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
863 case VEH_SHIP:
13883
8a9a3fcfabe6 (svn r18412) -Fix [FS#3350]: don't allow sending ships to rail waypoints and trains to buyos (Hirundo)
smatz <smatz@openttd.org>
parents: 13875
diff changeset
864 if (!(wp->facilities & FACIL_DOCK)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER);
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
865 if (wp->owner != OWNER_NONE) {
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
866 CommandCost ret = CheckOwnership(wp->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
867 if (ret.Failed()) return ret;
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
868 }
12472
604a2cfc77ab (svn r16909) -Fix [FS#2996]: NewGRF stations would be triggering assertions all over the place when using the more advanced station types.
rubidium <rubidium@openttd.org>
parents: 12377
diff changeset
869 break;
12361
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
870 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
871
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
872 /* Order flags can be any of the following for waypoints:
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
873 * [non-stop]
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
874 * non-stop orders (if any) are only valid for trains */
8881
4fd35184e35f (svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium <rubidium@openttd.org>
parents: 8874
diff changeset
875 if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
8863
84089dccec13 (svn r12630) -Fix (r12600): Missing 'break' made it impossible to add waypoints to vehicle orders.
maedhros <maedhros@openttd.org>
parents: 8862
diff changeset
876 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
877 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
878
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
879 case OT_CONDITIONAL: {
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
880 VehicleOrderID skip_to = new_order.GetConditionSkipToOrder();
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
881 if (skip_to != 0 && skip_to >= v->GetNumOrders()) return CMD_ERROR; // Always allow jumping to the first (even when there is no order).
18030
885fa3a8d835 (svn r22845) -Fix [FS#4745]: perform stricter checks on some commands (monoid)
rubidium <rubidium@openttd.org>
parents: 17829
diff changeset
882 if (new_order.GetConditionVariable() >= OCV_END) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
883
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
884 OrderConditionComparator occ = new_order.GetConditionComparator();
18030
885fa3a8d835 (svn r22845) -Fix [FS#4745]: perform stricter checks on some commands (monoid)
rubidium <rubidium@openttd.org>
parents: 17829
diff changeset
885 if (occ >= OCC_END) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
886 switch (new_order.GetConditionVariable()) {
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
887 case OCV_REQUIRES_SERVICE:
9666
172788f5a052 (svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium <rubidium@openttd.org>
parents: 9665
diff changeset
888 if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
889 break;
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
890
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
891 case OCV_UNCONDITIONALLY:
9666
172788f5a052 (svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium <rubidium@openttd.org>
parents: 9665
diff changeset
892 if (occ != OCC_EQUALS) return CMD_ERROR;
172788f5a052 (svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium <rubidium@openttd.org>
parents: 9665
diff changeset
893 if (new_order.GetConditionValue() != 0) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
894 break;
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
895
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
896 case OCV_LOAD_PERCENTAGE:
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
897 case OCV_RELIABILITY:
9666
172788f5a052 (svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium <rubidium@openttd.org>
parents: 9665
diff changeset
898 if (new_order.GetConditionValue() > 100) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
899 /* FALL THROUGH */
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
900 default:
9666
172788f5a052 (svn r13753) -Cleanup (r13752): save before commit instead of the other way around is usually better.
rubidium <rubidium@openttd.org>
parents: 9665
diff changeset
901 if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
902 break;
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
903 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
904 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
905 }
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
906
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
907 default: return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
908 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
909
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
910 if (sel_ord > v->GetNumOrders()) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
911
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
912 if (v->GetNumOrders() >= MAX_VEH_ORDER_ID) return_cmd_error(STR_ERROR_TOO_MANY_ORDERS);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
913 if (!Order::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
914 if (v->orders.list == NULL && !OrderList::CanAllocateItem()) return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
915
10993
8bb5d1f28e00 (svn r15333) -Fix: AIs weren't restricted to a maximum length for ship orders.
Yexo <Yexo@openttd.org>
parents: 10969
diff changeset
916 if (v->type == VEH_SHIP && _settings_game.pf.pathfinder_for_ships != VPF_NPF) {
8551
bfe75aee55ee (svn r12129) -Change [FS#1759]: simplified patch settings for pathfinders (Yorick)
smatz <smatz@openttd.org>
parents: 8469
diff changeset
917 /* Make sure the new destination is not too far away from the previous */
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
918 const Order *prev = NULL;
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
919 uint n = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
920
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
921 /* Find the last goto station or depot order before the insert location.
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
922 * If the order is to be inserted at the beginning of the order list this
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
923 * finds the last order in the list. */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
924 const Order *o;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
925 FOR_VEHICLE_ORDERS(v, o) {
12361
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
926 switch (o->GetType()) {
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
927 case OT_GOTO_STATION:
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
928 case OT_GOTO_DEPOT:
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
929 case OT_GOTO_WAYPOINT:
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
930 prev = o;
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
931 break;
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
932
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
933 default: break;
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
934 }
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
935 if (++n == sel_ord && prev != NULL) break;
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
936 }
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
937 if (prev != NULL) {
19003
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
938 uint dist;
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
939 if (new_order.IsType(OT_CONDITIONAL)) {
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
940 /* The order is not yet inserted, so we have to do the first iteration here. */
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
941 dist = GetOrderDistance(prev, v->GetOrder(new_order.GetConditionSkipToOrder()), v);
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
942 } else {
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
943 dist = GetOrderDistance(prev, &new_order, v);
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
944 }
3effafcdac97 (svn r23859) -Fix: Inserting conditional orders for ships checked the wrong orders wrt. maximum distance.
frosch <frosch@openttd.org>
parents: 18993
diff changeset
945
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
946 if (dist >= 130) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
947 return_cmd_error(STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION);
6071
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
948 }
0364a445b332 (svn r8802) -Fix
tron <tron@openttd.org>
parents: 6065
diff changeset
949 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
950 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
951
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
952 if (flags & DC_EXEC) {
7391
1b2a34c4f7fa (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7049
diff changeset
953 Order *new_o = new Order();
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
954 new_o->AssignOrder(new_order);
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
955 InsertOrder(v, new_o, sel_ord);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
956 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
957
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
958 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
959 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
960
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
961 /**
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
962 * Insert a new order but skip the validation.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
963 * @param v The vehicle to insert the order to.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
964 * @param new_o The new order.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
965 * @param sel_ord The position the order should be inserted at.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
966 */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
967 void InsertOrder(Vehicle *v, Order *new_o, VehicleOrderID sel_ord)
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
968 {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
969 /* Create new order and link in list */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
970 if (v->orders.list == NULL) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
971 v->orders.list = new OrderList(new_o, v);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
972 } else {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
973 v->orders.list->InsertOrderAt(new_o, sel_ord);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
974 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
975
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
976 Vehicle *u = v->FirstShared();
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
977 DeleteOrderWarnings(u);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
978 for (; u != NULL; u = u->NextShared()) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
979 assert(v->orders.list == u->orders.list);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
980
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
981 /* If there is added an order before the current one, we need
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
982 * to update the selected order. We do not change implicit/real order indices though.
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
983 * If the new order is between the current implicit order and real order, the implicit order will
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
984 * later skip the inserted order. */
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
985 if (sel_ord <= u->cur_real_order_index) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
986 uint cur = u->cur_real_order_index + 1;
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
987 /* Check if we don't go out of bound */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
988 if (cur < u->GetNumOrders()) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
989 u->cur_real_order_index = cur;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
990 }
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
991 }
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
992 if (sel_ord == u->cur_implicit_order_index && u->IsGroundVehicle()) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
993 /* We are inserting an order just before the current implicit order.
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
994 * We do not know whether we will reach current implicit or the newly inserted order first.
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
995 * So, disable creation of implicit orders until we are on track again. */
17567
3a23cb7f4a41 (svn r22331) -Change: When inserting an (automatic) order A in front of an order B, disable modifications of automatic orders for all vehicles currently heading for B as we do not know whether they will reach A or B first. (except for the vehicle causing the insertion of the automatic order itself)
frosch <frosch@openttd.org>
parents: 17566
diff changeset
996 uint16 &gv_flags = u->GetGroundVehicleFlags();
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
997 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
17567
3a23cb7f4a41 (svn r22331) -Change: When inserting an (automatic) order A in front of an order B, disable modifications of automatic orders for all vehicles currently heading for B as we do not know whether they will reach A or B first. (except for the vehicle causing the insertion of the automatic order itself)
frosch <frosch@openttd.org>
parents: 17566
diff changeset
998 }
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
999 if (sel_ord <= u->cur_implicit_order_index) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1000 uint cur = u->cur_implicit_order_index + 1;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1001 /* Check if we don't go out of bound */
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1002 if (cur < u->GetNumOrders()) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1003 u->cur_implicit_order_index = cur;
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1004 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1005 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1006 /* Update any possible open window of the vehicle */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1007 InvalidateVehicleOrder(u, INVALID_VEH_ORDER_ID | (sel_ord << 8));
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1008 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1009
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1010 /* As we insert an order, the order to skip to will be 'wrong'. */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1011 VehicleOrderID cur_order_id = 0;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1012 Order *order;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1013 FOR_VEHICLE_ORDERS(v, order) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1014 if (order->IsType(OT_CONDITIONAL)) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1015 VehicleOrderID order_id = order->GetConditionSkipToOrder();
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1016 if (order_id >= sel_ord) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1017 order->SetConditionSkipToOrder(order_id + 1);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1018 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1019 if (order_id == cur_order_id) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1020 order->SetConditionSkipToOrder((order_id + 1) % v->GetNumOrders());
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1021 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1022 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1023 cur_order_id++;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1024 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1025
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1026 /* Make sure to rebuild the whole list */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1027 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1028 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1029
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1030 /**
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1031 * Declone an order-list
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1032 * @param *dst delete the orders of this vehicle
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1033 * @param flags execution flags
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1034 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1035 static CommandCost DecloneOrder(Vehicle *dst, DoCommandFlag flags)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1036 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1037 if (flags & DC_EXEC) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1038 DeleteVehicleOrders(dst);
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1039 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9234
diff changeset
1040 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1041 }
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1042 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1043 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1044
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1045 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1046 * Delete an order from the orderlist of a vehicle.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1047 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1048 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1049 * @param p1 the ID of the vehicle
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1050 * @param p2 the order to delete (max 255)
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1051 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1052 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1053 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1054 CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1055 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1056 VehicleID veh_id = GB(p1, 0, 20);
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1057 VehicleOrderID sel_ord = GB(p2, 0, 8);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1058
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1059 Vehicle *v = Vehicle::GetIfValid(veh_id);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1060
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1061 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1062
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1063 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1064 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1065
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1066 /* If we did not select an order, we maybe want to de-clone the orders */
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15040
diff changeset
1067 if (sel_ord >= v->GetNumOrders()) return DecloneOrder(v, flags);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1068
16869
63f8b6eeb72c (svn r21603) -Codechange: no need to assign something to a variable and then test it for NULL when you're never using it again
rubidium <rubidium@openttd.org>
parents: 16868
diff changeset
1069 if (v->GetOrder(sel_ord) == NULL) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1070
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1071 if (flags & DC_EXEC) DeleteOrder(v, sel_ord);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1072 return CommandCost();
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1073 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1074
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1075 /**
17305
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1076 * Cancel the current loading order of the vehicle as the order was deleted.
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1077 * @param v the vehicle
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1078 */
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1079 static void CancelLoadingDueToDeletedOrder(Vehicle *v)
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1080 {
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1081 assert(v->current_order.IsType(OT_LOADING));
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1082 /* NON-stop flag is misused to see if a train is in a station that is
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1083 * on his order list or not */
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1084 v->current_order.SetNonStopType(ONSF_STOP_EVERYWHERE);
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1085 /* When full loading, "cancel" that order so the vehicle doesn't
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1086 * stay indefinitely at this station anymore. */
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1087 if (v->current_order.GetLoadType() & OLFB_FULL_LOAD) v->current_order.SetLoadType(OLF_LOAD_IF_POSSIBLE);
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1088 }
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1089
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1090 /**
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1091 * Delete an order but skip the parameter validation.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1092 * @param v The vehicle to delete the order from.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1093 * @param sel_ord The id of the order to be deleted.
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1094 */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1095 void DeleteOrder(Vehicle *v, VehicleOrderID sel_ord)
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1096 {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1097 v->orders.list->DeleteOrderAt(sel_ord);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1098
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1099 Vehicle *u = v->FirstShared();
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1100 DeleteOrderWarnings(u);
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1101 for (; u != NULL; u = u->NextShared()) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1102 assert(v->orders.list == u->orders.list);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1103
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1104 if (sel_ord == u->cur_real_order_index && u->current_order.IsType(OT_LOADING)) {
17305
d18df78fbeef (svn r22045) -Codechange: Move cancelling the current loading order on deleting the current order to a separate function.
frosch <frosch@openttd.org>
parents: 17284
diff changeset
1105 CancelLoadingDueToDeletedOrder(u);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1106 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1107
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1108 if (sel_ord < u->cur_real_order_index) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1109 u->cur_real_order_index--;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1110 } else if (sel_ord == u->cur_real_order_index) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1111 u->UpdateRealOrderIndex();
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1112 }
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1113
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1114 if (sel_ord < u->cur_implicit_order_index) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1115 u->cur_implicit_order_index--;
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1116 } else if (sel_ord == u->cur_implicit_order_index) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1117 /* Make sure the index is valid */
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1118 if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1119
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1120 /* Skip non-implicit orders for the implicit-order-index (e.g. if the current implicit order was deleted */
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1121 while (u->cur_implicit_order_index != u->cur_real_order_index && !u->GetOrder(u->cur_implicit_order_index)->IsType(OT_IMPLICIT)) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1122 u->cur_implicit_order_index++;
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1123 if (u->cur_implicit_order_index >= u->GetNumOrders()) u->cur_implicit_order_index = 0;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1124 }
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1125 }
17001
cda70a6d42ea (svn r21737) -Fix (r1)[FS#4384-ish]: A loading order was also marked as 'not part of orders' when the order before the current order was deleted.
frosch <frosch@openttd.org>
parents: 16909
diff changeset
1126
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1127 /* Update any possible open window of the vehicle */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1128 InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8));
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1129 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1130
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1131 /* As we delete an order, the order to skip to will be 'wrong'. */
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1132 VehicleOrderID cur_order_id = 0;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1133 Order *order = NULL;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1134 FOR_VEHICLE_ORDERS(v, order) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1135 if (order->IsType(OT_CONDITIONAL)) {
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1136 VehicleOrderID order_id = order->GetConditionSkipToOrder();
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1137 if (order_id >= sel_ord) {
17562
b3ce11d83234 (svn r22326) -Fix: Destinations of conditional orders were update incorrectly when deleting orders in front of the conditional orders, if the target order wwas the order just before of the conditional order.
frosch <frosch@openttd.org>
parents: 17446
diff changeset
1138 order_id = max(order_id - 1, 0);
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1139 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1140 if (order_id == cur_order_id) {
17562
b3ce11d83234 (svn r22326) -Fix: Destinations of conditional orders were update incorrectly when deleting orders in front of the conditional orders, if the target order wwas the order just before of the conditional order.
frosch <frosch@openttd.org>
parents: 17446
diff changeset
1141 order_id = (order_id + 1) % v->GetNumOrders();
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1142 }
17562
b3ce11d83234 (svn r22326) -Fix: Destinations of conditional orders were update incorrectly when deleting orders in front of the conditional orders, if the target order wwas the order just before of the conditional order.
frosch <frosch@openttd.org>
parents: 17446
diff changeset
1143 order->SetConditionSkipToOrder(order_id);
16868
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1144 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1145 cur_order_id++;
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1146 }
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1147
6f39950083d8 (svn r21602) -Codechange: split actual adding/removing of orders to/from a vehicle's order list from the validation of those (user) commands. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16783
diff changeset
1148 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1149 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1150
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1151 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1152 * Goto order of order-list.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1153 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1154 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1155 * @param p1 The ID of the vehicle which order is skipped
6794
4449e9d10ee5 (svn r10033) -Feature [FS#760]: skip to the selected order in the order list when clicking on the "skip" button while pressing CTRL.
rubidium <rubidium@openttd.org>
parents: 6638
diff changeset
1156 * @param p2 the selected order to which we want to skip
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1157 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1158 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1159 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1160 CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1161 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1162 VehicleID veh_id = GB(p1, 0, 20);
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1163 VehicleOrderID sel_ord = GB(p2, 0, 8);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1164
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1165 Vehicle *v = Vehicle::GetIfValid(veh_id);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1166
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1167 if (v == NULL || !v->IsPrimaryVehicle() || sel_ord == v->cur_implicit_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1168
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1169 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1170 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1171
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1172 if (flags & DC_EXEC) {
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
1173 if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
1174
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1175 v->cur_implicit_order_index = v->cur_real_order_index = sel_ord;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1176 v->UpdateRealOrderIndex();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1177
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1178 InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1179 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1180
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1181 /* We have an aircraft/ship, they have a mini-schedule, so update them all */
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
1182 if (v->type == VEH_AIRCRAFT) SetWindowClassesDirty(WC_AIRCRAFT_LIST);
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
1183 if (v->type == VEH_SHIP) SetWindowClassesDirty(WC_SHIPS_LIST);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1184
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1185 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1186 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1187
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1188 /**
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1189 * Move an order inside the orderlist
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1190 * @param tile unused
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1191 * @param flags operation to perform
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1192 * @param p1 the ID of the vehicle
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1193 * @param p2 order to move and target
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1194 * bit 0-15 : the order to move
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1195 * bit 16-31 : the target order
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1196 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1197 * @return the cost of this operation or an error
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1198 * @note The target order will move one place down in the orderlist
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1199 * if you move the order upwards else it'll move it one place down
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1200 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1201 CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1202 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1203 VehicleID veh = GB(p1, 0, 20);
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1204 VehicleOrderID moving_order = GB(p2, 0, 16);
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1205 VehicleOrderID target_order = GB(p2, 16, 16);
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1206
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1207 Vehicle *v = Vehicle::GetIfValid(veh);
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1208 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1209
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1210 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1211 if (ret.Failed()) return ret;
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1212
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1213 /* Don't make senseless movements */
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
1214 if (moving_order >= v->GetNumOrders() || target_order >= v->GetNumOrders() ||
14887
2c5920475362 (svn r19483) -Codechange: Code layout fixes, and parentheses reduction.
alberth <alberth@openttd.org>
parents: 14867
diff changeset
1215 moving_order == target_order || v->GetNumOrders() <= 1) return CMD_ERROR;
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1216
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11983
diff changeset
1217 Order *moving_one = v->GetOrder(moving_order);
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1218 /* Don't move an empty order */
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1219 if (moving_one == NULL) return CMD_ERROR;
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1220
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1221 if (flags & DC_EXEC) {
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1222 v->orders.list->MoveOrder(moving_order, target_order);
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1223
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1224 /* Update shared list */
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1225 Vehicle *u = v->FirstShared();
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1226
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1227 DeleteOrderWarnings(u);
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1228
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1229 for (; u != NULL; u = u->NextShared()) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1230 /* Update the current order.
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1231 * There are multiple ways to move orders, which result in cur_implicit_order_index
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1232 * and cur_real_order_index to not longer make any sense. E.g. moving another
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1233 * real order between them.
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1234 *
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1235 * Basically one could choose to preserve either of them, but not both.
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1236 * While both ways are suitable in this or that case from a human point of view, neither
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1237 * of them makes really sense.
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1238 * However, from an AI point of view, preserving cur_real_order_index is the most
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1239 * predictable and transparent behaviour.
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1240 *
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1241 * With that decision it basically does not matter what we do to cur_implicit_order_index.
19968
0dba7f49118c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents: 19900
diff changeset
1242 * If we change orders between the implicit- and real-index, the implicit orders are mostly likely
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1243 * completely out-dated anyway. So, keep it simple and just keep cur_implicit_order_index as well.
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1244 * The worst which can happen is that a lot of implicit orders are removed when reaching current_order.
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1245 */
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1246 if (u->cur_real_order_index == moving_order) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1247 u->cur_real_order_index = target_order;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1248 } else if (u->cur_real_order_index > moving_order && u->cur_real_order_index <= target_order) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1249 u->cur_real_order_index--;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1250 } else if (u->cur_real_order_index < moving_order && u->cur_real_order_index >= target_order) {
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1251 u->cur_real_order_index++;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1252 }
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1253
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1254 if (u->cur_implicit_order_index == moving_order) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1255 u->cur_implicit_order_index = target_order;
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1256 } else if (u->cur_implicit_order_index > moving_order && u->cur_implicit_order_index <= target_order) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1257 u->cur_implicit_order_index--;
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1258 } else if (u->cur_implicit_order_index < moving_order && u->cur_implicit_order_index >= target_order) {
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1259 u->cur_implicit_order_index++;
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1260 }
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1261
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1262 assert(v->orders.list == u->orders.list);
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1263 /* Update any possible open window of the vehicle */
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1264 InvalidateVehicleOrder(u, moving_order | (target_order << 8));
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1265 }
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1266
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1267 /* As we move an order, the order to skip to will be 'wrong'. */
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1268 Order *order;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1269 FOR_VEHICLE_ORDERS(v, order) {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1270 if (order->IsType(OT_CONDITIONAL)) {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1271 VehicleOrderID order_id = order->GetConditionSkipToOrder();
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1272 if (order_id == moving_order) {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1273 order_id = target_order;
12705
6b046fd8da1a (svn r17168) -Codechange: apply coding style to if and while statements
smatz <smatz@openttd.org>
parents: 12619
diff changeset
1274 } else if (order_id > moving_order && order_id <= target_order) {
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1275 order_id--;
12705
6b046fd8da1a (svn r17168) -Codechange: apply coding style to if and while statements
smatz <smatz@openttd.org>
parents: 12619
diff changeset
1276 } else if (order_id < moving_order && order_id >= target_order) {
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1277 order_id++;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1278 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1279 order->SetConditionSkipToOrder(order_id);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1280 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1281 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1282
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1283 /* Make sure to rebuild the whole list */
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9234
diff changeset
1284 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1285 }
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1286
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1287 return CommandCost();
6832
17319fb8c1c3 (svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents: 6794
diff changeset
1288 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1289
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1290 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1291 * Modify an order in the orderlist of a vehicle.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1292 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1293 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1294 * @param p1 various bitstuffed elements
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1295 * - p1 = (bit 0 - 19) - ID of the vehicle
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1296 * - p1 = (bit 24 - 31) - the selected order (if any). If the last order is given,
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1297 * the order will be inserted before that one
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1298 * the maximum vehicle order id is 254.
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1299 * @param p2 various bitstuffed elements
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1300 * - p2 = (bit 0 - 3) - what data to modify (@see ModifyOrderFlags)
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1301 * - p2 = (bit 4 - 15) - the data to modify
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1302 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1303 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1304 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1305 CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1306 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1307 VehicleOrderID sel_ord = GB(p1, 20, 8);
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1308 VehicleID veh = GB(p1, 0, 20);
15037
ae5f1c6f349c (svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents: 14898
diff changeset
1309 ModifyOrderFlags mof = Extract<ModifyOrderFlags, 0, 4>(p2);
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1310 uint16 data = GB(p2, 4, 11);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1311
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1312 if (mof >= MOF_END) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1313
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1314 Vehicle *v = Vehicle::GetIfValid(veh);
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1315 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1316
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1317 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1318 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1319
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1320 /* Is it a valid order? */
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
1321 if (sel_ord >= v->GetNumOrders()) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1322
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11983
diff changeset
1323 Order *order = v->GetOrder(sel_ord);
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1324 switch (order->GetType()) {
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1325 case OT_GOTO_STATION:
12361
82830e1cd892 (svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents: 12228
diff changeset
1326 if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1327 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1328
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1329 case OT_GOTO_DEPOT:
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1330 if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1331 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1332
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1333 case OT_GOTO_WAYPOINT:
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1334 if (mof != MOF_NON_STOP) return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1335 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1336
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1337 case OT_CONDITIONAL:
11680
e5e2c43d90df (svn r16063) -Fix (r13752): MOF_COND_DESTINATION was not accepted by CmdModifyOrder(). (only used by AI)
frosch <frosch@openttd.org>
parents: 11657
diff changeset
1338 if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE && mof != MOF_COND_DESTINATION) return CMD_ERROR;
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1339 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1340
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1341 default:
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1342 return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1343 }
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1344
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1345 switch (mof) {
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1346 default: NOT_REACHED();
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1347
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1348 case MOF_NON_STOP:
16783
37b5683941fa (svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents: 16733
diff changeset
1349 if (!v->IsGroundVehicle()) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1350 if (data >= ONSF_END) return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1351 if (data == order->GetNonStopType()) return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1352 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1353
11657
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1354 case MOF_STOP_LOCATION:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1355 if (v->type != VEH_TRAIN) return CMD_ERROR;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1356 if (data >= OSL_END) return CMD_ERROR;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1357 break;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1358
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1359 case MOF_UNLOAD:
8883
23eea6824c4b (svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents: 8881
diff changeset
1360 if ((data & ~(OUFB_UNLOAD | OUFB_TRANSFER | OUFB_NO_UNLOAD)) != 0) return CMD_ERROR;
23eea6824c4b (svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents: 8881
diff changeset
1361 /* Unload and no-unload are mutual exclusive and so are transfer and no unload. */
23eea6824c4b (svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents: 8881
diff changeset
1362 if (data != 0 && ((data & (OUFB_UNLOAD | OUFB_TRANSFER)) != 0) == ((data & OUFB_NO_UNLOAD) != 0)) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1363 if (data == order->GetUnloadType()) return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1364 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1365
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1366 case MOF_LOAD:
8883
23eea6824c4b (svn r12650) -Feature: ability to force a vehicle to not load at a station.
rubidium <rubidium@openttd.org>
parents: 8881
diff changeset
1367 if (data > OLFB_NO_LOAD || data == 1) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1368 if (data == order->GetLoadType()) return CMD_ERROR;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1369 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1370
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1371 case MOF_DEPOT_ACTION:
10285
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1372 if (data >= DA_END) return CMD_ERROR;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1373 break;
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1374
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1375 case MOF_COND_VARIABLE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1376 if (data >= OCV_END) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1377 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1378
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1379 case MOF_COND_COMPARATOR:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1380 if (data >= OCC_END) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1381 switch (order->GetConditionVariable()) {
8903
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1382 case OCV_UNCONDITIONALLY: return CMD_ERROR;
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1383
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1384 case OCV_REQUIRES_SERVICE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1385 if (data != OCC_IS_TRUE && data != OCC_IS_FALSE) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1386 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1387
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1388 default:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1389 if (data == OCC_IS_TRUE || data == OCC_IS_FALSE) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1390 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1391 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1392 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1393
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1394 case MOF_COND_VALUE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1395 switch (order->GetConditionVariable()) {
8903
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1396 case OCV_UNCONDITIONALLY: return CMD_ERROR;
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1397
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1398 case OCV_LOAD_PERCENTAGE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1399 case OCV_RELIABILITY:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1400 if (data > 100) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1401 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1402
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1403 default:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1404 if (data > 2047) return CMD_ERROR;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1405 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1406 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1407 break;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1408
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1409 case MOF_COND_DESTINATION:
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
1410 if (data >= v->GetNumOrders()) return CMD_ERROR;
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1411 break;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1412 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1413
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1414 if (flags & DC_EXEC) {
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1415 switch (mof) {
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1416 case MOF_NON_STOP:
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1417 order->SetNonStopType((OrderNonStopFlags)data);
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1418 if (data & ONSF_NO_STOP_AT_DESTINATION_STATION) order->SetRefit(CT_NO_REFIT);
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1419 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1420
11657
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1421 case MOF_STOP_LOCATION:
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1422 order->SetStopLocation((OrderStopLocation)data);
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1423 break;
ff1084d0d8a0 (svn r16037) -Feature: allow (per order) to let a train stop at the near end, middle or far end of a platform from the point of view of the driver of the train that enters the station.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
1424
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1425 case MOF_UNLOAD:
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1426 order->SetUnloadType((OrderUnloadFlags)data);
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1427 break;
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1428
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1429 case MOF_LOAD:
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1430 order->SetLoadType((OrderLoadFlags)data);
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1431 if (data & OLFB_NO_LOAD) order->SetRefit(CT_NO_REFIT);
8845
bb04cb5677d8 (svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium <rubidium@openttd.org>
parents: 8843
diff changeset
1432 break;
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1433
10285
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1434 case MOF_DEPOT_ACTION: {
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1435 switch (data) {
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1436 case DA_ALWAYS_GO:
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1437 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1438 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1439 break;
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1440
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1441 case DA_SERVICE:
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1442 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1443 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
17829
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1444 order->SetRefit(CT_NO_REFIT);
10285
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1445 break;
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1446
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1447 case DA_STOP:
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1448 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1449 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
17829
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1450 order->SetRefit(CT_NO_REFIT);
10285
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1451 break;
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1452
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1453 default:
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1454 NOT_REACHED();
615db2678973 (svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10226
diff changeset
1455 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1456 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1457 }
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1458
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1459 case MOF_COND_VARIABLE: {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1460 order->SetConditionVariable((OrderConditionVariable)data);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1461
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1462 OrderConditionComparator occ = order->GetConditionComparator();
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1463 switch (order->GetConditionVariable()) {
8903
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1464 case OCV_UNCONDITIONALLY:
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1465 order->SetConditionComparator(OCC_EQUALS);
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1466 order->SetConditionValue(0);
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1467 break;
d15e125c0b6a (svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents: 8901
diff changeset
1468
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1469 case OCV_REQUIRES_SERVICE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1470 if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) order->SetConditionComparator(OCC_IS_TRUE);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1471 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1472
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1473 case OCV_LOAD_PERCENTAGE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1474 case OCV_RELIABILITY:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1475 if (order->GetConditionValue() > 100) order->SetConditionValue(100);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1476 /* FALL THROUGH */
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1477 default:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1478 if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1479 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1480 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1481 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1482 }
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1483
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1484 case MOF_COND_COMPARATOR:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1485 order->SetConditionComparator((OrderConditionComparator)data);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1486 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1487
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1488 case MOF_COND_VALUE:
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1489 order->SetConditionValue(data);
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1490 break;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1491
9665
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1492 case MOF_COND_DESTINATION:
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1493 order->SetConditionSkipToOrder(data);
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1494 break;
294a2fc5d425 (svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents: 9641
diff changeset
1495
8845
bb04cb5677d8 (svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium <rubidium@openttd.org>
parents: 8843
diff changeset
1496 default: NOT_REACHED();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1497 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1498
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1499 /* Update the windows and full load flags, also for vehicles that share the same order list */
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1500 Vehicle *u = v->FirstShared();
8869
202439e9e12c (svn r12636) -Codechange: make CmdModifyOrder a little more flexible and remove 'hack' that used the full load flag to set the service if needed flag.
rubidium <rubidium@openttd.org>
parents: 8866
diff changeset
1501 DeleteOrderWarnings(u);
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1502 for (; u != NULL; u = u->NextShared()) {
8872
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1503 /* Toggle u->current_order "Full load" flag if it changed.
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1504 * However, as the same flag is used for depot orders, check
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1505 * whether we are not going to a depot as there are three
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1506 * cases where the full load flag can be active and only
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1507 * one case where the flag is used for depot orders. In the
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1508 * other cases for the OrderTypeByte the flags are not used,
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1509 * so do not care and those orders should not be active
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1510 * when this function is called.
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1511 */
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1512 if (sel_ord == u->cur_real_order_index &&
8872
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1513 (u->current_order.IsType(OT_GOTO_STATION) || u->current_order.IsType(OT_LOADING)) &&
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1514 u->current_order.GetLoadType() != order->GetLoadType()) {
32505929420d (svn r12639) -Fix: order window was not marked dirty on changed orders.
rubidium <rubidium@openttd.org>
parents: 8869
diff changeset
1515 u->current_order.SetLoadType(order->GetLoadType());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1516 }
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1517 InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1518 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1519 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1520
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1521 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1522 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1523
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1524 /**
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1525 * Check if an aircraft has enough range for an order list.
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1526 * @param v_new Aircraft to check.
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1527 * @param v_order Vehicle currently holding the order list.
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1528 * @param first First order in the source order list.
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1529 * @return True if the aircraft has enough range for the orders, false otherwise.
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1530 */
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1531 static bool CheckAircraftOrderDistance(const Aircraft *v_new, const Vehicle *v_order, const Order *first)
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1532 {
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1533 if (first == NULL || v_new->acache.cached_max_range == 0) return true;
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1534
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1535 /* Iterate over all orders to check the distance between all
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1536 * 'goto' orders and their respective next order (of any type). */
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1537 for (const Order *o = first; o != NULL; o = o->next) {
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1538 switch (o->GetType()) {
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1539 case OT_GOTO_STATION:
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1540 case OT_GOTO_DEPOT:
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1541 case OT_GOTO_WAYPOINT:
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1542 /* If we don't have a next order, we've reached the end and must check the first order instead. */
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1543 if (GetOrderDistance(o, o->next != NULL ? o->next : first, v_order) > v_new->acache.cached_max_range_sqr) return false;
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1544 break;
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1545
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1546 default: break;
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1547 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1548 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1549
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1550 return true;
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1551 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1552
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1553 /**
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1554 * Clone/share/copy an order-list of another vehicle.
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1555 * @param tile unused
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1556 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1557 * @param p1 various bitstuffed elements
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1558 * - p1 = (bit 0-19) - destination vehicle to clone orders to
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1559 * - p1 = (bit 30-31) - action to perform
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1560 * @param p2 source vehicle to clone orders from, if any (none for CO_UNSHARE)
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1561 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1562 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1563 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1564 CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1565 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1566 VehicleID veh_src = GB(p2, 0, 20);
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1567 VehicleID veh_dst = GB(p1, 0, 20);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1568
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1569 Vehicle *dst = Vehicle::GetIfValid(veh_dst);
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1570 if (dst == NULL || !dst->IsPrimaryVehicle()) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1571
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1572 CommandCost ret = CheckOwnership(dst->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1573 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1574
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1575 switch (GB(p1, 30, 2)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1576 case CO_SHARE: {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1577 Vehicle *src = Vehicle::GetIfValid(veh_src);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1578
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1579 /* Sanity checks */
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1580 if (src == NULL || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1581
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1582 CommandCost ret = CheckOwnership(src->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1583 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1585 /* Trucks can't share orders with busses (and visa versa) */
13852
5caf1ea3a9f9 (svn r18381) -Codechange: Add RoadVehicle::IsBus() to simplify some stuff.
frosch <frosch@openttd.org>
parents: 13851
diff changeset
1586 if (src->type == VEH_ROAD && RoadVehicle::From(src)->IsBus() != RoadVehicle::From(dst)->IsBus()) {
13851
06143488a65f (svn r18380) -Fix (r9301): One could not share orders between buses carrying different cargos.
frosch <frosch@openttd.org>
parents: 13679
diff changeset
1587 return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1588 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1589
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1590 /* Is the vehicle already in the shared list? */
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1591 if (src->FirstShared() == dst->FirstShared()) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1592
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1593 const Order *order;
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1594
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1595 FOR_VEHICLE_ORDERS(src, order) {
19487
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1596 if (!OrderGoesToStation(dst, order)) continue;
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1597
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1598 /* Allow copying unreachable destinations if they were already unreachable for the source.
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1599 * This is basically to allow cloning / autorenewing / autoreplacing vehicles, while the stations
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1600 * are temporarily invalid due to reconstruction. */
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1601 const Station *st = Station::Get(order->GetDestination());
8aee85c3b185 (svn r24390) -Change [FS#5213]: Allow cloning of orders which are unreachable for the destination vehicle if they were already unreachable for the source vehicle. This makes cloning/autorenewing/autoreplacing behave more smooth during station reconstruction.
frosch <frosch@openttd.org>
parents: 19381
diff changeset
1602 if (CanVehicleUseStation(src, st) && !CanVehicleUseStation(dst, st)) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
1603 return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1604 }
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1605 }
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1606
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1607 /* Check for aircraft range limits. */
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1608 if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1609 return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1610 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1611
17284
acb919c16a29 (svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents: 17281
diff changeset
1612 if (src->orders.list == NULL && !OrderList::CanAllocateItem()) {
acb919c16a29 (svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents: 17281
diff changeset
1613 return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
acb919c16a29 (svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents: 17281
diff changeset
1614 }
acb919c16a29 (svn r22024) -Fix [FS#4468]: verify we can allocate an OrderList before we actually try to do so (Rubidium)
smatz <smatz@openttd.org>
parents: 17281
diff changeset
1615
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1616 if (flags & DC_EXEC) {
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1617 /* If the destination vehicle had a OrderList, destroy it.
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1618 * We only reset the order indices, if the new orders are obviously different.
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1619 * (We mainly do this to keep the order indices valid and in range.) */
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1620 DeleteVehicleOrders(dst, false, dst->GetNumOrders() != src->GetNumOrders());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1621
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1622 dst->orders.list = src->orders.list;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1623
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1624 /* Link this vehicle in the shared-list */
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1625 dst->AddToShared(src);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1626
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1627 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1628 InvalidateVehicleOrder(src, VIWD_MODIFY_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1629
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9234
diff changeset
1630 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1631 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1632 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1633 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1634
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1635 case CO_COPY: {
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1636 Vehicle *src = Vehicle::GetIfValid(veh_src);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1637
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1638 /* Sanity checks */
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1639 if (src == NULL || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1640
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1641 CommandCost ret = CheckOwnership(src->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1642 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1643
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1644 /* Trucks can't copy all the orders from busses (and visa versa),
19968
0dba7f49118c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents: 19900
diff changeset
1645 * and neither can helicopters and aircraft. */
10652
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1646 const Order *order;
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1647 FOR_VEHICLE_ORDERS(src, order) {
42a789858c6c (svn r14954) -Fix [FS#1890]: sharing/cloning/inserting of orders that the/a vehicle (in the shared list) can't go to (wrong station type etc)
rubidium <rubidium@openttd.org>
parents: 10650
diff changeset
1648 if (OrderGoesToStation(dst, order) &&
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11866
diff changeset
1649 !CanVehicleUseStation(dst, Station::Get(order->GetDestination()))) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
1650 return_cmd_error(STR_ERROR_CAN_T_COPY_SHARE_ORDER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1651 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1652 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1653
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1654 /* Check for aircraft range limits. */
19206
a9d3a85134f9 (svn r24086) -Fix [FS#5131] (r23504): Cloning orders of aircraft with limited range failed.
frosch <frosch@openttd.org>
parents: 19093
diff changeset
1655 if (dst->type == VEH_AIRCRAFT && !CheckAircraftOrderDistance(Aircraft::From(dst), src, src->GetFirstOrder())) {
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1656 return_cmd_error(STR_ERROR_AIRCRAFT_NOT_ENOUGH_RANGE);
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1657 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18617
diff changeset
1658
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1659 /* make sure there are orders available */
18993
f43af50bcf99 (svn r23849) -Fix [FS#5008]: when the network is lagging, you try to copy a vehicle's order but accidentally create a station order and then copy the vehicle's order (before the first command is executed) one could trigger an assertion from the pool. Simplify the ancient code and make it more fool proof, even though it could stop copying a vehicle's orders slightly earlier than it would now... but who has come near that limit and really needed that many orders?
rubidium <rubidium@openttd.org>
parents: 18891
diff changeset
1660 if (!Order::CanAllocateItem(src->GetNumOrders()) || !OrderList::CanAllocateItem()) {
11730
a39da1e4c1f5 (svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents: 11719
diff changeset
1661 return_cmd_error(STR_ERROR_NO_MORE_SPACE_FOR_ORDERS);
10304
575039101d7c (svn r14547) -Fix: order pool seemed to look full when it was not as it only checked whether it was possible to allocate a new block of pool items instead of checking for free pool items.
rubidium <rubidium@openttd.org>
parents: 10285
diff changeset
1662 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1663
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1664 if (flags & DC_EXEC) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1665 const Order *order;
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1666 Order *first = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1667 Order **order_dst;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1668
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1669 /* If the destination vehicle had an order list, destroy the chain but keep the OrderList.
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1670 * We only reset the order indices, if the new orders are obviously different.
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1671 * (We mainly do this to keep the order indices valid and in range.) */
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1672 DeleteVehicleOrders(dst, true, dst->GetNumOrders() != src->GetNumOrders());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1673
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1674 order_dst = &first;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1675 FOR_VEHICLE_ORDERS(src, order) {
7391
1b2a34c4f7fa (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium <rubidium@openttd.org>
parents: 7049
diff changeset
1676 *order_dst = new Order();
8835
e8296a8dbe93 (svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents: 8834
diff changeset
1677 (*order_dst)->AssignOrder(*order);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1678 order_dst = &(*order_dst)->next;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1679 }
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1680 if (dst->orders.list == NULL) {
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1681 dst->orders.list = new OrderList(first, dst);
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1682 } else {
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1683 assert(dst->orders.list->GetFirstOrder() == NULL);
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1684 assert(!dst->orders.list->IsShared());
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1685 delete dst->orders.list;
17359
32ec2b49ee24 (svn r22105) -Fix: crash when copying an orderlist to a vehicle that already had orders
yexo <yexo@openttd.org>
parents: 17306
diff changeset
1686 assert(OrderList::CanAllocateItem());
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11949
diff changeset
1687 dst->orders.list = new OrderList(first, dst);
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1688 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1689
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1690 InvalidateVehicleOrder(dst, VIWD_REMOVE_ALL_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1691
9297
add307f2e6ea (svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents: 9234
diff changeset
1692 InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1693 }
15618
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1694 break;
e4640748f223 (svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents: 15569
diff changeset
1695 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1696
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1697 case CO_UNSHARE: return DecloneOrder(dst, flags);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1698 default: return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1699 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1700
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1701 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1702 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1703
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1704 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15618
diff changeset
1705 * Add/remove refit orders from an order
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1706 * @param tile Not used
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6370
diff changeset
1707 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1708 * @param p1 VehicleIndex of the vehicle having the order
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1709 * @param p2 bitmask
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1710 * - bit 0-7 CargoID
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1711 * - bit 16-23 number of order to modify
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1712 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13034
diff changeset
1713 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1714 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11014
diff changeset
1715 CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1716 {
15889
b6a023c19a16 (svn r20571) -Codechange: free/reserve some bits in the order commands to increase the vehicle pool limit
rubidium <rubidium@openttd.org>
parents: 15865
diff changeset
1717 VehicleID veh = GB(p1, 0, 20);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1718 VehicleOrderID order_number = GB(p2, 16, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1719 CargoID cargo = GB(p2, 0, 8);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1720
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1721 if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT && cargo != CT_AUTO_REFIT) return CMD_ERROR;
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1722
11949
c89301974eb8 (svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents: 11924
diff changeset
1723 const Vehicle *v = Vehicle::GetIfValid(veh);
15040
3314e49704e7 (svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents: 15037
diff changeset
1724 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
14815
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1725
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1726 CommandCost ret = CheckOwnership(v->owner);
ad5c3430b2b2 (svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents: 14638
diff changeset
1727 if (ret.Failed()) return ret;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1728
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11983
diff changeset
1729 Order *order = v->GetOrder(order_number);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1730 if (order == NULL) return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1731
18251
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1732 /* Automatic refit cargo is only supported for goto station orders. */
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1733 if (cargo == CT_AUTO_REFIT && !order->IsType(OT_GOTO_STATION)) return CMD_ERROR;
137b272acca5 (svn r23087) -Feature: Auto-refitting of vehicles during loading at a station when the vehicle allows it.
michi_cc <michi_cc@openttd.org>
parents: 18043
diff changeset
1734
20004
d2753003863f (svn r24936) -Fix [FS#5446]: Don't allow order refit to be set for no-load orders.
peter1138 <peter1138@openttd.org>
parents: 19968
diff changeset
1735 if (order->GetLoadType() & OLFB_NO_LOAD) return CMD_ERROR;
d2753003863f (svn r24936) -Fix [FS#5446]: Don't allow order refit to be set for no-load orders.
peter1138 <peter1138@openttd.org>
parents: 19968
diff changeset
1736
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1737 if (flags & DC_EXEC) {
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
1738 order->SetRefit(cargo);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1739
17829
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1740 /* Make the depot order an 'always go' order. */
19550
f0d97bcce76a (svn r24457) -Fix [FS#5264] (r23087): Changing auto-refit for a 'goto station' order was inadvertently modifying the full load state.
michi_cc <michi_cc@openttd.org>
parents: 19487
diff changeset
1741 if (cargo != CT_NO_REFIT && order->IsType(OT_GOTO_DEPOT)) {
17829
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1742 order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1743 order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1744 }
3c9a83a23782 (svn r22620) -Change [FS#4651]: Enforce refit orders to be 'always go to depot' orders; service-only and stop-in-depot orders make no sense with refitting.
frosch <frosch@openttd.org>
parents: 17804
diff changeset
1745
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1746 for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1747 /* Update any possible open window of the vehicle */
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
1748 InvalidateVehicleOrder(u, VIWD_MODIFY_ORDERS);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1749
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1750 /* If the vehicle already got the current depot set as current order, then update current order as well */
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
1751 if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
1752 u->current_order.SetRefit(cargo);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1753 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1754 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1755 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1756
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1757 return CommandCost();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1758 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1759
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1760
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1761 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1762 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1763 * Check the orders of a vehicle, to see if there are invalid orders and stuff
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1764 *
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1765 */
10647
592ae9307430 (svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents: 10582
diff changeset
1766 void CheckOrders(const Vehicle *v)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1767 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1768 /* Does the user wants us to check things? */
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9390
diff changeset
1769 if (_settings_client.gui.order_review_system == 0) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1770
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1771 /* Do nothing for crashed vehicles */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1772 if (v->vehstatus & VS_CRASHED) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1773
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1774 /* Do nothing for stopped vehicles if setting is '1' */
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15040
diff changeset
1775 if (_settings_client.gui.order_review_system == 1 && (v->vehstatus & VS_STOPPED)) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1776
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1777 /* do nothing we we're not the first vehicle in a share-chain */
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1778 if (v->FirstShared() != v) return;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1779
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1780 /* Only check every 20 days, so that we don't flood the message log */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10184
diff changeset
1781 if (v->owner == _local_company && v->day_counter % 20 == 0) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1782 int n_st, problem_type = -1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1783 const Order *order;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1784 int message = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1785
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1786 /* Check the order list */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1787 n_st = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1788
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1789 FOR_VEHICLE_ORDERS(v, order) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1790 /* Dummy order? */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
1791 if (order->IsType(OT_DUMMY)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1792 problem_type = 1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1793 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1794 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1795 /* Does station have a load-bay for this vehicle? */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
1796 if (order->IsType(OT_GOTO_STATION)) {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11866
diff changeset
1797 const Station *st = Station::Get(order->GetDestination());
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1798
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1799 n_st++;
14113
7cfec5bb9c2c (svn r18660) -Cleanup: remove useless function
yexo <yexo@openttd.org>
parents: 14072
diff changeset
1800 if (!CanVehicleUseStation(v, st)) problem_type = 3;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1801 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1802 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1803
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1804 /* Check if the last and the first order are the same */
10544
836dfaca2a32 (svn r14801) -Codechange: don't reference Vehicle::num_orders directly but through a method GetNumOrders() (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10499
diff changeset
1805 if (v->GetNumOrders() > 1) {
11991
a4d3838349e6 (svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents: 11983
diff changeset
1806 const Order *last = v->GetLastOrder();
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1807
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1808 if (v->orders.list->GetFirstOrder()->Equals(*last)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1809 problem_type = 2;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1810 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1811 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1812
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1813 /* Do we only have 1 station in our order list? */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1814 if (n_st < 2 && problem_type == -1) problem_type = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1815
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1816 #ifndef NDEBUG
11014
1a4a901b1a95 (svn r15354) -Fix (r14803): first shared of a vehicle could be NULL making it impossible to (share-)clone the vehicle.
rubidium <rubidium@openttd.org>
parents: 10993
diff changeset
1817 if (v->orders.list != NULL) v->orders.list->DebugCheckSanity();
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1818 #endif
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1819
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1820 /* We don't have a problem */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1821 if (problem_type < 0) return;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1822
12619
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12538
diff changeset
1823 message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS + problem_type;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1824 //DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1825
10574
bf4424d086f0 (svn r14831) -Codechange: use {VEHICLE} instead of Train/Ship/Road veh/Aircraft/{STRING} {COMMA} in lang files (part by Swallow)
smatz <smatz@openttd.org>
parents: 10573
diff changeset
1826 SetDParam(0, v->index);
19381
f37c5813696b (svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents: 19206
diff changeset
1827 AddVehicleAdviceNewsItem(message, v->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1828 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1829 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1830
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1831 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1832 * Removes an order from all vehicles. Triggers when, say, a station is removed.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1833 * @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1834 * @param destination The destination. Can be a StationID, DepotID or WaypointID.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1835 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1836 void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination)
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1837 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1838 Vehicle *v;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1839
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1840 /* Aircraft have StationIDs for depot orders and never use DepotIDs
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1841 * This fact is handled specially below
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1842 */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1843
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1844 /* Go through all vehicles */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1845 FOR_ALL_VEHICLES(v) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1846 Order *order;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1847
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1848 order = &v->current_order;
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
1849 if ((v->type == VEH_AIRCRAFT && order->IsType(OT_GOTO_DEPOT) ? OT_GOTO_STATION : order->GetType()) == type &&
8840
c3d2f0eb69a1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents: 8839
diff changeset
1850 v->current_order.GetDestination() == destination) {
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
1851 order->MakeDummy();
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
1852 SetWindowDirty(WC_VEHICLE_VIEW, v->index);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1853 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1854
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1855 /* Clear the order from the order-list */
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1856 int id = -1;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1857 FOR_VEHICLE_ORDERS(v, order) {
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1858 id++;
17446
7018bffbfa1b (svn r22200) -Fix (r21642): removing a station order could stop when removing first automatic order
smatz <smatz@openttd.org>
parents: 17370
diff changeset
1859 restart:
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1860
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1861 OrderType ot = order->GetType();
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1862 if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1863 if (ot == OT_IMPLICIT || (v->type == VEH_AIRCRAFT && ot == OT_GOTO_DEPOT)) ot = OT_GOTO_STATION;
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1864 if (ot == type && order->GetDestination() == destination) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1865 /* We want to clear implicit orders, but we don't want to make them
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1866 * dummy orders. They should just vanish. Also check the actual order
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1867 * type as ot is currently OT_GOTO_STATION. */
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1868 if (order->IsType(OT_IMPLICIT)) {
17446
7018bffbfa1b (svn r22200) -Fix (r21642): removing a station order could stop when removing first automatic order
smatz <smatz@openttd.org>
parents: 17370
diff changeset
1869 order = order->next; // DeleteOrder() invalidates current order
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1870 DeleteOrder(v, id);
17446
7018bffbfa1b (svn r22200) -Fix (r21642): removing a station order could stop when removing first automatic order
smatz <smatz@openttd.org>
parents: 17370
diff changeset
1871 if (order != NULL) goto restart;
7018bffbfa1b (svn r22200) -Fix (r21642): removing a station order could stop when removing first automatic order
smatz <smatz@openttd.org>
parents: 17370
diff changeset
1872 break;
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1873 }
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
1874
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
1875 order->MakeDummy();
10184
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1876 for (const Vehicle *w = v->FirstShared(); w != NULL; w = w->NextShared()) {
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1877 /* In GUI, simulate by removing the order and adding it back */
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1878 InvalidateVehicleOrder(w, id | (INVALID_VEH_ORDER_ID << 8));
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1879 InvalidateVehicleOrder(w, (INVALID_VEH_ORDER_ID << 8) | id);
fbd1b77a2509 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz <smatz@openttd.org>
parents: 10151
diff changeset
1880 }
10020
516f3198d980 (svn r14179) -Fix (r1): RemoveOrderFromAllVehicles() did not mark enough windows dirty.
frosch <frosch@openttd.org>
parents: 10019
diff changeset
1881 }
516f3198d980 (svn r14179) -Fix (r1): RemoveOrderFromAllVehicles() did not mark enough windows dirty.
frosch <frosch@openttd.org>
parents: 10019
diff changeset
1882 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1883 }
18617
31037ca54d3d (svn r23464) -Fix [FS#4876]: clear the backed up orders of a removed station as well, otherwise one could create orders to a station that was never in the original backupped orders. For example a road vehicle trying to go to a buoy.
rubidium <rubidium@openttd.org>
parents: 18363
diff changeset
1884
31037ca54d3d (svn r23464) -Fix [FS#4876]: clear the backed up orders of a removed station as well, otherwise one could create orders to a station that was never in the original backupped orders. For example a road vehicle trying to go to a buoy.
rubidium <rubidium@openttd.org>
parents: 18363
diff changeset
1885 OrderBackup::RemoveOrder(type, destination);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1886 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1887
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1888 /**
16733
4b988ed6473a (svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents: 16547
diff changeset
1889 * Checks if a vehicle has a depot in its order list.
4b988ed6473a (svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents: 16547
diff changeset
1890 * @return True iff at least one order is a depot order.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1891 */
16733
4b988ed6473a (svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents: 16547
diff changeset
1892 bool Vehicle::HasDepotOrder() const
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1893 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1894 const Order *order;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1895
16733
4b988ed6473a (svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents: 16547
diff changeset
1896 FOR_VEHICLE_ORDERS(this, order) {
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15040
diff changeset
1897 if (order->IsType(OT_GOTO_DEPOT)) return true;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1898 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1899
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1900 return false;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1901 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1902
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1903 /**
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1904 * Delete all orders from a vehicle
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1905 * @param v Vehicle whose orders to reset
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1906 * @param keep_orderlist If true, do not free the order list, only empty it.
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1907 * @param reset_order_indices If true, reset cur_implicit_order_index and cur_real_order_index
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1908 * and cancel the current full load order (if the vehicle is loading).
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1909 * If false, _you_ have to make sure the order indices are valid after
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1910 * your messing with them!
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1911 */
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1912 void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist, bool reset_order_indices)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1913 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1914 DeleteOrderWarnings(v);
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1915
8469
066d7c3ca93d (svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz).
belugas <belugas@openttd.org>
parents: 8373
diff changeset
1916 if (v->IsOrderListShared()) {
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1917 /* Remove ourself from the shared order list. */
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1918 v->RemoveFromShared();
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1919 v->orders.list = NULL;
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1920 } else if (v->orders.list != NULL) {
9941
53ba5561b1c2 (svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents: 9937
diff changeset
1921 /* Remove the orders */
10546
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1922 v->orders.list->FreeChain(keep_orderlist);
9ceef3c92be2 (svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents: 10544
diff changeset
1923 if (!keep_orderlist) v->orders.list = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1924 }
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1925
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1926 if (reset_order_indices) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
1927 v->cur_implicit_order_index = v->cur_real_order_index = 0;
17306
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1928 if (v->current_order.IsType(OT_LOADING)) {
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1929 CancelLoadingDueToDeletedOrder(v);
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1930 }
2ed9720f1bb1 (svn r22046) -Fix [FS#4487]: Make sure order indices stay in range when copying, sharing, unsharing or deleting all orders.
frosch <frosch@openttd.org>
parents: 17305
diff changeset
1931 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1932 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1933
17109
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1934 /**
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1935 * Clamp the service interval to the correct min/max. The actual min/max values
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1936 * depend on whether it's in percent or days.
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1937 * @param interval proposed service interval
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1938 * @param company_id the owner of the vehicle
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1939 * @return Clamped service interval
69b5b1b3eddd (svn r21846) -Codechange: move documentation towards the code to make it more likely to be updated [o-s].
rubidium <rubidium@openttd.org>
parents: 17072
diff changeset
1940 */
20062
7456d9748fcb (svn r24995) -Codechange: Add flags to vehicle service interval for custom & ispercent (peter1138)
rubidium <rubidium@openttd.org>
parents: 20004
diff changeset
1941 uint16 GetServiceIntervalClamped(uint interval, bool ispercent)
8211
165064de4629 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
1942 {
20062
7456d9748fcb (svn r24995) -Codechange: Add flags to vehicle service interval for custom & ispercent (peter1138)
rubidium <rubidium@openttd.org>
parents: 20004
diff changeset
1943 return ispercent ? Clamp(interval, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : Clamp(interval, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS);
8211
165064de4629 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
1944 }
165064de4629 (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
1945
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
1946 /**
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1947 *
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1948 * Check if a vehicle has any valid orders
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1949 *
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1950 * @return false if there are no valid orders
14072
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1951 * @note Conditional orders are not considered valid destination orders
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1952 *
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1953 */
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1954 static bool CheckForValidOrders(const Vehicle *v)
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1955 {
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1956 const Order *order;
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1957
14072
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1958 FOR_VEHICLE_ORDERS(v, order) {
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1959 switch (order->GetType()) {
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1960 case OT_GOTO_STATION:
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1961 case OT_GOTO_DEPOT:
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1962 case OT_GOTO_WAYPOINT:
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1963 return true;
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1964
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1965 default:
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1966 break;
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1967 }
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
1968 }
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1969
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1970 return false;
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1971 }
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1972
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
1973 /**
8900
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1974 * Compare the variable and value based on the given comparator.
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1975 */
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1976 static bool OrderConditionCompare(OrderConditionComparator occ, int variable, int value)
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1977 {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1978 switch (occ) {
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1979 case OCC_EQUALS: return variable == value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1980 case OCC_NOT_EQUALS: return variable != value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1981 case OCC_LESS_THAN: return variable < value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1982 case OCC_LESS_EQUALS: return variable <= value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1983 case OCC_MORE_THAN: return variable > value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1984 case OCC_MORE_EQUALS: return variable >= value;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1985 case OCC_IS_TRUE: return variable != 0;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1986 case OCC_IS_FALSE: return variable == 0;
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1987 default: NOT_REACHED();
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1988 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1989 }
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1990
a12b2ec504da (svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents: 8894
diff changeset
1991 /**
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1992 * Process a conditional order and determine the next order.
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1993 * @param order the order the vehicle currently has
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1994 * @param v the vehicle to update
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1995 * @return index of next order to jump to, or INVALID_VEH_ORDER_ID to use the next order
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1996 */
9807
5c6328db0312 (svn r13949) -Codechange [YAPP]: Declare the functions for processing conditional orders as non-static. (michi_cc)
rubidium <rubidium@openttd.org>
parents: 9666
diff changeset
1997 VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1998 {
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
1999 if (order->GetType() != OT_CONDITIONAL) return INVALID_VEH_ORDER_ID;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2000
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2001 bool skip_order = false;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2002 OrderConditionComparator occ = order->GetConditionComparator();
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2003 uint16 value = order->GetConditionValue();
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2004
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2005 switch (order->GetConditionVariable()) {
18043
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2006 case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2007 case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2008 case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2009 case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2010 case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2011 case OCV_UNCONDITIONALLY: skip_order = true; break;
c9919ff3aae4 (svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
frosch <frosch@openttd.org>
parents: 18030
diff changeset
2012 case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2013 default: NOT_REACHED();
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2014 }
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2015
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2016 return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2017 }
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2018
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2019 /**
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2020 * Update the vehicle's destination tile from an order.
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2021 * @param order the order the vehicle currently has
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2022 * @param v the vehicle to update
13070
1c4c4ae8d716 (svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents: 13067
diff changeset
2023 * @param conditional_depth the depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2024 * @param pbs_look_ahead Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2025 */
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2026 bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2027 {
20616
8f28ee9b2502 (svn r25562) -Fix [FS#5633]: If the next order cannot be resolved, reset the current order property instead of leaving it in an intermediate state.
frosch <frosch@openttd.org>
parents: 20403
diff changeset
2028 if (conditional_depth > v->GetNumOrders()) {
8f28ee9b2502 (svn r25562) -Fix [FS#5633]: If the next order cannot be resolved, reset the current order property instead of leaving it in an intermediate state.
frosch <frosch@openttd.org>
parents: 20403
diff changeset
2029 v->current_order.Free();
8f28ee9b2502 (svn r25562) -Fix [FS#5633]: If the next order cannot be resolved, reset the current order property instead of leaving it in an intermediate state.
frosch <frosch@openttd.org>
parents: 20403
diff changeset
2030 v->dest_tile = 0;
8f28ee9b2502 (svn r25562) -Fix [FS#5633]: If the next order cannot be resolved, reset the current order property instead of leaving it in an intermediate state.
frosch <frosch@openttd.org>
parents: 20403
diff changeset
2031 return false;
8f28ee9b2502 (svn r25562) -Fix [FS#5633]: If the next order cannot be resolved, reset the current order property instead of leaving it in an intermediate state.
frosch <frosch@openttd.org>
parents: 20403
diff changeset
2032 }
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2033
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2034 switch (order->GetType()) {
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2035 case OT_GOTO_STATION:
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2036 v->dest_tile = v->GetOrderStationLocation(order->GetDestination());
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2037 return true;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2038
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2039 case OT_GOTO_DEPOT:
15569
919e5dbec304 (svn r20229) -Fix [FS#3986]: "Service at nearest depot" behaved the same as "Go to nearest depot"
rubidium <rubidium@openttd.org>
parents: 15552
diff changeset
2040 if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2041 assert(!pbs_look_ahead);
15569
919e5dbec304 (svn r20229) -Fix [FS#3986]: "Service at nearest depot" behaved the same as "Go to nearest depot"
rubidium <rubidium@openttd.org>
parents: 15552
diff changeset
2042 UpdateVehicleTimetable(v, true);
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2043 v->IncrementRealOrderIndex();
15569
919e5dbec304 (svn r20229) -Fix [FS#3986]: "Service at nearest depot" behaved the same as "Go to nearest depot"
rubidium <rubidium@openttd.org>
parents: 15552
diff changeset
2044 break;
919e5dbec304 (svn r20229) -Fix [FS#3986]: "Service at nearest depot" behaved the same as "Go to nearest depot"
rubidium <rubidium@openttd.org>
parents: 15552
diff changeset
2045 }
919e5dbec304 (svn r20229) -Fix [FS#3986]: "Service at nearest depot" behaved the same as "Go to nearest depot"
rubidium <rubidium@openttd.org>
parents: 15552
diff changeset
2046
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2047 if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2048 /* We need to search for the nearest depot (hangar). */
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2049 TileIndex location;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2050 DestinationID destination;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2051 bool reverse;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2052
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2053 if (v->FindClosestDepot(&location, &destination, &reverse)) {
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2054 /* PBS reservations cannot reverse */
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2055 if (pbs_look_ahead && reverse) return false;
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2056
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2057 v->dest_tile = location;
20102
5ef3fbd3bdfa (svn r25041) -Remove [FS#3764-ish]: ordered refit with subtypes, since the cases where it worked were corner cases rather than the general case.
frosch <frosch@openttd.org>
parents: 20062
diff changeset
2058 v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo());
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2059
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2060 /* If there is no depot in front, reverse automatically (trains only) */
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2061 if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2062
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2063 if (v->type == VEH_AIRCRAFT) {
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12082
diff changeset
2064 Aircraft *a = Aircraft::From(v);
11982
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2065 if (a->state == FLYING && a->targetairport != destination) {
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2066 /* The aircraft is now heading for a different hangar than the next in the orders */
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2067 extern void AircraftNextAirportPos_and_Order(Aircraft *a);
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2068 AircraftNextAirportPos_and_Order(a);
9add5306a01e (svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents: 11981
diff changeset
2069 }
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2070 }
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2071 return true;
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2072 }
12050
2330a45bc659 (svn r16457) -Fix [FS#2925]: skipping a 'nearest depot order' because none could be found could cause multiple orders to get skipped
rubidium <rubidium@openttd.org>
parents: 12032
diff changeset
2073
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2074 /* If there is no depot, we cannot help PBS either. */
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2075 if (pbs_look_ahead) return false;
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2076
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2077 UpdateVehicleTimetable(v, true);
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2078 v->IncrementRealOrderIndex();
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2079 } else {
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2080 if (v->type != VEH_AIRCRAFT) {
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2081 v->dest_tile = Depot::Get(order->GetDestination())->xy;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2082 }
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2083 return true;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2084 }
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2085 break;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2086
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2087 case OT_GOTO_WAYPOINT:
12503
9da198c570da (svn r16940) -Codechange: make the pathfinders behave the same when finding waypoints or stations, i.e. don't force exactly one destination tile for a waypoint
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
2088 v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2089 return true;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2090
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2091 case OT_CONDITIONAL: {
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2092 assert(!pbs_look_ahead);
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2093 VehicleOrderID next_order = ProcessConditionalOrder(order, v);
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2094 if (next_order != INVALID_VEH_ORDER_ID) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2095 /* Jump to next_order. cur_implicit_order_index becomes exactly that order,
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2096 * cur_real_order_index might come after next_order. */
9641
d6df5044bb40 (svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium <rubidium@openttd.org>
parents: 9609
diff changeset
2097 UpdateVehicleTimetable(v, false);
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2098 v->cur_implicit_order_index = v->cur_real_order_index = next_order;
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2099 v->UpdateRealOrderIndex();
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2100 v->current_order_time += v->GetOrder(v->cur_real_order_index)->travel_time;
17566
6ea8ef177cf3 (svn r22330) -Change: When a conditional order triggers and causes skipping to a particular order, disable modifications to automatic orders. till reaching the next real order, as we do not know whether to change the targets of conditional orders when inserting automatic orders. (So, when the vehicle skips to an order and later inserts an automatic order, the conditional order will still point to the same order, so the automatic order will be inserted again the next time.)
frosch <frosch@openttd.org>
parents: 17562
diff changeset
2101
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2102 /* Disable creation of implicit orders.
17566
6ea8ef177cf3 (svn r22330) -Change: When a conditional order triggers and causes skipping to a particular order, disable modifications to automatic orders. till reaching the next real order, as we do not know whether to change the targets of conditional orders when inserting automatic orders. (So, when the vehicle skips to an order and later inserts an automatic order, the conditional order will still point to the same order, so the automatic order will be inserted again the next time.)
frosch <frosch@openttd.org>
parents: 17562
diff changeset
2103 * When inserting them we do not know that we would have to make the conditional orders point to them. */
6ea8ef177cf3 (svn r22330) -Change: When a conditional order triggers and causes skipping to a particular order, disable modifications to automatic orders. till reaching the next real order, as we do not know whether to change the targets of conditional orders when inserting automatic orders. (So, when the vehicle skips to an order and later inserts an automatic order, the conditional order will still point to the same order, so the automatic order will be inserted again the next time.)
frosch <frosch@openttd.org>
parents: 17562
diff changeset
2104 if (v->IsGroundVehicle()) {
6ea8ef177cf3 (svn r22330) -Change: When a conditional order triggers and causes skipping to a particular order, disable modifications to automatic orders. till reaching the next real order, as we do not know whether to change the targets of conditional orders when inserting automatic orders. (So, when the vehicle skips to an order and later inserts an automatic order, the conditional order will still point to the same order, so the automatic order will be inserted again the next time.)
frosch <frosch@openttd.org>
parents: 17562
diff changeset
2105 uint16 &gv_flags = v->GetGroundVehicleFlags();
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2106 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
17566
6ea8ef177cf3 (svn r22330) -Change: When a conditional order triggers and causes skipping to a particular order, disable modifications to automatic orders. till reaching the next real order, as we do not know whether to change the targets of conditional orders when inserting automatic orders. (So, when the vehicle skips to an order and later inserts an automatic order, the conditional order will still point to the same order, so the automatic order will be inserted again the next time.)
frosch <frosch@openttd.org>
parents: 17562
diff changeset
2107 }
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2108 } else {
9641
d6df5044bb40 (svn r13704) -Fix: make timetables work more sensible when used in conjunction with conditional orders, i.e. make it possibly to tell how long to travel to the next destination if you jump.
rubidium <rubidium@openttd.org>
parents: 9609
diff changeset
2109 UpdateVehicleTimetable(v, true);
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2110 v->IncrementRealOrderIndex();
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2111 }
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2112 break;
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2113 }
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2114
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2115 default:
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2116 v->dest_tile = 0;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2117 return false;
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2118 }
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2119
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2120 assert(v->cur_implicit_order_index < v->GetNumOrders());
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2121 assert(v->cur_real_order_index < v->GetNumOrders());
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2122
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2123 /* Get the current order */
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2124 order = v->GetOrder(v->cur_real_order_index);
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2125 if (order != NULL && order->IsType(OT_IMPLICIT)) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2126 assert(v->GetNumManualOrders() == 0);
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2127 order = NULL;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2128 }
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2129
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
2130 if (order == NULL) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2131 v->current_order.Free();
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2132 v->dest_tile = 0;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2133 return false;
16907
e2be394e4714 (svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents: 16869
diff changeset
2134 }
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2135
12377
0762b2672bc9 (svn r16802) -Fix [FS#3031]: service orders didn't behave like conditional orders; if a train doesn't need service it didn't completely skip the order, it would first send the vehicle towards the depot and would then realise it doesn't need to go there making it possible that the vehicle leaves that station on the wrong side.
rubidium <rubidium@openttd.org>
parents: 12361
diff changeset
2136 v->current_order = *order;
17804
7fc728e847d1 (svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
frosch <frosch@openttd.org>
parents: 17693
diff changeset
2137 return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2138 }
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2139
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2140 /**
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2141 * Handle the orders of a vehicle and determine the next place
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2142 * to go to if needed.
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2143 * @param v the vehicle to do this for.
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2144 * @return true *if* the vehicle is eligible for reversing
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2145 * (basically only when leaving a station).
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2146 */
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2147 bool ProcessOrders(Vehicle *v)
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2148 {
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
2149 switch (v->current_order.GetType()) {
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2150 case OT_GOTO_DEPOT:
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2151 /* Let a depot order in the orderlist interrupt. */
8853
02787d6f3834 (svn r12615) -Codechange: rename some enums related to depot orders to make it more clear that they are no loading/unloading flags. Also add more type strictness.
rubidium <rubidium@openttd.org>
parents: 8851
diff changeset
2152 if (!(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) return false;
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2153 break;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2154
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2155 case OT_LOADING:
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2156 return false;
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2157
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2158 case OT_LEAVESTATION:
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2159 if (v->type != VEH_AIRCRAFT) return false;
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2160 break;
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2161
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2162 default: break;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2163 }
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2164
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2165 /**
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2166 * Reversing because of order change is allowed only just after leaving a
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2167 * station (and the difficulty setting to allowed, of course)
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2168 * this can be detected because only after OT_LEAVESTATION, current_order
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2169 * will be reset to nothing. (That also happens if no order, but in that case
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2170 * it won't hit the point in code where may_reverse is checked)
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2171 */
8836
890a77315801 (svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents: 8835
diff changeset
2172 bool may_reverse = v->current_order.IsType(OT_NOTHING);
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2173
15897
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2174 /* Check if we've reached a 'via' destination. */
12503
9da198c570da (svn r16940) -Codechange: make the pathfinders behave the same when finding waypoints or stations, i.e. don't force exactly one destination tile for a waypoint
rubidium <rubidium@openttd.org>
parents: 12475
diff changeset
2175 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)) &&
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2176 IsTileType(v->tile, MP_STATION) &&
8840
c3d2f0eb69a1 (svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents: 8839
diff changeset
2177 v->current_order.GetDestination() == GetStationIndex(v->tile)) {
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2178 v->DeleteUnreachedImplicitOrders();
15897
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2179 /* We set the last visited station here because we do not want
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2180 * the train to stop at this 'via' station if the next order
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2181 * is a no-non-stop order; in that case not setting the last
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2182 * visited station will cause the vehicle to still stop. */
d613f94dd4ab (svn r20580) -Fix [FS#4039]: go via station and go via waypoint behaved differently when a train went back to the same (unordered) station again
rubidium <rubidium@openttd.org>
parents: 15889
diff changeset
2183 v->last_station_visited = v->current_order.GetDestination();
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2184 UpdateVehicleTimetable(v, true);
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2185 v->IncrementImplicitOrderIndex();
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2186 }
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2187
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2188 /* Get the current order */
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2189 assert(v->cur_implicit_order_index == 0 || v->cur_implicit_order_index < v->GetNumOrders());
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2190 v->UpdateRealOrderIndex();
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2191
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2192 const Order *order = v->GetOrder(v->cur_real_order_index);
17693
cdeed5a57cdb (svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents: 17567
diff changeset
2193 if (order != NULL && order->IsType(OT_IMPLICIT)) {
17194
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2194 assert(v->GetNumManualOrders() == 0);
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2195 order = NULL;
b590eca5d805 (svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents: 17109
diff changeset
2196 }
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2197
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2198 /* If no order, do nothing. */
14072
7a6b0728bf33 (svn r18615) -Fix: conditional orders were seen as 'valid' and as such aircraft with only conditional orders did not crash
rubidium <rubidium@openttd.org>
parents: 13883
diff changeset
2199 if (order == NULL || (v->type == VEH_AIRCRAFT && !CheckForValidOrders(v))) {
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2200 if (v->type == VEH_AIRCRAFT) {
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2201 /* Aircraft do something vastly different here, so handle separately */
11981
cf1aad9b971c (svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents: 11972
diff changeset
2202 extern void HandleMissingAircraftOrders(Aircraft *v);
12114
f020ec6be498 (svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents: 12082
diff changeset
2203 HandleMissingAircraftOrders(Aircraft::From(v));
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2204 return false;
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2205 }
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2206
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2207 v->current_order.Free();
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2208 v->dest_tile = 0;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2209 return false;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2210 }
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2211
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2212 /* If it is unchanged, keep it. */
8911
72fcd1140679 (svn r12681) -Fix [FS#1921]: aircraft stopping mid-air.
rubidium <rubidium@openttd.org>
parents: 8909
diff changeset
2213 if (order->Equals(v->current_order) && (v->type == VEH_AIRCRAFT || v->dest_tile != 0) &&
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11866
diff changeset
2214 (v->type != VEH_SHIP || !order->IsType(OT_GOTO_STATION) || Station::Get(order->GetDestination())->dock_tile != INVALID_TILE)) {
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2215 return false;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2216 }
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2217
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2218 /* Otherwise set it, and determine the destination tile. */
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2219 v->current_order = *order;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2220
19900
b4c4f1c24136 (svn r24833) -Codechange: Replace magic numbers for invalidating vehicle-related windows with an enum.
michi_cc <michi_cc@openttd.org>
parents: 19550
diff changeset
2221 InvalidateVehicleOrder(v, VIWD_MODIFY_ORDERS);
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2222 switch (v->type) {
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2223 default:
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2224 NOT_REACHED();
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2225
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2226 case VEH_ROAD:
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2227 case VEH_TRAIN:
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2228 break;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2229
8830
981a95f3204d (svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents: 8827
diff changeset
2230 case VEH_AIRCRAFT:
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2231 case VEH_SHIP:
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12892
diff changeset
2232 SetWindowClassesDirty(GetWindowClassForVehicleType(v->type));
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2233 break;
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2234 }
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2235
9440
8400f3760306 (svn r13358) -Codechange: split next order determination and conditional order processing functionality from the order handling. Patch based on work by michi_cc.
rubidium <rubidium@openttd.org>
parents: 9413
diff changeset
2236 return UpdateOrderDest(v, order) && may_reverse;
8827
095c429c5fa7 (svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents: 8787
diff changeset
2237 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
2238
8832
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2239 /**
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2240 * Check whether the given vehicle should stop at the given station
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2241 * based on this order and the non-stop settings.
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2242 * @param v the vehicle that might be stopping.
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2243 * @param station the station to stop at.
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2244 * @return true if the vehicle should stop.
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2245 */
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2246 bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2247 {
8941
3b0ffce16526 (svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch <frosch@openttd.org>
parents: 8926
diff changeset
2248 bool is_dest_station = this->IsType(OT_GOTO_STATION) && this->dest == station;
16547
a11cd939c335 (svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents: 15916
diff changeset
2249
a11cd939c335 (svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents: 15916
diff changeset
2250 return (!this->IsType(OT_GOTO_DEPOT) || (this->GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0) &&
8832
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2251 v->last_station_visited != station && // Do stop only when we've not just been there
8848
066a8010467f (svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium <rubidium@openttd.org>
parents: 8847
diff changeset
2252 /* Finally do stop when there is no non-stop flag set for this type of station. */
8941
3b0ffce16526 (svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch <frosch@openttd.org>
parents: 8926
diff changeset
2253 !(this->GetNonStopType() & (is_dest_station ? ONSF_NO_STOP_AT_DESTINATION_STATION : ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS));
8832
870ff040ec3e (svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents: 8830
diff changeset
2254 }
20307
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2255
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2256 bool Order::CanLoadOrUnload() const
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2257 {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2258 return (this->IsType(OT_GOTO_STATION) || this->IsType(OT_IMPLICIT)) &&
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2259 (this->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0 &&
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2260 ((this->GetLoadType() & OLFB_NO_LOAD) == 0 ||
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2261 (this->GetUnloadType() & OUFB_NO_UNLOAD) == 0);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2262 }
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2263
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2264 /**
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2265 * A vehicle can leave the current station with cargo if:
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2266 * 1. it can load cargo here OR
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2267 * 2a. it could leave the last station with cargo AND
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2268 * 2b. it doesn't have to unload all cargo here.
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2269 */
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2270 bool Order::CanLeaveWithCargo(bool has_cargo) const
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2271 {
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2272 return (this->GetLoadType() & OLFB_NO_LOAD) == 0 || (has_cargo &&
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2273 (this->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == 0);
93d7e37bd666 (svn r25259) -Codechange: track capacities and usage of links
rubidium <rubidium@openttd.org>
parents: 20102
diff changeset
2274 }