1 /*
2  * nazghul - an old-school RPG engine
3  * Copyright (C) 2004 Gordon McNutt
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17  * Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Gordon McNutt
20  * gmcnutt@users.sourceforge.net
21  *
22  */
23 
24 #ifndef magic_h
25 #define magic_h
26 
27 #include "object.h" /* for ObjectType */
28 #include "macros.h"
29 
30 BEGIN_DECL
31 
32 /* The number of spell words or "syllables" is limited to the number of letters
33  * in the English alphabet. That's because the first letter of each syllable
34  * uniquely identifies it. */
35 #define MAX_SPELL_WORDS 26
36 
37 /* The max number of reagents allowed in the mixture for a spell. */
38 #define MAX_MIX_REAGENTS 8
39 
40 /* Arbitrary limit on the number of characters (not syllables!) in a full spell
41  * name */
42 #define MAX_SPELL_NAME_LENGTH 64
43 
44 /* Arbitrary limit on the number of syllables in a spell name. */
45 #define MAX_SYLLABLES_PER_SPELL 8
46 
47 /* Spells are stored in a tree indexed by their "code". The code is the first
48  * letter of each word in the spell. For example, An Nox has the code AN. I
49  * also store the mixture here with the associated spell. For cimplicity I
50  * hard-code the max number of reagents permitted in a spell. */
51 struct spell {
52         ObjectType *type;
53         char *code;
54         int level;
55         int cost;
56         int context;
57         int action_points;
58         int n_reagents;
59         ObjectType *reagents[MAX_MIX_REAGENTS];
60         struct sprite *sprite;
61         struct spell *left;
62         struct spell *right;
63 };
64 
65 /* One of these is embedded in the global session structure. It manages all the
66  * magic-related information related to a session. */
67 struct magic {
68         char *words[MAX_SPELL_WORDS];
69         struct spell *spells;
70 };
71 
72 /* Initialize before loading a new session */
73 extern void magic_init(struct magic *);
74 
75 /* Cleanup at end-of-session */
76 extern void magic_end_session(struct magic *);
77 
78 /* Add a spell during session load. Returns the newly added spell or NULL on
79  * error. */
80 extern struct spell *magic_add_spell(struct magic *, char *code);
81 
82 /* Add a word during session load. Returns 0 on success or -1 on error. */
83 extern int magic_add_word(struct magic *, char *word);
84 
85 /* Lookup a word based on its first letter. Returns NULL on error or if no such
86  * word exists, otherwise the desired word. */
87 extern char *magic_lookup_word(struct magic *magic, char first_letter);
88 
89 /* Lookup spells when casting them during play */
90 extern struct spell *magic_lookup_spell(struct magic *, char *code);
91 
92 /* Add another reagent to a spell mixture during session load. */
93 extern int spell_add_reagent(struct spell *spell, ObjectType *reagent);
94 
95 /* Given a spell code like "VF" convert it to a full name like "Vas Flam" */
96 extern int magic_spell_code_to_name(struct magic *magic, char *buf, int len, char *code);
97 
98 /* Opposite of magic_spell_code_to_name() */
99 extern int magic_spell_name_to_code(struct magic *magic, char *buf, int len, const char *name);
100 
101 
102 END_DECL
103 
104 #endif
105