12 #include "table/strings.h"
18 #define DEFINE_NEWGRF_CLASS_METHOD(type) \
19 template <typename Tspec, typename Tid, Tid Tmax> \
20 type NewGRFClass<Tspec, Tid, Tmax>
23 template <
typename Tspec,
typename T
id, T
id Tmax>
30 this->name = STR_EMPTY;
39 for (Tid i = (Tid)0; i < Tmax; i++) {
40 classes[i].ResetClass();
55 for (Tid i = (Tid)0; i < Tmax; i++) {
56 if (classes[i].global_id == global_id) {
59 }
else if (classes[i].global_id == 0) {
61 classes[i].global_id = global_id;
66 GrfMsg(2,
"ClassAllocate: already allocated {} classes, using default", Tmax);
76 this->spec.push_back(spec);
78 if (this->IsUIAvailable(
static_cast<uint
>(this->spec.size() - 1))) this->ui_count++;
88 assert(spec->cls_id < Tmax);
89 Get(spec->cls_id)->Insert(spec);
97 template <
typename Tspec,
typename T
id, T
id Tmax>
100 assert(cls_id < Tmax);
101 return classes + cls_id;
111 for (i = 0; i < Tmax && classes[i].global_id != 0; i++) {}
122 for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) {
123 if (classes[i].GetUISpecCount() > 0) cnt++;
135 for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) {
136 if (classes[i].GetUISpecCount() == 0)
continue;
137 if (index-- == 0)
return (Tid)i;
150 return index < this->GetSpecCount() ? this->spec[index] :
nullptr;
160 if (ui_index < 0)
return -1;
161 for (uint i = 0; i < this->GetSpecCount(); i++) {
162 if (!this->IsUIAvailable(i))
continue;
163 if (ui_index-- == 0)
return i;
175 if ((uint)index >= this->GetSpecCount())
return -1;
177 for (
int i = 0; i < index; i++) {
178 if (this->IsUIAvailable(i)) ui_index++;
194 for (Tid i = (Tid)0; i < Tmax; i++) {
195 uint count =
static_cast<uint
>(classes[i].spec.size());
196 for (j = 0; j < count; j++) {
197 const Tspec *spec = classes[i].spec[j];
198 if (spec ==
nullptr)
continue;
199 if (spec->grf_prop.grffile->grfid == grfid && spec->grf_prop.local_id == local_id) {
200 if (index !=
nullptr) *index = j;
209 #undef DEFINE_NEWGRF_CLASS_METHOD
212 #define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax) \
213 template void name::ResetClass(); \
214 template void name::Reset(); \
215 template Tid name::Allocate(uint32_t global_id); \
216 template void name::Insert(Tspec *spec); \
217 template void name::Assign(Tspec *spec); \
218 template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
219 template uint name::GetClassCount(); \
220 template uint name::GetUIClassCount(); \
221 template Tid name::GetUIClass(uint index); \
222 template const Tspec *name::GetSpec(uint index) const; \
223 template int name::GetUIFromIndex(int index) const; \
224 template int name::GetIndexFromUI(int ui_index) const; \
225 template const Tspec *name::GetByGrf(uint32_t grfid, uint16_t local_id, int *index);