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.
23 * Declares Spellbook, class implementing creature's spellbook
24 * and (maybe) spell management
25 * @author The GemRB Project
40 #define MAX_SPELL_LEVEL 16
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
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
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
84 #define NUM_IWD2_SPELLTYPES 11
86 struct CREKnownSpell
{
92 struct CREMemorizedSpell
{
97 struct CRESpellMemorization
{
103 std::vector
<CREKnownSpell
*> known_spells
;
104 std::vector
<CREMemorizedSpell
*> memorized_spells
;
107 struct SpellExtHeader
{
110 ieDword type
; //spelltype
113 //these come from the header
115 ieResRef MemorisedIcon
;
123 ieDword strref
; //the spell's name
128 * Class implementing creature's spellbook and (maybe) spell management
131 class GEM_EXPORT Spellbook
{
133 std::vector
<CRESpellMemorization
*> *spells
;
134 std::vector
<SpellExtHeader
*> spellinfo
;
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
);
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 */
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 */