1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | 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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | #include <spells.h> |
27 | #include <spells.h> |
27 | #include <object.h> |
28 | #include <object.h> |
28 | #include <errno.h> |
29 | #include <errno.h> |
29 | #ifndef __CEXTRACT__ |
|
|
30 | # include <sproto.h> |
30 | #include <sproto.h> |
31 | #endif |
|
|
32 | #include <sounds.h> |
31 | #include <sounds.h> |
33 | |
32 | |
34 | extern char *spell_mapping[]; |
33 | extern char *spell_mapping[]; |
35 | |
34 | |
36 | /* This returns a random spell from 'ob'. If skill is set, then |
35 | /* This returns a random spell from 'ob'. If skill is set, then |
… | |
… | |
151 | } |
150 | } |
152 | |
151 | |
153 | /* pretty basic function - basically just takes |
152 | /* pretty basic function - basically just takes |
154 | * an object, sets the x,y, and calls insert_ob_in_map |
153 | * an object, sets the x,y, and calls insert_ob_in_map |
155 | */ |
154 | */ |
156 | |
|
|
157 | void |
155 | void |
158 | spell_effect (object *spob, int x, int y, maptile *map, object *originator) |
156 | spell_effect (object *spob, int x, int y, maptile *map, object *originator) |
159 | { |
157 | { |
160 | |
|
|
161 | if (spob->other_arch != NULL) |
158 | if (spob->other_arch) |
162 | { |
159 | map->insert (arch_to_object (spob->other_arch), x, y, originator); |
163 | object *effect = arch_to_object (spob->other_arch); |
|
|
164 | |
|
|
165 | effect->x = x; |
|
|
166 | effect->y = y; |
|
|
167 | |
|
|
168 | insert_ob_in_map (effect, map, originator, 0); |
|
|
169 | } |
|
|
170 | } |
160 | } |
171 | |
161 | |
172 | /* |
162 | /* |
173 | * This function takes a caster and spell and presents the |
163 | * This function takes a caster and spell and presents the |
174 | * effective level the caster needs to be to cast the spell. |
164 | * effective level the caster needs to be to cast the spell. |
175 | * basically, it just adjusts the spell->level with attuned/repelled |
165 | * basically, it just adjusts the spell->level with attuned/repelled |
176 | * spellpaths. Was called path_level_mod |
166 | * spellpaths. Was called path_level_mod. |
177 | * |
167 | * |
178 | * caster is person casting hte spell. |
168 | * caster is person casting the spell. |
179 | * spell is the spell object. |
169 | * spell is the spell object. |
180 | * Returns modified level. |
170 | * Returns modified level. |
181 | */ |
171 | */ |
182 | int |
172 | int |
183 | min_casting_level (object *caster, object *spell) |
173 | min_casting_level (object *caster, object *spell) |
184 | { |
174 | { |
185 | int new_level; |
175 | int new_level; |
186 | |
176 | |
187 | if (caster->path_denied & spell->path_attuned) |
177 | if (caster->path_denied & spell->path_attuned) |
188 | { |
|
|
189 | /* This case is not a bug, just the fact that this function is |
|
|
190 | * usually called BEFORE checking for path_deny. -AV |
|
|
191 | */ |
|
|
192 | #if 0 |
|
|
193 | LOG (llevError, "BUG: path_level_mod (arch %s, name %s): casting denied " "spell\n", caster->arch->name, caster->name); |
|
|
194 | #endif |
|
|
195 | return 1; |
178 | return 1; |
196 | } |
179 | |
197 | new_level = spell->level |
180 | new_level = spell->level |
198 | + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); |
181 | + (caster->path_repelled & spell->path_attuned ? +2 : 0) |
199 | return (new_level < 1) ? 1 : new_level; |
182 | + (caster->path_attuned & spell->path_attuned ? -2 : 0); |
200 | } |
|
|
201 | |
183 | |
|
|
184 | return max (1, new_level); |
|
|
185 | } |
202 | |
186 | |
203 | /* This function returns the effective level the spell |
187 | /* This function returns the effective level the spell |
204 | * is being cast at. |
188 | * is being cast at. |
205 | * Note that I changed the repelled/attuned bonus to 2 from 5. |
189 | * Note that I changed the repelled/attuned bonus to 2 from 5. |
206 | * This is because the new code compares casting_level against |
190 | * This is because the new code compares casting_level against |
… | |
… | |
212 | { |
196 | { |
213 | int level = caster->level; |
197 | int level = caster->level; |
214 | |
198 | |
215 | /* If this is a player, try to find the matching skill */ |
199 | /* If this is a player, try to find the matching skill */ |
216 | if (caster->type == PLAYER && spell->skill) |
200 | if (caster->type == PLAYER && spell->skill) |
217 | { |
|
|
218 | int i; |
|
|
219 | |
|
|
220 | for (i = 0; i < NUM_SKILLS; i++) |
201 | for (int i = 0; i < NUM_SKILLS; i++) |
221 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
202 | if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) |
222 | { |
203 | { |
223 | level = caster->contr->last_skill_ob[i]->level; |
204 | level = caster->contr->last_skill_ob[i]->level; |
224 | break; |
205 | break; |
225 | } |
206 | } |
226 | } |
|
|
227 | |
207 | |
228 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
208 | /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ |
229 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
209 | if (caster->type == ROD && caster->env && caster->env->type == PLAYER) |
230 | { |
210 | { |
231 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
211 | object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); |
… | |
… | |
240 | /* Always make this at least 1. If this is zero, we get divide by zero |
220 | /* Always make this at least 1. If this is zero, we get divide by zero |
241 | * errors in various places. |
221 | * errors in various places. |
242 | */ |
222 | */ |
243 | if (level < 1) |
223 | if (level < 1) |
244 | level = 1; |
224 | level = 1; |
|
|
225 | |
245 | return level; |
226 | return level; |
246 | } |
227 | } |
247 | |
228 | |
248 | /* The following function scales the spellpoint cost of |
229 | /* The following function scales the spellpoint cost of |
249 | * a spell by it's increased effectiveness. Some of the |
230 | * a spell by it's increased effectiveness. Some of the |
… | |
… | |
450 | { |
431 | { |
451 | object *op; |
432 | object *op; |
452 | |
433 | |
453 | if (OUT_OF_REAL_MAP (m, x, y)) |
434 | if (OUT_OF_REAL_MAP (m, x, y)) |
454 | return 0; |
435 | return 0; |
455 | for (op = get_map_ob (m, x, y); op != NULL; op = op->above) |
436 | for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above) |
456 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) && (!QUERY_FLAG (op, FLAG_ALIVE) || |
437 | if (QUERY_FLAG (op, FLAG_REFL_SPELL) |
457 | sp_op->type == LIGHTNING || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
438 | && (!QUERY_FLAG (op, FLAG_ALIVE) |
|
|
439 | || (rndm (0, 99)) < 90 - (sp_op->level / 10))) |
458 | return 1; |
440 | return 1; |
459 | |
441 | |
460 | return 0; |
442 | return 0; |
461 | } |
443 | } |
462 | |
444 | |
… | |
… | |
479 | { |
461 | { |
480 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
462 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
481 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
463 | new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); |
482 | dir = 0; |
464 | dir = 0; |
483 | } |
465 | } |
484 | new_op->x = op->x + freearr_x[dir]; |
466 | |
485 | new_op->y = op->y + freearr_y[dir]; |
467 | op->map->insert (new_op, |
486 | if (dir == 0) |
468 | op->x + freearr_x[dir], op->y + freearr_y[dir], |
487 | insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); |
469 | op, |
488 | else |
470 | dir ? 0 : INS_BELOW_ORIGINATOR); |
489 | insert_ob_in_map (new_op, op->map, op, 0); |
471 | |
490 | return dir; |
472 | return dir; |
491 | } |
473 | } |
492 | |
474 | |
493 | /* Returns true if it is ok to put spell *op on the space/may provided. |
475 | /* Returns true if it is ok to put spell *op on the space/may provided. |
494 | * immune_stop is basically the attacktype of the spell (why |
476 | * immune_stop is basically the attacktype of the spell (why |
… | |
… | |
496 | * has the AT_MAGIC bit set, and there is a counterwall |
478 | * has the AT_MAGIC bit set, and there is a counterwall |
497 | * on the space, the object doesn't get placed. if immune stop |
479 | * on the space, the object doesn't get placed. if immune stop |
498 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
480 | * does not have AT_MAGIC, then counterwalls do not effect the spell. |
499 | * |
481 | * |
500 | */ |
482 | */ |
501 | |
|
|
502 | int |
483 | int |
503 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
484 | ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) |
504 | { |
485 | { |
505 | object *tmp; |
486 | if (!xy_normalise (m, x, y)) |
506 | int mflags; |
|
|
507 | maptile *mp; |
|
|
508 | |
|
|
509 | mp = m; |
|
|
510 | mflags = get_map_flags (m, &mp, x, y, &x, &y); |
|
|
511 | |
|
|
512 | if (mflags & P_OUT_OF_MAP) |
|
|
513 | return 0; |
487 | return 0; |
514 | |
488 | |
515 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) |
489 | mapspace &ms = m->at (x, y); |
|
|
490 | |
|
|
491 | if (OB_TYPE_MOVE_BLOCK (op, ms.move_block)) |
516 | return 0; |
492 | return 0; |
517 | |
493 | |
518 | for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) |
494 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
519 | { |
495 | { |
520 | /* If there is a counterspell on the space, and this |
496 | /* If there is a counterspell on the space, and this |
521 | * object is using magic, don't progress. I believe we could |
497 | * object is using magic, don't progress. I believe we could |
522 | * leave this out and let in progress, and other areas of the code |
498 | * leave this out and let in progress, and other areas of the code |
523 | * will then remove it, but that would seem to to use more |
499 | * will then remove it, but that would seem to to use more |
… | |
… | |
546 | * playability reasons. |
522 | * playability reasons. |
547 | */ |
523 | */ |
548 | if (tmp->arch == op->arch |
524 | if (tmp->arch == op->arch |
549 | && tmp->type == op->type |
525 | && tmp->type == op->type |
550 | && tmp->subtype == op->subtype |
526 | && tmp->subtype == op->subtype |
|
|
527 | && tmp->owner == op->owner |
551 | && tmp->owner == op->owner && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
528 | && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) |
552 | { |
529 | { |
553 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
530 | tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); |
554 | tmp->range = MAX (tmp->range, op->range); |
531 | tmp->range = MAX (tmp->range, op->range); |
555 | tmp->duration = MAX (tmp->duration, op->duration); |
532 | tmp->duration = MAX (tmp->duration, op->duration); |
556 | return 0; |
533 | return 0; |
… | |
… | |
558 | |
535 | |
559 | /* Perhaps we should also put checks in for no magic and unholy |
536 | /* Perhaps we should also put checks in for no magic and unholy |
560 | * ground to prevent it from moving along? |
537 | * ground to prevent it from moving along? |
561 | */ |
538 | */ |
562 | } |
539 | } |
|
|
540 | |
563 | /* If it passes the above tests, it must be OK */ |
541 | /* If it passes the above tests, it must be OK */ |
564 | return 1; |
542 | return 1; |
565 | } |
543 | } |
566 | |
544 | |
567 | /* fire_arch_from_position: fires an archetype. |
545 | /* fire_arch_from_position: fires an archetype. |
… | |
… | |
598 | return 0; |
576 | return 0; |
599 | |
577 | |
600 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
578 | if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) |
601 | { |
579 | { |
602 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
580 | new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); |
603 | free_object (tmp); |
581 | tmp->destroy (); |
604 | return 0; |
582 | return 0; |
605 | } |
583 | } |
606 | |
|
|
607 | |
|
|
608 | |
584 | |
609 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
585 | tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); |
610 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
586 | tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); |
611 | /* code in time.c uses food for some things, duration for others */ |
587 | /* code in time.c uses food for some things, duration for others */ |
612 | tmp->stats.food = tmp->duration; |
588 | tmp->stats.food = tmp->duration; |
613 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
589 | tmp->range = spell->range + SP_level_range_adjust (caster, spell); |
614 | tmp->attacktype = spell->attacktype; |
590 | tmp->attacktype = spell->attacktype; |
615 | tmp->x = x; |
591 | tmp->x = x; |
616 | tmp->y = y; |
592 | tmp->y = y; |
617 | tmp->direction = dir; |
593 | tmp->direction = dir; |
618 | if (get_owner (op) != NULL) |
594 | if (op->owner != NULL) |
619 | copy_owner (tmp, op); |
595 | tmp->set_owner (op); |
620 | else |
596 | else |
621 | set_owner (tmp, op); |
597 | tmp->set_owner (op); |
622 | tmp->level = caster_level (caster, spell); |
598 | tmp->level = caster_level (caster, spell); |
623 | set_spell_skill (op, caster, spell, tmp); |
599 | set_spell_skill (op, caster, spell, tmp); |
624 | |
600 | |
625 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
601 | /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ |
626 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
602 | if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) |
… | |
… | |
629 | return 0; |
605 | return 0; |
630 | } |
606 | } |
631 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
607 | if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) |
632 | SET_ANIMATION (tmp, dir); |
608 | SET_ANIMATION (tmp, dir); |
633 | |
609 | |
634 | if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) |
610 | if ((tmp = insert_ob_in_map (tmp, m, op, 0))) |
635 | return 1; |
|
|
636 | |
|
|
637 | move_spell_effect (tmp); |
611 | move_spell_effect (tmp); |
638 | |
612 | |
639 | return 1; |
613 | return 1; |
640 | } |
614 | } |
641 | |
|
|
642 | |
|
|
643 | |
615 | |
644 | /***************************************************************************** |
616 | /***************************************************************************** |
645 | * |
617 | * |
646 | * Code related to rods - perhaps better located in another file? |
618 | * Code related to rods - perhaps better located in another file? |
647 | * |
619 | * |
648 | ****************************************************************************/ |
620 | ****************************************************************************/ |
649 | |
|
|
650 | void |
621 | void |
651 | regenerate_rod (object *rod) |
622 | regenerate_rod (object *rod) |
652 | { |
623 | { |
653 | if (rod->stats.hp < rod->stats.maxhp) |
624 | if (rod->stats.hp < rod->stats.maxhp) |
654 | { |
625 | { |
… | |
… | |
688 | * we then make the owner of this object the target. |
659 | * we then make the owner of this object the target. |
689 | * The owner could very well be no where near op. |
660 | * The owner could very well be no where near op. |
690 | */ |
661 | */ |
691 | if (op->type != PLAYER && op->type != RUNE) |
662 | if (op->type != PLAYER && op->type != RUNE) |
692 | { |
663 | { |
693 | tmp = get_owner (op); |
664 | tmp = op->owner; |
694 | /* If the owner does not exist, or is not a monster, than apply the spell |
665 | /* If the owner does not exist, or is not a monster, than apply the spell |
695 | * to the caster. |
666 | * to the caster. |
696 | */ |
667 | */ |
697 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
668 | if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) |
698 | tmp = op; |
669 | tmp = op; |
… | |
… | |
704 | y = op->y + freearr_y[dir]; |
675 | y = op->y + freearr_y[dir]; |
705 | |
676 | |
706 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
677 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
707 | |
678 | |
708 | if (mflags & P_OUT_OF_MAP) |
679 | if (mflags & P_OUT_OF_MAP) |
709 | tmp = NULL; |
680 | tmp = 0; |
710 | else |
681 | else |
711 | { |
682 | tmp = m->at (x, y).player (); |
712 | for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) |
|
|
713 | if (tmp->type == PLAYER) |
|
|
714 | break; |
|
|
715 | } |
|
|
716 | } |
683 | } |
|
|
684 | |
717 | /* didn't find a player there, look in current square for a player */ |
685 | /* didn't find a player there, look in current square for a player */ |
718 | if (tmp == NULL) |
686 | if (!tmp) |
719 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
687 | tmp = op->ms ().player (); |
720 | { |
|
|
721 | if (tmp->type == PLAYER) |
|
|
722 | break; |
|
|
723 | } |
|
|
724 | |
688 | |
725 | return tmp; |
689 | return tmp; |
726 | } |
690 | } |
727 | |
691 | |
728 | |
692 | |
… | |
… | |
760 | mp = m; |
724 | mp = m; |
761 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
725 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
762 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
726 | if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) |
763 | continue; |
727 | continue; |
764 | |
728 | |
765 | tmp = get_map_ob (mp, nx, ny); |
729 | tmp = GET_MAP_OB (mp, nx, ny); |
766 | |
730 | |
767 | while (tmp != NULL && (((owner_type == PLAYER && |
731 | while (tmp != NULL && (((owner_type == PLAYER && |
768 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
732 | !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || |
769 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
733 | (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) |
770 | tmp = tmp->above; |
734 | tmp = tmp->above; |
… | |
… | |
825 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
789 | create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); |
826 | |
790 | |
827 | insert_ob_in_map (head, op->map, op, 0); |
791 | insert_ob_in_map (head, op->map, op, 0); |
828 | |
792 | |
829 | /* thought it'd be cool to insert a burnout, too. */ |
793 | /* thought it'd be cool to insert a burnout, too. */ |
830 | tmp = get_archetype ("burnout"); |
794 | op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op); |
831 | tmp->map = op->map; |
|
|
832 | tmp->x = op->x + freearr_x[dir]; |
|
|
833 | tmp->y = op->y + freearr_y[dir]; |
|
|
834 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
835 | } |
795 | } |
836 | } |
796 | } |
837 | |
797 | |
838 | /* peterm: function which summons hostile monsters and |
798 | /* peterm: function which summons hostile monsters and |
839 | * places them in nearby squares. |
799 | * places them in nearby squares. |
… | |
… | |
966 | if (failure <= -20 && failure > -40) /* wonder */ |
926 | if (failure <= -20 && failure > -40) /* wonder */ |
967 | { |
927 | { |
968 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
928 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); |
969 | tmp = get_archetype (SPELL_WONDER); |
929 | tmp = get_archetype (SPELL_WONDER); |
970 | cast_cone (op, op, 0, tmp); |
930 | cast_cone (op, op, 0, tmp); |
971 | free_object (tmp); |
931 | tmp->destroy (); |
972 | } |
932 | } |
973 | |
933 | |
974 | else if (failure <= -40 && failure > -60) /* confusion */ |
934 | else if (failure <= -40 && failure > -60) /* confusion */ |
975 | { |
935 | { |
976 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
936 | new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); |
… | |
… | |
1010 | if (failure <= -20 && failure > -40) /* wonder */ |
970 | if (failure <= -20 && failure > -40) /* wonder */ |
1011 | { |
971 | { |
1012 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
972 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); |
1013 | tmp = get_archetype (SPELL_WONDER); |
973 | tmp = get_archetype (SPELL_WONDER); |
1014 | cast_cone (op, op, 0, tmp); |
974 | cast_cone (op, op, 0, tmp); |
1015 | free_object (tmp); |
975 | tmp->destroy (); |
1016 | } |
976 | } |
1017 | |
977 | |
1018 | else if (failure <= -40 && failure > -60) /* confusion */ |
978 | else if (failure <= -40 && failure > -60) /* confusion */ |
1019 | { |
979 | { |
1020 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
980 | new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); |
… | |
… | |
1039 | else |
999 | else |
1040 | { |
1000 | { |
1041 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
1001 | new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); |
1042 | tmp = get_archetype (LOOSE_MANA); |
1002 | tmp = get_archetype (LOOSE_MANA); |
1043 | tmp->level = skill->level; |
1003 | tmp->level = skill->level; |
1044 | tmp->x = op->x; |
|
|
1045 | tmp->y = op->y; |
|
|
1046 | |
1004 | |
1047 | /* increase the area of destruction a little for more powerful spells */ |
1005 | /* increase the area of destruction a little for more powerful spells */ |
1048 | tmp->range += isqrt (power); |
1006 | tmp->range += isqrt (power); |
1049 | |
1007 | |
1050 | if (power > 25) |
1008 | if (power > 25) |
1051 | tmp->stats.dam = 25 + isqrt (power); |
1009 | tmp->stats.dam = 25 + isqrt (power); |
1052 | else |
1010 | else |
1053 | tmp->stats.dam = power; /* nasty recoils! */ |
1011 | tmp->stats.dam = power; /* nasty recoils! */ |
1054 | |
1012 | |
1055 | tmp->stats.maxhp = tmp->count; |
1013 | tmp->stats.maxhp = tmp->count; |
1056 | insert_ob_in_map (tmp, op->map, NULL, 0); |
1014 | |
|
|
1015 | tmp->insert_at (op); |
1057 | } |
1016 | } |
1058 | } |
1017 | } |
1059 | } |
1018 | } |
1060 | |
1019 | |
1061 | int |
1020 | int |
… | |
… | |
1075 | /* Always cast spell on caster */ |
1034 | /* Always cast spell on caster */ |
1076 | success = cast_spell (op, caster, dir, spell, stringarg); |
1035 | success = cast_spell (op, caster, dir, spell, stringarg); |
1077 | |
1036 | |
1078 | if (caster->contr->party == NULL) |
1037 | if (caster->contr->party == NULL) |
1079 | { |
1038 | { |
1080 | remove_ob (spell); |
1039 | spell->remove (); |
1081 | return success; |
1040 | return success; |
1082 | } |
1041 | } |
1083 | for (pl = first_player; pl != NULL; pl = pl->next) |
1042 | for_all_players (pl) |
1084 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1043 | if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) |
1085 | { |
1044 | { |
1086 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1045 | cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); |
1087 | } |
1046 | } |
1088 | remove_ob (spell); |
1047 | spell->remove (); |
1089 | return success; |
1048 | return success; |
1090 | } |
1049 | } |
1091 | |
1050 | |
1092 | /* This is where the main dispatch when someone casts a spell. |
1051 | /* This is where the main dispatch when someone casts a spell. |
1093 | * |
1052 | * |
… | |
… | |
1143 | } |
1102 | } |
1144 | |
1103 | |
1145 | /* if caster is a spell casting object, this normally shouldn't be |
1104 | /* if caster is a spell casting object, this normally shouldn't be |
1146 | * an issue, because they don't have any spellpaths set up. |
1105 | * an issue, because they don't have any spellpaths set up. |
1147 | */ |
1106 | */ |
1148 | if (caster->path_denied & spell_ob->path_attuned) |
1107 | if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST)) |
1149 | { |
1108 | { |
1150 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1109 | new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); |
1151 | return 0; |
1110 | return 0; |
1152 | } |
1111 | } |
1153 | |
1112 | |
… | |
… | |
1186 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1145 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) |
1187 | { |
1146 | { |
1188 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1147 | new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); |
1189 | return 0; |
1148 | return 0; |
1190 | } |
1149 | } |
|
|
1150 | |
1191 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1151 | if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && |
1192 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1152 | SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) |
1193 | { |
1153 | { |
1194 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1154 | if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - |
1195 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
1155 | 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) |
… | |
… | |
1208 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1168 | if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < |
1209 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1169 | (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) |
1210 | { |
1170 | { |
1211 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1171 | play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); |
1212 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
1172 | new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); |
|
|
1173 | |
1213 | if (settings.casting_time == TRUE) |
1174 | if (settings.casting_time == TRUE) |
1214 | { |
|
|
1215 | op->casting_time = -1; |
1175 | op->casting_time = -1; |
1216 | } |
1176 | |
1217 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1177 | op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); |
1218 | return 0; |
1178 | return 0; |
1219 | } |
1179 | } |
1220 | else if (spell_ob->stats.sp) |
1180 | else if (spell_ob->stats.sp) |
1221 | { |
1181 | { |
… | |
… | |
1288 | * spell is actually cast, it knows about the stringarg. |
1248 | * spell is actually cast, it knows about the stringarg. |
1289 | * necessary for the invoke command spells. |
1249 | * necessary for the invoke command spells. |
1290 | */ |
1250 | */ |
1291 | if (stringarg) |
1251 | if (stringarg) |
1292 | { |
1252 | { |
1293 | op->spellarg = strdup_local (stringarg); |
1253 | op->spellarg = strdup (stringarg); |
1294 | } |
1254 | } |
1295 | else |
1255 | else |
1296 | op->spellarg = NULL; |
1256 | op->spellarg = NULL; |
1297 | return 0; |
1257 | return 0; |
1298 | } |
1258 | } |
… | |
… | |
1691 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1651 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1692 | { |
1652 | { |
1693 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1653 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1694 | |
1654 | |
1695 | if (!spell->destroyed ()) |
1655 | if (!spell->destroyed ()) |
1696 | { |
1656 | spell->destroy (); |
1697 | remove_ob (spell); |
|
|
1698 | free_object (spell); |
|
|
1699 | } |
|
|
1700 | } |
1657 | } |
1701 | break; |
1658 | break; |
1702 | |
1659 | |
1703 | case SP_MOVING_BALL: |
1660 | case SP_MOVING_BALL: |
1704 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1661 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
1705 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1662 | hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); |
1706 | else if (victim->material || victim->materialname) |
1663 | else if (victim->materialname) |
1707 | save_throw_object (victim, spell->attacktype, spell); |
1664 | save_throw_object (victim, spell->attacktype, spell); |
1708 | break; |
1665 | break; |
1709 | } |
1666 | } |
1710 | } |
1667 | } |