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.48 by root, Thu Jan 18 22:20:00 2007 UTC vs.
Revision 1.62 by root, Thu May 3 09:39:56 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 *
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
271 * op is going in direction 'dir' 267 * op is going in direction 'dir'
272 * type is the attacktype of the object. 268 * type is the attacktype of the object.
273 * full_hit is set if monster area does not matter. 269 * full_hit is set if monster area does not matter.
274 * returns 1 if it hits something, 0 otherwise. 270 * returns 1 if it hits something, 0 otherwise.
275 */ 271 */
276
277int 272int
278hit_map (object *op, int dir, int type, int full_hit) 273hit_map (object *op, int dir, int type, int full_hit)
279{ 274{
280 maptile *map; 275 maptile *map;
281 sint16 x, y; 276 sint16 x, y;
314 mapspace &ms = map->at (x, y); 309 mapspace &ms = map->at (x, y);
315 310
316 if (ms.flags () & P_SAFE) 311 if (ms.flags () & P_SAFE)
317 return 0; 312 return 0;
318 313
319 /* peterm: a few special cases for special attacktypes --counterspell 314 /* peterm: a few special cases for special attacktypes --counterspell
320 * 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
321 */ 316 */
322 if (type & (AT_COUNTERSPELL | AT_CHAOS)) 317 if (type & (AT_COUNTERSPELL | AT_CHAOS))
323 { 318 {
324 if (type & AT_COUNTERSPELL) 319 if (type & AT_COUNTERSPELL)
375 * that weak walls have is_alive set, which prevent objects from 370 * that weak walls have is_alive set, which prevent objects from
376 * 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
377 * 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
378 * destroyed right now. 373 * destroyed right now.
379 */ 374 */
380 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)
381 { 376 {
382 save_throw_object (tmp, type, op); 377 save_throw_object (tmp, type, op);
383 378
384 if (op->destroyed ()) 379 if (op->destroyed ())
385 break; 380 break;
654 { 649 {
655 i = 4; 650 i = 4;
656 map = hitter->map; 651 map = hitter->map;
657 if (out_of_map (map, hitter->x, hitter->y)) 652 if (out_of_map (map, hitter->x, hitter->y))
658 return; 653 return;
654
659 next = GET_MAP_OB (map, hitter->x, hitter->y); 655 next = GET_MAP_OB (map, hitter->x, hitter->y);
660 if (next) 656 if (next)
661 while (next) 657 while (next)
662 { 658 {
663 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))
664 i *= 3; 660 i *= 3;
665 tmp = next; 661 tmp = next;
666 next = tmp->above; 662 next = tmp->above;
667 } 663 }
664
668 if (i < 0) 665 if (i < 0)
669 return; 666 return;
667
670 if (rndm (0, i) != 0) 668 if (rndm (0, i) != 0)
671 return; 669 return;
672 } 670 }
673 else if (rndm (0, 5) != 0) 671 else if (rndm (0, 5) != 0)
674 return; 672 return;
673
675 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name); 674 sprintf (buf, "Your %s%s %s.", &hitter->name, buf2, &op->name);
676 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);
677 new_draw_info (NDI_BLACK, 0, hitter->owner, buf); 676 new_draw_info (NDI_BLACK, 0, hitter->owner, buf);
678 } 677 }
679} 678}
774 { 773 {
775 int hitdam = base_dam; 774 int hitdam = base_dam;
776 775
777 if (settings.casting_time == TRUE) 776 if (settings.casting_time == TRUE)
778 { 777 {
779 if ((hitter->type == PLAYER) && (hitter->casting_time > -1)) 778 if (hitter->type == PLAYER && hitter->casting_time > -1)
780 { 779 {
781 hitter->casting_time = -1; 780 hitter->casting_time = -1;
782 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!");
783 } 782 }
783
784 if ((op->casting_time > -1) && (hitdam > 0)) 784 if (op->casting_time > -1 && hitdam > 0)
785 { 785 {
786 op->casting_time = -1; 786 op->casting_time = -1;
787 if (op->type == PLAYER) 787 if (op->type == PLAYER)
788 { 788 {
789 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!");
790 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);
791 } 791 }
792 } 792 }
793 } 793 }
794
794 if (!simple_attack) 795 if (!simple_attack)
795 { 796 {
796 /* If you hit something, the victim should *always* wake up. 797 /* If you hit something, the victim should *always* wake up.
797 * Before, invisible hitters could avoid doing this. 798 * Before, invisible hitters could avoid doing this.
798 * -b.t. */ 799 * -b.t. */
806 807
807 /* 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 */
808 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) 809 if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE))
809 { 810 {
810 make_visible (op); 811 make_visible (op);
812
811 if (op->type == PLAYER) 813 if (op->type == PLAYER)
812 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!");
813 } 815 }
814 816
815 /* thrown items (hitter) will have various effects 817 /* thrown items (hitter) will have various effects
869} 871}
870 872
871int 873int
872attack_ob (object *op, object *hitter) 874attack_ob (object *op, object *hitter)
873{ 875{
874
875 if (hitter->head)
876 hitter = hitter->head; 876 hitter = hitter->head_ ();
877
877 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);
878} 879}
879 880
880/* op is the arrow, tmp is what is stopping the arrow. 881/* op is the arrow, tmp is what is stopping the arrow.
881 * 882 *
890 * 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
891 * stick around. 892 * stick around.
892 */ 893 */
893 if (op->weight <= 5000 && tmp->stats.hp >= 0) 894 if (op->weight <= 5000 && tmp->stats.hp >= 0)
894 { 895 {
895 if (tmp->head != NULL)
896 tmp = tmp->head; 896 tmp = tmp->head_ ();
897 897
898 op->remove (); 898 op->remove ();
899 op = insert_ob_in_ob (op, tmp); 899 op = insert_ob_in_ob (op, tmp);
900 900
901 if (tmp->type == PLAYER) 901 if (tmp->type == PLAYER)
1008 insert_ob_in_ob (hitter, container); 1008 insert_ob_in_ob (hitter, container);
1009 } 1009 }
1010 1010
1011 return op; 1011 return op;
1012} 1012}
1013
1014 1013
1015void 1014void
1016tear_down_wall (object *op) 1015tear_down_wall (object *op)
1017{ 1016{
1018 int perc = 0; 1017 int perc = 0;
1067 SET_FLAG (target, FLAG_SCARED); 1066 SET_FLAG (target, FLAG_SCARED);
1068 if (!target->enemy) 1067 if (!target->enemy)
1069 target->enemy = owner; 1068 target->enemy = owner;
1070} 1069}
1071 1070
1072
1073/* 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
1074 * appropriate attacktype. Only 1 attacktype should be set at a time. 1072 * appropriate attacktype. Only 1 attacktype should be set at a time.
1075 * 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
1076 * take. However, it will do other effects (paralyzation, slow, etc.) 1074 * take. However, it will do other effects (paralyzation, slow, etc.)
1077 * 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
1088 return 0; 1086 return 0;
1089 } 1087 }
1090 1088
1091 if (dam < 0) 1089 if (dam < 0)
1092 { 1090 {
1093 LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n", dam, hitter->debug_desc (), op->debug_desc2 ()); 1091 LOG (llevError, "hit_player_attacktype called with negative damage %d (hitter %s, target %s)\n",
1092 dam, hitter->debug_desc (), op->debug_desc ());
1094 return 0; 1093 return 0;
1095 } 1094 }
1096 1095
1097 /* 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
1098 * people can't mess with that or it otherwise get confused. */ 1097 * people can't mess with that or it otherwise get confused. */
1099 if (attacknum == ATNR_INTERNAL) 1098 if (attacknum == ATNR_INTERNAL)
1100 return dam; 1099 return dam;
1101 1100
1102 if (hitter->slaying) 1101 if (hitter->slaying)
1103 { 1102 {
1104 if (((op->race != NULL) && strstr (hitter->slaying, op->race)) || 1103 if ((op->race && strstr (hitter->slaying, op->race))
1105 (op->arch && (op->arch->name != NULL) && strstr (op->arch->name, hitter->slaying))) 1104 || (op->arch && op->arch->name && strstr (op->arch->name, hitter->slaying)))
1106 { 1105 {
1107 doesnt_slay = 0; 1106 doesnt_slay = 0;
1108 dam *= 3; 1107 dam *= 3;
1109 } 1108 }
1110 } 1109 }
1124 /* Special hack. By default, if immune to something, you 1123 /* Special hack. By default, if immune to something, you
1125 * shouldn't need to worry. However, acid is an exception, since 1124 * shouldn't need to worry. However, acid is an exception, since
1126 * it can still damage your items. Only include attacktypes if 1125 * it can still damage your items. Only include attacktypes if
1127 * special processing is needed */ 1126 * special processing is needed */
1128 1127
1129 if ((op->resist[attacknum] >= 100) && doesnt_slay && (attacknum != ATNR_ACID)) 1128 if (op->resist[attacknum] >= 100
1129 && doesnt_slay
1130 && attacknum != ATNR_ACID)
1130 return 0; 1131 return 0;
1131 1132
1132 /* Keep this in order - makes things easier to find */ 1133 /* Keep this in order - makes things easier to find */
1133 1134
1134 switch (attacknum) 1135 switch (attacknum)
1184 else if (attacknum == ATNR_DEPLETE) 1185 else if (attacknum == ATNR_DEPLETE)
1185 op->drain_stat (); 1186 op->drain_stat ();
1186 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))
1187 blind_player (op, hitter, dam); 1188 blind_player (op, hitter, dam);
1188 } 1189 }
1190
1189 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 */
1190 } 1192 }
1191 break; 1193 break;
1192 1194
1193 case ATNR_ACID: 1195 case ATNR_ACID:
1203 if (tmp->invisible) 1205 if (tmp->invisible)
1204 continue; 1206 continue;
1205 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 1207 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1206 /* >= 10% acid res. on items will protect these */ 1208 /* >= 10% acid res. on items will protect these */
1207 continue; 1209 continue;
1208 if (!(tmp->material & M_IRON)) 1210 if (!(tmp->materials & M_IRON))
1209 continue; 1211 continue;
1210 if (tmp->magic < -4) /* Let's stop at -5 */ 1212 if (tmp->magic < -4) /* Let's stop at -5 */
1211 continue; 1213 continue;
1212 if (tmp->type == RING 1214 if (tmp->type == RING
1213 /* removed boots and gloves from exclusion list in PR */ 1215 /* removed boots and gloves from exclusion list in PR */
1282 if (op->type != PLAYER || owner->type != PLAYER) 1284 if (op->type != PLAYER || owner->type != PLAYER)
1283 change_exp (owner, op->stats.exp / (rate * 2), 1285 change_exp (owner, op->stats.exp / (rate * 2),
1284 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);
1285 } 1287 }
1286 else if (op->type != PLAYER || hitter->type != PLAYER) 1288 else if (op->type != PLAYER || hitter->type != PLAYER)
1287 {
1288 change_exp (hitter, op->stats.exp / (rate * 2), 1289 change_exp (hitter, op->stats.exp / (rate * 2),
1289 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 1290 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1290 } 1291
1291 change_exp (op, -op->stats.exp / rate, NULL, 0); 1292 change_exp (op, -op->stats.exp / rate, NULL, 0);
1292 } 1293 }
1293 1294
1294 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
1295 * 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,
1309 1310
1310 /* 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
1311 * at half strength */ 1312 * at half strength */
1312 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1313 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1313 div = 2; 1314 div = 2;
1315
1314 /* Give a bonus if you resist turn undead */ 1316 /* Give a bonus if you resist turn undead */
1315 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)))
1316 scare_creature (op, owner); 1318 scare_creature (op, owner);
1317 } 1319 }
1318 else 1320 else
1324 case ATNR_DEATH: 1326 case ATNR_DEATH:
1325 deathstrike_player (op, hitter, &dam); 1327 deathstrike_player (op, hitter, &dam);
1326 break; 1328 break;
1327 1329
1328 case ATNR_CHAOS: 1330 case ATNR_CHAOS:
1329 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 ());
1330 dam = 0; 1332 dam = 0;
1331 break; 1333 break;
1332 1334
1333 case ATNR_COUNTERSPELL: 1335 case ATNR_COUNTERSPELL:
1334 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 ());
1335 dam = 0; 1337 dam = 0;
1336 /* This should never happen. Counterspell is handled 1338 /* This should never happen. Counterspell is handled
1337 * seperately and filtered out. If this does happen, 1339 * seperately and filtered out. If this does happen,
1338 * Counterspell has no effect on anything but spells, so it 1340 * Counterspell has no effect on anything but spells, so it
1339 * does no damage. */ 1341 * does no damage. */
1411 char buf[MAX_BUF]; 1413 char buf[MAX_BUF];
1412 const char *skill; 1414 const char *skill;
1413 int maxdam = 0; 1415 int maxdam = 0;
1414 int battleg = 0; /* true if op standing on battleground */ 1416 int battleg = 0; /* true if op standing on battleground */
1415 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 */
1416 object *owner = NULL; 1418 object *owner = 0;
1417 object *skop = NULL; 1419 object *skop = 0;
1418 1420
1419 if (op->stats.hp >= 0) 1421 if (op->stats.hp >= 0)
1420 return -1; 1422 return -1;
1421 1423
1422 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter))) 1424 if (INVOKE_OBJECT (KILL, op, ARG_OBJECT (hitter)))
1438 return maxdam; 1440 return maxdam;
1439 } 1441 }
1440 1442
1441 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) 1443 if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER)
1442 { 1444 {
1443 remove_friendly_object (op);
1444
1445 if (op->owner && op->owner->type == PLAYER && op->owner->contr->ranges[range_golem] == op)
1446 op->owner->contr->ranges[range_golem] = 0;
1447
1448 op->destroy (); 1445 op->destroy ();
1449 return maxdam; 1446 return maxdam;
1450 } 1447 }
1451 1448
1452 /* Now lets start dealing with experience we get for killing something */ 1449 /* Now lets start dealing with experience we get for killing something */
1511 */ 1508 */
1512 if (op->type == PLAYER && owner != op && !battleg) 1509 if (op->type == PLAYER && owner != op && !battleg)
1513 owner->change_luck (-settings.pk_luck_penalty); 1510 owner->change_luck (-settings.pk_luck_penalty);
1514 1511
1515 /* This code below deals with finding the appropriate skill 1512 /* This code below deals with finding the appropriate skill
1516 * to credit exp to. This is a bit problematic - we should 1513 * to credit exp to. This is a bit problematic - we should
1517 * probably never really have to look at current_weapon->skill 1514 * probably never really have to look at current_weapon->skill
1518 */ 1515 */
1519 skill = 0; 1516 skill = 0;
1520 1517
1521 if (hitter->skill && hitter->type != PLAYER) 1518 if (hitter->skill && hitter->type != PLAYER)
1522 skill = hitter->skill; 1519 skill = hitter->skill;
1523 else if (owner->chosen_skill) 1520 else if (owner->chosen_skill)
1524 { 1521 {
1525 skill = owner->chosen_skill->skill;
1526 skop = owner->chosen_skill; 1522 skop = owner->chosen_skill;
1523 skill = skop->skill;
1527 } 1524 }
1528 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON)) 1525 else if (QUERY_FLAG (owner, FLAG_READY_WEAPON))
1529 skill = owner->current_weapon->skill; 1526 skill = owner->current_weapon->skill;
1530 else 1527 else
1531 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");
1532 1529
1533 /* 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
1534 * 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!
1535 */ 1532 */
1536 if ((!skop || skop->type != SKILL) && skill) 1533 if ((!skop || skop->type != SKILL) && skill)
1537 { 1534 {
1538 int i; 1535 int i;
1539 1536
1602 if (owner->type != PLAYER || owner->contr->party == NULL) 1599 if (owner->type != PLAYER || owner->contr->party == NULL)
1603 change_exp (owner, exp, skill, 0); 1600 change_exp (owner, exp, skill, 0);
1604 else 1601 else
1605 { 1602 {
1606 int shares = 0, count = 0; 1603 int shares = 0, count = 0;
1607 player *pl;
1608 partylist *party = owner->contr->party; 1604 partylist *party = owner->contr->party;
1609 1605
1610 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);
1611 1607
1612 for_all_players (pl) 1608 for_all_players (pl)
1671} 1667}
1672 1668
1673/* 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
1674 * Returns 0 this is not friendly fire 1670 * Returns 0 this is not friendly fire
1675 */ 1671 */
1676
1677int 1672int
1678friendly_fire (object *op, object *hitter) 1673friendly_fire (object *op, object *hitter)
1679{ 1674{
1680 object *owner; 1675 object *owner;
1681 int friendlyfire; 1676 int friendlyfire;
1700 } 1695 }
1701 1696
1702 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE) 1697 if (hitter->type == SPELL || hitter->type == POISONING || hitter->type == DISEASE || hitter->type == RUNE)
1703 friendlyfire = 0; 1698 friendlyfire = 0;
1704 } 1699 }
1700
1705 return friendlyfire; 1701 return friendlyfire;
1706} 1702}
1707 1703
1708 1704
1709/* This isn't used just for players, but in fact most objects. 1705/* This isn't used just for players, but in fact most objects.
1738 object *owner = hitter->owner; 1734 object *owner = hitter->owner;
1739 1735
1740 if (!owner) 1736 if (!owner)
1741 owner = hitter; 1737 owner = hitter;
1742 1738
1743 if (owner->type == PLAYER && (!op_on_battleground (op, 0, 0) && (op->contr->peaceful || owner->contr->peaceful)) && op != owner) 1739 if (owner->type == PLAYER
1740 && (!op_on_battleground (op, 0, 0)
1741 && (op->contr->peaceful || owner->contr->peaceful))
1742 && op != owner)
1744 return 0; 1743 return 0;
1745 } 1744 }
1746#endif 1745#endif
1747 1746
1748 if (body_attack) 1747 if (body_attack)
1782 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1781 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1783 { 1782 {
1784 /* 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
1785 * destroyed() check above doesn't return, and might get here. 1784 * destroyed() check above doesn't return, and might get here.
1786 */ 1785 */
1786
1787 /* FIXME: This for example happens when a dead door is on a mover and
1788 gets it's speed_left raised on each mover-tick.
1789 Doors are removed in a kinda funny way by giving them speed and speed_left
1790 and waiting for that to run out.
1791 */
1787 LOG (llevDebug, "victim %s already dead in hit_player()\n", op->debug_desc ()); 1792 LOG (llevDebug, "victim %s (%d) already dead in hit_player()\n", op->debug_desc (), op->stats.hp);
1788 return 0; 1793 return 0;
1789 } 1794 }
1790 1795
1791#ifdef ATTACK_DEBUG 1796#ifdef ATTACK_DEBUG
1792 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); 1797 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1899 1904
1900#ifdef ATTACK_DEBUG 1905#ifdef ATTACK_DEBUG
1901 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); 1906 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);
1902#endif 1907#endif
1903 1908
1909 // for now, only do this for active objects, otherwise they
1910 // keep a refcount for a long time and I see no usefulness
1911 // for an non-active objetc to know its enemy.
1912 if (op->active)
1904 if (hitter->owner) 1913 if (hitter->owner)
1905 op->enemy = hitter->owner; 1914 op->enemy = hitter->owner;
1906 else if (QUERY_FLAG (hitter, FLAG_ALIVE)) 1915 else if (QUERY_FLAG (hitter, FLAG_ALIVE))
1907 op->enemy = hitter; 1916 op->enemy = hitter;
1908 1917
1909 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) 1918 if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER)
1910 { 1919 {
1911 /* The unaggressives look after themselves 8) */ 1920 /* The unaggressives look after themselves 8) */
1912 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 1921 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
1949 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note 1958 /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note
1950 * that before if the player was immune to ghosthit, the monster 1959 * that before if the player was immune to ghosthit, the monster
1951 * remained - that is no longer the case. 1960 * remained - that is no longer the case.
1952 */ 1961 */
1953 if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) 1962 if (QUERY_FLAG (hitter, FLAG_ONE_HIT))
1954 {
1955 if (QUERY_FLAG (hitter, FLAG_FRIENDLY))
1956 remove_friendly_object (hitter);
1957
1958 hitter->destroy (); 1963 hitter->destroy ();
1959 } 1964
1960 /* Lets handle creatures that are splitting now */ 1965 /* Lets handle creatures that are splitting now */
1961 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) 1966 else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING))
1962 { 1967 {
1963 int i; 1968 int i;
1964 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); 1969 int friendly = QUERY_FLAG (op, FLAG_FRIENDLY);
2008 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) 2013 else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10)
2009 hitter->destroy (); 2014 hitter->destroy ();
2010 2015
2011 return maxdam; 2016 return maxdam;
2012} 2017}
2013
2014 2018
2015void 2019void
2016poison_player (object *op, object *hitter, int dam) 2020poison_player (object *op, object *hitter, int dam)
2017{ 2021{
2018 archetype *at = archetype::find ("poisoning"); 2022 archetype *at = archetype::find ("poisoning");
2073{ 2077{
2074 archetype *at = archetype::find ("slowness"); 2078 archetype *at = archetype::find ("slowness");
2075 object *tmp; 2079 object *tmp;
2076 2080
2077 if (at == NULL) 2081 if (at == NULL)
2078 {
2079 LOG (llevError, "Can't find slowness archetype.\n"); 2082 LOG (llevError, "Can't find slowness archetype.\n");
2080 } 2083
2081 if ((tmp = present_arch_in_ob (at, op)) == NULL) 2084 if ((tmp = present_arch_in_ob (at, op)) == NULL)
2082 { 2085 {
2083 tmp = arch_to_object (at); 2086 tmp = arch_to_object (at);
2084 tmp = insert_ob_in_ob (tmp, op); 2087 tmp = insert_ob_in_ob (tmp, op);
2085 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); 2088 new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!");
2086 } 2089 }
2087 else 2090 else
2088 tmp->stats.food++; 2091 tmp->stats.food++;
2092
2089 SET_FLAG (tmp, FLAG_APPLIED); 2093 SET_FLAG (tmp, FLAG_APPLIED);
2090 tmp->speed_left = 0; 2094 tmp->speed_left = 0;
2091 op->update_stats (); 2095 op->update_stats ();
2092} 2096}
2093 2097
2110 tmp->speed = 0.05; 2114 tmp->speed = 0.05;
2111 tmp->subtype = FORCE_CONFUSION; 2115 tmp->subtype = FORCE_CONFUSION;
2112 tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); 2116 tmp->duration = 8 + MAX (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100);
2113 tmp->name = "confusion"; 2117 tmp->name = "confusion";
2114 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); 2118 maxduration = MAX (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100);
2119
2115 if (tmp->duration > maxduration) 2120 if (tmp->duration > maxduration)
2116 tmp->duration = maxduration; 2121 tmp->duration = maxduration;
2117 2122
2118 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) 2123 if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED))
2119 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); 2124 new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!");
2125
2120 SET_FLAG (op, FLAG_CONFUSED); 2126 SET_FLAG (op, FLAG_CONFUSED);
2121} 2127}
2122 2128
2123void 2129void
2124blind_player (object *op, object *hitter, int dam) 2130blind_player (object *op, object *hitter, int dam)
2190 op->speed_left = (float) -(FABS (op->speed) * max); 2196 op->speed_left = (float) -(FABS (op->speed) * max);
2191 2197
2192/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */ 2198/* tmp->stats.food = (signed short) (max/FABS(op->speed)); */
2193} 2199}
2194 2200
2195
2196/* Attempts to kill 'op'. hitter is the attack object, dam is 2201/* Attempts to kill 'op'. hitter is the attack object, dam is
2197 * the computed damaged. 2202 * the computed damaged.
2198 */ 2203 */
2199void 2204void
2200deathstrike_player (object *op, object *hitter, int *dam) 2205deathstrike_player (object *op, object *hitter, int *dam)
2217 if (def_lev < 1) 2222 if (def_lev < 1)
2218 { 2223 {
2219 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name); 2224 LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->name, &op->name);
2220 def_lev = 1; 2225 def_lev = 1;
2221 } 2226 }
2227
2222 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; 2228 atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2;
2223 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", 2229 /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n",
2224 atk_lev, def_lev); */ 2230 atk_lev, def_lev); */
2225 2231
2226 if (atk_lev >= def_lev) 2232 if (atk_lev >= def_lev)
2241 */ 2247 */
2242 *dam *= kill_lev / def_lev; 2248 *dam *= kill_lev / def_lev;
2243 } 2249 }
2244 } 2250 }
2245 else 2251 else
2246 {
2247 *dam = 0; /* no harm done */ 2252 *dam = 0; /* no harm done */
2248 }
2249} 2253}
2250 2254
2251/* thrown_item_effect() - handles any special effects of thrown 2255/* thrown_item_effect() - handles any special effects of thrown
2252 * items (like attacking living creatures--a potion thrown at a 2256 * items (like attacking living creatures--a potion thrown at a
2253 * monster). 2257 * monster).
2282 } 2286 }
2283 } 2287 }
2284} 2288}
2285 2289
2286/* adj_attackroll() - adjustments to attacks by various conditions */ 2290/* adj_attackroll() - adjustments to attacks by various conditions */
2287
2288int 2291int
2289adj_attackroll (object *hitter, object *target) 2292adj_attackroll (object *hitter, object *target)
2290{ 2293{
2291 object *attacker = hitter; 2294 object *attacker = hitter;
2292 int adjust = 0; 2295 int adjust = 0;
2357#endif 2360#endif
2358 2361
2359 return adjust; 2362 return adjust;
2360} 2363}
2361 2364
2362
2363/* determine if the object is an 'aimed' missile */ 2365/* determine if the object is an 'aimed' missile */
2364int 2366int
2365is_aimed_missile (object *op) 2367is_aimed_missile (object *op)
2366{ 2368{
2367 2369
2368 /* I broke what used to be one big if into a few nested 2370 /* I broke what used to be one big if into a few nested
2369 * ones so that figuring out the logic is at least possible. 2371 * ones so that figuring out the logic is at least possible.
2370 */ 2372 */
2371 if (op && (op->move_type & MOVE_FLYING)) 2373 if (op && (op->move_type & MOVE_FLYING))
2372 {
2373 if (op->type == ARROW || op->type == THROWN_OBJ) 2374 if (op->type == ARROW || op->type == THROWN_OBJ)
2374 return 1; 2375 return 1;
2375 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))
2376 return 1; 2377 return 1;
2377 } 2378
2378 return 0; 2379 return 0;
2379} 2380}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines