2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file newgrf_class.h Header file for classes to be used by e.g. NewGRF stations and airports */
10 #ifndef NEWGRF_CLASS_H
11 #define NEWGRF_CLASS_H
13 #include "strings_type.h"
16 * Struct containing information relating to NewGRF classes for stations and airports.
18 template <typename Tspec
, typename Tid
, Tid Tmax
>
21 uint count
; ///< Number of specs in this class.
22 uint ui_count
; ///< Number of specs in this class potentially available to the user.
23 Tspec
**spec
; ///< Array of specifications.
27 * @note We store pointers to membes of this array in various places outside this class (e.g. to 'name' for GRF string resolving).
28 * Thus this must be a static array, and cannot be a self-resizing SmallVector or similar.
30 static NewGRFClass
<Tspec
, Tid
, Tmax
> classes
[Tmax
];
34 /** Initialise the defaults. */
35 static void InsertDefaults();
38 uint32 global_id
; ///< Global ID for class, e.g. 'DFLT', 'WAYP', etc.
39 StringID name
; ///< Name of this class.
41 void Insert(Tspec
*spec
);
43 /** Get the number of allocated specs within the class. */
44 uint
GetSpecCount() const { return this->count
; }
45 /** Get the number of potentially user-available specs within the class. */
46 uint
GetUISpecCount() const { return this->ui_count
; }
47 int GetUIFromIndex(int index
) const;
48 int GetIndexFromUI(int ui_index
) const;
50 const Tspec
*GetSpec(uint index
) const;
52 /** Check whether the spec will be available to the user at some point in time. */
53 bool IsUIAvailable(uint index
) const;
56 static Tid
Allocate(uint32 global_id
);
57 static void Assign(Tspec
*spec
);
58 static uint
GetClassCount();
59 static uint
GetUIClassCount();
60 static Tid
GetUIClass(uint index
);
61 static NewGRFClass
*Get(Tid cls_id
);
63 static const Tspec
*GetByGrf(uint32 grfid
, byte local_id
, int *index
);
66 #endif /* NEWGRF_CLASS_H */