Constificiation.
[gemrb.git] / gemrb / core / GameData.h
blob125b630098e16fb7be21c8d8d042cfe682254ad4
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef GAMEDATA_H
22 #define GAMEDATA_H
24 #include "exports.h"
25 #include "SClassID.h"
26 #include "ie_types.h"
27 #include "Cache.h"
28 #include "ResourceManager.h"
29 #include "Holder.h"
31 class TableMgr;
32 class Palette;
33 class Item;
34 class Spell;
35 struct Effect;
36 class ScriptedAnimation;
37 class Factory;
38 class Actor;
39 class Sprite2D;
41 struct Table {
42 Holder<TableMgr> tm;
43 char ResRef[8];
44 unsigned int refcount;
47 class GEM_EXPORT GameData : public ResourceManager
49 public:
50 GameData();
51 ~GameData();
53 void ClearCaches();
55 /** Returns actor */
56 Actor *GetCreature(const char *ResRef, unsigned int PartySlot=0);
57 /** Returns a PC index, by loading a creature */
58 int LoadCreature(const char *ResRef, unsigned int PartySlot, bool character=false);
61 // 2DA table functions.
62 // (See also the AutoTable class)
64 /** Loads a 2DA Table, returns -1 on error or the Table Index on success */
65 int LoadTable(const char * ResRef);
66 /** Gets the index of a loaded table, returns -1 on error */
67 int GetTableIndex(const char * ResRef) const;
68 /** Gets a Loaded Table by its index, returns NULL on error */
69 Holder<TableMgr> GetTable(unsigned int index) const;
70 /** Frees a Loaded Table, returns false on error, true on success */
71 bool DelTable(unsigned int index);
73 Palette* GetPalette(const ieResRef resname);
74 void FreePalette(Palette *&pal, const ieResRef name=NULL);
76 Item* GetItem(const ieResRef resname);
77 void FreeItem(Item const *itm, const ieResRef name, bool free=false);
78 Spell* GetSpell(const ieResRef resname, bool silent=false);
79 void FreeSpell(Spell *spl, const ieResRef name, bool free=false);
80 Effect* GetEffect(const ieResRef resname);
81 void FreeEffect(Effect *eff, const ieResRef name, bool free=false);
83 /** creates a vvc/bam animation object at point */
84 ScriptedAnimation* GetScriptedAnimation( const char *ResRef, bool doublehint);
86 /** returns a single sprite (not cached) from a BAM resource */
87 Sprite2D* GetBAMSprite(const ieResRef ResRef, int cycle, int frame);
89 /** returns factory resource, currently works only with animations */
90 void* GetFactoryResource(const char* resname, SClass_ID type,
91 unsigned char mode = IE_NORMAL, bool silent=false);
92 private:
93 Cache ItemCache;
94 Cache SpellCache;
95 Cache EffectCache;
96 Cache PaletteCache;
97 Factory* factory;
98 std::vector<Table> tables;
101 extern GEM_EXPORT GameData * gamedata;
103 template <class T>
104 class ResourceHolder : public Holder<T>
106 public:
107 ResourceHolder()
110 ResourceHolder(const char* resname)
111 : Holder<T>(static_cast<T*>(gamedata->GetResource(resname,&T::ID)))
114 ResourceHolder(const char* resname, const ResourceManager& manager, bool silent = false)
115 : Holder<T>(static_cast<T*>(manager.GetResource(resname,&T::ID,silent)))
120 #endif