2005-07-24 15:12:37 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-03-31 00:24:18 +01:00
|
|
|
/** @file order_base.h */
|
2005-07-28 07:09:15 +01:00
|
|
|
|
2008-03-31 00:24:18 +01:00
|
|
|
#ifndef ORDER_BASE_H
|
|
|
|
#define ORDER_BASE_H
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2008-03-28 16:36:32 +00:00
|
|
|
#include "order_type.h"
|
2006-12-03 17:27:43 +00:00
|
|
|
#include "oldpool.h"
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "cargo_type.h"
|
2008-04-05 16:30:15 +01:00
|
|
|
#include "station_type.h"
|
|
|
|
#include "vehicle_type.h"
|
2005-02-06 10:24:57 +00:00
|
|
|
|
2007-08-03 00:40:19 +01:00
|
|
|
DECLARE_OLD_POOL(Order, Order, 6, 1000)
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If you change this, keep in mind that it is saved on 3 places:
|
2006-06-27 22:25:53 +01:00
|
|
|
* - Load_ORDR, all the global orders
|
|
|
|
* - Vehicle -> current_order
|
2007-06-20 20:17:22 +01:00
|
|
|
* - REF_ORDER (all REFs are currently limited to 16 bits!!)
|
2006-06-27 22:25:53 +01:00
|
|
|
*/
|
2007-08-03 00:40:19 +01:00
|
|
|
struct Order : PoolItem<Order, OrderID, &_Order_pool> {
|
2007-03-07 12:11:48 +00:00
|
|
|
Order *next; ///< Pointer to next order. If NULL, end of list
|
2007-02-04 13:46:21 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
OrderTypeByte type;
|
2005-01-15 19:06:22 +00:00
|
|
|
uint8 flags;
|
2006-08-26 17:34:03 +01:00
|
|
|
DestinationID dest; ///< The destionation of the order.
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2006-10-03 15:52:39 +01:00
|
|
|
CargoID refit_cargo; // Refit CargoID
|
|
|
|
byte refit_subtype; // Refit subtype
|
2007-03-08 21:39:34 +00:00
|
|
|
|
2007-06-20 20:17:22 +01:00
|
|
|
uint16 wait_time; ///< How long in ticks to wait at the destination.
|
|
|
|
uint16 travel_time; ///< How long in ticks the journey to this destination should take.
|
|
|
|
|
2007-08-03 00:40:19 +01:00
|
|
|
Order() : refit_cargo(CT_NO_REFIT) {}
|
|
|
|
~Order() { this->type = OT_NOTHING; }
|
|
|
|
|
2007-08-30 21:40:33 +01:00
|
|
|
/**
|
|
|
|
* Check if a Order really exists.
|
|
|
|
*/
|
|
|
|
inline bool IsValid() const { return this->type != OT_NOTHING; }
|
|
|
|
|
2008-04-05 21:57:01 +01:00
|
|
|
/**
|
|
|
|
* 'Free' the order
|
|
|
|
* @note ONLY use on "current_order" vehicle orders!
|
|
|
|
*/
|
2007-03-08 21:39:34 +00:00
|
|
|
void Free();
|
2008-04-05 21:57:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a complete order chain.
|
|
|
|
* @note do not use on "current_order" vehicle orders!
|
|
|
|
*/
|
2007-03-08 21:39:34 +00:00
|
|
|
void FreeChain();
|
2008-04-05 16:30:15 +01:00
|
|
|
|
|
|
|
bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
|
2008-04-05 22:45:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign the given order to this one.
|
|
|
|
* @param other the data to copy (except next pointer).
|
|
|
|
*/
|
|
|
|
void AssignOrder(const Order &other);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this order have the same type, flags and destination?
|
|
|
|
* @param other the second order to compare to.
|
|
|
|
* @return true if the type, flags and destination match.
|
|
|
|
*/
|
|
|
|
bool Equals(const Order &other) const;
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline VehicleOrderID GetMaxOrderIndex()
|
2006-08-22 21:41:26 +01:00
|
|
|
{
|
|
|
|
/* TODO - This isn't the real content of the function, but
|
|
|
|
* with the new pool-system this will be replaced with one that
|
2006-12-05 13:58:20 +00:00
|
|
|
* _really_ returns the highest index. Now it just returns
|
2006-08-22 21:41:26 +01:00
|
|
|
* the next safe value we are sure about everything is below.
|
|
|
|
*/
|
2006-12-05 13:58:20 +00:00
|
|
|
return GetOrderPoolSize() - 1;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static inline VehicleOrderID GetNumOrders()
|
2006-12-05 13:58:20 +00:00
|
|
|
{
|
2006-08-22 21:41:26 +01:00
|
|
|
return GetOrderPoolSize();
|
|
|
|
}
|
|
|
|
|
2007-03-08 21:39:34 +00:00
|
|
|
#define FOR_ALL_ORDERS_FROM(order, start) for (order = GetOrder(start); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) if (order->IsValid())
|
2005-02-06 10:24:57 +00:00
|
|
|
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
#define FOR_VEHICLE_ORDERS(v, order) for (order = v->orders; order != NULL; order = order->next)
|
|
|
|
|
2008-04-05 21:57:01 +01:00
|
|
|
/* (Un)pack routines */
|
|
|
|
uint32 PackOrder(const Order *order);
|
|
|
|
Order UnpackOrder(uint32 packed);
|
2005-01-15 19:06:22 +00:00
|
|
|
Order UnpackOldOrder(uint16 packed);
|
|
|
|
|
|
|
|
#endif /* ORDER_H */
|