summaryrefslogtreecommitdiff
path: root/src/vehicle_base.h
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-12-26 23:53:07 +0000
committersmatz <smatz@openttd.org>2008-12-26 23:53:07 +0000
commit53679122af1e0a68bbe4e9c1f73526dd7e118df6 (patch)
treeb9fbdb2305fad7754de07a1e731285f63be3c4b9 /src/vehicle_base.h
parentb8d82cc28c8f133008fe3794b7b52b43593aa209 (diff)
downloadopenttd-53679122af1e0a68bbe4e9c1f73526dd7e118df6.tar.xz
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r--src/vehicle_base.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index d051f79d9..15f2df1aa 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -647,6 +647,28 @@ static inline bool IsValidVehicleID(uint index)
return index < GetVehiclePoolSize() && GetVehicle(index)->IsValid();
}
+
+/** Generates sequence of free UnitID numbers */
+struct FreeUnitIDGenerator {
+ bool *cache; ///< array of occupied unit id numbers
+ UnitID maxid; ///< maximum ID at the moment of constructor call
+ UnitID curid; ///< last ID returned ; 0 if none
+
+ /** Initializes the structure. Vehicle unit numbers are supposed not to change after
+ * struct initialization, except after each call to this->NextID() the returned value
+ * is assigned to a vehicle.
+ * @param type type of vehicle
+ * @param owner owner of vehicles
+ */
+ FreeUnitIDGenerator(VehicleType type, CompanyID owner);
+
+ /** Returns next free UnitID. Supposes the last returned value was assigned to a vehicle. */
+ UnitID NextID();
+
+ /** Releases allocated memory */
+ ~FreeUnitIDGenerator() { free(this->cache); }
+};
+
/* Returns order 'index' of a vehicle or NULL when it doesn't exists */
static inline Order *GetVehicleOrder(const Vehicle *v, int index)
{