Crossfire Server  1.75.0
spell_util.cpp
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 #include "assets.h"
33 #include "AssetsManager.h"
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 
108 void dump_spells(void) {
109  int banner = 0;
110 
111  getManager()->archetypes()->each([] (const auto at) {
112  if (at->clone.type == SPELL) {
113  fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null",
114  at->name, at->clone.other_arch ? at->clone.other_arch->name : "null",
115  at->clone.skill ? at->clone.skill : "null", at->clone.level);
116  }
117  });
118 
119  getManager()->archetypes()->each([&] (const auto at) {
120  if (at->clone.type == SPELL && at->clone.path_attuned == 0) {
121  if (banner == 0) {
122  banner = 1;
123  fprintf(stderr, "Spells with no path set:\n");
124  }
125 
126  fprintf(stderr, "- %s\n", at->clone.name ? at->clone.name : "null");
127  }
128  });
129 }
130 
144 void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) {
145  if (spob->other_arch != NULL) {
146  object *effect = arch_to_object(spob->other_arch);
147  object_insert_in_map_at(effect, map, originator, 0, x, y);
148  }
149 }
150 
164 int min_casting_level(const object *caster, const object *spell) {
165  int new_level;
166 
167  if (caster->path_denied&spell->path_attuned) {
168  /* This case is not a bug, just the fact that this function is
169  * usually called BEFORE checking for path_deny. -AV
170  */
171  return 1;
172  }
173  new_level = spell->level
174  +((caster->path_repelled&spell->path_attuned) ? +2 : 0)
175  +((caster->path_attuned&spell->path_attuned) ? -2 : 0);
176  return MAX(new_level, 1);
177 }
178 
179 
194 int caster_level(const object *caster, const object *spell) {
195  int level = caster->level;
196 
197  /* If this is a player, try to find the matching skill */
198  if (caster->type == PLAYER && spell->skill) {
199  object* skill = find_applied_skill_by_name(caster, spell->skill);
200  if (skill != NULL) {
201  level = skill->level;
202  } else {
203  level = 0;
204  }
205  }
206  /* Got valid caster level. Now adjust for attunement */
207  level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0)
208  +((caster->path_attuned&spell->path_attuned) ? 2 : 0);
209 
210  /* Always make this at least 1. If this is zero, we get divide by zero
211  * errors in various places.
212  */
213  if (level < 1)
214  level = 1;
215  return level;
216 }
217 
236 int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags) {
237  int sp, grace, level = caster_level(caster, spell);
238 
240  if (spell->stats.sp && spell->stats.maxsp) {
241  sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp)));
242  } else
243  sp = spell->stats.sp;
244 
245  sp *= PATH_SP_MULT(caster, spell);
246  if (!sp && spell->stats.sp)
247  sp = 1;
248 
249  if (spell->stats.grace && spell->stats.maxgrace) {
250  grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace)));
251  } else
252  grace = spell->stats.grace;
253 
254  grace *= PATH_SP_MULT(caster, spell);
255  if (spell->stats.grace && !grace)
256  grace = 1;
257  } else {
258  sp = spell->stats.sp*PATH_SP_MULT(caster, spell);
259  if (spell->stats.sp && !sp)
260  sp = 1;
261  grace = spell->stats.grace*PATH_SP_MULT(caster, spell);
262  if (spell->stats.grace && !grace)
263  grace = 1;
264  }
265  if (flags == SPELL_HIGHEST)
266  return MAX(sp, grace);
267  else if (flags == SPELL_GRACE)
268  return grace;
269  else if (flags == SPELL_MANA)
270  return sp;
271  else {
272  LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
273  return 0;
274  }
275 }
276 
287 int SP_level_dam_adjust(const object *caster, const object *spob) {
288  int level = caster_level(caster, spob);
289  int adj = level-min_casting_level(caster, spob);
290 
291  if (adj < 0)
292  adj = 0;
293  if (spob->dam_modifier)
294  adj /= spob->dam_modifier;
295  else
296  adj = 0;
297  return adj;
298 }
299 
312 int SP_level_duration_adjust(const object *caster, const object *spob) {
313  int level = caster_level(caster, spob);
314  int adj = level-min_casting_level(caster, spob);
315 
316  if (adj < 0)
317  adj = 0;
318  if (spob->duration_modifier)
319  adj /= spob->duration_modifier;
320  else
321  adj = 0;
322 
323  return adj;
324 }
325 
338 int SP_level_range_adjust(const object *caster, const object *spob) {
339  int level = caster_level(caster, spob);
340  int adj = level-min_casting_level(caster, spob);
341 
342  if (adj < 0)
343  adj = 0;
344  if (spob->range_modifier)
345  adj /= spob->range_modifier;
346  else
347  adj = 0;
348 
349  return adj;
350 }
351 
362 int SP_level_wc_adjust(const object *caster, const object *spob) {
363  int level = caster_level(caster, spob);
364  int adj = level - min_casting_level(caster, spob), irate;
365  sstring rate;
366 
367  rate = object_get_value(spob, "wc_increase_rate");
368 
369  if (rate == NULL)
370  return 0;
371 
372  if (adj < 0)
373  adj = 0;
374 
375  irate = atoi(rate);
376  if (irate > 0)
377  adj /= irate;
378  else
379  adj = 0;
380  return adj;
381 }
382 
394 object *check_spell_known(object *op, const char *name) {
395  return object_find_by_type_and_name(op, SPELL, name);
396 }
397 
410 object *lookup_spell_by_name(object *op, const char *spname) {
411  object *spob1 = NULL, *spob2 = NULL;
412  int nummatch = 0;
413 
414  if (spname == NULL)
415  return NULL;
416 
417  /* Try to find the spell. We store the results in spob1
418  * and spob2 - spob1 is only taking the length of
419  * the past spname, spob2 uses the length of the spell name.
420  */
421  FOR_INV_PREPARE(op, spob) {
422  if (spob->type == SPELL) {
423  if (!strncmp(spob->name, spname, strlen(spname))) {
424  if (strlen(spname) == strlen(spob->name))
425  /* Perfect match, return it. */
426  return spob;
427  nummatch++;
428  spob1 = spob;
429  } else if (!strncmp(spob->name, spname, strlen(spob->name))) {
430  /* if spells have ambiguous names, it makes matching
431  * really difficult. (eg, fire and fireball would
432  * fall into this category). It shouldn't be hard to
433  * make sure spell names don't overlap in that fashion.
434  */
435  if (spob2)
436  LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name);
437  spob2 = spob;
438  }
439  }
440  } FOR_INV_FINISH();
441  /* if we have best match, return it. Otherwise, if we have one match
442  * on the loser match, return that, otehrwise null
443  */
444  if (spob2)
445  return spob2;
446  if (spob1 && nummatch == 1)
447  return spob1;
448  return NULL;
449 }
450 
470 int reflwall(mapstruct *m, int x, int y, object *sp_op) {
471  if (OUT_OF_REAL_MAP(m, x, y))
472  return 0;
473  FOR_MAP_PREPARE(m, x, y, op)
475  && (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10)))
476  return 1;
477  FOR_MAP_FINISH();
478  return 0;
479 }
480 
494 int cast_create_obj(object *op, object *new_op, int dir) {
495  mapstruct *m;
496  int16_t sx, sy;
497 
498  if (dir
499  && ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP)
500  || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) {
502  "Something is in the way. You cast it at your feet.");
503  dir = 0;
504  }
505  if (dir == 0)
506  object_insert_in_map_at(new_op, op->map, op, INS_BELOW_ORIGINATOR, op->x+freearr_x[dir], op->y+freearr_y[dir]);
507  else
508  object_insert_in_map_at(new_op, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
509  return dir;
510 }
511 
530 int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop) {
531  int mflags;
532  mapstruct *mp;
533 
534  mp = m;
535  mflags = get_map_flags(m, &mp, x, y, &x, &y);
536 
537  if (mflags&P_OUT_OF_MAP)
538  return 0;
539 
540  if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(mp, x, y)))
541  return 0;
542 
543  FOR_MAP_PREPARE(mp, x, y, tmp) {
544  /* If there is a counterspell on the space, and this
545  * object is using magic, don't progess. I believe we could
546  * leave this out and let in progress, and other areas of the code
547  * will then remove it, but that would seem to to use more
548  * resources, and may not work as well if a player is standing
549  * on top of a counterwall spell (may hit the player before being
550  * removed.) On the other hand, it may be more dramatic for the
551  * spell to actually hit the counterwall and be sucked up.
552  */
553  if ((tmp->attacktype&AT_COUNTERSPELL)
554  && (tmp->type != PLAYER)
555  && !QUERY_FLAG(tmp, FLAG_MONSTER)
556  && (tmp->type != WEAPON)
557  && (tmp->type != BOW)
558  && (tmp->type != ARROW)
559  && (tmp->type != GOLEM)
560  && (immune_stop&AT_MAGIC))
561  return 0;
562 
563  /* This is to prevent 'out of control' spells. Basically, this
564  * limits one spell effect per space per spell. This is definitely
565  * needed for performance reasons, and just for playability I believe.
566  * there are no such things as multispaced spells right now, so
567  * we don't need to worry about the head.
568  * We only need to go down this path is maxhp is set on both objects -
569  * otherwise, no reason to check. But if we do check, we need to
570  * do some extra work, looking in the spell_tags[] of each object,
571  * if they have it set.
572  */
573  if (tmp->type == op->type
574  && tmp->subtype == op->subtype
575  && tmp->stats.maxhp
576  && op->stats.maxhp) {
577  if ((tmp->stats.maxhp == op->stats.maxhp)
578  || (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp))
579  || (op->spell_tags && OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp))) {
581  return 0;
582  }
583 
584  /* if both objects have spell tags, then if the two tags entries
585  * from either match, that also counts. Need to check
586  * the spell_tags, because 0 values are allowed to match
587  */
588  if (op->spell_tags && tmp->spell_tags) {
589  int i;
590 
591  for (i = 0; i < SPELL_TAG_SIZE; i++) {
592  if (op->spell_tags[i] &&
593  op->spell_tags[i] == tmp->spell_tags[i]) {
595  return 0;
596  }
597  }
598  }
599  }
600  /* Perhaps we should also put checks in for no magic and unholy
601  * ground to prevent it from moving along?
602  */
603  } FOR_MAP_FINISH();
604  /* If it passes the above tests, it must be OK */
605  return 1;
606 }
607 
629 int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell) {
630  object *tmp;
631  int mflags;
632  mapstruct *m;
633 
634  if (dir < 0 || dir > 8) {
635  LOG(llevError, "Invalid direction %d in fire_arch_from_position for %s\n", dir, spell->name);
636  dir = RANDOM() % 8 + 1;
637  }
638 
639  if (spell->other_arch == NULL)
640  return 0;
641 
642  if (spell->type != SPELL)
643  LOG(llevError, "Unexpected object type %d in fire_arch_from_position for %s\n", spell->type, spell->name);
644 
645  m = op->map;
646  mflags = get_map_flags(m, &m, x, y, &x, &y);
647  if (mflags&P_OUT_OF_MAP) {
648  return 0;
649  }
650 
651  tmp = arch_to_object(spell->other_arch);
652  if (tmp == NULL)
653  return 0;
654 
655  mflags = get_map_flags(m, &tmp->map, x, y, &tmp->x, &tmp->y);
656  if (mflags&P_OUT_OF_MAP) {
658  return 0;
659  }
660 
661  if (spell->subtype == SP_BULLET) {
662  /* peterm: level dependency for bolts */
663  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
664  tmp->attacktype = spell->attacktype;
665  if (spell->slaying)
666  tmp->slaying = add_refcount(spell->slaying);
667 
668  tmp->range = 50;
669 
670  /* Need to store duration/range for the ball to use */
671  tmp->stats.hp = spell->duration+SP_level_duration_adjust(caster, spell);
672  tmp->stats.maxhp = spell->range+SP_level_range_adjust(caster, spell);
673  tmp->dam_modifier = spell->stats.food+SP_level_dam_adjust(caster, spell);
674 
675  tmp->direction = dir;
677 
678  object_set_owner(tmp, op);
679  } else {
680  if (spell->subtype != SP_MAGIC_MISSILE && spell->subtype != SP_MOVING_BALL)
681  LOG(llevError, "Unexpected object subtype %d in fire_arch_from_position for %s\n", spell->subtype, spell->name);
682 
683  /*
684  * Things like firewalls and such can fire even if blocked, since the
685  * origin is themselves which block things...
686  * This fixes bug #3536508.
687  */
688  if (caster->type == PLAYER && OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
690  "You can't cast the spell on top of a wall!");
692  return 0;
693  }
694 
695  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
696  tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell);
697  /* code in time.c uses food for some things, duration for others */
698  tmp->stats.food = tmp->duration;
699  tmp->range = spell->range+SP_level_range_adjust(caster, spell);
700  tmp->attacktype = spell->attacktype;
701  if (object_get_owner(op) != NULL)
702  object_copy_owner(tmp, op);
703  else
704  object_set_owner(tmp, op);
705  tmp->level = caster_level(caster, spell);
706  }
707 
708  tmp->direction = dir;
709  set_spell_skill(op, caster, spell, tmp);
710 
711  if (spell->subtype == SP_BULLET) {
712  if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
713  if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) {
715  return 0;
716  }
717  tmp->direction = absdir(tmp->direction+4);
718  x += DIRX(tmp);
719  y += DIRY(tmp);
720  mflags = get_map_flags(m, &m, x, y, &x, &y);
721  if (mflags&P_OUT_OF_MAP) {
723  return 0;
724  }
725  tmp->x = x;
726  tmp->y = y;
727  tmp->map = m;
728  }
729 
730  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
731  if (tmp != NULL)
732  check_bullet(tmp);
733  } else /*if (spell->subtype == SP_MAGIC_MISSILE || spell->subtype == SP_MOVING_BALL) */ {
734  /* needed for AT_HOLYWORD, AT_GODPOWER stuff */
735  if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) {
736  if (!tailor_god_spell(tmp, op))
737  return 0;
738  }
740 
741  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
742  if (tmp != NULL)
743  ob_process(tmp);
744  }
745 
746  return 1;
747 }
748 
749 /*****************************************************************************
750  *
751  * Code related to rods - perhaps better located in another file?
752  *
753  ****************************************************************************/
754 
761 void regenerate_rod(object *rod) {
762  if (rod->stats.hp < rod->stats.maxhp) {
763  rod->stats.hp += 1+rod->stats.maxhp/10;
764 
765  if (rod->stats.hp > rod->stats.maxhp)
766  rod->stats.hp = rod->stats.maxhp;
767  }
768 }
769 
776 void drain_rod_charge(object *rod) {
777  rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
778 }
779 
786 void drain_wand_charge(object *wand) {
787  assert(wand->type == WAND);
788 
789  if (!(--wand->stats.food)) {
790  object *tmp;
791  if (wand->arch) {
792  CLEAR_FLAG(wand, FLAG_ANIMATE);
793  wand->face = wand->arch->clone.face;
794  wand->speed = 0;
795  object_update_speed(wand);
796  }
797  tmp = object_get_player_container(wand);
798  if (tmp)
799  esrv_update_item(UPD_ANIM, tmp, wand);
800  }
801 }
802 
813 object *find_target_for_friendly_spell(object *op, int dir) {
814  object *tmp;
815  mapstruct *m;
816  int16_t x, y;
817  int mflags;
818 
819  /* I don't really get this block - if op isn't a player or rune,
820  * we then make the owner of this object the target.
821  * The owner could very well be no where near op.
822  */
823  if (op->type != PLAYER && op->type != RUNE) {
824  tmp = object_get_owner(op);
825  /* If the owner does not exist, or is not a monster, than apply the spell
826  * to the caster.
827  */
828  if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER))
829  tmp = op;
830  } else {
831  m = op->map;
832  x = op->x+freearr_x[dir];
833  y = op->y+freearr_y[dir];
834 
835  mflags = get_map_flags(m, &m, x, y, &x, &y);
836 
837  if (mflags&P_OUT_OF_MAP)
838  tmp = NULL;
839  else {
840  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
841  if (tmp->type == PLAYER)
842  break;
843  }
844  }
845  }
846  /* didn't find a player there, look in current square for a player */
847  if (tmp == NULL) {
848  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
849  if (tmp->type == PLAYER)
850  return tmp;
851  /* Don't forget to browse inside transports ! - gros 2006/07/25 */
852  if (tmp->type == TRANSPORT) {
853  object *inv;
854 
855  for (inv = tmp->inv; inv; inv = inv->below) {
856  if ((inv->type == PLAYER) && (op == inv))
857  return inv;
858  }
859  }
860  } FOR_MAP_FINISH();
861  }
862  return tmp;
863 }
864 
865 
866 
887 int spell_find_dir(mapstruct *m, int x, int y, object *exclude) {
888  int i;
889  int16_t nx, ny;
890  int owner_type = 0, mflags;
891  object *tmp;
892  mapstruct *mp;
893  int dirs[SIZEOFFREE];
894 
895  if (exclude != NULL) {
896  exclude = HEAD(exclude);
897  owner_type = exclude->type;
898  }
899 
900  get_search_arr(dirs);
901  for (i = 1; i < SIZEOFFREE; i++) {
902  nx = x+freearr_x[dirs[i]];
903  ny = y+freearr_y[dirs[i]];
904  mp = m;
905  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
906  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
907  continue;
908 
909  for (tmp = GET_MAP_OB(mp, nx, ny); tmp != NULL; tmp = tmp->above) {
910  object *head;
911 
912  head = HEAD(tmp);
913  if ((owner_type != PLAYER || QUERY_FLAG(head, FLAG_MONSTER) || QUERY_FLAG(head, FLAG_GENERATOR) || (head->type == PLAYER && op_on_battleground(head, NULL, NULL, NULL)))
914  && (owner_type == PLAYER || head->type == PLAYER)
915  && head != exclude
916  && can_see_monsterP(m, x, y, dirs[i])) {
917  return freedir[dirs[i]];
918  }
919  }
920  }
921  return -1; /* flag for "keep going the way you were" */
922 }
923 
924 
925 
939 static int put_a_monster(object *op, const char *monstername) {
940  object *tmp, *head = NULL, *prev = NULL;
941  archetype *at;
942  int dir;
943 
944  /* Handle cases where we are passed a bogus mosntername */
945  at = try_find_archetype(monstername);
946  if (at == NULL)
947  return 0;
948 
949  /* find a free square nearby
950  * first we check the closest square for free squares
951  */
952 
953  dir = object_find_first_free_spot(&at->clone, op->map, op->x, op->y);
954  if (dir != -1) {
955  /* This is basically grabbed for generate monster. Fixed 971225 to
956  * insert multipart monsters properly
957  */
958  while (at != NULL) {
959  tmp = arch_to_object(at);
960  tmp->x = op->x+freearr_x[dir]+at->clone.x;
961  tmp->y = op->y+freearr_y[dir]+at->clone.y;
962  tmp->map = op->map;
963  if (head) {
964  tmp->head = head;
965  prev->more = tmp;
966  }
967  if (!head)
968  head = tmp;
969  prev = tmp;
970  at = at->more;
971  }
972 
973  if (head->randomitems)
974  create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
975 
976  object_insert_in_map_at(head, op->map, op, 0, op->x, op->y);
977 
978  /* thought it'd be cool to insert a burnout, too.*/
979  tmp = create_archetype("burnout");
980  object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
981  return 1;
982  } else {
983  return 0;
984  }
985 }
986 
1005 int summon_hostile_monsters(object *op, int n, const char *monstername) {
1006  int i, put = 0;
1007 
1008  for (i = 0; i < n; i++)
1009  put += put_a_monster(op, monstername);
1010 
1011  return put;
1012 }
1013 
1014 
1033 void shuffle_attack(object *op) {
1034  int i;
1035 
1036  i = rndm(0, 21);
1038  SET_ANIMATION(op, ATTACKS[i].face);
1039 }
1040 
1041 
1052 static void prayer_failure(object *op, int failure, int power) {
1053  const char *godname;
1054  object *tmp;
1055 
1056  godname = determine_god(op);
1057  if (!strcmp(godname, "none"))
1058  godname = "Your spirit";
1059 
1060  if (failure <= -20 && failure > -40) { /* wonder */
1062  "%s gives a sign to renew your faith.",
1063  godname);
1065  cast_cone(op, op, 0, tmp);
1067  } else if (failure <= -40 && failure > -60) { /* confusion */
1069  "Your diety touches your mind!");
1070  confuse_living(op, op, 99);
1071  } else if (failure <= -60 && failure > -150) { /* paralysis */
1073  "%s requires you to pray NOW. You comply, ignoring all else.",
1074  godname);
1075 
1076  paralyze_living(op, 99);
1077  } else if (failure <= -150) { /* blast the immediate area */
1078  tmp = create_archetype(GOD_POWER);
1080  "%s smites you!",
1081  godname);
1082  /* Put a cap on power - this is effectively cost of the spell minus
1083  * characters current grace. Thus, if spell costs 30 grace and
1084  * character has -100 grace, this is cast as a level 130 spell.
1085  * Things start to break in those cases.
1086  */
1087  cast_magic_storm(op, tmp, power > 50 ? 50 : power);
1088  }
1089 }
1090 
1103 void spell_failure(object *op, int failure, int power, object *skill) {
1104  object *tmp;
1105 
1107  return;
1108 
1109  if (failure <= -20 && failure > -40) { /* wonder */
1111  "Your spell causes an unexpected effect.");
1113  cast_cone(op, op, 0, tmp);
1115  } else if (failure <= -40 && failure > -60) { /* confusion */
1117  "Your magic recoils on you, making you confused!");
1118  confuse_living(op, op, 99);
1119  } else if (failure <= -60 && failure > -80) { /* paralysis */
1121  "Your magic stuns you!");
1122  paralyze_living(op, 99);
1123  } else if (failure <= -80) { /* blast the immediate area */
1124  object *tmp;
1125 
1126  /* Safety check to make sure we don't get any mana storms in scorn */
1127  if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) {
1129  "The magic warps and you are turned inside out!");
1130  hit_player(op, 9998, op, AT_INTERNAL, 1);
1131  } else {
1133  "You lose control of the mana! The uncontrolled magic blasts you!");
1135  tmp->level = skill->level;
1136 
1137  /* increase the area of destruction a little for more powerful spells */
1138  tmp->range += isqrt(power);
1139 
1140  if (power > 25)
1141  tmp->stats.dam = 25+isqrt(power);
1142  else
1143  tmp->stats.dam = power; /* nasty recoils! */
1144 
1145  tmp->stats.maxhp = tmp->count;
1146  if (tmp->stats.maxhp == 0)
1147  tmp->stats.maxhp = 1;
1148  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
1149  }
1150  }
1151 }
1152 
1161 static int can_be_transmuted_to_flower(object *op) {
1162  if (op->invisible)
1163  return 0;
1164 
1165  if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON)
1166  return 1;
1167 
1168  return 0;
1169 }
1170 
1183 static void transmute_item_to_flower(object *op) {
1184  object *force;
1185  object *item;
1186  object *flower;
1187  object *first = NULL;
1188  int count = 0;
1189  char name[HUGE_BUF];
1190 
1191  FOR_INV_PREPARE(op, item)
1192  if (can_be_transmuted_to_flower(item)) {
1193  if (!first)
1194  first = item;
1195  count++;
1196  }
1197  FOR_INV_FINISH();
1198 
1199  if (count == 0)
1200  return;
1201 
1202  count = rndm(0, count-1);
1203  for (item = first; item; item = item->below) {
1204  if (can_be_transmuted_to_flower(item)) {
1205  count--;
1206  if (count < 0)
1207  break;
1208  }
1209  }
1210 
1211  if (!item)
1212  return;
1213 
1214  force = create_archetype(FORCE_NAME);
1215  force->duration = 100+rndm(0, 10)*100;
1217  force->speed = 1;
1218  object_update_speed(force);
1219 
1220  flower = create_archetype("flowers_permanent");
1221 
1222  if (QUERY_FLAG(item, FLAG_APPLIED))
1224  if (QUERY_FLAG(item, FLAG_STARTEQUIP)) {
1225  SET_FLAG(flower, FLAG_STARTEQUIP);
1226  }
1227  object_remove(item);
1228  flower->weight = item->nrof ? ((int32_t)item->nrof)*item->weight : item->weight;
1229  item->weight = 0;
1230  esrv_del_item(op->contr, item);
1231  object_insert_in_ob(item, force);
1232 
1233  query_short_name(item, name, HUGE_BUF);
1236  "Your %s turns to a flower!",
1237  name);
1238 
1239  object_insert_in_ob(force, flower);
1240  flower = object_insert_in_ob(flower, op);
1241  esrv_send_item(op, flower);
1242 }
1243 
1254 static void swap_random_stats(object *op) {
1255  object *force;
1256  int first, second;
1257 
1258  first = RANDOM()%NUM_STATS;
1259  second = RANDOM()%(NUM_STATS-1);
1260  if (second >= first)
1261  second++;
1262 
1265  "You suddenly feel really weird!");
1266 
1267  force = create_archetype(FORCE_NAME);
1268  force->duration = 100+rndm(0, 10)*100;
1269  force->speed = 1;
1270  SET_FLAG(force, FLAG_APPLIED);
1271  set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second));
1272  set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first));
1273  object_update_speed(force);
1274  object_insert_in_ob(force, op);
1275  change_abil(op, force);
1276  fix_object(op);
1277 }
1278 
1289 static void handle_spell_confusion(object *op) {
1290  switch (RANDOM()%2) {
1291  case 0:
1293  break;
1294 
1295  case 1:
1296  swap_random_stats(op);
1297  break;
1298  }
1299 }
1300 
1308 static int spell_consume_items(object *op, const object *spell_ob) {
1309  sstring requirements;
1310  char *copy;
1311  char *ingredients[10];
1312  object *found[10];
1313  int count, i;
1314  uint32_t nrof[10];
1315  char name_ob[MAX_BUF];
1316  const char *name2;
1317 
1318  if (op->type != PLAYER)
1319  return 1;
1320 
1321  requirements = object_get_value(spell_ob, "casting_requirements");
1322  if (!requirements)
1323  /* no special requirements */
1324  return 1;
1325 
1326  /* find items */
1327  copy = strdup_local(requirements);
1328  count = split_string(copy, ingredients, 10, ',');
1329 
1330  /* first pass, find items */
1331  for (i = 0; i < count; i++) {
1332  nrof[i] = 0;
1333  found[i] = NULL;
1334  while (isdigit(*ingredients[i])) {
1335  nrof[i] = 10*nrof[i]+(*(ingredients[i])-'0');
1336  ingredients[i]++;
1337  }
1338  if (nrof[i] == 0)
1339  nrof[i] = 1;
1340  while (*ingredients[i] == ' ')
1341  ingredients[i]++;
1342 
1343  /* now find item in op's inv */
1344  FOR_INV_PREPARE(op, check) {
1345 
1346  if (check->title == NULL)
1347  name2 = check->name;
1348  else {
1349  snprintf(name_ob, sizeof(name_ob), "%s %s", check->name, check->title);
1350  name2 = name_ob;
1351  }
1352 
1353  if (strcmp(name2, ingredients[i]) == 0) {
1354  found[i] = check;
1355  break;
1356  }
1357  } FOR_INV_FINISH();
1358 
1359  if (found[i] == NULL) {
1362  "Casting this spell requires %s, but you don't have any.",
1363  ingredients[i]);
1364  free(copy);
1365  return 0;
1366  }
1367 
1368  if (found[i]->nrof < nrof[i]) {
1371  "Casting this spell requires %d %s, but you only have %d.",
1372  nrof[i], found[i]->name_pl, found[i]->nrof);
1373  free(copy);
1374  return 0;
1375  }
1376  }
1377 
1378  free(copy);
1379 
1380  /* ok, found ingredients, remove'em */
1381  for (i = 0; i < count; i++) {
1382  object_decrease_nrof(found[i], nrof[i]);
1383  }
1384 
1385  /* all right, spell can be cast */
1386  return 1;
1387 }
1388 
1424 int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
1425  const char *godname;
1426  int success = 0, mflags, cast_level = 0;
1427  rangetype old_shoottype;
1428  object *skill = NULL;
1429  int confusion_effect = 0;
1430  float cost_multiplier = 1.0f;
1431 
1432  old_shoottype = op->contr ? op->contr->shoottype : range_none;
1433 
1434  if (!spell_ob) {
1435  LOG(llevError, "cast_spell: null spell object passed\n");
1436  return 0;
1437  }
1438  godname = determine_god(op);
1439  if (!strcmp(godname, "none"))
1440  godname = "A random spirit";
1441 
1442  /* the caller should set caster to op if appropriate */
1443  if (!caster) {
1444  LOG(llevError, "cast_spell: null caster object passed\n");
1445  return 0;
1446  }
1447  if (spell_ob->anim_suffix)
1448  apply_anim_suffix(caster, spell_ob->anim_suffix);
1449 
1450  /* Handle some random effect if confused. */
1451  if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) {
1452  if (rndm(0, 5) < 4) {
1453  spell_ob = find_random_spell_in_ob(op, NULL);
1456  "In your confused state, you're not sure of what you cast!");
1457  } else
1458  /* We fall through to deplate sp/gr, and do some checks. */
1459  confusion_effect = 1;
1460  }
1461 
1462  /* if caster is a spell casting object, this normally shouldn't be
1463  * an issue, because they don't have any spellpaths set up.
1464  */
1465  if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) {
1467  "That spell path is denied to you.");
1468  return 0;
1469  }
1470 
1471 
1472  mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL);
1473 
1474  /* See if we can cast a spell here. If the caster and op are
1475  * not alive, then this would mean that the mapmaker put the
1476  * objects on the space - presume that they know what they are
1477  * doing.
1478  */
1479  if (spell_ob->type == SPELL
1480  && caster->type != POTION
1481  && !QUERY_FLAG(op, FLAG_WIZCAST)
1482  && (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE))
1483  && !QUERY_FLAG(op, FLAG_MONSTER)
1484  && (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) {
1485  if (op->type != PLAYER)
1486  return 0;
1487 
1489 
1490  if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace)
1492  "This ground is unholy! %s ignores you.",
1493  godname);
1494  else
1495  switch (op->contr->shoottype) {
1496  case range_magic:
1498  "Something blocks your spellcasting.");
1499  break;
1500 
1501  case range_misc:
1503  "Something blocks the magic of your item.");
1504  break;
1505  case range_golem:
1507  "Something blocks the magic of your scroll.");
1508  break;
1509 
1510  default:
1511  break;
1512  }
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  if (caster == op && caster->type ==PLAYER && settings.casting_time == TRUE && spell_ob->type == SPELL) {
1615  if (op->casting_time == -1) { /* begin the casting */
1616  op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob);
1617  op->spell = spell_ob;
1618  /* put the stringarg into the object struct so that when the
1619  * spell is actually cast, it knows about the stringarg.
1620  * necessary for the invoke command spells.
1621  */
1622  if (stringarg) {
1623  op->spellarg = strdup_local(stringarg);
1624  } else
1625  op->spellarg = NULL;
1626  return 0;
1627  } else if (op->casting_time != 0) {
1628  if (op->type == PLAYER)
1630  "You are casting!");
1631  return 0;
1632  } else { /* casting_time == 0 */
1633  op->casting_time = -1;
1634  spell_ob = op->spell;
1635  stringarg = op->spellarg;
1636  }
1637  } else {
1638  if (!QUERY_FLAG(caster, FLAG_WIZ)) {
1639  /* Take into account how long it takes to cast the spell.
1640  * if the player is casting it, then we use the time in
1641  * the spell object. If it is a spell object, have it
1642  * take two ticks. Things that cast spells on the players
1643  * behalf (eg, altars, and whatever else) shouldn't cost
1644  * the player any time.
1645  * Ignore casting time for firewalls
1646  */
1647  if (caster == op && caster->type != FIREWALL) {
1648  op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1649  /* Other portions of the code may also decrement the speed of the player, so
1650  * put a lower limit so that the player isn't stuck here too long
1651  */
1652  if ((spell_ob->casting_time > 0)
1653  && op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed))
1654  op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1655  } else if (caster->type == WAND
1656  || caster->type == ROD
1657  || caster->type == POTION
1658  || caster->type == SCROLL) {
1659  op->speed_left -= 2*FABS(op->speed);
1660  }
1661  }
1662  }
1663 
1664  /* We want to try to find the skill to properly credit exp.
1665  * for spell casting objects, the exp goes to the skill the casting
1666  * object requires.
1667  */
1668  if (op != caster && !skill && caster->skill && !QUERY_FLAG(op, FLAG_MONSTER)) {
1669  skill = find_skill_by_name(op, caster->skill);
1670  if (!skill) {
1671  char name[MAX_BUF];
1672 
1673  query_name(caster, name, MAX_BUF);
1676  "You lack the skill %s to use the %s",
1677  caster->skill, name);
1678  return 0;
1679  }
1680  change_skill(op, skill, 0); /* needed for proper exp credit */
1681  }
1682 
1683  /* Need to get proper ownership for spells cast via runes - these are not
1684  * the normal 'rune of fire', but rather the magic runes that let the player
1685  * put some other spell into the rune (glyph, firetrap, magic rune, etc)
1686  */
1687  if (caster->type == RUNE) {
1688  object *owner = object_get_owner(caster);
1689 
1690  if (owner)
1691  skill = find_skill_by_name(owner, caster->skill);
1692  }
1693 
1694  if (confusion_effect) {
1695  /* If we get here, the confusion effect was 'random effect', so do it and bail out. */
1698  "In your confused state, you can't control the magic!");
1700 
1701  /* Still subtract full grace and sp. */
1702  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1703  op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE);
1704  op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA);
1705  }
1706 
1707  return 0;
1708  }
1709 
1710  play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name);
1711 
1712  switch (spell_ob->subtype) {
1713  /* The order of case statements is same as the order they show up
1714  * in in spells.h.
1715  */
1716  case SP_RAISE_DEAD:
1717  success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg);
1718  break;
1719 
1720  case SP_RUNE:
1721  success = write_rune(op, caster, spell_ob, dir, stringarg);
1722  break;
1723 
1724  case SP_MAKE_MARK:
1725  success = write_mark(op, spell_ob, stringarg);
1726  break;
1727 
1728  case SP_BOLT:
1729  success = fire_bolt(op, caster, dir, spell_ob);
1730  break;
1731 
1732  case SP_BULLET:
1733  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1734  break;
1735 
1736  case SP_CONE:
1737  success = cast_cone(op, caster, dir, spell_ob);
1738  break;
1739 
1740  case SP_BOMB:
1741  success = create_bomb(op, caster, dir, spell_ob);
1742  break;
1743 
1744  case SP_WONDER:
1745  success = cast_wonder(op, caster, dir, spell_ob);
1746  break;
1747 
1748  case SP_SMITE:
1749  success = cast_smite_spell(op, caster, dir, spell_ob);
1750  break;
1751 
1752  case SP_MAGIC_MISSILE:
1753  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1754  break;
1755 
1756  case SP_SUMMON_GOLEM:
1757  success = pets_summon_golem(op, caster, dir, spell_ob);
1758  if (success || op->contr == NULL)
1759  old_shoottype = range_golem;
1760  else
1761  /*
1762  * if the spell failed (something in the way for instance),
1763  * don't change the range so the player can try easily after that
1764  */
1765  old_shoottype = op->contr->shoottype;
1766  break;
1767 
1768  case SP_DIMENSION_DOOR:
1769  /* dimension door needs the actual caster, because that is what is
1770  * moved.
1771  */
1772  success = dimension_door(op, caster, spell_ob, dir);
1773  break;
1774 
1775  case SP_MAGIC_MAPPING:
1776  if (op->type == PLAYER) {
1777  spell_effect(spell_ob, op->x, op->y, op->map, op);
1778  draw_magic_map(op);
1779  success = 1;
1780  } else
1781  success = 0;
1782  break;
1783 
1784  case SP_MAGIC_WALL:
1785  success = magic_wall(op, caster, dir, spell_ob);
1786  break;
1787 
1788  case SP_DESTRUCTION:
1789  success = cast_destruction(op, caster, spell_ob);
1790  break;
1791 
1792  case SP_PERCEIVE_SELF:
1793  success = perceive_self(op);
1794  break;
1795 
1796  case SP_WORD_OF_RECALL:
1797  success = cast_word_of_recall(op, caster, spell_ob);
1798  break;
1799 
1800  case SP_INVISIBLE:
1801  success = cast_invisible(op, caster, spell_ob);
1802  break;
1803 
1804  case SP_PROBE:
1805  if (op != caster)
1806  cast_level = caster->level;
1807  else
1808  cast_level = skill != NULL ? skill->level : op->level;
1809  success = probe(op, caster, spell_ob, dir, cast_level);
1810  break;
1811 
1812  case SP_HEALING:
1813  success = cast_heal(op, caster, spell_ob, dir);
1814  break;
1815 
1816  case SP_CREATE_FOOD:
1817  success = cast_create_food(op, caster, spell_ob, dir, stringarg);
1818  break;
1819 
1820  case SP_EARTH_TO_DUST:
1821  success = cast_earth_to_dust(op, caster, spell_ob);
1822  break;
1823 
1824  case SP_CHANGE_ABILITY:
1825  success = cast_change_ability(op, caster, spell_ob, dir, 0);
1826  break;
1827 
1828  case SP_BLESS:
1829  success = cast_bless(op, caster, spell_ob, dir);
1830  break;
1831 
1832  case SP_CURSE:
1833  success = cast_curse(op, caster, spell_ob, dir);
1834  break;
1835 
1836  case SP_SUMMON_MONSTER:
1837  success = pets_summon_object(op, caster, spell_ob, dir, stringarg);
1838  if (!success) {
1839  cost_multiplier = 0.0f;
1840  }
1841  break;
1842 
1843  case SP_CHARGING:
1844  success = recharge(op, caster, spell_ob);
1845  break;
1846 
1847  case SP_POLYMORPH:
1848 #if 0
1849  /* Not great, but at least provide feedback so if players do have
1850  * polymorph (ie, find it as a preset item or left over from before
1851  * it was disabled), they get some feedback.
1852  */
1854  "The spell fizzles");
1855  success = 0;
1856 #else
1857  success = cast_polymorph(op, caster, spell_ob, dir);
1858 #endif
1859  break;
1860 
1861  case SP_ALCHEMY:
1862  success = alchemy(op, caster, spell_ob);
1863  break;
1864 
1865  case SP_REMOVE_CURSE:
1866  success = remove_curse(op, caster, spell_ob);
1867  break;
1868 
1869  case SP_IDENTIFY:
1870  success = cast_identify(op, caster, spell_ob);
1871  break;
1872 
1873  case SP_DETECTION:
1874  success = cast_detection(op, caster, spell_ob);
1875  break;
1876 
1877  case SP_MOOD_CHANGE:
1878  success = mood_change(op, caster, spell_ob);
1879  break;
1880 
1881  case SP_MOVING_BALL:
1882  if (spell_ob->path_repelled
1883  && (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) {
1885  "You lack the proper attunement to cast %s",
1886  spell_ob->name);
1887  success = 0;
1888  } else
1889  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1890  break;
1891 
1892  case SP_SWARM:
1893  success = fire_swarm(op, caster, spell_ob, dir);
1894  break;
1895 
1896  case SP_CHANGE_MANA:
1897  success = cast_transfer(op, caster, spell_ob, dir);
1898  break;
1899 
1900  case SP_DISPEL_RUNE:
1901  /* in rune.c */
1902  success = dispel_rune(op, skill, dir);
1903  break;
1904 
1905  case SP_CREATE_MISSILE:
1906  success = cast_create_missile(op, caster, spell_ob, dir, stringarg);
1907  break;
1908 
1909  case SP_CONSECRATE:
1910  success = cast_consecrate(op, caster, spell_ob);
1911  break;
1912 
1913  case SP_ANIMATE_WEAPON:
1914  success = animate_weapon(op, caster, spell_ob, dir);
1915  old_shoottype = range_golem;
1916  break;
1917 
1918  case SP_LIGHT:
1919  success = cast_light(op, caster, spell_ob, dir);
1920  break;
1921 
1922  case SP_CHANGE_MAP_LIGHT:
1923  success = cast_change_map_lightlevel(op, spell_ob);
1924  break;
1925 
1926  case SP_FAERY_FIRE:
1927  success = cast_destruction(op, caster, spell_ob);
1928  break;
1929 
1930  case SP_CAUSE_DISEASE:
1931  success = cast_cause_disease(op, caster, spell_ob, dir);
1932  break;
1933 
1934  case SP_AURA:
1935  success = create_aura(op, caster, spell_ob);
1936  break;
1937 
1938  case SP_TOWN_PORTAL:
1939  success = cast_create_town_portal(op, caster, spell_ob);
1940  break;
1941 
1942  case SP_ITEM_CURSE_BLESS:
1943  success = cast_item_curse_or_bless(op, spell_ob);
1944  break;
1945 
1946  case SP_ELEM_SHIELD:
1947  success = create_aura(op, caster, spell_ob);
1948  break;
1949 
1950  default:
1951  LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1952  }
1953 
1954  /* Subtract grace and sp. */
1955  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1956  op->stats.grace -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE));
1957  op->stats.sp -= (int)(0.5 + cost_multiplier * SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA));
1958  }
1959 
1960  /* FIXME - we need some better sound suppport */
1961  /* free the spell arg */
1962  if (settings.casting_time == TRUE) {
1963  free(stringarg);
1964  }
1965  /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1966  * to something like use_magic_item, but you really want to be able to fire
1967  * it again.
1968  */
1969  if (op->contr)
1970  op->contr->shoottype = old_shoottype;
1971 
1972  return success;
1973 }
1974 
1981 void store_spell_expiry(object *spell) {
1982  /* Keep when to warn the player of expiration */
1983  char dur[10];
1984  int i = spell->duration/5;
1985 
1986  if (!i)
1987  i = 1;
1988  snprintf(dur, sizeof(dur), "%d", i);
1989  object_set_value(spell, "spell_expiry_warn_1", dur, 1);
1990  i = i/5;
1991  if (i > 0) {
1992  snprintf(dur, sizeof(dur), "%d", i);
1993  object_set_value(spell, "spell_expiry_warn_2", dur, 1);
1994  }
1995 }
1996 
2006 void check_spell_expiry(object *spell) {
2007  const char *key;
2008 
2009  if (!spell->env || !IS_PLAYER(spell->env))
2010  return;
2011 
2012  key = object_get_value(spell, "spell_expiry_warn_1");
2013  if (key != NULL) {
2014  if (spell->duration == atoi(key)) {
2016  "The effects of your %s are draining out.", spell->name);
2017  return;
2018  }
2019  }
2020  key = object_get_value(spell, "spell_expiry_warn_2");
2021  if (key != NULL) {
2022  if (spell->duration == atoi(key)) {
2024  "The effects of your %s are about to expire.", spell->name);
2025  return;
2026  }
2027  }
2028 }
2029 
2037 void rod_adjust(object *rod) {
2038  /*
2039  * Add 50 to both level an divisor to keep prices a little
2040  * more reasonable. Otherwise, a high level version of a
2041  * low level spell can be worth tons a money (eg, level 20
2042  * rod, level 2 spell = 10 time multiplier). This way, the
2043  * value are a bit more reasonable.
2044  */
2045  rod->value = rod->value*rod->inv->value*(rod->level+50)/(rod->inv->level+50);
2046 
2047  /*
2048  * Maxhp is used to denote how many 'charges' the rod holds
2049  * before.
2050  */
2051  rod->stats.maxhp = MAX(rod->stats.maxhp, 2)*SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
2052  rod->stats.hp = rod->stats.maxhp;
2053 }
int SP_level_wc_adjust(const object *caster, const object *spob)
Returns adjusted wc based on the caster and the spell.
Definition: spell_util.cpp:362
Error, serious thing.
Definition: logger.h:11
#define AP_UNAPPLY
Item is to be remvoed.
Definition: define.h:596
#define AT_HOLYWORD
Damage based on race and caster&#39;s god.
Definition: attack.h:99
void set_spell_skill(object *op, object *caster, object *spob, object *dest)
Utility function to assign the correct skill when casting.
Definition: spell_util.cpp:94
int dispel_rune(object *op, object *skill, int dir)
Someone is trying to disarm a rune.
Definition: rune.cpp:304
int apply_manual(object *op, object *tmp, int aflag)
Main apply handler.
Definition: apply.cpp:259
Sound-related defines.
const char * determine_god(object *op)
Determines if op worships a god.
Definition: gods.cpp:55
#define ARCH_SPELL_BUNGLE
Archetype when player bungles a spell.
Definition: object.h:596
#define MSG_TYPE_ITEM_CHANGE
Item has changed in some way.
Definition: newclient.h:681
void shuffle_attack(object *op)
This routine shuffles the attack of op to one of the ones in the list.
see doc/Developers/objects
Definition: object.h:113
#define SP_BOLT
Definition: spells.h:78
#define INS_BELOW_ORIGINATOR
Insert new object immediately below originator.
Definition: object.h:586
#define MSG_TYPE_ITEM
Item related information.
Definition: newclient.h:429
int change_skill(object *who, object *new_skill, int flag)
This changes the object&#39;s skill to new_skill.
Definition: skill_util.cpp:357
Spell-related defines: spellpath, subtypes, ...
#define SP_MAKE_MARK
Definition: spells.h:77
#define AT_COUNTERSPELL
Cancels magic spells (524288) peterm@soda.berkeley.edu.
Definition: attack.h:97
struct archetype * arch
Pointer to archetype.
Definition: object.h:424
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg)
This handles the raise dead / resurrection spells.
int min_casting_level(const object *caster, const object *spell)
This function takes a caster and spell and presents the effective level the caster needs to be to cas...
Definition: spell_util.cpp:164
#define SP_CAUSE_DISEASE
Definition: spells.h:119
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.cpp:789
Unused?
Definition: treasure.h:32
void esrv_send_item(object *pl, object *op)
Sends item&#39;s info to player.
Definition: main.cpp:354
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.cpp:58
#define SP_TOWN_PORTAL
Definition: spells.h:121
int SP_level_range_adjust(const object *caster, const object *spob)
Adjust the range of the spell based on level.
Definition: spell_util.cpp:338
#define SP_CONE
Definition: spells.h:81
#define SP_BLESS
Definition: spells.h:99
int8_t direction
Means the object is moving that way.
Definition: object.h:344
void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator)
Inserts into map a spell effect based on other_arch.
Definition: spell_util.cpp:144
#define FABS(x)
Decstations have trouble with fabs()...
Definition: define.h:22
int rndm(int min, int max)
Returns a number between min and max.
Definition: utils.cpp:162
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Basic macro to see if if ob1 can not move onto a space based on the &#39;type&#39; move_block parameter Add c...
Definition: define.h:433
See Scroll.
Definition: object.h:226
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
Cast some stat-improving spell.
#define SP_CHANGE_MAP_LIGHT
Definition: spells.h:117
#define UPD_ANIM
Definition: newclient.h:335
#define strdup_local
Definition: compat.h:29
#define AT_INTERNAL
Only used for internal calculations.
Definition: attack.h:101
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
int16_t grace
Grace.
Definition: living.h:44
#define SP_CHANGE_ABILITY
Definition: spells.h:98
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:275
See Projectile.
Definition: object.h:122
#define P_NO_MAGIC
Spells (some) can&#39;t pass this object.
Definition: map.h:230
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.cpp:1132
#define SP_MOVING_BALL
Definition: spells.h:109
No range selected.
Definition: player.h:30
int cast_bless(object *op, object *caster, object *spell_ob, int dir)
Improve statistics of some living object.
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.cpp:1818
#define SP_AURA
Definition: spells.h:120
void object_update_turn_face(object *op)
If an object with the IS_TURNABLE() flag needs to be turned due to the closest player being on the ot...
Definition: object.cpp:1317
#define MSG_TYPE_SPELL
Spell related info.
Definition: newclient.h:428
int16_t maxgrace
Maximum grace.
Definition: living.h:45
#define SPELL_GRACE
Definition: spells.h:59
int level
Definition: readable.cpp:1561
Number of statistics.
Definition: living.h:18
object * below
Pointer to the object stacked below this one.
Definition: object.h:295
#define MSG_TYPE_SPELL_FAILURE
Spell failure messages.
Definition: newclient.h:669
void dump_spells(void)
Dumps all the spells - now also dumps skill associated with the spell.
Definition: spell_util.cpp:108
#define SP_ANIMATE_WEAPON
Definition: spells.h:115
object * check_spell_known(object *op, const char *name)
Checks to see if player knows the spell.
Definition: spell_util.cpp:394
#define HUGE_BUF
Used for messages - some can be quite long.
Definition: define.h:37
#define SET_ANIMATION(ob, newanim)
Definition: global.h:164
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
Definition: main.cpp:359
int cast_smite_spell(object *op, object *caster, int dir, object *spell)
The priest points to a creature and causes a &#39;godly curse&#39; to descend.
#define MSG_TYPE_SPELL_INFO
random info about spell, not related to failure/success
Definition: newclient.h:675
object * more
Pointer to the rest of a large body of objects.
Definition: object.h:303
sstring slaying
Which race to do double damage to.
Definition: object.h:327
int32_t value
How much money it is worth (or contains)
Definition: object.h:360
struct Statistics statistics
Merged spell statistics.
Definition: init.cpp:229
#define PREFER_LOW
Definition: define.h:585
object * above
Pointer to the object stacked above this one.
Definition: object.h:296
See Rune.
Definition: object.h:245
See Weapon.
Definition: object.h:124
#define DIRX(xyz)
Definition: define.h:463
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
object_find_first_free_spot(archetype, mapstruct, x, y) works like object_find_free_spot(), but it will search max number of squares.
Definition: object.cpp:3584
#define FLAG_CONFUSED
Will also be unable to cast spells.
Definition: define.h:299
int cast_word_of_recall(object *op, object *caster, object *spell_ob)
Word of recall causes the player to return &#39;home&#39;.
#define MSG_TYPE_SKILL_MISSING
Don&#39;t have the skill.
Definition: newclient.h:623
See Rod.
Definition: object.h:114
int16_t y
Position in the map for this object.
Definition: object.h:335
#define SPELL_WONDER
Definition: spells.h:163
sstring add_refcount(sstring str)
Like add_string(), but the string is already a shared string.
Definition: shstr.cpp:224
#define PATH_TIME_MULT(op, spell)
Multiplier for the casting time based on path attenuation.
Definition: spells.h:152
#define OUT_OF_REAL_MAP(M, X, Y)
Checks if a square is out of the map.
Definition: map.h:220
Misc items.
Definition: player.h:33
#define TRUE
Definition: compat.h:11
int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop)
Returns true if it is ok to put spell op on the space/may provided.
Definition: spell_util.cpp:530
int16_t duration
Number of moves (see &#39;speed&#39;) spell lasts.
Definition: object.h:415
void draw_magic_map(object *pl)
Creates and sends magic map to player.
Definition: info.cpp:475
#define FALSE
Definition: compat.h:14
#define MAX(x, y)
Definition: compat.h:24
void object_set_owner(object *op, object *owner)
Sets the owner and sets the skill and exp pointers to owner&#39;s current skill and experience objects...
Definition: object.cpp:825
int create_bomb(object *op, object *caster, int dir, object *spell)
Create a bomb.
int cast_item_curse_or_bless(object *op, object *spell_ob)
This alters player&#39;s marked item&#39;s cursed or blessed status, based on the spell_ob&#39;s fields...
int16_t x
Definition: object.h:335
uint32_t path_repelled
Paths the object is repelled from.
Definition: object.h:354
#define FLAG_REFLECTING
Object reflects from walls (lightning)
Definition: define.h:249
#define SP_CREATE_MISSILE
Definition: spells.h:113
Global type definitions and header inclusions.
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
int recharge(object *op, object *caster, object *spell_ob)
Recharge wands.
#define SP_HEALING
Definition: spells.h:95
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Sends message to player(s).
Definition: main.cpp:308
int SP_level_duration_adjust(const object *caster, const object *spob)
Adjust the duration of the spell based on level.
Definition: spell_util.cpp:312
See Wand & Staff.
Definition: object.h:225
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:425
static void handle_spell_confusion(object *op)
This does a random effect for op, which tried to cast a spell in a confused state.
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:271
#define MSG_TYPE_VICTIM_SPELL
Someone cast a bad spell on the player.
Definition: newclient.h:692
tag_t * spell_tags
Tags used for spell effect merging.
Definition: object.h:446
#define SP_WORD_OF_RECALL
Definition: spells.h:92
void set_attr_value(living *stats, int attr, int8_t value)
Sets Str/Dex/con/Wis/Cha/Int/Pow in stats to value, depending on what attr is (STR to POW)...
Definition: living.cpp:218
archetype * try_find_archetype(const char *name)
Definition: assets.cpp:274
#define DIRY(xyz)
Definition: define.h:464
int cast_cone(object *op, object *caster, int dir, object *spell)
Casts a cone spell.
int32_t weight
Attributes of the object.
Definition: object.h:375
static void transmute_item_to_flower(object *op)
This transforms one random item of op to a flower.
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Create food.
void spell_failure(object *op, int failure, int power, object *skill)
Handles the various effects for differing degrees of failure badness.
object * find_applied_skill_by_name(const object *op, const char *name)
Find a skill by name using the last_skill_ob list.
Definition: living.cpp:1932
void check_bullet(object *op)
Checks to see what op should do, given the space it is on (eg, explode, damage player, etc).
#define NDI_NAVY
Definition: newclient.h:248
#define LOOSE_MANA
Definition: spells.h:162
rangetype shoottype
Which range-attack is being used by player.
Definition: player.h:114
int get_cleric_chance(int stat)
Definition: living.cpp:2381
void esrv_del_item(player *pl, object *ob)
Tells the client to delete an item.
Definition: main.cpp:381
AssetsManager * getManager()
Definition: assets.cpp:309
int probe(object *op, object *caster, object *spell_ob, int dir, int level)
Try to get information about a living thing.
int change_abil(object *op, object *tmp)
Permanently alters an object&#39;s stats/flags based on another object.
Definition: living.cpp:394
method_ret ob_process(object *op)
Processes an object, giving it the opportunity to move or react.
Definition: ob_methods.cpp:67
int16_t level
Level of creature or object.
Definition: object.h:361
int spell_find_dir(mapstruct *m, int x, int y, object *exclude)
Search what direction a spell should go in, first the center square then some close squares in the gi...
Definition: spell_util.cpp:887
object * spell
Spell that was being cast.
Definition: object.h:420
object * object_decrease_nrof(object *op, uint32_t i)
Decreases a specified number from the amount of an object.
Definition: object.cpp:2661
int16_t sp
Spell points.
Definition: living.h:42
#define AT_GODPOWER
Adds relevant god&#39;s attacktype (1048576) peterm@soda.berkeley.edu.
Definition: attack.h:98
int cast_curse(object *op, object *caster, object *spell_ob, int dir)
Curse an object, reducing its statistics.
int fire_swarm(object *op, object *caster, object *spell, int dir)
The following routine creates a swarm of objects.
#define SP_PERCEIVE_SELF
Definition: spells.h:91
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Splits a string delimited by passed in sep value into characters into an array of strings...
Definition: utils.cpp:473
int16_t casting_time
Time left before spell goes off.
Definition: object.h:414
See Shooting Weapon.
Definition: object.h:123
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Scales the spellpoint cost of a spell by it&#39;s increased effectiveness.
Definition: spell_util.cpp:236
#define SP_BULLET
Definition: spells.h:79
#define FLAG_ALIVE
Object can fight (or be fought)
Definition: define.h:217
void confuse_living(object *op, object *hitter, int dam)
Confuse a living thing.
Definition: attack.cpp:2315
#define AP_IGNORE_CURSE
Apply/unapply regardless of cursed/damned status.
Definition: define.h:603
#define FLAG_REFL_SPELL
Spells (some) will reflect from object.
Definition: define.h:262
int cast_create_obj(object *op, object *new_op, int dir)
Creates object new_op in direction dir or if that is blocked, beneath the player (op).
Definition: spell_util.cpp:494
#define MSG_TYPE_VICTIM
Something bad is happening to the player.
Definition: newclient.h:433
#define SP_ITEM_CURSE_BLESS
Definition: spells.h:123
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
This calls the appropriate treasure creation function.
Definition: treasure.cpp:287
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell)
Fires an archetype.
Definition: spell_util.cpp:629
#define SP_MOOD_CHANGE
Definition: spells.h:108
int summon_hostile_monsters(object *op, int n, const char *monstername)
Summons hostile monsters and places them in nearby squares.
#define MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN
Protections in this.
Definition: newclient.h:583
int8_t range
Range of the spell.
Definition: object.h:417
float speed
Frequency of object &#39;moves&#39; relative to server tick rate.
Definition: object.h:337
int16_t encumbrance
How much our player is encumbered.
Definition: player.h:198
static int can_be_transmuted_to_flower(object *op)
Determines if an item can be transmuted after a cast failure.
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.cpp:227
object * create_archetype(const char *name)
Finds which archetype matches the given name, and returns a new object containing a copy of the arche...
Definition: arch.cpp:276
static bool IS_PLAYER(object *op)
Definition: object.h:611
#define SP_BOMB
Definition: spells.h:82
object * env
Pointer to the object which is the environment.
Definition: object.h:301
#define SET_FLAG(xyz, p)
Definition: define.h:384
#define QUERY_FLAG(xyz, p)
Definition: define.h:386
int8_t Wis
Use
Definition: living.h:36
sstring anim_suffix
Used to determine combined animations.
Definition: object.h:324
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:637
#define MSG_TYPE_ATTRIBUTE
Changes to attributes (stats, resistances, etc)
Definition: newclient.h:421
#define SP_WONDER
Definition: spells.h:83
void query_name(const object *op, char *buf, size_t size)
Describes an item.
Definition: item.cpp:594
int perceive_self(object *op)
Living thing wants to know information.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.cpp:1545
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.cpp:299
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:700
Control golem.
Definition: player.h:34
int pets_summon_golem(object *op, object *caster, int dir, object *spob)
Summons a monster.
Definition: pets.cpp:664
int cast_light(object *op, object *caster, object *spell, int dir)
Illuminates something on a map, or try to blind a living thing.
object * head
Points to the main object of a large body.
Definition: object.h:304
#define MSG_TYPE_SPELL_ERROR
Spell failure messages.
Definition: newclient.h:672
This is a game-map.
Definition: map.h:320
Definition: object.h:150
int caster_level(const object *caster, const object *spell)
This function returns the effective level the spell is being cast at.
Definition: spell_util.cpp:194
void get_search_arr(int *search_arr)
New function to make monster searching more efficient, and effective! This basically returns a random...
Definition: object.cpp:3627
int write_mark(object *op, object *spell, const char *msg)
This writes a rune that contains the appropriate message.
uint8_t range_modifier
How going up in level affects range.
Definition: object.h:418
#define OB_SPELL_TAG_MATCH(op, count)
Check whether a tag matches in the tags.
Definition: object.h:95
#define SP_SMITE
Definition: spells.h:84
Archetypes * archetypes()
Get archetypes.
Definition: AssetsManager.h:44
sstring object_get_value(const object *op, const char *const key)
Get an extra value by key.
Definition: object.cpp:4331
#define SP_ALCHEMY
Definition: spells.h:104
const Face * face
Face with colors.
Definition: object.h:341
object * find_random_spell_in_ob(object *ob, const char *skill)
This returns a random spell from &#39;ob&#39;.
Definition: spell_util.cpp:48
#define AP_NOPRINT
Don&#39;t print messages - caller will do that may be some that still print.
Definition: define.h:607
uint8_t dam_modifier
How going up in level affects damage.
Definition: object.h:419
void paralyze_living(object *op, int dam)
Paralyze a living thing.
Definition: attack.cpp:2402
#define SIZEOFFREE
Definition: define.h:155
#define P_OUT_OF_MAP
This space is outside the map.
Definition: map.h:254
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Gets the blocking state of a square.
Definition: map.h:195
See Potion.
Definition: object.h:116
#define GOD_POWER
Definition: spells.h:164
struct Settings settings
Global settings.
Definition: init.cpp:139
static void prayer_failure(object *op, int failure, int power)
Called when a player fails at casting a prayer.
#define SP_INVISIBLE
Definition: spells.h:93
#define SP_CHARGING
Definition: spells.h:102
#define MSG_TYPE_SKILL_FAILURE
Failure in using skill.
Definition: newclient.h:626
#define SP_DESTRUCTION
Definition: spells.h:90
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Check if the given object (usually a player) is standing on a battleground tile.
Definition: player.cpp:4267
int cast_detection(object *op, object *caster, object *spell)
Detect magic or invisible items.
void cast_magic_storm(object *op, object *tmp, int lvl)
This is really used mostly for spell fumbles and the like.
#define FREE_AND_CLEAR_STR(xyz)
Release the shared string, and set it to NULL.
Definition: global.h:200
int random_roll(int min, int max, const object *op, int goodbad)
Roll a random number between min and max.
Definition: utils.cpp:42
uint32_t tag_t
Object tag, unique during the whole game.
Definition: object.h:14
int16_t dam
How much damage this object does when hitting.
Definition: living.h:46
#define SP_DETECTION
Definition: spells.h:107
See Spell.
Definition: object.h:219
int cast_wonder(object *op, object *caster, int dir, object *spell_ob)
wonder is really just a spell that will likely cast another spell.
#define SP_RUNE
Definition: spells.h:76
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:609
uint32_t path_denied
Paths the object is denied access to.
Definition: object.h:355
int freedir[SIZEOFFREE]
Direction we&#39;re pointing on this spot.
Definition: object.cpp:317
int cast_invisible(object *op, object *caster, object *spell_ob)
Makes the player or character invisible.
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:218
int write_rune(object *op, object *caster, object *spell, int dir, const char *runename)
Player is attempting to write a magical rune.
Definition: rune.cpp:50
int isqrt(int n)
Compute the square root.
Definition: utils.cpp:562
living stats
Str, Con, Dex, etc.
Definition: object.h:378
int cast_consecrate(object *op, object *caster, object *spell)
A spell to make an altar your god&#39;s.
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
#define SP_SWARM
Definition: spells.h:110
int16_t invisible
How much longer the object will be invis.
Definition: object.h:370
See Magic Wall.
Definition: object.h:173
int cast_transfer(object *op, object *caster, object *spell, int dir)
This spell transfers sp from the player to another person.
#define SP_IDENTIFY
Definition: spells.h:106
#define SP_EARTH_TO_DUST
Definition: spells.h:97
float speed_left
How much speed is left to spend this round.
Definition: object.h:338
int dimension_door(object *op, object *caster, object *spob, int dir)
Teleport through some doors and space.
struct mapstruct * map
Pointer to the map in which this object is present.
Definition: object.h:305
int reflwall(mapstruct *m, int x, int y, object *sp_op)
Decides weither the (spell-)object sp_op will be reflected from the given mapsquare.
Definition: spell_util.cpp:470
int cast_destruction(object *op, object *caster, object *spell_ob)
Hit all monsters around the caster.
int SP_level_dam_adjust(const object *caster, const object *spob)
Returns adjusted damage based on the caster.
Definition: spell_util.cpp:287
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
Definition: object.cpp:305
static const flag_definition flags[]
Flag mapping.
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
Definition: define.h:753
#define SP_DIMENSION_DOOR
Definition: spells.h:87
#define SP_CHANGE_MANA
Definition: spells.h:111
object * object_find_by_type_and_name(const object *who, int type, const char *name)
Find object in inventory by type and name.
Definition: object.cpp:4093
#define SPELL_TAG_SIZE
Defines default size of the *spell_tags pointer.
Definition: object.h:83
See Player.
Definition: object.h:112
struct archetype * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:425
#define SP_CURSE
Definition: spells.h:100
struct treasurelist * randomitems
Items to be generated.
Definition: object.h:395
#define SP_POLYMORPH
Definition: spells.h:103
int tailor_god_spell(object *spellop, object *caster)
Changes the attributes of cone, smite, and ball spells as needed by the code.
Definition: gods.cpp:1223
Chaos_Attacks ATTACKS[22]
Some local definitions for shuffle_attack().
Definition: init.cpp:81
#define FLAG_ANIMATE
The object looks at archetype for faces.
Definition: define.h:229
Object structure, the core of Crossfire.
int cast_cause_disease(object *op, object *caster, object *spell, int dir)
Let&#39;s try to infect something.
#define PREFER_HIGH
Definition: define.h:584
#define FLAG_GENERATOR
Will generate type ob->stats.food.
Definition: define.h:235
int cast_heal(object *op, object *caster, object *spell, int dir)
Heals something.
static event_registration m
Definition: citylife.cpp:424
void play_sound_player_only(player *pl, int8_t sound_type, object *emitter, int dir, const char *action)
Plays a sound for specified player only.
Definition: sounds.cpp:51
#define RANDOM()
Definition: define.h:667
void rod_adjust(object *rod)
Adjusts rod attributes.
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg)
Create a missile (nonmagic - magic +4).
int mood_change(object *op, object *caster, object *spell)
This covers the various spells that change the moods of monsters - makes them angry, peaceful, friendly, etc.
#define FLAG_WIZCAST
The wizard can cast spells in no-magic area.
Definition: define.h:277
#define SP_FAERY_FIRE
Definition: spells.h:118
sstring name
The name of the object, obviously...
Definition: object.h:319
int8_t get_attr_value(const living *stats, int attr)
Gets the value of a stat.
Definition: living.cpp:313
int remove_curse(object *op, object *caster, object *spell)
This function removes the cursed/damned status on equipped items.
uint32_t nrof
Number of objects.
Definition: object.h:342
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_...
Definition: map.cpp:300
int cast_earth_to_dust(object *op, object *caster, object *spell_ob)
Basically destroys earthwalls in the area.
#define SPELL_HIGHEST
Definition: spells.h:60
int cast_change_map_lightlevel(object *op, object *spell)
This changes the light level for the entire map.
uint64_t spell_suppressions
Number of times ok_to_put_more() returned FALSE.
Definition: global.h:356
#define CLEAR_FLAG(xyz, p)
Definition: define.h:385
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:348
rangetype
What range is currently selected by the player.
Definition: player.h:28
int fire_bolt(object *op, object *caster, int dir, object *spob)
Cast a bolt-like spell.
#define SP_MAGIC_MISSILE
Definition: spells.h:85
#define FLAG_APPLIED
Object is ready for use by living.
Definition: define.h:222
char * spellarg
Optional argument when casting obj::spell.
Definition: object.h:421
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.cpp:1334
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
Recursive routine to see if we can find a path to a certain point.
Definition: object.cpp:3807
#define SP_MAGIC_MAPPING
Definition: spells.h:88
#define SP_LIGHT
Definition: spells.h:116
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
Definition: object.cpp:4484
#define SP_SUMMON_MONSTER
Definition: spells.h:101
object * inv
Pointer to the first object in the inventory.
Definition: object.h:298
#define FLAG_STARTEQUIP
Object was given to player at start.
Definition: define.h:255
#define FORCE_NAME
Definition: spells.h:169
#define AT_MAGIC
All magic spells, but not prayers (2)
Definition: attack.h:79
void drain_rod_charge(object *rod)
Drain charges from a rod.
Definition: spell_util.cpp:776
int alchemy(object *op, object *caster, object *spell_ob)
Change items to gold nuggets.
void object_copy_owner(object *op, object *clone)
Set the owner to clone&#39;s current owner and set the skill and experience objects to clone&#39;s objects (t...
Definition: object.cpp:878
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:173
#define FORCE_TRANSFORMED_ITEM
Definition: spells.h:146
static void swap_random_stats(object *op)
Randomly swaps 2 stats of op.
sstring skill
Name of the skill this object uses/grants.
Definition: object.h:329
int16_t maxsp
Max spell points.
Definition: living.h:43
uint32_t attacktype
Bitmask of attacks this object does.
Definition: object.h:352
#define FLAG_MONSTER
Will attack players.
Definition: define.h:232
#define ARCH_SPELL_BLOCKED
Archetype when a spell is blocked (unholy ground or non magic).
Definition: object.h:595
int animate_weapon(object *op, object *caster, object *spell, int dir)
Generalization of staff_to_snake().
#define MSG_TYPE_SKILL
Messages related to skill use.
Definition: newclient.h:424
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:270
Spells.
Definition: player.h:32
C function wrappers to interact with assets.
void drain_wand_charge(object *wand)
Drains a charge from a wand.
Definition: spell_util.cpp:786
static int put_a_monster(object *op, const char *monstername)
Puts a monster named monstername near by op.
Definition: spell_util.cpp:939
archetype * more
Next part of a linked object.
Definition: object.h:486
#define SP_MAGIC_WALL
Definition: spells.h:89
void check_spell_expiry(object *spell)
Checks if player should be warned of soon expiring spell.
int pets_summon_object(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
General purpose summoning function.
Definition: pets.cpp:885
object * find_target_for_friendly_spell(object *op, int dir)
This function is commonly used to find a friendly target for spells such as heal or protection or arm...
Definition: spell_util.cpp:813
int absdir(int d)
Computes an absolute direction.
Definition: object.cpp:3699
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
Definition: define.h:746
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Plays a sound on a map.
Definition: sounds.cpp:113
int32_t food
How much food in stomach.
Definition: living.h:48
object * lookup_spell_by_name(object *op, const char *spname)
Look at object &#39;op&#39; and see if they know the spell spname.
Definition: spell_util.cpp:410
void store_spell_expiry(object *spell)
Stores in the spell when to warn player of expiration.
Structure containing object statistics.
#define P_BLOCKSVIEW
This spot blocks the player&#39;s view.
Definition: map.h:229
#define SPELL_MANA
Definition: spells.h:58
#define SP_DISPEL_RUNE
Definition: spells.h:112
int16_t maxhp
Max hit points.
Definition: living.h:41
uint8_t subtype
Subtype of object.
Definition: object.h:349
uint16_t difficulty
What level the player should be to play here.
Definition: map.h:338
#define SP_ELEM_SHIELD
Definition: spells.h:124
static int spell_consume_items(object *op, const object *spell_ob)
Check if the player attempting to cast a spell has the required items, and eat those.
object * object_get_player_container(object *op)
Finds the player carrying an object.
Definition: object.cpp:592
void regenerate_rod(object *rod)
Regenerates a rod&#39;s charges.
Definition: spell_util.cpp:761
const char * sstring
Definition: sstring.h:2
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
Definition: object.cpp:2842
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Same as object_insert_in_map() except it handle separate coordinates and do a clean job preparing mul...
Definition: object.cpp:2085
tag_t count
Unique object number for this object.
Definition: object.h:307
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Object is attacked by something.
Definition: attack.cpp:1907
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Main dispatch when someone casts a spell.
void query_short_name(const object *op, char *buf, size_t size)
query_short_name(object) is similar to query_name(), but doesn&#39;t contain any information about object...
Definition: item.cpp:518
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:270
#define SP_SUMMON_GOLEM
Definition: spells.h:86
#define SOUND_TYPE_SPELL
Definition: newclient.h:350
#define SP_PROBE
Definition: spells.h:94
#define SP_CREATE_FOOD
Definition: spells.h:96
object * find_skill_by_name(object *who, const char *name)
This returns the skill pointer of the given name (the one that accumulates exp, has the level...
Definition: skill_util.cpp:209
int cast_create_town_portal(object *op, object *caster, object *spell)
This function cast the spell of town portal for op.
int cast_identify(object *op, object *caster, object *spell)
Identifies objects in the players inventory/on the ground.
object clone
An object from which to do object_copy()
Definition: object.h:487
uint8_t duration_modifier
how level modifies duration
Definition: object.h:416
#define P_NO_CLERIC
No clerical spells cast here.
Definition: map.h:241
#define SP_CONSECRATE
Definition: spells.h:114
int create_aura(object *op, object *caster, object *spell)
Create an aura spell object and put it in the player&#39;s inventory.
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
Definition: define.h:693
void apply_anim_suffix(object *who, const char *suffix)
Applies a compound animation to an object.
Definition: anim.cpp:150
int16_t hp
Hit Points.
Definition: living.h:40
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir)
Polymorph spell casting.
uint32_t path_attuned
Paths the object is attuned to.
Definition: object.h:353
int attacktype
Definition: attack.h:128
int magic_wall(object *op, object *caster, int dir, object *spell_ob)
This creates magic walls.
#define PATH_SP_MULT(op, spell)
Multiplier for spell points / grace based on the attenuation.
Definition: spells.h:36
#define SP_RAISE_DEAD
Definition: spells.h:75
void each(std::function< void(T *)> op)
Apply a function to each asset.
#define SP_REMOVE_CURSE
Definition: spells.h:105