diff options
author | bjarni <bjarni@openttd.org> | 2007-03-08 21:39:34 +0000 |
---|---|---|
committer | bjarni <bjarni@openttd.org> | 2007-03-08 21:39:34 +0000 |
commit | c2b7d0192d2b07ca7e4d87d583dabb2e43df49ec (patch) | |
tree | cfdbc180c9140ada4cb0bc22da9defe931609d16 /src/order.h | |
parent | daeac3d310a6bf367eb77f0b965f8930dc187899 (diff) | |
download | openttd-c2b7d0192d2b07ca7e4d87d583dabb2e43df49ec.tar.xz |
(svn r9072) -Codechange: [Orders] added methods to orders to free them and check if they are in use
Diffstat (limited to 'src/order.h')
-rw-r--r-- | src/order.h | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/order.h b/src/order.h index b996fb9d6..3a2ddb1f3 100644 --- a/src/order.h +++ b/src/order.h @@ -99,6 +99,10 @@ struct Order { CargoID refit_cargo; // Refit CargoID byte refit_subtype; // Refit subtype + + bool IsValid() const; + void Free(); + void FreeChain(); }; #define MAX_BACKUP_ORDER_COUNT 40 @@ -134,18 +138,26 @@ static inline VehicleOrderID GetNumOrders() /** * Check if a Order really exists. */ -static inline bool IsValidOrder(const Order *o) +inline bool Order::IsValid() const +{ + return type != OT_NOTHING; +} + +inline void Order::Free() { - return o->type != OT_NOTHING; + type = OT_NOTHING; + flags = 0; + dest = 0; + next = NULL; } -static inline void DeleteOrder(Order *o) +inline void Order::FreeChain() { - o->type = OT_NOTHING; - o->next = NULL; + if (next != NULL) next->FreeChain(); + Free(); } -#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)) +#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()) #define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0) @@ -160,7 +172,7 @@ static inline bool HasOrderPoolFree(uint amount) return true; FOR_ALL_ORDERS(order) - if (order->type == OT_NOTHING) + if (!order->IsValid()) if (--amount == 0) return true; |