ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/spell_util.C
(Generate patch)

Comparing deliantra/server/server/spell_util.C (file contents):
Revision 1.17 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.41 by root, Sat Apr 28 17:51:58 2007 UTC

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
34extern char *spell_mapping[]; 33extern 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
157void 155void
158spell_effect (object *spob, int x, int y, maptile *map, object *originator) 156spell_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 */
182int 172int
183min_casting_level (object *caster, object *spell) 173min_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
207 * min_caster_level, so the difference is effectively 4 191 * min_caster_level, so the difference is effectively 4
208 */ 192 */
209
210int 193int
211caster_level (object *caster, object *spell) 194caster_level (object *caster, object *spell)
212{ 195{
213 int level = caster->level; 196 int level = caster->level;
214 197
215 /* If this is a player, try to find the matching skill */ 198 /* If this is a player, try to find the matching skill */
216 if (caster->type == PLAYER && spell->skill) 199 if (caster->type == PLAYER && spell->skill)
217 {
218 int i;
219
220 for (i = 0; i < NUM_SKILLS; i++) 200 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) 201 if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill)
222 { 202 {
223 level = caster->contr->last_skill_ob[i]->level; 203 level = caster->contr->last_skill_ob[i]->level;
224 break; 204 break;
225 } 205 }
226 }
227 206
228 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ 207 /* 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) 208 if (caster->type == ROD && caster->env && caster->env->type == PLAYER)
230 { 209 {
231 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); 210 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM);
233 212
234 level = MIN (level, sk_level + level / 10 + 1); 213 level = MIN (level, sk_level + level / 10 + 1);
235 } 214 }
236 215
237 /* Got valid caster level. Now adjust for attunement */ 216 /* Got valid caster level. Now adjust for attunement */
238 level += ((caster->path_repelled & spell->path_attuned) ? -2 : 0) + ((caster->path_attuned & spell->path_attuned) ? 2 : 0); 217 level += caster->path_repelled & spell->path_attuned ? -2 : 0;
218 level += caster->path_attuned & spell->path_attuned ? +2 : 0;
239 219
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)
244 level = 1;
245 return level; 223 return max (level, 1);
246} 224}
247 225
248/* The following function scales the spellpoint cost of 226/* The following function scales the spellpoint cost of
249 * a spell by it's increased effectiveness. Some of the 227 * a spell by it's increased effectiveness. Some of the
250 * lower level spells become incredibly vicious at high 228 * lower level spells become incredibly vicious at high
450{ 428{
451 object *op; 429 object *op;
452 430
453 if (OUT_OF_REAL_MAP (m, x, y)) 431 if (OUT_OF_REAL_MAP (m, x, y))
454 return 0; 432 return 0;
455 for (op = get_map_ob (m, x, y); op != NULL; op = op->above) 433 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) || 434 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
457 sp_op->type == LIGHTNING || (rndm (0, 99)) < 90 - (sp_op->level / 10))) 435 && (!QUERY_FLAG (op, FLAG_ALIVE)
436 || (rndm (0, 99)) < 90 - (sp_op->level / 10)))
458 return 1; 437 return 1;
459 438
460 return 0; 439 return 0;
461} 440}
462 441
479 { 458 {
480 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 459 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."); 460 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
482 dir = 0; 461 dir = 0;
483 } 462 }
484 new_op->x = op->x + freearr_x[dir]; 463
485 new_op->y = op->y + freearr_y[dir]; 464 op->map->insert (new_op,
486 if (dir == 0) 465 op->x + freearr_x[dir], op->y + freearr_y[dir],
487 insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); 466 op,
488 else 467 dir ? 0 : INS_BELOW_ORIGINATOR);
489 insert_ob_in_map (new_op, op->map, op, 0); 468
490 return dir; 469 return dir;
491} 470}
492 471
493/* Returns true if it is ok to put spell *op on the space/may provided. 472/* 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 473 * immune_stop is basically the attacktype of the spell (why
496 * has the AT_MAGIC bit set, and there is a counterwall 475 * has the AT_MAGIC bit set, and there is a counterwall
497 * on the space, the object doesn't get placed. if immune stop 476 * 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. 477 * does not have AT_MAGIC, then counterwalls do not effect the spell.
499 * 478 *
500 */ 479 */
501
502int 480int
503ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop) 481ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
504{ 482{
505 object *tmp; 483 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; 484 return 0;
514 485
515 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) 486 mapspace &ms = m->at (x, y);
487
488 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
516 return 0; 489 return 0;
517 490
518 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) 491 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
519 { 492 {
520 /* If there is a counterspell on the space, and this 493 /* If there is a counterspell on the space, and this
521 * object is using magic, don't progress. I believe we could 494 * 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 495 * 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 496 * will then remove it, but that would seem to to use more
524 * resources, and may not work as well if a player is standing 497 * resources, and may not work as well if a player is standing
525 * on top of a counterwall spell (may hit the player before being 498 * on top of a counterwall spell (may hit the player before being
526 * removed.) On the other hand, it may be more dramatic for the 499 * removed.) On the other hand, it may be more dramatic for the
527 * spell to actually hit the counterwall and be sucked up. 500 * spell to actually hit the counterwall and be sucked up.
528 */ 501 */
529 if ((tmp->attacktype & AT_COUNTERSPELL) && 502 if ((tmp->attacktype & AT_COUNTERSPELL)
530 (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && 503 && !QUERY_FLAG (tmp, FLAG_MONSTER)
531 (tmp->type != WEAPON) && (tmp->type != BOW) && (tmp->type != ARROW) && (tmp->type != GOLEM) && (immune_stop & AT_MAGIC)) 504 && (tmp->type != PLAYER)
505 && (tmp->type != WEAPON)
506 && (tmp->type != BOW)
507 && (tmp->type != ARROW)
508 && (tmp->type != GOLEM)
509 && !QUERY_FLAG (tmp, FLAG_IS_FLOOR) // XXX:
510 // we special case floor here because there
511 // are sometimes spell effect floors
512 // which are used to inflict damage
513 // (and those shouldn't go away from
514 // sanctuary) see also: permanent lava
515 && (immune_stop & AT_MAGIC))
532 return 0; 516 return 0;
533 517
534 /* This is to prevent 'out of control' spells. Basically, this 518 /* This is to prevent 'out of control' spells. Basically, this
535 * limits one spell effect per space per spell. This is definately 519 * limits one spell effect per space per spell. This is definately
536 * needed for performance reasons, and just for playability I believe. 520 * needed for performance reasons, and just for playability I believe.
546 * playability reasons. 530 * playability reasons.
547 */ 531 */
548 if (tmp->arch == op->arch 532 if (tmp->arch == op->arch
549 && tmp->type == op->type 533 && tmp->type == op->type
550 && tmp->subtype == op->subtype 534 && tmp->subtype == op->subtype
535 && tmp->owner == op->owner
551 && tmp->owner == op->owner && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 536 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
552 { 537 {
553 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); 538 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam);
554 tmp->range = MAX (tmp->range, op->range); 539 tmp->range = MAX (tmp->range, op->range);
555 tmp->duration = MAX (tmp->duration, op->duration); 540 tmp->duration = MAX (tmp->duration, op->duration);
556 return 0; 541 return 0;
558 543
559 /* Perhaps we should also put checks in for no magic and unholy 544 /* Perhaps we should also put checks in for no magic and unholy
560 * ground to prevent it from moving along? 545 * ground to prevent it from moving along?
561 */ 546 */
562 } 547 }
548
563 /* If it passes the above tests, it must be OK */ 549 /* If it passes the above tests, it must be OK */
564 return 1; 550 return 1;
565} 551}
566 552
567/* fire_arch_from_position: fires an archetype. 553/* fire_arch_from_position: fires an archetype.
598 return 0; 584 return 0;
599 585
600 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) 586 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y)))
601 { 587 {
602 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); 588 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n");
603 free_object (tmp); 589 tmp->destroy ();
604 return 0; 590 return 0;
605 } 591 }
606
607
608 592
609 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 593 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
610 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); 594 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
611 /* code in time.c uses food for some things, duration for others */ 595 /* code in time.c uses food for some things, duration for others */
612 tmp->stats.food = tmp->duration; 596 tmp->stats.food = tmp->duration;
613 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 597 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
614 tmp->attacktype = spell->attacktype; 598 tmp->attacktype = spell->attacktype;
615 tmp->x = x; 599 tmp->x = x;
616 tmp->y = y; 600 tmp->y = y;
617 tmp->direction = dir; 601 tmp->direction = dir;
618 if (get_owner (op) != NULL) 602 if (op->owner != NULL)
619 copy_owner (tmp, op); 603 tmp->set_owner (op);
620 else 604 else
621 set_owner (tmp, op); 605 tmp->set_owner (op);
622 tmp->level = caster_level (caster, spell); 606 tmp->level = caster_level (caster, spell);
623 set_spell_skill (op, caster, spell, tmp); 607 set_spell_skill (op, caster, spell, tmp);
624 608
625 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 609 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
626 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 610 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
629 return 0; 613 return 0;
630 } 614 }
631 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 615 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
632 SET_ANIMATION (tmp, dir); 616 SET_ANIMATION (tmp, dir);
633 617
634 if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) 618 if ((tmp = insert_ob_in_map (tmp, m, op, 0)))
635 return 1;
636
637 move_spell_effect (tmp); 619 move_spell_effect (tmp);
638 620
639 return 1; 621 return 1;
640} 622}
641
642
643 623
644/***************************************************************************** 624/*****************************************************************************
645 * 625 *
646 * Code related to rods - perhaps better located in another file? 626 * Code related to rods - perhaps better located in another file?
647 * 627 *
648 ****************************************************************************/ 628 ****************************************************************************/
649
650void 629void
651regenerate_rod (object *rod) 630regenerate_rod (object *rod)
652{ 631{
653 if (rod->stats.hp < rod->stats.maxhp) 632 if (rod->stats.hp < rod->stats.maxhp)
654 { 633 {
663void 642void
664drain_rod_charge (object *rod) 643drain_rod_charge (object *rod)
665{ 644{
666 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST); 645 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST);
667} 646}
668
669
670
671 647
672/* this function is commonly used to find a friendly target for 648/* this function is commonly used to find a friendly target for
673 * spells such as heal or protection or armour 649 * spells such as heal or protection or armour
674 * op is what is looking for the target (which can be a player), 650 * op is what is looking for the target (which can be a player),
675 * dir is the direction we are looking in. Return object found, or 651 * dir is the direction we are looking in. Return object found, or
676 * NULL if no good object. 652 * NULL if no good object.
677 */ 653 */
678
679object * 654object *
680find_target_for_friendly_spell (object *op, int dir) 655find_target_for_friendly_spell (object *op, int dir)
681{ 656{
682 object *tmp; 657 object *tmp;
683 maptile *m;
684 sint16 x, y;
685 int mflags;
686 658
687 /* I don't really get this block - if op isn't a player or rune, 659 /* I don't really get this block - if op isn't a player or rune,
688 * we then make the owner of this object the target. 660 * we then make the owner of this object the target.
689 * The owner could very well be no where near op. 661 * The owner could very well be no where near op.
690 */ 662 */
691 if (op->type != PLAYER && op->type != RUNE) 663 if (op->type != PLAYER && op->type != RUNE)
692 { 664 {
693 tmp = get_owner (op); 665 tmp = op->owner;
694 /* If the owner does not exist, or is not a monster, than apply the spell 666 /* If the owner does not exist, or is not a monster, than apply the spell
695 * to the caster. 667 * to the caster.
696 */ 668 */
697 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) 669 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER))
698 tmp = op; 670 tmp = op;
699 } 671 }
700 else 672 else
701 { 673 {
702 m = op->map; 674 maptile *m = op->map;
703 x = op->x + freearr_x[dir]; 675 sint16 x = op->x + freearr_x[dir];
704 y = op->y + freearr_y[dir]; 676 sint16 y = op->y + freearr_y[dir];
705
706 mflags = get_map_flags (m, &m, x, y, &x, &y);
707
708 if (mflags & P_OUT_OF_MAP)
709 tmp = NULL;
710 else
711 { 677
712 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 678 tmp = xy_normalise (m, x, y)
713 if (tmp->type == PLAYER) 679 ? m->at (x, y).player ()
714 break; 680 : 0;
715 }
716 } 681 }
682
717 /* didn't find a player there, look in current square for a player */ 683 /* didn't find a player there, look in current square for a player */
718 if (tmp == NULL) 684 if (!tmp)
719 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 685 tmp = op->ms ().player ();
720 {
721 if (tmp->type == PLAYER)
722 break;
723 }
724 686
725 return tmp; 687 return tmp;
726} 688}
727 689
728 690
760 mp = m; 722 mp = m;
761 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 723 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
762 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) 724 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW))
763 continue; 725 continue;
764 726
765 tmp = get_map_ob (mp, nx, ny); 727 tmp = GET_MAP_OB (mp, nx, ny);
766 728
767 while (tmp != NULL && (((owner_type == PLAYER && 729 while (tmp != NULL && (((owner_type == PLAYER &&
768 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || 730 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) ||
769 (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) 731 (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude))))
770 tmp = tmp->above; 732 tmp = tmp->above;
773 return freedir[i]; 735 return freedir[i];
774 } 736 }
775 return -1; /* flag for "keep going the way you were" */ 737 return -1; /* flag for "keep going the way you were" */
776} 738}
777 739
778
779
780/* put_a_monster: puts a monster named monstername near by 740/* put_a_monster: puts a monster named monstername near by
781 * op. This creates the treasures for the monsters, and 741 * op. This creates the treasures for the monsters, and
782 * also deals with multipart monsters properly. 742 * also deals with multipart monsters properly.
783 */ 743 */
784
785void 744void
786put_a_monster (object *op, const char *monstername) 745put_a_monster (object *op, const char *monstername)
787{ 746{
788 object *tmp, *head = NULL, *prev = NULL; 747 object *tmp, *head = NULL, *prev = NULL;
789 archetype *at; 748 archetype *at;
825 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 784 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
826 785
827 insert_ob_in_map (head, op->map, op, 0); 786 insert_ob_in_map (head, op->map, op, 0);
828 787
829 /* thought it'd be cool to insert a burnout, too. */ 788 /* thought it'd be cool to insert a burnout, too. */
830 tmp = get_archetype ("burnout"); 789 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 } 790 }
836} 791}
837 792
838/* peterm: function which summons hostile monsters and 793/* peterm: function which summons hostile monsters and
839 * places them in nearby squares. 794 * places them in nearby squares.
866{ 821{
867 int attacktype; 822 int attacktype;
868 int face; 823 int face;
869} ATTACKS[22] = 824} ATTACKS[22] =
870{ 825{
871 {
872 AT_PHYSICAL, 0}, 826 { AT_PHYSICAL, 0},
873 {
874 AT_PHYSICAL, 0}, /*face = explosion */ 827 { AT_PHYSICAL, 0}, /*face = explosion */
875 {
876 AT_PHYSICAL, 0}, 828 { AT_PHYSICAL, 0},
877 {
878 AT_MAGIC, 1}, 829 { AT_MAGIC, 1},
879 {
880 AT_MAGIC, 1}, /* face = last-burnout */ 830 { AT_MAGIC, 1}, /* face = last-burnout */
881 {
882 AT_MAGIC, 1}, 831 { AT_MAGIC, 1},
883 {
884 AT_FIRE, 2}, 832 { AT_FIRE, 2},
885 {
886 AT_FIRE, 2}, /* face = fire.... */ 833 { AT_FIRE, 2}, /* face = fire.... */
887 {
888 AT_FIRE, 2}, 834 { AT_FIRE, 2},
889 {
890 AT_ELECTRICITY, 3}, 835 { AT_ELECTRICITY, 3},
891 {
892 AT_ELECTRICITY, 3}, /* ball_lightning */ 836 { AT_ELECTRICITY, 3}, /* ball_lightning */
893 {
894 AT_ELECTRICITY, 3}, 837 { AT_ELECTRICITY, 3},
895 {
896 AT_COLD, 4}, 838 { AT_COLD, 4},
897 {
898 AT_COLD, 4}, /* face=icestorm */ 839 { AT_COLD, 4}, /* face=icestorm */
899 {
900 AT_COLD, 4}, 840 { AT_COLD, 4},
901 {
902 AT_CONFUSION, 5}, 841 { AT_CONFUSION, 5},
903 {
904 AT_POISON, 7}, 842 { AT_POISON, 7},
905 {
906 AT_POISON, 7}, /* face = acid sphere. generator */ 843 { AT_POISON, 7}, /* face = acid sphere. generator */
907 {
908 AT_POISON, 7}, /* poisoncloud face */ 844 { AT_POISON, 7}, /* poisoncloud face */
909 {
910 AT_SLOW, 8}, 845 { AT_SLOW, 8},
911 {
912 AT_PARALYZE, 9}, 846 { AT_PARALYZE, 9},
913 {
914AT_FEAR, 10}}; 847 { AT_FEAR, 10},
915 848};
916
917 849
918/* shuffle_attack: peterm 850/* shuffle_attack: peterm
919 * This routine shuffles the attack of op to one of the 851 * This routine shuffles the attack of op to one of the
920 * ones in the list. It does this at random. It also 852 * ones in the list. It does this at random. It also
921 * chooses a face appropriate to the attack that is 853 * chooses a face appropriate to the attack that is
966 if (failure <= -20 && failure > -40) /* wonder */ 898 if (failure <= -20 && failure > -40) /* wonder */
967 { 899 {
968 new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); 900 new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname);
969 tmp = get_archetype (SPELL_WONDER); 901 tmp = get_archetype (SPELL_WONDER);
970 cast_cone (op, op, 0, tmp); 902 cast_cone (op, op, 0, tmp);
971 free_object (tmp); 903 tmp->destroy ();
972 } 904 }
973 905
974 else if (failure <= -40 && failure > -60) /* confusion */ 906 else if (failure <= -40 && failure > -60) /* confusion */
975 { 907 {
976 new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); 908 new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!");
1010 if (failure <= -20 && failure > -40) /* wonder */ 942 if (failure <= -20 && failure > -40) /* wonder */
1011 { 943 {
1012 new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); 944 new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect.");
1013 tmp = get_archetype (SPELL_WONDER); 945 tmp = get_archetype (SPELL_WONDER);
1014 cast_cone (op, op, 0, tmp); 946 cast_cone (op, op, 0, tmp);
1015 free_object (tmp); 947 tmp->destroy ();
1016 } 948 }
1017 949
1018 else if (failure <= -40 && failure > -60) /* confusion */ 950 else if (failure <= -40 && failure > -60) /* confusion */
1019 { 951 {
1020 new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); 952 new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!");
1039 else 971 else
1040 { 972 {
1041 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); 973 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!");
1042 tmp = get_archetype (LOOSE_MANA); 974 tmp = get_archetype (LOOSE_MANA);
1043 tmp->level = skill->level; 975 tmp->level = skill->level;
1044 tmp->x = op->x;
1045 tmp->y = op->y;
1046 976
1047 /* increase the area of destruction a little for more powerful spells */ 977 /* increase the area of destruction a little for more powerful spells */
1048 tmp->range += isqrt (power); 978 tmp->range += isqrt (power);
1049 979
1050 if (power > 25) 980 if (power > 25)
1051 tmp->stats.dam = 25 + isqrt (power); 981 tmp->stats.dam = 25 + isqrt (power);
1052 else 982 else
1053 tmp->stats.dam = power; /* nasty recoils! */ 983 tmp->stats.dam = power; /* nasty recoils! */
1054 984
1055 tmp->stats.maxhp = tmp->count; 985 tmp->stats.maxhp = tmp->count;
1056 insert_ob_in_map (tmp, op->map, NULL, 0); 986
987 tmp->insert_at (op);
1057 } 988 }
1058 } 989 }
1059} 990}
1060 991
1061int 992int
1062cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 993cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1063{ 994{
1064 int success; 995 int success;
1065 player *pl;
1066 object *spell; 996 object *spell;
1067 997
1068 if (!spell_ob->other_arch) 998 if (!spell_ob->other_arch)
1069 { 999 {
1070 LOG (llevError, "cast_party_spell: empty other arch\n"); 1000 LOG (llevError, "cast_party_spell: empty other arch\n");
1075 /* Always cast spell on caster */ 1005 /* Always cast spell on caster */
1076 success = cast_spell (op, caster, dir, spell, stringarg); 1006 success = cast_spell (op, caster, dir, spell, stringarg);
1077 1007
1078 if (caster->contr->party == NULL) 1008 if (caster->contr->party == NULL)
1079 { 1009 {
1080 remove_ob (spell); 1010 spell->remove ();
1081 return success; 1011 return success;
1082 } 1012 }
1083 for (pl = first_player; pl != NULL; pl = pl->next) 1013 for_all_players (pl)
1084 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) 1014 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster)))
1085 { 1015 {
1086 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); 1016 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1087 } 1017 }
1088 remove_ob (spell); 1018 spell->remove ();
1089 return success; 1019 return success;
1090} 1020}
1091 1021
1092/* This is where the main dispatch when someone casts a spell. 1022/* This is where the main dispatch when someone casts a spell.
1093 * 1023 *
1143 } 1073 }
1144 1074
1145 /* if caster is a spell casting object, this normally shouldn't be 1075 /* if caster is a spell casting object, this normally shouldn't be
1146 * an issue, because they don't have any spellpaths set up. 1076 * an issue, because they don't have any spellpaths set up.
1147 */ 1077 */
1148 if (caster->path_denied & spell_ob->path_attuned) 1078 if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST))
1149 { 1079 {
1150 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); 1080 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you.");
1151 return 0; 1081 return 0;
1152 } 1082 }
1153 1083
1186 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1116 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1187 { 1117 {
1188 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1118 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
1189 return 0; 1119 return 0;
1190 } 1120 }
1121
1191 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1122 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1192 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1123 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1193 { 1124 {
1194 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1125 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) 1126 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) < 1139 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])) 1140 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis]))
1210 { 1141 {
1211 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1142 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0);
1212 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); 1143 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell.");
1144
1213 if (settings.casting_time == TRUE) 1145 if (settings.casting_time == TRUE)
1214 {
1215 op->casting_time = -1; 1146 op->casting_time = -1;
1216 } 1147
1217 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); 1148 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1218 return 0; 1149 return 0;
1219 } 1150 }
1220 else if (spell_ob->stats.sp) 1151 else if (spell_ob->stats.sp)
1221 { 1152 {
1288 * spell is actually cast, it knows about the stringarg. 1219 * spell is actually cast, it knows about the stringarg.
1289 * necessary for the invoke command spells. 1220 * necessary for the invoke command spells.
1290 */ 1221 */
1291 if (stringarg) 1222 if (stringarg)
1292 { 1223 {
1293 op->spellarg = strdup_local (stringarg); 1224 op->spellarg = strdup (stringarg);
1294 } 1225 }
1295 else 1226 else
1296 op->spellarg = NULL; 1227 op->spellarg = NULL;
1297 return 0; 1228 return 0;
1298 } 1229 }
1691 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1622 if (QUERY_FLAG (victim, FLAG_ALIVE))
1692 { 1623 {
1693 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1624 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1694 1625
1695 if (!spell->destroyed ()) 1626 if (!spell->destroyed ())
1696 { 1627 spell->destroy ();
1697 remove_ob (spell);
1698 free_object (spell);
1699 }
1700 } 1628 }
1701 break; 1629 break;
1702 1630
1703 case SP_MOVING_BALL: 1631 case SP_MOVING_BALL:
1704 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1632 if (QUERY_FLAG (victim, FLAG_ALIVE))
1705 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1633 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1706 else if (victim->material || victim->materialname) 1634 else if (victim->materialname)
1707 save_throw_object (victim, spell->attacktype, spell); 1635 save_throw_object (victim, spell->attacktype, spell);
1708 break; 1636 break;
1709 } 1637 }
1710} 1638}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines