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.12 by root, Mon Sep 11 20:26:41 2006 UTC vs.
Revision 1.54 by root, Sun Jul 1 05:00:20 2007 UTC

1
2/* 1/*
3 * static char *rcsid_spell_util_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
4 * "$Id: spell_util.C,v 1.12 2006/09/11 20:26:41 root Exp $"; 3 *
5 */ 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
6
7
8/*
9 CrossFire, A Multiplayer game for X-windows
10
11 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
12 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
13 7 *
14 This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software: you can redistribute it and/or modify
15 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
16 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version. 11 * (at your option) any later version.
18 12 *
19 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,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details. 16 * GNU General Public License for more details.
23 17 *
24 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
25 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
27 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
28 The authors can be reached via e-mail at crossfire-devel@real-time.com
29*/ 22 */
30
31 23
32#include <global.h> 24#include <global.h>
33#include <spells.h> 25#include <spells.h>
34#include <object.h> 26#include <object.h>
35#include <errno.h> 27#include <errno.h>
36#ifndef __CEXTRACT__
37# include <sproto.h> 28#include <sproto.h>
38#endif
39#include <sounds.h> 29#include <sounds.h>
40 30
41extern char *spell_mapping[]; 31extern char *spell_mapping[];
42 32
43/* 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
105 95
106 if (init_spells_done) 96 if (init_spells_done)
107 return; 97 return;
108 LOG (llevDebug, "Checking spells...\n"); 98 LOG (llevDebug, "Checking spells...\n");
109 99
110 for (at = first_archetype; at; at = at->next) 100 for_all_archetypes (at)
111 { 101 {
112 if (at->clone.type == SPELL) 102 if (at->type == SPELL)
113 { 103 {
114 if (at->clone.skill) 104 if (at->skill)
115 { 105 {
116 for (i = 1; i < NUM_SKILLS; i++) 106 for (i = 1; i < NUM_SKILLS; i++)
117 if (!strcmp (skill_names[i], at->clone.skill)) 107 if (!strcmp (skill_names[i], at->skill))
118 break; 108 break;
119 if (i == NUM_SKILLS) 109 if (i == NUM_SKILLS)
120 { 110 {
121 LOG (llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill); 111 LOG (llevError, "Spell %s has improper associated skill %s\n", at->name, at->skill);
122 } 112 }
123 } 113 }
124 /* other_arch is already checked for in the loader */ 114 /* other_arch is already checked for in the loader */
125 } 115 }
126 } 116 }
127 117
128 i = 0; 118 i = 0;
129 while (spell_mapping[i]) 119 while (spell_mapping[i])
130 { 120 {
131 if (!find_archetype (spell_mapping[i])) 121 if (!archetype::find (spell_mapping[i]))
132 { 122 {
133 LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i); 123 LOG (llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
134 } 124 }
135 i++; 125 i++;
136 } 126 }
145void 135void
146dump_spells (void) 136dump_spells (void)
147{ 137{
148 archetype *at; 138 archetype *at;
149 139
150 for (at = first_archetype; at; at = at->next) 140 for_all_archetypes (at)
151 { 141 {
152 if (at->clone.type == SPELL) 142 if (at->type == SPELL)
153 { 143 {
154 fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->clone.name, 144 fprintf (stderr, "%s:%s:%s:%s:%d\n", &at->object::name,
155 &at->name, at->clone.other_arch ? &at->clone.other_arch->name : "<nil>", &at->clone.skill, at->clone.level); 145 &at->archname, at->other_arch ? &at->other_arch->archname : "<nil>", &at->skill, at->level);
156 } 146 }
157 } 147 }
158} 148}
159 149
160/* pretty basic function - basically just takes 150/* pretty basic function - basically just takes
161 * an object, sets the x,y, and calls insert_ob_in_map 151 * an object, sets the x,y, and calls insert_ob_in_map
162 */ 152 */
163
164void 153void
165spell_effect (object *spob, int x, int y, mapstruct *map, object *originator) 154spell_effect (object *spob, int x, int y, maptile *map, object *originator)
166{ 155{
167
168 if (spob->other_arch != NULL) 156 if (spob->other_arch)
169 { 157 map->insert (arch_to_object (spob->other_arch), x, y, originator);
170 object *effect = arch_to_object (spob->other_arch);
171
172 effect->x = x;
173 effect->y = y;
174
175 insert_ob_in_map (effect, map, originator, 0);
176 }
177} 158}
178 159
179/* 160/*
180 * This function takes a caster and spell and presents the 161 * This function takes a caster and spell and presents the
181 * effective level the caster needs to be to cast the spell. 162 * effective level the caster needs to be to cast the spell.
182 * basically, it just adjusts the spell->level with attuned/repelled 163 * basically, it just adjusts the spell->level with attuned/repelled
183 * spellpaths. Was called path_level_mod 164 * spellpaths. Was called path_level_mod.
184 * 165 *
185 * caster is person casting hte spell. 166 * caster is person casting the spell.
186 * spell is the spell object. 167 * spell is the spell object.
187 * Returns modified level. 168 * Returns modified level.
188 */ 169 */
189int 170int
190min_casting_level (object *caster, object *spell) 171min_casting_level (object *caster, object *spell)
191{ 172{
192 int new_level; 173 int new_level;
193 174
194 if (caster->path_denied & spell->path_attuned) 175 if (caster->path_denied & spell->path_attuned)
195 {
196 /* This case is not a bug, just the fact that this function is
197 * usually called BEFORE checking for path_deny. -AV
198 */
199#if 0
200 LOG (llevError, "BUG: path_level_mod (arch %s, name %s): casting denied " "spell\n", caster->arch->name, caster->name);
201#endif
202 return 1; 176 return 1;
203 } 177
204 new_level = spell->level 178 new_level = spell->level
205 + ((caster->path_repelled & spell->path_attuned) ? +2 : 0) + ((caster->path_attuned & spell->path_attuned) ? -2 : 0); 179 + (caster->path_repelled & spell->path_attuned ? +2 : 0)
206 return (new_level < 1) ? 1 : new_level; 180 + (caster->path_attuned & spell->path_attuned ? -2 : 0);
207}
208 181
182 return max (1, new_level);
183}
209 184
210/* This function returns the effective level the spell 185/* This function returns the effective level the spell
211 * is being cast at. 186 * is being cast at.
212 * Note that I changed the repelled/attuned bonus to 2 from 5. 187 * Note that I changed the repelled/attuned bonus to 2 from 5.
213 * This is because the new code compares casting_level against 188 * This is because the new code compares casting_level against
214 * min_caster_level, so the difference is effectively 4 189 * min_caster_level, so the difference is effectively 4
215 */ 190 */
216
217int 191int
218caster_level (object *caster, object *spell) 192caster_level (object *caster, object *spell)
219{ 193{
220 int level = caster->level; 194 int level = caster->level;
221 195
222 /* If this is a player, try to find the matching skill */ 196 /* If this is a player, try to find the matching skill */
223 if (caster->type == PLAYER && spell->skill) 197 if (caster->type == PLAYER && spell->skill)
224 {
225 int i;
226
227 for (i = 0; i < NUM_SKILLS; i++) 198 for (int i = 0; i < NUM_SKILLS; i++)
228 if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill) 199 if (caster->contr->last_skill_ob[i] && caster->contr->last_skill_ob[i]->skill == spell->skill)
229 { 200 {
230 level = caster->contr->last_skill_ob[i]->level; 201 level = caster->contr->last_skill_ob[i]->level;
231 break; 202 break;
232 } 203 }
233 }
234 204
235 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */ 205 /* if a rod is fired by a player, take the use_magic_item skill in consideration. */
236 if (caster->type == ROD && caster->env && caster->env->type == PLAYER) 206 if (caster->type == ROD && caster->env && caster->env->type == PLAYER)
237 { 207 {
238 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM); 208 object *skill = find_skill_by_number (caster->env, SK_USE_MAGIC_ITEM);
240 210
241 level = MIN (level, sk_level + level / 10 + 1); 211 level = MIN (level, sk_level + level / 10 + 1);
242 } 212 }
243 213
244 /* Got valid caster level. Now adjust for attunement */ 214 /* Got valid caster level. Now adjust for attunement */
245 level += ((caster->path_repelled & spell->path_attuned) ? -2 : 0) + ((caster->path_attuned & spell->path_attuned) ? 2 : 0); 215 level += caster->path_repelled & spell->path_attuned ? -2 : 0;
216 level += caster->path_attuned & spell->path_attuned ? +2 : 0;
246 217
247 /* Always make this at least 1. If this is zero, we get divide by zero 218 /* Always make this at least 1. If this is zero, we get divide by zero
248 * errors in various places. 219 * errors in various places.
249 */ 220 */
250 if (level < 1)
251 level = 1;
252 return level; 221 return max (level, 1);
253} 222}
254 223
255/* The following function scales the spellpoint cost of 224/* The following function scales the spellpoint cost of
256 * a spell by it's increased effectiveness. Some of the 225 * a spell by it's increased effectiveness. Some of the
257 * lower level spells become incredibly vicious at high 226 * lower level spells become incredibly vicious at high
451 * reflect_spell fails.) 420 * reflect_spell fails.)
452 * Caller should be sure it passes us valid map coordinates 421 * Caller should be sure it passes us valid map coordinates
453 * eg, updated for tiled maps. 422 * eg, updated for tiled maps.
454 */ 423 */
455int 424int
456reflwall (mapstruct *m, int x, int y, object *sp_op) 425reflwall (maptile *m, int x, int y, object *sp_op)
457{ 426{
458 object *op; 427 object *op;
459 428
460 if (OUT_OF_REAL_MAP (m, x, y)) 429 if (OUT_OF_REAL_MAP (m, x, y))
461 return 0; 430 return 0;
462 for (op = get_map_ob (m, x, y); op != NULL; op = op->above) 431 for (op = GET_MAP_OB (m, x, y); op != NULL; op = op->above)
463 if (QUERY_FLAG (op, FLAG_REFL_SPELL) && (!QUERY_FLAG (op, FLAG_ALIVE) || 432 if (QUERY_FLAG (op, FLAG_REFL_SPELL)
464 sp_op->type == LIGHTNING || (rndm (0, 99)) < 90 - (sp_op->level / 10))) 433 && (!QUERY_FLAG (op, FLAG_ALIVE)
434 || (rndm (0, 99)) < 90 - (sp_op->level / 10)))
465 return 1; 435 return 1;
466 436
467 return 0; 437 return 0;
468} 438}
469 439
475 * in. 445 * in.
476 */ 446 */
477int 447int
478cast_create_obj (object *op, object *caster, object *new_op, int dir) 448cast_create_obj (object *op, object *caster, object *new_op, int dir)
479{ 449{
480 mapstruct *m; 450 maptile *m;
481 sint16 sx, sy; 451 sint16 sx, sy;
482 452
483 if (dir && 453 if (dir &&
484 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) || 454 ((get_map_flags (op->map, &m, op->x + freearr_x[dir], op->y + freearr_y[dir], &sx, &sy) & P_OUT_OF_MAP) ||
485 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy)))) 455 OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, sx, sy))))
486 { 456 {
487 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); 457 new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way.");
488 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet."); 458 new_draw_info (NDI_UNIQUE, 0, op, "You cast it at your feet.");
489 dir = 0; 459 dir = 0;
490 } 460 }
491 new_op->x = op->x + freearr_x[dir]; 461
492 new_op->y = op->y + freearr_y[dir]; 462 op->map->insert (new_op,
493 if (dir == 0) 463 op->x + freearr_x[dir], op->y + freearr_y[dir],
494 insert_ob_in_map (new_op, op->map, op, INS_BELOW_ORIGINATOR); 464 op,
495 else 465 dir ? 0 : INS_BELOW_ORIGINATOR);
496 insert_ob_in_map (new_op, op->map, op, 0); 466
497 return dir; 467 return dir;
498} 468}
499 469
500/* Returns true if it is ok to put spell *op on the space/may provided. 470/* Returns true if it is ok to put spell *op on the space/may provided.
501 * immune_stop is basically the attacktype of the spell (why 471 * immune_stop is basically the attacktype of the spell (why
503 * has the AT_MAGIC bit set, and there is a counterwall 473 * has the AT_MAGIC bit set, and there is a counterwall
504 * on the space, the object doesn't get placed. if immune stop 474 * on the space, the object doesn't get placed. if immune stop
505 * does not have AT_MAGIC, then counterwalls do not effect the spell. 475 * does not have AT_MAGIC, then counterwalls do not effect the spell.
506 * 476 *
507 */ 477 */
508
509int 478int
510ok_to_put_more (mapstruct *m, sint16 x, sint16 y, object *op, int immune_stop) 479ok_to_put_more (maptile *m, sint16 x, sint16 y, object *op, int immune_stop)
511{ 480{
512 object *tmp; 481 if (!xy_normalise (m, x, y))
513 int mflags;
514 mapstruct *mp;
515
516 mp = m;
517 mflags = get_map_flags (m, &mp, x, y, &x, &y);
518
519 if (mflags & P_OUT_OF_MAP)
520 return 0; 482 return 0;
521 483
522 if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (mp, x, y))) 484 mapspace &ms = m->at (x, y);
485
486 if (OB_TYPE_MOVE_BLOCK (op, ms.move_block))
523 return 0; 487 return 0;
524 488
525 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) 489 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
526 { 490 {
527 /* If there is a counterspell on the space, and this 491 /* If there is a counterspell on the space, and this
528 * object is using magic, don't progress. I believe we could 492 * object is using magic, don't progress. I believe we could
529 * leave this out and let in progress, and other areas of the code 493 * leave this out and let in progress, and other areas of the code
530 * will then remove it, but that would seem to to use more 494 * will then remove it, but that would seem to to use more
531 * resources, and may not work as well if a player is standing 495 * resources, and may not work as well if a player is standing
532 * on top of a counterwall spell (may hit the player before being 496 * on top of a counterwall spell (may hit the player before being
533 * removed.) On the other hand, it may be more dramatic for the 497 * removed.) On the other hand, it may be more dramatic for the
534 * spell to actually hit the counterwall and be sucked up. 498 * spell to actually hit the counterwall and be sucked up.
535 */ 499 */
536 if ((tmp->attacktype & AT_COUNTERSPELL) && 500 if ((tmp->attacktype & AT_COUNTERSPELL)
537 (tmp->type != PLAYER) && !QUERY_FLAG (tmp, FLAG_MONSTER) && 501 && !QUERY_FLAG (tmp, FLAG_MONSTER)
538 (tmp->type != WEAPON) && (tmp->type != BOW) && (tmp->type != ARROW) && (tmp->type != GOLEM) && (immune_stop & AT_MAGIC)) 502 && (tmp->type != PLAYER)
503 && (tmp->type != WEAPON)
504 && (tmp->type != BOW)
505 && (tmp->type != ARROW)
506 && (tmp->type != GOLEM)
507 && !QUERY_FLAG (tmp, FLAG_IS_FLOOR) // XXX:
508 // we special case floor here because there
509 // are sometimes spell effect floors
510 // which are used to inflict damage
511 // (and those shouldn't go away from
512 // sanctuary) see also: permanent lava
513 && (immune_stop & AT_MAGIC))
539 return 0; 514 return 0;
540 515
541 /* This is to prevent 'out of control' spells. Basically, this 516 /* This is to prevent 'out of control' spells. Basically, this
542 * limits one spell effect per space per spell. This is definately 517 * limits one spell effect per space per spell. This is definately
543 * needed for performance reasons, and just for playability I believe. 518 * needed for performance reasons, and just for playability I believe.
553 * playability reasons. 528 * playability reasons.
554 */ 529 */
555 if (tmp->arch == op->arch 530 if (tmp->arch == op->arch
556 && tmp->type == op->type 531 && tmp->type == op->type
557 && tmp->subtype == op->subtype 532 && tmp->subtype == op->subtype
533 && tmp->owner == op->owner
558 && tmp->owner == op->owner && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp))) 534 && ((tmp->subtype == SP_EXPLOSION) || (tmp->subtype == SP_CONE && tmp->stats.sp == op->stats.sp)))
559 { 535 {
560 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam); 536 tmp->stats.dam = MAX (tmp->stats.dam, op->stats.dam);
561 tmp->range = MAX (tmp->range, op->range); 537 tmp->range = MAX (tmp->range, op->range);
562 tmp->duration = MAX (tmp->duration, op->duration); 538 tmp->duration = MAX (tmp->duration, op->duration);
563 return 0; 539 return 0;
565 541
566 /* Perhaps we should also put checks in for no magic and unholy 542 /* Perhaps we should also put checks in for no magic and unholy
567 * ground to prevent it from moving along? 543 * ground to prevent it from moving along?
568 */ 544 */
569 } 545 }
546
570 /* If it passes the above tests, it must be OK */ 547 /* If it passes the above tests, it must be OK */
571 return 1; 548 return 1;
572} 549}
573 550
574/* fire_arch_from_position: fires an archetype. 551/* fire_arch_from_position: fires an archetype.
585int 562int
586fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) 563fire_arch_from_position (object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
587{ 564{
588 object *tmp; 565 object *tmp;
589 int mflags; 566 int mflags;
590 mapstruct *m; 567 maptile *m;
591 568
592 if (spell->other_arch == NULL) 569 if (spell->other_arch == NULL)
593 return 0; 570 return 0;
594 571
595 m = op->map; 572 m = op->map;
605 return 0; 582 return 0;
606 583
607 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y))) 584 if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (m, x, y)))
608 { 585 {
609 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n"); 586 new_draw_info (NDI_UNIQUE, 0, op, "You can't cast the spell on top of a wall!\n");
610 free_object (tmp); 587 tmp->destroy ();
611 return 0; 588 return 0;
612 } 589 }
613
614
615 590
616 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); 591 tmp->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell);
617 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); 592 tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell);
618 /* code in time.c uses food for some things, duration for others */ 593 /* code in time.c uses food for some things, duration for others */
619 tmp->stats.food = tmp->duration; 594 tmp->stats.food = tmp->duration;
620 tmp->range = spell->range + SP_level_range_adjust (caster, spell); 595 tmp->range = spell->range + SP_level_range_adjust (caster, spell);
621 tmp->attacktype = spell->attacktype; 596 tmp->attacktype = spell->attacktype;
622 tmp->x = x; 597 tmp->x = x;
623 tmp->y = y; 598 tmp->y = y;
624 tmp->direction = dir; 599 tmp->direction = dir;
625 if (get_owner (op) != NULL) 600 if (op->owner != NULL)
626 copy_owner (tmp, op); 601 tmp->set_owner (op);
627 else 602 else
628 set_owner (tmp, op); 603 tmp->set_owner (op);
629 tmp->level = caster_level (caster, spell); 604 tmp->level = caster_level (caster, spell);
630 set_spell_skill (op, caster, spell, tmp); 605 set_spell_skill (op, caster, spell, tmp);
631 606
632 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */ 607 /* needed for AT_HOLYWORD,AT_GODPOWER stuff */
633 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) 608 if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER)
636 return 0; 611 return 0;
637 } 612 }
638 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) 613 if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE))
639 SET_ANIMATION (tmp, dir); 614 SET_ANIMATION (tmp, dir);
640 615
641 if ((tmp = insert_ob_in_map (tmp, m, op, 0)) == NULL) 616 if ((tmp = insert_ob_in_map (tmp, m, op, 0)))
642 return 1;
643
644 move_spell_effect (tmp); 617 move_spell_effect (tmp);
645 618
646 return 1; 619 return 1;
647} 620}
648
649
650 621
651/***************************************************************************** 622/*****************************************************************************
652 * 623 *
653 * Code related to rods - perhaps better located in another file? 624 * Code related to rods - perhaps better located in another file?
654 * 625 *
655 ****************************************************************************/ 626 ****************************************************************************/
656
657void 627void
658regenerate_rod (object *rod) 628regenerate_rod (object *rod)
659{ 629{
660 if (rod->stats.hp < rod->stats.maxhp) 630 if (rod->stats.hp < rod->stats.maxhp)
661 { 631 rod->stats.hp = min (rod->stats.maxhp, rod->stats.hp + 1 + rod->stats.maxhp / 10);
662 rod->stats.hp += 1 + rod->stats.maxhp / 10;
663
664 if (rod->stats.hp > rod->stats.maxhp)
665 rod->stats.hp = rod->stats.maxhp;
666 }
667} 632}
668
669 633
670void 634void
671drain_rod_charge (object *rod) 635drain_rod_charge (object *rod)
672{ 636{
673 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST); 637 rod->stats.hp -= SP_level_spellpoint_cost (rod, rod->inv, SPELL_HIGHEST);
674} 638}
675
676
677
678 639
679/* this function is commonly used to find a friendly target for 640/* this function is commonly used to find a friendly target for
680 * spells such as heal or protection or armour 641 * spells such as heal or protection or armour
681 * op is what is looking for the target (which can be a player), 642 * op is what is looking for the target (which can be a player),
682 * dir is the direction we are looking in. Return object found, or 643 * dir is the direction we are looking in. Return object found, or
683 * NULL if no good object. 644 * NULL if no good object.
684 */ 645 */
685
686object * 646object *
687find_target_for_friendly_spell (object *op, int dir) 647find_target_for_friendly_spell (object *op, int dir)
688{ 648{
689 object *tmp; 649 object *tmp;
690 mapstruct *m;
691 sint16 x, y;
692 int mflags;
693 650
694 /* I don't really get this block - if op isn't a player or rune, 651 /* I don't really get this block - if op isn't a player or rune,
695 * we then make the owner of this object the target. 652 * we then make the owner of this object the target.
696 * The owner could very well be no where near op. 653 * The owner could very well be no where near op.
697 */ 654 */
698 if (op->type != PLAYER && op->type != RUNE) 655 if (op->type != PLAYER && op->type != RUNE)
699 { 656 {
700 tmp = get_owner (op); 657 tmp = op->owner;
701 /* If the owner does not exist, or is not a monster, than apply the spell 658 /* If the owner does not exist, or is not a monster, than apply the spell
702 * to the caster. 659 * to the caster.
703 */ 660 */
704 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER)) 661 if (!tmp || !QUERY_FLAG (tmp, FLAG_MONSTER))
705 tmp = op; 662 tmp = op;
706 } 663 }
707 else 664 else
708 { 665 {
709 m = op->map; 666 maptile *m = op->map;
710 x = op->x + freearr_x[dir]; 667 sint16 x = op->x + freearr_x[dir];
711 y = op->y + freearr_y[dir]; 668 sint16 y = op->y + freearr_y[dir];
712
713 mflags = get_map_flags (m, &m, x, y, &x, &y);
714
715 if (mflags & P_OUT_OF_MAP)
716 tmp = NULL;
717 else
718 { 669
719 for (tmp = get_map_ob (m, x, y); tmp != NULL; tmp = tmp->above) 670 tmp = xy_normalise (m, x, y)
720 if (tmp->type == PLAYER) 671 ? m->at (x, y).player ()
721 break; 672 : 0;
722 }
723 } 673 }
674
724 /* didn't find a player there, look in current square for a player */ 675 /* didn't find a player there, look in current square for a player */
725 if (tmp == NULL) 676 if (!tmp)
726 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) 677 tmp = op->ms ().player ();
727 {
728 if (tmp->type == PLAYER)
729 break;
730 }
731 678
732 return tmp; 679 return tmp;
733} 680}
734 681
735 682
745 * any, otherwise -1. 692 * any, otherwise -1.
746 * note that exclude can be NULL, in which case all bets are off. 693 * note that exclude can be NULL, in which case all bets are off.
747 */ 694 */
748 695
749int 696int
750spell_find_dir (mapstruct *m, int x, int y, object *exclude) 697spell_find_dir (maptile *m, int x, int y, object *exclude)
751{ 698{
752 int i, max = SIZEOFFREE; 699 int i, max = SIZEOFFREE;
753 sint16 nx, ny; 700 sint16 nx, ny;
754 int owner_type = 0, mflags; 701 int owner_type = 0, mflags;
755 object *tmp; 702 object *tmp;
756 mapstruct *mp; 703 maptile *mp;
757 704
758 if (exclude && exclude->head) 705 if (exclude && exclude->head)
759 exclude = exclude->head; 706 exclude = exclude->head;
760 if (exclude && exclude->type) 707 if (exclude && exclude->type)
761 owner_type = exclude->type; 708 owner_type = exclude->type;
767 mp = m; 714 mp = m;
768 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 715 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny);
769 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW)) 716 if (mflags & (P_OUT_OF_MAP | P_BLOCKSVIEW))
770 continue; 717 continue;
771 718
772 tmp = get_map_ob (mp, nx, ny); 719 tmp = GET_MAP_OB (mp, nx, ny);
773 720
774 while (tmp != NULL && (((owner_type == PLAYER && 721 while (tmp != NULL && (((owner_type == PLAYER &&
775 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) || 722 !QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_GENERATOR)) ||
776 (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude)))) 723 (owner_type != PLAYER && tmp->type != PLAYER)) || (tmp == exclude || (tmp->head && tmp->head == exclude))))
777 tmp = tmp->above; 724 tmp = tmp->above;
780 return freedir[i]; 727 return freedir[i];
781 } 728 }
782 return -1; /* flag for "keep going the way you were" */ 729 return -1; /* flag for "keep going the way you were" */
783} 730}
784 731
785
786
787/* put_a_monster: puts a monster named monstername near by 732/* put_a_monster: puts a monster named monstername near by
788 * op. This creates the treasures for the monsters, and 733 * op. This creates the treasures for the monsters, and
789 * also deals with multipart monsters properly. 734 * also deals with multipart monsters properly.
790 */ 735 */
791
792void 736void
793put_a_monster (object *op, const char *monstername) 737put_a_monster (object *op, const char *monstername)
794{ 738{
795 object *tmp, *head = NULL, *prev = NULL; 739 object *tmp, *head = NULL, *prev = NULL;
796 archetype *at; 740 archetype *at;
797 int dir; 741 int dir;
798 742
799 /* Handle cases where we are passed a bogus mosntername */ 743 /* Handle cases where we are passed a bogus mosntername */
800 744
801 if ((at = find_archetype (monstername)) == NULL) 745 if ((at = archetype::find (monstername)) == NULL)
802 return; 746 return;
803 747
804 /* find a free square nearby 748 /* find a free square nearby
805 * first we check the closest square for free squares 749 * first we check the closest square for free squares
806 */ 750 */
807 751
808 dir = find_first_free_spot (&at->clone, op->map, op->x, op->y); 752 dir = find_first_free_spot (at, op->map, op->x, op->y);
809 if (dir != -1) 753 if (dir != -1)
810 { 754 {
811 /* This is basically grabbed for generate monster. Fixed 971225 to 755 /* This is basically grabbed for generate monster. Fixed 971225 to
812 * insert multipart monsters properly 756 * insert multipart monsters properly
813 */ 757 */
758 //TODO: use expand_tail + ...
814 while (at != NULL) 759 while (at != NULL)
815 { 760 {
816 tmp = arch_to_object (at); 761 tmp = arch_to_object (at);
817 tmp->x = op->x + freearr_x[dir] + at->clone.x; 762 tmp->x = op->x + freearr_x[dir] + at->x;
818 tmp->y = op->y + freearr_y[dir] + at->clone.y; 763 tmp->y = op->y + freearr_y[dir] + at->y;
819 tmp->map = op->map; 764 tmp->map = op->map;
820 if (head) 765 if (head)
821 { 766 {
822 tmp->head = head; 767 tmp->head = head;
823 prev->more = tmp; 768 prev->more = tmp;
824 } 769 }
770
825 if (!head) 771 if (!head)
826 head = tmp; 772 head = tmp;
773
827 prev = tmp; 774 prev = tmp;
775
828 at = at->more; 776 at = (archetype *)at->more;
829 } 777 }
830 778
831 if (head->randomitems) 779 if (head->randomitems)
832 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0); 780 create_treasure (head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
833 781
834 insert_ob_in_map (head, op->map, op, 0); 782 insert_ob_in_map (head, op->map, op, 0);
835 783
836 /* thought it'd be cool to insert a burnout, too. */ 784 /* thought it'd be cool to insert a burnout, too. */
837 tmp = get_archetype ("burnout"); 785 op->map->insert (get_archetype ("burnout"), op->x + freearr_x[dir], op->y + freearr_y[dir], op);
838 tmp->map = op->map;
839 tmp->x = op->x + freearr_x[dir];
840 tmp->y = op->y + freearr_y[dir];
841 insert_ob_in_map (tmp, op->map, op, 0);
842 } 786 }
843} 787}
844 788
845/* peterm: function which summons hostile monsters and 789/* peterm: function which summons hostile monsters and
846 * places them in nearby squares. 790 * places them in nearby squares.
873{ 817{
874 int attacktype; 818 int attacktype;
875 int face; 819 int face;
876} ATTACKS[22] = 820} ATTACKS[22] =
877{ 821{
878 {
879 AT_PHYSICAL, 0}, 822 { AT_PHYSICAL, 0},
880 {
881 AT_PHYSICAL, 0}, /*face = explosion */ 823 { AT_PHYSICAL, 0}, /*face = explosion */
882 {
883 AT_PHYSICAL, 0}, 824 { AT_PHYSICAL, 0},
884 {
885 AT_MAGIC, 1}, 825 { AT_MAGIC, 1},
886 {
887 AT_MAGIC, 1}, /* face = last-burnout */ 826 { AT_MAGIC, 1}, /* face = last-burnout */
888 {
889 AT_MAGIC, 1}, 827 { AT_MAGIC, 1},
890 {
891 AT_FIRE, 2}, 828 { AT_FIRE, 2},
892 {
893 AT_FIRE, 2}, /* face = fire.... */ 829 { AT_FIRE, 2}, /* face = fire.... */
894 {
895 AT_FIRE, 2}, 830 { AT_FIRE, 2},
896 {
897 AT_ELECTRICITY, 3}, 831 { AT_ELECTRICITY, 3},
898 {
899 AT_ELECTRICITY, 3}, /* ball_lightning */ 832 { AT_ELECTRICITY, 3}, /* ball_lightning */
900 {
901 AT_ELECTRICITY, 3}, 833 { AT_ELECTRICITY, 3},
902 {
903 AT_COLD, 4}, 834 { AT_COLD, 4},
904 {
905 AT_COLD, 4}, /* face=icestorm */ 835 { AT_COLD, 4}, /* face=icestorm */
906 {
907 AT_COLD, 4}, 836 { AT_COLD, 4},
908 {
909 AT_CONFUSION, 5}, 837 { AT_CONFUSION, 5},
910 {
911 AT_POISON, 7}, 838 { AT_POISON, 7},
912 {
913 AT_POISON, 7}, /* face = acid sphere. generator */ 839 { AT_POISON, 7}, /* face = acid sphere. generator */
914 {
915 AT_POISON, 7}, /* poisoncloud face */ 840 { AT_POISON, 7}, /* poisoncloud face */
916 {
917 AT_SLOW, 8}, 841 { AT_SLOW, 8},
918 {
919 AT_PARALYZE, 9}, 842 { AT_PARALYZE, 9},
920 {
921AT_FEAR, 10}}; 843 { AT_FEAR, 10},
922 844};
923
924 845
925/* shuffle_attack: peterm 846/* shuffle_attack: peterm
926 * This routine shuffles the attack of op to one of the 847 * This routine shuffles the attack of op to one of the
927 * ones in the list. It does this at random. It also 848 * ones in the list. It does this at random. It also
928 * chooses a face appropriate to the attack that is 849 * chooses a face appropriate to the attack that is
973 if (failure <= -20 && failure > -40) /* wonder */ 894 if (failure <= -20 && failure > -40) /* wonder */
974 { 895 {
975 new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname); 896 new_draw_info_format (NDI_UNIQUE, 0, op, "%s gives a sign to renew your faith.", godname);
976 tmp = get_archetype (SPELL_WONDER); 897 tmp = get_archetype (SPELL_WONDER);
977 cast_cone (op, op, 0, tmp); 898 cast_cone (op, op, 0, tmp);
978 free_object (tmp); 899 tmp->destroy ();
979 } 900 }
980 901
981 else if (failure <= -40 && failure > -60) /* confusion */ 902 else if (failure <= -40 && failure > -60) /* confusion */
982 { 903 {
983 new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!"); 904 new_draw_info (NDI_UNIQUE, 0, op, "Your diety touches your mind!");
1017 if (failure <= -20 && failure > -40) /* wonder */ 938 if (failure <= -20 && failure > -40) /* wonder */
1018 { 939 {
1019 new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect."); 940 new_draw_info (NDI_UNIQUE, 0, op, "Your spell causes an unexpected effect.");
1020 tmp = get_archetype (SPELL_WONDER); 941 tmp = get_archetype (SPELL_WONDER);
1021 cast_cone (op, op, 0, tmp); 942 cast_cone (op, op, 0, tmp);
1022 free_object (tmp); 943 tmp->destroy ();
1023 } 944 }
1024 945
1025 else if (failure <= -40 && failure > -60) /* confusion */ 946 else if (failure <= -40 && failure > -60) /* confusion */
1026 { 947 {
1027 new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!"); 948 new_draw_info (NDI_UNIQUE, 0, op, "Your magic recoils on you, making you confused!");
1046 else 967 else
1047 { 968 {
1048 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!"); 969 new_draw_info (NDI_UNIQUE, 0, op, "You lose control of the mana! The uncontrolled magic blasts you!");
1049 tmp = get_archetype (LOOSE_MANA); 970 tmp = get_archetype (LOOSE_MANA);
1050 tmp->level = skill->level; 971 tmp->level = skill->level;
1051 tmp->x = op->x;
1052 tmp->y = op->y;
1053 972
1054 /* increase the area of destruction a little for more powerful spells */ 973 /* increase the area of destruction a little for more powerful spells */
1055 tmp->range += isqrt (power); 974 tmp->range += isqrt (power);
1056 975
1057 if (power > 25) 976 if (power > 25)
1058 tmp->stats.dam = 25 + isqrt (power); 977 tmp->stats.dam = 25 + isqrt (power);
1059 else 978 else
1060 tmp->stats.dam = power; /* nasty recoils! */ 979 tmp->stats.dam = power; /* nasty recoils! */
1061 980
1062 tmp->stats.maxhp = tmp->count; 981 tmp->stats.maxhp = tmp->count;
1063 insert_ob_in_map (tmp, op->map, NULL, 0); 982
983 tmp->insert_at (op);
1064 } 984 }
1065 } 985 }
1066} 986}
1067 987
1068int 988int
1069cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 989cast_party_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1070{ 990{
1071 int success; 991 int success;
1072 player *pl;
1073 object *spell; 992 object *spell;
1074 993
1075 if (!spell_ob->other_arch) 994 if (!spell_ob->other_arch)
1076 { 995 {
1077 LOG (llevError, "cast_party_spell: empty other arch\n"); 996 LOG (llevError, "cast_party_spell: empty other arch\n");
1082 /* Always cast spell on caster */ 1001 /* Always cast spell on caster */
1083 success = cast_spell (op, caster, dir, spell, stringarg); 1002 success = cast_spell (op, caster, dir, spell, stringarg);
1084 1003
1085 if (caster->contr->party == NULL) 1004 if (caster->contr->party == NULL)
1086 { 1005 {
1087 remove_ob (spell); 1006 spell->remove ();
1088 return success; 1007 return success;
1089 } 1008 }
1090 for (pl = first_player; pl != NULL; pl = pl->next) 1009 for_all_players (pl)
1091 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster))) 1010 if ((pl->ob->contr->party == caster->contr->party) && (on_same_map (pl->ob, caster)))
1092 { 1011 {
1093 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg); 1012 cast_spell (pl->ob, caster, pl->ob->facing, spell, stringarg);
1094 } 1013 }
1095 remove_ob (spell); 1014 spell->remove ();
1096 return success; 1015 return success;
1097} 1016}
1098 1017
1099/* This is where the main dispatch when someone casts a spell. 1018/* This is where the main dispatch when someone casts a spell.
1100 * 1019 *
1121 * 1040 *
1122 * if it is a player casting the spell (op->type == PLAYER, op == caster), 1041 * if it is a player casting the spell (op->type == PLAYER, op == caster),
1123 * this function will decrease the mana/grace appropriately. For other 1042 * this function will decrease the mana/grace appropriately. For other
1124 * objects, the caller should do what it considers appropriate. 1043 * objects, the caller should do what it considers appropriate.
1125 */ 1044 */
1126
1127int 1045int
1128cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg) 1046cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg)
1129{ 1047{
1130
1131 const char *godname; 1048 const char *godname;
1132 int success = 0, mflags, cast_level = 0, old_shoottype; 1049 int success = 0, mflags, cast_level = 0;
1133 object *skill = NULL; 1050 object *skill = NULL;
1134
1135 old_shoottype = op->contr ? op->contr->shoottype : 0;
1136 1051
1137 if (!spell_ob) 1052 if (!spell_ob)
1138 { 1053 {
1139 LOG (llevError, "cast_spell: null spell object passed\n"); 1054 LOG (llevError, "cast_spell: null spell object passed\n");
1140 return 0; 1055 return 0;
1141 } 1056 }
1057
1142 if (!strcmp ((godname = determine_god (op)), "none")) 1058 if (!strcmp ((godname = determine_god (op)), "none"))
1143 godname = "A random spirit"; 1059 godname = "A random spirit";
1144 1060
1145 /* the caller should set caster to op if appropriate */ 1061 /* the caller should set caster to op if appropriate */
1146 if (!caster) 1062 if (!caster)
1150 } 1066 }
1151 1067
1152 /* if caster is a spell casting object, this normally shouldn't be 1068 /* if caster is a spell casting object, this normally shouldn't be
1153 * an issue, because they don't have any spellpaths set up. 1069 * an issue, because they don't have any spellpaths set up.
1154 */ 1070 */
1155 if (caster->path_denied & spell_ob->path_attuned) 1071 if (caster->path_denied & spell_ob->path_attuned && !QUERY_FLAG (caster, FLAG_WIZCAST))
1156 { 1072 {
1157 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you."); 1073 new_draw_info (NDI_UNIQUE, 0, op, "That spell path is denied to you.");
1158 return 0; 1074 return 0;
1159 } 1075 }
1160 1076
1168 * at least process that code. 1084 * at least process that code.
1169 */ 1085 */
1170 if (op->type == PLAYER && op == caster) 1086 if (op->type == PLAYER && op == caster)
1171 { 1087 {
1172 cast_level = caster_level (caster, spell_ob); 1088 cast_level = caster_level (caster, spell_ob);
1089
1173 if (spell_ob->skill) 1090 if (spell_ob->skill)
1174 { 1091 {
1175 skill = find_skill_by_name (op, spell_ob->skill); 1092 skill = find_skill_by_name (op, spell_ob->skill);
1093
1176 if (!skill) 1094 if (!skill)
1177 { 1095 {
1178 new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s.", &spell_ob->skill, &spell_ob->name); 1096 new_draw_info_format (NDI_UNIQUE, 0, op, "You need the skill %s to cast %s.", &spell_ob->skill, &spell_ob->name);
1179 return 0; 1097 return 0;
1180 } 1098 }
1099
1181 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ)) 1100 if (min_casting_level (op, spell_ob) > cast_level && !QUERY_FLAG (op, FLAG_WIZ))
1182 { 1101 {
1183 new_draw_info (NDI_UNIQUE, 0, op, "You lack enough skill to cast that spell."); 1102 new_draw_info (NDI_UNIQUE, 0, op, "You lack enough skill to cast that spell.");
1184 return 0; 1103 return 0;
1185 } 1104 }
1186 } 1105 }
1106
1187 /* If the caster is the wiz, they don't ever fail, and don't have 1107 /* If the caster is the wiz, they don't ever fail, and don't have
1188 * to have sufficient grace/mana. 1108 * to have sufficient grace/mana.
1189 */ 1109 */
1190 if (!QUERY_FLAG (op, FLAG_WIZ)) 1110 if (!QUERY_FLAG (op, FLAG_WIZ))
1191 { 1111 {
1193 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp) 1113 SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA) > op->stats.sp)
1194 { 1114 {
1195 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana."); 1115 new_draw_info (NDI_UNIQUE, 0, op, "You don't have enough mana.");
1196 return 0; 1116 return 0;
1197 } 1117 }
1118
1198 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) && 1119 if (SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) &&
1199 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace) 1120 SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) > op->stats.grace)
1200 { 1121 {
1201 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace - 1122 if (random_roll (0, op->stats.Wis - 1, op, PREFER_HIGH) + op->stats.grace -
1202 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0) 1123 10 * SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE) / op->stats.maxgrace > 0)
1214 /* player/monster is trying to cast the spell. might fumble it */ 1135 /* player/monster is trying to cast the spell. might fumble it */
1215 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) < 1136 if (spell_ob->stats.grace && random_roll (0, 99, op, PREFER_HIGH) <
1216 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis])) 1137 (spell_ob->level / (float) MAX (1, op->level) * cleric_chance[op->stats.Wis]))
1217 { 1138 {
1218 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0); 1139 play_sound_player_only (op->contr, SOUND_FUMBLE_SPELL, 0, 0);
1219 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the spell."); 1140 new_draw_info (NDI_UNIQUE, 0, op, "You fumble the prayer.");
1220 if (settings.casting_time == TRUE) 1141
1221 {
1222 op->casting_time = -1;
1223 }
1224 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW); 1142 op->stats.grace -= random_roll (1, SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1225 return 0; 1143 return 0;
1226 } 1144 }
1227 else if (spell_ob->stats.sp) 1145 else if (spell_ob->stats.sp)
1228 { 1146 {
1231 if (failure < 0) 1149 if (failure < 0)
1232 { 1150 {
1233 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use."); 1151 new_draw_info (NDI_UNIQUE, 0, op, "You bungle the spell because you have too much heavy equipment in use.");
1234 if (settings.spell_failure_effects == TRUE) 1152 if (settings.spell_failure_effects == TRUE)
1235 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill); 1153 spell_failure (op, failure, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), skill);
1236 op->contr->shoottype = (rangetype) old_shoottype; 1154
1237 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW); 1155 op->stats.sp -= random_roll (0, SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1238 return 0; 1156 return 0;
1239 } 1157 }
1240 } 1158 }
1241 } 1159 }
1264 { 1182 {
1265 if (op->type != PLAYER) 1183 if (op->type != PLAYER)
1266 return 0; 1184 return 0;
1267 1185
1268 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace) 1186 if ((mflags & P_NO_CLERIC) && spell_ob->stats.grace)
1269 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname); 1187 new_draw_info_format (NDI_UNIQUE, 0, op, "This ground is unholy! %s ignores you.", godname);
1270 else 1188 else if (object *item = op->contr->ranged_ob)
1271 switch (op->contr->shoottype)
1272 { 1189 {
1273 case range_magic: 1190 if (item->type == SPELL)
1274 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting."); 1191 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks your spellcasting.");
1275 break; 1192 else if (item->type == SCROLL)
1276 case range_misc:
1277 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item.");
1278 break;
1279 case range_golem:
1280 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll."); 1193 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your scroll.");
1281 break;
1282 default:
1283 break;
1284 }
1285 return 0;
1286 }
1287
1288 if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL)
1289 {
1290 if (op->casting_time == -1)
1291 { /* begin the casting */
1292 op->casting_time = (sint16) (spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob));
1293 op->spell = spell_ob;
1294 /* put the stringarg into the object struct so that when the
1295 * spell is actually cast, it knows about the stringarg.
1296 * necessary for the invoke command spells.
1297 */
1298 if (stringarg)
1299 {
1300 op->spellarg = strdup_local (stringarg);
1301 }
1302 else 1194 else
1303 op->spellarg = NULL; 1195 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the magic of your item.");
1304 return 0;
1305 }
1306 else if (op->casting_time != 0)
1307 {
1308 if (op->type == PLAYER)
1309 new_draw_info (NDI_UNIQUE, 0, op, "You are casting!");
1310 return 0;
1311 } 1196 }
1312 else 1197 else
1313 { /* casting_time == 0 */ 1198 new_draw_info (NDI_UNIQUE, 0, op, "Something blocks the spell!");
1314 op->casting_time = -1; 1199
1315 spell_ob = op->spell; 1200 return 0;
1316 stringarg = op->spellarg;
1317 }
1318 }
1319 else
1320 { 1201 }
1202
1321 /* Take into account how long it takes to cast the spell. 1203 /* Take into account how long it takes to cast the spell.
1322 * if the player is casting it, then we use the time in 1204 * if the player is casting it, then we use the time in
1323 * the spell object. If it is a spell object, have it 1205 * the spell object. If it is a spell object, have it
1324 * take two ticks. Things that cast spells on the players 1206 * take two ticks. Things that cast spells on the players
1325 * behalf (eg, altars, and whatever else) shouldn't cost 1207 * behalf (eg, altars, and whatever else) shouldn't cost
1326 * the player any time. 1208 * the player any time.
1327 * Ignore casting time for firewalls 1209 * Ignore casting time for firewalls
1210 */
1211 if (caster == op && caster->type != FIREWALL)
1212 {
1213 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1214 /* Other portions of the code may also decrement the speed of the player, so
1215 * put a lower limit so that the player isn't stuck here too long
1328 */ 1216 */
1329 if (caster == op && caster->type != FIREWALL)
1330 {
1331 op->speed_left -= spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1332 /* Other portions of the code may also decrement the speed of the player, so
1333 * put a lower limit so that the player isn't stuck here too long
1334 */
1335 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed)) 1217 if ((spell_ob->casting_time > 0) && op->speed_left < -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed))
1336 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed); 1218 op->speed_left = -spell_ob->casting_time * PATH_TIME_MULT (op, spell_ob) * FABS (op->speed);
1337 } 1219 }
1338 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL) 1220 else if (caster->type == WAND || caster->type == HORN || caster->type == ROD || caster->type == POTION || caster->type == SCROLL)
1339 {
1340 op->speed_left -= 2 * FABS (op->speed); 1221 op->speed_left -= 2 * FABS (op->speed);
1341 }
1342 }
1343 1222
1344 if (op->type == PLAYER && op == caster) 1223 if (op->type == PLAYER && op == caster)
1345 { 1224 {
1346 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE); 1225 op->stats.grace -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_GRACE);
1347 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA); 1226 op->stats.sp -= SP_level_spellpoint_cost (caster, spell_ob, SPELL_MANA);
1357 if (!skill) 1236 if (!skill)
1358 { 1237 {
1359 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use the %s", &caster->skill, query_name (caster)); 1238 new_draw_info_format (NDI_UNIQUE, 0, op, "You lack the skill %s to use the %s", &caster->skill, query_name (caster));
1360 return 0; 1239 return 0;
1361 } 1240 }
1241
1362 change_skill (op, skill, 0); /* needed for proper exp credit */ 1242 op->change_skill (skill); /* needed for proper exp credit */
1363 } 1243 }
1244
1245 if (INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1246 return RESULT_INT (0);
1364 1247
1365 switch (spell_ob->subtype) 1248 switch (spell_ob->subtype)
1366 { 1249 {
1367 /* The order of case statements is same as the order they show up 1250 /* The order of case statements is same as the order they show up
1368 * in in spells.h. 1251 * in in spells.h.
1369 */ 1252 */
1370 case SP_RAISE_DEAD: 1253 case SP_RAISE_DEAD:
1371 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg); 1254 success = cast_raise_dead_spell (op, caster, spell_ob, dir, stringarg);
1372 break; 1255 break;
1373 1256
1374 case SP_RUNE: 1257 case SP_RUNE:
1407 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob); 1290 success = fire_arch_from_position (op, caster, op->x + freearr_x[dir], op->y + freearr_y[dir], dir, spell_ob);
1408 break; 1291 break;
1409 1292
1410 case SP_SUMMON_GOLEM: 1293 case SP_SUMMON_GOLEM:
1411 success = summon_golem (op, caster, dir, spell_ob); 1294 success = summon_golem (op, caster, dir, spell_ob);
1412 old_shoottype = range_golem;
1413 break; 1295 break;
1414 1296
1415 case SP_DIMENSION_DOOR: 1297 case SP_DIMENSION_DOOR:
1416 /* dimension door needs the actual caster, because that is what is 1298 /* dimension door needs the actual caster, because that is what is
1417 * moved. 1299 * moved.
1550 success = cast_consecrate (op, caster, spell_ob); 1432 success = cast_consecrate (op, caster, spell_ob);
1551 break; 1433 break;
1552 1434
1553 case SP_ANIMATE_WEAPON: 1435 case SP_ANIMATE_WEAPON:
1554 success = animate_weapon (op, caster, spell_ob, dir); 1436 success = animate_weapon (op, caster, spell_ob, dir);
1555 old_shoottype = range_golem;
1556 break; 1437 break;
1557 1438
1558 case SP_LIGHT: 1439 case SP_LIGHT:
1559 success = cast_light (op, caster, spell_ob, dir); 1440 success = cast_light (op, caster, spell_ob, dir);
1560 break; 1441 break;
1573 1454
1574 case SP_AURA: 1455 case SP_AURA:
1575 success = create_aura (op, caster, spell_ob); 1456 success = create_aura (op, caster, spell_ob);
1576 break; 1457 break;
1577 1458
1578 case SP_TOWN_PORTAL:
1579 success = cast_create_town_portal (op, caster, spell_ob, dir);
1580 break;
1581
1582 case SP_PARTY_SPELL: 1459 case SP_PARTY_SPELL:
1583 success = cast_party_spell (op, caster, dir, spell_ob, stringarg); 1460 success = cast_party_spell (op, caster, dir, spell_ob, stringarg);
1584 break; 1461 break;
1585 1462
1586 default: 1463 default:
1587 if (!INVOKE_OBJECT (CAST_SPELL, spell_ob, ARG_OBJECT (op), ARG_OBJECT (caster), ARG_INT (dir), ARG_STRING (stringarg)))
1588 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype); 1464 LOG (llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1589 } 1465 }
1590 1466
1591 /* FIXME - we need some better sound suppport */ 1467 /* FIXME - we need some better sound suppport */
1592 // yes, for example, augment map info with the spell effect 1468 // yes, for example, augment map info with the spell effect
1593 // so clients can calculate the sounds themselves 1469 // so clients can calculate the sounds themselves
1594 //play_sound_map(op->map, op->x, op->y, SOUND_CAST_SPELL_0 + spell_ob->subtype); 1470 //play_sound_map(op->map, op->x, op->y, SOUND_CAST_SPELL_0 + spell_ob->subtype);
1595 1471
1596 /* free the spell arg */
1597 if (settings.casting_time == TRUE && stringarg)
1598 {
1599 free (stringarg);
1600 stringarg = NULL;
1601 }
1602 /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1603 * to something like use_magic_item, but you really want to be able to fire
1604 * it again.
1605 */
1606 if (op->contr)
1607 op->contr->shoottype = (rangetype) old_shoottype;
1608
1609 return success; 1472 return success;
1610} 1473}
1611 1474
1612 1475
1613/* This is called from time.c/process_object(). That function 1476/* This is called from time.c/process_object(). That function
1695 break; 1558 break;
1696 1559
1697 case SP_MAGIC_MISSILE: 1560 case SP_MAGIC_MISSILE:
1698 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1561 if (QUERY_FLAG (victim, FLAG_ALIVE))
1699 { 1562 {
1700 tag_t spell_tag = spell->count;
1701
1702 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1563 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1703 if (!was_destroyed (spell, spell_tag)) 1564
1704 { 1565 if (!spell->destroyed ())
1705 remove_ob (spell); 1566 spell->destroy ();
1706 free_object (spell);
1707 }
1708 } 1567 }
1709 break; 1568 break;
1710 1569
1711 case SP_MOVING_BALL: 1570 case SP_MOVING_BALL:
1712 if (QUERY_FLAG (victim, FLAG_ALIVE)) 1571 if (QUERY_FLAG (victim, FLAG_ALIVE))
1713 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1); 1572 hit_player (victim, spell->stats.dam, spell, spell->attacktype, 1);
1714 else if (victim->material || victim->materialname) 1573 else if (victim->materialname)
1715 save_throw_object (victim, spell->attacktype, spell); 1574 save_throw_object (victim, spell->attacktype, spell);
1716 break; 1575 break;
1717 } 1576 }
1718} 1577}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines