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.41 by root, Mon Jan 15 00:40:49 2007 UTC vs.
Revision 1.101 by root, Fri Dec 26 13:33:22 2008 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 *
21 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 The authors can be reached via e-mail to <crossfire@schmorp.de>
23*/ 22 */
23
24#include <assert.h> 24#include <assert.h>
25#include <global.h> 25#include <global.h>
26#include <living.h> 26#include <living.h>
27#include <material.h> 27#include <material.h>
28#include <skills.h> 28#include <skills.h>
29
30#ifndef __CEXTRACT__
31# include <sproto.h>
32#endif
33
34#include <sounds.h> 29#include <sounds.h>
30#include <sproto.h>
35 31
36typedef struct att_msg_str 32typedef struct att_msg_str
37{ 33{
38 char *msg1; 34 char *msg1;
39 char *msg2; 35 char *msg2;
45 * its magical benefits. 41 * its magical benefits.
46 */ 42 */
47void 43void
48cancellation (object *op) 44cancellation (object *op)
49{ 45{
50 object *tmp;
51
52 if (op->invisible) 46 if (op->invisible)
53 return; 47 return;
54 48
55 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) 49 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ)
56 { 50 {
57 /* Recur through the inventory */ 51 /* Recurse through the inventory */
58 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 52 for (object *tmp = op->inv; tmp; tmp = tmp->below)
59 if (!did_make_save_item (tmp, AT_CANCELLATION, op)) 53 if (!did_make_save_item (tmp, AT_CANCELLATION, op))
60 cancellation (tmp); 54 cancellation (tmp);
61 } 55 }
62 else if (FABS (op->magic) <= (rndm (0, 5))) 56 else if (FABS (op->magic) <= rndm (0, 5))
63 { 57 {
64 /* Nullify this object. This code could probably be more complete */ 58 /* Nullify this object. This code could probably be more complete */
65 /* in what abilities it should cancel */ 59 /* in what abilities it should cancel */
66 op->magic = 0; 60 op->magic = 0;
61
67 CLEAR_FLAG (op, FLAG_DAMNED); 62 CLEAR_FLAG (op, FLAG_DAMNED);
68 CLEAR_FLAG (op, FLAG_CURSED); 63 CLEAR_FLAG (op, FLAG_CURSED);
69 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 64 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
70 CLEAR_FLAG (op, FLAG_KNOWN_CURSED); 65 CLEAR_FLAG (op, FLAG_KNOWN_CURSED);
71 if (op->env && op->env->type == PLAYER) 66
72 { 67 if (object *pl = op->visible_to ())
73 esrv_send_item (op->env, op); 68 esrv_update_item (UPD_FLAGS, pl, op);
74 }
75 } 69 }
76} 70}
77 71
78/* did_make_save_item just checks to make sure the item actually 72/* did_make_save_item just checks to make sure the item actually
79 * made its saving throw based on the tables. It does not take 73 * made its saving throw based on the tables. It does not take
83did_make_save_item (object *op, int type, object *originator) 77did_make_save_item (object *op, int type, object *originator)
84{ 78{
85 int i, roll, saves = 0, attacks = 0, number; 79 int i, roll, saves = 0, attacks = 0, number;
86 materialtype_t *mt; 80 materialtype_t *mt;
87 81
88 if (op->materialname == NULL) 82 if (!op->materialname)
89 { 83 {
90 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next) 84 for (mt = materialt; mt && mt->next; mt = mt->next)
91 if (op->material & mt->material) 85 if (op->materials & mt->material)
92 break; 86 break;
93 } 87 }
94 else 88 else
95 mt = name_to_material (op->materialname); 89 mt = name_to_material (op->materialname);
96 90
97 if (mt == NULL) 91 if (!mt)
98 return TRUE; 92 return TRUE;
99 93
100 roll = rndm (1, 20); 94 roll = rndm (1, 20);
101 95
102 /* the attacktypes have no meaning for object saves 96 /* the attacktypes have no meaning for object saves
110 if (type != AT_MAGIC) 104 if (type != AT_MAGIC)
111 type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW | 105 type &= ~(AT_CONFUSION | AT_DRAIN | AT_GHOSTHIT | AT_POISON | AT_SLOW |
112 AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH | 106 AT_PARALYZE | AT_TURN_UNDEAD | AT_FEAR | AT_DEPLETE | AT_DEATH |
113 AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC); 107 AT_COUNTERSPELL | AT_HOLYWORD | AT_BLIND | AT_LIFE_STEALING | AT_MAGIC);
114 108
115 if (type == 0) 109 if (type == 0) return TRUE;
116 return TRUE; 110
117 if (roll == 20) 111 if (roll == 20) return TRUE;
118 return TRUE; 112 if (roll == 1) return FALSE;
119 if (roll == 1)
120 return FALSE;
121 113
122 for (number = 0; number < NROFATTACKS; number++) 114 for (number = 0; number < NROFATTACKS; number++)
123 { 115 {
124 i = 1 << number; 116 i = 1 << number;
117
125 if (!(i & type)) 118 if (!(i & type))
126 continue; 119 continue;
120
127 attacks++; 121 attacks++;
128 if (op->resist[number] == 100) 122 if (op->resist[number] == 100)
129 saves++; 123 saves++;
130 else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100) 124 else if (roll >= mt->save[number] - op->magic - op->resist[number] / 100)
131 saves++; 125 saves++;
133 saves++; 127 saves++;
134 } 128 }
135 129
136 if (saves == attacks || attacks == 0) 130 if (saves == attacks || attacks == 0)
137 return TRUE; 131 return TRUE;
132
138 if ((saves == 0) || (rndm (1, attacks) > saves)) 133 if (saves == 0 || (rndm (1, attacks) > saves))
139 return FALSE; 134 return FALSE;
135
140 return TRUE; 136 return TRUE;
141} 137}
142 138
143/* This function calls did_make_save_item. It then performs the 139/* This function calls did_make_save_item. It then performs the
144 * appropriate actions to the item (such as burning the item up, 140 * appropriate actions to the item (such as burning the item up,
145 * calling cancellation, etc.) 141 * calling cancellation, etc.)
146 */ 142 */
147
148void 143void
149save_throw_object (object *op, int type, object *originator) 144save_throw_object (object *op, int type, object *originator)
150{ 145{
151 if (!did_make_save_item (op, type, originator)) 146 if (!did_make_save_item (op, type, originator))
152 { 147 {
153 object *env = op->env; 148 object *env = op->env;
154 int x = op->x, y = op->y; 149 int x = op->x, y = op->y;
155 maptile *m = op->map; 150 maptile *m = op->map;
156 151
157 op = stop_item (op); 152 op = stop_item (op);
158 if (op == NULL) 153 if (!op)
159 return; 154 return;
160 155
161 /* Hacked the following so that type LIGHTER will work. 156 /* Hacked the following so that type LIGHTER will work.
162 * Also, objects which are potenital "lights" that are hit by 157 * Also, objects which are potential "lights" that are hit by
163 * flame/elect attacks will be set to glow. "lights" are any 158 * flame/elect attacks will be set to glow. "lights" are any
164 * object with +/- glow_radius and an "other_arch" to change to. 159 * object with +/- glow_radius and an "other_arch" to change to.
165 * (and please note that we cant fail our save and reach this 160 * (and please note that we cant fail our save and reach this
166 * function if the object doesnt contain a material that can burn. 161 * function if the object doesnt contain a material that can burn.
167 * So forget lighting magical swords on fire with this!) -b.t. 162 * So forget lighting magical swords on fire with this!) -b.t.
168 */ 163 */
169 if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE)) 164 if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE))
170 { 165 {
171 const char *arch = op->other_arch->name; 166 const char *arch = op->other_arch->archname;
172 167
173 op = decrease_ob_nr (op, 1); 168 if (op->decrease ())
174
175 if (op)
176 fix_stopped_item (op, m, originator); 169 fix_stopped_item (op, m, originator);
177 170
178 if ((op = get_archetype (arch)) != NULL) 171 if ((op = archetype::get (arch)))
179 { 172 {
180 if (env) 173 if (env)
181 { 174 env->insert (op);
182 op->x = env->x, op->y = env->y;
183 insert_ob_in_ob (op, env);
184 if (env->contr)
185 esrv_send_item (env, op);
186 }
187 else 175 else
188 {
189 op->x = x, op->y = y;
190 insert_ob_in_map (op, m, originator, 0); 176 m->insert (op, x, y, originator);
191 }
192 } 177 }
193 178
194 return; 179 return;
195 } 180 }
196 181
201 return; 186 return;
202 } 187 }
203 188
204 if (op->nrof > 1) 189 if (op->nrof > 1)
205 { 190 {
206 op = decrease_ob_nr (op, rndm (0, op->nrof - 1)); 191 if (op->decrease (rndm (0, op->nrof - 1)))
207
208 if (op)
209 fix_stopped_item (op, m, originator); 192 fix_stopped_item (op, m, originator);
210 } 193 }
211 else 194 else
212 { 195 {
213 if (op->env) 196 // drop everything to the ground, if possible
214 { 197 op->insert_at (originator);
215 object *tmp = op->in_player ();
216
217 if (tmp)
218 esrv_del_item (tmp->contr, op->count);
219 }
220
221 op->destroy (); 198 op->drop_and_destroy ();
222 } 199 }
223 200
224 if (type & (AT_FIRE | AT_ELECTRICITY)) 201 if (type & (AT_FIRE | AT_ELECTRICITY))
225 if (env) 202 if (env)
226 { 203 {
227 op = get_archetype ("burnout"); 204 op = archetype::get (shstr_burnout);
228 op->x = env->x, op->y = env->y; 205 op->x = env->x, op->y = env->y;
229 insert_ob_in_ob (op, env); 206 env->insert (op);
230 } 207 }
231 else 208 else
232 replace_insert_ob_in_map ("burnout", originator); 209 replace_insert_ob_in_map (shstr_burnout, originator);
233 210
234 return; 211 return;
235 } 212 }
236 213
237 /* The value of 50 is arbitrary. */ 214 /* The value of 50 is arbitrary. */
238 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2)) 215 if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2))
239 { 216 {
240 object *tmp;
241 archetype *at = archetype::find ("icecube"); 217 archetype *at = archetype::find (shstr_icecube);
242 218
243 if (at == NULL) 219 if (at == NULL)
244 return; 220 return;
245 221
246 op = stop_item (op); 222 op = stop_item (op);
247 if (op == NULL) 223 if (op == NULL)
248 return; 224 return;
249 225
250 if ((tmp = present_arch (at, op->map, op->x, op->y)) == NULL) 226 object *tmp = present_arch (at, op->map, op->x, op->y);
227 if (!tmp)
251 { 228 {
252 tmp = arch_to_object (at); 229 tmp = arch_to_object (at);
253 tmp->x = op->x, tmp->y = op->y; 230 tmp->x = op->x, tmp->y = op->y;
254 /* This was in the old (pre new movement code) - 231 /* This was in the old (pre new movement code) -
255 * icecubes have slow_move set to 1 - don't want 232 * icecubes have slow_move set to 1 - don't want
258 tmp->move_slow_penalty = 0; 235 tmp->move_slow_penalty = 0;
259 tmp->move_slow = 0; 236 tmp->move_slow = 0;
260 insert_ob_in_map (tmp, op->map, originator, 0); 237 insert_ob_in_map (tmp, op->map, originator, 0);
261 } 238 }
262 239
263 if (!QUERY_FLAG (op, FLAG_REMOVED)) 240 tmp->insert (op);
264 op->remove ();
265
266 insert_ob_in_ob (op, tmp);
267 return; 241 return;
268 } 242 }
269} 243}
270 244
271/* Object op is hitting the map. 245/* Object op is hitting the map.
272 * op is going in direction 'dir' 246 * op is going in direction 'dir'
273 * type is the attacktype of the object. 247 * type is the attacktype of the object.
274 * full_hit is set if monster area does not matter. 248 * full_hit is set if monster area does not matter.
275 * returns 1 if it hits something, 0 otherwise. 249 * returns 1 if it hits something, 0 otherwise.
276 */ 250 */
277
278int 251int
279hit_map (object *op, int dir, int type, int full_hit) 252hit_map (object *op, int dir, int type, int full_hit)
280{ 253{
281 maptile *map; 254 maptile *map;
282 sint16 x, y; 255 sint16 x, y;
288 return 0; 261 return 0;
289 } 262 }
290 263
291 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) 264 if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL)
292 { 265 {
293 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->name, &op->name); 266 LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name);
294 return 0; 267 return 0;
295 } 268 }
296 269
297 if (!op->map) 270 if (!op->map)
298 { 271 {
301 } 274 }
302 275
303 if (op->head) 276 if (op->head)
304 op = op->head; 277 op = op->head;
305 278
306 map = op->map; 279 mapxy pos (op);
307 x = op->x + freearr_x[dir]; 280 pos.move (dir);
308 y = op->y + freearr_y[dir];
309 281
310 if (!xy_normalise (map, x, y)) 282 if (!pos.normalise ())
311 return 0; 283 return 0;
312 284
313 // elmex: a safe map tile can't be hit! 285 // elmex: a safe map tile can't be hit!
314 // this should prevent most harmful effects on items and players there. 286 // this should prevent most harmful effects on items and players there.
315 mapspace &ms = map->at (x, y); 287 mapspace &ms = pos.ms ();
316 288
317 if (ms.flags () & P_SAFE) 289 if (ms.flags () & P_SAFE)
318 return 0; 290 return 0;
319 291
320 /* peterm: a few special cases for special attacktypes --counterspell 292 /* peterm: a few special cases for special attacktypes --counterspell
321 * must be out here because it strikes things which are not alive 293 * must be out here because it strikes things which are not alive
322 */ 294 */
323 if (type & (AT_COUNTERSPELL | AT_CHAOS)) 295 if (type & (AT_COUNTERSPELL | AT_CHAOS))
324 { 296 {
325 if (type & AT_COUNTERSPELL) 297 if (type & AT_COUNTERSPELL)
358 330
359 /* Something could have happened to 'tmp' while 'tmp->below' was processed. 331 /* Something could have happened to 'tmp' while 'tmp->below' was processed.
360 * For example, 'tmp' was put in an icecube. 332 * For example, 'tmp' was put in an icecube.
361 * This is one of the few cases where on_same_map should not be used. 333 * This is one of the few cases where on_same_map should not be used.
362 */ 334 */
363 if (tmp->map != map || tmp->x != x || tmp->y != y) 335 if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y)
364 continue; 336 continue;
365 337
366 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 338 if (QUERY_FLAG (tmp, FLAG_ALIVE))
367 { 339 {
368 hit_player (tmp, op->stats.dam, op, type, full_hit); 340 hit_player (tmp, op->stats.dam, op, type, full_hit);
376 * that weak walls have is_alive set, which prevent objects from 348 * that weak walls have is_alive set, which prevent objects from
377 * passing over/through them. We don't care what type of movement 349 * passing over/through them. We don't care what type of movement
378 * the wall blocks - if it blocks any type of movement, can't be 350 * the wall blocks - if it blocks any type of movement, can't be
379 * destroyed right now. 351 * destroyed right now.
380 */ 352 */
381 else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block) 353 else if (tmp->materialname && op->stats.dam > 0 && !tmp->move_block)
382 { 354 {
383 save_throw_object (tmp, type, op); 355 save_throw_object (tmp, type, op);
384 356
385 if (op->destroyed ()) 357 if (op->destroyed ())
386 break; 358 break;
545 { 517 {
546 int mtype; 518 int mtype;
547 519
548 switch (hitter->current_weapon->weapontype) 520 switch (hitter->current_weapon->weapontype)
549 { 521 {
550 case WEAP_HIT: 522 case WEAP_HIT:
551 mtype = ATM_BASIC; 523 mtype = ATM_BASIC;
552 break; 524 break;
553 case WEAP_SLASH: 525 case WEAP_SLASH:
554 mtype = ATM_SLASH; 526 mtype = ATM_SLASH;
555 break; 527 break;
556 case WEAP_PIERCE: 528 case WEAP_PIERCE:
557 mtype = ATM_PIERCE; 529 mtype = ATM_PIERCE;
558 break; 530 break;
559 case WEAP_CLEAVE: 531 case WEAP_CLEAVE:
560 mtype = ATM_CLEAVE; 532 mtype = ATM_CLEAVE;
561 break; 533 break;
562 case WEAP_SLICE: 534 case WEAP_SLICE:
563 mtype = ATM_SLICE; 535 mtype = ATM_SLICE;
564 break; 536 break;
565 case WEAP_STAB: 537 case WEAP_STAB:
566 mtype = ATM_STAB; 538 mtype = ATM_STAB;
567 break; 539 break;
568 case WEAP_WHIP: 540 case WEAP_WHIP:
569 mtype = ATM_WHIP; 541 mtype = ATM_WHIP;
570 break; 542 break;
571 case WEAP_CRUSH: 543 case WEAP_CRUSH:
572 mtype = ATM_CRUSH; 544 mtype = ATM_CRUSH;
573 break; 545 break;
574 case WEAP_BLUD: 546 case WEAP_BLUD:
575 mtype = ATM_BLUD; 547 mtype = ATM_BLUD;
576 break; 548 break;
577 default: 549 default:
578 mtype = ATM_BASIC; 550 mtype = ATM_BASIC;
579 break; 551 break;
580 } 552 }
553
581 for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) 554 for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++)
582 if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) 555 if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1)
583 { 556 {
584 sprintf (buf1, "%s %s%s", attack_mess[mtype][i].buf1, &op->name, attack_mess[mtype][i].buf2); 557 sprintf (buf1, "%s %s%s", attack_mess[mtype][i].buf1, &op->name, attack_mess[mtype][i].buf2);
585 strcpy (buf2, attack_mess[mtype][i].buf3); 558 strcpy (buf2, attack_mess[mtype][i].buf3);
619 if (hitter->owner != NULL) 592 if (hitter->owner != NULL)
620 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2); 593 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2);
621 else 594 else
622 { 595 {
623 sprintf (buf, "%s%s you.", &hitter->name, buf2); 596 sprintf (buf, "%s%s you.", &hitter->name, buf2);
597
624 if (dam != 0) 598 if (dam != 0)
625 { 599 {
626 if (dam < 10) 600 if (dam < 10)
627 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT1, 0, 0); 601 op->contr->play_sound (sound_find ("player_is_hit1"));
628 else if (dam < 20) 602 else if (dam < 20)
629 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT2, 0, 0); 603 op->contr->play_sound (sound_find ("player_is_hit2"));
630 else 604 else
631 play_sound_player_only (op->contr, SOUND_PLAYER_IS_HIT3, 0, 0); 605 op->contr->play_sound (sound_find ("player_is_hit3"));
632 } 606 }
633 } 607 }
608
634 new_draw_info (NDI_BLACK, 0, op, buf); 609 new_draw_info (NDI_BLACK, 0, op, buf);
635 } /* end of player hitting player */ 610 } /* end of player hitting player */
636 611
637 if (hitter->type == PLAYER) 612 if (hitter->type == PLAYER)
638 { 613 {
639 sprintf (buf, "You %s.", buf1); 614 sprintf (buf, "You %s.", buf1);
615
640 if (dam != 0) 616 if (dam != 0)
641 { 617 {
642 if (dam < 10) 618 if (dam < 10)
643 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS1, 0, 0); 619 op->play_sound (sound_find ("player_hits1"));
644 else if (dam < 20) 620 else if (dam < 20)
645 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS2, 0, 0); 621 op->play_sound (sound_find ("player_hits2"));
646 else 622 else
647 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS3, 0, 0); 623 op->play_sound (sound_find ("player_hits3"));
648 } 624 }
625
649 new_draw_info (NDI_BLACK, 0, hitter, buf); 626 new_draw_info (NDI_BLACK, 0, hitter, buf);
650 } 627 }
651 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 628 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
652 { 629 {
653 /* look for stacked spells and start reducing the message chances */ 630 /* look for stacked spells and start reducing the message chances */
655 { 632 {
656 i = 4; 633 i = 4;
657 map = hitter->map; 634 map = hitter->map;
658 if (out_of_map (map, hitter->x, hitter->y)) 635 if (out_of_map (map, hitter->x, hitter->y))
659 return; 636 return;
637
660 next = GET_MAP_OB (map, hitter->x, hitter->y); 638 next = GET_MAP_OB (map, hitter->x, hitter->y);
661 if (next) 639 if (next)
662 while (next) 640 while (next)
663 { 641 {
664 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) 642 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE))
665 i *= 3; 643 i *= 3;
644
666 tmp = next; 645 tmp = next;
667 next = tmp->above; 646 next = tmp->above;
668 } 647 }
648
669 if (i < 0) 649 if (i < 0)
670 return; 650 return;
651
671 if (rndm (0, i) != 0) 652 if (rndm (0, i) != 0)
672 return; 653 return;
673 } 654 }
674 else if (rndm (0, 5) != 0) 655 else if (rndm (0, 5) != 0)
675 return; 656 return;
657
676 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name); 658 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name);
677 play_sound_map (op->map, op->x, op->y, SOUND_PLAYER_HITS4); 659 op->play_sound (sound_find ("player_hits4"));
678 new_draw_info (NDI_BLACK, 0, hitter->owner, buf); 660 new_draw_info (NDI_BLACK, 0, hitter->owner, buf);
679 } 661 }
680} 662}
681 663
682 664
686 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) 668 if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED))
687 { 669 {
688 LOG (llevError, "BUG: get_attack_mode(): freed object\n"); 670 LOG (llevError, "BUG: get_attack_mode(): freed object\n");
689 return 1; 671 return 1;
690 } 672 }
673
691 if ((*target)->head) 674 if ((*target)->head)
692 *target = (*target)->head; 675 *target = (*target)->head;
676
693 if ((*hitter)->head) 677 if ((*hitter)->head)
694 *hitter = (*hitter)->head; 678 *hitter = (*hitter)->head;
679
680 if ((*target)->type == LOCKED_DOOR)
681 return 1; // locked doors cannot be hit
682
695 if ((*hitter)->env != NULL || (*target)->env != NULL) 683 if ((*hitter)->env || (*target)->env)
696 { 684 {
697 *simple_attack = 1; 685 *simple_attack = 1;
698 return 0; 686 return 0;
699 } 687 }
688
700 if (QUERY_FLAG (*target, FLAG_REMOVED) 689 if (QUERY_FLAG (*target, FLAG_REMOVED)
701 || QUERY_FLAG (*hitter, FLAG_REMOVED) || (*hitter)->map == NULL || !on_same_map ((*hitter), (*target))) 690 || QUERY_FLAG (*hitter, FLAG_REMOVED)
691 || !(*hitter)->map
692 || !on_same_map (*hitter, *target))
702 { 693 {
703 LOG (llevError, "BUG: hitter (arch %s, name %s) with no relation to " "target\n", &(*hitter)->arch->name, &(*hitter)->name); 694 LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n",
695 (*hitter)->debug_desc (), (*target)->debug_desc ());
704 return 1; 696 return 1;
705 } 697 }
698
706 *simple_attack = 0; 699 *simple_attack = 0;
707 return 0; 700 return 0;
708} 701}
709 702
710static int 703static int
746 739
747 /* 740 /*
748 * A little check to make it more difficult to dance forward and back 741 * A little check to make it more difficult to dance forward and back
749 * to avoid ever being hit by monsters. 742 * to avoid ever being hit by monsters.
750 */ 743 */
751 if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > -(FABS (op->speed)) * 0.3) 744 if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > abs (op->speed) * -0.3f)
752 { 745 {
753 /* Decrease speed BEFORE calling process_object. Otherwise, an 746 /* Decrease speed BEFORE calling process_object. Otherwise, an
754 * infinite loop occurs, with process_object calling move_monster, 747 * infinite loop occurs, with process_object calling move_monster,
755 * which then gets here again. By decreasing the speed before 748 * which then gets here again. By decreasing the speed before
756 * we call process_object, the 'if' statement above will fail. 749 * we call process_object, the 'if' statement above will fail.
757 */ 750 */
758 op->speed_left--; 751 --op->speed_left;
759 process_object (op); 752 process_object (op);
760 753
761 if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack)) 754 if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack))
762 goto error; 755 goto error;
763 } 756 }
773 /* See if we hit the creature */ 766 /* See if we hit the creature */
774 if (roll == 20 || op->stats.ac >= base_wc - roll) 767 if (roll == 20 || op->stats.ac >= base_wc - roll)
775 { 768 {
776 int hitdam = base_dam; 769 int hitdam = base_dam;
777 770
778 if (settings.casting_time == TRUE)
779 {
780 if ((hitter->type == PLAYER) && (hitter->casting_time > -1))
781 {
782 hitter->casting_time = -1;
783 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost your spell!");
784 }
785 if ((op->casting_time > -1) && (hitdam > 0))
786 {
787 op->casting_time = -1;
788 if (op->type == PLAYER)
789 {
790 new_draw_info (NDI_UNIQUE, 0, op, "You were hit and lost your spell!");
791 new_draw_info_format (NDI_ALL | NDI_UNIQUE, 5, NULL, "%s was hit by %s and lost a spell.", &op_name, &hitter->name);
792 }
793 }
794 }
795 if (!simple_attack) 771 if (!simple_attack)
796 { 772 {
797 /* If you hit something, the victim should *always* wake up. 773 /* If you hit something, the victim should *always* wake up.
798 * Before, invisible hitters could avoid doing this. 774 * Before, invisible hitters could avoid doing this.
799 * -b.t. */ 775 * -b.t. */
804 * for help. */ 780 * for help. */
805 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) 781 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int))
806 npc_call_help (op); 782 npc_call_help (op);
807 783
808 /* if you were hidden and hit by a creature, you are discovered */ 784 /* if you were hidden and hit by a creature, you are discovered */
809 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) 785 if (op->flag [FLAG_HIDDEN] && hitter->flag [FLAG_ALIVE])
810 { 786 {
811 make_visible (op); 787 make_visible (op);
788
812 if (op->type == PLAYER) 789 if (op->type == PLAYER)
813 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!"); 790 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!");
814 } 791 }
815 792
816 /* thrown items (hitter) will have various effects 793 /* thrown items (hitter) will have various effects
870} 847}
871 848
872int 849int
873attack_ob (object *op, object *hitter) 850attack_ob (object *op, object *hitter)
874{ 851{
875
876 if (hitter->head)
877 hitter = hitter->head; 852 hitter = hitter->head_ ();
853
878 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); 854 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc);
879} 855}
880 856
881/* op is the arrow, tmp is what is stopping the arrow. 857/* op is the arrow, tmp is what is stopping the arrow.
882 * 858 *
891 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons 867 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons
892 * stick around. 868 * stick around.
893 */ 869 */
894 if (op->weight <= 5000 && tmp->stats.hp >= 0) 870 if (op->weight <= 5000 && tmp->stats.hp >= 0)
895 { 871 {
896 if (tmp->head != NULL) 872 tmp->head_ ()->insert (op);
897 tmp = tmp->head;
898
899 op->remove ();
900 op = insert_ob_in_ob (op, tmp);
901
902 if (tmp->type == PLAYER)
903 esrv_send_item (tmp, op);
904
905 return 1; 873 return 1;
906 } 874 }
907 else 875 else
908 return 0; 876 return 0;
909} 877}
923 /* Disassemble missile */ 891 /* Disassemble missile */
924 if (op->inv) 892 if (op->inv)
925 { 893 {
926 container = op; 894 container = op;
927 hitter = op->inv; 895 hitter = op->inv;
928 hitter->remove ();
929 insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON); 896 hitter->insert_at (container, hitter, INS_NO_MERGE | INS_NO_WALK_ON);
930 /* Note that we now have an empty THROWN_OBJ on the map. Code that 897 /* Note that we now have an empty THROWN_OBJ on the map. Code that
931 * might be called until this THROWN_OBJ is either reassembled or 898 * might be called until this THROWN_OBJ is either reassembled or
932 * removed at the end of this function must be able to deal with empty 899 * removed at the end of this function must be able to deal with empty
933 * THROWN_OBJs. */ 900 * THROWN_OBJs. */
934 } 901 }
948 * other places as well!) 915 * other places as well!)
949 */ 916 */
950 if (hitter->destroyed () || hitter->env != NULL) 917 if (hitter->destroyed () || hitter->env != NULL)
951 { 918 {
952 if (container) 919 if (container)
953 {
954 container->remove ();
955 container->destroy (); 920 container->destroy ();
956 }
957 921
958 return 0; 922 return 0;
959 } 923 }
960 924
961 /* Missile hit victim */ 925 /* Missile hit victim */
985 * can fly over but not otherwise move over. What is the correct 949 * can fly over but not otherwise move over. What is the correct
986 * way to handle those otherwise? 950 * way to handle those otherwise?
987 */ 951 */
988 if (victim->x != hitter->x || victim->y != hitter->y) 952 if (victim->x != hitter->x || victim->y != hitter->y)
989 { 953 {
954 if (victim->destroyed ())
955 hitter->destroy ();
956 else
957 {
990 hitter->remove (); 958 hitter->remove ();
991 hitter->x = victim->x; 959 hitter->x = victim->x;
992 hitter->y = victim->y; 960 hitter->y = victim->y;
993 insert_ob_in_map (hitter, victim->map, hitter, 0); 961 insert_ob_in_map (hitter, victim->map, hitter, 0);
962 }
994 } 963 }
995 else 964 else
996 /* Else leave arrow where it is */ 965 /* Else leave arrow where it is */
997 merge_ob (hitter, NULL); 966 merge_ob (hitter, NULL);
998 967
1009 insert_ob_in_ob (hitter, container); 978 insert_ob_in_ob (hitter, container);
1010 } 979 }
1011 980
1012 return op; 981 return op;
1013} 982}
1014
1015 983
1016void 984void
1017tear_down_wall (object *op) 985tear_down_wall (object *op)
1018{ 986{
1019 int perc = 0; 987 int perc = 0;
1068 SET_FLAG (target, FLAG_SCARED); 1036 SET_FLAG (target, FLAG_SCARED);
1069 if (!target->enemy) 1037 if (!target->enemy)
1070 target->enemy = owner; 1038 target->enemy = owner;
1071} 1039}
1072 1040
1073
1074/* This returns the amount of damage hitter does to op with the 1041/* This returns the amount of damage hitter does to op with the
1075 * appropriate attacktype. Only 1 attacktype should be set at a time. 1042 * appropriate attacktype. Only 1 attacktype should be set at a time.
1076 * This doesn't damage the player, but returns how much it should 1043 * This doesn't damage the player, but returns how much it should
1077 * take. However, it will do other effects (paralyzation, slow, etc.) 1044 * take. However, it will do other effects (paralyzation, slow, etc.)
1078 * Note - changed for PR code - we now pass the attack number and not 1045 * Note - changed for PR code - we now pass the attack number and not
1079 * the attacktype. Makes it easier for the PR code. */ 1046 * the attacktype. Makes it easier for the PR code. */
1080
1081int 1047int
1082hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic) 1048hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic)
1083{ 1049{
1084 int doesnt_slay = 1; 1050 int doesnt_slay = 1;
1085 1051
1090 return 0; 1056 return 0;
1091 } 1057 }
1092 1058
1093 if (dam < 0) 1059 if (dam < 0)
1094 { 1060 {
1095 LOG (llevError, "hit_player_attacktype called with negative damage: %d\n", dam); 1061 LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n",
1062 dam, hitter->debug_desc (), op->debug_desc ());
1096 return 0; 1063 return 0;
1097 } 1064 }
1098 1065
1099 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so 1066 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so
1100 * people can't mess with that or it otherwise get confused. */ 1067 * people can't mess with that or it otherwise get confused. */
1101 if (attacknum == ATNR_INTERNAL) 1068 if (attacknum == ATNR_INTERNAL)
1102 return dam; 1069 return dam;
1103 1070
1104 if (hitter->slaying) 1071 if (hitter->slaying)
1105 { 1072 {
1106 if (((op->race != NULL) && strstr (hitter->slaying, op->race)) || 1073 if ((op->race && strstr (hitter->slaying, op->race))
1107 (op->arch && (op->arch->name != NULL) && strstr (op->arch->name, hitter->slaying))) 1074 || (op->arch && op->arch->archname && strstr (op->arch->archname, hitter->slaying)))
1108 { 1075 {
1109 doesnt_slay = 0; 1076 doesnt_slay = 0;
1110 dam *= 3; 1077 dam *= 3;
1111 } 1078 }
1112 } 1079 }
1126 /* Special hack. By default, if immune to something, you 1093 /* Special hack. By default, if immune to something, you
1127 * shouldn't need to worry. However, acid is an exception, since 1094 * shouldn't need to worry. However, acid is an exception, since
1128 * it can still damage your items. Only include attacktypes if 1095 * it can still damage your items. Only include attacktypes if
1129 * special processing is needed */ 1096 * special processing is needed */
1130 1097
1131 if ((op->resist[attacknum] >= 100) && doesnt_slay && (attacknum != ATNR_ACID)) 1098 if (op->resist[attacknum] >= 100
1099 && doesnt_slay
1100 && attacknum != ATNR_ACID)
1132 return 0; 1101 return 0;
1133 1102
1134 /* Keep this in order - makes things easier to find */ 1103 /* Keep this in order - makes things easier to find */
1135 1104
1136 switch (attacknum) 1105 switch (attacknum)
1186 else if (attacknum == ATNR_DEPLETE) 1155 else if (attacknum == ATNR_DEPLETE)
1187 op->drain_stat (); 1156 op->drain_stat ();
1188 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) 1157 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR))
1189 blind_player (op, hitter, dam); 1158 blind_player (op, hitter, dam);
1190 } 1159 }
1160
1191 dam = 0; /* These are all effects and don't do real damage */ 1161 dam = 0; /* These are all effects and don't do real damage */
1192 } 1162 }
1193 break; 1163 break;
1164
1194 case ATNR_ACID: 1165 case ATNR_ACID:
1195 { 1166 {
1196 int flag = 0; 1167 int flag = 0;
1197 1168
1198 /* Items only get corroded if you're not on a battleground and 1169 /* Items only get corroded if you're not on a battleground and
1199 * if your acid resistance is below 50%. */ 1170 * if your acid resistance is below 50%. */
1200 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50)) 1171 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50))
1201 { 1172 {
1202 object *tmp;
1203
1204 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1173 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1205 { 1174 {
1206 if (tmp->invisible) 1175 if (tmp->invisible)
1207 continue; 1176 continue;
1208 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 1177 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1209 /* >= 10% acid res. on itmes will protect these */ 1178 /* >= 10% acid res. on items will protect these */
1210 continue; 1179 continue;
1211 if (!(tmp->material & M_IRON)) 1180 if (!(tmp->materials & M_IRON))
1212 continue; 1181 continue;
1213 if (tmp->magic < -4) /* Let's stop at -5 */ 1182 if (tmp->magic < -4) /* Let's stop at -5 */
1214 continue; 1183 continue;
1215 if (tmp->type == RING || 1184 if (tmp->type == RING
1216 /* removed boots and gloves from exclusion list in 1185 /* removed boots and gloves from exclusion list in PR */
1217 PR */ 1186 || tmp->type == GIRDLE
1218 tmp->type == GIRDLE || tmp->type == AMULET || tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1187 || tmp->type == AMULET
1188 || tmp->type == WAND
1189 || tmp->type == ROD
1190 || tmp->type == HORN)
1219 continue; /* To avoid some strange effects */ 1191 continue; /* To avoid some strange effects */
1220 1192
1221 /* High damage acid has better chance of corroding 1193 /* High damage acid has better chance of corroding
1222 objects */ 1194 objects */
1223 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic) 1195 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic)
1224 { 1196 {
1225 if (op->type == PLAYER)
1226 /* Make this more visible */
1227 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op,
1228 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp));
1229 flag = 1; 1197 flag = 1;
1230 tmp->magic--; 1198 tmp->magic--;
1231 if (op->type == PLAYER) 1199
1232 esrv_send_item (op, tmp); 1200 if (object *pl = tmp->visible_to ())
1201 {
1202 /* Make this more visible */
1203 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, pl,
1204 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp));
1205
1206 esrv_send_item (op, tmp); //TODO: UPD_NAME should be enough (it's enough in other cases)
1207 }
1233 } 1208 }
1234 } 1209 }
1210
1235 if (flag) 1211 if (flag)
1236 op->update_stats (); /* Something was corroded */ 1212 op->update_stats (); /* Something was corroded */
1237 } 1213 }
1238 } 1214 }
1239 break; 1215 break;
1216
1240 case ATNR_DRAIN: 1217 case ATNR_DRAIN:
1241 { 1218 {
1242 /* rate is the proportion of exp drained. High rate means 1219 /* rate is the proportion of exp drained. High rate means
1243 * not much is drained, low rate means a lot is drained. 1220 * not much is drained, low rate means a lot is drained.
1244 */ 1221 */
1269 * exp, but the wiz would still lose exp! If drainee is a wiz, 1246 * exp, but the wiz would still lose exp! If drainee is a wiz,
1270 * nothing happens. 1247 * nothing happens.
1271 * Try to credit the owner. We try to display player -> player drain 1248 * Try to credit the owner. We try to display player -> player drain
1272 * attacks, hence all the != PLAYER checks. 1249 * attacks, hence all the != PLAYER checks.
1273 */ 1250 */
1274 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WAS_WIZ)) 1251 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ))
1275 { 1252 {
1276 object *owner = hitter->owner; 1253 object *owner = hitter->owner;
1277 1254
1278 if (owner && owner != hitter) 1255 if (owner && owner != hitter)
1279 { 1256 {
1280 if (op->type != PLAYER || owner->type != PLAYER) 1257 if (op->type != PLAYER || owner->type != PLAYER)
1281 change_exp (owner, op->stats.exp / (rate * 2), 1258 change_exp (owner, op->stats.exp / (rate * 2),
1282 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); 1259 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL);
1283 } 1260 }
1284 else if (op->type != PLAYER || hitter->type != PLAYER) 1261 else if (op->type != PLAYER || hitter->type != PLAYER)
1285 {
1286 change_exp (hitter, op->stats.exp / (rate * 2), 1262 change_exp (hitter, op->stats.exp / (rate * 2),
1287 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 1263 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1288 } 1264
1289 change_exp (op, -op->stats.exp / rate, NULL, 0); 1265 change_exp (op, -op->stats.exp / rate, NULL, 0);
1290 } 1266 }
1267
1291 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure 1268 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
1292 * drain attack, you won't know that you are actually sucking out EXP, 1269 * drain attack, you won't know that you are actually sucking out EXP,
1293 * as the messages will say you missed 1270 * as the messages will say you missed
1294 */ 1271 */
1295 } 1272 }
1296 } 1273 }
1297 break; 1274 break;
1275
1298 case ATNR_TURN_UNDEAD: 1276 case ATNR_TURN_UNDEAD:
1299 { 1277 {
1300 if (QUERY_FLAG (op, FLAG_UNDEAD)) 1278 if (QUERY_FLAG (op, FLAG_UNDEAD))
1301 { 1279 {
1302 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1280 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1303 object *god = find_god (determine_god (owner)); 1281 object *god = find_god (determine_god (owner));
1304 int div = 1; 1282 int div = 1;
1305 1283
1306 /* if undead are not an enemy of your god, you turn them 1284 /* if undead are not an enemy of your god, you turn them
1307 * at half strength */ 1285 * at half strength */
1308 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1286 if (!god || !god->slaying || strstr (god->slaying, shstr_undead) == NULL)
1309 div = 2; 1287 div = 2;
1288
1310 /* Give a bonus if you resist turn undead */ 1289 /* Give a bonus if you resist turn undead */
1311 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) 1290 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1312 scare_creature (op, owner); 1291 scare_creature (op, owner);
1313 } 1292 }
1314 else 1293 else
1315 dam = 0; /* don't damage non undead - should we damage 1294 dam = 0; /* don't damage non undead - should we damage
1316 undead? */ 1295 undead? */
1317 } 1296 }
1318 break; 1297 break;
1298
1319 case ATNR_DEATH: 1299 case ATNR_DEATH:
1320 deathstrike_player (op, hitter, &dam); 1300 deathstrike_player (op, hitter, &dam);
1321 break; 1301 break;
1302
1322 case ATNR_CHAOS: 1303 case ATNR_CHAOS:
1323 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc2 ()); 1304 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc ());
1324 dam = 0; 1305 dam = 0;
1325 break; 1306 break;
1307
1326 case ATNR_COUNTERSPELL: 1308 case ATNR_COUNTERSPELL:
1327 LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc2 ()); 1309 LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc ());
1328 dam = 0; 1310 dam = 0;
1329 /* This should never happen. Counterspell is handled 1311 /* This should never happen. Counterspell is handled
1330 * seperately and filtered out. If this does happen, 1312 * seperately and filtered out. If this does happen,
1331 * Counterspell has no effect on anything but spells, so it 1313 * Counterspell has no effect on anything but spells, so it
1332 * does no damage. */ 1314 * does no damage. */
1333 break; 1315 break;
1316
1334 case ATNR_HOLYWORD: 1317 case ATNR_HOLYWORD:
1335 { 1318 {
1336 /* This has already been handled by hit_player, 1319 /* This has already been handled by hit_player,
1337 * no need to check twice -- DAMN */ 1320 * no need to check twice -- DAMN */
1338 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1321 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1340 /* As with turn undead above, give a bonus on the saving throw */ 1323 /* As with turn undead above, give a bonus on the saving throw */
1341 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) 1324 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis])
1342 scare_creature (op, owner); 1325 scare_creature (op, owner);
1343 } 1326 }
1344 break; 1327 break;
1328
1345 case ATNR_LIFE_STEALING: 1329 case ATNR_LIFE_STEALING:
1346 { 1330 {
1347 int new_hp; 1331 int new_hp;
1348 1332
1349 /* this is replacement to drain for players, instead of taking 1333 /* this is replacement to drain for players, instead of taking
1356 * 1000). 1340 * 1000).
1357 */ 1341 */
1358 /* You can't steal life from something undead */ 1342 /* You can't steal life from something undead */
1359 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) 1343 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD)))
1360 return 0; 1344 return 0;
1345
1361 /* If drain protection is higher than life stealing, use that */ 1346 /* If drain protection is higher than life stealing, use that */
1362 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 1347 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1363 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; 1348 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;
1364 else 1349 else
1365 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000; 1350 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000;
1351
1366 /* You die at -1 hp, not zero. */ 1352 /* You die at -1 hp, not zero. */
1367 if (dam > (op->stats.hp + 1)) 1353 if (dam > (op->stats.hp + 1))
1368 dam = op->stats.hp + 1; 1354 dam = op->stats.hp + 1;
1355
1369 new_hp = hitter->stats.hp + dam; 1356 new_hp = hitter->stats.hp + dam;
1370 if (new_hp > hitter->stats.maxhp) 1357 if (new_hp > hitter->stats.maxhp)
1371 new_hp = hitter->stats.maxhp; 1358 new_hp = hitter->stats.maxhp;
1359
1372 if (new_hp > hitter->stats.hp) 1360 if (new_hp > hitter->stats.hp)
1373 hitter->stats.hp = new_hp; 1361 hitter->stats.hp = new_hp;
1374 } 1362 }
1375 } 1363 }
1376 1364
1394 */ 1382 */
1395int 1383int
1396kill_object (object *op, int dam, object *hitter, int type) 1384kill_object (object *op, int dam, object *hitter, int type)
1397{ 1385{
1398 char buf[MAX_BUF]; 1386 char buf[MAX_BUF];
1399 const char *skill; 1387 shstr skill;
1400 int maxdam = 0; 1388 int maxdam = 0;
1401 int battleg = 0; /* true if op standing on battleground */ 1389 int battleg = 0; /* true if op standing on battleground */
1402 int pk = 0; /* true if op and what controls hitter are both players */ 1390 int pk = 0; /* true if op and what controls hitter are both players */
1403 object *owner = NULL; 1391 object *owner = 0;
1404 object *skop = NULL; 1392 object *skop = 0;
1405 1393
1406 if (op->stats.hp >= 0) 1394 if (op->stats.hp >= 0)
1407 return -1; 1395 return -1;
1408 1396
1409 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter))) 1397 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter)))
1418 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) 1406 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW))
1419 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ 1407 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */
1420 1408
1421 if (op->type == DOOR) 1409 if (op->type == DOOR)
1422 { 1410 {
1423 op->set_speed (0.1); 1411 op->set_speed (0.1f);
1424 op->speed_left = -0.05; 1412 op->speed_left = -0.05f;
1425 return maxdam; 1413 return maxdam;
1426 } 1414 }
1427 1415
1428 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1416 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1429 { 1417 {
1430 remove_friendly_object (op);
1431
1432 if (op->owner && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op)
1433 op->owner->contr->ranges[range_golem] = 0;
1434
1435 op->destroy (); 1418 op->drop_and_destroy ();
1436 return maxdam; 1419 return maxdam;
1437 } 1420 }
1438 1421
1439 /* Now lets start dealing with experience we get for killing something */ 1422 /* Now lets start dealing with experience we get for killing something */
1440 1423
1441 owner = hitter->owner; 1424 owner = hitter->outer_owner ();
1442 if (!owner) 1425 if (!owner)
1443 owner = hitter; 1426 owner = hitter;
1444 1427
1445 /* is the victim (op) standing on battleground? */ 1428 /* is the victim (op) standing on battleground? */
1446 if (op_on_battleground (op, NULL, NULL)) 1429 if (op_on_battleground (op, NULL, NULL))
1451 pk = 1; 1434 pk = 1;
1452 1435
1453 /* Player killed something */ 1436 /* Player killed something */
1454 if (owner->type == PLAYER) 1437 if (owner->type == PLAYER)
1455 { 1438 {
1456 Log_Kill (owner->name,
1457 query_name (op), op->type, (owner != hitter) ? query_name (hitter) : NULL, (owner != hitter) ? hitter->type : 0);
1458
1459 /* Log players killing other players - makes it easier to detect 1439 /* Log players killing other players - makes it easier to detect
1460 * and filter out malicious player killers - that is why the 1440 * and filter out malicious player killers - that is why the
1461 * ip address is included. 1441 * ip address is included.
1462 */ 1442 */
1463 if (op->type == PLAYER && !battleg) 1443 if (op->type == PLAYER && !battleg)
1483 else 1463 else
1484 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op)); 1464 new_draw_info_format (NDI_BLACK, 0, owner, "You killed %s.", query_name (op));
1485 1465
1486 /* Only play sounds for melee kills */ 1466 /* Only play sounds for melee kills */
1487 if (hitter->type == PLAYER) 1467 if (hitter->type == PLAYER)
1488 play_sound_map (owner->map, owner->x, owner->y, SOUND_PLAYER_KILLS); 1468 owner->play_sound (sound_find ("player_kills"));
1489 } 1469 }
1490 1470
1491 /* If a player kills another player, not on 1471 /* If a player kills another player, not on
1492 * battleground, the "killer" looses 1 luck. Since this is 1472 * battleground, the "killer" looses 1 luck. Since this is
1493 * not reversible, it's actually quite a pain IMHO. -AV 1473 * not reversible, it's actually quite a pain IMHO. -AV
1498 */ 1478 */
1499 if (op->type == PLAYER && owner != op && !battleg) 1479 if (op->type == PLAYER && owner != op && !battleg)
1500 owner->change_luck (-settings.pk_luck_penalty); 1480 owner->change_luck (-settings.pk_luck_penalty);
1501 1481
1502 /* This code below deals with finding the appropriate skill 1482 /* This code below deals with finding the appropriate skill
1503 * to credit exp to. This is a bit problematic - we should 1483 * to credit exp to. This is a bit problematic - we should
1504 * probably never really have to look at current_weapon->skill 1484 * probably never really have to look at current_weapon->skill
1505 */ 1485 */
1506 skill = 0;
1507
1508 if (hitter->skill && hitter->type != PLAYER) 1486 if (hitter->skill && hitter->type != PLAYER)
1509 skill = hitter->skill; 1487 skill = hitter->skill;
1510 else if (owner->chosen_skill) 1488 else if (owner->chosen_skill)
1511 { 1489 {
1512 skill = owner->chosen_skill->skill;
1513 skop = owner->chosen_skill; 1490 skop = owner->chosen_skill;
1491 skill = skop->skill;
1514 } 1492 }
1515 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON)) 1493 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon)
1516 skill = owner->current_weapon->skill; 1494 skill = owner->current_weapon->skill;
1517 else 1495 else
1496 {
1518 LOG (llevError, "kill_object - unable to find skill that killed monster\n"); 1497 LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n"
1498 "op: %s\n" "hitter: %s\n" "owner: %s\n",
1499 owner->debug_desc (), hitter->debug_desc (), op->debug_desc ());
1500 skill = 0;
1501 }
1519 1502
1520 /* We have the skill we want to credit to - now find the object this goes 1503 /* We have the skill we want to credit to - now find the object this goes
1521 * to. Make sure skop is an actual skill, and not a skill tool! 1504 * to. Make sure skop is an actual skill, and not a skill tool!
1522 */ 1505 */
1523 if ((!skop || skop->type != SKILL) && skill) 1506 skop = owner->contr->find_skill (skill);
1524 {
1525 int i;
1526
1527 for (i = 0; i < NUM_SKILLS; i++)
1528 if (owner->contr->last_skill_ob[i] && !strcmp (owner->contr->last_skill_ob[i]->skill, skill))
1529 {
1530 skop = owner->contr->last_skill_ob[i];
1531 break;
1532 }
1533 }
1534 } /* Was it a player that hit somethign */ 1507 } /* Was it a player that hit somethign */
1535 else 1508 else
1536 skill = 0; 1509 skill = 0;
1537 1510
1538 /* Pet (or spell) killed something. */
1539 if (owner != hitter)
1540 sprintf (buf, "%s killed %s with %s%s%s.", &owner->name,
1541 query_name (op), query_name (hitter), battleg ? " (duel)" : "", pk ? " (pk)" : "");
1542 else
1543 sprintf (buf, "%s killed %s%s%s%s.", &hitter->name, &op->name,
1544 (QUERY_FLAG (hitter, FLAG_MONSTER)) || hitter->type == PLAYER ?
1545 " in hand to hand combat" : "", battleg ? " (duel)" : "", pk ? " (pk)" : "");
1546
1547 /* These may have been set in the player code section above */ 1511 /* These may have been set in the player code section above */
1548 if (!skop) 1512 if (!skop)
1549 skop = hitter->chosen_skill; 1513 skop = hitter->chosen_skill;
1550 1514
1551 if (!skill && skop) 1515 if (!skill && skop)
1552 skill = skop->skill; 1516 skill = skop->skill;
1553 1517
1554 new_draw_info (NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, buf);
1555
1556 /* If you didn't kill yourself, and your not the wizard */ 1518 /* If you didn't kill yourself, and your not the wizard */
1557 if (owner != op && !QUERY_FLAG (op, FLAG_WAS_WIZ)) 1519 if (owner != op && !QUERY_FLAG (op, FLAG_WIZ))
1558 { 1520 {
1559 int exp; 1521 int exp;
1560 1522
1561 /* Really don't give much experience for killing other players */ 1523 /* Really don't give much experience for killing other players */
1562 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously 1524 // schmorp: temporarily? reduce the amount of exp gained for pking enourmously
1589 if (owner->type != PLAYER || owner->contr->party == NULL) 1551 if (owner->type != PLAYER || owner->contr->party == NULL)
1590 change_exp (owner, exp, skill, 0); 1552 change_exp (owner, exp, skill, 0);
1591 else 1553 else
1592 { 1554 {
1593 int shares = 0, count = 0; 1555 int shares = 0, count = 0;
1594 player *pl;
1595 partylist *party = owner->contr->party; 1556 partylist *party = owner->contr->party;
1596 1557
1597 add_kill_to_party (party, query_name (owner), query_name (op), exp); 1558 add_kill_to_party (party, query_name (owner), query_name (op), exp);
1598 1559
1599 for_all_players (pl) 1560 for_all_players (pl)
1630 { 1591 {
1631 object *owner1 = op->owner; 1592 object *owner1 = op->owner;
1632 1593
1633 if (owner1 && owner1->type == PLAYER) 1594 if (owner1 && owner1->type == PLAYER)
1634 { 1595 {
1635 play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0); 1596 owner1->contr->play_sound (sound_find ("pet_is_killed"));
1636 /* Maybe we should include the owner that killed this, maybe not */ 1597 /* Maybe we should include the owner that killed this, maybe not */
1637 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); 1598 new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, was killed by %s.", &op->name, &hitter->name);
1638 } 1599 }
1639 1600
1640 remove_friendly_object (op); 1601 remove_friendly_object (op);
1641 } 1602 }
1642 1603
1643 op->destroy (); 1604 op->drop_and_destroy ();
1644 } 1605 }
1645 else 1606 else
1646 {
1647 /* Player has been killed! */ 1607 /* Player has been killed! */
1648 if (owner->type == PLAYER) 1608 op->contr->killer = owner->type == PLAYER ? owner : hitter;
1649 snprintf (op->contr->killer, sizeof (op->contr->killer), "%s the %s", &owner->name, owner->contr->title);
1650 else
1651 assign (op->contr->killer, hitter->name);
1652 }
1653 1609
1654 /* This was return -1 - that doesn't seem correct - if we return -1, process 1610 /* This was return -1 - that doesn't seem correct - if we return -1, process
1655 * continues in the calling function. 1611 * continues in the calling function.
1656 */ 1612 */
1657 return maxdam; 1613 return maxdam;
1658} 1614}
1659 1615
1660/* Find out if this is friendly fire (PVP and attacker is peaceful) or not 1616/* Find out if this is friendly fire (PVP and attacker is peaceful) or not
1661 * Returns 0 this is not friendly fire 1617 * Returns 0 this is not friendly fire
1662 */ 1618 */
1663
1664int 1619int
1665friendly_fire (object *op, object *hitter) 1620friendly_fire (object *op, object *hitter)
1666{ 1621{
1667 object *owner; 1622 object *owner;
1668 int friendlyfire; 1623 int friendlyfire;
1687 } 1642 }
1688 1643
1689 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE) 1644 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE)
1690 friendlyfire = 0; 1645 friendlyfire = 0;
1691 } 1646 }
1647
1692 return friendlyfire; 1648 return friendlyfire;
1693} 1649}
1694
1695 1650
1696/* This isn't used just for players, but in fact most objects. 1651/* This isn't used just for players, but in fact most objects.
1697 * op is the object to be hit, dam is the amount of damage, hitter 1652 * op is the object to be hit, dam is the amount of damage, hitter
1698 * is what is hitting the object, type is the attacktype, and 1653 * is what is hitting the object, type is the attacktype, and
1699 * full_hit is set if monster area does not matter. 1654 * full_hit is set if monster area does not matter.
1717 1672
1718 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ 1673 /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */
1719 if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) 1674 if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE))
1720 return 0; 1675 return 0;
1721 1676
1722#ifdef PROHIBIT_PLAYERKILL 1677 // only allow pk for hostile players
1723 if (op->type == PLAYER) 1678 if (op->type == PLAYER)
1724 { 1679 {
1725 object *owner = hitter->owner; 1680 object *owner = hitter->owner;
1726 1681
1727 if (!owner) 1682 if (!owner)
1728 owner = hitter; 1683 owner = hitter;
1729 1684
1730 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner) 1685 if (owner->type == PLAYER
1686 && (!op_on_battleground (op, 0, 0)
1687 && (op->contr->peaceful || owner->contr->peaceful))
1688 && op != owner)
1731 return 0; 1689 return 0;
1732 } 1690 }
1733#endif
1734 1691
1735 if (body_attack) 1692 if (body_attack)
1736 { 1693 {
1737 /* slow and paralyze must hit the head. But we don't want to just 1694 /* slow and paralyze must hit the head. But we don't want to just
1738 * return - we still need to process other attacks the spell still 1695 * return - we still need to process other attacks the spell still
1752 } 1709 }
1753 } 1710 }
1754 1711
1755 if (!simple_attack && op->type == DOOR) 1712 if (!simple_attack && op->type == DOOR)
1756 { 1713 {
1757 object *tmp;
1758
1759 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1714 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1760 if (tmp->type == RUNE || tmp->type == TRAP) 1715 if (tmp->type == RUNE || tmp->type == TRAP)
1761 { 1716 {
1762 spring_trap (tmp, hitter); 1717 spring_trap (tmp, hitter);
1763 1718
1764 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) 1719 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack))
1771 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1726 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1772 { 1727 {
1773 /* FIXME: If a player is killed by a rune in a door, the 1728 /* FIXME: If a player is killed by a rune in a door, the
1774 * destroyed() check above doesn't return, and might get here. 1729 * destroyed() check above doesn't return, and might get here.
1775 */ 1730 */
1731
1732 /* FIXME: This for example happens when a dead door is on a mover and
1733 gets it's speed_left raised on each mover-tick.
1734 Doors are removed in a kinda funny way by giving them speed and speed_left
1735 and waiting for that to run out.
1736 */
1776 LOG (llevDebug, "victim (arch %s, name %s) already dead in " "hit_player()\n", &op->arch->name, &op->name); 1737 LOG (llevDebug, "victim %s (%d) already dead in hit_player()\n", op->debug_desc (), op->stats.hp);
1777 return 0; 1738 return 0;
1778 } 1739 }
1779 1740
1780#ifdef ATTACK_DEBUG 1741#ifdef ATTACK_DEBUG
1781 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); 1742 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1787 * in case 0>dam>1, we try to "simulate" a float value-effect */ 1748 * in case 0>dam>1, we try to "simulate" a float value-effect */
1788 dam = dam * (100 - op->resist[ATNR_MAGIC]); 1749 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1789 if (dam >= 100) 1750 if (dam >= 100)
1790 dam /= 100; 1751 dam /= 100;
1791 else 1752 else
1792 dam = (dam > (rndm (0, 99))) ? 1 : 0; 1753 dam = (dam > rndm (0, 99)) ? 1 : 0;
1793 } 1754 }
1794 1755
1795 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map 1756 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map
1796 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit 1757 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit
1797 */ 1758 */
1813 if ((!hitter->slaying || 1774 if ((!hitter->slaying ||
1814 (!(op->race && strstr (hitter->slaying, op->race)) && 1775 (!(op->race && strstr (hitter->slaying, op->race)) &&
1815 !(op->name && strstr (hitter->slaying, op->name)))) && 1776 !(op->name && strstr (hitter->slaying, op->name)))) &&
1816 (!QUERY_FLAG (op, FLAG_UNDEAD) || 1777 (!QUERY_FLAG (op, FLAG_UNDEAD) ||
1817 (hitter->title != NULL 1778 (hitter->title != NULL
1818 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL))) 1779 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, shstr_undead) != NULL)))
1819 return 0; 1780 return 0;
1820 } 1781 }
1821 1782
1822 maxattacktype = type; /* initialise this to something */ 1783 maxattacktype = type; /* initialise this to something */
1823 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1784 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1855 */ 1816 */
1856 friendlyfire = friendly_fire (op, hitter); 1817 friendlyfire = friendly_fire (op, hitter);
1857 if (friendlyfire && maxdam) 1818 if (friendlyfire && maxdam)
1858 { 1819 {
1859 maxdam = ((dam * settings.set_friendly_fire) / 100); 1820 maxdam = ((dam * settings.set_friendly_fire) / 100);
1860#ifndef COZY_SERVER
1861 maxdam++;
1862#endif
1863 1821
1864#ifdef ATTACK_DEBUG 1822#ifdef ATTACK_DEBUG
1865 LOG (llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n", 1823 LOG (llevDebug, "Friendly fire (type:%d setting: %d%) did %d damage dropped to %d\n",
1866 friendlyfire, settings.set_friendly_fire, dam, maxdam); 1824 friendlyfire, settings.set_friendly_fire, dam, maxdam);
1867#endif 1825#endif
1868 } 1826 }
1869 1827
1870 if (!full_hit) 1828 if (!full_hit)
1871 { 1829 {
1872 archetype *at;
1873 int area; 1830 int area;
1874 int remainder; 1831 int remainder;
1875 1832
1876 area = 0; 1833 area = 0;
1877 for (at = op->arch; at != NULL; at = at->more) 1834
1835 for (archetype *at = op->arch; at; at = (archetype *)at->more)
1878 area++; 1836 area++;
1837
1879 assert (area > 0); 1838 assert (area > 0);
1880 1839
1881 /* basically: maxdam /= area; we try to "simulate" a float 1840 /* basically: maxdam /= area; we try to "simulate" a float
1882 value-effect */ 1841 value-effect */
1883 remainder = 100 * (maxdam % area) / area; 1842 remainder = 100 * (maxdam % area) / area;
1884 maxdam /= area; 1843 maxdam /= area;
1885 if (RANDOM () % 100 < remainder) 1844 if (rndm (100) < remainder)
1886 maxdam++; 1845 maxdam++;
1887 } 1846 }
1888 1847
1889#ifdef ATTACK_DEBUG 1848#ifdef ATTACK_DEBUG
1890 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); 1849 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1891#endif 1850#endif
1892 1851
1852 // for now, only do this for active objects, otherwise they
1853 // keep a refcount for a long time and I see no usefulness
1854 // for an non-active objetc to know its enemy.
1855 if (op->active)
1893 if (hitter->owner) 1856 if (hitter->owner)
1894 op->enemy = hitter->owner; 1857 op->enemy = hitter->owner;
1895 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1858 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1896 op->enemy = hitter; 1859 op->enemy = hitter;
1897 1860
1898 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1861 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1899 { 1862 {
1900 /* The unaggressives look after themselves 8) */ 1863 /* The unaggressives look after themselves 8) */
1901 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 1864 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
1931 1894
1932 /* See if the creature has been killed */ 1895 /* See if the creature has been killed */
1933 rtn_kill = kill_object (op, maxdam, hitter, type); 1896 rtn_kill = kill_object (op, maxdam, hitter, type);
1934 if (rtn_kill != -1) 1897 if (rtn_kill != -1)
1935 return rtn_kill; 1898 return rtn_kill;
1936
1937 1899
1938 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1900 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1939 * that before if the player was immune to ghosthit, the monster 1901 * that before if the player was immune to ghosthit, the monster
1940 * remained - that is no longer the case. 1902 * remained - that is no longer the case.
1941 */ 1903 */
1942 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1904 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1943 {
1944 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1945 remove_friendly_object (hitter);
1946
1947 hitter->destroy (); 1905 hitter->drop_and_destroy ();
1948 }
1949 /* Lets handle creatures that are splitting now */ 1906 /* Lets handle creatures that are splitting now */
1950 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1907 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1951 { 1908 {
1952 int i; 1909 int i;
1953 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1910 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
1960 return maxdam; 1917 return maxdam;
1961 } 1918 }
1962 1919
1963 op->remove (); 1920 op->remove ();
1964 1921
1965 for (i = 0; i < NROFNEWOBJS (op); i++) 1922 for (i = 0; i < op->stats.food; i++)
1966 { /* This doesn't handle op->more yet */ 1923 { /* This doesn't handle op->more yet */
1967 object *tmp = arch_to_object (op->other_arch); 1924 object *tmp = arch_to_object (op->other_arch);
1968 int j; 1925 int j;
1969 1926
1970 tmp->stats.hp = op->stats.hp; 1927 tmp->stats.hp = op->stats.hp;
1993 } 1950 }
1994 1951
1995 op->destroy (); 1952 op->destroy ();
1996 } 1953 }
1997 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) 1954 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
1998 hitter->destroy (); 1955 hitter->drop_and_destroy ();
1999 1956
2000 return maxdam; 1957 return maxdam;
2001} 1958}
2002
2003 1959
2004void 1960void
2005poison_player (object *op, object *hitter, int dam) 1961poison_player (object *op, object *hitter, int dam)
2006{ 1962{
2007 archetype *at = archetype::find ("poisoning"); 1963 archetype *at = archetype::find ("poisoning");
2043 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10); 1999 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10);
2044 tmp->stats.Int = MAX (-dam / 7, -10); 2000 tmp->stats.Int = MAX (-dam / 7, -10);
2045 SET_FLAG (tmp, FLAG_APPLIED); 2001 SET_FLAG (tmp, FLAG_APPLIED);
2046 op->update_stats (); 2002 op->update_stats ();
2047 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); 2003 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
2004 op->play_sound (tmp->sound);
2048 } 2005 }
2006
2049 if (hitter->type == PLAYER) 2007 if (hitter->type == PLAYER)
2050 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); 2008 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
2051 else if (hitter->owner != NULL && hitter->owner->type == PLAYER) 2009 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
2052 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); 2010 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name);
2053 } 2011 }
2012
2054 tmp->speed_left = 0; 2013 tmp->speed_left = 0;
2055 } 2014 }
2056 else 2015 else
2057 tmp->stats.food++; 2016 tmp->stats.food++;
2058} 2017}
2062{ 2021{
2063 archetype *at = archetype::find ("slowness"); 2022 archetype *at = archetype::find ("slowness");
2064 object *tmp; 2023 object *tmp;
2065 2024
2066 if (at == NULL) 2025 if (at == NULL)
2067 {
2068 LOG (llevError, "Can't find slowness archetype.\n"); 2026 LOG (llevError, "Can't find slowness archetype.\n");
2069 } 2027
2070 if ((tmp = present_arch_in_ob (at, op)) == NULL) 2028 if ((tmp = present_arch_in_ob (at, op)) == NULL)
2071 { 2029 {
2072 tmp = arch_to_object (at); 2030 tmp = arch_to_object (at);
2073 tmp = insert_ob_in_ob (tmp, op); 2031 tmp = insert_ob_in_ob (tmp, op);
2074 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); 2032 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!");
2075 } 2033 }
2076 else 2034 else
2077 tmp->stats.food++; 2035 tmp->stats.food++;
2036
2078 SET_FLAG (tmp, FLAG_APPLIED); 2037 SET_FLAG (tmp, FLAG_APPLIED);
2079 tmp->speed_left = 0; 2038 tmp->speed_left = 0;
2080 op->update_stats (); 2039 op->update_stats ();
2081} 2040}
2082 2041
2099 tmp->speed = 0.05; 2058 tmp->speed = 0.05;
2100 tmp->subtype = FORCE_CONFUSION; 2059 tmp->subtype = FORCE_CONFUSION;
2101 tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); 2060 tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100);
2102 tmp->name = "confusion"; 2061 tmp->name = "confusion";
2103 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); 2062 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
2063
2104 if (tmp->duration > maxduration) 2064 if (tmp->duration > maxduration)
2105 tmp->duration = maxduration; 2065 tmp->duration = maxduration;
2106 2066
2107 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) 2067 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED))
2108 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); 2068 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!");
2069
2109 SET_FLAG (op, FLAG_CONFUSED); 2070 SET_FLAG (op, FLAG_CONFUSED);
2110} 2071}
2111 2072
2112void 2073void
2113blind_player (object *op, object *hitter, int dam) 2074blind_player (object *op, object *hitter, int dam)
2179 op->speed_left = (float) -(FABS (op->speed) * max); 2140 op->speed_left = (float) -(FABS (op->speed) * max);
2180 2141
2181/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ 2142/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */
2182} 2143}
2183 2144
2184
2185/* Attempts to kill 'op'. hitter is the attack object, dam is 2145/* Attempts to kill 'op'. hitter is the attack object, dam is
2186 * the computed damaged. 2146 * the computed damaged.
2187 */ 2147 */
2188void 2148void
2189deathstrike_player (object *op, object *hitter, int *dam) 2149deathstrike_player (object *op, object *hitter, int *dam)
2197 ** field of the deathstriking object */ 2157 ** field of the deathstriking object */
2198 2158
2199 int atk_lev, def_lev, kill_lev; 2159 int atk_lev, def_lev, kill_lev;
2200 2160
2201 if (hitter->slaying) 2161 if (hitter->slaying)
2202 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, undead_name)) || (op->race && strstr (hitter->slaying, op->race)))) 2162 if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, shstr_undead)) || (op->race && strstr (hitter->slaying, op->race))))
2203 return; 2163 return;
2204 2164
2205 def_lev = op->level; 2165 def_lev = op->level;
2206 if (def_lev < 1) 2166 if (def_lev < 1)
2207 { 2167 {
2208 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name); 2168 LOG (llevError, "BUG: arch %s with level < 1 (%s)\n", &op->arch->archname, op->debug_desc ());
2209 def_lev = 1; 2169 def_lev = 1;
2210 } 2170 }
2171
2211 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; 2172 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2212 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2173 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2213 atk_lev, def_lev); */ 2174 atk_lev, def_lev); */
2214 2175
2215 if (atk_lev >= def_lev) 2176 if (atk_lev >= def_lev)
2230 */ 2191 */
2231 *dam *= kill_lev / def_lev; 2192 *dam *= kill_lev / def_lev;
2232 } 2193 }
2233 } 2194 }
2234 else 2195 else
2235 {
2236 *dam = 0; /* no harm done */ 2196 *dam = 0; /* no harm done */
2237 }
2238} 2197}
2239 2198
2240/* thrown_item_effect() - handles any special effects of thrown 2199/* thrown_item_effect() - handles any special effects of thrown
2241 * items (like attacking living creatures--a potion thrown at a 2200 * items (like attacking living creatures--a potion thrown at a
2242 * monster). 2201 * monster).
2271 } 2230 }
2272 } 2231 }
2273} 2232}
2274 2233
2275/* adj_attackroll() - adjustments to attacks by various conditions */ 2234/* adj_attackroll() - adjustments to attacks by various conditions */
2276
2277int 2235int
2278adj_attackroll (object *hitter, object *target) 2236adj_attackroll (object *hitter, object *target)
2279{ 2237{
2280 object *attacker = hitter; 2238 object *attacker = hitter;
2281 int adjust = 0; 2239 int adjust = 0;
2308 { 2266 {
2309 /* target is unseen */ 2267 /* target is unseen */
2310 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) 2268 if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND))
2311 adjust -= 10; 2269 adjust -= 10;
2312 /* dark map penalty for the hitter (lacks infravision if we got here). */ 2270 /* dark map penalty for the hitter (lacks infravision if we got here). */
2313 else if (target->map && target->map->darkness > 0 && !stand_in_light (target)) 2271 else if (target->map && target->map->darklevel () > 0 && !stand_in_light (target))
2314 adjust -= target->map->darkness; 2272 adjust -= target->map->darklevel ();
2315 } 2273 }
2316 2274
2317 if (QUERY_FLAG (attacker, FLAG_SCARED)) 2275 if (QUERY_FLAG (attacker, FLAG_SCARED))
2318 adjust -= 3; 2276 adjust -= 3;
2319 2277
2346#endif 2304#endif
2347 2305
2348 return adjust; 2306 return adjust;
2349} 2307}
2350 2308
2351
2352/* determine if the object is an 'aimed' missile */ 2309/* determine if the object is an 'aimed' missile */
2353int 2310int
2354is_aimed_missile (object *op) 2311is_aimed_missile (object *op)
2355{ 2312{
2356 2313
2357 /* I broke what used to be one big if into a few nested 2314 /* I broke what used to be one big if into a few nested
2358 * ones so that figuring out the logic is at least possible. 2315 * ones so that figuring out the logic is at least possible.
2359 */ 2316 */
2360 if (op && (op->move_type & MOVE_FLYING)) 2317 if (op && (op->move_type & MOVE_FLYING))
2361 {
2362 if (op->type == ARROW || op->type == THROWN_OBJ) 2318 if (op->type == ARROW || op->type == THROWN_OBJ)
2363 return 1; 2319 return 1;
2364 else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION)) 2320 else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION))
2365 return 1; 2321 return 1;
2366 } 2322
2367 return 0; 2323 return 0;
2368} 2324}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines