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 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 | } |
… | |
… | |
131 | * calling cancellation, etc.) |
125 | * calling cancellation, etc.) |
132 | */ |
126 | */ |
133 | void |
127 | void |
134 | save_throw_object (object *op, int type, object *originator) |
128 | save_throw_object (object *op, int type, object *originator) |
135 | { |
129 | { |
|
|
130 | op = op->head_ (); |
|
|
131 | |
136 | if (!did_make_save_item (op, type, originator)) |
132 | if (!did_make_save_item (op, type, originator)) |
137 | { |
133 | { |
138 | object *env = op->env; |
134 | object *env = op->env; |
139 | int x = op->x, y = op->y; |
135 | int x = op->x, y = op->y; |
140 | maptile *m = op->map; |
136 | maptile *m = op->map; |
… | |
… | |
213 | |
209 | |
214 | return; |
210 | return; |
215 | } |
211 | } |
216 | |
212 | |
217 | /* The value of 50 is arbitrary. */ |
213 | /* The value of 50 is arbitrary. */ |
218 | 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)) |
219 | { |
215 | { |
220 | archetype *at = archetype::find (shstr_icecube); |
216 | archetype *at = archetype::find (shstr_icecube); |
221 | |
217 | |
222 | if (at == NULL) |
218 | if (at == NULL) |
223 | return; |
219 | return; |
… | |
… | |
227 | return; |
223 | return; |
228 | |
224 | |
229 | object *tmp = present_arch (at, op->map, op->x, op->y); |
225 | object *tmp = present_arch (at, op->map, op->x, op->y); |
230 | if (!tmp) |
226 | if (!tmp) |
231 | { |
227 | { |
232 | tmp = arch_to_object (at); |
228 | tmp = at->instance (); |
233 | tmp->x = op->x, tmp->y = op->y; |
229 | tmp->x = op->x, tmp->y = op->y; |
234 | /* This was in the old (pre new movement code) - |
230 | /* This was in the old (pre new movement code) - |
235 | * icecubes have slow_move set to 1 - don't want |
231 | * icecubes have slow_move set to 1 - don't want |
236 | * that for ones we create. |
232 | * that for ones we create. |
237 | */ |
233 | */ |
… | |
… | |
252 | * returns 1 if it hits something, 0 otherwise. |
248 | * returns 1 if it hits something, 0 otherwise. |
253 | */ |
249 | */ |
254 | int |
250 | int |
255 | 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) |
256 | { |
252 | { |
257 | maptile *map; |
|
|
258 | sint16 x, y; |
253 | sint16 x, y; |
259 | 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 */ |
260 | |
255 | |
261 | if (QUERY_FLAG (op, FLAG_FREED)) |
256 | if (op->flag [FLAG_FREED]) |
262 | { |
257 | { |
263 | LOG (llevError, "BUG: hit_map(): free object\n"); |
258 | LOG (llevError, "BUG: hit_map(): free object\n"); |
264 | return 0; |
259 | return 0; |
265 | } |
260 | } |
266 | |
261 | |
267 | if (QUERY_FLAG (op, FLAG_REMOVED) || op->env != NULL) |
262 | if (op->flag [FLAG_REMOVED] || op->env != NULL) |
268 | { |
263 | { |
269 | 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); |
270 | return 0; |
265 | return 0; |
271 | } |
266 | } |
272 | |
267 | |
… | |
… | |
336 | * 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. |
337 | */ |
332 | */ |
338 | 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) |
339 | continue; |
334 | continue; |
340 | |
335 | |
341 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
336 | if (tmp->flag [FLAG_ALIVE]) |
342 | { |
337 | { |
343 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
338 | hit_player (tmp, op->stats.dam, op, type, full_hit); |
344 | retflag |= 1; |
339 | retflag |= 1; |
345 | |
340 | |
346 | if (op->destroyed ()) |
341 | if (op->destroyed ()) |
… | |
… | |
362 | if (op->destroyed ()) |
357 | if (op->destroyed ()) |
363 | break; |
358 | break; |
364 | } |
359 | } |
365 | } |
360 | } |
366 | |
361 | |
367 | return 0; |
362 | return retflag; |
368 | } |
363 | } |
369 | |
364 | |
370 | static void |
365 | static void |
371 | attack_message (int dam, int type, object *op, object *hitter) |
366 | attack_message (int dam, int type, object *op, object *hitter) |
372 | { |
367 | { |
… | |
… | |
521 | { |
516 | { |
522 | int mtype; |
517 | int mtype; |
523 | |
518 | |
524 | switch (hitter->current_weapon->weapontype) |
519 | switch (hitter->current_weapon->weapontype) |
525 | { |
520 | { |
526 | case WEAP_HIT: |
521 | case WEAP_HIT: mtype = ATM_BASIC; break; |
527 | mtype = ATM_BASIC; |
522 | case WEAP_SLASH: mtype = ATM_SLASH; break; |
528 | break; |
523 | case WEAP_PIERCE: mtype = ATM_PIERCE; break; |
529 | case WEAP_SLASH: |
524 | case WEAP_CLEAVE: mtype = ATM_CLEAVE; break; |
530 | mtype = ATM_SLASH; |
525 | case WEAP_SLICE: mtype = ATM_SLICE; break; |
531 | break; |
526 | case WEAP_STAB: mtype = ATM_STAB; break; |
532 | case WEAP_PIERCE: |
527 | case WEAP_WHIP: mtype = ATM_WHIP; break; |
533 | mtype = ATM_PIERCE; |
528 | case WEAP_CRUSH: mtype = ATM_CRUSH; break; |
534 | break; |
529 | case WEAP_BLUD: mtype = ATM_BLUD; break; |
535 | case WEAP_CLEAVE: |
530 | default: mtype = ATM_BASIC; break; |
536 | mtype = ATM_CLEAVE; |
|
|
537 | break; |
|
|
538 | case WEAP_SLICE: |
|
|
539 | mtype = ATM_SLICE; |
|
|
540 | break; |
|
|
541 | case WEAP_STAB: |
|
|
542 | mtype = ATM_STAB; |
|
|
543 | break; |
|
|
544 | case WEAP_WHIP: |
|
|
545 | mtype = ATM_WHIP; |
|
|
546 | break; |
|
|
547 | case WEAP_CRUSH: |
|
|
548 | mtype = ATM_CRUSH; |
|
|
549 | break; |
|
|
550 | case WEAP_BLUD: |
|
|
551 | mtype = ATM_BLUD; |
|
|
552 | break; |
|
|
553 | default: |
|
|
554 | mtype = ATM_BASIC; |
|
|
555 | break; |
|
|
556 | } |
531 | } |
557 | |
532 | |
558 | 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++) |
559 | 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) |
560 | { |
535 | { |
… | |
… | |
666 | } |
641 | } |
667 | |
642 | |
668 | static int |
643 | static int |
669 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
644 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
670 | { |
645 | { |
671 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
646 | if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED]) |
672 | { |
647 | { |
673 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
648 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
674 | return 1; |
649 | return 1; |
675 | } |
650 | } |
676 | |
651 | |
… | |
… | |
684 | { |
659 | { |
685 | *simple_attack = 1; |
660 | *simple_attack = 1; |
686 | return 0; |
661 | return 0; |
687 | } |
662 | } |
688 | |
663 | |
689 | if (QUERY_FLAG (*target, FLAG_REMOVED) |
664 | if ((*target)->flag [FLAG_REMOVED] |
690 | || QUERY_FLAG (*hitter, FLAG_REMOVED) |
665 | || (*hitter)->flag [FLAG_REMOVED] |
691 | || !(*hitter)->map |
666 | || !(*hitter)->map |
692 | || !on_same_map (*hitter, *target)) |
667 | || !on_same_map (*hitter, *target)) |
693 | { |
668 | { |
694 | 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", |
695 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
670 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
… | |
… | |
708 | */ |
683 | */ |
709 | int new_mode; |
684 | int new_mode; |
710 | |
685 | |
711 | if (hitter->env == target || target->env == hitter) |
686 | if (hitter->env == target || target->env == hitter) |
712 | new_mode = 1; |
687 | new_mode = 1; |
713 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
688 | else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED] |
714 | || hitter->map == NULL || !on_same_map (hitter, target)) |
689 | || hitter->map == NULL || !on_same_map (hitter, target)) |
715 | return 1; |
690 | return 1; |
716 | else |
691 | else |
717 | new_mode = 0; |
692 | new_mode = 0; |
718 | |
693 | |
… | |
… | |
724 | * monster). |
699 | * monster). |
725 | */ |
700 | */ |
726 | static void |
701 | static void |
727 | thrown_item_effect (object *hitter, object *victim) |
702 | thrown_item_effect (object *hitter, object *victim) |
728 | { |
703 | { |
729 | if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
704 | if (!hitter->flag [FLAG_ALIVE]) |
730 | { |
705 | { |
731 | /* 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 |
732 | * easier for expansion. |
707 | * easier for expansion. |
733 | */ |
708 | */ |
734 | switch (hitter->type) |
709 | switch (hitter->type) |
735 | { |
710 | { |
736 | case POTION: |
711 | case POTION: |
737 | /* should player get a save throw instead of checking magic protection? */ |
712 | /* should player get a save throw instead of checking magic protection? */ |
738 | 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)) |
739 | (void) apply_potion (victim, hitter); |
714 | apply_potion (victim, hitter); |
740 | break; |
715 | break; |
741 | |
716 | |
742 | case POISON: /* poison drinks */ |
717 | case POISON: /* poison drinks */ |
743 | /* As with potions, should monster get a save? */ |
718 | /* As with potions, should monster get a save? */ |
744 | 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)) |
745 | apply_poison (victim, hitter); |
720 | apply_poison (victim, hitter); |
746 | break; |
721 | break; |
747 | |
722 | |
748 | /* Removed case statements that did nothing. |
723 | /* Removed case statements that did nothing. |
749 | * 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, |
… | |
… | |
756 | |
731 | |
757 | /* determine if the object is an 'aimed' missile */ |
732 | /* determine if the object is an 'aimed' missile */ |
758 | static int |
733 | static int |
759 | is_aimed_missile (object *op) |
734 | is_aimed_missile (object *op) |
760 | { |
735 | { |
761 | |
|
|
762 | /* 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 |
763 | * ones so that figuring out the logic is at least possible. |
737 | * ones so that figuring out the logic is at least possible. |
764 | */ |
738 | */ |
765 | if (op && (op->move_type & MOVE_FLYING)) |
739 | if (op && (op->move_type & MOVE_FLYING)) |
766 | if (op->type == ARROW || op->type == THROWN_OBJ) |
740 | if (op->type == ARROW || op->type == THROWN_OBJ) |
… | |
… | |
790 | if ((attacker = hitter->owner) == NULL) |
764 | if ((attacker = hitter->owner) == NULL) |
791 | attacker = hitter; |
765 | attacker = hitter; |
792 | /* 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 |
793 | * owned by him - need to handle that case to avoid crashes. |
767 | * owned by him - need to handle that case to avoid crashes. |
794 | */ |
768 | */ |
795 | if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
769 | if (attacker->flag [FLAG_REMOVED]) |
796 | attacker = hitter; |
770 | attacker = hitter; |
797 | } |
771 | } |
798 | else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
772 | else if (!hitter->flag [FLAG_ALIVE]) |
799 | return 0; |
773 | return 0; |
800 | |
774 | |
801 | /* determine the condtions under which we make an attack. |
775 | /* determine the condtions under which we make an attack. |
802 | * Add more cases, as the need occurs. */ |
776 | * Add more cases, as the need occurs. */ |
803 | |
777 | |
804 | if (!can_see_enemy (attacker, target)) |
778 | if (!can_see_enemy (attacker, target)) |
805 | { |
779 | { |
806 | /* target is unseen */ |
780 | /* target is unseen */ |
807 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
781 | if (target->invisible || attacker->flag [FLAG_BLIND]) |
808 | adjust -= 10; |
782 | adjust -= 10; |
809 | /* 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). */ |
810 | else if (!stand_in_light (target)) |
784 | else if (!stand_in_light (target)) |
811 | adjust -= target->map->darklevel (); |
785 | adjust -= target->map->darklevel (); |
812 | } |
786 | } |
813 | |
787 | |
814 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
788 | if (attacker->flag [FLAG_SCARED]) |
815 | adjust -= 3; |
789 | adjust -= 3; |
816 | |
790 | |
817 | if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
791 | if (target->flag [FLAG_UNAGGRESSIVE]) |
818 | adjust += 1; |
792 | adjust += 1; |
819 | |
793 | |
820 | if (QUERY_FLAG (target, FLAG_SCARED)) |
794 | if (target->flag [FLAG_SCARED]) |
821 | adjust += 1; |
795 | adjust += 1; |
822 | |
796 | |
823 | if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
797 | if (attacker->flag [FLAG_CONFUSED]) |
824 | adjust -= 3; |
798 | adjust -= 3; |
825 | |
799 | |
826 | /* if we attack at a different 'altitude' its harder */ |
800 | /* if we attack at a different 'altitude' its harder */ |
827 | if ((attacker->move_type & target->move_type) == 0) |
801 | if ((attacker->move_type & target->move_type) == 0) |
828 | adjust -= 2; |
802 | adjust -= 2; |
… | |
… | |
864 | |
838 | |
865 | /* |
839 | /* |
866 | * 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 |
867 | * to avoid ever being hit by monsters. |
841 | * to avoid ever being hit by monsters. |
868 | */ |
842 | */ |
869 | 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) |
870 | { |
844 | { |
871 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
845 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
872 | * infinite loop occurs, with process_object calling move_monster, |
846 | * infinite loop occurs, with process_object calling move_monster, |
873 | * which then gets here again. By decreasing the speed before |
847 | * which then gets here again. By decreasing the speed before |
874 | * we call process_object, the 'if' statement above will fail. |
848 | * we call process_object, the 'if' statement above will fail. |
… | |
… | |
896 | if (!simple_attack) |
870 | if (!simple_attack) |
897 | { |
871 | { |
898 | /* If you hit something, the victim should *always* wake up. |
872 | /* If you hit something, the victim should *always* wake up. |
899 | * Before, invisible hitters could avoid doing this. |
873 | * Before, invisible hitters could avoid doing this. |
900 | * -b.t. */ |
874 | * -b.t. */ |
901 | if (QUERY_FLAG (op, FLAG_SLEEP)) |
875 | if (op->flag [FLAG_SLEEP]) |
902 | CLEAR_FLAG (op, FLAG_SLEEP); |
876 | op->clr_flag (FLAG_SLEEP); |
903 | |
877 | |
904 | /* 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 |
905 | * for help. */ |
879 | * for help. */ |
906 | 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)) |
907 | npc_call_help (op); |
881 | npc_call_help (op); |
… | |
… | |
927 | } |
901 | } |
928 | |
902 | |
929 | /* 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 |
930 | * to go further and it will cause FPE's below. |
904 | * to go further and it will cause FPE's below. |
931 | */ |
905 | */ |
932 | if (hitdam <= 0) |
906 | max_it (hitdam, 1); |
933 | hitdam = 1; |
|
|
934 | |
907 | |
935 | type = hitter->attacktype; |
908 | type = hitter->attacktype; |
936 | |
909 | |
937 | /* 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* |
938 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
911 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
… | |
… | |
946 | */ |
919 | */ |
947 | if (!type) |
920 | if (!type) |
948 | type = AT_PHYSICAL; |
921 | type = AT_PHYSICAL; |
949 | |
922 | |
950 | /* Handle monsters that hit back */ |
923 | /* Handle monsters that hit back */ |
951 | 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]) |
952 | { |
925 | { |
953 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
926 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
954 | 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"); |
955 | |
928 | |
956 | 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); |
… | |
… | |
982 | } |
955 | } |
983 | |
956 | |
984 | int |
957 | int |
985 | attack_ob (object *op, object *hitter) |
958 | attack_ob (object *op, object *hitter) |
986 | { |
959 | { |
987 | hitter = hitter->head_ (); |
|
|
988 | |
|
|
989 | 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); |
990 | } |
961 | } |
991 | |
962 | |
992 | /* op is the arrow, tmp is what is stopping the arrow. |
963 | /* op is the arrow, tmp is what is stopping the arrow. |
993 | * |
964 | * |
994 | * 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. |
… | |
… | |
1102 | |
1073 | |
1103 | return 0; |
1074 | return 0; |
1104 | } |
1075 | } |
1105 | |
1076 | |
1106 | if (hit_something && op->speed >= 10.0) |
1077 | if (hit_something && op->speed >= 10.0) |
1107 | op->speed -= 1.0; |
1078 | op->set_speed (op->speed - 1.f); |
1108 | |
1079 | |
1109 | /* Missile missed victim - reassemble missile */ |
1080 | /* Missile missed victim - reassemble missile */ |
1110 | if (container) |
1081 | if (container) |
1111 | { |
1082 | { |
1112 | hitter->remove (); |
1083 | hitter->remove (); |
… | |
… | |
1180 | * MSW 2002-07-17 |
1151 | * MSW 2002-07-17 |
1181 | */ |
1152 | */ |
1182 | int |
1153 | int |
1183 | kill_object (object *op, int dam, object *hitter, int type) |
1154 | kill_object (object *op, int dam, object *hitter, int type) |
1184 | { |
1155 | { |
1185 | char buf[MAX_BUF]; |
|
|
1186 | shstr skill; |
1156 | shstr skill; |
1187 | int maxdam = 0; |
1157 | int maxdam = 0; |
1188 | int battleg = 0; /* true if op standing on battleground */ |
1158 | int battleg = 0; /* true if op standing on battleground */ |
1189 | 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 */ |
1190 | object *owner = 0; |
1160 | object *owner = 0; |
… | |
… | |
1200 | * this creature. The function(s) that call us have already |
1170 | * this creature. The function(s) that call us have already |
1201 | * adjusted the creatures HP total, so that is negative. |
1171 | * adjusted the creatures HP total, so that is negative. |
1202 | */ |
1172 | */ |
1203 | maxdam = dam + op->stats.hp + 1; |
1173 | maxdam = dam + op->stats.hp + 1; |
1204 | |
1174 | |
1205 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
1175 | if (op->flag [FLAG_BLOCKSVIEW]) |
1206 | 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 */ |
1207 | |
1177 | |
1208 | if (op->type == DOOR) |
1178 | if (op->type == DOOR) |
1209 | { |
1179 | { |
1210 | op->set_speed (0.1f); |
1180 | op->set_speed (0.1f); |
1211 | op->speed_left = -0.05f; |
1181 | op->speed_left = -0.05f; |
1212 | return maxdam; |
1182 | return maxdam; |
1213 | } |
1183 | } |
1214 | |
1184 | |
1215 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1185 | if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER) |
1216 | { |
1186 | { |
1217 | op->drop_and_destroy (); |
1187 | op->drop_and_destroy (); |
1218 | return maxdam; |
1188 | return maxdam; |
1219 | } |
1189 | } |
1220 | |
1190 | |
… | |
… | |
1287 | else if (owner->chosen_skill) |
1257 | else if (owner->chosen_skill) |
1288 | { |
1258 | { |
1289 | skop = owner->chosen_skill; |
1259 | skop = owner->chosen_skill; |
1290 | skill = skop->skill; |
1260 | skill = skop->skill; |
1291 | } |
1261 | } |
1292 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1262 | else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon) |
1293 | skill = owner->current_weapon->skill; |
1263 | skill = owner->current_weapon->skill; |
1294 | else |
1264 | else |
1295 | { |
1265 | { |
|
|
1266 | LOG (llevError | logBacktrace, |
1296 | 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" |
1297 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
1268 | "op: %s\n" "hitter: %s\n" "op: %s\n", |
1298 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1269 | op->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1299 | skill = 0; |
1270 | skill = 0; |
1300 | } |
1271 | } |
1301 | |
1272 | |
1302 | /* 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 |
1303 | * 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! |
… | |
… | |
1313 | |
1284 | |
1314 | if (!skill && skop) |
1285 | if (!skill && skop) |
1315 | skill = skop->skill; |
1286 | skill = skop->skill; |
1316 | |
1287 | |
1317 | /* If you didn't kill yourself, and your not the wizard */ |
1288 | /* If you didn't kill yourself, and your not the wizard */ |
1318 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1289 | if (owner != op && !op->flag [FLAG_WIZ]) |
1319 | { |
1290 | { |
1320 | int exp; |
1291 | int exp; |
1321 | |
1292 | |
1322 | /* Really don't give much experience for killing other players */ |
1293 | /* Really don't give much experience for killing other players */ |
1323 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1294 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
… | |
… | |
1380 | } /* else part of a party */ |
1351 | } /* else part of a party */ |
1381 | } /* end if person didn't kill himself */ |
1352 | } /* end if person didn't kill himself */ |
1382 | |
1353 | |
1383 | if (op->type != PLAYER) |
1354 | if (op->type != PLAYER) |
1384 | { |
1355 | { |
1385 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
1356 | if (op->flag [FLAG_FRIENDLY]) |
1386 | { |
1357 | { |
1387 | object *owner1 = op->owner; |
1358 | object *owner1 = op->owner; |
1388 | |
1359 | |
1389 | if (owner1 && owner1->type == PLAYER) |
1360 | if (owner1 && owner1->type == PLAYER) |
1390 | { |
1361 | { |
… | |
… | |
1455 | int |
1426 | int |
1456 | 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) |
1457 | { |
1428 | { |
1458 | int magic = type & AT_MAGIC; |
1429 | int magic = type & AT_MAGIC; |
1459 | 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? */ |
1460 | int maxdam = 0, ndam = 0, attacktype = 1; |
1431 | int maxdam = 0, ndam = 0; |
1461 | int maxattacktype; |
1432 | int maxattacktype; |
1462 | int simple_attack; |
1433 | int simple_attack; |
1463 | int rtn_kill = 0; |
1434 | int rtn_kill = 0; |
1464 | int friendlyfire; |
1435 | int friendlyfire; |
1465 | |
1436 | |
1466 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1437 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1467 | return 0; |
1438 | return 0; |
1468 | |
1439 | |
1469 | /* 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 */ |
1470 | if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
1441 | if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE]) |
1471 | return 0; |
1442 | return 0; |
1472 | |
1443 | |
1473 | // only allow pk for hostile players |
1444 | // only allow pk for hostile players |
1474 | if (op->type == PLAYER) |
1445 | if (op->type == PLAYER) |
1475 | { |
1446 | { |
… | |
… | |
1517 | |
1488 | |
1518 | break; |
1489 | break; |
1519 | } |
1490 | } |
1520 | } |
1491 | } |
1521 | |
1492 | |
1522 | if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
1493 | if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0) |
1523 | { |
1494 | { |
1524 | /* 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 |
1525 | * destroyed() check above doesn't return, and might get here. |
1496 | * destroyed() check above doesn't return, and might get here. |
1526 | */ |
1497 | */ |
1527 | |
1498 | |
… | |
… | |
1568 | object *god; |
1539 | object *god; |
1569 | |
1540 | |
1570 | if ((!hitter->slaying |
1541 | if ((!hitter->slaying |
1571 | || (!(op->race && hitter->slaying.contains (op->race)) |
1542 | || (!(op->race && hitter->slaying.contains (op->race)) |
1572 | && !(op->name && hitter->slaying.contains (op->name)))) |
1543 | && !(op->name && hitter->slaying.contains (op->name)))) |
1573 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1544 | && (!op->flag [FLAG_UNDEAD] |
1574 | || (hitter->title |
1545 | || (hitter->title |
1575 | && (god = find_god (determine_god (hitter))) != NULL |
1546 | && (god = find_god (determine_god (hitter))) != NULL |
1576 | && god->race.contains (shstr_undead)))) |
1547 | && god->race.contains (shstr_undead)))) |
1577 | return 0; |
1548 | return 0; |
1578 | } |
1549 | } |
… | |
… | |
1650 | // 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 |
1651 | // for an non-active objetc to know its enemy. |
1622 | // for an non-active objetc to know its enemy. |
1652 | if (op->active) |
1623 | if (op->active) |
1653 | if (hitter->owner) |
1624 | if (hitter->owner) |
1654 | op->enemy = hitter->owner; |
1625 | op->enemy = hitter->owner; |
1655 | else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1626 | else if (hitter->flag [FLAG_ALIVE]) |
1656 | op->enemy = hitter; |
1627 | op->enemy = hitter; |
1657 | |
1628 | |
1658 | if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
1629 | if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER) |
1659 | { |
1630 | { |
1660 | /* The unaggressives look after themselves 8) */ |
1631 | /* The unaggressives look after themselves 8) */ |
1661 | CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
1632 | op->clr_flag (FLAG_UNAGGRESSIVE); |
1662 | npc_call_help (op); |
1633 | npc_call_help (op); |
1663 | } |
1634 | } |
1664 | |
1635 | |
1665 | if (magic && did_make_save (op, op->level, 0)) |
1636 | if (magic && did_make_save (op, op->level, 0)) |
1666 | maxdam = maxdam / 2; |
1637 | maxdam = maxdam / 2; |
… | |
… | |
1669 | |
1640 | |
1670 | op->stats.hp -= maxdam; |
1641 | op->stats.hp -= maxdam; |
1671 | |
1642 | |
1672 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1643 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1673 | if (op->stats.hp >= 0 |
1644 | if (op->stats.hp >= 0 |
1674 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
1645 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
1675 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1646 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1676 | { |
1647 | { |
1677 | |
1648 | |
1678 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1649 | if (op->flag [FLAG_MONSTER]) |
1679 | SET_FLAG (op, FLAG_RUN_AWAY); |
1650 | op->set_flag (FLAG_RUN_AWAY); |
1680 | else |
1651 | else |
1681 | scare_creature (op, hitter); |
1652 | scare_creature (op, hitter); |
1682 | } |
1653 | } |
1683 | |
1654 | |
1684 | if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
1655 | if (op->flag [FLAG_TEAR_DOWN]) |
1685 | { |
1656 | { |
1686 | if (maxdam) |
1657 | if (maxdam) |
1687 | tear_down_wall (op); |
1658 | tear_down_wall (op); |
1688 | |
1659 | |
1689 | return maxdam; /* nothing more to do for wall */ |
1660 | return maxdam; /* nothing more to do for wall */ |
… | |
… | |
1696 | |
1667 | |
1697 | /* 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 |
1698 | * that before if the player was immune to ghosthit, the monster |
1669 | * that before if the player was immune to ghosthit, the monster |
1699 | * remained - that is no longer the case. |
1670 | * remained - that is no longer the case. |
1700 | */ |
1671 | */ |
1701 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1672 | if (hitter->flag [FLAG_ONE_HIT]) |
1702 | hitter->drop_and_destroy (); |
1673 | hitter->drop_and_destroy (); |
1703 | /* Lets handle creatures that are splitting now */ |
1674 | /* Lets handle creatures that are splitting now */ |
1704 | 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]) |
1705 | { |
1676 | { |
1706 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1677 | int friendly = op->flag [FLAG_FRIENDLY]; |
1707 | int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
1678 | int unaggressive = op->flag [FLAG_UNAGGRESSIVE]; |
1708 | object *owner = op->owner; |
1679 | object *owner = op->owner; |
1709 | |
1680 | |
1710 | if (!op->other_arch) |
1681 | if (!op->other_arch) |
1711 | { |
1682 | { |
1712 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1683 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
… | |
… | |
1715 | |
1686 | |
1716 | op->remove (); |
1687 | op->remove (); |
1717 | |
1688 | |
1718 | for (int i = 0; i < op->stats.food; i++) |
1689 | for (int i = 0; i < op->stats.food; i++) |
1719 | { /* This doesn't handle op->more yet */ |
1690 | { /* This doesn't handle op->more yet */ |
1720 | object *tmp = arch_to_object (op->other_arch); |
1691 | object *tmp = op->other_arch->instance (); |
1721 | |
1692 | |
1722 | tmp->stats.hp = op->stats.hp; |
1693 | tmp->stats.hp = op->stats.hp; |
1723 | |
1694 | |
1724 | if (friendly) |
1695 | if (friendly) |
1725 | { |
1696 | { |
… | |
… | |
1729 | if (owner) |
1700 | if (owner) |
1730 | tmp->set_owner (owner); |
1701 | tmp->set_owner (owner); |
1731 | } |
1702 | } |
1732 | |
1703 | |
1733 | if (unaggressive) |
1704 | if (unaggressive) |
1734 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
1705 | tmp->set_flag (FLAG_UNAGGRESSIVE); |
1735 | |
1706 | |
1736 | 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); |
1737 | |
1708 | |
1738 | if (j == -1) /* No spot to put this monster */ |
1709 | if (j == -1) /* No spot to put this monster */ |
1739 | tmp->destroy (); |
1710 | tmp->destroy (); |
… | |
… | |
1756 | poison_player (object *op, object *hitter, int dam) |
1727 | poison_player (object *op, object *hitter, int dam) |
1757 | { |
1728 | { |
1758 | archetype *at = archetype::find (shstr_poisoning); |
1729 | archetype *at = archetype::find (shstr_poisoning); |
1759 | object *tmp = present_arch_in_ob (at, op); |
1730 | object *tmp = present_arch_in_ob (at, op); |
1760 | |
1731 | |
1761 | if (tmp == NULL) |
1732 | if (!tmp) |
1762 | { |
1733 | { |
1763 | if ((tmp = arch_to_object (at)) == NULL) |
1734 | tmp = insert_ob_in_ob (at->instance (), op); |
1764 | LOG (llevError, "Failed to clone arch poisoning.\n"); |
1735 | /* peterm: give poisoning some teeth. It should |
|
|
1736 | * be able to kill things better than it does: |
|
|
1737 | * damage should be dependent something--I choose to |
|
|
1738 | * do this: if it's a monster, the damage from the |
|
|
1739 | * poisoning goes as the level of the monster/2. |
|
|
1740 | * If anything else, goes as damage. |
|
|
1741 | */ |
|
|
1742 | |
|
|
1743 | if (hitter->flag [FLAG_ALIVE]) |
|
|
1744 | tmp->stats.dam += hitter->level / 2; |
1765 | else |
1745 | else |
1766 | { |
|
|
1767 | tmp = insert_ob_in_ob (tmp, op); |
|
|
1768 | /* peterm: give poisoning some teeth. It should |
|
|
1769 | * be able to kill things better than it does: |
|
|
1770 | * damage should be dependent something--I choose to |
|
|
1771 | * do this: if it's a monster, the damage from the |
|
|
1772 | * poisoning goes as the level of the monster/2. |
|
|
1773 | * If anything else, goes as damage. |
|
|
1774 | */ |
|
|
1775 | |
|
|
1776 | if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
|
|
1777 | tmp->stats.dam += hitter->level / 2; |
|
|
1778 | else |
|
|
1779 | tmp->stats.dam = dam; |
1746 | tmp->stats.dam = dam; |
1780 | |
1747 | |
1781 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1748 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1782 | if (hitter->skill && hitter->skill != tmp->skill) |
1749 | if (hitter->skill && hitter->skill != tmp->skill) |
1783 | { |
|
|
1784 | tmp->skill = hitter->skill; |
1750 | tmp->skill = hitter->skill; |
1785 | } |
|
|
1786 | |
1751 | |
1787 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1752 | tmp->stats.food += dam; /* more damage, longer poisoning */ |
1788 | |
1753 | |
1789 | if (op->type == PLAYER) |
1754 | if (op->type == PLAYER) |
1790 | { |
1755 | { |
1791 | /* player looses stats, maximum is -10 of each */ |
1756 | /* player looses stats, maximum is -10 of each */ |
1792 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1757 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1793 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1758 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1794 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1759 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1795 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1760 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1796 | SET_FLAG (tmp, FLAG_APPLIED); |
1761 | tmp->set_flag (FLAG_APPLIED); |
1797 | op->update_stats (); |
1762 | op->update_stats (); |
1798 | 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."); |
1799 | op->play_sound (tmp->sound); |
1764 | op->play_sound (tmp->sound); |
1800 | } |
1765 | } |
1801 | |
1766 | |
1802 | if (hitter->type == PLAYER) |
1767 | if (hitter->type == PLAYER) |
1803 | new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); |
1768 | new_draw_info_format (NDI_UNIQUE, 0, hitter, "You poison %s.", &op->name); |
1804 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1769 | else if (hitter->owner != NULL && hitter->owner->type == PLAYER) |
1805 | new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); |
1770 | new_draw_info_format (NDI_UNIQUE, 0, hitter->owner, "Your %s poisons %s.", &hitter->name, &op->name); |
1806 | } |
|
|
1807 | |
1771 | |
1808 | tmp->speed_left = 0; |
1772 | tmp->speed_left = 0; |
1809 | } |
1773 | } |
1810 | else |
1774 | else |
1811 | tmp->stats.food++; |
1775 | tmp->stats.food++; |
… | |
… | |
1815 | slow_player (object *op, object *hitter, int dam) |
1779 | slow_player (object *op, object *hitter, int dam) |
1816 | { |
1780 | { |
1817 | archetype *at = archetype::find (shstr_slowness); |
1781 | archetype *at = archetype::find (shstr_slowness); |
1818 | object *tmp; |
1782 | object *tmp; |
1819 | |
1783 | |
1820 | if (at == NULL) |
1784 | if (!at) |
1821 | LOG (llevError, "Can't find slowness archetype.\n"); |
1785 | LOG (llevError, "Can't find slowness archetype.\n"); |
1822 | |
1786 | |
1823 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1787 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1824 | { |
1788 | { |
1825 | tmp = arch_to_object (at); |
1789 | tmp = at->instance (); |
1826 | tmp = insert_ob_in_ob (tmp, op); |
1790 | tmp = insert_ob_in_ob (tmp, op); |
1827 | 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!"); |
1828 | } |
1792 | } |
1829 | else |
1793 | else |
1830 | tmp->stats.food++; |
1794 | tmp->stats.food++; |
1831 | |
1795 | |
1832 | SET_FLAG (tmp, FLAG_APPLIED); |
1796 | tmp->set_flag (FLAG_APPLIED); |
1833 | tmp->speed_left = 0; |
1797 | tmp->speed_left = 0; |
1834 | op->update_stats (); |
1798 | op->update_stats (); |
1835 | } |
1799 | } |
1836 | |
1800 | |
1837 | void |
1801 | void |
… | |
… | |
1841 | int maxduration; |
1805 | int maxduration; |
1842 | |
1806 | |
1843 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1807 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1844 | if (!tmp) |
1808 | if (!tmp) |
1845 | { |
1809 | { |
1846 | tmp = get_archetype (FORCE_NAME); |
1810 | tmp = archetype::get (FORCE_NAME); |
1847 | tmp = insert_ob_in_ob (tmp, op); |
1811 | tmp = insert_ob_in_ob (tmp, op); |
1848 | } |
1812 | } |
1849 | |
1813 | |
1850 | /* Duration added per hit and max. duration of confusion both depend |
1814 | /* Duration added per hit and max. duration of confusion both depend |
1851 | * on the player's resistance |
1815 | * on the player's resistance |
1852 | */ |
1816 | */ |
1853 | tmp->speed = 0.05; |
1817 | tmp->set_speed (0.05); |
1854 | tmp->subtype = FORCE_CONFUSION; |
1818 | tmp->subtype = FORCE_CONFUSION; |
1855 | 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); |
1856 | tmp->name = shstr_confusion; |
1820 | tmp->name = shstr_confusion; |
1857 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1821 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1858 | |
1822 | |
1859 | if (tmp->duration > maxduration) |
1823 | if (tmp->duration > maxduration) |
1860 | tmp->duration = maxduration; |
1824 | tmp->duration = maxduration; |
1861 | |
1825 | |
1862 | if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
1826 | if (op->type == PLAYER && !op->flag [FLAG_CONFUSED]) |
1863 | 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!"); |
1864 | |
1828 | |
1865 | SET_FLAG (op, FLAG_CONFUSED); |
1829 | op->set_flag (FLAG_CONFUSED); |
1866 | } |
1830 | } |
1867 | |
1831 | |
1868 | void |
1832 | void |
1869 | blind_player (object *op, object *hitter, int dam) |
1833 | blind_player (object *op, object *hitter, int dam) |
1870 | { |
1834 | { |
1871 | object *tmp, *owner; |
|
|
1872 | |
|
|
1873 | /* 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 */ |
1874 | if (op->resist[ATNR_BLIND] == 100) |
1836 | if (op->resist[ATNR_BLIND] == 100) |
1875 | return; |
1837 | return; |
1876 | |
1838 | |
1877 | tmp = present_in_ob (BLINDNESS, op); |
1839 | object *tmp = present_in_ob (BLINDNESS, op); |
1878 | if (!tmp) |
1840 | if (!tmp) |
1879 | { |
1841 | { |
1880 | tmp = get_archetype (shstr_blindness); |
1842 | tmp = archetype::get (shstr_blindness); |
1881 | SET_FLAG (tmp, FLAG_BLIND); |
1843 | tmp->set_flag (FLAG_BLIND); |
1882 | SET_FLAG (tmp, FLAG_APPLIED); |
1844 | tmp->set_flag (FLAG_APPLIED); |
1883 | /* 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. |
1884 | * speed is a float anyways. |
1846 | tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED)); |
1885 | */ |
|
|
1886 | tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
|
|
1887 | |
1847 | |
1888 | tmp = insert_ob_in_ob (tmp, op); |
1848 | tmp = insert_ob_in_ob (tmp, op); |
1889 | change_abil (op, tmp); /* Mostly to display any messages */ |
1849 | change_abil (op, tmp); /* Mostly to display any messages */ |
1890 | op->update_stats (); /* This takes care of some other stuff */ |
1850 | op->update_stats (); /* This takes care of some other stuff */ |
1891 | |
1851 | |
1892 | if (hitter->owner) |
|
|
1893 | owner = hitter->owner; |
|
|
1894 | else |
|
|
1895 | owner = hitter; |
|
|
1896 | |
|
|
1897 | 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)); |
1898 | } |
1853 | } |
|
|
1854 | |
1899 | tmp->stats.food += dam; |
1855 | tmp->stats.food += dam; |
1900 | if (tmp->stats.food > 10) |
1856 | min_it (tmp->stats.food, 10); |
1901 | tmp->stats.food = 10; |
|
|
1902 | } |
1857 | } |
1903 | |
1858 | |
1904 | void |
1859 | void |
1905 | paralyze_player (object *op, object *hitter, int dam) |
1860 | paralyze_player (object *op, object *hitter, int dam) |
1906 | { |
1861 | { |
… | |
… | |
1945 | ** field of the deathstriking object */ |
1900 | ** field of the deathstriking object */ |
1946 | |
1901 | |
1947 | int atk_lev, def_lev, kill_lev; |
1902 | int atk_lev, def_lev, kill_lev; |
1948 | |
1903 | |
1949 | if (hitter->slaying) |
1904 | if (hitter->slaying) |
1950 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
1905 | if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead)) |
1951 | || (op->race && hitter->slaying.contains (op->race)))) |
1906 | || (op->race && hitter->slaying.contains (op->race)))) |
1952 | return; |
1907 | return; |
1953 | |
1908 | |
1954 | def_lev = op->level; |
1909 | def_lev = op->level; |
1955 | if (def_lev < 1) |
1910 | if (def_lev < 1) |
… | |
… | |
2080 | * Second, just getting hit doesn't mean it always affects |
2035 | * Second, just getting hit doesn't mean it always affects |
2081 | * you. Third, you still get a saving through against the |
2036 | * you. Third, you still get a saving through against the |
2082 | * effect. |
2037 | * effect. |
2083 | */ |
2038 | */ |
2084 | if (op->has_active_speed () |
2039 | if (op->has_active_speed () |
2085 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
2040 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
2086 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2041 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2087 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2042 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2088 | { |
2043 | { |
2089 | |
2044 | |
2090 | /* Player has been hit by something */ |
2045 | /* Player has been hit by something */ |
… | |
… | |
2100 | scare_creature (op, hitter); |
2055 | scare_creature (op, hitter); |
2101 | else if (attacknum == ATNR_CANCELLATION) |
2056 | else if (attacknum == ATNR_CANCELLATION) |
2102 | cancellation (op); |
2057 | cancellation (op); |
2103 | else if (attacknum == ATNR_DEPLETE) |
2058 | else if (attacknum == ATNR_DEPLETE) |
2104 | op->drain_stat (); |
2059 | op->drain_stat (); |
2105 | 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]) |
2106 | blind_player (op, hitter, dam); |
2061 | blind_player (op, hitter, dam); |
2107 | } |
2062 | } |
2108 | |
2063 | |
2109 | 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 */ |
2110 | } |
2065 | } |
… | |
… | |
2120 | { |
2075 | { |
2121 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2076 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2122 | { |
2077 | { |
2123 | if (tmp->invisible) |
2078 | if (tmp->invisible) |
2124 | continue; |
2079 | continue; |
2125 | if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
2080 | if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10)) |
2126 | /* >= 10% acid res. on items will protect these */ |
2081 | /* >= 10% acid res. on items will protect these */ |
2127 | continue; |
2082 | continue; |
2128 | if (!(tmp->materials & M_IRON)) |
2083 | if (!(tmp->materials & M_IRON)) |
2129 | continue; |
2084 | continue; |
2130 | if (tmp->magic < -4) /* Let's stop at -5 */ |
2085 | if (tmp->magic < -4) /* Let's stop at -5 */ |
… | |
… | |
2175 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2130 | rate = 400 * 100 / (100 - op->resist[ATNR_DRAIN]); |
2176 | |
2131 | |
2177 | if (op->stats.exp <= rate) |
2132 | if (op->stats.exp <= rate) |
2178 | { |
2133 | { |
2179 | if (op->type == GOLEM) |
2134 | if (op->type == GOLEM) |
2180 | dam = 999; /* Its force is "sucked" away. 8) */ |
2135 | dam = 9998; /* Its force is "sucked" away. 8) */ |
2181 | else |
2136 | else |
2182 | /* If we can't drain, lets try to do physical damage */ |
2137 | /* If we can't drain, lets try to do physical damage */ |
2183 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2138 | dam = hit_player_attacktype (op, hitter, dam, ATNR_PHYSICAL, magic); |
2184 | } |
2139 | } |
2185 | else |
2140 | else |
… | |
… | |
2194 | * 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, |
2195 | * nothing happens. |
2150 | * nothing happens. |
2196 | * 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 |
2197 | * attacks, hence all the != PLAYER checks. |
2152 | * attacks, hence all the != PLAYER checks. |
2198 | */ |
2153 | */ |
2199 | if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
2154 | if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ]) |
2200 | { |
2155 | { |
2201 | object *owner = hitter->owner; |
2156 | object *owner = hitter->owner; |
2202 | |
2157 | |
2203 | if (owner && owner != hitter) |
2158 | if (owner && owner != hitter) |
2204 | { |
2159 | { |
2205 | if (op->type != PLAYER || owner->type != PLAYER) |
2160 | if (op->type != PLAYER || owner->type != PLAYER) |
2206 | change_exp (owner, op->stats.exp / (rate * 2), |
2161 | change_exp (owner, op->stats.exp / (rate * 2), |
2207 | 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); |
2208 | } |
2163 | } |
2209 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2164 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2210 | change_exp (hitter, op->stats.exp / (rate * 2), |
2165 | change_exp (hitter, op->stats.exp / (rate * 2), |
2211 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
2166 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0); |
2212 | |
2167 | |
2213 | change_exp (op, -op->stats.exp / rate, NULL, 0); |
2168 | change_exp (op, -op->stats.exp / rate, shstr (), 0); |
2214 | } |
2169 | } |
2215 | |
2170 | |
2216 | 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 |
2217 | * 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, |
2218 | * as the messages will say you missed |
2173 | * as the messages will say you missed |
… | |
… | |
2221 | } |
2176 | } |
2222 | break; |
2177 | break; |
2223 | |
2178 | |
2224 | case ATNR_TURN_UNDEAD: |
2179 | case ATNR_TURN_UNDEAD: |
2225 | { |
2180 | { |
2226 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
2181 | if (op->flag [FLAG_UNDEAD]) |
2227 | { |
2182 | { |
2228 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2183 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2229 | object *god = find_god (determine_god (owner)); |
2184 | object *god = find_god (determine_god (owner)); |
2230 | int div = 1; |
2185 | int div = 1; |
2231 | |
2186 | |
… | |
… | |
2286 | * damage it does do to the player. Given that, |
2241 | * damage it does do to the player. Given that, |
2287 | * 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 |
2288 | * 1000). |
2243 | * 1000). |
2289 | */ |
2244 | */ |
2290 | /* You can't steal life from something undead */ |
2245 | /* You can't steal life from something undead */ |
2291 | if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
2246 | if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD])) |
2292 | return 0; |
2247 | return 0; |
2293 | |
2248 | |
2294 | /* If drain protection is higher than life stealing, use that */ |
2249 | /* If drain protection is higher than life stealing, use that */ |
2295 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2250 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2296 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
2251 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |