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.44 by root, Mon Jan 15 15:41:09 2007 UTC vs.
Revision 1.61 by root, Tue May 1 05:48:20 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 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
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 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>
23*/ 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;
84 materialtype_t *mt; 80 materialtype_t *mt;
85 81
86 if (op->materialname == NULL) 82 if (op->materialname == NULL)
87 { 83 {
88 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next) 84 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next)
89 if (op->material & mt->material) 85 if (op->materials & mt->material)
90 break; 86 break;
91 } 87 }
92 else 88 else
93 mt = name_to_material (op->materialname); 89 mt = name_to_material (op->materialname);
94 90
131 saves++; 127 saves++;
132 } 128 }
133 129
134 if (saves == attacks || attacks == 0) 130 if (saves == attacks || attacks == 0)
135 return TRUE; 131 return TRUE;
132
136 if ((saves == 0) || (rndm (1, attacks) > saves)) 133 if (saves == 0 || (rndm (1, attacks) > saves))
137 return FALSE; 134 return FALSE;
135
138 return TRUE; 136 return TRUE;
139} 137}
140 138
141/* This function calls did_make_save_item. It then performs the 139/* This function calls did_make_save_item. It then performs the
142 * appropriate actions to the item (such as burning the item up, 140 * appropriate actions to the item (such as burning the item up,
269 * op is going in direction 'dir' 267 * op is going in direction 'dir'
270 * type is the attacktype of the object. 268 * type is the attacktype of the object.
271 * full_hit is set if monster area does not matter. 269 * full_hit is set if monster area does not matter.
272 * returns 1 if it hits something, 0 otherwise. 270 * returns 1 if it hits something, 0 otherwise.
273 */ 271 */
274
275int 272int
276hit_map (object *op, int dir, int type, int full_hit) 273hit_map (object *op, int dir, int type, int full_hit)
277{ 274{
278 maptile *map; 275 maptile *map;
279 sint16 x, y; 276 sint16 x, y;
312 mapspace &ms = map->at (x, y); 309 mapspace &ms = map->at (x, y);
313 310
314 if (ms.flags () & P_SAFE) 311 if (ms.flags () & P_SAFE)
315 return 0; 312 return 0;
316 313
317 /* peterm: a few special cases for special attacktypes --counterspell 314 /* peterm: a few special cases for special attacktypes --counterspell
318 * must be out here because it strikes things which are not alive 315 * must be out here because it strikes things which are not alive
319 */ 316 */
320 if (type & (AT_COUNTERSPELL | AT_CHAOS)) 317 if (type & (AT_COUNTERSPELL | AT_CHAOS))
321 { 318 {
322 if (type & AT_COUNTERSPELL) 319 if (type & AT_COUNTERSPELL)
373 * that weak walls have is_alive set, which prevent objects from 370 * that weak walls have is_alive set, which prevent objects from
374 * passing over/through them. We don't care what type of movement 371 * passing over/through them. We don't care what type of movement
375 * the wall blocks - if it blocks any type of movement, can't be 372 * the wall blocks - if it blocks any type of movement, can't be
376 * destroyed right now. 373 * destroyed right now.
377 */ 374 */
378 else if ((tmp->material || tmp->materialname) && op->stats.dam > 0 && !tmp->move_block) 375 else if (tmp->materialname && op->stats.dam > 0 && !tmp->move_block)
379 { 376 {
380 save_throw_object (tmp, type, op); 377 save_throw_object (tmp, type, op);
381 378
382 if (op->destroyed ()) 379 if (op->destroyed ())
383 break; 380 break;
652 { 649 {
653 i = 4; 650 i = 4;
654 map = hitter->map; 651 map = hitter->map;
655 if (out_of_map (map, hitter->x, hitter->y)) 652 if (out_of_map (map, hitter->x, hitter->y))
656 return; 653 return;
654
657 next = GET_MAP_OB (map, hitter->x, hitter->y); 655 next = GET_MAP_OB (map, hitter->x, hitter->y);
658 if (next) 656 if (next)
659 while (next) 657 while (next)
660 { 658 {
661 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE)) 659 if (next->type == SPELL_EFFECT && (next->subtype == SP_EXPLOSION || next->subtype == SP_BULLET || next->subtype == SP_CONE))
662 i *= 3; 660 i *= 3;
663 tmp = next; 661 tmp = next;
664 next = tmp->above; 662 next = tmp->above;
665 } 663 }
664
666 if (i < 0) 665 if (i < 0)
667 return; 666 return;
667
668 if (rndm (0, i) != 0) 668 if (rndm (0, i) != 0)
669 return; 669 return;
670 } 670 }
671 else if (rndm (0, 5) != 0) 671 else if (rndm (0, 5) != 0)
672 return; 672 return;
673
673 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name); 674 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name);
674 play_sound_map (op->map, op->x, op->y, SOUND_PLAYER_HITS4); 675 play_sound_map (op->map, op->x, op->y, SOUND_PLAYER_HITS4);
675 new_draw_info (NDI_BLACK, 0, hitter->owner, buf); 676 new_draw_info (NDI_BLACK, 0, hitter->owner, buf);
676 } 677 }
677} 678}
772 { 773 {
773 int hitdam = base_dam; 774 int hitdam = base_dam;
774 775
775 if (settings.casting_time == TRUE) 776 if (settings.casting_time == TRUE)
776 { 777 {
777 if ((hitter->type == PLAYER) && (hitter->casting_time > -1)) 778 if (hitter->type == PLAYER && hitter->casting_time > -1)
778 { 779 {
779 hitter->casting_time = -1; 780 hitter->casting_time = -1;
780 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost your spell!"); 781 new_draw_info (NDI_UNIQUE, 0, hitter, "You attacked and lost your spell!");
781 } 782 }
783
782 if ((op->casting_time > -1) && (hitdam > 0)) 784 if (op->casting_time > -1 && hitdam > 0)
783 { 785 {
784 op->casting_time = -1; 786 op->casting_time = -1;
785 if (op->type == PLAYER) 787 if (op->type == PLAYER)
786 { 788 {
787 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!");
788 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);
789 } 791 }
790 } 792 }
791 } 793 }
794
792 if (!simple_attack) 795 if (!simple_attack)
793 { 796 {
794 /* If you hit something, the victim should *always* wake up. 797 /* If you hit something, the victim should *always* wake up.
795 * Before, invisible hitters could avoid doing this. 798 * Before, invisible hitters could avoid doing this.
796 * -b.t. */ 799 * -b.t. */
804 807
805 /* if you were hidden and hit by a creature, you are discovered */ 808 /* if you were hidden and hit by a creature, you are discovered */
806 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) 809 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE))
807 { 810 {
808 make_visible (op); 811 make_visible (op);
812
809 if (op->type == PLAYER) 813 if (op->type == PLAYER)
810 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!"); 814 new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!");
811 } 815 }
812 816
813 /* thrown items (hitter) will have various effects 817 /* thrown items (hitter) will have various effects
867} 871}
868 872
869int 873int
870attack_ob (object *op, object *hitter) 874attack_ob (object *op, object *hitter)
871{ 875{
872
873 if (hitter->head)
874 hitter = hitter->head; 876 hitter = hitter->head_ ();
877
875 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); 878 return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc);
876} 879}
877 880
878/* op is the arrow, tmp is what is stopping the arrow. 881/* op is the arrow, tmp is what is stopping the arrow.
879 * 882 *
888 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons 891 * debate - 5000 is 5 kg, so arrows, knives, and other light weapons
889 * stick around. 892 * stick around.
890 */ 893 */
891 if (op->weight <= 5000 && tmp->stats.hp >= 0) 894 if (op->weight <= 5000 && tmp->stats.hp >= 0)
892 { 895 {
893 if (tmp->head != NULL)
894 tmp = tmp->head; 896 tmp = tmp->head_ ();
895 897
896 op->remove (); 898 op->remove ();
897 op = insert_ob_in_ob (op, tmp); 899 op = insert_ob_in_ob (op, tmp);
898 900
899 if (tmp->type == PLAYER) 901 if (tmp->type == PLAYER)
1006 insert_ob_in_ob (hitter, container); 1008 insert_ob_in_ob (hitter, container);
1007 } 1009 }
1008 1010
1009 return op; 1011 return op;
1010} 1012}
1011
1012 1013
1013void 1014void
1014tear_down_wall (object *op) 1015tear_down_wall (object *op)
1015{ 1016{
1016 int perc = 0; 1017 int perc = 0;
1065 SET_FLAG (target, FLAG_SCARED); 1066 SET_FLAG (target, FLAG_SCARED);
1066 if (!target->enemy) 1067 if (!target->enemy)
1067 target->enemy = owner; 1068 target->enemy = owner;
1068} 1069}
1069 1070
1070
1071/* This returns the amount of damage hitter does to op with the 1071/* This returns the amount of damage hitter does to op with the
1072 * appropriate attacktype. Only 1 attacktype should be set at a time. 1072 * appropriate attacktype. Only 1 attacktype should be set at a time.
1073 * This doesn't damage the player, but returns how much it should 1073 * This doesn't damage the player, but returns how much it should
1074 * take. However, it will do other effects (paralyzation, slow, etc.) 1074 * take. However, it will do other effects (paralyzation, slow, etc.)
1075 * Note - changed for PR code - we now pass the attack number and not 1075 * Note - changed for PR code - we now pass the attack number and not
1086 return 0; 1086 return 0;
1087 } 1087 }
1088 1088
1089 if (dam < 0) 1089 if (dam < 0)
1090 { 1090 {
1091 LOG (llevError, "hit_player_attacktype called with negative damage: %d\n", dam); 1091 LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n",
1092 dam, hitter->debug_desc (), op->debug_desc ());
1092 return 0; 1093 return 0;
1093 } 1094 }
1094 1095
1095 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so 1096 /* AT_INTERNAL is supposed to do exactly dam. Put a case here so
1096 * people can't mess with that or it otherwise get confused. */ 1097 * people can't mess with that or it otherwise get confused. */
1097 if (attacknum == ATNR_INTERNAL) 1098 if (attacknum == ATNR_INTERNAL)
1098 return dam; 1099 return dam;
1099 1100
1100 if (hitter->slaying) 1101 if (hitter->slaying)
1101 { 1102 {
1102 if (((op->race != NULL) && strstr (hitter->slaying, op->race)) || 1103 if ((op->race && strstr (hitter->slaying, op->race))
1103 (op->arch && (op->arch->name != NULL) && strstr (op->arch->name, hitter->slaying))) 1104 || (op->arch && op->arch->name && strstr (op->arch->name, hitter->slaying)))
1104 { 1105 {
1105 doesnt_slay = 0; 1106 doesnt_slay = 0;
1106 dam *= 3; 1107 dam *= 3;
1107 } 1108 }
1108 } 1109 }
1122 /* Special hack. By default, if immune to something, you 1123 /* Special hack. By default, if immune to something, you
1123 * shouldn't need to worry. However, acid is an exception, since 1124 * shouldn't need to worry. However, acid is an exception, since
1124 * it can still damage your items. Only include attacktypes if 1125 * it can still damage your items. Only include attacktypes if
1125 * special processing is needed */ 1126 * special processing is needed */
1126 1127
1127 if ((op->resist[attacknum] >= 100) && doesnt_slay && (attacknum != ATNR_ACID)) 1128 if (op->resist[attacknum] >= 100
1129 && doesnt_slay
1130 && attacknum != ATNR_ACID)
1128 return 0; 1131 return 0;
1129 1132
1130 /* Keep this in order - makes things easier to find */ 1133 /* Keep this in order - makes things easier to find */
1131 1134
1132 switch (attacknum) 1135 switch (attacknum)
1182 else if (attacknum == ATNR_DEPLETE) 1185 else if (attacknum == ATNR_DEPLETE)
1183 op->drain_stat (); 1186 op->drain_stat ();
1184 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) 1187 else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR))
1185 blind_player (op, hitter, dam); 1188 blind_player (op, hitter, dam);
1186 } 1189 }
1190
1187 dam = 0; /* These are all effects and don't do real damage */ 1191 dam = 0; /* These are all effects and don't do real damage */
1188 } 1192 }
1189 break; 1193 break;
1190 1194
1191 case ATNR_ACID: 1195 case ATNR_ACID:
1201 if (tmp->invisible) 1205 if (tmp->invisible)
1202 continue; 1206 continue;
1203 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 1207 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1204 /* >= 10% acid res. on items will protect these */ 1208 /* >= 10% acid res. on items will protect these */
1205 continue; 1209 continue;
1206 if (!(tmp->material & M_IRON)) 1210 if (!(tmp->materials & M_IRON))
1207 continue; 1211 continue;
1208 if (tmp->magic < -4) /* Let's stop at -5 */ 1212 if (tmp->magic < -4) /* Let's stop at -5 */
1209 continue; 1213 continue;
1210 if (tmp->type == RING 1214 if (tmp->type == RING
1211 /* removed boots and gloves from exclusion list in PR */ 1215 /* removed boots and gloves from exclusion list in PR */
1280 if (op->type != PLAYER || owner->type != PLAYER) 1284 if (op->type != PLAYER || owner->type != PLAYER)
1281 change_exp (owner, op->stats.exp / (rate * 2), 1285 change_exp (owner, op->stats.exp / (rate * 2),
1282 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); 1286 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL);
1283 } 1287 }
1284 else if (op->type != PLAYER || hitter->type != PLAYER) 1288 else if (op->type != PLAYER || hitter->type != PLAYER)
1285 {
1286 change_exp (hitter, op->stats.exp / (rate * 2), 1289 change_exp (hitter, op->stats.exp / (rate * 2),
1287 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 1290 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1288 } 1291
1289 change_exp (op, -op->stats.exp / rate, NULL, 0); 1292 change_exp (op, -op->stats.exp / rate, NULL, 0);
1290 } 1293 }
1291 1294
1292 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure 1295 dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure
1293 * drain attack, you won't know that you are actually sucking out EXP, 1296 * drain attack, you won't know that you are actually sucking out EXP,
1307 1310
1308 /* if undead are not an enemy of your god, you turn them 1311 /* if undead are not an enemy of your god, you turn them
1309 * at half strength */ 1312 * at half strength */
1310 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1313 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1311 div = 2; 1314 div = 2;
1315
1312 /* Give a bonus if you resist turn undead */ 1316 /* Give a bonus if you resist turn undead */
1313 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) 1317 if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100)))
1314 scare_creature (op, owner); 1318 scare_creature (op, owner);
1315 } 1319 }
1316 else 1320 else
1322 case ATNR_DEATH: 1326 case ATNR_DEATH:
1323 deathstrike_player (op, hitter, &dam); 1327 deathstrike_player (op, hitter, &dam);
1324 break; 1328 break;
1325 1329
1326 case ATNR_CHAOS: 1330 case ATNR_CHAOS:
1327 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc2 ()); 1331 LOG (llevError, "%s was hit by %s with non-specific chaos.\n", op->debug_desc (), hitter->debug_desc ());
1328 dam = 0; 1332 dam = 0;
1329 break; 1333 break;
1330 1334
1331 case ATNR_COUNTERSPELL: 1335 case ATNR_COUNTERSPELL:
1332 LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc2 ()); 1336 LOG (llevError, "%s was hit by %s with counterspell attack.\n", op->debug_desc (), hitter->debug_desc ());
1333 dam = 0; 1337 dam = 0;
1334 /* This should never happen. Counterspell is handled 1338 /* This should never happen. Counterspell is handled
1335 * seperately and filtered out. If this does happen, 1339 * seperately and filtered out. If this does happen,
1336 * Counterspell has no effect on anything but spells, so it 1340 * Counterspell has no effect on anything but spells, so it
1337 * does no damage. */ 1341 * does no damage. */
1409 char buf[MAX_BUF]; 1413 char buf[MAX_BUF];
1410 const char *skill; 1414 const char *skill;
1411 int maxdam = 0; 1415 int maxdam = 0;
1412 int battleg = 0; /* true if op standing on battleground */ 1416 int battleg = 0; /* true if op standing on battleground */
1413 int pk = 0; /* true if op and what controls hitter are both players */ 1417 int pk = 0; /* true if op and what controls hitter are both players */
1414 object *owner = NULL; 1418 object *owner = 0;
1415 object *skop = NULL; 1419 object *skop = 0;
1416 1420
1417 if (op->stats.hp >= 0) 1421 if (op->stats.hp >= 0)
1418 return -1; 1422 return -1;
1419 1423
1420 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter))) 1424 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter)))
1436 return maxdam; 1440 return maxdam;
1437 } 1441 }
1438 1442
1439 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1443 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1440 { 1444 {
1441 remove_friendly_object (op);
1442
1443 if (op->owner && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op)
1444 op->owner->contr->ranges[range_golem] = 0;
1445
1446 op->destroy (); 1445 op->destroy ();
1447 return maxdam; 1446 return maxdam;
1448 } 1447 }
1449 1448
1450 /* Now lets start dealing with experience we get for killing something */ 1449 /* Now lets start dealing with experience we get for killing something */
1509 */ 1508 */
1510 if (op->type == PLAYER && owner != op && !battleg) 1509 if (op->type == PLAYER && owner != op && !battleg)
1511 owner->change_luck (-settings.pk_luck_penalty); 1510 owner->change_luck (-settings.pk_luck_penalty);
1512 1511
1513 /* This code below deals with finding the appropriate skill 1512 /* This code below deals with finding the appropriate skill
1514 * to credit exp to. This is a bit problematic - we should 1513 * to credit exp to. This is a bit problematic - we should
1515 * probably never really have to look at current_weapon->skill 1514 * probably never really have to look at current_weapon->skill
1516 */ 1515 */
1517 skill = 0; 1516 skill = 0;
1518 1517
1519 if (hitter->skill && hitter->type != PLAYER) 1518 if (hitter->skill && hitter->type != PLAYER)
1520 skill = hitter->skill; 1519 skill = hitter->skill;
1521 else if (owner->chosen_skill) 1520 else if (owner->chosen_skill)
1522 { 1521 {
1523 skill = owner->chosen_skill->skill;
1524 skop = owner->chosen_skill; 1522 skop = owner->chosen_skill;
1523 skill = skop->skill;
1525 } 1524 }
1526 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON)) 1525 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON))
1527 skill = owner->current_weapon->skill; 1526 skill = owner->current_weapon->skill;
1528 else 1527 else
1529 LOG (llevError, "kill_object - unable to find skill that killed monster\n"); 1528 LOG (llevError, "kill_object - unable to find skill that killed monster\n");
1530 1529
1531 /* We have the skill we want to credit to - now find the object this goes 1530 /* We have the skill we want to credit to - now find the object this goes
1532 * to. Make sure skop is an actual skill, and not a skill tool! 1531 * to. Make sure skop is an actual skill, and not a skill tool!
1533 */ 1532 */
1534 if ((!skop || skop->type != SKILL) && skill) 1533 if ((!skop || skop->type != SKILL) && skill)
1535 { 1534 {
1536 int i; 1535 int i;
1537 1536
1600 if (owner->type != PLAYER || owner->contr->party == NULL) 1599 if (owner->type != PLAYER || owner->contr->party == NULL)
1601 change_exp (owner, exp, skill, 0); 1600 change_exp (owner, exp, skill, 0);
1602 else 1601 else
1603 { 1602 {
1604 int shares = 0, count = 0; 1603 int shares = 0, count = 0;
1605 player *pl;
1606 partylist *party = owner->contr->party; 1604 partylist *party = owner->contr->party;
1607 1605
1608 add_kill_to_party (party, query_name (owner), query_name (op), exp); 1606 add_kill_to_party (party, query_name (owner), query_name (op), exp);
1609 1607
1610 for_all_players (pl) 1608 for_all_players (pl)
1669} 1667}
1670 1668
1671/* Find out if this is friendly fire (PVP and attacker is peaceful) or not 1669/* Find out if this is friendly fire (PVP and attacker is peaceful) or not
1672 * Returns 0 this is not friendly fire 1670 * Returns 0 this is not friendly fire
1673 */ 1671 */
1674
1675int 1672int
1676friendly_fire (object *op, object *hitter) 1673friendly_fire (object *op, object *hitter)
1677{ 1674{
1678 object *owner; 1675 object *owner;
1679 int friendlyfire; 1676 int friendlyfire;
1736 object *owner = hitter->owner; 1733 object *owner = hitter->owner;
1737 1734
1738 if (!owner) 1735 if (!owner)
1739 owner = hitter; 1736 owner = hitter;
1740 1737
1741 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner) 1738 if (owner->type == PLAYER
1739 && (!op_on_battleground (op, 0, 0)
1740 && (op->contr->peaceful || owner->contr->peaceful))
1741 && op != owner)
1742 return 0; 1742 return 0;
1743 } 1743 }
1744#endif 1744#endif
1745 1745
1746 if (body_attack) 1746 if (body_attack)
1780 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1780 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1781 { 1781 {
1782 /* FIXME: If a player is killed by a rune in a door, the 1782 /* FIXME: If a player is killed by a rune in a door, the
1783 * destroyed() check above doesn't return, and might get here. 1783 * destroyed() check above doesn't return, and might get here.
1784 */ 1784 */
1785
1786 /* FIXME: This for example happens when a dead door is on a mover and
1787 gets it's speed_left raised on each mover-tick.
1788 Doors are removed in a kinda funny way by giving them speed and speed_left
1789 and waiting for that to run out.
1790 */
1785 LOG (llevDebug, "victim %s already dead in hit_player()\n", op->debug_desc ()); 1791 LOG (llevDebug, "victim %s (%d) already dead in hit_player()\n", op->debug_desc (), op->stats.hp);
1786 return 0; 1792 return 0;
1787 } 1793 }
1788 1794
1789#ifdef ATTACK_DEBUG 1795#ifdef ATTACK_DEBUG
1790 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); 1796 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1796 * in case 0>dam>1, we try to "simulate" a float value-effect */ 1802 * in case 0>dam>1, we try to "simulate" a float value-effect */
1797 dam = dam * (100 - op->resist[ATNR_MAGIC]); 1803 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1798 if (dam >= 100) 1804 if (dam >= 100)
1799 dam /= 100; 1805 dam /= 100;
1800 else 1806 else
1801 dam = (dam > (rndm (0, 99))) ? 1 : 0; 1807 dam = (dam > rndm (0, 99)) ? 1 : 0;
1802 } 1808 }
1803 1809
1804 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map 1810 /* AT_CHAOS here is a weapon or monster. Spells are handled by hit_map
1805 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit 1811 * If the attacktype still has chaos, shuffle it, then clear the Chaos bit
1806 */ 1812 */
1889 1895
1890 /* basically: maxdam /= area; we try to "simulate" a float 1896 /* basically: maxdam /= area; we try to "simulate" a float
1891 value-effect */ 1897 value-effect */
1892 remainder = 100 * (maxdam % area) / area; 1898 remainder = 100 * (maxdam % area) / area;
1893 maxdam /= area; 1899 maxdam /= area;
1894 if (RANDOM () % 100 < remainder) 1900 if (rndm (100) < remainder)
1895 maxdam++; 1901 maxdam++;
1896 } 1902 }
1897 1903
1898#ifdef ATTACK_DEBUG 1904#ifdef ATTACK_DEBUG
1899 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); 1905 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1900#endif 1906#endif
1901 1907
1908 // for now, only do this for active objects, otherwise they
1909 // keep a refcount for a long time and I see no usefulness
1910 // for an non-active objetc to know its enemy.
1911 if (op->active)
1902 if (hitter->owner) 1912 if (hitter->owner)
1903 op->enemy = hitter->owner; 1913 op->enemy = hitter->owner;
1904 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1914 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1905 op->enemy = hitter; 1915 op->enemy = hitter;
1906 1916
1907 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1917 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1908 { 1918 {
1909 /* The unaggressives look after themselves 8) */ 1919 /* The unaggressives look after themselves 8) */
1910 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 1920 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
1947 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1957 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1948 * that before if the player was immune to ghosthit, the monster 1958 * that before if the player was immune to ghosthit, the monster
1949 * remained - that is no longer the case. 1959 * remained - that is no longer the case.
1950 */ 1960 */
1951 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1961 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1952 {
1953 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1954 remove_friendly_object (hitter);
1955
1956 hitter->destroy (); 1962 hitter->destroy ();
1957 } 1963
1958 /* Lets handle creatures that are splitting now */ 1964 /* Lets handle creatures that are splitting now */
1959 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1965 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1960 { 1966 {
1961 int i; 1967 int i;
1962 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1968 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
2188 op->speed_left = (float) -(FABS (op->speed) * max); 2194 op->speed_left = (float) -(FABS (op->speed) * max);
2189 2195
2190/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ 2196/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */
2191} 2197}
2192 2198
2193
2194/* Attempts to kill 'op'. hitter is the attack object, dam is 2199/* Attempts to kill 'op'. hitter is the attack object, dam is
2195 * the computed damaged. 2200 * the computed damaged.
2196 */ 2201 */
2197void 2202void
2198deathstrike_player (object *op, object *hitter, int *dam) 2203deathstrike_player (object *op, object *hitter, int *dam)
2215 if (def_lev < 1) 2220 if (def_lev < 1)
2216 { 2221 {
2217 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name); 2222 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name);
2218 def_lev = 1; 2223 def_lev = 1;
2219 } 2224 }
2225
2220 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; 2226 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2221 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2227 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2222 atk_lev, def_lev); */ 2228 atk_lev, def_lev); */
2223 2229
2224 if (atk_lev >= def_lev) 2230 if (atk_lev >= def_lev)
2239 */ 2245 */
2240 *dam *= kill_lev / def_lev; 2246 *dam *= kill_lev / def_lev;
2241 } 2247 }
2242 } 2248 }
2243 else 2249 else
2244 {
2245 *dam = 0; /* no harm done */ 2250 *dam = 0; /* no harm done */
2246 }
2247} 2251}
2248 2252
2249/* thrown_item_effect() - handles any special effects of thrown 2253/* thrown_item_effect() - handles any special effects of thrown
2250 * items (like attacking living creatures--a potion thrown at a 2254 * items (like attacking living creatures--a potion thrown at a
2251 * monster). 2255 * monster).
2355#endif 2359#endif
2356 2360
2357 return adjust; 2361 return adjust;
2358} 2362}
2359 2363
2360
2361/* determine if the object is an 'aimed' missile */ 2364/* determine if the object is an 'aimed' missile */
2362int 2365int
2363is_aimed_missile (object *op) 2366is_aimed_missile (object *op)
2364{ 2367{
2365 2368
2371 if (op->type == ARROW || op->type == THROWN_OBJ) 2374 if (op->type == ARROW || op->type == THROWN_OBJ)
2372 return 1; 2375 return 1;
2373 else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION)) 2376 else if (op->type == SPELL_EFFECT && (op->subtype == SP_BULLET || op->subtype == SP_EXPLOSION))
2374 return 1; 2377 return 1;
2375 } 2378 }
2379
2376 return 0; 2380 return 0;
2377} 2381}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines