1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <assert.h> |
25 | #include <assert.h> |
26 | #include <global.h> |
26 | #include <global.h> |
27 | #include <living.h> |
27 | #include <living.h> |
28 | #include <material.h> |
28 | #include <material.h> |
29 | #include <skills.h> |
29 | #include <skills.h> |
30 | #include <sounds.h> |
30 | #include <sounds.h> |
31 | #include <sproto.h> |
31 | #include <sproto.h> |
32 | |
|
|
33 | typedef struct att_msg_str |
|
|
34 | { |
|
|
35 | char *msg1; |
|
|
36 | char *msg2; |
|
|
37 | } att_msg; |
|
|
38 | |
32 | |
39 | /*#define ATTACK_DEBUG*/ |
33 | /*#define ATTACK_DEBUG*/ |
40 | |
34 | |
41 | /* did_make_save_item just checks to make sure the item actually |
35 | /* did_make_save_item just checks to make sure the item actually |
42 | * made its saving throw based on the tables. It does not take |
36 | * made its saving throw based on the tables. It does not take |
… | |
… | |
101 | cancellation (object *op) |
95 | cancellation (object *op) |
102 | { |
96 | { |
103 | if (op->invisible) |
97 | if (op->invisible) |
104 | return; |
98 | return; |
105 | |
99 | |
106 | if (QUERY_FLAG (op, FLAG_ALIVE) || op->type == CONTAINER || op->type == THROWN_OBJ) |
100 | if (op->flag [FLAG_ALIVE] || op->type == CONTAINER || op->type == THROWN_OBJ) |
107 | { |
101 | { |
108 | /* Recurse through the inventory */ |
102 | /* Recurse through the inventory */ |
109 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
103 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
110 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
104 | if (!did_make_save_item (tmp, AT_CANCELLATION, op)) |
111 | cancellation (tmp); |
105 | cancellation (tmp); |
… | |
… | |
114 | { |
108 | { |
115 | /* Nullify this object. This code could probably be more complete */ |
109 | /* Nullify this object. This code could probably be more complete */ |
116 | /* in what abilities it should cancel */ |
110 | /* in what abilities it should cancel */ |
117 | op->magic = 0; |
111 | op->magic = 0; |
118 | |
112 | |
119 | CLEAR_FLAG (op, FLAG_DAMNED); |
113 | op->clr_flag (FLAG_DAMNED); |
120 | CLEAR_FLAG (op, FLAG_CURSED); |
114 | op->clr_flag (FLAG_CURSED); |
121 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
115 | op->clr_flag (FLAG_KNOWN_MAGICAL); |
122 | CLEAR_FLAG (op, FLAG_KNOWN_CURSED); |
116 | op->clr_flag (FLAG_KNOWN_CURSED); |
123 | |
117 | |
124 | if (object *pl = op->visible_to ()) |
118 | if (object *pl = op->visible_to ()) |
125 | esrv_update_item (UPD_FLAGS, pl, op); |
119 | esrv_update_item (UPD_FLAGS, pl, op); |
126 | } |
120 | } |
127 | } |
121 | } |
… | |
… | |
215 | |
209 | |
216 | return; |
210 | return; |
217 | } |
211 | } |
218 | |
212 | |
219 | /* The value of 50 is arbitrary. */ |
213 | /* The value of 50 is arbitrary. */ |
220 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2)) |
214 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !op->flag [FLAG_NO_PICK] && rndm (2)) |
221 | { |
215 | { |
222 | archetype *at = archetype::find (shstr_icecube); |
216 | archetype *at = archetype::find (shstr_icecube); |
223 | |
217 | |
224 | if (at == NULL) |
218 | if (at == NULL) |
225 | return; |
219 | return; |
… | |
… | |
254 | * returns 1 if it hits something, 0 otherwise. |
248 | * returns 1 if it hits something, 0 otherwise. |
255 | */ |
249 | */ |
256 | int |
250 | int |
257 | hit_map (object *op, int dir, uint32_t type, int full_hit) |
251 | hit_map (object *op, int dir, uint32_t type, int full_hit) |
258 | { |
252 | { |
259 | maptile *map; |
|
|
260 | sint16 x, y; |
253 | sint16 x, y; |
261 | int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ |
254 | int retflag = 0; /* added this flag.. will return 1 if it hits a monster */ |
262 | |
255 | |
263 | if (QUERY_FLAG (op, FLAG_FREED)) |
256 | if (op->flag [FLAG_FREED]) |
264 | { |
257 | { |
265 | LOG (llevError, "BUG: hit_map(): free object\n"); |
258 | LOG (llevError, "BUG: hit_map(): free object\n"); |
266 | return 0; |
259 | return 0; |
267 | } |
260 | } |
268 | |
261 | |
269 | if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) |
262 | if (op->flag [FLAG_REMOVED] || op->env != NULL) |
270 | { |
263 | { |
271 | LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); |
264 | LOG (llevError, "BUG: hit_map(): hitter (arch %s, name %s) not on a map\n", &op->arch->archname, &op->name); |
272 | return 0; |
265 | return 0; |
273 | } |
266 | } |
274 | |
267 | |
… | |
… | |
338 | * This is one of the few cases where on_same_map should not be used. |
331 | * This is one of the few cases where on_same_map should not be used. |
339 | */ |
332 | */ |
340 | if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) |
333 | if (tmp->map != pos.m || tmp->x != pos.x || tmp->y != pos.y) |
341 | continue; |
334 | continue; |
342 | |
335 | |
343 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
336 | if (tmp->flag [FLAG_ALIVE]) |
344 | { |
337 | { |
345 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
338 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
346 | retflag |= 1; |
339 | retflag |= 1; |
347 | |
340 | |
348 | if (op->destroyed ()) |
341 | if (op->destroyed ()) |
… | |
… | |
364 | if (op->destroyed ()) |
357 | if (op->destroyed ()) |
365 | break; |
358 | break; |
366 | } |
359 | } |
367 | } |
360 | } |
368 | |
361 | |
369 | return 0; |
362 | return retflag; |
370 | } |
363 | } |
371 | |
364 | |
372 | static void |
365 | static void |
373 | attack_message (int dam, int type, object *op, object *hitter) |
366 | attack_message (int dam, int type, object *op, object *hitter) |
374 | { |
367 | { |
… | |
… | |
523 | { |
516 | { |
524 | int mtype; |
517 | int mtype; |
525 | |
518 | |
526 | switch (hitter->current_weapon->weapontype) |
519 | switch (hitter->current_weapon->weapontype) |
527 | { |
520 | { |
528 | case WEAP_HIT: |
521 | case WEAP_HIT: mtype = ATM_BASIC; break; |
529 | mtype = ATM_BASIC; |
522 | case WEAP_SLASH: mtype = ATM_SLASH; break; |
530 | break; |
523 | case WEAP_PIERCE: mtype = ATM_PIERCE; break; |
531 | case WEAP_SLASH: |
524 | case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; |
532 | mtype = ATM_SLASH; |
525 | case WEAP_SLICE: mtype = ATM_SLICE; break; |
533 | break; |
526 | case WEAP_STAB: mtype = ATM_STAB; break; |
534 | case WEAP_PIERCE: |
527 | case WEAP_WHIP: mtype = ATM_WHIP; break; |
535 | mtype = ATM_PIERCE; |
528 | case WEAP_CRUSH: mtype = ATM_CRUSH; break; |
536 | break; |
529 | case WEAP_BLUD: mtype = ATM_BLUD; break; |
537 | case WEAP_CLEAVE: |
530 | default: mtype = ATM_BASIC; break; |
538 | mtype = ATM_CLEAVE; |
|
|
539 | break; |
|
|
540 | case WEAP_SLICE: |
|
|
541 | mtype = ATM_SLICE; |
|
|
542 | break; |
|
|
543 | case WEAP_STAB: |
|
|
544 | mtype = ATM_STAB; |
|
|
545 | break; |
|
|
546 | case WEAP_WHIP: |
|
|
547 | mtype = ATM_WHIP; |
|
|
548 | break; |
|
|
549 | case WEAP_CRUSH: |
|
|
550 | mtype = ATM_CRUSH; |
|
|
551 | break; |
|
|
552 | case WEAP_BLUD: |
|
|
553 | mtype = ATM_BLUD; |
|
|
554 | break; |
|
|
555 | default: |
|
|
556 | mtype = ATM_BASIC; |
|
|
557 | break; |
|
|
558 | } |
531 | } |
559 | |
532 | |
560 | for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
533 | for (i = 0; i < MAXATTACKMESS && attack_mess[mtype][i].level != -1; i++) |
561 | if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) |
534 | if (dam < attack_mess[mtype][i].level || attack_mess[mtype][i + 1].level == -1) |
562 | { |
535 | { |
… | |
… | |
668 | } |
641 | } |
669 | |
642 | |
670 | static int |
643 | static int |
671 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
644 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
672 | { |
645 | { |
673 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
646 | if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED]) |
674 | { |
647 | { |
675 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
648 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
676 | return 1; |
649 | return 1; |
677 | } |
650 | } |
678 | |
651 | |
… | |
… | |
686 | { |
659 | { |
687 | *simple_attack = 1; |
660 | *simple_attack = 1; |
688 | return 0; |
661 | return 0; |
689 | } |
662 | } |
690 | |
663 | |
691 | if (QUERY_FLAG (*target, FLAG_REMOVED) |
664 | if ((*target)->flag [FLAG_REMOVED] |
692 | || QUERY_FLAG (*hitter, FLAG_REMOVED) |
665 | || (*hitter)->flag [FLAG_REMOVED] |
693 | || !(*hitter)->map |
666 | || !(*hitter)->map |
694 | || !on_same_map (*hitter, *target)) |
667 | || !on_same_map (*hitter, *target)) |
695 | { |
668 | { |
696 | LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", |
669 | LOG (llevError | logBacktrace, "BUG: hitter (%s) with no relation to target (%s)\n", |
697 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
670 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
… | |
… | |
710 | */ |
683 | */ |
711 | int new_mode; |
684 | int new_mode; |
712 | |
685 | |
713 | if (hitter->env == target || target->env == hitter) |
686 | if (hitter->env == target || target->env == hitter) |
714 | new_mode = 1; |
687 | new_mode = 1; |
715 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
688 | else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED] |
716 | || hitter->map == NULL || !on_same_map (hitter, target)) |
689 | || hitter->map == NULL || !on_same_map (hitter, target)) |
717 | return 1; |
690 | return 1; |
718 | else |
691 | else |
719 | new_mode = 0; |
692 | new_mode = 0; |
720 | |
693 | |
… | |
… | |
726 | * monster). |
699 | * monster). |
727 | */ |
700 | */ |
728 | static void |
701 | static void |
729 | thrown_item_effect (object *hitter, object *victim) |
702 | thrown_item_effect (object *hitter, object *victim) |
730 | { |
703 | { |
731 | if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
704 | if (!hitter->flag [FLAG_ALIVE]) |
732 | { |
705 | { |
733 | /* May not need a switch for just 2 types, but this makes it |
706 | /* May not need a switch for just 2 types, but this makes it |
734 | * easier for expansion. |
707 | * easier for expansion. |
735 | */ |
708 | */ |
736 | switch (hitter->type) |
709 | switch (hitter->type) |
737 | { |
710 | { |
738 | case POTION: |
711 | case POTION: |
739 | /* should player get a save throw instead of checking magic protection? */ |
712 | /* should player get a save throw instead of checking magic protection? */ |
740 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_MAGIC] < 60)) |
713 | if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_MAGIC] < 60)) |
741 | apply_potion (victim, hitter); |
714 | apply_potion (victim, hitter); |
742 | break; |
715 | break; |
743 | |
716 | |
744 | case POISON: /* poison drinks */ |
717 | case POISON: /* poison drinks */ |
745 | /* As with potions, should monster get a save? */ |
718 | /* As with potions, should monster get a save? */ |
746 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_UNDEAD) && (victim->resist[ATNR_POISON] < 60)) |
719 | if (victim->flag [FLAG_ALIVE] && !victim->flag [FLAG_UNDEAD] && (victim->resist[ATNR_POISON] < 60)) |
747 | apply_poison (victim, hitter); |
720 | apply_poison (victim, hitter); |
748 | break; |
721 | break; |
749 | |
722 | |
750 | /* Removed case statements that did nothing. |
723 | /* Removed case statements that did nothing. |
751 | * food may be poisonous, but monster must be willing to eat it, |
724 | * food may be poisonous, but monster must be willing to eat it, |
… | |
… | |
758 | |
731 | |
759 | /* determine if the object is an 'aimed' missile */ |
732 | /* determine if the object is an 'aimed' missile */ |
760 | static int |
733 | static int |
761 | is_aimed_missile (object *op) |
734 | is_aimed_missile (object *op) |
762 | { |
735 | { |
763 | |
|
|
764 | /* I broke what used to be one big if into a few nested |
736 | /* I broke what used to be one big if into a few nested |
765 | * ones so that figuring out the logic is at least possible. |
737 | * ones so that figuring out the logic is at least possible. |
766 | */ |
738 | */ |
767 | if (op && (op->move_type & MOVE_FLYING)) |
739 | if (op && (op->move_type & MOVE_FLYING)) |
768 | if (op->type == ARROW || op->type == THROWN_OBJ) |
740 | if (op->type == ARROW || op->type == THROWN_OBJ) |
… | |
… | |
792 | if ((attacker = hitter->owner) == NULL) |
764 | if ((attacker = hitter->owner) == NULL) |
793 | attacker = hitter; |
765 | attacker = hitter; |
794 | /* A player who saves but hasn't quit still could have objects |
766 | /* A player who saves but hasn't quit still could have objects |
795 | * owned by him - need to handle that case to avoid crashes. |
767 | * owned by him - need to handle that case to avoid crashes. |
796 | */ |
768 | */ |
797 | if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
769 | if (attacker->flag [FLAG_REMOVED]) |
798 | attacker = hitter; |
770 | attacker = hitter; |
799 | } |
771 | } |
800 | else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
772 | else if (!hitter->flag [FLAG_ALIVE]) |
801 | return 0; |
773 | return 0; |
802 | |
774 | |
803 | /* determine the condtions under which we make an attack. |
775 | /* determine the condtions under which we make an attack. |
804 | * Add more cases, as the need occurs. */ |
776 | * Add more cases, as the need occurs. */ |
805 | |
777 | |
806 | if (!can_see_enemy (attacker, target)) |
778 | if (!can_see_enemy (attacker, target)) |
807 | { |
779 | { |
808 | /* target is unseen */ |
780 | /* target is unseen */ |
809 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
781 | if (target->invisible || attacker->flag [FLAG_BLIND]) |
810 | adjust -= 10; |
782 | adjust -= 10; |
811 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
783 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
812 | else if (!stand_in_light (target)) |
784 | else if (!stand_in_light (target)) |
813 | adjust -= target->map->darklevel (); |
785 | adjust -= target->map->darklevel (); |
814 | } |
786 | } |
815 | |
787 | |
816 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
788 | if (attacker->flag [FLAG_SCARED]) |
817 | adjust -= 3; |
789 | adjust -= 3; |
818 | |
790 | |
819 | if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
791 | if (target->flag [FLAG_UNAGGRESSIVE]) |
820 | adjust += 1; |
792 | adjust += 1; |
821 | |
793 | |
822 | if (QUERY_FLAG (target, FLAG_SCARED)) |
794 | if (target->flag [FLAG_SCARED]) |
823 | adjust += 1; |
795 | adjust += 1; |
824 | |
796 | |
825 | if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
797 | if (attacker->flag [FLAG_CONFUSED]) |
826 | adjust -= 3; |
798 | adjust -= 3; |
827 | |
799 | |
828 | /* if we attack at a different 'altitude' its harder */ |
800 | /* if we attack at a different 'altitude' its harder */ |
829 | if ((attacker->move_type & target->move_type) == 0) |
801 | if ((attacker->move_type & target->move_type) == 0) |
830 | adjust -= 2; |
802 | adjust -= 2; |
… | |
… | |
866 | |
838 | |
867 | /* |
839 | /* |
868 | * A little check to make it more difficult to dance forward and back |
840 | * A little check to make it more difficult to dance forward and back |
869 | * to avoid ever being hit by monsters. |
841 | * to avoid ever being hit by monsters. |
870 | */ |
842 | */ |
871 | if (!simple_attack && QUERY_FLAG (op, FLAG_MONSTER) && op->speed_left > op->speed * -0.3f) |
843 | if (!simple_attack && op->flag [FLAG_MONSTER] && op->speed_left > op->speed * -0.3f) |
872 | { |
844 | { |
873 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
845 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
874 | * infinite loop occurs, with process_object calling move_monster, |
846 | * infinite loop occurs, with process_object calling move_monster, |
875 | * which then gets here again. By decreasing the speed before |
847 | * which then gets here again. By decreasing the speed before |
876 | * we call process_object, the 'if' statement above will fail. |
848 | * we call process_object, the 'if' statement above will fail. |
… | |
… | |
898 | if (!simple_attack) |
870 | if (!simple_attack) |
899 | { |
871 | { |
900 | /* If you hit something, the victim should *always* wake up. |
872 | /* If you hit something, the victim should *always* wake up. |
901 | * Before, invisible hitters could avoid doing this. |
873 | * Before, invisible hitters could avoid doing this. |
902 | * -b.t. */ |
874 | * -b.t. */ |
903 | if (QUERY_FLAG (op, FLAG_SLEEP)) |
875 | if (op->flag [FLAG_SLEEP]) |
904 | CLEAR_FLAG (op, FLAG_SLEEP); |
876 | op->clr_flag (FLAG_SLEEP); |
905 | |
877 | |
906 | /* If the victim can't see the attacker, it may alert others |
878 | /* If the victim can't see the attacker, it may alert others |
907 | * for help. */ |
879 | * for help. */ |
908 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
880 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
909 | npc_call_help (op); |
881 | npc_call_help (op); |
… | |
… | |
929 | } |
901 | } |
930 | |
902 | |
931 | /* Need to do at least 1 damage, otherwise there is no point |
903 | /* Need to do at least 1 damage, otherwise there is no point |
932 | * to go further and it will cause FPE's below. |
904 | * to go further and it will cause FPE's below. |
933 | */ |
905 | */ |
934 | if (hitdam <= 0) |
906 | max_it (hitdam, 1); |
935 | hitdam = 1; |
|
|
936 | |
907 | |
937 | type = hitter->attacktype; |
908 | type = hitter->attacktype; |
938 | |
909 | |
939 | /* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
910 | /* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
940 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
911 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
… | |
… | |
948 | */ |
919 | */ |
949 | if (!type) |
920 | if (!type) |
950 | type = AT_PHYSICAL; |
921 | type = AT_PHYSICAL; |
951 | |
922 | |
952 | /* Handle monsters that hit back */ |
923 | /* Handle monsters that hit back */ |
953 | if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) |
924 | if (!simple_attack && op->flag [FLAG_HITBACK] && hitter->flag [FLAG_ALIVE]) |
954 | { |
925 | { |
955 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
926 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
956 | new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); |
927 | new_draw_info (NDI_UNIQUE, 0, hitter, "You are splashed by acid!\n"); |
957 | |
928 | |
958 | hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
929 | hit_player (hitter, random_roll (0, (op->stats.dam), hitter, PREFER_LOW), op, op->attacktype, 1); |
… | |
… | |
984 | } |
955 | } |
985 | |
956 | |
986 | int |
957 | int |
987 | attack_ob (object *op, object *hitter) |
958 | attack_ob (object *op, object *hitter) |
988 | { |
959 | { |
989 | hitter = hitter->head_ (); |
|
|
990 | |
|
|
991 | return attack_ob_simple (op, hitter, hitter->stats.dam, hitter->stats.wc); |
960 | return attack_ob_simple (op, hitter->head_ (), hitter->stats.dam, hitter->stats.wc); |
992 | } |
961 | } |
993 | |
962 | |
994 | /* op is the arrow, tmp is what is stopping the arrow. |
963 | /* op is the arrow, tmp is what is stopping the arrow. |
995 | * |
964 | * |
996 | * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. |
965 | * Returns 1 if op was inserted into tmp's inventory, 0 otherwise. |
… | |
… | |
1049 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1018 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1050 | * attack_ob_simple() returns, and we've got an arrow that still exists |
1019 | * attack_ob_simple() returns, and we've got an arrow that still exists |
1051 | * but is no longer on the map. Ugh. (Beware: Such things can happen at |
1020 | * but is no longer on the map. Ugh. (Beware: Such things can happen at |
1052 | * other places as well!) |
1021 | * other places as well!) |
1053 | */ |
1022 | */ |
1054 | if (hitter->destroyed () || hitter->env != NULL) |
1023 | if (hitter->destroyed () || hitter->env) |
1055 | { |
1024 | { |
1056 | if (container) |
1025 | if (container) |
1057 | container->destroy (); |
1026 | container->destroy (); |
1058 | |
1027 | |
1059 | return 0; |
1028 | return 0; |
1060 | } |
1029 | } |
1061 | |
1030 | |
1062 | /* Missile hit victim */ |
1031 | /* Missile hit victim */ |
1063 | /* if the speed is > 10, then this is a fast moving arrow, we go straight |
1032 | /* if the speed is >= 10, then this is a fast moving arrow, we go straight |
1064 | * through the target |
1033 | * through the target |
1065 | */ |
1034 | */ |
1066 | if (hit_something && op->speed <= 10.0) |
1035 | if (hit_something) |
|
|
1036 | if (op->speed < 10.0) |
1067 | { |
1037 | { |
1068 | /* Stop arrow */ |
1038 | /* Stop arrow */ |
1069 | if (!container) |
1039 | if (!container) |
1070 | { |
1040 | { |
1071 | hitter = fix_stopped_arrow (hitter); |
1041 | hitter = fix_stopped_arrow (hitter); |
1072 | if (!hitter) |
1042 | if (!hitter) |
1073 | return 0; |
1043 | return 0; |
1074 | } |
1044 | } |
1075 | else |
1045 | else |
1076 | container->destroy (); |
1046 | container->destroy (); |
1077 | |
1047 | |
1078 | /* Try to stick arrow into victim */ |
1048 | /* Try to stick arrow into victim */ |
1079 | if (!victim->destroyed () && stick_arrow (hitter, victim)) |
1049 | if (!victim->destroyed () && stick_arrow (hitter, victim)) |
|
|
1050 | return 0; |
|
|
1051 | |
|
|
1052 | /* Else try to put arrow on victim's map square |
|
|
1053 | * remove check for P_WALL here. If the arrow got to this |
|
|
1054 | * space, that is good enough - with the new movement code, |
|
|
1055 | * there is now the potential for lots of spaces where something |
|
|
1056 | * can fly over but not otherwise move over. What is the correct |
|
|
1057 | * way to handle those otherwise? |
|
|
1058 | */ |
|
|
1059 | if (victim->x != hitter->x || victim->y != hitter->y) |
|
|
1060 | { |
|
|
1061 | if (victim->destroyed ()) |
|
|
1062 | hitter->destroy (); |
|
|
1063 | else |
|
|
1064 | { |
|
|
1065 | hitter->remove (); |
|
|
1066 | hitter->x = victim->x; |
|
|
1067 | hitter->y = victim->y; |
|
|
1068 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
1069 | } |
|
|
1070 | } |
|
|
1071 | else |
|
|
1072 | /* Else leave arrow where it is */ |
|
|
1073 | merge_ob (hitter, NULL); |
|
|
1074 | |
1080 | return 0; |
1075 | return 0; |
1081 | |
|
|
1082 | /* Else try to put arrow on victim's map square |
|
|
1083 | * remove check for P_WALL here. If the arrow got to this |
|
|
1084 | * space, that is good enough - with the new movement code, |
|
|
1085 | * there is now the potential for lots of spaces where something |
|
|
1086 | * can fly over but not otherwise move over. What is the correct |
|
|
1087 | * way to handle those otherwise? |
|
|
1088 | */ |
|
|
1089 | if (victim->x != hitter->x || victim->y != hitter->y) |
|
|
1090 | { |
|
|
1091 | if (victim->destroyed ()) |
|
|
1092 | hitter->destroy (); |
|
|
1093 | else |
|
|
1094 | { |
|
|
1095 | hitter->remove (); |
|
|
1096 | hitter->x = victim->x; |
|
|
1097 | hitter->y = victim->y; |
|
|
1098 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
1099 | } |
|
|
1100 | } |
1076 | } |
1101 | else |
1077 | else |
1102 | /* Else leave arrow where it is */ |
1078 | op->set_speed (op->speed - 1.f); |
1103 | merge_ob (hitter, NULL); |
|
|
1104 | |
|
|
1105 | return 0; |
|
|
1106 | } |
|
|
1107 | |
|
|
1108 | if (hit_something && op->speed >= 10.0) |
|
|
1109 | op->speed -= 1.0; |
|
|
1110 | |
1079 | |
1111 | /* Missile missed victim - reassemble missile */ |
1080 | /* Missile missed victim - reassemble missile */ |
1112 | if (container) |
1081 | if (container) |
1113 | { |
1082 | { |
1114 | hitter->remove (); |
1083 | hitter->remove (); |
… | |
… | |
1182 | * MSW 2002-07-17 |
1151 | * MSW 2002-07-17 |
1183 | */ |
1152 | */ |
1184 | int |
1153 | int |
1185 | kill_object (object *op, int dam, object *hitter, int type) |
1154 | kill_object (object *op, int dam, object *hitter, int type) |
1186 | { |
1155 | { |
1187 | char buf[MAX_BUF]; |
|
|
1188 | shstr skill; |
1156 | shstr skill; |
1189 | int maxdam = 0; |
1157 | int maxdam = 0; |
1190 | int battleg = 0; /* true if op standing on battleground */ |
1158 | int battleg = 0; /* true if op standing on battleground */ |
1191 | int pk = 0; /* true if op and what controls hitter are both players */ |
1159 | int pk = 0; /* true if op and what controls hitter are both players */ |
1192 | object *owner = 0; |
1160 | object *owner = 0; |
… | |
… | |
1202 | * this creature. The function(s) that call us have already |
1170 | * this creature. The function(s) that call us have already |
1203 | * adjusted the creatures HP total, so that is negative. |
1171 | * adjusted the creatures HP total, so that is negative. |
1204 | */ |
1172 | */ |
1205 | maxdam = dam + op->stats.hp + 1; |
1173 | maxdam = dam + op->stats.hp + 1; |
1206 | |
1174 | |
1207 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
1175 | if (op->flag [FLAG_BLOCKSVIEW]) |
1208 | update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ |
1176 | update_all_los (op->map, op->x, op->y); /* makes sure los will be recalculated */ |
1209 | |
1177 | |
1210 | if (op->type == DOOR) |
1178 | if (op->type == DOOR) |
1211 | { |
1179 | { |
1212 | op->set_speed (0.1f); |
1180 | op->set_speed (0.1f); |
1213 | op->speed_left = -0.05f; |
1181 | op->speed_left = -0.05f; |
1214 | return maxdam; |
1182 | return maxdam; |
1215 | } |
1183 | } |
1216 | |
1184 | |
1217 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1185 | if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER) |
1218 | { |
1186 | { |
1219 | op->drop_and_destroy (); |
1187 | op->drop_and_destroy (); |
1220 | return maxdam; |
1188 | return maxdam; |
1221 | } |
1189 | } |
1222 | |
1190 | |
… | |
… | |
1289 | else if (owner->chosen_skill) |
1257 | else if (owner->chosen_skill) |
1290 | { |
1258 | { |
1291 | skop = owner->chosen_skill; |
1259 | skop = owner->chosen_skill; |
1292 | skill = skop->skill; |
1260 | skill = skop->skill; |
1293 | } |
1261 | } |
1294 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1262 | else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon) |
1295 | skill = owner->current_weapon->skill; |
1263 | skill = owner->current_weapon->skill; |
1296 | else |
1264 | else |
1297 | { |
1265 | { |
|
|
1266 | LOG (llevError | logBacktrace, |
1298 | LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" |
1267 | "BUG: kill_object - unable to find skill that killed monster\n" |
1299 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
1268 | "op: %s\n" "hitter: %s\n" "op: %s\n", |
1300 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1269 | op->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1301 | skill = 0; |
1270 | skill = 0; |
1302 | } |
1271 | } |
1303 | |
1272 | |
1304 | /* We have the skill we want to credit to - now find the object this goes |
1273 | /* We have the skill we want to credit to - now find the object this goes |
1305 | * to. Make sure skop is an actual skill, and not a skill tool! |
1274 | * to. Make sure skop is an actual skill, and not a skill tool! |
… | |
… | |
1315 | |
1284 | |
1316 | if (!skill && skop) |
1285 | if (!skill && skop) |
1317 | skill = skop->skill; |
1286 | skill = skop->skill; |
1318 | |
1287 | |
1319 | /* If you didn't kill yourself, and your not the wizard */ |
1288 | /* If you didn't kill yourself, and your not the wizard */ |
1320 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1289 | if (owner != op && !op->flag [FLAG_WIZ]) |
1321 | { |
1290 | { |
1322 | int exp; |
1291 | int exp; |
1323 | |
1292 | |
1324 | /* Really don't give much experience for killing other players */ |
1293 | /* Really don't give much experience for killing other players */ |
1325 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1294 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
… | |
… | |
1382 | } /* else part of a party */ |
1351 | } /* else part of a party */ |
1383 | } /* end if person didn't kill himself */ |
1352 | } /* end if person didn't kill himself */ |
1384 | |
1353 | |
1385 | if (op->type != PLAYER) |
1354 | if (op->type != PLAYER) |
1386 | { |
1355 | { |
1387 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
1356 | if (op->flag [FLAG_FRIENDLY]) |
1388 | { |
1357 | { |
1389 | object *owner1 = op->owner; |
1358 | object *owner1 = op->owner; |
1390 | |
1359 | |
1391 | if (owner1 && owner1->type == PLAYER) |
1360 | if (owner1 && owner1->type == PLAYER) |
1392 | { |
1361 | { |
… | |
… | |
1457 | int |
1426 | int |
1458 | hit_player (object *op, int dam, object *hitter, uint32_t type, int full_hit) |
1427 | hit_player (object *op, int dam, object *hitter, uint32_t type, int full_hit) |
1459 | { |
1428 | { |
1460 | int magic = type & AT_MAGIC; |
1429 | int magic = type & AT_MAGIC; |
1461 | int body_attack = op && op->head; /* Did we hit op's head? */ |
1430 | int body_attack = op && op->head; /* Did we hit op's head? */ |
1462 | int maxdam = 0, ndam = 0, attacktype = 1; |
1431 | int maxdam = 0, ndam = 0; |
1463 | int maxattacktype; |
1432 | int maxattacktype; |
1464 | int simple_attack; |
1433 | int simple_attack; |
1465 | int rtn_kill = 0; |
1434 | int rtn_kill = 0; |
1466 | int friendlyfire; |
1435 | int friendlyfire; |
1467 | |
1436 | |
1468 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1437 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1469 | return 0; |
1438 | return 0; |
1470 | |
1439 | |
1471 | /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ |
1440 | /* very simple: if our target has no_damage 1 set or is wiz, we can't hurt him */ |
1472 | if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
1441 | if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE]) |
1473 | return 0; |
1442 | return 0; |
1474 | |
1443 | |
1475 | // only allow pk for hostile players |
1444 | // only allow pk for hostile players |
1476 | if (op->type == PLAYER) |
1445 | if (op->type == PLAYER) |
1477 | { |
1446 | { |
… | |
… | |
1519 | |
1488 | |
1520 | break; |
1489 | break; |
1521 | } |
1490 | } |
1522 | } |
1491 | } |
1523 | |
1492 | |
1524 | if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
1493 | if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0) |
1525 | { |
1494 | { |
1526 | /* FIXME: If a player is killed by a rune in a door, the |
1495 | /* FIXME: If a player is killed by a rune in a door, the |
1527 | * destroyed() check above doesn't return, and might get here. |
1496 | * destroyed() check above doesn't return, and might get here. |
1528 | */ |
1497 | */ |
1529 | |
1498 | |
… | |
… | |
1570 | object *god; |
1539 | object *god; |
1571 | |
1540 | |
1572 | if ((!hitter->slaying |
1541 | if ((!hitter->slaying |
1573 | || (!(op->race && hitter->slaying.contains (op->race)) |
1542 | || (!(op->race && hitter->slaying.contains (op->race)) |
1574 | && !(op->name && hitter->slaying.contains (op->name)))) |
1543 | && !(op->name && hitter->slaying.contains (op->name)))) |
1575 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1544 | && (!op->flag [FLAG_UNDEAD] |
1576 | || (hitter->title |
1545 | || (hitter->title |
1577 | && (god = find_god (determine_god (hitter))) != NULL |
1546 | && (god = find_god (determine_god (hitter))) != NULL |
1578 | && god->race.contains (shstr_undead)))) |
1547 | && god->race.contains (shstr_undead)))) |
1579 | return 0; |
1548 | return 0; |
1580 | } |
1549 | } |
… | |
… | |
1652 | // keep a refcount for a long time and I see no usefulness |
1621 | // keep a refcount for a long time and I see no usefulness |
1653 | // for an non-active objetc to know its enemy. |
1622 | // for an non-active objetc to know its enemy. |
1654 | if (op->active) |
1623 | if (op->active) |
1655 | if (hitter->owner) |
1624 | if (hitter->owner) |
1656 | op->enemy = hitter->owner; |
1625 | op->enemy = hitter->owner; |
1657 | else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1626 | else if (hitter->flag [FLAG_ALIVE]) |
1658 | op->enemy = hitter; |
1627 | op->enemy = hitter; |
1659 | |
1628 | |
1660 | if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
1629 | if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER) |
1661 | { |
1630 | { |
1662 | /* The unaggressives look after themselves 8) */ |
1631 | /* The unaggressives look after themselves 8) */ |
1663 | CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
1632 | op->clr_flag (FLAG_UNAGGRESSIVE); |
1664 | npc_call_help (op); |
1633 | npc_call_help (op); |
1665 | } |
1634 | } |
1666 | |
1635 | |
1667 | if (magic && did_make_save (op, op->level, 0)) |
1636 | if (magic && did_make_save (op, op->level, 0)) |
1668 | maxdam = maxdam / 2; |
1637 | maxdam = maxdam / 2; |
… | |
… | |
1671 | |
1640 | |
1672 | op->stats.hp -= maxdam; |
1641 | op->stats.hp -= maxdam; |
1673 | |
1642 | |
1674 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1643 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1675 | if (op->stats.hp >= 0 |
1644 | if (op->stats.hp >= 0 |
1676 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
1645 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
1677 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1646 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1678 | { |
1647 | { |
1679 | |
1648 | |
1680 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1649 | if (op->flag [FLAG_MONSTER]) |
1681 | SET_FLAG (op, FLAG_RUN_AWAY); |
1650 | op->set_flag (FLAG_RUN_AWAY); |
1682 | else |
1651 | else |
1683 | scare_creature (op, hitter); |
1652 | scare_creature (op, hitter); |
1684 | } |
1653 | } |
1685 | |
1654 | |
1686 | if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
1655 | if (op->flag [FLAG_TEAR_DOWN]) |
1687 | { |
1656 | { |
1688 | if (maxdam) |
1657 | if (maxdam) |
1689 | tear_down_wall (op); |
1658 | tear_down_wall (op); |
1690 | |
1659 | |
1691 | return maxdam; /* nothing more to do for wall */ |
1660 | return maxdam; /* nothing more to do for wall */ |
… | |
… | |
1698 | |
1667 | |
1699 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1668 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1700 | * that before if the player was immune to ghosthit, the monster |
1669 | * that before if the player was immune to ghosthit, the monster |
1701 | * remained - that is no longer the case. |
1670 | * remained - that is no longer the case. |
1702 | */ |
1671 | */ |
1703 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1672 | if (hitter->flag [FLAG_ONE_HIT]) |
1704 | hitter->drop_and_destroy (); |
1673 | hitter->drop_and_destroy (); |
1705 | /* Lets handle creatures that are splitting now */ |
1674 | /* Lets handle creatures that are splitting now */ |
1706 | else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) |
1675 | else if (type & AT_PHYSICAL && !op->flag [FLAG_FREED] && op->flag [FLAG_SPLITTING]) |
1707 | { |
1676 | { |
1708 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1677 | int friendly = op->flag [FLAG_FRIENDLY]; |
1709 | int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
1678 | int unaggressive = op->flag [FLAG_UNAGGRESSIVE]; |
1710 | object *owner = op->owner; |
1679 | object *owner = op->owner; |
1711 | |
1680 | |
1712 | if (!op->other_arch) |
1681 | if (!op->other_arch) |
1713 | { |
1682 | { |
1714 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1683 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
… | |
… | |
1731 | if (owner) |
1700 | if (owner) |
1732 | tmp->set_owner (owner); |
1701 | tmp->set_owner (owner); |
1733 | } |
1702 | } |
1734 | |
1703 | |
1735 | if (unaggressive) |
1704 | if (unaggressive) |
1736 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
1705 | tmp->set_flag (FLAG_UNAGGRESSIVE); |
1737 | |
1706 | |
1738 | int j = find_first_free_spot (tmp, op->map, op->x, op->y); |
1707 | int j = find_first_free_spot (tmp, op->map, op->x, op->y); |
1739 | |
1708 | |
1740 | if (j == -1) /* No spot to put this monster */ |
1709 | if (j == -1) /* No spot to put this monster */ |
1741 | tmp->destroy (); |
1710 | tmp->destroy (); |
… | |
… | |
1758 | poison_player (object *op, object *hitter, int dam) |
1727 | poison_player (object *op, object *hitter, int dam) |
1759 | { |
1728 | { |
1760 | archetype *at = archetype::find (shstr_poisoning); |
1729 | archetype *at = archetype::find (shstr_poisoning); |
1761 | object *tmp = present_arch_in_ob (at, op); |
1730 | object *tmp = present_arch_in_ob (at, op); |
1762 | |
1731 | |
1763 | if (tmp == NULL) |
1732 | if (!tmp) |
1764 | { |
1733 | { |
1765 | tmp = insert_ob_in_ob (at->instance (), op); |
1734 | tmp = insert_ob_in_ob (at->instance (), op); |
1766 | /* peterm: give poisoning some teeth. It should |
1735 | /* peterm: give poisoning some teeth. It should |
1767 | * be able to kill things better than it does: |
1736 | * be able to kill things better than it does: |
1768 | * damage should be dependent something--I choose to |
1737 | * damage should be dependent something--I choose to |
1769 | * do this: if it's a monster, the damage from the |
1738 | * do this: if it's a monster, the damage from the |
1770 | * poisoning goes as the level of the monster/2. |
1739 | * poisoning goes as the level of the monster/2. |
1771 | * If anything else, goes as damage. |
1740 | * If anything else, goes as damage. |
1772 | */ |
1741 | */ |
1773 | |
1742 | |
1774 | if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1743 | if (hitter->flag [FLAG_ALIVE]) |
1775 | tmp->stats.dam += hitter->level / 2; |
1744 | tmp->stats.dam += hitter->level / 2; |
1776 | else |
1745 | else |
1777 | tmp->stats.dam = dam; |
1746 | tmp->stats.dam = dam; |
1778 | |
1747 | |
1779 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1748 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
… | |
… | |
1787 | /* player looses stats, maximum is -10 of each */ |
1756 | /* player looses stats, maximum is -10 of each */ |
1788 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1757 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1789 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1758 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1790 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1759 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1791 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1760 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1792 | SET_FLAG (tmp, FLAG_APPLIED); |
1761 | tmp->set_flag (FLAG_APPLIED); |
1793 | op->update_stats (); |
1762 | op->update_stats (); |
1794 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); |
1763 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very ill."); |
1795 | op->play_sound (tmp->sound); |
1764 | op->play_sound (tmp->sound); |
1796 | } |
1765 | } |
1797 | |
1766 | |
… | |
… | |
1810 | slow_player (object *op, object *hitter, int dam) |
1779 | slow_player (object *op, object *hitter, int dam) |
1811 | { |
1780 | { |
1812 | archetype *at = archetype::find (shstr_slowness); |
1781 | archetype *at = archetype::find (shstr_slowness); |
1813 | object *tmp; |
1782 | object *tmp; |
1814 | |
1783 | |
1815 | if (at == NULL) |
1784 | if (!at) |
1816 | LOG (llevError, "Can't find slowness archetype.\n"); |
1785 | LOG (llevError, "Can't find slowness archetype.\n"); |
1817 | |
1786 | |
1818 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1787 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1819 | { |
1788 | { |
1820 | tmp = at->instance (); |
1789 | tmp = at->instance (); |
… | |
… | |
1822 | new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); |
1791 | new_draw_info (NDI_UNIQUE, 0, op, "The world suddenly moves very fast!"); |
1823 | } |
1792 | } |
1824 | else |
1793 | else |
1825 | tmp->stats.food++; |
1794 | tmp->stats.food++; |
1826 | |
1795 | |
1827 | SET_FLAG (tmp, FLAG_APPLIED); |
1796 | tmp->set_flag (FLAG_APPLIED); |
1828 | tmp->speed_left = 0; |
1797 | tmp->speed_left = 0; |
1829 | op->update_stats (); |
1798 | op->update_stats (); |
1830 | } |
1799 | } |
1831 | |
1800 | |
1832 | void |
1801 | void |
… | |
… | |
1836 | int maxduration; |
1805 | int maxduration; |
1837 | |
1806 | |
1838 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1807 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1839 | if (!tmp) |
1808 | if (!tmp) |
1840 | { |
1809 | { |
1841 | tmp = get_archetype (FORCE_NAME); |
1810 | tmp = archetype::get (FORCE_NAME); |
1842 | tmp = insert_ob_in_ob (tmp, op); |
1811 | tmp = insert_ob_in_ob (tmp, op); |
1843 | } |
1812 | } |
1844 | |
1813 | |
1845 | /* Duration added per hit and max. duration of confusion both depend |
1814 | /* Duration added per hit and max. duration of confusion both depend |
1846 | * on the player's resistance |
1815 | * on the player's resistance |
1847 | */ |
1816 | */ |
1848 | tmp->speed = 0.05; |
1817 | tmp->set_speed (0.05); |
1849 | tmp->subtype = FORCE_CONFUSION; |
1818 | tmp->subtype = FORCE_CONFUSION; |
1850 | tmp->duration = 8 + max (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1819 | tmp->duration = 8 + max (1, 5 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1851 | tmp->name = shstr_confusion; |
1820 | tmp->name = shstr_confusion; |
1852 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1821 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1853 | |
1822 | |
1854 | if (tmp->duration > maxduration) |
1823 | if (tmp->duration > maxduration) |
1855 | tmp->duration = maxduration; |
1824 | tmp->duration = maxduration; |
1856 | |
1825 | |
1857 | if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
1826 | if (op->type == PLAYER && !op->flag [FLAG_CONFUSED]) |
1858 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); |
1827 | new_draw_info (NDI_UNIQUE, 0, op, "You suddenly feel very confused!"); |
1859 | |
1828 | |
1860 | SET_FLAG (op, FLAG_CONFUSED); |
1829 | op->set_flag (FLAG_CONFUSED); |
1861 | } |
1830 | } |
1862 | |
1831 | |
1863 | void |
1832 | void |
1864 | blind_player (object *op, object *hitter, int dam) |
1833 | blind_player (object *op, object *hitter, int dam) |
1865 | { |
1834 | { |
1866 | object *tmp, *owner; |
|
|
1867 | |
|
|
1868 | /* Save some work if we know it isn't going to affect the player */ |
1835 | /* Save some work if we know it isn't going to affect the player */ |
1869 | if (op->resist[ATNR_BLIND] == 100) |
1836 | if (op->resist[ATNR_BLIND] == 100) |
1870 | return; |
1837 | return; |
1871 | |
1838 | |
1872 | tmp = present_in_ob (BLINDNESS, op); |
1839 | object *tmp = present_in_ob (BLINDNESS, op); |
1873 | if (!tmp) |
1840 | if (!tmp) |
1874 | { |
1841 | { |
1875 | tmp = get_archetype (shstr_blindness); |
1842 | tmp = archetype::get (shstr_blindness); |
1876 | SET_FLAG (tmp, FLAG_BLIND); |
1843 | tmp->set_flag (FLAG_BLIND); |
1877 | SET_FLAG (tmp, FLAG_APPLIED); |
1844 | tmp->set_flag (FLAG_APPLIED); |
1878 | /* use floats so we don't lose too much precision due to rounding errors. |
1845 | // use floats so we don't lose too much precision due to rounding errors. |
1879 | * speed is a float anyways. |
1846 | tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED)); |
1880 | */ |
|
|
1881 | tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
|
|
1882 | |
1847 | |
1883 | tmp = insert_ob_in_ob (tmp, op); |
1848 | tmp = insert_ob_in_ob (tmp, op); |
1884 | change_abil (op, tmp); /* Mostly to display any messages */ |
1849 | change_abil (op, tmp); /* Mostly to display any messages */ |
1885 | op->update_stats (); /* This takes care of some other stuff */ |
1850 | op->update_stats (); /* This takes care of some other stuff */ |
1886 | |
1851 | |
1887 | if (hitter->owner) |
|
|
1888 | owner = hitter->owner; |
|
|
1889 | else |
|
|
1890 | owner = hitter; |
|
|
1891 | |
|
|
1892 | new_draw_info_format (NDI_UNIQUE, 0, owner, "Your attack blinds %s!", query_name (op)); |
1852 | new_draw_info_format (NDI_UNIQUE, 0, hitter->outer_owner (), "Your attack blinds %s!", query_name (op)); |
1893 | } |
1853 | } |
|
|
1854 | |
1894 | tmp->stats.food += dam; |
1855 | tmp->stats.food += dam; |
1895 | if (tmp->stats.food > 10) |
1856 | min_it (tmp->stats.food, 10); |
1896 | tmp->stats.food = 10; |
|
|
1897 | } |
1857 | } |
1898 | |
1858 | |
1899 | void |
1859 | void |
1900 | paralyze_player (object *op, object *hitter, int dam) |
1860 | paralyze_player (object *op, object *hitter, int dam) |
1901 | { |
1861 | { |
… | |
… | |
1940 | ** field of the deathstriking object */ |
1900 | ** field of the deathstriking object */ |
1941 | |
1901 | |
1942 | int atk_lev, def_lev, kill_lev; |
1902 | int atk_lev, def_lev, kill_lev; |
1943 | |
1903 | |
1944 | if (hitter->slaying) |
1904 | if (hitter->slaying) |
1945 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
1905 | if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead)) |
1946 | || (op->race && hitter->slaying.contains (op->race)))) |
1906 | || (op->race && hitter->slaying.contains (op->race)))) |
1947 | return; |
1907 | return; |
1948 | |
1908 | |
1949 | def_lev = op->level; |
1909 | def_lev = op->level; |
1950 | if (def_lev < 1) |
1910 | if (def_lev < 1) |
… | |
… | |
2075 | * Second, just getting hit doesn't mean it always affects |
2035 | * Second, just getting hit doesn't mean it always affects |
2076 | * you. Third, you still get a saving through against the |
2036 | * you. Third, you still get a saving through against the |
2077 | * effect. |
2037 | * effect. |
2078 | */ |
2038 | */ |
2079 | if (op->has_active_speed () |
2039 | if (op->has_active_speed () |
2080 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
2040 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
2081 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2041 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2082 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2042 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2083 | { |
2043 | { |
2084 | |
2044 | |
2085 | /* Player has been hit by something */ |
2045 | /* Player has been hit by something */ |
… | |
… | |
2095 | scare_creature (op, hitter); |
2055 | scare_creature (op, hitter); |
2096 | else if (attacknum == ATNR_CANCELLATION) |
2056 | else if (attacknum == ATNR_CANCELLATION) |
2097 | cancellation (op); |
2057 | cancellation (op); |
2098 | else if (attacknum == ATNR_DEPLETE) |
2058 | else if (attacknum == ATNR_DEPLETE) |
2099 | op->drain_stat (); |
2059 | op->drain_stat (); |
2100 | else if (attacknum == ATNR_BLIND && !QUERY_FLAG (op, FLAG_UNDEAD) && !QUERY_FLAG (op, FLAG_GENERATOR)) |
2060 | else if (attacknum == ATNR_BLIND && !op->flag [FLAG_UNDEAD] && !op->flag [FLAG_GENERATOR]) |
2101 | blind_player (op, hitter, dam); |
2061 | blind_player (op, hitter, dam); |
2102 | } |
2062 | } |
2103 | |
2063 | |
2104 | dam = 0; /* These are all effects and don't do real damage */ |
2064 | dam = 0; /* These are all effects and don't do real damage */ |
2105 | } |
2065 | } |
… | |
… | |
2115 | { |
2075 | { |
2116 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2076 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2117 | { |
2077 | { |
2118 | if (tmp->invisible) |
2078 | if (tmp->invisible) |
2119 | continue; |
2079 | continue; |
2120 | if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
2080 | if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10)) |
2121 | /* >= 10% acid res. on items will protect these */ |
2081 | /* >= 10% acid res. on items will protect these */ |
2122 | continue; |
2082 | continue; |
2123 | if (!(tmp->materials & M_IRON)) |
2083 | if (!(tmp->materials & M_IRON)) |
2124 | continue; |
2084 | continue; |
2125 | if (tmp->magic < -4) /* Let's stop at -5 */ |
2085 | if (tmp->magic < -4) /* Let's stop at -5 */ |
… | |
… | |
2170 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2130 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2171 | |
2131 | |
2172 | if (op->stats.exp <= rate) |
2132 | if (op->stats.exp <= rate) |
2173 | { |
2133 | { |
2174 | if (op->type == GOLEM) |
2134 | if (op->type == GOLEM) |
2175 | dam = 999; /* Its force is "sucked" away. 8) */ |
2135 | dam = 9998; /* Its force is "sucked" away. 8) */ |
2176 | else |
2136 | else |
2177 | /* If we can't drain, lets try to do physical damage */ |
2137 | /* If we can't drain, lets try to do physical damage */ |
2178 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2138 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2179 | } |
2139 | } |
2180 | else |
2140 | else |
… | |
… | |
2189 | * exp, but the wiz would still lose exp! If drainee is a wiz, |
2149 | * exp, but the wiz would still lose exp! If drainee is a wiz, |
2190 | * nothing happens. |
2150 | * nothing happens. |
2191 | * Try to credit the owner. We try to display player -> player drain |
2151 | * Try to credit the owner. We try to display player -> player drain |
2192 | * attacks, hence all the != PLAYER checks. |
2152 | * attacks, hence all the != PLAYER checks. |
2193 | */ |
2153 | */ |
2194 | if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
2154 | if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ]) |
2195 | { |
2155 | { |
2196 | object *owner = hitter->owner; |
2156 | object *owner = hitter->owner; |
2197 | |
2157 | |
2198 | if (owner && owner != hitter) |
2158 | if (owner && owner != hitter) |
2199 | { |
2159 | { |
2200 | if (op->type != PLAYER || owner->type != PLAYER) |
2160 | if (op->type != PLAYER || owner->type != PLAYER) |
2201 | change_exp (owner, op->stats.exp / (rate * 2), |
2161 | change_exp (owner, op->stats.exp / (rate * 2), |
2202 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, SK_EXP_TOTAL); |
2162 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), SK_EXP_TOTAL); |
2203 | } |
2163 | } |
2204 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2164 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2205 | change_exp (hitter, op->stats.exp / (rate * 2), |
2165 | change_exp (hitter, op->stats.exp / (rate * 2), |
2206 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
2166 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0); |
2207 | |
2167 | |
2208 | change_exp (op, -op->stats.exp / rate, NULL, 0); |
2168 | change_exp (op, -op->stats.exp / rate, shstr (), 0); |
2209 | } |
2169 | } |
2210 | |
2170 | |
2211 | dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure |
2171 | dam = 1; /* Drain is an effect. Still return 1 - otherwise, if you have pure |
2212 | * drain attack, you won't know that you are actually sucking out EXP, |
2172 | * drain attack, you won't know that you are actually sucking out EXP, |
2213 | * as the messages will say you missed |
2173 | * as the messages will say you missed |
… | |
… | |
2216 | } |
2176 | } |
2217 | break; |
2177 | break; |
2218 | |
2178 | |
2219 | case ATNR_TURN_UNDEAD: |
2179 | case ATNR_TURN_UNDEAD: |
2220 | { |
2180 | { |
2221 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
2181 | if (op->flag [FLAG_UNDEAD]) |
2222 | { |
2182 | { |
2223 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2183 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2224 | object *god = find_god (determine_god (owner)); |
2184 | object *god = find_god (determine_god (owner)); |
2225 | int div = 1; |
2185 | int div = 1; |
2226 | |
2186 | |
… | |
… | |
2281 | * damage it does do to the player. Given that, |
2241 | * damage it does do to the player. Given that, |
2282 | * it only does 1/10'th normal damage (hence the divide by |
2242 | * it only does 1/10'th normal damage (hence the divide by |
2283 | * 1000). |
2243 | * 1000). |
2284 | */ |
2244 | */ |
2285 | /* You can't steal life from something undead */ |
2245 | /* You can't steal life from something undead */ |
2286 | if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
2246 | if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD])) |
2287 | return 0; |
2247 | return 0; |
2288 | |
2248 | |
2289 | /* If drain protection is higher than life stealing, use that */ |
2249 | /* If drain protection is higher than life stealing, use that */ |
2290 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2250 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2291 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
2251 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |