* Get an unused unit number for a vehicle (if allowed). * @param type Type of vehicle * @return A unused unit number for the given type of vehicle if it is allowed to build one, else \c UINT16_MAX. */
| 1874 | * @return A unused unit number for the given type of vehicle if it is allowed to build one, else \c UINT16_MAX. |
| 1875 | */ |
| 1876 | UnitID GetFreeUnitNumber(VehicleType type) |
| 1877 | { |
| 1878 | /* Check whether it is allowed to build another vehicle. */ |
| 1879 | uint max_veh; |
| 1880 | switch (type) { |
| 1881 | case VEH_TRAIN: max_veh = _settings_game.vehicle.max_trains; break; |
| 1882 | case VEH_ROAD: max_veh = _settings_game.vehicle.max_roadveh; break; |
| 1883 | case VEH_SHIP: max_veh = _settings_game.vehicle.max_ships; break; |
| 1884 | case VEH_AIRCRAFT: max_veh = _settings_game.vehicle.max_aircraft; break; |
| 1885 | default: NOT_REACHED(); |
| 1886 | } |
| 1887 | |
| 1888 | const Company *c = Company::Get(_current_company); |
| 1889 | if (c->group_all[type].num_vehicle >= max_veh) return UINT16_MAX; // Currently already at the limit, no room to make a new one. |
| 1890 | |
| 1891 | return c->freeunits[type].NextID(); |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | /** |
no test coverage detected