13template <
typename Tspec,
typename Tindex, Tindex Tmax>
29template <
typename Tspec,
typename Tindex, Tindex Tmax>
44 GrfMsg(2,
"ClassAllocate: already allocated {} classes, using default", Tmax);
45 return static_cast<Tindex
>(0);
52template <
typename Tspec,
typename Tindex, Tindex Tmax>
55 auto it = this->spec.insert(std::end(this->spec), spec);
56 uint16_t index =
static_cast<uint16_t
>(std::distance(std::begin(this->spec), it));
57 if (spec !=
nullptr) (*it)->index = index;
59 if (this->IsUIAvailable(index)) this->ui_count++;
67template <
typename Tspec,
typename Tindex, Tindex Tmax>
71 Get(spec->class_index)->Insert(spec);
79template <
typename Tspec,
typename Tindex, Tindex Tmax>
90template <
typename Tspec,
typename Tindex, Tindex Tmax>
100template <
typename Tspec,
typename Tindex, Tindex Tmax>
103 return std::ranges::count_if(
NewGRFClass::classes, [](
const auto &cls) {
return cls.GetUISpecCount() > 0; });
111template <
typename Tspec,
typename Tindex, Tindex Tmax>
115 return index < this->GetSpecCount() ? this->spec[index] :
nullptr;
125template <
typename Tspec,
typename Tindex, Tindex Tmax>
129 for (
const auto &spec : cls.spec) {
130 if (spec ==
nullptr)
continue;
131 if (spec->grf_prop.local_id != local_id)
continue;
132 if (spec->grf_prop.grfid == grfid)
return spec;
Struct containing information relating to NewGRF classes for stations and airports.
static void Assign(Tspec *spec)
Assign a spec to one of the classes.
void Insert(Tspec *spec)
Insert a spec into the class, and update its index.
uint32_t global_id
Global ID for class, e.g. 'DFLT', 'WAYP', etc.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
static uint GetUIClassCount()
Get the number of classes available to the user.
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
static const Tspec * GetByGrf(uint32_t grfid, uint16_t local_id)
Retrieve a spec by GRF location.
static uint GetClassCount()
Get the number of allocated classes.
static void InsertDefaults()
Initialise the defaults.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static std::vector< NewGRFClass< Tspec, Tindex, Tmax > > classes
The actual classes.
static void Reset()
Reset the classes, i.e.
Header file for classes to be used by e.g.