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.39 by root, Mon Jan 8 01:19:03 2007 UTC vs.
Revision 1.50 by pippijn, Thu Mar 1 12:28:16 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) 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>
45 * its magical benefits. 45 * its magical benefits.
46 */ 46 */
47void 47void
48cancellation (object *op) 48cancellation (object *op)
49{ 49{
50 object *tmp;
51
52 if (op->invisible) 50 if (op->invisible)
53 return; 51 return;
54 52
55 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)
56 { 54 {
57 /* Recur through the inventory */ 55 /* Recurse through the inventory */
58 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 56 for (object *tmp = op->inv; tmp; tmp = tmp->below)
59 if (!did_make_save_item (tmp, AT_CANCELLATION, op)) 57 if (!did_make_save_item (tmp, AT_CANCELLATION, op))
60 cancellation (tmp); 58 cancellation (tmp);
61 } 59 }
62 else if (FABS (op->magic) <= (rndm (0, 5))) 60 else if (FABS (op->magic) <= rndm (0, 5))
63 { 61 {
64 /* Nullify this object. This code could probably be more complete */ 62 /* Nullify this object. This code could probably be more complete */
65 /* in what abilities it should cancel */ 63 /* in what abilities it should cancel */
66 op->magic = 0; 64 op->magic = 0;
65
67 CLEAR_FLAG (op, FLAG_DAMNED); 66 CLEAR_FLAG (op, FLAG_DAMNED);
68 CLEAR_FLAG (op, FLAG_CURSED); 67 CLEAR_FLAG (op, FLAG_CURSED);
69 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); 68 CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
70 CLEAR_FLAG (op, FLAG_KNOWN_CURSED); 69 CLEAR_FLAG (op, FLAG_KNOWN_CURSED);
70
71 if (op->env && op->env->type == PLAYER) 71 if (op->env && op->env->type == PLAYER)
72 {
73 esrv_send_item (op->env, op); 72 esrv_send_item (op->env, op);
74 }
75 } 73 }
76} 74}
77 75
78/* 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
79 * 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
86 materialtype_t *mt; 84 materialtype_t *mt;
87 85
88 if (op->materialname == NULL) 86 if (op->materialname == NULL)
89 { 87 {
90 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next) 88 for (mt = materialt; mt != NULL && mt->next != NULL; mt = mt->next)
91 if (op->material & mt->material) 89 if (op->materials & mt->material)
92 break; 90 break;
93 } 91 }
94 else 92 else
95 mt = name_to_material (op->materialname); 93 mt = name_to_material (op->materialname);
94
96 if (mt == NULL) 95 if (mt == NULL)
97 return TRUE; 96 return TRUE;
97
98 roll = rndm (1, 20); 98 roll = rndm (1, 20);
99 99
100 /* the attacktypes have no meaning for object saves 100 /* the attacktypes have no meaning for object saves
101 * 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
102 * 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
131 saves++; 131 saves++;
132 } 132 }
133 133
134 if (saves == attacks || attacks == 0) 134 if (saves == attacks || attacks == 0)
135 return TRUE; 135 return TRUE;
136
136 if ((saves == 0) || (rndm (1, attacks) > saves)) 137 if (saves == 0 || (rndm (1, attacks) > saves))
137 return FALSE; 138 return FALSE;
139
138 return TRUE; 140 return TRUE;
139} 141}
140 142
141/* This function calls did_make_save_item. It then performs the 143/* This function calls did_make_save_item. It then performs the
142 * appropriate actions to the item (such as burning the item up, 144 * appropriate actions to the item (such as burning the item up,
143 * calling cancellation, etc.) 145 * calling cancellation, etc.)
144 */ 146 */
145
146void 147void
147save_throw_object (object *op, int type, object *originator) 148save_throw_object (object *op, int type, object *originator)
148{ 149{
149 if (!did_make_save_item (op, type, originator)) 150 if (!did_make_save_item (op, type, originator))
150 { 151 {
303 304
304 map = op->map; 305 map = op->map;
305 x = op->x + freearr_x[dir]; 306 x = op->x + freearr_x[dir];
306 y = op->y + freearr_y[dir]; 307 y = op->y + freearr_y[dir];
307 308
308 int mflags = get_map_flags (map, &map, x, y, &x, &y); 309 if (!xy_normalise (map, x, y))
310 return 0;
309 311
310 // elmex: a safe map tile can't be hit! 312 // elmex: a safe map tile can't be hit!
311 // this should prevent most harmful effects on items and players there. 313 // this should prevent most harmful effects on items and players there.
312 if (mflags & (P_OUT_OF_MAP | P_SAFE)) 314 mapspace &ms = map->at (x, y);
315
316 if (ms.flags () & P_SAFE)
313 return 0; 317 return 0;
314 318
315 /* peterm: a few special cases for special attacktypes --counterspell 319 /* peterm: a few special cases for special attacktypes --counterspell
316 * 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
317 */ 321 */
318 322 if (type & (AT_COUNTERSPELL | AT_CHAOS))
323 {
319 if (type & AT_COUNTERSPELL) 324 if (type & AT_COUNTERSPELL)
320 { 325 {
321 counterspell (op, dir); /* see spell_effect.c */ 326 counterspell (op, dir); /* see spell_effect.c */
322 327
323 /* If the only attacktype is counterspell or magic, don't need 328 /* If the only attacktype is counterspell or magic, don't need
324 * to do any further processing. 329 * to do any further processing.
325 */ 330 */
326 if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC))) 331 if (!(type & ~(AT_COUNTERSPELL | AT_MAGIC)))
327 return 0; 332 return 0;
328 333
329 type &= ~AT_COUNTERSPELL; 334 type &= ~AT_COUNTERSPELL;
330 } 335 }
331 336
332 if (type & AT_CHAOS) 337 if (type & AT_CHAOS)
333 { 338 {
334 shuffle_attack (op, 1); /*1 flag tells it to change the face */ 339 shuffle_attack (op, 1); /* flag tells it to change the face */
335 update_object (op, UP_OBJ_FACE); 340 update_object (op, UP_OBJ_FACE);
336 type &= ~AT_CHAOS; 341 type &= ~AT_CHAOS;
342 }
337 } 343 }
338 344
339 /* There may still be objects that were above 'next', but there is no 345 /* There may still be objects that were above 'next', but there is no
340 * simple way to find out short of copying all object references and 346 * simple way to find out short of copying all object references and
341 * tags into a temporary array before we start processing the first 347 * tags into a temporary array before we start processing the first
342 * object. That's why we just abort on destroy. 348 * object. That's why we just abort on destroy.
343 * 349 *
344 * This happens whenever attack spells (like fire) hit a pile 350 * This happens whenever attack spells (like fire) hit a pile
345 * of objects. This is not a bug - nor an error. 351 * of objects. This is not a bug - nor an error.
346 */ 352 */
347 for (object *next = map->at (x, y).bot; next && !next->destroyed (); ) 353 for (object *next = ms.bot; next && !next->destroyed (); )
348 { 354 {
349 object *tmp = next; 355 object *tmp = next;
350 next = tmp->above; 356 next = tmp->above;
351 357
352 /* Something could have happened to 'tmp' while 'tmp->below' was processed. 358 /* Something could have happened to 'tmp' while 'tmp->below' was processed.
358 364
359 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 365 if (QUERY_FLAG (tmp, FLAG_ALIVE))
360 { 366 {
361 hit_player (tmp, op->stats.dam, op, type, full_hit); 367 hit_player (tmp, op->stats.dam, op, type, full_hit);
362 retflag |= 1; 368 retflag |= 1;
369
363 if (op->destroyed ()) 370 if (op->destroyed ())
364 break; 371 break;
365 } 372 }
366 /* Here we are potentially destroying an object. If the object has 373 /* Here we are potentially destroying an object. If the object has
367 * 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
368 * that weak walls have is_alive set, which prevent objects from 375 * that weak walls have is_alive set, which prevent objects from
369 * 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
370 * 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
371 * destroyed right now. 378 * destroyed right now.
372 */ 379 */
373 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)
374 { 381 {
375 save_throw_object (tmp, type, op); 382 save_throw_object (tmp, type, op);
376 383
377 if (op->destroyed ()) 384 if (op->destroyed ())
378 break; 385 break;
770 if (settings.casting_time == TRUE) 777 if (settings.casting_time == TRUE)
771 { 778 {
772 if ((hitter->type == PLAYER) && (hitter->casting_time > -1)) 779 if ((hitter->type == PLAYER) && (hitter->casting_time > -1))
773 { 780 {
774 hitter->casting_time = -1; 781 hitter->casting_time = -1;
775 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!");
776 } 783 }
777 if ((op->casting_time > -1) && (hitdam > 0)) 784 if ((op->casting_time > -1) && (hitdam > 0))
778 { 785 {
779 op->casting_time = -1; 786 op->casting_time = -1;
780 if (op->type == PLAYER) 787 if (op->type == PLAYER)
781 { 788 {
782 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!");
783 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);
784 } 791 }
785 } 792 }
786 } 793 }
787 if (!simple_attack) 794 if (!simple_attack)
1067 * appropriate attacktype. Only 1 attacktype should be set at a time. 1074 * appropriate attacktype. Only 1 attacktype should be set at a time.
1068 * 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
1069 * take. However, it will do other effects (paralyzation, slow, etc.) 1076 * take. However, it will do other effects (paralyzation, slow, etc.)
1070 * 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
1071 * the attacktype. Makes it easier for the PR code. */ 1078 * the attacktype. Makes it easier for the PR code. */
1072
1073int 1079int
1074hit_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)
1075{ 1081{
1076
1077 int doesnt_slay = 1; 1082 int doesnt_slay = 1;
1078 1083
1079 /* 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 */
1080 if (attacknum >= NROFATTACKS) 1085 if (attacknum >= NROFATTACKS)
1081 { 1086 {
1083 return 0; 1088 return 0;
1084 } 1089 }
1085 1090
1086 if (dam < 0) 1091 if (dam < 0)
1087 { 1092 {
1088 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 ());
1089 return 0; 1094 return 0;
1090 } 1095 }
1091 1096
1092 /* 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
1093 * people can't mess with that or it otherwise get confused. */ 1098 * people can't mess with that or it otherwise get confused. */
1126 1131
1127 /* Keep this in order - makes things easier to find */ 1132 /* Keep this in order - makes things easier to find */
1128 1133
1129 switch (attacknum) 1134 switch (attacknum)
1130 { 1135 {
1131 case ATNR_PHYSICAL: 1136 case ATNR_PHYSICAL:
1132 /* here also check for diseases */ 1137 /* here also check for diseases */
1133 check_physically_infect (op, hitter); 1138 check_physically_infect (op, hitter);
1134 break; 1139 break;
1135 1140
1136 /* Don't need to do anything for: 1141 /* Don't need to do anything for:
1137 magic, 1142 magic,
1138 fire, 1143 fire,
1139 electricity, 1144 electricity,
1140 cold */ 1145 cold */
1141 1146
1142 case ATNR_CONFUSION: 1147 case ATNR_CONFUSION:
1143 case ATNR_POISON: 1148 case ATNR_POISON:
1144 case ATNR_SLOW: 1149 case ATNR_SLOW:
1145 case ATNR_PARALYZE: 1150 case ATNR_PARALYZE:
1146 case ATNR_FEAR: 1151 case ATNR_FEAR:
1147 case ATNR_CANCELLATION: 1152 case ATNR_CANCELLATION:
1148 case ATNR_DEPLETE: 1153 case ATNR_DEPLETE:
1149 case ATNR_BLIND: 1154 case ATNR_BLIND:
1150 { 1155 {
1151 /* chance for inflicting a special attack depends on the 1156 /* chance for inflicting a special attack depends on the
1152 * difference between attacker's and defender's level 1157 * difference between attacker's and defender's level
1153 */ 1158 */
1154 int level_diff = MIN (110, MAX (0, op->level - hitter->level)); 1159 int level_diff = MIN (110, MAX (0, op->level - hitter->level));
1155 1160
1156 /* First, only creatures/players with speed can be affected. 1161 /* First, only creatures/players with speed can be affected.
1157 * Second, just getting hit doesn't mean it always affects 1162 * Second, just getting hit doesn't mean it always affects
1158 * you. Third, you still get a saving through against the 1163 * you. Third, you still get a saving through against the
1159 * effect. 1164 * effect.
1160 */ 1165 */
1161 if (op->speed && 1166 if (op->speed &&
1162 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) && 1167 (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) &&
1163 !(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))
1164 { 1169 {
1165 1170
1166 /* Player has been hit by something */ 1171 /* Player has been hit by something */
1167 if (attacknum == ATNR_CONFUSION) 1172 if (attacknum == ATNR_CONFUSION)
1168 confuse_player (op, hitter, dam); 1173 confuse_player (op, hitter, dam);
1169 else if (attacknum == ATNR_POISON) 1174 else if (attacknum == ATNR_POISON)
1170 poison_player (op, hitter, dam); 1175 poison_player (op, hitter, dam);
1171 else if (attacknum == ATNR_SLOW) 1176 else if (attacknum == ATNR_SLOW)
1172 slow_player (op, hitter, dam); 1177 slow_player (op, hitter, dam);
1173 else if (attacknum == ATNR_PARALYZE) 1178 else if (attacknum == ATNR_PARALYZE)
1174 paralyze_player (op, hitter, dam); 1179 paralyze_player (op, hitter, dam);
1175 else if (attacknum == ATNR_FEAR) 1180 else if (attacknum == ATNR_FEAR)
1176 scare_creature (op, hitter); 1181 scare_creature (op, hitter);
1177 else if (attacknum == ATNR_CANCELLATION) 1182 else if (attacknum == ATNR_CANCELLATION)
1178 cancellation (op); 1183 cancellation (op);
1179 else if (attacknum == ATNR_DEPLETE) 1184 else if (attacknum == ATNR_DEPLETE)
1180 op->drain_stat (); 1185 op->drain_stat ();
1181 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))
1182 blind_player (op, hitter, dam); 1187 blind_player (op, hitter, dam);
1183 } 1188 }
1184 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 */
1185 } 1190 }
1186 break; 1191 break;
1192
1187 case ATNR_ACID: 1193 case ATNR_ACID:
1188 { 1194 {
1189 int flag = 0; 1195 int flag = 0;
1190 1196
1191 /* 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
1192 * if your acid resistance is below 50%. */ 1198 * if your acid resistance is below 50%. */
1193 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))
1194 { 1200 {
1195 object *tmp;
1196
1197 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1201 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1198 { 1202 {
1199 if (tmp->invisible) 1203 if (tmp->invisible)
1200 continue; 1204 continue;
1201 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) 1205 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10))
1202 /* >= 10% acid res. on itmes will protect these */ 1206 /* >= 10% acid res. on items will protect these */
1203 continue; 1207 continue;
1204 if (!(tmp->material & M_IRON)) 1208 if (!(tmp->materials & M_IRON))
1205 continue; 1209 continue;
1206 if (tmp->magic < -4) /* Let's stop at -5 */ 1210 if (tmp->magic < -4) /* Let's stop at -5 */
1207 continue; 1211 continue;
1208 if (tmp->type == RING || 1212 if (tmp->type == RING
1209 /* removed boots and gloves from exclusion list in 1213 /* removed boots and gloves from exclusion list in PR */
1210 PR */ 1214 || tmp->type == GIRDLE
1211 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)
1212 continue; /* To avoid some strange effects */ 1219 continue; /* To avoid some strange effects */
1213 1220
1214 /* High damage acid has better chance of corroding 1221 /* High damage acid has better chance of corroding
1215 objects */ 1222 objects */
1216 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)
1217 { 1224 {
1218 if (op->type == PLAYER) 1225 if (op->type == PLAYER)
1219 /* Make this more visible */ 1226 /* Make this more visible */
1220 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op, 1227 new_draw_info_format (NDI_UNIQUE | NDI_RED, 0, op,
1221 "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));
1222 flag = 1; 1229 flag = 1;
1223 tmp->magic--; 1230 tmp->magic--;
1224 if (op->type == PLAYER) 1231 if (op->type == PLAYER)
1225 esrv_send_item (op, tmp); 1232 esrv_send_item (op, tmp);
1226 } 1233 }
1227 } 1234 }
1235
1228 if (flag) 1236 if (flag)
1229 op->update_stats (); /* Something was corroded */ 1237 op->update_stats (); /* Something was corroded */
1230 } 1238 }
1231 } 1239 }
1232 break; 1240 break;
1241
1233 case ATNR_DRAIN: 1242 case ATNR_DRAIN:
1234 { 1243 {
1235 /* rate is the proportion of exp drained. High rate means 1244 /* rate is the proportion of exp drained. High rate means
1236 * not much is drained, low rate means a lot is drained. 1245 * not much is drained, low rate means a lot is drained.
1237 */ 1246 */
1238 int rate; 1247 int rate;
1239 1248
1240 if (op->resist[ATNR_DRAIN] >= 0) 1249 if (op->resist[ATNR_DRAIN] >= 0)
1241 rate = 400 + op->resist[ATNR_DRAIN] * 3; 1250 rate = 400 + op->resist[ATNR_DRAIN] * 3;
1242 else 1251 else
1243 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); 1252 rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]);
1244 1253
1245 if (op->stats.exp <= rate) 1254 if (op->stats.exp <= rate)
1246 { 1255 {
1247 if (op->type == GOLEM) 1256 if (op->type == GOLEM)
1248 dam = 999; /* Its force is "sucked" away. 8) */ 1257 dam = 999; /* Its force is "sucked" away. 8) */
1249 else 1258 else
1250 /* If we can't drain, lets try to do physical damage */ 1259 /* If we can't drain, lets try to do physical damage */
1251 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); 1260 dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic);
1252 } 1261 }
1253 else 1262 else
1254 { 1263 {
1255 /* Randomly give the hitter some hp */ 1264 /* Randomly give the hitter some hp */
1256 if (hitter->stats.hp < hitter->stats.maxhp && 1265 if (hitter->stats.hp < hitter->stats.maxhp &&
1257 (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)
1258 hitter->stats.hp++; 1267 hitter->stats.hp++;
1259 1268
1260 /* Can't do drains on battleground spaces. 1269 /* Can't do drains on battleground spaces.
1261 * 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
1262 * 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,
1263 * nothing happens. 1272 * nothing happens.
1264 * 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
1265 * attacks, hence all the != PLAYER checks. 1274 * attacks, hence all the != PLAYER checks.
1266 */ 1275 */
1267 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))
1268 { 1277 {
1269 object *owner = hitter->owner; 1278 object *owner = hitter->owner;
1270 1279
1271 if (owner && owner != hitter) 1280 if (owner && owner != hitter)
1272 { 1281 {
1273 if (op->type != PLAYER || owner->type != PLAYER) 1282 if (op->type != PLAYER || owner->type != PLAYER)
1274 change_exp (owner, op->stats.exp / (rate * 2), 1283 change_exp (owner, op->stats.exp / (rate * 2),
1275 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);
1276 } 1285 }
1277 else if (op->type != PLAYER || hitter->type != PLAYER) 1286 else if (op->type != PLAYER || hitter->type != PLAYER)
1278 { 1287 {
1279 change_exp (hitter, op->stats.exp / (rate * 2), 1288 change_exp (hitter, op->stats.exp / (rate * 2),
1280 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); 1289 hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0);
1281 } 1290 }
1282 change_exp (op, -op->stats.exp / rate, NULL, 0); 1291 change_exp (op, -op->stats.exp / rate, NULL, 0);
1283 } 1292 }
1293
1284 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
1285 * 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,
1286 * as the messages will say you missed 1296 * as the messages will say you missed
1287 */ 1297 */
1288 } 1298 }
1289 } 1299 }
1290 break; 1300 break;
1301
1291 case ATNR_TURN_UNDEAD: 1302 case ATNR_TURN_UNDEAD:
1292 { 1303 {
1293 if (QUERY_FLAG (op, FLAG_UNDEAD)) 1304 if (QUERY_FLAG (op, FLAG_UNDEAD))
1294 { 1305 {
1295 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1306 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1296 object *god = find_god (determine_god (owner)); 1307 object *god = find_god (determine_god (owner));
1297 int div = 1; 1308 int div = 1;
1298 1309
1299 /* 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
1300 * at half strength */ 1311 * at half strength */
1301 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL) 1312 if (!god || !god->slaying || strstr (god->slaying, undead_name) == NULL)
1302 div = 2; 1313 div = 2;
1303 /* Give a bonus if you resist turn undead */ 1314 /* Give a bonus if you resist turn undead */
1304 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)))
1305 scare_creature (op, owner); 1316 scare_creature (op, owner);
1306 } 1317 }
1307 else 1318 else
1308 dam = 0; /* don't damage non undead - should we damage 1319 dam = 0; /* don't damage non undead - should we damage
1309 undead? */ 1320 undead? */
1310 } 1321 }
1311 break; 1322 break;
1323
1312 case ATNR_DEATH: 1324 case ATNR_DEATH:
1313 deathstrike_player (op, hitter, &dam); 1325 deathstrike_player (op, hitter, &dam);
1314 break; 1326 break;
1327
1315 case ATNR_CHAOS: 1328 case ATNR_CHAOS:
1316 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 ());
1317 dam = 0; 1330 dam = 0;
1318 break; 1331 break;
1332
1319 case ATNR_COUNTERSPELL: 1333 case ATNR_COUNTERSPELL:
1320 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 ());
1321 dam = 0; 1335 dam = 0;
1322 /* This should never happen. Counterspell is handled 1336 /* This should never happen. Counterspell is handled
1323 * seperately and filtered out. If this does happen, 1337 * seperately and filtered out. If this does happen,
1324 * Counterspell has no effect on anything but spells, so it 1338 * Counterspell has no effect on anything but spells, so it
1325 * does no damage. */ 1339 * does no damage. */
1326 break; 1340 break;
1341
1327 case ATNR_HOLYWORD: 1342 case ATNR_HOLYWORD:
1328 { 1343 {
1329 /* This has already been handled by hit_player, 1344 /* This has already been handled by hit_player,
1330 * no need to check twice -- DAMN */ 1345 * no need to check twice -- DAMN */
1331 object *owner = hitter->owner ? (object *)hitter->owner : hitter; 1346 object *owner = hitter->owner ? (object *)hitter->owner : hitter;
1332 1347
1333 /* 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 */
1334 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])
1335 scare_creature (op, owner); 1350 scare_creature (op, owner);
1336 } 1351 }
1337 break; 1352 break;
1353
1338 case ATNR_LIFE_STEALING: 1354 case ATNR_LIFE_STEALING:
1339 { 1355 {
1340 int new_hp; 1356 int new_hp;
1341 1357
1342 /* this is replacement to drain for players, instead of taking 1358 /* this is replacement to drain for players, instead of taking
1343 * exp it takes hp. It is geared for players, probably not 1359 * exp it takes hp. It is geared for players, probably not
1344 * much use giving it to monsters 1360 * much use giving it to monsters
1345 * 1361 *
1346 * 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
1347 * damage it does do to the player. Given that, 1363 * damage it does do to the player. Given that,
1348 * 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
1349 * 1000). 1365 * 1000).
1350 */ 1366 */
1351 /* You can't steal life from something undead */ 1367 /* You can't steal life from something undead */
1352 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) 1368 if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD)))
1353 return 0; 1369 return 0;
1370
1354 /* If drain protection is higher than life stealing, use that */ 1371 /* If drain protection is higher than life stealing, use that */
1355 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) 1372 if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING])
1356 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; 1373 dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000;
1357 else 1374 else
1358 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000; 1375 dam = (dam * (100 - op->resist[ATNR_LIFE_STEALING])) / 3000;
1376
1359 /* You die at -1 hp, not zero. */ 1377 /* You die at -1 hp, not zero. */
1360 if (dam > (op->stats.hp + 1)) 1378 if (dam > (op->stats.hp + 1))
1361 dam = op->stats.hp + 1; 1379 dam = op->stats.hp + 1;
1380
1362 new_hp = hitter->stats.hp + dam; 1381 new_hp = hitter->stats.hp + dam;
1363 if (new_hp > hitter->stats.maxhp) 1382 if (new_hp > hitter->stats.maxhp)
1364 new_hp = hitter->stats.maxhp; 1383 new_hp = hitter->stats.maxhp;
1384
1365 if (new_hp > hitter->stats.hp) 1385 if (new_hp > hitter->stats.hp)
1366 hitter->stats.hp = new_hp; 1386 hitter->stats.hp = new_hp;
1367 } 1387 }
1368 } 1388 }
1389
1369 return dam; 1390 return dam;
1370} 1391}
1371
1372 1392
1373/* 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
1374 * allow script procedures to "kill" objects in a combat-like fashion. 1394 * allow script procedures to "kill" objects in a combat-like fashion.
1375 * 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
1376 * Sword. Note that nothing has been changed from the original version 1396 * Sword. Note that nothing has been changed from the original version
1582 if (owner->type != PLAYER || owner->contr->party == NULL) 1602 if (owner->type != PLAYER || owner->contr->party == NULL)
1583 change_exp (owner, exp, skill, 0); 1603 change_exp (owner, exp, skill, 0);
1584 else 1604 else
1585 { 1605 {
1586 int shares = 0, count = 0; 1606 int shares = 0, count = 0;
1587 player *pl;
1588 partylist *party = owner->contr->party; 1607 partylist *party = owner->contr->party;
1589 1608
1590 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);
1591 1610
1592 for_all_players (pl) 1611 for_all_players (pl)
1691 * is what is hitting the object, type is the attacktype, and 1710 * is what is hitting the object, type is the attacktype, and
1692 * full_hit is set if monster area does not matter. 1711 * full_hit is set if monster area does not matter.
1693 * dam is base damage - protections/vulnerabilities/slaying matches can 1712 * dam is base damage - protections/vulnerabilities/slaying matches can
1694 * modify it. 1713 * modify it.
1695 */ 1714 */
1696
1697 /* Oct 95 - altered the following slightly for MULTIPLE_GODS hack 1715/* Oct 95 - altered the following slightly for MULTIPLE_GODS hack
1698 * which needs new attacktype AT_HOLYWORD to work . b.t. */ 1716 * which needs new attacktype AT_HOLYWORD to work . b.t. */
1699
1700int 1717int
1701hit_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)
1702{ 1719{
1703 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC); 1720 int maxdam = 0, ndam = 0, attacktype = 1, magic = (type & AT_MAGIC);
1704 int maxattacktype, attacknum; 1721 int maxattacktype, attacknum;
1747 } 1764 }
1748 } 1765 }
1749 1766
1750 if (!simple_attack && op->type == DOOR) 1767 if (!simple_attack && op->type == DOOR)
1751 { 1768 {
1752 object *tmp;
1753
1754 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1769 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1755 if (tmp->type == RUNE || tmp->type == TRAP) 1770 if (tmp->type == RUNE || tmp->type == TRAP)
1756 { 1771 {
1757 spring_trap (tmp, hitter); 1772 spring_trap (tmp, hitter);
1758 1773
1759 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack)) 1774 if (hitter->destroyed () || op->destroyed () || abort_attack (op, hitter, simple_attack))
1766 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) 1781 if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0)
1767 { 1782 {
1768 /* 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
1769 * destroyed() check above doesn't return, and might get here. 1784 * destroyed() check above doesn't return, and might get here.
1770 */ 1785 */
1771 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 ());
1772 return 0; 1787 return 0;
1773 } 1788 }
1774 1789
1775#ifdef ATTACK_DEBUG 1790#ifdef ATTACK_DEBUG
1776 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam); 1791 LOG (llevDebug, "hit player: attacktype %d, dam %d\n", type, dam);
1782 * 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 */
1783 dam = dam * (100 - op->resist[ATNR_MAGIC]); 1798 dam = dam * (100 - op->resist[ATNR_MAGIC]);
1784 if (dam >= 100) 1799 if (dam >= 100)
1785 dam /= 100; 1800 dam /= 100;
1786 else 1801 else
1787 dam = (dam > (rndm (0, 99))) ? 1 : 0; 1802 dam = (dam > rndm (0, 99)) ? 1 : 0;
1788 } 1803 }
1789 1804
1790 /* 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
1791 * 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
1792 */ 1807 */
1875 1890
1876 /* basically: maxdam /= area; we try to "simulate" a float 1891 /* basically: maxdam /= area; we try to "simulate" a float
1877 value-effect */ 1892 value-effect */
1878 remainder = 100 * (maxdam % area) / area; 1893 remainder = 100 * (maxdam % area) / area;
1879 maxdam /= area; 1894 maxdam /= area;
1880 if (RANDOM () % 100 < remainder) 1895 if (rndm (100) < remainder)
1881 maxdam++; 1896 maxdam++;
1882 } 1897 }
1883 1898
1884#ifdef ATTACK_DEBUG 1899#ifdef ATTACK_DEBUG
1885 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam); 1900 LOG (llevDebug, "Attacktype %d did %d damage\n", type, maxdam);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines