order.h
author rubidium
Mon, 04 Sep 2006 20:40:33 +0000
changeset 4549 106ed18a7675
parent 4527 fa30d19685c2
child 4712 4335ad42e163
permissions -rw-r--r--
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
-Cleanup: whitespace alignment of a few tables.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2159
diff changeset
     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"
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
     9
#include "pool.h"
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 {
db2afc41002a (svn r6161) -Feature: List of vehicles with the same shared orders
bjarni
parents: 4392
diff changeset
    12
	INVALID_ORDER = 0xFFFF,
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
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    15
/* Order types */
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
    16
enum OrderTypes {
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    17
	OT_NOTHING       = 0,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    18
	OT_GOTO_STATION  = 1,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    19
	OT_GOTO_DEPOT    = 2,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    20
	OT_LOADING       = 3,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    21
	OT_LEAVESTATION  = 4,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    22
	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
    23
	OT_GOTO_WAYPOINT = 6,
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
    24
};
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
    25
/* It needs to be 8bits, because we save and load it as such */
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
typedef uint8 OrderType;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    27
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    28
/* 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
    29
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
    30
/** 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
    31
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
    32
	//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
    33
	/** 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
    34
	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
    35
	/** 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
    36
      * 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
    37
	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
    38
	/** 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
    39
	  * @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
    40
	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
    41
2b46869fc0d4 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1314
diff changeset
    42
	//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
    43
	/** 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
    44
	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
    45
	/** 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
    46
	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
    47
	/** 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
    48
	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
    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
	//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
    51
	/** 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
    52
	  * @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
    53
	OF_NON_STOP           = 0x8
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    54
};
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    55
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
    56
/** 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
    57
 * for descrption of flags, see OrderFlagMasks
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    58
 * @see OrderFlagMasks
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    59
 */
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    60
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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
	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
    67
	OFB_NON_STOP          = 3
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    68
};
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    69
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
    70
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    71
/* Possible clone options */
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    72
enum {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    73
	CO_SHARE   = 0,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    74
	CO_COPY    = 1,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    75
	CO_UNSHARE = 2
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
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    78
/* 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
    79
 * - Load_ORDR, all the global orders
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    80
 * - Vehicle -> current_order
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    81
 * - REF_SHEDULE (all REFs are currently limited to 16 bits!!)
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    82
 */
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    83
typedef struct Order {
4351
c9799dd53eec (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
    84
	OrderType type;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    85
	uint8  flags;
4389
18d6ccfb5335 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4384
diff changeset
    86
	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
    87
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 3140
diff changeset
    88
	struct Order *next;   ///< Pointer to next order. If NULL, end of list
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    89
4392
68ca7ef4f600 (svn r6145) -Codechange: added OrderID to indicate Order indexes out of the pool
truelight
parents: 4391
diff changeset
    90
	OrderID index;         ///< Index of the order, is not saved or anything, just for reference
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    91
} Order;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    92
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
    93
#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
    94
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    95
typedef struct {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    96
	VehicleID clone;
4391
40c1c7dd05f3 (svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents: 4389
diff changeset
    97
	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
    98
	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
    99
	uint16 service_interval;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   100
	char name[32];
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   101
} BackuppedOrders;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   102
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   103
VARDEF TileIndex _backup_orders_tile;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   104
VARDEF BackuppedOrders _backup_orders_data[1];
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   105
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   106
extern MemoryPool _order_pool;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   107
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   108
/**
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   109
 * Get the pointer to the order with index 'index'
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   110
 */
4392
68ca7ef4f600 (svn r6145) -Codechange: added OrderID to indicate Order indexes out of the pool
truelight
parents: 4391
diff changeset
   111
static inline Order *GetOrder(OrderID index)
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   112
{
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   113
	return (Order*)GetItemFromPool(&_order_pool, index);
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   114
}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   115
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   116
/**
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   117
 * Get the current size of the OrderPool
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   118
 */
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   119
static inline uint16 GetOrderPoolSize(void)
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   120
{
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   121
	return _order_pool.total_items;
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   122
}
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   123
4391
40c1c7dd05f3 (svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents: 4389
diff changeset
   124
static inline VehicleOrderID GetOrderArraySize(void)
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   125
{
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   126
	/* 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
   127
	 *  with the new pool-system this will be replaced with one that
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   128
	 *  _really_ returns the highest index + 1. Now it just returns
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   129
	 *  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
   130
	 */
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   131
	return GetOrderPoolSize();
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   132
}
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   133
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   134
/**
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   135
 * 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
   136
 */
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   137
static inline bool IsValidOrder(const Order *o)
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   138
{
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   139
	return o->type != OT_NOTHING;
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   140
}
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   141
4384
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   142
static inline void DeleteOrder(Order *o)
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   143
{
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   144
	o->type = OT_NOTHING;
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   145
	o->next = NULL;
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   146
}
7e0d3ed719d9 (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4354
diff changeset
   147
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4344
diff changeset
   148
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) if (IsValidOrder(order))
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   149
#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
   150
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   151
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   152
#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
   153
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   154
static inline bool HasOrderPoolFree(uint amount)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   155
{
1043
44508ede2f92 (svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents: 1024
diff changeset
   156
	const Order *order;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   157
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   158
	/* There is always room if not all blocks in the pool are reserved */
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   159
	if (_order_pool.current_blocks < _order_pool.max_blocks)
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   160
		return true;
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   161
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   162
	FOR_ALL_ORDERS(order)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   163
		if (order->type == OT_NOTHING)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   164
			if (--amount == 0)
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   165
				return true;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   166
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   167
	return false;
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
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1053
diff changeset
   170
static inline bool IsOrderPoolFull(void)
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   171
{
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   172
	return !HasOrderPoolFree(1);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   173
}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   174
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   175
/* Pack and unpack routines */
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   176
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   177
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
   178
{
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
   179
	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
   180
}
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
static inline Order UnpackOrder(uint32 packed)
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
	Order order;
4351
c9799dd53eec (svn r6052) -Codechange: change OrderType (order->type) in a typedef
truelight
parents: 4346
diff changeset
   185
	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
   186
	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
   187
	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
   188
	order.next    = NULL;
1884
804ff5f94ed0 (svn r2390) - Codechange: Fix some warnings on GCC 4.0.0
hackykid
parents: 1796
diff changeset
   189
	order.index   = 0; // avoid compiler warning
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   190
	return order;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   191
}
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
/* 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
   194
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2433
diff changeset
   195
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
   196
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
   197
void InvalidateVehicleOrder(const Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   198
bool VehicleHasDepotOrders(const Vehicle *v);
3140
5555cc95043a (svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents: 2817
diff changeset
   199
void CheckOrders(const Vehicle*);
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   200
void DeleteVehicleOrders(Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   201
bool IsOrderListShared(const Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   202
void AssignOrder(Order *order, Order data);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2433
diff changeset
   203
bool CheckForValidOrders(const Vehicle* v);
1024
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
Order UnpackOldOrder(uint16 packed);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   206
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   207
#endif /* ORDER_H */