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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines