OpenTTD Source: src/newgrf_class.h Source File

OpenTTD Source 12.2

newgrf_class.h
Go to the documentation of this file.
1 /*
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/>.
6 */
7
10 #ifndef NEWGRF_CLASS_H
11 #define NEWGRF_CLASS_H
12
13 #include "strings_type.h"
14
18 template <typename Tspec, typename Tid, Tid Tmax>
19 struct NewGRFClass {
20 private:
21 uint count;
22 uint ui_count;
23 Tspec **spec;
24
30 static NewGRFClass<Tspec, Tid, Tmax> classes[Tmax];
31
32 void ResetClass();
33
35 static void InsertDefaults();
36
37 public:
38 uint32 global_id;
39 StringID name;
40
41 void Insert(Tspec *spec);
42
44 uint GetSpecCount() const { return this->count; }
46 uint GetUISpecCount() const { return this->ui_count; }
47 int GetUIFromIndex(int index) const;
48 int GetIndexFromUI(int ui_index) const;
49
50 const Tspec *GetSpec(uint index) const;
51
53 bool IsUIAvailable(uint index) const;
54
55 static void Reset();
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);
62
63 static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
64 };
65
66 #endif /* NEWGRF_CLASS_H */
NewGRFClass::GetUISpecCount
uint GetUISpecCount() const
Get the number of potentially user-available specs within the class.
Definition: newgrf_class.h:46
NewGRFClass::GetSpecCount
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition: newgrf_class.h:44
strings_type.h
NewGRFClass::IsUIAvailable
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
Definition: newgrf_airport.cpp:79
NewGRFClass::global_id
uint32 global_id
Global ID for class, e.g. 'DFLT', 'WAYP', etc.
Definition: newgrf_class.h:38
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
NewGRFClass::count
uint count
Number of specs in this class.
Definition: newgrf_class.h:21
NewGRFClass::ui_count
uint ui_count
Number of specs in this class potentially available to the user.
Definition: newgrf_class.h:22
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition: newgrf_airport.cpp:70
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NewGRFClass::name
StringID name
Name of this class.
Definition: newgrf_class.h:39
NewGRFClass::classes
static NewGRFClass< Tspec, Tid, Tmax > classes[Tmax]
The actual classes.
Definition: newgrf_class.h:30
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:103
NewGRFClass::spec
Tspec ** spec
Array of specifications.
Definition: newgrf_class.h:23