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.24 by root, Sat Dec 9 16:11:09 2006 UTC vs.
Revision 1.51 by root, Thu Mar 15 14:23:02 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23#include <assert.h> 24#include <assert.h>
24#include <global.h> 25#include <global.h>
25#include <living.h> 26#include <living.h>
26#include <material.h> 27#include <material.h>
27#include <skills.h> 28#include <skills.h>
44 * its magical benefits. 45 * its magical benefits.
45 */ 46 */
46void 47void
47cancellation (object *op) 48cancellation (object *op)
48{ 49{
49 object *tmp;
50
51 if (op->invisible) 50 if (op->invisible)
52 return; 51 return;
53 52
54 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) 53 if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ)
55 { 54 {
56 /* Recur through the inventory */ 55 /* Recurse through the inventory */
57 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 56 for (object *tmp = op->inv; tmp; tmp = tmp->below)
58 if (!did_make_save_item (tmp, AT_CANCELLATION, op)) 57 if (!did_make_save_item (tmp, AT_CANCELLATION, op))
59 cancellation (tmp); 58 cancellation (tmp);
60 } 59 }
61 else if (FABS (op->magic) <= (rndm (0, 5))) 60 else if (FABS (op->magic) <= rndm (0, 5))
62 { 61 {
63 /* Nullify this object. This code could probably be more complete */ 62 /* Nullify this object. This code could probably be more complete */
64 /* in what abilities it should cancel */ 63 /* in what abilities it should cancel */
65 op->magic = 0; 64 op->magic = 0;
65
66 CLEAR_FLAG (op, FLAG_DAMNED); 66 CLEAR_FLAG (op, FLAG_DAMNED);
67 CLEAR_FLAG (op, FLAG_CURSED); 67 CLEAR_FLAG (op, FLAG_CURSED);
68 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 68 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
69 CLEAR_FLAG (op, FLAG_KNOWN_CURSED); 69 CLEAR_FLAG (op, FLAG_KNOWN_CURSED);
70
70 if (op->env && op->env->type == PLAYER) 71 if (op->env && op->env->type == PLAYER)
71 {
72 esrv_send_item (op->env, op); 72 esrv_send_item (op->env, op);
73 }
74 } 73 }
75} 74}
76
77
78 75
79/* did_make_save_item just checks to make sure the item actually 76/* did_make_save_item just checks to make sure the item actually
80 * made its saving throw based on the tables. It does not take 77 * made its saving throw based on the tables. It does not take
81 * any further action (like destroying the item). 78 * any further action (like destroying the item).
82 */ 79 */
83
84int 80int
85did_make_save_item (object *op, int type, object *originator) 81did_make_save_item (object *op, int type, object *originator)
86{ 82{
87 int i, roll, saves = 0, attacks = 0, number; 83 int i, roll, saves = 0, attacks = 0, number;
88 materialtype_t *mt; 84 materialtype_t *mt;
89 85
90 if (op->materialname == NULL) 86 if (op->materialname == NULL)
91 { 87 {
92 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next) 88 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next)
93 {
94 if (op->material & mt->material) 89 if (op->materials & mt->material)
95 break; 90 break;
96 }
97 } 91 }
98 else 92 else
99 mt = name_to_material (op->materialname); 93 mt = name_to_material (op->materialname);
94
100 if (mt == NULL) 95 if (mt == NULL)
101 return TRUE; 96 return TRUE;
97
102 roll = rndm (1, 20); 98 roll = rndm (1, 20);
103 99
104 /* the attacktypes have no meaning for object saves 100 /* the attacktypes have no meaning for object saves
105 * If the type is only magic, don't adjust type - basically, if 101 * If the type is only magic, don't adjust type - basically, if
106 * pure magic is hitting an object, it should save. However, if it 102 * pure magic is hitting an object, it should save. However, if it
135 saves++; 131 saves++;
136 } 132 }
137 133
138 if (saves == attacks || attacks == 0) 134 if (saves == attacks || attacks == 0)
139 return TRUE; 135 return TRUE;
136
140 if ((saves == 0) || (rndm (1, attacks) > saves)) 137 if (saves == 0 || (rndm (1, attacks) > saves))
141 return FALSE; 138 return FALSE;
139
142 return TRUE; 140 return TRUE;
143} 141}
144 142
145/* This function calls did_make_save_item. It then performs the 143/* This function calls did_make_save_item. It then performs the
146 * appropriate actions to the item (such as burning the item up, 144 * appropriate actions to the item (such as burning the item up,
147 * calling cancellation, etc.) 145 * calling cancellation, etc.)
148 */ 146 */
149
150void 147void
151save_throw_object (object *op, int type, object *originator) 148save_throw_object (object *op, int type, object *originator)
152{ 149{
153 if (!did_make_save_item (op, type, originator)) 150 if (!did_make_save_item (op, type, originator))
154 { 151 {
212 } 209 }
213 else 210 else
214 { 211 {
215 if (op->env) 212 if (op->env)
216 { 213 {
217 object *tmp = is_player_inv (op->env); 214 object *tmp = op->in_player ();
218 215
219 if (tmp) 216 if (tmp)
220 esrv_del_item (tmp->contr, op->count); 217 esrv_del_item (tmp->contr, op->count);
221 } 218 }
222 219
223 if (!QUERY_FLAG (op, FLAG_REMOVED)) 220 op->destroy ();
224 remove_ob (op);
225
226 free_object (op);
227 } 221 }
228 222
229 if (type & (AT_FIRE | AT_ELECTRICITY)) 223 if (type & (AT_FIRE | AT_ELECTRICITY))
230 if (env) 224 if (env)
231 { 225 {
264 tmp->move_slow = 0; 258 tmp->move_slow = 0;
265 insert_ob_in_map (tmp, op->map, originator, 0); 259 insert_ob_in_map (tmp, op->map, originator, 0);
266 } 260 }
267 261
268 if (!QUERY_FLAG (op, FLAG_REMOVED)) 262 if (!QUERY_FLAG (op, FLAG_REMOVED))
269 remove_ob (op); 263 op->remove ();
270 264
271 insert_ob_in_ob (op, tmp); 265 insert_ob_in_ob (op, tmp);
272 return; 266 return;
273 } 267 }
274} 268}
281 */ 275 */
282 276
283int 277int
284hit_map (object *op, int dir, int type, int full_hit) 278hit_map (object *op, int dir, int type, int full_hit)
285{ 279{
286 object *tmp, *next;
287 maptile *map; 280 maptile *map;
288 sint16 x, y; 281 sint16 x, y;
289 int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ 282 int retflag = 0; /* added this flag.. will return 1 if it hits a monster */
290 283
291 if (QUERY_FLAG (op, FLAG_FREED)) 284 if (QUERY_FLAG (op, FLAG_FREED))
311 304
312 map = op->map; 305 map = op->map;
313 x = op->x + freearr_x[dir]; 306 x = op->x + freearr_x[dir];
314 y = op->y + freearr_y[dir]; 307 y = op->y + freearr_y[dir];
315 308
316 int mflags = get_map_flags (map, &map, x, y, &x, &y); 309 if (!xy_normalise (map, x, y))
310 return 0;
317 311
318 // elmex: a safe map tile can't be hit! 312 // elmex: a safe map tile can't be hit!
319 // this should prevent most harmful effects on items and players there. 313 // this should prevent most harmful effects on items and players there.
320 if (mflags & (P_OUT_OF_MAP | P_SAFE)) 314 mapspace &ms = map->at (x, y);
315
316 if (ms.flags () & P_SAFE)
321 return 0; 317 return 0;
322 318
323 /* peterm: a few special cases for special attacktypes --counterspell 319 /* peterm: a few special cases for special attacktypes --counterspell
324 * must be out here because it strikes things which are not alive 320 * must be out here because it strikes things which are not alive
325 */ 321 */
326 322 if (type & (AT_COUNTERSPELL | AT_CHAOS))
323 {
327 if (type & AT_COUNTERSPELL) 324 if (type & AT_COUNTERSPELL)
328 { 325 {
329 counterspell (op, dir); /* see spell_effect.c */ 326 counterspell (op, dir); /* see spell_effect.c */
330 327
331 /* If the only attacktype is counterspell or magic, don't need 328 /* If the only attacktype is counterspell or magic, don't need
332 * to do any further processing. 329 * to do any further processing.
333 */
334 if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC)))
335 return 0;
336
337 type &= ~AT_COUNTERSPELL;
338 }
339
340 if (type & AT_CHAOS)
341 {
342 shuffle_attack (op, 1); /*1 flag tells it to change the face */
343 update_object (op, UP_OBJ_FACE);
344 type &= ~AT_CHAOS;
345 }
346
347 next = get_map_ob (map, x, y);
348
349 while (next)
350 {
351 if (next->destroyed ())
352 {
353 /* There may still be objects that were above 'next', but there is no
354 * simple way to find out short of copying all object references and
355 * tags into a temporary array before we start processing the first
356 * object. That's why we just abort.
357 *
358 * This happens whenever attack spells (like fire) hit a pile
359 * of objects. This is not a bug - nor an error. The errormessage
360 * below was spamming the logs for absolutely no reason.
361 */ 330 */
362 /* LOG (llevDebug, "hit_map(): next object destroyed\n"); */ 331 if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC)))
363 break; 332 return 0;
333
334 type &= ~AT_COUNTERSPELL;
335 }
336
337 if (type & AT_CHAOS)
364 } 338 {
339 shuffle_attack (op, 1); /* flag tells it to change the face */
340 update_object (op, UP_OBJ_FACE);
341 type &= ~AT_CHAOS;
342 }
343 }
365 344
345 /* There may still be objects that were above 'next', but there is no
346 * simple way to find out short of copying all object references and
347 * tags into a temporary array before we start processing the first
348 * object. That's why we just abort on destroy.
349 *
350 * This happens whenever attack spells (like fire) hit a pile
351 * of objects. This is not a bug - nor an error.
352 */
353 for (object *next = ms.bot; next && !next->destroyed (); )
354 {
366 tmp = next; 355 object *tmp = next;
367 next = tmp->above; 356 next = tmp->above;
368
369 if (tmp->destroyed ())
370 {
371 LOG (llevError, "BUG: hit_map(): found freed object\n");
372 break;
373 }
374 357
375 /* Something could have happened to 'tmp' while 'tmp->below' was processed. 358 /* Something could have happened to 'tmp' while 'tmp->below' was processed.
376 * For example, 'tmp' was put in an icecube. 359 * For example, 'tmp' was put in an icecube.
377 * This is one of the few cases where on_same_map should not be used. 360 * This is one of the few cases where on_same_map should not be used.
378 */ 361 */
381 364
382 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 365 if (QUERY_FLAG (tmp, FLAG_ALIVE))
383 { 366 {
384 hit_player (tmp, op->stats.dam, op, type, full_hit); 367 hit_player (tmp, op->stats.dam, op, type, full_hit);
385 retflag |= 1; 368 retflag |= 1;
369
386 if (op->destroyed ()) 370 if (op->destroyed ())
387 break; 371 break;
388 } 372 }
389
390 /* Here we are potentially destroying an object. If the object has 373 /* Here we are potentially destroying an object. If the object has
391 * NO_PASS set, it is also immune - you can't destroy walls. Note 374 * NO_PASS set, it is also immune - you can't destroy walls. Note
392 * that weak walls have is_alive set, which prevent objects from 375 * that weak walls have is_alive set, which prevent objects from
393 * passing over/through them. We don't care what type of movement 376 * passing over/through them. We don't care what type of movement
394 * the wall blocks - if it blocks any type of movement, can't be 377 * the wall blocks - if it blocks any type of movement, can't be
395 * destroyed right now. 378 * destroyed right now.
396 */ 379 */
397 else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block) 380 else if (tmp->materialname && op->stats.dam > 0 && !tmp->move_block)
398 { 381 {
399 save_throw_object (tmp, type, op); 382 save_throw_object (tmp, type, op);
383
400 if (op->destroyed ()) 384 if (op->destroyed ())
401 break; 385 break;
402 } 386 }
403 } 387 }
404 388
435 sprintf (buf1, "missed %s", &op->name); 419 sprintf (buf1, "missed %s", &op->name);
436 sprintf (buf2, " misses"); 420 sprintf (buf2, " misses");
437 found++; 421 found++;
438 } 422 }
439 else if ((hitter->type == DISEASE || hitter->type == SYMPTOM || 423 else if ((hitter->type == DISEASE || hitter->type == SYMPTOM ||
440 hitter->type == POISONING || (type & AT_POISON && IS_LIVE (op))) && !found) 424 hitter->type == POISONING || (type & AT_POISON && op->is_alive ())) && !found)
441 { 425 {
442 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++) 426 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_SUFFER][i].level != -1; i++)
443 if (dam < attack_mess[ATM_SUFFER][i].level || attack_mess[ATM_SUFFER][i + 1].level == -1) 427 if (dam < attack_mess[ATM_SUFFER][i].level || attack_mess[ATM_SUFFER][i + 1].level == -1)
444 { 428 {
445 sprintf (buf1, "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, &op->name, attack_mess[ATM_SUFFER][i].buf2); 429 sprintf (buf1, "%s %s%s", attack_mess[ATM_SUFFER][i].buf1, &op->name, attack_mess[ATM_SUFFER][i].buf2);
457 strcpy (buf2, attack_mess[ATM_DOOR][i].buf3); 441 strcpy (buf2, attack_mess[ATM_DOOR][i].buf3);
458 found++; 442 found++;
459 break; 443 break;
460 } 444 }
461 } 445 }
462 else if (hitter->type == PLAYER && IS_LIVE (op)) 446 else if (hitter->type == PLAYER && op->is_alive ())
463 { 447 {
464 if (USING_SKILL (hitter, SK_KARATE)) 448 if (USING_SKILL (hitter, SK_KARATE))
465 { 449 {
466 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++) 450 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_KARATE][i].level != -1; i++)
467 if (dam < attack_mess[ATM_KARATE][i].level || attack_mess[ATM_KARATE][i + 1].level == -1) 451 if (dam < attack_mess[ATM_KARATE][i].level || attack_mess[ATM_KARATE][i + 1].level == -1)
493 found++; 477 found++;
494 break; 478 break;
495 } 479 }
496 } 480 }
497 } 481 }
482
498 if (found) 483 if (found)
499 { 484 {
500 /* done */ 485 /* done */
501 } 486 }
502 else if (IS_ARROW (hitter) && (type == AT_PHYSICAL || type == AT_MAGIC)) 487 else if (hitter->is_arrow () && (type == AT_PHYSICAL || type == AT_MAGIC))
503 { 488 {
504 sprintf (buf1, "hit"); /* just in case */ 489 sprintf (buf1, "hit"); /* just in case */
505 for (i = 0; i < MAXATTACKMESS; i++) 490 for (i = 0; i < MAXATTACKMESS; i++)
506 if (dam < attack_mess[ATM_ARROW][i].level || attack_mess[ATM_ARROW][i + 1].level == -1) 491 if (dam < attack_mess[ATM_ARROW][i].level || attack_mess[ATM_ARROW][i + 1].level == -1)
507 { 492 {
508 strcpy (buf2, attack_mess[ATM_ARROW][i].buf3); 493 strcpy (buf2, attack_mess[ATM_ARROW][i].buf3);
509 found++; 494 found++;
510 break; 495 break;
511 } 496 }
512 } 497 }
513 else if (type & AT_DRAIN && IS_LIVE (op)) 498 else if (type & AT_DRAIN && op->is_alive ())
514 { 499 {
515 /* drain is first, because some items have multiple attypes */ 500 /* drain is first, because some items have multiple attypes */
516 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++) 501 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_DRAIN][i].level != -1; i++)
517 if (dam < attack_mess[ATM_DRAIN][i].level || attack_mess[ATM_DRAIN][i + 1].level == -1) 502 if (dam < attack_mess[ATM_DRAIN][i].level || attack_mess[ATM_DRAIN][i + 1].level == -1)
518 { 503 {
520 strcpy (buf2, attack_mess[ATM_DRAIN][i].buf3); 505 strcpy (buf2, attack_mess[ATM_DRAIN][i].buf3);
521 found++; 506 found++;
522 break; 507 break;
523 } 508 }
524 } 509 }
525 else if (type & AT_ELECTRICITY && IS_LIVE (op)) 510 else if (type & AT_ELECTRICITY && op->is_alive ())
526 { 511 {
527 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++) 512 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_ELEC][i].level != -1; i++)
528 if (dam < attack_mess[ATM_ELEC][i].level || attack_mess[ATM_ELEC][i + 1].level == -1) 513 if (dam < attack_mess[ATM_ELEC][i].level || attack_mess[ATM_ELEC][i + 1].level == -1)
529 { 514 {
530 sprintf (buf1, "%s %s%s", attack_mess[ATM_ELEC][i].buf1, &op->name, attack_mess[ATM_ELEC][i].buf2); 515 sprintf (buf1, "%s %s%s", attack_mess[ATM_ELEC][i].buf1, &op->name, attack_mess[ATM_ELEC][i].buf2);
531 strcpy (buf2, attack_mess[ATM_ELEC][i].buf3); 516 strcpy (buf2, attack_mess[ATM_ELEC][i].buf3);
532 found++; 517 found++;
533 break; 518 break;
534 } 519 }
535 } 520 }
536 else if (type & AT_COLD && IS_LIVE (op)) 521 else if (type & AT_COLD && op->is_alive ())
537 { 522 {
538 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++) 523 for (i = 0; i < MAXATTACKMESS && attack_mess[ATM_COLD][i].level != -1; i++)
539 if (dam < attack_mess[ATM_COLD][i].level || attack_mess[ATM_COLD][i + 1].level == -1) 524 if (dam < attack_mess[ATM_COLD][i].level || attack_mess[ATM_COLD][i + 1].level == -1)
540 { 525 {
541 sprintf (buf1, "%s %s%s", attack_mess[ATM_COLD][i].buf1, &op->name, attack_mess[ATM_COLD][i].buf2); 526 sprintf (buf1, "%s %s%s", attack_mess[ATM_COLD][i].buf1, &op->name, attack_mess[ATM_COLD][i].buf2);
618 strcpy (buf1, "hit"); 603 strcpy (buf1, "hit");
619 strcpy (buf2, " hits"); 604 strcpy (buf2, " hits");
620 } 605 }
621 606
622 /* bail out if a monster is casting spells */ 607 /* bail out if a monster is casting spells */
623 if (!(hitter->type == PLAYER || (get_owner (hitter) != NULL && hitter->owner->type == PLAYER))) 608 if (!(hitter->type == PLAYER || (hitter->owner != NULL && hitter->owner->type == PLAYER)))
624 return; 609 return;
625 610
626 /* scale down magic considerably. */ 611 /* scale down magic considerably. */
627 if (type & AT_MAGIC && rndm (0, 5)) 612 if (type & AT_MAGIC && rndm (0, 5))
628 return; 613 return;
629 614
630 /* Did a player hurt another player? Inform both! */ 615 /* Did a player hurt another player? Inform both! */
631 if (op->type == PLAYER && (get_owner (hitter) == NULL ? hitter->type : hitter->owner->type) == PLAYER) 616 if (op->type == PLAYER && (hitter->owner == NULL ? hitter->type : hitter->owner->type) == PLAYER)
632 { 617 {
633 if (get_owner (hitter) != NULL) 618 if (hitter->owner != NULL)
634 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2); 619 sprintf (buf, "%s's %s%s you.", &hitter->owner->name, &hitter->name, buf2);
635 else 620 else
636 { 621 {
637 sprintf (buf, "%s%s you.", &hitter->name, buf2); 622 sprintf (buf, "%s%s you.", &hitter->name, buf2);
638 if (dam != 0) 623 if (dam != 0)
660 else 645 else
661 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS3, 0, 0); 646 play_sound_player_only (hitter->contr, SOUND_PLAYER_HITS3, 0, 0);
662 } 647 }
663 new_draw_info (NDI_BLACK, 0, hitter, buf); 648 new_draw_info (NDI_BLACK, 0, hitter, buf);
664 } 649 }
665 else if (get_owner (hitter) != NULL && hitter->owner->type == PLAYER) 650 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
666 { 651 {
667 /* look for stacked spells and start reducing the message chances */ 652 /* look for stacked spells and start reducing the message chances */
668 if (hitter->type == SPELL_EFFECT && (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE)) 653 if (hitter->type == SPELL_EFFECT && (hitter->subtype == SP_EXPLOSION || hitter->subtype == SP_BULLET || hitter->subtype == SP_CONE))
669 { 654 {
670 i = 4; 655 i = 4;
671 map = hitter->map; 656 map = hitter->map;
672 if (out_of_map (map, hitter->x, hitter->y)) 657 if (out_of_map (map, hitter->x, hitter->y))
673 return; 658 return;
674 next = get_map_ob (map, hitter->x, hitter->y); 659 next = GET_MAP_OB (map, hitter->x, hitter->y);
675 if (next) 660 if (next)
676 while (next) 661 while (next)
677 { 662 {
678 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) 663 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE))
679 i *= 3; 664 i *= 3;
769 * which then gets here again. By decreasing the speed before 754 * which then gets here again. By decreasing the speed before
770 * we call process_object, the 'if' statement above will fail. 755 * we call process_object, the 'if' statement above will fail.
771 */ 756 */
772 op->speed_left--; 757 op->speed_left--;
773 process_object (op); 758 process_object (op);
759
774 if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack)) 760 if (op->destroyed () || hitter->destroyed () || abort_attack (op, hitter, simple_attack))
775 goto error; 761 goto error;
776 } 762 }
777 763
778 op_name = op->name; 764 op_name = op->name;
791 if (settings.casting_time == TRUE) 777 if (settings.casting_time == TRUE)
792 { 778 {
793 if ((hitter->type == PLAYER) && (hitter->casting_time > -1)) 779 if ((hitter->type == PLAYER) && (hitter->casting_time > -1))
794 { 780 {
795 hitter->casting_time = -1; 781 hitter->casting_time = -1;
796 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost " "your spell!"); 782 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost your spell!");
797 } 783 }
798 if ((op->casting_time > -1) && (hitdam > 0)) 784 if ((op->casting_time > -1) && (hitdam > 0))
799 { 785 {
800 op->casting_time = -1; 786 op->casting_time = -1;
801 if (op->type == PLAYER) 787 if (op->type == PLAYER)
802 { 788 {
803 new_draw_info (NDI_UNIQUE, 0, op, "You were hit and lost " "your spell!"); 789 new_draw_info (NDI_UNIQUE, 0, op, "You were hit and lost your spell!");
804 new_draw_info_format (NDI_ALL | NDI_UNIQUE, 5, NULL, "%s was hit by %s and lost a spell.", &op_name, &hitter->name); 790 new_draw_info_format (NDI_ALL | NDI_UNIQUE, 5, NULL, "%s was hit by %s and lost a spell.", &op_name, &hitter->name);
805 } 791 }
806 } 792 }
807 } 793 }
808 if (!simple_attack) 794 if (!simple_attack)
813 if (QUERY_FLAG (op, FLAG_SLEEP)) 799 if (QUERY_FLAG (op, FLAG_SLEEP))
814 CLEAR_FLAG (op, FLAG_SLEEP); 800 CLEAR_FLAG (op, FLAG_SLEEP);
815 801
816 /* If the victim can't see the attacker, it may alert others 802 /* If the victim can't see the attacker, it may alert others
817 * for help. */ 803 * for help. */
818 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !get_owner (op) && rndm (0, op->stats.Int)) 804 if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int))
819 npc_call_help (op); 805 npc_call_help (op);
820 806
821 /* if you were hidden and hit by a creature, you are discovered */ 807 /* if you were hidden and hit by a creature, you are discovered */
822 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) 808 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE))
823 { 809 {
830 * when they hit the victim. For things like thrown daggers, 816 * when they hit the victim. For things like thrown daggers,
831 * this sets 'hitter' to the actual dagger, and not the 817 * this sets 'hitter' to the actual dagger, and not the
832 * wrapper object. 818 * wrapper object.
833 */ 819 */
834 thrown_item_effect (hitter, op); 820 thrown_item_effect (hitter, op);
821
835 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) 822 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack))
836 goto leave; 823 goto leave;
837 } 824 }
838 825
839 /* Need to do at least 1 damage, otherwise there is no point 826 /* Need to do at least 1 damage, otherwise there is no point
906 if (op->weight <= 5000 && tmp->stats.hp >= 0) 893 if (op->weight <= 5000 && tmp->stats.hp >= 0)
907 { 894 {
908 if (tmp->head != NULL) 895 if (tmp->head != NULL)
909 tmp = tmp->head; 896 tmp = tmp->head;
910 897
911 remove_ob (op); 898 op->remove ();
912 op = insert_ob_in_ob (op, tmp); 899 op = insert_ob_in_ob (op, tmp);
913 900
914 if (tmp->type == PLAYER) 901 if (tmp->type == PLAYER)
915 esrv_send_item (tmp, op); 902 esrv_send_item (tmp, op);
916 903
935 /* Disassemble missile */ 922 /* Disassemble missile */
936 if (op->inv) 923 if (op->inv)
937 { 924 {
938 container = op; 925 container = op;
939 hitter = op->inv; 926 hitter = op->inv;
940 remove_ob (hitter); 927 hitter->remove ();
941 insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON); 928 insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON);
942 /* Note that we now have an empty THROWN_OBJ on the map. Code that 929 /* Note that we now have an empty THROWN_OBJ on the map. Code that
943 * might be called until this THROWN_OBJ is either reassembled or 930 * might be called until this THROWN_OBJ is either reassembled or
944 * removed at the end of this function must be able to deal with empty 931 * removed at the end of this function must be able to deal with empty
945 * THROWN_OBJs. */ 932 * THROWN_OBJs. */
961 */ 948 */
962 if (hitter->destroyed () || hitter->env != NULL) 949 if (hitter->destroyed () || hitter->env != NULL)
963 { 950 {
964 if (container) 951 if (container)
965 { 952 {
966 remove_ob (container); 953 container->remove ();
967 free_object (container); 954 container->destroy ();
968 } 955 }
969 956
970 return 0; 957 return 0;
971 } 958 }
972 959
982 hitter = fix_stopped_arrow (hitter); 969 hitter = fix_stopped_arrow (hitter);
983 if (!hitter) 970 if (!hitter)
984 return 0; 971 return 0;
985 } 972 }
986 else 973 else
987 { 974 container->destroy ();
988 remove_ob (container);
989 free_object (container);
990 }
991 975
992 /* Try to stick arrow into victim */ 976 /* Try to stick arrow into victim */
993 if (!victim->destroyed () && stick_arrow (hitter, victim)) 977 if (!victim->destroyed () && stick_arrow (hitter, victim))
994 return 0; 978 return 0;
995 979
1000 * can fly over but not otherwise move over. What is the correct 984 * can fly over but not otherwise move over. What is the correct
1001 * way to handle those otherwise? 985 * way to handle those otherwise?
1002 */ 986 */
1003 if (victim->x != hitter->x || victim->y != hitter->y) 987 if (victim->x != hitter->x || victim->y != hitter->y)
1004 { 988 {
1005 remove_ob (hitter); 989 hitter->remove ();
1006 hitter->x = victim->x; 990 hitter->x = victim->x;
1007 hitter->y = victim->y; 991 hitter->y = victim->y;
1008 insert_ob_in_map (hitter, victim->map, hitter, 0); 992 insert_ob_in_map (hitter, victim->map, hitter, 0);
1009 } 993 }
1010 else 994 else
1018 op->speed -= 1.0; 1002 op->speed -= 1.0;
1019 1003
1020 /* Missile missed victim - reassemble missile */ 1004 /* Missile missed victim - reassemble missile */
1021 if (container) 1005 if (container)
1022 { 1006 {
1023 remove_ob (hitter); 1007 hitter->remove ();
1024 insert_ob_in_ob (hitter, container); 1008 insert_ob_in_ob (hitter, container);
1025 } 1009 }
1026 1010
1027 return op; 1011 return op;
1028} 1012}
1040 } 1024 }
1041 else if (!GET_ANIM_ID (op)) 1025 else if (!GET_ANIM_ID (op))
1042 { 1026 {
1043 /* Object has been called - no animations, so remove it */ 1027 /* Object has been called - no animations, so remove it */
1044 if (op->stats.hp < 0) 1028 if (op->stats.hp < 0)
1029 op->destroy ();
1045 { 1030
1046 remove_ob (op); /* Should update LOS */
1047 free_object (op);
1048 /* Don't know why this is here - remove_ob should do it for us */
1049 /*update_position(m, x, y); */
1050 }
1051 return; /* no animations, so nothing more to do */ 1031 return; /* no animations, so nothing more to do */
1052 } 1032 }
1033
1053 perc = NUM_ANIMATIONS (op) - ((int) NUM_ANIMATIONS (op) * op->stats.hp) / op->stats.maxhp; 1034 perc = NUM_ANIMATIONS (op) - ((int) NUM_ANIMATIONS (op) * op->stats.hp) / op->stats.maxhp;
1035
1054 if (perc >= (int) NUM_ANIMATIONS (op)) 1036 if (perc >= (int) NUM_ANIMATIONS (op))
1055 perc = NUM_ANIMATIONS (op) - 1; 1037 perc = NUM_ANIMATIONS (op) - 1;
1056 else if (perc < 1) 1038 else if (perc < 1)
1057 perc = 1; 1039 perc = 1;
1040
1058 SET_ANIMATION (op, perc); 1041 SET_ANIMATION (op, perc);
1059 update_object (op, UP_OBJ_FACE); 1042 update_object (op, UP_OBJ_FACE);
1043
1060 if (perc == NUM_ANIMATIONS (op) - 1) 1044 if (perc == NUM_ANIMATIONS (op) - 1)
1061 { /* Reached the last animation */ 1045 { /* Reached the last animation */
1062 if (op->face == blank_face) 1046 if (op->face == blank_face)
1063 {
1064 /* If the last face is blank, remove the ob */ 1047 /* If the last face is blank, remove the ob */
1065 remove_ob (op); /* Should update LOS */ 1048 op->destroy ();
1066 free_object (op);
1067
1068 /* remove_ob should call update_position for us */
1069 /*update_position(m, x, y); */
1070
1071 }
1072 else 1049 else
1073 { /* The last face was not blank, leave an image */ 1050 { /* The last face was not blank, leave an image */
1074 CLEAR_FLAG (op, FLAG_BLOCKSVIEW); 1051 CLEAR_FLAG (op, FLAG_BLOCKSVIEW);
1075 update_all_los (op->map, op->x, op->y); 1052 update_all_los (op->map, op->x, op->y);
1076 op->move_block = 0; 1053 op->move_block = 0;
1080} 1057}
1081 1058
1082void 1059void
1083scare_creature (object *target, object *hitter) 1060scare_creature (object *target, object *hitter)
1084{ 1061{
1085 object *owner = get_owner (hitter); 1062 object *owner = hitter->owner;
1086 1063
1087 if (!owner) 1064 if (!owner)
1088 owner = hitter; 1065 owner = hitter;
1089 1066
1090 SET_FLAG (target, FLAG_SCARED); 1067 SET_FLAG (target, FLAG_SCARED);
1097 * appropriate attacktype. Only 1 attacktype should be set at a time. 1074 * appropriate attacktype. Only 1 attacktype should be set at a time.
1098 * This doesn't damage the player, but returns how much it should 1075 * This doesn't damage the player, but returns how much it should
1099 * take. However, it will do other effects (paralyzation, slow, etc.) 1076 * take. However, it will do other effects (paralyzation, slow, etc.)
1100 * Note - changed for PR code - we now pass the attack number and not 1077 * Note - changed for PR code - we now pass the attack number and not
1101 * the attacktype. Makes it easier for the PR code. */ 1078 * the attacktype. Makes it easier for the PR code. */
1102
1103int 1079int
1104hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic) 1080hit_player_attacktype (object *op, object *hitter, int dam, uint32 attacknum, int magic)
1105{ 1081{
1106
1107 int doesnt_slay = 1; 1082 int doesnt_slay = 1;
1108 1083
1109 /* Catch anyone that may be trying to send us a bitmask instead of the number */ 1084 /* Catch anyone that may be trying to send us a bitmask instead of the number */
1110 if (attacknum >= NROFATTACKS) 1085 if (attacknum >= NROFATTACKS)
1111 { 1086 {
1113 return 0; 1088 return 0;
1114 } 1089 }
1115 1090
1116 if (dam < 0) 1091 if (dam < 0)
1117 { 1092 {
1118 LOG (llevError, "hit_player_attacktype called with negative damage: %d\n", dam); 1093 LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n", dam, hitter->debug_desc (), op->debug_desc2 ());
1119 return 0; 1094 return 0;
1120 } 1095 }
1121 1096
1122 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so 1097 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so
1123 * people can't mess with that or it otherwise get confused. */ 1098 * people can't mess with that or it otherwise get confused. */
1156 1131
1157 /* Keep this in order - makes things easier to find */ 1132 /* Keep this in order - makes things easier to find */
1158 1133
1159 switch (attacknum) 1134 switch (attacknum)
1160 { 1135 {
1161 case ATNR_PHYSICAL: 1136 case ATNR_PHYSICAL:
1162 /* here also check for diseases */ 1137 /* here also check for diseases */
1163 check_physically_infect (op, hitter); 1138 check_physically_infect (op, hitter);
1164 break; 1139 break;
1165 1140
1166 /* Don't need to do anything for: 1141 /* Don't need to do anything for:
1167 magic, 1142 magic,
1168 fire, 1143 fire,
1169 electricity, 1144 electricity,
1170 cold */ 1145 cold */
1171 1146
1172 case ATNR_CONFUSION: 1147 case ATNR_CONFUSION:
1173 case ATNR_POISON: 1148 case ATNR_POISON:
1174 case ATNR_SLOW: 1149 case ATNR_SLOW:
1175 case ATNR_PARALYZE: 1150 case ATNR_PARALYZE:
1176 case ATNR_FEAR: 1151 case ATNR_FEAR:
1177 case ATNR_CANCELLATION: 1152 case ATNR_CANCELLATION:
1178 case ATNR_DEPLETE: 1153 case ATNR_DEPLETE:
1179 case ATNR_BLIND: 1154 case ATNR_BLIND:
1180 { 1155 {
1181 /* chance for inflicting a special attack depends on the 1156 /* chance for inflicting a special attack depends on the
1182 * difference between attacker's and defender's level 1157 * difference between attacker's and defender's level
1183 */ 1158 */
1184 int level_diff = MIN (110, MAX (0, op->level - hitter->level)); 1159 int level_diff = MIN (110, MAX (0, op->level - hitter->level));
1185 1160
1186 /* First, only creatures/players with speed can be affected. 1161 /* First, only creatures/players with speed can be affected.
1187 * Second, just getting hit doesn't mean it always affects 1162 * Second, just getting hit doesn't mean it always affects
1188 * you. Third, you still get a saving through against the 1163 * you. Third, you still get a saving through against the
1189 * effect. 1164 * effect.
1190 */ 1165 */
1191 if (op->speed && 1166 if (op->speed &&
1192 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && 1167 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1193 !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) 1168 !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) && !did_make_save (op, level_diff, op->resist[attacknum] / 10))
1194 { 1169 {
1195 1170
1196 /* Player has been hit by something */ 1171 /* Player has been hit by something */
1197 if (attacknum == ATNR_CONFUSION) 1172 if (attacknum == ATNR_CONFUSION)
1198 confuse_player (op, hitter, dam); 1173 confuse_player (op, hitter, dam);
1199 else if (attacknum == ATNR_POISON) 1174 else if (attacknum == ATNR_POISON)
1200 poison_player (op, hitter, dam); 1175 poison_player (op, hitter, dam);
1201 else if (attacknum == ATNR_SLOW) 1176 else if (attacknum == ATNR_SLOW)
1202 slow_player (op, hitter, dam); 1177 slow_player (op, hitter, dam);
1203 else if (attacknum == ATNR_PARALYZE) 1178 else if (attacknum == ATNR_PARALYZE)
1204 paralyze_player (op, hitter, dam); 1179 paralyze_player (op, hitter, dam);
1205 else if (attacknum == ATNR_FEAR) 1180 else if (attacknum == ATNR_FEAR)
1206 scare_creature (op, hitter); 1181 scare_creature (op, hitter);
1207 else if (attacknum == ATNR_CANCELLATION) 1182 else if (attacknum == ATNR_CANCELLATION)
1208 cancellation (op); 1183 cancellation (op);
1209 else if (attacknum == ATNR_DEPLETE) 1184 else if (attacknum == ATNR_DEPLETE)
1210 drain_stat (op); 1185 op->drain_stat ();
1211 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) 1186 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR))
1212 blind_player (op, hitter, dam); 1187 blind_player (op, hitter, dam);
1213 } 1188 }
1214 dam = 0; /* These are all effects and don't do real damage */ 1189 dam = 0; /* These are all effects and don't do real damage */
1215 } 1190 }
1216 break; 1191 break;
1192
1217 case ATNR_ACID: 1193 case ATNR_ACID:
1218 { 1194 {
1219 int flag = 0; 1195 int flag = 0;
1220 1196
1221 /* Items only get corroded if you're not on a battleground and 1197 /* Items only get corroded if you're not on a battleground and
1222 * if your acid resistance is below 50%. */ 1198 * if your acid resistance is below 50%. */
1223 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50)) 1199 if (!op_on_battleground (op, NULL, NULL) && (op->resist[ATNR_ACID] < 50))
1224 { 1200 {
1225 object *tmp;
1226
1227 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1201 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1228 { 1202 {
1229 if (tmp->invisible) 1203 if (tmp->invisible)
1230 continue; 1204 continue;
1231 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 1205 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1232 /* >= 10% acid res. on itmes will protect these */ 1206 /* >= 10% acid res. on items will protect these */
1233 continue; 1207 continue;
1234 if (!(tmp->material & M_IRON)) 1208 if (!(tmp->materials & M_IRON))
1235 continue; 1209 continue;
1236 if (tmp->magic < -4) /* Let's stop at -5 */ 1210 if (tmp->magic < -4) /* Let's stop at -5 */
1237 continue; 1211 continue;
1238 if (tmp->type == RING || 1212 if (tmp->type == RING
1239 /* removed boots and gloves from exclusion list in 1213 /* removed boots and gloves from exclusion list in PR */
1240 PR */ 1214 || tmp->type == GIRDLE
1241 tmp->type == GIRDLE || tmp->type == AMULET || tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1215 || tmp->type == AMULET
1216 || tmp->type == WAND
1217 || tmp->type == ROD
1218 || tmp->type == HORN)
1242 continue; /* To avoid some strange effects */ 1219 continue; /* To avoid some strange effects */
1243 1220
1244 /* High damage acid has better chance of corroding 1221 /* High damage acid has better chance of corroding
1245 objects */ 1222 objects */
1246 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic) 1223 if (rndm (0, dam + 4) > random_roll (0, 39, op, PREFER_HIGH) + 2 * tmp->magic)
1247 { 1224 {
1248 if (op->type == PLAYER) 1225 if (op->type == PLAYER)
1249 /* Make this more visible */ 1226 /* Make this more visible */
1250 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, 1227 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op,
1251 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp)); 1228 "The %s's acid corrodes your %s!", query_name (hitter), query_name (tmp));
1252 flag = 1; 1229 flag = 1;
1253 tmp->magic--; 1230 tmp->magic--;
1254 if (op->type == PLAYER) 1231 if (op->type == PLAYER)
1255 esrv_send_item (op, tmp); 1232 esrv_send_item (op, tmp);
1256 } 1233 }
1257 } 1234 }
1258 if (flag)
1259 fix_player (op); /* Something was corroded */
1260 } 1235
1236 if (flag)
1237 op->update_stats (); /* Something was corroded */
1261 } 1238 }
1239 }
1262 break; 1240 break;
1241
1263 case ATNR_DRAIN: 1242 case ATNR_DRAIN:
1264 { 1243 {
1265 /* rate is the proportion of exp drained. High rate means 1244 /* rate is the proportion of exp drained. High rate means
1266 * not much is drained, low rate means a lot is drained. 1245 * not much is drained, low rate means a lot is drained.
1267 */ 1246 */
1268 int rate; 1247 int rate;
1269 1248
1270 if (op->resist[ATNR_DRAIN] >= 0) 1249 if (op->resist[ATNR_DRAIN] >= 0)
1271 rate = 400 + op->resist[ATNR_DRAIN] * 3; 1250 rate = 400 + op->resist[ATNR_DRAIN] * 3;
1272 else 1251 else
1273 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 1252 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
1274 1253
1275 if (op->stats.exp <= rate) 1254 if (op->stats.exp <= rate)
1276 { 1255 {
1277 if (op->type == GOLEM) 1256 if (op->type == GOLEM)
1278 dam = 999; /* Its force is "sucked" away. 8) */ 1257 dam = 999; /* Its force is "sucked" away. 8) */
1279 else 1258 else
1280 /* If we can't drain, lets try to do physical damage */ 1259 /* If we can't drain, lets try to do physical damage */
1281 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); 1260 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
1282 } 1261 }
1283 else 1262 else
1284 { 1263 {
1285 /* Randomly give the hitter some hp */ 1264 /* Randomly give the hitter some hp */
1286 if (hitter->stats.hp < hitter->stats.maxhp && 1265 if (hitter->stats.hp < hitter->stats.maxhp &&
1287 (op->level > hitter->level) && random_roll (0, (op->level - hitter->level + 2), hitter, PREFER_HIGH) > 3) 1266 (op->level > hitter->level) && random_roll (0, (op->level - hitter->level + 2), hitter, PREFER_HIGH) > 3)
1288 hitter->stats.hp++; 1267 hitter->stats.hp++;
1289 1268
1290 /* Can't do drains on battleground spaces. 1269 /* Can't do drains on battleground spaces.
1291 * Move the wiz check up here - before, the hitter wouldn't gain exp 1270 * Move the wiz check up here - before, the hitter wouldn't gain exp
1292 * exp, but the wiz would still lose exp! If drainee is a wiz, 1271 * exp, but the wiz would still lose exp! If drainee is a wiz,
1293 * nothing happens. 1272 * nothing happens.
1294 * Try to credit the owner. We try to display player -> player drain 1273 * Try to credit the owner. We try to display player -> player drain
1295 * attacks, hence all the != PLAYER checks. 1274 * attacks, hence all the != PLAYER checks.
1296 */ 1275 */
1297 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WAS_WIZ)) 1276 if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WAS_WIZ))
1298 { 1277 {
1299 object *owner = get_owner (hitter); 1278 object *owner = hitter->owner;
1300 1279
1301 if (owner && owner != hitter) 1280 if (owner && owner != hitter)
1302 { 1281 {
1303 if (op->type != PLAYER || owner->type != PLAYER) 1282 if (op->type != PLAYER || owner->type != PLAYER)
1304 change_exp (owner, op->stats.exp / (rate * 2), 1283 change_exp (owner, op->stats.exp / (rate * 2),
1305 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); 1284 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL);
1306 } 1285 }
1307 else if (op->type != PLAYER || hitter->type != PLAYER) 1286 else if (op->type != PLAYER || hitter->type != PLAYER)
1308 { 1287 {
1309 change_exp (hitter, op->stats.exp / (rate * 2), 1288 change_exp (hitter, op->stats.exp / (rate * 2),
1310 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 1289 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1311 } 1290 }
1312 change_exp (op, -op->stats.exp / rate, NULL, 0); 1291 change_exp (op, -op->stats.exp / rate, NULL, 0);
1313 } 1292 }
1293
1314 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure 1294 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
1315 * drain attack, you won't know that you are actually sucking out EXP, 1295 * drain attack, you won't know that you are actually sucking out EXP,
1316 * as the messages will say you missed 1296 * as the messages will say you missed
1317 */ 1297 */
1318 } 1298 }
1319 } 1299 }
1320 break; 1300 break;
1301
1321 case ATNR_TURN_UNDEAD: 1302 case ATNR_TURN_UNDEAD:
1322 { 1303 {
1323 if (QUERY_FLAG (op, FLAG_UNDEAD)) 1304 if (QUERY_FLAG (op, FLAG_UNDEAD))
1324 { 1305 {
1325 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1306 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1326 object *god = find_god (determine_god (owner)); 1307 object *god = find_god (determine_god (owner));
1327 int div = 1; 1308 int div = 1;
1328 1309
1329 /* if undead are not an enemy of your god, you turn them 1310 /* if undead are not an enemy of your god, you turn them
1330 * at half strength */ 1311 * at half strength */
1331 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1312 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1332 div = 2; 1313 div = 2;
1333 /* Give a bonus if you resist turn undead */ 1314 /* Give a bonus if you resist turn undead */
1334 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) 1315 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1335 scare_creature (op, owner); 1316 scare_creature (op, owner);
1336 } 1317 }
1337 else 1318 else
1338 dam = 0; /* don't damage non undead - should we damage 1319 dam = 0; /* don't damage non undead - should we damage
1339 undead? */ 1320 undead? */
1340 } 1321 }
1341 break; 1322 break;
1323
1342 case ATNR_DEATH: 1324 case ATNR_DEATH:
1343 deathstrike_player (op, hitter, &dam); 1325 deathstrike_player (op, hitter, &dam);
1344 break; 1326 break;
1327
1345 case ATNR_CHAOS: 1328 case ATNR_CHAOS:
1346 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", query_name (op), query_name (hitter)); 1329 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc2 ());
1347 dam = 0; 1330 dam = 0;
1348 break; 1331 break;
1332
1349 case ATNR_COUNTERSPELL: 1333 case ATNR_COUNTERSPELL:
1350 LOG (llevError, "%s was hit by %s with counterspell attack.\n", query_name (op), query_name (hitter)); 1334 LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc2 ());
1351 dam = 0; 1335 dam = 0;
1352 /* This should never happen. Counterspell is handled 1336 /* This should never happen. Counterspell is handled
1353 * seperately and filtered out. If this does happen, 1337 * seperately and filtered out. If this does happen,
1354 * Counterspell has no effect on anything but spells, so it 1338 * Counterspell has no effect on anything but spells, so it
1355 * does no damage. */ 1339 * does no damage. */
1356 break; 1340 break;
1341
1357 case ATNR_HOLYWORD: 1342 case ATNR_HOLYWORD:
1358 { 1343 {
1359 /* This has already been handled by hit_player, 1344 /* This has already been handled by hit_player,
1360 * no need to check twice -- DAMN */ 1345 * no need to check twice -- DAMN */
1361 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1346 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1362 1347
1363 /* As with turn undead above, give a bonus on the saving throw */ 1348 /* As with turn undead above, give a bonus on the saving throw */
1364 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis]) 1349 if ((op->level + (op->resist[ATNR_HOLYWORD] / 100)) < owner->level + turn_bonus[owner->stats.Wis])
1365 scare_creature (op, owner); 1350 scare_creature (op, owner);
1366 } 1351 }
1367 break; 1352 break;
1353
1368 case ATNR_LIFE_STEALING: 1354 case ATNR_LIFE_STEALING:
1369 { 1355 {
1370 int new_hp; 1356 int new_hp;
1371 1357
1372 /* this is replacement to drain for players, instead of taking 1358 /* this is replacement to drain for players, instead of taking
1373 * exp it takes hp. It is geared for players, probably not 1359 * exp it takes hp. It is geared for players, probably not
1374 * much use giving it to monsters 1360 * much use giving it to monsters
1375 * 1361 *
1376 * life stealing doesn't do a lot of damage, but it gives the 1362 * life stealing doesn't do a lot of damage, but it gives the
1377 * damage it does do to the player. Given that, 1363 * damage it does do to the player. Given that,
1378 * it only does 1/10'th normal damage (hence the divide by 1364 * it only does 1/10'th normal damage (hence the divide by
1379 * 1000). 1365 * 1000).
1380 */ 1366 */
1381 /* You can't steal life from something undead */ 1367 /* You can't steal life from something undead */
1382 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) 1368 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD)))
1383 return 0; 1369 return 0;
1370
1384 /* If drain protection is higher than life stealing, use that */ 1371 /* If drain protection is higher than life stealing, use that */
1385 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 1372 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1386 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; 1373 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;
1387 else 1374 else
1388 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000; 1375 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000;
1376
1389 /* You die at -1 hp, not zero. */ 1377 /* You die at -1 hp, not zero. */
1390 if (dam > (op->stats.hp + 1)) 1378 if (dam > (op->stats.hp + 1))
1391 dam = op->stats.hp + 1; 1379 dam = op->stats.hp + 1;
1380
1392 new_hp = hitter->stats.hp + dam; 1381 new_hp = hitter->stats.hp + dam;
1393 if (new_hp > hitter->stats.maxhp) 1382 if (new_hp > hitter->stats.maxhp)
1394 new_hp = hitter->stats.maxhp; 1383 new_hp = hitter->stats.maxhp;
1384
1395 if (new_hp > hitter->stats.hp) 1385 if (new_hp > hitter->stats.hp)
1396 hitter->stats.hp = new_hp; 1386 hitter->stats.hp = new_hp;
1397 } 1387 }
1398 } 1388 }
1389
1399 return dam; 1390 return dam;
1400} 1391}
1401
1402 1392
1403/* GROS: This code comes from hit_player. It has been made external to 1393/* GROS: This code comes from hit_player. It has been made external to
1404 * allow script procedures to "kill" objects in a combat-like fashion. 1394 * allow script procedures to "kill" objects in a combat-like fashion.
1405 * It was initially used by (kill-object) developed for the Collector's 1395 * It was initially used by (kill-object) developed for the Collector's
1406 * Sword. Note that nothing has been changed from the original version 1396 * Sword. Note that nothing has been changed from the original version
1441 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) 1431 if (QUERY_FLAG (op, FLAG_BLOCKSVIEW))
1442 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ 1432 update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */
1443 1433
1444 if (op->type == DOOR) 1434 if (op->type == DOOR)
1445 { 1435 {
1446 op->speed = 0.1; 1436 op->set_speed (0.1);
1447 update_ob_speed (op);
1448 op->speed_left = -0.05; 1437 op->speed_left = -0.05;
1449 return maxdam; 1438 return maxdam;
1450 } 1439 }
1451 1440
1452 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1441 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1453 { 1442 {
1454 remove_friendly_object (op); 1443 remove_friendly_object (op);
1455 1444
1456 if (get_owner (op) && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op) 1445 if (op->owner && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op)
1457 op->owner->contr->ranges[range_golem] = 0; 1446 op->owner->contr->ranges[range_golem] = 0;
1458 1447
1459 remove_ob (op); 1448 op->destroy ();
1460 free_object (op);
1461 return maxdam; 1449 return maxdam;
1462 } 1450 }
1463 1451
1464 /* Now lets start dealing with experience we get for killing something */ 1452 /* Now lets start dealing with experience we get for killing something */
1465 1453
1466 owner = get_owner (hitter); 1454 owner = hitter->owner;
1467 if (!owner) 1455 if (!owner)
1468 owner = hitter; 1456 owner = hitter;
1469 1457
1470 /* is the victim (op) standing on battleground? */ 1458 /* is the victim (op) standing on battleground? */
1471 if (op_on_battleground (op, NULL, NULL)) 1459 if (op_on_battleground (op, NULL, NULL))
1492 char buf[256]; 1480 char buf[256];
1493 1481
1494 tmv = localtime (&t); 1482 tmv = localtime (&t);
1495 strftime (buf, 256, "%a %b %d %H:%M:%S %Y", tmv); 1483 strftime (buf, 256, "%a %b %d %H:%M:%S %Y", tmv);
1496 1484
1497 LOG (llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, &owner->name, owner->contr->socket.host, query_name (op)); 1485 LOG (llevInfo, "%s PLAYER_KILL_PLAYER: %s (%s) killed %s\n", buf, &owner->name, owner->contr->ns->host, query_name (op));
1498 } 1486 }
1499 1487
1500 /* try to filter some things out - basically, if you are 1488 /* try to filter some things out - basically, if you are
1501 * killing a level 1 creature and your level 20, you 1489 * killing a level 1 creature and your level 20, you
1502 * probably don't want to see that. 1490 * probably don't want to see that.
1520 * player that the object belonged to - so if you killed another player 1508 * player that the object belonged to - so if you killed another player
1521 * with spells, pets, whatever, there was no penalty. 1509 * with spells, pets, whatever, there was no penalty.
1522 * Changed to make luck penalty configurable in settings. 1510 * Changed to make luck penalty configurable in settings.
1523 */ 1511 */
1524 if (op->type == PLAYER && owner != op && !battleg) 1512 if (op->type == PLAYER && owner != op && !battleg)
1525 change_luck (owner, -settings.pk_luck_penalty); 1513 owner->change_luck (-settings.pk_luck_penalty);
1526 1514
1527 /* This code below deals with finding the appropriate skill 1515 /* This code below deals with finding the appropriate skill
1528 * to credit exp to. This is a bit problematic - we should 1516 * to credit exp to. This is a bit problematic - we should
1529 * probably never really have to look at current_weapon->skill 1517 * probably never really have to look at current_weapon->skill
1530 */ 1518 */
1541 skill = owner->current_weapon->skill; 1529 skill = owner->current_weapon->skill;
1542 else 1530 else
1543 LOG (llevError, "kill_object - unable to find skill that killed monster\n"); 1531 LOG (llevError, "kill_object - unable to find skill that killed monster\n");
1544 1532
1545 /* We have the skill we want to credit to - now find the object this goes 1533 /* We have the skill we want to credit to - now find the object this goes
1546 * to. Make sure skop is an actual skill, and not a skill tool! 1534 * to. Make sure skop is an actual skill, and not a skill tool!
1547 */ 1535 */
1548 if ((!skop || skop->type != SKILL) && skill) 1536 if ((!skop || skop->type != SKILL) && skill)
1549 { 1537 {
1550 int i; 1538 int i;
1551 1539
1614 if (owner->type != PLAYER || owner->contr->party == NULL) 1602 if (owner->type != PLAYER || owner->contr->party == NULL)
1615 change_exp (owner, exp, skill, 0); 1603 change_exp (owner, exp, skill, 0);
1616 else 1604 else
1617 { 1605 {
1618 int shares = 0, count = 0; 1606 int shares = 0, count = 0;
1619 player *pl;
1620 partylist *party = owner->contr->party; 1607 partylist *party = owner->contr->party;
1621 1608
1622#ifdef PARTY_KILL_LOG
1623 add_kill_to_party (party, query_name (owner), query_name (op), exp); 1609 add_kill_to_party (party, query_name (owner), query_name (op), exp);
1624#endif 1610
1625 for (pl = first_player; pl != NULL; pl = pl->next) 1611 for_all_players (pl)
1626 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner)) 1612 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner))
1627 { 1613 {
1628 count++; 1614 count++;
1629 shares += (pl->ob->level + 4); 1615 shares += (pl->ob->level + 4);
1630 } 1616 }
1633 change_exp (owner, exp, skill, SK_EXP_TOTAL); 1619 change_exp (owner, exp, skill, SK_EXP_TOTAL);
1634 else 1620 else
1635 { 1621 {
1636 int share = exp / shares, given = 0, nexp; 1622 int share = exp / shares, given = 0, nexp;
1637 1623
1638 for (pl = first_player; pl != NULL; pl = pl->next) 1624 for_all_players (pl)
1639 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner)) 1625 if (party && pl->ob->contr->party == party && on_same_map (pl->ob, owner))
1640 { 1626 {
1641 nexp = (pl->ob->level + 4) * share; 1627 nexp = (pl->ob->level + 4) * share;
1642 change_exp (pl->ob, nexp, skill, SK_EXP_TOTAL); 1628 change_exp (pl->ob, nexp, skill, SK_EXP_TOTAL);
1643 given += nexp; 1629 given += nexp;
1652 1638
1653 if (op->type != PLAYER) 1639 if (op->type != PLAYER)
1654 { 1640 {
1655 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 1641 if (QUERY_FLAG (op, FLAG_FRIENDLY))
1656 { 1642 {
1657 object *owner1 = get_owner (op); 1643 object *owner1 = op->owner;
1658 1644
1659 if (owner1 && owner1->type == PLAYER) 1645 if (owner1 && owner1->type == PLAYER)
1660 { 1646 {
1661 play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0); 1647 play_sound_player_only (owner1->contr, SOUND_PET_IS_KILLED, 0, 0);
1662 /* Maybe we should include the owner that killed this, maybe not */ 1648 /* Maybe we should include the owner that killed this, maybe not */
1664 } 1650 }
1665 1651
1666 remove_friendly_object (op); 1652 remove_friendly_object (op);
1667 } 1653 }
1668 1654
1669 remove_ob (op); 1655 op->destroy ();
1670 free_object (op);
1671 } 1656 }
1672 else 1657 else
1673 { 1658 {
1674 /* Player has been killed! */ 1659 /* Player has been killed! */
1675 if (owner->type == PLAYER) 1660 if (owner->type == PLAYER)
1705 return 0; 1690 return 0;
1706 1691
1707 if (hitter->type == PLAYER && hitter->contr->peaceful == 1) 1692 if (hitter->type == PLAYER && hitter->contr->peaceful == 1)
1708 return 1; 1693 return 1;
1709 1694
1710 if ((owner = get_owner (hitter)) != NULL) 1695 if ((owner = hitter->owner) != NULL)
1711 { 1696 {
1712 if (owner->type == PLAYER && owner->contr->peaceful == 1) 1697 if (owner->type == PLAYER && owner->contr->peaceful == 1)
1713 friendlyfire = 2; 1698 friendlyfire = 2;
1714 } 1699 }
1715 1700
1725 * is what is hitting the object, type is the attacktype, and 1710 * is what is hitting the object, type is the attacktype, and
1726 * full_hit is set if monster area does not matter. 1711 * full_hit is set if monster area does not matter.
1727 * dam is base damage - protections/vulnerabilities/slaying matches can 1712 * dam is base damage - protections/vulnerabilities/slaying matches can
1728 * modify it. 1713 * modify it.
1729 */ 1714 */
1730
1731 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1715/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1732 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1716 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1733
1734int 1717int
1735hit_player (object *op, int dam, object *hitter, int type, int full_hit) 1718hit_player (object *op, int dam, object *hitter, int type, int full_hit)
1736{ 1719{
1737 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); 1720 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC);
1738 int maxattacktype, attacknum; 1721 int maxattacktype, attacknum;
1749 return 0; 1732 return 0;
1750 1733
1751#ifdef PROHIBIT_PLAYERKILL 1734#ifdef PROHIBIT_PLAYERKILL
1752 if (op->type == PLAYER) 1735 if (op->type == PLAYER)
1753 { 1736 {
1754 object *owner = get_owner (hitter); 1737 object *owner = hitter->owner;
1755 1738
1756 if (!owner) 1739 if (!owner)
1757 owner = hitter; 1740 owner = hitter;
1758 1741
1759 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner) 1742 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner)
1781 } 1764 }
1782 } 1765 }
1783 1766
1784 if (!simple_attack && op->type == DOOR) 1767 if (!simple_attack && op->type == DOOR)
1785 { 1768 {
1786 object *tmp;
1787
1788 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1769 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1789 if (tmp->type == RUNE || tmp->type == TRAP) 1770 if (tmp->type == RUNE || tmp->type == TRAP)
1790 { 1771 {
1791 spring_trap (tmp, hitter); 1772 spring_trap (tmp, hitter);
1773
1792 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) 1774 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack))
1793 return 0; 1775 return 0;
1776
1794 break; 1777 break;
1795 } 1778 }
1796 } 1779 }
1797 1780
1798 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1781 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1799 { 1782 {
1800 /* FIXME: If a player is killed by a rune in a door, the 1783 /* FIXME: If a player is killed by a rune in a door, the
1801 * destroyed() check above doesn't return, and might get here. 1784 * destroyed() check above doesn't return, and might get here.
1802 */ 1785 */
1803 LOG (llevDebug, "victim (arch %s, name %s) already dead in " "hit_player()\n", &op->arch->name, &op->name); 1786 LOG (llevDebug, "victim %s already dead in hit_player()\n", op->debug_desc ());
1804 return 0; 1787 return 0;
1805 } 1788 }
1806 1789
1807#ifdef ATTACK_DEBUG 1790#ifdef ATTACK_DEBUG
1808 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); 1791 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1814 * in case 0>dam>1, we try to "simulate" a float value-effect */ 1797 * in case 0>dam>1, we try to "simulate" a float value-effect */
1815 dam = dam * (100 - op->resist[ATNR_MAGIC]); 1798 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1816 if (dam >= 100) 1799 if (dam >= 100)
1817 dam /= 100; 1800 dam /= 100;
1818 else 1801 else
1819 dam = (dam > (rndm (0, 99))) ? 1 : 0; 1802 dam = (dam > rndm (0, 99)) ? 1 : 0;
1820 } 1803 }
1821 1804
1822 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map 1805 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map
1823 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit 1806 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit
1824 */ 1807 */
1844 (hitter->title != NULL 1827 (hitter->title != NULL
1845 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL))) 1828 && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, undead_name) != NULL)))
1846 return 0; 1829 return 0;
1847 } 1830 }
1848 1831
1849 maxattacktype = type; /* initialize this to something */ 1832 maxattacktype = type; /* initialise this to something */
1850 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) 1833 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum)
1851 { 1834 {
1852 /* Magic isn't really a true attack type - it gets combined with other 1835 /* Magic isn't really a true attack type - it gets combined with other
1853 * attack types. As such, skip it over. However, if magic is 1836 * attack types. As such, skip it over. However, if magic is
1854 * the only attacktype in the group, then still attack with it 1837 * the only attacktype in the group, then still attack with it
1907 1890
1908 /* basically: maxdam /= area; we try to "simulate" a float 1891 /* basically: maxdam /= area; we try to "simulate" a float
1909 value-effect */ 1892 value-effect */
1910 remainder = 100 * (maxdam % area) / area; 1893 remainder = 100 * (maxdam % area) / area;
1911 maxdam /= area; 1894 maxdam /= area;
1912 if (RANDOM () % 100 < remainder) 1895 if (rndm (100) < remainder)
1913 maxdam++; 1896 maxdam++;
1914 } 1897 }
1915 1898
1916#ifdef ATTACK_DEBUG 1899#ifdef ATTACK_DEBUG
1917 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); 1900 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1918#endif 1901#endif
1919 1902
1920 if (get_owner (hitter)) 1903 if (hitter->owner)
1921 op->enemy = hitter->owner; 1904 op->enemy = hitter->owner;
1922 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1905 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1923 op->enemy = hitter; 1906 op->enemy = hitter;
1924 1907
1925 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1908 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1950 1933
1951 if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) 1934 if (QUERY_FLAG (op, FLAG_TEAR_DOWN))
1952 { 1935 {
1953 if (maxdam) 1936 if (maxdam)
1954 tear_down_wall (op); 1937 tear_down_wall (op);
1938
1955 return maxdam; /* nothing more to do for wall */ 1939 return maxdam; /* nothing more to do for wall */
1956 } 1940 }
1957 1941
1958 /* See if the creature has been killed */ 1942 /* See if the creature has been killed */
1959 rtn_kill = kill_object (op, maxdam, hitter, type); 1943 rtn_kill = kill_object (op, maxdam, hitter, type);
1967 */ 1951 */
1968 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1952 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1969 { 1953 {
1970 if (QUERY_FLAG (hitter, FLAG_FRIENDLY)) 1954 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1971 remove_friendly_object (hitter); 1955 remove_friendly_object (hitter);
1972 remove_ob (hitter); 1956
1973 free_object (hitter); 1957 hitter->destroy ();
1974 } 1958 }
1975 /* Lets handle creatures that are splitting now */ 1959 /* Lets handle creatures that are splitting now */
1976 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1960 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1977 { 1961 {
1978 int i; 1962 int i;
1979 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1963 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
1980 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); 1964 int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE);
1981 object *owner = get_owner (op); 1965 object *owner = op->owner;
1982 1966
1983 if (!op->other_arch) 1967 if (!op->other_arch)
1984 { 1968 {
1985 LOG (llevError, "SPLITTING without other_arch error.\n"); 1969 LOG (llevError, "SPLITTING without other_arch error.\n");
1986 return maxdam; 1970 return maxdam;
1987 } 1971 }
1972
1988 remove_ob (op); 1973 op->remove ();
1974
1989 for (i = 0; i < NROFNEWOBJS (op); i++) 1975 for (i = 0; i < NROFNEWOBJS (op); i++)
1990 { /* This doesn't handle op->more yet */ 1976 { /* This doesn't handle op->more yet */
1991 object *tmp = arch_to_object (op->other_arch); 1977 object *tmp = arch_to_object (op->other_arch);
1992 int j; 1978 int j;
1993 1979
1994 tmp->stats.hp = op->stats.hp; 1980 tmp->stats.hp = op->stats.hp;
1981
1995 if (friendly) 1982 if (friendly)
1996 { 1983 {
1997 SET_FLAG (tmp, FLAG_FRIENDLY);
1998 add_friendly_object (tmp); 1984 add_friendly_object (tmp);
1999 tmp->attack_movement = PETMOVE; 1985 tmp->attack_movement = PETMOVE;
1986
2000 if (owner != NULL) 1987 if (owner)
2001 set_owner (tmp, owner); 1988 tmp->set_owner (owner);
2002 } 1989 }
1990
2003 if (unaggressive) 1991 if (unaggressive)
2004 SET_FLAG (tmp, FLAG_UNAGGRESSIVE); 1992 SET_FLAG (tmp, FLAG_UNAGGRESSIVE);
1993
2005 j = find_first_free_spot (tmp, op->map, op->x, op->y); 1994 j = find_first_free_spot (tmp, op->map, op->x, op->y);
1995
2006 if (j == -1) /* No spot to put this monster */ 1996 if (j == -1) /* No spot to put this monster */
2007 free_object (tmp); 1997 tmp->destroy ();
2008 else 1998 else
2009 { 1999 {
2010 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; 2000 tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j];
2011 insert_ob_in_map (tmp, op->map, NULL, 0); 2001 insert_ob_in_map (tmp, op->map, NULL, 0);
2012 } 2002 }
2013 } 2003 }
2014 if (friendly) 2004
2015 remove_friendly_object (op); 2005 op->destroy ();
2016 free_object (op);
2017 } 2006 }
2018 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) 2007 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
2019 { 2008 hitter->destroy ();
2020 remove_ob (hitter); 2009
2021 free_object (hitter);
2022 }
2023 return maxdam; 2010 return maxdam;
2024} 2011}
2025 2012
2026 2013
2027void 2014void
2048 if (QUERY_FLAG (hitter, FLAG_ALIVE)) 2035 if (QUERY_FLAG (hitter, FLAG_ALIVE))
2049 tmp->stats.dam += hitter->level / 2; 2036 tmp->stats.dam += hitter->level / 2;
2050 else 2037 else
2051 tmp->stats.dam = dam; 2038 tmp->stats.dam = dam;
2052 2039
2053 copy_owner (tmp, hitter); /* so we get credit for poisoning kills */ 2040 tmp->set_owner (hitter); /* so we get credit for poisoning kills */
2054 if (hitter->skill && hitter->skill != tmp->skill) 2041 if (hitter->skill && hitter->skill != tmp->skill)
2055 { 2042 {
2056 tmp->skill = hitter->skill; 2043 tmp->skill = hitter->skill;
2057 } 2044 }
2058 2045
2064 tmp->stats.Con = MAX (-(dam / 4 + 1), -10); 2051 tmp->stats.Con = MAX (-(dam / 4 + 1), -10);
2065 tmp->stats.Str = MAX (-(dam / 3 + 2), -10); 2052 tmp->stats.Str = MAX (-(dam / 3 + 2), -10);
2066 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10); 2053 tmp->stats.Dex = MAX (-(dam / 6 + 1), -10);
2067 tmp->stats.Int = MAX (-dam / 7, -10); 2054 tmp->stats.Int = MAX (-dam / 7, -10);
2068 SET_FLAG (tmp, FLAG_APPLIED); 2055 SET_FLAG (tmp, FLAG_APPLIED);
2069 fix_player (op); 2056 op->update_stats ();
2070 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); 2057 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill.");
2071 } 2058 }
2072 if (hitter->type == PLAYER) 2059 if (hitter->type == PLAYER)
2073 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); 2060 new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name);
2074 else if (get_owner (hitter) != NULL && hitter->owner->type == PLAYER) 2061 else if (hitter->owner != NULL && hitter->owner->type == PLAYER)
2075 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); 2062 new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name);
2076 } 2063 }
2077 tmp->speed_left = 0; 2064 tmp->speed_left = 0;
2078 } 2065 }
2079 else 2066 else
2098 } 2085 }
2099 else 2086 else
2100 tmp->stats.food++; 2087 tmp->stats.food++;
2101 SET_FLAG (tmp, FLAG_APPLIED); 2088 SET_FLAG (tmp, FLAG_APPLIED);
2102 tmp->speed_left = 0; 2089 tmp->speed_left = 0;
2103 fix_player (op); 2090 op->update_stats ();
2104} 2091}
2105 2092
2106void 2093void
2107confuse_player (object *op, object *hitter, int dam) 2094confuse_player (object *op, object *hitter, int dam)
2108{ 2095{
2152 */ 2139 */
2153 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; 2140 tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100;
2154 2141
2155 tmp = insert_ob_in_ob (tmp, op); 2142 tmp = insert_ob_in_ob (tmp, op);
2156 change_abil (op, tmp); /* Mostly to display any messages */ 2143 change_abil (op, tmp); /* Mostly to display any messages */
2157 fix_player (op); /* This takes care of some other stuff */ 2144 op->update_stats (); /* This takes care of some other stuff */
2158 2145
2159 if (hitter->owner) 2146 if (hitter->owner)
2160 owner = get_owner (hitter); 2147 owner = hitter->owner;
2161 else 2148 else
2162 owner = hitter; 2149 owner = hitter;
2163 2150
2164 new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op)); 2151 new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op));
2165 } 2152 }
2311 } 2298 }
2312 2299
2313 /* aimed missiles use the owning object's sight */ 2300 /* aimed missiles use the owning object's sight */
2314 if (is_aimed_missile (hitter)) 2301 if (is_aimed_missile (hitter))
2315 { 2302 {
2316 if ((attacker = get_owner (hitter)) == NULL) 2303 if ((attacker = hitter->owner) == NULL)
2317 attacker = hitter; 2304 attacker = hitter;
2318 /* A player who saves but hasn't quit still could have objects 2305 /* A player who saves but hasn't quit still could have objects
2319 * owned by him - need to handle that case to avoid crashes. 2306 * owned by him - need to handle that case to avoid crashes.
2320 */ 2307 */
2321 if (QUERY_FLAG (attacker, FLAG_REMOVED)) 2308 if (QUERY_FLAG (attacker, FLAG_REMOVED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines