melee / ranged effects
[gemrb.git] / gemrb / core / Spellbook.h
blob3a65b775f02816a85d786867d3433c8822d1259f
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 /** Adds a new CRESpellMemorization, to the *end* only */
152 bool AddSpellMemorization(CRESpellMemorization* sm);
154 public:
155 Spellbook();
156 ~Spellbook();
157 static void InitializeSpellbook();
158 static void ReleaseMemory();
160 void FreeSpellPage(CRESpellMemorization* sm);
161 /** duplicates the source spellbook into the current one */
162 void CopyFrom(const Actor *source);
163 /** Check if the spell is memorised, optionally deplete it (casting) */
164 bool HaveSpell(const char *resref, ieDword flags);
165 bool HaveSpell(int spellid, ieDword flags);
166 /** Check if the spell is in the book */
167 bool KnowSpell(const char *resref);
168 bool KnowSpell(int spellid);
170 /** returns a CRESpellMemorization pointer */
171 CRESpellMemorization *GetSpellMemorization(unsigned int type, unsigned int level);
172 int GetTypes() const;
173 bool IsIWDSpellBook() const;
174 unsigned int GetSpellLevelCount(int type) const;
175 unsigned int GetTotalPageCount() const;
176 unsigned int GetTotalKnownSpellsCount() const;
177 unsigned int GetTotalMemorizedSpellsCount() const;
178 unsigned int GetKnownSpellsCount(int type, unsigned int level) const;
179 /** adds the priest slot bonuses from mxsplwis */
180 void BonusSpells(int type, int count, int *bonuses);
181 /** clears up the spell bonuses before recalculation */
182 void ClearBonus();
183 /** removes a spell from memory/book */
184 bool RemoveSpell(CREKnownSpell* spell);
185 /** this removes ALL spells of name ResRef */
186 void RemoveSpell(const ieResRef ResRef);
187 /** this removes ALL spells matching spellid */
188 void RemoveSpell(int spellid);
190 /** sets the book type */
191 void SetBookType(int clss);
192 /** returns the page number for the spelltype */
193 static int GetSpellType(int spelltype);
194 /** adds a spell to the book, returns experience if learned */
195 int LearnSpell(Spell *spell, int memo);
196 CREKnownSpell* GetKnownSpell(int type, unsigned int level, unsigned int index) const;
197 unsigned int GetMemorizedSpellsCount(int type) const;
198 unsigned int GetMemorizedSpellsCount(int type, unsigned int level) const;
199 CREMemorizedSpell* GetMemorizedSpell(int type, unsigned int level, unsigned int index) const;
201 int GetMemorizableSpellsCount(int type, unsigned int level, bool bonus) const;
202 void SetMemorizableSpellsCount(int Value, int type, unsigned int level, bool bonus);
204 /** Adds spell from known to memorized */
205 bool MemorizeSpell(CREKnownSpell* spl, bool usable);
207 /** Removes memorized spell */
208 bool UnmemorizeSpell(CREMemorizedSpell* spl);
210 /** Removes (or just depletes) memorized spell by ResRef */
211 bool UnmemorizeSpell(const char *resref, bool deplete);
213 /** finds the first spell needing to rememorize */
214 CREMemorizedSpell* FindUnchargedSpell(int type, int level=0);
216 /** Sets spell from memorized as 'not-yet-cast' */
217 bool ChargeSpell(CREMemorizedSpell* spl);
219 /** Sets spell from memorized as 'already-cast' */
220 bool DepleteSpell(int type, unsigned int page, unsigned int slot);
222 /** picks the highest spell of type and makes it 'already cast' */
223 bool DepleteSpell(int type);
225 /** recharges all spells */
226 void ChargeAllSpells();
228 /** creates sorcerer's selection of spells to memorise:
229 selects all spells as many times as the spell page allows */
230 void CreateSorcererMemory(int type);
232 /** returns the number of distinct spells (generates spellinfo) */
233 unsigned int GetSpellInfoSize(int type);
235 /** lists spells of a type */
236 bool GetSpellInfo(SpellExtHeader *array, int type, int startindex, int count);
237 /** Dumps spellbook to stdout for debugging */
238 void dump();
241 #endif