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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
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 |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
33 | /* This returns a random spell from 'ob'. If skill is set, then |
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 |
34 | * the spell must be of this skill, it can be NULL in which case all |
35 | * matching spells are used. |
35 | * matching spells are used. |
36 | */ |
36 | */ |
37 | object * |
37 | object * |
38 | find_random_spell_in_ob (object *ob, const char *skill) |
38 | find_random_spell_in_ob (object *ob, shstr_cmp skill) |
39 | { |
39 | { |
40 | int k = 0, s; |
40 | int k = 0, s; |
41 | |
41 | |
42 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
42 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
43 | if (tmp->type == SPELL && (!skill || tmp->skill == skill)) |
43 | if (tmp->type == SPELL && (!skill || tmp->skill == skill)) |
… | |
… | |
45 | |
45 | |
46 | /* No spells, no need to progess further */ |
46 | /* No spells, no need to progess further */ |
47 | if (!k) |
47 | if (!k) |
48 | return NULL; |
48 | return NULL; |
49 | |
49 | |
50 | s = RANDOM () % k; |
50 | s = rndm (k); |
51 | |
51 | |
52 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
52 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
53 | if (tmp->type == SPELL && (!skill || tmp->skill == skill)) |
53 | if (tmp->type == SPELL && (!skill || tmp->skill == skill)) |
54 | if (!s) |
54 | if (!s) |
55 | return tmp; |
55 | return tmp; |
… | |
… | |
95 | // repell has no such quarrels |
95 | // repell has no such quarrels |
96 | return (caster->path_attuned & spell->path_attuned ? min (level, +ATTUNE_REPELL) : 0) |
96 | return (caster->path_attuned & spell->path_attuned ? min (level, +ATTUNE_REPELL) : 0) |
97 | + (caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0); |
97 | + (caster->path_repelled & spell->path_attuned ? -ATTUNE_REPELL : 0); |
98 | } |
98 | } |
99 | |
99 | |
100 | /* |
|
|
101 | * This function takes a caster and spell and presents the |
|
|
102 | * effective level the caster needs to be to cast the spell. |
|
|
103 | * basically, it just adjusts the spell->level with attuned/repelled |
|
|
104 | * spellpaths. Was called path_level_mod. |
|
|
105 | * |
|
|
106 | * caster is person casting the spell. |
|
|
107 | * spell is the spell object. |
|
|
108 | * Returns modified level. |
|
|
109 | */ |
|
|
110 | int |
|
|
111 | min_casting_level (object *caster, object *spell) |
|
|
112 | { |
|
|
113 | if (caster->path_denied & spell->path_attuned) |
|
|
114 | return 500; |
|
|
115 | |
|
|
116 | return max (1, spell->level + attuned_bonus (caster, spell, spell->level)); |
|
|
117 | } |
|
|
118 | |
|
|
119 | /* This function returns the effective level the spell |
100 | /* This function returns the effective level the spell |
120 | * is being cast at. |
101 | * is being cast at. |
121 | */ |
102 | */ |
122 | int |
103 | int |
123 | casting_level (object *caster, object *spell) |
104 | casting_level (object *caster, object *spell) |
… | |
… | |
145 | level = lerp (level, (int)spell->level, 100, 1, 100); |
126 | level = lerp (level, (int)spell->level, 100, 1, 100); |
146 | |
127 | |
147 | /* Always make this at least 1. If this is zero, we get divide by zero |
128 | /* Always make this at least 1. If this is zero, we get divide by zero |
148 | * errors in various places. |
129 | * errors in various places. |
149 | */ |
130 | */ |
150 | return max (level, 1); |
131 | return clamp (level, 1, settings.max_level); |
151 | } |
132 | } |
152 | |
133 | |
153 | /* The following function scales the spellpoint cost of |
134 | /* The following function scales the spellpoint cost of |
154 | * a spell by it's increased effectiveness. Some of the |
135 | * a spell by it's increased effectiveness. Some of the |
155 | * lower level spells become incredibly vicious at high |
136 | * lower level spells become incredibly vicious at high |
… | |
… | |
266 | /* Checks to see if player knows the spell. If the name is the same |
247 | /* Checks to see if player knows the spell. If the name is the same |
267 | * as an existing spell, we presume they know it. |
248 | * as an existing spell, we presume they know it. |
268 | * returns 1 if they know the spell, 0 if they don't. |
249 | * returns 1 if they know the spell, 0 if they don't. |
269 | */ |
250 | */ |
270 | object * |
251 | object * |
271 | check_spell_known (object *op, const char *name) |
252 | check_spell_known (object *op, shstr_cmp name) |
272 | { |
253 | { |
273 | object *spop; |
254 | object *spop; |
274 | shstr_cmp name_ (name); |
|
|
275 | |
255 | |
276 | for (spop = op->inv; spop; spop = spop->below) |
256 | for (spop = op->inv; spop; spop = spop->below) |
277 | if (spop->type == SPELL && spop->name == name) |
257 | if (spop->type == SPELL && spop->name == name) |
278 | return spop; |
258 | return spop; |
279 | |
259 | |
… | |
… | |
289 | * exact match, we also return NULL. |
269 | * exact match, we also return NULL. |
290 | */ |
270 | */ |
291 | object * |
271 | object * |
292 | lookup_spell_by_name (object *op, const char *spname) |
272 | lookup_spell_by_name (object *op, const char *spname) |
293 | { |
273 | { |
294 | object *spob1 = NULL, *spob2 = NULL, *spob; |
274 | object *spob1 = 0, *spob2 = 0; |
295 | int nummatch = 0; |
275 | int nummatch = 0; |
296 | |
276 | |
297 | if (spname == NULL) |
277 | if (!spname) |
298 | return NULL; |
278 | return 0; |
299 | |
279 | |
300 | /* Try to find the spell. We store the results in spob1 |
280 | /* Try to find the spell. We store the results in spob1 |
301 | * and spob2 - spob1 is only taking the length of |
281 | * and spob2 - spob1 is only taking the length of |
302 | * the past spname, spob2 uses the length of the spell name. |
282 | * the past spname, spob2 uses the length of the spell name. |
303 | */ |
283 | */ |
304 | for (spob = op->inv; spob; spob = spob->below) |
284 | for (object *spob = op->inv; spob; spob = spob->below) |
305 | { |
285 | { |
306 | if (spob->type == SPELL) |
286 | if (spob->type == SPELL) |
307 | { |
287 | { |
|
|
288 | // TODO: WTF? |
308 | if (!strncmp (spob->name, spname, strlen (spname))) |
289 | if (!strncmp (spob->name, spname, strlen (spname))) |
309 | { |
290 | { |
310 | nummatch++; |
291 | nummatch++; |
311 | spob1 = spob; |
292 | spob1 = spob; |
312 | } |
293 | } |
… | |
… | |
317 | * fall into this category). It shouldn't be hard to |
298 | * fall into this category). It shouldn't be hard to |
318 | * make sure spell names don't overlap in that fashion. |
299 | * make sure spell names don't overlap in that fashion. |
319 | */ |
300 | */ |
320 | if (spob2) |
301 | if (spob2) |
321 | LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name); |
302 | LOG (llevError, "Found multiple spells with overlapping base names: %s, %s\n", &spob2->name, &spob->name); |
|
|
303 | |
322 | spob2 = spob; |
304 | spob2 = spob; |
323 | } |
305 | } |
324 | } |
306 | } |
325 | } |
307 | } |
326 | /* if we have best match, return it. Otherwise, if we have one match |
308 | /* if we have best match, return it. Otherwise, if we have one match |
327 | * on the loser match, return that, otehrwise null |
309 | * on the loser match, return that, otehrwise null |
328 | */ |
310 | */ |
329 | if (spob2) |
311 | if (spob2) |
330 | return spob2; |
312 | return spob2; |
|
|
313 | |
331 | if (spob1 && nummatch == 1) |
314 | if (spob1 && nummatch == 1) |
332 | return spob1; |
315 | return spob1; |
|
|
316 | |
333 | return NULL; |
317 | return NULL; |
334 | } |
318 | } |
335 | |
319 | |
336 | /* reflwall - decides weither the (spell-)object sp_op will |
320 | /* reflwall - decides weither the (spell-)object sp_op will |
337 | * be reflected from the given mapsquare. Returns 1 if true. |
321 | * be reflected from the given mapsquare. Returns 1 if true. |
… | |
… | |
384 | dir ? 0 : INS_BELOW_ORIGINATOR); |
368 | dir ? 0 : INS_BELOW_ORIGINATOR); |
385 | |
369 | |
386 | return dir; |
370 | return dir; |
387 | } |
371 | } |
388 | |
372 | |
|
|
373 | static bool |
|
|
374 | mergable_owner (object *o1, object *o2) |
|
|
375 | { |
|
|
376 | if (o1 == o2) |
|
|
377 | return 1; |
|
|
378 | |
|
|
379 | if (!o1 || !o2) |
|
|
380 | return 0; |
|
|
381 | |
|
|
382 | if (o1->flag [FLAG_FRIENDLY] != o1->flag [FLAG_FRIENDLY]) |
|
|
383 | return 0; |
|
|
384 | |
|
|
385 | if (o1->is_player () || o2->is_player ()) |
|
|
386 | return 0; |
|
|
387 | |
|
|
388 | return 1; |
|
|
389 | } |
|
|
390 | |
389 | /* Returns true if it is ok to put spell *op on the space/may provided. |
391 | /* Returns true if it is ok to put spell *op on the space/may provided. |
390 | * immune_stop is basically the attacktype of the spell (why |
392 | * immune_stop is basically the attacktype of the spell (why |
391 | * passed as a different value, not sure of). If immune_stop |
393 | * passed as a different value, not sure of). If immune_stop |
392 | * has the AT_MAGIC bit set, and there is a counterwall |
394 | * has the AT_MAGIC bit set, and there is a counterwall |
393 | * on the space, the object doesn't get placed. if immune stop |
395 | * on the space, the object doesn't get placed. if immune stop |
394 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
396 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
395 | * |
|
|
396 | */ |
397 | */ |
397 | int |
398 | int |
398 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
399 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
399 | { |
400 | { |
400 | if (!xy_normalise (m, x, y)) |
401 | if (!xy_normalise (m, x, y)) |
… | |
… | |
403 | mapspace &ms = m->at (x, y); |
404 | mapspace &ms = m->at (x, y); |
404 | ms.update (); |
405 | ms.update (); |
405 | |
406 | |
406 | if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) |
407 | if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) |
407 | return 0; |
408 | return 0; |
|
|
409 | |
|
|
410 | int max_effects = 5; // max. number of similar spells per mapspace |
408 | |
411 | |
409 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
412 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
410 | { |
413 | { |
411 | /* If there is a counterspell on the space, and this |
414 | /* If there is a counterspell on the space, and this |
412 | * object is using magic, don't progress. I believe we could |
415 | * object is using magic, don't progress. I believe we could |
… | |
… | |
431 | // (and those shouldn't go away from |
434 | // (and those shouldn't go away from |
432 | // sanctuary) see also: permanent lava |
435 | // sanctuary) see also: permanent lava |
433 | && (immune_stop & AT_MAGIC)) |
436 | && (immune_stop & AT_MAGIC)) |
434 | return 0; |
437 | return 0; |
435 | |
438 | |
436 | /* This is to prevent 'out of control' spells. Basically, this |
|
|
437 | * limits one spell effect per space per spell. This is definately |
|
|
438 | * needed for performance reasons, and just for playability I believe. |
|
|
439 | * there are no such things as multispaced spells right now, so |
|
|
440 | * we don't need to worry about the head. |
|
|
441 | */ |
|
|
442 | if ((tmp->stats.maxhp == op->stats.maxhp) && (tmp->type == op->type) && (tmp->subtype == op->subtype)) |
|
|
443 | return 0; |
|
|
444 | |
|
|
445 | /* |
|
|
446 | * Combine similar spell effects into one spell effect. Needed for |
|
|
447 | * performance reasons with meteor swarm and the like, but also for |
|
|
448 | * playability reasons. |
|
|
449 | */ |
|
|
450 | if (tmp->arch == op->arch /* no harm if not comparing by name here */ |
|
|
451 | && tmp->type == op->type |
439 | if (tmp->type == op->type) |
452 | && tmp->subtype == op->subtype |
|
|
453 | && tmp->owner == op->owner |
|
|
454 | && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
|
|
455 | { |
440 | { |
456 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
441 | if (tmp->subtype == op->subtype |
457 | tmp->range = MAX (tmp->range, op->range); |
442 | && tmp->arch == op->arch /* no harm if not comparing by name here */) |
458 | tmp->duration = MAX (tmp->duration, op->duration); |
443 | { |
|
|
444 | /* This is to prevent 'out of control' spells. Basically, this |
|
|
445 | * limits one spell effect per space per spell. This is definately |
|
|
446 | * needed for performance reasons, and just for playability I believe. |
|
|
447 | * there are no such things as multispaced spells right now, so |
|
|
448 | * we don't need to worry about the head. |
|
|
449 | */ |
|
|
450 | if (tmp->stats.maxhp == op->stats.maxhp) |
|
|
451 | return 0; |
|
|
452 | |
|
|
453 | /* |
|
|
454 | * Combine similar spell effects into one spell effect. Needed for |
|
|
455 | * performance reasons with meteor swarm and the like, but also for |
|
|
456 | * playability reasons. |
|
|
457 | */ |
|
|
458 | if (((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
|
|
459 | if (mergable_owner (tmp, op)) |
|
|
460 | { |
|
|
461 | // if same owner, then combine, but reduce advantage of multiple spells |
|
|
462 | max_it (tmp->stats.dam, op->stats.dam); |
|
|
463 | max_it (tmp->range , op->range); |
|
|
464 | max_it (tmp->duration , op->duration); |
|
|
465 | return 0; |
|
|
466 | } |
|
|
467 | } |
|
|
468 | |
|
|
469 | // if there are too many spell effects on this space, |
|
|
470 | // then don't allow more of them, for performance reasons. |
|
|
471 | if (tmp->type == SPELL_EFFECT |
|
|
472 | && !--max_effects) |
459 | return 0; |
473 | return 0; |
460 | } |
474 | } |
461 | |
475 | |
462 | /* Perhaps we should also put checks in for no magic and unholy |
476 | /* Perhaps we should also put checks in for no magic and unholy |
463 | * ground to prevent it from moving along? |
477 | * ground to prevent it from moving along? |
464 | */ |
478 | */ |
… | |
… | |
689 | * Note that this is not used by any spells (summon evil monsters |
703 | * Note that this is not used by any spells (summon evil monsters |
690 | * use to call this, but best I can tell, that spell/ability was |
704 | * use to call this, but best I can tell, that spell/ability was |
691 | * never used. This is however used by various failures on the |
705 | * never used. This is however used by various failures on the |
692 | * players part (alchemy, reincarnation, etc) |
706 | * players part (alchemy, reincarnation, etc) |
693 | */ |
707 | */ |
694 | |
|
|
695 | int |
708 | int |
696 | summon_hostile_monsters (object *op, int n, const char *monstername) |
709 | summon_hostile_monsters (object *op, int n, const char *monstername) |
697 | { |
710 | { |
698 | int i; |
711 | int i; |
699 | |
712 | |
… | |
… | |
764 | { |
777 | { |
765 | SET_ANIMATION (op, ATTACKS[i].face); |
778 | SET_ANIMATION (op, ATTACKS[i].face); |
766 | } |
779 | } |
767 | } |
780 | } |
768 | |
781 | |
769 | |
|
|
770 | /* prayer_failure: This is called when a player fails |
782 | /* prayer_failure: This is called when a player fails |
771 | * at casting a prayer. |
783 | * at casting a prayer. |
772 | * op is the player. |
784 | * op is the player. |
773 | * failure is basically how much grace they had. |
785 | * failure is basically how much grace they had. |
774 | * power is how much grace the spell would normally take to cast. |
786 | * power is how much grace the spell would normally take to cast. |
775 | */ |
787 | */ |
776 | |
|
|
777 | void |
788 | void |
778 | prayer_failure (object *op, int failure, int power) |
789 | prayer_failure (object *op, int failure, int power) |
779 | { |
790 | { |
780 | const char *godname; |
791 | const char *godname; |
781 | object *tmp; |
792 | object *tmp; |
… | |
… | |
876 | } |
887 | } |
877 | } |
888 | } |
878 | } |
889 | } |
879 | |
890 | |
880 | int |
891 | int |
881 | cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
892 | cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *spellparam) |
882 | { |
893 | { |
883 | int success; |
894 | int success; |
884 | object *spell; |
895 | object *spell; |
885 | |
896 | |
886 | if (!spell_ob->other_arch) |
897 | if (!spell_ob->other_arch) |
… | |
… | |
890 | } |
901 | } |
891 | |
902 | |
892 | spell = arch_to_object (spell_ob->other_arch); |
903 | spell = arch_to_object (spell_ob->other_arch); |
893 | |
904 | |
894 | /* Always cast spell on caster */ |
905 | /* Always cast spell on caster */ |
895 | success = cast_spell (op, caster, dir, spell, stringarg); |
906 | success = cast_spell (op, caster, dir, spell, spellparam); |
896 | |
907 | |
897 | if (caster->contr->party == NULL) |
908 | if (!op->contr || !op->contr->party) |
898 | { |
909 | { |
899 | spell->remove (); |
910 | spell->remove (); |
900 | return success; |
911 | return success; |
901 | } |
912 | } |
902 | |
913 | |
903 | for_all_players (pl) |
914 | for_all_players (pl) |
904 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
915 | if ((pl->ob->contr->party == op->contr->party) && (on_same_map (pl->ob, caster))) |
905 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
916 | cast_spell (pl->ob, caster, pl->ob->facing, spell, spellparam); |
906 | |
917 | |
907 | spell->remove (); |
918 | spell->remove (); |
908 | return success; |
919 | return success; |
909 | } |
920 | } |
910 | |
921 | |
… | |
… | |
916 | * same as op. |
927 | * same as op. |
917 | * dir is the direction to cast in. Note in some cases, if the spell |
928 | * dir is the direction to cast in. Note in some cases, if the spell |
918 | * is self only, dir really doesn't make a difference. |
929 | * is self only, dir really doesn't make a difference. |
919 | * spell_ob is the spell object that is being cast. From that, |
930 | * spell_ob is the spell object that is being cast. From that, |
920 | * we can determine what to do. |
931 | * we can determine what to do. |
921 | * stringarg is any options that are being used. It can be NULL. Almost |
932 | * spellparam is any options that are being used. It can be NULL. Almost |
922 | * certainly, only players will set it. It is basically used as optional |
933 | * certainly, only players will set it. It is basically used as optional |
923 | * parameters to a spell (eg, item to create, information for marking runes, |
934 | * parameters to a spell (eg, item to create, information for marking runes, |
924 | * etc. |
935 | * etc. |
925 | * returns 1 on successful cast, or 0 on error. These values should really |
936 | * returns 1 on successful cast, or 0 on error. These values should really |
926 | * be swapped, so that 0 is successful, and non zero is failure, with a code |
937 | * be swapped, so that 0 is successful, and non zero is failure, with a code |
… | |
… | |
934 | * if it is a player casting the spell (op->type == PLAYER, op == caster), |
945 | * if it is a player casting the spell (op->type == PLAYER, op == caster), |
935 | * this function will decrease the mana/grace appropriately. For other |
946 | * this function will decrease the mana/grace appropriately. For other |
936 | * objects, the caller should do what it considers appropriate. |
947 | * objects, the caller should do what it considers appropriate. |
937 | */ |
948 | */ |
938 | int |
949 | int |
939 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) |
950 | cast_spell (object *op, object *caster, int dir, object *spell_ob, char *spellparam) |
940 | { |
951 | { |
941 | const char *godname; |
952 | const char *godname; |
942 | int success = 0, cast_level = 0; |
953 | int success = 0; |
943 | object *skill = NULL; |
954 | object *skill = NULL; |
944 | |
955 | |
945 | if (!spell_ob) |
956 | if (!spell_ob) |
946 | { |
957 | { |
947 | LOG (llevError, "cast_spell: null spell object passed\n"); |
958 | LOG (llevError, "cast_spell: null spell object passed\n"); |
… | |
… | |
995 | |
1006 | |
996 | int caster_level = skill->level; |
1007 | int caster_level = skill->level; |
997 | |
1008 | |
998 | if (op->path_attuned & spell_ob->path_attuned) |
1009 | if (op->path_attuned & spell_ob->path_attuned) |
999 | { |
1010 | { |
1000 | caster_level += min (cast_level * 2, ATTUNE_REPELL); |
1011 | caster_level += min (caster_level, ATTUNE_REPELL); |
1001 | msg = " (attuned)"; |
1012 | msg = " (attuned)"; |
1002 | } |
1013 | } |
1003 | |
1014 | |
1004 | if (op->path_repelled & spell_ob->path_attuned) |
1015 | if (op->path_repelled & spell_ob->path_attuned) |
1005 | { |
1016 | { |
1006 | caster_level = ATTUNE_REPELL; // negative is ok |
1017 | caster_level -= ATTUNE_REPELL; // negative is ok |
1007 | msg = " (repelled)"; |
1018 | msg = " (repelled)"; |
1008 | } |
1019 | } |
1009 | |
1020 | |
1010 | if (spell_ob->level > caster_level) |
1021 | if (spell_ob->level > caster_level) |
1011 | { |
1022 | { |
… | |
… | |
1018 | } |
1029 | } |
1019 | |
1030 | |
1020 | /* If the caster is the wiz, they don't ever fail, and don't have |
1031 | /* If the caster is the wiz, they don't ever fail, and don't have |
1021 | * to have sufficient grace/mana. |
1032 | * to have sufficient grace/mana. |
1022 | */ |
1033 | */ |
1023 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
1034 | if (!QUERY_FLAG (op, FLAG_WIZCAST)) |
1024 | { |
1035 | { |
1025 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && |
1036 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) && |
1026 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1037 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1027 | { |
1038 | { |
1028 | op->failmsg ("You don't have enough mana!"); |
1039 | op->failmsg ("You don't have enough mana!"); |
… | |
… | |
1151 | } |
1162 | } |
1152 | |
1163 | |
1153 | op->change_skill (skill); /* needed for proper exp credit */ |
1164 | op->change_skill (skill); /* needed for proper exp credit */ |
1154 | } |
1165 | } |
1155 | |
1166 | |
1156 | if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg))) |
1167 | if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (spellparam))) |
1157 | return RESULT_INT (0); |
1168 | return RESULT_INT (0); |
1158 | |
1169 | |
1159 | switch (spell_ob->subtype) |
1170 | switch (spell_ob->subtype) |
1160 | { |
1171 | { |
1161 | /* The order of case statements is same as the order they show up |
1172 | /* The order of case statements is same as the order they show up |
1162 | * in in spells.h. |
1173 | * in spells.h. |
1163 | */ |
1174 | */ |
1164 | case SP_RAISE_DEAD: |
1175 | case SP_RAISE_DEAD: |
1165 | success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg); |
1176 | success = cast_raise_dead_spell (op, caster, spell_ob, dir, spellparam); |
1166 | break; |
1177 | break; |
1167 | |
1178 | |
1168 | case SP_RUNE: |
1179 | case SP_RUNE: |
1169 | success = write_rune (op, caster, spell_ob, dir, stringarg); |
1180 | success = write_rune (op, caster, spell_ob, dir, spellparam); |
1170 | break; |
1181 | break; |
1171 | |
1182 | |
1172 | case SP_MAKE_MARK: |
1183 | case SP_MAKE_MARK: |
1173 | success = write_mark (op, spell_ob, stringarg); |
1184 | success = write_mark (op, spell_ob, spellparam); |
1174 | break; |
1185 | break; |
1175 | |
1186 | |
1176 | case SP_BOLT: |
1187 | case SP_BOLT: |
1177 | success = fire_bolt (op, caster, dir, spell_ob, skill); |
1188 | success = fire_bolt (op, caster, dir, spell_ob, skill); |
1178 | break; |
1189 | break; |
… | |
… | |
1207 | |
1218 | |
1208 | case SP_DIMENSION_DOOR: |
1219 | case SP_DIMENSION_DOOR: |
1209 | /* dimension door needs the actual caster, because that is what is |
1220 | /* dimension door needs the actual caster, because that is what is |
1210 | * moved. |
1221 | * moved. |
1211 | */ |
1222 | */ |
1212 | success = dimension_door (op, caster, spell_ob, dir); |
1223 | success = dimension_door (op, caster, spell_ob, dir, spellparam); |
1213 | break; |
1224 | break; |
1214 | |
1225 | |
1215 | case SP_MAGIC_MAPPING: |
1226 | case SP_MAGIC_MAPPING: |
1216 | if (op->type == PLAYER) |
1227 | if (op->type == PLAYER) |
1217 | { |
1228 | { |
… | |
… | |
1250 | case SP_HEALING: |
1261 | case SP_HEALING: |
1251 | success = cast_heal (op, caster, spell_ob, dir); |
1262 | success = cast_heal (op, caster, spell_ob, dir); |
1252 | break; |
1263 | break; |
1253 | |
1264 | |
1254 | case SP_CREATE_FOOD: |
1265 | case SP_CREATE_FOOD: |
1255 | success = cast_create_food (op, caster, spell_ob, dir, stringarg); |
1266 | success = cast_create_food (op, caster, spell_ob, dir, spellparam); |
1256 | break; |
1267 | break; |
1257 | |
1268 | |
1258 | case SP_EARTH_TO_DUST: |
1269 | case SP_EARTH_TO_DUST: |
1259 | success = cast_earth_to_dust (op, caster, spell_ob); |
1270 | success = cast_earth_to_dust (op, caster, spell_ob); |
1260 | break; |
1271 | break; |
… | |
… | |
1270 | case SP_CURSE: |
1281 | case SP_CURSE: |
1271 | success = cast_curse (op, caster, spell_ob, dir); |
1282 | success = cast_curse (op, caster, spell_ob, dir); |
1272 | break; |
1283 | break; |
1273 | |
1284 | |
1274 | case SP_SUMMON_MONSTER: |
1285 | case SP_SUMMON_MONSTER: |
1275 | success = summon_object (op, caster, spell_ob, dir, stringarg); |
1286 | success = summon_object (op, caster, spell_ob, dir, spellparam); |
1276 | break; |
1287 | break; |
1277 | |
1288 | |
1278 | case SP_CHARGING: |
1289 | case SP_CHARGING: |
1279 | success = recharge (op, caster, spell_ob); |
1290 | success = recharge (op, caster, spell_ob); |
1280 | break; |
1291 | break; |
… | |
… | |
1334 | /* in rune.c */ |
1345 | /* in rune.c */ |
1335 | success = dispel_rune (op, caster, spell_ob, skill, dir); |
1346 | success = dispel_rune (op, caster, spell_ob, skill, dir); |
1336 | break; |
1347 | break; |
1337 | |
1348 | |
1338 | case SP_CREATE_MISSILE: |
1349 | case SP_CREATE_MISSILE: |
1339 | success = cast_create_missile (op, caster, spell_ob, dir, stringarg); |
1350 | success = cast_create_missile (op, caster, spell_ob, dir, spellparam); |
1340 | break; |
1351 | break; |
1341 | |
1352 | |
1342 | case SP_CONSECRATE: |
1353 | case SP_CONSECRATE: |
1343 | success = cast_consecrate (op, caster, spell_ob); |
1354 | success = cast_consecrate (op, caster, spell_ob); |
1344 | break; |
1355 | break; |
… | |
… | |
1366 | case SP_AURA: |
1377 | case SP_AURA: |
1367 | success = create_aura (op, caster, spell_ob); |
1378 | success = create_aura (op, caster, spell_ob); |
1368 | break; |
1379 | break; |
1369 | |
1380 | |
1370 | case SP_PARTY_SPELL: |
1381 | case SP_PARTY_SPELL: |
1371 | success = cast_party_spell (op, caster, dir, spell_ob, stringarg); |
1382 | success = cast_party_spell (op, caster, dir, spell_ob, spellparam); |
1372 | break; |
1383 | break; |
1373 | |
1384 | |
1374 | default: |
1385 | default: |
1375 | LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); |
1386 | LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); |
1376 | } |
1387 | } |
… | |
… | |
1472 | |
1483 | |
1473 | case SP_MAGIC_MISSILE: |
1484 | case SP_MAGIC_MISSILE: |
1474 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1485 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1475 | { |
1486 | { |
1476 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1487 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1477 | |
|
|
1478 | if (!spell->destroyed ()) |
|
|
1479 | spell->destroy (); |
1488 | spell->destroy (); |
1480 | } |
1489 | } |
1481 | break; |
1490 | break; |
1482 | |
1491 | |
1483 | case SP_MOVING_BALL: |
1492 | case SP_MOVING_BALL: |
1484 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1493 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1485 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1494 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1486 | else if (victim->materialname) |
1495 | else if (victim->materialname) |
1487 | save_throw_object (victim, spell->attacktype, spell); |
1496 | save_throw_object (victim, spell->attacktype, spell); |
1488 | break; |
|
|
1489 | } |
|
|
1490 | } |
|
|
1491 | |
1497 | |
|
|
1498 | break; |
|
|
1499 | } |
|
|
1500 | } |
|
|
1501 | |
|
|
1502 | /** |
|
|
1503 | * This function will let a fireball explode at the position of |
|
|
1504 | * the victim with a specific maximum level. |
|
|
1505 | */ |
|
|
1506 | void |
|
|
1507 | create_exploding_ball_at (object *victim, int level) |
|
|
1508 | { |
|
|
1509 | object *ball = get_archetype (EXPLODING_FIREBALL); |
|
|
1510 | ball->dam_modifier = random_roll (1, level, victim, PREFER_LOW) / 5 + 1; |
|
|
1511 | ball->stats.maxhp = random_roll (1, level, victim, PREFER_LOW) / 10 + 2; |
|
|
1512 | ball->insert_at (victim); |
|
|
1513 | } |