~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/order.h

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: order.h 12296 2008-02-27 21:46:57Z glx $ */
2
 
 
3
 
/** @file order.h */
4
 
 
5
 
#ifndef ORDER_H
6
 
#define ORDER_H
7
 
 
8
 
#include "oldpool.h"
9
 
#include "core/bitmath_func.hpp"
10
 
#include "cargo_type.h"
11
 
#include "vehicle_type.h"
12
 
#include "tile_type.h"
13
 
#include "date_type.h"
14
 
 
15
 
enum {
16
 
        INVALID_VEH_ORDER_ID = 0xFF,
17
 
};
18
 
 
19
 
static const OrderID INVALID_ORDER = 0xFFFF;
20
 
 
21
 
/* Order types */
22
 
enum OrderType {
23
 
        OT_BEGIN         = 0,
24
 
        OT_NOTHING       = 0,
25
 
        OT_GOTO_STATION  = 1,
26
 
        OT_GOTO_DEPOT    = 2,
27
 
        OT_LOADING       = 3,
28
 
        OT_LEAVESTATION  = 4,
29
 
        OT_DUMMY         = 5,
30
 
        OT_GOTO_WAYPOINT = 6,
31
 
        OT_END
32
 
};
33
 
 
34
 
/* It needs to be 8bits, because we save and load it as such */
35
 
/** Define basic enum properties */
36
 
template <> struct EnumPropsT<OrderType> : MakeEnumPropsT<OrderType, byte, OT_BEGIN, OT_END, OT_END> {};
37
 
typedef TinyEnumT<OrderType> OrderTypeByte;
38
 
 
39
 
 
40
 
/* Order flags -- please use OF instead OF and use HASBIT/SETBIT/CLEARBIT */
41
 
 
42
 
/** Order flag masks - these are for direct bit operations */
43
 
enum OrderFlagMasks {
44
 
        //Flags for stations:
45
 
        /** vehicle will transfer cargo (i. e. not deliver to nearby industry/town even if accepted there) */
46
 
        OFB_TRANSFER           = 0x1,
47
 
        /** If OFB_TRANSFER is not set, drop any cargo loaded. If accepted, deliver, otherwise cargo remains at the station.
48
 
      * No new cargo is loaded onto the vehicle whatsoever */
49
 
        OFB_UNLOAD             = 0x2,
50
 
        /** Wait for full load of all vehicles, or of at least one cargo type, depending on patch setting
51
 
          * @todo make this two different flags */
52
 
        OFB_FULL_LOAD          = 0x4,
53
 
 
54
 
        //Flags for depots:
55
 
        /** The current depot-order was initiated because it was in the vehicle's order list */
56
 
        OFB_PART_OF_ORDERS     = 0x2,
57
 
        /** if OFB_PART_OF_ORDERS is not set, this will cause the vehicle to be stopped in the depot */
58
 
        OFB_HALT_IN_DEPOT      = 0x4,
59
 
        /** if OFB_PART_OF_ORDERS is set, this will cause the order only be come active if the vehicle needs servicing */
60
 
        OFB_SERVICE_IF_NEEDED  = 0x4, //used when OFB_PART_OF_ORDERS is set.
61
 
 
62
 
        //Common flags
63
 
        /** This causes the vehicle not to stop at intermediate OR the destination station (depending on patch settings)
64
 
          * @todo make this two different flags */
65
 
        OFB_NON_STOP           = 0x8
66
 
};
67
 
 
68
 
/** Order flags bits - these are for the *BIT macros
69
 
 * for descrption of flags, see OrderFlagMasks
70
 
 * @see OrderFlagMasks
71
 
 */
72
 
enum {
73
 
        OF_TRANSFER          = 0,
74
 
        OF_UNLOAD            = 1,
75
 
        OF_FULL_LOAD         = 2,
76
 
        OF_PART_OF_ORDERS    = 1,
77
 
        OF_HALT_IN_DEPOT     = 2,
78
 
        OF_SERVICE_IF_NEEDED = 2,
79
 
        OF_NON_STOP          = 3
80
 
};
81
 
 
82
 
 
83
 
/* Possible clone options */
84
 
enum {
85
 
        CO_SHARE   = 0,
86
 
        CO_COPY    = 1,
87
 
        CO_UNSHARE = 2
88
 
};
89
 
 
90
 
struct Order;
91
 
DECLARE_OLD_POOL(Order, Order, 6, 1000)
92
 
 
93
 
/* If you change this, keep in mind that it is saved on 3 places:
94
 
 * - Load_ORDR, all the global orders
95
 
 * - Vehicle -> current_order
96
 
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
97
 
 */
98
 
struct Order : PoolItem<Order, OrderID, &_Order_pool> {
99
 
        Order *next;          ///< Pointer to next order. If NULL, end of list
100
 
 
101
 
        OrderTypeByte type;
102
 
