14 #include "table/strings.h" 20 #define DEFINE_NEWGRF_CLASS_METHOD(type) \ 21 template <typename Tspec, typename Tid, Tid Tmax> \ 22 type NewGRFClass<Tspec, Tid, Tmax> 25 template <
typename Tspec,
typename T
id, T
id Tmax>
32 this->name = STR_EMPTY;
43 for (Tid i = (Tid)0; i < Tmax; i++) {
44 classes[i].ResetClass();
59 for (Tid i = (Tid)0; i < Tmax; i++) {
60 if (classes[i].global_id == global_id) {
63 }
else if (classes[i].global_id == 0) {
65 classes[i].global_id = global_id;
70 grfmsg(2,
"ClassAllocate: already allocated %d classes, using default", Tmax);
80 uint i = this->count++;
81 this->spec =
ReallocT(this->spec, this->count);
85 if (this->IsUIAvailable(i)) this->ui_count++;
95 assert(spec->cls_id < Tmax);
96 Get(spec->cls_id)->Insert(spec);
104 template <
typename Tspec,
typename T
id, T
id Tmax>
107 assert(cls_id < Tmax);
108 return classes + cls_id;
118 for (i = 0; i < Tmax && classes[i].global_id != 0; i++) {}
129 for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) {
130 if (classes[i].GetUISpecCount() > 0) cnt++;
142 for (uint i = 0; i < Tmax && classes[i].global_id != 0; i++) {
143 if (classes[i].GetUISpecCount() == 0)
continue;
144 if (index-- == 0)
return (Tid)i;
157 return index < this->GetSpecCount() ? this->spec[index] : NULL;
167 if (ui_index < 0)
return -1;
168 for (uint i = 0; i < this->GetSpecCount(); i++) {
169 if (!this->IsUIAvailable(i))
continue;
170 if (ui_index-- == 0)
return i;
182 if ((uint)index >= this->GetSpecCount())
return -1;
184 for (
int i = 0; i < index; i++) {
185 if (this->IsUIAvailable(i)) ui_index++;
201 for (Tid i = (Tid)0; i < Tmax; i++) {
202 for (j = 0; j < classes[i].count; j++) {
203 const Tspec *spec = classes[i].spec[j];
204 if (spec == NULL)
continue;
205 if (spec->grf_prop.grffile->grfid == grfid && spec->grf_prop.local_id == local_id) {
206 if (index != NULL) *index = j;
215 #undef DEFINE_NEWGRF_CLASS_METHOD 218 #define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax) \ 219 template void name::ResetClass(); \ 220 template void name::Reset(); \ 221 template Tid name::Allocate(uint32 global_id); \ 222 template void name::Insert(Tspec *spec); \ 223 template void name::Assign(Tspec *spec); \ 224 template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \ 225 template uint name::GetClassCount(); \ 226 template uint name::GetUIClassCount(); \ 227 template Tid name::GetUIClass(uint index); \ 228 template const Tspec *name::GetSpec(uint index) const; \ 229 template int name::GetUIFromIndex(int index) const; \ 230 template int name::GetIndexFromUI(int ui_index) const; \ 231 template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index); #define DEFINE_NEWGRF_CLASS_METHOD(type)
Helper for defining the class method's signatures.
Struct containing information relating to NewGRF classes for stations and airports.
static T * ReallocT(T *t_ptr, size_t num_elements)
Simplified reallocation function that allocates the specified number of elements of the given type...
Header file for classes to be used by e.g.
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.