Crossfire Server, Trunk
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 
46 object *find_random_spell_in_ob(object *ob, const char *skill) {
47  int k = 0, s;
48 
50  if (tmp->type == SPELL && (!skill || tmp->skill == skill))
51  k++;
53 
54  /* No spells, no need to progess further */
55  if (!k)
56  return NULL;
57 
58  s = RANDOM()%k;
60  if (tmp->type == SPELL && (!skill || tmp->skill == skill)) {
61  if (!s)
62  return tmp;
63  else
64  s--;
65  }
67 
68  /* Should never get here, but just in case */
69  return NULL;
70 }
71 
92 void set_spell_skill(object *op, object *caster, object *spob, object *dest) {
93  if (dest->skill)
94  FREE_AND_CLEAR_STR(dest->skill);
95  if (caster == op && spob->skill)
96  dest->skill = add_refcount(spob->skill);
97  else if (caster->skill)
98  dest->skill = add_refcount(caster->skill);
99 }
100 
106 void dump_spells(void) {
107  archetype *at;
108  int banner = 0;
109 
110  for (at = get_next_archetype(NULL); at; at = get_next_archetype(at)) {
111  if (at->clone.type == SPELL) {
112  fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null",
113  at->name, at->clone.other_arch ? at->clone.other_arch->name : "null",
114  at->clone.skill ? at->clone.skill : "null", at->clone.level);
115  }
116  }
117 
118  for (at = get_next_archetype(NULL); at; at = get_next_archetype(at)) {
119  if (at->clone.type == SPELL && at->clone.path_attuned == 0) {
120  if (banner == 0) {
121  banner = 1;
122  fprintf(stderr, "Spells with no path set:\n");
123  }
124 
125  fprintf(stderr, "- %s\n", at->clone.name ? at->clone.name : "null");
126  }
127  }
128 }
129 
143 void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) {
144  if (spob->other_arch != NULL) {
145  object *effect = arch_to_object(spob->other_arch);
146  object_insert_in_map_at(effect, map, originator, 0, x, y);
147  }
148 }
149 
163 int min_casting_level(const object *caster, const object *spell) {
164  int new_level;
165 
166  if (caster->path_denied&spell->path_attuned) {
167  /* This case is not a bug, just the fact that this function is
168  * usually called BEFORE checking for path_deny. -AV
169  */
170  return 1;
171  }
172  new_level = spell->level
173  +((caster->path_repelled&spell->path_attuned) ? +2 : 0)
174  +((caster->path_attuned&spell->path_attuned) ? -2 : 0);
175  return MAX(new_level, 1);
176 }
177 
178 
193 int caster_level(const object *caster, const object *spell) {
194  int level = caster->level;
195 
196  /* If this is a player, try to find the matching skill */
197  if (caster->type == PLAYER && spell->skill) {
198  object* skill = find_applied_skill_by_name(caster, spell->skill);
199  if (skill != NULL) {
200  level = skill->level;
201  } else {
202  level = 0;
203  }
204  }
205  /* Got valid caster level. Now adjust for attunement */
206  level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0)
207  +((caster->path_attuned&spell->path_attuned) ? 2 : 0);
208 
209  /* Always make this at least 1. If this is zero, we get divide by zero
210  * errors in various places.
211  */
212  if (level < 1)
213  level = 1;
214  return level;
215 }
216 
235 int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags) {
236  int sp, grace, level = caster_level(caster, spell);
237 
239  if (spell->stats.sp && spell->stats.maxsp) {
240  sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp)));
241  } else
242  sp = spell->stats.sp;
243 
244  sp *= PATH_SP_MULT(caster, spell);
245  if (!sp && spell->stats.sp)
246  sp = 1;
247 
248  if (spell->stats.grace && spell->stats.maxgrace) {
249  grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace)));
250  } else
251  grace = spell->stats.grace;
252 
253  grace *= PATH_SP_MULT(caster, spell);
254  if (spell->stats.grace && !grace)
255  grace = 1;
256  } else {
257  sp = spell->stats.sp*PATH_SP_MULT(caster, spell);
258  if (spell->stats.sp && !sp)
259  sp = 1;
260  grace = spell->stats.grace*PATH_SP_MULT(caster, spell);
261  if (spell->stats.grace && !grace)
262  grace = 1;
263  }
264  if (flags == SPELL_HIGHEST)
265  return MAX(sp, grace);
266  else if (flags == SPELL_GRACE)
267  return grace;
268  else if (flags == SPELL_MANA)
269  return sp;
270  else {
271  LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
272  return 0;
273  }
274 }
275 
286 int SP_level_dam_adjust(const object *caster, const object *spob) {
287  int level = caster_level(caster, spob);
288  int adj = level-min_casting_level(caster, spob);
289 
290  if (adj < 0)
291  adj = 0;
292  if (spob->dam_modifier)
293  adj /= spob->dam_modifier;
294  else
295  adj = 0;
296  return adj;
297 }
298 
311 int SP_level_duration_adjust(const object *caster, const object *spob) {
312  int level = caster_level(caster, spob);
313  int adj = level-min_casting_level(caster, spob);
314 
315  if (adj < 0)
316  adj = 0;
317  if (spob->duration_modifier)
318  adj /= spob->duration_modifier;
319  else
320  adj = 0;
321 
322  return adj;
323 }
324 
337 int SP_level_range_adjust(const object *caster, const object *spob) {
338  int level = caster_level(caster, spob);
339  int adj = level-min_casting_level(caster, spob);
340 
341  if (adj < 0)
342  adj = 0;
343  if (spob->range_modifier)
344  adj /= spob->range_modifier;
345  else
346  adj = 0;
347 
348  return adj;
349 }
350 
361 int SP_level_wc_adjust(const object *caster, const object *spob) {
362  int level = caster_level(caster, spob);
363  int adj = level - min_casting_level(caster, spob), irate;
364  sstring rate;
365 
366  rate = object_get_value(spob, "wc_increase_rate");
367 
368  if (rate == NULL)
369  return 0;
370 
371  if (adj < 0)
372  adj = 0;
373 
374  irate = atoi(rate);
375  if (irate > 0)
376  adj /= irate;
377  else
378  adj = 0;
379  return adj;
380 }
381 
393 object *check_spell_known(object *op, const char *name) {
395 }
396 
409 object *lookup_spell_by_name(object *op, const char *spname) {
410  object *spob1 = NULL, *spob2 = NULL;
411  int nummatch = 0;
412 
413  if (spname == NULL)
414  return NULL;
415 
416  /* Try to find the spell. We store the results in spob1
417  * and spob2 - spob1 is only taking the length of
418  * the past spname, spob2 uses the length of the spell name.
419  */
420  FOR_INV_PREPARE(op, spob) {
421  if (spob->type == SPELL) {
422  if (!strncmp(spob->name, spname, strlen(spname))) {
423  if (strlen(spname) == strlen(spob->name))
424  /* Perfect match, return it. */
425  return spob;
426  nummatch++;
427  spob1 = spob;
428  } else if (!strncmp(spob->name, spname, strlen(spob->name))) {
429  /* if spells have ambiguous names, it makes matching
430  * really difficult. (eg, fire and fireball would
431  * fall into this category). It shouldn't be hard to
432  * make sure spell names don't overlap in that fashion.
433  */
434  if (spob2)
435  LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name);
436  spob2 = spob;
437  }
438  }
439  } FOR_INV_FINISH();
440  /* if we have best match, return it. Otherwise, if we have one match
441  * on the loser match, return that, otehrwise null
442  */
443  if (spob2)
444  return spob2;
445  if (spob1 && nummatch == 1)
446  return spob1;
447  return NULL;
448 }
449 
469 int reflwall(mapstruct *m, int x, int y, object *sp_op) {
470  if (OUT_OF_REAL_MAP(m, x, y))
471  return 0;
472  FOR_MAP_PREPARE(m, x, y, op)
474  && (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10)))
475  return 1;
476  FOR_MAP_FINISH();
477  return 0;
478 }
479 
493 int cast_create_obj(object *op, object *new_op, int dir) {
494  mapstruct *m;
495  int16_t sx, sy;
496 
497  if (dir
498  && ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP)
499  || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) {
501  "Something is in the way. You cast it at your feet.");
502  dir = 0;
503  }
504  if (dir == 0)
505  object_insert_in_map_at(new_op, op->map, op, INS_BELOW_ORIGINATOR, op->x+freearr_x[dir], op->y+freearr_y[dir]);
506  else
507  object_insert_in_map_at(new_op, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
508  return dir;
509 }
510 
529 int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop) {
530  int mflags;
531  mapstruct *mp;
532 
533  mp = m;
534  mflags = get_map_flags(m, &mp, x, y, &x, &y);
535 
536  if (mflags&P_OUT_OF_MAP)
537  return 0;
538 
540  return 0;
541 
542  FOR_MAP_PREPARE(mp, x, y, tmp) {
543  /* If there is a counterspell on the space, and this
544  * object is using magic, don't progess. I believe we could
545  * leave this out and let in progress, and other areas of the code
546  * will then remove it, but that would seem to to use more
547  * resources, and may not work as well if a player is standing
548  * on top of a counterwall spell (may hit the player before being
549  * removed.) On the other hand, it may be more dramatic for the
550  * spell to actually hit the counterwall and be sucked up.
551  */
552  if ((tmp->attacktype&AT_COUNTERSPELL)
553  && (tmp->type != PLAYER)
555  && (tmp->type != WEAPON)
556  && (tmp->type != BOW)
557  && (tmp->type != ARROW)
558  && (tmp->type != GOLEM)
559  && (immune_stop&AT_MAGIC))
560  return 0;
561 
562  /* This is to prevent 'out of control' spells. Basically, this
563  * limits one spell effect per space per spell. This is definitely
564  * needed for performance reasons, and just for playability I believe.
565  * there are no such things as multispaced spells right now, so
566  * we don't need to worry about the head.
567  * We only need to go down this path is maxhp is set on both objects -
568  * otherwise, no reason to check. But if we do check, we need to
569  * do some extra work, looking in the spell_tags[] of each object,
570  * if they have it set.
571  */
572  if (tmp->type == op->type
573  && tmp->subtype == op->subtype
574  && tmp->stats.maxhp
575  && op->stats.maxhp) {
576  if ((tmp->stats.maxhp == op->stats.maxhp)
577  || (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp))
578  || (op->spell_tags && OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp))) {
580  return 0;
581  }
582 
583  /* if both objects have spell tags, then if the two tags entries
584  * from either match, that also counts. Need to check
585  * the spell_tags, because 0 values are allowed to match
586  */
587  if (op->spell_tags && tmp->spell_tags) {
588  int i;
589 
590  for (i = 0; i < SPELL_TAG_SIZE; i++) {
591  if (op->spell_tags[i] &&
592  op->spell_tags[i] == tmp->spell_tags[i]) {
594  return 0;
595  }
596  }
597  }
598  }
599  /* Perhaps we should also put checks in for no magic and unholy
600  * ground to prevent it from moving along?
601  */
602  } FOR_MAP_FINISH();
603  /* If it passes the above tests, it must be OK */
604  return 1;
605 }
606 
628 int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell) {
629  object *tmp;
630  int mflags;
631  mapstruct *m;
632 
633  if (dir < 0 || dir > 8) {
634  LOG(llevError, "Invalid direction %d in fire_arch_from_position for %s\n", dir, spell->name);
635  dir = RANDOM() % 8 + 1;
636  }
637 
638  if (spell->other_arch == NULL)
639  return 0;
640 
641  if (spell->type != SPELL)
642  LOG(llevError, "Unexpected object type %d in fire_arch_from_position for %s\n", spell->type, spell->name);
643 
644  m = op->map;
645  mflags = get_map_flags(m, &m, x, y, &x, &y);
646  if (mflags&P_OUT_OF_MAP) {
647  return 0;
648  }
649 
650  tmp = arch_to_object(spell->other_arch);
651  if (tmp == NULL)
652  return 0;
653 
654  mflags = get_map_flags(m, &tmp->map, x, y, &tmp->x, &tmp->y);
655  if (mflags&P_OUT_OF_MAP) {
657  return 0;
658  }
659 
660  if (spell->subtype == SP_BULLET) {
661  /* peterm: level dependency for bolts */
662  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
663  tmp->attacktype = spell->attacktype;
664  if (spell->slaying)
665  tmp->slaying = add_refcount(spell->slaying);
666 
667  tmp->range = 50;
668 
669  /* Need to store duration/range for the ball to use */
670  tmp->stats.hp = spell->duration+SP_level_duration_adjust(caster, spell);
671  tmp->stats.maxhp = spell->range+SP_level_range_adjust(caster, spell);
672  tmp->dam_modifier = spell->stats.food+SP_level_dam_adjust(caster, spell);
673 
674  tmp->direction = dir;
676 
678  } else {
679  if (spell->subtype != SP_MAGIC_MISSILE && spell->subtype != SP_MOVING_BALL)
680  LOG(llevError, "Unexpected object subtype %d in fire_arch_from_position for %s\n", spell->subtype, spell->name);
681 
682  /*
683  * Things like firewalls and such can fire even if blocked, since the
684  * origin is themselves which block things...
685  * This fixes bug #3536508.
686  */
687  if (caster->type == PLAYER && OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
689  "You can't cast the spell on top of a wall!");
691  return 0;
692  }
693 
694  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
695  tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell);
696  /* code in time.c uses food for some things, duration for others */
697  tmp->stats.food = tmp->duration;
698  tmp->range = spell->range+SP_level_range_adjust(caster, spell);
699  tmp->attacktype = spell->attacktype;
700  if (object_get_owner(op) != NULL)
702  else
704  tmp->level = caster_level(caster, spell);
705  }
706 
707  tmp->direction = dir;
708  set_spell_skill(op, caster, spell, tmp);
709 
710  if (spell->subtype == SP_BULLET) {
711  if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
712  if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) {
714  return 0;
715  }
716  tmp->direction = absdir(tmp->direction+4);
717  x += DIRX(tmp);
718  y += DIRY(tmp);
719  mflags = get_map_flags(m, &m, x, y, &x, &y);
720  if (mflags&P_OUT_OF_MAP) {
722  return 0;
723  }
724  tmp->x = x;
725  tmp->y = y;
726  tmp->map = m;
727  }
728 
729  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
730  if (tmp != NULL)
731  check_bullet(tmp);
732  } else /*if (spell->subtype == SP_MAGIC_MISSILE || spell->subtype == SP_MOVING_BALL) */ {
733  /* needed for AT_HOLYWORD, AT_GODPOWER stuff */
734  if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) {
735  if (!tailor_god_spell(tmp, op))
736  return 0;
737  }
739 
740  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
741  if (tmp != NULL)
742  ob_process(tmp);
743  }
744 
745  return 1;
746 }
747 
748 /*****************************************************************************
749  *
750  * Code related to rods - perhaps better located in another file?
751  *
752  ****************************************************************************/
753 
760 void regenerate_rod(object *rod) {
761  if (rod->stats.hp < rod->stats.maxhp) {
762  rod->stats.hp += 1+rod->stats.maxhp/10;
763 
764  if (rod->stats.hp > rod->stats.maxhp)
765  rod->stats.hp = rod->stats.maxhp;
766  }
767 }
768 
775 void drain_rod_charge(object *rod) {
776  rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
777 }
778 
785 void drain_wand_charge(object *wand) {
786  assert(wand->type == WAND);
787 
788  if (!(--wand->stats.food)) {
789  object *tmp;
790  if (wand->arch) {
791  CLEAR_FLAG(wand, FLAG_ANIMATE);
792  wand->face = wand->arch->clone.face;
793  wand->speed = 0;
794  object_update_speed(wand);
795  }
797  if (tmp)
798  esrv_update_item(UPD_ANIM, tmp, wand);
799  }
800 }
801 
812 object *find_target_for_friendly_spell(object *op, int dir) {
813  object *tmp;
814  mapstruct *m;
815  int16_t x, y;
816  int mflags;
817 
818  /* I don't really get this block - if op isn't a player or rune,
819  * we then make the owner of this object the target.
820  * The owner could very well be no where near op.
821  */
822  if (op->type != PLAYER && op->type != RUNE) {
824  /* If the owner does not exist, or is not a monster, than apply the spell
825  * to the caster.
826  */
827  if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER))
828  tmp = op;
829  } else {
830  m = op->map;
831  x = op->x+freearr_x[dir];
832  y = op->y+freearr_y[dir];
833 
834  mflags = get_map_flags(m, &m, x, y, &x, &y);
835 
836  if (mflags&P_OUT_OF_MAP)
837  tmp = NULL;
838  else {
839  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
840  if (tmp->type == PLAYER)
841  break;
842  }
843  }
844  }
845  /* didn't find a player there, look in current square for a player */
846  if (tmp == NULL) {
847  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
848  if (tmp->type == PLAYER)
849  return tmp;
850  /* Don't forget to browse inside transports ! - gros 2006/07/25 */
851  if (tmp->type == TRANSPORT) {
852  object *inv;
853 
854  for (inv = tmp->inv; inv; inv = inv->below) {
855  if ((inv->type == PLAYER) && (op == inv))
856  return inv;
857  }
858  }
859  } FOR_MAP_FINISH();
860  }
861  return tmp;
862 }
863 
864 
865 
886 int spell_find_dir(mapstruct *m, int x, int y, object *exclude) {
887  int i;
888  int16_t nx, ny;
889  int owner_type = 0, mflags;
890  object *tmp;
891  mapstruct *mp;
892  int dirs[SIZEOFFREE];
893 
894  if (exclude != NULL) {
895  exclude = HEAD(exclude);
896  owner_type = exclude->type;
897  }
898 
899  get_search_arr(dirs);
900  for (i = 1; i < SIZEOFFREE; i++) {
901  nx = x+freearr_x[dirs[i]];
902  ny = y+freearr_y[dirs[i]];
903  mp = m;
904  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
905  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
906  continue;
907 
908  for (tmp = GET_MAP_OB(mp, nx, ny); tmp != NULL; tmp = tmp->above) {
909  object *head;
910 
911  head = HEAD(tmp);
912  if ((owner_type != PLAYER || QUERY_FLAG(head, FLAG_MONSTER) || QUERY_FLAG(head, FLAG_GENERATOR) || (head->type == PLAYER && op_on_battleground(head, NULL, NULL, NULL)))
913  && (owner_type == PLAYER || head->type == PLAYER)
914  && head != exclude
915  && can_see_monsterP(m, x, y, dirs[i])) {
916  return freedir[dirs[i]];
917  }
918  }
919  }
920  return -1; /* flag for "keep going the way you were" */
921 }
922 
923 
924 
938 static int put_a_monster(object *op, const char *monstername) {
939  object *tmp, *head = NULL, *prev = NULL;
940  archetype *at;
941  int dir;
942 
943  /* Handle cases where we are passed a bogus mosntername */
944  at = try_find_archetype(monstername);
945  if (at == NULL)
946  return 0;
947 
948  /* find a free square nearby
949  * first we check the closest square for free squares
950  */
951 
952  dir = object_find_first_free_spot(&at->clone, op->map, op->x, op->y);
953  if (dir != -1) {
954  /* This is basically grabbed for generate monster. Fixed 971225 to
955  * insert multipart monsters properly
956  */
957  while (at != NULL) {
958  tmp = arch_to_object(at);
959  tmp->x = op->x+freearr_x[dir]+at->clone.x;
960  tmp->y = op->y+freearr_y[dir]+at->clone.y;
961  tmp->map = op->map;
962  if (head) {
963  tmp->head = head;
964  prev->more = tmp;
965  }
966  if (!head)
967  head = tmp;
968  prev = tmp;
969  at = at->more;
970  }
971 
972  if (head->randomitems)
973  create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
974 
975  object_insert_in_map_at(head, op->map, op, 0, op->x, op->y);
976 
977  /* thought it'd be cool to insert a burnout, too.*/
978  tmp = create_archetype("burnout");
979  object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
980  return 1;
981  } else {
982  return 0;
983  }
984 }
985 
1004 int summon_hostile_monsters(object *op, int n, const char *monstername) {
1005  int i, put = 0;
1006 
1007  for (i = 0; i < n; i++)
1008  put += put_a_monster(op, monstername);
1009 
1010  return put;
1011 }
1012 
1013 
1032 void shuffle_attack(object *op) {
1033  int i;
1034 
1035  i = rndm(0, 21);
1036  op->attacktype = ATTACKS[i].attacktype|AT_MAGIC;
1037  SET_ANIMATION(op, ATTACKS[i].face);
1038 }
1039 
1040 
1051 static void prayer_failure(object *op, int failure, int power) {
1052  const char *godname;
1053  object *tmp;
1054 
1055  godname = determine_god(op);
1056  if (!strcmp(godname, "none"))
1057  godname = "Your spirit";
1058 
1059  if (failure <= -20 && failure > -40) { /* wonder */
1061  "%s gives a sign to renew your faith.",
1062  godname);
1064  cast_cone(op, op, 0, tmp);
1066  } else if (failure <= -40 && failure > -60) { /* confusion */
1068  "Your diety touches your mind!");
1069  confuse_living(op, op, 99);
1070  } else if (failure <= -60 && failure > -150) { /* paralysis */
1072  "%s requires you to pray NOW. You comply, ignoring all else.",
1073  godname);
1074 
1075  paralyze_living(op, 99);
1076  } else if (failure <= -150) { /* blast the immediate area */
1079  "%s smites you!",
1080  godname);
1081  /* Put a cap on power - this is effectively cost of the spell minus
1082  * characters current grace. Thus, if spell costs 30 grace and
1083  * character has -100 grace, this is cast as a level 130 spell.
1084  * Things start to break in those cases.
1085  */
1086  cast_magic_storm(op, tmp, power > 50 ? 50 : power);
1087  }
1088 }
1089 
1102 void spell_failure(object *op, int failure, int power, object *skill) {
1103  object *tmp;
1104 
1106  return;
1107 
1108  if (failure <= -20 && failure > -40) { /* wonder */
1110  "Your spell causes an unexpected effect.");
1112  cast_cone(op, op, 0, tmp);
1114  } else if (failure <= -40 && failure > -60) { /* confusion */
1116  "Your magic recoils on you, making you confused!");
1117  confuse_living(op, op, 99);
1118  } else if (failure <= -60 && failure > -80) { /* paralysis */
1120  "Your magic stuns you!");
1121  paralyze_living(op, 99);
1122  } else if (failure <= -80) { /* blast the immediate area */
1123  object *tmp;
1124 
1125  /* Safety check to make sure we don't get any mana storms in scorn */
1126  if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) {
1128  "The magic warps and you are turned inside out!");
1129  hit_player(op, 9998, op, AT_INTERNAL, 1);
1130  } else {
1132  "You lose control of the mana! The uncontrolled magic blasts you!");
1134  tmp->level = skill->level;
1135 
1136  /* increase the area of destruction a little for more powerful spells */
1137  tmp->range += isqrt(power);
1138 
1139  if (power > 25)
1140  tmp->stats.dam = 25+isqrt(power);
1141  else
1142  tmp->stats.dam = power; /* nasty recoils! */
1143 
1144  tmp->stats.maxhp = tmp->count;
1145  if (tmp->stats.maxhp == 0)
1146  tmp->stats.maxhp = 1;
1147  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
1148  }
1149  }
1150 }
1151 
1160 static int can_be_transmuted_to_flower(object *op) {
1161  if (op->invisible)
1162  return 0;
1163 
1164  if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON)
1165  return 1;
1166 
1167  return 0;
1168 }
1169 
1182 static void transmute_item_to_flower(object *op) {
1183  object *force;
1184  object *item;
1185  object *flower;
1186  object *first = NULL;
1187  int count = 0;
1188  char name[HUGE_BUF];
1189 
1192  if (!first)
1193  first = item;
1194  count++;
1195  }
1196  FOR_INV_FINISH();
1197 
1198  if (count == 0)
1199  return;
1200 
1201  count = rndm(0, count-1);
1202  for (item = first; item; item = item->below) {
1204  count--;
1205  if (count < 0)
1206  break;
1207  }
1208  }
1209 
1210  if (!item)
1211  return;
1212 
1214  force->duration = 100+rndm(0, 10)*100;
1215  force->subtype = FORCE_TRANSFORMED_ITEM;
1216  force->speed = 1;
1218 
1219  flower = create_archetype("flowers_permanent");
1220 
1224  flower->weight = item->nrof ? ((int32_t)item->nrof)*item->weight : item->weight;
1225  item->weight = 0;
1226  esrv_del_item(op->contr, item);
1228 
1232  "Your %s turns to a flower!",
1233  name);
1234 
1235  object_insert_in_ob(force, flower);
1236  flower = object_insert_in_ob(flower, op);
1237  esrv_send_item(op, flower);
1238 }
1239 
1250 static void swap_random_stats(object *op) {
1251  object *force;
1252  int first, second;
1253 
1254  first = RANDOM()%NUM_STATS;
1255  second = RANDOM()%(NUM_STATS-1);
1256  if (second >= first)
1257  second++;
1258 
1261  "You suddenly feel really weird!");
1262 
1264  force->duration = 100+rndm(0, 10)*100;
1265  force->speed = 1;
1267  set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second));
1268  set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first));
1271  change_abil(op, force);
1272  fix_object(op);
1273 }
1274 
1285 static void handle_spell_confusion(object *op) {
1286  switch (RANDOM()%2) {
1287  case 0:
1289  break;
1290 
1291  case 1:
1293  break;
1294  }
1295 }
1296 
1304 static int spell_consume_items(object *op, const object *spell_ob) {
1305  sstring requirements;
1306  char *copy;
1307  char *ingredients[10];
1308  object *found[10];
1309  int count, i;
1310  uint32_t nrof[10];
1311  char name_ob[MAX_BUF];
1312  const char *name2;
1313 
1314  if (op->type != PLAYER)
1315  return 1;
1316 
1317  requirements = object_get_value(spell_ob, "casting_requirements");
1318  if (!requirements)
1319  /* no special requirements */
1320  return 1;
1321 
1322  /* find items */
1323  copy = strdup_local(requirements);
1324  count = split_string(copy, ingredients, 10, ',');
1325 
1326  /* first pass, find items */
1327  for (i = 0; i < count; i++) {
1328  nrof[i] = 0;
1329  found[i] = NULL;
1330  while (isdigit(*ingredients[i])) {
1331  nrof[i] = 10*nrof[i]+(*(ingredients[i])-'0');
1332  ingredients[i]++;
1333  }
1334  if (nrof[i] == 0)
1335  nrof[i] = 1;
1336  while (*ingredients[i] == ' ')
1337  ingredients[i]++;
1338 
1339  /* now find item in op's inv */
1341 
1342  if (check->title == NULL)
1343  name2 = check->name;
1344  else {
1345  snprintf(name_ob, sizeof(name_ob), "%s %s", check->name, check->title);
1346  name2 = name_ob;
1347  }
1348 
1349  if (strcmp(name2, ingredients[i]) == 0) {
1350  found[i] = check;
1351  break;
1352  }
1353  } FOR_INV_FINISH();
1354 
1355  if (found[i] == NULL) {
1358  "Casting this spell requires %s, but you don't have any.",
1359  ingredients[i]);
1360  free(copy);
1361  return 0;
1362  }
1363 
1364  if (found[i]->nrof < nrof[i]) {
1367  "Casting this spell requires %d %s, but you only have %d.",
1368  nrof[i], found[i]->name_pl, found[i]->nrof);
1369  free(copy);
1370  return 0;
1371  }
1372  }
1373 
1374  free(copy);
1375 
1376  /* ok, found ingredients, remove'em */
1377  for (i = 0; i < count; i++) {
1378  object_decrease_nrof(found[i], nrof[i]);
1379  }
1380 
1381  /* all right, spell can be cast */
1382  return 1;
1383 }
1384 
1420 int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
1421  const char *godname;
1422  int success = 0, mflags, cast_level = 0;
1423  rangetype old_shoottype;
1424  object *skill = NULL;
1425  int confusion_effect = 0;
1426  float cost_multiplier = 1.0f;
1427 
1428  old_shoottype = op->contr ? op->contr->shoottype : range_none;
1429 
1430  if (!spell_ob) {
1431  LOG(llevError, "cast_spell: null spell object passed\n");
1432  return 0;
1433  }
1434  godname = determine_god(op);
1435  if (!strcmp(godname, "none"))
1436  godname = "A random spirit";
1437 
1438  /* the caller should set caster to op if appropriate */
1439  if (!caster) {
1440  LOG(llevError, "cast_spell: null caster object passed\n");
1441  return 0;
1442  }
1443  if (spell_ob->anim_suffix)
1444  apply_anim_suffix(caster, spell_ob->anim_suffix);
1445 
1446  /* Handle some random effect if confused. */
1447  if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) {
1448  if (rndm(0, 5) < 4) {
1449  spell_ob = find_random_spell_in_ob(op, NULL);
1452  "In your confused state, you're not sure of what you cast!");
1453  } else
1454  /* We fall through to deplate sp/gr, and do some checks. */
1455  confusion_effect = 1;
1456  }
1457 
1458  /* if caster is a spell casting object, this normally shouldn't be
1459  * an issue, because they don't have any spellpaths set up.
1460  */
1461  if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) {
1463  "That spell path is denied to you.");
1464  return 0;
1465  }
1466 
1467 
1468  mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL);
1469 
1470  /* See if we can cast a spell here. If the caster and op are
1471  * not alive, then this would mean that the mapmaker put the
1472  * objects on the space - presume that they know what they are
1473  * doing.
1474  */
1475  if (spell_ob->type == SPELL
1476  && caster->type != POTION
1477  && !QUERY_FLAG(op, FLAG_WIZCAST)
1478  && (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE))
1479  && !QUERY_FLAG(op, FLAG_MONSTER)
1480  && (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) {
1481  if (op->type != PLAYER)
1482  return 0;
1483 
1485 
1486  if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace)
1488  "This ground is unholy! %s ignores you.",
1489  godname);
1490  else
1491  switch (op->contr->shoottype) {
1492  case range_magic:
1494  "Something blocks your spellcasting.");
1495  break;
1496 
1497  case range_misc:
1499  "Something blocks the magic of your item.");
1500  break;
1501  case range_golem:
1503  "Something blocks the magic of your scroll.");
1504  break;
1505 
1506  default:
1507  break;
1508  }
1509  return 0;
1510  }
1511 
1512  /* if it is a player casting the spell, and they are really casting it
1513  * (vs it coming from a wand, scroll, or whatever else), do some
1514  * checks. We let monsters do special things - eg, they
1515  * don't need the skill, bypass level checks, etc. The monster function
1516  * should take care of that.
1517  * Remove the wiz check here and move it further down - some spells
1518  * need to have the right skill pointer passed, so we need to
1519  * at least process that code.
1520  */
1521  if (op->type == PLAYER && op == caster) {
1522  cast_level = caster_level(caster, spell_ob);
1523  if (spell_ob->skill) {
1524  skill = find_skill_by_name(op, spell_ob->skill);
1525  if (!skill) {
1528  "You need the skill %s to cast %s.",
1529  spell_ob->skill, spell_ob->name);
1530  return 0;
1531  }
1532  if (min_casting_level(op, spell_ob) > cast_level && !QUERY_FLAG(op, FLAG_WIZ)) {
1534  "You lack enough skill to cast that spell.");
1535  return 0;
1536  }
1537  }
1538  /* If the caster is the wiz, they don't ever fail, and don't have
1539  * to have sufficient grace/mana.
1540  */
1541  if (!QUERY_FLAG(op, FLAG_WIZ)) {
1542  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA)
1543  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) > op->stats.sp) {
1545  "You don't have enough mana.");
1546  return 0;
1547  }
1548  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)
1549  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) > op->stats.grace) {
1550  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) {
1553  "%s grants your prayer, though you are unworthy.",
1554  godname);
1555  } else {
1556  prayer_failure(op, op->stats.grace, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)-op->stats.grace);
1559  "%s ignores your prayer.",
1560  godname);
1561  return 0;
1562  }
1563  }
1564 
1565  /* player/monster is trying to cast the spell. might fumble it */
1566  if (spell_ob->stats.grace
1567  && random_roll(0, 99, op, PREFER_HIGH) < (get_cleric_chance(op->stats.Wis) * spell_ob->level/MAX(1, op->level))) {
1568  play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell_ob, 0, "fumble");
1570  "You fumble the spell.");
1571  if (settings.casting_time == TRUE) {
1572  op->casting_time = -1;
1573  }
1574  op->stats.grace -= random_roll(1, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
1575  object *bungle = create_archetype(ARCH_SPELL_BUNGLE);
1576  if (bungle->arch != NULL) {
1577  cast_create_obj(op, bungle, 0);
1578  } else {
1579  LOG(llevError, "cast_spell: Could not create spell_bungle arch\n");
1580  }
1581  return 0;
1582  } else if (spell_ob->stats.sp) {
1583  int failure = random_roll(0, 199, op, PREFER_HIGH)-op->contr->encumbrance+op->level-spell_ob->level+35;
1584 
1585  if (failure < 0) {
1588  "You bungle the spell because you have too much heavy equipment in use.");
1590  spell_failure(op, failure, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), skill);
1591  op->contr->shoottype = old_shoottype;
1592  op->stats.sp -= random_roll(0, SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA), op, PREFER_LOW);
1593  object *bungle = create_archetype(ARCH_SPELL_BUNGLE);
1594  if (bungle->arch != NULL) {
1595  cast_create_obj(op, bungle, 0);
1596  } else {
1597  LOG(llevError, "cast_spell: Could not create spell_bungle arch\n");
1598  }
1599  return 0;
1600  }
1601  }
1602 
1603  /* ensure the potentially required items are eaten */
1604  if (!spell_consume_items(op, spell_ob))
1605  /* already warned by the function */
1606  return 0;
1607  }
1608  }
1609 
1610  if (caster == op && caster->type ==PLAYER && settings.casting_time == TRUE && spell_ob->type == SPELL) {
1611  if (op->casting_time == -1) { /* begin the casting */
1612  op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob);
1613  op->spell = spell_ob;
1614  /* put the stringarg into the object struct so that when the
1615  * spell is actually cast, it knows about the stringarg.
1616  * necessary for the invoke command spells.
1617  */
1618  if (stringarg) {
1619  op->spellarg = strdup_local(stringarg);
1620  } else
1621  op->spellarg = NULL;
1622  return 0;
1623  } else if (op->casting_time != 0) {
1624  if (op->type == PLAYER)
1626  "You are casting!");
1627  return 0;
1628  } else { /* casting_time == 0 */
1629  op->casting_time = -1;
1630  spell_ob = op->spell;
1631  stringarg = op->spellarg;
1632  }
1633  } else {
1634  if (!QUERY_FLAG(caster, FLAG_WIZ)) {
1635  /* Take into account how long it takes to cast the spell.
1636  * if the player is casting it, then we use the time in
1637  * the spell object. If it is a spell object, have it
1638  * take two ticks. Things that cast spells on the players
1639  * behalf (eg, altars, and whatever else) shouldn't cost
1640  * the player any time.
1641  * Ignore casting time for firewalls
1642  */
1643  if (caster == op && caster->type != FIREWALL) {
1644  op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1645  /* Other portions of the code may also decrement the speed of the player, so
1646  * put a lower limit so that the player isn't stuck here too long
1647  */
1648  if ((spell_ob->casting_time > 0)
1649  && op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed))
1650  op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1651  } else if (caster->type == WAND
1652  || caster->type == ROD
1653  || caster->type == POTION
1654  || caster->type == SCROLL) {
1655  op->speed_left -= 2*FABS(op->speed);
1656  }
1657  }
1658  }
1659 
1660  /* We want to try to find the skill to properly credit exp.
1661  * for spell casting objects, the exp goes to the skill the casting
1662  * object requires.
1663  */
1664  if (op != caster && !skill && caster->skill && !QUERY_FLAG(op, FLAG_MONSTER)) {
1665  skill = find_skill_by_name(op, caster->skill);
1666  if (!skill) {
1667  char name[MAX_BUF];
1668 
1669  query_name(caster, name, MAX_BUF);
1672  "You lack the skill %s to use the %s",
1673  caster->skill, name);
1674  return 0;
1675  }
1676  change_skill(op, skill, 0); /* needed for proper exp credit */
1677  }
1678 
1679  /* Need to get proper ownership for spells cast via runes - these are not
1680  * the normal 'rune of fire', but rather the magic runes that let the player
1681  * put some other spell into the rune (glyph, firetrap, magic rune, etc)
1682  */
1683  if (caster->type == RUNE) {
1684  object *owner = object_get_owner(caster);
1685 
1686  if (owner)
1687  skill = find_skill_by_name(owner, caster->skill);
1688  }
1689 
1690  if (confusion_effect) {
1691  /* If we get here, the confusion effect was 'random effect', so do it and bail out. */
1694  "In your confused state, you can't control the magic!");
1696 
1697  /* Still subtract full grace and sp. */
1698  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1699  op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE);
1700  op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA);
1701  }
1702 
1703  return 0;
1704  }
1705 
1706  play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name);
1707 
1708  switch (spell_ob->subtype) {
1709  /* The order of case statements is same as the order they show up
1710  * in in spells.h.
1711  */
1712  case SP_RAISE_DEAD:
1713  success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg);
1714  break;
1715 
1716  case SP_RUNE:
1717  success = write_rune(op, caster, spell_ob, dir, stringarg);
1718  break;
1719 
1720  case SP_MAKE_MARK:
1721  success = write_mark(op, spell_ob, stringarg);
1722  break;
1723 
1724  case SP_BOLT:
1725  success = fire_bolt(op, caster, dir, spell_ob);
1726  break;
1727 
1728  case SP_BULLET:
1729  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1730  break;
1731 
1732  case SP_CONE:
1733  success = cast_cone(op, caster, dir, spell_ob);
1734  break;
1735 
1736  case SP_BOMB:
1737  success = create_bomb(op, caster, dir, spell_ob);
1738  break;
1739 
1740  case SP_WONDER:
1741  success = cast_wonder(op, caster, dir, spell_ob);
1742  break;
1743 
1744  case SP_SMITE:
1745  success = cast_smite_spell(op, caster, dir, spell_ob);
1746  break;
1747 
1748  case SP_MAGIC_MISSILE:
1749  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1750  break;
1751 
1752  case SP_SUMMON_GOLEM:
1753  success = pets_summon_golem(op, caster, dir, spell_ob);
1754  if (success || op->contr == NULL)
1755  old_shoottype = range_golem;
1756  else
1757  /*
1758  * if the spell failed (something in the way for instance),
1759  * don't change the range so the player can try easily after that
1760  */
1761  old_shoottype = op->contr->shoottype;
1762  break;
1763 
1764  case SP_DIMENSION_DOOR:
1765  /* dimension door needs the actual caster, because that is what is
1766  * moved.
1767  */
1768  success = dimension_door(op, caster, spell_ob, dir);
1769  break;
1770 
1771  case SP_MAGIC_MAPPING:
1772  if (op->type == PLAYER) {
1773  spell_effect(spell_ob, op->x, op->y, op->map, op);
1774  draw_magic_map(op);
1775  success = 1;
1776  } else
1777  success = 0;
1778  break;
1779 
1780  case SP_MAGIC_WALL:
1781  success = magic_wall(op, caster, dir, spell_ob);
1782  break;
1783 
1784  case SP_DESTRUCTION:
1785  success = cast_destruction(op, caster, spell_ob);
1786  break;
1787 
1788  case SP_PERCEIVE_SELF:
1789  success = perceive_self(op);
1790  break;
1791 
1792  case SP_WORD_OF_RECALL:
1793  success = cast_word_of_recall(op, caster, spell_ob);
1794  break;
1795 
1796  case SP_INVISIBLE:
1797  success = cast_invisible(op, caster, spell_ob);
1798  break;
1799 
1800  case SP_PROBE:
1801  if (op != caster)
1802  cast_level = caster->level;
1803  else
1804  cast_level = skill != NULL ? skill->level : op->level;
1805  success = probe(op, caster, spell_ob, dir, cast_level);
1806  break;
1807 
1808  case SP_HEALING:
1809  success = cast_heal(op, caster, spell_ob, dir);
1810  break;
1811 
1812  case SP_CREATE_FOOD:
1813  success = cast_create_food(op, caster, spell_ob, dir, stringarg);
1814  break;
1815 
1816  case SP_EARTH_TO_DUST:
1817  success = cast_earth_to_dust(op, caster, spell_ob);
1818  break;
1819 
1820  case SP_CHANGE_ABILITY:
1821  success = cast_change_ability(op, caster, spell_ob, dir, 0);
1822  break;
1823 
1824  case SP_BLESS:
1825  success = cast_bless(op, caster, spell_ob, dir);
1826  break;
1827 
1828  case SP_CURSE:
1829  success = cast_curse(op, caster, spell_ob, dir);
1830  break;
1831 
1832  case SP_SUMMON_MONSTER:
1833  success = pets_summon_object(op, caster, spell_ob, dir, stringarg);
1834  if (!success) {
1835  cost_multiplier = 0.0f;
1836  }
1837  break;
1838 
1839  case SP_CHARGING:
1840  success = recharge(op, caster, spell_ob);
1841  break;
1842 
1843  case SP_POLYMORPH:
1844 #if 0
1845  /* Not great, but at least provide feedback so if players do have
1846  * polymorph (ie, find it as a preset item or left over from before
1847  * it was disabled), they get some feedback.
1848  */
1850  "The spell fizzles");
1851  success = 0;
1852 #else
1853  success = cast_polymorph(op, caster, spell_ob, dir);
1854 #endif
1855  break;
1856 
1857  case SP_ALCHEMY:
1858  success = alchemy(op, caster, spell_ob);
1859  break;
1860 
1861  case SP_REMOVE_CURSE:
1862  success = remove_curse(op, caster, spell_ob);
1863  break;
1864 
1865  case SP_IDENTIFY:
1866  success = cast_identify(op, caster, spell_ob);
1867  break;
1868 
1869  case SP_DETECTION:
1870  success = cast_detection(op, caster, spell_ob);
1871  break;
1872 
1873  case SP_MOOD_CHANGE:
1874  success = mood_change(op, caster, spell_ob);
1875  break;
1876 
1877  case SP_MOVING_BALL:
1878  if (spell_ob->path_repelled
1879  && (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) {
1881  "You lack the proper attunement to cast %s",
1882  spell_ob->name);
1883  success = 0;
1884  } else
1885  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1886  break;
1887 
1888  case SP_SWARM:
1889  success = fire_swarm(op, caster, spell_ob, dir);
1890  break;
1891 
1892  case SP_CHANGE_MANA:
1893  success = cast_transfer(op, caster, spell_ob, dir);
1894  break;
1895 
1896  case SP_DISPEL_RUNE:
1897  /* in rune.c */
1898  success = dispel_rune(op, skill, dir);
1899  break;
1900 
1901  case SP_CREATE_MISSILE:
1902  success = cast_create_missile(op, caster, spell_ob, dir, stringarg);
1903  break;
1904 
1905  case SP_CONSECRATE:
1906  success = cast_consecrate(op, caster, spell_ob);
1907  break;
1908 
1909  case SP_ANIMATE_WEAPON:
1910  success = animate_weapon(op, caster, spell_ob, dir);
1911  old_shoottype = range_golem;
1912  break;
1913 
1914  case SP_LIGHT:
1915  success = cast_light(op, caster, spell_ob, dir);
1916  break;
1917 
1918  case SP_CHANGE_MAP_LIGHT:
1919  success = cast_change_map_lightlevel(op, spell_ob);
1920  break;
1921 
1922  case SP_FAERY_FIRE:
1923  success = cast_destruction(op, caster, spell_ob);
1924  break;
1925 
1926  case SP_CAUSE_DISEASE:
1927  success = cast_cause_disease(op, caster, spell_ob, dir);
1928  break;
1929 
1930  case SP_AURA:
1931  success = create_aura(op, caster, spell_ob);
1932  break;
1933 
1934  case SP_TOWN_PORTAL:
1935  success = cast_create_town_portal(op, caster, spell_ob);
1936  break;
1937 
1938  case SP_ITEM_CURSE_BLESS:
1939  success = cast_item_curse_or_curse(op, spell_ob);
1940  break;
1941 
1942  case SP_ELEM_SHIELD:
1943  success = create_aura(op, caster, spell_ob);
1944  break;
1945 
1946  default:
1947  LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1948  }
1949 
1950  /* Subtract grace and sp. */
1951  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1952  op->stats.grace -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE));
1953  op->stats.sp -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA));
1954  }
1955 
1956  /* FIXME - we need some better sound suppport */
1957  /* free the spell arg */
1958  if (settings.casting_time == TRUE) {
1959  free(stringarg);
1960  }
1961  /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1962  * to something like use_magic_item, but you really want to be able to fire
1963  * it again.
1964  */
1965  if (op->contr)
1966  op->contr->shoottype = old_shoottype;
1967 
1968  return success;
1969 }
1970 
1977 void store_spell_expiry(object *spell) {
1978  /* Keep when to warn the player of expiration */
1979  char dur[10];
1980  int i = spell->duration/5;
1981 
1982  if (!i)
1983  i = 1;
1984  snprintf(dur, sizeof(dur), "%d", i);
1985  object_set_value(spell, "spell_expiry_warn_1", dur, 1);
1986  i = i/5;
1987  if (i > 0) {
1988  snprintf(dur, sizeof(dur), "%d", i);
1989  object_set_value(spell, "spell_expiry_warn_2", dur, 1);
1990  }
1991 }
1992 
2002 void check_spell_expiry(object *spell) {
2003  const char *key;
2004 
2005  if (!spell->env || !IS_PLAYER(spell->env))
2006  return;
2007 
2008  key = object_get_value(spell, "spell_expiry_warn_1");
2009  if (key != NULL) {
2010  if (spell->duration == atoi(key)) {
2012  "The effects of your %s are draining out.", spell->name);
2013  return;
2014  }
2015  }
2016  key = object_get_value(spell, "spell_expiry_warn_2");
2017  if (key != NULL) {
2018  if (spell->duration == atoi(key)) {
2020  "The effects of your %s are about to expire.", spell->name);
2021  return;
2022  }
2023  }
2024 }
2025 
2033 void rod_adjust(object *rod) {
2034  /*
2035  * Add 50 to both level an divisor to keep prices a little
2036  * more reasonable. Otherwise, a high level version of a
2037  * low level spell can be worth tons a money (eg, level 20
2038  * rod, level 2 spell = 10 time multiplier). This way, the
2039  * value are a bit more reasonable.
2040  */
2041  rod->value = rod->value*rod->inv->value*(rod->level+50)/(rod->inv->level+50);
2042 
2043  /*
2044  * Maxhp is used to denote how many 'charges' the rod holds
2045  * before.
2046  */
2047  rod->stats.maxhp = MAX(rod->stats.maxhp, 2)*SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
2048  rod->stats.hp = rod->stats.maxhp;
2049 }
Settings::casting_time
uint8_t casting_time
Definition: global.h:265
paralyze_living
void paralyze_living(object *op, int dam)
Definition: attack.c:2353
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
object_find_first_free_spot
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3570
PLAYER
@ PLAYER
Definition: object.h:107
SP_MAGIC_MISSILE
#define SP_MAGIC_MISSILE
Definition: spells.h:85
freedir
int freedir[SIZEOFFREE]
Definition: object.c:317
global.h
SP_HEALING
#define SP_HEALING
Definition: spells.h:95
add_refcount
sstring add_refcount(sstring str)
Definition: shstr.c:210
SP_BOLT
#define SP_BOLT
Definition: spells.h:78
Chaos_Attacks::attacktype
int attacktype
Definition: attack.h:126
liv::dam
int16_t dam
Definition: living.h:46
fire_bolt
int fire_bolt(object *op, object *caster, int dir, object *spob)
Definition: spell_attack.c:61
object_remove
void object_remove(object *op)
Definition: object.c:1819
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
obj::face
const Face * face
Definition: object.h:336
AT_MAGIC
#define AT_MAGIC
Definition: attack.h:77
FLAG_CONFUSED
#define FLAG_CONFUSED
Definition: define.h:311
BOW
@ BOW
Definition: object.h:118
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
SP_BOMB
#define SP_BOMB
Definition: spells.h:82
WAND
@ WAND
Definition: object.h:220
cast_consecrate
int cast_consecrate(object *op, object *caster, object *spell)
Definition: spell_effect.c:2990
cast_create_food
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: spell_effect.c:640
object_copy_owner
void object_copy_owner(object *op, object *clone)
Definition: object.c:897
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
fire_arch_from_position
int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell)
Definition: spell_util.c:628
FLAG_GENERATOR
#define FLAG_GENERATOR
Definition: define.h:248
strdup_local
#define strdup_local
Definition: compat.h:29
SP_ANIMATE_WEAPON
#define SP_ANIMATE_WEAPON
Definition: spells.h:115
diamondslots.x
x
Definition: diamondslots.py:15
SP_FAERY_FIRE
#define SP_FAERY_FIRE
Definition: spells.h:118
MSG_TYPE_SKILL
#define MSG_TYPE_SKILL
Definition: newclient.h:407
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
ARCH_SPELL_BUNGLE
#define ARCH_SPELL_BUNGLE
Definition: object.h:580
get_next_archetype
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:280
cast_identify
int cast_identify(object *op, object *caster, object *spell)
Definition: spell_effect.c:2508
get_cleric_chance
int get_cleric_chance(int stat)
Definition: living.c:2370
liv::maxgrace
int16_t maxgrace
Definition: living.h:45
dimension_door
int dimension_door(object *op, object *caster, object *spob, int dir)
Definition: spell_effect.c:1618
cast_change_map_lightlevel
int cast_change_map_lightlevel(object *op, object *spell)
Definition: spell_effect.c:3298
obj::value
int32_t value
Definition: object.h:355
perceive_self
int perceive_self(object *op)
Definition: spell_effect.c:1011
confuse_living
void confuse_living(object *op, object *hitter, int dam)
Definition: attack.c:2266
prayer_failure
static void prayer_failure(object *op, int failure, int power)
Definition: spell_util.c:1051
cast_destruction
int cast_destruction(object *op, object *caster, object *spell_ob)
Definition: spell_attack.c:707
op_on_battleground
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4213
find_target_for_friendly_spell
object * find_target_for_friendly_spell(object *op, int dir)
Definition: spell_util.c:812
FALSE
#define FALSE
Definition: compat.h:14
obj::path_attuned
uint32_t path_attuned
Definition: object.h:348
liv::maxhp
int16_t maxhp
Definition: living.h:41
tailor_god_spell
int tailor_god_spell(object *spellop, object *caster)
Definition: gods.c:1222
SP_level_dam_adjust
int SP_level_dam_adjust(const object *caster, const object *spob)
Definition: spell_util.c:286
OB_SPELL_TAG_MATCH
#define OB_SPELL_TAG_MATCH(op, count)
Definition: object.h:93
magic_wall
int magic_wall(object *op, object *caster, int dir, object *spell_ob)
Definition: spell_effect.c:1465
handle_spell_confusion
static void handle_spell_confusion(object *op)
Definition: spell_util.c:1285
check_bullet
void check_bullet(object *op)
Definition: spell_attack.c:217
summon_hostile_monsters
int summon_hostile_monsters(object *op, int n, const char *monstername)
Definition: spell_util.c:1004
spell_failure
void spell_failure(object *op, int failure, int power, object *skill)
Definition: spell_util.c:1102
PREFER_LOW
#define PREFER_LOW
Definition: define.h:564
WEAPON
@ WEAPON
Definition: object.h:119
cast_cause_disease
int cast_cause_disease(object *op, object *caster, object *spell, int dir)
Definition: spell_attack.c:1207
SP_CONSECRATE
#define SP_CONSECRATE
Definition: spells.h:114
LOOSE_MANA
#define LOOSE_MANA
Definition: spells.h:162
guildjoin.ob
ob
Definition: guildjoin.py:42
liv::hp
int16_t hp
Definition: living.h:40
MSG_TYPE_ATTRIBUTE
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:405
min_casting_level
int min_casting_level(const object *caster, const object *spell)
Definition: spell_util.c:163
range_none
@ range_none
Definition: player.h:30
SP_CONE
#define SP_CONE
Definition: spells.h:81
obj::range_modifier
uint8_t range_modifier
Definition: object.h:411
commongive.inv
inv
Definition: commongive.py:28
SET_ANIMATION
#define SET_ANIMATION(ob, newanim)
Definition: global.h:159
SP_CAUSE_DISEASE
#define SP_CAUSE_DISEASE
Definition: spells.h:119
play_sound_player_only
void play_sound_player_only(player *pl, int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:51
MSG_TYPE_VICTIM_SPELL
#define MSG_TYPE_VICTIM_SPELL
Definition: newclient.h:654
SP_level_range_adjust
int SP_level_range_adjust(const object *caster, const object *spob)
Definition: spell_util.c:337
cast_curse
int cast_curse(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_attack.c:800
play_sound_map
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:113
FLAG_WIZCAST
#define FLAG_WIZCAST
Definition: define.h:289
RUNE
@ RUNE
Definition: object.h:240
change_skill
int change_skill(object *who, object *new_skill, int flag)
Definition: skill_util.c:350
SP_CREATE_FOOD
#define SP_CREATE_FOOD
Definition: spells.h:96
cast_raise_dead_spell
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg)
Definition: resurrection.c:181
obj::path_denied
uint32_t path_denied
Definition: object.h:350
DIRX
#define DIRX(xyz)
Definition: define.h:463
Ice.tmp
int tmp
Definition: Ice.py:207
AT_INTERNAL
#define AT_INTERNAL
Definition: attack.h:99
write_mark
int write_mark(object *op, object *spell, const char *msg)
Definition: spell_effect.c:3416
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
cast_polymorph
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_effect.c:435
P_NO_MAGIC
#define P_NO_MAGIC
Definition: map.h:228
TRANSPORT
@ TRANSPORT
Definition: object.h:108
SP_CREATE_MISSILE
#define SP_CREATE_MISSILE
Definition: spells.h:113
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
SP_DISPEL_RUNE
#define SP_DISPEL_RUNE
Definition: spells.h:112
range_golem
@ range_golem
Definition: player.h:34
apply_manual
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:597
MSG_TYPE_SPELL_INFO
#define MSG_TYPE_SPELL_INFO
Definition: newclient.h:639
create_treasure
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:241
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
obj::randomitems
struct treasureliststruct * randomitems
Definition: object.h:390
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
isqrt
int isqrt(int n)
Definition: utils.c:569
MSG_TYPE_VICTIM
#define MSG_TYPE_VICTIM
Definition: newclient.h:415
ob_process
method_ret ob_process(object *op)
Definition: ob_methods.c:67
MAX
#define MAX(x, y)
Definition: compat.h:24
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:299
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:305
find_applied_skill_by_name
object * find_applied_skill_by_name(const object *op, const char *name)
Definition: living.c:1921
obj::duration_modifier
uint8_t duration_modifier
Definition: object.h:409
obj::duration
int16_t duration
Definition: object.h:408
cast_detection
int cast_detection(object *op, object *caster, object *spell)
Definition: spell_effect.c:2583
cast_magic_storm
void cast_magic_storm(object *op, object *tmp, int lvl)
Definition: spell_effect.c:46
find_random_spell_in_ob
object * find_random_spell_in_ob(object *ob, const char *skill)
Definition: spell_util.c:46
pets_summon_object
int pets_summon_object(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Definition: pets.c:872
reputation_trigger_connect.check
def check()
Definition: reputation_trigger_connect.py:18
cast_light
int cast_light(object *op, object *caster, object *spell, int dir)
Definition: spell_attack.c:1136
archt
Definition: object.h:469
settings
struct Settings settings
Definition: init.c:39
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
esrv_send_item
void esrv_send_item(object *pl, object *op)
Definition: main.c:355
SP_level_wc_adjust
int SP_level_wc_adjust(const object *caster, const object *spob)
Definition: spell_util.c:361
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4317
obj::slaying
sstring slaying
Definition: object.h:322
SP_SUMMON_MONSTER
#define SP_SUMMON_MONSTER
Definition: spells.h:101
m
static event_registration m
Definition: citylife.cpp:427
liv::maxsp
int16_t maxsp
Definition: living.h:43
can_be_transmuted_to_flower
static int can_be_transmuted_to_flower(object *op)
Definition: spell_util.c:1160
PATH_SP_MULT
#define PATH_SP_MULT(op, spell)
Definition: spells.h:36
PREFER_HIGH
#define PREFER_HIGH
Definition: define.h:563
cast_heal
int cast_heal(object *op, object *caster, object *spell, int dir)
Definition: spell_effect.c:1754
SP_BULLET
#define SP_BULLET
Definition: spells.h:79
disinfect.map
map
Definition: disinfect.py:4
dump_spells
void dump_spells(void)
Definition: spell_util.c:106
SP_ITEM_CURSE_BLESS
#define SP_ITEM_CURSE_BLESS
Definition: spells.h:123
SP_TOWN_PORTAL
#define SP_TOWN_PORTAL
Definition: spells.h:121
spell_find_dir
int spell_find_dir(mapstruct *m, int x, int y, object *exclude)
Definition: spell_util.c:886
obj::name
sstring name
Definition: object.h:314
determine_god
const char * determine_god(object *op)
Definition: gods.c:55
remove_curse
int remove_curse(object *op, object *caster, object *spell)
Definition: spell_effect.c:2409
mood_change
int mood_change(object *op, object *caster, object *spell)
Definition: spell_attack.c:904
SP_MOOD_CHANGE
#define SP_MOOD_CHANGE
Definition: spells.h:108
SPELL_WONDER
#define SPELL_WONDER
Definition: spells.h:163
MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN
#define MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN
Definition: newclient.h:555
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:585
POTION
@ POTION
Definition: object.h:111
GT_INVISIBLE
@ GT_INVISIBLE
Definition: treasure.h:32
object_update_turn_face
void object_update_turn_face(object *op)
Definition: object.c:1313
obj::path_repelled
uint32_t path_repelled
Definition: object.h:349
SP_DIMENSION_DOOR
#define SP_DIMENSION_DOOR
Definition: spells.h:87
HEAD
#define HEAD(op)
Definition: object.h:593
ATTACKS
EXTERN Chaos_Attacks ATTACKS[22]
Definition: attack.h:134
range_magic
@ range_magic
Definition: player.h:32
ROD
@ ROD
Definition: object.h:109
create_bomb
int create_bomb(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:447
shuffle_attack
void shuffle_attack(object *op)
Definition: spell_util.c:1032
SP_level_duration_adjust
int SP_level_duration_adjust(const object *caster, const object *spob)
Definition: spell_util.c:311
SPELL_GRACE
#define SPELL_GRACE
Definition: spells.h:59
MSG_TYPE_ITEM
#define MSG_TYPE_ITEM
Definition: newclient.h:412
query_short_name
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:510
reflwall
int reflwall(mapstruct *m, int x, int y, object *sp_op)
Definition: spell_util.c:469
AP_IGNORE_CURSE
#define AP_IGNORE_CURSE
Definition: define.h:582
SP_REMOVE_CURSE
#define SP_REMOVE_CURSE
Definition: spells.h:105
absdir
int absdir(int d)
Definition: object.c:3685
regenerate_rod
void regenerate_rod(object *rod)
Definition: spell_util.c:760
SPELL_HIGHEST
#define SPELL_HIGHEST
Definition: spells.h:60
obj::x
int16_t x
Definition: object.h:330
SP_SMITE
#define SP_SMITE
Definition: spells.h:84
FORCE_TRANSFORMED_ITEM
#define FORCE_TRANSFORMED_ITEM
Definition: spells.h:146
cast_create_town_portal
int cast_create_town_portal(object *op, object *caster, object *spell)
Definition: spell_effect.c:1250
fix_object
void fix_object(object *op)
Definition: living.c:1126
draw_magic_map
void draw_magic_map(object *pl)
Definition: info.c:474
SP_DETECTION
#define SP_DETECTION
Definition: spells.h:107
cast_spell
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1420
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:193
obj::other_arch
struct archt * other_arch
Definition: object.h:418
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
create_aura
int create_aura(object *op, object *caster, object *spell)
Definition: spell_effect.c:3330
archt::more
struct archt * more
Definition: object.h:472
INS_BELOW_ORIGINATOR
#define INS_BELOW_ORIGINATOR
Definition: object.h:570
GOLEM
@ GOLEM
Definition: object.h:145
MSG_TYPE_SKILL_MISSING
#define MSG_TYPE_SKILL_MISSING
Definition: newclient.h:587
object_set_value
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4470
sstring
const typedef char * sstring
Definition: global.h:40
rndm
int rndm(int min, int max)
Definition: utils.c:162
disinfect.count
int count
Definition: disinfect.py:7
obj::speed
float speed
Definition: object.h:332
cast_create_obj
int cast_create_obj(object *op, object *new_op, int dir)
Definition: spell_util.c:493
rangetype
rangetype
Definition: player.h:28
tag_t
uint32_t tag_t
Definition: object.h:12
obj::env
struct obj * env
Definition: object.h:296
drain_wand_charge
void drain_wand_charge(object *wand)
Definition: spell_util.c:785
sproto.h
liv::food
int32_t food
Definition: living.h:48
ARROW
@ ARROW
Definition: object.h:117
mapdef
Definition: map.h:317
MSG_TYPE_SPELL
#define MSG_TYPE_SPELL
Definition: newclient.h:411
SOUND_TYPE_SPELL
#define SOUND_TYPE_SPELL
Definition: newclient.h:334
cast_item_curse_or_curse
int cast_item_curse_or_curse(object *op, object *spell_ob)
Definition: spell_effect.c:2457
SP_EARTH_TO_DUST
#define SP_EARTH_TO_DUST
Definition: spells.h:97
SP_CHANGE_MAP_LIGHT
#define SP_CHANGE_MAP_LIGHT
Definition: spells.h:117
SP_DESTRUCTION
#define SP_DESTRUCTION
Definition: spells.h:90
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
object_set_owner
void object_set_owner(object *op, object *owner)
Definition: object.c:844
find_skill_by_name
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:202
SIZEOFFREE
#define SIZEOFFREE
Definition: define.h:155
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:250
MAX_BUF
#define MAX_BUF
Definition: define.h:35
split_string
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Definition: utils.c:483
cast_bless
int cast_bless(object *op, object *caster, object *spell_ob, int dir)
Definition: spell_effect.c:2057
Statistics::spell_suppressions
uint64_t spell_suppressions
Definition: global.h:353
esrv_del_item
void esrv_del_item(player *pl, object *ob)
Definition: main.c:382
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:281
check_spell_known
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:393
RANDOM
#define RANDOM()
Definition: define.h:644
IS_PLAYER
static bool IS_PLAYER(object *op)
Definition: object.h:595
statistics
struct Statistics statistics
Definition: init.c:100
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:195
SP_MAGIC_WALL
#define SP_MAGIC_WALL
Definition: spells.h:89
probe
int probe(object *op, object *caster, object *spell_ob, int dir, int level)
Definition: spell_effect.c:708
random_roll
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
transmute_item_to_flower
static void transmute_item_to_flower(object *op)
Definition: spell_util.c:1182
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
Settings::spell_failure_effects
uint8_t spell_failure_effects
Definition: global.h:264
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
obj::y
int16_t y
Definition: object.h:330
SP_INVISIBLE
#define SP_INVISIBLE
Definition: spells.h:93
OUT_OF_REAL_MAP
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:218
obj::arch
struct archt * arch
Definition: object.h:417
set_spell_skill
void set_spell_skill(object *op, object *caster, object *spob, object *dest)
Definition: spell_util.c:92
SP_PROBE
#define SP_PROBE
Definition: spells.h:94
range_misc
@ range_misc
Definition: player.h:33
sounds.h
SP_PERCEIVE_SELF
#define SP_PERCEIVE_SELF
Definition: spells.h:91
FLAG_REFL_SPELL
#define FLAG_REFL_SPELL
Definition: define.h:275
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
swap_random_stats
static void swap_random_stats(object *op)
Definition: spell_util.c:1250
obj::type
uint8_t type
Definition: object.h:343
check_spell_expiry
void check_spell_expiry(object *spell)
Definition: spell_util.c:2002
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
spells.h
obj::stats
living stats
Definition: object.h:373
MSG_TYPE_SKILL_FAILURE
#define MSG_TYPE_SKILL_FAILURE
Definition: newclient.h:590
alchemy
int alchemy(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:2309
animate_weapon
int animate_weapon(object *op, object *caster, object *spell, int dir)
Definition: spell_effect.c:3068
archt::clone
object clone
Definition: object.h:473
MSG_TYPE_SPELL_FAILURE
#define MSG_TYPE_SPELL_FAILURE
Definition: newclient.h:633
SP_CHANGE_ABILITY
#define SP_CHANGE_ABILITY
Definition: spells.h:98
Settings::spellpoint_level_depend
uint8_t spellpoint_level_depend
Definition: global.h:269
obj::weight
int32_t weight
Definition: object.h:370
apply_anim_suffix
void apply_anim_suffix(object *who, const char *suffix)
Definition: anim.c:149
PATH_TIME_MULT
#define PATH_TIME_MULT(op, spell)
Definition: spells.h:152
item
Definition: item.py:1
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
FIREWALL
@ FIREWALL
Definition: object.h:168
SP_MOVING_BALL
#define SP_MOVING_BALL
Definition: spells.h:109
SP_RUNE
#define SP_RUNE
Definition: spells.h:76
liv::grace
int16_t grace
Definition: living.h:44
give.op
op
Definition: give.py:33
ARCH_SPELL_BLOCKED
#define ARCH_SPELL_BLOCKED
Definition: object.h:579
MSG_TYPE_SPELL_ERROR
#define MSG_TYPE_SPELL_ERROR
Definition: newclient.h:636
GOD_POWER
#define GOD_POWER
Definition: spells.h:164
convert.dest
dest
Definition: convert.py:25
SP_POLYMORPH
#define SP_POLYMORPH
Definition: spells.h:103
pets_summon_golem
int pets_summon_golem(object *op, object *caster, int dir, object *spob)
Definition: pets.c:651
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:360
FLAG_REFLECTING
#define FLAG_REFLECTING
Definition: define.h:262
dispel_rune
int dispel_rune(object *op, object *skill, int dir)
Definition: rune.c:295
obj::casting_time
int16_t casting_time
Definition: object.h:407
hit_player
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Definition: attack.c:1860
diamondslots.y
y
Definition: diamondslots.py:16
spell_consume_items
static int spell_consume_items(object *op, const object *spell_ob)
Definition: spell_util.c:1304
ok_to_put_more
int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop)
Definition: spell_util.c:529
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
caster_level
int caster_level(const object *caster, const object *spell)
Definition: spell_util.c:193
AP_NOPRINT
#define AP_NOPRINT
Definition: define.h:585
set_attr_value
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:219
rod_adjust
void rod_adjust(object *rod)
Definition: spell_util.c:2033
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
cast_wonder
int cast_wonder(object *op, object *caster, int dir, object *spell_ob)
Definition: spell_effect.c:977
SP_MAGIC_MAPPING
#define SP_MAGIC_MAPPING
Definition: spells.h:88
object_update_speed
void object_update_speed(object *op)
Definition: object.c:1330
obj::subtype
uint8_t subtype
Definition: object.h:344
put_a_monster
static int put_a_monster(object *op, const char *monstername)
Definition: spell_util.c:938
obj::more
struct obj * more
Definition: object.h:298
SP_CHARGING
#define SP_CHARGING
Definition: spells.h:102
SP_CHANGE_MANA
#define SP_CHANGE_MANA
Definition: spells.h:111
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
castle_read.key
key
Definition: castle_read.py:64
make_face_from_files.int
int
Definition: make_face_from_files.py:26
FLAG_ANIMATE
#define FLAG_ANIMATE
Definition: define.h:242
AT_COUNTERSPELL
#define AT_COUNTERSPELL
Definition: attack.h:95
obj::skill
sstring skill
Definition: object.h:324
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
get_attr_value
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:314
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
SP_BLESS
#define SP_BLESS
Definition: spells.h:99
AT_GODPOWER
#define AT_GODPOWER
Definition: attack.h:96
fire_swarm
int fire_swarm(object *op, object *caster, object *spell, int dir)
Definition: spell_attack.c:1088
try_find_archetype
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:288
SP_RAISE_DEAD
#define SP_RAISE_DEAD
Definition: spells.h:75
cast_change_ability
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
Definition: spell_effect.c:1909
SP_MAKE_MARK
#define SP_MAKE_MARK
Definition: spells.h:77
SP_ALCHEMY
#define SP_ALCHEMY
Definition: spells.h:104
object_decrease_nrof
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2652
SP_SUMMON_GOLEM
#define SP_SUMMON_GOLEM
Definition: spells.h:86
OB_TYPE_MOVE_BLOCK
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:432
level
int level
Definition: readable.c:1608
P_NO_CLERIC
#define P_NO_CLERIC
Definition: map.h:239
MSG_TYPE_ITEM_CHANGE
#define MSG_TYPE_ITEM_CHANGE
Definition: newclient.h:644
archt::name
sstring name
Definition: object.h:470
cast_word_of_recall
int cast_word_of_recall(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:915
UPD_ANIM
#define UPD_ANIM
Definition: newclient.h:319
SP_WONDER
#define SP_WONDER
Definition: spells.h:83
SCROLL
@ SCROLL
Definition: object.h:221
write_rune
int write_rune(object *op, object *caster, object *spell, int dir, const char *runename)
Definition: rune.c:50
object_find_by_type_and_name
object * object_find_by_type_and_name(const object *who, int type, const char *name)
Definition: object.c:4079
say.item
dictionary item
Definition: say.py:149
obj::anim_suffix
sstring anim_suffix
Definition: object.h:319
AP_UNAPPLY
#define AP_UNAPPLY
Definition: define.h:575
obj::attacktype
uint32_t attacktype
Definition: object.h:347
cast_create_missile
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg)
Definition: spell_effect.c:503
cast_transfer
int cast_transfer(object *op, object *caster, object *spell, int dir)
Definition: spell_effect.c:2841
spell_effect
void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator)
Definition: spell_util.c:143
TRUE
#define TRUE
Definition: compat.h:11
AT_HOLYWORD
#define AT_HOLYWORD
Definition: attack.h:97
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:301
object_get_player_container
object * object_get_player_container(object *op)
Definition: object.c:611
get_search_arr
void get_search_arr(int *search_arr)
Definition: object.c:3613
change_abil
int change_abil(object *op, object *tmp)
Definition: living.c:395
SPELL
@ SPELL
Definition: object.h:214
SP_IDENTIFY
#define SP_IDENTIFY
Definition: spells.h:106
liv::sp
int16_t sp
Definition: living.h:42
cast_smite_spell
int cast_smite_spell(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:546
SPELL_TAG_SIZE
#define SPELL_TAG_SIZE
Definition: object.h:81
SP_SWARM
#define SP_SWARM
Definition: spells.h:110
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
SP_LIGHT
#define SP_LIGHT
Definition: spells.h:116
cast_earth_to_dust
int cast_earth_to_dust(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:864
recharge
int recharge(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:81
MSG_TYPE_APPLY_ERROR
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:601
living.h
SP_CURSE
#define SP_CURSE
Definition: spells.h:100
drain_rod_charge
void drain_rod_charge(object *rod)
Definition: spell_util.c:775
NUM_STATS
@ NUM_STATS
Definition: living.h:18
lookup_spell_by_name
object * lookup_spell_by_name(object *op, const char *spname)
Definition: spell_util.c:409
store_spell_expiry
void store_spell_expiry(object *spell)
Definition: spell_util.c:1977
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
can_see_monsterP
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
Definition: object.c:3793
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:319
object.h
obj::level
int16_t level
Definition: object.h:356
cast_invisible
int cast_invisible(object *op, object *caster, object *spell_ob)
Definition: spell_effect.c:812
obj::range
int8_t range
Definition: object.h:410
SP_WORD_OF_RECALL
#define SP_WORD_OF_RECALL
Definition: spells.h:92
DIRY
#define DIRY(xyz)
Definition: define.h:464
cast_cone
int cast_cone(object *op, object *caster, int dir, object *spell)
Definition: spell_attack.c:297
SP_level_spellpoint_cost
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.c:235
P_BLOCKSVIEW
#define P_BLOCKSVIEW
Definition: map.h:227
FORCE_NAME
#define FORCE_NAME
Definition: spells.h:169
obj::inv
struct obj * inv
Definition: object.h:293
SP_ELEM_SHIELD
#define SP_ELEM_SHIELD
Definition: spells.h:124
give.name
name
Definition: give.py:27
obj::dam_modifier
uint8_t dam_modifier
Definition: object.h:412
SPELL_MANA
#define SPELL_MANA
Definition: spells.h:58
dragon_attune.force
force
Definition: dragon_attune.py:45
object_get_owner
object * object_get_owner(object *op)
Definition: object.c:808
SP_AURA
#define SP_AURA
Definition: spells.h:120
level
Definition: level.py:1