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.137 by root, Sun Apr 11 01:35:51 2010 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 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);
947 */ 927 */
948 if (!type) 928 if (!type)
949 type = AT_PHYSICAL; 929 type = AT_PHYSICAL;
950 930
951 /* Handle monsters that hit back */ 931 /* Handle monsters that hit back */
952 if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) 932 if (!simple_attack && op->flag [FLAG_HITBACK] && hitter->flag [FLAG_ALIVE])
953 { 933 {
954 if (op->attacktype & AT_ACID && hitter->type == PLAYER) 934 if (op->attacktype & AT_ACID && hitter->type == PLAYER)
955 new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); 935 new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n");
956 936
957 hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); 937 hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1);
1201 * this creature. The function(s) that call us have already 1181 * this creature. The function(s) that call us have already
1202 * adjusted the creatures HP total, so that is negative. 1182 * adjusted the creatures HP total, so that is negative.
1203 */ 1183 */
1204 maxdam = dam + op->stats.hp + 1; 1184 maxdam = dam + op->stats.hp + 1;
1205 1185
1206 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) 1186 if (op->flag [FLAG_BLOCKSVIEW])
1207 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ 1187 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */
1208 1188
1209 if (op->type == DOOR) 1189 if (op->type == DOOR)
1210 { 1190 {
1211 op->set_speed (0.1f); 1191 op->set_speed (0.1f);
1212 op->speed_left = -0.05f; 1192 op->speed_left = -0.05f;
1213 return maxdam; 1193 return maxdam;
1214 } 1194 }
1215 1195
1216 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1196 if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER)
1217 { 1197 {
1218 op->drop_and_destroy (); 1198 op->drop_and_destroy ();
1219 return maxdam; 1199 return maxdam;
1220 } 1200 }
1221 1201
1288 else if (owner->chosen_skill) 1268 else if (owner->chosen_skill)
1289 { 1269 {
1290 skop = owner->chosen_skill; 1270 skop = owner->chosen_skill;
1291 skill = skop->skill; 1271 skill = skop->skill;
1292 } 1272 }
1293 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) 1273 else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon)
1294 skill = owner->current_weapon->skill; 1274 skill = owner->current_weapon->skill;
1295 else 1275 else
1296 { 1276 {
1277 LOG (llevError | logBacktrace,
1297 LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" 1278 "BUG: kill_object - unable to find skill that killed monster\n"
1298 "op: %s\n" "hitter: %s\n" "owner: %s\n", 1279 "op: %s\n" "hitter: %s\n" "owner: %s\n",
1299 owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); 1280 owner->debug_desc (), hitter->debug_desc (), op->debug_desc ());
1300 skill = 0; 1281 skill = 0;
1301 } 1282 }
1302 1283
1303 /* We have the skill we want to credit to - now find the object this goes 1284 /* 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! 1285 * to. Make sure skop is an actual skill, and not a skill tool!
1314 1295
1315 if (!skill && skop) 1296 if (!skill && skop)
1316 skill = skop->skill; 1297 skill = skop->skill;
1317 1298
1318 /* If you didn't kill yourself, and your not the wizard */ 1299 /* If you didn't kill yourself, and your not the wizard */
1319 if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) 1300 if (owner != op && !op->flag [FLAG_WIZ])
1320 { 1301 {
1321 int exp; 1302 int exp;
1322 1303
1323 /* Really don't give much experience for killing other players */ 1304 /* Really don't give much experience for killing other players */
1324 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously 1305 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously
1381 } /* else part of a party */ 1362 } /* else part of a party */
1382 } /* end if person didn't kill himself */ 1363 } /* end if person didn't kill himself */
1383 1364
1384 if (op->type != PLAYER) 1365 if (op->type != PLAYER)
1385 { 1366 {
1386 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 1367 if (op->flag [FLAG_FRIENDLY])
1387 { 1368 {
1388 object *owner1 = op->owner; 1369 object *owner1 = op->owner;
1389 1370
1390 if (owner1 && owner1->type == PLAYER) 1371 if (owner1 && owner1->type == PLAYER)
1391 { 1372 {
1452 * modify it. 1433 * modify it.
1453 */ 1434 */
1454/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1435/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1455 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1436 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1456int 1437int
1457hit_player (object *op, int dam, object *hitter, int type, int full_hit) 1438hit_player (object *op, int dam, object *hitter, uint32_t type, int full_hit)
1458{ 1439{
1459 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); 1440 int magic = type & AT_MAGIC;
1460 int maxattacktype, attacknum;
1461 int body_attack = op && op->head; /* Did we hit op's head? */ 1441 int body_attack = op && op->head; /* Did we hit op's head? */
1442 int maxdam = 0, ndam = 0, attacktype = 1;
1443 int maxattacktype;
1462 int simple_attack; 1444 int simple_attack;
1463 int rtn_kill = 0; 1445 int rtn_kill = 0;
1464 int friendlyfire; 1446 int friendlyfire;
1465 1447
1466 if (get_attack_mode (&op, &hitter, &simple_attack)) 1448 if (get_attack_mode (&op, &hitter, &simple_attack))
1467 return 0; 1449 return 0;
1468 1450
1469 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ 1451 /* 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)) 1452 if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE])
1471 return 0; 1453 return 0;
1472 1454
1473 // only allow pk for hostile players 1455 // only allow pk for hostile players
1474 if (op->type == PLAYER) 1456 if (op->type == PLAYER)
1475 { 1457 {
1517 1499
1518 break; 1500 break;
1519 } 1501 }
1520 } 1502 }
1521 1503
1522 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1504 if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0)
1523 { 1505 {
1524 /* FIXME: If a player is killed by a rune in a door, the 1506 /* FIXME: If a player is killed by a rune in a door, the
1525 * destroyed() check above doesn't return, and might get here. 1507 * destroyed() check above doesn't return, and might get here.
1526 */ 1508 */
1527 1509
1568 object *god; 1550 object *god;
1569 1551
1570 if ((!hitter->slaying 1552 if ((!hitter->slaying
1571 || (!(op->race && hitter->slaying.contains (op->race)) 1553 || (!(op->race && hitter->slaying.contains (op->race))
1572 && !(op->name && hitter->slaying.contains (op->name)))) 1554 && !(op->name && hitter->slaying.contains (op->name))))
1573 && (!QUERY_FLAG (op, FLAG_UNDEAD) 1555 && (!op->flag [FLAG_UNDEAD]
1574 || (hitter->title 1556 || (hitter->title
1575 && (god = find_god (determine_god (hitter))) != NULL 1557 && (god = find_god (determine_god (hitter))) != NULL
1576 && god->race.contains (shstr_undead)))) 1558 && god->race.contains (shstr_undead))))
1577 return 0; 1559 return 0;
1578 } 1560 }
1579 1561
1580 maxattacktype = type; /* initialise this to something */ 1562 maxattacktype = type; /* initialise this to something */
1581 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1563 for_all_bits_sparse_32 (type, attacknum)
1582 { 1564 {
1565 uint32_t attacktype = 1 << attacknum;
1566
1583 /* Magic isn't really a true attack type - it gets combined with other 1567 /* 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 1568 * attack types. As such, skip it over. However, if magic is
1585 * the only attacktype in the group, then still attack with it 1569 * the only attacktype in the group, then still attack with it
1586 */ 1570 */
1587 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC)) 1571 if ((attacktype == AT_MAGIC) && (type & ~AT_MAGIC))
1590 /* Go through and hit the player with each attacktype, one by one. 1574 /* Go through and hit the player with each attacktype, one by one.
1591 * hit_player_attacktype only figures out the damage, doesn't inflict 1575 * hit_player_attacktype only figures out the damage, doesn't inflict
1592 * it. It will do the appropriate action for attacktypes with 1576 * it. It will do the appropriate action for attacktypes with
1593 * effects (slow, paralization, etc. 1577 * effects (slow, paralization, etc.
1594 */ 1578 */
1595 if (type & attacktype)
1596 {
1597 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic); 1579 ndam = hit_player_attacktype (op, hitter, dam, attacknum, magic);
1580
1598 /* the >= causes us to prefer messages from special attacks, if 1581 /* the >= causes us to prefer messages from special attacks, if
1599 * the damage is equal. 1582 * the damage is equal.
1600 */ 1583 */
1601 if (ndam >= maxdam) 1584 if (ndam >= maxdam)
1602 { 1585 {
1603 maxdam = ndam; 1586 maxdam = ndam;
1604 maxattacktype = 1 << attacknum; 1587 maxattacktype = 1 << attacknum;
1605 }
1606 } 1588 }
1607 } 1589 }
1608 1590
1609 /* if this is friendly fire then do a set % of damage only 1591 /* 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 1592 * 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 1632 // keep a refcount for a long time and I see no usefulness
1651 // for an non-active objetc to know its enemy. 1633 // for an non-active objetc to know its enemy.
1652 if (op->active) 1634 if (op->active)
1653 if (hitter->owner) 1635 if (hitter->owner)
1654 op->enemy = hitter->owner; 1636 op->enemy = hitter->owner;
1655 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1637 else if (hitter->flag [FLAG_ALIVE])
1656 op->enemy = hitter; 1638 op->enemy = hitter;
1657 1639
1658 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1640 if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER)
1659 { 1641 {
1660 /* The unaggressives look after themselves 8) */ 1642 /* The unaggressives look after themselves 8) */
1661 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 1643 op->clr_flag (FLAG_UNAGGRESSIVE);
1662 npc_call_help (op); 1644 npc_call_help (op);
1663 } 1645 }
1664 1646
1665 if (magic && did_make_save (op, op->level, 0)) 1647 if (magic && did_make_save (op, op->level, 0))
1666 maxdam = maxdam / 2; 1648 maxdam = maxdam / 2;
1668 attack_message (maxdam, maxattacktype, op, hitter); 1650 attack_message (maxdam, maxattacktype, op, hitter);
1669 1651
1670 op->stats.hp -= maxdam; 1652 op->stats.hp -= maxdam;
1671 1653
1672 /* Eneq(@csd.uu.se): Check to see if monster runs away. */ 1654 /* Eneq(@csd.uu.se): Check to see if monster runs away. */
1673 if ((op->stats.hp >= 0) && 1655 if (op->stats.hp >= 0
1674 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && 1656 && (op->flag [FLAG_MONSTER] || op->type == PLAYER)
1675 op->stats.hp < (signed short) (((float) op->run_away / (float) 100) * (float) op->stats.maxhp)) 1657 && op->stats.hp * 100 < op->stats.maxhp * op->run_away)
1676 { 1658 {
1677 1659
1678 if (QUERY_FLAG (op, FLAG_MONSTER)) 1660 if (op->flag [FLAG_MONSTER])
1679 SET_FLAG (op, FLAG_RUN_AWAY); 1661 op->set_flag (FLAG_RUN_AWAY);
1680 else 1662 else
1681 scare_creature (op, hitter); 1663 scare_creature (op, hitter);
1682 } 1664 }
1683 1665
1684 if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) 1666 if (op->flag [FLAG_TEAR_DOWN])
1685 { 1667 {
1686 if (maxdam) 1668 if (maxdam)
1687 tear_down_wall (op); 1669 tear_down_wall (op);
1688 1670
1689 return maxdam; /* nothing more to do for wall */ 1671 return maxdam; /* nothing more to do for wall */
1696 1678
1697 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1679 /* 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 1680 * that before if the player was immune to ghosthit, the monster
1699 * remained - that is no longer the case. 1681 * remained - that is no longer the case.
1700 */ 1682 */
1701 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1683 if (hitter->flag [FLAG_ONE_HIT])
1702 hitter->drop_and_destroy (); 1684 hitter->drop_and_destroy ();
1703 /* Lets handle creatures that are splitting now */ 1685 /* Lets handle creatures that are splitting now */
1704 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1686 else if (type & AT_PHYSICAL && !op->flag [FLAG_FREED] && op->flag [FLAG_SPLITTING])
1705 { 1687 {
1706 int i;
1707 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1688 int friendly = op->flag [FLAG_FRIENDLY];
1708 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); 1689 int unaggressive = op->flag [FLAG_UNAGGRESSIVE];
1709 object *owner = op->owner; 1690 object *owner = op->owner;
1710 1691
1711 if (!op->other_arch) 1692 if (!op->other_arch)
1712 { 1693 {
1713 LOG (llevError, "SPLITTING without other_arch error.\n"); 1694 LOG (llevError, "SPLITTING without other_arch error.\n");
1714 return maxdam; 1695 return maxdam;
1715 } 1696 }
1716 1697
1717 op->remove (); 1698 op->remove ();
1718 1699
1719 for (i = 0; i < op->stats.food; i++) 1700 for (int i = 0; i < op->stats.food; i++)
1720 { /* This doesn't handle op->more yet */ 1701 { /* This doesn't handle op->more yet */
1721 object *tmp = arch_to_object (op->other_arch); 1702 object *tmp = op->other_arch->instance ();
1722 int j;
1723 1703
1724 tmp->stats.hp = op->stats.hp; 1704 tmp->stats.hp = op->stats.hp;
1725 1705
1726 if (friendly) 1706 if (friendly)
1727 { 1707 {
1731 if (owner) 1711 if (owner)
1732 tmp->set_owner (owner); 1712 tmp->set_owner (owner);
1733 } 1713 }
1734 1714
1735 if (unaggressive) 1715 if (unaggressive)
1736 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 1716 tmp->set_flag (FLAG_UNAGGRESSIVE);
1737 1717
1738 j = find_first_free_spot (tmp, op->map, op->x, op->y); 1718 int j = find_first_free_spot (tmp, op->map, op->x, op->y);
1739 1719
1740 if (j == -1) /* No spot to put this monster */ 1720 if (j == -1) /* No spot to put this monster */
1741 tmp->destroy (); 1721 tmp->destroy ();
1742 else 1722 else
1743 { 1723 {
1758poison_player (object *op, object *hitter, int dam) 1738poison_player (object *op, object *hitter, int dam)
1759{ 1739{
1760 archetype *at = archetype::find (shstr_poisoning); 1740 archetype *at = archetype::find (shstr_poisoning);
1761 object *tmp = present_arch_in_ob (at, op); 1741 object *tmp = present_arch_in_ob (at, op);
1762 1742
1763 if (tmp == NULL) 1743 if (!tmp)
1764 { 1744 {
1765 if ((tmp = arch_to_object (at)) == NULL) 1745 tmp = insert_ob_in_ob (at->instance (), op);
1766 LOG (llevError, "Failed to clone arch poisoning.\n"); 1746 /* peterm: give poisoning some teeth. It should
1747 * be able to kill things better than it does:
1748 * damage should be dependent something--I choose to
1749 * do this: if it's a monster, the damage from the
1750 * poisoning goes as the level of the monster/2.
1751 * If anything else, goes as damage.
1752 */
1753
1754 if (hitter->flag [FLAG_ALIVE])
1755 tmp->stats.dam += hitter->level / 2;
1767 else 1756 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; 1757 tmp->stats.dam = dam;
1782 1758
1783 tmp->set_owner (hitter); /* so we get credit for poisoning kills */ 1759 tmp->set_owner (hitter); /* so we get credit for poisoning kills */
1784 if (hitter->skill && hitter->skill != tmp->skill) 1760 if (hitter->skill && hitter->skill != tmp->skill)
1785 {
1786 tmp->skill = hitter->skill; 1761 tmp->skill = hitter->skill;
1787 }
1788 1762
1789 tmp->stats.food += dam; /* more damage, longer poisoning */ 1763 tmp->stats.food += dam; /* more damage, longer poisoning */
1790 1764
1791 if (op->type == PLAYER) 1765 if (op->type == PLAYER)
1792 { 1766 {
1793 /* player looses stats, maximum is -10 of each */ 1767 /* player looses stats, maximum is -10 of each */
1794 tmp->stats.Con = max (-(dam / 4 + 1), -10); 1768 tmp->stats.Con = max (-(dam / 4 + 1), -10);
1795 tmp->stats.Str = max (-(dam / 3 + 2), -10); 1769 tmp->stats.Str = max (-(dam / 3 + 2), -10);
1796 tmp->stats.Dex = max (-(dam / 6 + 1), -10); 1770 tmp->stats.Dex = max (-(dam / 6 + 1), -10);
1797 tmp->stats.Int = max (-(dam / 7 ), -10); 1771 tmp->stats.Int = max (-(dam / 7 ), -10);
1798 SET_FLAG (tmp, FLAG_APPLIED); 1772 tmp->set_flag (FLAG_APPLIED);
1799 op->update_stats (); 1773 op->update_stats ();
1800 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); 1774 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
1801 op->play_sound (tmp->sound); 1775 op->play_sound (tmp->sound);
1802 } 1776 }
1803 1777
1804 if (hitter->type == PLAYER) 1778 if (hitter->type == PLAYER)
1805 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); 1779 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
1806 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 1780 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); 1781 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name);
1808 }
1809 1782
1810 tmp->speed_left = 0; 1783 tmp->speed_left = 0;
1811 } 1784 }
1812 else 1785 else
1813 tmp->stats.food++; 1786 tmp->stats.food++;
1817slow_player (object *op, object *hitter, int dam) 1790slow_player (object *op, object *hitter, int dam)
1818{ 1791{
1819 archetype *at = archetype::find (shstr_slowness); 1792 archetype *at = archetype::find (shstr_slowness);
1820 object *tmp; 1793 object *tmp;
1821 1794
1822 if (at == NULL) 1795 if (!at)
1823 LOG (llevError, "Can't find slowness archetype.\n"); 1796 LOG (llevError, "Can't find slowness archetype.\n");
1824 1797
1825 if ((tmp = present_arch_in_ob (at, op)) == NULL) 1798 if ((tmp = present_arch_in_ob (at, op)) == NULL)
1826 { 1799 {
1827 tmp = arch_to_object (at); 1800 tmp = at->instance ();
1828 tmp = insert_ob_in_ob (tmp, op); 1801 tmp = insert_ob_in_ob (tmp, op);
1829 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); 1802 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!");
1830 } 1803 }
1831 else 1804 else
1832 tmp->stats.food++; 1805 tmp->stats.food++;
1833 1806
1834 SET_FLAG (tmp, FLAG_APPLIED); 1807 tmp->set_flag (FLAG_APPLIED);
1835 tmp->speed_left = 0; 1808 tmp->speed_left = 0;
1836 op->update_stats (); 1809 op->update_stats ();
1837} 1810}
1838 1811
1839void 1812void
1859 maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); 1832 maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
1860 1833
1861 if (tmp->duration > maxduration) 1834 if (tmp->duration > maxduration)
1862 tmp->duration = maxduration; 1835 tmp->duration = maxduration;
1863 1836
1864 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) 1837 if (op->type == PLAYER && !op->flag [FLAG_CONFUSED])
1865 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); 1838 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!");
1866 1839
1867 SET_FLAG (op, FLAG_CONFUSED); 1840 op->set_flag (FLAG_CONFUSED);
1868} 1841}
1869 1842
1870void 1843void
1871blind_player (object *op, object *hitter, int dam) 1844blind_player (object *op, object *hitter, int dam)
1872{ 1845{
1878 1851
1879 tmp = present_in_ob (BLINDNESS, op); 1852 tmp = present_in_ob (BLINDNESS, op);
1880 if (!tmp) 1853 if (!tmp)
1881 { 1854 {
1882 tmp = get_archetype (shstr_blindness); 1855 tmp = get_archetype (shstr_blindness);
1883 SET_FLAG (tmp, FLAG_BLIND); 1856 tmp->set_flag (FLAG_BLIND);
1884 SET_FLAG (tmp, FLAG_APPLIED); 1857 tmp->set_flag (FLAG_APPLIED);
1885 /* use floats so we don't lose too much precision due to rounding errors. 1858 /* use floats so we don't lose too much precision due to rounding errors.
1886 * speed is a float anyways. 1859 * speed is a float anyways.
1887 */ 1860 */
1888 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; 1861 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100;
1889 1862
1919 */ 1892 */
1920 1893
1921 /* Do this as a float - otherwise, rounding might very well reduce this to 0 */ 1894 /* 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; 1895 float effect = dam * 3.f * (100.f - op->resist[ATNR_PARALYZE]) / 100.f;
1923 1896
1924 op->speed_left -= fabs (op->speed) * effect; 1897 op->speed_left -= op->speed * effect;
1925 /* tmp->stats.food+=(signed short) effect/op->speed; */ 1898 /* tmp->stats.food+=(signed short) effect/op->speed; */
1926 1899
1927 /* max number of ticks to be affected for. */ 1900 /* max number of ticks to be affected for. */
1928 float max = (100 - op->resist[ATNR_PARALYZE]) / 2; 1901 float max = (100 - op->resist[ATNR_PARALYZE]) / 2;
1929 1902
1930 if (op->speed_left < -(fabs (op->speed) * max)) 1903 max_it (op->speed_left, -op->speed * max);
1931 op->speed_left = -(fabs (op->speed) * max);
1932 1904
1933/* tmp->stats.food = (signed short) (max / fabs (op->speed)); */ 1905/* tmp->stats.food = (signed short) (max / op->speed); */
1934} 1906}
1935 1907
1936/* Attempts to kill 'op'. hitter is the attack object, dam is 1908/* Attempts to kill 'op'. hitter is the attack object, dam is
1937 * the computed damaged. 1909 * the computed damaged.
1938 */ 1910 */
1948 ** field of the deathstriking object */ 1920 ** field of the deathstriking object */
1949 1921
1950 int atk_lev, def_lev, kill_lev; 1922 int atk_lev, def_lev, kill_lev;
1951 1923
1952 if (hitter->slaying) 1924 if (hitter->slaying)
1953 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) 1925 if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead))
1954 || (op->race && hitter->slaying.contains (op->race)))) 1926 || (op->race && hitter->slaying.contains (op->race))))
1955 return; 1927 return;
1956 1928
1957 def_lev = op->level; 1929 def_lev = op->level;
1958 if (def_lev < 1) 1930 if (def_lev < 1)
2083 * Second, just getting hit doesn't mean it always affects 2055 * Second, just getting hit doesn't mean it always affects
2084 * you. Third, you still get a saving through against the 2056 * you. Third, you still get a saving through against the
2085 * effect. 2057 * effect.
2086 */ 2058 */
2087 if (op->has_active_speed () 2059 if (op->has_active_speed ()
2088 && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) 2060 && (op->flag [FLAG_MONSTER] || op->type == PLAYER)
2089 && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) 2061 && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1))
2090 && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) 2062 && !did_make_save (op, level_diff, op->resist[attacknum] / 10))
2091 { 2063 {
2092 2064
2093 /* Player has been hit by something */ 2065 /* Player has been hit by something */
2103 scare_creature (op, hitter); 2075 scare_creature (op, hitter);
2104 else if (attacknum == ATNR_CANCELLATION) 2076 else if (attacknum == ATNR_CANCELLATION)
2105 cancellation (op); 2077 cancellation (op);
2106 else if (attacknum == ATNR_DEPLETE) 2078 else if (attacknum == ATNR_DEPLETE)
2107 op->drain_stat (); 2079 op->drain_stat ();
2108 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) 2080 else if (attacknum == ATNR_BLIND && !op->flag [FLAG_UNDEAD] && !op->flag [FLAG_GENERATOR])
2109 blind_player (op, hitter, dam); 2081 blind_player (op, hitter, dam);
2110 } 2082 }
2111 2083
2112 dam = 0; /* These are all effects and don't do real damage */ 2084 dam = 0; /* These are all effects and don't do real damage */
2113 } 2085 }
2123 { 2095 {
2124 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2096 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2125 { 2097 {
2126 if (tmp->invisible) 2098 if (tmp->invisible)
2127 continue; 2099 continue;
2128 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 2100 if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10))
2129 /* >= 10% acid res. on items will protect these */ 2101 /* >= 10% acid res. on items will protect these */
2130 continue; 2102 continue;
2131 if (!(tmp->materials & M_IRON)) 2103 if (!(tmp->materials & M_IRON))
2132 continue; 2104 continue;
2133 if (tmp->magic < -4) /* Let's stop at -5 */ 2105 if (tmp->magic < -4) /* Let's stop at -5 */
2178 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 2150 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
2179 2151
2180 if (op->stats.exp <= rate) 2152 if (op->stats.exp <= rate)
2181 { 2153 {
2182 if (op->type == GOLEM) 2154 if (op->type == GOLEM)
2183 dam = 999; /* Its force is "sucked" away. 8) */ 2155 dam = 9998; /* Its force is "sucked" away. 8) */
2184 else 2156 else
2185 /* If we can't drain, lets try to do physical damage */ 2157 /* If we can't drain, lets try to do physical damage */
2186 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); 2158 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
2187 } 2159 }
2188 else 2160 else
2197 * exp, but the wiz would still lose exp! If drainee is a wiz, 2169 * exp, but the wiz would still lose exp! If drainee is a wiz,
2198 * nothing happens. 2170 * nothing happens.
2199 * Try to credit the owner. We try to display player -> player drain 2171 * Try to credit the owner. We try to display player -> player drain
2200 * attacks, hence all the != PLAYER checks. 2172 * attacks, hence all the != PLAYER checks.
2201 */ 2173 */
2202 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) 2174 if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ])
2203 { 2175 {
2204 object *owner = hitter->owner; 2176 object *owner = hitter->owner;
2205 2177
2206 if (owner && owner != hitter) 2178 if (owner && owner != hitter)
2207 { 2179 {
2224 } 2196 }
2225 break; 2197 break;
2226 2198
2227 case ATNR_TURN_UNDEAD: 2199 case ATNR_TURN_UNDEAD:
2228 { 2200 {
2229 if (QUERY_FLAG (op, FLAG_UNDEAD)) 2201 if (op->flag [FLAG_UNDEAD])
2230 { 2202 {
2231 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 2203 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
2232 object *god = find_god (determine_god (owner)); 2204 object *god = find_god (determine_god (owner));
2233 int div = 1; 2205 int div = 1;
2234 2206
2289 * damage it does do to the player. Given that, 2261 * damage it does do to the player. Given that,
2290 * it only does 1/10'th normal damage (hence the divide by 2262 * it only does 1/10'th normal damage (hence the divide by
2291 * 1000). 2263 * 1000).
2292 */ 2264 */
2293 /* You can't steal life from something undead */ 2265 /* You can't steal life from something undead */
2294 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) 2266 if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD]))
2295 return 0; 2267 return 0;
2296 2268
2297 /* If drain protection is higher than life stealing, use that */ 2269 /* If drain protection is higher than life stealing, use that */
2298 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 2270 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
2299 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; 2271 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines