author | rubidium |
Thu, 02 Aug 2007 23:40:19 +0000 | |
changeset 7391 | 8c87aec393c7 |
parent 7375 | 961ab798c4b6 |
child 7496 | 49cec492627b |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4549
106ed18a7675
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4527
diff
changeset
|
3 |
/** @file order.h */ |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
4 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
5 |
#ifndef ORDER_H |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
6 |
#define ORDER_H |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
7 |
|
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2140
diff
changeset
|
8 |
#include "macros.h" |
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:
4977
diff
changeset
|
9 |
#include "oldpool.h" |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1093
diff
changeset
|
10 |
|
4408
db2afc41002a
(svn r6161) -Feature: List of vehicles with the same shared orders
bjarni
parents:
4392
diff
changeset
|
11 |
enum { |
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
|
12 |
INVALID_VEH_ORDER_ID = 0xFF, |
4408
db2afc41002a
(svn r6161) -Feature: List of vehicles with the same shared orders
bjarni
parents:
4392
diff
changeset
|
13 |
}; |
db2afc41002a
(svn r6161) -Feature: List of vehicles with the same shared orders
bjarni
parents:
4392
diff
changeset
|
14 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
15 |
static const OrderID INVALID_ORDER = 0xFFFF; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
16 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
17 |
/* Order types */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
18 |
enum OrderType { |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
19 |
OT_BEGIN = 0, |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
20 |
OT_NOTHING = 0, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
21 |
OT_GOTO_STATION = 1, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
22 |
OT_GOTO_DEPOT = 2, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
23 |
OT_LOADING = 3, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
24 |
OT_LEAVESTATION = 4, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
25 |
OT_DUMMY = 5, |
4421
605e155a0445
(svn r6176) -Fix r6052: I assumed an typedefd enum would be an uint8, which is a really stupid thing to assume.
truelight
parents:
4414
diff
changeset
|
26 |
OT_GOTO_WAYPOINT = 6, |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
27 |
OT_END |
4421
605e155a0445
(svn r6176) -Fix r6052: I assumed an typedefd enum would be an uint8, which is a really stupid thing to assume.
truelight
parents:
4414
diff
changeset
|
28 |
}; |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
29 |
|
4421
605e155a0445
(svn r6176) -Fix r6052: I assumed an typedefd enum would be an uint8, which is a really stupid thing to assume.
truelight
parents:
4414
diff
changeset
|
30 |
/* It needs to be 8bits, because we save and load it as such */ |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
31 |
/** Define basic enum properties */ |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
32 |
template <> struct EnumPropsT<OrderType> : MakeEnumPropsT<OrderType, byte, OT_BEGIN, OT_END, OT_END> {}; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
33 |
typedef TinyEnumT<OrderType> OrderTypeByte; |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
34 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
35 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
36 |
/* Order flags -- please use OFB instead OF and use HASBIT/SETBIT/CLEARBIT */ |
1615
24c6310f887b
(svn r2119) - Fix: [ 1172878 ] Trains "Go to depot" button: click twice skip to next order (patch by Loic GUILLOUX). I also added short explanation of OF_/OFB_ difference to order.h.
pasky
parents:
1530
diff
changeset
|
37 |
|
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
38 |
/** Order flag masks - these are for direct bit operations */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
39 |
enum OrderFlagMasks { |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1314
diff
changeset
|
40 |
//Flags for stations: |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
41 |
/** vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there) */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
42 |
OF_TRANSFER = 0x1, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
43 |
/** If OF_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station. |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
44 |
* No new cargo is loaded onto the vehicle whatsoever */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
45 |
OF_UNLOAD = 0x2, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
46 |
/** Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
47 |
* @todo make this two different flags */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
48 |
OF_FULL_LOAD = 0x4, |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1314
diff
changeset
|
49 |
|
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1314
diff
changeset
|
50 |
//Flags for depots: |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
51 |
/** The current depot-order was initiated because it was in the vehicle's order list */ |
4344
7e123fec5b0b
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4077
diff
changeset
|
52 |
OF_PART_OF_ORDERS = 0x2, |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
53 |
/** if OF_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
54 |
OF_HALT_IN_DEPOT = 0x4, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
55 |
/** if OF_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
56 |
OF_SERVICE_IF_NEEDED = 0x4, //used when OF_PART_OF_ORDERS is set. |
1530
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1314
diff
changeset
|
57 |
|
2b46869fc0d4
(svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents:
1314
diff
changeset
|
58 |
//Common flags |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
59 |
/** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings) |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
60 |
* @todo make this two different flags */ |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
61 |
OF_NON_STOP = 0x8 |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
62 |
}; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
63 |
|
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
64 |
/** Order flags bits - these are for the *BIT macros |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
65 |
* for descrption of flags, see OrderFlagMasks |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
66 |
* @see OrderFlagMasks |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
67 |
*/ |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
68 |
enum { |
2214
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
69 |
OFB_TRANSFER = 0, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
70 |
OFB_UNLOAD = 1, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
71 |
OFB_FULL_LOAD = 2, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
72 |
OFB_PART_OF_ORDERS = 1, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
73 |
OFB_HALT_IN_DEPOT = 2, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
74 |
OFB_SERVICE_IF_NEEDED = 2, |
056bbc3c8236
(svn r2732) -Codechange: Cleaned the order flags some more. Hit some inconsistencies while trying to locate bug 1244167
celestar
parents:
2186
diff
changeset
|
75 |
OFB_NON_STOP = 3 |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
76 |
}; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
77 |
|
1615
24c6310f887b
(svn r2119) - Fix: [ 1172878 ] Trains "Go to depot" button: click twice skip to next order (patch by Loic GUILLOUX). I also added short explanation of OF_/OFB_ difference to order.h.
pasky
parents:
1530
diff
changeset
|
78 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
79 |
/* Possible clone options */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
80 |
enum { |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
81 |
CO_SHARE = 0, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
82 |
CO_COPY = 1, |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
83 |
CO_UNSHARE = 2 |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
84 |
}; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
85 |
|
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
86 |
struct Order; |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
87 |
DECLARE_OLD_POOL(Order, Order, 6, 1000) |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
88 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
89 |
/* If you change this, keep in mind that it is saved on 3 places: |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
90 |
* - Load_ORDR, all the global orders |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
91 |
* - Vehicle -> current_order |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
92 |
* - REF_ORDER (all REFs are currently limited to 16 bits!!) |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
3347
diff
changeset
|
93 |
*/ |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
94 |
struct Order : PoolItem<Order, OrderID, &_Order_pool> { |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
95 |
Order *next; ///< Pointer to next order. If NULL, end of list |
5938 | 96 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
97 |
OrderTypeByte type; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
98 |
uint8 flags; |
4389
18d6ccfb5335
(svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents:
4384
diff
changeset
|
99 |
DestinationID dest; ///< The destionation of the order. |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
100 |
|
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
|
101 |
CargoID refit_cargo; // Refit 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
|
102 |
byte refit_subtype; // Refit subtype |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
103 |
|
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
104 |
uint16 wait_time; ///< How long in ticks to wait at the destination. |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
105 |
uint16 travel_time; ///< How long in ticks the journey to this destination should take. |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
106 |
|
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
107 |
Order() : refit_cargo(CT_NO_REFIT) {} |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
108 |
~Order() { this->type = OT_NOTHING; } |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
109 |
|
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
110 |
bool IsValid() const; |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
111 |
void Free(); |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
112 |
void FreeChain(); |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
113 |
}; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
114 |
|
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:
2214
diff
changeset
|
115 |
#define MAX_BACKUP_ORDER_COUNT 40 |
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:
2214
diff
changeset
|
116 |
|
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
117 |
struct BackuppedOrders { |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
118 |
VehicleID clone; |
4391
40c1c7dd05f3
(svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents:
4389
diff
changeset
|
119 |
VehicleOrderID orderindex; |
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:
2214
diff
changeset
|
120 |
Order order[MAX_BACKUP_ORDER_COUNT + 1]; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
121 |
uint16 service_interval; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
122 |
char name[32]; |
6248
e4a2ed7e5613
(svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents:
6247
diff
changeset
|
123 |
}; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
124 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
125 |
VARDEF TileIndex _backup_orders_tile; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
126 |
VARDEF BackuppedOrders _backup_orders_data[1]; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
127 |
|
6247 | 128 |
static inline VehicleOrderID GetMaxOrderIndex() |
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
129 |
{ |
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
130 |
/* TODO - This isn't the real content of the function, but |
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
131 |
* with the new pool-system this will be replaced with one that |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
132 |
* _really_ returns the highest index. Now it just returns |
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
133 |
* the next safe value we are sure about everything is below. |
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
134 |
*/ |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
135 |
return GetOrderPoolSize() - 1; |
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
136 |
} |
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
137 |
|
6247 | 138 |
static inline VehicleOrderID GetNumOrders() |
5247
1f982de55b88
(svn r7372) - CodeChange: Rename all GetXXXArraySize() functions to GetNumXXX() and add GetMaxXXXIndex() functions. This prepares for the new pool interface.
matthijs
parents:
5216
diff
changeset
|
139 |
{ |
4354
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
140 |
return GetOrderPoolSize(); |
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
141 |
} |
10f4ce894eb1
(svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents:
4351
diff
changeset
|
142 |
|
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
143 |
/** |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
144 |
* Check if a Order really exists. |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
145 |
*/ |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
146 |
inline bool Order::IsValid() const |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
147 |
{ |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
148 |
return this->type != OT_NOTHING; |
4346
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
149 |
} |
66105d4f6e83
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents:
4344
diff
changeset
|
150 |
|
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
151 |
inline void Order::Free() |
4384
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4354
diff
changeset
|
152 |
{ |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
153 |
this->type = OT_NOTHING; |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
154 |
this->flags = 0; |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
155 |
this->dest = 0; |
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
156 |
this->next = NULL; |
4384
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4354
diff
changeset
|
157 |
} |
7e0d3ed719d9
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4354
diff
changeset
|
158 |
|
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
159 |
inline void Order::FreeChain() |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
160 |
{ |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
161 |
if (next != NULL) next->FreeChain(); |
7391
8c87aec393c7
(svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents:
7375
diff
changeset
|
162 |
delete this; |
6263
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
163 |
} |
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
164 |
|
6bd0726c74e2
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents:
6248
diff
changeset
|
165 |
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid()) |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1093
diff
changeset
|
166 |
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) |
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1093
diff
changeset
|
167 |
|
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
168 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
169 |
#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
170 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
171 |
static inline bool HasOrderPoolFree(uint amount) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
172 |
{ |
1043
44508ede2f92
(svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents:
1024
diff
changeset
|
173 |
const Order *order; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
174 |
|
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1093
diff
changeset
|
175 |
/* There is always room if not all blocks in the pool are reserved */ |
7375
961ab798c4b6
(svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents:
6980
diff
changeset
|
176 |
if (_Order_pool.CanAllocateMoreBlocks()) return true; |
1314
10c3417e9c22
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1093
diff
changeset
|
177 |
|
7375
961ab798c4b6
(svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents:
6980
diff
changeset
|
178 |
FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
179 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
180 |
return false; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
181 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
182 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
183 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
184 |
/* Pack and unpack routines */ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
185 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
186 |
static inline uint32 PackOrder(const Order *order) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
187 |
{ |
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:
4449
diff
changeset
|
188 |
return order->dest << 16 | order->flags << 8 | order->type; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
189 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
190 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
191 |
static inline Order UnpackOrder(uint32 packed) |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
192 |
{ |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
193 |
Order order; |
4351
c9799dd53eec
(svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents:
4346
diff
changeset
|
194 |
order.type = (OrderType)GB(packed, 0, 8); |
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:
1935
diff
changeset
|
195 |
order.flags = GB(packed, 8, 8); |
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:
4449
diff
changeset
|
196 |
order.dest = GB(packed, 16, 16); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
197 |
order.next = NULL; |
1884
804ff5f94ed0
(svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents:
1796
diff
changeset
|
198 |
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:
4715
diff
changeset
|
199 |
order.refit_cargo = CT_NO_REFIT; |
4715 | 200 |
order.refit_subtype = 0; |
6980
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
201 |
order.wait_time = 0; |
c7c4f3bf5901
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents:
6263
diff
changeset
|
202 |
order.travel_time = 0; |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
203 |
return order; |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
204 |
} |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
205 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
206 |
/* Functions */ |
1796
614d996f6be7
(svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents:
1786
diff
changeset
|
207 |
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order); |
2630 | 208 |
void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* order); |
4389
18d6ccfb5335
(svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents:
4384
diff
changeset
|
209 |
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
210 |
void InvalidateVehicleOrder(const Vehicle *v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
211 |
bool VehicleHasDepotOrders(const Vehicle *v); |
3140
5555cc95043a
(svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents:
2817
diff
changeset
|
212 |
void CheckOrders(const Vehicle*); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
213 |
void DeleteVehicleOrders(Vehicle *v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
214 |
bool IsOrderListShared(const Vehicle *v); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
215 |
void AssignOrder(Order *order, Order data); |
2630 | 216 |
bool CheckForValidOrders(const Vehicle* v); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
217 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
218 |
Order UnpackOldOrder(uint16 packed); |
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
219 |
|
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff
changeset
|
220 |
#endif /* ORDER_H */ |