(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID

This commit is contained in:
smatz
2008-12-26 23:53:07 +00:00
parent f183e1c6cf
commit 9c2c1dea06
3 changed files with 60 additions and 60 deletions

View File

@@ -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)
{