src/order.h
author rubidium
Thu, 01 Feb 2007 15:49:12 +0000
changeset 5893 7e431a4abebb
parent 5587 167d9a91ef02
child 5922 caa040c9e25d
permissions -rw-r--r--
(svn r8511) -Codechange: make WindowClass an enumerated value.
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"
5216
8bd14ee39af2 (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"
1314
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 {
4712
4335ad42e163 (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
    12
	INVALID_VEH_ORDER_ID = 0xFF,
4408
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
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    15
static const OrderID INVALID_ORDER = 0xFFFF;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    16
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    17
/* Order types */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    18
enum OrderType {
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    19
	OT_BEGIN         = 0,
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    20
	OT_NOTHING       = 0,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    21
	OT_GOTO_STATION  = 1,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    22
	OT_GOTO_DEPOT    = 2,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    23
	OT_LOADING       = 3,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    24
	OT_LEAVESTATION  = 4,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    25
	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
    26
	OT_GOTO_WAYPOINT = 6,
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    27
	OT_END
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
    28
};
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    29
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
    30
/* It needs to be 8bits, because we save and load it as such */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    31
/** Define basic enum properties */
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    32
template <> struct EnumPropsT<OrderType> : MakeEnumPropsT<OrderType, byte, OT_BEGIN, OT_END, OT_END> {};
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    33
typedef TinyEnumT<OrderType> OrderTypeByte;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    34
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    35
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    36
/* 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
    37
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
    38
/** 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
    39
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
    40
	//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
    41
	/** 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
    42
	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
    43
	/** 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
    44
      * 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
    45
	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
    46
	/** 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
    47
	  * @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
    48
	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
    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
	//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
    51
	/** 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
    52
	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
    53
	/** 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
    54
	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
    55
	/** 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
    56
	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
    57
2b46869fc0d4 (svn r2034) -Codechange: Replaced the rather meaningless LOAD and UNLOAD flags for depots by something more meaningful
celestar
parents: 1314
diff changeset
    58
	//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
    59
	/** 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
    60
	  * @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
    61
	OF_NON_STOP           = 0x8
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    62
};
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    63
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
    64
/** 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
    65
 * for descrption of flags, see OrderFlagMasks
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    66
 * @see OrderFlagMasks
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    67
 */
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    68
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
    69
	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
    70
	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
    71
	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
    72
	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
    73
	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
    74
	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
    75
	OFB_NON_STOP          = 3
1024
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
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
    78
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    79
/* Possible clone options */
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    80
enum {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    81
	CO_SHARE   = 0,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    82
	CO_COPY    = 1,
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    83
	CO_UNSHARE = 2
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    84
};
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    85
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    86
/* 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
    87
 * - Load_ORDR, all the global orders
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    88
 * - Vehicle -> current_order
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3347
diff changeset
    89
 * - 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
    90
 */
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    91
typedef struct Order {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
    92
	OrderTypeByte type;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    93
	uint8  flags;
4389
18d6ccfb5335 (svn r6142) -Codechange: added WaypointID (sorry DV, couldn't splits it anymore)
truelight
parents: 4384
diff changeset
    94
	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
    95
3173
f56ca618721b (svn r3805) - [FS#62] Fix doxygen comments to refer to the correct parameter. (sulai)
peter1138
parents: 3140
diff changeset
    96
	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
    97
4392
68ca7ef4f600 (svn r6145) -Codechange: added OrderID to indicate Order indexes out of the pool
truelight
parents: 4391
diff changeset
    98
	OrderID index;         ///< Index of the order, is not saved or anything, just for reference
4712
4335ad42e163 (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
    99
4335ad42e163 (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
   100
	CargoID refit_cargo; // Refit CargoID
4335ad42e163 (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
   101
	byte refit_subtype; // Refit subtype
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   102
} Order;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   103
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
   104
#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
   105
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   106
typedef struct {
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   107
	VehicleID clone;
4391
40c1c7dd05f3 (svn r6144) -Codechange: renamed OrderID to VehicleOrderID, because it had nothing to do
truelight
parents: 4389
diff changeset
   108
	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
   109
	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
   110
	uint16 service_interval;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   111
	char name[32];
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   112
} BackuppedOrders;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   113
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   114
VARDEF TileIndex _backup_orders_tile;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   115
VARDEF BackuppedOrders _backup_orders_data[1];
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   116
5216
8bd14ee39af2 (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
   117
DECLARE_OLD_POOL(Order, Order, 6, 1000)
1314
10c3417e9c22 (svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents: 1093
diff changeset
   118
5247
1f982de55b88 (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
   119
static inline VehicleOrderID GetMaxOrderIndex(void)
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   120
{
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   121
	/* 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
   122
	 *  with the new pool-system this will be replaced with one that
5247
1f982de55b88 (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
   123
	 *  _really_ returns the highest index. Now it just returns
4354
10f4ce894eb1 (svn r6055) -Codechange: added GetXXXArraySize, which returns HighestID + 1 (or, will do that).
truelight
parents: 4351
diff changeset
   124
	 *  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
   125
	 */
5247
1f982de55b88 (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
   126
	return GetOrderPoolSize() - 1;
1f982de55b88 (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
   127
}
1f982de55b88 (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
   128
1f982de55b88 (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
   129
static inline VehicleOrderID GetNumOrders(void)
1f982de55b88 (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
   130
{
4354
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
4977
c5dd04c706bc (svn r6980) Use the pool macros for the Order pool
tron
parents: 4780
diff changeset
   148
#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))
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 */
4977
c5dd04c706bc (svn r6980) Use the pool macros for the Order pool
tron
parents: 4780
diff changeset
   159
	if (_Order_pool.current_blocks < _Order_pool.max_blocks)
1314
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
4780
307af11a644c (svn r6694) -Fix: FS#361 Refit-to Order bug (only one of the two bugs mentioned there)
bjarni
parents: 4715
diff changeset
   190
	order.refit_cargo   = CT_NO_REFIT;
4715
175674c3036f (svn r6627) -Fix r6624: fixed some warnings
bjarni
parents: 4712
diff changeset
   191
	order.refit_subtype = 0;
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   192
	return order;
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   193
}
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   194
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   195
/* 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
   196
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2433
diff changeset
   197
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
   198
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
   199
void InvalidateVehicleOrder(const Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   200
bool VehicleHasDepotOrders(const Vehicle *v);
3140
5555cc95043a (svn r3758) Remove the news validation callback. It is superseded by r3757.
tron
parents: 2817
diff changeset
   201
void CheckOrders(const Vehicle*);
1024
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   202
void DeleteVehicleOrders(Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   203
bool IsOrderListShared(const Vehicle *v);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   204
void AssignOrder(Order *order, Order data);
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2433
diff changeset
   205
bool CheckForValidOrders(const Vehicle* v);
1024
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
Order UnpackOldOrder(uint16 packed);
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   208
5e446b5b3ec5 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   209
#endif /* ORDER_H */