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