Crossfire Server, Trunk
spell_effect.c
Go to the documentation of this file.
1 /*
2  CrossFire, A Multiplayer game for X-windows
3 
4  Copyright (C) 2007 Mark Wedel & Crossfire Development Team
5  Copyright (C) 1992 Frank Tore Johansen
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21  The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23 
28 #include <global.h>
29 #include <ob_methods.h>
30 #include <ob_types.h>
31 #include <sounds.h>
32 #include <sproto.h>
33 
34 static method_ret spell_effect_type_move_on(object *trap, object *victim, object *originator);
36 
37 static void move_bolt(object *op);
38 static void move_bullet(object *op);
39 static void explosion(object *op);
40 static void move_cone(object *op);
41 static void animate_bomb(object *op);
42 static void move_missile(object *op);
43 static void execute_word_of_recall(object *op);
44 static void move_ball_spell(object *op);
45 static void move_swarm_spell(object *op);
46 static void move_aura(object *aura);
47 
48 static void forklightning(object *op, object *tmp);
49 static void check_spell_knockback(object *op);
50 
57 }
58 
66 static method_ret spell_effect_type_move_on(object *trap, object *victim, object *originator) {
67  if (common_pre_ob_move_on(trap, victim, originator) == METHOD_ERROR)
68  return METHOD_OK;
69 
70  switch (trap->subtype) {
71  case SP_CONE:
73  && trap->speed
74  && trap->attacktype)
75  hit_player(victim, trap->stats.dam, trap, trap->attacktype, 0);
76  break;
77 
78  case SP_MAGIC_MISSILE:
80  tag_t spell_tag = trap->count;
81 
82  hit_player(victim, trap->stats.dam, trap, trap->attacktype, 1);
83  if (!object_was_destroyed(trap, spell_tag)) {
84  object_remove(trap);
86  }
87  }
88  break;
89 
90  case SP_MOVING_BALL:
92  hit_player(victim, trap->stats.dam, trap, trap->attacktype, 1);
93  else if (victim->material || victim->materialname)
94  save_throw_object(victim, trap->attacktype, trap);
95  break;
96  }
97  common_post_ob_move_on(trap, victim, originator);
98  return METHOD_OK;
99 }
100 
107  switch (op->subtype) {
108  case SP_BOLT:
109  move_bolt(op);
110  break;
111 
112  case SP_BULLET:
113  move_bullet(op);
114  break;
115 
116  case SP_EXPLOSION:
117  explosion(op);
118  break;
119 
120  case SP_CONE:
121  move_cone(op);
122  break;
123 
124  case SP_BOMB:
125  animate_bomb(op);
126  break;
127 
128  case SP_MAGIC_MISSILE:
129  move_missile(op);
130  break;
131 
132  case SP_WORD_OF_RECALL:
134  break;
135 
136  case SP_MOVING_BALL:
138  break;
139 
140  case SP_SWARM:
142  break;
143 
144  case SP_AURA:
145  move_aura(op);
146  break;
147  }
148  return METHOD_OK;
149 }
150 
156 static void move_bolt(object *op) {
157  object *tmp;
158  int mflags;
159  int16_t x, y;
160  mapstruct *m;
161 
162  if (--(op->duration) < 0) {
163  object_remove(op);
165  return;
166  }
167  hit_map(op, 0, op->attacktype, 1);
168 
170 
171  if (!op->direction)
172  return;
173 
174  if (--op->range < 0) {
175  op->range = 0;
176  } else {
177  x = op->x+DIRX(op);
178  y = op->y+DIRY(op);
179  m = op->map;
180  mflags = get_map_flags(m, &m, x, y, &x, &y);
181 
182  if (mflags&P_OUT_OF_MAP)
183  return;
184 
185  /* We are about to run into something - we may bounce */
186  /* Calling reflwall is pretty costly, as it has to look at all the objects
187  * on the space. So only call reflwall if we think the data it returns
188  * will be useful.
189  */
191  || ((mflags&P_IS_ALIVE) && reflwall(m, x, y, op))) {
193  return;
194 
195  /* Since walls don't run diagonal, if the bolt is in
196  * one of 4 main directions, it just reflects back in the
197  * opposite direction. However, if the bolt is travelling
198  * on the diagonal, it is trickier - eg, a bolt travelling
199  * northwest bounces different if it hits a north/south
200  * wall (bounces to northeast) vs an east/west (bounces
201  * to the southwest.
202  */
203  if (op->direction&1) {
204  op->direction = absdir(op->direction+4);
205  } else {
206  int left, right;
207  int mflags;
208 
209  /* Need to check for P_OUT_OF_MAP: if the bolt is tavelling
210  * over a corner in a tiled map, it is possible that
211  * op->direction is within an adjacent map but either
212  * op->direction-1 or op->direction+1 does not exist.
213  */
214  mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction-1)], op->y+freearr_y[absdir(op->direction-1)], &x, &y);
215 
216  left = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y));
217 
218  mflags = get_map_flags(op->map, &m, op->x+freearr_x[absdir(op->direction+1)], op->y+freearr_y[absdir(op->direction+1)], &x, &y);
219  right = (mflags&P_OUT_OF_MAP) ? 0 : OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y));
220 
221  if (left == right)
222  op->direction = absdir(op->direction+4);
223  else if (left)
224  op->direction = absdir(op->direction+2);
225  else if (right)
226  op->direction = absdir(op->direction-2);
227  }
228  object_update_turn_face(op); /* A bolt *must *be IS_TURNABLE */
229  return;
230  } else { /* Create a copy of this object and put it ahead */
231  tmp = object_new();
232  object_copy(op, tmp);
233  tmp->speed_left = -0.1;
234  tmp = object_insert_in_map_at(tmp, op->map, op, 0, op->x+DIRX(op), op->y+DIRY(op));
235  /* To make up for the decrease at the top of the function */
236  tmp->duration++;
237 
238  /* New forking code. Possibly create forks of this object
239  * going off in other directions.
240  */
241 
242  if (rndm(0, 99) < tmp->stats.Dex) { /* stats.Dex % of forking */
243  forklightning(op, tmp);
244  }
245  /* In this way, the object left behind sticks on the space, but
246  * doesn't create any bolts that continue to move onward.
247  */
248  op->range = 0;
249  } /* copy object and move it along */
250  } /* if move bolt along */
251 }
252 
259 static void move_bullet(object *op) {
260  int16_t new_x, new_y;
261  int mflags;
262  mapstruct *m;
263 
264  /* Reached the end of its life - remove it */
265  if (--op->range <= 0) {
266  if (op->other_arch) {
268  } else {
269  object_remove(op);
271  }
272  return;
273  }
274 
275  new_x = op->x+DIRX(op);
276  new_y = op->y+DIRY(op);
277  m = op->map;
278  mflags = get_map_flags(m, &m, new_x, new_y, &new_x, &new_y);
279 
280  if (mflags&P_OUT_OF_MAP) {
281  object_remove(op);
283  return;
284  }
285 
286  if (!op->direction || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y))) {
287  if (op->other_arch) {
289  } else {
290  object_remove(op);
292  }
293  return;
294  }
295 
296  object_remove(op);
297  if ((op = object_insert_in_map_at(op, m, op, 0, new_x, new_y)) == NULL)
298  return;
299 
300  if (reflwall(op->map, op->x, op->y, op)) {
301  op->direction = absdir(op->direction+4);
303  } else {
304  check_bullet(op);
305  }
306 }
307 
313 static void explosion(object *op) {
314  object *tmp;
315  mapstruct *m = op->map;
316  int i;
317 
318  if (--(op->duration) < 0) {
319  object_remove(op);
321  return;
322  }
323  hit_map(op, 0, op->attacktype, 0);
325 
326  if (op->range > 0) {
327  for (i = 1; i < 9; i++) {
328  int16_t dx, dy;
329  int16_t Dx, Dy;
330  dx = op->x+freearr_x[i];
331  dy = op->y+freearr_y[i];
332  /* ok_to_put_more already does things like checks for walls,
333  * out of map, etc.
334  */
335  if (ok_to_put_more(op->map, dx, dy, op, op->attacktype)) {
336  tmp = object_new();
337  object_copy(op, tmp);
338  tmp->state = 0;
339  tmp->speed_left = -0.21;
340  tmp->range--;
341  tmp->value = 0;
342  Dx=dx-op->x;
343  Dy=dy-op->y;
344  if (Dx==-1 && Dy==-1){
345  tmp->direction=8;
346  }
347  if (Dx==0 && Dy==-1){
348  tmp->direction=1;
349  }
350  if (Dx==1 && Dy==-1){
351  tmp->direction=2;
352  }
353  if (Dx==1 && Dy==0){
354  tmp->direction=3;
355  }
356  if (Dx==1 && Dy==1){
357  tmp->direction=4;
358  }
359  if (Dx==0 && Dy==1){
360  tmp->direction=5;
361  }
362  if (Dx==-1 && Dy==-1){
363  tmp->direction=6;
364  }
365  if (Dx==-1 && Dy==0){
366  tmp->direction=7;
367  }
368 
369  object_insert_in_map_at(tmp, m, op, 0, dx, dy);
370 
371  }
372  }
373  /* Reset range so we don't try to propogate anymore.
374  * Call object_merge_spell() to see if we can merge with another
375  * spell on the space.
376  */
377  op->range = 0;
378  object_merge_spell(op, op->x, op->y);
379  }
380 }
381 
386 static void move_cone(object *op) {
387  int i;
388  tag_t tag;
389 
390  /* if no map then hit_map will crash so just ignore object */
391  if (!op->map) {
392  LOG(llevError, "Tried to move_cone object %s without a map.\n", op->name ? op->name : "unknown");
393  op->speed = 0;
395  return;
396  }
397 
398  /* lava saves it's life, but not yours :) */
399  if (QUERY_FLAG(op, FLAG_LIFESAVE)) {
400  hit_map(op, 0, op->attacktype, 0);
401  return;
402  }
403 
404  tag = op->count;
405  hit_map(op, 0, op->attacktype, 0);
406 
407  /* Check to see if we should push anything.
408  * Spell objects with weight push whatever they encounter to some
409  * degree.
410  */
412 
414  return;
415 
416  if ((op->duration--) < 0) {
417  object_remove(op);
419  return;
420  }
421 
422  /* Object has hit maximum range, so don't have it move
423  * any further. When the duration above expires,
424  * then the object will get removed.
425  */
426  if (--op->range < 0) {
427  op->range = 0; /* just so it doesn't wrap */
428  return;
429  }
430 
431  for (i = -1; i < 2; i++) {
432  int16_t x = op->x+freearr_x[absdir(op->stats.sp+i)];
433  int16_t y = op->y+freearr_y[absdir(op->stats.sp+i)];
434 
435  if (ok_to_put_more(op->map, x, y, op, op->attacktype)) {
436  object *tmp = object_new();
437 
438  object_copy(op, tmp);
439  tmp->duration = op->duration+1;
440 
441  /* Use for spell tracking - see ok_to_put_more() */
442  tmp->stats.maxhp = op->stats.maxhp;
443  object_insert_in_map_at(tmp, op->map, op, 0, x, y);
444  if (tmp->other_arch)
445  cone_drop(tmp);
446  }
447  }
448 }
449 
454 static void animate_bomb(object *op) {
455  int i;
456  object *env, *tmp;
457  archetype *at;
458 
459  if (op->state != NUM_ANIMATIONS(op)-1)
460  return;
461 
463 
464  if (op->env) {
465  if (env->map == NULL)
466  return;
467 
468  object_remove(op);
469  if ((op = object_insert_in_map_at(op, env->map, op, 0, env->x, env->y)) == NULL)
470  return;
471  }
472 
473  /* This copies a lot of the code from the fire bullet,
474  * but using the cast_bullet isn't really feasible,
475  * so just set up the appropriate values.
476  */
477  at = find_archetype(SPLINT);
478  if (at) {
479  for (i = 1; i < 9; i++) {
480  if (out_of_map(op->map, op->x+freearr_x[i], op->y+freearr_x[i]))
481  continue;
482  tmp = arch_to_object(at);
483  tmp->direction = i;
484  tmp->range = op->range;
485  tmp->stats.dam = op->stats.dam;
486  tmp->duration = op->duration;
487  tmp->attacktype = op->attacktype;
489  if (op->skill && op->skill != tmp->skill) {
490  if (tmp->skill)
491  free_string(tmp->skill);
492  tmp->skill = add_refcount(op->skill);
493  }
495  object_insert_in_map_at(tmp, op->map, op, 0, op->x+freearr_x[i], op->y+freearr_x[i]);
496  ob_process(tmp);
497  }
498  }
499 
501 }
502 
507 static void move_missile(object *op) {
508  int i, mflags;
509  int16_t new_x, new_y;
510  mapstruct *m;
511 
512  if (op->range-- <= 0) {
513  object_remove(op);
515  return;
516  }
517 
518  /* call is required to potentially clean owner, but we don't care for the result */
520 
521  new_x = op->x+DIRX(op);
522  new_y = op->y+DIRY(op);
523 
524  mflags = get_map_flags(op->map, &m, new_x, new_y, &new_x, &new_y);
525 
526  if (!(mflags&P_OUT_OF_MAP)
527  && ((mflags&P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, new_x, new_y)))) {
528  tag_t tag = op->count;
529 
530  hit_map(op, op->direction, AT_MAGIC, 1);
531  /* Basically, missile only hits one thing then goes away.
532  * we need to remove it if someone hasn't already done so.
533  */
534  if (!object_was_destroyed(op, tag)) {
535  object_remove(op);
537  }
538  return;
539  }
540 
541  object_remove(op);
542  if (!op->direction || (mflags&P_OUT_OF_MAP)) {
544  return;
545  }
546  i = spell_find_dir(m, new_x, new_y, object_get_owner(op));
547  if (i > 0 && i != op->direction) {
548  op->direction = adjust_dir(op->direction, i);
550  }
551  object_insert_in_map_at(op, m, op, 0, new_x, new_y);
552 }
553 
558 static void execute_word_of_recall(object *op) {
559  object *wor = op;
560 
561  while (op != NULL && op->type != PLAYER)
562  op = op->env;
563 
564  if (op != NULL) {
565  // Drop any unpaid items that would be carried.
566  // This prevents abuse of balms of return home in shops.
567  remove_unpaid_objects(op->inv, op, 0);
568 
569  enter_exit(op, wor);
570  }
571  object_remove(wor);
573 }
574 
580 static void move_ball_spell(object *op) {
581  int i, j, dam_save, dir, mflags;
582  int16_t nx, ny, hx, hy;
583  object *owner;
584  mapstruct *m;
585 
586  owner = object_get_owner(op);
587 
588  /* the following logic makes sure that the ball doesn't move into a wall,
589  * and makes sure that it will move along a wall to try and get at it's
590  * victim. The block immediately below more or less chooses a random
591  * offset to move the ball, eg, keep it mostly on course, with some
592  * deviations.
593  */
594 
595  dir = 0;
596  j = rndm(0, 1);
597  for (i = 1; i <= 9; i++) {
598  /* i bit 0: alters sign of offset
599  * other bits (i/2): absolute value of offset
600  */
601 
602  int offset = ((i^j)&1) ? (i/2) : -(i/2);
603  int tmpdir = absdir(op->direction+offset);
604 
605  nx = op->x+freearr_x[tmpdir];
606  ny = op->y+freearr_y[tmpdir];
607  if (!(get_map_flags(op->map, &m, nx, ny, &nx, &ny)&P_OUT_OF_MAP)
608  && !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, nx, ny)))) {
609  dir = tmpdir;
610  break;
611  }
612  }
613  if (dir == 0) {
614  nx = op->x;
615  ny = op->y;
616  m = op->map;
617  }
618 
619  object_remove(op);
620  object_insert_in_map_at(op, m, op, 0, nx, ny);
621 
622  dam_save = op->stats.dam; /* save the original dam: we do halfdam on
623  surrounding squares */
624 
625  /* loop over current square and neighbors to hit.
626  * if this has an other_arch field, we insert that in
627  * the surround spaces.
628  */
629  for (j = 0; j < 9; j++) {
630  object *new_ob;
631 
632  hx = nx+freearr_x[j];
633  hy = ny+freearr_y[j];
634 
635  m = op->map;
636  mflags = get_map_flags(m, &m, hx, hy, &hx, &hy);
637 
638  if (mflags&P_OUT_OF_MAP)
639  continue;
640 
641  /* first, don't ever, ever hit the owner. Don't hit out
642  * of the map either.
643  */
644 
645  if ((mflags&P_IS_ALIVE) && (!owner || owner->x != hx || owner->y != hy || !on_same_map(owner, op))) {
646  if (j)
647  op->stats.dam = dam_save/2;
648  hit_map(op, j, op->attacktype, 1);
649  }
650 
651  /* insert the other arch */
652  if (op->other_arch && !(OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, hx, hy)))) {
653  new_ob = arch_to_object(op->other_arch);
654  object_insert_in_map_at(new_ob, m, op, 0, hx, hy);
655  }
656  }
657 
658  /* restore to the center location and damage*/
659  op->stats.dam = dam_save;
660 
661  i = spell_find_dir(op->map, op->x, op->y, object_get_owner(op));
662  if (i >= 0) { /* we have a preferred direction! */
663  op->direction = adjust_dir(op->direction, i);
664  if (rndm(0, 3) != 0)
665  op->direction = adjust_dir(op->direction, i);
666  if (rndm(0, 3) == 0)
667  op->direction = adjust_dir(op->direction, i);
668  }
669 }
670 
671 /*
672  * This is an implementation of the swarm spell. It was written for meteor
673  * swarm, but it could be used for any swarm. A swarm spell is a special type
674  * of object that casts swarms of other types of spells. Which spell it casts
675  * is flexible. It fires the spells from a set of squares surrounding the
676  * caster, in a given direction.
677  * @param op The spell effect.
678  */
679 static void move_swarm_spell(object *op) {
680  static int cardinal_adjust[9] = { -3, -2, -1, 0, 0, 0, 1, 2, 3 };
681  static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 };
682  int16_t target_x, target_y, origin_x, origin_y;
683  int basedir, adjustdir;
684  mapstruct *m;
685  object *owner;
686 
687  owner = object_get_owner(op);
688  if (op->duration == 0 || owner == NULL || owner->x != op->x || owner->y != op->y) {
689  object_remove(op);
691  return;
692  }
693  op->duration--;
694 
695  basedir = op->direction;
696  if (basedir == 0) {
697  /* spray in all directions! 8) */
698  basedir = get_random_dir();
699  }
700 
701  /* new offset calculation to make swarm element distribution
702  * more uniform
703  */
704  if (op->duration) {
705  if (basedir&1) {
706  adjustdir = cardinal_adjust[rndm(0, 8)];
707  } else {
708  adjustdir = diagonal_adjust[rndm(0, 9)];
709  }
710  } else {
711  adjustdir = 0; /* fire the last one from forward. */
712  }
713 
714  target_x = op->x+freearr_x[absdir(basedir+adjustdir)];
715  target_y = op->y+freearr_y[absdir(basedir+adjustdir)];
716 
717  /* back up one space so we can hit point-blank targets, but this
718  * necessitates extra out_of_map check below
719  */
720  origin_x = target_x-freearr_x[basedir];
721  origin_y = target_y-freearr_y[basedir];
722 
723 
724  /* spell pointer is set up for the spell this casts. Since this
725  * should just be a pointer to the spell in some inventory,
726  * it is unlikely to disappear by the time we need it. However,
727  * do some sanity checking anyways.
728  */
729 
730  if (op->spell && op->spell->type == SPELL && !(get_map_flags(op->map, &m, target_x, target_y, &target_x, &target_y)&P_OUT_OF_MAP)) {
731  /* Bullet spells have a bunch more customization that needs to be done */
732  if (op->spell->subtype == SP_BULLET)
733  fire_arch_from_position(owner, op, origin_x+freearr_x[basedir], origin_y+freearr_y[basedir], basedir, op->spell);
734  else if (op->spell->subtype == SP_MAGIC_MISSILE)
735  fire_arch_from_position(owner, op, origin_x, origin_y, basedir, op->spell);
736  }
737 }
738 
749 static void move_aura(object *aura) {
750  int i, j, mflags;
751  object *env;
752  mapstruct *m;
753  uint8_t aura_animation_state = 0;
754  sstring whole_aura_animation = NULL;
755  char aura_animation_name[200];
756  if (aura->other_arch && aura->other_arch->clone.type != SPELL) {
757  whole_aura_animation = object_get_value(&aura->other_arch->clone, "whole_aura_animation");
758  if (whole_aura_animation) {
759  snprintf(aura_animation_name, sizeof(aura_animation_name), "%s_0_0", whole_aura_animation);
760  Animations *anim = try_find_animation(aura_animation_name);
761  if (anim) {
762  aura_animation_state = aura->duration % (anim->num_animations / anim->facings);
763  } else {
764  whole_aura_animation = NULL;
765  }
766  }
767  }
768 
769  /* auras belong in inventories */
770  env = aura->env;
771 
772  /* no matter what we've gotta remove the aura...
773  * we'll put it back if its time isn't up.
774  */
775  object_remove(aura);
776 
777  /* exit if we're out of gas */
778  if (aura->duration-- < 0) {
780  return;
781  }
782 
783  /* auras only exist in inventories */
784  if (env == NULL || env->map == NULL) {
786  return;
787  }
788 
789  for (i = -aura->range; i <= aura->range; i++) {
790  for (j = -aura->range; j <= aura->range; ++j) {
791  int16_t nx, ny;
792 
793  // Env should be the starting location for the aura, so use
794  // it as the base positioning instead of the aura.
795  // This allows us to be less hacky when handling the long-range aura.
796  nx = env->x+i;
797  ny = env->y+j;
798  mflags = get_map_flags(env->map, &m, nx, ny, &nx, &ny);
799 
800  /* Consider the movement type of the person with the aura as
801  * movement type of the aura. Eg, if the player is flying, the aura
802  * is flying also, if player is walking, it is on the ground, etc.
803  */
804  if (!(mflags&P_OUT_OF_MAP) && !(OB_TYPE_MOVE_BLOCK(env, GET_MAP_MOVE_BLOCK(m, nx, ny)))) {
805  // If the aura has no attacktype, don't try to hit the map with it.
806  // Chances are, it is casting it's own spell instead.
807  if (aura->attacktype != 0 && (i != 0 || j != 0)) {
808  // Instead of using freearr in hit_map, be move the aura around,
809  // and then call hit_map with direction 0. This allows us to have range > 3.
810 
811  /* we need to jump out of the inventory for a bit
812  * in order to hit the map conveniently.
813  */
814  if (!QUERY_FLAG(aura, FLAG_REMOVED))
815  object_remove(aura);
816  object_insert_in_map_at(aura, m, aura, 0, nx, ny);
817  hit_map(aura, 0, aura->attacktype, 0);
818  object_remove(aura);
819  }
820 
821  if (aura->other_arch) {
822  object *new_ob;
823 
824  new_ob = arch_to_object(aura->other_arch);
825  // If the aura contains a spell, we attempt to cast the spell on every tile we affect.
826  if (new_ob->type != SPELL) {
827  new_ob = object_insert_in_map_at(new_ob, m, aura, 0, nx, ny);
828  if (new_ob && whole_aura_animation) {
829  snprintf(aura_animation_name, sizeof(aura_animation_name), "%s_%d_%d", whole_aura_animation, i + aura->range, j + aura->range);
830  Animations *anim = try_find_animation(aura_animation_name);
831  if (anim) {
832  SET_FLAG(new_ob, FLAG_ANIMATE);
833  new_ob->animation = anim;
834  new_ob->state = aura_animation_state;
835  animate_object(new_ob, 0);
836  }
837  }
838  }
839  else if (i != 0 || j != 0) {
840  // Find a living creature that is on the same side as the caster.
841  FOR_MAP_PREPARE(m, nx, ny, tmp) {
842  // If the entity is living and aligned with the caster, then cast the spell at them.
843  // Allow auras to be cast by enemies, too. In that case, they only affect their allies.
844  if (QUERY_FLAG(tmp, FLAG_ALIVE) &&
846  (QUERY_FLAG(env, FLAG_FRIENDLY) || env->contr))){
847  cast_spell(tmp, aura, 0, new_ob, NULL);
848  }
849  } FOR_MAP_FINISH();
851  }
852  }
853  }
854  }
855  }
856 
857  /* put the aura back in the player's inventory */
858  if (!QUERY_FLAG(aura, FLAG_REMOVED))
859  object_remove(aura);
860  object_insert_in_ob(aura, env);
861  check_spell_expiry(aura);
862 }
863 
869 static void forklightning(object *op, object *tmp) {
870  int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */
871  int t_dir; /* stores temporary dir calculation */
872  mapstruct *m;
873  int16_t sx, sy;
874  object *new_bolt;
875 
876  /* pick a fork direction. tmp->stats.Con is the left bias
877  * i.e., the chance in 100 of forking LEFT
878  * Should start out at 50, down to 25 for one already going left
879  * down to 0 for one going 90 degrees left off original path
880  */
881 
882  if (rndm(0, 99) < tmp->stats.Con) /* fork left */
883  new_dir = -1;
884 
885  /* check the new dir for a wall and in the map*/
886  t_dir = absdir(tmp->direction+new_dir);
887 
888  if (get_map_flags(tmp->map, &m, tmp->x+freearr_x[t_dir], tmp->y+freearr_y[t_dir], &sx, &sy)&P_OUT_OF_MAP)
889  return;
890 
892  return;
893 
894  /* OK, we made a fork */
895  new_bolt = object_new();
896 
897  object_copy(tmp, new_bolt);
898 
899  /* reduce chances of subsequent forking */
900  new_bolt->stats.Dex -= 10;
901  tmp->stats.Dex -= 10; /* less forks from main bolt too */
902  new_bolt->stats.Con += 25*new_dir; /* adjust the left bias */
903  new_bolt->speed_left = -0.1;
904  new_bolt->direction = t_dir;
905  new_bolt->duration++;
906  new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */
907  new_bolt->stats.dam++;
908  tmp->stats.dam /= 2; /* reduce father bolt damage */
909  tmp->stats.dam++;
910  new_bolt = object_insert_in_map_at(new_bolt, m, op, 0, sx, sy);
911  object_update_turn_face(new_bolt);
912 }
913 
920 static void check_spell_knockback(object *op) {
921  object *tmp, *tmp2; /* object on the map */
922  int weight_move;
923  int frictionmod = 2; /*poor man's physics - multipy targets weight by this amount */
924 
925  /* if cone object has no weight drop out */
926  if (!op->weight) {
927  return;
928  }
929 
930  weight_move = op->weight+(op->weight*op->level)/3;
931  /*LOG(llevDebug, "DEBUG: arch weighs %d and masses %d (%s,level %d)\n", op->weight, weight_move, op->name, op->level);*/
932 
933  for (tmp = GET_MAP_OB(op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) {
934  int num_sections = 1;
935 
936  /* don't move DM */
937  if (QUERY_FLAG(tmp, FLAG_WIZ))
938  return;
939 
940  /* don't move parts of objects */
941  if (tmp->head)
942  continue;
943 
944  /* don't move floors or immobile objects */
946  continue;
947 
948  /* count the object's sections */
949  for (tmp2 = tmp; tmp2 != NULL; tmp2 = tmp2->more)
950  num_sections++;
951 
952  /* I'm not sure if it makes sense to divide by num_sections - bigger
953  * objects should be harder to move, and we are moving the entire
954  * object, not just the head, so the total weight should be relevant.
955  */
956 
957  /* surface area? -tm */
958 
959  if (tmp->move_type&MOVE_FLYING)
960  frictionmod = 1; /* flying objects loose the friction modifier */
961  if (rndm(0, weight_move-1) > ((tmp->weight/num_sections)*frictionmod)) { /* move it. */
962  /* move_object is really for monsters, but looking at
963  * the move_object function, it appears that it should
964  * also be safe for objects.
965  * This does return if successful or not, but
966  * I don't see us doing anything useful with that information
967  * right now.
968  */
969 // LOG(llevDebug, "trying move\n");
970  if (op->direction){
971  move_object(tmp,absdir(op->direction));
972  }
973 
974  else {
975  (move_object(tmp, absdir(op->stats.sp)));
976 
977  }
978  }
979  else{
980 // LOG(llevDebug, "did not try move, don't know why\n");
981  }
982  }
983 }
object_was_destroyed
#define object_was_destroyed(op, old_tag)
Definition: object.h:68
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
PLAYER
@ PLAYER
Definition: object.h:107
SP_MAGIC_MISSILE
#define SP_MAGIC_MISSILE
Definition: spells.h:85
global.h
FREE_OBJ_NO_DESTROY_CALLBACK
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:531
add_refcount
sstring add_refcount(sstring str)
Definition: shstr.c:210
SP_BOLT
#define SP_BOLT
Definition: spells.h:78
liv::dam
int16_t dam
Definition: living.h:46
object_free
void object_free(object *ob, int flags)
Definition: object.c:1578
spell_effect_type_process
static method_ret spell_effect_type_process(object *op)
Definition: spell_effect.c:106
object_remove
void object_remove(object *op)
Definition: object.c:1819
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
adjust_dir
int adjust_dir(int dir, int destination_dir)
Definition: utils.c:436
AT_MAGIC
#define AT_MAGIC
Definition: attack.h:77
llevError
@ llevError
Definition: logger.h:11
SP_BOMB
#define SP_BOMB
Definition: spells.h:82
object_copy_owner
void object_copy_owner(object *op, object *clone)
Definition: object.c:897
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
diamondslots.x
x
Definition: diamondslots.py:15
obj::count
tag_t count
Definition: object.h:302
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
register_process
void register_process(int ob_type, process_func method)
Definition: ob_types.c:71
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2312
object_new
object * object_new(void)
Definition: object.c:1255
cast_spell
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1420
METHOD_OK
#define METHOD_OK
Definition: ob_methods.h:15
check_bullet
void check_bullet(object *op)
Definition: spell_attack.c:217
object_merge_spell
void object_merge_spell(object *op, int16_t x, int16_t y)
Definition: object.c:2109
explode_bullet
void explode_bullet(object *op)
Definition: spell_attack.c:121
SP_CONE
#define SP_CONE
Definition: spells.h:81
DIRX
#define DIRX(xyz)
Definition: define.h:463
Ice.tmp
int tmp
Definition: Ice.py:207
hit_map
int hit_map(object *op, int dir, uint32_t type, int full_hit)
Definition: attack.c:349
fire_arch_from_position
int fire_arch_from_position(object *op, object *caster, int16_t x, int16_t y, int dir, object *spell)
Definition: spell_util.c:628
P_IS_ALIVE
#define P_IS_ALIVE
Definition: map.h:238
ok_to_put_more
int ok_to_put_more(mapstruct *m, int16_t x, int16_t y, object *op, uint32_t immune_stop)
Definition: spell_util.c:529
check_spell_knockback
static void check_spell_knockback(object *op)
Definition: spell_effect.c:920
ob_process
method_ret ob_process(object *op)
Definition: ob_methods.c:67
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:299
move_bullet
static void move_bullet(object *op)
Definition: spell_effect.c:259
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:305
obj::duration
int16_t duration
Definition: object.h:408
archt
Definition: object.h:469
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
animate_object
void animate_object(object *op, int dir)
Definition: anim.c:43
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4317
free_string
void free_string(sstring str)
Definition: shstr.c:280
m
static event_registration m
Definition: citylife.cpp:427
SPLINT
#define SPLINT
Definition: spells.h:165
SP_BULLET
#define SP_BULLET
Definition: spells.h:79
spell_find_dir
int spell_find_dir(mapstruct *m, int x, int y, object *exclude)
Definition: spell_util.c:886
move_swarm_spell
static void move_swarm_spell(object *op)
Definition: spell_effect.c:679
spell_effect_type_move_on
static method_ret spell_effect_type_move_on(object *trap, object *victim, object *originator)
Definition: spell_effect.c:66
object_copy
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:1064
object_update_turn_face
void object_update_turn_face(object *op)
Definition: object.c:1313
remove_unpaid_objects
void remove_unpaid_objects(object *op, object *env, int free_items)
Definition: player.c:3182
cone_drop
void cone_drop(object *op)
Definition: spell_attack.c:265
common_pre_ob_move_on
method_ret common_pre_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:51
obj::speed_left
float speed_left
Definition: object.h:333
move_cone
static void move_cone(object *op)
Definition: spell_effect.c:386
absdir
int absdir(int d)
Definition: object.c:3685
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
explosion
static void explosion(object *op)
Definition: spell_effect.c:313
obj::x
int16_t x
Definition: object.h:330
CFweardisguise.tag
tag
Definition: CFweardisguise.py:25
register_move_on
void register_move_on(int ob_type, move_on_func method)
Definition: ob_types.c:89
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:193
obj::other_arch
struct archt * other_arch
Definition: object.h:418
sstring
const typedef char * sstring
Definition: global.h:40
rndm
int rndm(int min, int max)
Definition: utils.c:162
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
obj::speed
float speed
Definition: object.h:332
tag_t
uint32_t tag_t
Definition: object.h:12
obj::env
struct obj * env
Definition: object.h:296
liv::Con
int8_t Con
Definition: living.h:36
sproto.h
animate.anim
string anim
Definition: animate.py:20
mapdef
Definition: map.h:317
obj::animation
const Animations * animation
Definition: object.h:421
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:250
env
static std::shared_ptr< inja::Environment > env
Definition: mapper.cpp:2216
execute_word_of_recall
static void execute_word_of_recall(object *op)
Definition: spell_effect.c:558
move_aura
static void move_aura(object *aura)
Definition: spell_effect.c:749
try_find_animation
Animations * try_find_animation(const char *name)
Definition: assets.cpp:300
move_object
int move_object(object *op, int dir)
Definition: move.c:39
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:723
obj::y
int16_t y
Definition: object.h:330
method_ret
char method_ret
Definition: ob_methods.h:14
ob_types.h
animations_struct
Definition: face.h:25
sounds.h
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
obj::type
uint8_t type
Definition: object.h:343
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
obj::stats
living stats
Definition: object.h:373
obj::direction
int8_t direction
Definition: object.h:339
archt::clone
object clone
Definition: object.h:473
obj::state
uint8_t state
Definition: object.h:354
liv::Dex
int8_t Dex
Definition: living.h:36
reputation.victim
victim
Definition: reputation.py:14
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
SP_MOVING_BALL
#define SP_MOVING_BALL
Definition: spells.h:109
enter_exit
void enter_exit(object *op, object *exit_ob)
Definition: server.c:732
give.op
op
Definition: give.py:33
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:284
FLAG_REFLECTING
#define FLAG_REFLECTING
Definition: define.h:262
SPELL_EFFECT
@ SPELL_EFFECT
Definition: object.h:215
hit_player
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Definition: attack.c:1860
diamondslots.y
y
Definition: diamondslots.py:16
NUM_ANIMATIONS
#define NUM_ANIMATIONS(ob)
Definition: global.h:168
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
object_update_speed
void object_update_speed(object *op)
Definition: object.c:1330
obj::subtype
uint8_t subtype
Definition: object.h:344
check_spell_expiry
void check_spell_expiry(object *spell)
Definition: spell_util.c:2002
obj::more
struct obj * more
Definition: object.h:298
object_get_env_recursive
object * object_get_env_recursive(object *op)
Definition: object.c:594
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
move_ball_spell
static void move_ball_spell(object *op)
Definition: spell_effect.c:580
FLAG_ANIMATE
#define FLAG_ANIMATE
Definition: define.h:242
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
reflwall
int reflwall(mapstruct *m, int x, int y, object *sp_op)
Definition: spell_util.c:469
move_bolt
static void move_bolt(object *op)
Definition: spell_effect.c:156
OB_TYPE_MOVE_BLOCK
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:432
METHOD_ERROR
#define METHOD_ERROR
Definition: ob_methods.h:17
FREE_OBJ_FREE_INVENTORY
#define FREE_OBJ_FREE_INVENTORY
Definition: object.h:530
move_missile
static void move_missile(object *op)
Definition: spell_effect.c:507
get_random_dir
int get_random_dir(void)
Definition: utils.c:410
ob_methods.h
obj::attacktype
uint32_t attacktype
Definition: object.h:347
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:301
SPELL
@ SPELL
Definition: object.h:214
save_throw_object
void save_throw_object(object *op, uint32_t type, object *originator)
Definition: attack.c:196
SP_SWARM
#define SP_SWARM
Definition: spells.h:110
common_post_ob_move_on
void common_post_ob_move_on(object *trap, object *victim, object *originator)
Definition: common_apply.c:86
forklightning
static void forklightning(object *op, object *tmp)
Definition: spell_effect.c:869
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2657
SP_EXPLOSION
#define SP_EXPLOSION
Definition: spells.h:80
init_type_spell_effect
void init_type_spell_effect(void)
Definition: spell_effect.c:54
animate_bomb
static void animate_bomb(object *op)
Definition: spell_effect.c:454
FLAG_LIFESAVE
#define FLAG_LIFESAVE
Definition: define.h:305
obj::range
int8_t range
Definition: object.h:410
DIRY
#define DIRY(xyz)
Definition: define.h:464
SP_WORD_OF_RECALL
#define SP_WORD_OF_RECALL
Definition: spells.h:92
FLAG_IS_FLOOR
#define FLAG_IS_FLOOR
Definition: define.h:302
object_get_owner
object * object_get_owner(object *op)
Definition: object.c:808
SP_AURA
#define SP_AURA
Definition: spells.h:120