author | KUDr |
Fri, 20 Apr 2007 19:43:06 +0000 | |
changeset 6513 | 454347ca3dfb |
parent 6481 | 85ad87daf4b0 |
child 6573 | 26d4c4618f60 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6351
8d0b6cce8d6d
(svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents:
6337
diff
changeset
|
3 |
/** @file order_cmd.cpp */ |
8d0b6cce8d6d
(svn r9390) -Documentation : correct Doxygen of comments and @file inclusion. This time, brought to you by the letter O
belugas
parents:
6337
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1884
diff
changeset
|
6 |
#include "openttd.h" |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
7 |
#include "order.h" |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
8 |
#include "airport.h" |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
9 |
#include "depot.h" |
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2140
diff
changeset
|
10 |
#include "functions.h" |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
340
diff
changeset
|
11 |
#include "table/strings.h" |
0 | 12 |
#include "vehicle.h" |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
13 |
#include "waypoint.h" |
0 | 14 |
#include "command.h" |
15 |
#include "station.h" |
|
16 |
#include "player.h" |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
17 |
#include "news.h" |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
18 |
#include "saveload.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1751
diff
changeset
|
19 |
#include "vehicle_gui.h" |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
20 |
#include "cargotype.h" |
0 | 21 |
|
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
22 |
/** |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
23 |
* Called if a new block is added to the order-pool |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
24 |
*/ |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
25 |
static void OrderPoolNewBlock(uint start_item) |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
26 |
{ |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
27 |
Order *order; |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
28 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
29 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
30 |
* TODO - This is just a temporary stage, this will be removed. */ |
4977 | 31 |
for (order = GetOrder(start_item); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) order->index = start_item++; |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
32 |
} |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
33 |
|
5216
8bd14ee39af2
(svn r7331) - Codechange: Rename all memory pool macro's and types to "old pool", so the new pool implementation can be committed alongside it.
matthijs
parents:
4987
diff
changeset
|
34 |
DEFINE_OLD_POOL(Order, Order, OrderPoolNewBlock, NULL) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
35 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
36 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
37 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
38 |
* Unpacks a order from savegames made with TTD(Patch) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
39 |
* |
0 | 40 |
*/ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
41 |
Order UnpackOldOrder(uint16 packed) |
0 | 42 |
{ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
43 |
Order order; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
44 |
order.type = (OrderType)GB(packed, 0, 4); |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
45 |
order.flags = GB(packed, 4, 4); |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
46 |
order.dest = GB(packed, 8, 8); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
47 |
order.next = NULL; |
0 | 48 |
|
4780
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
49 |
order.refit_cargo = CT_NO_REFIT; |
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
50 |
order.refit_subtype = 0; |
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
51 |
order.index = 0; // avoid compiler warning |
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
52 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
53 |
// Sanity check |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
54 |
// TTD stores invalid orders as OT_NOTHING with non-zero flags/station |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
55 |
if (!order.IsValid() && (order.flags != 0 || order.dest != 0)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
56 |
order.type = OT_DUMMY; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
57 |
order.flags = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
58 |
} |
0 | 59 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
60 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
61 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
62 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
63 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
64 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
65 |
* Unpacks a order from savegames with version 4 and lower |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
66 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
67 |
*/ |
2817 | 68 |
static Order UnpackVersion4Order(uint16 packed) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
69 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
70 |
Order order; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
71 |
order.type = (OrderType)GB(packed, 0, 4); |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
72 |
order.flags = GB(packed, 4, 4); |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
73 |
order.dest = GB(packed, 8, 8); |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
74 |
order.next = NULL; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
75 |
order.index = 0; // avoid compiler warning |
4780
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
76 |
order.refit_cargo = CT_NO_REFIT; |
4715 | 77 |
order.refit_subtype = 0; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
78 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
79 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
80 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
81 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
82 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
83 |
* Updates the widgets of a vehicle which contains the order-data |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
84 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
85 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
86 |
void InvalidateVehicleOrder(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
87 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
88 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
89 |
InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
90 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
91 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
92 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
93 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
94 |
* Swap two orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
95 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
96 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
97 |
static void SwapOrders(Order *order1, Order *order2) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
98 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
99 |
Order temp_order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
100 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
101 |
temp_order = *order1; |
1043
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
102 |
AssignOrder(order1, *order2); |
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
103 |
order1->next = order2->next; |
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
104 |
AssignOrder(order2, temp_order); |
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
105 |
order2->next = temp_order.next; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
106 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
107 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
108 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
109 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
110 |
* Allocate a new order |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
111 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
112 |
* @return Order* if a free space is found, else NULL. |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
113 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
114 |
*/ |
6247 | 115 |
static Order *AllocateOrder() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
116 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
117 |
Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
118 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
119 |
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
120 |
* TODO - This is just a temporary stage, this will be removed. */ |
4977 | 121 |
for (order = GetOrder(0); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) { |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
122 |
if (!order->IsValid()) { |
4392
68ca7ef4f600
(svn r6145) -Codechange: added OrderID to indicate Order indexes out of the pool
truelight
parents:
4391
diff
changeset
|
123 |
OrderID index = order->index; |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
124 |
|
2639 | 125 |
memset(order, 0, sizeof(*order)); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
126 |
order->index = index; |
1111
6f4d8544e70b
(svn r1612) -Fix: made sure that ->next pointers are set to NULL
truelight
parents:
1106
diff
changeset
|
127 |
order->next = NULL; |
4780
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
128 |
order->refit_cargo = CT_NO_REFIT; |
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
129 |
order->refit_subtype = 0; |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
130 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
131 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
132 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
133 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
134 |
|
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
135 |
/* Check if we can add a block to the pool */ |
4977 | 136 |
if (AddBlockToPool(&_Order_pool)) return AllocateOrder(); |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
137 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
138 |
return NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
139 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
140 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
141 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
142 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
143 |
* Assign data to an order (from an other order) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
144 |
* This function makes sure that the index is maintained correctly |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
145 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
146 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
147 |
void AssignOrder(Order *order, Order data) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
148 |
{ |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
149 |
order->type = data.type; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
150 |
order->flags = data.flags; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
151 |
order->dest = data.dest; |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
152 |
|
4780
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
153 |
order->refit_cargo = data.refit_cargo; |
307af11a644c
(svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents:
4735
diff
changeset
|
154 |
order->refit_subtype = data.refit_subtype; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
155 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
156 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
157 |
|
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
158 |
/** |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
159 |
* Delete all news items regarding defective orders about a vehicle |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
160 |
* This could kill still valid warnings (for example about void order when just |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
161 |
* another order gets added), but assume the player will notice the problems, |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
162 |
* when (s)he's changing the orders. |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
163 |
*/ |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
164 |
static void DeleteOrderWarnings(const Vehicle* v) |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
165 |
{ |
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
166 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_TOO_FEW_ORDERS + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
167 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_VOID_ORDER + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
168 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_DUPLICATE_ENTRY + v->type * 4); |
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
169 |
DeleteVehicleNews(v->index, STR_TRAIN_HAS_INVALID_ENTRY + v->type * 4); |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
170 |
} |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
171 |
|
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
172 |
|
6071 | 173 |
static TileIndex GetOrderLocation(const Order& o) |
174 |
{ |
|
175 |
switch (o.type) { |
|
176 |
default: NOT_REACHED(); |
|
177 |
case OT_GOTO_STATION: return GetStation(o.dest)->xy; |
|
178 |
case OT_GOTO_DEPOT: return GetDepot(o.dest)->xy; |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
183 |
/** Add an order to the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
184 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
185 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
186 |
* @param p1 various bitstuffed elements |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
187 |
* - p1 = (bit 0 - 15) - ID of the vehicle |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
188 |
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
189 |
* the order will be inserted before that one |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
190 |
* only the first 8 bits used currently (bit 16 - 23) (max 255) |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
191 |
* @param p2 packed order to insert |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
192 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
193 |
int32 CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
194 |
{ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
195 |
Vehicle *v; |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
196 |
VehicleID veh = GB(p1, 0, 16); |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
197 |
VehicleOrderID sel_ord = GB(p1, 16, 16); |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
198 |
Order new_order = UnpackOrder(p2); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
199 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
200 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
201 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
202 |
v = GetVehicle(veh); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
203 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
204 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
205 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
206 |
/* Check if the inserted order is to the correct destination (owner, type), |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
207 |
* and has the correct flags if any */ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
208 |
switch (new_order.type) { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
209 |
case OT_GOTO_STATION: { |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
210 |
const Station *st; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
211 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
212 |
if (!IsValidStationID(new_order.dest)) return CMD_ERROR; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
213 |
st = GetStation(new_order.dest); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
214 |
|
6065 | 215 |
if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
216 |
return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
217 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
218 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
219 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
220 |
case VEH_TRAIN: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
221 |
if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
222 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
223 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
224 |
case VEH_ROAD: |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
225 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
226 |
if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
227 |
} else { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
228 |
if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
229 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
230 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
231 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
232 |
case VEH_SHIP: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
233 |
if (!(st->facilities & FACIL_DOCK)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
234 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
235 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
236 |
case VEH_AIRCRAFT: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
237 |
if (!(st->facilities & FACIL_AIRPORT)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
238 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
239 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
240 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
241 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
242 |
|
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
243 |
/* Order flags can be any of the following for stations: |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
244 |
* [full-load | unload] [+ transfer] [+ non-stop] |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
245 |
* non-stop orders (if any) are only valid for trains */ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
246 |
switch (new_order.flags) { |
2639 | 247 |
case 0: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
248 |
case OF_FULL_LOAD: |
2639 | 249 |
case OF_FULL_LOAD | OF_TRANSFER: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
250 |
case OF_UNLOAD: |
2639 | 251 |
case OF_UNLOAD | OF_TRANSFER: |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
252 |
case OF_TRANSFER: |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
253 |
break; |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
254 |
|
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
255 |
case OF_NON_STOP: |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
256 |
case OF_NON_STOP | OF_FULL_LOAD: |
2639 | 257 |
case OF_NON_STOP | OF_FULL_LOAD | OF_TRANSFER: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
258 |
case OF_NON_STOP | OF_UNLOAD: |
2639 | 259 |
case OF_NON_STOP | OF_UNLOAD | OF_TRANSFER: |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
260 |
case OF_NON_STOP | OF_TRANSFER: |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
261 |
if (v->type != VEH_TRAIN) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
262 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
263 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
264 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
265 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
266 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
267 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
268 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
269 |
case OT_GOTO_DEPOT: { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
270 |
if (v->type == VEH_AIRCRAFT) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
271 |
const Station* st; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
272 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
273 |
if (!IsValidStationID(new_order.dest)) return CMD_ERROR; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
274 |
st = GetStation(new_order.dest); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
275 |
|
6031 | 276 |
if (!CheckOwnership(st->owner) || |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
277 |
!(st->facilities & FACIL_AIRPORT) || |
6032 | 278 |
st->Airport()->nof_depots == 0) { |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
279 |
return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
280 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
281 |
} else { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
282 |
const Depot* dp; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
283 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
284 |
if (!IsValidDepotID(new_order.dest)) return CMD_ERROR; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
285 |
dp = GetDepot(new_order.dest); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
286 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
287 |
if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
288 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
289 |
switch (v->type) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
290 |
case VEH_TRAIN: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
291 |
if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
292 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
293 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
294 |
case VEH_ROAD: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
295 |
if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
296 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
297 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
298 |
case VEH_SHIP: |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
299 |
if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
300 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
301 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
302 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
303 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
304 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
305 |
|
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
306 |
/* Order flags can be any of the following for depots: |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
307 |
* order [+ halt] [+ non-stop] |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
308 |
* non-stop orders (if any) are only valid for trains */ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
309 |
switch (new_order.flags) { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
310 |
case OF_PART_OF_ORDERS: |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
311 |
case OF_PART_OF_ORDERS | OF_HALT_IN_DEPOT: |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
312 |
break; |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
313 |
|
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
314 |
case OF_NON_STOP | OF_PART_OF_ORDERS: |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
315 |
case OF_NON_STOP | OF_PART_OF_ORDERS | OF_HALT_IN_DEPOT: |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
316 |
if (v->type != VEH_TRAIN) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
317 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
318 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
319 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
320 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
321 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
322 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
323 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
324 |
case OT_GOTO_WAYPOINT: { |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
325 |
const Waypoint* wp; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
326 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
327 |
if (v->type != VEH_TRAIN) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
328 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
329 |
if (!IsValidWaypointID(new_order.dest)) return CMD_ERROR; |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
330 |
wp = GetWaypoint(new_order.dest); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
331 |
|
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
332 |
if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
333 |
|
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
334 |
/* Order flags can be any of the following for waypoints: |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
335 |
* [non-stop] |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
336 |
* non-stop orders (if any) are only valid for trains */ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
337 |
switch (new_order.flags) { |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
338 |
case 0: break; |
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
339 |
|
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
340 |
case OF_NON_STOP: |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
341 |
if (v->type != VEH_TRAIN) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
342 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
343 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
344 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
345 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
346 |
break; |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
347 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
348 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
349 |
default: return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
350 |
} |
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
351 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
352 |
if (sel_ord > v->num_orders) return CMD_ERROR; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
353 |
|
5922 | 354 |
if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
355 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
356 |
/* XXX - This limit is only here because the backuppedorders can't |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
357 |
* handle any more then this.. */ |
2433
7e826fbf74d3
(svn r2959) - Fix: [ 1266036 ] Fix [ 1236317 ] Vehicles with and TRANSFER order don't have that order restored (i_dachev). Also disallow non-train type vehicles to have non-stop orders.
Darkvater
parents:
2295
diff
changeset
|
358 |
if (v->num_orders >= MAX_BACKUP_ORDER_COUNT) return_cmd_error(STR_8832_TOO_MANY_ORDERS); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
359 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
360 |
if (v->type == VEH_SHIP && |
6071 | 361 |
IsHumanPlayer(v->owner) && |
362 |
!_patches.new_pathfinding_all) { |
|
363 |
// Make sure the new destination is not too far away from the previous |
|
364 |
const Order *prev = NULL; |
|
365 |
uint n = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
366 |
|
6071 | 367 |
/* Find the last goto station or depot order before the insert location. |
368 |
* If the order is to be inserted at the beginning of the order list this |
|
369 |
* finds the last order in the list. */ |
|
370 |
for (const Order *o = v->orders; o != NULL; o = o->next) { |
|
371 |
if (o->type == OT_GOTO_STATION || o->type == OT_GOTO_DEPOT) prev = o; |
|
372 |
if (++n == sel_ord && prev != NULL) break; |
|
373 |
} |
|
374 |
if (prev != NULL) { |
|
375 |
uint dist = DistanceManhattan( |
|
376 |
GetOrderLocation(*prev), |
|
377 |
GetOrderLocation(new_order) |
|
378 |
); |
|
379 |
if (dist >= 130) { |
|
380 |
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); |
|
381 |
} |
|
382 |
} |
|
0 | 383 |
} |
384 |
||
385 |
if (flags & DC_EXEC) { |
|
386 |
Vehicle *u; |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
387 |
Order *new_o = AllocateOrder(); |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
388 |
AssignOrder(new_o, new_order); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
389 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
390 |
/* Create new order and link in list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
391 |
if (v->orders == NULL) { |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
392 |
v->orders = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
393 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
394 |
/* Try to get the previous item (we are inserting above the |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
395 |
selected) */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
396 |
Order *order = GetVehicleOrder(v, sel_ord - 1); |
0 | 397 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
398 |
if (order == NULL && GetVehicleOrder(v, sel_ord) != NULL) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
399 |
/* There is no previous item, so we are altering v->orders itself |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
400 |
But because the orders can be shared, we copy the info over |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
401 |
the v->orders, so we don't have to change the pointers of |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
402 |
all vehicles */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
403 |
SwapOrders(v->orders, new_o); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
404 |
/* Now update the next pointers */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
405 |
v->orders->next = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
406 |
} else if (order == NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
407 |
/* 'sel' is a non-existing order, add him to the end */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
408 |
order = GetLastVehicleOrder(v); |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
409 |
order->next = new_o; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
410 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
411 |
/* Put the new order in between */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
412 |
new_o->next = order->next; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
413 |
order->next = new_o; |
0 | 414 |
} |
415 |
} |
|
588 | 416 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
417 |
u = GetFirstVehicleFromSharedList(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
418 |
DeleteOrderWarnings(u); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
419 |
for (; u != NULL; u = u->next_shared) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
420 |
/* Increase amount of orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
421 |
u->num_orders++; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
422 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
423 |
/* If the orderlist was empty, assign it */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
424 |
if (u->orders == NULL) u->orders = v->orders; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
425 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
426 |
assert(v->orders == u->orders); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
427 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
428 |
/* If there is added an order before the current one, we need |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
429 |
to update the selected order */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
430 |
if (sel_ord <= u->cur_order_index) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
431 |
uint cur = u->cur_order_index + 1; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
432 |
/* Check if we don't go out of bound */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
433 |
if (cur < u->num_orders) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
434 |
u->cur_order_index = cur; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
435 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
436 |
/* Update any possible open window of the vehicle */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
437 |
InvalidateVehicleOrder(u); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
438 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
439 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
440 |
/* Make sure to rebuild the whole list */ |
588 | 441 |
RebuildVehicleLists(); |
0 | 442 |
} |
443 |
||
444 |
return 0; |
|
445 |
} |
|
446 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
447 |
/** Declone an order-list |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
448 |
* @param *dst delete the orders of this vehicle |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
449 |
* @param flags execution flags |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
450 |
*/ |
0 | 451 |
static int32 DecloneOrder(Vehicle *dst, uint32 flags) |
452 |
{ |
|
453 |
if (flags & DC_EXEC) { |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
454 |
DeleteVehicleOrders(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
455 |
InvalidateVehicleOrder(dst); |
588 | 456 |
RebuildVehicleLists(); |
0 | 457 |
} |
458 |
return 0; |
|
459 |
} |
|
460 |
||
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
461 |
/** |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
462 |
* Remove the VehicleList that shows all the vehicles with the same shared |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
463 |
* orders. |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
464 |
*/ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
465 |
static void RemoveSharedOrderVehicleList(Vehicle *v) |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
466 |
{ |
6370
bcf7979ecc4f
(svn r9429) -Fix r9338: when deleting a vehicle which has shared orders with one more vehicle and no orders, segfaulted
truelight
parents:
6351
diff
changeset
|
467 |
assert(v->orders != NULL); |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
468 |
WindowClass window_class = WC_NONE; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
469 |
|
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
470 |
switch (v->type) { |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
471 |
default: NOT_REACHED(); |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
472 |
case VEH_TRAIN: window_class = WC_TRAINS_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
473 |
case VEH_ROAD: window_class = WC_ROADVEH_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
474 |
case VEH_SHIP: window_class = WC_SHIPS_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
475 |
case VEH_AIRCRAFT: window_class = WC_AIRCRAFT_LIST; break; |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
476 |
} |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
477 |
DeleteWindowById(window_class, (v->orders->index << 16) | (v->type << 11) | VLW_SHARED_ORDERS | v->owner); |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
478 |
} |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
479 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
480 |
/** Delete an order from the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
481 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
482 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
483 |
* @param p1 the ID of the vehicle |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
484 |
* @param p2 the order to delete (max 255) |
0 | 485 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
486 |
int32 CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 487 |
{ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
488 |
Vehicle *v, *u; |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
489 |
VehicleID veh_id = p1; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
490 |
VehicleOrderID sel_ord = p2; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
491 |
Order *order; |
0 | 492 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
493 |
if (!IsValidVehicleID(veh_id)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
494 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
495 |
v = GetVehicle(veh_id); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
496 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
497 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
498 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
499 |
/* If we did not select an order, we maybe want to de-clone the orders */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
500 |
if (sel_ord >= v->num_orders) |
0 | 501 |
return DecloneOrder(v, flags); |
502 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
503 |
order = GetVehicleOrder(v, sel_ord); |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
504 |
if (order == NULL) return CMD_ERROR; |
0 | 505 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
506 |
if (flags & DC_EXEC) { |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
507 |
if (GetVehicleOrder(v, sel_ord - 1) == NULL) { |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
508 |
if (GetVehicleOrder(v, sel_ord + 1) != NULL) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
509 |
/* First item, but not the last, so we need to alter v->orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
510 |
Because we can have shared order, we copy the data |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
511 |
from the next item over the deleted */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
512 |
order = GetVehicleOrder(v, sel_ord + 1); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
513 |
SwapOrders(v->orders, order); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
514 |
} else { |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
515 |
/* XXX -- The system currently can't handle a shared-order vehicle list |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
516 |
* open when there aren't any orders in the list, so close the window |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
517 |
* in this case. Of course it needs a better fix later */ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
518 |
RemoveSharedOrderVehicleList(v); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
519 |
/* Last item, so clean the list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
520 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
521 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
522 |
} else { |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
523 |
GetVehicleOrder(v, sel_ord - 1)->next = order->next; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
524 |
} |
0 | 525 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
526 |
/* Give the item free */ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
527 |
order->Free(); |
0 | 528 |
|
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
529 |
u = GetFirstVehicleFromSharedList(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
530 |
DeleteOrderWarnings(u); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
531 |
for (; u != NULL; u = u->next_shared) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
532 |
u->num_orders--; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
533 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
534 |
if (sel_ord < u->cur_order_index) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
535 |
u->cur_order_index--; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
536 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
537 |
/* If we removed the last order, make sure the shared vehicles |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
538 |
* also set their orders to NULL */ |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
539 |
if (v->orders == NULL) u->orders = NULL; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
540 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
541 |
assert(v->orders == u->orders); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
542 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
543 |
/* NON-stop flag is misused to see if a train is in a station that is |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
544 |
* on his order list or not */ |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
545 |
if (sel_ord == u->cur_order_index && u->current_order.type == OT_LOADING && |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
546 |
HASBIT(u->current_order.flags, OFB_NON_STOP)) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
547 |
u->current_order.flags = 0; |
0 | 548 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
549 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
550 |
/* Update any possible open window of the vehicle */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
551 |
InvalidateVehicleOrder(u); |
0 | 552 |
} |
588 | 553 |
|
554 |
RebuildVehicleLists(); |
|
0 | 555 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
556 |
|
0 | 557 |
return 0; |
558 |
} |
|
559 |
||
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
560 |
/** Goto next order of order-list. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
561 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
562 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
563 |
* @param p1 The ID of the vehicle which order is skipped |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
564 |
* @param p2 unused |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
565 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
566 |
int32 CmdSkipOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 567 |
{ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
568 |
Vehicle *v; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
569 |
VehicleID veh_id = p1; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
570 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
571 |
if (!IsValidVehicleID(veh_id)) return CMD_ERROR; |
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
572 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
573 |
v = GetVehicle(veh_id); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
574 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
575 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
576 |
|
0 | 577 |
if (flags & DC_EXEC) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
578 |
/* Goto next order */ |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
579 |
VehicleOrderID b = v->cur_order_index + 1; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
580 |
if (b >= v->num_orders) b = 0; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
581 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
582 |
v->cur_order_index = b; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
583 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
584 |
if (v->type == VEH_TRAIN) v->u.rail.days_since_order_progr = 0; |
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1111
diff
changeset
|
585 |
|
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
586 |
if (v->type == VEH_ROAD) ClearSlot(v); |
0 | 587 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
588 |
/* NON-stop flag is misused to see if a train is in a station that is |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
589 |
* on his order list or not */ |
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
590 |
if (v->current_order.type == OT_LOADING && HASBIT(v->current_order.flags, OFB_NON_STOP)) |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
591 |
v->current_order.flags = 0; |
0 | 592 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
593 |
InvalidateVehicleOrder(v); |
0 | 594 |
} |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
595 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
596 |
/* We have an aircraft/ship, they have a mini-schedule, so update them all */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
597 |
if (v->type == VEH_AIRCRAFT) InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
598 |
if (v->type == VEH_SHIP) InvalidateWindowClasses(WC_SHIPS_LIST); |
1020
59ee8ceac74c
(svn r1521) -Fix: Ship Vehicle Lists are now redrawn correctly
celestar
parents:
919
diff
changeset
|
599 |
|
0 | 600 |
return 0; |
601 |
} |
|
602 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
603 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
604 |
/** Modify an order in the orderlist of a vehicle. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
605 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
606 |
* @param flags operation to perform |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
607 |
* @param p1 various bitstuffed elements |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
608 |
* - p1 = (bit 0 - 15) - ID of the vehicle |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
609 |
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given, |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
610 |
* the order will be inserted before that one |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
611 |
* only the first 8 bits used currently (bit 16 - 23) (max 255) |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
612 |
* @param p2 mode to change the order to (always set) |
0 | 613 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
614 |
int32 CmdModifyOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 615 |
{ |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
616 |
Vehicle *v; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
617 |
Order *order; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
618 |
VehicleOrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits. |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
619 |
VehicleID veh = GB(p1, 0, 16); |
0 | 620 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
621 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1891
diff
changeset
|
622 |
if (p2 != OFB_FULL_LOAD && p2 != OFB_UNLOAD && p2 != OFB_NON_STOP && p2 != OFB_TRANSFER) return CMD_ERROR; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
623 |
|
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
624 |
v = GetVehicle(veh); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
625 |
|
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
626 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
627 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
628 |
/* Is it a valid order? */ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
629 |
if (sel_ord >= v->num_orders) return CMD_ERROR; |
0 | 630 |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
631 |
order = GetVehicleOrder(v, sel_ord); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
632 |
if (order->type != OT_GOTO_STATION && |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
633 |
(order->type != OT_GOTO_DEPOT || p2 == OFB_UNLOAD) && |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
634 |
(order->type != OT_GOTO_WAYPOINT || p2 != OFB_NON_STOP)) { |
0 | 635 |
return CMD_ERROR; |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
636 |
} |
0 | 637 |
|
638 |
if (flags & DC_EXEC) { |
|
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
639 |
switch (p2) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
640 |
case OFB_FULL_LOAD: |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
641 |
TOGGLEBIT(order->flags, OFB_FULL_LOAD); |
2639 | 642 |
if (order->type != OT_GOTO_DEPOT) CLRBIT(order->flags, OFB_UNLOAD); |
0 | 643 |
break; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
644 |
case OFB_UNLOAD: |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
645 |
TOGGLEBIT(order->flags, OFB_UNLOAD); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
646 |
CLRBIT(order->flags, OFB_FULL_LOAD); |
0 | 647 |
break; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
648 |
case OFB_NON_STOP: |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
649 |
TOGGLEBIT(order->flags, OFB_NON_STOP); |
0 | 650 |
break; |
1935
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1891
diff
changeset
|
651 |
case OFB_TRANSFER: |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1891
diff
changeset
|
652 |
TOGGLEBIT(order->flags, OFB_TRANSFER); |
164d58b9137c
(svn r2441) -Feature: You can now give transfer order to set up feeder systems
celestar
parents:
1891
diff
changeset
|
653 |
break; |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
654 |
default: NOT_REACHED(); |
0 | 655 |
} |
656 |
||
1760
efa84b242ba1
(svn r2264) - Fix: [ 1060686 1187655 ] Changing the full-load flag on the current order doesn't take effect immediately. (glx)
matthijs
parents:
1752
diff
changeset
|
657 |
/* Update the windows and full load flags, also for vehicles that share the same order list */ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
658 |
{ |
2989 | 659 |
Vehicle* u; |
660 |
||
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
661 |
u = GetFirstVehicleFromSharedList(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
662 |
DeleteOrderWarnings(u); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
663 |
for (; u != NULL; u = u->next_shared) { |
5374
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
664 |
/* Toggle u->current_order "Full load" flag if it changed. |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
665 |
* However, as the same flag is used for depot orders, check |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
666 |
* whether we are not going to a depot as there are three |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
667 |
* cases where the full load flag can be active and only |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
668 |
* one case where the flag is used for depot orders. In the |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
669 |
* other cases for the OrderTypeByte the flags are not used, |
5374
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
670 |
* so do not care and those orders should not be active |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
671 |
* when this function is called. |
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
672 |
*/ |
1786
7cfd46c3fcc4
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1760
diff
changeset
|
673 |
if (sel_ord == u->cur_order_index && |
5374
4510e8944ed0
(svn r7559) -Fix (FS#456): clicking the 'Full Load' button when the 'current' order is selected in the Order GUI and one has instructed the train to go to the depot, via the button in the Train View GUI, changed the depot order by switching from 'service at depot' to 'stop at depot' and vice versa.
rubidium
parents:
5216
diff
changeset
|
674 |
u->current_order.type != OT_GOTO_DEPOT && |
2989 | 675 |
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD)) { |
1760
efa84b242ba1
(svn r2264) - Fix: [ 1060686 1187655 ] Changing the full-load flag on the current order doesn't take effect immediately. (glx)
matthijs
parents:
1752
diff
changeset
|
676 |
TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD); |
2989 | 677 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
678 |
InvalidateVehicleOrder(u); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
679 |
} |
0 | 680 |
} |
681 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
682 |
|
0 | 683 |
return 0; |
684 |
} |
|
685 |
||
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
686 |
/** Clone/share/copy an order-list of an other vehicle. |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
687 |
* @param tile unused |
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
688 |
* @param flags operation to perform |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
689 |
* @param p1 various bitstuffed elements |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
690 |
* - p1 = (bit 0-15) - destination vehicle to clone orders to (p1 & 0xFFFF) |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
691 |
* - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE) |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
692 |
* @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
693 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
694 |
int32 CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
695 |
{ |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
696 |
Vehicle *dst; |
2140
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
697 |
VehicleID veh_src = GB(p1, 16, 16); |
a04d0142ad65
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
2089
diff
changeset
|
698 |
VehicleID veh_dst = GB(p1, 0, 16); |
0 | 699 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
700 |
if (!IsValidVehicleID(veh_dst)) return CMD_ERROR; |
0 | 701 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
702 |
dst = GetVehicle(veh_dst); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
703 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
704 |
if (!CheckOwnership(dst->owner)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
705 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
706 |
switch (p2) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
707 |
case CO_SHARE: { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
708 |
Vehicle *src; |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
709 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
710 |
if (!IsValidVehicleID(veh_src)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
711 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
712 |
src = GetVehicle(veh_src); |
588 | 713 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
714 |
/* Sanity checks */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
715 |
if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
716 |
return CMD_ERROR; |
0 | 717 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
718 |
/* Trucks can't share orders with busses (and visa versa) */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
719 |
if (src->type == VEH_ROAD) { |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
720 |
if (src->cargo_type != dst->cargo_type && (IsCargoInClass(src->cargo_type, CC_PASSENGERS) || IsCargoInClass(dst->cargo_type, CC_PASSENGERS))) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
721 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
722 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
723 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
724 |
/* Is the vehicle already in the shared list? */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
725 |
{ |
2989 | 726 |
const Vehicle* u; |
727 |
||
728 |
for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) { |
|
729 |
if (u == dst) return CMD_ERROR; |
|
29
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
730 |
} |
b4bf7559cfa7
(svn r30) -Fix [1007272] Copy orders between bus/truck possible. You cannot share orders between busses/trucks. You can only copy orders if all the facilities in schedule allow both types to go there (Celestar)
darkvater
parents:
19
diff
changeset
|
731 |
} |
0 | 732 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
733 |
if (flags & DC_EXEC) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
734 |
/* If the destination vehicle had a OrderList, destroy it */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
735 |
DeleteVehicleOrders(dst); |
0 | 736 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
737 |
dst->orders = src->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
738 |
dst->num_orders = src->num_orders; |
588 | 739 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
740 |
/* Link this vehicle in the shared-list */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
741 |
dst->next_shared = src->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
742 |
dst->prev_shared = src; |
2951 | 743 |
if (src->next_shared != NULL) src->next_shared->prev_shared = dst; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
744 |
src->next_shared = dst; |
0 | 745 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
746 |
InvalidateVehicleOrder(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
747 |
InvalidateVehicleOrder(src); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
748 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
749 |
RebuildVehicleLists(); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
750 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
751 |
} break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
752 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
753 |
case CO_COPY: { |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
754 |
Vehicle *src; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
755 |
int delta; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
756 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
757 |
if (!IsValidVehicleID(veh_src)) return CMD_ERROR; |
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
758 |
|
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
759 |
src = GetVehicle(veh_src); |
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
760 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
761 |
/* Sanity checks */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
762 |
if (!CheckOwnership(src->owner) || dst->type != src->type || dst == src) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
763 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
764 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
765 |
/* Trucks can't copy all the orders from busses (and visa versa) */ |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
766 |
if (src->type == VEH_ROAD) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
767 |
const Order *order; |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
768 |
TileIndex required_dst = INVALID_TILE; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
769 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
770 |
FOR_VEHICLE_ORDERS(src, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
771 |
if (order->type == OT_GOTO_STATION) { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
772 |
const Station *st = GetStation(order->dest); |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
773 |
if (IsCargoInClass(dst->cargo_type, CC_PASSENGERS)) { |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
774 |
if (st->bus_stops != NULL) required_dst = st->bus_stops->xy; |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
775 |
} else { |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
776 |
if (st->truck_stops != NULL) required_dst = st->truck_stops->xy; |
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
777 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
778 |
/* This station has not the correct road-bay, so we can't copy! */ |
1297
9b867da8f798
(svn r1801) -Fix [Multistop] Fixed a crash that occured when copying orders due to not checking a pointer to be non-NULL
celestar
parents:
1266
diff
changeset
|
779 |
if (required_dst == INVALID_TILE) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
780 |
return CMD_ERROR; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
781 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
782 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
783 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
784 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
785 |
/* make sure there are orders available */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
786 |
delta = IsOrderListShared(dst) ? src->num_orders + 1 : src->num_orders - dst->num_orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
787 |
if (!HasOrderPoolFree(delta)) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
788 |
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
789 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
790 |
if (flags & DC_EXEC) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
791 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
792 |
Order **order_dst; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
793 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
794 |
/* If the destination vehicle had a OrderList, destroy it */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
795 |
DeleteVehicleOrders(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
796 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
797 |
order_dst = &dst->orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
798 |
FOR_VEHICLE_ORDERS(src, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
799 |
*order_dst = AllocateOrder(); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
800 |
AssignOrder(*order_dst, *order); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
801 |
order_dst = &(*order_dst)->next; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
802 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
803 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
804 |
dst->num_orders = src->num_orders; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
805 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
806 |
InvalidateVehicleOrder(dst); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
807 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
808 |
RebuildVehicleLists(); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
809 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
810 |
} break; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
811 |
|
1793
b9a37c98b468
(svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents:
1789
diff
changeset
|
812 |
case CO_UNSHARE: return DecloneOrder(dst, flags); |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
813 |
default: return CMD_ERROR; |
0 | 814 |
} |
815 |
||
816 |
return 0; |
|
817 |
} |
|
818 |
||
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
819 |
/** Add/remove refit orders from an order |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
820 |
* @param tile Not used |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
821 |
* @param flags operation to perform |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
822 |
* @param p1 VehicleIndex of the vehicle having the order |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
823 |
* @param p2 bitmask |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
824 |
* - bit 0-7 CargoID |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
825 |
* - bit 8-15 Cargo subtype |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
826 |
* - bit 16-23 number of order to modify |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
827 |
*/ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
828 |
int32 CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
829 |
{ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
830 |
const Vehicle *v; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
831 |
Order *order; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
832 |
VehicleID veh = GB(p1, 0, 16); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
833 |
VehicleOrderID order_number = GB(p2, 16, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
834 |
CargoID cargo = GB(p2, 0, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
835 |
byte subtype = GB(p2, 8, 8); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
836 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
837 |
if (!IsValidVehicleID(veh)) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
838 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
839 |
v = GetVehicle(veh); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
840 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
841 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
842 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
843 |
order = GetVehicleOrder(v, order_number); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
844 |
if (order == NULL) return CMD_ERROR; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
845 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
846 |
if (flags & DC_EXEC) { |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
847 |
Vehicle *u; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
848 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
849 |
order->refit_cargo = cargo; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
850 |
order->refit_subtype = subtype; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
851 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
852 |
u = GetFirstVehicleFromSharedList(v); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
853 |
for (; u != NULL; u = u->next_shared) { |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
854 |
/* Update any possible open window of the vehicle */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
855 |
InvalidateVehicleOrder(u); |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
856 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
857 |
/* If the vehicle already got the current depot set as current order, then update current order as well */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
858 |
if (u->cur_order_index == order_number && HASBIT(u->current_order.flags, OFB_PART_OF_ORDERS)) { |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
859 |
u->current_order.refit_cargo = cargo; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
860 |
u->current_order.refit_subtype = subtype; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
861 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
862 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
863 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
864 |
|
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
865 |
return 0; |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
866 |
} |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
867 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
868 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
869 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
870 |
* Backup a vehicle order-list, so you can replace a vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
871 |
* without loosing the order-list |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
872 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
873 |
*/ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
874 |
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) |
0 | 875 |
{ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
876 |
/* Save general info */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
877 |
bak->orderindex = v->cur_order_index; |
0 | 878 |
bak->service_interval = v->service_interval; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
879 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
880 |
/* Safe custom string, if any */ |
4862
ac034ec9ed2b
(svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents:
4845
diff
changeset
|
881 |
if (!IsCustomName(v->string_id)) { |
2639 | 882 |
bak->name[0] = '\0'; |
0 | 883 |
} else { |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4862
diff
changeset
|
884 |
GetName(bak->name, v->string_id & 0x7FF, lastof(bak->name)); |
0 | 885 |
} |
886 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
887 |
/* If we have shared orders, store it on a special way */ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
888 |
if (IsOrderListShared(v)) { |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
889 |
const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
890 |
|
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
891 |
bak->clone = u->index; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
892 |
} else { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
893 |
/* Else copy the orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
894 |
Order *order, *dest; |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
895 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
896 |
dest = bak->order; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
897 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
898 |
/* We do not have shared orders */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
899 |
bak->clone = INVALID_VEHICLE; |
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
900 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
901 |
/* Copy the orders */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
902 |
FOR_VEHICLE_ORDERS(v, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
903 |
*dest = *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
904 |
dest++; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
905 |
} |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
906 |
/* End the list with an empty order */ |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
907 |
dest->Free(); |
0 | 908 |
} |
909 |
} |
|
910 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
911 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
912 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
913 |
* Restore vehicle orders that are backupped via BackupVehicleOrders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
914 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
915 |
*/ |
2630 | 916 |
void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak) |
0 | 917 |
{ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
918 |
uint i; |
0 | 919 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
920 |
/* If we have a custom name, process that */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
921 |
if (bak->name[0] != 0) { |
1820
d03c56850dc2
(svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents:
1796
diff
changeset
|
922 |
_cmd_text = bak->name; |
0 | 923 |
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); |
924 |
} |
|
925 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
926 |
/* If we had shared orders, recover that */ |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
927 |
if (bak->clone != INVALID_VEHICLE) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
928 |
DoCommandP(0, v->index | (bak->clone << 16), 0, NULL, CMD_CLONE_ORDER); |
0 | 929 |
return; |
930 |
} |
|
931 |
||
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
932 |
/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
933 |
* order number is one more than the current amount of orders, and because |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
934 |
* in network the commands are queued before send, the second insert always |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
935 |
* fails in test mode. By bypassing the test-mode, that no longer is a problem. */ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
936 |
for (i = 0; bak->order[i].IsValid(); i++) { |
555
02df8a1b7f33
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
937 |
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) |
0 | 938 |
break; |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
939 |
} |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
940 |
|
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
941 |
/* Restore vehicle order-index and service interval */ |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
942 |
DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX); |
0 | 943 |
} |
944 |
||
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
945 |
/** Restore the current order-index of a vehicle and sets service-interval. |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
946 |
* @param tile unused |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6370
diff
changeset
|
947 |
* @param flags operation to perform |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
948 |
* @param p1 the ID of the vehicle |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
949 |
* @param p2 various bistuffed elements |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
950 |
* - p2 = (bit 0-15) - current order-index (p2 & 0xFFFF) |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
951 |
* - p2 = (bit 16-31) - service interval (p2 >> 16) |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
952 |
* @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
953 |
* as far as I can see. We can store it in BackuppedOrders, and restore it, but |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
954 |
* but we have no way of seeing it has been tampered with or not, as we have no |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
955 |
* legit way of knowing what that ID was.@n |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
956 |
* If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
957 |
* restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;" |
0 | 958 |
*/ |
3491
35d747bb5e82
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
959 |
int32 CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 960 |
{ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
961 |
Vehicle *v; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
962 |
VehicleOrderID cur_ord = GB(p2, 0, 16); |
2635 | 963 |
uint16 serv_int = GB(p2, 16, 16); |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
964 |
|
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
965 |
if (!IsValidVehicleID(p1)) return CMD_ERROR; |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
966 |
|
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
967 |
v = GetVehicle(p1); |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
968 |
|
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
969 |
/* Check the vehicle type and ownership, and if the service interval and order are in range */ |
4352
6703cd8d39e0
(svn r6053) -Codechange: renamed all IsXXXIndex to IsValidXXXID
truelight
parents:
4351
diff
changeset
|
970 |
if (!CheckOwnership(v->owner)) return CMD_ERROR; |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
971 |
if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR; |
1718
96d76767ea93
(svn r2222) Check the parameters of Cmd{Insert,Delete,Modify,Skip}Order() and CmdRestoreOrderIndex():
tron
parents:
1680
diff
changeset
|
972 |
|
0 | 973 |
if (flags & DC_EXEC) { |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
974 |
v->cur_order_index = cur_ord; |
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1793
diff
changeset
|
975 |
v->service_interval = serv_int; |
0 | 976 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
977 |
|
0 | 978 |
return 0; |
979 |
} |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
980 |
|
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
981 |
|
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
982 |
static TileIndex GetStationTileForVehicle(const Vehicle* v, const Station* st) |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
983 |
{ |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
984 |
switch (v->type) { |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
985 |
default: NOT_REACHED(); |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
986 |
case VEH_TRAIN: return st->train_tile; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
987 |
case VEH_AIRCRAFT: return st->airport_tile; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
988 |
case VEH_SHIP: return st->dock_tile; |
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
989 |
case VEH_ROAD: |
6329
a492d5e61d7b
(svn r9301) -Codechange: Use cargo class to determine if a road vehicle can stop in bus or truck stops.
peter1138
parents:
6263
diff
changeset
|
990 |
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
991 |
return (st->bus_stops != NULL) ? st->bus_stops->xy : 0; |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
992 |
} else { |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
993 |
return (st->truck_stops != NULL) ? st->truck_stops->xy : 0; |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
994 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
995 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
996 |
} |
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
997 |
|
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
998 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
999 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1000 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1001 |
* Check the orders of a vehicle, to see if there are invalid orders and stuff |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1002 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1003 |
*/ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1004 |
void CheckOrders(const Vehicle* v) |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1005 |
{ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1006 |
/* Does the user wants us to check things? */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1007 |
if (_patches.order_review_system == 0) return; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1008 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1009 |
/* Do nothing for crashed vehicles */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1010 |
if (v->vehstatus & VS_CRASHED) return; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1011 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1012 |
/* Do nothing for stopped vehicles if setting is '1' */ |
2549 | 1013 |
if (_patches.order_review_system == 1 && v->vehstatus & VS_STOPPED) |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1014 |
return; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1015 |
|
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1043
diff
changeset
|
1016 |
/* do nothing we we're not the first vehicle in a share-chain */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1017 |
if (v->next_shared != NULL) return; |
1053
8d90844ddc2e
(svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents:
1043
diff
changeset
|
1018 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1019 |
/* Only check every 20 days, so that we don't flood the message log */ |
2549 | 1020 |
if (v->owner == _local_player && v->day_counter % 20 == 0) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1021 |
int n_st, problem_type = -1; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1022 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1023 |
int message = 0; |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1024 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1025 |
/* Check the order list */ |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1026 |
n_st = 0; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1027 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1028 |
FOR_VEHICLE_ORDERS(v, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1029 |
/* Dummy order? */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1030 |
if (order->type == OT_DUMMY) { |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1031 |
problem_type = 1; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1032 |
break; |
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1033 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1034 |
/* Does station have a load-bay for this vehicle? */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1035 |
if (order->type == OT_GOTO_STATION) { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1036 |
const Station* st = GetStation(order->dest); |
4177
9590b6cb5f77
(svn r5615) Move GetStationTileForVehicle() to its only user
tron
parents:
4077
diff
changeset
|
1037 |
TileIndex required_tile = GetStationTileForVehicle(v, st); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1038 |
|
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1039 |
n_st++; |
2639 | 1040 |
if (required_tile == 0) problem_type = 3; |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1041 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1042 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1043 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1044 |
/* Check if the last and the first order are the same */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1045 |
if (v->num_orders > 1) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1046 |
const Order* last = GetLastVehicleOrder(v); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1047 |
|
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1048 |
if (v->orders->type == last->type && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1049 |
v->orders->flags == last->flags && |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1050 |
v->orders->dest == last->dest) { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1051 |
problem_type = 2; |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1052 |
} |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1053 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1054 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1055 |
/* Do we only have 1 station in our order list? */ |
2639 | 1056 |
if (n_st < 2 && problem_type == -1) problem_type = 0; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1057 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1058 |
/* We don't have a problem */ |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1059 |
if (problem_type < 0) return; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1060 |
|
5955
fe61588d5188
(svn r8621) -Codechange: assigned new numbers to the VEH_(type) enum so that VEH_Train is 0, VEH_Road is 1 and so on
bjarni
parents:
5922
diff
changeset
|
1061 |
message = STR_TRAIN_HAS_TOO_FEW_ORDERS + (v->type << 2) + problem_type; |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5374
diff
changeset
|
1062 |
//DEBUG(misc, 3, "Triggered News Item for vehicle %d", v->index); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
55
diff
changeset
|
1063 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1064 |
SetDParam(0, v->unitnumber); |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1065 |
AddNewsItem( |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1066 |
message, |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1067 |
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, 0), |
55
73fae6c6568e
(svn r56) Improved order checker + patch setting for it (celestar)
dominik
parents:
29
diff
changeset
|
1068 |
v->index, |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1069 |
0 |
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
3139
diff
changeset
|
1070 |
); |
19
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1071 |
} |
6080d2b6a959
(svn r20) Feature: warning when a vehicle has invalid orders (celestar)
dominik
parents:
0
diff
changeset
|
1072 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1073 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1074 |
/** |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1075 |
* Removes an order from all vehicles. Triggers when, say, a station is removed. |
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1076 |
* @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]). |
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4350
diff
changeset
|
1077 |
* @param destination The destination. Can be a StationID, DepotID or WaypointID. |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1078 |
*/ |
4389
18d6ccfb5335
(svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents:
4384
diff
changeset
|
1079 |
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1080 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1081 |
Vehicle *v; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1082 |
|
4528
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1083 |
/* Aircraft have StationIDs for depot orders and never use DepotIDs |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1084 |
* This fact is handled specially below |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1085 |
*/ |
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1086 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1087 |
/* Go through all vehicles */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1088 |
FOR_ALL_VEHICLES(v) { |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1089 |
Order *order; |
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1090 |
bool invalidate; |
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1091 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1092 |
/* Forget about this station if this station is removed */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1093 |
if (v->last_station_visited == destination && type == OT_GOTO_STATION) { |
1266
eccd576e322f
(svn r1770) -Fix: Hopefully last pieces of code that are containing a station-id
truelight
parents:
1247
diff
changeset
|
1094 |
v->last_station_visited = INVALID_STATION; |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1095 |
} |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1096 |
|
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1097 |
order = &v->current_order; |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1098 |
if ((v->type == VEH_AIRCRAFT && order->type == OT_GOTO_DEPOT ? OT_GOTO_STATION : order->type) == type && |
4528
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1099 |
v->current_order.dest == destination) { |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1100 |
order->type = OT_DUMMY; |
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1101 |
order->flags = 0; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1102 |
InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1103 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1104 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1105 |
/* Clear the order from the order-list */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1106 |
invalidate = false; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1107 |
FOR_VEHICLE_ORDERS(v, order) { |
6259
471b91a4b1d8
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6247
diff
changeset
|
1108 |
if ((v->type == VEH_AIRCRAFT && order->type == OT_GOTO_DEPOT ? OT_GOTO_STATION : order->type) == type && |
4528
969ebcde6b81
(svn r6355) -Fix: Go to hangar orders for aircraft could get spuriously removed when a road or rail depot got deleted (Darkvater and me)
tron
parents:
4527
diff
changeset
|
1109 |
order->dest == destination) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1110 |
order->type = OT_DUMMY; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1111 |
order->flags = 0; |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1112 |
invalidate = true; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1113 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1114 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1115 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1116 |
/* Only invalidate once, and if needed */ |
4533
45eec0a20138
(svn r6360) -Codechange: Polish RemoveOrderFromAllVehicles()
tron
parents:
4528
diff
changeset
|
1117 |
if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1118 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1119 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1120 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1121 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1122 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1123 |
* Checks if a vehicle has a GOTO_DEPOT in his order list |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1124 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1125 |
* @return True if this is true (lol ;)) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1126 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1127 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1128 |
bool VehicleHasDepotOrders(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1129 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1130 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1131 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1132 |
FOR_VEHICLE_ORDERS(v, order) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1133 |
if (order->type == OT_GOTO_DEPOT) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1134 |
return true; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1135 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1136 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1137 |
return false; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1138 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1139 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1140 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1141 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1142 |
* Delete all orders from a vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1143 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1144 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1145 |
void DeleteVehicleOrders(Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1146 |
{ |
3139
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
1147 |
DeleteOrderWarnings(v); |
b17abef09e15
(svn r3757) -Feature: Delete news items about vehicles, when they get stale
tron
parents:
3123
diff
changeset
|
1148 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1149 |
/* If we have a shared order-list, don't delete the list, but just |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1150 |
remove our pointer */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1151 |
if (IsOrderListShared(v)) { |
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1152 |
Vehicle *u = v; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1153 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1154 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1155 |
v->num_orders = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1156 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1157 |
/* Unlink ourself */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1158 |
if (v->prev_shared != NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1159 |
v->prev_shared->next_shared = v->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1160 |
u = v->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1161 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1162 |
if (v->next_shared != NULL) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1163 |
v->next_shared->prev_shared = v->prev_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1164 |
u = v->next_shared; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1165 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1166 |
v->prev_shared = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1167 |
v->next_shared = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1168 |
|
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1169 |
/* If we are the only one left in the Shared Order Vehicle List, |
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1170 |
* remove it, as we are no longer a Shared Order Vehicle */ |
6370
bcf7979ecc4f
(svn r9429) -Fix r9338: when deleting a vehicle which has shared orders with one more vehicle and no orders, segfaulted
truelight
parents:
6351
diff
changeset
|
1171 |
if (u->prev_shared == NULL && u->next_shared == NULL && u->orders != NULL) RemoveSharedOrderVehicleList(u); |
6337
2da03fc77b33
(svn r9338) -Fix: close the Shared Order Vehicle List if you remove the shared link with only 2 vehicles
truelight
parents:
6336
diff
changeset
|
1172 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1173 |
/* We only need to update this-one, because if there is a third |
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1174 |
* vehicle which shares the same order-list, nothing will change. If |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1175 |
* this is the last vehicle, the last line of the order-window |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1176 |
* will change from Shared order list, to Order list, so it needs |
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4534
diff
changeset
|
1177 |
* an update */ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1178 |
InvalidateVehicleOrder(u); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1179 |
return; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1180 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1181 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1182 |
/* Remove the orders */ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1183 |
Order *cur = v->orders; |
6336
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
1184 |
/* Delete the vehicle list of shared orders, if any */ |
beb48363fe28
(svn r9337) -Fix [FS#542]: assert() when you removed the orders of a shared list while having the shared order vehicle list open.
truelight
parents:
6329
diff
changeset
|
1185 |
if (cur != NULL) RemoveSharedOrderVehicleList(v); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1186 |
v->orders = NULL; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1187 |
v->num_orders = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1188 |
|
4735
632bb67a4c50
(svn r6647) -Fix: [vehicle list windows] Lists of shared orders are now no longer closed by a window event if the list is empty
bjarni
parents:
4715
diff
changeset
|
1189 |
if (cur != NULL) { |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1190 |
cur->FreeChain(); // Free the orders. |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1191 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1192 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1193 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1194 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1195 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1196 |
* Check if we share our orders with an other vehicle |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1197 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1198 |
* @return Returns the vehicle who has the same order |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1199 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1200 |
*/ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1201 |
bool IsOrderListShared(const Vehicle *v) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1202 |
{ |
2645
841087328e0e
(svn r3187) Simplify overly complicated ifs, especially if (foo) return false; else return true; is confusing
tron
parents:
2639
diff
changeset
|
1203 |
return v->next_shared != NULL || v->prev_shared != NULL; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1204 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1205 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1206 |
/** |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1207 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1208 |
* Check if a vehicle has any valid orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1209 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1210 |
* @return false if there are no valid orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1211 |
* |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1212 |
*/ |
2630 | 1213 |
bool CheckForValidOrders(const Vehicle* v) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1214 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1215 |
const Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1216 |
|
2639 | 1217 |
FOR_VEHICLE_ORDERS(v, order) if (order->type != OT_DUMMY) return true; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1218 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1219 |
return false; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1220 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1221 |
|
6247 | 1222 |
void InitializeOrders() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1223 |
{ |
4977 | 1224 |
CleanPool(&_Order_pool); |
1225 |
AddBlockToPool(&_Order_pool); |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1226 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1227 |
_backup_orders_tile = 0; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1228 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1229 |
|
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1820
diff
changeset
|
1230 |
static const SaveLoad _order_desc[] = { |
4527
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1231 |
SLE_VAR(Order, type, SLE_UINT8), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1232 |
SLE_VAR(Order, flags, SLE_UINT8), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1233 |
SLE_VAR(Order, dest, SLE_UINT16), |
fa30d19685c2
(svn r6353) -Codechange: Make DestinationID a typedef of uin16, which is as large as any type of destinataion (StationID, DepotID, WaypointID) it can hold
tron
parents:
4392
diff
changeset
|
1234 |
SLE_REF(Order, next, REF_ORDER), |
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1235 |
SLE_CONDVAR(Order, refit_cargo, SLE_UINT8, 36, SL_MAX_VERSION), |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1236 |
SLE_CONDVAR(Order, refit_subtype, SLE_UINT8, 36, SL_MAX_VERSION), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1237 |
|
4712
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1238 |
/* Leftover from the minor savegame version stuff |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1239 |
* We will never use those free bytes, but we have to keep this line to allow loading of old savegames */ |
4335ad42e163
(svn r6624) -Feature: added ability to add refit commands to vehicle orders (can only be done in goto depot orders)
bjarni
parents:
4549
diff
changeset
|
1240 |
SLE_CONDNULL(10, 5, 35), |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1241 |
SLE_END() |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1242 |
}; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1243 |
|
6247 | 1244 |
static void Save_ORDR() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1245 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1246 |
Order *order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1247 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1248 |
FOR_ALL_ORDERS(order) { |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1249 |
SlSetArrayIndex(order->index); |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
1250 |
SlObject(order, _order_desc); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1251 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1252 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1253 |
|
6247 | 1254 |
static void Load_ORDR() |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1255 |
{ |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1256 |
if (CheckSavegameVersionOldStyle(5, 2)) { |
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1257 |
/* Version older than 5.2 did not have a ->next pointer. Convert them |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1258 |
(in the old days, the orderlist was 5000 items big) */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1259 |
uint len = SlGetFieldLength(); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1260 |
uint i; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1261 |
|
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1262 |
if (CheckSavegameVersion(5)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1263 |
/* Pre-version 5 had an other layout for orders |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1264 |
(uint16 instead of uint32) */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1265 |
uint16 orders[5000]; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1266 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1267 |
len /= sizeof(uint16); |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1268 |
assert (len <= lengthof(orders)); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1269 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1270 |
SlArray(orders, len, SLE_UINT16); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1271 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1272 |
for (i = 0; i < len; ++i) { |
4977 | 1273 |
if (!AddBlockIfNeeded(&_Order_pool, i)) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1274 |
error("Orders: failed loading savegame: too many orders"); |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1275 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1276 |
AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i])); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1277 |
} |
2685
805a28b7c3b7
(svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents:
2645
diff
changeset
|
1278 |
} else if (CheckSavegameVersionOldStyle(5, 2)) { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1279 |
uint32 orders[5000]; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1280 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1281 |
len /= sizeof(uint32); |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1282 |
assert (len <= lengthof(orders)); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1283 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1284 |
SlArray(orders, len, SLE_UINT32); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1285 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1286 |
for (i = 0; i < len; ++i) { |
4977 | 1287 |
if (!AddBlockIfNeeded(&_Order_pool, i)) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1288 |
error("Orders: failed loading savegame: too many orders"); |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1289 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1290 |
AssignOrder(GetOrder(i), UnpackOrder(orders[i])); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1291 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1292 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1293 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1294 |
/* Update all the next pointer */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1295 |
for (i = 1; i < len; ++i) { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1296 |
/* The orders were built like this: |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1297 |
* While the order is valid, set the previous will get it's next pointer set |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1298 |
* We start with index 1 because no order will have the first in it's next pointer */ |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6259
diff
changeset
|
1299 |
if (GetOrder(i)->IsValid()) |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1300 |
GetOrder(i - 1)->next = GetOrder(i); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1301 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1302 |
} else { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1303 |
int index; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1304 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1305 |
while ((index = SlIterateArray()) != -1) { |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1306 |
Order *order; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1307 |
|
4977 | 1308 |
if (!AddBlockIfNeeded(&_Order_pool, index)) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1309 |
error("Orders: failed loading savegame: too many orders"); |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1310 |
|
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1297
diff
changeset
|
1311 |
order = GetOrder(index); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1312 |
SlObject(order, _order_desc); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1313 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1314 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1315 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1316 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
1317 |
extern const ChunkHandler _order_chunk_handlers[] = { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1318 |
{ 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST}, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1020
diff
changeset
|
1319 |
}; |