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