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.43 |
* Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.42 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
root |
1.27 |
* |
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 |
|
|
/* Shows all spells that op knows. If params is supplied, the must match |
36 |
|
|
* that. Given there is more than one skill, we can't supply break |
37 |
|
|
* them down to cleric/wizardry. |
38 |
|
|
*/ |
39 |
root |
1.5 |
static void |
40 |
|
|
show_matching_spells (object *op, char *params) |
41 |
elmex |
1.1 |
{ |
42 |
root |
1.5 |
object *spell; |
43 |
|
|
char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp; |
44 |
|
|
int num_found = 0, i; |
45 |
|
|
|
46 |
|
|
/* We go and see what spells the player has. We put them |
47 |
|
|
* into the spell_sort array so that we can sort them - |
48 |
|
|
* we prefix the skill in the name so that the sorting |
49 |
|
|
* works better. |
50 |
|
|
*/ |
51 |
root |
1.19 |
for (spell = op->inv; spell; spell = spell->below) |
52 |
root |
1.5 |
{ |
53 |
|
|
/* If it is a spell, and no params are passed, or they |
54 |
|
|
* match the name, process this spell. |
55 |
|
|
*/ |
56 |
|
|
if (spell->type == SPELL && (!params || !strncmp (params, spell->name, strlen (params)))) |
57 |
|
|
{ |
58 |
|
|
if (spell->path_attuned & op->path_denied) |
59 |
|
|
{ |
60 |
|
|
sprintf (spell_sort[num_found++], "%s:%-22s %3s %3s", spell->skill ? &spell->skill : "generic", &spell->name, "den", "den"); |
61 |
|
|
} |
62 |
|
|
else |
63 |
|
|
{ |
64 |
|
|
sprintf (spell_sort[num_found++], |
65 |
|
|
"%s:%-22s %3d %3d", spell->skill ? &spell->skill : "generic", |
66 |
|
|
&spell->name, spell->level, SP_level_spellpoint_cost (op, spell, SPELL_HIGHEST)); |
67 |
root |
1.2 |
} |
68 |
|
|
} |
69 |
elmex |
1.1 |
} |
70 |
root |
1.19 |
|
71 |
root |
1.5 |
if (!num_found) |
72 |
|
|
{ |
73 |
|
|
/* If a matching string was passed along, now try it without that |
74 |
|
|
* string. It is odd to do something like 'cast trans', |
75 |
|
|
* and it say you have no spells, when really, you do, but just |
76 |
|
|
* nothing that matches. |
77 |
|
|
*/ |
78 |
|
|
if (params) |
79 |
|
|
show_matching_spells (op, NULL); |
80 |
|
|
else |
81 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, "You know no spells"); |
82 |
|
|
} |
83 |
|
|
else |
84 |
|
|
{ |
85 |
|
|
/* Note in the code below that we make some |
86 |
|
|
* presumptions that there will be a colon in the |
87 |
|
|
* string. given the code above, this is always |
88 |
|
|
* the case. |
89 |
|
|
*/ |
90 |
root |
1.16 |
qsort (spell_sort, num_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp); |
91 |
root |
1.5 |
strcpy (tmp, "asdfg"); /* Dummy string so initial compare fails */ |
92 |
|
|
for (i = 0; i < num_found; i++) |
93 |
|
|
{ |
94 |
|
|
/* Different skill name, so print banner */ |
95 |
|
|
if (strncmp (tmp, spell_sort[i], strlen (tmp))) |
96 |
|
|
{ |
97 |
|
|
strcpy (tmp, spell_sort[i]); |
98 |
|
|
cp = strchr (tmp, ':'); |
99 |
|
|
*cp = '\0'; |
100 |
|
|
new_draw_info (NDI_UNIQUE, 0, op, ""); |
101 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "%s spells %.*s [lvl] [sp]", tmp, 12 - strlen (tmp), " "); |
102 |
root |
1.2 |
} |
103 |
root |
1.5 |
new_draw_info (NDI_UNIQUE, 0, op, strchr (spell_sort[i], ':') + 1); |
104 |
root |
1.2 |
} |
105 |
elmex |
1.1 |
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
/* sets up to cast a spell. op is the caster, params is the spell name, |
109 |
|
|
* and command is the first letter of the spell type (c=cast, i=invoke, |
110 |
|
|
* p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
111 |
|
|
* prepare) just set up the range type. |
112 |
|
|
*/ |
113 |
root |
1.41 |
static int |
114 |
root |
1.5 |
command_cast_spell (object *op, char *params, char command) |
115 |
elmex |
1.1 |
{ |
116 |
root |
1.5 |
int castnow = 0; |
117 |
|
|
char *cp; |
118 |
|
|
object *spob; |
119 |
|
|
|
120 |
|
|
if (command == 'i') |
121 |
|
|
castnow = 1; |
122 |
|
|
|
123 |
|
|
/* Remove control of the golem */ |
124 |
root |
1.20 |
if (object *golem = op->contr->golem) |
125 |
root |
1.38 |
golem->drop_and_destroy (); |
126 |
elmex |
1.1 |
|
127 |
root |
1.18 |
if (params) |
128 |
root |
1.5 |
{ |
129 |
|
|
int spellnumber = 0; |
130 |
|
|
|
131 |
|
|
if ((spellnumber = atoi (params))) |
132 |
root |
1.9 |
for (spob = op->inv; spob && spob->count != spellnumber; spob = spob->below) |
133 |
root |
1.6 |
/* nop */; |
134 |
root |
1.5 |
else |
135 |
|
|
spob = lookup_spell_by_name (op, params); |
136 |
|
|
|
137 |
|
|
if (spob && spob->type == SPELL) |
138 |
|
|
{ |
139 |
|
|
/* Now grab any extra data, if there is any. Forward pass |
140 |
|
|
* any 'of' delimiter |
141 |
|
|
*/ |
142 |
|
|
if (spellnumber) |
143 |
|
|
{ |
144 |
|
|
/* if we passed a number, the options start at the second word */ |
145 |
|
|
cp = strchr (params, ' '); |
146 |
|
|
if (cp) |
147 |
|
|
{ |
148 |
|
|
cp++; |
149 |
|
|
if (!strncmp (cp, "of ", 3)) |
150 |
|
|
cp += 3; |
151 |
root |
1.2 |
} |
152 |
|
|
} |
153 |
root |
1.20 |
else if (strlen (params) > strlen (spob->name)) |
154 |
root |
1.5 |
{ |
155 |
|
|
cp = params + strlen (spob->name); |
156 |
|
|
*cp = 0; |
157 |
|
|
cp++; |
158 |
|
|
if (!strncmp (cp, "of ", 3)) |
159 |
|
|
cp += 3; |
160 |
root |
1.2 |
} |
161 |
root |
1.5 |
else |
162 |
|
|
cp = NULL; |
163 |
|
|
|
164 |
root |
1.20 |
if (!spob->skill) |
165 |
|
|
{ |
166 |
|
|
new_draw_info_format (NDI_UNIQUE, 0, op, "%s is a weird spell, please report it to the dungeon master!", &spob->name); |
167 |
|
|
LOG (llevError, "spell without skill found: %s", spob->debug_desc ()); |
168 |
|
|
return 1; |
169 |
|
|
} |
170 |
|
|
|
171 |
|
|
object *skill = find_skill_by_name (op, spob->skill); |
172 |
|
|
|
173 |
|
|
if (!skill) |
174 |
root |
1.5 |
{ |
175 |
root |
1.31 |
op->failmsg (format ("You need the skill %s to cast %s!", &spob->skill, &spob->name)); |
176 |
root |
1.5 |
return 1; |
177 |
|
|
} |
178 |
|
|
|
179 |
root |
1.32 |
splay (spob); |
180 |
|
|
|
181 |
root |
1.5 |
if (castnow) |
182 |
root |
1.6 |
cast_spell (op, op, op->facing, spob, cp); |
183 |
root |
1.5 |
else |
184 |
|
|
{ |
185 |
root |
1.33 |
if (op->contr->ranged_ob) |
186 |
|
|
if (op->contr->ranged_ob->flag [FLAG_APPLIED]) |
187 |
|
|
apply_special (op, op->contr->ranged_ob, AP_UNAPPLY); |
188 |
|
|
else |
189 |
|
|
op->contr->ranged_ob = 0; |
190 |
root |
1.30 |
|
191 |
root |
1.31 |
if (op->contr->ranged_ob) |
192 |
|
|
op->failmsg (format ("You have to unapply the %s first to ready a spell.", &op->contr->ranged_ob->name)); |
193 |
|
|
else |
194 |
|
|
{ |
195 |
|
|
op->change_weapon (op->contr->ranged_ob = spob); |
196 |
|
|
|
197 |
|
|
assign (op->contr->spellparam, cp ? cp : ""); |
198 |
|
|
op->statusmsg (format ("You ready the spell %s", &spob->name)); |
199 |
|
|
} |
200 |
root |
1.2 |
} |
201 |
root |
1.6 |
|
202 |
root |
1.5 |
return 0; |
203 |
|
|
} /* else fall through to below and print spells */ |
204 |
|
|
} /* params supplied */ |
205 |
|
|
|
206 |
|
|
/* We get here if cast was given without options or we could not find |
207 |
|
|
* the requested spell. List all the spells the player knows. |
208 |
|
|
*/ |
209 |
root |
1.22 |
new_draw_info (NDI_UNIQUE, 0, op, "Cast what spell? Choose one of:"); |
210 |
root |
1.5 |
show_matching_spells (op, params); |
211 |
root |
1.22 |
|
212 |
root |
1.5 |
return 1; |
213 |
elmex |
1.1 |
} |
214 |
|
|
|
215 |
root |
1.40 |
int |
216 |
|
|
command_invoke (object *op, char *params) |
217 |
|
|
{ |
218 |
|
|
return command_cast_spell (op, params, 'i'); |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
int |
222 |
|
|
command_cast (object *op, char *params) |
223 |
|
|
{ |
224 |
|
|
return command_cast_spell (op, params, 'c'); |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
int |
228 |
|
|
command_prepare (object *op, char *params) |
229 |
|
|
{ |
230 |
|
|
return command_cast_spell (op, params, 'p'); |
231 |
|
|
} |
232 |
|
|
|
233 |
elmex |
1.1 |
/**************************************************************************/ |
234 |
|
|
|
235 |
root |
1.41 |
static void |
236 |
root |
1.5 |
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 |
|
|
} |