summaryrefslogtreecommitdiff
path: root/src/order.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/order.h')
-rw-r--r--src/order.h26
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;