order.h
author tron
Sat, 22 Jan 2005 20:23:18 +0000
changeset 1093 e8d26c7dc42f
parent 1053 dfb5243315f1
child 1314 d6a253cf92c3
permissions -rw-r--r--
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     1
#ifndef ORDER_H
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     2
#define ORDER_H
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     3
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     4
/* Order types */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     5
enum {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     6
	OT_NOTHING       = 0,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     7
	OT_GOTO_STATION  = 1,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     8
	OT_GOTO_DEPOT    = 2,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
     9
	OT_LOADING       = 3,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    10
	OT_LEAVESTATION  = 4,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    11
	OT_DUMMY         = 5,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    12
	OT_GOTO_WAYPOINT = 6
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    13
};
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    14
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    15
/* Order flags -- please use OFB instead OF and use HASBIT/SETBIT/CLEARBIT */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    16
enum {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    17
	OF_UNLOAD    = 0x2,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    18
	OF_FULL_LOAD = 0x4, // Also used when to force an aircraft into a depot
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    19
	OF_NON_STOP  = 0x8
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    20
};
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    21
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    22
/* Order flags bits */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    23
enum {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    24
	OFB_UNLOAD    = 1,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    25
	OFB_FULL_LOAD = 2,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    26
	OFB_NON_STOP  = 3
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    27
};
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    28
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    29
/* Possible clone options */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    30
enum {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    31
	CO_SHARE   = 0,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    32
	CO_COPY    = 1,
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    33
	CO_UNSHARE = 2
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    34
};
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    35
1053
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    36
/* Modes for the order checker */
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    37
enum {
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    38
	OC_INIT     = 0, //the order checker can initialize a news message
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    39
	OC_VALIDATE = 1, //the order checker validates a news message
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    40
};
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
    41
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    42
/* If you change this, keep in mind that it is saved on 3 places:
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    43
    - Load_ORDR, all the global orders
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    44
    - Vehicle -> current_order
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    45
    - REF_SHEDULE (all REFs are currently limited to 16 bits!!) */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    46
typedef struct Order {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    47
	uint8  type;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    48
	uint8  flags;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    49
	uint16 station;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    50
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    51
	struct Order *next;   //! Pointer to next order. If NULL, end of list
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    52
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    53
	uint16 index;         //! Index of the order, is not saved or anything, just for reference
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    54
} Order;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    55
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    56
typedef struct {
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    57
	VehicleID clone;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    58
	byte orderindex;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    59
	Order order[41];
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    60
	uint16 service_interval;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    61
	char name[32];
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    62
} BackuppedOrders;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    63
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    64
VARDEF TileIndex _backup_orders_tile;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    65
VARDEF BackuppedOrders _backup_orders_data[1];
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    66
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    67
VARDEF Order _orders[5000];
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    68
VARDEF uint32 _orders_size;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    69
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    70
static inline Order *GetOrder(uint index)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    71
{
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    72
	assert(index < _orders_size);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    73
	return &_orders[index];
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    74
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    75
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    76
#define FOR_ALL_ORDERS_FROM(o, from) for(o = GetOrder(from); o != &_orders[_orders_size]; o++)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    77
#define FOR_ALL_ORDERS(o) FOR_ALL_ORDERS_FROM(o, 0)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    78
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    79
#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
    80
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    81
static inline bool HasOrderPoolFree(uint amount)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    82
{
1043
123072ba6ced (svn r1544) -Fix: SwapOrder did not use AssignOrder, which caused the saveroutine to
truelight
parents: 1024
diff changeset
    83
	const Order *order;
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    84
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    85
	FOR_ALL_ORDERS(order)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    86
		if (order->type == OT_NOTHING)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    87
			if (--amount == 0)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    88
				return true;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    89
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    90
	return false;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    91
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    92
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1053
diff changeset
    93
static inline bool IsOrderPoolFull(void)
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    94
{
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    95
	return !HasOrderPoolFree(1);
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
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    98
/* Pack and unpack routines */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
    99
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   100
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
   101
{
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   102
	return order->station << 16 | order->flags << 8 | order->type;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   103
}
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   104
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   105
static inline Order UnpackOrder(uint32 packed)
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   106
{
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   107
	Order order;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   108
	order.type    = (packed & 0x000000FF);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   109
	order.flags   = (packed & 0x0000FF00) >> 8;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   110
	order.station = (packed & 0xFFFF0000) >> 16;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   111
	order.next    = NULL;
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   112
	return order;
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
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   115
/* Functions */
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   116
void BackupVehicleOrders(Vehicle *v, BackuppedOrders *order);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   117
void RestoreVehicleOrders(Vehicle *v, BackuppedOrders *order);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   118
void DeleteDestinationFromVehicleOrder(Order dest);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   119
void InvalidateVehicleOrder(const Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   120
bool VehicleHasDepotOrders(const Vehicle *v);
1053
dfb5243315f1 (svn r1554) -Fix: [ 1103187 ] Order Check messages are now validated before
celestar
parents: 1043
diff changeset
   121
bool CheckOrders(uint data_a, uint data_b);
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   122
void DeleteVehicleOrders(Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   123
bool IsOrderListShared(const Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   124
void AssignOrder(Order *order, Order data);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   125
bool CheckForValidOrders(Vehicle *v);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   126
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   127
Order UnpackVersion4Order(uint16 packed);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   128
Order UnpackOldOrder(uint16 packed);
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   129
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
diff changeset
   130
#endif /* ORDER_H */