Crossfire Server, Trunk  R20513
spell_util.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <assert.h>
22 #include <ctype.h>
23 #include <errno.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "living.h"
28 #include "object.h"
29 #include "sounds.h"
30 #include "spells.h"
31 #include "sproto.h"
32 
33 extern const char *const spell_mapping[];
34 
48 object *find_random_spell_in_ob(object *ob, const char *skill) {
49  int k = 0, s;
50 
51  FOR_INV_PREPARE(ob, tmp)
52  if (tmp->type == SPELL && (!skill || tmp->skill == skill))
53  k++;
55 
56  /* No spells, no need to progess further */
57  if (!k)
58  return NULL;
59 
60  s = RANDOM()%k;
61  FOR_INV_PREPARE(ob, tmp)
62  if (tmp->type == SPELL && (!skill || tmp->skill == skill)) {
63  if (!s)
64  return tmp;
65  else
66  s--;
67  }
69 
70  /* Should never get here, but just in case */
71  return NULL;
72 }
73 
94 void set_spell_skill(object *op, object *caster, object *spob, object *dest) {
95  if (dest->skill)
97  if (caster == op && spob->skill)
98  dest->skill = add_refcount(spob->skill);
99  else if (caster->skill)
100  dest->skill = add_refcount(caster->skill);
101 }
102 
109 void check_spells(void) {
110 #ifdef SPELL_DEBUG
111  int i;
112  archetype *at;
113 
114  LOG(llevDebug, "Checking spells...\n");
115 
116  for (at = first_archetype; at; at = at->next) {
117  if (at->clone.type == SPELL) {
118  if (at->clone.skill) {
119  for (i = 1; i < NUM_SKILLS; i++)
120  if (!strcmp(skill_names[i], at->clone.skill))
121  break;
122  if (i == NUM_SKILLS) {
123  LOG(llevError, "Spell %s has improper associated skill %s\n", at->name, at->clone.skill);
124  }
125  }
126  /* other_arch is already checked for in the loader */
127  }
128  }
129 
130  i = 0;
131  while (spell_mapping[i]) {
132  if (!find_archetype(spell_mapping[i])) {
133  LOG(llevError, "Unable to find spell mapping %s (%i)\n", spell_mapping[i], i);
134  }
135  i++;
136  }
137  LOG(llevDebug, "Checking spells completed.\n");
138 #endif
139 }
140 
146 void dump_spells(void) {
147  archetype *at;
148  int banner = 0;
149 
150  for (at = first_archetype; at; at = at->next) {
151  if (at->clone.type == SPELL) {
152  fprintf(stderr, "%s:%s:%s:%s:%d\n", at->clone.name ? at->clone.name : "null",
153  at->name, at->clone.other_arch ? at->clone.other_arch->name : "null",
154  at->clone.skill ? at->clone.skill : "null", at->clone.level);
155  }
156  }
157 
158  for (at = first_archetype; at; at = at->next) {
159  if (at->clone.type == SPELL && at->clone.path_attuned == 0) {
160  if (banner == 0) {
161  banner = 1;
162  fprintf(stderr, "Spells with no path set:\n");
163  }
164 
165  fprintf(stderr, "- %s\n", at->clone.name ? at->clone.name : "null");
166  }
167  }
168 }
169 
183 void spell_effect(object *spob, int x, int y, mapstruct *map, object *originator) {
184  if (spob->other_arch != NULL) {
185  object *effect = arch_to_object(spob->other_arch);
186  object_insert_in_map_at(effect, map, originator, 0, x, y);
187  }
188 }
189 
203 int min_casting_level(const object *caster, const object *spell) {
204  int new_level;
205 
206  if (caster->path_denied&spell->path_attuned) {
207  /* This case is not a bug, just the fact that this function is
208  * usually called BEFORE checking for path_deny. -AV
209  */
210  return 1;
211  }
212  new_level = spell->level
213  +((caster->path_repelled&spell->path_attuned) ? +2 : 0)
214  +((caster->path_attuned&spell->path_attuned) ? -2 : 0);
215  return MAX(new_level, 1);
216 }
217 
218 
233 int caster_level(const object *caster, const object *spell) {
234  int level = caster->level;
235 
236  /* If this is a player, try to find the matching skill */
237  if (caster->type == PLAYER && spell->skill) {
238  int i;
239 
240  for (i = 0; i < NUM_SKILLS; i++)
241  if (caster->contr->last_skill_ob[i]
242  && caster->contr->last_skill_ob[i]->skill == spell->skill) {
243  level = caster->contr->last_skill_ob[i]->level;
244  break;
245  }
246  }
247  /* Got valid caster level. Now adjust for attunement */
248  level += ((caster->path_repelled&spell->path_attuned) ? -2 : 0)
249  +((caster->path_attuned&spell->path_attuned) ? 2 : 0);
250 
251  /* Always make this at least 1. If this is zero, we get divide by zero
252  * errors in various places.
253  */
254  if (level < 1)
255  level = 1;
256  return level;
257 }
258 
277 int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags) {
278  int sp, grace, level = caster_level(caster, spell);
279 
281  if (spell->stats.sp && spell->stats.maxsp) {
282  sp = (int)(spell->stats.sp*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxsp)));
283  } else
284  sp = spell->stats.sp;
285 
286  sp *= PATH_SP_MULT(caster, spell);
287  if (!sp && spell->stats.sp)
288  sp = 1;
289 
290  if (spell->stats.grace && spell->stats.maxgrace) {
291  grace = (int)(spell->stats.grace*(1.0+MAX(0, (float)(level-spell->level)/(float)spell->stats.maxgrace)));
292  } else
293  grace = spell->stats.grace;
294 
295  grace *= PATH_SP_MULT(caster, spell);
296  if (spell->stats.grace && !grace)
297  grace = 1;
298  } else {
299  sp = spell->stats.sp*PATH_SP_MULT(caster, spell);
300  if (spell->stats.sp && !sp)
301  sp = 1;
302  grace = spell->stats.grace*PATH_SP_MULT(caster, spell);
303  if (spell->stats.grace && !grace)
304  grace = 1;
305  }
306  if (flags == SPELL_HIGHEST)
307  return MAX(sp, grace);
308  else if (flags == SPELL_GRACE)
309  return grace;
310  else if (flags == SPELL_MANA)
311  return sp;
312  else {
313  LOG(llevError, "SP_level_spellpoint_cost: Unknown flags passed: %d\n", flags);
314  return 0;
315  }
316 }
317 
328 int SP_level_dam_adjust(const object *caster, const object *spob) {
329  int level = caster_level(caster, spob);
330  int adj = level-min_casting_level(caster, spob);
331 
332  if (adj < 0)
333  adj = 0;
334  if (spob->dam_modifier)
335  adj /= spob->dam_modifier;
336  else
337  adj = 0;
338  return adj;
339 }
340 
353 int SP_level_duration_adjust(const object *caster, const object *spob) {
354  int level = caster_level(caster, spob);
355  int adj = level-min_casting_level(caster, spob);
356 
357  if (adj < 0)
358  adj = 0;
359  if (spob->duration_modifier)
360  adj /= spob->duration_modifier;
361  else
362  adj = 0;
363 
364  return adj;
365 }
366 
379 int SP_level_range_adjust(const object *caster, const object *spob) {
380  int level = caster_level(caster, spob);
381  int adj = level-min_casting_level(caster, spob);
382 
383  if (adj < 0)
384  adj = 0;
385  if (spob->range_modifier)
386  adj /= spob->range_modifier;
387  else
388  adj = 0;
389 
390  return adj;
391 }
392 
403 int SP_level_wc_adjust(const object *caster, const object *spob) {
404  int level = caster_level(caster, spob);
405  int adj = level - min_casting_level(caster, spob), irate;
406  sstring rate;
407 
408  rate = object_get_value(spob, "wc_increase_rate");
409 
410  if (rate == NULL)
411  return 0;
412 
413  if (adj < 0)
414  adj = 0;
415 
416  irate = atoi(rate);
417  if (irate > 0)
418  adj /= irate;
419  else
420  adj = 0;
421  return adj;
422 }
423 
435 object *check_spell_known(object *op, const char *name) {
436  return object_find_by_type_and_name(op, SPELL, name);
437 }
438 
451 object *lookup_spell_by_name(object *op, const char *spname) {
452  object *spob1 = NULL, *spob2 = NULL;
453  int nummatch = 0;
454 
455  if (spname == NULL)
456  return NULL;
457 
458  /* Try to find the spell. We store the results in spob1
459  * and spob2 - spob1 is only taking the length of
460  * the past spname, spob2 uses the length of the spell name.
461  */
462  FOR_INV_PREPARE(op, spob) {
463  if (spob->type == SPELL) {
464  if (!strncmp(spob->name, spname, strlen(spname))) {
465  if (strlen(spname) == strlen(spob->name))
466  /* Perfect match, return it. */
467  return spob;
468  nummatch++;
469  spob1 = spob;
470  } else if (!strncmp(spob->name, spname, strlen(spob->name))) {
471  /* if spells have ambiguous names, it makes matching
472  * really difficult. (eg, fire and fireball would
473  * fall into this category). It shouldn't be hard to
474  * make sure spell names don't overlap in that fashion.
475  */
476  if (spob2)
477  LOG(llevError, "Found multiple spells with overlapping base names: %s, %s\n", spob2->name, spob->name);
478  spob2 = spob;
479  }
480  }
481  } FOR_INV_FINISH();
482  /* if we have best match, return it. Otherwise, if we have one match
483  * on the loser match, return that, otehrwise null
484  */
485  if (spob2)
486  return spob2;
487  if (spob1 && nummatch == 1)
488  return spob1;
489  return NULL;
490 }
491 
511 int reflwall(mapstruct *m, int x, int y, object *sp_op) {
512  if (OUT_OF_REAL_MAP(m, x, y))
513  return 0;
514  FOR_MAP_PREPARE(m, x, y, op)
515  if (QUERY_FLAG(op, FLAG_REFL_SPELL)
516  && (!QUERY_FLAG(op, FLAG_ALIVE) || (rndm(0, 99)) < 90-(sp_op->level/10)))
517  return 1;
518  FOR_MAP_FINISH();
519  return 0;
520 }
521 
535 int cast_create_obj(object *op, object *new_op, int dir) {
536  mapstruct *m;
537  int16_t sx, sy;
538 
539  if (dir
540  && ((get_map_flags(op->map, &m, op->x+freearr_x[dir], op->y+freearr_y[dir], &sx, &sy)&P_OUT_OF_MAP)
541  || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, sx, sy)))) {
543  "Something is in the way. You cast it at your feet.");
544  dir = 0;
545  }
546  if (dir == 0)
547  object_insert_in_map_at(new_op, op->map, op, INS_BELOW_ORIGINATOR, op->x+freearr_x[dir], op->y+freearr_y[dir]);
548  else
549  object_insert_in_map_at(new_op, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
550  return dir;
551 }
552 
571 int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop) {
572  int mflags;
573  mapstruct *mp;
574 
575  mp = m;
576  mflags = get_map_flags(m, &mp, x, y, &x, &y);
577 
578  if (mflags&P_OUT_OF_MAP)
579  return 0;
580 
581  if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(mp, x, y)))
582  return 0;
583 
584  FOR_MAP_PREPARE(mp, x, y, tmp) {
585  /* If there is a counterspell on the space, and this
586  * object is using magic, don't progess. I believe we could
587  * leave this out and let in progress, and other areas of the code
588  * will then remove it, but that would seem to to use more
589  * resources, and may not work as well if a player is standing
590  * on top of a counterwall spell (may hit the player before being
591  * removed.) On the other hand, it may be more dramatic for the
592  * spell to actually hit the counterwall and be sucked up.
593  */
594  if ((tmp->attacktype&AT_COUNTERSPELL)
595  && (tmp->type != PLAYER)
596  && !QUERY_FLAG(tmp, FLAG_MONSTER)
597  && (tmp->type != WEAPON)
598  && (tmp->type != BOW)
599  && (tmp->type != ARROW)
600  && (tmp->type != GOLEM)
601  && (immune_stop&AT_MAGIC))
602  return 0;
603 
604  /* This is to prevent 'out of control' spells. Basically, this
605  * limits one spell effect per space per spell. This is definitely
606  * needed for performance reasons, and just for playability I believe.
607  * there are no such things as multispaced spells right now, so
608  * we don't need to worry about the head.
609  * We only need to go down this path is maxhp is set on both objects -
610  * otherwise, no reason to check. But if we do check, we need to
611  * do some extra work, looking in the spell_tags[] of each object,
612  * if they have it set.
613  */
614  if (tmp->type == op->type
615  && tmp->subtype == op->subtype
616  && tmp->stats.maxhp
617  && op->stats.maxhp) {
618  if ((tmp->stats.maxhp == op->stats.maxhp)
619  || (tmp->spell_tags && OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp))
620  || (op->spell_tags && OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp))) {
622  return 0;
623  }
624 
625  /* if both objects have spell tags, then if the two tags entries
626  * from either match, that also counts. Need to check
627  * the spell_tags, because 0 values are allowed to match
628  */
629  if (op->spell_tags && tmp->spell_tags) {
630  int i;
631 
632  for (i = 0; i < SPELL_TAG_SIZE; i++) {
633  if (op->spell_tags[i] &&
634  op->spell_tags[i] == tmp->spell_tags[i]) {
636  return 0;
637  }
638  }
639  }
640  }
641  /* Perhaps we should also put checks in for no magic and unholy
642  * ground to prevent it from moving along?
643  */
644  } FOR_MAP_FINISH();
645  /* If it passes the above tests, it must be OK */
646  return 1;
647 }
648 
672 int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell) {
673  object *tmp;
674  int mflags;
675  mapstruct *m;
676 
677  if (dir < 0 || dir > 8) {
678  LOG(llevError, "Invalid direction %d in fire_arch_from_position for %s\n", dir, spell->name);
679  dir = RANDOM() % 8 + 1;
680  }
681 
682  if (spell->other_arch == NULL)
683  return 0;
684 
685  if (spell->type != SPELL)
686  LOG(llevError, "Unexpected object type %d in fire_arch_from_position for %s\n", spell->type, spell->name);
687 
688  m = op->map;
689  mflags = get_map_flags(m, &m, x, y, &x, &y);
690  if (mflags&P_OUT_OF_MAP) {
691  return 0;
692  }
693 
694  tmp = arch_to_object(spell->other_arch);
695  if (tmp == NULL)
696  return 0;
697 
698  mflags = get_map_flags(m, &tmp->map, x, y, &tmp->x, &tmp->y);
699  if (mflags&P_OUT_OF_MAP) {
701  return 0;
702  }
703 
704  if (spell->subtype == SP_BULLET) {
705  /* peterm: level dependency for bolts */
706  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
707  tmp->attacktype = spell->attacktype;
708  if (spell->slaying)
709  tmp->slaying = add_refcount(spell->slaying);
710 
711  tmp->range = 50;
712 
713  /* Need to store duration/range for the ball to use */
714  tmp->stats.hp = spell->duration+SP_level_duration_adjust(caster, spell);
715  tmp->stats.maxhp = spell->range+SP_level_range_adjust(caster, spell);
716  tmp->dam_modifier = spell->stats.food+SP_level_dam_adjust(caster, spell);
717 
718  tmp->direction = dir;
720 
721  object_set_owner(tmp, op);
722  } else {
723  if (spell->subtype != SP_MAGIC_MISSILE && spell->subtype != SP_MOVING_BALL)
724  LOG(llevError, "Unexpected object subtype %d in fire_arch_from_position for %s\n", spell->subtype, spell->name);
725 
726  /*
727  * Things like firewalls and such can fire even if blocked, since the
728  * origin is themselves which block things...
729  * This fixes bug #3536508.
730  */
731  if (caster->type == PLAYER && OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
733  "You can't cast the spell on top of a wall!");
735  return 0;
736  }
737 
738  tmp->stats.dam = spell->stats.dam+SP_level_dam_adjust(caster, spell);
739  tmp->duration = spell->duration+SP_level_duration_adjust(caster, spell);
740  /* code in time.c uses food for some things, duration for others */
741  tmp->stats.food = tmp->duration;
742  tmp->range = spell->range+SP_level_range_adjust(caster, spell);
743  tmp->attacktype = spell->attacktype;
744  if (object_get_owner(op) != NULL)
745  object_copy_owner(tmp, op);
746  else
747  object_set_owner(tmp, op);
748  tmp->level = caster_level(caster, spell);
749  }
750 
751  tmp->direction = dir;
752  set_spell_skill(op, caster, spell, tmp);
753 
754  if (spell->subtype == SP_BULLET) {
755  if (OB_TYPE_MOVE_BLOCK(tmp, GET_MAP_MOVE_BLOCK(tmp->map, tmp->x, tmp->y))) {
756  if (!QUERY_FLAG(tmp, FLAG_REFLECTING)) {
758  return 0;
759  }
760  tmp->direction = absdir(tmp->direction+4);
761  x += DIRX(tmp);
762  y += DIRY(tmp);
763  mflags = get_map_flags(m, &m, x, y, &x, &y);
764  if (mflags&P_OUT_OF_MAP) {
766  return 0;
767  }
768  tmp->x = x;
769  tmp->y = y;
770  tmp->map = m;
771  }
772 
773  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
774  if (tmp != NULL)
775  check_bullet(tmp);
776  } else /*if (spell->subtype == SP_MAGIC_MISSILE || spell->subtype == SP_MOVING_BALL) */ {
777  /* needed for AT_HOLYWORD, AT_GODPOWER stuff */
778  if (tmp->attacktype&AT_HOLYWORD || tmp->attacktype&AT_GODPOWER) {
779  if (!tailor_god_spell(tmp, op))
780  return 0;
781  }
783 
784  tmp = object_insert_in_map_at(tmp, tmp->map, op, 0, tmp->x, tmp->y);
785  if (tmp != NULL)
786  ob_process(tmp);
787  }
788 
789  return 1;
790 }
791 
792 /*****************************************************************************
793  *
794  * Code related to rods - perhaps better located in another file?
795  *
796  ****************************************************************************/
797 
804 void regenerate_rod(object *rod) {
805  if (rod->stats.hp < rod->stats.maxhp) {
806  rod->stats.hp += 1+rod->stats.maxhp/10;
807 
808  if (rod->stats.hp > rod->stats.maxhp)
809  rod->stats.hp = rod->stats.maxhp;
810  }
811 }
812 
819 void drain_rod_charge(object *rod) {
820  rod->stats.hp -= SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
821 }
822 
829 void drain_wand_charge(object *wand) {
830  assert(wand->type == WAND);
831 
832  if (!(--wand->stats.food)) {
833  object *tmp;
834  if (wand->arch) {
835  CLEAR_FLAG(wand, FLAG_ANIMATE);
836  wand->face = wand->arch->clone.face;
837  wand->speed = 0;
838  object_update_speed(wand);
839  }
840  tmp = object_get_player_container(wand);
841  if (tmp)
842  esrv_update_item(UPD_ANIM, tmp, wand);
843  }
844 }
845 
856 object *find_target_for_friendly_spell(object *op, int dir) {
857  object *tmp;
858  mapstruct *m;
859  int16_t x, y;
860  int mflags;
861 
862  /* I don't really get this block - if op isn't a player or rune,
863  * we then make the owner of this object the target.
864  * The owner could very well be no where near op.
865  */
866  if (op->type != PLAYER && op->type != RUNE) {
867  tmp = object_get_owner(op);
868  /* If the owner does not exist, or is not a monster, than apply the spell
869  * to the caster.
870  */
871  if (!tmp || !QUERY_FLAG(tmp, FLAG_MONSTER))
872  tmp = op;
873  } else {
874  m = op->map;
875  x = op->x+freearr_x[dir];
876  y = op->y+freearr_y[dir];
877 
878  mflags = get_map_flags(m, &m, x, y, &x, &y);
879 
880  if (mflags&P_OUT_OF_MAP)
881  tmp = NULL;
882  else {
883  for (tmp = GET_MAP_OB(m, x, y); tmp != NULL; tmp = tmp->above) {
884  if (tmp->type == PLAYER)
885  break;
886  }
887  }
888  }
889  /* didn't find a player there, look in current square for a player */
890  if (tmp == NULL)
891  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
892  if (tmp->type == PLAYER)
893  return tmp;
894  /* Don't forget to browse inside transports ! - gros 2006/07/25 */
895  if (tmp->type == TRANSPORT) {
896  object *inv;
897 
898  for (inv = tmp->inv; inv; inv = inv->below) {
899  if ((inv->type == PLAYER) && (op == inv))
900  return inv;
901  }
902  }
903  } FOR_MAP_FINISH();
904  return tmp;
905 }
906 
907 
908 
929 int spell_find_dir(mapstruct *m, int x, int y, object *exclude) {
930  int i;
931  int16_t nx, ny;
932  int owner_type = 0, mflags;
933  object *tmp;
934  mapstruct *mp;
935  int dirs[SIZEOFFREE];
936 
937  if (exclude != NULL) {
938  exclude = HEAD(exclude);
939  owner_type = exclude->type;
940  }
941 
942  get_search_arr(dirs);
943  for (i = 1; i < SIZEOFFREE; i++) {
944  nx = x+freearr_x[dirs[i]];
945  ny = y+freearr_y[dirs[i]];
946  mp = m;
947  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
948  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
949  continue;
950 
951  for (tmp = GET_MAP_OB(mp, nx, ny); tmp != NULL; tmp = tmp->above) {
952  object *head;
953 
954  head = HEAD(tmp);
955  if ((owner_type != PLAYER || QUERY_FLAG(head, FLAG_MONSTER) || QUERY_FLAG(head, FLAG_GENERATOR) || (head->type == PLAYER && op_on_battleground(head, NULL, NULL, NULL)))
956  && (owner_type == PLAYER || head->type == PLAYER)
957  && head != exclude
958  && can_see_monsterP(m, x, y, dirs[i])) {
959  return freedir[dirs[i]];
960  }
961  }
962  }
963  return -1; /* flag for "keep going the way you were" */
964 }
965 
966 
967 
981 static int put_a_monster(object *op, const char *monstername) {
982  object *tmp, *head = NULL, *prev = NULL;
983  archetype *at;
984  int dir;
985 
986  /* Handle cases where we are passed a bogus mosntername */
987  at = find_archetype(monstername);
988  if (at == NULL)
989  return 0;
990 
991  /* find a free square nearby
992  * first we check the closest square for free squares
993  */
994 
995  dir = object_find_first_free_spot(&at->clone, op->map, op->x, op->y);
996  if (dir != -1) {
997  /* This is basically grabbed for generate monster. Fixed 971225 to
998  * insert multipart monsters properly
999  */
1000  while (at != NULL) {
1001  tmp = arch_to_object(at);
1002  tmp->x = op->x+freearr_x[dir]+at->clone.x;
1003  tmp->y = op->y+freearr_y[dir]+at->clone.y;
1004  tmp->map = op->map;
1005  if (head) {
1006  tmp->head = head;
1007  prev->more = tmp;
1008  }
1009  if (!head)
1010  head = tmp;
1011  prev = tmp;
1012  at = at->more;
1013  }
1014 
1015  if (head->randomitems)
1016  create_treasure(head->randomitems, head, GT_INVISIBLE, op->map->difficulty, 0);
1017 
1018  object_insert_in_map_at(head, op->map, op, 0, op->x, op->y);
1019 
1020  /* thought it'd be cool to insert a burnout, too.*/
1021  tmp = create_archetype("burnout");
1022  object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[dir], op->y+freearr_y[dir]);
1023  return 1;
1024  } else {
1025  return 0;
1026  }
1027 }
1028 
1047 int summon_hostile_monsters(object *op, int n, const char *monstername) {
1048  int i, put = 0;
1049 
1050  for (i = 0; i < n; i++)
1051  put += put_a_monster(op, monstername);
1052 
1053  return put;
1054 }
1055 
1056 
1081 void shuffle_attack(object *op, int change_face) {
1082  int i;
1083 
1084  i = rndm(0, 21);
1086  if (change_face) {
1087  SET_ANIMATION(op, ATTACKS[i].face);
1088  }
1089 }
1090 
1091 
1102 static void prayer_failure(object *op, int failure, int power) {
1103  const char *godname;
1104  object *tmp;
1105 
1106  godname = determine_god(op);
1107  if (!strcmp(godname, "none"))
1108  godname = "Your spirit";
1109 
1110  if (failure <= -20 && failure > -40) { /* wonder */
1112  "%s gives a sign to renew your faith.",
1113  godname);
1115  cast_cone(op, op, 0, tmp);
1117  } else if (failure <= -40 && failure > -60) { /* confusion */
1119  "Your diety touches your mind!");
1120  confuse_living(op, op, 99);
1121  } else if (failure <= -60 && failure > -150) { /* paralysis */
1123  "%s requires you to pray NOW. You comply, ignoring all else.",
1124  godname);
1125 
1126  paralyze_living(op, 99);
1127  } else if (failure <= -150) { /* blast the immediate area */
1128  tmp = create_archetype(GOD_POWER);
1130  "%s smites you!",
1131  godname);
1132  /* Put a cap on power - this is effectively cost of the spell minus
1133  * characters current grace. Thus, if spell costs 30 grace and
1134  * character has -100 grace, this is cast as a level 130 spell.
1135  * Things start to break in those cases.
1136  */
1137  cast_magic_storm(op, tmp, power > 50 ? 50 : power);
1138  }
1139 }
1140 
1153 void spell_failure(object *op, int failure, int power, object *skill) {
1154  object *tmp;
1155 
1157  return;
1158 
1159  if (failure <= -20 && failure > -40) { /* wonder */
1161  "Your spell causes an unexpected effect.");
1163  cast_cone(op, op, 0, tmp);
1165  } else if (failure <= -40 && failure > -60) { /* confusion */
1167  "Your magic recoils on you, making you confused!");
1168  confuse_living(op, op, 99);
1169  } else if (failure <= -60 && failure > -80) { /* paralysis */
1171  "Your magic stuns you!");
1172  paralyze_living(op, 99);
1173  } else if (failure <= -80) { /* blast the immediate area */
1174  object *tmp;
1175 
1176  /* Safety check to make sure we don't get any mana storms in scorn */
1177  if (get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL)&P_NO_MAGIC) {
1179  "The magic warps and you are turned inside out!");
1180  hit_player(op, 9998, op, AT_INTERNAL, 1);
1181  } else {
1183  "You lose control of the mana! The uncontrolled magic blasts you!");
1185  tmp->level = skill->level;
1186 
1187  /* increase the area of destruction a little for more powerful spells */
1188  tmp->range += isqrt(power);
1189 
1190  if (power > 25)
1191  tmp->stats.dam = 25+isqrt(power);
1192  else
1193  tmp->stats.dam = power; /* nasty recoils! */
1194 
1195  tmp->stats.maxhp = tmp->count;
1196  if (tmp->stats.maxhp == 0)
1197  tmp->stats.maxhp = 1;
1198  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
1199  }
1200  }
1201 }
1202 
1211 static int can_be_transmuted_to_flower(object *op) {
1212  if (op->invisible)
1213  return 0;
1214 
1215  if (op->type == POTION || op->type == SCROLL || op->type == WAND || op->type == ROD || op->type == WEAPON)
1216  return 1;
1217 
1218  return 0;
1219 }
1220 
1233 static void transmute_item_to_flower(object *op) {
1234  object *force;
1235  object *item;
1236  object *flower;
1237  object *first = NULL;
1238  int count = 0;
1239  char name[HUGE_BUF];
1240 
1241  FOR_INV_PREPARE(op, item)
1242  if (can_be_transmuted_to_flower(item)) {
1243  if (!first)
1244  first = item;
1245  count++;
1246  }
1247  FOR_INV_FINISH();
1248 
1249  if (count == 0)
1250  return;
1251 
1252  count = rndm(0, count-1);
1253  for (item = first; item; item = item->below) {
1254  if (can_be_transmuted_to_flower(item)) {
1255  count--;
1256  if (count < 0)
1257  break;
1258  }
1259  }
1260 
1261  if (!item)
1262  return;
1263 
1264  force = create_archetype(FORCE_NAME);
1265  force->duration = 100+rndm(0, 10)*100;
1267  force->speed = 1;
1268  object_update_speed(force);
1269 
1270  flower = create_archetype("flowers_permanent");
1271 
1272  if (QUERY_FLAG(item, FLAG_APPLIED))
1274  object_remove(item);
1275  flower->weight = item->nrof ? ((int32_t)item->nrof)*item->weight : item->weight;
1276  item->weight = 0;
1277  esrv_del_item(op->contr, item);
1278  object_insert_in_ob(item, force);
1279 
1280  query_short_name(item, name, HUGE_BUF);
1283  "Your %s turns to a flower!",
1284  name);
1285 
1286  object_insert_in_ob(force, flower);
1287  flower = object_insert_in_ob(flower, op);
1288  esrv_send_item(op, flower);
1289 }
1290 
1301 static void swap_random_stats(object *op) {
1302  object *force;
1303  int first, second;
1304 
1305  first = RANDOM()%NUM_STATS;
1306  second = RANDOM()%(NUM_STATS-1);
1307  if (second >= first)
1308  second++;
1309 
1312  "You suddenly feel really weird!");
1313 
1314  force = create_archetype(FORCE_NAME);
1315  force->duration = 100+rndm(0, 10)*100;
1316  force->speed = 1;
1317  SET_FLAG(force, FLAG_APPLIED);
1318  set_attr_value(&force->stats, second, get_attr_value(&op->stats, first)-get_attr_value(&op->stats, second));
1319  set_attr_value(&force->stats, first, get_attr_value(&op->stats, second)-get_attr_value(&op->stats, first));
1320  object_update_speed(force);
1321  object_insert_in_ob(force, op);
1322  change_abil(op, force);
1323  fix_object(op);
1324 }
1325 
1336 static void handle_spell_confusion(object *op) {
1337  switch (RANDOM()%2) {
1338  case 0:
1340  break;
1341 
1342  case 1:
1343  swap_random_stats(op);
1344  break;
1345  }
1346 }
1347 
1355 static int spell_consume_items(object *op, const object *spell_ob) {
1356  sstring requirements;
1357  char *copy;
1358  char *ingredients[10];
1359  object *found[10];
1360  int count, i;
1361  uint32_t nrof[10];
1362  char name_ob[MAX_BUF];
1363  const char *name2;
1364 
1365  if (op->type != PLAYER)
1366  return 1;
1367 
1368  requirements = object_get_value(spell_ob, "casting_requirements");
1369  if (!requirements)
1370  /* no special requirements */
1371  return 1;
1372 
1373  /* find items */
1374  copy = strdup_local(requirements);
1375  count = split_string(copy, ingredients, 10, ',');
1376 
1377  /* first pass, find items */
1378  for (i = 0; i < count; i++) {
1379  nrof[i] = 0;
1380  found[i] = NULL;
1381  while (isdigit(*ingredients[i])) {
1382  nrof[i] = 10*nrof[i]+(*(ingredients[i])-'0');
1383  ingredients[i]++;
1384  }
1385  if (nrof[i] == 0)
1386  nrof[i] = 1;
1387  while (*ingredients[i] == ' ')
1388  ingredients[i]++;
1389 
1390  /* now find item in op's inv */
1391  FOR_INV_PREPARE(op, check) {
1392 
1393  if (check->title == NULL)
1394  name2 = check->name;
1395  else {
1396  snprintf(name_ob, sizeof(name_ob), "%s %s", check->name, check->title);
1397  name2 = name_ob;
1398  }
1399 
1400  if (strcmp(name2, ingredients[i]) == 0) {
1401  found[i] = check;
1402  break;
1403  }
1404  } FOR_INV_FINISH();
1405 
1406  if (found[i] == NULL) {
1409  "Casting this spell requires %s, but you don't have any.",
1410  ingredients[i]);
1411  free(copy);
1412  return 0;
1413  }
1414 
1415  if (found[i]->nrof < nrof[i]) {
1418  "Casting this spell requires %d %s, but you only have %d.",
1419  nrof[i], found[i]->name_pl, found[i]->nrof);
1420  free(copy);
1421  return 0;
1422  }
1423  }
1424 
1425  free(copy);
1426 
1427  /* ok, found ingredients, remove'em */
1428  for (i = 0; i < count; i++) {
1429  object_decrease_nrof(found[i], nrof[i]);
1430  }
1431 
1432  /* all right, spell can be cast */
1433  return 1;
1434 }
1435 
1471 int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg) {
1472  const char *godname;
1473  int success = 0, mflags, cast_level = 0;
1474  rangetype old_shoottype;
1475  object *skill = NULL;
1476  int confusion_effect = 0;
1477 
1478  old_shoottype = op->contr ? op->contr->shoottype : range_none;
1479 
1480  if (!spell_ob) {
1481  LOG(llevError, "cast_spell: null spell object passed\n");
1482  return 0;
1483  }
1484  godname = determine_god(op);
1485  if (!strcmp(godname, "none"))
1486  godname = "A random spirit";
1487 
1488  /* the caller should set caster to op if appropriate */
1489  if (!caster) {
1490  LOG(llevError, "cast_spell: null caster object passed\n");
1491  return 0;
1492  }
1493  if (spell_ob->anim_suffix)
1494  apply_anim_suffix(caster, spell_ob->anim_suffix);
1495 
1496  /* Handle some random effect if confused. */
1497  if (QUERY_FLAG(op, FLAG_CONFUSED) && caster == op && op->type == PLAYER) {
1498  if (rndm(0, 5) < 4) {
1499  spell_ob = find_random_spell_in_ob(op, NULL);
1502  "In your confused state, you're not sure of what you cast!");
1503  } else
1504  /* We fall through to deplate sp/gr, and do some checks. */
1505  confusion_effect = 1;
1506  }
1507 
1508  /* if caster is a spell casting object, this normally shouldn't be
1509  * an issue, because they don't have any spellpaths set up.
1510  */
1511  if ((caster->path_denied&spell_ob->path_attuned) && !QUERY_FLAG(caster, FLAG_WIZ)) {
1513  "That spell path is denied to you.");
1514  return 0;
1515  }
1516 
1517  /* if it is a player casting the spell, and they are really casting it
1518  * (vs it coming from a wand, scroll, or whatever else), do some
1519  * checks. We let monsters do special things - eg, they
1520  * don't need the skill, bypass level checks, etc. The monster function
1521  * should take care of that.
1522  * Remove the wiz check here and move it further down - some spells
1523  * need to have the right skill pointer passed, so we need to
1524  * at least process that code.
1525  */
1526  if (op->type == PLAYER && op == caster) {
1527  cast_level = caster_level(caster, spell_ob);
1528  if (spell_ob->skill) {
1529  skill = find_skill_by_name(op, spell_ob->skill);
1530  if (!skill) {
1533  "You need the skill %s to cast %s.",
1534  spell_ob->skill, spell_ob->name);
1535  return 0;
1536  }
1537  if (min_casting_level(op, spell_ob) > cast_level && !QUERY_FLAG(op, FLAG_WIZ)) {
1539  "You lack enough skill to cast that spell.");
1540  return 0;
1541  }
1542  }
1543  /* If the caster is the wiz, they don't ever fail, and don't have
1544  * to have sufficient grace/mana.
1545  */
1546  if (!QUERY_FLAG(op, FLAG_WIZ)) {
1547  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA)
1548  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA) > op->stats.sp) {
1550  "You don't have enough mana.");
1551  return 0;
1552  }
1553  if (SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)
1554  && SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE) > op->stats.grace) {
1555  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) {
1558  "%s grants your prayer, though you are unworthy.",
1559  godname);
1560  } else {
1561  prayer_failure(op, op->stats.grace, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE)-op->stats.grace);
1564  "%s ignores your prayer.",
1565  godname);
1566  return 0;
1567  }
1568  }
1569 
1570  /* player/monster is trying to cast the spell. might fumble it */
1571  if (spell_ob->stats.grace
1572  && random_roll(0, 99, op, PREFER_HIGH) < (get_cleric_chance(op->stats.Wis) * spell_ob->level/MAX(1, op->level))) {
1573  play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell_ob, 0, "fumble");
1575  "You fumble the spell.");
1576  if (settings.casting_time == TRUE) {
1577  op->casting_time = -1;
1578  }
1579  op->stats.grace -= random_roll(1, SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE), op, PREFER_LOW);
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) {
1586  draw_ext_info(NDI_UNIQUE, 0, op,
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);
1594  return 0;
1595  }
1596  }
1597 
1598  /* ensure the potentially required items are eaten */
1599  if (!spell_consume_items(op, spell_ob))
1600  /* already warned by the function */
1601  return 0;
1602  }
1603  }
1604 
1605  mflags = get_map_flags(op->map, NULL, op->x, op->y, NULL, NULL);
1606 
1607  /* See if we can cast a spell here. If the caster and op are
1608  * not alive, then this would mean that the mapmaker put the
1609  * objects on the space - presume that they know what they are
1610  * doing.
1611  */
1612  if (spell_ob->type == SPELL
1613  && caster->type != POTION
1614  && !QUERY_FLAG(op, FLAG_WIZCAST)
1615  && (QUERY_FLAG(caster, FLAG_ALIVE) || QUERY_FLAG(op, FLAG_ALIVE))
1616  && !QUERY_FLAG(op, FLAG_MONSTER)
1617  && (((mflags&P_NO_MAGIC) && spell_ob->stats.sp) || ((mflags&P_NO_CLERIC) && spell_ob->stats.grace))) {
1618  if (op->type != PLAYER)
1619  return 0;
1620 
1622 
1623  if ((mflags&P_NO_CLERIC) && spell_ob->stats.grace)
1625  "This ground is unholy! %s ignores you.",
1626  godname);
1627  else
1628  switch (op->contr->shoottype) {
1629  case range_magic:
1631  "Something blocks your spellcasting.");
1632  break;
1633 
1634  case range_misc:
1636  "Something blocks the magic of your item.");
1637  break;
1638  case range_golem:
1640  "Something blocks the magic of your scroll.");
1641  break;
1642 
1643  default:
1644  break;
1645  }
1646  return 0;
1647  }
1648 
1649  if (caster == op && caster->type ==PLAYER && settings.casting_time == TRUE && spell_ob->type == SPELL) {
1650  if (op->casting_time == -1) { /* begin the casting */
1651  op->casting_time = spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob);
1652  op->spell = spell_ob;
1653  /* put the stringarg into the object struct so that when the
1654  * spell is actually cast, it knows about the stringarg.
1655  * necessary for the invoke command spells.
1656  */
1657  if (stringarg) {
1658  op->spellarg = strdup_local(stringarg);
1659  } else
1660  op->spellarg = NULL;
1661  return 0;
1662  } else if (op->casting_time != 0) {
1663  if (op->type == PLAYER)
1665  "You are casting!");
1666  return 0;
1667  } else { /* casting_time == 0 */
1668  op->casting_time = -1;
1669  spell_ob = op->spell;
1670  stringarg = op->spellarg;
1671  }
1672  } else {
1673  if (!QUERY_FLAG(caster, FLAG_WIZ)) {
1674  /* Take into account how long it takes to cast the spell.
1675  * if the player is casting it, then we use the time in
1676  * the spell object. If it is a spell object, have it
1677  * take two ticks. Things that cast spells on the players
1678  * behalf (eg, altars, and whatever else) shouldn't cost
1679  * the player any time.
1680  * Ignore casting time for firewalls
1681  */
1682  if (caster == op && caster->type != FIREWALL) {
1683  op->speed_left -= spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1684  /* Other portions of the code may also decrement the speed of the player, so
1685  * put a lower limit so that the player isn't stuck here too long
1686  */
1687  if ((spell_ob->casting_time > 0)
1688  && op->speed_left < -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed))
1689  op->speed_left = -spell_ob->casting_time*PATH_TIME_MULT(op, spell_ob)*FABS(op->speed);
1690  } else if (caster->type == WAND
1691  || caster->type == ROD
1692  || caster->type == POTION
1693  || caster->type == SCROLL) {
1694  op->speed_left -= 2*FABS(op->speed);
1695  }
1696  }
1697  }
1698 
1699  if (op->type == PLAYER && op == caster && !QUERY_FLAG(caster, FLAG_WIZ)) {
1700  op->stats.grace -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_GRACE);
1701  op->stats.sp -= SP_level_spellpoint_cost(caster, spell_ob, SPELL_MANA);
1702  }
1703 
1704  /* We want to try to find the skill to properly credit exp.
1705  * for spell casting objects, the exp goes to the skill the casting
1706  * object requires.
1707  */
1708  if (op != caster && !skill && caster->skill && !QUERY_FLAG(op, FLAG_MONSTER)) {
1709  skill = find_skill_by_name(op, caster->skill);
1710  if (!skill) {
1711  char name[MAX_BUF];
1712 
1713  query_name(caster, name, MAX_BUF);
1716  "You lack the skill %s to use the %s",
1717  caster->skill, name);
1718  return 0;
1719  }
1720  change_skill(op, skill, 0); /* needed for proper exp credit */
1721  }
1722 
1723  /* Need to get proper ownership for spells cast via runes - these are not
1724  * the normal 'rune of fire', but rather the magic runes that let the player
1725  * put some other spell into the rune (glyph, firetrap, magic rune, etc)
1726  */
1727  if (caster->type == RUNE) {
1728  object *owner = object_get_owner(caster);
1729 
1730  if (owner)
1731  skill = find_skill_by_name(owner, caster->skill);
1732  }
1733 
1734  if (confusion_effect) {
1735  /* If we get here, the confusion effect was 'random effect', so do it and bail out. */
1738  "In your confused state, you can't control the magic!");
1740  return 0;
1741  }
1742 
1743  play_sound_map(SOUND_TYPE_SPELL, caster, dir, spell_ob->name);
1744 
1745  switch (spell_ob->subtype) {
1746  /* The order of case statements is same as the order they show up
1747  * in in spells.h.
1748  */
1749  case SP_RAISE_DEAD:
1750  success = cast_raise_dead_spell(op, caster, spell_ob, dir, stringarg);
1751  break;
1752 
1753  case SP_RUNE:
1754  success = write_rune(op, caster, spell_ob, dir, stringarg);
1755  break;
1756 
1757  case SP_MAKE_MARK:
1758  success = write_mark(op, spell_ob, stringarg);
1759  break;
1760 
1761  case SP_BOLT:
1762  success = fire_bolt(op, caster, dir, spell_ob);
1763  break;
1764 
1765  case SP_BULLET:
1766  success = fire_arch_from_position(op, caster, op->x+freearr_x[dir], op->y+freearr_y[dir], dir, spell_ob);
1767  break;
1768 
1769  case SP_CONE:
1770  success = cast_cone(op, caster, dir, spell_ob);
1771  break;
1772 
1773  case SP_BOMB:
1774  success = create_bomb(op, caster, dir, spell_ob);
1775  break;
1776 
1777  case SP_WONDER:
1778  success = cast_wonder(op, caster, dir, spell_ob);
1779  break;
1780 
1781  case SP_SMITE:
1782  success = cast_smite_spell(op, caster, dir, spell_ob);
1783  break;
1784 
1785  case SP_MAGIC_MISSILE:
1786  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1787  break;
1788 
1789  case SP_SUMMON_GOLEM:
1790  success = pets_summon_golem(op, caster, dir, spell_ob);
1791  if (success || op->contr == NULL)
1792  old_shoottype = range_golem;
1793  else
1794  /*
1795  * if the spell failed (something in the way for instance),
1796  * don't change the range so the player can try easily after that
1797  */
1798  old_shoottype = op->contr->shoottype;
1799  break;
1800 
1801  case SP_DIMENSION_DOOR:
1802  /* dimension door needs the actual caster, because that is what is
1803  * moved.
1804  */
1805  success = dimension_door(op, caster, spell_ob, dir);
1806  break;
1807 
1808  case SP_MAGIC_MAPPING:
1809  if (op->type == PLAYER) {
1810  spell_effect(spell_ob, op->x, op->y, op->map, op);
1811  draw_magic_map(op);
1812  success = 1;
1813  } else
1814  success = 0;
1815  break;
1816 
1817  case SP_MAGIC_WALL:
1818  success = magic_wall(op, caster, dir, spell_ob);
1819  break;
1820 
1821  case SP_DESTRUCTION:
1822  success = cast_destruction(op, caster, spell_ob);
1823  break;
1824 
1825  case SP_PERCEIVE_SELF:
1826  success = perceive_self(op);
1827  break;
1828 
1829  case SP_WORD_OF_RECALL:
1830  success = cast_word_of_recall(op, caster, spell_ob);
1831  break;
1832 
1833  case SP_INVISIBLE:
1834  success = cast_invisible(op, caster, spell_ob);
1835  break;
1836 
1837  case SP_PROBE:
1838  if (op != caster)
1839  cast_level = caster->level;
1840  else
1841  cast_level = skill != NULL ? skill->level : op->level;
1842  success = probe(op, caster, spell_ob, dir, cast_level);
1843  break;
1844 
1845  case SP_HEALING:
1846  success = cast_heal(op, caster, spell_ob, dir);
1847  break;
1848 
1849  case SP_CREATE_FOOD:
1850  success = cast_create_food(op, caster, spell_ob, dir, stringarg);
1851  break;
1852 
1853  case SP_EARTH_TO_DUST:
1854  success = cast_earth_to_dust(op, caster, spell_ob);
1855  break;
1856 
1857  case SP_CHANGE_ABILITY:
1858  success = cast_change_ability(op, caster, spell_ob, dir, 0);
1859  break;
1860 
1861  case SP_BLESS:
1862  success = cast_bless(op, caster, spell_ob, dir);
1863  break;
1864 
1865  case SP_CURSE:
1866  success = cast_curse(op, caster, spell_ob, dir);
1867  break;
1868 
1869  case SP_SUMMON_MONSTER:
1870  success = pets_summon_object(op, caster, spell_ob, dir, stringarg);
1871  break;
1872 
1873  case SP_CHARGING:
1874  success = recharge(op, caster, spell_ob);
1875  break;
1876 
1877  case SP_POLYMORPH:
1878 #if 0
1879  /* Not great, but at least provide feedback so if players do have
1880  * polymorph (ie, find it as a preset item or left over from before
1881  * it was disabled), they get some feedback.
1882  */
1884  "The spell fizzles");
1885  success = 0;
1886 #else
1887  success = cast_polymorph(op, caster, spell_ob, dir);
1888 #endif
1889  break;
1890 
1891  case SP_ALCHEMY:
1892  success = alchemy(op, caster, spell_ob);
1893  break;
1894 
1895  case SP_REMOVE_CURSE:
1896  success = remove_curse(op, caster, spell_ob);
1897  break;
1898 
1899  case SP_IDENTIFY:
1900  success = cast_identify(op, caster, spell_ob);
1901  break;
1902 
1903  case SP_DETECTION:
1904  success = cast_detection(op, caster, spell_ob);
1905  break;
1906 
1907  case SP_MOOD_CHANGE:
1908  success = mood_change(op, caster, spell_ob);
1909  break;
1910 
1911  case SP_MOVING_BALL:
1912  if (spell_ob->path_repelled
1913  && (spell_ob->path_repelled&caster->path_attuned) != spell_ob->path_repelled) {
1915  "You lack the proper attunement to cast %s",
1916  spell_ob->name);
1917  success = 0;
1918  } else
1919  success = fire_arch_from_position(op, caster, op->x, op->y, dir, spell_ob);
1920  break;
1921 
1922  case SP_SWARM:
1923  success = fire_swarm(op, caster, spell_ob, dir);
1924  break;
1925 
1926  case SP_CHANGE_MANA:
1927  success = cast_transfer(op, caster, spell_ob, dir);
1928  break;
1929 
1930  case SP_DISPEL_RUNE:
1931  /* in rune.c */
1932  success = dispel_rune(op, caster, spell_ob, skill, dir);
1933  break;
1934 
1935  case SP_CREATE_MISSILE:
1936  success = cast_create_missile(op, caster, spell_ob, dir, stringarg);
1937  break;
1938 
1939  case SP_CONSECRATE:
1940  success = cast_consecrate(op, caster, spell_ob);
1941  break;
1942 
1943  case SP_ANIMATE_WEAPON:
1944  success = animate_weapon(op, caster, spell_ob, dir);
1945  old_shoottype = range_golem;
1946  break;
1947 
1948  case SP_LIGHT:
1949  success = cast_light(op, caster, spell_ob, dir);
1950  break;
1951 
1952  case SP_CHANGE_MAP_LIGHT:
1953  success = cast_change_map_lightlevel(op, caster, spell_ob);
1954  break;
1955 
1956  case SP_FAERY_FIRE:
1957  success = cast_destruction(op, caster, spell_ob);
1958  break;
1959 
1960  case SP_CAUSE_DISEASE:
1961  success = cast_cause_disease(op, caster, spell_ob, dir);
1962  break;
1963 
1964  case SP_AURA:
1965  success = create_aura(op, caster, spell_ob);
1966  break;
1967 
1968  case SP_TOWN_PORTAL:
1969  success = cast_create_town_portal(op, caster, spell_ob, dir);
1970  break;
1971 
1972  case SP_ITEM_CURSE_BLESS:
1973  success = cast_item_curse_or_curse(op, caster, spell_ob);
1974  break;
1975 
1976  case SP_ELEM_SHIELD:
1977  success = create_aura(op, caster, spell_ob);
1978  break;
1979 
1980  default:
1981  LOG(llevError, "cast_spell: Unhandled spell subtype %d\n", spell_ob->subtype);
1982  }
1983 
1984  /* FIXME - we need some better sound suppport */
1985  /* free the spell arg */
1986  if (settings.casting_time == TRUE) {
1987  free(stringarg);
1988  stringarg = NULL;
1989  }
1990  /* perhaps a bit of a hack, but if using a wand, it has to change the skill
1991  * to something like use_magic_item, but you really want to be able to fire
1992  * it again.
1993  */
1994  if (op->contr)
1995  op->contr->shoottype = old_shoottype;
1996 
1997  return success;
1998 }
1999 
2006 void store_spell_expiry(object *spell) {
2007  /* Keep when to warn the player of expiration */
2008  char dur[10];
2009  int i = spell->duration/5;
2010 
2011  if (!i)
2012  i = 1;
2013  snprintf(dur, sizeof(dur), "%d", i);
2014  object_set_value(spell, "spell_expiry_warn_1", dur, 1);
2015  i = i/5;
2016  if (i > 0) {
2017  snprintf(dur, sizeof(dur), "%d", i);
2018  object_set_value(spell, "spell_expiry_warn_2", dur, 1);
2019  }
2020 }
2021 
2031 void check_spell_expiry(object *spell) {
2032  const char *key;
2033 
2034  if (!spell->env || !spell->env->type == PLAYER)
2035  return;
2036 
2037  key = object_get_value(spell, "spell_expiry_warn_1");
2038  if (key != NULL) {
2039  if (spell->duration == atoi(key)) {
2041  "The effects of your %s are draining out.", spell->name);
2042  return;
2043  }
2044  }
2045  key = object_get_value(spell, "spell_expiry_warn_2");
2046  if (key != NULL) {
2047  if (spell->duration == atoi(key)) {
2049  "The effects of your %s are about to expire.", spell->name);
2050  return;
2051  }
2052  }
2053 }
2054 
2062 void rod_adjust(object *rod) {
2063  /*
2064  * Add 50 to both level an divisor to keep prices a little
2065  * more reasonable. Otherwise, a high level version of a
2066  * low level spell can be worth tons a money (eg, level 20
2067  * rod, level 2 spell = 10 time multiplier). This way, the
2068  * value are a bit more reasonable.
2069  */
2070  rod->value = rod->value*rod->inv->value*(rod->level+50)/(rod->inv->level+50);
2071 
2072  /*
2073  * Maxhp is used to denote how many 'charges' the rod holds
2074  * before.
2075  */
2076  rod->stats.maxhp = MAX(rod->stats.maxhp, 2)*SP_level_spellpoint_cost(rod, rod->inv, SPELL_HIGHEST);
2077  rod->stats.hp = rod->stats.maxhp;
2078 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Sends message to player(s).
Definition: main.c:315
Error, serious thing.
Definition: logger.h:11
#define AP_UNAPPLY
Item is to be remvoed.
Definition: define.h:611
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.c:3999
#define AT_HOLYWORD
Definition: attack.h:97
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.c:218
int apply_manual(object *op, object *tmp, int aflag)
Main apply handler.
Definition: apply.c:510
void drain_rod_charge(object *rod)
Drain charges from a rod.
Definition: spell_util.c:819
Sound-related defines.
const char * determine_god(object *op)
Determines if op worships a god.
Definition: gods.c:106
archetype * find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:695
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.c:451
#define ARCH_SPELL_BUNGLE
Archetype when player bungles a spell.
Definition: object.h:583
#define MSG_TYPE_ITEM_CHANGE
Item has changed in some way.
Definition: newclient.h:640
see doc/Developers/objects
Definition: object.h:108
#define SP_BOLT
Definition: spells.h:78
#define INS_BELOW_ORIGINATOR
Insert new object immediately below originator.
Definition: object.h:572
#define MSG_TYPE_ITEM
Item related information.
Definition: newclient.h:388
int change_skill(object *who, object *new_skill, int flag)
This changes the object&#39;s skill to new_skill.
Definition: skill_util.c:356
Spell-related defines: spellpath, subtypes, ...
#define SP_MAKE_MARK
Definition: spells.h:77
#define AT_COUNTERSPELL
Definition: attack.h:95
uint8_t dam_modifier
How going up in level affects damage.
Definition: object.h:407
int cast_raise_dead_spell(object *op, object *caster, object *spell, int dir, const char *arg)
This handles the raise dead / resurrection spells.
Definition: resurrection.c:181
struct Statistics statistics
Merged spell statistics.
Definition: init.c:113
#define SP_CAUSE_DISEASE
Definition: spells.h:119
void spell_failure(object *op, int failure, int power, object *skill)
Handles the various effects for differing degrees of failure badness.
Definition: spell_util.c:1153
void esrv_send_item(object *pl, object *op)
Sends item&#39;s info to player.
Definition: main.c:339
#define SET_FLAG(xyz, p)
Definition: define.h:223
sstring add_refcount(sstring str)
This will increase the refcount of the string str.
Definition: shstr.c:210
#define SP_TOWN_PORTAL
Definition: spells.h:121
#define SP_CONE
Definition: spells.h:81
#define SP_BLESS
Definition: spells.h:99
object * find_target_for_friendly_spell(object *op, int dir)
This function is commonly used to find a friendly target for spells such as heal or protection or arm...
Definition: spell_util.c:856
#define FABS(x)
Decstations have trouble with fabs()...
Definition: define.h:22
See Scroll.
Definition: object.h:221
int cast_change_ability(object *op, object *caster, object *spell_ob, int dir, int silent)
Cast some stat-improving spell.
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.c:657
#define SP_CHANGE_MAP_LIGHT
Definition: spells.h:117
#define UPD_ANIM
Definition: newclient.h:294
#define strdup_local
Definition: compat.h:25
tag_t * spell_tags
Tags used for spell effect merging.
Definition: object.h:436
#define AT_INTERNAL
Definition: attack.h:99
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.c:511
#define SP_CHANGE_ABILITY
Definition: spells.h:98
uint8_t spellpoint_level_depend
Spell costs go up with level.
Definition: global.h:271
See Projectile.
Definition: object.h:117
#define P_NO_MAGIC
Spells (some) can&#39;t pass this object.
Definition: map.h:227
int8_t range
Range of the spell.
Definition: object.h:405
#define SP_MOVING_BALL
Definition: spells.h:109
No range selected.
Definition: player.h:17
int cast_bless(object *op, object *caster, object *spell_ob, int dir)
Improve statistics of some living object.
#define SP_AURA
Definition: spells.h:120
#define MSG_TYPE_SPELL
Spell related info.
Definition: newclient.h:387
#define SPELL_GRACE
Definition: spells.h:59
void get_search_arr(int *search_arr)
New function to make monster searching more efficient, and effective! This basically returns a random...
Definition: object.c:3501
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.c:672
#define MSG_TYPE_SPELL_FAILURE
Spell failure messages.
Definition: newclient.h:628
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.c:929
int16_t maxgrace
Maximum grace.
Definition: living.h:44
#define SP_ANIMATE_WEAPON
Definition: spells.h:115
Unused?
Definition: treasure.h:32
int SP_level_duration_adjust(const object *caster, const object *spob)
Adjust the duration of the spell based on level.
Definition: spell_util.c:353
#define HUGE_BUF
Used for messages - some can be quite long.
Definition: define.h:37
int SP_level_range_adjust(const object *caster, const object *spob)
Adjust the range of the spell based on level.
Definition: spell_util.c:379
#define SET_ANIMATION(ob, newanim)
Definition: global.h:171
void esrv_update_item(int flags, object *pl, object *op)
Updates object *op for player *pl.
Definition: main.c:342
const char * object_get_value(const object *op, const char *const key)
Get an extra value by key.
Definition: object.c:4246
struct treasureliststruct * randomitems
Items to be generated.
Definition: object.h:385
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.
Definition: spell_attack.c:546
#define MSG_TYPE_SPELL_INFO
random info about spell, not related to failure/success
Definition: newclient.h:634
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.
Definition: spell_util.c:1355
object clone
An object from which to do object_copy()
Definition: object.h:470
int16_t duration
How long the spell lasts.
Definition: object.h:403
int16_t invisible
How much longer the object will be invis.
Definition: object.h:360
short freearr_x[SIZEOFFREE]
X offset when searching around a spot.
Definition: object.c:65
#define PREFER_LOW
Definition: define.h:600
uint8_t duration_modifier
how level modifies duration
Definition: object.h:404
rangetype shoottype
Which range-attack is being used by player.
Definition: player.h:99
See Rune.
Definition: object.h:240
See Weapon.
Definition: object.h:119
#define DIRX(xyz)
Definition: define.h:477
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.c:571
int isqrt(int n)
Compute the square root.
Definition: utils.c:585
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.c:277
const char * slaying
Which race to do double damage to.
Definition: object.h:319
#define FLAG_CONFUSED
Will also be unable to cast spells.
Definition: define.h:312
int cast_word_of_recall(object *op, object *caster, object *spell_ob)
Word of recall causes the player to return &#39;home&#39;.
Definition: spell_effect.c:899
const char * skill_names[NUM_SKILLS]
Will contain a number-name mapping for skills, initialized by init_skills().
Definition: skill_util.c:57
#define MSG_TYPE_SKILL_MISSING
Don&#39;t have the skill.
Definition: newclient.h:582
uint8_t subtype
Subtype of object.
Definition: object.h:339
See Rod.
Definition: object.h:109
#define SPELL_WONDER
Definition: spells.h:163
struct obj * above
Pointer to the object stacked above this one.
Definition: object.h:288
#define PATH_TIME_MULT(op, spell)
Multiplier for the casting time based on path attenuation.
Definition: spells.h:152
method_ret ob_process(object *op)
Processes an object, giving it the opportunity to move or react.
Definition: ob_methods.c:62
#define OUT_OF_REAL_MAP(M, X, Y)
Checks if a square is out of the map.
Definition: map.h:217
Misc items.
Definition: player.h:20
#define TRUE
Definition: compat.h:10
int freedir[SIZEOFFREE]
Direction we&#39;re pointing on this spot.
Definition: object.c:83
void draw_magic_map(object *pl)
Creates and sends magic map to player.
Definition: info.c:440
int8_t get_attr_value(const living *stats, int attr)
Gets the value of a stat.
Definition: living.c:313
#define FALSE
Definition: compat.h:11
object * check_spell_known(object *op, const char *name)
Checks to see if player knows the spell.
Definition: spell_util.c:435
uint32_t path_attuned
Paths the object is attuned to.
Definition: object.h:343
#define MAX(x, y)
Definition: compat.h:20
int create_bomb(object *op, object *caster, int dir, object *spell)
Create a bomb.
Definition: spell_attack.c:447
int16_t sp
Spell points.
Definition: living.h:41
#define FLAG_REFLECTING
Object reflects from walls (lightning)
Definition: define.h:262
#define SP_CREATE_MISSILE
Definition: spells.h:113
Global type definitions and header inclusions.
uint32_t path_repelled
Paths the object is repelled from.
Definition: object.h:344
struct archt * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:413
int recharge(object *op, object *caster, object *spell_ob)
Recharge wands.
Definition: spell_effect.c:79
#define SP_HEALING
Definition: spells.h:95
int absdir(int d)
Computes an absolute direction.
Definition: object.c:3637
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.c:310
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
static int can_be_transmuted_to_flower(object *op)
Determines if an item can be transmuted after a cast failure.
Definition: spell_util.c:1211
See Wand & Staff.
Definition: object.h:220
#define MSG_TYPE_APPLY
Applying objects.
Definition: newclient.h:384
uint8_t casting_time
It takes awhile to cast a spell.
Definition: global.h:268
#define MSG_TYPE_VICTIM_SPELL
Someone cast a bad spell on the player.
Definition: newclient.h:651
#define SP_WORD_OF_RECALL
Definition: spells.h:92
int16_t maxsp
Max spell points.
Definition: living.h:42
int16_t hp
Hit Points.
Definition: living.h:39
#define DIRY(xyz)
Definition: define.h:478
int caster_level(const object *caster, const object *spell)
This function returns the effective level the spell is being cast at.
Definition: spell_util.c:233
int cast_cone(object *op, object *caster, int dir, object *spell)
Casts a cone spell.
Definition: spell_attack.c:297
int cast_create_food(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
Create food.
Definition: spell_effect.c:605
void rod_adjust(object *rod)
Adjusts rod attributes.
Definition: spell_util.c:2062
short freearr_y[SIZEOFFREE]
Y offset when searching around a spot.
Definition: object.c:71
void check_bullet(object *op)
Checks to see what op should do, given the space it is on (eg, explode, damage player, etc).
Definition: spell_attack.c:217
#define NDI_NAVY
Definition: newclient.h:223
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
This calls the appropriate treasure creation function.
Definition: treasure.c:490
#define LOOSE_MANA
Definition: spells.h:162
void esrv_del_item(player *pl, object *ob)
Tells the client to delete an item.
Definition: main.c:355
int summon_hostile_monsters(object *op, int n, const char *monstername)
Summons hostile monsters and places them in nearby squares.
Definition: spell_util.c:1047
int rndm(int min, int max)
Returns a number between min and max.
Definition: utils.c:161
int probe(object *op, object *caster, object *spell_ob, int dir, int level)
Try to get information about a living thing.
Definition: spell_effect.c:683
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.c:601
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
Definition: object.c:4375
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.c:1368
int change_abil(object *op, object *tmp)
Permanently alters an object&#39;s stats/flags based on another object.
Definition: living.c:394
int16_t y
Position in the map for this object.
Definition: object.h:326
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.c:1921
int16_t maxhp
Max hit points.
Definition: living.h:40
int cast_item_curse_or_curse(object *op, object *caster, object *spell_ob)
This alters player&#39;s marked item&#39;s cursed or blessed status, based on the spell_ob&#39;s fields...
#define AT_GODPOWER
Definition: attack.h:96
int cast_curse(object *op, object *caster, object *spell_ob, int dir)
Curse an object, reducing its statistics.
Definition: spell_attack.c:800
int fire_swarm(object *op, object *caster, object *spell, int dir)
The following routine creates a swarm of objects.
static void swap_random_stats(object *op)
Randomly swaps 2 stats of op.
Definition: spell_util.c:1301
#define SP_PERCEIVE_SELF
Definition: spells.h:91
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.c:1109
See Shooting Weapon.
Definition: object.h:118
uint32_t path_denied
Paths the object is denied access to.
Definition: object.h:345
#define SP_BULLET
Definition: spells.h:79
#define FLAG_ALIVE
Object can fight (or be fought)
Definition: define.h:230
void confuse_living(object *op, object *hitter, int dam)
Confuse a living thing.
Definition: attack.c:2221
#define AP_IGNORE_CURSE
Apply/unapply regardless of cursed/damned status.
Definition: define.h:617
#define FLAG_REFL_SPELL
Spells (some) will reflect from object.
Definition: define.h:275
#define MSG_TYPE_VICTIM
Something bad is happening to the player.
Definition: newclient.h:392
#define SP_ITEM_CURSE_BLESS
Definition: spells.h:123
struct obj * spell
Spell that was being cast.
Definition: object.h:408
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.c:620
void store_spell_expiry(object *spell)
Stores in the spell when to warn player of expiration.
Definition: spell_util.c:2006
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.c:2690
int cast_create_town_portal(object *op, object *caster, object *spell, int dir)
This function cast the spell of town portal for op.
#define SP_MOOD_CHANGE
Definition: spells.h:108
float speed_left
How much speed is left to spend this round.
Definition: object.h:329
signed short int16_t
Definition: win32.h:160
EXTERN Chaos_Attacks ATTACKS[22]
Definition: attack.h:134
int32_t weight
Attributes of the object.
Definition: object.h:365
static void handle_spell_confusion(object *op)
This does a random effect for op, which tried to cast a spell in a confused state.
Definition: spell_util.c:1336
const char * anim_suffix
Used to determine combined animations.
Definition: object.h:316
uint8_t range_modifier
How going up in level affects range.
Definition: object.h:406
#define SP_BOMB
Definition: spells.h:82
int8_t Wis
Definition: living.h:35
struct mapdef * map
Pointer to the map in which this object is present.
Definition: object.h:297
#define snprintf
Definition: win32.h:46
static void transmute_item_to_flower(object *op)
This transforms one random item of op to a flower.
Definition: spell_util.c:1233
#define MSG_TYPE_APPLY_ERROR
Definition: newclient.h:596
#define SP_WONDER
Definition: spells.h:83
int perceive_self(object *op)
Living thing wants to know information.
Definition: spell_effect.c:995
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:712
void set_spell_skill(object *op, object *caster, object *spob, object *dest)
Utility function to assign the correct skill when casting.
Definition: spell_util.c:94
Control golem.
Definition: player.h:21
int pets_summon_golem(object *op, object *caster, int dir, object *spob)
Summons a monster.
Definition: pets.c:672
int cast_light(object *op, object *caster, object *spell, int dir)
Illuminates something on a map, or try to blind a living thing.
int16_t dam
How much damage this object does when hitting.
Definition: living.h:45
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.c:535
#define MSG_TYPE_SPELL_ERROR
Spell failure messages.
Definition: newclient.h:631
void drain_wand_charge(object *wand)
Drains a charge from a wand.
Definition: spell_util.c:829
Definition: object.h:145
const char * name
The name of the object, obviously...
Definition: object.h:311
struct obj * env
Pointer to the object which is the environment.
Definition: object.h:293
int write_mark(object *op, object *spell, const char *msg)
This writes a rune that contains the appropriate message.
void regenerate_rod(object *rod)
Regenerates a rod&#39;s charges.
Definition: spell_util.c:804
#define OB_SPELL_TAG_MATCH(op, count)
Check whether a tag matches in the tags.
Definition: object.h:93
#define SP_SMITE
Definition: spells.h:84
struct obj * below
Pointer to the object stacked below this one.
Definition: object.h:287
struct archt * more
Next part of a linked object.
Definition: object.h:469
const char *const spell_mapping[]
static int put_a_monster(object *op, const char *monstername)
Puts a monster named monstername near by op.
Definition: spell_util.c:981
int8_t direction
Means the object is moving that way.
Definition: object.h:334
#define SP_ALCHEMY
Definition: spells.h:104
object * find_random_spell_in_ob(object *ob, const char *skill)
This returns a random spell from &#39;ob&#39;.
Definition: spell_util.c:48
uint32_t nrof
How many of the objects.
Definition: object.h:333
#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:447
#define AP_NOPRINT
Don&#39;t print messages - caller will do that may be some that still print.
Definition: define.h:621
void paralyze_living(object *op, int dam)
Paralyze a living thing.
Definition: attack.c:2304
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
This space is outside the map.
Definition: map.h:251
Number of statistics.
Definition: living.h:18
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Gets the blocking state of a square.
Definition: map.h:192
See Potion.
Definition: object.h:111
struct pl * contr
Pointer to the player which control this object.
Definition: object.h:276
#define GOD_POWER
Definition: spells.h:164
#define SP_INVISIBLE
Definition: spells.h:93
#define SP_CHARGING
Definition: spells.h:102
#define MSG_TYPE_SKILL_FAILURE
Failure in using skill.
Definition: newclient.h:585
#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.c:4232
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.
Definition: spell_effect.c:44
#define FREE_AND_CLEAR_STR(xyz)
Release the shared string, and set it to NULL.
Definition: global.h:208
char * spellarg
Optional argument when casting obj::spell.
Definition: object.h:409
uint32_t tag_t
Object tag, unique during the whole game.
Definition: object.h:12
#define SP_DETECTION
Definition: spells.h:107
float speed
The overall speed of this object.
Definition: object.h:328
See Spell.
Definition: object.h:214
int cast_wonder(object *op, object *caster, int dir, object *spell_ob)
wonder is really just a spell that will likely cast another spell.
Definition: spell_effect.c:961
#define SP_RUNE
Definition: spells.h:76
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:594
int cast_invisible(object *op, object *caster, object *spell_ob)
Makes the player or character invisible.
Definition: spell_effect.c:787
#define FLAG_WIZ
Object has special privilegies.
Definition: define.h:231
int write_rune(object *op, object *caster, object *spell, int dir, const char *runename)
Player is attempting to write a magical rune.
Definition: rune.c:50
void shuffle_attack(object *op, int change_face)
This routine shuffles the attack of op to one of the ones in the list.
Definition: spell_util.c:1081
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
See Magic Wall.
Definition: object.h:168
int cast_transfer(object *op, object *caster, object *spell, int dir)
This spell transfers sp from the player to another person.
int16_t x
Definition: object.h:326
#define SP_IDENTIFY
Definition: spells.h:106
#define SP_EARTH_TO_DUST
Definition: spells.h:97
int16_t encumbrance
How much our player is encumbered.
Definition: player.h:179
const char * skill
Name of the skill this object uses/grants.
Definition: object.h:321
int dimension_door(object *op, object *caster, object *spob, int dir)
Teleport through some doors and space.
#define NUM_SKILLS
This is the highest number skill in the table +1 This is used to store pointers to the actual skills ...
Definition: skills.h:71
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.c:3458
uint16_t difficulty
What level the player should be to play here.
Definition: map.h:343
int cast_destruction(object *op, object *caster, object *spell_ob)
Hit all monsters around the caster.
Definition: spell_attack.c:707
static const flag_definition flags[]
Flag mapping.
#define FOR_MAP_FINISH()
Finishes FOR_MAP_PREPARE().
Definition: define.h:765
#define SP_DIMENSION_DOOR
Definition: spells.h:87
#define SP_CHANGE_MANA
Definition: spells.h:111
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
#define SPELL_TAG_SIZE
Defines default size of the *spell_tags pointer.
Definition: object.h:81
unsigned int uint32_t
Definition: win32.h:162
See Player.
Definition: object.h:107
void check_spells(void)
It goes through the spells looking for any obvious errors.
Definition: spell_util.c:109
#define SP_CURSE
Definition: spells.h:100
#define SP_POLYMORPH
Definition: spells.h:103
int tailor_god_spell(object *spellop, object *caster)
Changes the attributes of cone, smite, and ball spells as needed by the code.
Definition: gods.c:1328
#define FLAG_ANIMATE
The object looks at archetype for faces.
Definition: define.h:242
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:599
uint32_t attacktype
Bitmask of attacks this object does.
Definition: object.h:342
#define FLAG_GENERATOR
Will generate type ob->stats.food.
Definition: define.h:248
int cast_heal(object *op, object *caster, object *spell, int dir)
Heals something.
object * object_decrease_nrof(object *op, uint32_t i)
Decreases a specified number from the amount of an object.
Definition: object.c:2505
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.c:51
#define RANDOM()
Definition: define.h:679
int16_t grace
Grace.
Definition: living.h:43
int cast_create_missile(object *op, object *caster, object *spell, int dir, const char *stringarg)
Create a missile (nonmagic - magic +4).
Definition: spell_effect.c:498
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.
Definition: spell_attack.c:904
tag_t count
Unique object number for this object.
Definition: object.h:299
living stats
Str, Con, Dex, etc.
Definition: object.h:368
#define FLAG_WIZCAST
The wizard can cast spells in no-magic area.
Definition: define.h:290
#define SP_FAERY_FIRE
Definition: spells.h:118
struct archt * arch
Pointer to archetype.
Definition: object.h:412
int remove_curse(object *op, object *caster, object *spell)
This function removes the cursed/damned status on equipped items.
Only for debugging purposes.
Definition: logger.h:13
int cast_earth_to_dust(object *op, object *caster, object *spell_ob)
Basically destroys earthwalls in the area.
Definition: spell_effect.c:848
#define SPELL_HIGHEST
Definition: spells.h:60
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
struct Settings settings
Server settings.
Definition: init.c:40
void dump_spells(void)
Dumps all the spells - now also dumps skill associated with the spell.
Definition: spell_util.c:146
uint64_t spell_suppressions
Number of times ok_to_put_more() returned FALSE.
Definition: global.h:348
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
rangetype
What range is currently selected by the player.
Definition: player.h:15
int fire_bolt(object *op, object *caster, int dir, object *spob)
Cast a bolt-like spell.
Definition: spell_attack.c:61
#define SP_MAGIC_MISSILE
Definition: spells.h:85
#define FLAG_APPLIED
Object is ready for use by living.
Definition: define.h:235
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.c:547
object * object_get_player_container(object *op)
Finds the player carrying an object.
Definition: object.c:353
#define SP_MAGIC_MAPPING
Definition: spells.h:88
signed int int32_t
Definition: win32.h:159
#define SP_LIGHT
Definition: spells.h:116
#define SP_SUMMON_MONSTER
Definition: spells.h:101
int16_t casting_time
Time left before spell goes off.
Definition: object.h:402
#define FORCE_NAME
Definition: spells.h:169
#define AT_MAGIC
Definition: attack.h:77
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.c:203
int alchemy(object *op, object *caster, object *spell_ob)
Change items to gold nuggets.
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
Definition: map.h:172
#define FORCE_TRANSFORMED_ITEM
Definition: spells.h:146
#define FLAG_MONSTER
Will attack players.
Definition: define.h:245
#define ARCH_SPELL_BLOCKED
Archetype when a spell is blocked (unholy ground or non magic).
Definition: object.h:582
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:383
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.c:302
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.c:499
struct obj * inv
Pointer to the first object in the inventory.
Definition: object.h:290
#define NDI_UNIQUE
Print immediately, don&#39;t buffer.
Definition: newclient.h:245
void apply_anim_suffix(object *who, sstring suffix)
Applies a compound animation to an object.
Definition: anim.c:292
int get_cleric_chance(int stat)
Definition: living.c:2263
struct obj * head
Points to the main object of a large body.
Definition: object.h:296
Spells.
Definition: player.h:19
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
#define SP_MAGIC_WALL
Definition: spells.h:89
int pets_summon_object(object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
General purpose summoning function.
Definition: pets.c:935
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Constructs a loop iterating over all objects of a map tile.
Definition: define.h:758
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Plays a sound on a map.
Definition: sounds.c:101
object * last_skill_ob[NUM_SKILLS]
Exp objects sent to client.
Definition: player.h:137
void check_spell_expiry(object *spell)
Checks if player should be warned of soon expiring spell.
Definition: spell_util.c:2031
Structure containing object statistics.
#define P_BLOCKSVIEW
This spot blocks the player&#39;s view.
Definition: map.h:226
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.c:3745
int cast_change_map_lightlevel(object *op, object *caster, object *spell)
This changes the light level for the entire map.
void query_name(const object *op, char *buf, size_t size)
Describes an item.
Definition: item.c:625
#define SPELL_MANA
Definition: spells.h:58
#define SP_DISPEL_RUNE
Definition: spells.h:112
#define SP_ELEM_SHIELD
Definition: spells.h:124
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Main dispatch when someone casts a spell.
Definition: spell_util.c:1471
This is a game-map.
Definition: map.h:325
int random_roll(int min, int max, const object *op, int goodbad)
Roll a random number between min and max.
Definition: utils.c:42
const New_Face * face
Face with colors.
Definition: object.h:332
static void prayer_failure(object *op, int failure, int power)
Called when a player fails at casting a prayer.
Definition: spell_util.c:1102
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.c:183
int SP_level_wc_adjust(const object *caster, const object *spob)
Returns adjusted wc based on the caster and the spell.
Definition: spell_util.c:403
int SP_level_dam_adjust(const object *caster, const object *spob)
Returns adjusted damage based on the caster.
Definition: spell_util.c:328
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Object is attacked by something.
Definition: attack.c:1861
int16_t level
Level of creature or object.
Definition: object.h:351
uint8_t spell_failure_effects
Nasty backlash to spell failures.
Definition: global.h:267
void fix_object(object *op)
Updates all abilities given by applied objects in the inventory of the given object.
Definition: living.c:1120
#define SP_SUMMON_GOLEM
Definition: spells.h:86
#define SOUND_TYPE_SPELL
Definition: newclient.h:309
#define SP_PROBE
Definition: spells.h:94
#define SP_CREATE_FOOD
Definition: spells.h:96
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
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.c:213
struct obj * more
Pointer to the rest of a large body of objects.
Definition: object.h:295
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.c:571
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.c:1129
int cast_identify(object *op, object *caster, object *spell)
Identifies objects in the players inventory/on the ground.
int32_t value
How much money it is worth (or contains)
Definition: object.h:350
object * object_get_owner(object *op)
Returns the object which this object marks as being the owner.
Definition: object.c:559
const char * name
More definite name, like "generate_kobold".
Definition: object.h:466
int dispel_rune(object *op, object *caster, object *spell, object *skill, int dir)
Someone is trying to disarm a rune.
Definition: rune.c:299
#define P_NO_CLERIC
No clerical spells cast here.
Definition: map.h:238
#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:705
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.c:1654
int cast_polymorph(object *op, object *caster, object *spell_ob, int dir)
Polymorph spell casting.
Definition: spell_effect.c:430
int32_t food
How much food in stomach.
Definition: living.h:47
int attacktype
Definition: attack.h:126
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
#define SP_REMOVE_CURSE
Definition: spells.h:105