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