1 /**
2  ** Spellbook.h - Spellbook object.
3  **
4  ** Written: 10/1/98 - JSF
5  **/
6 
7 /*
8 Copyright (C) 2000-2013 The Exult Team.
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24 
25 #ifndef INCL_SPELLBOOK
26 #define INCL_SPELLBOOK  1
27 
28 #include "iregobjs.h"
29 
30 const int NREAGENTS = 11;       // Total # reagents.
31 
32 /*
33  *  A spellbook:
34  */
35 class Spellbook_object : public Ireg_game_object {
36 	// Reagents needed for each spell:
37 	static unsigned short bg_reagents[9 * 8], si_reagents[9 * 8];
38 	unsigned short *reagents;   // ->appropriate table.
39 	unsigned char circles[9];   // Spell-present flags for each circle.
40 	int bookmark;           // Spell # that bookmark is on, or -1.
41 public:
42 	friend class Bookmark_button;
43 	friend class Spellbook_gump;
44 	// Create from ireg. data.
45 	Spellbook_object(int shapenum, int framenum, unsigned int shapex,
46 	                 unsigned int shapey, unsigned int lft, unsigned char *c,
47 	                 unsigned char bmark);
as_spellbook()48 	Spellbook_object *as_spellbook() override {
49 		return this;
50 	}
has_spell(int spell)51 	bool has_spell(int spell) {  // Has a spell.
52 		int circle = spell / 8;
53 		int num = spell % 8;    // # within circle.
54 		return (circles[circle] & (1 << num)) != 0;
55 	}
56 	int add_spell(int spell);   // Add a spell.
57 	int remove_spell(int spell);    // Remove a spell.
58 	void clear_spells();    // Empties spellbook.
59 	bool has_ring(Actor *act);  // Has ring-o-reagents?
60 	// Can we do this spell?
61 	bool can_do_spell(Actor *act, int spell);
can_do_spell(Actor * act)62 	bool can_do_spell(Actor *act) { // Can we do bookmarked spell?
63 		return bookmark >= 0 ? can_do_spell(act, bookmark) : false;
64 	}
65 	// Do the spell.
66 	bool do_spell(Actor *act, int spell, bool can_do = false,
67 	              bool in_combat = false);
68 	// Do bookmarked spell.
69 	bool do_spell(Actor *act, bool in_combat = false) {
70 		return bookmark >= 0 ?
71 		       do_spell(act, bookmark, false, in_combat) : false;
72 	}
73 	static void execute_spell(Actor *act, int spell,
74 	                          bool in_combat = false);
75 	// Run usecode function.
76 	void activate(int event = 1) override;
77 	// Write out to IREG file.
78 	void write_ireg(ODataSource *out) override;
79 	// Get size of IREG.
80 	// Returns -1 if can't write to buffer
81 	int get_ireg_size() override;
82 };
83 
84 #endif
85