Mercurial > hg > openttd
annotate src/order_cmd.cpp @ 18043:c9919ff3aae4 draft
(svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
author | frosch <frosch@openttd.org> |
---|---|
date | Tue, 30 Aug 2011 20:21:01 +0000 |
parents | 885fa3a8d835 |
children | 137b272acca5 |
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" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 #include "vehicle_gui.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8064
diff
changeset
|
19 #include "strings_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8130
diff
changeset
|
20 #include "window_func.h" |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
21 #include "timetable.h" |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
22 #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
|
23 #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
|
24 #include "core/pool_func.hpp" |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
25 #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
|
26 #include "roadveh.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12225
diff
changeset
|
27 #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
|
28 #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
|
29 #include "company_base.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 |
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
|
44 /** |
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
|
45 * '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
|
46 * @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
|
47 */ |
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
|
48 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
|
49 { |
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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 } |
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
|
55 |
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
|
56 /** |
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 * 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
|
58 * @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
|
59 */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
60 void Order::MakeGoToStation(StationID destination) |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
61 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
62 this->type = OT_GOTO_STATION; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
63 this->flags = 0; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
64 this->dest = destination; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
65 } |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
66 |
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
|
67 /** |
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
|
68 * 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
|
69 * @param destination the depot 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
|
70 * @param order is this order a 'default' order, or an overriden vehicle 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 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
|
72 * @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
|
73 * @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
|
74 * @param subtype the subtype 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
|
75 */ |
11809
57fd0a8c36cb
(svn r16199) -Codechange: Pass OrderNonStopFlags also to MakeGoToDepotOrder().
frosch <frosch@openttd.org>
parents:
11730
diff
changeset
|
76 void Order::MakeGoToDepot(DepotID destination, OrderDepotTypeFlags order, OrderNonStopFlags non_stop_type, OrderDepotActionFlags action, CargoID cargo, byte subtype) |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
77 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
78 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
|
79 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
|
80 this->SetDepotActionType(action); |
11809
57fd0a8c36cb
(svn r16199) -Codechange: Pass OrderNonStopFlags also to MakeGoToDepotOrder().
frosch <frosch@openttd.org>
parents:
11730
diff
changeset
|
81 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
|
82 this->dest = destination; |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
83 this->SetRefit(cargo, subtype); |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
84 } |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
85 |
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
|
86 /** |
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 * 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
|
88 * @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
|
89 */ |
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
|
90 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
|
91 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
92 this->type = OT_GOTO_WAYPOINT; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
93 this->flags = 0; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
94 this->dest = destination; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
95 } |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
96 |
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
|
97 /** |
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 * 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
|
99 * @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
|
100 */ |
8843
1f412a20da48
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents:
8840
diff
changeset
|
101 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
|
102 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
103 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
|
104 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
|
105 } |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
106 |
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
|
107 /** |
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
|
108 * 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
|
109 */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
110 void Order::MakeLeaveStation() |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
111 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
112 this->type = OT_LEAVESTATION; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
113 this->flags = 0; |
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 |
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
|
116 /** |
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
|
117 * 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
|
118 */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
119 void Order::MakeDummy() |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
120 { |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
121 this->type = OT_DUMMY; |
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
122 this->flags = 0; |
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 |
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
|
125 /** |
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
|
126 * 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
|
127 * @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
|
128 */ |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
129 void Order::MakeConditional(VehicleOrderID order) |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
130 { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
131 this->type = OT_CONDITIONAL; |
8901
f30afabf2b45
(svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium <rubidium@openttd.org>
parents:
8900
diff
changeset
|
132 this->flags = order; |
f30afabf2b45
(svn r12668) -Fix (12667): swapping of variables went wrong.
rubidium <rubidium@openttd.org>
parents:
8900
diff
changeset
|
133 this->dest = 0; |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
134 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
135 |
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
|
136 /** |
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
|
137 * 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
|
138 * @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
|
139 */ |
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
|
140 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
|
141 { |
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
|
142 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
|
143 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
|
144 } |
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
|
145 |
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
|
146 /** |
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
|
147 * Make this depot order also a refit 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
|
148 * @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
|
149 * @param subtype the subtype 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
|
150 * @pre IsType(OT_GOTO_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
|
151 */ |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
152 void Order::SetRefit(CargoID cargo, byte subtype) |
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
153 { |
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
154 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
|
155 this->refit_subtype = subtype; |
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
156 } |
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
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 /** |
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
|
159 * 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
|
160 * @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
|
161 * @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
|
162 */ |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
163 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
|
164 { |
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
|
165 /* 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
|
166 * 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
|
167 * 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
|
168 * 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
|
169 * 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
|
170 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
|
171 ((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
|
172 (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
|
173 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
|
174 (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
|
175 } |
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 |
16547
a11cd939c335
(svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents:
15916
diff
changeset
|
177 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
|
178 } |
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
179 |
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
|
180 /** |
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
|
181 * 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
|
182 * 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
|
183 * @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
|
184 * @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
|
185 */ |
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
|
186 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
|
187 { |
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
|
188 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
|
189 } |
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
|
190 |
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
|
191 /** |
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 * 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
|
193 * 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
|
194 * @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
|
195 */ |
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
|
196 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
|
197 { |
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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
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 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
|
214 } |
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 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
|
216 } |
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 |
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
|
218 /** |
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
|
219 * 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
|
220 * @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
|
221 */ |
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
|
222 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
|
223 { |
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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 this->refit_subtype = 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
|
230 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
|
231 this->travel_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
|
232 } |
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
|
233 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
235 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 * 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
|
237 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
238 */ |
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
|
239 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
|
240 { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12892
diff
changeset
|
241 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
|
242 |
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
|
243 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
|
244 /* 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
|
245 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
|
246 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
|
247 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
|
248 } |
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 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12892
diff
changeset
|
250 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
|
251 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
|
252 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 * |
14136
54dfd3720fa1
(svn r18683) -Fix: it's not an other
rubidium <rubidium@openttd.org>
parents:
14113
diff
changeset
|
256 * 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
|
257 * 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
|
258 * @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
|
259 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 */ |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
261 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
|
262 { |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
263 this->type = other.type; |
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
264 this->flags = other.flags; |
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
265 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
|
266 |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
267 this->refit_cargo = other.refit_cargo; |
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
268 this->refit_subtype = other.refit_subtype; |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6950
diff
changeset
|
269 |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
270 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
|
271 this->travel_time = other.travel_time; |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 |
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
|
274 /** |
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
|
275 * 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
|
276 * @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
|
277 * @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
|
278 */ |
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
|
279 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
|
280 { |
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
|
281 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
|
282 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
|
283 |
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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 |
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
|
289 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
|
290 ++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
|
291 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
|
292 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
|
293 } |
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
|
294 |
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
|
295 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
|
296 ++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
|
297 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
|
298 } |
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 |
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 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
|
301 } |
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 |
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
|
303 /** |
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
|
304 * 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
|
305 * @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
|
306 * @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
|
307 */ |
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
|
308 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
|
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 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
|
311 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
|
312 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
|
313 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
|
314 } |
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
|
315 |
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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 } 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
|
322 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
|
323 } |
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 |
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
|
326 /** |
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
|
327 * 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
|
328 * @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
|
329 * @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
|
330 */ |
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
|
331 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
|
332 { |
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 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
|
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 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
|
336 |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15040
diff
changeset
|
337 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
|
338 order = order->next; |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15040
diff
changeset
|
339 } |
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
|
340 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
|
341 } |
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 |
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
|
343 /** |
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
|
344 * 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
|
345 * @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
|
346 * @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
|
347 */ |
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 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
|
349 { |
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 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
|
351 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
|
352 } 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
|
353 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
|
354 /* 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
|
355 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
|
356 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
|
357 } 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
|
358 /* 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
|
359 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
|
360 } 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
|
361 /* 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
|
362 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
|
363 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
|
364 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
|
365 } |
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
|
366 } |
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
|
367 ++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
|
368 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
|
369 this->timetable_duration += new_order->wait_time + new_order->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
|
370 } |
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
|
371 |
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
|
372 |
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
|
373 /** |
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
|
374 * 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
|
375 * @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
|
376 */ |
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
|
377 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
|
378 { |
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
|
379 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
|
380 |
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
|
381 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
|
382 |
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
|
383 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
|
384 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
|
385 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
|
386 } 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
|
387 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
|
388 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
|
389 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
|
390 } |
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
|
391 --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
|
392 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
|
393 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
|
394 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
|
395 } |
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
|
396 |
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
|
397 /** |
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
|
398 * 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
|
399 * @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
|
400 * @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
|
401 */ |
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
|
402 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
|
403 { |
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
|
404 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
|
405 |
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
|
406 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
|
407 |
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
|
408 /* 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
|
409 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
|
410 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
|
411 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
|
412 } 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
|
413 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
|
414 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
|
415 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
|
416 } |
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
|
417 |
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
|
418 /* 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
|
419 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
|
420 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
|
421 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
|
422 } 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
|
423 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
|
424 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
|
425 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
|
426 } |
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
|
427 } |
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
|
428 |
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
|
429 /** |
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
|
430 * 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
|
431 * @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
|
432 * @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
|
433 */ |
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
|
434 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
|
435 { |
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
|
436 --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
|
437 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
|
438 } |
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
|
439 |
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
|
440 /** |
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
|
441 * 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
|
442 * @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
|
443 */ |
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
|
444 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
|
445 { |
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
|
446 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
|
447 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
|
448 } |
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
|
449 |
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
|
450 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
|
451 } |
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
|
452 |
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
|
453 /** |
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
|
454 * 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
|
455 * @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
|
456 * @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
|
457 */ |
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
|
458 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
|
459 { |
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
|
460 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
|
461 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
|
462 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
|
463 } |
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
|
464 |
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
|
465 /** |
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
|
466 * 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
|
467 * @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
|
468 */ |
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
|
469 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
|
470 { |
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
|
471 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
|
472 /* 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
|
473 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
|
474 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
|
475 } |
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
|
476 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
|
477 } |
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
|
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 /** |
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 * 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
|
481 */ |
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
|
482 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
|
483 { |
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 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
|
485 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
|
486 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
|
487 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
|
488 |
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 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
|
490 |
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 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
|
492 ++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
|
493 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
|
494 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
|
495 } |
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 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
|
497 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
|
498 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
|
499 |
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 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
|
501 ++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
|
502 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
|
503 } |
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 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
|
505 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
|
506 (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
|
507 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
|
508 } |
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
|
509 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
510 /** |
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
|
511 * 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
|
512 * 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
|
513 * @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
|
514 * @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
|
515 * @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
|
516 */ |
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
|
517 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
|
518 { |
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
|
519 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
|
520 (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
|
521 } |
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
|
522 |
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
|
523 /** |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
524 * 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
|
525 * 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
|
526 * 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
|
527 * 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
|
528 */ |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10582
diff
changeset
|
529 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
|
530 { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12538
diff
changeset
|
531 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
|
532 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
|
533 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
|
534 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
|
535 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
536 |
14638
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
537 /** |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
538 * 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
|
539 * @param v The vehicle to get the location for. |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
540 * @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
|
541 */ |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
542 TileIndex Order::GetLocation(const Vehicle *v) const |
6071 | 543 { |
14638
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
544 switch (this->GetType()) { |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
545 case OT_GOTO_WAYPOINT: |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
546 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
|
547 case OT_IMPLICIT: |
14638
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
548 return BaseStation::Get(this->GetDestination())->xy; |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
549 |
14633
31e99b467d35
(svn r19210) -Fix: GetDestination() is invalid for nearest-depot orders.
frosch <frosch@openttd.org>
parents:
14258
diff
changeset
|
550 case OT_GOTO_DEPOT: |
14638
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
551 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
|
552 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
|
553 |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
554 default: |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
555 return INVALID_TILE; |
6071 | 556 } |
557 } | |
558 | |
9609
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
559 static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0) |
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
560 { |
12361
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
561 assert(v->type == VEH_SHIP); |
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
562 |
9609
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
563 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
|
564 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
|
565 |
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
566 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
|
567 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11983
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 } |
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
572 |
14638
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
573 TileIndex prev_tile = prev->GetLocation(v); |
82bfab312c8e
(svn r19215) -Codechange: Add Order::GetLocation() to deduplicate code.
frosch <frosch@openttd.org>
parents:
14633
diff
changeset
|
574 TileIndex cur_tile = cur->GetLocation(v); |
14633
31e99b467d35
(svn r19210) -Fix: GetDestination() is invalid for nearest-depot orders.
frosch <frosch@openttd.org>
parents:
14258
diff
changeset
|
575 if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0; |
31e99b467d35
(svn r19210) -Fix: GetDestination() is invalid for nearest-depot orders.
frosch <frosch@openttd.org>
parents:
14258
diff
changeset
|
576 return 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
|
577 } |
6071 | 578 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
579 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
580 * 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
|
581 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
582 * @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
|
583 * @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
|
584 * - 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
|
585 * - 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
|
586 * 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
|
587 * 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
|
588 * @param p2 packed order to insert |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
589 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
590 * @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
|
591 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
592 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
|
593 { |
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
|
594 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
|
595 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
|
596 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
|
597 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
598 Vehicle *v = Vehicle::GetIfValid(veh); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
599 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
|
600 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
601 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
602 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
|
603 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
604 /* 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
|
605 * 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
611 if (st->owner != OWNER_NONE) { |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
612 CommandCost ret = CheckOwnership(st->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
613 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
614 } |
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
|
615 |
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
|
616 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
|
617 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
|
618 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
|
619 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 |
16783
37b5683941fa
(svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents:
16733
diff
changeset
|
621 /* 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
|
622 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
|
623 |
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
|
624 /* 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
|
625 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
|
626 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
|
627 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
|
628 } |
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
|
629 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
|
630 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
|
631 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
|
632 } |
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
|
633 |
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
|
634 /* 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 /* 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
|
640 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
|
641 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
|
642 |
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
|
643 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
|
644 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
|
645 } |
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
|
646 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
647 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
648 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
649 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 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
|
654 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
655 if (st == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
656 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
657 CommandCost ret = CheckOwnership(st->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
658 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
659 |
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
|
660 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
|
661 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
|
662 } |
2bcad37f1d27
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents:
8885
diff
changeset
|
663 } else { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
664 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
|
665 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
666 if (dp == NULL) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
667 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
668 CommandCost ret = CheckOwnership(GetTileOwner(dp->xy)); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
669 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
|
670 |
2bcad37f1d27
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents:
8885
diff
changeset
|
671 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
|
672 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
|
673 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
|
674 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
|
675 |
2bcad37f1d27
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents:
8885
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 |
2bcad37f1d27
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents:
8885
diff
changeset
|
680 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
|
681 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
|
682 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
|
683 |
2bcad37f1d27
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
rubidium <rubidium@openttd.org>
parents:
8885
diff
changeset
|
684 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
|
685 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 |
16783
37b5683941fa
(svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents:
16733
diff
changeset
|
689 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
|
690 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
|
691 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
|
692 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
|
693 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 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
|
697 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
|
698 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
|
699 |
12361
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
700 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
|
701 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
|
702 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
703 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
|
704 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
|
705 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
706 CommandCost ret = CheckOwnership(wp->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
707 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
|
708 break; |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
709 } |
12361
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
710 |
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
|
711 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
|
712 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
|
713 if (wp->owner != OWNER_NONE) { |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
714 CommandCost ret = CheckOwnership(wp->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
715 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
716 } |
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
|
717 break; |
12361
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
718 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
719 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
720 /* 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
|
721 * [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
|
722 * 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
|
723 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
|
724 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
|
725 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
726 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
727 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
|
728 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
|
729 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
|
730 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
|
731 |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
732 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 break; |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
738 |
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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
744 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
|
745 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
|
746 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
|
747 /* 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
|
748 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
|
749 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
|
750 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
|
751 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
752 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
753 } |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
754 |
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 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
|
756 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
757 |
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
|
758 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
|
759 |
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
|
760 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
|
761 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
|
762 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
|
763 |
10993
8bb5d1f28e00
(svn r15333) -Fix: AIs weren't restricted to a maximum length for ship orders.
Yexo <Yexo@openttd.org>
parents:
10969
diff
changeset
|
764 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
|
765 /* Make sure the new destination is not too far away from the previous */ |
6071 | 766 const Order *prev = NULL; |
767 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
|
768 |
6071 | 769 /* Find the last goto station or depot order before the insert location. |
770 * If the order is to be inserted at the beginning of the order list this | |
771 * 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 prev = o; |
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
779 break; |
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
780 |
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
781 default: break; |
82830e1cd892
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
782 } |
6071 | 783 if (++n == sel_ord && prev != NULL) break; |
784 } | |
785 if (prev != NULL) { | |
9609
fe9766039f5b
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
rubidium <rubidium@openttd.org>
parents:
9593
diff
changeset
|
786 uint dist = GetOrderDistance(prev, &new_order, v); |
6071 | 787 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
|
788 return_cmd_error(STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION); |
6071 | 789 } |
790 } | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
791 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
793 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
|
794 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
|
795 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
|
796 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
|
797 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
798 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
799 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
|
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 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
802 /** |
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
|
803 * 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
|
804 * @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
|
805 * @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
|
806 * @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
|
807 */ |
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
|
808 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
|
809 { |
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
|
810 /* 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
|
811 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
|
812 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
|
813 } 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
|
814 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
|
815 } |
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
|
816 |
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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 |
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
|
822 /* 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
|
823 * 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
|
824 * 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
|
825 * 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
|
826 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
|
827 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
|
828 /* 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
|
829 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
|
830 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
|
831 } |
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
|
832 } |
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
|
833 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
|
834 /* 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
|
835 * 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
|
836 * 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
|
837 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
|
838 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
|
839 } |
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
|
840 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
|
841 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
|
842 /* 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
|
843 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
|
844 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
|
845 } |
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
|
846 } |
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
|
847 /* 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
|
848 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
|
849 } |
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
|
850 |
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
|
851 /* 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 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
|
859 } |
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
|
860 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
|
861 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
|
862 } |
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
|
863 } |
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
|
864 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
|
865 } |
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
|
866 |
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
|
867 /* 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
|
868 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
|
869 } |
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
|
870 |
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
|
871 /** |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
872 * 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
|
873 * @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
|
874 * @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
|
875 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
876 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
|
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 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
|
879 DeleteVehicleOrders(dst); |
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
|
880 InvalidateVehicleOrder(dst, -1); |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9234
diff
changeset
|
881 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
|
882 } |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
883 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
|
884 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
885 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
886 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
887 * 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
|
888 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
889 * @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
|
890 * @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
|
891 * @param p2 the order to delete (max 255) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
892 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
893 * @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
|
894 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
895 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
|
896 { |
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
|
897 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
|
898 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
|
899 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
900 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
|
901 |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
902 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
|
903 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
904 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
905 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
|
906 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
907 /* 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
|
908 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
|
909 |
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
|
910 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
|
911 |
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
|
912 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
|
913 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
|
914 } |
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 |
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
|
916 /** |
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
|
917 * 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
|
918 * @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
|
919 */ |
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
|
920 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
|
921 { |
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
|
922 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
|
923 /* 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
|
924 * 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
|
925 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
|
926 /* 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
|
927 * 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
|
928 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
|
929 } |
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
|
930 |
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
|
931 /** |
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
|
932 * 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
|
933 * @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
|
934 * @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
|
935 */ |
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
|
936 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
|
937 { |
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
|
938 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
|
939 |
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
|
940 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
|
941 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
|
942 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
|
943 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
|
944 |
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
|
945 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
|
946 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
|
947 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
948 |
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
|
949 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
|
950 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
|
951 } 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
|
952 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
|
953 } |
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
|
954 |
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
|
955 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
|
956 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
|
957 } 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
|
958 /* 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
|
959 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
|
960 |
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
|
961 /* 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
|
962 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
|
963 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
|
964 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
|
965 } |
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
|
966 } |
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
|
967 |
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
|
968 /* 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
|
969 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
|
970 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
971 |
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
|
972 /* 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
|
973 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
|
974 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
|
975 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
|
976 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
|
977 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
|
978 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
|
979 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
|
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 (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
|
982 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
|
983 } |
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
|
984 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
|
985 } |
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
|
986 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
|
987 } |
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 |
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
|
989 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
|
990 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
991 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
992 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
993 * 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
|
994 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
995 * @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
|
996 * @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
|
997 * @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
|
998 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
999 * @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
|
1000 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
1001 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
|
1002 { |
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
|
1003 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
|
1004 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
|
1005 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1006 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
|
1007 |
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
|
1008 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
|
1009 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1010 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1011 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
|
1012 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1013 if (flags & DC_EXEC) { |
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
|
1014 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
|
1015 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
|
1016 |
8843
1f412a20da48
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents:
8840
diff
changeset
|
1017 if (v->current_order.IsType(OT_LOADING)) v->LeaveStation(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1018 |
12892
2245b86757b7
(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
rubidium <rubidium@openttd.org>
parents:
12804
diff
changeset
|
1019 InvalidateVehicleOrder(v, -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
|
1020 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1021 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1022 /* 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
|
1023 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
|
1024 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
|
1025 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1026 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
|
1027 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1028 |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1029 /** |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1030 * Move an order inside the orderlist |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1031 * @param tile unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1032 * @param flags operation to perform |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1033 * @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
|
1034 * @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
|
1035 * 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
|
1036 * bit 16-31 : the target order |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1037 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1038 * @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
|
1039 * @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
|
1040 * 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
|
1041 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
1042 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
|
1043 { |
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
|
1044 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
|
1045 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
|
1046 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
|
1047 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1048 Vehicle *v = Vehicle::GetIfValid(veh); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
1049 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
|
1050 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1051 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1052 if (ret.Failed()) return ret; |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1053 |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1054 /* 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
|
1055 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
|
1056 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
|
1057 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11983
diff
changeset
|
1058 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
|
1059 /* Don't move an empty order */ |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1060 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
|
1061 |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1062 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
|
1063 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
|
1064 |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1065 /* 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
|
1066 Vehicle *u = v->FirstShared(); |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1067 |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1068 DeleteOrderWarnings(u); |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1069 |
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
|
1070 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
|
1071 /* 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
|
1072 * 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
|
1073 * 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
|
1074 * 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
|
1075 * |
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
|
1076 * 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
|
1077 * 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
|
1078 * 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
|
1079 * 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
|
1080 * 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
|
1081 * |
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
|
1082 * With that decision it basically does not matter what we do to 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
|
1083 * If we change orders between the implict- and real-index, the implicit orders are mostly likely |
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
|
1084 * 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
|
1085 * 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
|
1086 */ |
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
|
1087 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
|
1088 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
|
1089 } 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
|
1090 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
|
1091 } 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
|
1092 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
|
1093 } |
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
|
1094 |
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
|
1095 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
|
1096 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
|
1097 } 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
|
1098 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
|
1099 } 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
|
1100 u->cur_implicit_order_index++; |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1101 } |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1102 |
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
|
1103 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
|
1104 /* 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
|
1105 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
|
1106 } |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1107 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1108 /* 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
|
1109 Order *order; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1110 FOR_VEHICLE_ORDERS(v, order) { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1111 if (order->IsType(OT_CONDITIONAL)) { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1112 VehicleOrderID order_id = order->GetConditionSkipToOrder(); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1113 if (order_id == moving_order) { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1114 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
|
1115 } 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
|
1116 order_id--; |
12705
6b046fd8da1a
(svn r17168) -Codechange: apply coding style to if and while statements
smatz <smatz@openttd.org>
parents:
12619
diff
changeset
|
1117 } 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
|
1118 order_id++; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1119 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1120 order->SetConditionSkipToOrder(order_id); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1121 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1122 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1123 |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1124 /* 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
|
1125 InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0); |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1126 } |
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1127 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1128 return CommandCost(); |
6832
17319fb8c1c3
(svn r10071) -Feature [FS#828]: moving of orders (skidd13).
rubidium <rubidium@openttd.org>
parents:
6794
diff
changeset
|
1129 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1130 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1131 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1132 * 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
|
1133 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
1134 * @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
|
1135 * @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
|
1136 * - 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
|
1137 * - 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
|
1138 * 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
|
1139 * 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
|
1140 * @param p2 various bitstuffed elements |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1141 * - 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
|
1142 * - p2 = (bit 4 - 15) - the data to modify |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1143 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1144 * @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
|
1145 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
1146 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
|
1147 { |
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
|
1148 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
|
1149 VehicleID veh = GB(p1, 0, 20); |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14898
diff
changeset
|
1150 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
|
1151 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
|
1152 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1153 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
|
1154 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1155 Vehicle *v = Vehicle::GetIfValid(veh); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
1156 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
|
1157 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1158 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1159 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
|
1160 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1161 /* 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
|
1162 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
|
1163 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11983
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 |
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
|
1170 case OT_GOTO_DEPOT: |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1171 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
|
1172 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
|
1173 |
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
|
1174 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
|
1175 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
|
1176 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
|
1177 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1178 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
|
1179 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
|
1180 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1181 |
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
|
1182 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
|
1183 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
|
1184 } |
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
|
1185 |
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
|
1186 switch (mof) { |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1187 default: NOT_REACHED(); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1188 |
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
|
1189 case MOF_NON_STOP: |
16783
37b5683941fa
(svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
terkhen <terkhen@openttd.org>
parents:
16733
diff
changeset
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 |
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
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 |
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
|
1200 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
|
1201 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
|
1202 /* 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
|
1203 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
|
1204 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
|
1205 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
|
1206 |
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
|
1207 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
|
1208 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
|
1209 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
|
1210 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
|
1211 |
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
|
1212 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
|
1213 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
|
1214 break; |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1215 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1216 case MOF_COND_VARIABLE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1217 if (data >= OCV_END) return CMD_ERROR; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1218 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1219 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1220 case MOF_COND_COMPARATOR: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1221 if (data >= OCC_END) return CMD_ERROR; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1222 switch (order->GetConditionVariable()) { |
8903
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1223 case OCV_UNCONDITIONALLY: return CMD_ERROR; |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1224 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1225 case OCV_REQUIRES_SERVICE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1226 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
|
1227 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1228 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1229 default: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1230 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
|
1231 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1232 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1233 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1234 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1235 case MOF_COND_VALUE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1236 switch (order->GetConditionVariable()) { |
8903
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1237 case OCV_UNCONDITIONALLY: return CMD_ERROR; |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1238 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1239 case OCV_LOAD_PERCENTAGE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1240 case OCV_RELIABILITY: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1241 if (data > 100) return CMD_ERROR; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1242 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1243 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1244 default: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1245 if (data > 2047) return CMD_ERROR; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1246 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1247 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1248 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
|
1249 |
294a2fc5d425
(svn r13752) -Fix [FS#2130]: correctly restore conditional orders when they are put 'into' backup.
rubidium <rubidium@openttd.org>
parents:
9641
diff
changeset
|
1250 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
|
1251 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
|
1252 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
|
1253 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1254 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1255 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
|
1256 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
|
1257 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
|
1258 order->SetNonStopType((OrderNonStopFlags)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
|
1259 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
|
1260 |
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
|
1261 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
|
1262 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
|
1263 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
|
1264 |
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
|
1265 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
|
1266 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
|
1267 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
|
1268 |
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
|
1269 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
|
1270 order->SetLoadType((OrderLoadFlags)data); |
8845
bb04cb5677d8
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1271 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
|
1272 |
10285
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1273 case MOF_DEPOT_ACTION: { |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1274 switch (data) { |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1275 case DA_ALWAYS_GO: |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1276 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
|
1277 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
|
1278 break; |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1279 |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1280 case DA_SERVICE: |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1281 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
|
1282 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
|
1283 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
|
1284 break; |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1285 |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1286 case DA_STOP: |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1287 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
|
1288 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
|
1289 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
|
1290 break; |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1291 |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1292 default: |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1293 NOT_REACHED(); |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10226
diff
changeset
|
1294 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1295 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1296 } |
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
|
1297 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1298 case MOF_COND_VARIABLE: { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1299 order->SetConditionVariable((OrderConditionVariable)data); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1300 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1301 OrderConditionComparator occ = order->GetConditionComparator(); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1302 switch (order->GetConditionVariable()) { |
8903
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1303 case OCV_UNCONDITIONALLY: |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1304 order->SetConditionComparator(OCC_EQUALS); |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1305 order->SetConditionValue(0); |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1306 break; |
d15e125c0b6a
(svn r12670) -Add: unconditional/always order 'jump/skip' variable.
rubidium <rubidium@openttd.org>
parents:
8901
diff
changeset
|
1307 |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1308 case OCV_REQUIRES_SERVICE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1309 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
|
1310 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1311 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1312 case OCV_LOAD_PERCENTAGE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1313 case OCV_RELIABILITY: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1314 if (order->GetConditionValue() > 100) order->SetConditionValue(100); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1315 /* FALL THROUGH */ |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1316 default: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1317 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
|
1318 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1319 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1320 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1321 } |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1322 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1323 case MOF_COND_COMPARATOR: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1324 order->SetConditionComparator((OrderConditionComparator)data); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1325 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1326 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1327 case MOF_COND_VALUE: |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1328 order->SetConditionValue(data); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1329 break; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1330 |
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
|
1331 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
|
1332 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
|
1333 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
|
1334 |
8845
bb04cb5677d8
(svn r12595) -Codechange: hide Order's flags in the last few cases.
rubidium <rubidium@openttd.org>
parents:
8843
diff
changeset
|
1335 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
|
1336 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1337 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 /* 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
|
1339 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
|
1340 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
|
1341 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
|
1342 /* 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
|
1343 * 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
|
1344 * 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
|
1345 * 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
|
1346 * 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
|
1347 * 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
|
1348 * 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
|
1349 * 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
|
1350 */ |
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
|
1351 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
|
1352 (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
|
1353 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
|
1354 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
|
1355 } |
12892
2245b86757b7
(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
rubidium <rubidium@openttd.org>
parents:
12804
diff
changeset
|
1356 InvalidateVehicleOrder(u, -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
|
1357 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1358 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1359 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1360 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
|
1361 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1362 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1363 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1364 * 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
|
1365 * @param tile unused |
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
1366 * @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
|
1367 * @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
|
1368 * - 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
|
1369 * - 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
|
1370 * @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
|
1371 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1372 * @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
|
1373 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
1374 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
|
1375 { |
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
|
1376 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
|
1377 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
|
1378 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1379 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
|
1380 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
|
1381 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1382 CommandCost ret = CheckOwnership(dst->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1383 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
|
1384 |
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
|
1385 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
|
1386 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
|
1387 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
|
1388 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1389 /* Sanity checks */ |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
1390 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
|
1391 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1392 CommandCost ret = CheckOwnership(src->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1393 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
|
1394 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1395 /* 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
|
1396 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
|
1397 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
|
1398 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1399 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1400 /* 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
|
1401 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
|
1402 |
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
|
1403 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
|
1404 |
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
|
1405 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
|
1406 if (OrderGoesToStation(dst, order) && |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11866
diff
changeset
|
1407 !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
|
1408 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
|
1409 } |
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
|
1410 } |
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
|
1411 |
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
|
1412 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
|
1413 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
|
1414 } |
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
|
1415 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1416 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
|
1417 /* 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
|
1418 * 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
|
1419 * (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
|
1420 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
|
1421 |
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
|
1422 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
|
1423 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1424 /* 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
|
1425 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
|
1426 |
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
|
1427 InvalidateVehicleOrder(dst, -1); |
12892
2245b86757b7
(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
rubidium <rubidium@openttd.org>
parents:
12804
diff
changeset
|
1428 InvalidateVehicleOrder(src, -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
|
1429 |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9234
diff
changeset
|
1430 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
|
1431 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1432 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1433 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1434 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1435 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
|
1436 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
|
1437 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1438 /* Sanity checks */ |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
1439 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
|
1440 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1441 CommandCost ret = CheckOwnership(src->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1442 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
|
1443 |
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
|
1444 /* Trucks can't copy all the orders from busses (and visa versa), |
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
|
1445 * and neither can helicopters and aircarft. */ |
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
|
1446 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
|
1447 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
|
1448 if (OrderGoesToStation(dst, order) && |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11866
diff
changeset
|
1449 !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
|
1450 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
|
1451 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1452 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1453 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1454 /* make sure there are orders available */ |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1455 int delta = dst->IsOrderListShared() ? src->GetNumOrders() + 1 : src->GetNumOrders() - dst->GetNumOrders(); |
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
|
1456 if (!Order::CanAllocateItem(delta) || |
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
|
1457 ((dst->orders.list == NULL || dst->IsOrderListShared()) && !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
|
1458 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
|
1459 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1460 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1461 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
|
1462 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
|
1463 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
|
1464 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
|
1465 |
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
|
1466 /* 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
|
1467 * 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
|
1468 * (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
|
1469 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
|
1470 |
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
|
1471 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
|
1472 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
|
1473 *order_dst = new Order(); |
8835
e8296a8dbe93
(svn r12583) -Codechange: make AssignOrder a class function of order.
rubidium <rubidium@openttd.org>
parents:
8834
diff
changeset
|
1474 (*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
|
1475 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
|
1476 } |
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
|
1477 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
|
1478 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
|
1479 } 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
|
1480 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
|
1481 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
|
1482 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
|
1483 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
|
1484 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
|
1485 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 |
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
|
1487 InvalidateVehicleOrder(dst, -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
|
1488 |
9297
add307f2e6ea
(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.
rubidium <rubidium@openttd.org>
parents:
9234
diff
changeset
|
1489 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
|
1490 } |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1491 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15569
diff
changeset
|
1492 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1493 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1494 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
|
1495 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
|
1496 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1497 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1498 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
|
1499 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1500 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1501 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
1502 * 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
|
1503 * @param tile Not used |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6370
diff
changeset
|
1504 * @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
|
1505 * @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
|
1506 * @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
|
1507 * - 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
|
1508 * - bit 8-15 Cargo subtype |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1509 * - bit 16-23 number of order to modify |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1510 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1511 * @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
|
1512 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11014
diff
changeset
|
1513 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
|
1514 { |
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
|
1515 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
|
1516 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
|
1517 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
|
1518 byte subtype = GB(p2, 8, 8); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1519 |
17003
eefeb3bca2f3
(svn r21739) -Fix [FS#4388] (r19657): make clearing refit orders work again
rubidium <rubidium@openttd.org>
parents:
17001
diff
changeset
|
1520 if (cargo >= NUM_CARGO && cargo != CT_NO_REFIT) return CMD_ERROR; |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
1521 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1522 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
|
1523 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
|
1524 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1525 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14638
diff
changeset
|
1526 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
|
1527 |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11983
diff
changeset
|
1528 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
|
1529 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
|
1530 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1531 if (flags & DC_EXEC) { |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
1532 order->SetRefit(cargo, subtype); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1533 |
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
|
1534 /* Make the depot order an 'always go' order. */ |
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
|
1535 if (cargo != CT_NO_REFIT) { |
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
|
1536 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
|
1537 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
|
1538 } |
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
|
1539 |
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
|
1540 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
|
1541 /* Update any possible open window of the vehicle */ |
12892
2245b86757b7
(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
rubidium <rubidium@openttd.org>
parents:
12804
diff
changeset
|
1542 InvalidateVehicleOrder(u, -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
|
1543 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1544 /* 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
|
1545 if (u->cur_real_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) { |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
1546 u->current_order.SetRefit(cargo, subtype); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1547 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1548 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1549 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1550 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
1551 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
|
1552 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1553 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1554 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1555 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1556 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1557 * 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
|
1558 * |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1559 */ |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10582
diff
changeset
|
1560 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
|
1561 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1562 /* 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
|
1563 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
|
1564 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1565 /* 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
|
1566 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
|
1567 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1568 /* 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
|
1569 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
|
1570 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1571 /* 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
|
1572 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
|
1573 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1574 /* 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
|
1575 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
|
1576 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
|
1577 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
|
1578 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
|
1579 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1580 /* 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
|
1581 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
|
1582 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1583 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
|
1584 /* Dummy order? */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
1585 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
|
1586 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
|
1587 break; |
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 /* 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
|
1590 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
|
1591 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
|
1592 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1593 n_st++; |
14113
7cfec5bb9c2c
(svn r18660) -Cleanup: remove useless function
yexo <yexo@openttd.org>
parents:
14072
diff
changeset
|
1594 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
|
1595 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1596 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1597 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1598 /* 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
|
1599 if (v->GetNumOrders() > 1) { |
11991
a4d3838349e6
(svn r16397) -Codechange: move GetVehicleOrder/GetLastVehicleOrder into Vehicle
rubidium <rubidium@openttd.org>
parents:
11983
diff
changeset
|
1600 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
|
1601 |
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
|
1602 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
|
1603 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
|
1604 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1605 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1606 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1607 /* 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
|
1608 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
|
1609 |
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
|
1610 #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
|
1611 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
|
1612 #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
|
1613 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1614 /* 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
|
1615 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
|
1616 |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12538
diff
changeset
|
1617 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
|
1618 //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
|
1619 |
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
|
1620 SetDParam(0, v->index); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
11991
diff
changeset
|
1621 AddVehicleNewsItem( |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1622 message, |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9111
diff
changeset
|
1623 NS_ADVICE, |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
11991
diff
changeset
|
1624 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
|
1625 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1626 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1627 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1628 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1629 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1630 * 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
|
1631 * @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
|
1632 * @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
|
1633 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1634 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
|
1635 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1636 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
|
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 /* 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
|
1639 * 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
|
1640 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1641 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1642 /* 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
|
1643 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
|
1644 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
|
1645 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1646 order = &v->current_order; |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
1647 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
|
1648 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
|
1649 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
|
1650 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
|
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 /* 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
|
1654 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
|
1655 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
|
1656 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
|
1657 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
|
1658 |
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
|
1659 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
|
1660 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
|
1661 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
|
1662 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
|
1663 /* 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
|
1664 * 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
|
1665 * 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
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 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
|
1671 } |
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
|
1672 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
1673 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
|
1674 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
|
1675 /* 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
|
1676 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
|
1677 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
|
1678 } |
10020
516f3198d980
(svn r14179) -Fix (r1): RemoveOrderFromAllVehicles() did not mark enough windows dirty.
frosch <frosch@openttd.org>
parents:
10019
diff
changeset
|
1679 } |
516f3198d980
(svn r14179) -Fix (r1): RemoveOrderFromAllVehicles() did not mark enough windows dirty.
frosch <frosch@openttd.org>
parents:
10019
diff
changeset
|
1680 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1681 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1682 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1683 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1684 /** |
16733
4b988ed6473a
(svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
16547
diff
changeset
|
1685 * 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
|
1686 * @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
|
1687 */ |
16733
4b988ed6473a
(svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
16547
diff
changeset
|
1688 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
|
1689 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1690 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
|
1691 |
16733
4b988ed6473a
(svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
16547
diff
changeset
|
1692 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
|
1693 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
|
1694 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1695 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1696 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
|
1697 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1698 |
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 * 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
|
1701 * @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
|
1702 * @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
|
1703 * @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
|
1704 * 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
|
1705 * 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
|
1706 * 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
|
1707 */ |
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
|
1708 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
|
1709 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1710 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
|
1711 |
8469
066d7c3ca93d
(svn r12040) -Codechange: Change IsOrderListShared from a simple function to a class member(MagicBuzz).
belugas <belugas@openttd.org>
parents:
8373
diff
changeset
|
1712 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
|
1713 /* 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
|
1714 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
|
1715 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
|
1716 } 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
|
1717 /* 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
|
1718 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
|
1719 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
|
1720 } |
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
|
1721 |
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
|
1722 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
|
1723 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
|
1724 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
|
1725 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
|
1726 } |
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
|
1727 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1729 |
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
|
1730 /** |
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
|
1731 * 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
|
1732 * 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
|
1733 * @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
|
1734 * @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
|
1735 * @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
|
1736 */ |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12010
diff
changeset
|
1737 uint16 GetServiceIntervalClamped(uint interval, CompanyID company_id) |
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
|
1738 { |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12010
diff
changeset
|
1739 return (Company::Get(company_id)->settings.vehicle.servint_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
|
1740 } |
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
|
1741 |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1742 /** |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1743 * |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1744 * 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
|
1745 * |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1746 * @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
|
1747 * @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
|
1748 * |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1749 */ |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1750 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
|
1751 { |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1752 const Order *order; |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1753 |
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
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 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
|
1760 |
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
|
1761 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
|
1762 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
|
1763 } |
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
|
1764 } |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1765 |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1766 return false; |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1767 } |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1768 |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1769 /** |
8900
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1770 * 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
|
1771 */ |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1772 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
|
1773 { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1774 switch (occ) { |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1775 case OCC_EQUALS: return variable == value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1776 case OCC_NOT_EQUALS: return variable != value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1777 case OCC_LESS_THAN: return variable < value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1778 case OCC_LESS_EQUALS: return variable <= value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1779 case OCC_MORE_THAN: return variable > value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1780 case OCC_MORE_EQUALS: return variable >= value; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1781 case OCC_IS_TRUE: return variable != 0; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1782 case OCC_IS_FALSE: return variable == 0; |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1783 default: NOT_REACHED(); |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1784 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1785 } |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1786 |
a12b2ec504da
(svn r12667) -Feature: conditional 'skip/jump' orders.
rubidium <rubidium@openttd.org>
parents:
8894
diff
changeset
|
1787 /** |
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
|
1788 * 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
|
1789 * @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
|
1790 * @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
|
1791 * @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
|
1792 */ |
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
|
1793 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
|
1794 { |
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
|
1795 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
|
1796 |
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
|
1797 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
|
1798 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
|
1799 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
|
1800 |
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
|
1801 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
|
1802 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
|
1803 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
|
1804 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
|
1805 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
|
1806 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
|
1807 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
|
1808 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
|
1809 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
|
1810 } |
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
|
1811 |
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
|
1812 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
|
1813 } |
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
|
1814 |
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
|
1815 /** |
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
|
1816 * 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
|
1817 * @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
|
1818 * @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
|
1819 * @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
|
1820 * @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
|
1821 */ |
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
|
1822 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
|
1823 { |
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
|
1824 if (conditional_depth > v->GetNumOrders()) return false; |
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
|
1825 |
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
|
1826 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
|
1827 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
|
1828 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
|
1829 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
|
1830 |
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
|
1831 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
|
1832 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
|
1833 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
|
1834 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
|
1835 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
|
1836 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
|
1837 } |
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
|
1838 |
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
|
1839 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
|
1840 /* 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
|
1841 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
|
1842 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
|
1843 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
|
1844 |
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
|
1845 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
|
1846 /* 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
|
1847 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
|
1848 |
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
|
1849 v->dest_tile = location; |
11809
57fd0a8c36cb
(svn r16199) -Codechange: Pass OrderNonStopFlags also to MakeGoToDepotOrder().
frosch <frosch@openttd.org>
parents:
11730
diff
changeset
|
1850 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(), v->current_order.GetRefitSubtype()); |
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
|
1851 |
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
|
1852 /* 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
|
1853 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
|
1854 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1855 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
|
1856 Aircraft *a = Aircraft::From(v); |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1857 if (a->state == FLYING && a->targetairport != destination) { |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1858 /* 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
|
1859 extern void AircraftNextAirportPos_and_Order(Aircraft *a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1860 AircraftNextAirportPos_and_Order(a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1861 } |
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
|
1862 } |
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
|
1863 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
|
1864 } |
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
|
1865 |
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
|
1866 /* 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
|
1867 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
|
1868 |
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
|
1869 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
|
1870 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
|
1871 } 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
|
1872 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
|
1873 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
|
1874 } |
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
|
1875 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
|
1876 } |
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
|
1877 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
|
1878 |
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
|
1879 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
|
1880 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
|
1881 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
|
1882 |
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
|
1883 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
|
1884 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
|
1885 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
|
1886 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
|
1887 /* 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
|
1888 * 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
|
1889 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
|
1890 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
|
1891 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
|
1892 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
|
1893 |
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
|
1894 /* 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
|
1895 * 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
|
1896 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
|
1897 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
|
1898 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
|
1899 } |
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
|
1900 } 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
|
1901 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
|
1902 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
|
1903 } |
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
|
1904 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
|
1905 } |
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
|
1906 |
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
|
1907 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
|
1908 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
|
1909 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
|
1910 } |
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
|
1911 |
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
|
1912 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
|
1913 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
|
1914 |
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
|
1915 /* 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
|
1916 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
|
1917 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
|
1918 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
|
1919 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
|
1920 } |
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
|
1921 |
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
|
1922 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
|
1923 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
|
1924 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
|
1925 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
|
1926 } |
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
|
1927 |
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
|
1928 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
|
1929 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
|
1930 } |
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
|
1931 |
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
|
1932 /** |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1933 * 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
|
1934 * 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
|
1935 * @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
|
1936 * @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
|
1937 * (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
|
1938 */ |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1939 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
|
1940 { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
1941 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
|
1942 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
|
1943 /* 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
|
1944 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
|
1945 break; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1946 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1947 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
|
1948 return false; |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1949 |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1950 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
|
1951 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
|
1952 break; |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1953 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1954 default: break; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1955 } |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1956 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1957 /** |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1958 * 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
|
1959 * 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
|
1960 * 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
|
1961 * 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
|
1962 * 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
|
1963 */ |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8835
diff
changeset
|
1964 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
|
1965 |
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
|
1966 /* 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
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 /* 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
|
1972 * 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
|
1973 * 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
|
1974 * 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
|
1975 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
|
1976 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
|
1977 v->IncrementImplicitOrderIndex(); |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1978 } |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1979 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1980 /* 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
|
1981 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
|
1982 v->UpdateRealOrderIndex(); |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1983 |
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
|
1984 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
|
1985 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
|
1986 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
|
1987 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
|
1988 } |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1989 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1990 /* 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
|
1991 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
|
1992 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
|
1993 /* 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
|
1994 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
|
1995 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
|
1996 return false; |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1997 } |
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
1998 |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
1999 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
|
2000 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
|
2001 return false; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2002 } |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2003 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2004 /* 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
|
2005 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
|
2006 (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
|
2007 return false; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2008 } |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2009 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2010 /* 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
|
2011 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
|
2012 |
12892
2245b86757b7
(svn r17384) -Fix [FS#2859]: remove all order window state changes out of the drawing routine and call them immediately when changes happen instead of on the next OnPaint. This prevents pressing buttons when they should've been already disabled.
rubidium <rubidium@openttd.org>
parents:
12804
diff
changeset
|
2013 InvalidateVehicleOrder(v, -2); |
8827
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2014 switch (v->type) { |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2015 default: |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2016 NOT_REACHED(); |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2017 |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2018 case VEH_ROAD: |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2019 case VEH_TRAIN: |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2020 break; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2021 |
8830
981a95f3204d
(svn r12578) -Codechange: merge the aircrafts ProcessOrder too into the 'unified' ProcessOrder.
rubidium <rubidium@openttd.org>
parents:
8827
diff
changeset
|
2022 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
|
2023 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
|
2024 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
|
2025 break; |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2026 } |
095c429c5fa7
(svn r12575) -Codechange: unduplicate Process*Orders for trains, ships and road vehicles.
rubidium <rubidium@openttd.org>
parents:
8787
diff
changeset
|
2027 |
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
|
2028 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
|
2029 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2030 |
8832
870ff040ec3e
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents:
8830
diff
changeset
|
2031 /** |
870ff040ec3e
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents:
8830
diff
changeset
|
2032 * 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
|
2033 * 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
|
2034 * @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
|
2035 * @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
|
2036 * @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
|
2037 */ |
870ff040ec3e
(svn r12580) -Codechange: merge some logical related to non-stop orders.
rubidium <rubidium@openttd.org>
parents:
8830
diff
changeset
|
2038 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
|
2039 { |
8941
3b0ffce16526
(svn r12716) -Fix: Do not compare StationIDs with DepotIDs or WaypointIDs.
frosch <frosch@openttd.org>
parents:
8926
diff
changeset
|
2040 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
|
2041 |
a11cd939c335
(svn r21273) -Codechange: Return values should start at the same line.
alberth <alberth@openttd.org>
parents:
15916
diff
changeset
|
2042 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
|
2043 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
|
2044 /* 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
|
2045 !(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
|
2046 } |