src/order.h
author rubidium
Fri, 28 Mar 2008 16:36:32 +0000
changeset 9267 71cf88230dc1
parent 9266 416385a64dcb
permissions -rw-r--r--
(svn r12470) -Codechange: split order related types from order.h (and openttd.h) to order_type.h.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     2
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4527
diff changeset
     3
/** @file order.h */
2214
75d037f8dcc4 (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
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     5
#ifndef ORDER_H
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     6
#define ORDER_H
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     7
9267
71cf88230dc1 (svn r12470) -Codechange: split order related types from order.h (and openttd.h) to order_type.h.
rubidium
parents: 9266
diff changeset
     8
#include "order_type.h"
5216
d581e4db95b6 (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"
8609
8c0c3e9dd6a0 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8149
diff changeset
    10
#include "core/bitmath_func.hpp"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8609
diff changeset
    11
#include "cargo_type.h"
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8609
diff changeset
    12
#include "vehicle_type.h"
8634
5ffca02f9115 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8615
diff changeset
    13
#include "tile_type.h"
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
    14
#include "date_type.h"
9266
416385a64dcb (svn r12469) -Codechange: split type related stuff from group.h (and openttd.h) to group_type.h.
rubidium
parents: 9263
diff changeset
    15
#include "group_type.h"
1314
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
    16
7887
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    17
DECLARE_OLD_POOL(Order, Order, 6, 1000)
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    18
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    19
/* If you change this, keep in mind that it is saved on 3 places:
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    20
 * - Load_ORDR, all the global orders
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    21
 * - Vehicle -> current_order
7476
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
    22
 * - REF_ORDER (all REFs are currently limited to 16 bits!!)
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    23
 */
7887
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    24
struct Order : PoolItem<Order, OrderID, &_Order_pool> {
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    25
	Order *next;          ///< Pointer to next order. If NULL, end of list
6189
2b1ae5e373e9 (svn r8582) -Fix
tron
parents: 6173
diff changeset
    26
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5726
diff changeset
    27
	OrderTypeByte type;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    28
	uint8  flags;
4389
e4555522d257 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4384
diff changeset
    29
	DestinationID dest;   ///< The destionation of the order.
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    30
4712
273ec3b182bf (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
    31
	CargoID refit_cargo; // Refit CargoID
273ec3b182bf (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
    32
	byte refit_subtype; // Refit subtype
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    33
7476
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
    34
	uint16 wait_time;    ///< How long in ticks to wait at the destination.
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
    35
	uint16 travel_time;  ///< How long in ticks the journey to this destination should take.
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
    36
7887
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    37
	Order() : refit_cargo(CT_NO_REFIT) {}
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    38
	~Order() { this->type = OT_NOTHING; }
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    39
7992
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7887
diff changeset
    40
	/**
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7887
diff changeset
    41
	 * Check if a Order really exists.
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7887
diff changeset
    42
	 */
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7887
diff changeset
    43
	inline bool IsValid() const { return this->type != OT_NOTHING; }
8ac3fcd8d570 (svn r11009) -Codechange: unvirtualise IsValid as that isn't needed with templates. This gives up to 10% performance increase in games with lots of vehicles.
rubidium
parents: 7887
diff changeset
    44
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    45
	void Free();
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    46
	void FreeChain();
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    47
};
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    48
8149
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7992
diff changeset
    49
struct BackuppedOrders {
8818
d8d3812f8f35 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8798
diff changeset
    50
	BackuppedOrders() : order(NULL), name(NULL) { }
d8d3812f8f35 (svn r11887) -Fix [FS#1658]: segmentation faults/wrong frees due uninitialized memory in the AI.
rubidium
parents: 8798
diff changeset
    51
	~BackuppedOrders() { free(order); free(name); }
2433
5f55c796b85b (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
    52
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    53
	VehicleID clone;
4391
7bfd170bfdf5 (svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents: 4389
diff changeset
    54
	VehicleOrderID orderindex;
9146
2c8c94a75544 (svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
glx
parents: 8965
diff changeset
    55
	GroupID group;
8149
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7992
diff changeset
    56
	Order *order;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    57
	uint16 service_interval;
8754
5dae65402806 (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8707
diff changeset
    58
	char *name;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    59
};
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    60
8764
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8754
diff changeset
    61
extern TileIndex _backup_orders_tile;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8754
diff changeset
    62
extern BackuppedOrders _backup_orders_data;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    63
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6189
diff changeset
    64
static inline VehicleOrderID GetMaxOrderIndex()
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    65
{
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    66
	/* TODO - This isn't the real content of the function, but
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    67
	 *  with the new pool-system this will be replaced with one that
5247
c3eece01af11 (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
    68
	 *  _really_ returns the highest index. Now it just returns
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    69
	 *  the next safe value we are sure about everything is below.
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    70
	 */
5247
c3eece01af11 (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
    71
	return GetOrderPoolSize() - 1;
c3eece01af11 (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
    72
}
c3eece01af11 (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
    73
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6189
diff changeset
    74
static inline VehicleOrderID GetNumOrders()
5247
c3eece01af11 (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
    75
{
4354
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    76
	return GetOrderPoolSize();
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    77
}
684ab9249dae (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
    78
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    79
inline void Order::Free()
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
    80
{
7887
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    81
	this->type  = OT_NOTHING;
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    82
	this->flags = 0;
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    83
	this->dest  = 0;
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    84
	this->next  = NULL;
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
    85
}
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
    86
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    87
inline void Order::FreeChain()
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    88
{
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    89
	if (next != NULL) next->FreeChain();
7887
5740662fc5ce (svn r10760) -Codechange: make the order struct use the pool item class as super class.
rubidium
parents: 7871
diff changeset
    90
	delete this;
6589
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    91
}
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    92
addf4b6946d0 (svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
bjarni
parents: 6574
diff changeset
    93
#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
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
    94
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
    95
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    96
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    97
#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    98
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    99
static inline bool HasOrderPoolFree(uint amount)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   100
{
1043
123072ba6ced (svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents: 1024
diff changeset
   101
	const Order *order;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   102
1314
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   103
	/* There is always room if not all blocks in the pool are reserved */
7871
23f2383ad490 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 7476
diff changeset
   104
	if (_Order_pool.CanAllocateMoreBlocks()) return true;
1314
d6a253cf92c3 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   105
7871
23f2383ad490 (svn r10744) -Codechange: make the pool a little more OO, so it can be easier in other places.
rubidium
parents: 7476
diff changeset
   106
	FOR_ALL_ORDERS(order) if (!order->IsValid() && --amount == 0) return true;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   107
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   108
	return false;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   109
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   110
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   111
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   112
/* Pack and unpack routines */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   113
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   114
static inline uint32 PackOrder(const Order *order)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   115
{
4527
b18634a31a4a (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
   116
	return order->dest << 16 | order->flags << 8 | order->type;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   117
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   118
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   119
static inline Order UnpackOrder(uint32 packed)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   120
{
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   121
	Order order;
4351
63ae31104f07 (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
   122
	order.type    = (OrderType)GB(packed,  0,  8);
2140
d708eb80ab8b (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
   123
	order.flags   = GB(packed,  8,  8);
4527
b18634a31a4a (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
   124
	order.dest    = GB(packed, 16, 16);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   125
	order.next    = NULL;
1884
ae1d6213c6dd (svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents: 1796
diff changeset
   126
	order.index   = 0; // avoid compiler warning
4780
fe1f661dfa86 (svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents: 4715
diff changeset
   127
	order.refit_cargo   = CT_NO_REFIT;
4715
7ab95d47d2eb (svn r6627) -Fix r6624: fixed some warnings
bjarni
parents: 4712
diff changeset
   128
	order.refit_subtype = 0;
7476
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
   129
	order.wait_time     = 0;
7f086e4b2a76 (svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros
parents: 6589
diff changeset
   130
	order.travel_time   = 0;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   131
	return order;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   132
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   133
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   134
/* Functions */
8149
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7992
diff changeset
   135
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data);
eb78fb69096f (svn r11184) -Codechange: cleanup the code related to backup orders.
rubidium
parents: 7992
diff changeset
   136
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data);
4389
e4555522d257 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4384
diff changeset
   137
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   138
void InvalidateVehicleOrder(const Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   139
bool VehicleHasDepotOrders(const Vehicle *v);
3140
69cb681c6d86 (svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents: 2817
diff changeset
   140
void CheckOrders(const Vehicle*);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   141
void DeleteVehicleOrders(Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   142
void AssignOrder(Order *order, Order data);
2630
35249d2ded3e (svn r3172) static, const
tron
parents: 2433
diff changeset
   143
bool CheckForValidOrders(const Vehicle* v);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   144
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   145
Order UnpackOldOrder(uint16 packed);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   146
8707
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   147
#define MIN_SERVINT_PERCENT  5
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   148
#define MAX_SERVINT_PERCENT 90
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   149
#define MIN_SERVINT_DAYS    30
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   150
#define MAX_SERVINT_DAYS   800
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   151
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   152
/**
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   153
 * Get the service interval domain.
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   154
 * Get the new proposed service interval for the vehicle is indeed, clamped
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   155
 * within the given bounds. @see MIN_SERVINT_PERCENT ,etc.
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   156
 * @param index proposed service interval
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   157
 * @return service interval
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   158
 */
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   159
Date GetServiceIntervalClamped(uint index);
55835d8fbfcd (svn r11774) -Change: do not include variables.h in a header when it is not needed.
rubidium
parents: 8634
diff changeset
   160
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   161
#endif /* ORDER_H */