1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * 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 |
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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* This file deals with range related commands (casting, shooting, |
25 | /* This file deals with range related commands (casting, shooting, |
26 | * throwing, etc. |
26 | * throwing, etc. |
… | |
… | |
28 | |
28 | |
29 | #include <global.h> |
29 | #include <global.h> |
30 | #include <sproto.h> |
30 | #include <sproto.h> |
31 | #include <spells.h> |
31 | #include <spells.h> |
32 | #include <skills.h> |
32 | #include <skills.h> |
33 | #include <commands.h> |
|
|
34 | |
33 | |
35 | /* Shows all spells that op knows. If params is supplied, the must match |
34 | /* 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 |
35 | * that. Given there is more than one skill, we can't supply break |
37 | * them down to cleric/wizardry. |
36 | * them down to cleric/wizardry. |
38 | */ |
37 | */ |
… | |
… | |
104 | } |
103 | } |
105 | } |
104 | } |
106 | } |
105 | } |
107 | |
106 | |
108 | /* sets up to cast a spell. op is the caster, params is the spell name, |
107 | /* 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, |
108 | * 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 |
109 | * p=prepare). Invoke casts a spell immediately, where as cast (and I believe |
111 | * prepare) just set up the range type. |
110 | * prepare) just set up the range type. |
112 | */ |
111 | */ |
113 | static int |
112 | static int |
114 | command_cast_spell (object *op, char *params, char command) |
113 | command_cast_spell (object *op, char *params, char command) |
115 | { |
114 | { |
116 | int castnow = 0; |
115 | int castnow = 0; |
117 | char *cp; |
116 | char *cp; |
118 | object *spob; |
|
|
119 | |
117 | |
120 | if (command == 'i') |
118 | if (command == 'i') |
121 | castnow = 1; |
119 | castnow = 1; |
122 | |
120 | |
123 | /* Remove control of the golem */ |
121 | /* Remove control of the golem */ |
124 | if (object *golem = op->contr->golem) |
122 | if (object *golem = op->contr->golem) |
125 | golem->drop_and_destroy (); |
123 | golem->drop_and_destroy (); |
126 | |
124 | |
127 | if (params) |
125 | if (params) |
128 | { |
126 | { |
129 | int spellnumber = 0; |
127 | object *spob = op->find_spell (params); |
130 | |
128 | |
131 | if ((spellnumber = atoi (params))) |
129 | if (spob) |
132 | for (spob = op->inv; spob && spob->count != spellnumber; spob = spob->below) |
|
|
133 | /* nop */; |
|
|
134 | else |
|
|
135 | spob = lookup_spell_by_name (op, params); |
|
|
136 | |
|
|
137 | if (spob && spob->type == SPELL) |
|
|
138 | { |
130 | { |
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 | } |
|
|
152 | } |
|
|
153 | else if (strlen (params) > strlen (spob->name)) |
131 | if (strlen (params) > strlen (spob->name)) |
154 | { |
132 | { |
155 | cp = params + strlen (spob->name); |
133 | cp = params + strlen (spob->name); |
156 | *cp = 0; |
134 | *cp = 0; |
157 | cp++; |
135 | cp++; |
158 | if (!strncmp (cp, "of ", 3)) |
136 | if (!strncmp (cp, "of ", 3)) |
159 | cp += 3; |
137 | cp += 3; |
160 | } |
138 | } |
161 | else |
139 | else |
162 | cp = NULL; |
140 | cp = NULL; |
163 | |
141 | |
164 | 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 | { |
|
|
175 | op->failmsg (format ("You need the skill %s to cast %s!", &spob->skill, &spob->name)); |
|
|
176 | return 1; |
|
|
177 | } |
|
|
178 | |
|
|
179 | splay (spob); |
|
|
180 | |
|
|
181 | if (castnow) |
142 | if (castnow) |
182 | cast_spell (op, op, op->facing, spob, cp); |
143 | cast_spell (op, op, op->facing, spob, cp); |
183 | else |
144 | else if (op->apply (spob)) |
184 | { |
145 | { |
185 | if (op->contr->ranged_ob) |
146 | splay (spob); |
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 | |
|
|
191 | 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 : ""); |
147 | assign (op->contr->spellparam, cp ? cp : ""); |
198 | op->statusmsg (format ("You ready the spell %s", &spob->name)); |
|
|
199 | } |
|
|
200 | } |
148 | } |
201 | |
149 | |
202 | return 0; |
150 | return 0; |
203 | } /* else fall through to below and print spells */ |
151 | } /* else fall through to below and print spells */ |
204 | } /* params supplied */ |
152 | } /* params supplied */ |
… | |
… | |
230 | return command_cast_spell (op, params, 'p'); |
178 | return command_cast_spell (op, params, 'p'); |
231 | } |
179 | } |
232 | |
180 | |
233 | /**************************************************************************/ |
181 | /**************************************************************************/ |
234 | |
182 | |
235 | static void |
|
|
236 | change_spell (object *op, char k) |
|
|
237 | { |
|
|
238 | if (op->contr->combat_ob == op->current_weapon) |
|
|
239 | { |
|
|
240 | if (op->contr->ranged_ob) |
|
|
241 | op->change_weapon (op->contr->ranged_ob); |
|
|
242 | } |
|
|
243 | else if (op->contr->ranged_ob == op->current_weapon) |
|
|
244 | { |
|
|
245 | if (op->contr->combat_ob) |
|
|
246 | op->change_weapon (op->contr->combat_ob); |
|
|
247 | } |
|
|
248 | |
|
|
249 | //TODO: maybe switch to golem, if any? |
|
|
250 | } |
|
|
251 | |
|
|
252 | int |
183 | int |
253 | command_rotateshoottype (object *op, char *params) |
184 | command_rotateshoottype (object *op, char *params) |
254 | { |
185 | { |
255 | if (!params) |
186 | if (op->contr->combat_ob && op->contr->ranged_ob) |
256 | change_spell (op, '+'); |
187 | op->apply ( |
257 | else |
188 | op->current_weapon == op->contr->combat_ob |
258 | change_spell (op, params[0]); |
189 | ? op->contr->ranged_ob |
|
|
190 | : op->contr->combat_ob |
|
|
191 | ); |
|
|
192 | |
|
|
193 | //TODO: maybe switch to golem, if any? |
259 | |
194 | |
260 | return 0; |
195 | return 0; |
261 | } |
196 | } |
|
|
197 | |