Crossfire Server, Branches 1.12  R18729
spell_util.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_spell_util_c =
3  * "$Id: spell_util.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 
7 /*
8  CrossFire, A Multiplayer game for X-windows
9 
10  Copyright (C) 2006 Mark Wedel & Crossfire Development Team
11  Copyright (C) 1992 Frank Tore Johansen
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 
27  The authors can be reached via e-mail at crossfire-devel@real-time.com
28 */
29 
35 #include <global.h>
36 #include <spells.h>
37 #include <object.h>
38 #include <errno.h>
39 #ifndef __CEXTRACT__
40 #include <sproto.h>
41 #endif
42 #include <sounds.h>
43 #include <assert.h>
44 
45 extern const char *const spell_mapping[];
46 
60 object *find_random_spell_in_ob(object *ob, const char *skill) {
61  int k = 0, s;
62  object *tmp;
63 
64  for (tmp = ob->inv; tmp; tmp = tmp->below)
65  if (tmp->type == SPELL && (!skill || tmp->skill == skill))
66  k++;
67 
68  /* No spells, no need to progess further */
69  if (!k)
70  return NULL;
71 
72  s = RANDOM()%k;
73 
74  for (tmp = ob->inv; tmp; tmp = tmp->below)
75  if (tmp->type == SPELL && (!skill || tmp->skill == skill)) {
76  if (!s)
77  return tmp;
78  else
79  s--;
80  }
81  /* Should never get here, but just in case */
82  return NULL;
83 }
84 
105 void set_spell_skill(object *op, object *caster, object *spob, object *dest) {
106  if (dest->skill)
107  FREE_AND_CLEAR_STR(dest->skill);
108  if (caster == op && spob->skill)
109  dest->skill = add_refcount(spob->skill);
110  else if (caster->skill)
111  dest->skill = add_refcount(caster->skill);
112 }
113 
120 void check_spells(void) {
121 #ifdef SPELL_DEBUG
122  int i;
123  archetype *at;
124 
125  LOG(llevDebug, "Checking spells...\n");
126 
127  for (at = first_archetype; at; at = at->next) {
128  if (at->clone.type == SPELL) {
129  if (at->clone.skill) {
130  for (i = 1; i < NUM_SKILLS; i++)
131  if (!strcmp(skill_names[i], at->clone.skill))
132  break;
133  if (i == NUM_SKILLS) {
134  LOG(llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill);
135  }
136  }
137  /* other_arch is already checked for in the loader */
138  }
139  }
140 
141  i = 0;
142  while (spell_mapping[i]) {
143  if (!find_archetype(spell_mapping[i])) {
144  LOG(llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
145  }
146  i++;
147  }
148  LOG(llevDebug, "Checking spells completed.\n");
149 #endif
150 }
151 
157 void dump_spells(void) {
158  archetype *at;
159 
160  for (at = first_archetype; at; at = at->next) {
161  if (at->clone.type == SPELL) {
162  fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null",
163  at->name, at->clone.other_arch ? at->clone.other_arch->name : "null",
164  at->clone.skill ? at->clone.skill : "null", at->clone.level);
165  }
166  }
167 }
168 
182 void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) {
183 
184  if (spob->other_arch != NULL) {
185  object *effect = arch_to_object(spob->other_arch);
186 
187  effect->x = x;
188  effect->y = y;
189 
190  insert_ob_in_map(effect, map, originator, 0);
191  }
192 }
193 
207 int min_casting_level(const object *caster, const object *spell) {
208  int new_level;
209 
210  if (caster->path_denied&spell->path_attuned) {
211  /* This case is not a bug, just the fact that this function is
212  * usually called BEFORE checking for path_deny. -AV
213  */
214  return 1;
215  }
216  new_level = spell->level
217  +((caster->path_repelled&spell->path_attuned) ? +2 : 0)
218  +((caster->path_attuned&spell->path_attuned) ? -2 : 0);
219  return MAX(new_level, 1);
220 }
221 
222 
237 int caster_level(const object *caster, const object *spell) {
238  int level = caster->level;
239 
240  /* If this is a player, try to find the matching skill */
241  if (caster->type == PLAYER && spell->skill) {
242  int i;
243 
244  for (i = 0; i < NUM_SKILLS; i++)
245  if (caster->contr->last_skill_ob[i]
246  && caster->contr->last_skill_ob[i]->skill == spell->skill) {
247  level = caster->contr->last_skill_ob[i]->level;
248  break;
249  }
250  }
251  /* Got valid caster level. Now adjust for attunement */
252  level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0)
253  +((caster->path_attuned&spell->path_attuned) ? 2 : 0);
254 
255  /* Always make this at least 1. If this is zero, we get divide by zero
256  * errors in various places.
257  */
258  if (level < 1)
259  level = 1;
260  return level;
261 }
262 
281 sint16 SP_level_spellpoint_cost(object *caster, object *spell, int flags) {
282  int sp, grace, level = caster_level(caster, spell);
283 
285  if (spell->stats.sp && spell->stats.maxsp) {
286  sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp)));
287  } else
288  sp = spell->stats.sp;
289 
290  sp *= PATH_SP_MULT(caster, spell);
291  if (!sp && spell->stats.sp)
292  sp = 1;
293 
294  if (spell->stats.grace && spell->stats.maxgrace) {
295  grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace)));
296  } else
297  grace = spell->stats.grace;
298 
299  grace *= PATH_SP_MULT(caster, spell);
300  if (spell->stats.grace && !grace)
301  grace = 1;
302  } else {
303  sp = spell->stats.sp*PATH_SP_MULT(caster, spell);
304  if (spell->stats.sp && !sp)
305  sp = 1;
306  grace = spell->stats.grace*PATH_SP_MULT(caster, spell);
307  if (spell->stats.grace && !grace)
308  grace = 1;
309  }
310  if (flags == SPELL_HIGHEST)
311  return MAX(sp, grace);
312  else if (flags == SPELL_GRACE)
313  return grace;
314  else if (flags == SPELL_MANA)
315  return sp;
316  else {
317  LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
318  return 0;
319  }
320 }
321 
332 int SP_level_dam_adjust(const object *caster, const object *spob) {
333  int level = caster_level(caster, spob);
334  int adj = level-min_casting_level(caster, spob);
335 
336  if (adj < 0)
337  adj = 0;
338  if (spob->dam_modifier)
339  adj /= spob->dam_modifier;
340  else
341  adj = 0;
342  return adj;
343 }
344 
357 int SP_level_duration_adjust(const object *caster, const object *spob) {
358  int level = caster_level(caster, spob);
359  int adj = level-min_casting_level(caster, spob);
360 
361  if (adj < 0)
362  adj = 0;
363  if (spob->duration_modifier)
364  adj /= spob->duration_modifier;
365  else
366  adj = 0;
367 
368  return adj;
369 }
370 
383 int SP_level_range_adjust(const object *caster, const object *spob) {
384  int level = caster_level(caster, spob);
385  int adj = level-min_casting_level(caster, spob);
386 
387  if (adj < 0)
388  adj = 0;
389  if (spob->range_modifier)
390  adj /= spob->range_modifier;
391  else
392  adj = 0;
393 
394  return adj;
395 }
396 
408 object *check_spell_known(object *op, const char *name) {
409  object *spop;
410 
411  for (spop = op->inv; spop; spop = spop->below)
412  if (spop->type == SPELL && !strcmp(spop->name, name))
413  return spop;
414 
415  return NULL;
416 }
417 
430 object *lookup_spell_by_name(object *op, const char *spname) {
431  object *spob1 = NULL, *spob2 = NULL, *spob;
432  int nummatch = 0;
433 
434  if (spname == NULL)
435  return NULL;
436 
437  /* Try to find the spell. We store the results in spob1
438  * and spob2 - spob1 is only taking the length of
439  * the past spname, spob2 uses the length of the spell name.
440  */
441  for (spob = op->inv; spob; spob = spob->below) {
442  if (spob->type == SPELL) {
443  if (!strncmp(spob->name, spname, strlen(spname))) {
444  if (strlen(spname) == strlen(spob->name))
445  /* Perfect match, return it. */
446  return spob;
447  nummatch++;
448  spob1 = spob;
449  } else if (!strncmp(spob->name, spname, strlen(spob->name))) {
450  /* if spells have ambiguous names, it makes matching
451  * really difficult. (eg, fire and fireball would
452  * fall into this category). It shouldn't be hard to
453  * make sure spell names don't overlap in that fashion.
454  */
455  if (spob2)
456  LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name);
457  spob2 = spob;
458  }
459  }
460  }
461  /* if we have best match, return it. Otherwise, if we have one match
462  * on the loser match, return that, otehrwise null
463  */
464  if (spob2)
465  return spob2;
466  if (spob1 && nummatch == 1)
467  return spob1;
468  return NULL;
469 }
470 
490 int reflwall(mapstruct *m, int x, int y, object *sp_op) {
491  object *op;
492 
493  if (OUT_OF_REAL_MAP(m, x, y))
494  return 0;
495  for (op = GET_MAP_OB(m, x, y); op != NULL; op = op->above)
496  if (QUERY_FLAG(op, FLAG_REFL_SPELL)
497  && (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10)))
498  return 1;
499 
500  return 0;
501 }
502 
517 int cast_create_obj(object *op, object *new_op, int dir) {
518  mapstruct *m;
519  sint16 sx, sy;
520 
521  if (dir
522  && ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP)
523  || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) {
525  "Something is in the way. You cast it at your feet.", NULL);
526  dir = 0;
527  }
528  new_op->x = op->x+freearr_x[dir];
529  new_op->y = op->y+freearr_y[dir];
530  if (dir == 0)
531  insert_ob_in_map(new_op, op->map, op, INS_BELOW_ORIGINATOR);
532  else
533  insert_ob_in_map(new_op, op->map, op, 0);
534  return dir;
535 }
536 
555 int ok_to_put_more(mapstruct *m, sint16 x, sint16 y, object *op, uint32 immune_stop) {
556  object *tmp;
557  int mflags;
558  mapstruct *mp;
559 
560  mp = m;
561  mflags = get_map_flags(m, &mp, x, y, &x, &y);
562 
563  if (mflags&P_OUT_OF_MAP)
564  return 0;
565 
566  if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(mp, x, y)))
567  return 0;
568 
569  for (tmp = GET_MAP_OB(mp, x, y); tmp != NULL; tmp = tmp->above) {
570  /* If there is a counterspell on the space, and this
571  * object is using magic, don't progess. I believe we could
572  * leave this out and let in progress, and other areas of the code
573  * will then remove it, but that would seem to to use more
574  * resources, and may not work as well if a player is standing
575  * on top of a counterwall spell (may hit the player before being
576  * removed.) On the other hand, it may be more dramatic for the
577  * spell to actually hit the counterwall and be sucked up.
578  */
579  if ((tmp->attacktype&AT_COUNTERSPELL)
580  && (tmp->type != PLAYER)
581  && !QUERY_FLAG(tmp, FLAG_MONSTER)
582  && (tmp->type != WEAPON)
583  && (tmp->type != BOW)
584  && (tmp->type != ARROW)
585  && (tmp->type != GOLEM)
586  && (immune_stop&AT_MAGIC))
587  return 0;
588 
589  /* This is to prevent 'out of control' spells. Basically, this
590  * limits one spell effect per space per spell. This is definitely
591  * needed for performance reasons, and just for playability I believe.
592  * there are no such things as multispaced spells right now, so
593  * we don't need to worry about the head.
594  * We only need to go down this path is maxhp is set on both objects -
595  * otherwise, no reason to check. But if we do check, we need to
596  * do some extra work, looking in the spell_tags[] of each object,
597  * if they have it set.
598  */
599  if (tmp->type == op->type
600  && tmp->subtype == op->subtype
601  && tmp->stats.maxhp
602  && op->stats.maxhp) {
603  if ((tmp->stats.maxhp == op->stats.maxhp)
604  || (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, op->stats.maxhp))
605  || (op->spell_tags && OB_SPELL_TAG_MATCH(op, tmp->stats.maxhp))) {
607  return 0;
608  }
609 
610  /* if both objects have spell tags, then if the two tags entries
611  * from either match, that also counts. Need to check
612  * the spell_tags, because 0 values are allowed to match
613  */
614  if (op->spell_tags && tmp->spell_tags) {
615  int i;
616 
617  for (i = 0; i < SPELL_TAG_SIZE; i++) {
618  if (op->spell_tags[i] && op->spell_tags[i] == tmp->spell_tags[i])
620  return 0;
621  }
622  }
623  }
624  /* Perhaps we should also put checks in for no magic and unholy
625  * ground to prevent it from moving along?
626  */
627  }
628  /* If it passes the above tests, it must be OK */
629  return 1;
630 }
631 
653 int fire_arch_from_position(object *op, object *caster, sint16 x, sint16 y, int dir, object *spell) {
654  object *tmp;
655  int mflags;
656  mapstruct *m;
657 
658  if (spell->other_arch == NULL)
659  return 0;
660 
661  m = op->map;
662  mflags = get_map_flags(m, &m, x, y, &x, &y);
663  if (mflags&P_OUT_OF_MAP) {
664  return 0;
665  }
666 
667  tmp = arch_to_object(spell->other_arch);
668  if (tmp == NULL)
669  return 0;
670 
671  if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(m, x, y))) {
672  if (caster->type == PLAYER)
673  /* If caster is not player, it's for instance a swarm, so don't say there's an issue. */
675  "You can't cast the spell on top of a wall!", NULL);
676  free_object(tmp);
677  return 0;
678  }
679 
680 
681 
682  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
683  tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell);
684  /* code in time.c uses food for some things, duration for others */
685  tmp->stats.food = tmp->duration;
686  tmp->range = spell->range+SP_level_range_adjust(caster, spell);
687  tmp->attacktype = spell->attacktype;
688  tmp->x = x;
689  tmp->y = y;
690  tmp->direction = dir;
691  if (get_owner(op) != NULL)
692  copy_owner(tmp, op);
693  else
694  set_owner(tmp, op);
695  tmp->level = caster_level(caster, spell);
696  set_spell_skill(op, caster, spell, tmp);
697 
698  /* needed for AT_HOLYWORD, AT_GODPOWER stuff */
699  if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) {
700  if (!tailor_god_spell(tmp, op))
701  return 0;
702  }
703  if (QUERY_FLAG(tmp, FLAG_IS_TURNABLE))
704  SET_ANIMATION(tmp, dir);
705 
706  if ((tmp = insert_ob_in_map(tmp, m, op, 0)) == NULL)
707  return 1;
708 
709  ob_process(tmp);
710 
711  return 1;
712 }
713 
714 
715 
716 /*****************************************************************************
717  *
718  * Code related to rods - perhaps better located in another file?
719  *
720  ****************************************************************************/
721 
728 void regenerate_rod(object *rod) {
729  if (rod->stats.hp < rod->stats.maxhp) {
730  rod->stats.hp += 1+rod->stats.maxhp/10;
731 
732  if (rod->stats.hp > rod->stats.maxhp)
733  rod->stats.hp = rod->stats.maxhp;
734  }
735 }
736 
743 void drain_rod_charge(object *rod) {
744  rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
745 }
746 
753 void drain_wand_charge(object *wand) {
754  assert(wand->type == WAND);
755 
756  if (!(--wand->stats.food)) {
757  object *tmp;
758  if (wand->arch) {
759  CLEAR_FLAG(wand, FLAG_ANIMATE);
760  wand->face = wand->arch->clone.face;
761  wand->speed = 0;
762  update_ob_speed(wand);
763  }
764  if ((tmp = get_player_container(wand)))
765  esrv_update_item(UPD_ANIM, tmp, wand);
766  }
767 }
768 
779 object *find_target_for_friendly_spell(object *op, int dir) {
780  object *tmp;
781  mapstruct *m;
782  sint16 x, y;
783  int mflags;
784 
785  /* I don't really get this block - if op isn't a player or rune,
786  * we then make the owner of this object the target.
787  * The owner could very well be no where near op.
788  */
789  if (op->type != PLAYER && op->type != RUNE) {
790  tmp = get_owner(op);
791  /* If the owner does not exist, or is not a monster, than apply the spell
792  * to the caster.
793  */
794  if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER))
795  tmp = op;
796  } else {
797  m = op->map;
798  x = op->x+freearr_x[dir];
799  y = op->y+freearr_y[dir];
800 
801  mflags = get_map_flags(m, &m, x, y, &x, &y);
802 
803  if (mflags&P_OUT_OF_MAP)
804  tmp = NULL;
805  else {
806  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
807  if (tmp->type == PLAYER)
808  break;
809  }
810  }
811  }
812  /* didn't find a player there, look in current square for a player */
813  if (tmp == NULL)
814  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
815  if (tmp->type == PLAYER)
816  break;
817  /* Don't forget to browse inside transports ! - gros 2006/07/25 */
818  if (tmp->type == TRANSPORT) {
819  object *inv;
820 
821  for (inv = tmp->inv; inv; inv = inv->below) {
822  if ((inv->type == PLAYER) && (op == inv))
823  return inv;
824  }
825  }
826  }
827  return tmp;
828 }
829 
830 
831 
852 int spell_find_dir(mapstruct *m, int x, int y, object *exclude) {
853  int i, max = SIZEOFFREE;
854  sint16 nx, ny;
855  int owner_type = 0, mflags;
856  object *tmp;
857  mapstruct *mp;
858 
859  if (exclude && exclude->head)
860  exclude = exclude->head;
861  if (exclude && exclude->type)
862  owner_type = exclude->type;
863 
864  for (i = rndm(1, 8); i < max; i++) {
865  nx = x+freearr_x[i];
866  ny = y+freearr_y[i];
867  mp = m;
868  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
869  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
870  continue;
871 
872  tmp = GET_MAP_OB(mp, nx, ny);
873 
874  while (tmp != NULL
875  && (((owner_type == PLAYER && !QUERY_FLAG(tmp, FLAG_MONSTER) && !QUERY_FLAG(tmp, FLAG_GENERATOR) && !(tmp->type == PLAYER && op_on_battleground(tmp, NULL, NULL, NULL)))
876  || (owner_type != PLAYER && tmp->type != PLAYER))
877  || (tmp == exclude || (tmp->head && tmp->head == exclude))))
878  tmp = tmp->above;
879 
880  if (tmp != NULL && can_see_monsterP(m, x, y, i))
881  return freedir[i];
882  }
883  return -1; /* flag for "keep going the way you were" */
884 }
885 
886 
887 
901 static int put_a_monster(object *op, const char *monstername) {
902  object *tmp, *head = NULL, *prev = NULL;
903  archetype *at;
904  int dir;
905 
906  /* Handle cases where we are passed a bogus mosntername */
907 
908  if ((at = find_archetype(monstername)) == NULL)
909  return 0;
910 
911  /* find a free square nearby
912  * first we check the closest square for free squares
913  */
914 
915  dir = find_first_free_spot(&at->clone, op->map, op->x, op->y);
916  if (dir != -1) {
917  /* This is basically grabbed for generate monster. Fixed 971225 to
918  * insert multipart monsters properly
919  */
920  while (at != NULL) {
921  tmp = arch_to_object(at);
922  tmp->x = op->x+freearr_x[dir]+at->clone.x;
923  tmp->y = op->y+freearr_y[dir]+at->clone.y;
924  tmp->map = op->map;
925  if (head) {
926  tmp->head = head;
927  prev->more = tmp;
928  }
929  if (!head)
930  head = tmp;
931  prev = tmp;
932  at = at->more;
933  }
934 
935  if (head->randomitems)
936  create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
937 
938  insert_ob_in_map(head, op->map, op, 0);
939 
940  /* thought it'd be cool to insert a burnout, too.*/
941  tmp = create_archetype("burnout");
942  tmp->map = op->map;
943  tmp->x = op->x+freearr_x[dir];
944  tmp->y = op->y+freearr_y[dir];
945  insert_ob_in_map(tmp, op->map, op, 0);
946  return 1;
947  } else {
948  return 0;
949  }
950 }
951 
970 int summon_hostile_monsters(object *op, int n, const char *monstername) {
971  int i, put = 0;
972 
973  for (i = 0; i < n; i++)
974  put += put_a_monster(op, monstername);
975 
976  return put;
977 }
978 
979 
1004 void shuffle_attack(object *op, int change_face) {
1005  int i;
1006 
1007  i = rndm(0, 21);
1009  if (change_face) {
1010  SET_ANIMATION(op, ATTACKS[i].face);
1011  }
1012 }
1013 
1014 
1025 static void prayer_failure(object *op, int failure, int power) {
1026  const char *godname;
1027  object *tmp;
1028 
1029  if (!strcmp((godname = determine_god(op)), "none"))
1030  godname = "Your spirit";
1031 
1032  if (failure <= -20 && failure > -40) { /* wonder */
1034  "%s gives a sign to renew your faith.",
1035  "%s gives a sign to renew your faith.",
1036  godname);
1038  cast_cone(op, op, 0, tmp);
1039  free_object(tmp);
1040  } else if (failure <= -40 && failure > -60) { /* confusion */
1042  "Your diety touches your mind!", NULL);
1043  confuse_living(op, op, 99);
1044  } else if (failure <= -60 && failure > -150) { /* paralysis */
1046  "%s requires you to pray NOW. You comply, ignoring all else.",
1047  "%s requires you to pray NOW. You comply, ignoring all else.",
1048  godname);
1049 
1050  paralyze_living(op, op, 99);
1051  } else if (failure <= -150) { /* blast the immediate area */
1052  tmp = create_archetype(GOD_POWER);
1054  "%s smites you!",
1055  "%s smites you!",
1056  godname);
1057  /* Put a cap on power - this is effectively cost of the spell minus
1058  * characters current grace. Thus, if spell costs 30 grace and
1059  * character has -100 grace, this is cast as a level 130 spell.
1060  * Things start to break in those cases.
1061  */
1062  cast_magic_storm(op, tmp, power>50?50:power);
1063  }
1064 }
1065 
1078 void spell_failure(object *op, int failure, int power, object *skill) {
1079  object *tmp;
1080 
1082  return;
1083 
1084  if (failure <= -20 && failure > -40) { /* wonder */
1086  "Your spell causes an unexpected effect.", NULL);
1088  cast_cone(op, op, 0, tmp);
1089  free_object(tmp);
1090  } else if (failure <= -40 && failure > -60) { /* confusion */
1092  "Your magic recoils on you, making you confused!", NULL);
1093  confuse_living(op, op, 99);
1094  } else if (failure <= -60 && failure > -80) { /* paralysis */
1096  "Your magic stuns you!", NULL);
1097  paralyze_living(op, op, 99);
1098  } else if (failure <= -80) { /* blast the immediate area */
1099  object *tmp;
1100 
1101  /* Safety check to make sure we don't get any mana storms in scorn */
1102  if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) {
1104  "The magic warps and you are turned inside out!", NULL);
1105  hit_player(op, 9998, op, AT_INTERNAL, 1);
1106  } else {
1108  "You lose control of the mana! The uncontrolled magic blasts you!",
1109  NULL);
1111  tmp->level = skill->level;
1112  tmp->x = op->x;
1113  tmp->y = op->y;
1114 
1115  /* increase the area of destruction a little for more powerful spells */
1116  tmp->range += isqrt(power);
1117 
1118  if (power > 25)
1119  tmp->stats.dam = 25+isqrt(power);
1120  else
1121  tmp->stats.dam = power; /* nasty recoils! */
1122 
1123  tmp->stats.maxhp = tmp->count;
1124  insert_ob_in_map(tmp, op->map, NULL, 0);
1125  }
1126  }
1127 }
1128 
1134 static int can_be_transmuted(object *op) {
1135  if (op->invisible)
1136  return 0;
1137 
1138  if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON)
1139  return 1;
1140 
1141  return 0;
1142 }
1143 
1156 static void transmute_item_to_flower(object *op) {
1157  object *force;
1158  object *item;
1159  object *flower;
1160  object *first = NULL;
1161  int count = 0;
1162  char name[HUGE_BUF];
1163 
1164  for (item = op->inv; item; item = item->below) {
1165  if (can_be_transmuted(item)) {
1166  if (!first)
1167  first = item;
1168  count++;
1169  }
1170  }
1171 
1172  if (count == 0)
1173  return;
1174 
1175  count = rndm(0, count-1);
1176  for (item = first; item; item = item->below) {
1177  if (can_be_transmuted(item)) {
1178  count--;
1179  if (count < 0)
1180  break;
1181  }
1182  }
1183 
1184  if (!item)
1185  return;
1186 
1187  force = create_archetype(FORCE_NAME);
1188  force->duration = 100+rndm(0, 10)*100;
1190  force->speed = 1;
1191  update_ob_speed(force);
1192 
1193  flower = create_archetype("flowers_permanent");
1194 
1195  if (QUERY_FLAG(item, FLAG_APPLIED))
1197  remove_ob(item);
1198  flower->weight = item->nrof ? item->nrof*item->weight : item->weight;
1199  item->weight = 0;
1200  esrv_del_item(op->contr, item->count);
1201  insert_ob_in_ob(item, force);
1202 
1203  query_short_name(item, name, HUGE_BUF);
1206  "Your %s turns to a flower!",
1207  "Your %s turns to a flower!",
1208  name);
1209 
1210  insert_ob_in_ob(force, flower);
1211  flower = insert_ob_in_ob(flower, op);
1212  esrv_send_item(op, flower);
1213 }
1214 
1225 static void swap_random_stats(object *op) {
1226  object *force;
1227  int first, second;
1228 
1229  first = RANDOM()%NUM_STATS;
1230  second = RANDOM()%(NUM_STATS-1);
1231  if (second >= first)
1232  second++;
1233 
1236  "You suddenly feel really weird!",
1237  "You suddenly feel really weird!");
1238 
1239  force = create_archetype(FORCE_NAME);
1240  force->duration = 100+rndm(0, 10)*100;
1241  force->speed = 1;
1242  SET_FLAG(force, FLAG_APPLIED);
1243  set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second));
1244  set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first));
1245  update_ob_speed(force);
1246  insert_ob_in_ob(force, op);
1247  change_abil(op, force);
1248  fix_object(op);
1249 }
1250 
1261 static void handle_spell_confusion(object *op) {
1262  switch (RANDOM()%2) {
1263  case 0:
1265  break;
1266 
1267  case 1:
1268  swap_random_stats(op);
1269  break;
1270  }
1271 }
1272 
1308 int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
1309 
1310  const char *godname;
1311  int success = 0, mflags, cast_level = 0, old_shoottype;
1312  object *skill = NULL;
1313  int confusion_effect = 0;
1314 
1315  old_shoottype = op->contr ? op->contr->shoottype : 0;
1316 
1317  if (!spell_ob) {
1318  LOG(llevError, "cast_spell: null spell object passed\n");
1319  return 0;
1320  }
1321  if (!strcmp((godname = determine_god(op)), "none"))
1322  godname = "A random spirit";
1323 
1324  /* the caller should set caster to op if appropriate */
1325  if (!caster) {
1326  LOG(llevError, "cast_spell: null caster object passed\n");
1327  return 0;
1328  }
1329  if (spell_ob->anim_suffix)
1330  apply_anim_suffix(caster, spell_ob->anim_suffix);
1331 
1332  /* Handle some random effect if confused. */
1333  if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) {
1334  if (rndm(0, 5) < 4) {
1335  spell_ob = find_random_spell_in_ob(op, NULL);
1338  "In your confused state, you're not sure of what you cast!",
1339  "In your confused state, you're not sure of what you cast!");
1340  } else
1341  /* We fall through to deplate sp/gr, and do some checks. */
1342  confusion_effect = 1;
1343  }
1344 
1345  /* if caster is a spell casting object, this normally shouldn't be
1346  * an issue, because they don't have any spellpaths set up.
1347  */
1348  if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) {
1350  "That spell path is denied to you.", NULL);
1351  return 0;
1352  }
1353 
1354  /* if it is a player casting the spell, and they are really casting it
1355  * (vs it coming from a wand, scroll, or whatever else), do some
1356  * checks. We let monsters do special things - eg, they
1357  * don't need the skill, bypass level checks, etc. The monster function
1358  * should take care of that.
1359  * Remove the wiz check here and move it further down - some spells
1360  * need to have the right skill pointer passed, so we need to
1361  * at least process that code.
1362  */
1363  if (op->type == PLAYER && op == caster) {
1364  cast_level = caster_level(caster, spell_ob);
1365  if (spell_ob->skill) {
1366  skill = find_skill_by_name(op, spell_ob->skill);
1367  if (!skill) {
1370  "You need the skill %s to cast %s.",
1371  "You need the skill %s to cast %s.",
1372  spell_ob->skill, spell_ob->name);
1373  return 0;
1374  }
1375  if (min_casting_level(op, spell_ob) > cast_level && !QUERY_FLAG(op, FLAG_WIZ)) {
1377  "You lack enough skill to cast that spell.", NULL);
1378  return 0;
1379  }
1380  }
1381  /* If the caster is the wiz, they don't ever fail, and don't have
1382  * to have sufficient grace/mana.
1383  */
1384  if (!QUERY_FLAG(op, FLAG_WIZ)) {
1385  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA)
1386  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) > op->stats.sp) {
1388  "You don't have enough mana.", NULL);
1389  return 0;
1390  }
1391  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)
1392  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) > op->stats.grace) {
1393  if (random_roll(0, op->stats.Wis-1, op, PREFER_HIGH)+op->stats.grace-10*SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)/op->stats.maxgrace > 0) {
1396  "%s grants your prayer, though you are unworthy.",
1397  "%s grants your prayer, though you are unworthy.",
1398  godname);
1399  } else {
1400  prayer_failure(op, op->stats.grace, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)-op->stats.grace);
1403  "%s ignores your prayer.",
1404  "%s ignores your prayer.",
1405  godname);
1406  return 0;
1407  }
1408  }
1409 
1410  /* player/monster is trying to cast the spell. might fumble it */
1411  if (spell_ob->stats.grace
1412  && random_roll(0, 99, op, PREFER_HIGH) < (spell_ob->level/(float)MAX(1, op->level)*cleric_chance[op->stats.Wis])) {
1413  play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell_ob, 0, "fumble");
1415  "You fumble the spell.", NULL);
1416  if (settings.casting_time == TRUE) {
1417  op->casting_time = -1;
1418  }
1419  op->stats.grace -= random_roll(1, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1420  return 0;
1421  } else if (spell_ob->stats.sp) {
1422  int failure = random_roll(0, 199, op, PREFER_HIGH)-op->contr->encumbrance+op->level-spell_ob->level+35;
1423 
1424  if (failure < 0) {
1425  draw_ext_info(NDI_UNIQUE, 0, op,
1427  "You bungle the spell because you have too much heavy equipment in use.",
1428  NULL);
1430  spell_failure(op, failure, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), skill);
1431  op->contr->shoottype = old_shoottype;
1432  op->stats.sp -= random_roll(0, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1433  return 0;
1434  }
1435  }
1436  }
1437  }
1438 
1439  mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL);
1440 
1441  /* See if we can cast a spell here. If the caster and op are
1442  * not alive, then this would mean that the mapmaker put the
1443  * objects on the space - presume that they know what they are
1444  * doing.
1445  */
1446  if (spell_ob->type == SPELL
1447  && caster->type != POTION
1448  && !QUERY_FLAG(op, FLAG_WIZCAST)
1449  && (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE))
1450  && !QUERY_FLAG(op, FLAG_MONSTER)
1451  && (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) {
1452 
1453  if (op->type != PLAYER)
1454  return 0;
1455 
1456  if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace)
1458  "This ground is unholy! %s ignores you.",
1459  "This ground is unholy! %s ignores you.",
1460  godname);
1461  else
1462  switch (op->contr->shoottype) {
1463  case range_magic:
1465  "Something blocks your spellcasting.", NULL);
1466  break;
1467 
1468  case range_misc:
1470  "Something blocks the magic of your item.", NULL);
1471  break;
1472  case range_golem:
1474  "Something blocks the magic of your scroll.", NULL);
1475  break;
1476 
1477  default:
1478  break;
1479  }
1480  return 0;
1481  }
1482 
1483  if (caster == op && settings.casting_time == TRUE && spell_ob->type == SPELL) {
1484  if (op->casting_time == -1) { /* begin the casting */
1485  op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob);
1486  op->spell = spell_ob;
1487  /* put the stringarg into the object struct so that when the
1488  * spell is actually cast, it knows about the stringarg.
1489  * necessary for the invoke command spells.
1490  */
1491  if (stringarg) {
1492  op->spellarg = strdup_local(stringarg);
1493  } else
1494  op->spellarg = NULL;
1495  return 0;
1496  } else if (op->casting_time != 0) {
1497  if (op->type == PLAYER)
1499  "You are casting!", NULL);
1500  return 0;
1501  } else { /* casting_time == 0 */
1502  op->casting_time = -1;
1503  spell_ob = op->spell;
1504  stringarg = op->spellarg;
1505  }
1506  } else {
1507  if (!QUERY_FLAG(caster, FLAG_WIZ)) {
1508  /* Take into account how long it takes to cast the spell.
1509  * if the player is casting it, then we use the time in
1510  * the spell object. If it is a spell object, have it
1511  * take two ticks. Things that cast spells on the players
1512  * behalf (eg, altars, and whatever else) shouldn't cost
1513  * the player any time.
1514  * Ignore casting time for firewalls
1515  */
1516  if (caster == op && caster->type != FIREWALL) {
1517  op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1518  /* Other portions of the code may also decrement the speed of the player, so
1519  * put a lower limit so that the player isn't stuck here too long
1520  */
1521  if ((spell_ob->casting_time > 0)
1522  && op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed))
1523  op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1524  } else if (caster->type == WAND
1525  || caster->type == HORN
1526  || caster->type == ROD
1527  || caster->type == POTION
1528  || caster->type == SCROLL) {
1529  op->speed_left -= 2*FABS(op->speed);
1530  }
1531  }
1532  }
1533 
1534  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1535  op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE);
1536  op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA);
1537  }
1538 
1539  /* We want to try to find the skill to properly credit exp.
1540  * for spell casting objects, the exp goes to the skill the casting
1541  * object requires.
1542  */
1543  if (op != caster && !skill && caster->skill) {
1544  skill = find_skill_by_name(op, caster->skill);
1545  if (!skill) {
1546  char name[MAX_BUF];
1547 
1548  query_name(caster, name, MAX_BUF);
1551  "You lack the skill %s to use the %s",
1552  "You lack the skill %s to use the %s",
1553  caster->skill, name);
1554  return 0;
1555  }
1556  change_skill(op, skill, 0); /* needed for proper exp credit */
1557  }
1558 
1559  /* Need to get proper ownership for spells cast via runes - these are not
1560  * the normal 'rune of fire', but rather the magic runes that let the player
1561  * put some other spell into the rune (glyph, firetrap, magic rune, etc)
1562  */
1563  if (caster->type == RUNE) {
1564  object *owner = get_owner(caster);
1565 
1566  if (owner)
1567  skill = find_skill_by_name(owner, caster->skill);
1568  }
1569 
1570  if (confusion_effect) {
1571  /* If we get here, the confusion effect was 'random effect', so do it and bail out. */
1574  "In your confused state, you can't control the magic!",
1575  "In your confused state, you can't control the magic!");
1577  return 0;
1578  }
1579 
1580  play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name);
1581 
1582  switch (spell_ob->subtype) {
1583  /* The order of case statements is same as the order they show up
1584  * in in spells.h.
1585  */
1586  case SP_RAISE_DEAD:
1587  success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg);
1588  break;
1589 
1590  case SP_RUNE:
1591  success = write_rune(op, caster, spell_ob, dir, stringarg);
1592  break;
1593 
1594  case SP_MAKE_MARK:
1595  success = write_mark(op, spell_ob, stringarg);
1596  break;
1597 
1598  case SP_BOLT:
1599  success = fire_bolt(op, caster, dir, spell_ob, skill);
1600  break;
1601 
1602  case SP_BULLET:
1603  success = fire_bullet(op, caster, dir, spell_ob);
1604  break;
1605 
1606  case SP_CONE:
1607  success = cast_cone(op, caster, dir, spell_ob);
1608  break;
1609 
1610  case SP_BOMB:
1611  success = create_bomb(op, caster, dir, spell_ob);
1612  break;
1613 
1614  case SP_WONDER:
1615  success = cast_wonder(op, caster, dir, spell_ob);
1616  break;
1617 
1618  case SP_SMITE:
1619  success = cast_smite_spell(op, caster, dir, spell_ob);
1620  break;
1621 
1622  case SP_MAGIC_MISSILE:
1623  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1624  break;
1625 
1626  case SP_SUMMON_GOLEM:
1627  success = summon_golem(op, caster, dir, spell_ob);
1628  old_shoottype = range_golem;
1629  break;
1630 
1631  case SP_DIMENSION_DOOR:
1632  /* dimension door needs the actual caster, because that is what is
1633  * moved.
1634  */
1635  success = dimension_door(op, caster, spell_ob, dir);
1636  break;
1637 
1638  case SP_MAGIC_MAPPING:
1639  if (op->type == PLAYER) {
1640  spell_effect(spell_ob, op->x, op->y, op->map, op);
1641  draw_magic_map(op);
1642  success = 1;
1643  } else
1644  success = 0;
1645  break;
1646 
1647  case SP_MAGIC_WALL:
1648  success = magic_wall(op, caster, dir, spell_ob);
1649  break;
1650 
1651  case SP_DESTRUCTION:
1652  success = cast_destruction(op, caster, spell_ob);
1653  break;
1654 
1655  case SP_PERCEIVE_SELF:
1656  success = perceive_self(op);
1657  break;
1658 
1659  case SP_WORD_OF_RECALL:
1660  success = cast_word_of_recall(op, caster, spell_ob);
1661  break;
1662 
1663  case SP_INVISIBLE:
1664  success = cast_invisible(op, caster, spell_ob);
1665  break;
1666 
1667  case SP_PROBE:
1668  success = probe(op, caster, spell_ob, dir);
1669  break;
1670 
1671  case SP_HEALING:
1672  success = cast_heal(op, caster, spell_ob, dir);
1673  break;
1674 
1675  case SP_CREATE_FOOD:
1676  success = cast_create_food(op, caster, spell_ob, dir, stringarg);
1677  break;
1678 
1679  case SP_EARTH_TO_DUST:
1680  success = cast_earth_to_dust(op, caster, spell_ob);
1681  break;
1682 
1683  case SP_CHANGE_ABILITY:
1684  success = cast_change_ability(op, caster, spell_ob, dir, 0);
1685  break;
1686 
1687  case SP_BLESS:
1688  success = cast_bless(op, caster, spell_ob, dir);
1689  break;
1690 
1691  case SP_CURSE:
1692  success = cast_curse(op, caster, spell_ob, dir);
1693  break;
1694 
1695  case SP_SUMMON_MONSTER:
1696  success = summon_object(op, caster, spell_ob, dir, stringarg);
1697  break;
1698 
1699  case SP_CHARGING:
1700  success = recharge(op, caster, spell_ob);
1701  break;
1702 
1703  case SP_POLYMORPH:
1704 #if 0
1705  /* Not great, but at least provide feedback so if players do have
1706  * polymorph (ie, find it as a preset item or left over from before
1707  * it was disabled), they get some feedback.
1708  */
1710  "The spell fizzles", NULL);
1711  success = 0;
1712 #else
1713  success = cast_polymorph(op, caster, spell_ob, dir);
1714 #endif
1715  break;
1716 
1717  case SP_ALCHEMY:
1718  success = alchemy(op, caster, spell_ob);
1719  break;
1720 
1721  case SP_REMOVE_CURSE:
1722  success = remove_curse(op, caster, spell_ob);
1723  break;
1724 
1725  case SP_IDENTIFY:
1726  success = cast_identify(op, caster, spell_ob);
1727  break;
1728 
1729  case SP_DETECTION:
1730  success = cast_detection(op, caster, spell_ob);
1731  break;
1732 
1733  case SP_MOOD_CHANGE:
1734  success = mood_change(op, caster, spell_ob);
1735  break;
1736 
1737  case SP_MOVING_BALL:
1738  if (spell_ob->path_repelled
1739  && (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) {
1741  "You lack the proper attunement to cast %s",
1742  "You lack the proper attunement to cast %s",
1743  spell_ob->name);
1744  success = 0;
1745  } else
1746  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1747  break;
1748 
1749  case SP_SWARM:
1750  success = fire_swarm(op, caster, spell_ob, dir);
1751  break;
1752 
1753  case SP_CHANGE_MANA:
1754  success = cast_transfer(op, caster, spell_ob, dir);
1755  break;
1756 
1757  case SP_DISPEL_RUNE:
1758  /* in rune.c */
1759  success = dispel_rune(op, caster, spell_ob, skill, dir);
1760  break;
1761 
1762  case SP_CREATE_MISSILE:
1763  success = cast_create_missile(op, caster, spell_ob, dir, stringarg);
1764  break;
1765 
1766  case SP_CONSECRATE:
1767  success = cast_consecrate(op, caster, spell_ob);
1768  break;
1769 
1770  case SP_ANIMATE_WEAPON:
1771  success = animate_weapon(op, caster, spell_ob, dir);
1772  old_shoottype = range_golem;
1773  break;
1774 
1775  case SP_LIGHT:
1776  success = cast_light(op, caster, spell_ob, dir);
1777  break;
1778 
1779  case SP_CHANGE_MAP_LIGHT:
1780  success = cast_change_map_lightlevel(op, caster, spell_ob);
1781  break;
1782 
1783  case SP_FAERY_FIRE:
1784  success = cast_destruction(op, caster, spell_ob);
1785  break;
1786 
1787  case SP_CAUSE_DISEASE:
1788  success = cast_cause_disease(op, caster, spell_ob, dir);
1789  break;
1790 
1791  case SP_AURA:
1792  success = create_aura(op, caster, spell_ob);
1793  break;
1794 
1795  case SP_TOWN_PORTAL:
1796  success = cast_create_town_portal(op, caster, spell_ob, dir);
1797  break;
1798 
1799  case SP_ITEM_CURSE_BLESS:
1800  success = cast_item_curse_or_curse(op, caster, spell_ob);
1801  break;
1802 
1803  default:
1804  LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1805  }
1806 
1807  /* FIXME - we need some better sound suppport */
1808  /* free the spell arg */
1809  if (settings.casting_time == TRUE && stringarg) {
1810  free(stringarg);
1811  stringarg = NULL;
1812  }
1813  /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1814  * to something like use_magic_item, but you really want to be able to fire
1815  * it again.
1816  */
1817  if (op->contr)
1818  op->contr->shoottype = old_shoottype;
1819 
1820  return success;
1821 }
1822 
1829 void store_spell_expiry(object *spell) {
1830  /* Keep when to warn the player of expiration */
1831  char dur[10];
1832  int i = spell->duration/5;
1833 
1834  if (!i)
1835  i = 1;
1836  snprintf(dur, sizeof(dur), "%d", i);
1837  set_ob_key_value(spell, "spell_expiry_warn_1", dur, 1);
1838  i = i/5;
1839  if (i > 0) {
1840  snprintf(dur, sizeof(dur), "%d", i);
1841  set_ob_key_value(spell, "spell_expiry_warn_2", dur, 1);
1842  }
1843 }
1844 
1854 void check_spell_expiry(object *spell) {
1855  const char *key;
1856 
1857  if (!spell->env || !spell->env->type == PLAYER)
1858  return;
1859 
1860  if ((key = get_ob_key_value(spell, "spell_expiry_warn_1")) != NULL) {
1861  if (spell->duration == atoi(key)) {
1863  "The effects of your %s are draining out.", NULL, spell->name);
1864  return;
1865  }
1866  }
1867  if ((key = get_ob_key_value(spell, "spell_expiry_warn_2")) != NULL) {
1868  if (spell->duration == atoi(key)) {
1870  "The effects of your %s are about to expire.", NULL, spell->name);
1871  return;
1872  }
1873  }
1874 }
#define AP_UNAPPLY
Definition: define.h:1010
#define AT_HOLYWORD
Definition: attack.h:125
#define MSG_TYPE_SKILL_MISSING
Definition: newclient.h:501
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny)
Definition: map.c:330
void drain_rod_charge(object *rod)
Definition: spell_util.c:743
const char * determine_god(object *op)
Definition: gods.c:118
archetype * find_archetype(const char *name)
Definition: arch.c:700
object * lookup_spell_by_name(object *op, const char *spname)
Definition: spell_util.c:430
#define SP_BOLT
Definition: spells.h:106
#define INS_BELOW_ORIGINATOR
Definition: object.h:398
int change_skill(object *who, object *new_skill, int flag)
Definition: skill_util.c:301
#define SP_MAKE_MARK
Definition: spells.h:105
#define AT_COUNTERSPELL
Definition: attack.h:123
int fire_bolt(object *op, object *caster, int dir, object *spob, object *skill)
Definition: spell_attack.c:78
#define FALSE
Definition: exp.c:42
const char * get_ob_key_value(const object *op, const char *const key)
Definition: object.c:3701
signed short sint16
Definition: global.h:72
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg)
Definition: resurrection.c:186
struct Statistics statistics
Definition: init.c:119
#define SP_CAUSE_DISEASE
Definition: spells.h:147
int probe(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_effect.c:715
void set_owner(object *op, object *owner)
Definition: object.c:564
void spell_failure(object *op, int failure, int power, object *skill)
Definition: spell_util.c:1078
void esrv_send_item(object *pl, object *op)
Definition: standalone.c:197
#define SET_FLAG(xyz, p)
Definition: define.h:510
sstring add_refcount(sstring str)
Definition: shstr.c:202
#define SP_TOWN_PORTAL
Definition: spells.h:149
#define SP_CONE
Definition: spells.h:109
#define SP_BLESS
Definition: spells.h:127
uint8 range_modifier
Definition: object.h:257
object * find_target_for_friendly_spell(object *op, int dir)
Definition: spell_util.c:779
#define FABS(x)
Definition: define.h:61
sint8 range
Definition: object.h:256
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
uint64 spell_suppressions
Definition: global.h:426
#define SP_CHANGE_MAP_LIGHT
Definition: spells.h:145
#define WAND
Definition: define.h:291
tag_t * spell_tags
Definition: object.h:292
#define AT_INTERNAL
Definition: attack.h:127
int reflwall(mapstruct *m, int x, int y, object *sp_op)
Definition: spell_util.c:490
#define SP_CHANGE_ABILITY
Definition: spells.h:126
#define P_NO_MAGIC
Definition: map.h:248
int fire_bullet(object *op, object *caster, int dir, object *spob)
Definition: spell_attack.c:301
#define MSG_TYPE_ITEM
Definition: newclient.h:334
#define SP_MOVING_BALL
Definition: spells.h:137
#define MSG_TYPE_SPELL_INFO
Definition: newclient.h:554
int cast_bless(object *op, object *caster, object *spell_ob, int dir)
#define SP_AURA
Definition: spells.h:148
#define SPELL_GRACE
Definition: spells.h:87
uint8 casting_time
Definition: global.h:358
sint8 get_attr_value(const living *stats, int attr)
Definition: living.c:377
int spell_find_dir(mapstruct *m, int x, int y, object *exclude)
Definition: spell_util.c:852
sint16 maxgrace
Definition: living.h:86
#define SP_ANIMATE_WEAPON
Definition: spells.h:143
#define MSG_TYPE_SPELL_FAILURE
Definition: newclient.h:548
sint16 encumbrance
Definition: player.h:230
int SP_level_duration_adjust(const object *caster, const object *spob)
Definition: spell_util.c:357
#define HUGE_BUF
Definition: define.h:83
int SP_level_range_adjust(const object *caster, const object *spob)
Definition: spell_util.c:383
#define SET_ANIMATION(ob, newanim)
Definition: global.h:247
void esrv_update_item(int flags, object *pl, object *op)
Definition: standalone.c:200
#define MSG_TYPE_SKILL_FAILURE
Definition: newclient.h:504
struct treasureliststruct * randomitems
Definition: object.h:236
int cast_smite_spell(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:655
#define UPD_ANIM
Definition: newclient.h:259
object clone
Definition: object.h:326
sint16 duration
Definition: object.h:254
sint16 invisible
Definition: object.h:211
short freearr_x[SIZEOFFREE]
Definition: object.c:75
#define PREFER_LOW
Definition: define.h:909
#define POTION
Definition: define.h:117
rangetype shoottype
Definition: player.h:153
void draw_ext_info(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
Definition: standalone.c:171
#define FLAG_CONFUSED
Definition: define.h:608
int cast_word_of_recall(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:935
#define SCROLL
Definition: define.h:293
const char * skill_names[NUM_SKILLS]
Definition: skill_util.c:65
#define MSG_TYPE_SPELL_ERROR
Definition: newclient.h:551
uint8 subtype
Definition: object.h:190
#define MSG_TYPE_SPELL
Definition: newclient.h:333
uint8 spellpoint_level_depend
Definition: global.h:362
#define SPELL_WONDER
Definition: spells.h:190
#define RUNE
Definition: define.h:325
struct obj * above
Definition: object.h:146
#define PATH_TIME_MULT(op, spell)
Definition: spells.h:179
method_ret ob_process(object *op)
Definition: ob_methods.c:79
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:238
int freedir[SIZEOFFREE]
Definition: object.c:93
int manual_apply(object *op, object *tmp, int aflag)
Definition: apply.c:512
#define GOLEM
Definition: define.h:168
void draw_magic_map(object *pl)
Definition: info.c:542
sint16 x
Definition: object.h:179
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:408
uint32 path_attuned
Definition: object.h:194
int create_bomb(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:552
sint16 sp
Definition: living.h:83
#define SP_CREATE_MISSILE
Definition: spells.h:141
uint32 path_repelled
Definition: object.h:195
void draw_ext_info_format(int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *new_format, const char *old_format,...)
Definition: standalone.c:175
struct archt * other_arch
Definition: object.h:264
int recharge(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:90
#define SP_HEALING
Definition: spells.h:123
Definition: object.h:321
uint8 dam_modifier
Definition: object.h:258
#define SP_WORD_OF_RECALL
Definition: spells.h:120
#define PLAYER
Definition: define.h:113
sint16 maxsp
Definition: living.h:84
sint16 hp
Definition: living.h:81
int caster_level(const object *caster, const object *spell)
Definition: spell_util.c:237
int cast_cone(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:403
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: spell_effect.c:639
short freearr_y[SIZEOFFREE]
Definition: object.c:81
#define NDI_NAVY
Definition: newclient.h:197
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:499
#define LOOSE_MANA
Definition: spells.h:189
void paralyze_living(object *op, object *hitter, int dam)
Definition: attack.c:2324
int summon_hostile_monsters(object *op, int n, const char *monstername)
Definition: spell_util.c:970
int rndm(int min, int max)
Definition: utils.c:174
int change_abil(object *op, object *tmp)
Definition: living.c:443
void remove_ob(object *op)
Definition: object.c:1515
sint16 maxhp
Definition: living.h:82
int cast_item_curse_or_curse(object *op, object *caster, object *spell_ob)
#define AT_GODPOWER
Definition: attack.h:124
int cast_curse(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_attack.c:914
int fire_swarm(object *op, object *caster, object *spell, int dir)
static void swap_random_stats(object *op)
Definition: spell_util.c:1225
#define SP_PERCEIVE_SELF
Definition: spells.h:119
uint32 path_denied
Definition: object.h:196
#define SP_BULLET
Definition: spells.h:107
#define FLAG_ALIVE
Definition: define.h:526
void confuse_living(object *op, object *hitter, int dam)
Definition: attack.c:2237
#define AP_IGNORE_CURSE
Definition: define.h:1016
#define FLAG_REFL_SPELL
Definition: define.h:571
#define TRANSPORT
Definition: define.h:114
#define SP_ITEM_CURSE_BLESS
Definition: spells.h:151
uint8 spell_failure_effects
Definition: global.h:357
struct obj * spell
Definition: object.h:259
object * create_archetype(const char *name)
Definition: arch.c:625
void store_spell_expiry(object *spell)
Definition: spell_util.c:1829
int cast_create_town_portal(object *op, object *caster, object *spell, int dir)
object * get_player_container(object *op)
Definition: object.c:356
#define SP_MOOD_CHANGE
Definition: spells.h:136
float speed_left
Definition: object.h:182
#define MSG_TYPE_VICTIM
Definition: newclient.h:336
EXTERN Chaos_Attacks ATTACKS[22]
Definition: attack.h:161
sint32 weight
Definition: object.h:216
static void handle_spell_confusion(object *op)
Definition: spell_util.c:1261
#define SP_BOMB
Definition: spells.h:110
sint8 Wis
Definition: living.h:78
struct mapdef * map
Definition: object.h:155
void set_attr_value(living *stats, int attr, sint8 value)
Definition: living.c:296
static void transmute_item_to_flower(object *op)
Definition: spell_util.c:1156
#define SP_WONDER
Definition: spells.h:111
#define HORN
Definition: define.h:147
int perceive_self(object *op)
void set_spell_skill(object *op, object *caster, object *spob, object *dest)
Definition: spell_util.c:105
int find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3240
int cast_light(object *op, object *caster, object *spell, int dir)
sint16 dam
Definition: living.h:87
int cast_create_obj(object *op, object *new_op, int dir)
Definition: spell_util.c:517
void drain_wand_charge(object *wand)
Definition: spell_util.c:753
const char * name
Definition: object.h:167
struct obj * env
Definition: object.h:151
#define SPELL
Definition: define.h:283
int write_mark(object *op, object *spell, const char *msg)
void regenerate_rod(object *rod)
Definition: spell_util.c:728
#define OB_SPELL_TAG_MATCH(op, count)
Definition: object.h:109
#define SP_SMITE
Definition: spells.h:112
object * get_owner(object *op)
Definition: object.c:524
struct obj * below
Definition: object.h:145
struct archt * more
Definition: object.h:325
const char *const spell_mapping[]
uint16 difficulty
Definition: map.h:364
#define MSG_TYPE_ITEM_CHANGE
Definition: newclient.h:559
static int put_a_monster(object *op, const char *monstername)
Definition: spell_util.c:901
#define TRUE
Definition: exp.c:41
#define SP_ALCHEMY
Definition: spells.h:132
object * find_random_spell_in_ob(object *ob, const char *skill)
Definition: spell_util.c:60
uint32 nrof
Definition: object.h:184
int fire_arch_from_position(object *op, object *caster, sint16 x, sint16 y, int dir, object *spell)
Definition: spell_util.c:653
const int cleric_chance[MAX_STAT+1]
Definition: living.c:160
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:740
#define AP_NOPRINT
Definition: define.h:1020
#define SIZEOFFREE
Definition: define.h:441
#define P_OUT_OF_MAP
Definition: map.h:272
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:213
sint16 y
Definition: object.h:179
struct pl * contr
Definition: object.h:134
#define GOD_POWER
Definition: spells.h:191
#define WEAPON
Definition: define.h:127
#define SP_INVISIBLE
Definition: spells.h:121
#define SP_CHARGING
Definition: spells.h:130
void play_sound_map(sint8 sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:90
#define SP_DESTRUCTION
Definition: spells.h:118
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4002
int cast_detection(object *op, object *caster, object *spell)
void cast_magic_storm(object *op, object *tmp, int lvl)
Definition: spell_effect.c:55
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:283
char * spellarg
Definition: object.h:260
#define MAX(x, y)
Definition: define.h:70
#define SP_DETECTION
Definition: spells.h:135
#define MSG_TYPE_SKILL
Definition: newclient.h:329
float speed
Definition: object.h:181
int cast_wonder(object *op, object *caster, int dir, object *spell_ob)
Definition: spell_effect.c:997
#define SP_RUNE
Definition: spells.h:104
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
char * strdup_local(const char *str)
Definition: porting.c:310
#define MSG_TYPE_APPLY
Definition: newclient.h:330
int cast_invisible(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:821
#define FLAG_WIZ
Definition: define.h:527
int write_rune(object *op, object *caster, object *spell, int dir, const char *runename)
Definition: rune.c:66
object * insert_ob_in_ob(object *op, object *where)
Definition: object.c:2510
void shuffle_attack(object *op, int change_face)
Definition: spell_util.c:1004
int cast_consecrate(object *op, object *caster, object *spell)
#define MAX_BUF
Definition: define.h:81
#define SP_SWARM
Definition: spells.h:138
int cast_transfer(object *op, object *caster, object *spell, int dir)
#define SP_IDENTIFY
Definition: spells.h:134
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1992
#define SP_EARTH_TO_DUST
Definition: spells.h:125
const char * skill
Definition: object.h:174
int dimension_door(object *op, object *caster, object *spob, int dir)
#define NUM_SKILLS
Definition: skills.h:95
void copy_owner(object *op, object *clone)
Definition: object.c:614
int cast_destruction(object *op, object *caster, object *spell_ob)
Definition: spell_attack.c:819
static const flag_definition flags[]
#define SP_DIMENSION_DOOR
Definition: spells.h:115
#define SP_CHANGE_MANA
Definition: spells.h:139
#define SPELL_TAG_SIZE
Definition: object.h:107
void check_spells(void)
Definition: spell_util.c:120
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
#define SP_CURSE
Definition: spells.h:128
#define SP_POLYMORPH
Definition: spells.h:131
int tailor_god_spell(object *spellop, object *caster)
Definition: gods.c:1394
#define FLAG_ANIMATE
Definition: define.h:538
sint16 SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.c:281
static int can_be_transmuted(object *op)
Definition: spell_util.c:1134
int cast_cause_disease(object *op, object *caster, object *spell, int dir)
#define PREFER_HIGH
Definition: define.h:908
uint32 attacktype
Definition: object.h:193
#define NUM_STATS
Definition: living.h:48
#define FLAG_GENERATOR
Definition: define.h:544
int cast_heal(object *op, object *caster, object *spell, int dir)
sint8 direction
Definition: object.h:185
sint16 grace
Definition: living.h:85
int set_ob_key_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:3826
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg)
Definition: spell_effect.c:525
#define FIREWALL
Definition: define.h:204
int summon_object(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: pets.c:929
int mood_change(object *op, object *caster, object *spell)
tag_t count
Definition: object.h:157
living stats
Definition: object.h:219
#define FLAG_WIZCAST
Definition: define.h:586
#define SP_FAERY_FIRE
Definition: spells.h:146
struct archt * arch
Definition: object.h:263
int remove_curse(object *op, object *caster, object *spell)
int cast_earth_to_dust(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:882
#define SPELL_HIGHEST
Definition: spells.h:88
struct Settings settings
Definition: init.c:48
int isqrt(int n)
Definition: porting.c:573
int summon_golem(object *op, object *caster, int dir, object *spob)
Definition: pets.c:669
void dump_spells(void)
Definition: spell_util.c:157
struct archt * next
Definition: object.h:323
#define SP_MAGIC_MISSILE
Definition: spells.h:113
#define FLAG_APPLIED
Definition: define.h:531
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:551
const char * anim_suffix
Definition: object.h:169
#define SP_MAGIC_MAPPING
Definition: spells.h:116
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:516
#define SP_LIGHT
Definition: spells.h:144
#define SP_SUMMON_MONSTER
Definition: spells.h:129
sint16 casting_time
Definition: object.h:253
#define FORCE_NAME
Definition: spells.h:196
void update_ob_speed(object *op)
Definition: object.c:1008
#define AT_MAGIC
Definition: attack.h:105
int min_casting_level(const object *caster, const object *spell)
Definition: spell_util.c:207
#define BOW
Definition: define.h:126
int alchemy(object *op, object *caster, object *spell_ob)
void play_sound_player_only(player *pl, sint8 sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:40
#define GET_MAP_OB(M, X, Y)
Definition: map.h:193
#define FORCE_TRANSFORMED_ITEM
Definition: spells.h:173
#define FLAG_MONSTER
Definition: define.h:541
int animate_weapon(object *op, object *caster, object *spell, int dir)
struct obj * inv
Definition: object.h:148
#define NDI_UNIQUE
Definition: newclient.h:219
void apply_anim_suffix(object *who, sstring suffix)
Definition: anim.c:289
struct obj * head
Definition: object.h:154
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
#define ARROW
Definition: define.h:125
unsigned int uint32
Definition: global.h:58
#define ROD
Definition: define.h:115
#define SP_MAGIC_WALL
Definition: spells.h:117
object * last_skill_ob[NUM_SKILLS]
Definition: player.h:191
void check_spell_expiry(object *spell)
Definition: spell_util.c:1854
#define P_BLOCKSVIEW
Definition: map.h:247
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
Definition: object.c:3524
int cast_change_map_lightlevel(object *op, object *caster, object *spell)
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:628
#define SPELL_MANA
Definition: spells.h:86
#define SP_DISPEL_RUNE
Definition: spells.h:140
#define MSG_TYPE_VICTIM_SPELL
Definition: newclient.h:569
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1308
void free_object(object *ob)
Definition: object.c:1238
Definition: map.h:346
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:51
New_Face * face
Definition: object.h:183
static void prayer_failure(object *op, int failure, int power)
Definition: spell_util.c:1025
void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator)
Definition: spell_util.c:182
int SP_level_dam_adjust(const object *caster, const object *spob)
Definition: spell_util.c:332
int ok_to_put_more(mapstruct *m, sint16 x, sint16 y, object *op, uint32 immune_stop)
Definition: spell_util.c:555
sint16 level
Definition: object.h:202
void esrv_del_item(player *pl, int tag)
Definition: standalone.c:213
void fix_object(object *op)
Definition: living.c:900
#define SP_SUMMON_GOLEM
Definition: spells.h:114
#define SOUND_TYPE_SPELL
Definition: sounds.h:36
#define SP_PROBE
Definition: spells.h:122
#define SP_CREATE_FOOD
Definition: spells.h:124
EXTERN archetype * first_archetype
Definition: global.h:195
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:207
struct obj * more
Definition: object.h:153
object * arch_to_object(archetype *at)
Definition: arch.c:576
int cast_identify(object *op, object *caster, object *spell)
uint8 duration_modifier
Definition: object.h:255
const char * name
Definition: object.h:322
int hit_player(object *op, int dam, object *hitter, uint32 type, int full_hit)
Definition: attack.c:1868
int dispel_rune(object *op, object *caster, object *spell, object *skill, int dir)
Definition: rune.c:323
#define P_NO_CLERIC
Definition: map.h:259
#define SP_CONSECRATE
Definition: spells.h:142
int create_aura(object *op, object *caster, object *spell)
uint8 type
Definition: object.h:189
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_effect.c:453
sint32 food
Definition: living.h:89
int attacktype
Definition: attack.h:154
int magic_wall(object *op, object *caster, int dir, object *spell_ob)
#define PATH_SP_MULT(op, spell)
Definition: spells.h:64
#define SP_RAISE_DEAD
Definition: spells.h:103
#define FLAG_IS_TURNABLE
Definition: define.h:552
#define SP_REMOVE_CURSE
Definition: spells.h:133