Crossfire Server, Trunk  R21466
spell_util.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <assert.h>
22 #include <ctype.h>
23 #include <errno.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "living.h"
28 #include "object.h"
29 #include "sounds.h"
30 #include "spells.h"
31 #include "sproto.h"
32 
33 extern const char *const spell_mapping[];
34 
48 object *find_random_spell_in_ob(object *ob, const char *skill) {
49  int k = 0, s;
50 
51  FOR_INV_PREPARE(ob, tmp)
52  if (tmp->type == SPELL && (!skill || tmp->skill == skill))
53  k++;
55 
56  /* No spells, no need to progess further */
57  if (!k)
58  return NULL;
59 
60  s = RANDOM()%k;
61  FOR_INV_PREPARE(ob, tmp)
62  if (tmp->type == SPELL && (!skill || tmp->skill == skill)) {
63  if (!s)
64  return tmp;
65  else
66  s--;
67  }
69 
70  /* Should never get here, but just in case */
71  return NULL;
72 }
73 
94 void set_spell_skill(object *op, object *caster, object *spob, object *dest) {
95  if (dest->skill)
97  if (caster == op && spob->skill)
98  dest->skill = add_refcount(spob->skill);
99  else if (caster->skill)
100  dest->skill = add_refcount(caster->skill);
101 }
102 
109 void check_spells(void) {
110 #ifdef SPELL_DEBUG
111  int i;
112  archetype *at;
113 
114  LOG(llevDebug, "Checking spells...\n");
115 
116  for (at = first_archetype; at; at = at->next) {
117  if (at->clone.type == SPELL) {
118  if (at->clone.skill) {
119  for (i = 0; i < MAX_SKILLS && skill_names[i]; i++)
120  if (!strcmp(skill_names[i], at->clone.skill))
121  break;
122  if (i == MAX_SKILLS || !skill_names[i]) {
123  LOG(llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill);
124  }
125  }
126  /* other_arch is already checked for in the loader */
127  }
128  }
129 
130  i = 0;
131  while (spell_mapping[i]) {
132  if (!find_archetype(spell_mapping[i])) {
133  LOG(llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
134  }
135  i++;
136  }
137  LOG(llevDebug, "Checking spells completed.\n");
138 #endif
139 }
140 
146 void dump_spells(void) {
147  archetype *at;
148  int banner = 0;
149 
150  for (at = first_archetype; at; at = at->next) {
151  if (at->clone.type == SPELL) {
152  fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null",
153  at->name, at->clone.other_arch ? at->clone.other_arch->name : "null",
154  at->clone.skill ? at->clone.skill : "null", at->clone.level);
155  }
156  }
157 
158  for (at = first_archetype; at; at = at->next) {
159  if (at->clone.type == SPELL && at->clone.path_attuned == 0) {
160  if (banner == 0) {
161  banner = 1;
162  fprintf(stderr, "Spells with no path set:\n");
163  }
164 
165  fprintf(stderr, "- %s\n", at->clone.name ? at->clone.name : "null");
166  }
167  }
168 }
169 
183 void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) {
184  if (spob->other_arch != NULL) {
185  object *effect = arch_to_object(spob->other_arch);
186  object_insert_in_map_at(effect, map, originator, 0, x, y);
187  }
188 }
189 
203 int min_casting_level(const object *caster, const object *spell) {
204  int new_level;
205 
206  if (caster->path_denied&spell->path_attuned) {
207  /* This case is not a bug, just the fact that this function is
208  * usually called BEFORE checking for path_deny. -AV
209  */
210  return 1;
211  }
212  new_level = spell->level
213  +((caster->path_repelled&spell->path_attuned) ? +2 : 0)
214  +((caster->path_attuned&spell->path_attuned) ? -2 : 0);
215  return MAX(new_level, 1);
216 }
217 
218 
233 int caster_level(const object *caster, const object *spell) {
234  int level = caster->level;
235 
236  /* If this is a player, try to find the matching skill */
237  if (caster->type == PLAYER && spell->skill) {
238  object* skill = find_applied_skill_by_name(caster, spell->skill);
239  if (skill != NULL) {
240  level = skill->level;
241  } else {
242  level = 0;
243  }
244  }
245  /* Got valid caster level. Now adjust for attunement */
246  level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0)
247  +((caster->path_attuned&spell->path_attuned) ? 2 : 0);
248 
249  /* Always make this at least 1. If this is zero, we get divide by zero
250  * errors in various places.
251  */
252  if (level < 1)
253  level = 1;
254  return level;
255 }
256 
275 int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags) {
276  int sp, grace, level = caster_level(caster, spell);
277 
279  if (spell->stats.sp && spell->stats.maxsp) {
280  sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp)));
281  } else
282  sp = spell->stats.sp;
283 
284  sp *= PATH_SP_MULT(caster, spell);
285  if (!sp && spell->stats.sp)
286  sp = 1;
287 
288  if (spell->stats.grace && spell->stats.maxgrace) {
289  grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace)));
290  } else
291  grace = spell->stats.grace;
292 
293  grace *= PATH_SP_MULT(caster, spell);
294  if (spell->stats.grace && !grace)
295  grace = 1;
296  } else {
297  sp = spell->stats.sp*PATH_SP_MULT(caster, spell);
298  if (spell->stats.sp && !sp)
299  sp = 1;
300  grace = spell->stats.grace*PATH_SP_MULT(caster, spell);
301  if (spell->stats.grace && !grace)
302  grace = 1;
303  }
304  if (flags == SPELL_HIGHEST)
305  return MAX(sp, grace);
306  else if (flags == SPELL_GRACE)
307  return grace;
308  else if (flags == SPELL_MANA)
309  return sp;
310  else {
311  LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
312  return 0;
313  }
314 }
315 
326 int SP_level_dam_adjust(const object *caster, const object *spob) {
327  int level = caster_level(caster, spob);
328  int adj = level-min_casting_level(caster, spob);
329 
330  if (adj < 0)
331  adj = 0;
332  if (spob->dam_modifier)
333  adj /= spob->dam_modifier;
334  else
335  adj = 0;
336  return adj;
337 }
338 
351 int SP_level_duration_adjust(const object *caster, const object *spob) {
352  int level = caster_level(caster, spob);
353  int adj = level-min_casting_level(caster, spob);
354 
355  if (adj < 0)
356  adj = 0;
357  if (spob->duration_modifier)
358  adj /= spob->duration_modifier;
359  else
360  adj = 0;
361 
362  return adj;
363 }
364 
377 int SP_level_range_adjust(const object *caster, const object *spob) {
378  int level = caster_level(caster, spob);
379  int adj = level-min_casting_level(caster, spob);
380 
381  if (adj < 0)
382  adj = 0;
383  if (spob->range_modifier)
384  adj /= spob->range_modifier;
385  else
386  adj = 0;
387 
388  return adj;
389 }
390 
401 int SP_level_wc_adjust(const object *caster, const object *spob) {
402  int level = caster_level(caster, spob);
403  int adj = level - min_casting_level(caster, spob), irate;
404  sstring rate;
405 
406  rate = object_get_value(spob, "wc_increase_rate");
407 
408  if (rate == NULL)
409  return 0;
410 
411  if (adj < 0)
412  adj = 0;
413 
414  irate = atoi(rate);
415  if (irate > 0)
416  adj /= irate;
417  else
418  adj = 0;
419  return adj;
420 }
421 
433 object *check_spell_known(object *op, const char *name) {
434  return object_find_by_type_and_name(op, SPELL, name);
435 }
436 
449 object *lookup_spell_by_name(object *op, const char *spname) {
450  object *spob1 = NULL, *spob2 = NULL;
451  int nummatch = 0;
452 
453  if (spname == NULL)
454  return NULL;
455 
456  /* Try to find the spell. We store the results in spob1
457  * and spob2 - spob1 is only taking the length of
458  * the past spname, spob2 uses the length of the spell name.
459  */
460  FOR_INV_PREPARE(op, spob) {
461  if (spob->type == SPELL) {
462  if (!strncmp(spob->name, spname, strlen(spname))) {
463  if (strlen(spname) == strlen(spob->name))
464  /* Perfect match, return it. */
465  return spob;
466  nummatch++;
467  spob1 = spob;
468  } else if (!strncmp(spob->name, spname, strlen(spob->name))) {
469  /* if spells have ambiguous names, it makes matching
470  * really difficult. (eg, fire and fireball would
471  * fall into this category). It shouldn't be hard to
472  * make sure spell names don't overlap in that fashion.
473  */
474  if (spob2)
475  LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name);
476  spob2 = spob;
477  }
478  }
479  } FOR_INV_FINISH();
480  /* if we have best match, return it. Otherwise, if we have one match
481  * on the loser match, return that, otehrwise null
482  */
483  if (spob2)
484  return spob2;
485  if (spob1 && nummatch == 1)
486  return spob1;
487  return NULL;
488 }
489 
509 int reflwall(mapstruct *m, int x, int y, object *sp_op) {
510  if (OUT_OF_REAL_MAP(m, x, y))
511  return 0;
512  FOR_MAP_PREPARE(m, x, y, op)
513  if (QUERY_FLAG(op, FLAG_REFL_SPELL)
514  && (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10)))
515  return 1;
516  FOR_MAP_FINISH();
517  return 0;
518 }
519 
533 int cast_create_obj(object *op, object *new_op, int dir) {
534  mapstruct *m;
535  int16_t sx, sy;
536 
537  if (dir
538  && ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP)
539  || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) {
541  "Something is in the way. You cast it at your feet.");
542  dir = 0;
543  }
544  if (dir == 0)
545  object_insert_in_map_at(new_op, op->map, op, INS_BELOW_ORIGINATOR, op->x+freearr_x[dir], op->y+freearr_y[dir]);
546  else
547  object_insert_in_map_at(new_op, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
548  return dir;
549 }
550 
569 int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop) {
570  int mflags;
571  mapstruct *mp;
572 
573  mp = m;
574  mflags = get_map_flags(m, &mp, x, y, &x, &y);
575 
576  if (mflags&P_OUT_OF_MAP)
577  return 0;
578 
579  if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(mp, x, y)))
580  return 0;
581 
582  FOR_MAP_PREPARE(mp, x, y, tmp) {
583  /* If there is a counterspell on the space, and this
584  * object is using magic, don't progess. I believe we could
585  * leave this out and let in progress, and other areas of the code
586  * will then remove it, but that would seem to to use more
587  * resources, and may not work as well if a player is standing
588  * on top of a counterwall spell (may hit the player before being
589  * removed.) On the other hand, it may be more dramatic for the
590  * spell to actually hit the counterwall and be sucked up.
591  */
592  if ((tmp->attacktype&AT_COUNTERSPELL)
593  && (tmp->type != PLAYER)
594  && !QUERY_FLAG(tmp, FLAG_MONSTER)
595  && (tmp->type != WEAPON)
596  && (tmp->type != BOW)
597  && (tmp->type != ARROW)
598  && (tmp->type != GOLEM)
599  && (immune_stop&AT_MAGIC))
600  return 0;
601 
602  /* This is to prevent 'out of control' spells. Basically, this
603  * limits one spell effect per space per spell. This is definitely
604  * needed for performance reasons, and just for playability I believe.
605  * there are no such things as multispaced spells right now, so
606  * we don't need to worry about the head.
607  * We only need to go down this path is maxhp is set on both objects -
608  * otherwise, no reason to check. But if we do check, we need to
609  * do some extra work, looking in the spell_tags[] of each object,
610  * if they have it set.
611  */
612  if (tmp->type == op->type
613  && tmp->subtype == op->subtype
614  && tmp->stats.maxhp
615  && op->stats.maxhp) {
616  if ((tmp->stats.maxhp == op->stats.maxhp)
617  || (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp))
618  || (op->spell_tags && OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp))) {
620  return 0;
621  }
622 
623  /* if both objects have spell tags, then if the two tags entries
624  * from either match, that also counts. Need to check
625  * the spell_tags, because 0 values are allowed to match
626  */
627  if (op->spell_tags && tmp->spell_tags) {
628  int i;
629 
630  for (i = 0; i < SPELL_TAG_SIZE; i++) {
631  if (op->spell_tags[i] &&
632  op->spell_tags[i] == tmp->spell_tags[i]) {
634  return 0;
635  }
636  }
637  }
638  }
639  /* Perhaps we should also put checks in for no magic and unholy
640  * ground to prevent it from moving along?
641  */
642  } FOR_MAP_FINISH();
643  /* If it passes the above tests, it must be OK */
644  return 1;
645 }
646 
670 int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell) {
671  object *tmp;
672  int mflags;
673  mapstruct *m;
674 
675  if (dir < 0 || dir > 8) {
676  LOG(llevError, "Invalid direction %d in fire_arch_from_position for %s\n", dir, spell->name);
677  dir = RANDOM() % 8 + 1;
678  }
679 
680  if (spell->other_arch == NULL)
681  return 0;
682 
683  if (spell->type != SPELL)
684  LOG(llevError, "Unexpected object type %d in fire_arch_from_position for %s\n", spell->type, spell->name);
685 
686  m = op->map;
687  mflags = get_map_flags(m, &m, x, y, &x, &y);
688  if (mflags&P_OUT_OF_MAP) {
689  return 0;
690  }
691 
692  tmp = arch_to_object(spell->other_arch);
693  if (tmp == NULL)
694  return 0;
695 
696  mflags = get_map_flags(m, &tmp->map, x, y, &tmp->x, &tmp->y);
697  if (mflags&P_OUT_OF_MAP) {
699  return 0;
700  }
701 
702  if (spell->subtype == SP_BULLET) {
703  /* peterm: level dependency for bolts */
704  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
705  tmp->attacktype = spell->attacktype;
706  if (spell->slaying)
707  tmp->slaying = add_refcount(spell->slaying);
708 
709  tmp->range = 50;
710 
711  /* Need to store duration/range for the ball to use */
712  tmp->stats.hp = spell->duration+SP_level_duration_adjust(caster, spell);
713  tmp->stats.maxhp = spell->range+SP_level_range_adjust(caster, spell);
714  tmp->dam_modifier = spell->stats.food+SP_level_dam_adjust(caster, spell);
715 
716  tmp->direction = dir;
718 
719  object_set_owner(tmp, op);
720  } else {
721  if (spell->subtype != SP_MAGIC_MISSILE && spell->subtype != SP_MOVING_BALL)
722  LOG(llevError, "Unexpected object subtype %d in fire_arch_from_position for %s\n", spell->subtype, spell->name);
723 
724  /*
725  * Things like firewalls and such can fire even if blocked, since the
726  * origin is themselves which block things...
727  * This fixes bug #3536508.
728  */
729  if (caster->type == PLAYER && OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
731  "You can't cast the spell on top of a wall!");
733  return 0;
734  }
735 
736  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
737  tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell);
738  /* code in time.c uses food for some things, duration for others */
739  tmp->stats.food = tmp->duration;
740  tmp->range = spell->range+SP_level_range_adjust(caster, spell);
741  tmp->attacktype = spell->attacktype;
742  if (object_get_owner(op) != NULL)
743  object_copy_owner(tmp, op);
744  else
745  object_set_owner(tmp, op);
746  tmp->level = caster_level(caster, spell);
747  }
748 
749  tmp->direction = dir;
750  set_spell_skill(op, caster, spell, tmp);
751 
752  if (spell->subtype == SP_BULLET) {
753  if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
754  if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) {
756  return 0;
757  }
758  tmp->direction = absdir(tmp->direction+4);
759  x += DIRX(tmp);
760  y += DIRY(tmp);
761  mflags = get_map_flags(m, &m, x, y, &x, &y);
762  if (mflags&P_OUT_OF_MAP) {
764  return 0;
765  }
766  tmp->x = x;
767  tmp->y = y;
768  tmp->map = m;
769  }
770 
771  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
772  if (tmp != NULL)
773  check_bullet(tmp);
774  } else /*if (spell->subtype == SP_MAGIC_MISSILE || spell->subtype == SP_MOVING_BALL) */ {
775  /* needed for AT_HOLYWORD, AT_GODPOWER stuff */
776  if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) {
777  if (!tailor_god_spell(tmp, op))
778  return 0;
779  }
781 
782  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
783  if (tmp != NULL)
784  ob_process(tmp);
785  }
786 
787  return 1;
788 }
789 
790 /*****************************************************************************
791  *
792  * Code related to rods - perhaps better located in another file?
793  *
794  ****************************************************************************/
795 
802 void regenerate_rod(object *rod) {
803  if (rod->stats.hp < rod->stats.maxhp) {
804  rod->stats.hp += 1+rod->stats.maxhp/10;
805 
806  if (rod->stats.hp > rod->stats.maxhp)
807  rod->stats.hp = rod->stats.maxhp;
808  }
809 }
810 
817 void drain_rod_charge(object *rod) {
818  rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
819 }
820 
827 void drain_wand_charge(object *wand) {
828  assert(wand->type == WAND);
829 
830  if (!(--wand->stats.food)) {
831  object *tmp;
832  if (wand->arch) {
833  CLEAR_FLAG(wand, FLAG_ANIMATE);
834  wand->face = wand->arch->clone.face;
835  wand->speed = 0;
836  object_update_speed(wand);
837  }
838  tmp = object_get_player_container(wand);
839  if (tmp)
840  esrv_update_item(UPD_ANIM, tmp, wand);
841  }
842 }
843 
854 object *find_target_for_friendly_spell(object *op, int dir) {
855  object *tmp;
856  mapstruct *m;
857  int16_t x, y;
858  int mflags;
859 
860  /* I don't really get this block - if op isn't a player or rune,
861  * we then make the owner of this object the target.
862  * The owner could very well be no where near op.
863  */
864  if (op->type != PLAYER && op->type != RUNE) {
865  tmp = object_get_owner(op);
866  /* If the owner does not exist, or is not a monster, than apply the spell
867  * to the caster.
868  */
869  if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER))
870  tmp = op;
871  } else {
872  m = op->map;
873  x = op->x+freearr_x[dir];
874  y = op->y+freearr_y[dir];
875 
876  mflags = get_map_flags(m, &m, x, y, &x, &y);
877 
878  if (mflags&P_OUT_OF_MAP)
879  tmp = NULL;
880  else {
881  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
882  if (tmp->type == PLAYER)
883  break;
884  }
885  }
886  }
887  /* didn't find a player there, look in current square for a player */
888  if (tmp == NULL)
889  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
890  if (tmp->type == PLAYER)
891  return tmp;
892  /* Don't forget to browse inside transports ! - gros 2006/07/25 */
893  if (tmp->type == TRANSPORT) {
894  object *inv;
895 
896  for (inv = tmp->inv; inv; inv = inv->below) {
897  if ((inv->type == PLAYER) && (op == inv))
898  return inv;
899  }
900  }
901  } FOR_MAP_FINISH();
902  return tmp;
903 }
904 
905 
906 
927 int spell_find_dir(mapstruct *m, int x, int y, object *exclude) {
928  int i;
929  int16_t nx, ny;
930  int owner_type = 0, mflags;
931  object *tmp;
932  mapstruct *mp;
933  int dirs[SIZEOFFREE];
934 
935  if (exclude != NULL) {
936  exclude = HEAD(exclude);
937  owner_type = exclude->type;
938  }
939 
940  get_search_arr(dirs);
941  for (i = 1; i < SIZEOFFREE; i++) {
942  nx = x+freearr_x[dirs[i]];
943  ny = y+freearr_y[dirs[i]];
944  mp = m;
945  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
946  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
947  continue;
948 
949  for (tmp = GET_MAP_OB(mp, nx, ny); tmp != NULL; tmp = tmp->above) {
950  object *head;
951 
952  head = HEAD(tmp);
953  if ((owner_type != PLAYER || QUERY_FLAG(head, FLAG_MONSTER) || QUERY_FLAG(head, FLAG_GENERATOR) || (head->type == PLAYER && op_on_battleground(head, NULL, NULL, NULL)))
954  && (owner_type == PLAYER || head->type == PLAYER)
955  && head != exclude
956  && can_see_monsterP(m, x, y, dirs[i])) {
957  return freedir[dirs[i]];
958  }
959  }
960  }
961  return -1; /* flag for "keep going the way you were" */
962 }
963 
964 
965 
979 static int put_a_monster(object *op, const char *monstername) {
980  object *tmp, *head = NULL, *prev = NULL;
981  archetype *at;
982  int dir;
983 
984  /* Handle cases where we are passed a bogus mosntername */
985  at = find_archetype(monstername);
986  if (at == NULL)
987  return 0;
988 
989  /* find a free square nearby
990  * first we check the closest square for free squares
991  */
992 
993  dir = object_find_first_free_spot(&at->clone, op->map, op->x, op->y);
994  if (dir != -1) {
995  /* This is basically grabbed for generate monster. Fixed 971225 to
996  * insert multipart monsters properly
997  */
998  while (at != NULL) {
999  tmp = arch_to_object(at);
1000  tmp->x = op->x+freearr_x[dir]+at->clone.x;
1001  tmp->y = op->y+freearr_y[dir]+at->clone.y;
1002  tmp->map = op->map;
1003  if (head) {
1004  tmp->head = head;
1005  prev->more = tmp;
1006  }
1007  if (!head)
1008  head = tmp;
1009  prev = tmp;
1010  at = at->more;
1011  }
1012 
1013  if (head->randomitems)
1014  create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
1015 
1016  object_insert_in_map_at(head, op->map, op, 0, op->x, op->y);
1017 
1018  /* thought it'd be cool to insert a burnout, too.*/
1019  tmp = create_archetype("burnout");
1020  object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
1021  return 1;
1022  } else {
1023  return 0;
1024  }
1025 }
1026 
1045 int summon_hostile_monsters(object *op, int n, const char *monstername) {
1046  int i, put = 0;
1047 
1048  for (i = 0; i < n; i++)
1049  put += put_a_monster(op, monstername);
1050 
1051  return put;
1052 }
1053 
1054 
1079 void shuffle_attack(object *op, int change_face) {
1080  int i;
1081 
1082  i = rndm(0, 21);
1084  if (change_face) {
1085  SET_ANIMATION(op, ATTACKS[i].face);
1086  }
1087 }
1088 
1089 
1100 static void prayer_failure(object *op, int failure, int power) {
1101  const char *godname;
1102  object *tmp;
1103 
1104  godname = determine_god(op);
1105  if (!strcmp(godname, "none"))
1106  godname = "Your spirit";
1107 
1108  if (failure <= -20 && failure > -40) { /* wonder */
1110  "%s gives a sign to renew your faith.",
1111  godname);
1113  cast_cone(op, op, 0, tmp);
1115  } else if (failure <= -40 && failure > -60) { /* confusion */
1117  "Your diety touches your mind!");
1118  confuse_living(op, op, 99);
1119  } else if (failure <= -60 && failure > -150) { /* paralysis */
1121  "%s requires you to pray NOW. You comply, ignoring all else.",
1122  godname);
1123 
1124  paralyze_living(op, 99);
1125  } else if (failure <= -150) { /* blast the immediate area */
1126  tmp = create_archetype(GOD_POWER);
1128  "%s smites you!",
1129  godname);
1130  /* Put a cap on power - this is effectively cost of the spell minus
1131  * characters current grace. Thus, if spell costs 30 grace and
1132  * character has -100 grace, this is cast as a level 130 spell.
1133  * Things start to break in those cases.
1134  */
1135  cast_magic_storm(op, tmp, power > 50 ? 50 : power);
1136  }
1137 }
1138 
1151 void spell_failure(object *op, int failure, int power, object *skill) {
1152  object *tmp;
1153 
1155  return;
1156 
1157  if (failure <= -20 && failure > -40) { /* wonder */
1159  "Your spell causes an unexpected effect.");
1161  cast_cone(op, op, 0, tmp);
1163  } else if (failure <= -40 && failure > -60) { /* confusion */
1165  "Your magic recoils on you, making you confused!");
1166  confuse_living(op, op, 99);
1167  } else if (failure <= -60 && failure > -80) { /* paralysis */
1169  "Your magic stuns you!");
1170  paralyze_living(op, 99);
1171  } else if (failure <= -80) { /* blast the immediate area */
1172  object *tmp;
1173 
1174  /* Safety check to make sure we don't get any mana storms in scorn */
1175  if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) {
1177  "The magic warps and you are turned inside out!");
1178  hit_player(op, 9998, op, AT_INTERNAL, 1);
1179  } else {
1181  "You lose control of the mana! The uncontrolled magic blasts you!");
1183  tmp->level = skill->level;
1184 
1185  /* increase the area of destruction a little for more powerful spells */
1186  tmp->range += isqrt(power);
1187 
1188  if (power > 25)
1189  tmp->stats.dam = 25+isqrt(power);
1190  else
1191  tmp->stats.dam = power; /* nasty recoils! */
1192 
1193  tmp->stats.maxhp = tmp->count;
1194  if (tmp->stats.maxhp == 0)
1195  tmp->stats.maxhp = 1;
1196  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
1197  }
1198  }
1199 }
1200 
1209 static int can_be_transmuted_to_flower(object *op) {
1210  if (op->invisible)
1211  return 0;
1212 
1213  if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON)
1214  return 1;
1215 
1216  return 0;
1217 }
1218 
1231 static void transmute_item_to_flower(object *op) {
1232  object *force;
1233  object *item;
1234  object *flower;
1235  object *first = NULL;
1236  int count = 0;
1237  char name[HUGE_BUF];
1238 
1239  FOR_INV_PREPARE(op, item)
1240  if (can_be_transmuted_to_flower(item)) {
1241  if (!first)
1242  first = item;
1243  count++;
1244  }
1245  FOR_INV_FINISH();
1246 
1247  if (count == 0)
1248  return;
1249 
1250  count = rndm(0, count-1);
1251  for (item = first; item; item = item->below) {
1252  if (can_be_transmuted_to_flower(item)) {
1253  count--;
1254  if (count < 0)
1255  break;
1256  }
1257  }
1258 
1259  if (!item)
1260  return;
1261 
1262  force = create_archetype(FORCE_NAME);
1263  force->duration = 100+rndm(0, 10)*100;
1265  force->speed = 1;
1266  object_update_speed(force);
1267 
1268  flower = create_archetype("flowers_permanent");
1269 
1270  if (QUERY_FLAG(item, FLAG_APPLIED))
1272  object_remove(item);
1273  flower->weight = item->nrof ? ((int32_t)item->nrof)*item->weight : item->weight;
1274  item->weight = 0;
1275  esrv_del_item(op->contr, item);
1276  object_insert_in_ob(item, force);
1277 
1278  query_short_name(item, name, HUGE_BUF);
1281  "Your %s turns to a flower!",
1282  name);
1283 
1284  object_insert_in_ob(force, flower);
1285  flower = object_insert_in_ob(flower, op);
1286  esrv_send_item(op, flower);
1287 }
1288 
1299 static void swap_random_stats(object *op) {
1300  object *force;
1301  int first, second;
1302 
1303  first = RANDOM()%NUM_STATS;
1304  second = RANDOM()%(NUM_STATS-1);
1305  if (second >= first)
1306  second++;
1307 
1310  "You suddenly feel really weird!");
1311 
1312  force = create_archetype(FORCE_NAME);
1313  force->duration = 100+rndm(0, 10)*100;
1314  force->speed = 1;
1315  SET_FLAG(force, FLAG_APPLIED);
1316  set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second));
1317  set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first));
1318  object_update_speed(force);
1319  object_insert_in_ob(force, op);
1320  change_abil(op, force);
1321  fix_object(op);
1322 }
1323 
1334 static void handle_spell_confusion(object *op) {
1335  switch (RANDOM()%2) {
1336  case 0:
1338  break;
1339 
1340  case 1:
1341  swap_random_stats(op);
1342  break;
1343  }
1344 }
1345 
1353 static int spell_consume_items(object *op, const object *spell_ob) {
1354  sstring requirements;
1355  char *copy;
1356  char *ingredients[10];
1357  object *found[10];
1358  int count, i;
1359  uint32_t nrof[10];
1360  char name_ob[MAX_BUF];
1361  const char *name2;
1362 
1363  if (op->type != PLAYER)
1364  return 1;
1365 
1366  requirements = object_get_value(spell_ob, "casting_requirements");
1367  if (!requirements)
1368  /* no special requirements */
1369  return 1;
1370 
1371  /* find items */
1372  copy = strdup_local(requirements);
1373  count = split_string(copy, ingredients, 10, ',');
1374 
1375  /* first pass, find items */
1376  for (i = 0; i < count; i++) {
1377  nrof[i] = 0;
1378  found[i] = NULL;
1379  while (isdigit(*ingredients[i])) {
1380  nrof[i] = 10*nrof[i]+(*(ingredients[i])-'0');
1381  ingredients[i]++;
1382  }
1383  if (nrof[i] == 0)
1384  nrof[i] = 1;
1385  while (*ingredients[i] == ' ')
1386  ingredients[i]++;
1387 
1388  /* now find item in op's inv */
1389  FOR_INV_PREPARE(op, check) {
1390 
1391  if (check->title == NULL)
1392  name2 = check->name;
1393  else {
1394  snprintf(name_ob, sizeof(name_ob), "%s %s", check->name, check->title);
1395  name2 = name_ob;
1396  }
1397 
1398  if (strcmp(name2, ingredients[i]) == 0) {
1399  found[i] = check;
1400  break;
1401  }
1402  } FOR_INV_FINISH();
1403 
1404  if (found[i] == NULL) {
1407  "Casting this spell requires %s, but you don't have any.",
1408  ingredients[i]);
1409  free(copy);
1410  return 0;
1411  }
1412 
1413  if (found[i]->nrof < nrof[i]) {
1416  "Casting this spell requires %d %s, but you only have %d.",
1417  nrof[i], found[i]->name_pl, found[i]->nrof);
1418  free(copy);
1419  return 0;
1420  }
1421  }
1422 
1423  free(copy);
1424 
1425  /* ok, found ingredients, remove'em */
1426  for (i = 0; i < count; i++) {
1427  object_decrease_nrof(found[i], nrof[i]);
1428  }
1429 
1430  /* all right, spell can be cast */
1431  return 1;
1432 }
1433 
1469 int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
1470  const char *godname;
1471  int success = 0, mflags, cast_level = 0;
1472  rangetype old_shoottype;
1473  object *skill = NULL;
1474  int confusion_effect = 0;
1475  float cost_multiplier = 1.0f;
1476 
1477  old_shoottype = op->contr ? op->contr->shoottype : range_none;
1478 
1479  if (!spell_ob) {
1480  LOG(llevError, "cast_spell: null spell object passed\n");
1481  return 0;
1482  }
1483  godname = determine_god(op);
1484  if (!strcmp(godname, "none"))
1485  godname = "A random spirit";
1486 
1487  /* the caller should set caster to op if appropriate */
1488  if (!caster) {
1489  LOG(llevError, "cast_spell: null caster object passed\n");
1490  return 0;
1491  }
1492  if (spell_ob->anim_suffix)
1493  apply_anim_suffix(caster, spell_ob->anim_suffix);
1494 
1495  /* Handle some random effect if confused. */
1496  if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) {
1497  if (rndm(0, 5) < 4) {
1498  spell_ob = find_random_spell_in_ob(op, NULL);
1501  "In your confused state, you're not sure of what you cast!");
1502  } else
1503  /* We fall through to deplate sp/gr, and do some checks. */
1504  confusion_effect = 1;
1505  }
1506 
1507  /* if caster is a spell casting object, this normally shouldn't be
1508  * an issue, because they don't have any spellpaths set up.
1509  */
1510  if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) {
1512  "That spell path is denied to you.");
1513  return 0;
1514  }
1515 
1516  /* if it is a player casting the spell, and they are really casting it
1517  * (vs it coming from a wand, scroll, or whatever else), do some
1518  * checks. We let monsters do special things - eg, they
1519  * don't need the skill, bypass level checks, etc. The monster function
1520  * should take care of that.
1521  * Remove the wiz check here and move it further down - some spells
1522  * need to have the right skill pointer passed, so we need to
1523  * at least process that code.
1524  */
1525  if (op->type == PLAYER && op == caster) {
1526  cast_level = caster_level(caster, spell_ob);
1527  if (spell_ob->skill) {
1528  skill = find_skill_by_name(op, spell_ob->skill);
1529  if (!skill) {
1532  "You need the skill %s to cast %s.",
1533  spell_ob->skill, spell_ob->name);
1534  return 0;
1535  }
1536  if (min_casting_level(op, spell_ob) > cast_level && !QUERY_FLAG(op, FLAG_WIZ)) {
1538  "You lack enough skill to cast that spell.");
1539  return 0;
1540  }
1541  }
1542  /* If the caster is the wiz, they don't ever fail, and don't have
1543  * to have sufficient grace/mana.
1544  */
1545  if (!QUERY_FLAG(op, FLAG_WIZ)) {
1546  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA)
1547  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) > op->stats.sp) {
1549  "You don't have enough mana.");
1550  return 0;
1551  }
1552  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)
1553  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) > op->stats.grace) {
1554  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) {
1557  "%s grants your prayer, though you are unworthy.",
1558  godname);
1559  } else {
1560  prayer_failure(op, op->stats.grace, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)-op->stats.grace);
1563  "%s ignores your prayer.",
1564  godname);
1565  return 0;
1566  }
1567  }
1568 
1569  /* player/monster is trying to cast the spell. might fumble it */
1570  if (spell_ob->stats.grace
1571  && random_roll(0, 99, op, PREFER_HIGH) < (get_cleric_chance(op->stats.Wis) * spell_ob->level/MAX(1, op->level))) {
1572  play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell_ob, 0, "fumble");
1574  "You fumble the spell.");
1575  if (settings.casting_time == TRUE) {
1576  op->casting_time = -1;
1577  }
1578  op->stats.grace -= random_roll(1, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1579  object *bungle = create_archetype(ARCH_SPELL_BUNGLE);
1580  if (bungle->arch != NULL) {
1581  cast_create_obj(op, bungle, 0);
1582  } else {
1583  LOG(llevError, "cast_spell: Could not create spell_bungle arch\n");
1584  }
1585  return 0;
1586  } else if (spell_ob->stats.sp) {
1587  int failure = random_roll(0, 199, op, PREFER_HIGH)-op->contr->encumbrance+op->level-spell_ob->level+35;
1588 
1589  if (failure < 0) {
1590  draw_ext_info(NDI_UNIQUE, 0, op,
1592  "You bungle the spell because you have too much heavy equipment in use.");
1594  spell_failure(op, failure, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), skill);
1595  op->contr->shoottype = old_shoottype;
1596  op->stats.sp -= random_roll(0, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1597  object *bungle = create_archetype(ARCH_SPELL_BUNGLE);
1598  if (bungle->arch != NULL) {
1599  cast_create_obj(op, bungle, 0);
1600  } else {
1601  LOG(llevError, "cast_spell: Could not create spell_bungle arch\n");
1602  }
1603  return 0;
1604  }
1605  }
1606 
1607  /* ensure the potentially required items are eaten */
1608  if (!spell_consume_items(op, spell_ob))
1609  /* already warned by the function */
1610  return 0;
1611  }
1612  }
1613 
1614  mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL);
1615 
1616  /* See if we can cast a spell here. If the caster and op are
1617  * not alive, then this would mean that the mapmaker put the
1618  * objects on the space - presume that they know what they are
1619  * doing.
1620  */
1621  if (spell_ob->type == SPELL
1622  && caster->type != POTION
1623  && !QUERY_FLAG(op, FLAG_WIZCAST)
1624  && (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE))
1625  && !QUERY_FLAG(op, FLAG_MONSTER)
1626  && (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) {
1627  if (op->type != PLAYER)
1628  return 0;
1629 
1631 
1632  if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace)
1634  "This ground is unholy! %s ignores you.",
1635  godname);
1636  else
1637  switch (op->contr->shoottype) {
1638  case range_magic:
1640  "Something blocks your spellcasting.");
1641  break;
1642 
1643  case range_misc:
1645  "Something blocks the magic of your item.");
1646  break;
1647  case range_golem:
1649  "Something blocks the magic of your scroll.");
1650  break;
1651 
1652  default:
1653  break;
1654  }
1655  return 0;
1656  }
1657 
1658  if (caster == op && caster->type ==PLAYER && settings.casting_time == TRUE && spell_ob->type == SPELL) {
1659  if (op->casting_time == -1) { /* begin the casting */
1660  op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob);
1661  op->spell = spell_ob;
1662  /* put the stringarg into the object struct so that when the
1663  * spell is actually cast, it knows about the stringarg.
1664  * necessary for the invoke command spells.
1665  */
1666  if (stringarg) {
1667  op->spellarg = strdup_local(stringarg);
1668  } else
1669  op->spellarg = NULL;
1670  return 0;
1671  } else if (op->casting_time != 0) {
1672  if (op->type == PLAYER)
1674  "You are casting!");
1675  return 0;
1676  } else { /* casting_time == 0 */
1677  op->casting_time = -1;
1678  spell_ob = op->spell;
1679  stringarg = op->spellarg;
1680  }
1681  } else {
1682  if (!QUERY_FLAG(caster, FLAG_WIZ)) {
1683  /* Take into account how long it takes to cast the spell.
1684  * if the player is casting it, then we use the time in
1685  * the spell object. If it is a spell object, have it
1686  * take two ticks. Things that cast spells on the players
1687  * behalf (eg, altars, and whatever else) shouldn't cost
1688  * the player any time.
1689  * Ignore casting time for firewalls
1690  */
1691  if (caster == op && caster->type != FIREWALL) {
1692  op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1693  /* Other portions of the code may also decrement the speed of the player, so
1694  * put a lower limit so that the player isn't stuck here too long
1695  */
1696  if ((spell_ob->casting_time > 0)
1697  && op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed))
1698  op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1699  } else if (caster->type == WAND
1700  || caster->type == ROD
1701  || caster->type == POTION
1702  || caster->type == SCROLL) {
1703  op->speed_left -= 2*FABS(op->speed);
1704  }
1705  }
1706  }
1707 
1708  /* We want to try to find the skill to properly credit exp.
1709  * for spell casting objects, the exp goes to the skill the casting
1710  * object requires.
1711  */
1712  if (op != caster && !skill && caster->skill && !QUERY_FLAG(op, FLAG_MONSTER)) {
1713  skill = find_skill_by_name(op, caster->skill);
1714  if (!skill) {
1715  char name[MAX_BUF];
1716 
1717  query_name(caster, name, MAX_BUF);
1720  "You lack the skill %s to use the %s",
1721  caster->skill, name);
1722  return 0;
1723  }
1724  change_skill(op, skill, 0); /* needed for proper exp credit */
1725  }
1726 
1727  /* Need to get proper ownership for spells cast via runes - these are not
1728  * the normal 'rune of fire', but rather the magic runes that let the player
1729  * put some other spell into the rune (glyph, firetrap, magic rune, etc)
1730  */
1731  if (caster->type == RUNE) {
1732  object *owner = object_get_owner(caster);
1733 
1734  if (owner)
1735  skill = find_skill_by_name(owner, caster->skill);
1736  }
1737 
1738  if (confusion_effect) {
1739  /* If we get here, the confusion effect was 'random effect', so do it and bail out. */
1742  "In your confused state, you can't control the magic!");
1744 
1745  /* Still subtract full grace and sp. */
1746  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1747  op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE);
1748  op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA);
1749  }
1750 
1751  return 0;
1752  }
1753 
1754  play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name);
1755 
1756  switch (spell_ob->subtype) {
1757  /* The order of case statements is same as the order they show up
1758  * in in spells.h.
1759  */
1760  case SP_RAISE_DEAD:
1761  success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg);
1762  break;
1763 
1764  case SP_RUNE:
1765  success = write_rune(op, caster, spell_ob, dir, stringarg);
1766  break;
1767 
1768  case SP_MAKE_MARK:
1769  success = write_mark(op, spell_ob, stringarg);
1770  break;
1771 
1772  case SP_BOLT:
1773  success = fire_bolt(op, caster, dir, spell_ob);
1774  break;
1775 
1776  case SP_BULLET:
1777  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1778  break;
1779 
1780  case SP_CONE:
1781  success = cast_cone(op, caster, dir, spell_ob);
1782  break;
1783 
1784  case SP_BOMB:
1785  success = create_bomb(op, caster, dir, spell_ob);
1786  break;
1787 
1788  case SP_WONDER:
1789  success = cast_wonder(op, caster, dir, spell_ob);
1790  break;
1791 
1792  case SP_SMITE:
1793  success = cast_smite_spell(op, caster, dir, spell_ob);
1794  break;
1795 
1796  case SP_MAGIC_MISSILE:
1797  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1798  break;
1799 
1800  case SP_SUMMON_GOLEM:
1801  success = pets_summon_golem(op, caster, dir, spell_ob);
1802  if (success || op->contr == NULL)
1803  old_shoottype = range_golem;
1804  else
1805  /*
1806  * if the spell failed (something in the way for instance),
1807  * don't change the range so the player can try easily after that
1808  */
1809  old_shoottype = op->contr->shoottype;
1810  break;
1811 
1812  case SP_DIMENSION_DOOR:
1813  /* dimension door needs the actual caster, because that is what is
1814  * moved.
1815  */
1816  success = dimension_door(op, caster, spell_ob, dir);
1817  break;
1818 
1819  case SP_MAGIC_MAPPING:
1820  if (op->type == PLAYER) {
1821  spell_effect(spell_ob, op->x, op->y, op->map, op);
1822  draw_magic_map(op);
1823  success = 1;
1824  } else
1825  success = 0;
1826  break;
1827 
1828  case SP_MAGIC_WALL:
1829  success = magic_wall(op, caster, dir, spell_ob);
1830  break;
1831 
1832  case SP_DESTRUCTION:
1833  success = cast_destruction(op, caster, spell_ob);
1834  break;
1835 
1836  case SP_PERCEIVE_SELF:
1837  success = perceive_self(op);
1838  break;
1839 
1840  case SP_WORD_OF_RECALL:
1841  success = cast_word_of_recall(op, caster, spell_ob);
1842  break;
1843 
1844  case SP_INVISIBLE:
1845  success = cast_invisible(op, caster, spell_ob);
1846  break;
1847 
1848  case SP_PROBE:
1849  if (op != caster)
1850  cast_level = caster->level;
1851  else
1852  cast_level = skill != NULL ? skill->level : op->level;
1853  success = probe(op, caster, spell_ob, dir, cast_level);
1854  break;
1855 
1856  case SP_HEALING:
1857  success = cast_heal(op, caster, spell_ob, dir);
1858  break;
1859 
1860  case SP_CREATE_FOOD:
1861  success = cast_create_food(op, caster, spell_ob, dir, stringarg);
1862  break;
1863 
1864  case SP_EARTH_TO_DUST:
1865  success = cast_earth_to_dust(op, caster, spell_ob);
1866  break;
1867 
1868  case SP_CHANGE_ABILITY:
1869  success = cast_change_ability(op, caster, spell_ob, dir, 0);
1870  break;
1871 
1872  case SP_BLESS:
1873  success = cast_bless(op, caster, spell_ob, dir);
1874  break;
1875 
1876  case SP_CURSE:
1877  success = cast_curse(op, caster, spell_ob, dir);
1878  break;
1879 
1880  case SP_SUMMON_MONSTER:
1881  success = pets_summon_object(op, caster, spell_ob, dir, stringarg);
1882  if (!success) {
1883  cost_multiplier = 0.0f;
1884  }
1885  break;
1886 
1887  case SP_CHARGING:
1888  success = recharge(op, caster, spell_ob);
1889  break;
1890 
1891  case SP_POLYMORPH:
1892 #if 0
1893  /* Not great, but at least provide feedback so if players do have
1894  * polymorph (ie, find it as a preset item or left over from before
1895  * it was disabled), they get some feedback.
1896  */
1898  "The spell fizzles");
1899  success = 0;
1900 #else
1901  success = cast_polymorph(op, caster, spell_ob, dir);
1902 #endif
1903  break;
1904 
1905  case SP_ALCHEMY:
1906  success = alchemy(op, caster, spell_ob);
1907  break;
1908 
1909  case SP_REMOVE_CURSE:
1910  success = remove_curse(op, caster, spell_ob);
1911  break;
1912 
1913  case SP_IDENTIFY:
1914  success = cast_identify(op, caster, spell_ob);
1915  break;
1916 
1917  case SP_DETECTION:
1918  success = cast_detection(op, caster, spell_ob);
1919  break;
1920 
1921  case SP_MOOD_CHANGE:
1922  success = mood_change(op, caster, spell_ob);
1923  break;
1924 
1925  case SP_MOVING_BALL:
1926  if (spell_ob->path_repelled
1927  && (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) {
1929  "You lack the proper attunement to cast %s",
1930  spell_ob->name);
1931  success = 0;
1932  } else
1933  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1934  break;
1935 
1936  case SP_SWARM:
1937  success = fire_swarm(op, caster, spell_ob, dir);
1938  break;
1939 
1940  case SP_CHANGE_MANA:
1941  success = cast_transfer(op, caster, spell_ob, dir);
1942  break;
1943 
1944  case SP_DISPEL_RUNE:
1945  /* in rune.c */
1946  success = dispel_rune(op, caster, spell_ob, skill, dir);
1947  break;
1948 
1949  case SP_CREATE_MISSILE:
1950  success = cast_create_missile(op, caster, spell_ob, dir, stringarg);
1951  break;
1952 
1953  case SP_CONSECRATE:
1954  success = cast_consecrate(op, caster, spell_ob);
1955  break;
1956 
1957  case SP_ANIMATE_WEAPON:
1958  success = animate_weapon(op, caster, spell_ob, dir);
1959  old_shoottype = range_golem;
1960  break;
1961 
1962  case SP_LIGHT:
1963  success = cast_light(op, caster, spell_ob, dir);
1964  break;
1965 
1966  case SP_CHANGE_MAP_LIGHT:
1967  success = cast_change_map_lightlevel(op, caster, spell_ob);
1968  break;
1969 
1970  case SP_FAERY_FIRE:
1971  success = cast_destruction(op, caster, spell_ob);
1972  break;
1973 
1974  case SP_CAUSE_DISEASE:
1975  success = cast_cause_disease(op, caster, spell_ob, dir);
1976  break;
1977 
1978  case SP_AURA:
1979  success = create_aura(op, caster, spell_ob);
1980  break;
1981 
1982  case SP_TOWN_PORTAL:
1983  success = cast_create_town_portal(op, caster, spell_ob, dir);
1984  break;
1985 
1986  case SP_ITEM_CURSE_BLESS:
1987  success = cast_item_curse_or_curse(op, caster, spell_ob);
1988  break;
1989 
1990  case SP_ELEM_SHIELD:
1991  success = create_aura(op, caster, spell_ob);
1992  break;
1993 
1994  default:
1995  LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1996  }
1997 
1998  /* Subtract grace and sp. */
1999  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
2000  op->stats.grace -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE));
2001  op->stats.sp -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA));
2002  }
2003 
2004  /* FIXME - we need some better sound suppport */
2005  /* free the spell arg */
2006  if (settings.casting_time == TRUE) {
2007  free(stringarg);
2008  stringarg = NULL;
2009  }
2010  /* perhaps a bit of a hack, but if using a wand, it has to change the skill
2011  * to something like use_magic_item, but you really want to be able to fire
2012  * it again.
2013  */
2014  if (op->contr)
2015  op->contr->shoottype = old_shoottype;
2016 
2017  return success;
2018 }
2019 
2026 void store_spell_expiry(object *spell) {
2027  /* Keep when to warn the player of expiration */
2028  char dur[10];
2029  int i = spell->duration/5;
2030 
2031  if (!i)
2032  i = 1;
2033  snprintf(dur, sizeof(dur), "%d", i);
2034  object_set_value(spell, "spell_expiry_warn_1", dur, 1);
2035  i = i/5;
2036  if (i > 0) {
2037  snprintf(dur, sizeof(dur), "%d", i);
2038  object_set_value(spell, "spell_expiry_warn_2", dur, 1);
2039  }
2040 }
2041 
2051 void check_spell_expiry(object *spell) {
2052  const char *key;
2053 
2054  if (!spell->env || !IS_PLAYER(spell->env))
2055  return;
2056 
2057  key = object_get_value(spell, "spell_expiry_warn_1");
2058  if (key != NULL) {
2059  if (spell->duration == atoi(key)) {
2061  "The effects of your %s are draining out.", spell->name);
2062  return;
2063  }
2064  }
2065  key = object_get_value(spell, "spell_expiry_warn_2");
2066  if (key != NULL) {
2067  if (spell->duration == atoi(key)) {
2069  "The effects of your %s are about to expire.", spell->name);
2070  return;
2071  }
2072  }
2073 }
2074 
2082 void rod_adjust(object *rod) {
2083  /*
2084  * Add 50 to both level an divisor to keep prices a little
2085  * more reasonable. Otherwise, a high level version of a
2086  * low level spell can be worth tons a money (eg, level 20
2087  * rod, level 2 spell = 10 time multiplier). This way, the
2088  * value are a bit more reasonable.
2089  */
2090  rod->value = rod->value*rod->inv->value*(rod->level+50)/(rod->inv->level+50);
2091 
2092  /*
2093  * Maxhp is used to denote how many 'charges' the rod holds
2094  * before.
2095  */
2096  rod->stats.maxhp = MAX(rod->stats.maxhp, 2)*SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
2097  rod->stats.hp = rod->stats.maxhp;
2098 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:316
#define AP_UNAPPLY
Definition: define.h:613
object * object_find_by_type_and_name(const object *who, int type, const char *name)
Definition: object.c:4052
#define AT_HOLYWORD
Definition: attack.h:97
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:219
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:605
void drain_rod_charge(object *rod)
Definition: spell_util.c:817
const char * determine_god(object *op)
Definition: gods.c:106
archetype * find_archetype(const char *name)
Definition: arch.c:695
object * lookup_spell_by_name(object *op, const char *spname)
Definition: spell_util.c:449
#define ARCH_SPELL_BUNGLE
Definition: object.h:583
#define MSG_TYPE_ITEM_CHANGE
Definition: newclient.h:640
#define SP_BOLT
Definition: spells.h:78
#define INS_BELOW_ORIGINATOR
Definition: object.h:572
#define MSG_TYPE_ITEM
Definition: newclient.h:388
int change_skill(object *who, object *new_skill, int flag)
Definition: skill_util.c:340
const char * skill_names[MAX_SKILLS]
Definition: skill_util.c:58
#define SP_MAKE_MARK
Definition: spells.h:77
#define AT_COUNTERSPELL
Definition: attack.h:95
uint8_t dam_modifier
Definition: object.h:409
object * find_applied_skill_by_name(const object *op, const char *name)
Definition: living.c:1915
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg)
Definition: resurrection.c:181
struct Statistics statistics
Definition: init.c:98
#define SP_CAUSE_DISEASE
Definition: spells.h:119
void spell_failure(object *op, int failure, int power, object *skill)
Definition: spell_util.c:1151
void esrv_send_item(object *pl, object *op)
Definition: main.c:340
#define SET_FLAG(xyz, p)
Definition: define.h:223
sstring add_refcount(sstring str)
Definition: shstr.c:210
#define SP_TOWN_PORTAL
Definition: spells.h:121
#define SP_CONE
Definition: spells.h:81
#define SP_BLESS
Definition: spells.h:99
object * find_target_for_friendly_spell(object *op, int dir)
Definition: spell_util.c:854
#define FABS(x)
Definition: define.h:22
Definition: object.h:221
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
void object_copy_owner(object *op, object *clone)
Definition: object.c:690
#define SP_CHANGE_MAP_LIGHT
Definition: spells.h:117
#define UPD_ANIM
Definition: newclient.h:294
#define strdup_local
Definition: compat.h:25
tag_t * spell_tags
Definition: object.h:438
#define AT_INTERNAL
Definition: attack.h:99
int reflwall(mapstruct *m, int x, int y, object *sp_op)
Definition: spell_util.c:509
#define SP_CHANGE_ABILITY
Definition: spells.h:98
uint8_t spellpoint_level_depend
Definition: global.h:276
Definition: object.h:117
#define P_NO_MAGIC
Definition: map.h:227
int8_t range
Definition: object.h:407
#define SP_MOVING_BALL
Definition: spells.h:109
int cast_bless(object *op, object *caster, object *spell_ob, int dir)
#define SP_AURA
Definition: spells.h:120
#define MSG_TYPE_SPELL
Definition: newclient.h:387
#define SPELL_GRACE
Definition: spells.h:59
void get_search_arr(int *search_arr)
Definition: object.c:3519
int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell)
Definition: spell_util.c:670
#define MSG_TYPE_SPELL_FAILURE
Definition: newclient.h:628
int spell_find_dir(mapstruct *m, int x, int y, object *exclude)
Definition: spell_util.c:927
int16_t maxgrace
Definition: living.h:45
#define SP_ANIMATE_WEAPON
Definition: spells.h:115
int SP_level_duration_adjust(const object *caster, const object *spob)
Definition: spell_util.c:351
#define HUGE_BUF
Definition: define.h:37
int SP_level_range_adjust(const object *caster, const object *spob)
Definition: spell_util.c:377
#define SET_ANIMATION(ob, newanim)
Definition: global.h:169
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:343
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4299
struct treasureliststruct * randomitems
Definition: object.h:387
int cast_smite_spell(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:546
#define MSG_TYPE_SPELL_INFO
Definition: newclient.h:634
static int spell_consume_items(object *op, const object *spell_ob)
Definition: spell_util.c:1353
object clone
Definition: object.h:472
int16_t duration
Definition: object.h:405
int16_t invisible
Definition: object.h:361
short freearr_x[SIZEOFFREE]
Definition: object.c:65
#define PREFER_LOW
Definition: define.h:602
uint8_t duration_modifier
Definition: object.h:406
rangetype shoottype
Definition: player.h:99
Definition: object.h:240
Definition: object.h:119
#define DIRX(xyz)
Definition: define.h:479
int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop)
Definition: spell_util.c:569
int isqrt(int n)
Definition: utils.c:586
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.c:275
const char * slaying
Definition: object.h:319
#define FLAG_CONFUSED
Definition: define.h:312
int cast_word_of_recall(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:916
#define MSG_TYPE_SKILL_MISSING
Definition: newclient.h:582
uint8_t subtype
Definition: object.h:340
Definition: object.h:109
#define SPELL_WONDER
Definition: spells.h:163
struct obj * above
Definition: object.h:288
#define PATH_TIME_MULT(op, spell)
Definition: spells.h:152
method_ret ob_process(object *op)
Definition: ob_methods.c:68
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:217
#define TRUE
Definition: compat.h:10
int freedir[SIZEOFFREE]
Definition: object.c:83
void draw_magic_map(object *pl)
Definition: info.c:440
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:314
#define FALSE
Definition: compat.h:11
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:433
uint32_t path_attuned
Definition: object.h:344
#define MAX(x, y)
Definition: compat.h:20
int create_bomb(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:447
int16_t sp
Definition: living.h:42
#define FLAG_REFLECTING
Definition: define.h:262
#define SP_CREATE_MISSILE
Definition: spells.h:113
uint32_t path_repelled
Definition: object.h:345
struct archt * other_arch
Definition: object.h:415
int recharge(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:80
#define SP_HEALING
Definition: spells.h:95
int absdir(int d)
Definition: object.c:3655
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:311
Definition: object.h:467
static int can_be_transmuted_to_flower(object *op)
Definition: spell_util.c:1209
Definition: object.h:220
#define MSG_TYPE_APPLY
Definition: newclient.h:384
uint8_t casting_time
Definition: global.h:272
#define MSG_TYPE_VICTIM_SPELL
Definition: newclient.h:651
#define SP_WORD_OF_RECALL
Definition: spells.h:92
int16_t maxsp
Definition: living.h:43
int16_t hp
Definition: living.h:40
#define DIRY(xyz)
Definition: define.h:480
int caster_level(const object *caster, const object *spell)
Definition: spell_util.c:233
int cast_cone(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:297
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: spell_effect.c:622
void rod_adjust(object *rod)
Definition: spell_util.c:2082
short freearr_y[SIZEOFFREE]
Definition: object.c:71
void check_bullet(object *op)
Definition: spell_attack.c:217
#define NDI_NAVY
Definition: newclient.h:223
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:488
#define LOOSE_MANA
Definition: spells.h:162
void esrv_del_item(player *pl, object *ob)
Definition: main.c:356
int summon_hostile_monsters(object *op, int n, const char *monstername)
Definition: spell_util.c:1045
int rndm(int min, int max)
Definition: utils.c:162
int probe(object *op, object *caster, object *spell_ob, int dir, int level)
Definition: spell_effect.c:700
void object_set_owner(object *op, object *owner)
Definition: object.c:634
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4428
void object_free_drop_inventory(object *ob)
Definition: object.c:1391
int change_abil(object *op, object *tmp)
Definition: living.c:395
int16_t y
Definition: object.h:326
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1935
int16_t maxhp
Definition: living.h:41
int cast_item_curse_or_curse(object *op, object *caster, object *spell_ob)
#define AT_GODPOWER
Definition: attack.h:96
int cast_curse(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_attack.c:800
int fire_swarm(object *op, object *caster, object *spell, int dir)
static void swap_random_stats(object *op)
Definition: spell_util.c:1299
#define SP_PERCEIVE_SELF
Definition: spells.h:91
void object_update_turn_face(object *op)
Definition: object.c:1132
Definition: object.h:118
uint32_t path_denied
Definition: object.h:346
#define SP_BULLET
Definition: spells.h:79
#define FLAG_ALIVE
Definition: define.h:230
void confuse_living(object *op, object *hitter, int dam)
Definition: attack.c:2266
#define AP_IGNORE_CURSE
Definition: define.h:620
#define FLAG_REFL_SPELL
Definition: define.h:275
#define MSG_TYPE_VICTIM
Definition: newclient.h:392
#define SP_ITEM_CURSE_BLESS
Definition: spells.h:123
struct obj * spell
Definition: object.h:410
object * create_archetype(const char *name)
Definition: arch.c:620
void store_spell_expiry(object *spell)
Definition: spell_util.c:2026
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2709
int cast_create_town_portal(object *op, object *caster, object *spell, int dir)
#define SP_MOOD_CHANGE
Definition: spells.h:108
float speed_left
Definition: object.h:329
signed short int16_t
Definition: win32.h:160
EXTERN Chaos_Attacks ATTACKS[22]
Definition: attack.h:134
int32_t weight
Definition: object.h:366
static void handle_spell_confusion(object *op)
Definition: spell_util.c:1334
const char * anim_suffix
Definition: object.h:316
uint8_t range_modifier
Definition: object.h:408
static bool IS_PLAYER(object *op)
Definition: object.h:596
#define SP_BOMB
Definition: spells.h:82
int8_t Wis
Definition: living.h:36
struct mapdef * map
Definition: object.h:297
#define snprintf
Definition: win32.h:46
static void transmute_item_to_flower(object *op)
Definition: spell_util.c:1231
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
#define SP_WONDER
Definition: spells.h:83
int perceive_self(object *op)
#define FOR_INV_FINISH()
Definition: define.h:715
void set_spell_skill(object *op, object *caster, object *spob, object *dest)
Definition: spell_util.c:94
int pets_summon_golem(object *op, object *caster, int dir, object *spob)
Definition: pets.c:672
int cast_light(object *op, object *caster, object *spell, int dir)
int16_t dam
Definition: living.h:46
int cast_create_obj(object *op, object *new_op, int dir)
Definition: spell_util.c:533
#define MSG_TYPE_SPELL_ERROR
Definition: newclient.h:631
void drain_wand_charge(object *wand)
Definition: spell_util.c:827
Definition: object.h:145
const char * name
Definition: object.h:311
struct obj * env
Definition: object.h:293
int write_mark(object *op, object *spell, const char *msg)
void regenerate_rod(object *rod)
Definition: spell_util.c:802
#define OB_SPELL_TAG_MATCH(op, count)
Definition: object.h:93
#define SP_SMITE
Definition: spells.h:84
struct obj * below
Definition: object.h:287
struct archt * more
Definition: object.h:471
const char *const spell_mapping[]
static int put_a_monster(object *op, const char *monstername)
Definition: spell_util.c:979
int8_t direction
Definition: object.h:335
#define SP_ALCHEMY
Definition: spells.h:104
object * find_random_spell_in_ob(object *ob, const char *skill)
Definition: spell_util.c:48
uint32_t nrof
Definition: object.h:333
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:447
#define AP_NOPRINT
Definition: define.h:624
void paralyze_living(object *op, int dam)
Definition: attack.c:2349
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
Definition: map.h:251
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:192
Definition: object.h:111
struct pl * contr
Definition: object.h:276
#define GOD_POWER
Definition: spells.h:164
#define SP_INVISIBLE
Definition: spells.h:93
#define SP_CHARGING
Definition: spells.h:102
#define MSG_TYPE_SKILL_FAILURE
Definition: newclient.h:585
#define SP_DESTRUCTION
Definition: spells.h:90
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4304
int cast_detection(object *op, object *caster, object *spell)
void cast_magic_storm(object *op, object *tmp, int lvl)
Definition: spell_effect.c:45
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:206
char * spellarg
Definition: object.h:411
uint32_t tag_t
Definition: object.h:12
#define SP_DETECTION
Definition: spells.h:107
float speed
Definition: object.h:328
Definition: object.h:214
int cast_wonder(object *op, object *caster, int dir, object *spell_ob)
Definition: spell_effect.c:978
#define SP_RUNE
Definition: spells.h:76
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define HEAD(op)
Definition: object.h:594
int cast_invisible(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:804
#define FLAG_WIZ
Definition: define.h:231
int write_rune(object *op, object *caster, object *spell, int dir, const char *runename)
Definition: rune.c:50
void shuffle_attack(object *op, int change_face)
Definition: spell_util.c:1079
int cast_consecrate(object *op, object *caster, object *spell)
#define MAX_BUF
Definition: define.h:35
#define SP_SWARM
Definition: spells.h:110
int cast_transfer(object *op, object *caster, object *spell, int dir)
int16_t x
Definition: object.h:326
#define SP_IDENTIFY
Definition: spells.h:106
#define SP_EARTH_TO_DUST
Definition: spells.h:97
int16_t encumbrance
Definition: player.h:179
const char * skill
Definition: object.h:321
int dimension_door(object *op, object *caster, object *spob, int dir)
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3476
uint16_t difficulty
Definition: map.h:343
int cast_destruction(object *op, object *caster, object *spell_ob)
Definition: spell_attack.c:707
static const flag_definition flags[]
#define FOR_MAP_FINISH()
Definition: define.h:768
#define SP_DIMENSION_DOOR
Definition: spells.h:87
#define SP_CHANGE_MANA
Definition: spells.h:111
const char * sstring
Definition: global.h:40
#define SPELL_TAG_SIZE
Definition: object.h:81
unsigned int uint32_t
Definition: win32.h:162
Definition: object.h:107
void check_spells(void)
Definition: spell_util.c:109
#define SP_CURSE
Definition: spells.h:100
#define SP_POLYMORPH
Definition: spells.h:103
int tailor_god_spell(object *spellop, object *caster)
Definition: gods.c:1314
#define FLAG_ANIMATE
Definition: define.h:242
int cast_cause_disease(object *op, object *caster, object *spell, int dir)
#define PREFER_HIGH
Definition: define.h:601
uint32_t attacktype
Definition: object.h:343
#define FLAG_GENERATOR
Definition: define.h:248
int cast_heal(object *op, object *caster, object *spell, int dir)
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2522
void play_sound_player_only(player *pl, int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:51
#define RANDOM()
Definition: define.h:682
int16_t grace
Definition: living.h:44
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg)
Definition: spell_effect.c:499
int mood_change(object *op, object *caster, object *spell)
Definition: spell_attack.c:904
tag_t count
Definition: object.h:299
living stats
Definition: object.h:369
#define FLAG_WIZCAST
Definition: define.h:290
#define SP_FAERY_FIRE
Definition: spells.h:118
struct archt * arch
Definition: object.h:414
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:865
#define SPELL_HIGHEST
Definition: spells.h:60
uint8_t type
Definition: object.h:339
struct Settings settings
Definition: init.c:39
void dump_spells(void)
Definition: spell_util.c:146
uint64_t spell_suppressions
Definition: global.h:355
struct archt * next
Definition: object.h:469
rangetype
Definition: player.h:15
int fire_bolt(object *op, object *caster, int dir, object *spob)
Definition: spell_attack.c:61
#define SP_MAGIC_MISSILE
Definition: spells.h:85
#define FLAG_APPLIED
Definition: define.h:235
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:551
object * object_get_player_container(object *op)
Definition: object.c:386
#define SP_MAGIC_MAPPING
Definition: spells.h:88
signed int int32_t
Definition: win32.h:159
#define SP_LIGHT
Definition: spells.h:116
#define SP_SUMMON_MONSTER
Definition: spells.h:101
int16_t casting_time
Definition: object.h:404
#define FORCE_NAME
Definition: spells.h:169
#define AT_MAGIC
Definition: attack.h:77
int min_casting_level(const object *caster, const object *spell)
Definition: spell_util.c:203
int alchemy(object *op, object *caster, object *spell_ob)
#define GET_MAP_OB(M, X, Y)
Definition: map.h:172
#define FORCE_TRANSFORMED_ITEM
Definition: spells.h:146
#define FLAG_MONSTER
Definition: define.h:245
#define ARCH_SPELL_BLOCKED
Definition: object.h:582
int animate_weapon(object *op, object *caster, object *spell, int dir)
#define MSG_TYPE_SKILL
Definition: newclient.h:383
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:310
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Definition: utils.c:500
struct obj * inv
Definition: object.h:290
#define NDI_UNIQUE
Definition: newclient.h:245
void apply_anim_suffix(object *who, sstring suffix)
Definition: anim.c:319
int get_cleric_chance(int stat)
Definition: living.c:2364
struct obj * head
Definition: object.h:296
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define SP_MAGIC_WALL
Definition: spells.h:89
int pets_summon_object(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: pets.c:935
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:761
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:107
void check_spell_expiry(object *spell)
Definition: spell_util.c:2051
#define P_BLOCKSVIEW
Definition: map.h:226
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
Definition: object.c:3763
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:626
#define SPELL_MANA
Definition: spells.h:58
#define SP_DISPEL_RUNE
Definition: spells.h:112
#define SP_ELEM_SHIELD
Definition: spells.h:124
#define MAX_SKILLS
Definition: skills.h:70
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1469
Definition: map.h:325
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
const New_Face * face
Definition: object.h:332
static void prayer_failure(object *op, int failure, int power)
Definition: spell_util.c:1100
void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator)
Definition: spell_util.c:183
int SP_level_wc_adjust(const object *caster, const object *spob)
Definition: spell_util.c:401
int SP_level_dam_adjust(const object *caster, const object *spob)
Definition: spell_util.c:326
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Definition: attack.c:1862
int16_t level
Definition: object.h:352
uint8_t spell_failure_effects
Definition: global.h:271
void fix_object(object *op)
Definition: living.c:1120
#define SP_SUMMON_GOLEM
Definition: spells.h:86
#define SOUND_TYPE_SPELL
Definition: newclient.h:309
#define SP_PROBE
Definition: spells.h:94
#define SP_CREATE_FOOD
Definition: spells.h:96
EXTERN archetype * first_archetype
Definition: global.h:122
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:192
struct obj * more
Definition: object.h:295
object * arch_to_object(archetype *at)
Definition: arch.c:571
void object_update_speed(object *op)
Definition: object.c:1152
int cast_identify(object *op, object *caster, object *spell)
int32_t value
Definition: object.h:351
object * object_get_owner(object *op)
Definition: object.c:592
const char * name
Definition: object.h:468
int dispel_rune(object *op, object *caster, object *spell, object *skill, int dir)
Definition: rune.c:299
#define P_NO_CLERIC
Definition: map.h:238
#define SP_CONSECRATE
Definition: spells.h:114
int create_aura(object *op, object *caster, object *spell)
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:708
void object_remove(object *op)
Definition: object.c:1668
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_effect.c:431
int32_t food
Definition: living.h:48
int attacktype
Definition: attack.h:126
int magic_wall(object *op, object *caster, int dir, object *spell_ob)
#define PATH_SP_MULT(op, spell)
Definition: spells.h:36
#define SP_RAISE_DEAD
Definition: spells.h:75
#define SP_REMOVE_CURSE
Definition: spells.h:105