ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_range.C
Revision: 1.39
Committed: Mon Oct 12 14:00:59 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81
Changes since 1.38: +7 -6 lines
Log Message:
clarify license

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.29 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.27 *
4 root 1.34 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.27 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7     *
8 root 1.39 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 root 1.27 *
13 root 1.28 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 root 1.27 *
18 root 1.39 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.27 *
22 root 1.29 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.15 */
24 elmex 1.1
25     /* This file deals with range related commands (casting, shooting,
26     * throwing, etc.
27     */
28    
29     #include <global.h>
30 root 1.13 #include <sproto.h>
31 elmex 1.1 #include <spells.h>
32     #include <skills.h>
33     #include <commands.h>
34    
35 root 1.5 int
36     command_invoke (object *op, char *params)
37 elmex 1.1 {
38 root 1.5 return command_cast_spell (op, params, 'i');
39 elmex 1.1 }
40    
41 root 1.5 int
42     command_cast (object *op, char *params)
43 elmex 1.1 {
44 root 1.5 return command_cast_spell (op, params, 'c');
45 elmex 1.1 }
46    
47 root 1.5 int
48     command_prepare (object *op, char *params)
49 elmex 1.1 {
50 root 1.5 return command_cast_spell (op, params, 'p');
51 elmex 1.1 }
52    
53     /* Shows all spells that op knows. If params is supplied, the must match
54     * that. Given there is more than one skill, we can't supply break
55     * them down to cleric/wizardry.
56     */
57 root 1.5 static void
58     show_matching_spells (object *op, char *params)
59 elmex 1.1 {
60 root 1.5 object *spell;
61     char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp;
62     int num_found = 0, i;
63    
64     /* We go and see what spells the player has. We put them
65     * into the spell_sort array so that we can sort them -
66     * we prefix the skill in the name so that the sorting
67     * works better.
68     */
69 root 1.19 for (spell = op->inv; spell; spell = spell->below)
70 root 1.5 {
71     /* If it is a spell, and no params are passed, or they
72     * match the name, process this spell.
73     */
74     if (spell->type == SPELL && (!params || !strncmp (params, spell->name, strlen (params))))
75     {
76     if (spell->path_attuned & op->path_denied)
77     {
78     sprintf (spell_sort[num_found++], "%s:%-22s %3s %3s", spell->skill ? &spell->skill : "generic", &spell->name, "den", "den");
79     }
80     else
81     {
82     sprintf (spell_sort[num_found++],
83     "%s:%-22s %3d %3d", spell->skill ? &spell->skill : "generic",
84     &spell->name, spell->level, SP_level_spellpoint_cost (op, spell, SPELL_HIGHEST));
85 root 1.2 }
86     }
87 elmex 1.1 }
88 root 1.19
89 root 1.5 if (!num_found)
90     {
91     /* If a matching string was passed along, now try it without that
92     * string. It is odd to do something like 'cast trans',
93     * and it say you have no spells, when really, you do, but just
94     * nothing that matches.
95     */
96     if (params)
97     show_matching_spells (op, NULL);
98     else
99     new_draw_info (NDI_UNIQUE, 0, op, "You know no spells");
100     }
101     else
102     {
103     /* Note in the code below that we make some
104     * presumptions that there will be a colon in the
105     * string. given the code above, this is always
106     * the case.
107     */
108 root 1.16 qsort (spell_sort, num_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp);
109 root 1.5 strcpy (tmp, "asdfg"); /* Dummy string so initial compare fails */
110     for (i = 0; i < num_found; i++)
111     {
112     /* Different skill name, so print banner */
113     if (strncmp (tmp, spell_sort[i], strlen (tmp)))
114     {
115     strcpy (tmp, spell_sort[i]);
116     cp = strchr (tmp, ':');
117     *cp = '\0';
118     new_draw_info (NDI_UNIQUE, 0, op, "");
119     new_draw_info_format (NDI_UNIQUE, 0, op, "%s spells %.*s [lvl] [sp]", tmp, 12 - strlen (tmp), " ");
120 root 1.2 }
121 root 1.5 new_draw_info (NDI_UNIQUE, 0, op, strchr (spell_sort[i], ':') + 1);
122 root 1.2 }
123 elmex 1.1 }
124     }
125    
126     /* sets up to cast a spell. op is the caster, params is the spell name,
127     * and command is the first letter of the spell type (c=cast, i=invoke,
128     * p=prepare). Invoke casts a spell immediately, where as cast (and I believe
129     * prepare) just set up the range type.
130     */
131 root 1.5 int
132     command_cast_spell (object *op, char *params, char command)
133 elmex 1.1 {
134 root 1.5 int castnow = 0;
135     char *cp;
136     object *spob;
137    
138     if (command == 'i')
139     castnow = 1;
140    
141     /* Remove control of the golem */
142 root 1.20 if (object *golem = op->contr->golem)
143 root 1.38 golem->drop_and_destroy ();
144 elmex 1.1
145 root 1.18 if (params)
146 root 1.5 {
147     int spellnumber = 0;
148    
149     if ((spellnumber = atoi (params)))
150 root 1.9 for (spob = op->inv; spob && spob->count != spellnumber; spob = spob->below)
151 root 1.6 /* nop */;
152 root 1.5 else
153     spob = lookup_spell_by_name (op, params);
154    
155     if (spob && spob->type == SPELL)
156     {
157     /* Now grab any extra data, if there is any. Forward pass
158     * any 'of' delimiter
159     */
160     if (spellnumber)
161     {
162     /* if we passed a number, the options start at the second word */
163     cp = strchr (params, ' ');
164     if (cp)
165     {
166     cp++;
167     if (!strncmp (cp, "of ", 3))
168     cp += 3;
169 root 1.2 }
170     }
171 root 1.20 else if (strlen (params) > strlen (spob->name))
172 root 1.5 {
173     cp = params + strlen (spob->name);
174     *cp = 0;
175     cp++;
176     if (!strncmp (cp, "of ", 3))
177     cp += 3;
178 root 1.2 }
179 root 1.5 else
180     cp = NULL;
181    
182 root 1.20 if (!spob->skill)
183     {
184     new_draw_info_format (NDI_UNIQUE, 0, op, "%s is a weird spell, please report it to the dungeon master!", &spob->name);
185     LOG (llevError, "spell without skill found: %s", spob->debug_desc ());
186     return 1;
187     }
188    
189     object *skill = find_skill_by_name (op, spob->skill);
190    
191     if (!skill)
192 root 1.5 {
193 root 1.31 op->failmsg (format ("You need the skill %s to cast %s!", &spob->skill, &spob->name));
194 root 1.5 return 1;
195     }
196    
197 root 1.32 splay (spob);
198    
199 root 1.5 if (castnow)
200 root 1.6 cast_spell (op, op, op->facing, spob, cp);
201 root 1.5 else
202     {
203 root 1.33 if (op->contr->ranged_ob)
204     if (op->contr->ranged_ob->flag [FLAG_APPLIED])
205     apply_special (op, op->contr->ranged_ob, AP_UNAPPLY);
206     else
207     op->contr->ranged_ob = 0;
208 root 1.30
209 root 1.31 if (op->contr->ranged_ob)
210     op->failmsg (format ("You have to unapply the %s first to ready a spell.", &op->contr->ranged_ob->name));
211     else
212     {
213     op->change_weapon (op->contr->ranged_ob = spob);
214    
215     assign (op->contr->spellparam, cp ? cp : "");
216     op->statusmsg (format ("You ready the spell %s", &spob->name));
217     }
218 root 1.2 }
219 root 1.6
220 root 1.5 return 0;
221     } /* else fall through to below and print spells */
222     } /* params supplied */
223    
224     /* We get here if cast was given without options or we could not find
225     * the requested spell. List all the spells the player knows.
226     */
227 root 1.22 new_draw_info (NDI_UNIQUE, 0, op, "Cast what spell? Choose one of:");
228 root 1.5 show_matching_spells (op, params);
229 root 1.22
230 root 1.5 return 1;
231 elmex 1.1 }
232    
233     /**************************************************************************/
234    
235 root 1.5 void
236     change_spell (object *op, char k)
237     {
238 root 1.23 if (op->contr->combat_ob == op->current_weapon)
239     {
240     if (op->contr->ranged_ob)
241 root 1.25 op->change_weapon (op->contr->ranged_ob);
242 root 1.23 }
243     else if (op->contr->ranged_ob == op->current_weapon)
244     {
245     if (op->contr->combat_ob)
246 root 1.25 op->change_weapon (op->contr->combat_ob);
247 root 1.23 }
248    
249 root 1.20 //TODO: maybe switch to golem, if any?
250 elmex 1.1 }
251    
252 root 1.5 int
253     command_rotateshoottype (object *op, char *params)
254 elmex 1.1 {
255     if (!params)
256 root 1.5 change_spell (op, '+');
257 elmex 1.1 else
258 root 1.5 change_spell (op, params[0]);
259 root 1.19
260 elmex 1.1 return 0;
261     }