summaryrefslogtreecommitdiff
path: root/vehicle.h
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-02-04 13:23:29 +0000
committertruelight <truelight@openttd.org>2005-02-04 13:23:29 +0000
commit42f98c7eec8cd46ea8452911fb4381f209de342f (patch)
tree512961ac36580ababc52512c67235f48f4bef8c8 /vehicle.h
parent88ebe22d8b6e844b501688673f71db3505ea2b57 (diff)
downloadopenttd-42f98c7eec8cd46ea8452911fb4381f209de342f.tar.xz
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
Diffstat (limited to 'vehicle.h')
-rw-r--r--vehicle.h43
1 files changed, 26 insertions, 17 deletions
diff --git a/vehicle.h b/vehicle.h
index a180036d9..716aad77d 100644
--- a/vehicle.h
+++ b/vehicle.h
@@ -1,6 +1,7 @@
#ifndef VEHICLE_H
#define VEHICLE_H
+#include "pool.h"
#include "vehicle_gui.h"
#include "order.h"
@@ -359,33 +360,41 @@ byte GetDirectionTowards(Vehicle *v, int x, int y);
#define END_ENUM_WAGONS(v) } while ( (v=v->next) != NULL);
/* vehicle.c */
-enum {
- NUM_NORMAL_VEHICLES = 2048,
- NUM_SPECIAL_VEHICLES = 512,
- NUM_VEHICLES = NUM_NORMAL_VEHICLES + NUM_SPECIAL_VEHICLES
-};
+VARDEF SortStruct *_vehicle_sort;
-VARDEF Vehicle _vehicles[NUM_VEHICLES];
-VARDEF uint _vehicles_size;
+extern MemoryPool _vehicle_pool;
-VARDEF SortStruct *_vehicle_sort;
+/**
+ * Get the pointer to the vehicle with index 'index'
+ */
+static inline Vehicle *GetVehicle(VehicleID index)
+{
+ return (Vehicle*)GetItemFromPool(&_vehicle_pool, index);
+}
-static inline Vehicle *GetVehicle(uint index)
+/**
+ * Get the current size of the VehiclePool
+ */
+static inline uint16 GetVehiclePoolSize(void)
{
- assert(index < _vehicles_size);
- return &_vehicles[index];
+ return _vehicle_pool.total_items;
}
+#define FOR_ALL_VEHICLES_FROM(v, start) for (v = GetVehicle(start); v != NULL; v = (v->index + 1 < GetVehiclePoolSize()) ? GetVehicle(v->index + 1) : NULL)
+#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
+
+/**
+ * Check if an index is a vehicle-index (so between 0 and max-vehicles)
+ *
+ * @return Returns true if the vehicle-id is in range
+ */
static inline bool IsVehicleIndex(uint index)
{
- if (index < _vehicles_size)
+ if (index < GetVehiclePoolSize())
return true;
- else
- return false;
-}
-#define FOR_ALL_VEHICLES(v) for(v = _vehicles; v != &_vehicles[_vehicles_size]; v++)
-#define FOR_ALL_VEHICLES_FROM(v, from) for(v = GetVehicle(from); v != &_vehicles[_vehicles_size]; v++)
+ return false;
+}
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
static inline Order *GetVehicleOrder(const Vehicle *v, int index)