Crossfire Server, Trunk  R22047
attack.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 
21 #include "global.h"
22 
23 #include <assert.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "living.h"
28 #include "material.h"
29 #include "skills.h"
30 #include "sounds.h"
31 #include "sproto.h"
32 
33 /*#define ATTACK_DEBUG*/
34 
35 static void slow_living(object *op, object *hitter, int dam);
36 static void deathstrike_living(object *op, object *hitter, int *dam);
37 static int adj_attackroll(object *hitter, object *target);
38 static int is_aimed_missile(object *op);
39 static int did_make_save_item(object *op, int type, object *originator);
40 static void poison_living(object *op, object *hitter, int dam);
41 
49 static void cancellation(object *op) {
50  if (op->invisible)
51  return;
52 
53  if (QUERY_FLAG(op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) {
54  /* Recur through the inventory */
55  FOR_INV_PREPARE(op, inv)
56  if (!did_make_save_item(inv, AT_CANCELLATION, op))
57  cancellation(inv);
59  } else if (FABS(op->magic) <= rndm(0, 5)) {
60  /* Nullify this object. This code could probably be more complete */
61  /* in what abilities it should cancel */
62  op->magic = 0;
67  if (op->env && op->env->type == PLAYER) {
68  esrv_update_item(UPD_FLAGS, op->env, op);
69  }
70  }
71 }
72 
73 static void object_get_materialtype(object* op, materialtype_t** mt) {
74  if (op->materialname == NULL) {
75  for (*mt = materialt; *mt != NULL && (*mt)->next != NULL; *mt = (*mt)->next) {
76  if (op->material & (*mt)->material)
77  break;
78  }
79  } else
80  *mt = name_to_material(op->materialname);
81 }
82 
98 static int did_make_save_item(object *op, int type, object *originator) {
99  int i, roll, saves = 0, attacks = 0, number;
100  materialtype_t* mt;
101  object_get_materialtype(op, &mt);
102  if (mt == NULL)
103  return TRUE;
104  roll = rndm(1, 20);
105 
106  /* the attacktypes have no meaning for object saves
107  * If the type is only magic, don't adjust type - basically, if
108  * pure magic is hitting an object, it should save. However, if it
109  * is magic teamed with something else, then strip out the
110  * magic type, and instead let the fire, cold, or whatever component
111  * destroy the item. Otherwise, you get the case of poisoncloud
112  * destroying objects because it has magic attacktype.
113  */
114  if (type != AT_MAGIC)
118  AT_MAGIC);
119 
120  if (type == 0)
121  return TRUE;
122  if (roll == 20)
123  return TRUE;
124 
125  for (number = 0; number < NROFATTACKS; number++) {
126  i = 1<<number;
127  if (!(i&type))
128  continue;
129  attacks++;
130  if (op->resist[number] == 100)
131  saves++;
132  else if (roll >= mt->save[number]-op->magic-op->resist[number]/100)
133  saves++;
134  else if ((20-mt->save[number])/3 > originator->stats.dam)
135  saves++;
136  }
137 
138  if (saves == attacks || attacks == 0)
139  return TRUE;
140  if (saves == 0 || rndm(1, attacks) > saves)
141  return FALSE;
142  return TRUE;
143 }
144 
145 static void put_in_icecube(object* op, object* originator) {
146  archetype* at = find_archetype("icecube");
147  if (at == NULL)
148  return;
149  op = stop_item(op);
150  if (op == NULL)
151  return;
152 
153  // Put in existing icecube if one exists, otherwise make one
154  object* tmp = map_find_by_archetype(op->map, op->x, op->y, at);
155  if (tmp == NULL) {
156  tmp = arch_to_object(at);
157  /* This was in the old (pre new movement code) -
158  * icecubes have slow_move set to 1 - don't want
159  * that for ones we create.
160  */
161  tmp->move_slow_penalty = 0;
162  tmp->move_slow = 0;
163  object_insert_in_map_at(tmp, op->map, originator, 0, op->x, op->y);
164  }
165  if (!QUERY_FLAG(op, FLAG_REMOVED))
166  object_remove(op);
167  (void)object_insert_in_ob(op, tmp);
168 }
169 
182 void save_throw_object(object *op, uint32_t type, object *originator) {
183  int dam;
184 
185  if (!did_make_save_item(op, type, originator)) {
186  object *env = op->env;
187  int x = op->x, y = op->y;
188  mapstruct *m = op->map;
189  /* For use with burning off equipped items */
190  int weight = op->weight;
191 
192  op = stop_item(op);
193  if (op == NULL)
194  return;
195 
196  /*
197  * If this object is a transport and has players in it, make them disembark.
198  */
199  if (op->type == TRANSPORT && op->inv) {
200  if (op->map == NULL) {
201  LOG(llevError, "Transport %s not on a map but with an item %s in it?\n", op->name, op->inv->name);
202  } else {
203  char name[MAX_BUF];
204  query_name(op, name, sizeof(name));
205  FOR_INV_PREPARE(op, inv) {
206  if (inv->contr) {
208  "You are expelled from the %s during its destruction.",
209  name);
210  inv->contr->transport = NULL;
211  }
212  }
213  FOR_INV_FINISH();
214  }
215  }
216 
217 
218  /* Set off runes in the inventory of the object being destroyed. */
219  FOR_INV_PREPARE(op, inv)
220  if (inv->type == RUNE)
221  spring_trap(inv, originator);
222  FOR_INV_FINISH();
223 
224  /* Hacked the following so that type LIGHTER will work.
225  * Also, objects which are potenital "lights" that are hit by
226  * flame/elect attacks will be set to glow. "lights" are any
227  * object with +/- glow_radius and an "other_arch" to change to.
228  * (and please note that we cant fail our save and reach this
229  * function if the object doesnt contain a material that can burn.
230  * So forget lighting magical swords on fire with this!) -b.t.
231  */
232  if (type&(AT_FIRE|AT_ELECTRICITY)
233  && op->other_arch
234  && QUERY_FLAG(op, FLAG_IS_LIGHTABLE)) {
235  const char *arch = op->other_arch->name;
236  int no_pick = QUERY_FLAG(op, FLAG_NO_PICK);
237 
238  op = object_decrease_nrof(op, 1);
239  if (op)
240  fix_stopped_item(op, m, originator);
241  op = create_archetype(arch);
242  if (op != NULL) {
243  if (env) {
244  op->x = env->x,
245  op->y = env->y;
246  object_insert_in_ob(op, env);
247  } else {
248  if (no_pick) {
249  SET_FLAG(op, FLAG_NO_PICK);
250  }
251  object_insert_in_map_at(op, m, originator, 0, x, y);
252  }
253  }
254  return;
255  }
256  if (type&AT_CANCELLATION) { /* Cancellation. */
257  cancellation(op);
258  fix_stopped_item(op, m, originator);
259  return;
260  }
261  if (op->nrof > 1) {
262  op = object_decrease_nrof(op, rndm(0, op->nrof-1));
263  if (op)
264  fix_stopped_item(op, m, originator);
265  } else {
266  if (!QUERY_FLAG(op, FLAG_REMOVED))
267  object_remove(op);
269  }
270  if (type&(AT_FIRE|AT_ELECTRICITY)) {
271  if (env) {
272  /* Check to see if the item being burnt is being worn */
273  if (QUERY_FLAG(op, FLAG_APPLIED)) {
274  /* if the object is applied, it should be safe to assume env is a player or creature. */
275  if (env->resist[ATNR_FIRE] < 100)
276  /* Should the message type be something different? */
278  "OUCH! It burns!");
279  else
281  "Despite the flame, you feel nothing.");
282  /* burning off an item causes 1 point of fire damage for every kilogram of mass the item has */
283  dam = weight / 1000 * (100 - env->resist[ATNR_FIRE]) / 100;
284  /* Double the damage on cursed items */
285  if (QUERY_FLAG(op, FLAG_CURSED))
286  dam *= 2;
287  /* Triple the damage on damned items. A cursed and damned item would thus inflict 6x damage. */
288  if (QUERY_FLAG(op, FLAG_DAMNED))
289  dam *= 3;
290  env->stats.hp -= dam;
291  /* You die at -1, not 0 */
292  if (env->stats.hp < 0)
293  kill_player(env, NULL);
294  }
295  op = create_archetype("burnout");
296  op->x = env->x,
297  op->y = env->y;
298  object_insert_in_ob(op, env);
299  } else {
300  object_replace_insert_in_map("burnout", originator);
301  }
302  }
303  return;
304  }
305  /* The value of 50 is arbitrary. */
306  if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) &&
307  !QUERY_FLAG(op, FLAG_NO_PICK) && (RANDOM() & 2)) {
308  put_in_icecube(op, originator);
309  }
310 }
311 
327 int hit_map(object *op, int dir, uint32_t type, int full_hit) {
328  mapstruct *map;
329  int16_t x, y;
330  int retflag = 0; /* added this flag.. will return 1 if it hits a monster */
331  tag_t op_tag;
332 
333  if (QUERY_FLAG(op, FLAG_FREED)) {
334  LOG(llevError, "BUG: hit_map(): free object\n");
335  return 0;
336  }
337 
338  if (QUERY_FLAG(op, FLAG_REMOVED) || op->env != NULL) {
339  LOG(llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", op->arch->name, op->name);
340  return 0;
341  }
342 
343  if (!op->map) {
344  LOG(llevError, "BUG: hit_map(): %s has no map\n", op->name);
345  return 0;
346  }
347 
348  op = HEAD(op);
349  op_tag = op->count;
350 
351  map = op->map;
352  x = op->x+freearr_x[dir];
353  y = op->y+freearr_y[dir];
354  if (get_map_flags(map, &map, x, y, &x, &y)&P_OUT_OF_MAP)
355  return 0;
356 
357  /* peterm: a few special cases for special attacktypes --counterspell
358  * must be out here because it strikes things which are not alive
359  */
360 
361  if (type&AT_COUNTERSPELL) {
362  counterspell(op, dir); /* see spell_effect.c */
363 
364  /* If the only attacktype is counterspell or magic, don't need
365  * to do any further processing.
366  */
367  if (!(type&~(AT_COUNTERSPELL|AT_MAGIC))) {
368  return 0;
369  }
370  type &= ~AT_COUNTERSPELL;
371  }
372 
373  if (type&AT_CHAOS) {
374  shuffle_attack(op);
375  object_update(op, UP_OBJ_FACE);
376  type &= ~AT_CHAOS;
377  }
378 
379  FOR_MAP_PREPARE(map, x, y, tmp) {
380  if (QUERY_FLAG(tmp, FLAG_FREED)) {
381  LOG(llevError, "BUG: hit_map(): found freed object\n");
382  break;
383  }
384 
385  /* Something could have happened to 'tmp' while 'tmp->below' was processed.
386  * For example, 'tmp' was put in an icecube.
387  * This is one of the few cases where on_same_map should not be used.
388  */
389  if (tmp->map != map || tmp->x != x || tmp->y != y)
390  continue;
391 
392  tmp = HEAD(tmp);
393 
394  /* Need to hit everyone in the transport with this spell */
395  if (tmp->type == TRANSPORT) {
396  FOR_INV_PREPARE(tmp, pl)
397  if (pl->type == PLAYER)
398  hit_player(pl, op->stats.dam, op, type, full_hit);
399  FOR_INV_FINISH();
400  }
401 
402  if (QUERY_FLAG(tmp, FLAG_ALIVE)) {
403  hit_player(tmp, op->stats.dam, op, type, full_hit);
404  retflag |= 1;
405  if (object_was_destroyed(op, op_tag))
406  break;
407  }
408  /* Here we are potentially destroying an object. If the object has
409  * NO_PASS set, it is also immune - you can't destroy walls. Note
410  * that weak walls have is_alive set, which prevent objects from
411  * passing over/through them. We don't care what type of movement
412  * the wall blocks - if it blocks any type of movement, can't be
413  * destroyed right now.
414  */
415  else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block) {
416  save_throw_object(tmp, type, op);
417  if (object_was_destroyed(op, op_tag))
418  break;
419  }
420  } FOR_MAP_FINISH();
421  return 0;
422 }
423 
439 static void attack_message(int dam, int type, object *op, object *hitter) {
440  char buf[MAX_BUF], buf1[MAX_BUF], buf2[MAX_BUF];
441  int i, found = 0;
442  mapstruct *map;
443  object *owner;
444 
445  /* put in a few special messages for some of the common attacktypes
446  * a player might have. For example, fire, electric, cold, etc
447  * [garbled 20010919]
448  */
449 
450  if (dam == 9998 && op->type == DOOR) {
451  snprintf(buf1, sizeof(buf1), "unlock %s", op->name);
452  snprintf(buf2, sizeof(buf2), " unlocks");
453  found++;
454  }
455  if (dam < 0) {
456  snprintf(buf1, sizeof(buf1), "hit %s", op->name);
457  snprintf(buf2, sizeof(buf2), " hits");
458  found++;
459  } else if (dam == 0) {
460  snprintf(buf1, sizeof(buf1), "missed %s", op->name);
461  snprintf(buf2, sizeof(buf2), " misses");
462  found++;
463  } else if ((hitter->type == DISEASE
464  || hitter->type == SYMPTOM
465  || hitter->type == POISONING
466  || (type&AT_POISON && IS_LIVE(op))) && !found) {
467  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++)
468  if (dam < attack_mess[ATM_SUFFER][i].level
469  || attack_mess[ATM_SUFFER][i+1].level == -1) {
470  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, op->name, attack_mess[ATM_SUFFER][i].buf2);
471  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_SUFFER][i].buf3);
472  found++;
473  break;
474  }
475  } else if (op->type == DOOR && !found) {
476  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DOOR][i].level != -1; i++)
477  if (dam < attack_mess[ATM_DOOR][i].level
478  || attack_mess[ATM_DOOR][i+1].level == -1) {
479  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_DOOR][i].buf1, op->name, attack_mess[ATM_DOOR][i].buf2);
480  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_DOOR][i].buf3);
481  found++;
482  break;
483  }
484  } else if (hitter->type == PLAYER && IS_LIVE(op)) {
485  if (USING_SKILL(hitter, SK_KARATE)) {
486  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++)
487  if (dam < attack_mess[ATM_KARATE][i].level
488  || attack_mess[ATM_KARATE][i+1].level == -1) {
489  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_KARATE][i].buf1, op->name, attack_mess[ATM_KARATE][i].buf2);
490  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_KARATE][i].buf3);
491  found++;
492  break;
493  }
494  } else if (USING_SKILL(hitter, SK_CLAWING)) {
495  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_CLAW][i].level != -1; i++)
496  if (dam < attack_mess[ATM_CLAW][i].level
497  || attack_mess[ATM_CLAW][i+1].level == -1) {
498  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_CLAW][i].buf1, op->name, attack_mess[ATM_CLAW][i].buf2);
499  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_CLAW][i].buf3);
500  found++;
501  break;
502  }
503  } else if (USING_SKILL(hitter, SK_PUNCHING)) {
504  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_PUNCH][i].level != -1; i++)
505  if (dam < attack_mess[ATM_PUNCH][i].level
506  || attack_mess[ATM_PUNCH][i+1].level == -1) {
507  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_PUNCH][i].buf1, op->name, attack_mess[ATM_PUNCH][i].buf2);
508  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_PUNCH][i].buf3);
509  found++;
510  break;
511  }
512  } else if (USING_SKILL(hitter, SK_WRAITH_FEED)) {
513  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_WRAITH_FEED][i].level != -1; i++)
514  if (dam < attack_mess[ATM_WRAITH_FEED][i].level) {
515  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_WRAITH_FEED][i].buf1, op->name, attack_mess[ATM_WRAITH_FEED][i].buf2);
516  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_WRAITH_FEED][i].buf3);
517  found++;
518  break;
519  }
520  }
521  }
522  if (found) {
523  /* done */
524  } else if (IS_ARROW(hitter) && (type == AT_PHYSICAL || type == AT_MAGIC)) {
525  snprintf(buf1, sizeof(buf1), "hit"); /* just in case */
526  for (i = 0; i < MAXATTACKMESS; i++)
527  if (dam < attack_mess[ATM_ARROW][i].level
528  || attack_mess[ATM_ARROW][i+1].level == -1) {
529  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_ARROW][i].buf3);
530  found++;
531  break;
532  }
533  } else if (type&AT_DRAIN && IS_LIVE(op)) {
534  /* drain is first, because some items have multiple attypes */
535  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++)
536  if (dam < attack_mess[ATM_DRAIN][i].level
537  || attack_mess[ATM_DRAIN][i+1].level == -1) {
538  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_DRAIN][i].buf1, op->name, attack_mess[ATM_DRAIN][i].buf2);
539  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_DRAIN][i].buf3);
540  found++;
541  break;
542  }
543  } else if (type&AT_ELECTRICITY && IS_LIVE(op)) {
544  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++)
545  if (dam < attack_mess[ATM_ELEC][i].level
546  || attack_mess[ATM_ELEC][i+1].level == -1) {
547  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_ELEC][i].buf1, op->name, attack_mess[ATM_ELEC][i].buf2);
548  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_ELEC][i].buf3);
549  found++;
550  break;
551  }
552  } else if (type&AT_COLD && IS_LIVE(op)) {
553  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++)
554  if (dam < attack_mess[ATM_COLD][i].level
555  || attack_mess[ATM_COLD][i+1].level == -1) {
556  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_COLD][i].buf1, op->name, attack_mess[ATM_COLD][i].buf2);
557  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_COLD][i].buf3);
558  found++;
559  break;
560  }
561  } else if (type&AT_FIRE) {
562  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_FIRE][i].level != -1; i++)
563  if (dam < attack_mess[ATM_FIRE][i].level
564  || attack_mess[ATM_FIRE][i+1].level == -1) {
565  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_FIRE][i].buf1, op->name, attack_mess[ATM_FIRE][i].buf2);
566  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_FIRE][i].buf3);
567  found++;
568  break;
569  }
570  } else if (hitter->current_weapon != NULL) {
571  int mtype;
572 
573  switch (hitter->current_weapon->weapontype) {
574  case WEAP_HIT: mtype = ATM_BASIC; break;
575  case WEAP_SLASH: mtype = ATM_SLASH; break;
576  case WEAP_PIERCE: mtype = ATM_PIERCE; break;
577  case WEAP_CLEAVE: mtype = ATM_CLEAVE; break;
578  case WEAP_SLICE: mtype = ATM_SLICE; break;
579  case WEAP_STAB: mtype = ATM_STAB; break;
580  case WEAP_WHIP: mtype = ATM_WHIP; break;
581  case WEAP_CRUSH: mtype = ATM_CRUSH; break;
582  case WEAP_BLUD: mtype = ATM_BLUD; break;
583  default: mtype = ATM_BASIC; break;
584  }
585  for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++)
586  if (dam < attack_mess[mtype][i].level
587  || attack_mess[mtype][i+1].level == -1) {
588  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[mtype][i].buf1, op->name, attack_mess[mtype][i].buf2);
589  snprintf(buf2, sizeof(buf2), "%s", attack_mess[mtype][i].buf3);
590  found++;
591  break;
592  }
593  } else {
594  for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_BASIC][i].level != -1; i++)
595  if (dam < attack_mess[ATM_BASIC][i].level
596  || attack_mess[ATM_BASIC][i+1].level == -1) {
597  snprintf(buf1, sizeof(buf1), "%s %s%s", attack_mess[ATM_BASIC][i].buf1, op->name, attack_mess[ATM_BASIC][i].buf2);
598  snprintf(buf2, sizeof(buf2), "%s", attack_mess[ATM_BASIC][i].buf3);
599  found++;
600  break;
601  }
602  }
603 
604  if (!found) {
605  snprintf(buf1, sizeof(buf1), "hit");
606  snprintf(buf2, sizeof(buf2), "hits");
607  }
608 
609  if (dam > 0) {
610  if (hitter->chosen_skill)
611  play_sound_map(SOUND_TYPE_HIT, hitter, 0, hitter->chosen_skill->name);
612  }
613 
614  /* bail out if a monster is casting spells */
615  owner = object_get_owner(hitter);
616  if (hitter->type != PLAYER && (owner == NULL || owner->type != PLAYER))
617  return;
618 
619  /* scale down magic considerably. */
620  if (type&AT_MAGIC && rndm(0, 5))
621  return;
622 
623  /* Did a player hurt another player? Inform both! */
624  /* only show half the player->player combat messages */
625  if (op->type == PLAYER
626  && rndm(0, 1)
627  && ((owner != NULL ? owner : hitter)->type) == PLAYER) {
628  if (owner != NULL)
629  snprintf(buf, sizeof(buf), "%s's %s %s you.", owner->name, hitter->name, buf2);
630  else {
631  snprintf(buf, sizeof(buf), "%s%s you.", hitter->name, buf2);
632  }
634  } /* end of player hitting player */
635 
636  /* scale down these messages too */
637  /*if(hitter->type == PLAYER && rndm(0, 2) == 0) {*/
638  if (hitter->type == PLAYER) {
639  snprintf(buf, sizeof(buf), "You %s.", buf1);
641  buf);
642  } else if (owner != NULL && owner->type == PLAYER) {
643  /* look for stacked spells and start reducing the message chances */
644  if (hitter->type == SPELL_EFFECT
645  && (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE)) {
646  i = 4;
647  map = hitter->map;
648  if (OUT_OF_REAL_MAP(map, hitter->x, hitter->y))
649  return;
650  FOR_MAP_PREPARE(map, hitter->x, hitter->y, next)
651  if (next->type == SPELL_EFFECT
652  && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) {
653  i *= 3;
654  if (i > 10000)
655  /* no need to test more, and avoid overflows */
656  break;
657  }
658  FOR_MAP_FINISH();
659  if (i < 0)
660  return;
661  if (rndm(0, i) != 0)
662  return;
663  } else if (rndm(0, 5) != 0)
664  return;
665  play_sound_map(SOUND_TYPE_HIT, owner, 0, "hit");
667  "Your %s%s %s.",
668  hitter->name, buf2, op->name);
669  }
670 }
671 
683 static int get_attack_mode(object **target, object **hitter,
684  int *simple_attack) {
685  if (QUERY_FLAG(*target, FLAG_FREED) || QUERY_FLAG(*hitter, FLAG_FREED)) {
686  LOG(llevError, "BUG: get_attack_mode(): freed object\n");
687  return 1;
688  }
689  *target = HEAD(*target);
690  *hitter = HEAD(*hitter);
691  if ((*hitter)->env != NULL || (*target)->env != NULL) {
692  *simple_attack = 1;
693  return 0;
694  }
695  if (QUERY_FLAG(*target, FLAG_REMOVED)
696  || QUERY_FLAG(*hitter, FLAG_REMOVED)
697  || (*hitter)->map == NULL
698  || !on_same_map((*hitter), (*target))) {
699  LOG(llevError, "BUG: hitter (arch %s, name %s) with no relation to target\n", (*hitter)->arch->name, (*hitter)->name);
700  return 1;
701  }
702  *simple_attack = 0;
703  return 0;
704 }
705 
719 static int abort_attack(object *target, object *hitter, int simple_attack) {
720  int new_mode;
721 
722  if (hitter->env == target || target->env == hitter)
723  new_mode = 1;
724  else if (QUERY_FLAG(hitter, FLAG_REMOVED)
725  || QUERY_FLAG(target, FLAG_REMOVED)
726  || hitter->map == NULL || !on_same_map(hitter, target))
727  return 1;
728  else
729  new_mode = 0;
730  return new_mode != simple_attack;
731 }
732 
733 static void thrown_item_effect(object *, object *);
734 
750 static int attack_ob_simple(object *op, object *hitter, int base_dam, int base_wc) {
751  int simple_attack, roll, dam;
752  uint32_t type;
753  tag_t op_tag, hitter_tag;
754  const char *anim_suffix = NULL;
755 
756  if (get_attack_mode(&op, &hitter, &simple_attack))
757  return 1;
758 
759  /* This is used to handle script_weapons with weapons, only for players. */
760  if (hitter->type == PLAYER) {
761  if (hitter->current_weapon != NULL) {
762  if (events_execute_object_event(hitter->current_weapon, EVENT_ATTACKS,
763  hitter, op, NULL, SCRIPT_FIX_ALL) != 0)
764  return 0;
765  }
766  }
767 
768  if (hitter->current_weapon) {
769  anim_suffix = hitter->current_weapon->anim_suffix;
770  } else if (hitter->chosen_skill) {
771  anim_suffix = hitter->chosen_skill->anim_suffix;
772  }
773 
774  if (!anim_suffix) {
775  anim_suffix = "attack";
776  }
777  apply_anim_suffix(hitter, anim_suffix);
778 
779 
780  op_tag = op->count;
781  hitter_tag = hitter->count;
782  /*
783  * A little check to make it more difficult to dance forward and back
784  * to avoid ever being hit by monsters.
785  */
786  if (!simple_attack && QUERY_FLAG(op, FLAG_MONSTER)
787  && op->speed_left > -(FABS(op->speed))*0.3) {
788  /* Decrease speed BEFORE calling process_object. Otherwise, an
789  * infinite loop occurs, with process_object calling monster_move(),
790  * which then gets here again. By decreasing the speed before
791  * we call process_object, the 'if' statement above will fail.
792  */
793  op->speed_left--;
794  process_object(op);
795  if (object_was_destroyed(op, op_tag)
796  || object_was_destroyed(hitter, hitter_tag)
797  || abort_attack(op, hitter, simple_attack))
798  return 1;
799  }
800 
801  roll = random_roll(1, 20, hitter, PREFER_HIGH);
802 
803  /* Adjust roll for various situations. */
804  if (!simple_attack)
805  roll += adj_attackroll(hitter, op);
806 
807  /* See if we hit the creature */
808  if (roll >= 20 || op->stats.ac >= base_wc-roll) {
809  if (settings.casting_time == TRUE) {
810  if (hitter->type == PLAYER && hitter->casting_time > -1) {
811  hitter->casting_time = -1;
813  "You attacked and lost your spell!");
814  }
815  if (op->casting_time > -1 && base_dam > 0) {
816  op->casting_time = -1;
817  if (op->type == PLAYER) {
819  "You were hit and lost your spell!");
822  "%s was hit by %s and lost a spell.",
823  op->name, hitter->name);
824  }
825  }
826  }
827  if (!simple_attack) {
828  /* If you hit something, the victim should *always *wake up.
829  * Before, invisible hitters could avoid doing this.
830  * -b.t. */
831  if (QUERY_FLAG(op, FLAG_SLEEP))
832  CLEAR_FLAG(op, FLAG_SLEEP);
833 
834  /* If the victim can't see the attacker, it may alert others
835  * for help. */
836  if (op->type != PLAYER && !monster_can_see_enemy(op, hitter)
837  && !object_get_owner(op) && rndm(0, op->stats.Int))
839 
840  /* if you were hidden and hit by a creature, you are discovered*/
841  if (op->hide && QUERY_FLAG(hitter, FLAG_ALIVE)) {
842  make_visible(op);
843  if (op->type == PLAYER)
845  "You were hit by a wild attack. You are no longer hidden!");
846  }
847 
848  /* thrown items (hitter) will have various effects
849  * when they hit the victim. For things like thrown daggers,
850  * this sets 'hitter' to the actual dagger, and not the
851  * wrapper object.
852  */
853  thrown_item_effect(hitter, op);
854  if (object_was_destroyed(hitter, hitter_tag)
855  || object_was_destroyed(op, op_tag)
856  || abort_attack(op, hitter, simple_attack)) {
857  return 0;
858  }
859  }
860 
861  /* Need to do at least 1 damage, otherwise there is no point
862  * to go further and it will cause FPE's below.
863  */
864  if (base_dam <= 0)
865  base_dam = 1;
866 
867  type = hitter->attacktype;
868  if (!type)
869  type = AT_PHYSICAL;
870  /* Handle monsters that hit back */
871  if (!simple_attack && QUERY_FLAG(op, FLAG_HITBACK)
872  && QUERY_FLAG(hitter, FLAG_ALIVE)) {
873  if (op->attacktype&AT_ACID && hitter->type == PLAYER)
875  "You are splashed by acid!\n");
876  hit_player(hitter, random_roll(0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1);
877  if (object_was_destroyed(op, op_tag)
878  || object_was_destroyed(hitter, hitter_tag)
879  || abort_attack(op, hitter, simple_attack)) {
880  return 0;
881  }
882  }
883 
884  /* In the new attack code, it should handle multiple attack
885  * types in its area, so remove it from here.
886  */
887  dam = hit_player(op, random_roll(1, base_dam, hitter, PREFER_HIGH), hitter, type, 1);
888  if (object_was_destroyed(op, op_tag)
889  || object_was_destroyed(hitter, hitter_tag)
890  || abort_attack(op, hitter, simple_attack)) {
891  return 0;
892  }
893  } else {/* end of if hitter hit op */
894  play_sound_map(SOUND_TYPE_HIT, hitter, 0, "miss");
895  dam = 0; /* if we missed, dam=0 */
896  }
897 
898  /*attack_message(dam, type, op, hitter);*/
899 
900  return dam;
901 }
902 
912 int attack_ob(object *op, object *hitter) {
913  hitter = HEAD(hitter);
914  return attack_ob_simple(op, hitter, hitter->stats.dam, hitter->stats.wc);
915 }
916 
927 static int stick_arrow(object *op, object *tmp) {
928  /* If the missile hit a player, we insert it in their inventory.
929  * However, if the missile is heavy, we don't do so (assume it falls
930  * to the ground after a hit). What a good value for this is up to
931  * debate - 5000 is 5 kg, so arrows, knives, and other light weapons
932  * stick around.
933  */
934  if (op->weight <= 5000 && tmp->stats.hp >= 0) {
935  object_remove(op);
936  op = object_insert_in_ob(op, HEAD(tmp));
937  return 1;
938  } else
939  return 0;
940 }
941 
954 object *hit_with_arrow(object *op, object *victim) {
955  object *container, *hitter;
956  int hit_something = 0;
957  tag_t victim_tag, hitter_tag, container_tag;
958  int16_t victim_x, victim_y;
959  mapstruct *victim_map;
960  const char *old_skill = NULL;
961 
962  /* Disassemble missile */
963  hitter = op->inv;
965  if (hitter->type != EVENT_CONNECTOR) {
966  break;
967  }
969  if (!hitter) {
970  container = NULL;
971  hitter = op;
972  if (free_no_drop(hitter))
973  return NULL;
974  } else {
975  container = op;
976  object_remove(hitter);
977  if (free_no_drop(hitter))
978  return NULL;
979 
980  object_insert_in_map_at(hitter, container->map, hitter, INS_NO_MERGE|INS_NO_WALK_ON, container->x, container->y);
981  /* Note that we now have an empty THROWN_OBJ on the map. Code that
982  * might be called until this THROWN_OBJ is either reassembled or
983  * removed at the end of this function must be able to deal with empty
984  * THROWN_OBJs. */
985  container_tag = container->count;
986  }
987 
988  /* Try to hit victim */
989  victim_x = victim->x;
990  victim_y = victim->y;
991  victim_map = victim->map;
992  victim_tag = victim->count;
993  hitter_tag = hitter->count;
994  /* FIXME provide also to script the skill? hitter is the throwed
995  items, but there is no information about the fact it was
996  thrown
997  */
998  if (events_execute_object_event(op, EVENT_ATTACKS, hitter, victim, NULL, SCRIPT_FIX_ALL) == 0) {
999  /*
1000  * temporary set the hitter's skill to the one associated with the
1001  * throw wrapper. This is needed to that thrower gets it's xp at the
1002  * correct level. This might proves an awfull hack :/ We should really
1003  * provide attack_ob_simple with the skill to use...
1004  */
1005  if (container != NULL) {
1006  old_skill = hitter->skill;
1007  hitter->skill = add_refcount(container->skill);
1008  }
1009  hit_something = attack_ob_simple(victim, hitter, op->stats.dam, op->stats.wc);
1010  }
1011  /* Arrow attacks door, rune of summoning is triggered, demon is put on
1012  * arrow, move_apply() calls this function, arrow sticks in demon,
1013  * attack_ob_simple() returns, and we've got an arrow that still exists
1014  * but is no longer on the map. Ugh. (Beware: Such things can happen at
1015  * other places as well!)
1016  */
1017  if (object_was_destroyed(hitter, hitter_tag) || hitter->env != NULL) {
1018  if (container) {
1019  object_remove(container);
1020  object_free_drop_inventory(container);
1021  }
1022  return NULL;
1023  }
1024  if (container != NULL) {
1025  free_string(hitter->skill);
1026  hitter->skill = old_skill;
1027  }
1028  /* Missile hit victim */
1029  /* if the speed is > 10, then this is a fast moving arrow, we go straight
1030  * through the target
1031  */
1032  if (hit_something && op->speed <= 10.0) {
1033  /* Stop arrow */
1034  if (container == NULL) {
1035  hitter = fix_stopped_arrow(hitter);
1036  if (hitter == NULL)
1037  return NULL;
1038  } else {
1039  if(!object_was_destroyed(container, container_tag)) {
1040  object_remove(container);
1041  object_free_drop_inventory(container);
1042  }
1043  }
1044 
1045  /* Try to stick arrow into victim */
1046  if (!object_was_destroyed(victim, victim_tag)
1047  && stick_arrow(hitter, victim)) {
1048  object_set_owner(hitter, NULL);
1049  return NULL;
1050  }
1051 
1052  /* Else try to put arrow on victim's map square
1053  * remove check for P_WALL here. If the arrow got to this
1054  * space, that is good enough - with the new movement code,
1055  * there is now the potential for lots of spaces where something
1056  * can fly over but not otherwise move over. What is the correct
1057  * way to handle those otherwise?
1058  */
1059  if (victim_x != hitter->x || victim_y != hitter->y) {
1060  object_remove(hitter);
1061  object_set_owner(hitter, NULL);
1062  object_insert_in_map_at(hitter, victim_map, hitter, 0, victim_x, victim_y);
1063  } else {
1064  /* Else leave arrow where it is */
1065  object_merge(hitter, NULL);
1066  object_set_owner(hitter, NULL);
1067  }
1068  return NULL;
1069  }
1070 
1071  if (hit_something && op->speed >= 10.0)
1072  op->speed -= 1.0;
1073 
1074  /* Missile missed victim - reassemble missile */
1075  if (container) {
1076  object_remove(hitter);
1077  object_insert_in_ob(hitter, container);
1078  }
1079  return op;
1080 }
1088 static void tear_down_wall(object *op) {
1089  int perc = 0;
1090 
1091  if (!op->stats.maxhp) {
1092  LOG(llevError, "TEAR_DOWN wall %s had no maxhp.\n", op->name);
1093  perc = 1;
1094  } else if (!GET_ANIM_ID(op)) {
1095  /* Object has been called - no animations, so remove it */
1096  if (op->stats.hp < 0) {
1097  object_remove(op); /* Should update LOS */
1099  /* Don't know why this is here - object_remove() should do it for us */
1100  /*update_position(m, x, y);*/
1101  }
1102  return; /* no animations, so nothing more to do */
1103  }
1104  assert(op->stats.maxhp > 0);
1105  perc = NUM_ANIMATIONS(op)-((int)NUM_ANIMATIONS(op)*op->stats.hp)/op->stats.maxhp;
1106 
1107  if (perc >= (int)NUM_ANIMATIONS(op))
1108  perc = NUM_ANIMATIONS(op)-1;
1109  else if (perc < 1)
1110  perc = 1;
1111  SET_ANIMATION(op, perc);
1112  object_update(op, UP_OBJ_FACE);
1113  if (perc == NUM_ANIMATIONS(op)-1) { /* Reached the last animation */
1114  if (op->face == blank_face) {
1115  /* If the last face is blank, remove the ob */
1116  object_remove(op); /* Should update LOS */
1118 
1119  /* object_remove() should call update_position for us */
1120  /*update_position(m, x, y);*/
1121  } else { /* The last face was not blank, leave an image */
1123  update_all_los(op->map, op->x, op->y);
1124  op->move_block = 0;
1125  CLEAR_FLAG(op, FLAG_ALIVE);
1126  }
1127  }
1128 }
1129 
1137 static void scare_creature(object *target, object *hitter) {
1138  object *owner = object_get_owner(hitter);
1139 
1140  if (!owner)
1141  owner = hitter;
1142 
1143  SET_FLAG(target, FLAG_SCARED);
1144  if (!target->enemy)
1145  object_set_enemy(target, owner);
1146 }
1147 
1164 static int hit_with_one_attacktype(object *op, object *hitter, int dam, uint32_t attacknum) {
1165  int doesnt_slay = 1;
1166  char name_hitter[MAX_BUF], name_op[MAX_BUF];
1167 
1168  /* Catch anyone that may be trying to send us a bitmask instead of the number */
1169  if (attacknum >= NROFATTACKS) {
1170  LOG(llevError, "hit_with_one_attacktype: Invalid attacknumber passed: %u\n", attacknum);
1171  return 0;
1172  }
1173 
1174  if (dam < 0) {
1175  LOG(llevError, "hit_with_one_attacktype called with negative damage: %d\n", dam);
1176  return 0;
1177  }
1178 
1179  /* AT_INTERNAL is supposed to do exactly dam. Put a case here so
1180  * people can't mess with that or it otherwise get confused. */
1181  if (attacknum == ATNR_INTERNAL)
1182  return dam;
1183 
1184  if (hitter->slaying) {
1185  // Look for the race as one of many that can be listed.
1186  if ((op->race != NULL && strstr(op->race, hitter->slaying))
1187  /*
1188  * Since we can do multiple races, we should be able to avoid the arch check.
1189  * This gives a more flexible race system, so skeletal mages can be a type of skeleton and such
1190  || (op->arch && op->arch->name != NULL && strstr(op->arch->name, hitter->slaying))
1191  */) {
1192  doesnt_slay = 0;
1193  dam *= 3;
1194  }
1195  }
1196 
1197  /* Adjust the damage for resistance. Note that neg. values increase damage. */
1198  /*
1199  * Skip lifestealing here, because it undergoes a more specific resistance scaling
1200  * in its own section that involves the better of drain/life stealing resistance
1201  *
1202  * Daniel Hawkins 2018-05-31
1203  */
1204  if (attacknum != ATNR_LIFE_STEALING && op->resist[attacknum]) {
1205  /* basically: dam = dam*(100-op->resist[attacknum])/100;
1206  * in case 0>dam>1, we try to "simulate" a float value-effect */
1207  dam *= (100-op->resist[attacknum]);
1208  if (dam >= 100)
1209  dam /= 100;
1210  else
1211  dam = (dam > (random_roll(0, 99, op, PREFER_LOW))) ? 1 : 0;
1212  }
1213 
1214  /* Special hack. By default, if immune to something, you
1215  * shouldn't need to worry. However, acid is an exception, since
1216  * it can still damage your items. Only include attacktypes if
1217  * special processing is needed */
1218 
1219  if (op->resist[attacknum] >= 100
1220  && doesnt_slay
1221  && attacknum != ATNR_ACID)
1222  return 0;
1223 
1224  /* Keep this in order - makes things easier to find */
1225 
1226  switch (attacknum) {
1227  case ATNR_PHYSICAL:
1228  /* here also check for diseases */
1229  check_physically_infect(op, hitter);
1230  break;
1231 
1232  /* Don't need to do anything for:
1233  magic,
1234  fire,
1235  electricity,
1236  cold */
1237 
1238  case ATNR_CONFUSION:
1239  case ATNR_POISON:
1240  case ATNR_SLOW:
1241  case ATNR_PARALYZE:
1242  case ATNR_FEAR:
1243  case ATNR_CANCELLATION:
1244  case ATNR_DEPLETE:
1245  case ATNR_BLIND: {
1246  /* chance for inflicting a special attack depends on the
1247  * difference between attacker's and defender's level
1248  */
1249  int level_diff = MIN(110, MAX(0, op->level-hitter->level));
1250 
1251  /* First, only creatures/players with speed can be affected.
1252  * Second, just getting hit doesn't mean it always affects
1253  * you. Third, you still get a saving through against the
1254  * effect.
1255  */
1256  if (op->speed
1257  && (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER)
1258  && !(rndm(0, (attacknum == ATNR_SLOW ? 6 : 3)-1))
1259  && !did_make_save(op, level_diff, op->resist[attacknum]/10)) {
1260  /* Player has been hit by something */
1261  if (attacknum == ATNR_CONFUSION)
1262  confuse_living(op, hitter, dam);
1263  else if (attacknum == ATNR_POISON)
1264  poison_living(op, hitter, dam);
1265  else if (attacknum == ATNR_SLOW)
1266  slow_living(op, hitter, dam);
1267  else if (attacknum == ATNR_PARALYZE)
1268  paralyze_living(op, dam);
1269  else if (attacknum == ATNR_FEAR)
1270  scare_creature(op, hitter);
1271  else if (attacknum == ATNR_CANCELLATION)
1272  cancellation(op);
1273  else if (attacknum == ATNR_DEPLETE)
1274  drain_stat(op);
1275  else if (attacknum == ATNR_BLIND
1276  && !QUERY_FLAG(op, FLAG_UNDEAD)
1277  && !QUERY_FLAG(op, FLAG_GENERATOR))
1278  blind_living(op, hitter, dam);
1279  }
1280  dam = 0; /* These are all effects and don't do real damage */
1281  }
1282  break;
1283 
1284  case ATNR_ACID: {
1285  int flag = 0;
1286 
1287  /* Items only get corroded if you're not on a battleground and
1288  * if your acid resistance is below 50%. */
1289  if (!op_on_battleground(op, NULL, NULL, NULL)
1290  && (op->resist[ATNR_ACID] < 50)) {
1291  FOR_INV_PREPARE(op, tmp) {
1292  if (tmp->invisible)
1293  continue;
1294  if (!QUERY_FLAG(tmp, FLAG_APPLIED)
1295  || (tmp->resist[ATNR_ACID] >= 10))
1296  /* >= 10% acid res. on itmes will protect these */
1297  continue;
1298  if (!(tmp->material&M_IRON))
1299  continue;
1300  if (tmp->magic < -4) /* Let's stop at -5 */
1301  continue;
1302  if (tmp->type == RING
1303  /* removed boots and gloves from exclusion list in PR */
1304  || tmp->type == GIRDLE
1305  || tmp->type == AMULET
1306  || tmp->type == WAND
1307  || tmp->type == ROD)
1308  continue; /* To avoid some strange effects */
1309 
1310  /* High damage acid has better chance of corroding objects */
1311  if (rndm(0, dam+4) > random_roll(0, 39, op, PREFER_HIGH)+2*tmp->magic) {
1312  if (op->type == PLAYER) {
1313  /* Make this more visible */
1314  query_name(hitter, name_hitter, MAX_BUF);
1315  query_name(tmp, name_op, MAX_BUF);
1318  "The %s's acid corrodes your %s!",
1319  name_hitter, name_op);
1320  }
1321  flag = 1;
1322  tmp->magic--;
1323  if (op->type == PLAYER)
1324  esrv_update_item(UPD_NAME, op, tmp);
1325  }
1326  } FOR_INV_FINISH();
1327  if (flag)
1328  fix_object(op); /* Something was corroded */
1329  }
1330  }
1331  break;
1332 
1333  case ATNR_DRAIN: {
1334  /* rate is the proportion of exp drained. High rate means
1335  * not much is drained, low rate means a lot is drained.
1336  */
1337  int rate;
1338 
1339  if (op->resist[ATNR_DRAIN] >= 0)
1340  rate = 50+op->resist[ATNR_DRAIN]/2;
1341  else
1342  rate = 5000/(100-op->resist[ATNR_DRAIN]);
1343 
1344  /* full protection has no effect. Nothing else in this
1345  * function needs to get done, so just return. */
1346  if (!rate)
1347  return 0;
1348 
1349  if (op->stats.exp <= rate) {
1350  if (op->type == GOLEM)
1351  dam = 999; /* Its force is "sucked" away. 8) */
1352  else
1353  /* If we can't drain, lets try to do physical damage */
1354  dam = hit_with_one_attacktype(op, hitter, dam, ATNR_PHYSICAL);
1355  } else {
1356  /* Randomly give the hitter some hp */
1357  if (hitter->stats.hp < hitter->stats.maxhp
1358  && (op->level > hitter->level)
1359  && random_roll(0, (op->level-hitter->level+2), hitter, PREFER_HIGH) > 3)
1360  hitter->stats.hp++;
1361 
1362  /* Can't do drains on battleground spaces.
1363  * Move the wiz check up here - before, the hitter wouldn't gain exp
1364  * exp, but the wiz would still lose exp! If drainee is a wiz,
1365  * nothing happens.
1366  * Try to credit the owner. We try to display player -> player drain
1367  * attacks, hence all the != PLAYER checks.
1368  */
1369  if (!op_on_battleground(hitter, NULL, NULL, NULL) && !QUERY_FLAG(op, FLAG_WAS_WIZ)) {
1370  object *owner = object_get_owner(hitter);
1371  int64_t orig_exp = op->stats.exp;
1372 
1373  change_exp(op, -op->stats.exp/rate, NULL, 0);
1374 
1375  if (owner && owner != hitter) {
1376  if (op->type != PLAYER || owner->type != PLAYER)
1377  change_exp(owner, MIN(op->stats.exp/(rate*2), orig_exp - op->stats.exp),
1378  hitter->chosen_skill ? hitter->chosen_skill->skill : NULL, SK_EXP_TOTAL);
1379  } else if (op->type != PLAYER || hitter->type != PLAYER) {
1380  change_exp(hitter, MIN(op->stats.exp/(rate*2), orig_exp - op->stats.exp),
1381  hitter->chosen_skill ? hitter->chosen_skill->skill : NULL, 0);
1382  }
1383  }
1384  dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
1385  * drain attack, you won't know that you are actually sucking out EXP,
1386  * as the messages will say you missed
1387  */
1388  }
1389  }
1390  break;
1391 
1392  case ATNR_TURN_UNDEAD: {
1393  if (QUERY_FLAG(op, FLAG_UNDEAD)) {
1394  object *owner = object_get_owner(hitter) == NULL ? hitter : object_get_owner(hitter);
1395  const object *god = find_god(determine_god(owner));
1396  int div = 1;
1397 
1398  /* if undead are not an enemy of your god, you turn them
1399  * at half strength */
1400  if (!god
1401  || !god->slaying
1402  || strstr(god->slaying, undead_name) == NULL)
1403  div = 2;
1404 
1405  /* The previous code was highly suspect - resist turn undead/100 would
1406  * at best give a bonus of 1 - increase that to resist turn undead/20 -
1407  * this gives a bit higher bonus. Also the bonus was added to the wrong
1408  * side of the equation, actually making it easier to turn creatures
1409  * if they had that resistance.
1410  */
1411  if ((op->level*div + (op->resist[ATNR_TURN_UNDEAD] / 20)) < (get_turn_bonus(owner->stats.Wis)+owner->level))
1412  scare_creature(op, owner);
1413  } else
1414  dam = 0; /* don't damage non undead - should we damage undead? */
1415  }
1416  break;
1417 
1418  case ATNR_DEATH:
1419  deathstrike_living(op, hitter, &dam);
1420  break;
1421 
1422  case ATNR_CHAOS:
1423  query_name(op, name_op, MAX_BUF);
1424  query_name(hitter, name_hitter, MAX_BUF);
1425  LOG(llevError, "%s was hit by %s with non-specific chaos.\n", name_op, name_hitter);
1426  dam = 0;
1427  break;
1428 
1429  case ATNR_COUNTERSPELL:
1430  dam = 0;
1431  /* While counterspell is handled separately and filtered out when it
1432  * moves, players can still step on a square that has an active
1433  * counterspell. When this happens, do no damage because counterspell
1434  * has no effect on anything but spells. */
1435  break;
1436 
1437  case ATNR_HOLYWORD: {
1438  /* This has already been handled by hit_player,
1439  * no need to check twice -- DAMN */
1440 
1441  object *owner = object_get_owner(hitter) == NULL ? hitter : object_get_owner(hitter);
1442 
1443  /* As with turn undead above, give a bonus on the saving throw */
1444  if (op->level+(op->resist[ATNR_HOLYWORD]/100) < owner->level+get_turn_bonus(owner->stats.Wis))
1445  scare_creature(op, owner);
1446  }
1447  break;
1448 
1449  case ATNR_LIFE_STEALING: {
1450  int new_hp;
1451  /* this is replacement to drain for players, instead of taking
1452  * exp it takes hp. It is geared for players, probably not
1453  * much use giving it to monsters
1454  *
1455  * life stealing doesn't do a lot of damage, but it gives the
1456  * damage it does do to the player. Given that,
1457  * it only does 1/30'th normal damage (hence the divide by
1458  * 3000). Wraith get 1/2 of the damage, and therefore divide
1459  * by 200. This number may need tweaking for game balance.
1460  */
1461 
1462  int dam_modifier = is_wraith_pl(hitter) ? 200 : 3000;
1463 
1464  /* You can't steal life from something undead or not alive. */
1465  if (op->type == GOLEM
1466  || (QUERY_FLAG(op, FLAG_UNDEAD))
1467  || !(QUERY_FLAG(op, FLAG_ALIVE))
1468  || (op->type == DOOR))
1469  return 0;
1470  /* If drain protection is higher than life stealing, use that */
1471  if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1472  dam = (dam*(100-op->resist[ATNR_DRAIN]))/dam_modifier;
1473  else
1474  dam = (dam*(100-op->resist[ATNR_LIFE_STEALING]))/dam_modifier;
1475  /* You die at -1 hp, not zero. */
1476  if (dam > op->stats.hp+1)
1477  dam = op->stats.hp+1;
1478  new_hp = hitter->stats.hp+dam;
1479  if (new_hp > hitter->stats.maxhp)
1480  new_hp = hitter->stats.maxhp;
1481  if (new_hp > hitter->stats.hp)
1482  hitter->stats.hp = new_hp;
1483 
1484  /* Wraith also get food through life stealing */
1485  if (is_wraith_pl(hitter)) {
1486  if (hitter->stats.food+dam >= MAX_FOOD)
1487  hitter->stats.food = MAX_FOOD;
1488  else
1489  hitter->stats.food += dam;
1490  fix_object(hitter);
1491  }
1492  }
1493  }
1494  return dam;
1495 }
1496 
1497 /*
1498  * This function is defined in party.c, but conditionally, something "make proto"
1499  * doesn't handle. So define it locally.
1500  */
1501 #ifdef PARTY_KILL_LOG
1502 void party_add_kill(partylist *party, const char *killer, const char *dead, long exp);
1503 #endif
1504 
1532 static int kill_object(object *op, int dam, object *hitter) {
1533  char kill_message[MAX_BUF];
1534  const char *skill;
1535  int maxdam = 0;
1536  int battleg = 0; /* true if op standing on battleground */
1537  int pk = 0; /* true if op and what controls hitter are both players*/
1538  object *owner = NULL;
1539  const object *skop = NULL;
1540 
1541  if (op->stats.hp >= 0)
1542  return -1;
1543 
1544  if (events_execute_object_event(op, EVENT_DEATH, hitter, NULL, NULL, SCRIPT_FIX_ALL) != 0)
1545  return 0;
1547 
1549 
1550  /* maxdam needs to be the amount of damage it took to kill
1551  * this creature. The function(s) that call us have already
1552  * adjusted the creatures HP total, so that is negative.
1553  */
1554  maxdam = dam+op->stats.hp+1;
1555 
1556  if (QUERY_FLAG(op, FLAG_BLOCKSVIEW))
1557  update_all_los(op->map, op->x, op->y); /* makes sure los will be recalculated */
1558 
1559  if (op->type == DOOR) {
1560  op->speed = 0.1;
1561  object_update_speed(op);
1562  op->speed_left = -0.05;
1563  return maxdam;
1564  }
1565  if (QUERY_FLAG(op, FLAG_FRIENDLY) && op->type != PLAYER) {
1566  object *owner;
1567 
1569  owner = object_get_owner(op);
1570  if (owner != NULL
1571  && owner->type == PLAYER) {
1572  if (owner->contr->ranges[range_golem] == op) {
1573  owner->contr->ranges[range_golem] = NULL;
1574  owner->contr->golem_count = 0;
1575  }
1576 
1577  /*play_sound_player_only(owner1->contr, SOUND_PET_IS_KILLED, 0, 0);*/
1578  /* Maybe we should include the owner that killed this, maybe not */
1580  "Your pet, the %s, is killed by %s.",
1581  op->name, hitter->name);
1582  }
1583  /*
1584  * there can be items both friendly and without any owner, for instance
1585  * in various maps, so this isn't an error.
1586  else
1587  LOG(llevError, "BUG: hit_player(): Encountered golem without owner.\n");
1588  */
1589 
1590  object_remove(op);
1592  return maxdam;
1593  }
1594 
1595  /* Now lets start dealing with experience we get for killing something */
1596 
1597  owner = object_get_owner(hitter);
1598  if (owner == NULL)
1599  owner = hitter;
1600 
1601  /* is the victim (op) standing on battleground? */
1602  if (op_on_battleground(op, NULL, NULL, NULL))
1603  battleg = 1;
1604 
1605  /* is this player killing? -- Don't count it if you suicide, though. */
1606  if (op->type == PLAYER && owner->type == PLAYER && owner != op)
1607  pk = 1;
1608 
1609  /* Player killed something */
1610  if (owner->type == PLAYER) {
1611 
1612  /* Log players killing other players - makes it easier to detect
1613  * and filter out malicious player killers - that is why the
1614  * ip address is included.
1615  */
1616  if (op->type == PLAYER && !battleg) {
1617  time_t t = time(NULL);
1618  struct tm *tmv;
1619  char buf[256];
1620  char name[MAX_BUF];
1621 
1622  tmv = localtime(&t);
1623  strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y", tmv);
1624  query_name(op, name, MAX_BUF);
1625 
1626  LOG(llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, owner->name, owner->contr->socket.host, name);
1627  }
1628 
1629  /* try to filter some things out - basically, if you are
1630  * killing a level 1 creature and your level 20, you
1631  * probably don't want to see that.
1632  */
1633  if (owner->level < op->level*2 || op->stats.exp > 1000) {
1634  if (owner != hitter) {
1635  char killed[MAX_BUF], with[MAX_BUF];
1636 
1637  query_name(op, killed, MAX_BUF);
1638  query_name(hitter, with, MAX_BUF);
1640  "You killed %s with %s.",
1641  killed, with);
1642  } else {
1643  char killed[MAX_BUF];
1644 
1645  query_name(op, killed, MAX_BUF);
1647  "You killed %s.",
1648  killed);
1649  }
1650  }
1651 
1652  /* If a player kills another player, not on
1653  * battleground, the "killer" looses 1 luck. Since this is
1654  * not reversible, it's actually quite a pain IMHO. -AV
1655  * Fix bug in that we were changing the luck of the hitter, not
1656  * player that the object belonged to - so if you killed another player
1657  * with spells, pets, whatever, there was no penalty.
1658  * Changed to make luck penalty configurable in settings.
1659  *
1660  * Simplified comparison since pk is no longer set to 1 if self-kill
1661  * -- SilverNexus 2017-06-17+
1662  */
1663  if (pk == 1 && !battleg)
1665 
1666  /* This code below deals with finding the appropriate skill
1667  * to credit exp to. This is a bit problematic - we should
1668  * probably never really have to look at current_weapon->skill
1669  */
1670  skill = NULL;
1671  if (hitter->skill && hitter->type != PLAYER)
1672  skill = hitter->skill;
1673  else if (owner->chosen_skill) {
1674  skill = owner->chosen_skill->skill;
1675  skop = owner->chosen_skill;
1676  } else if (QUERY_FLAG(owner, FLAG_READY_WEAPON))
1677  skill = owner->current_weapon->skill;
1678  else
1679  LOG(llevError, "kill_object - unable to find skill that killed monster\n");
1680 
1681  /* We have the skill we want to credit to - now find the object this goes
1682  * to. Make sure skop is an actual skill, and not a skill tool!
1683  */
1684  if ((!skop || skop->type != SKILL) && skill) {
1685  skop = find_applied_skill_by_name(owner, skill);
1686  }
1687  } /* Was it a player that hit somethign */
1688  else {
1689  skill = NULL;
1690  }
1691 
1692  /* Pet (or spell) killed something. */
1693  if (owner != hitter) {
1694  char name_op[MAX_BUF], name_hitter[MAX_BUF];
1695  const char *owner_prefix;
1696  const char *op_prefix;
1697 
1698  owner_prefix = !battleg && pk && owner->contr != NULL && !owner->contr->peaceful ? "hostile " : "";
1699  op_prefix = !battleg && pk && op->contr != NULL && !op->contr->peaceful ? "hostile " : "";
1700 
1701  query_name(op, name_op, MAX_BUF);
1702  query_name(hitter, name_hitter, MAX_BUF);
1703  snprintf(kill_message, sizeof(kill_message), "%s%s killed %s%s with %s%s.", owner_prefix, owner->name, op_prefix, name_op, name_hitter, battleg ? " (duel)" : (pk ? " (pk)" : ""));
1704  } else {
1705  const char *hitter_prefix;
1706  const char *op_prefix;
1707 
1708  hitter_prefix = !battleg && pk && hitter->contr != NULL && !hitter->contr->peaceful ? "hostile " : "";
1709  op_prefix = !battleg && pk && op->contr != NULL && !op->contr->peaceful ? "hostile " : "";
1710 
1711  snprintf(kill_message, sizeof(kill_message), "%s%s killed %s%s%s%s.", hitter_prefix, hitter->name, op_prefix, op->name,
1712  (QUERY_FLAG(hitter, FLAG_MONSTER)) || hitter->type == PLAYER ?
1713  " in hand to hand combat" : "", battleg ? " (duel)" : (pk ? " (pk)" : ""));
1714  }
1715  /* These may have been set in the player code section above */
1716  if (!skop)
1717  skop = hitter->chosen_skill;
1718  if (!skill && skop)
1719  skill = skop->skill;
1720 
1721  draw_ext_info(NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_PLAYER,
1722  kill_message);
1723  play_sound_map(SOUND_TYPE_HIT, op, 0, "kill");
1724 
1725 
1726  /* If you didn't kill yourself, and your not the wizard */
1727  if (owner != op && !QUERY_FLAG(op, FLAG_WAS_WIZ)) {
1728  int64_t exp;
1729 
1730  exp = calc_skill_exp(owner, op, skop);
1731 
1732  /* Really don't give much experience for killing other players */
1733  if (op->type == PLAYER) {
1734  if (battleg) {
1736  "Your foe has fallen!\nVICTORY!!!");
1737  } else {
1738  exp = settings.pk_max_experience_percent*exp/100;
1739  if (settings.pk_max_experience >= 0)
1740  exp = MIN(settings.pk_max_experience, exp);
1741  /* Never exceed what victim can lose considering permanent exp. */
1742  exp = check_exp_loss(op, exp);
1743  }
1744  }
1745 
1746  /* Don't know why this is set this way - doesn't make
1747  * sense to just divide everything by two for no reason.
1748  */
1749 
1750  if (!settings.simple_exp)
1751  exp = exp/2;
1752 
1753  /* if op is standing on "battleground" (arena), no way to gain
1754  * exp by killing him
1755  */
1756  if (battleg)
1757  exp = 0;
1758 
1759 #ifdef PARTY_KILL_LOG
1760  if (owner->type == PLAYER && owner->contr->party != NULL) {
1761  char name[MAX_BUF];
1762  char op_name[MAX_BUF];
1763 
1764  query_name(owner, name, MAX_BUF);
1765  query_name(op, op_name, sizeof(op_name));
1766  party_add_kill(owner->contr->party, name, op_name, exp);
1767  }
1768 #endif
1769  share_exp(owner, exp, skill, SK_EXP_TOTAL);
1770  } /* end if person didn't kill himself */
1771 
1772  if (op->type != PLAYER) {
1773  object_remove(op);
1775  /* Player has been killed! */
1776  } else {
1777  if (owner->type == PLAYER) {
1778  snprintf(op->contr->killer, BIG_NAME, "%s the %s", owner->name, owner->contr->title);
1779  } else {
1780  strncpy(op->contr->killer, hitter->name, BIG_NAME);
1781  op->contr->killer[BIG_NAME-1] = '\0';
1782  }
1783  /* Need to run kill_player (just in case, make sure is not wiz) */
1784  if (!QUERY_FLAG(op, FLAG_WIZ))
1785  kill_player(op, owner->type == PLAYER ? owner : hitter);
1786  }
1787  /* This was return -1 - that doesn't seem correct - if we return -1, process
1788  * continues in the calling function.
1789  */
1790  return maxdam;
1791 }
1792 
1803 int friendly_fire(object *op, object *hitter) {
1804  object *owner;
1805  int friendlyfire;
1806 
1807  hitter = HEAD(hitter);
1808  friendlyfire = 0;
1809 
1810  if (op->type == PLAYER) {
1811  if (hitter->type == PLAYER && hitter->contr->peaceful == 1)
1812  return 1;
1813 
1814  owner = object_get_owner(hitter);
1815  if (owner != NULL) {
1816  if (owner->type == PLAYER && owner->contr->peaceful == 1)
1817  friendlyfire = 2;
1818  }
1819 
1820  if (hitter->type == SPELL
1821  || hitter->type == POISONING
1822  || hitter->type == DISEASE
1823  || hitter->type == RUNE)
1824  friendlyfire = 0;
1825  }
1826  return friendlyfire;
1827 }
1828 
1852 int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit) {
1853  int maxdam = 0, ndam = 0, magic = (type&AT_MAGIC);
1854  int maxattacktype, attacknum;
1855  int body_attack = op->head != NULL; /* Did we hit op's head? */
1856  int simple_attack;
1857  tag_t op_tag, hitter_tag;
1858  int rtn_kill = 0;
1859  int friendlyfire;
1860  object *owner;
1861 
1862  if (events_execute_object_event(op, EVENT_ATTACKED, hitter, hitter->current_weapon ? hitter->current_weapon : hitter, NULL, SCRIPT_FIX_ALL) != 0)
1863  return 0;
1864  FOR_INV_PREPARE(op, inv)
1865  if (events_execute_object_event(inv, EVENT_ATTACKED, hitter, hitter->current_weapon ? hitter->current_weapon : hitter, NULL, SCRIPT_FIX_ALL) != 0)
1866  return 0;
1867  FOR_INV_FINISH();
1868 
1869  if (get_attack_mode(&op, &hitter, &simple_attack))
1870  return 0;
1871 
1872  /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */
1873  if (QUERY_FLAG(op, FLAG_WIZ) || QUERY_FLAG(op, FLAG_NO_DAMAGE))
1874  return 0;
1875 
1876  op_tag = op->count;
1877  hitter_tag = hitter->count;
1878 
1879  if (body_attack) {
1880  /* slow and paralyze must hit the head. But we don't want to just
1881  * return - we still need to process other attacks the spell still
1882  * might have. So just remove the paralyze and slow attacktypes,
1883  * and keep on processing if we have other attacktypes.
1884  * return if only magic or nothing is left - under normal code
1885  * we don't attack with pure magic if there is another attacktype.
1886  * Only do processing if the initial attacktype includes one of those
1887  * attack so we don't cancel out things like magic bullet.
1888  */
1889  if (type&(AT_PARALYZE|AT_SLOW)) {
1890  type &= ~(AT_PARALYZE|AT_SLOW);
1891  if (!type || type == AT_MAGIC)
1892  return 0;
1893  }
1894  }
1895 
1896  if (!simple_attack && op->type == DOOR) {
1897  object *tmp;
1898 
1899  tmp = object_find_by_type2(op, RUNE, TRAP);
1900  if (tmp != NULL) {
1901  spring_trap(tmp, hitter);
1902  if (object_was_destroyed(hitter, hitter_tag)
1903  || object_was_destroyed(op, op_tag)
1904  || abort_attack(op, hitter, simple_attack))
1905  return 0;
1906  }
1907  }
1908 
1909  if (!QUERY_FLAG(op, FLAG_ALIVE) || op->stats.hp < 0) {
1910  /* FIXME: If a player is killed by a rune in a door, the
1911  * object_was_destroyed() check above doesn't return, and might get here.
1912  */
1913  LOG(llevDebug, "victim (arch %s, name %s) already dead in hit_player()\n", op->arch->name, op->name);
1914  return 0;
1915  }
1916 
1917 #ifdef ATTACK_DEBUG
1918  LOG(llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1919 #endif
1920 
1921  if (magic) {
1922  /* basically: dam = dam*(100-op->resist[attacknum])/100;
1923  * in case 0>dam>1, we try to "simulate" a float value-effect */
1924  dam = dam*(100-op->resist[ATNR_MAGIC]);
1925  if (dam >= 100)
1926  dam /= 100;
1927  else
1928  dam = (dam > (rndm(0, 99))) ? 1 : 0;
1929  }
1930 
1931  /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map
1932  * We don't use shuffle_attack(), because that changes the it in the
1933  * creature structure, and thus is permanent until fix_object() is
1934  * called again. Chaos should change on each attack.
1935  */
1936  if (type&AT_CHAOS) {
1937  type = ATTACKS[RANDOM()%(sizeof(ATTACKS)/sizeof(*ATTACKS))].attacktype|AT_MAGIC;
1938  }
1939 
1940  /* Holyword is really an attacktype modifier (like magic is). If
1941  * holyword is part of an attacktype, then make sure the creature is
1942  * a proper match, otherwise no damage.
1943  */
1944  if (type&AT_HOLYWORD) {
1945  const object *god;
1946 
1947  if ((!hitter->slaying || (!(op->race && strstr(hitter->slaying, op->race))
1948  && !(op->name && strstr(hitter->slaying, op->name))))
1949  && (!QUERY_FLAG(op, FLAG_UNDEAD) || (hitter->title != NULL
1950  && (god = find_god(determine_god(hitter))) != NULL
1951  && god->race != NULL
1952  && strstr(god->race, undead_name) != NULL)))
1953  return 0;
1954  }
1955 
1956  maxattacktype = type; /* initialize this to something */
1957  for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) {
1958  int attacktype;
1959 
1960  attacktype = 1<<attacknum;
1961 
1962  /* Magic isn't really a true attack type - it gets combined with other
1963  * attack types. As such, skip it over. However, if magic is
1964  * the only attacktype in the group, then still attack with it
1965  */
1966  if (attacktype == AT_MAGIC && (type&~AT_MAGIC))
1967  continue;
1968 
1969  /* Go through and hit the player with each attacktype, one by one.
1970  * hit_with_one_attacktype only figures out the damage, doesn't inflict
1971  * it. It will do the appropriate action for attacktypes with
1972  * effects (slow, paralization, etc.
1973  */
1974  if (type&attacktype) {
1975  ndam = hit_with_one_attacktype(op, hitter, dam, attacknum);
1976  /* the >= causes us to prefer messages from special attacks, if
1977  * the damage is equal.
1978  */
1979  if (ndam >= maxdam) {
1980  maxdam = ndam;
1981  maxattacktype = 1<<attacknum;
1982  }
1983  /* Special case: death attack always deals all damage, as it should kill the monster
1984  * right away. */
1985  if (attacktype == AT_DEATH && ndam > 0)
1986  full_hit = 1;
1987  }
1988  }
1989 
1990 
1991  /* if this is friendly fire then do a set % of damage only
1992  * Note - put a check in to make sure this attack is actually
1993  * doing damage - otherwise, the +1 in the coe below will make
1994  * an attack do damage before when it otherwise didn't
1995  * Only reduce damage if not on battlground - if in arena, do
1996  * full damage. Note that it is intentional that the check for
1997  * battleground is inside the friendlyfire if statement - op_on_battleground()
1998  * is a fairly costly function to call, and we don't want to call it for
1999  * every attack - by doing it only for friendlyfire, it shouldn't get called
2000  * that often
2001  */
2002  friendlyfire = friendly_fire(op, hitter);
2003  if (friendlyfire && maxdam) {
2004  if (!op_on_battleground(op, NULL, NULL, NULL)) {
2005  maxdam = ((dam*settings.set_friendly_fire)/100)+1;
2006 #ifdef ATTACK_DEBUG
2007  LOG(llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n", friendlyfire, settings.set_friendly_fire, dam, maxdam);
2008 #endif
2009  }
2010  }
2011 
2012  if (!full_hit) {
2013  archetype *at;
2014  unsigned int area = 0;
2015  for (at = op->arch; at != NULL; at = at->more)
2016  area++;
2017 
2018  /* basically: maxdam /= area; we try to "simulate" a float
2019  value-effect */
2020  unsigned int remainder = 100*(maxdam%area)/area;
2021  maxdam /= area;
2022  if (RANDOM()%100 < remainder)
2023  maxdam++;
2024  }
2025 
2026 #ifdef ATTACK_DEBUG
2027  LOG(llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
2028 #endif
2029 
2030  owner = object_get_owner(hitter);
2031  if (owner != NULL) {
2032  if (op->enemy != hitter)
2033  object_set_enemy(op, owner);
2034  } else if (QUERY_FLAG(hitter, FLAG_ALIVE))
2035  if (op->enemy == NULL || rndm(1, 20) == 0)
2036  object_set_enemy(op, hitter);
2037 
2038  if (QUERY_FLAG(op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) {
2039  /* The unaggressives look after themselves 8) */
2042  }
2043 
2044  if (magic && did_make_save(op, op->level, 0))
2045  maxdam = maxdam/2;
2046 
2047  attack_message(maxdam, maxattacktype, op, hitter);
2048 
2049  op->stats.hp -= maxdam;
2050 
2051  /* Eneq(@csd.uu.se): Check to see if monster runs away. */
2052  if (op->stats.hp >= 0
2053  && (QUERY_FLAG(op, FLAG_MONSTER) || op->type == PLAYER)
2054  && op->stats.hp < (int16_t)((int32_t)op->run_away * op->stats.maxhp / 100)) {
2055  if (QUERY_FLAG(op, FLAG_MONSTER))
2056  SET_FLAG(op, FLAG_RUN_AWAY);
2057  else
2058  scare_creature(op, hitter);
2059  }
2060 
2061  if (QUERY_FLAG(op, FLAG_TEAR_DOWN)) {
2062  if (maxdam)
2063  tear_down_wall(op);
2064  return maxdam; /* nothing more to do for wall */
2065  }
2066 
2067  /* See if the creature has been killed */
2068  rtn_kill = kill_object(op, maxdam, hitter);
2069  if (rtn_kill != -1)
2070  return rtn_kill;
2071 
2072  /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
2073  * that before if the player was immune to ghosthit, the monster
2074  * remained - that is no longer the case.
2075  */
2076  if (QUERY_FLAG(hitter, FLAG_ONE_HIT)) {
2077  if (QUERY_FLAG(hitter, FLAG_FRIENDLY))
2078  remove_friendly_object(hitter);
2079  object_remove(hitter);
2081  /* Lets handle creatures that are splitting now */
2082  } else if (type&AT_PHYSICAL && !QUERY_FLAG(op, FLAG_FREED) && QUERY_FLAG(op, FLAG_SPLITTING)) {
2083  change_object(op);
2084  } else if (type&AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) {
2085  object_remove(hitter);
2087  }
2088  return maxdam;
2089 }
2090 
2101 static void poison_living(object *op, object *hitter, int dam) {
2102  archetype *at = find_archetype("poisoning");
2103  if (at == NULL) {
2104  return;
2105  }
2106  object *tmp = arch_present_in_ob(at, op);
2107  const char *skill;
2108 
2109  if (tmp == NULL) {
2110  tmp = arch_to_object(at);
2111  if (tmp == NULL)
2112  LOG(llevError, "Failed to clone arch poisoning.\n");
2113  else {
2114  tmp = object_insert_in_ob(tmp, op);
2115  /* peterm: give poisoning some teeth. It should
2116  * be able to kill things better than it does:
2117  * damage should be dependent something--I choose to
2118  * do this: if it's a monster, the damage from the
2119  * poisoning goes as the level of the monster/2.
2120  * If anything else, goes as damage.
2121  */
2122 
2123  if (QUERY_FLAG(hitter, FLAG_ALIVE))
2124  tmp->stats.dam += hitter->level/2;
2125  else
2126  tmp->stats.dam = dam;
2127 
2128  object_copy_owner(tmp, hitter); /* so we get credit for poisoning kills */
2129  skill = hitter->skill;
2130  if (!skill && hitter->chosen_skill)
2131  skill = hitter->chosen_skill->name;
2132 
2133  if (skill && skill != tmp->skill) {
2134  if (tmp->skill)
2135  free_string(tmp->skill);
2136  tmp->skill = add_refcount(skill);
2137  }
2138 
2139  tmp->stats.food += dam; /* more damage, longer poisoning */
2140 
2141  if (op->type == PLAYER) {
2142  /* player looses stats, maximum is -10 of each */
2143  tmp->stats.Con = MAX(-(dam/4+1), -10);
2144  tmp->stats.Str = MAX(-(dam/3+2), -10);
2145  tmp->stats.Dex = MAX(-(dam/6+1), -10);
2146  tmp->stats.Int = MAX(-dam/7, -10);
2147  SET_FLAG(tmp, FLAG_APPLIED);
2148  fix_object(op);
2149  draw_ext_info(NDI_UNIQUE, 0, op,
2151  "You suddenly feel very ill.");
2152  }
2153  if (hitter->type == PLAYER)
2154  draw_ext_info_format(NDI_UNIQUE, 0, hitter,
2156  "You poison %s.",
2157  op->name);
2158  else {
2159  object *owner;
2160 
2161  owner = object_get_owner(hitter);
2162  if (owner != NULL && owner->type == PLAYER)
2163  draw_ext_info_format(NDI_UNIQUE, 0, owner,
2165  "Your %s poisons %s.",
2166  hitter->name, op->name);
2167  }
2168  tmp->speed_left = 0;
2169  }
2170  } else
2171  tmp->stats.food++;
2172 }
2173 
2174 int slow_living_by(object *op, const int speed_penalty) {
2175  archetype *at = find_archetype("slowness");
2176  if (at == NULL) {
2177  return 0;
2178  }
2179  object* tmp = arch_present_in_ob(at, op);
2180  int ret;
2181  if (tmp == NULL) {
2182  tmp = arch_to_object(at);
2183  tmp->stats.exp = -speed_penalty;
2184  tmp = object_insert_in_ob(tmp, op);
2185  ret = 1;
2186  }
2187  // If we are hitting for more intense slowness, override the old one.
2188  else if (tmp->stats.exp > -speed_penalty) {
2189  tmp->stats.exp = -speed_penalty;
2190  tmp->stats.food -= 3; // But also reduce the duration to compensate.
2191  ret = 2;
2192  } else {
2193  tmp->stats.food++;
2194  ret = 3;
2195  }
2196  SET_FLAG(tmp, FLAG_APPLIED);
2197  tmp->speed_left = 0;
2198  fix_object(op);
2199  return ret;
2200 }
2201 
2212 static void slow_living(object *op, object *hitter, int dam) {
2213  // Used to calculate the speed penalty of the slow attempt
2214  int speed_penalty;
2215 
2221  // Higher level slow effects make you slower.
2222  speed_penalty = hitter->level - op->level + random_roll(1, 5, hitter, PREFER_LOW);
2223  // Resistance to slow will also affect how much you are slowed by.
2224  speed_penalty = speed_penalty * (100-op->resist[ATNR_SLOW]) / 100;
2225  // Make sure we actually have a penalty amount. We can assume that op is not immune in this method.
2226  if (speed_penalty < 1)
2227  speed_penalty = 1;
2228  else if (speed_penalty > 30) // Data barrier for stats.exp is 127, but that is huge slowness. Pick something less than that.
2229  speed_penalty = 30;
2230  switch (slow_living_by(op, speed_penalty)) {
2231  case 1:
2234  "The world suddenly moves very fast!");
2235  break;
2236  case 2:
2239  "The world moves even faster!");
2240  break;
2241 
2242  }
2243 }
2244 
2255 void confuse_living(object *op, object *hitter, int dam) {
2256  object *tmp;
2257  int maxduration;
2258 
2259  tmp = object_present_in_ob_by_name(FORCE, "confusion", op);
2260  if (!tmp) {
2262  tmp = object_insert_in_ob(tmp, op);
2263  }
2264  SET_FLAG(tmp, FLAG_APPLIED);
2265  SET_FLAG(tmp, FLAG_CONFUSED);
2266 
2267  /* Duration added per hit and max. duration of confusion both depend
2268  * on the player's resistance
2269  */
2270  tmp->speed = 0.05;
2271  tmp->subtype = FORCE_CONFUSION;
2272  tmp->duration = 8+MAX(1, 5*(100-op->resist[ATNR_CONFUSION])/100);
2273  if (tmp->name)
2274  free_string(tmp->name);
2275  tmp->name = add_string("confusion");
2276  maxduration = MAX(2, 30*(100-op->resist[ATNR_CONFUSION])/100);
2277  if (tmp->duration > maxduration)
2278  tmp->duration = maxduration;
2279 
2280  if (op->type == PLAYER && !QUERY_FLAG(op, FLAG_CONFUSED))
2282  "You suddenly feel very confused!");
2283  SET_FLAG(op, FLAG_CONFUSED);
2284 }
2285 
2296 void blind_living(object *op, object *hitter, int dam) {
2297  object *tmp, *owner;
2298  char victim[MAX_BUF];
2299 
2300  /* Save some work if we know it isn't going to affect the player */
2301  if (op->resist[ATNR_BLIND] == 100)
2302  return;
2303 
2304  tmp = object_present_in_ob(BLINDNESS, op);
2305  if (!tmp) {
2306  tmp = create_archetype("blindness");
2307  SET_FLAG(tmp, FLAG_BLIND);
2308  SET_FLAG(tmp, FLAG_APPLIED);
2309  /* use floats so we don't lose too much precision due to rounding errors.
2310  * speed is a float anyways.
2311  */
2312  tmp->speed = tmp->speed*(100.0-(float)op->resist[ATNR_BLIND])/100;
2313 
2314  tmp = object_insert_in_ob(tmp, op);
2315  change_abil(op, tmp); /* Mostly to display any messages */
2316  fix_object(op); /* This takes care of some other stuff */
2317 
2318  owner = object_get_owner(hitter);
2319  if (owner == NULL)
2320  owner = hitter;
2321 
2322  query_name(op, victim, MAX_BUF);
2324  "Your attack blinds %s!",
2325  victim);
2326  }
2327  tmp->stats.food += dam;
2328  if (tmp->stats.food > 10)
2329  tmp->stats.food = 10;
2330 }
2331 
2340 void paralyze_living(object *op, int dam) {
2341  float effect, max;
2342 
2343  /* Do this as a float - otherwise, rounding might very well reduce this to 0 */
2344  effect = (float)dam*3.0*(100.0-op->resist[ATNR_PARALYZE])/100;
2345 
2346  if (effect == 0)
2347  return;
2348 
2349  op->speed_left -= FABS(op->speed)*effect;
2350 
2351  /* max number of ticks to be affected for. */
2352  max = (100-op->resist[ATNR_PARALYZE])/2;
2353  if (op->speed_left < -(FABS(op->speed)*max))
2354  op->speed_left = (float)-(FABS(op->speed)*max);
2355  // Set a paralyze flag and print a message to a player if the flag isn't set;
2356  // this tells the player that he/she has been hit by a paralysis attack.
2357  if (!QUERY_FLAG(op, FLAG_PARALYZED)) {
2358  SET_FLAG(op, FLAG_PARALYZED);
2359  if (op->type == PLAYER)
2361  "You limbs stop moving!");
2362  }
2363  /* If the flag is already set, then the paralysis is merely extended.
2364  * At this point, we do nothing.
2365  * It may be worthwhile to give players another message on paralysis extensions.
2366  *
2367  * Daniel Hawkins 2017-08-22
2368  */
2369 }
2370 
2391 static void deathstrike_living(object *op, object *hitter, int *dam) {
2392  int atk_lev, def_lev, kill_lev, roll;
2393 
2394  if (hitter->slaying) {
2395  if (!((QUERY_FLAG(op, FLAG_UNDEAD) && strstr(hitter->slaying, undead_name))
2396  || (op->race && strstr(op->race, hitter->slaying))))
2397  {
2398  *dam = 0; // Don't do damage if we aren't deathstriking them.
2399  return;
2400  }
2401  } else
2402  if (QUERY_FLAG(op, FLAG_UNDEAD))
2403  {
2404  *dam = 0; // Don't do damage if we aren't deathstriking them.
2405  return;
2406  }
2407 
2408  def_lev = op->level;
2409  if (def_lev < 1) {
2410  LOG(llevError, "deathstrike_living: arch %s (%s in %s at %d, %d) has level < 1\n", op->arch->name, op->name, op->map->name, op->x, op->y);
2411  def_lev = 1;
2412  }
2413  /*
2414  * Redo this calculation -- you could essentially only kill creatures less than half your level,
2415  * making death extremely weak at high levels.
2416  * Refactoring to use a d20 roll with a fairly high DC (still dependent on level)
2417  * Also, toss in a resistance-based hit modifier.
2418  * Higher resistance requires higher levels in order to kill with a death attack.
2419  *
2420  * Daniel Hawkins 2018-05-21
2421  */
2422  atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level);
2423  /* LOG(llevDebug, "Deathstrike - attack level %d, defender level %d\n", atk_lev, def_lev); */
2424 
2425  roll = random_roll(1, 20, hitter, PREFER_HIGH);
2426  kill_lev = roll - 18 + atk_lev; // Use 19+ as a kill for same level and no resistance;
2427  kill_lev = kill_lev * (100 - op->resist[ATNR_DEATH]) / 100; // Do not compress to *= for roundoff reasons.
2428 
2429  // If we hit, then kill them. Otherwise, damage is 0.
2430  if (kill_lev > def_lev) {
2431  *dam = op->stats.hp+10; /* take all hp. they can still save for 1/2 */
2432  /* I think this doesn't really do much. Because of
2433  * integer rounding, this only makes any difference if the
2434  * attack level is double the defender level.
2435  */
2436  *dam *= kill_lev/def_lev;
2437  }
2438  else {
2439  *dam = 0; /* no harm done */
2440  }
2441 }
2442 
2455 static void thrown_item_effect(object *hitter, object *victim) {
2456  if (!QUERY_FLAG(hitter, FLAG_ALIVE)) {
2457  /* May not need a switch for just 2 types, but this makes it
2458  * easier for expansion.
2459  */
2460  switch (hitter->type) {
2461  case POTION:
2462  /* should player get a save throw instead of checking magic protection? */
2463  if (QUERY_FLAG(victim, FLAG_ALIVE)
2464  && !QUERY_FLAG(victim, FLAG_UNDEAD)
2465  && (victim->resist[ATNR_MAGIC] < 60))
2466  (void)ob_apply(hitter, victim, 0);
2467  break;
2468 
2469  case POISON: /* poison drinks */
2470  /* As with potions, should monster get a save? */
2471  if (QUERY_FLAG(victim, FLAG_ALIVE)
2472  && !QUERY_FLAG(victim, FLAG_UNDEAD)
2473  && (victim->resist[ATNR_POISON] < 60))
2474  (void)ob_apply(victim, hitter, 0);
2475  break;
2476 
2477  /* Removed case statements that did nothing.
2478  * food may be poisonous, but monster must be willing to eat it,
2479  * so we don't handle it here.
2480  * Containers should perhaps break open, but that code was disabled.
2481  */
2482  }
2483  }
2484 }
2485 
2495 static int adj_attackroll(object *hitter, object *target) {
2496  object *attacker = hitter;
2497  int adjust = 0;
2498 
2499  /* safety */
2500  if (!target || !hitter || !hitter->map || !target->map || !on_same_map(hitter, target)) {
2501  LOG(llevError, "BUG: adj_attackroll(): hitter and target not on same map\n");
2502  return 0;
2503  }
2504 
2505  /* aimed missiles use the owning object's sight */
2506  if (is_aimed_missile(hitter)) {
2507  attacker = object_get_owner(hitter);
2508  if (attacker == NULL)
2509  attacker = hitter;
2510  /* A player who saves but hasn't quit still could have objects
2511  * owned by him - need to handle that case to avoid crashes.
2512  */
2513  if (QUERY_FLAG(attacker, FLAG_REMOVED))
2514  attacker = hitter;
2515  } else if (!QUERY_FLAG(hitter, FLAG_ALIVE))
2516  return 0;
2517 
2518  /* determine the condtions under which we make an attack.
2519  * Add more cases, as the need occurs. */
2520 
2521  if (!monster_can_see_enemy(attacker, target)) {
2522  /* target is unseen */
2523  if (target->invisible || QUERY_FLAG(attacker, FLAG_BLIND))
2524  adjust -= 10;
2525  /* dark map penalty for the hitter, though xray can help for a player */
2526  else if (target->map && target->map->darkness > 0 && !monster_stand_in_light(target) && (hitter->type != PLAYER || !player_can_view(hitter, target)))
2527  adjust -= target->map->darkness;
2528  }
2529 
2530  if (QUERY_FLAG(attacker, FLAG_SCARED))
2531  adjust -= 3;
2532 
2533  if (QUERY_FLAG(target, FLAG_UNAGGRESSIVE))
2534  adjust += 1;
2535 
2536  if (QUERY_FLAG(target, FLAG_SCARED))
2537  adjust += 1;
2538 
2539  if (QUERY_FLAG(attacker, FLAG_CONFUSED))
2540  adjust -= 3;
2541 
2542  /* if we attack at a different 'altitude' its harder
2543  * Note - only make this adjustment if the target actually
2544  * has a move type. Doors don't (they don't move), and
2545  * this would evaluate as true. If anything, something without
2546  * a move type should be easier to hit.
2547  */
2548  if (target->move_type && (attacker->move_type&target->move_type) == 0)
2549  adjust -= 2;
2550 
2551  return adjust;
2552 }
2553 
2562 static int is_aimed_missile(object *op) {
2563  /* I broke what used to be one big if into a few nested
2564  * ones so that figuring out the logic is at least possible.
2565  */
2566  if (op && (op->move_type&MOVE_FLYING)) {
2567  if (op->type == ARROW || op->type == THROWN_OBJ)
2568  return 1;
2569  else if (op->type == SPELL_EFFECT
2570  && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION))
2571  return 1;
2572  }
2573  return 0;
2574 }
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:313
static void scare_creature(object *target, object *hitter)
Definition: attack.c:1137
void spring_trap(object *trap, object *victim)
Definition: rune.c:205
void paralyze_living(object *op, int dam)
Definition: attack.c:2340
#define AT_HOLYWORD
Definition: attack.h:97
static int abort_attack(object *target, object *hitter, int simple_attack)
Definition: attack.c:719
#define SOUND_TYPE_HIT
Definition: newclient.h:312
#define EVENT_GKILL
Definition: events.h:41
Definition: player.h:92
const char * determine_god(object *op)
Definition: gods.c:106
#define FLAG_DAMNED
Definition: define.h:318
#define ATM_KARATE
Definition: attack.h:29
void drain_stat(object *op)
Definition: living.c:717
#define FLAG_ONE_HIT
Definition: define.h:344
#define AT_ELECTRICITY
Definition: attack.h:79
#define AT_COUNTERSPELL
Definition: attack.h:95
#define ATM_CRUSH
Definition: attack.h:38
#define ATM_PIERCE
Definition: attack.h:33
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:658
object * find_applied_skill_by_name(const object *op, const char *name)
Definition: living.c:1919
#define AT_DEPLETE
Definition: attack.h:92
#define AT_GHOSTHIT
Definition: attack.h:85
#define ATM_BLUD
Definition: attack.h:39
#define FLAG_SLEEP
Definition: define.h:308
materialtype_t * name_to_material(const char *name)
Definition: utils.c:248
#define ATNR_TURN_UNDEAD
Definition: attack.h:62
#define FLAG_HITBACK
Definition: define.h:267
static void attack_message(int dam, int type, object *op, object *hitter)
Definition: attack.c:439
static void thrown_item_effect(object *, object *)
Definition: attack.c:2455
void apply_anim_suffix(object *who, const char *suffix)
Definition: anim.c:149
#define SET_FLAG(xyz, p)
Definition: define.h:223
int level
Definition: attack.h:119
sstring add_refcount(sstring str)
Definition: shstr.c:210
#define SP_CONE
Definition: spells.h:81
#define NDI_ALL
Definition: newclient.h:246
EXTERN materialtype_t * materialt
Definition: material.h:43
#define FABS(x)
Definition: define.h:22
static int stick_arrow(object *op, object *tmp)
Definition: attack.c:927
int monster_can_see_enemy(object *op, object *enemy)
Definition: monster.c:2574
StringBuffer * buf
Definition: readable.c:1591
void object_copy_owner(object *op, object *clone)
Definition: object.c:657
#define WEAP_CLEAVE
Definition: define.h:80
const Face * blank_face
Definition: image.c:35
#define FLAG_FRIENDLY
Definition: define.h:246
archetype * find_archetype(const char *name)
Definition: assets.cpp:253
#define ATNR_DEPLETE
Definition: attack.h:65
#define BIG_NAME
Definition: define.h:42
int8_t save[NROFATTACKS]
Definition: material.h:37
#define AT_CANCELLATION
Definition: attack.h:91
void free_string(sstring str)
Definition: shstr.c:280
#define WEAP_SLICE
Definition: define.h:81
void fix_stopped_item(object *op, mapstruct *map, object *originator)
Definition: time.c:492
#define SET_ANIMATION(ob, newanim)
Definition: global.h:160
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:340
#define ATNR_SLOW
Definition: attack.h:60
short freearr_x[SIZEOFFREE]
Definition: object.c:65
#define PREFER_LOW
Definition: define.h:601
#define FLAG_CONFUSED
Definition: define.h:312
int free_no_drop(object *op)
Definition: time.c:562
static void tear_down_wall(object *op)
Definition: attack.c:1088
#define AT_COLD
Definition: attack.h:80
void blind_living(object *op, object *hitter, int dam)
Definition: attack.c:2296
void change_luck(object *op, int value)
Definition: living.c:797
static int is_aimed_missile(object *op)
Definition: attack.c:2562
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:218
#define TRUE
Definition: compat.h:10
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:2954
#define FLAG_IS_LIGHTABLE
Definition: define.h:278
int64_t check_exp_loss(const object *op, int64_t exp)
Definition: living.c:2064
object * stop_item(object *op)
Definition: time.c:452
#define FALSE
Definition: compat.h:11
void remove_friendly_object(object *op)
Definition: friend.c:56
#define MAX(x, y)
Definition: compat.h:20
void object_update(object *op, int action)
Definition: object.c:1190
method_ret ob_apply(object *op, object *applier, int aflags)
Definition: ob_methods.c:44
static int did_make_save_item(object *op, int type, object *originator)
Definition: attack.c:98
#define FLAG_TEAR_DOWN
Definition: define.h:279
#define AT_BLIND
Definition: attack.h:98
const object * find_god(const char *name)
Definition: gods.c:80
#define NDI_BLACK
Definition: newclient.h:221
#define WEAP_BLUD
Definition: define.h:85
int player_can_view(object *pl, object *op)
Definition: player.c:4103
#define SCRIPT_FIX_ALL
Definition: global.h:370
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:308
#define ATM_FIRE
Definition: attack.h:27
#define ATNR_CONFUSION
Definition: attack.h:54
#define MSG_TYPE_APPLY
Definition: newclient.h:384
uint8_t casting_time
Definition: global.h:269
#define ATM_WHIP
Definition: attack.h:37
#define FOR_OB_AND_BELOW_FINISH()
Definition: define.h:791
static int adj_attackroll(object *hitter, object *target)
Definition: attack.c:2495
#define MIN(x, y)
Definition: compat.h:17
#define FLAG_REMOVED
Definition: define.h:232
void events_execute_global_event(int eventcode,...)
Definition: events.cpp:27
short freearr_y[SIZEOFFREE]
Definition: object.c:71
partylist * party
Definition: player.h:186
#define FLAG_KNOWN_MAGICAL
Definition: define.h:320
#define AT_TURN_UNDEAD
Definition: attack.h:89
#define AT_LIFE_STEALING
Definition: attack.h:100
int rndm(int min, int max)
Definition: utils.c:162
#define WEAP_WHIP
Definition: define.h:83
#define FLAG_UNDEAD
Definition: define.h:270
void object_set_owner(object *op, object *owner)
Definition: object.c:604
#define EVENT_ATTACKED
Definition: events.h:20
#define AT_CHAOS
Definition: attack.h:94
#define MSG_TYPE_ATTACK_PET_DIED
Definition: newclient.h:611
void object_free_drop_inventory(object *ob)
Definition: object.c:1316
int change_abil(object *op, object *tmp)
Definition: living.c:395
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1849
void confuse_living(object *op, object *hitter, int dam)
Definition: attack.c:2255
#define NDI_RED
Definition: newclient.h:224
void object_replace_insert_in_map(const char *arch_string, object *op)
Definition: object.c:2342
#define ATM_ARROW
Definition: attack.h:23
#define SP_BULLET
Definition: spells.h:79
#define FLAG_ALIVE
Definition: define.h:230
void kill_player(object *op, const object *killer)
Definition: player.c:3453
#define ATNR_CANCELLATION
Definition: attack.h:64
#define MSG_TYPE_VICTIM
Definition: newclient.h:392
static int get_attack_mode(object **target, object **hitter, int *simple_attack)
Definition: attack.c:683
int get_turn_bonus(int stat)
Definition: living.c:2372
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2602
EXTERN const char * undead_name
Definition: global.h:155
int is_wraith_pl(object *op)
Definition: player.c:165
#define SK_EXP_TOTAL
Definition: skills.h:79
#define ATNR_PARALYZE
Definition: attack.h:61
signed short int16_t
Definition: win32.h:160
EXTERN Chaos_Attacks ATTACKS[22]
Definition: attack.h:134
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:536
object * create_archetype(const char *name)
Definition: arch.cpp:281
int64_t pk_max_experience
Definition: global.h:313
#define ATM_PUNCH
Definition: attack.h:31
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
int monster_stand_in_light(object *op)
Definition: monster.c:2531
void monster_npc_call_help(object *op)
Definition: monster.c:1840
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:474
#define MSG_TYPE_ATTACK_DID_KILL
Definition: newclient.h:610
#define ATM_SLASH
Definition: attack.h:32
#define ATNR_LIFE_STEALING
Definition: attack.h:73
#define ATNR_DEATH
Definition: attack.h:66
#define snprintf
Definition: win32.h:46
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:380
#define ATM_CLAW
Definition: attack.h:30
int hit_map(object *op, int dir, uint32_t type, int full_hit)
Definition: attack.c:327
#define MOVE_FLYING
Definition: define.h:410
#define FOR_INV_FINISH()
Definition: define.h:714
#define MAXATTACKMESS
Definition: attack.h:19
#define ATNR_BLIND
Definition: attack.h:71
#define FLAG_BLOCKSVIEW
Definition: define.h:269
#define ATNR_INTERNAL
Definition: attack.h:72
#define ATNR_FEAR
Definition: attack.h:63
#define WEAP_STAB
Definition: define.h:82
#define WEAP_PIERCE
Definition: define.h:79
#define MSG_TYPE_VICTIM_WAS_HIT
Definition: newclient.h:647
object * object_present_in_ob(uint8_t type, const object *op)
Definition: object.c:2900
#define ATM_COLD
Definition: attack.h:26
#define FLAG_PARALYZED
Definition: define.h:380
#define ATNR_MAGIC
Definition: attack.h:50
#define ATM_CLEAVE
Definition: attack.h:34
static void object_get_materialtype(object *op, materialtype_t **mt)
Definition: attack.c:73
#define UPD_FLAGS
Definition: newclient.h:290
#define P_OUT_OF_MAP
Definition: map.h:252
#define AT_FIRE
Definition: attack.h:78
#define ATNR_HOLYWORD
Definition: attack.h:70
#define FLAG_SCARED
Definition: define.h:271
#define FORCE_CONFUSION
Definition: spells.h:144
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4201
uint8_t simple_exp
Definition: global.h:262
#define ATNR_PHYSICAL
Definition: attack.h:49
#define ATM_WRAITH_FEED
Definition: attack.h:42
static void deathstrike_living(object *op, object *hitter, int *dam)
Definition: attack.c:2391
#define ATNR_POISON
Definition: attack.h:59
#define AT_PHYSICAL
Definition: attack.h:76
int process_object(object *op)
Definition: time.c:796
#define IS_LIVE(op)
Definition: define.h:172
int on_same_map(const object *op1, const object *op2)
Definition: map.c:2666
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define MSG_TYPE_APPLY_UNAPPLY
Definition: newclient.h:597
#define FLAG_WIZ
Definition: define.h:231
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2166
#define MSG_TYPE_ATTACK_FUMBLE
Definition: newclient.h:609
#define WEAP_CRUSH
Definition: define.h:84
#define MAX_BUF
Definition: define.h:35
#define MSG_TYPE_ATTACK
Definition: newclient.h:385
#define MSG_TYPE_ADMIN
Definition: newclient.h:377
#define MSG_TYPE_ATTACK_DID_HIT
Definition: newclient.h:607
#define WEAP_SLASH
Definition: define.h:78
#define ATM_DRAIN
Definition: attack.h:24
#define ATNR_COUNTERSPELL
Definition: attack.h:68
#define ATM_DOOR
Definition: attack.h:40
#define ATNR_DRAIN
Definition: attack.h:56
#define FLAG_RUN_AWAY
Definition: define.h:280
#define EVENT_DEATH
Definition: events.h:24
int slow_living_by(object *op, const int speed_penalty)
Definition: attack.c:2174
#define M_IRON
Definition: material.h:15
signed __int64 int64_t
Definition: win32.h:168
#define FLAG_READY_WEAPON
Definition: define.h:335
#define AT_DRAIN
Definition: attack.h:83
#define FOR_MAP_FINISH()
Definition: define.h:767
#define FLAG_KNOWN_CURSED
Definition: define.h:321
#define FLAG_CURSED
Definition: define.h:317
unsigned int uint32_t
Definition: win32.h:162
char killer[BIG_NAME]
Definition: player.h:171
#define AT_POISON
Definition: attack.h:86
#define FLAG_NO_DAMAGE
Definition: define.h:364
#define PREFER_HIGH
Definition: define.h:600
#define FLAG_GENERATOR
Definition: define.h:248
#define FLAG_BLIND
Definition: define.h:337
uint16_t set_friendly_fire
Definition: global.h:274
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2421
#define RANDOM()
Definition: define.h:681
static void cancellation(object *op)
Definition: attack.c:49
#define NUM_ANIMATIONS(ob)
Definition: global.h:169
EXTERN attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]
Definition: attack.h:131
#define AT_FEAR
Definition: attack.h:90
#define AT_SLOW
Definition: attack.h:87
#define EVENT_ATTACKS
Definition: events.h:21
struct Settings settings
Definition: init.c:39
void object_set_enemy(object *op, object *enemy)
Definition: object.c:679
static void put_in_icecube(object *op, object *originator)
Definition: attack.c:145
#define FLAG_SPLITTING
Definition: define.h:266
void check_physically_infect(object *victim, object *hitter)
Definition: disease.c:663
#define FLAG_APPLIED
Definition: define.h:235
#define NROFATTACKS
Definition: attack.h:17
object * object_merge(object *op, object *top)
Definition: object.c:1800
signed int int32_t
Definition: win32.h:159
#define UPD_NAME
Definition: newclient.h:293
int hit_player(object *op, int dam, object *hitter, uint32_t type, int full_hit)
Definition: attack.c:1852
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:598
void object_handle_death_animation(object *op)
Definition: object.c:5142
#define FOR_OB_AND_BELOW_PREPARE(op_)
Definition: define.h:787
#define FORCE_NAME
Definition: spells.h:169
#define AT_MAGIC
Definition: attack.h:77
#define GET_ANIM_ID(ob)
Definition: global.h:163
sstring add_string(const char *str)
Definition: shstr.c:124
struct pl * next
Definition: player.h:93
static const int32_t MAX_FOOD
Definition: define.h:476
#define ATM_BASIC
Definition: attack.h:28
#define ATM_SUFFER
Definition: attack.h:41
#define FLAG_MONSTER
Definition: define.h:245
void counterspell(object *op, int dir)
static int attack_ob_simple(object *op, object *hitter, int base_dam, int base_wc)
Definition: attack.c:750
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:259
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:311
#define NDI_UNIQUE
Definition: newclient.h:245
#define ATM_SLICE
Definition: attack.h:35
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
int did_make_save(const object *op, int level, int bonus)
Definition: living.c:2280
void make_visible(object *op)
Definition: player.c:3910
#define FLAG_WAS_WIZ
Definition: define.h:234
struct _materialtype * next
Definition: material.h:39
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:760
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:107
static int kill_object(object *op, int dam, object *hitter)
Definition: attack.c:1532
#define ATNR_COLD
Definition: attack.h:53
#define MSG_TYPE_ATTACK_PET_HIT
Definition: newclient.h:608
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:583
void save_throw_object(object *op, uint32_t type, object *originator)
Definition: attack.c:182
void share_exp(object *op, int64_t exp, const char *skill, int flag)
Definition: living.c:2310
static void slow_living(object *op, object *hitter, int dam)
Definition: attack.c:2212
Definition: map.h:326
object * map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at)
Definition: object.c:2850
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
char * buf2
Definition: attack.h:121
#define USING_SKILL(op, skill)
Definition: skills.h:85
#define AT_CONFUSION
Definition: attack.h:81
int friendly_fire(object *op, object *hitter)
Definition: attack.c:1803
#define FLAG_NO_PICK
Definition: define.h:239
#define ATM_STAB
Definition: attack.h:36
int pk_max_experience_percent
Definition: global.h:314
#define IS_ARROW(op)
Definition: define.h:177
#define AT_ACID
Definition: attack.h:82
void fix_object(object *op)
Definition: living.c:1124
#define ATNR_CHAOS
Definition: attack.h:67
#define ATNR_ACID
Definition: attack.h:55
#define SP_EXPLOSION
Definition: spells.h:80
#define AT_DEATH
Definition: attack.h:93
void object_update_speed(object *op)
Definition: object.c:1086
int attack_ob(object *op, object *hitter)
Definition: attack.c:912
object * object_get_owner(object *op)
Definition: object.c:568
void change_object(object *op)
Definition: time.c:589
int level
Definition: readable.c:1589
#define WEAP_HIT
Definition: define.h:77
static int hit_with_one_attacktype(object *op, object *hitter, int dam, uint32_t attacknum)
Definition: attack.c:1164
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Definition: object.c:2935
object * fix_stopped_arrow(object *op)
Definition: time.c:509
static void poison_living(object *op, object *hitter, int dam)
Definition: attack.c:2101
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:707
int16_t pk_luck_penalty
Definition: global.h:256
void object_remove(object *op)
Definition: object.c:1588
void shuffle_attack(object *op)
Definition: spell_util.c:1071
object * hit_with_arrow(object *op, object *victim)
Definition: attack.c:954
#define AT_PARALYZE
Definition: attack.h:88
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START
Definition: newclient.h:558
#define ATM_ELEC
Definition: attack.h:25
const char *const attacks[NROFATTACKS]
Definition: living.c:130
object * object_find_by_type2(const object *who, int type1, int type2)
Definition: object.c:3827
#define FLAG_FREED
Definition: define.h:233
#define ATNR_FIRE
Definition: attack.h:51