ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/attack.C
(Generate patch)

Comparing deliantra/server/server/attack.C (file contents):
Revision 1.118 by root, Tue Nov 10 04:38:45 2009 UTC vs.
Revision 1.145 by root, Tue Jan 3 11:25:35 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
41/* did_make_save_item just checks to make sure the item actually 41/* did_make_save_item just checks to make sure the item actually
42 * made its saving throw based on the tables. It does not take 42 * made its saving throw based on the tables. It does not take
43 * any further action (like destroying the item). 43 * any further action (like destroying the item).
44 */ 44 */
45static int 45static int
46did_make_save_item (object *op, int type, object *originator) 46did_make_save_item (object *op, uint32_t type, object *originator)
47{ 47{
48 int i, roll, saves = 0, attacks = 0, number; 48 int saves = 0, attacks = 0;
49 materialtype_t *mt = op->material; 49 materialtype_t *mt = op->material;
50 50
51 // destroying objects without material has many bad effects
52 if (mt == MATERIAL_NULL)
53 return 1;
54
51 roll = rndm (1, 20); 55 int roll = rndm (1, 20);
52 56
53 /* the attacktypes have no meaning for object saves 57 /* the attacktypes have no meaning for object saves
54 * If the type is only magic, don't adjust type - basically, if 58 * If the type is only magic, don't adjust type - basically, if
55 * pure magic is hitting an object, it should save. However, if it 59 * pure magic is hitting an object, it should save. However, if it
56 * is magic teamed with something else, then strip out the 60 * is magic teamed with something else, then strip out the
57 * magic type, and instead let the fire, cold, or whatever component 61 * magic type, and instead let the fire, cold, or whatever component
58 * destroy the item. Otherwise, you get the case of poisoncloud 62 * destroy the item. Otherwise, you get the case of poisoncloud
59 * destroying objects because it has magic attacktype. 63 * destroying objects because it has magic attacktype.
60 */ 64 */
61 if (type != AT_MAGIC) 65 if (type != AT_MAGIC)
62 type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | 66 type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW |
63 AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | 67 AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH |
64 AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); 68 AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC);
65 69
70
66 if (type == 0) return TRUE; 71 if (type == 0) return TRUE;
67 72
68 if (roll == 20) return TRUE; 73 if (roll == 20) return TRUE;
69 if (roll == 1) return FALSE; 74 if (roll == 1) return FALSE;
70 75
71 for (number = 0; number < NROFATTACKS; number++) 76 for_all_bits_sparse_32 (type, number)
72 { 77 {
73 i = 1 << number;
74
75 if (!(i & type))
76 continue;
77
78 attacks++; 78 attacks++;
79
79 if (op->resist[number] == 100) 80 if (op->resist[number] == 100)
80 saves++; 81 saves++;
81 else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100) 82 else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100)
82 saves++; 83 saves++;
83 else if ((20 - mt->save[number]) / 3 > originator->stats.dam) 84 else if ((20 - mt->save[number]) / 3 > originator->stats.dam)
100cancellation (object *op) 101cancellation (object *op)
101{ 102{
102 if (op->invisible) 103 if (op->invisible)
103 return; 104 return;
104 105
105 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) 106 if (op->flag [FLAG_ALIVE] || op->type == CONTAINER || op->type == THROWN_OBJ)
106 { 107 {
107 /* Recurse through the inventory */ 108 /* Recurse through the inventory */
108 for (object *tmp = op->inv; tmp; tmp = tmp->below) 109 for (object *tmp = op->inv; tmp; tmp = tmp->below)
109 if (!did_make_save_item (tmp, AT_CANCELLATION, op)) 110 if (!did_make_save_item (tmp, AT_CANCELLATION, op))
110 cancellation (tmp); 111 cancellation (tmp);
113 { 114 {
114 /* Nullify this object. This code could probably be more complete */ 115 /* Nullify this object. This code could probably be more complete */
115 /* in what abilities it should cancel */ 116 /* in what abilities it should cancel */
116 op->magic = 0; 117 op->magic = 0;
117 118
118 CLEAR_FLAG (op, FLAG_DAMNED); 119 op->clr_flag (FLAG_DAMNED);
119 CLEAR_FLAG (op, FLAG_CURSED); 120 op->clr_flag (FLAG_CURSED);
120 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 121 op->clr_flag (FLAG_KNOWN_MAGICAL);
121 CLEAR_FLAG (op, FLAG_KNOWN_CURSED); 122 op->clr_flag (FLAG_KNOWN_CURSED);
122 123
123 if (object *pl = op->visible_to ()) 124 if (object *pl = op->visible_to ())
124 esrv_update_item (UPD_FLAGS, pl, op); 125 esrv_update_item (UPD_FLAGS, pl, op);
125 } 126 }
126} 127}
130 * calling cancellation, etc.) 131 * calling cancellation, etc.)
131 */ 132 */
132void 133void
133save_throw_object (object *op, int type, object *originator) 134save_throw_object (object *op, int type, object *originator)
134{ 135{
136 op = op->head_ ();
137
135 if (!did_make_save_item (op, type, originator)) 138 if (!did_make_save_item (op, type, originator))
136 { 139 {
137 object *env = op->env; 140 object *env = op->env;
138 int x = op->x, y = op->y; 141 int x = op->x, y = op->y;
139 maptile *m = op->map; 142 maptile *m = op->map;
148 * object with +/- glow_radius and an "other_arch" to change to. 151 * object with +/- glow_radius and an "other_arch" to change to.
149 * (and please note that we cant fail our save and reach this 152 * (and please note that we cant fail our save and reach this
150 * function if the object doesnt contain a material that can burn. 153 * function if the object doesnt contain a material that can burn.
151 * So forget lighting magical swords on fire with this!) -b.t. 154 * So forget lighting magical swords on fire with this!) -b.t.
152 */ 155 */
153 if (type & (AT_FIRE | AT_ELECTRICITY) 156 if (type & (AT_FIRE | AT_ELECTRICITY))
154 && (QUERY_FLAG (op, FLAG_IS_LIGHTABLE)
155 || op->type == LAMP
156 || op->type == TORCH
157 )) 157 {
158 { 158 // seems LAMPs and TORCHes are always IS_LIGHTABLE?
159 switch (op->type) 159 if (op->type == LAMP || op->type == TORCH)
160 { 160 {
161 case LAMP:
162 case TORCH:
163 // turn on a lamp
164 apply_lamp (op, true); 161 apply_lamp (op, true); // turn on a lamp
165 break; 162 return;
166
167 default:
168 // for instance icecubes:
169 if (op->other_arch)
170 {
171 const char *arch = op->other_arch->archname;
172
173 if (op->decrease ())
174 fix_stopped_item (op, m, originator);
175
176 if ((op = archetype::get (arch)))
177 {
178 if (env)
179 env->insert (op);
180 else
181 m->insert (op, x, y, originator);
182 }
183 }
184 } 163 }
164 else if (op->flag [FLAG_IS_LIGHTABLE])
165 {
166 if (op->other_arch)
167 {
168 const char *arch = op->other_arch->archname;
169
170 if (op->decrease ())
171 fix_stopped_item (op, m, originator);
172
173 if ((op = archetype::get (arch)))
174 {
175 if (env)
176 env->insert (op);
177 else
178 m->insert (op, x, y, originator);
179 }
180 }
181
185 return; 182 return;
183 }
186 } 184 }
187 185
188 if (type & AT_CANCELLATION) 186 if (type & AT_CANCELLATION)
189 { /* Cancellation. */ 187 { /* Cancellation. */
190 cancellation (op); 188 cancellation (op);
191 fix_stopped_item (op, m, originator); 189 fix_stopped_item (op, m, originator);
190
192 return; 191 return;
193 }
194
195 if (op->nrof > 1)
196 {
197 if (op->decrease (rndm (0, op->nrof - 1)))
198 fix_stopped_item (op, m, originator);
199 }
200 else
201 {
202 // drop everything to the ground, if possible
203 op->insert_at (originator);
204 op->drop_and_destroy ();
205 } 192 }
206 193
207 if (type & (AT_FIRE | AT_ELECTRICITY)) 194 if (type & (AT_FIRE | AT_ELECTRICITY))
208 if (env) 195 if (env)
209 { 196 {
210 op = archetype::get (shstr_burnout); 197 object *op = archetype::get (shstr_burnout);
211 op->x = env->x, op->y = env->y; 198 op->x = env->x, op->y = env->y;
212 env->insert (op); 199 env->insert (op);
213 } 200 }
214 else 201 else
215 replace_insert_ob_in_map (shstr_burnout, originator); 202 replace_insert_ob_in_map (shstr_burnout, originator);
216 203
204 if (op->nrof > 1)
205 {
206 if (op->decrease (rndm (0, op->nrof - 1)))
207 fix_stopped_item (op, m, originator);
208 }
209 else
210 {
211 // drop everything to the ground, if possible
212 op->insert_at (originator);
213 op->drop_and_destroy ();
214 }
215
217 return; 216 return;
218 } 217 }
219 218
220 /* The value of 50 is arbitrary. */ 219 /* The value of 50 is arbitrary. */
221 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2)) 220 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !op->flag [FLAG_NO_PICK] && rndm (2))
222 { 221 {
223 archetype *at = archetype::find (shstr_icecube); 222 archetype *at = archetype::find (shstr_icecube);
224 223
225 if (at == NULL) 224 if (at == NULL)
226 return; 225 return;
230 return; 229 return;
231 230
232 object *tmp = present_arch (at, op->map, op->x, op->y); 231 object *tmp = present_arch (at, op->map, op->x, op->y);
233 if (!tmp) 232 if (!tmp)
234 { 233 {
235 tmp = arch_to_object (at); 234 tmp = at->instance ();
236 tmp->x = op->x, tmp->y = op->y; 235 tmp->x = op->x, tmp->y = op->y;
237 /* This was in the old (pre new movement code) - 236 /* This was in the old (pre new movement code) -
238 * icecubes have slow_move set to 1 - don't want 237 * icecubes have slow_move set to 1 - don't want
239 * that for ones we create. 238 * that for ones we create.
240 */ 239 */
253 * type is the attacktype of the object. 252 * type is the attacktype of the object.
254 * full_hit is set if monster area does not matter. 253 * full_hit is set if monster area does not matter.
255 * returns 1 if it hits something, 0 otherwise. 254 * returns 1 if it hits something, 0 otherwise.
256 */ 255 */
257int 256int
258hit_map (object *op, int dir, int type, int full_hit) 257hit_map (object *op, int dir, uint32_t type, int full_hit)
259{ 258{
260 maptile *map; 259 maptile *map;
261 sint16 x, y; 260 sint16 x, y;
262 int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ 261 int retflag = 0; /* added this flag.. will return 1 if it hits a monster */
263 262
264 if (QUERY_FLAG (op, FLAG_FREED)) 263 if (op->flag [FLAG_FREED])
265 { 264 {
266 LOG (llevError, "BUG: hit_map(): free object\n"); 265 LOG (llevError, "BUG: hit_map(): free object\n");
267 return 0; 266 return 0;
268 } 267 }
269 268
270 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) 269 if (op->flag [FLAG_REMOVED] || op->env != NULL)
271 { 270 {
272 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); 271 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name);
273 return 0; 272 return 0;
274 } 273 }
275 274
339 * This is one of the few cases where on_same_map should not be used. 338 * This is one of the few cases where on_same_map should not be used.
340 */ 339 */
341 if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) 340 if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y)
342 continue; 341 continue;
343 342
344 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 343 if (tmp->flag [FLAG_ALIVE])
345 { 344 {
346 hit_player (tmp, op->stats.dam, op, type, full_hit); 345 hit_player (tmp, op->stats.dam, op, type, full_hit);
347 retflag |= 1; 346 retflag |= 1;
348 347
349 if (op->destroyed ()) 348 if (op->destroyed ())
353 * NO_PASS set, it is also immune - you can't destroy walls. Note 352 * NO_PASS set, it is also immune - you can't destroy walls. Note
354 * that weak walls have is_alive set, which prevent objects from 353 * that weak walls have is_alive set, which prevent objects from
355 * passing over/through them. We don't care what type of movement 354 * passing over/through them. We don't care what type of movement
356 * the wall blocks - if it blocks any type of movement, can't be 355 * the wall blocks - if it blocks any type of movement, can't be
357 * destroyed right now. 356 * destroyed right now.
357 * Without the material check the server completely fails to work,
358 * objects detsroy themselves, floors get destroyed etc. etc.
358 */ 359 */
359 else if (op->stats.dam > 0 && !tmp->move_block) 360 else if (op->stats.dam > 0 && !tmp->move_block && tmp->material != MATERIAL_NULL)
360 { 361 {
361 save_throw_object (tmp, type, op); 362 save_throw_object (tmp, type, op);
362 363
363 if (op->destroyed ()) 364 if (op->destroyed ())
364 break; 365 break;
522 { 523 {
523 int mtype; 524 int mtype;
524 525
525 switch (hitter->current_weapon->weapontype) 526 switch (hitter->current_weapon->weapontype)
526 { 527 {
527 case WEAP_HIT: 528 case WEAP_HIT: mtype = ATM_BASIC; break;
528 mtype = ATM_BASIC; 529 case WEAP_SLASH: mtype = ATM_SLASH; break;
529 break; 530 case WEAP_PIERCE: mtype = ATM_PIERCE; break;
530 case WEAP_SLASH: 531 case WEAP_CLEAVE: mtype = ATM_CLEAVE; break;
531 mtype = ATM_SLASH; 532 case WEAP_SLICE: mtype = ATM_SLICE; break;
532 break; 533 case WEAP_STAB: mtype = ATM_STAB; break;
533 case WEAP_PIERCE: 534 case WEAP_WHIP: mtype = ATM_WHIP; break;
534 mtype = ATM_PIERCE; 535 case WEAP_CRUSH: mtype = ATM_CRUSH; break;
535 break; 536 case WEAP_BLUD: mtype = ATM_BLUD; break;
536 case WEAP_CLEAVE: 537 default: mtype = ATM_BASIC; break;
537 mtype = ATM_CLEAVE;
538 break;
539 case WEAP_SLICE:
540 mtype = ATM_SLICE;
541 break;
542 case WEAP_STAB:
543 mtype = ATM_STAB;
544 break;
545 case WEAP_WHIP:
546 mtype = ATM_WHIP;
547 break;
548 case WEAP_CRUSH:
549 mtype = ATM_CRUSH;
550 break;
551 case WEAP_BLUD:
552 mtype = ATM_BLUD;
553 break;
554 default:
555 mtype = ATM_BASIC;
556 break;
557 } 538 }
558 539
559 for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) 540 for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++)
560 if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) 541 if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1)
561 { 542 {
667} 648}
668 649
669static int 650static int
670get_attack_mode (object **target, object **hitter, int *simple_attack) 651get_attack_mode (object **target, object **hitter, int *simple_attack)
671{ 652{
672 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) 653 if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED])
673 { 654 {
674 LOG (llevError, "BUG: get_attack_mode(): freed object\n"); 655 LOG (llevError, "BUG: get_attack_mode(): freed object\n");
675 return 1; 656 return 1;
676 } 657 }
677 658
685 { 666 {
686 *simple_attack = 1; 667 *simple_attack = 1;
687 return 0; 668 return 0;
688 } 669 }
689 670
690 if (QUERY_FLAG (*target, FLAG_REMOVED) 671 if ((*target)->flag [FLAG_REMOVED]
691 || QUERY_FLAG (*hitter, FLAG_REMOVED) 672 || (*hitter)->flag [FLAG_REMOVED]
692 || !(*hitter)->map 673 || !(*hitter)->map
693 || !on_same_map (*hitter, *target)) 674 || !on_same_map (*hitter, *target))
694 { 675 {
695 LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", 676 LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n",
696 (*hitter)->debug_desc (), (*target)->debug_desc ()); 677 (*hitter)->debug_desc (), (*target)->debug_desc ());
709 */ 690 */
710 int new_mode; 691 int new_mode;
711 692
712 if (hitter->env == target || target->env == hitter) 693 if (hitter->env == target || target->env == hitter)
713 new_mode = 1; 694 new_mode = 1;
714 else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) 695 else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED]
715 || hitter->map == NULL || !on_same_map (hitter, target)) 696 || hitter->map == NULL || !on_same_map (hitter, target))
716 return 1; 697 return 1;
717 else 698 else
718 new_mode = 0; 699 new_mode = 0;
719 700
725 * monster). 706 * monster).
726 */ 707 */
727static void 708static void
728thrown_item_effect (object *hitter, object *victim) 709thrown_item_effect (object *hitter, object *victim)
729{ 710{
730 if (!QUERY_FLAG (hitter, FLAG_ALIVE)) 711 if (!hitter->flag [FLAG_ALIVE])
731 { 712 {
732 /* May not need a switch for just 2 types, but this makes it 713 /* May not need a switch for just 2 types, but this makes it
733 * easier for expansion. 714 * easier for expansion.
734 */ 715 */
735 switch (hitter->type) 716 switch (hitter->type)
736 { 717 {
737 case POTION: 718 case POTION:
738 /* should player get a save throw instead of checking magic protection? */ 719 /* should player get a save throw instead of checking magic protection? */
739 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_MAGIC] < 60)) 720 if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_MAGIC] < 60))
740 (void) apply_potion (victim, hitter); 721 apply_potion (victim, hitter);
741 break; 722 break;
742 723
743 case POISON: /* poison drinks */ 724 case POISON: /* poison drinks */
744 /* As with potions, should monster get a save? */ 725 /* As with potions, should monster get a save? */
745 if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_POISON] < 60)) 726 if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_POISON] < 60))
746 apply_poison (victim, hitter); 727 apply_poison (victim, hitter);
747 break; 728 break;
748 729
749 /* Removed case statements that did nothing. 730 /* Removed case statements that did nothing.
750 * food may be poisonous, but monster must be willing to eat it, 731 * food may be poisonous, but monster must be willing to eat it,
757 738
758/* determine if the object is an 'aimed' missile */ 739/* determine if the object is an 'aimed' missile */
759static int 740static int
760is_aimed_missile (object *op) 741is_aimed_missile (object *op)
761{ 742{
762
763 /* I broke what used to be one big if into a few nested 743 /* I broke what used to be one big if into a few nested
764 * ones so that figuring out the logic is at least possible. 744 * ones so that figuring out the logic is at least possible.
765 */ 745 */
766 if (op && (op->move_type & MOVE_FLYING)) 746 if (op && (op->move_type & MOVE_FLYING))
767 if (op->type == ARROW || op->type == THROWN_OBJ) 747 if (op->type == ARROW || op->type == THROWN_OBJ)
791 if ((attacker = hitter->owner) == NULL) 771 if ((attacker = hitter->owner) == NULL)
792 attacker = hitter; 772 attacker = hitter;
793 /* A player who saves but hasn't quit still could have objects 773 /* A player who saves but hasn't quit still could have objects
794 * owned by him - need to handle that case to avoid crashes. 774 * owned by him - need to handle that case to avoid crashes.
795 */ 775 */
796 if (QUERY_FLAG (attacker, FLAG_REMOVED)) 776 if (attacker->flag [FLAG_REMOVED])
797 attacker = hitter; 777 attacker = hitter;
798 } 778 }
799 else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) 779 else if (!hitter->flag [FLAG_ALIVE])
800 return 0; 780 return 0;
801 781
802 /* determine the condtions under which we make an attack. 782 /* determine the condtions under which we make an attack.
803 * Add more cases, as the need occurs. */ 783 * Add more cases, as the need occurs. */
804 784
805 if (!can_see_enemy (attacker, target)) 785 if (!can_see_enemy (attacker, target))
806 { 786 {
807 /* target is unseen */ 787 /* target is unseen */
808 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) 788 if (target->invisible || attacker->flag [FLAG_BLIND])
809 adjust -= 10; 789 adjust -= 10;
810 /* dark map penalty for the hitter (lacks infravision if we got here). */ 790 /* dark map penalty for the hitter (lacks infravision if we got here). */
811 else if (!stand_in_light (target)) 791 else if (!stand_in_light (target))
812 adjust -= target->map->darklevel (); 792 adjust -= target->map->darklevel ();
813 } 793 }
814 794
815 if (QUERY_FLAG (attacker, FLAG_SCARED)) 795 if (attacker->flag [FLAG_SCARED])
816 adjust -= 3; 796 adjust -= 3;
817 797
818 if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) 798 if (target->flag [FLAG_UNAGGRESSIVE])
819 adjust += 1; 799 adjust += 1;
820 800
821 if (QUERY_FLAG (target, FLAG_SCARED)) 801 if (target->flag [FLAG_SCARED])
822 adjust += 1; 802 adjust += 1;
823 803
824 if (QUERY_FLAG (attacker, FLAG_CONFUSED)) 804 if (attacker->flag [FLAG_CONFUSED])
825 adjust -= 3; 805 adjust -= 3;
826 806
827 /* if we attack at a different 'altitude' its harder */ 807 /* if we attack at a different 'altitude' its harder */
828 if ((attacker->move_type & target->move_type) == 0) 808 if ((attacker->move_type & target->move_type) == 0)
829 adjust -= 2; 809 adjust -= 2;
865 845
866 /* 846 /*
867 * A little check to make it more difficult to dance forward and back 847 * A little check to make it more difficult to dance forward and back
868 * to avoid ever being hit by monsters. 848 * to avoid ever being hit by monsters.
869 */ 849 */
870 if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > abs (op->speed) * -0.3f) 850 if (!simple_attack && op->flag [FLAG_MONSTER] && op->speed_left > op->speed * -0.3f)
871 { 851 {
872 /* Decrease speed BEFORE calling process_object. Otherwise, an 852 /* Decrease speed BEFORE calling process_object. Otherwise, an
873 * infinite loop occurs, with process_object calling move_monster, 853 * infinite loop occurs, with process_object calling move_monster,
874 * which then gets here again. By decreasing the speed before 854 * which then gets here again. By decreasing the speed before
875 * we call process_object, the 'if' statement above will fail. 855 * we call process_object, the 'if' statement above will fail.
897 if (!simple_attack) 877 if (!simple_attack)
898 { 878 {
899 /* If you hit something, the victim should *always* wake up. 879 /* If you hit something, the victim should *always* wake up.
900 * Before, invisible hitters could avoid doing this. 880 * Before, invisible hitters could avoid doing this.
901 * -b.t. */ 881 * -b.t. */
902 if (QUERY_FLAG (op, FLAG_SLEEP)) 882 if (op->flag [FLAG_SLEEP])
903 CLEAR_FLAG (op, FLAG_SLEEP); 883 op->clr_flag (FLAG_SLEEP);
904 884
905 /* If the victim can't see the attacker, it may alert others 885 /* If the victim can't see the attacker, it may alert others
906 * for help. */ 886 * for help. */
907 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) 887 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int))
908 npc_call_help (op); 888 npc_call_help (op);
928 } 908 }
929 909
930 /* Need to do at least 1 damage, otherwise there is no point 910 /* Need to do at least 1 damage, otherwise there is no point
931 * to go further and it will cause FPE's below. 911 * to go further and it will cause FPE's below.
932 */ 912 */
933 if (hitdam <= 0) 913 max_it (hitdam, 1);
934 hitdam = 1;
935 914
936 type = hitter->attacktype; 915 type = hitter->attacktype;
937 916
938 /* Ok, because some of the brainfucks of the good *sigh* old *sigh* 917 /* Ok, because some of the brainfucks of the good *sigh* old *sigh*
939 * Crossfire we have to default the attacktype here to AT_PHYSICAL. 918 * Crossfire we have to default the attacktype here to AT_PHYSICAL.
947 */ 926 */
948 if (!type) 927 if (!type)
949 type = AT_PHYSICAL; 928 type = AT_PHYSICAL;
950 929
951 /* Handle monsters that hit back */ 930 /* Handle monsters that hit back */
952 if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) 931 if (!simple_attack && op->flag [FLAG_HITBACK] && hitter->flag [FLAG_ALIVE])
953 { 932 {
954 if (op->attacktype & AT_ACID && hitter->type == PLAYER) 933 if (op->attacktype & AT_ACID && hitter->type == PLAYER)
955 new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); 934 new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n");
956 935
957 hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); 936 hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1);
983} 962}
984 963
985int 964int
986attack_ob (object *op, object *hitter) 965attack_ob (object *op, object *hitter)
987{ 966{
988 hitter = hitter->head_ ();
989
990 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); 967 return attack_ob_simple (op, hitter->head_ (), hitter->stats.dam, hitter->stats.wc);
991} 968}
992 969
993/* op is the arrow, tmp is what is stopping the arrow. 970/* op is the arrow, tmp is what is stopping the arrow.
994 * 971 *
995 * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. 972 * Returns 1 if op was inserted into tmp's inventory, 0 otherwise.
1103 1080
1104 return 0; 1081 return 0;
1105 } 1082 }
1106 1083
1107 if (hit_something && op->speed >= 10.0) 1084 if (hit_something && op->speed >= 10.0)
1108 op->speed -= 1.0; 1085 op->set_speed (op->speed - 1.f);
1109 1086
1110 /* Missile missed victim - reassemble missile */ 1087 /* Missile missed victim - reassemble missile */
1111 if (container) 1088 if (container)
1112 { 1089 {
1113 hitter->remove (); 1090 hitter->remove ();
1201 * this creature. The function(s) that call us have already 1178 * this creature. The function(s) that call us have already
1202 * adjusted the creatures HP total, so that is negative. 1179 * adjusted the creatures HP total, so that is negative.
1203 */ 1180 */
1204 maxdam = dam + op->stats.hp + 1; 1181 maxdam = dam + op->stats.hp + 1;
1205 1182
1206 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) 1183 if (op->flag [FLAG_BLOCKSVIEW])
1207 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ 1184 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */
1208 1185
1209 if (op->type == DOOR) 1186 if (op->type == DOOR)
1210 { 1187 {
1211 op->set_speed (0.1f); 1188 op->set_speed (0.1f);
1212 op->speed_left = -0.05f; 1189 op->speed_left = -0.05f;
1213 return maxdam; 1190 return maxdam;
1214 } 1191 }
1215 1192
1216 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1193 if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER)
1217 { 1194 {
1218 op->drop_and_destroy (); 1195 op->drop_and_destroy ();
1219 return maxdam; 1196 return maxdam;
1220 } 1197 }
1221 1198
1288 else if (owner->chosen_skill) 1265 else if (owner->chosen_skill)
1289 { 1266 {
1290 skop = owner->chosen_skill; 1267 skop = owner->chosen_skill;
1291 skill = skop->skill; 1268 skill = skop->skill;
1292 } 1269 }
1293 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) 1270 else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon)
1294 skill = owner->current_weapon->skill; 1271 skill = owner->current_weapon->skill;
1295 else 1272 else
1296 { 1273 {
1274 LOG (llevError | logBacktrace,
1297 LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" 1275 "BUG: kill_object - unable to find skill that killed monster\n"
1298 "op: %s\n" "hitter: %s\n" "owner: %s\n", 1276 "op: %s\n" "hitter: %s\n" "op: %s\n",
1299 owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); 1277 op->debug_desc (), hitter->debug_desc (), op->debug_desc ());
1300 skill = 0; 1278 skill = 0;
1301 } 1279 }
1302 1280
1303 /* We have the skill we want to credit to - now find the object this goes 1281 /* We have the skill we want to credit to - now find the object this goes
1304 * to. Make sure skop is an actual skill, and not a skill tool! 1282 * to. Make sure skop is an actual skill, and not a skill tool!
1314 1292
1315 if (!skill && skop) 1293 if (!skill && skop)
1316 skill = skop->skill; 1294 skill = skop->skill;
1317 1295
1318 /* If you didn't kill yourself, and your not the wizard */ 1296 /* If you didn't kill yourself, and your not the wizard */
1319 if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) 1297 if (owner != op && !op->flag [FLAG_WIZ])
1320 { 1298 {
1321 int exp; 1299 int exp;
1322 1300
1323 /* Really don't give much experience for killing other players */ 1301 /* Really don't give much experience for killing other players */
1324 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously 1302 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously
1381 } /* else part of a party */ 1359 } /* else part of a party */
1382 } /* end if person didn't kill himself */ 1360 } /* end if person didn't kill himself */
1383 1361
1384 if (op->type != PLAYER) 1362 if (op->type != PLAYER)
1385 { 1363 {
1386 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 1364 if (op->flag [FLAG_FRIENDLY])
1387 { 1365 {
1388 object *owner1 = op->owner; 1366 object *owner1 = op->owner;
1389 1367
1390 if (owner1 && owner1->type == PLAYER) 1368 if (owner1 && owner1->type == PLAYER)
1391 { 1369 {
1452 * modify it. 1430 * modify it.
1453 */ 1431 */
1454/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1432/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1455 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1433 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1456int 1434int
1457hit_player (object *op, int dam, object *hitter, int type, int full_hit) 1435hit_player (object *op, int dam, object *hitter, uint32_t type, int full_hit)
1458{ 1436{
1459 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); 1437 int magic = type & AT_MAGIC;
1460 int maxattacktype, attacknum;
1461 int body_attack = op && op->head; /* Did we hit op's head? */ 1438 int body_attack = op && op->head; /* Did we hit op's head? */
1439 int maxdam = 0, ndam = 0, attacktype = 1;
1440 int maxattacktype;
1462 int simple_attack; 1441 int simple_attack;
1463 int rtn_kill = 0; 1442 int rtn_kill = 0;
1464 int friendlyfire; 1443 int friendlyfire;
1465 1444
1466 if (get_attack_mode (&op, &hitter, &simple_attack)) 1445 if (get_attack_mode (&op, &hitter, &simple_attack))
1467 return 0; 1446 return 0;
1468 1447
1469 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ 1448 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */
1470 if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) 1449 if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE])
1471 return 0; 1450 return 0;
1472 1451
1473 // only allow pk for hostile players 1452 // only allow pk for hostile players
1474 if (op->type == PLAYER) 1453 if (op->type == PLAYER)
1475 { 1454 {
1517 1496
1518 break; 1497 break;
1519 } 1498 }
1520 } 1499 }
1521 1500
1522 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1501 if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0)
1523 { 1502 {
1524 /* FIXME: If a player is killed by a rune in a door, the 1503 /* FIXME: If a player is killed by a rune in a door, the
1525 * destroyed() check above doesn't return, and might get here. 1504 * destroyed() check above doesn't return, and might get here.
1526 */ 1505 */
1527 1506
1568 object *god; 1547 object *god;
1569 1548
1570 if ((!hitter->slaying 1549 if ((!hitter->slaying
1571 || (!(op->race && hitter->slaying.contains (op->race)) 1550 || (!(op->race && hitter->slaying.contains (op->race))
1572 && !(op->name && hitter->slaying.contains (op->name)))) 1551 && !(op->name && hitter->slaying.contains (op->name))))
1573 && (!QUERY_FLAG (op, FLAG_UNDEAD) 1552 && (!op->flag [FLAG_UNDEAD]
1574 || (hitter->title 1553 || (hitter->title
1575 && (god = find_god (determine_god (hitter))) != NULL 1554 && (god = find_god (determine_god (hitter))) != NULL
1576 && god->race.contains (shstr_undead)))) 1555 && god->race.contains (shstr_undead))))
1577 return 0; 1556 return 0;
1578 } 1557 }
1579 1558
1580 maxattacktype = type; /* initialise this to something */ 1559 maxattacktype = type; /* initialise this to something */
1581 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1560 for_all_bits_sparse_32 (type, attacknum)
1582 { 1561 {
1562 uint32_t attacktype = 1 << attacknum;
1563
1583 /* Magic isn't really a true attack type - it gets combined with other 1564 /* Magic isn't really a true attack type - it gets combined with other
1584 * attack types. As such, skip it over. However, if magic is 1565 * attack types. As such, skip it over. However, if magic is
1585 * the only attacktype in the group, then still attack with it 1566 * the only attacktype in the group, then still attack with it
1586 */ 1567 */
1587 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) 1568 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC))
1590 /* Go through and hit the player with each attacktype, one by one. 1571 /* Go through and hit the player with each attacktype, one by one.
1591 * hit_player_attacktype only figures out the damage, doesn't inflict 1572 * hit_player_attacktype only figures out the damage, doesn't inflict
1592 * it. It will do the appropriate action for attacktypes with 1573 * it. It will do the appropriate action for attacktypes with
1593 * effects (slow, paralization, etc. 1574 * effects (slow, paralization, etc.
1594 */ 1575 */
1595 if (type & attacktype)
1596 {
1597 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); 1576 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic);
1577
1598 /* the >= causes us to prefer messages from special attacks, if 1578 /* the >= causes us to prefer messages from special attacks, if
1599 * the damage is equal. 1579 * the damage is equal.
1600 */ 1580 */
1601 if (ndam >= maxdam) 1581 if (ndam >= maxdam)
1602 { 1582 {
1603 maxdam = ndam; 1583 maxdam = ndam;
1604 maxattacktype = 1 << attacknum; 1584 maxattacktype = 1 << attacknum;
1605 }
1606 } 1585 }
1607 } 1586 }
1608 1587
1609 /* if this is friendly fire then do a set % of damage only 1588 /* if this is friendly fire then do a set % of damage only
1610 * Note - put a check in to make sure this attack is actually 1589 * Note - put a check in to make sure this attack is actually
1650 // keep a refcount for a long time and I see no usefulness 1629 // keep a refcount for a long time and I see no usefulness
1651 // for an non-active objetc to know its enemy. 1630 // for an non-active objetc to know its enemy.
1652 if (op->active) 1631 if (op->active)
1653 if (hitter->owner) 1632 if (hitter->owner)
1654 op->enemy = hitter->owner; 1633 op->enemy = hitter->owner;
1655 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1634 else if (hitter->flag [FLAG_ALIVE])
1656 op->enemy = hitter; 1635 op->enemy = hitter;
1657 1636
1658 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1637 if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER)
1659 { 1638 {
1660 /* The unaggressives look after themselves 8) */ 1639 /* The unaggressives look after themselves 8) */
1661 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 1640 op->clr_flag (FLAG_UNAGGRESSIVE);
1662 npc_call_help (op); 1641 npc_call_help (op);
1663 } 1642 }
1664 1643
1665 if (magic && did_make_save (op, op->level, 0)) 1644 if (magic && did_make_save (op, op->level, 0))
1666 maxdam = maxdam / 2; 1645 maxdam = maxdam / 2;
1668 attack_message (maxdam, maxattacktype, op, hitter); 1647 attack_message (maxdam, maxattacktype, op, hitter);
1669 1648
1670 op->stats.hp -= maxdam; 1649 op->stats.hp -= maxdam;
1671 1650
1672 /* Eneq(@csd.uu.se): Check to see if monster runs away. */ 1651 /* Eneq(@csd.uu.se): Check to see if monster runs away. */
1673 if ((op->stats.hp >= 0) && 1652 if (op->stats.hp >= 0
1674 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && 1653 && (op->flag [FLAG_MONSTER] || op->type == PLAYER)
1675 op->stats.hp < (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) 1654 && op->stats.hp * 100 < op->stats.maxhp * op->run_away)
1676 { 1655 {
1677 1656
1678 if (QUERY_FLAG (op, FLAG_MONSTER)) 1657 if (op->flag [FLAG_MONSTER])
1679 SET_FLAG (op, FLAG_RUN_AWAY); 1658 op->set_flag (FLAG_RUN_AWAY);
1680 else 1659 else
1681 scare_creature (op, hitter); 1660 scare_creature (op, hitter);
1682 } 1661 }
1683 1662
1684 if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) 1663 if (op->flag [FLAG_TEAR_DOWN])
1685 { 1664 {
1686 if (maxdam) 1665 if (maxdam)
1687 tear_down_wall (op); 1666 tear_down_wall (op);
1688 1667
1689 return maxdam; /* nothing more to do for wall */ 1668 return maxdam; /* nothing more to do for wall */
1696 1675
1697 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1676 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1698 * that before if the player was immune to ghosthit, the monster 1677 * that before if the player was immune to ghosthit, the monster
1699 * remained - that is no longer the case. 1678 * remained - that is no longer the case.
1700 */ 1679 */
1701 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1680 if (hitter->flag [FLAG_ONE_HIT])
1702 hitter->drop_and_destroy (); 1681 hitter->drop_and_destroy ();
1703 /* Lets handle creatures that are splitting now */ 1682 /* Lets handle creatures that are splitting now */
1704 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1683 else if (type & AT_PHYSICAL && !op->flag [FLAG_FREED] && op->flag [FLAG_SPLITTING])
1705 { 1684 {
1706 int i;
1707 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1685 int friendly = op->flag [FLAG_FRIENDLY];
1708 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); 1686 int unaggressive = op->flag [FLAG_UNAGGRESSIVE];
1709 object *owner = op->owner; 1687 object *owner = op->owner;
1710 1688
1711 if (!op->other_arch) 1689 if (!op->other_arch)
1712 { 1690 {
1713 LOG (llevError, "SPLITTING without other_arch error.\n"); 1691 LOG (llevError, "SPLITTING without other_arch error.\n");
1714 return maxdam; 1692 return maxdam;
1715 } 1693 }
1716 1694
1717 op->remove (); 1695 op->remove ();
1718 1696
1719 for (i = 0; i < op->stats.food; i++) 1697 for (int i = 0; i < op->stats.food; i++)
1720 { /* This doesn't handle op->more yet */ 1698 { /* This doesn't handle op->more yet */
1721 object *tmp = arch_to_object (op->other_arch); 1699 object *tmp = op->other_arch->instance ();
1722 int j;
1723 1700
1724 tmp->stats.hp = op->stats.hp; 1701 tmp->stats.hp = op->stats.hp;
1725 1702
1726 if (friendly) 1703 if (friendly)
1727 { 1704 {
1731 if (owner) 1708 if (owner)
1732 tmp->set_owner (owner); 1709 tmp->set_owner (owner);
1733 } 1710 }
1734 1711
1735 if (unaggressive) 1712 if (unaggressive)
1736 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 1713 tmp->set_flag (FLAG_UNAGGRESSIVE);
1737 1714
1738 j = find_first_free_spot (tmp, op->map, op->x, op->y); 1715 int j = find_first_free_spot (tmp, op->map, op->x, op->y);
1739 1716
1740 if (j == -1) /* No spot to put this monster */ 1717 if (j == -1) /* No spot to put this monster */
1741 tmp->destroy (); 1718 tmp->destroy ();
1742 else 1719 else
1743 { 1720 {
1758poison_player (object *op, object *hitter, int dam) 1735poison_player (object *op, object *hitter, int dam)
1759{ 1736{
1760 archetype *at = archetype::find (shstr_poisoning); 1737 archetype *at = archetype::find (shstr_poisoning);
1761 object *tmp = present_arch_in_ob (at, op); 1738 object *tmp = present_arch_in_ob (at, op);
1762 1739
1763 if (tmp == NULL) 1740 if (!tmp)
1764 { 1741 {
1765 if ((tmp = arch_to_object (at)) == NULL) 1742 tmp = insert_ob_in_ob (at->instance (), op);
1766 LOG (llevError, "Failed to clone arch poisoning.\n"); 1743 /* peterm: give poisoning some teeth. It should
1744 * be able to kill things better than it does:
1745 * damage should be dependent something--I choose to
1746 * do this: if it's a monster, the damage from the
1747 * poisoning goes as the level of the monster/2.
1748 * If anything else, goes as damage.
1749 */
1750
1751 if (hitter->flag [FLAG_ALIVE])
1752 tmp->stats.dam += hitter->level / 2;
1767 else 1753 else
1768 {
1769 tmp = insert_ob_in_ob (tmp, op);
1770 /* peterm: give poisoning some teeth. It should
1771 * be able to kill things better than it does:
1772 * damage should be dependent something--I choose to
1773 * do this: if it's a monster, the damage from the
1774 * poisoning goes as the level of the monster/2.
1775 * If anything else, goes as damage.
1776 */
1777
1778 if (QUERY_FLAG (hitter, FLAG_ALIVE))
1779 tmp->stats.dam += hitter->level / 2;
1780 else
1781 tmp->stats.dam = dam; 1754 tmp->stats.dam = dam;
1782 1755
1783 tmp->set_owner (hitter); /* so we get credit for poisoning kills */ 1756 tmp->set_owner (hitter); /* so we get credit for poisoning kills */
1784 if (hitter->skill && hitter->skill != tmp->skill) 1757 if (hitter->skill && hitter->skill != tmp->skill)
1785 {
1786 tmp->skill = hitter->skill; 1758 tmp->skill = hitter->skill;
1787 }
1788 1759
1789 tmp->stats.food += dam; /* more damage, longer poisoning */ 1760 tmp->stats.food += dam; /* more damage, longer poisoning */
1790 1761
1791 if (op->type == PLAYER) 1762 if (op->type == PLAYER)
1792 { 1763 {
1793 /* player looses stats, maximum is -10 of each */ 1764 /* player looses stats, maximum is -10 of each */
1794 tmp->stats.Con = max (-(dam / 4 + 1), -10); 1765 tmp->stats.Con = max (-(dam / 4 + 1), -10);
1795 tmp->stats.Str = max (-(dam / 3 + 2), -10); 1766 tmp->stats.Str = max (-(dam / 3 + 2), -10);
1796 tmp->stats.Dex = max (-(dam / 6 + 1), -10); 1767 tmp->stats.Dex = max (-(dam / 6 + 1), -10);
1797 tmp->stats.Int = max (-(dam / 7 ), -10); 1768 tmp->stats.Int = max (-(dam / 7 ), -10);
1798 SET_FLAG (tmp, FLAG_APPLIED); 1769 tmp->set_flag (FLAG_APPLIED);
1799 op->update_stats (); 1770 op->update_stats ();
1800 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); 1771 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
1801 op->play_sound (tmp->sound); 1772 op->play_sound (tmp->sound);
1802 } 1773 }
1803 1774
1804 if (hitter->type == PLAYER) 1775 if (hitter->type == PLAYER)
1805 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); 1776 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
1806 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 1777 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
1807 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); 1778 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name);
1808 }
1809 1779
1810 tmp->speed_left = 0; 1780 tmp->speed_left = 0;
1811 } 1781 }
1812 else 1782 else
1813 tmp->stats.food++; 1783 tmp->stats.food++;
1817slow_player (object *op, object *hitter, int dam) 1787slow_player (object *op, object *hitter, int dam)
1818{ 1788{
1819 archetype *at = archetype::find (shstr_slowness); 1789 archetype *at = archetype::find (shstr_slowness);
1820 object *tmp; 1790 object *tmp;
1821 1791
1822 if (at == NULL) 1792 if (!at)
1823 LOG (llevError, "Can't find slowness archetype.\n"); 1793 LOG (llevError, "Can't find slowness archetype.\n");
1824 1794
1825 if ((tmp = present_arch_in_ob (at, op)) == NULL) 1795 if ((tmp = present_arch_in_ob (at, op)) == NULL)
1826 { 1796 {
1827 tmp = arch_to_object (at); 1797 tmp = at->instance ();
1828 tmp = insert_ob_in_ob (tmp, op); 1798 tmp = insert_ob_in_ob (tmp, op);
1829 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); 1799 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!");
1830 } 1800 }
1831 else 1801 else
1832 tmp->stats.food++; 1802 tmp->stats.food++;
1833 1803
1834 SET_FLAG (tmp, FLAG_APPLIED); 1804 tmp->set_flag (FLAG_APPLIED);
1835 tmp->speed_left = 0; 1805 tmp->speed_left = 0;
1836 op->update_stats (); 1806 op->update_stats ();
1837} 1807}
1838 1808
1839void 1809void
1843 int maxduration; 1813 int maxduration;
1844 1814
1845 tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); 1815 tmp = present_in_ob_by_name (FORCE, shstr_confusion, op);
1846 if (!tmp) 1816 if (!tmp)
1847 { 1817 {
1848 tmp = get_archetype (FORCE_NAME); 1818 tmp = archetype::get (FORCE_NAME);
1849 tmp = insert_ob_in_ob (tmp, op); 1819 tmp = insert_ob_in_ob (tmp, op);
1850 } 1820 }
1851 1821
1852 /* Duration added per hit and max. duration of confusion both depend 1822 /* Duration added per hit and max. duration of confusion both depend
1853 * on the player's resistance 1823 * on the player's resistance
1854 */ 1824 */
1855 tmp->speed = 0.05; 1825 tmp->set_speed (0.05);
1856 tmp->subtype = FORCE_CONFUSION; 1826 tmp->subtype = FORCE_CONFUSION;
1857 tmp->duration = 8 + max (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); 1827 tmp->duration = 8 + max (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1858 tmp->name = shstr_confusion; 1828 tmp->name = shstr_confusion;
1859 maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); 1829 maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1860 1830
1861 if (tmp->duration > maxduration) 1831 if (tmp->duration > maxduration)
1862 tmp->duration = maxduration; 1832 tmp->duration = maxduration;
1863 1833
1864 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) 1834 if (op->type == PLAYER && !op->flag [FLAG_CONFUSED])
1865 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); 1835 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!");
1866 1836
1867 SET_FLAG (op, FLAG_CONFUSED); 1837 op->set_flag (FLAG_CONFUSED);
1868} 1838}
1869 1839
1870void 1840void
1871blind_player (object *op, object *hitter, int dam) 1841blind_player (object *op, object *hitter, int dam)
1872{ 1842{
1873 object *tmp, *owner;
1874
1875 /* Save some work if we know it isn't going to affect the player */ 1843 /* Save some work if we know it isn't going to affect the player */
1876 if (op->resist[ATNR_BLIND] == 100) 1844 if (op->resist[ATNR_BLIND] == 100)
1877 return; 1845 return;
1878 1846
1879 tmp = present_in_ob (BLINDNESS, op); 1847 object *tmp = present_in_ob (BLINDNESS, op);
1880 if (!tmp) 1848 if (!tmp)
1881 { 1849 {
1882 tmp = get_archetype (shstr_blindness); 1850 tmp = archetype::get (shstr_blindness);
1883 SET_FLAG (tmp, FLAG_BLIND); 1851 tmp->set_flag (FLAG_BLIND);
1884 SET_FLAG (tmp, FLAG_APPLIED); 1852 tmp->set_flag (FLAG_APPLIED);
1885 /* use floats so we don't lose too much precision due to rounding errors. 1853 // use floats so we don't lose too much precision due to rounding errors.
1886 * speed is a float anyways. 1854 tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED));
1887 */
1888 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100;
1889 1855
1890 tmp = insert_ob_in_ob (tmp, op); 1856 tmp = insert_ob_in_ob (tmp, op);
1891 change_abil (op, tmp); /* Mostly to display any messages */ 1857 change_abil (op, tmp); /* Mostly to display any messages */
1892 op->update_stats (); /* This takes care of some other stuff */ 1858 op->update_stats (); /* This takes care of some other stuff */
1893 1859
1894 if (hitter->owner)
1895 owner = hitter->owner;
1896 else
1897 owner = hitter;
1898
1899 new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op)); 1860 new_draw_info_format (NDI_UNIQUE, 0, hitter->outer_owner (), "Your attack blinds %s!", query_name (op));
1900 } 1861 }
1862
1901 tmp->stats.food += dam; 1863 tmp->stats.food += dam;
1902 if (tmp->stats.food > 10) 1864 min_it (tmp->stats.food, 10);
1903 tmp->stats.food = 10;
1904} 1865}
1905 1866
1906void 1867void
1907paralyze_player (object *op, object *hitter, int dam) 1868paralyze_player (object *op, object *hitter, int dam)
1908{ 1869{
1919 */ 1880 */
1920 1881
1921 /* Do this as a float - otherwise, rounding might very well reduce this to 0 */ 1882 /* Do this as a float - otherwise, rounding might very well reduce this to 0 */
1922 float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f; 1883 float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f;
1923 1884
1924 op->speed_left -= fabs (op->speed) * effect; 1885 op->speed_left -= op->speed * effect;
1925 /* tmp->stats.food+=(signed short) effect/op->speed; */ 1886 /* tmp->stats.food+=(signed short) effect/op->speed; */
1926 1887
1927 /* max number of ticks to be affected for. */ 1888 /* max number of ticks to be affected for. */
1928 float max = (100 - op->resist[ATNR_PARALYZE]) / 2; 1889 float max = (100 - op->resist[ATNR_PARALYZE]) / 2;
1929 1890
1930 if (op->speed_left < -(fabs (op->speed) * max)) 1891 max_it (op->speed_left, -op->speed * max);
1931 op->speed_left = -(fabs (op->speed) * max);
1932 1892
1933/* tmp->stats.food = (signed short) (max / fabs (op->speed)); */ 1893/* tmp->stats.food = (signed short) (max / op->speed); */
1934} 1894}
1935 1895
1936/* Attempts to kill 'op'. hitter is the attack object, dam is 1896/* Attempts to kill 'op'. hitter is the attack object, dam is
1937 * the computed damaged. 1897 * the computed damaged.
1938 */ 1898 */
1948 ** field of the deathstriking object */ 1908 ** field of the deathstriking object */
1949 1909
1950 int atk_lev, def_lev, kill_lev; 1910 int atk_lev, def_lev, kill_lev;
1951 1911
1952 if (hitter->slaying) 1912 if (hitter->slaying)
1953 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) 1913 if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead))
1954 || (op->race && hitter->slaying.contains (op->race)))) 1914 || (op->race && hitter->slaying.contains (op->race))))
1955 return; 1915 return;
1956 1916
1957 def_lev = op->level; 1917 def_lev = op->level;
1958 if (def_lev < 1) 1918 if (def_lev < 1)
2083 * Second, just getting hit doesn't mean it always affects 2043 * Second, just getting hit doesn't mean it always affects
2084 * you. Third, you still get a saving through against the 2044 * you. Third, you still get a saving through against the
2085 * effect. 2045 * effect.
2086 */ 2046 */
2087 if (op->has_active_speed () 2047 if (op->has_active_speed ()
2088 && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) 2048 && (op->flag [FLAG_MONSTER] || op->type == PLAYER)
2089 && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) 2049 && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1))
2090 && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) 2050 && !did_make_save (op, level_diff, op->resist[attacknum] / 10))
2091 { 2051 {
2092 2052
2093 /* Player has been hit by something */ 2053 /* Player has been hit by something */
2103 scare_creature (op, hitter); 2063 scare_creature (op, hitter);
2104 else if (attacknum == ATNR_CANCELLATION) 2064 else if (attacknum == ATNR_CANCELLATION)
2105 cancellation (op); 2065 cancellation (op);
2106 else if (attacknum == ATNR_DEPLETE) 2066 else if (attacknum == ATNR_DEPLETE)
2107 op->drain_stat (); 2067 op->drain_stat ();
2108 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) 2068 else if (attacknum == ATNR_BLIND && !op->flag [FLAG_UNDEAD] && !op->flag [FLAG_GENERATOR])
2109 blind_player (op, hitter, dam); 2069 blind_player (op, hitter, dam);
2110 } 2070 }
2111 2071
2112 dam = 0; /* These are all effects and don't do real damage */ 2072 dam = 0; /* These are all effects and don't do real damage */
2113 } 2073 }
2123 { 2083 {
2124 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2084 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2125 { 2085 {
2126 if (tmp->invisible) 2086 if (tmp->invisible)
2127 continue; 2087 continue;
2128 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 2088 if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10))
2129 /* >= 10% acid res. on items will protect these */ 2089 /* >= 10% acid res. on items will protect these */
2130 continue; 2090 continue;
2131 if (!(tmp->materials & M_IRON)) 2091 if (!(tmp->materials & M_IRON))
2132 continue; 2092 continue;
2133 if (tmp->magic < -4) /* Let's stop at -5 */ 2093 if (tmp->magic < -4) /* Let's stop at -5 */
2178 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 2138 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
2179 2139
2180 if (op->stats.exp <= rate) 2140 if (op->stats.exp <= rate)
2181 { 2141 {
2182 if (op->type == GOLEM) 2142 if (op->type == GOLEM)
2183 dam = 999; /* Its force is "sucked" away. 8) */ 2143 dam = 9998; /* Its force is "sucked" away. 8) */
2184 else 2144 else
2185 /* If we can't drain, lets try to do physical damage */ 2145 /* If we can't drain, lets try to do physical damage */
2186 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); 2146 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
2187 } 2147 }
2188 else 2148 else
2197 * exp, but the wiz would still lose exp! If drainee is a wiz, 2157 * exp, but the wiz would still lose exp! If drainee is a wiz,
2198 * nothing happens. 2158 * nothing happens.
2199 * Try to credit the owner. We try to display player -> player drain 2159 * Try to credit the owner. We try to display player -> player drain
2200 * attacks, hence all the != PLAYER checks. 2160 * attacks, hence all the != PLAYER checks.
2201 */ 2161 */
2202 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) 2162 if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ])
2203 { 2163 {
2204 object *owner = hitter->owner; 2164 object *owner = hitter->owner;
2205 2165
2206 if (owner && owner != hitter) 2166 if (owner && owner != hitter)
2207 { 2167 {
2208 if (op->type != PLAYER || owner->type != PLAYER) 2168 if (op->type != PLAYER || owner->type != PLAYER)
2209 change_exp (owner, op->stats.exp / (rate * 2), 2169 change_exp (owner, op->stats.exp / (rate * 2),
2210 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); 2170 hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), SK_EXP_TOTAL);
2211 } 2171 }
2212 else if (op->type != PLAYER || hitter->type != PLAYER) 2172 else if (op->type != PLAYER || hitter->type != PLAYER)
2213 change_exp (hitter, op->stats.exp / (rate * 2), 2173 change_exp (hitter, op->stats.exp / (rate * 2),
2214 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 2174 hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0);
2215 2175
2216 change_exp (op, -op->stats.exp / rate, NULL, 0); 2176 change_exp (op, -op->stats.exp / rate, shstr (), 0);
2217 } 2177 }
2218 2178
2219 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure 2179 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
2220 * drain attack, you won't know that you are actually sucking out EXP, 2180 * drain attack, you won't know that you are actually sucking out EXP,
2221 * as the messages will say you missed 2181 * as the messages will say you missed
2224 } 2184 }
2225 break; 2185 break;
2226 2186
2227 case ATNR_TURN_UNDEAD: 2187 case ATNR_TURN_UNDEAD:
2228 { 2188 {
2229 if (QUERY_FLAG (op, FLAG_UNDEAD)) 2189 if (op->flag [FLAG_UNDEAD])
2230 { 2190 {
2231 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 2191 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
2232 object *god = find_god (determine_god (owner)); 2192 object *god = find_god (determine_god (owner));
2233 int div = 1; 2193 int div = 1;
2234 2194
2289 * damage it does do to the player. Given that, 2249 * damage it does do to the player. Given that,
2290 * it only does 1/10'th normal damage (hence the divide by 2250 * it only does 1/10'th normal damage (hence the divide by
2291 * 1000). 2251 * 1000).
2292 */ 2252 */
2293 /* You can't steal life from something undead */ 2253 /* You can't steal life from something undead */
2294 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) 2254 if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD]))
2295 return 0; 2255 return 0;
2296 2256
2297 /* If drain protection is higher than life stealing, use that */ 2257 /* If drain protection is higher than life stealing, use that */
2298 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 2258 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
2299 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; 2259 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines