ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_util.C
Revision: 1.79
Committed: Mon Sep 29 06:32:09 2008 UTC (15 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.78: +52 -39 lines
Log Message:
spell effective level system reworked

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * 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 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */
23
24 #include <global.h>
25 #include <spells.h>
26 #include <object.h>
27 #include <errno.h>
28 #include <sproto.h>
29 #include <sounds.h>
30
31 extern char *spell_mapping[];
32
33 /* This returns a random spell from 'ob'. If skill is set, then
34 * the spell must be of this skill, it can be NULL in which case all
35 * matching spells are used.
36 */
37 object *
38 find_random_spell_in_ob (object *ob, const char *skill)
39 {
40 int k = 0, s;
41
42 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
43 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
44 k++;
45
46 /* No spells, no need to progess further */
47 if (!k)
48 return NULL;
49
50 s = RANDOM () % k;
51
52 for (object *tmp = ob->inv; tmp; tmp = tmp->below)
53 if (tmp->type == SPELL && (!skill || tmp->skill == skill))
54 if (!s)
55 return tmp;
56 else
57 s--;
58
59 /* Should never get here, but just in case */
60 return 0;
61 }
62
63 /* Relatively simple function that gets used a lot.
64 * Basically, it sets up the skill pointer for the spell being
65 * cast. If op is really casting the spell, then the skill
66 * is whatever skill the spell requires.
67 * if instead caster (rod, horn, wand, etc) is casting the skill,
68 * then they get exp for the skill that you need to use for
69 * that object (use magic device).
70 */
71 void
72 set_spell_skill (object *op, object *caster, object *spob, object *dest)
73 {
74 if (caster == op && spob->skill)
75 dest->skill = spob->skill;
76 else
77 dest->skill = caster->skill;
78 }
79
80 /* pretty basic function - basically just takes
81 * an object, sets the x,y, and calls insert_ob_in_map
82 */
83 void
84 spell_effect (object *spob, int x, int y, maptile *map, object *originator)
85 {
86 if (spob->other_arch)
87 map->insert (arch_to_object (spob->other_arch), x, y, originator);
88 }
89
90 /*
91 * This function takes a caster and spell and presents the
92 * effective level the caster needs to be to cast the spell.
93 * basically, it just adjusts the spell->level with attuned/repelled
94 * spellpaths. Was called path_level_mod.
95 *
96 * caster is person casting the spell.
97 * spell is the spell object.
98 * Returns modified level.
99 */
100 int
101 min_casting_level (object *caster, object *spell)
102 {
103 if (caster->path_denied & spell->path_attuned)
104 return 1;
105
106 int new_level = spell->level
107 + (caster->path_repelled & spell->path_attuned ? +ATTUNE_REPELL : 0)
108 + (caster->path_attuned & spell->path_attuned ? -ATTUNE_REPELL : 0);
109
110 return max (1, new_level);
111 }
112
113 /* This function returns the effective level the spell
114 * is being cast at.
115 */
116 int
117 casting_level (object *caster, object *spell)
118 {
119 int level = caster->level;
120
121 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */
122 if (caster->type == ROD && caster->env && caster->env->type == PLAYER)
123 {
124 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM);
125 int sk_level = skill ? skill->level : 1;
126
127 level = min (level, sk_level + level / 10 + 1);
128 }
129 else if (caster->type == PLAYER) /* If this is a player, try to find the matching skill */
130 if (object *skill = caster->contr->find_skill (spell->skill))
131 level = skill->level;
132
133 // now scale the effective level from the startinglevel..100 range to 1..100
134 if (level < 100)
135 level = lerp (level, (int)spell->level, 100, 1, 100);
136
137 /* Got valid caster level. Now adjust for attunement */
138 // attuned only increases up to 2 times the original level */
139 if (caster->path_attuned & spell->path_attuned)
140 level = min (level * 2, level + ATTUNE_REPELL);
141
142 // repell has no such quarrels
143 if (caster->path_repelled & spell->path_attuned)
144 level -= ATTUNE_REPELL;
145
146 /* Always make this at least 1. If this is zero, we get divide by zero
147 * errors in various places.
148 */
149 return max (level, 1);
150 }
151
152 /* The following function scales the spellpoint cost of
153 * a spell by it's increased effectiveness. Some of the
154 * lower level spells become incredibly vicious at high
155 * levels. Very cheap mass destruction. This function is
156 * intended to keep the sp cost related to the effectiveness.
157 * op is the player/monster
158 * caster is what is casting the spell, can be op.
159 * spell is the spell object.
160 * Note that it is now possible for a spell to cost both grace and
161 * mana. In that case, we return which ever value is higher.
162 */
163 sint16
164 SP_level_spellpoint_cost (object *caster, object *spell, int flags)
165 {
166 int sp, grace, level = casting_level (caster, spell);
167
168 if (settings.spellpoint_level_depend == TRUE)
169 {
170 if (spell->stats.sp && spell->stats.maxsp)
171 {
172 sp = (int) (spell->stats.sp * (1.0 + MAX (0, (float) (level - spell->level) / (float) spell->stats.maxsp)));
173 }
174 else
175 sp = spell->stats.sp;
176
177 sp *= (int) PATH_SP_MULT (caster, spell);
178 if (!sp && spell->stats.sp)
179 sp = 1;
180
181 if (spell->stats.grace && spell->stats.maxgrace)
182 {
183 grace = (int) (spell->stats.grace * (1.0 + MAX (0, (float) (level - spell->level) / (float) spell->stats.maxgrace)));
184 }
185 else
186 grace = spell->stats.grace;
187
188 grace *= (int) PATH_SP_MULT (caster, spell);
189 if (spell->stats.grace && !grace)
190 grace = 1;
191 }
192 else
193 {
194 sp = (int) (spell->stats.sp * PATH_SP_MULT (caster, spell));
195 if (spell->stats.sp && !sp)
196 sp = 1;
197
198 grace = (int) (spell->stats.grace * PATH_SP_MULT (caster, spell));
199 if (spell->stats.grace && !grace)
200 grace = 1;
201 }
202
203 if (flags == SPELL_HIGHEST)
204 return MAX (sp, grace);
205 else if (flags == SPELL_GRACE)
206 return grace;
207 else if (flags == SPELL_MANA)
208 return sp;
209 else
210 {
211 LOG (llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
212 return 0;
213 }
214 }
215
216 /*
217 * Return the effective casting level of the spell.
218 * To make spells independent of their starting level, this function
219 * scales the range spellstartlevel .. 100 into the range 1..100
220 */
221 static int
222 SP_casting_level (object *caster, object *spell)
223 {
224 return casting_level (caster, spell);
225 }
226
227 /* SP_level_dam_adjust: Returns adjusted damage based on the caster.
228 * spob is the spell we are adjusting.
229 */
230 int
231 SP_level_dam_adjust (object *caster, object *spob)
232 {
233 if (!spob->dam_modifier)
234 return 0;
235
236 return SP_casting_level (caster, spob) / spob->dam_modifier;
237 }
238
239 /* Adjust the strength of the spell based on level.
240 * This is basically the same as SP_level_dam_adjust above,
241 * but instead looks at the level_modifier value.
242 */
243 int
244 SP_level_duration_adjust (object *caster, object *spob)
245 {
246 if (!spob->duration_modifier)
247 return 0;
248
249 return SP_casting_level (caster, spob) / spob->duration_modifier;
250 }
251
252 /* Adjust the strength of the spell based on level.
253 * This is basically the same as SP_level_dam_adjust above,
254 * but instead looks at the level_modifier value.
255 */
256 int
257 SP_level_range_adjust (object *caster, object *spob)
258 {
259 if (!spob->range_modifier)
260 return 0;
261
262 return SP_casting_level (caster, spob) / spob->range_modifier;
263 }
264
265 /* Checks to see if player knows the spell. If the name is the same
266 * as an existing spell, we presume they know it.
267 * returns 1 if they know the spell, 0 if they don't.
268 */
269 object *
270 check_spell_known (object *op, const char *name)
271 {
272 object *spop;
273 shstr_cmp name_ (name);
274
275 for (spop = op->inv; spop; spop = spop->below)
276 if (spop->type == SPELL && spop->name == name)
277 return spop;
278
279 return 0;
280 }
281
282
283 /*
284 * Look at object 'op' and see if they know the spell
285 * spname. This is pretty close to check_spell_known
286 * above, but it uses a looser matching mechanism.
287 * returns the matching spell object, or NULL.
288 * If we match multiple spells but don't get an
289 * exact match, we also return NULL.
290 */
291
292 object *
293 lookup_spell_by_name (object *op, const char *spname)
294 {
295 object *spob1 = NULL, *spob2 = NULL, *spob;
296 int nummatch = 0;
297
298 if (spname == NULL)
299 return NULL;
300
301 /* Try to find the spell. We store the results in spob1
302 * and spob2 - spob1 is only taking the length of
303 * the past spname, spob2 uses the length of the spell name.
304 */
305 for (spob = op->inv; spob; spob = spob->below)
306 {
307 if (spob->type == SPELL)
308 {
309 if (!strncmp (spob->name, spname, strlen (spname)))
310 {
311 nummatch++;
312 spob1 = spob;
313 }
314 else if (!strncmp (spob->name, spname, strlen (spob->name)))
315 {
316 /* if spells have ambiguous names, it makes matching
317 * really difficult. (eg, fire and fireball would
318 * fall into this category). It shouldn't be hard to
319 * make sure spell names don't overlap in that fashion.
320 */
321 if (spob2)
322 LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name);
323 spob2 = spob;
324 }
325 }
326 }
327 /* if we have best match, return it. Otherwise, if we have one match
328 * on the loser match, return that, otehrwise null
329 */
330 if (spob2)
331 return spob2;
332 if (spob1 && nummatch == 1)
333 return spob1;
334 return NULL;
335 }
336
337 /* reflwall - decides weither the (spell-)object sp_op will
338 * be reflected from the given mapsquare. Returns 1 if true.
339 * (Note that for living creatures there is a small chance that
340 * reflect_spell fails.)
341 * Caller should be sure it passes us valid map coordinates
342 * eg, updated for tiled maps.
343 */
344 int
345 reflwall (maptile *m, int x, int y, object *sp_op)
346 {
347 if (OUT_OF_REAL_MAP (m, x, y))
348 return 0;
349
350 for (object *op = GET_MAP_OB (m, x, y); op; op = op->above)
351 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
352 && (!QUERY_FLAG (op, FLAG_ALIVE)
353 || (rndm (0, 99)) < 90 - (sp_op->level / 10)))
354 return 1;
355
356 return 0;
357 }
358
359 /* cast_create_object: creates object new_op in direction dir
360 * or if that is blocked, beneath the player (op).
361 * we pass 'caster', but don't use it for anything.
362 * This is really just a simple wrapper function .
363 * returns the direction that the object was actually placed
364 * in.
365 */
366 int
367 cast_create_obj (object *op, object *caster, object *new_op, int dir)
368 {
369 maptile *m;
370 sint16 sx, sy;
371
372 if (dir &&
373 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) ||
374 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))))
375 {
376 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
377 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
378 dir = 0;
379 }
380
381 SET_FLAG (new_op, FLAG_IDENTIFIED);
382 op->map->insert (new_op,
383 op->x + freearr_x[dir], op->y + freearr_y[dir],
384 op,
385 dir ? 0 : INS_BELOW_ORIGINATOR);
386
387 return dir;
388 }
389
390 /* Returns true if it is ok to put spell *op on the space/may provided.
391 * immune_stop is basically the attacktype of the spell (why
392 * passed as a different value, not sure of). If immune_stop
393 * has the AT_MAGIC bit set, and there is a counterwall
394 * on the space, the object doesn't get placed. if immune stop
395 * does not have AT_MAGIC, then counterwalls do not effect the spell.
396 *
397 */
398 int
399 ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
400 {
401 if (!xy_normalise (m, x, y))
402 return 0;
403
404 mapspace &ms = m->at (x, y);
405 ms.update ();
406
407 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
408 return 0;
409
410 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
411 {
412 /* If there is a counterspell on the space, and this
413 * object is using magic, don't progress. I believe we could
414 * leave this out and let in progress, and other areas of the code
415 * will then remove it, but that would seem to to use more
416 * resources, and may not work as well if a player is standing
417 * on top of a counterwall spell (may hit the player before being
418 * removed.) On the other hand, it may be more dramatic for the
419 * spell to actually hit the counterwall and be sucked up.
420 */
421 if ((tmp->attacktype & AT_COUNTERSPELL)
422 && !QUERY_FLAG (tmp, FLAG_MONSTER)
423 && (tmp->type != PLAYER)
424 && (tmp->type != WEAPON)
425 && (tmp->type != BOW)
426 && (tmp->type != ARROW)
427 && (tmp->type != GOLEM)
428 && !QUERY_FLAG (tmp, FLAG_IS_FLOOR) // XXX:
429 // we special case floor here because there
430 // are sometimes spell effect floors
431 // which are used to inflict damage
432 // (and those shouldn't go away from
433 // sanctuary) see also: permanent lava
434 && (immune_stop & AT_MAGIC))
435 return 0;
436
437 /* This is to prevent 'out of control' spells. Basically, this
438 * limits one spell effect per space per spell. This is definately
439 * needed for performance reasons, and just for playability I believe.
440 * there are no such things as multispaced spells right now, so
441 * we don't need to worry about the head.
442 */
443 if ((tmp->stats.maxhp == op->stats.maxhp) && (tmp->type == op->type) && (tmp->subtype == op->subtype))
444 return 0;
445
446 /*
447 * Combine similar spell effects into one spell effect. Needed for
448 * performance reasons with meteor swarm and the like, but also for
449 * playability reasons.
450 */
451 if (tmp->arch == op->arch /* no harm if not comparing by name here */
452 && tmp->type == op->type
453 && tmp->subtype == op->subtype
454 && tmp->owner == op->owner
455 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
456 {
457 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam);
458 tmp->range = MAX (tmp->range, op->range);
459 tmp->duration = MAX (tmp->duration, op->duration);
460 return 0;
461 }
462
463 /* Perhaps we should also put checks in for no magic and unholy
464 * ground to prevent it from moving along?
465 */
466 }
467
468 /* If it passes the above tests, it must be OK */
469 return 1;
470 }
471
472 /* fire_arch_from_position: fires an archetype.
473 * op: person firing the object.
474 * caster: object casting the spell.
475 * x, y: where to fire the spell (note, it then uses op->map for the map
476 * for these coordinates, which is probably a really bad idea.
477 * dir: direction to fire in.
478 * spell: spell that is being fired. It uses other_arch for the archetype
479 * to fire.
480 * returns 0 on failure, 1 on success.
481 */
482 int
483 fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
484 {
485 if (!spell->other_arch)
486 return 0;
487
488 object *tmp = spell->other_arch->instance ();
489
490 if (!tmp)
491 return 0;
492
493 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
494 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
495 /* code in time.c uses food for some things, duration for others */
496 tmp->stats.food = tmp->duration;
497 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
498 tmp->attacktype = spell->attacktype;
499 tmp->direction = dir;
500 tmp->set_owner (op);
501 tmp->level = casting_level (caster, spell);
502 set_spell_skill (op, caster, spell, tmp);
503
504 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
505 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
506 if (!tailor_god_spell (tmp, op))
507 return 0;
508
509 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
510 SET_ANIMATION (tmp, dir);
511
512 if ((tmp = op->map->insert (tmp, x, y, op)))
513 move_spell_effect (tmp);
514
515 return 1;
516 }
517
518 /*****************************************************************************
519 *
520 * Code related to rods - perhaps better located in another file?
521 *
522 ****************************************************************************/
523 void
524 regenerate_rod (object *rod)
525 {
526 if (rod->stats.hp < rod->stats.maxhp)
527 rod->stats.hp = min (rod->stats.maxhp, rod->stats.hp + 1 + rod->stats.maxhp / 10);
528 }
529
530 void
531 drain_rod_charge (object *rod)
532 {
533 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST);
534 }
535
536 /* this function is commonly used to find a friendly target for
537 * spells such as heal or protection or armour
538 * op is what is looking for the target (which can be a player),
539 * dir is the direction we are looking in. Return object found, or
540 * NULL if no good object.
541 */
542 object *
543 find_target_for_friendly_spell (object *op, int dir)
544 {
545 object *tmp;
546
547 /* I don't really get this block - if op isn't a player or rune,
548 * we then make the owner of this object the target.
549 * The owner could very well be no where near op.
550 */
551 if (op->type != PLAYER && op->type != RUNE)
552 {
553 tmp = op->owner;
554 /* If the owner does not exist, or is not a monster, than apply the spell
555 * to the caster.
556 */
557 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER))
558 tmp = op;
559 }
560 else
561 {
562 maptile *m = op->map;
563 sint16 x = op->x + freearr_x[dir];
564 sint16 y = op->y + freearr_y[dir];
565
566 tmp = xy_normalise (m, x, y)
567 ? m->at (x, y).player ()
568 : 0;
569 }
570
571 /* didn't find a player there, look in current square for a player */
572 if (!tmp)
573 tmp = op->ms ().player ();
574
575 return tmp;
576 }
577
578 /* raytrace:
579 * spell_find_dir(map, x, y, exclude) will search first the center square
580 * then some close squares in the given map at the given coordinates for
581 * live objects.
582 * It will not consider the object given as exclude (= caster) among possible
583 * live objects. If the caster is a player, the spell will go after
584 * monsters/generators only. If not, the spell will hunt players only.
585 * It returns the direction toward the first/closest live object if it finds
586 * any, otherwise -1.
587 * note that exclude can be NULL, in which case all bets are off.
588 */
589 int
590 spell_find_dir (maptile *m, int x, int y, object *exclude)
591 {
592 int i, max = SIZEOFFREE;
593 sint16 nx, ny;
594 int owner_type = 0, mflags;
595 object *tmp;
596 maptile *mp;
597
598 if (exclude && exclude->head)
599 exclude = exclude->head;
600 if (exclude && exclude->type)
601 owner_type = exclude->type;
602
603 for (i = rndm (1, 8); i < max; i++)
604 {
605 nx = x + freearr_x[i];
606 ny = y + freearr_y[i];
607 mp = m;
608 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
609 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW))
610 continue;
611
612 tmp = GET_MAP_OB (mp, nx, ny);
613
614 while (tmp != NULL && (((owner_type == PLAYER &&
615 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) ||
616 (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude))))
617 tmp = tmp->above;
618
619 if (tmp != NULL && can_see_monsterP (m, x, y, i))
620 return freedir[i];
621 }
622 return -1; /* flag for "keep going the way you were" */
623 }
624
625 /* put_a_monster: puts a monster named monstername near by
626 * op. This creates the treasures for the monsters, and
627 * also deals with multipart monsters properly.
628 */
629 void
630 put_a_monster (object *op, const char *monstername)
631 {
632 object *tmp, *head = NULL, *prev = NULL;
633 archetype *at;
634 int dir;
635
636 /* Handle cases where we are passed a bogus mosntername */
637
638 if ((at = archetype::find (monstername)) == NULL)
639 return;
640
641 /* find a free square nearby
642 * first we check the closest square for free squares
643 */
644
645 dir = find_first_free_spot (at, op->map, op->x, op->y);
646 if (dir != -1)
647 {
648 /* This is basically grabbed for generate monster. Fixed 971225 to
649 * insert multipart monsters properly
650 */
651 //TODO: use expand_tail + ...
652 while (at != NULL)
653 {
654 tmp = arch_to_object (at);
655 tmp->x = op->x + freearr_x[dir] + at->x;
656 tmp->y = op->y + freearr_y[dir] + at->y;
657 tmp->map = op->map;
658 if (head)
659 {
660 tmp->head = head;
661 prev->more = tmp;
662 }
663
664 if (!head)
665 head = tmp;
666
667 prev = tmp;
668
669 at = (archetype *)at->more;
670 }
671
672 if (head->randomitems)
673 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
674
675 insert_ob_in_map (head, op->map, op, 0);
676
677 /* thought it'd be cool to insert a burnout, too. */
678 op->map->insert (archetype::get (shstr_burnout), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
679 }
680 }
681
682 /* peterm: function which summons hostile monsters and
683 * places them in nearby squares.
684 * op is the summoner.
685 * n is the number of monsters.
686 * monstername is the name of the monster.
687 * returns the number of monsters, which is basically n.
688 * it should really see how many it successfully replaced and
689 * return that instead.
690 * Note that this is not used by any spells (summon evil monsters
691 * use to call this, but best I can tell, that spell/ability was
692 * never used. This is however used by various failures on the
693 * players part (alchemy, reincarnation, etc)
694 */
695
696 int
697 summon_hostile_monsters (object *op, int n, const char *monstername)
698 {
699 int i;
700
701 for (i = 0; i < n; i++)
702 put_a_monster (op, monstername);
703
704 return n;
705 }
706
707
708 /* Some local definitions for shuffle-attack */
709 struct attacktype_shuffle
710 {
711 int attacktype;
712 int face;
713 } ATTACKS[22] =
714 {
715 { AT_PHYSICAL, 0},
716 { AT_PHYSICAL, 0}, /*face = explosion */
717 { AT_PHYSICAL, 0},
718 { AT_MAGIC, 1},
719 { AT_MAGIC, 1}, /* face = last-burnout */
720 { AT_MAGIC, 1},
721 { AT_FIRE, 2},
722 { AT_FIRE, 2}, /* face = fire.... */
723 { AT_FIRE, 2},
724 { AT_ELECTRICITY, 3},
725 { AT_ELECTRICITY, 3}, /* ball_lightning */
726 { AT_ELECTRICITY, 3},
727 { AT_COLD, 4},
728 { AT_COLD, 4}, /* face=icestorm */
729 { AT_COLD, 4},
730 { AT_CONFUSION, 5},
731 { AT_POISON, 7},
732 { AT_POISON, 7}, /* face = acid sphere. generator */
733 { AT_POISON, 7}, /* poisoncloud face */
734 { AT_SLOW, 8},
735 { AT_PARALYZE, 9},
736 { AT_FEAR, 10},
737 };
738
739 /* shuffle_attack: peterm
740 * This routine shuffles the attack of op to one of the
741 * ones in the list. It does this at random. It also
742 * chooses a face appropriate to the attack that is
743 * being committed by that square at the moment.
744 * right now it's being used by color spray and create pool of
745 * chaos.
746 * This could really be a better implementation - the
747 * faces and attacktypes above are hardcoded, which is never
748 * good. The faces refer to faces in the animation sequence.
749 * Not sure how to do better - but not having it hardcoded
750 * would be nice.
751 * I also fixed a bug here in that attacktype was |= -
752 * to me, that would be that it would quickly get all
753 * attacktypes, which probably wasn't the intent. MSW 2003-06-03
754 */
755 void
756 shuffle_attack (object *op, int change_face)
757 {
758 int i;
759
760 i = rndm (0, 21);
761
762 op->attacktype = ATTACKS[i].attacktype | AT_MAGIC;
763
764 if (change_face)
765 {
766 SET_ANIMATION (op, ATTACKS[i].face);
767 }
768 }
769
770
771 /* prayer_failure: This is called when a player fails
772 * at casting a prayer.
773 * op is the player.
774 * failure is basically how much grace they had.
775 * power is how much grace the spell would normally take to cast.
776 */
777
778 void
779 prayer_failure (object *op, int failure, int power)
780 {
781 const char *godname;
782 object *tmp;
783
784 if (!strcmp ((godname = determine_god (op)), "none"))
785 godname = "Your spirit";
786
787 if (failure <= -20 && failure > -40) /* wonder */
788 {
789 new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname);
790 tmp = get_archetype (SPELL_WONDER);
791 cast_cone (op, op, 0, tmp);
792 tmp->destroy ();
793 }
794
795 else if (failure <= -40 && failure > -60) /* confusion */
796 {
797 new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!");
798 confuse_player (op, op, 99);
799 }
800 else if (failure <= -60 && failure > -150) /* paralysis */
801 {
802 new_draw_info_format (NDI_UNIQUE, 0, op, "%s requires you to pray NOW.", godname);
803 new_draw_info (NDI_UNIQUE, 0, op, "You comply, ignoring all else.");
804 paralyze_player (op, op, 99);
805 }
806 else if (failure <= -150) /* blast the immediate area */
807 {
808 tmp = get_archetype (GOD_POWER);
809 new_draw_info_format (NDI_UNIQUE, 0, op, "%s smites you!", godname);
810 cast_magic_storm (op, tmp, power);
811 }
812 }
813
814 /*
815 * spell_failure() handles the various effects for differing degrees
816 * of failure badness.
817 * op is the player that failed.
818 * failure is a random value of how badly you failed.
819 * power is how many spellpoints you'd normally need for the spell.
820 * skill is the skill you'd need to cast the spell.
821 */
822
823 void
824 spell_failure (object *op, int failure, int power, object *skill)
825 {
826 object *tmp;
827
828 if (settings.spell_failure_effects == FALSE)
829 return;
830
831 if (failure <= -20 && failure > -40) /* wonder */
832 {
833 new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect.");
834 tmp = get_archetype (SPELL_WONDER);
835 cast_cone (op, op, 0, tmp);
836 tmp->destroy ();
837 }
838
839 else if (failure <= -40 && failure > -60) /* confusion */
840 {
841 new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!");
842 confuse_player (op, op, 99);
843 }
844 else if (failure <= -60 && failure > -80) /* paralysis */
845 {
846 new_draw_info (NDI_UNIQUE, 0, op, "Your magic stuns you!");
847 paralyze_player (op, op, 99);
848 }
849 else if (failure <= -80) /* blast the immediate area */
850 {
851 object *tmp;
852
853 /* Safety check to make sure we don't get any mana storms in scorn */
854 if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_NO_MAGIC)
855 {
856 new_draw_info (NDI_UNIQUE, 0, op, "The magic warps and you are turned inside out!");
857 hit_player (op, 9998, op, AT_INTERNAL, 1);
858
859 }
860 else
861 {
862 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!");
863 tmp = get_archetype (LOOSE_MANA);
864 tmp->level = skill->level;
865
866 /* increase the area of destruction a little for more powerful spells */
867 tmp->range += isqrt (power);
868
869 if (power > 25)
870 tmp->stats.dam = 25 + isqrt (power);
871 else
872 tmp->stats.dam = power; /* nasty recoils! */
873
874 tmp->stats.maxhp = tmp->count;
875
876 tmp->insert_at (op);
877 }
878 }
879 }
880
881 int
882 cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
883 {
884 int success;
885 object *spell;
886
887 if (!spell_ob->other_arch)
888 {
889 LOG (llevError, "cast_party_spell: empty other arch\n");
890 return 0;
891 }
892
893 spell = arch_to_object (spell_ob->other_arch);
894
895 /* Always cast spell on caster */
896 success = cast_spell (op, caster, dir, spell, stringarg);
897
898 if (caster->contr->party == NULL)
899 {
900 spell->remove ();
901 return success;
902 }
903
904 for_all_players (pl)
905 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster)))
906 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
907
908 spell->remove ();
909 return success;
910 }
911
912 /* This is where the main dispatch when someone casts a spell.
913 *
914 * op is the creature that is owner of the object that is casting the spell -
915 * eg, the player or monster.
916 * caster is the actual object (wand, potion) casting the spell. can be
917 * same as op.
918 * dir is the direction to cast in. Note in some cases, if the spell
919 * is self only, dir really doesn't make a difference.
920 * spell_ob is the spell object that is being cast. From that,
921 * we can determine what to do.
922 * stringarg is any options that are being used. It can be NULL. Almost
923 * certainly, only players will set it. It is basically used as optional
924 * parameters to a spell (eg, item to create, information for marking runes,
925 * etc.
926 * returns 1 on successful cast, or 0 on error. These values should really
927 * be swapped, so that 0 is successful, and non zero is failure, with a code
928 * of what it failed.
929 *
930 * Note that this function is really a dispatch routine that calls other
931 * functions - it just blindly returns what ever value those functions
932 * return. So if your writing a new function that is called from this,
933 * it shoudl also return 1 on success, 0 on failure.
934 *
935 * if it is a player casting the spell (op->type == PLAYER, op == caster),
936 * this function will decrease the mana/grace appropriately. For other
937 * objects, the caller should do what it considers appropriate.
938 */
939 int
940 cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
941 {
942 const char *godname;
943 int success = 0, cast_level = 0;
944 object *skill = NULL;
945
946 if (!spell_ob)
947 {
948 LOG (llevError, "cast_spell: null spell object passed\n");
949 return 0;
950 }
951
952 if (!strcmp ((godname = determine_god (op)), "none"))
953 godname = "A random spirit";
954
955 /* the caller should set caster to op if appropriate */
956 if (!caster)
957 {
958 LOG (llevError, "cast_spell: null caster object passed\n");
959 return 0;
960 }
961
962 /* if caster is a spell casting object, this normally shouldn't be
963 * an issue, because they don't have any spellpaths set up.
964 */
965 if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST))
966 {
967 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you.");
968 return 0;
969 }
970
971 /* if it is a player casting the spell, and they are really casting it
972 * (vs it coming from a wand, scroll, or whatever else), do some
973 * checks. We let monsters do special things - eg, they
974 * don't need the skill, bypass level checks, etc. The monster function
975 * should take care of that.
976 * Remove the wiz check here and move it further down - some spells
977 * need to have the right skill pointer passed, so we need to
978 * at least process that code.
979 */
980 if (op->type == PLAYER && op == caster)
981 {
982 if (spell_ob->skill)
983 {
984 skill = find_skill_by_name (op, spell_ob->skill);
985
986 if (!skill)
987 {
988 op->failmsg (format ("You need the skill %s to cast %s! "
989 "H<You either need to learn the skill via a skill scroll "
990 "or you need to wear a talisman or holy symbol.>",
991 &spell_ob->skill, &spell_ob->name));
992 return 0;
993 }
994
995 const char *msg = "";
996
997 int caster_level = skill->level;
998
999 if (op->path_attuned & spell_ob->path_attuned)
1000 {
1001 caster_level += ATTUNE_REPELL;
1002 msg = " (attuned)";
1003 }
1004
1005 if (op->path_repelled & spell_ob->path_attuned)
1006 {
1007 caster_level = ATTUNE_REPELL; // negative is ok
1008 msg = " (repelled)";
1009 }
1010
1011 int casting_level = min_casting_level (op, spell_ob);
1012
1013 if (casting_level > caster_level)
1014 {
1015 op->failmsg (format ("You lack enough skill to cast that spell! "
1016 "H<Your effective cast level is %d%s, but level %d is required.>",
1017 caster_level, msg, casting_level));
1018 if (!op->is_wiz ())
1019 return 0;
1020 }
1021 }
1022
1023 /* If the caster is the wiz, they don't ever fail, and don't have
1024 * to have sufficient grace/mana.
1025 */
1026 if (!QUERY_FLAG (op, FLAG_WIZ))
1027 {
1028 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) &&
1029 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1030 {
1031 op->failmsg ("You don't have enough mana!");
1032 return 0;
1033 }
1034
1035 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1036 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1037 {
1038 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace -
1039 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)
1040 op->statusmsg (format ("%s grants your prayer, though you are unworthy.", godname));
1041 else
1042 {
1043 prayer_failure (op, op->stats.grace, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) - op->stats.grace);
1044 op->failmsg (format ("%s ignores your prayer.", godname));
1045 return 0;
1046 }
1047 }
1048
1049 /* player/monster is trying to cast the spell. might fumble it */
1050 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) <
1051 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis]))
1052 {
1053 op->contr->play_sound (sound_find ("fumble_spell"));
1054 op->failmsg ("You fumble the prayer.");
1055
1056 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1057 return 0;
1058 }
1059 else if (spell_ob->stats.sp)
1060 {
1061 int failure = random_roll (0, 199, op, PREFER_HIGH) - op->contr->encumbrance + op->level - spell_ob->level + 35;
1062
1063 if (failure < 0)
1064 {
1065 op->failmsg ("You bungle the spell because you have too much heavy equipment in use.");
1066 if (settings.spell_failure_effects == TRUE)
1067 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill);
1068
1069 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1070 return 0;
1071 }
1072 }
1073 }
1074 }
1075
1076 int mflags = op->ms ().flags ();
1077
1078 /* See if we can cast a spell here. If the caster and op are
1079 * not alive, then this would mean that the mapmaker put the
1080 * objects on the space - presume that they know what they are
1081 * doing.
1082 */
1083
1084 if ((mflags & P_SAFE) && !QUERY_FLAG (op, FLAG_WIZCAST)) // There is _ABSOLUTELY_ no magic allowed here (except wizards :-)!
1085 {
1086 op->failmsg ("This ground is sacred! The gods prevent any magical effects done by you here!");
1087 return 0;
1088 }
1089
1090 if ((spell_ob->type == SPELL)
1091 && (caster->type != POTION)
1092 && !QUERY_FLAG (op, FLAG_WIZCAST)
1093 && (QUERY_FLAG (caster, FLAG_ALIVE)
1094 || QUERY_FLAG (op, FLAG_ALIVE))
1095 && (((mflags & P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)))
1096 {
1097 if (op->type != PLAYER)
1098 return 0;
1099
1100 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1101 op->failmsg (format ("This ground is unholy! %s ignores you.", godname));
1102 else if (object *item = op->contr->ranged_ob)
1103 {
1104 if (item->type == SPELL)
1105 op->failmsg ("Something blocks your spellcasting.");
1106 else if (item->type == SCROLL)
1107 op->failmsg ("Something blocks the magic of your scroll.");
1108 else
1109 op->failmsg ("Something blocks the magic of your item.");
1110 }
1111 else
1112 op->failmsg ("Something blocks the spell!");
1113
1114 return 0;
1115 }
1116
1117 /* Take into account how long it takes to cast the spell.
1118 * if the player is casting it, then we use the time in
1119 * the spell object. If it is a spell object, have it
1120 * take two ticks. Things that cast spells on the players
1121 * behalf (eg, altars, and whatever else) shouldn't cost
1122 * the player any time.
1123 * Ignore casting time for firewalls
1124 */
1125 if (caster == op && caster->type != FIREWALL)
1126 {
1127 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1128 /* Other portions of the code may also decrement the speed of the player, so
1129 * put a lower limit so that the player isn't stuck here too long
1130 */
1131 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed))
1132 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1133 }
1134 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL)
1135 op->speed_left -= 2 * FABS (op->speed);
1136
1137 if (op->type == PLAYER && op == caster)
1138 {
1139 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE);
1140 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA);
1141 }
1142
1143 /* We want to try to find the skill to properly credit exp.
1144 * for spell casting objects, the exp goes to the skill the casting
1145 * object requires.
1146 */
1147 if (op != caster && !skill && caster->skill)
1148 {
1149 skill = find_skill_by_name (op, caster->skill);
1150 if (!skill)
1151 {
1152 op->failmsg (format ("You lack the skill %s to use the %s!", &caster->skill, query_name (caster)));
1153 return 0;
1154 }
1155
1156 op->change_skill (skill); /* needed for proper exp credit */
1157 }
1158
1159 if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1160 return RESULT_INT (0);
1161
1162 switch (spell_ob->subtype)
1163 {
1164 /* The order of case statements is same as the order they show up
1165 * in in spells.h.
1166 */
1167 case SP_RAISE_DEAD:
1168 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg);
1169 break;
1170
1171 case SP_RUNE:
1172 success = write_rune (op, caster, spell_ob, dir, stringarg);
1173 break;
1174
1175 case SP_MAKE_MARK:
1176 success = write_mark (op, spell_ob, stringarg);
1177 break;
1178
1179 case SP_BOLT:
1180 success = fire_bolt (op, caster, dir, spell_ob, skill);
1181 break;
1182
1183 case SP_BULLET:
1184 success = fire_bullet (op, caster, dir, spell_ob);
1185 break;
1186
1187 case SP_CONE:
1188 success = cast_cone (op, caster, dir, spell_ob);
1189 break;
1190
1191 case SP_BOMB:
1192 success = create_bomb (op, caster, dir, spell_ob);
1193 break;
1194
1195 case SP_WONDER:
1196 success = cast_wonder (op, caster, dir, spell_ob);
1197 break;
1198
1199 case SP_SMITE:
1200 success = cast_smite_spell (op, caster, dir, spell_ob);
1201 break;
1202
1203 case SP_MAGIC_MISSILE:
1204 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1205 break;
1206
1207 case SP_SUMMON_GOLEM:
1208 success = summon_golem (op, caster, dir, spell_ob);
1209 break;
1210
1211 case SP_DIMENSION_DOOR:
1212 /* dimension door needs the actual caster, because that is what is
1213 * moved.
1214 */
1215 success = dimension_door (op, caster, spell_ob, dir);
1216 break;
1217
1218 case SP_MAGIC_MAPPING:
1219 if (op->type == PLAYER)
1220 {
1221 spell_effect (spell_ob, op->x, op->y, op->map, op);
1222 draw_magic_map (op);
1223 success = 1;
1224 }
1225 else
1226 success = 0;
1227 break;
1228
1229 case SP_MAGIC_WALL:
1230 success = magic_wall (op, caster, dir, spell_ob);
1231 break;
1232
1233 case SP_DESTRUCTION:
1234 success = cast_destruction (op, caster, spell_ob);
1235 break;
1236
1237 case SP_PERCEIVE_SELF:
1238 success = perceive_self (op);
1239 break;
1240
1241 case SP_WORD_OF_RECALL:
1242 success = cast_word_of_recall (op, caster, spell_ob);
1243 break;
1244
1245 case SP_INVISIBLE:
1246 success = cast_invisible (op, caster, spell_ob);
1247 break;
1248
1249 case SP_PROBE:
1250 success = probe (op, caster, spell_ob, dir);
1251 break;
1252
1253 case SP_HEALING:
1254 success = cast_heal (op, caster, spell_ob, dir);
1255 break;
1256
1257 case SP_CREATE_FOOD:
1258 success = cast_create_food (op, caster, spell_ob, dir, stringarg);
1259 break;
1260
1261 case SP_EARTH_TO_DUST:
1262 success = cast_earth_to_dust (op, caster, spell_ob);
1263 break;
1264
1265 case SP_CHANGE_ABILITY:
1266 success = cast_change_ability (op, caster, spell_ob, dir, 0);
1267 break;
1268
1269 case SP_BLESS:
1270 success = cast_bless (op, caster, spell_ob, dir);
1271 break;
1272
1273 case SP_CURSE:
1274 success = cast_curse (op, caster, spell_ob, dir);
1275 break;
1276
1277 case SP_SUMMON_MONSTER:
1278 success = summon_object (op, caster, spell_ob, dir, stringarg);
1279 break;
1280
1281 case SP_CHARGING:
1282 success = recharge (op, caster, spell_ob);
1283 break;
1284
1285 case SP_POLYMORPH:
1286 #ifdef NO_POLYMORPH
1287 /* Not great, but at least provide feedback so if players do have
1288 * polymorph (ie, find it as a preset item or left over from before
1289 * it was disabled), they get some feedback.
1290 */
1291 op->failmsg ("The spell fizzles!");
1292 success = 0;
1293 #else
1294 success = cast_polymorph (op, caster, spell_ob, dir);
1295 #endif
1296 break;
1297
1298 case SP_ALCHEMY:
1299 success = alchemy (op, caster, spell_ob);
1300 break;
1301
1302 case SP_REMOVE_CURSE:
1303 success = remove_curse (op, caster, spell_ob);
1304 break;
1305
1306 case SP_IDENTIFY:
1307 success = cast_identify (op, caster, spell_ob);
1308 break;
1309
1310 case SP_DETECTION:
1311 success = cast_detection (op, caster, spell_ob, skill);
1312 break;
1313
1314 case SP_MOOD_CHANGE:
1315 success = mood_change (op, caster, spell_ob);
1316 break;
1317
1318 case SP_MOVING_BALL:
1319 if (spell_ob->path_repelled && (spell_ob->path_repelled & caster->path_attuned) != spell_ob->path_repelled)
1320 {
1321 op->failmsg (format ("You lack the proper attunement to cast %s!", &spell_ob->name));
1322 success = 0;
1323 }
1324 else
1325 success = fire_arch_from_position (op, caster, op->x, op->y, dir, spell_ob);
1326 break;
1327
1328 case SP_SWARM:
1329 success = fire_swarm (op, caster, spell_ob, dir);
1330 break;
1331
1332 case SP_CHANGE_MANA:
1333 success = cast_transfer (op, caster, spell_ob, dir);
1334 break;
1335
1336 case SP_DISPEL_RUNE:
1337 /* in rune.c */
1338 success = dispel_rune (op, caster, spell_ob, skill, dir);
1339 break;
1340
1341 case SP_CREATE_MISSILE:
1342 success = cast_create_missile (op, caster, spell_ob, dir, stringarg);
1343 break;
1344
1345 case SP_CONSECRATE:
1346 success = cast_consecrate (op, caster, spell_ob);
1347 break;
1348
1349 case SP_ANIMATE_WEAPON:
1350 success = animate_weapon (op, caster, spell_ob, dir);
1351 break;
1352
1353 case SP_LIGHT:
1354 success = cast_light (op, caster, spell_ob, dir);
1355 break;
1356
1357 case SP_CHANGE_MAP_LIGHT:
1358 success = cast_change_map_lightlevel (op, caster, spell_ob);
1359 break;
1360
1361 case SP_FAERY_FIRE:
1362 success = cast_destruction (op, caster, spell_ob);
1363 break;
1364
1365 case SP_CAUSE_DISEASE:
1366 success = cast_cause_disease (op, caster, spell_ob, dir);
1367 break;
1368
1369 case SP_AURA:
1370 success = create_aura (op, caster, spell_ob);
1371 break;
1372
1373 case SP_PARTY_SPELL:
1374 success = cast_party_spell (op, caster, dir, spell_ob, stringarg);
1375 break;
1376
1377 default:
1378 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1379 }
1380
1381 op->play_sound (
1382 success
1383 ? spell_ob->sound
1384 ? spell_ob->sound
1385 : sound_find ("spell_success")
1386 : sound_find ("fumble_spell")
1387 );
1388
1389 return success;
1390 }
1391
1392 /* This is called from time.c/process_object(). That function
1393 * calls this for any SPELL_EFFECT type objects. This function
1394 * then dispatches them to the appropriate specific routines.
1395 */
1396 void
1397 move_spell_effect (object *op)
1398 {
1399 switch (op->subtype)
1400 {
1401 case SP_BOLT:
1402 move_bolt (op);
1403 break;
1404
1405 case SP_BULLET:
1406 move_bullet (op);
1407 break;
1408
1409 case SP_EXPLOSION:
1410 explosion (op);
1411 break;
1412
1413 case SP_CONE:
1414 move_cone (op);
1415 break;
1416
1417 case SP_BOMB:
1418 animate_bomb (op);
1419 break;
1420
1421 case SP_MAGIC_MISSILE:
1422 move_missile (op);
1423 break;
1424
1425 case SP_WORD_OF_RECALL:
1426 execute_word_of_recall (op);
1427 break;
1428
1429 case SP_MOVING_BALL:
1430 move_ball_spell (op);
1431 break;
1432
1433 case SP_SWARM:
1434 move_swarm_spell (op);
1435 break;
1436
1437 case SP_AURA:
1438 move_aura (op);
1439 break;
1440 }
1441 }
1442
1443 /* this checks to see if something special should happen if
1444 * something runs into the object.
1445 */
1446 void
1447 check_spell_effect (object *op)
1448 {
1449 switch (op->subtype)
1450 {
1451 case SP_BOLT:
1452 move_bolt (op);
1453 return;
1454
1455 case SP_BULLET:
1456 check_bullet (op);
1457 return;
1458 }
1459 }
1460
1461 /* This is called by move_apply. Basically, if someone
1462 * moves onto a spell effect and the walk_on or fly_on flags
1463 * are set, this is called. This should only be called for
1464 * objects of the appropriate type.
1465 */
1466 void
1467 apply_spell_effect (object *spell, object *victim)
1468 {
1469 switch (spell->subtype)
1470 {
1471 case SP_CONE:
1472 if (QUERY_FLAG (victim, FLAG_ALIVE) && spell->speed && spell->attacktype)
1473 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 0);
1474 break;
1475
1476 case SP_MAGIC_MISSILE:
1477 if (QUERY_FLAG (victim, FLAG_ALIVE))
1478 {
1479 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1480
1481 if (!spell->destroyed ())
1482 spell->destroy ();
1483 }
1484 break;
1485
1486 case SP_MOVING_BALL:
1487 if (QUERY_FLAG (victim, FLAG_ALIVE))
1488 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1489 else if (victim->materialname)
1490 save_throw_object (victim, spell->attacktype, spell);
1491 break;
1492 }
1493 }
1494