Control: Change controls to use new callback infrastrucure.
[gemrb.git] / gemrb / core / Spellbook.h
blob63156102ddf9b3159e6d0b0e3b1ebf4f254919cc
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 /**
22 * @file Spellbook.h
23 * Declares Spellbook, class implementing creature's spellbook
24 * and (maybe) spell management
25 * @author The GemRB Project
28 #ifndef SPELLBOOK_H
29 #define SPELLBOOK_H
31 #include "exports.h"
32 #include "ie_types.h"
33 #include "win32def.h"
35 #include <vector>
37 class Actor;
38 class Spell;
40 #define MAX_SPELL_LEVEL 16
42 //HaveSpell flags
43 #define HS_DEPLETE 1
45 //LearnSpell flags
46 #define LS_ADDXP 1 //give xp for learning it
47 #define LS_LEARN 2 //give message when learned it
48 #define LS_STATS 4 //check stats (alignment, etc)
49 #define LS_MEMO 8 //memorize it instantly (add innate)
51 //LearnSpell return values
52 #define LSR_OK 0
53 #define LSR_KNOWN 1 //already knows
54 #define LSR_INVALID 2 //invalid resref
55 #define LSR_FAILED 3 //failed stat roll
56 #define LSR_STAT 4 //insufficient stat (can't learn the spell due to low stat)
57 #define LSR_LEVEL 5 //insufficient level (low mage, etc level)
58 #define LSR_FULL 6 //can't learn more spells of this level (due to level)
60 // !!! Keep these synchronized with GUIDefines.py !!!
61 typedef enum ieSpellType {
62 IE_SPELL_TYPE_PRIEST = 0,
63 IE_SPELL_TYPE_WIZARD = 1,
64 IE_SPELL_TYPE_INNATE = 2,
65 IE_SPELL_TYPE_SONG = 3 //not in spellbook
66 } ieSpellType;
68 #define NUM_SPELLTYPES 3
70 typedef enum ieIWD2SpellType {
71 IE_IWD2_SPELL_BARD = 0,
72 IE_IWD2_SPELL_CLERIC = 1,
73 IE_IWD2_SPELL_DRUID = 2,
74 IE_IWD2_SPELL_PALADIN = 3,
75 IE_IWD2_SPELL_RANGER = 4,
76 IE_IWD2_SPELL_SORCEROR = 5,
77 IE_IWD2_SPELL_WIZARD = 6,
78 IE_IWD2_SPELL_DOMAIN = 7,
79 IE_IWD2_SPELL_INNATE = 8,
80 IE_IWD2_SPELL_SONG = 9,
81 IE_IWD2_SPELL_SHAPE = 10
82 } ieIWD2SPellType;
84 #define NUM_IWD2_SPELLTYPES 11
86 struct CREKnownSpell {
87 ieResRef SpellResRef;
88 ieWord Level;
89 ieWord Type;
92 struct CREMemorizedSpell {
93 ieResRef SpellResRef;
94 ieDword Flags;
97 struct CRESpellMemorization {
98 ieWord Level;
99 ieWord Number;
100 ieWord Number2;
101 ieWord Type;
103 std::vector<CREKnownSpell*> known_spells;
104 std::vector<CREMemorizedSpell*> memorized_spells;
107 struct SpellExtHeader {
108 ieDword level;
109 ieDword count;
110 ieDword type; //spelltype
111 ieDword headerindex;
112 ieDword slot;
113 //these come from the header
114 ieByte SpellForm;
115 ieResRef MemorisedIcon;
116 ieByte Target;
117 ieByte TargetNumber;
118 ieWord Range;
119 ieWord Projectile;
120 ieWord CastingTime;
121 //other data
122 ieResRef spellname;
123 ieDword strref; //the spell's name
127 * @class Spellbook
128 * Class implementing creature's spellbook and (maybe) spell management
131 class GEM_EXPORT Spellbook {
132 private:
133 std::vector<CRESpellMemorization*> *spells;
134 std::vector<SpellExtHeader*> spellinfo;
135 int sorcerer;
137 /** Sets spell from memorized as 'already-cast' */
138 bool DepleteSpell(CREMemorizedSpell* spl);
139 /** Depletes a sorcerer type spellpage by one */
140 void DepleteLevel(CRESpellMemorization* sm);
141 /** regenerates the spellinfo list */
142 void GenerateSpellInfo();
143 /** invalidates the spellinfo list */
144 void ClearSpellInfo();
145 /** looks up the spellinfo list for an element */
146 SpellExtHeader *FindSpellInfo(unsigned int level, unsigned int type, const ieResRef name);
147 /** removes all instances of a spell from a given page */
148 void RemoveMemorization(CRESpellMemorization* sm, const ieResRef ResRef);
149 /** adds a spell to the book, internal */
150 bool AddKnownSpell(CREKnownSpell *spl, int memo);
151 /** returns a CRESpellMemorization pointer */
152 CRESpellMemorization *GetSpellMemorization(unsigned int type, unsigned int level);
153 public:
154 Spellbook();
155 ~Spellbook();
156 static void InitializeSpellbook();
157 static void ReleaseMemory();
159 void FreeSpellPage(CRESpellMemorization* sm);
160 /** Check if the spell is memorised, optionally deplete it (casting) */
161 bool HaveSpell(const char *resref, ieDword flags);
162 bool HaveSpell(int spellid, ieDword flags);
163 /** Check if the spell is in the book */
164 bool KnowSpell(const char *resref);
165 bool KnowSpell(int spellid);
167 bool AddSpellMemorization(CRESpellMemorization* sm);
168 int GetTypes() const;
169 bool IsIWDSpellBook() const;
170 unsigned int GetSpellLevelCount(int type) const;
171 unsigned int GetTotalPageCount() const;
172 unsigned int GetTotalKnownSpellsCount() const;
173 unsigned int GetTotalMemorizedSpellsCount() const;
174 unsigned int GetKnownSpellsCount(int type, unsigned int level) const;
175 /** adds the priest slot bonuses from mxsplwis */
176 void BonusSpells(int type, int count, int *bonuses);
177 /** clears up the spell bonuses before recalculation */
178 void ClearBonus();
179 /** removes a spell from memory/book */
180 bool RemoveSpell(CREKnownSpell* spell);
181 /** this removes ALL spells of name ResRef */
182 void RemoveSpell(const ieResRef ResRef);
183 /** this removes ALL spells matching spellid */
184 void RemoveSpell(int spellid);
186 /** sets the book type */
187 void SetBookType(int clss);
188 /** returns the page number for the spelltype */
189 static int GetSpellType(int spelltype);
190 /** adds a spell to the book, returns experience if learned */
191 int LearnSpell(Spell *spell, int memo);
192 CREKnownSpell* GetKnownSpell(int type, unsigned int level, unsigned int index) const;
193 unsigned int GetMemorizedSpellsCount(int type) const;
194 unsigned int GetMemorizedSpellsCount(int type, unsigned int level) const;
195 CREMemorizedSpell* GetMemorizedSpell(int type, unsigned int level, unsigned int index) const;
197 int GetMemorizableSpellsCount(int type, unsigned int level, bool bonus) const;
198 void SetMemorizableSpellsCount(int Value, int type, unsigned int level, bool bonus);
200 /** Adds spell from known to memorized */
201 bool MemorizeSpell(CREKnownSpell* spl, bool usable);
203 /** Removes memorized spell */
204 bool UnmemorizeSpell(CREMemorizedSpell* spl);
206 /** finds the first spell needing to rememorize */
207 CREMemorizedSpell* FindUnchargedSpell(int type, int level=0);
209 /** Sets spell from memorized as 'not-yet-cast' */
210 bool ChargeSpell(CREMemorizedSpell* spl);
212 /** Sets spell from memorized as 'already-cast' */
213 bool DepleteSpell(int type, unsigned int page, unsigned int slot);
215 /** picks the highest spell of type and makes it 'already cast' */
216 bool DepleteSpell(int type);
218 /** recharges all spells */
219 void ChargeAllSpells();
221 /** creates sorcerer's selection of spells to memorise:
222 selects all spells as many times as the spell page allows */
223 void CreateSorcererMemory(int type);
225 /** returns the number of distinct spells (generates spellinfo) */
226 unsigned int GetSpellInfoSize(int type);
228 /** lists spells of a type */
229 bool GetSpellInfo(SpellExtHeader *array, int type, int startindex, int count);
230 /** Dumps spellbook to stdout for debugging */
231 void dump();
234 #endif