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