        uint8  flags;
103
 
        DestinationID dest;   ///< The destionation of the order.
104
 
 
105
 
        CargoID refit_cargo; // Refit CargoID
106
 
        byte refit_subtype; // Refit subtype
107
 
 
108
 
        uint16 wait_time;    ///< How long in ticks to wait at the destination.
109
 
        uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
110
 
 
111
 
        Order() : refit_cargo(CT_NO_REFIT) {}
112
 
        ~Order() { this->type = OT_NOTHING; }
113
 
 
114
 
        /**
115
 
         * Check if a Order really exists.
116
 
         */
117
 
        inline bool IsValid() const { return this->type != OT_NOTHING; }
118
 
 
119
 
        void Free();
120
 
        void FreeChain();
121
 
};
122
 
 
123
 
struct BackuppedOrders {
124
 
        BackuppedOrders() : order(NULL), name(NULL) { }
125
 
        ~BackuppedOrders() { free(order); free(name); }
126
 
 
127
 
        VehicleID clone;
128
 
        VehicleOrderID orderindex;
129
 
        GroupID group;
130
 
        Order *order;
131
 
        uint16 service_interval;
132
 
        char *name;
133
 
};
134
 
 
135
 
extern TileIndex _backup_orders_tile;
136
 
extern BackuppedOrders _backup_orders_data;
137
 
 
138
 
static inline VehicleOrderID GetMaxOrderIndex()
139
 
{
140
 
        /* TODO - This isn't the real content of the function, but
141
 
         *  with the new pool-system this will be replaced with one that
142
 
         *  _really_ returns the highest index. Now it just returns
143
 
         *  the next safe value we are sure about everything is below.
144
 
         */
145
 
        return GetOrderPoolSize() - 1;
146
 
}
147
 
 
148
 
static inline VehicleOrderID GetNumOrders()
149
 
{
150
 
        return GetOrderPoolSize();
151
 
}
152
 
 
153
 
inline void Order::Free()
154
 
{
155
 
        this->type  = OT_NOTHING;
156
 
        this->flags = 0;
157
 
        this->dest  = 0;
158
 
        this->next  = NULL;
159
 
}
160
 
 
161
 
inline void Order::FreeChain()
162
 
{
163
 
        if (next != NULL) next->FreeChain();
164
 
        delete this;
165
 
}
166
 
 
167
 
#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())
168
 
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
169
 
 
170
 
 
171
 
#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
172
 
 
173
 
static inline bool HasOrderPoolFree(uint amount)
174
 
{
175
 
        const Order *order;
176
 
 
177
 
        /* There is always room if not all blocks in the pool are reserved */
178
 
        if (_Order_pool.CanAllocateMoreBlocks()) return true;
179
 
 
180
 
        FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true;
181
 
 
182
 
        return false;
183
 
}
184
 
 
185
 
 
186
 
/* Pack and unpack routines */
187
 
 
188
 
static inline uint32 PackOrder(const Order *order)
189
 
{
190
 
        return order->dest << 16 | order->flags << 8 | order->type;
191
 
}
192
 
 
193
 
static inline Order UnpackOrder(uint32 packed)
194
 
{
195
 
        Order order;
196
 
        order.type    = (OrderType)GB(packed,  0,  8);
197
 
        order.flags   = GB(packed,  8,  8);
198
 
        order.dest    = GB(packed, 16, 16);
199
 
        order.next    = NULL;
200
 
        order.index   = 0; // avoid compiler warning
201
 
        order.refit_cargo   = CT_NO_REFIT;
202
 
        order.refit_subtype = 0;
203
 
        order.wait_time     = 0;
204
 
        order.travel_time   = 0;
205
 
        return order;
206
 
}
207
 
 
208
 
/* Functions */
209
 
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data);
210
 
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data);
211
 
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination);
212
 
void InvalidateVehicleOrder(const Vehicle *v);
213
 
bool VehicleHasDepotOrders(const Vehicle *v);
214
 
void CheckOrders(const Vehicle*);
215
 
void DeleteVehicleOrders(Vehicle *v);
216
 
void AssignOrder(Order *order, Order data);
217
 
bool CheckForValidOrders(const Vehicle* v);
218
 
 
219
 
Order UnpackOldOrder(uint16 packed);
220
 
 
221
 
#define MIN_SERVINT_PERCENT  5
222
 
#define MAX_SERVINT_PERCENT 90
223
 
#define MIN_SERVINT_DAYS    30
224
 
#define MAX_SERVINT_DAYS   800
225
 
 
226
 
/**
227
 
 * Get the service interval domain.
228
 
 * Get the new proposed service interval for the vehicle is indeed, clamped
229
 
 * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
230
 
 * @param index proposed service interval
231
 
 * @return service interval
232
 
 */
233
 
Date GetServiceIntervalClamped(uint index);
234
 
 
235
 
#endif /* ORDER_H */