OpenTTD Source: FreeUnitIDGenerator Struct Reference

OpenTTD Source 1.11.0-RC1

Public Member Functions | Data Fields
FreeUnitIDGenerator Struct Reference

Generates sequence of free UnitID numbers. More...

`#include <vehicle_base.h>`

## Public Member Functions
| FreeUnitIDGenerator (VehicleType type, CompanyID owner)
| Initializes the structure. More...
UnitID | NextID ()
| Returns next free UnitID. More...
| ~FreeUnitIDGenerator ()
| Releases allocated memory.

## Data Fields
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

## Detailed Description

Generates sequence of free UnitID numbers.

Definition at line 1235 of file vehicle_base.h.

## Constructor & Destructor Documentation

## ◆ FreeUnitIDGenerator()

FreeUnitIDGenerator::FreeUnitIDGenerator | ( | VehicleType | type,
|  | CompanyID | owner
| ) |  |

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.

Parameters

  type | type of vehicle
  owner | owner of vehicles

Definition at line 1746 of file vehicle.cpp.

References cache, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), maxid, Vehicle::owner, BaseVehicle::type, and Vehicle::unitnumber.

## Member Function Documentation

## ◆ NextID()

UnitID FreeUnitIDGenerator::NextID | ( |  | ) |

Returns next free UnitID.

Supposes the last returned value was assigned to a vehicle.

Definition at line 1771 of file vehicle.cpp.

References cache, and curid.

The documentation for this struct was generated from the following files:

- src/vehicle_base.h
- src/vehicle.cpp