Mercurial > hg > openttd
comparison src/order.h @ 5475:eabf4b86aed6 draft
(svn r7759) -Merge: makefile rewrite. This merge features:
- A proper ./configure, so everything needs to be configured only once, not for every make.
- Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies.
- A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC.
- Proper support for OSX universal binaries.
- Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files.
- Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files.
Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Tue, 02 Jan 2007 19:19:48 +0000 |
parents | |
children | c44c070c5032 |
comparison
equal
deleted
inserted
replaced
5474:ba7562ec5adc | 5475:eabf4b86aed6 |
---|---|
1 /* $Id$ */ | |
2 | |
3 /** @file order.h */ | |
4 | |
5 #ifndef ORDER_H | |
6 #define ORDER_H | |
7 | |
8 #include "macros.h" | |
9 #include "oldpool.h" | |
10 | |
11 enum { | |
12 INVALID_VEH_ORDER_ID = 0xFF, | |
13 INVALID_ORDER = 0xFFFF, | |
14 }; | |
15 | |
16 /* Order types */ | |
17 enum OrderTypes { | |
18 OT_NOTHING = 0, | |
19 OT_GOTO_STATION = 1, | |
20 OT_GOTO_DEPOT = 2, | |
21 OT_LOADING = 3, | |
22 OT_LEAVESTATION = 4, | |
23 OT_DUMMY = 5, | |
24 OT_GOTO_WAYPOINT = 6, | |
25 }; | |
26 /* It needs to be 8bits, because we save and load it as such */ | |
27 typedef uint8 OrderType; | |
28 | |
29 /* Order flags -- please use OFB instead OF and use HASBIT/SETBIT/CLEARBIT */ | |
30 | |
31 /** Order flag masks - these are for direct bit operations */ | |
32 enum OrderFlagMasks { | |
33 //Flags for stations: | |
34 /** vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there) */ | |
35 OF_TRANSFER = 0x1, | |
36 /** If OF_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station. | |
37 * No new cargo is loaded onto the vehicle whatsoever */ | |
38 OF_UNLOAD = 0x2, | |
39 /** Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting | |
40 * @todo make this two different flags */ | |
41 OF_FULL_LOAD = 0x4, | |
42 | |
43 //Flags for depots: | |
44 /** The current depot-order was initiated because it was in the vehicle's order list */ | |
45 OF_PART_OF_ORDERS = 0x2, | |
46 /** if OF_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot */ | |
47 OF_HALT_IN_DEPOT = 0x4, | |
48 /** if OF_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */ | |
49 OF_SERVICE_IF_NEEDED = 0x4, //used when OF_PART_OF_ORDERS is set. | |
50 | |
51 //Common flags | |
52 /** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings) | |
53 * @todo make this two different flags */ | |
54 OF_NON_STOP = 0x8 | |
55 }; | |
56 | |
57 /** Order flags bits - these are for the *BIT macros | |
58 * for descrption of flags, see OrderFlagMasks | |
59 * @see OrderFlagMasks | |
60 */ | |
61 enum { | |
62 OFB_TRANSFER = 0, | |
63 OFB_UNLOAD = 1, | |
64 OFB_FULL_LOAD = 2, | |
65 OFB_PART_OF_ORDERS = 1, | |
66 OFB_HALT_IN_DEPOT = 2, | |
67 OFB_SERVICE_IF_NEEDED = 2, | |
68 OFB_NON_STOP = 3 | |
69 }; | |
70 | |
71 | |
72 /* Possible clone options */ | |
73 enum { | |
74 CO_SHARE = 0, | |
75 CO_COPY = 1, | |
76 CO_UNSHARE = 2 | |
77 }; | |
78 | |
79 /* If you change this, keep in mind that it is saved on 3 places: | |
80 * - Load_ORDR, all the global orders | |
81 * - Vehicle -> current_order | |
82 * - REF_SHEDULE (all REFs are currently limited to 16 bits!!) | |
83 */ | |
84 typedef struct Order { | |
85 OrderType type; | |
86 uint8 flags; | |
87 DestinationID dest; ///< The destionation of the order. | |
88 | |
89 struct Order *next; ///< Pointer to next order. If NULL, end of list | |
90 | |
91 OrderID index; ///< Index of the order, is not saved or anything, just for reference | |
92 | |
93 CargoID refit_cargo; // Refit CargoID | |
94 byte refit_subtype; // Refit subtype | |
95 } Order; | |
96 | |
97 #define MAX_BACKUP_ORDER_COUNT 40 | |
98 | |
99 typedef struct { | |
100 VehicleID clone; | |
101 VehicleOrderID orderindex; | |
102 Order order[MAX_BACKUP_ORDER_COUNT + 1]; | |
103 uint16 service_interval; | |
104 char name[32]; | |
105 } BackuppedOrders; | |
106 | |
107 VARDEF TileIndex _backup_orders_tile; | |
108 VARDEF BackuppedOrders _backup_orders_data[1]; | |
109 | |
110 DECLARE_OLD_POOL(Order, Order, 6, 1000) | |
111 | |
112 static inline VehicleOrderID GetMaxOrderIndex(void) | |
113 { | |
114 /* TODO - This isn't the real content of the function, but | |
115 * with the new pool-system this will be replaced with one that | |
116 * _really_ returns the highest index. Now it just returns | |
117 * the next safe value we are sure about everything is below. | |
118 */ | |
119 return GetOrderPoolSize() - 1; | |
120 } | |
121 | |
122 static inline VehicleOrderID GetNumOrders(void) | |
123 { | |
124 return GetOrderPoolSize(); | |
125 } | |
126 | |
127 /** | |
128 * Check if a Order really exists. | |
129 */ | |
130 static inline bool IsValidOrder(const Order *o) | |
131 { | |
132 return o->type != OT_NOTHING; | |
133 } | |
134 | |
135 static inline void DeleteOrder(Order *o) | |
136 { | |
137 o->type = OT_NOTHING; | |
138 o->next = NULL; | |
139 } | |
140 | |
141 #define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (IsValidOrder(order)) | |
142 #define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) | |
143 | |
144 | |
145 #define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next) | |
146 | |
147 static inline bool HasOrderPoolFree(uint amount) | |
148 { | |
149 const Order *order; | |
150 | |
151 /* There is always room if not all blocks in the pool are reserved */ | |
152 if (_Order_pool.current_blocks < _Order_pool.max_blocks) | |
153 return true; | |
154 | |
155 FOR_ALL_ORDERS(order) | |
156 if (order->type == OT_NOTHING) | |
157 if (--amount == 0) | |
158 return true; | |
159 | |
160 return false; | |
161 } | |
162 | |
163 static inline bool IsOrderPoolFull(void) | |
164 { | |
165 return !HasOrderPoolFree(1); | |
166 } | |
167 | |
168 /* Pack and unpack routines */ | |
169 | |
170 static inline uint32 PackOrder(const Order *order) | |
171 { | |
172 return order->dest << 16 | order->flags << 8 | order->type; | |
173 } | |
174 | |
175 static inline Order UnpackOrder(uint32 packed) | |
176 { | |
177 Order order; | |
178 order.type = (OrderType)GB(packed, 0, 8); | |
179 order.flags = GB(packed, 8, 8); | |
180 order.dest = GB(packed, 16, 16); | |
181 order.next = NULL; | |
182 order.index = 0; // avoid compiler warning | |
183 order.refit_cargo = CT_NO_REFIT; | |
184 order.refit_subtype = 0; | |
185 return order; | |
186 } | |
187 | |
188 /* Functions */ | |
189 void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order); | |
190 void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* order); | |
191 void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination); | |
192 void InvalidateVehicleOrder(const Vehicle *v); | |
193 bool VehicleHasDepotOrders(const Vehicle *v); | |
194 void CheckOrders(const Vehicle*); | |
195 void DeleteVehicleOrders(Vehicle *v); | |
196 bool IsOrderListShared(const Vehicle *v); | |
197 void AssignOrder(Order *order, Order data); | |
198 bool CheckForValidOrders(const Vehicle* v); | |
199 | |
200 Order UnpackOldOrder(uint16 packed); | |
201 | |
202 #endif /* ORDER_H */ |