# newgrf_class.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef NEWGRF_CLASS_H
    00013 #define NEWGRF_CLASS_H
    00014
    00015 #include "strings_type.h"
    00016
    00020 template <typename Tspec, typename Tid, Tid Tmax>
    00021 struct NewGRFClass {
    00022 private:
    00023   uint count;
    00024   uint ui_count;
    00025   Tspec **spec;
    00026
    00032   static NewGRFClass<Tspec, Tid, Tmax> classes[Tmax];
    00033
    00034   void ResetClass();
    00035
    00037   static void InsertDefaults();
    00038
    00039 public:
    00040   uint32 global_id;
    00041   StringID name;
    00042
    00043   void Insert(Tspec *spec);
    00044
    00046   uint GetSpecCount() const { return this->count; }
    00048   uint GetUISpecCount() const { return this->ui_count; }
    00049   int GetUIFromIndex(int index) const;
    00050   int GetIndexFromUI(int ui_index) const;
    00051
    00052   const Tspec *GetSpec(uint index) const;
    00053
    00055   bool IsUIAvailable(uint index) const;
    00056
    00057   static void Reset();
    00058   static Tid Allocate(uint32 global_id);
    00059   static void Assign(Tspec *spec);
    00060   static uint GetClassCount();
    00061   static uint GetUIClassCount();
    00062   static Tid GetUIClass(uint index);
    00063   static NewGRFClass *Get(Tid cls_id);
    00064
    00065   static const Tspec *GetByGrf(uint32 grfid, byte local_id, int *index);
    00066 };
    00067
    00068 #endif /* NEWGRF_CLASS_H */