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,2009,2010 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 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 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 | { |
… | |
… | |
648 | } |
641 | } |
649 | |
642 | |
650 | static int |
643 | static int |
651 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
644 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
652 | { |
645 | { |
653 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
646 | if ((*target)->flag [FLAG_FREED] || (*hitter)->flag [FLAG_FREED]) |
654 | { |
647 | { |
655 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
648 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
656 | return 1; |
649 | return 1; |
657 | } |
650 | } |
658 | |
651 | |
… | |
… | |
666 | { |
659 | { |
667 | *simple_attack = 1; |
660 | *simple_attack = 1; |
668 | return 0; |
661 | return 0; |
669 | } |
662 | } |
670 | |
663 | |
671 | if (QUERY_FLAG (*target, FLAG_REMOVED) |
664 | if ((*target)->flag [FLAG_REMOVED] |
672 | || QUERY_FLAG (*hitter, FLAG_REMOVED) |
665 | || (*hitter)->flag [FLAG_REMOVED] |
673 | || !(*hitter)->map |
666 | || !(*hitter)->map |
674 | || !on_same_map (*hitter, *target)) |
667 | || !on_same_map (*hitter, *target)) |
675 | { |
668 | { |
676 | 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", |
677 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
670 | (*hitter)->debug_desc (), (*target)->debug_desc ()); |
… | |
… | |
690 | */ |
683 | */ |
691 | int new_mode; |
684 | int new_mode; |
692 | |
685 | |
693 | if (hitter->env == target || target->env == hitter) |
686 | if (hitter->env == target || target->env == hitter) |
694 | new_mode = 1; |
687 | new_mode = 1; |
695 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
688 | else if (hitter->flag [FLAG_REMOVED] || target->flag [FLAG_REMOVED] |
696 | || hitter->map == NULL || !on_same_map (hitter, target)) |
689 | || hitter->map == NULL || !on_same_map (hitter, target)) |
697 | return 1; |
690 | return 1; |
698 | else |
691 | else |
699 | new_mode = 0; |
692 | new_mode = 0; |
700 | |
693 | |
… | |
… | |
706 | * monster). |
699 | * monster). |
707 | */ |
700 | */ |
708 | static void |
701 | static void |
709 | thrown_item_effect (object *hitter, object *victim) |
702 | thrown_item_effect (object *hitter, object *victim) |
710 | { |
703 | { |
711 | if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
704 | if (!hitter->flag [FLAG_ALIVE]) |
712 | { |
705 | { |
713 | /* 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 |
714 | * easier for expansion. |
707 | * easier for expansion. |
715 | */ |
708 | */ |
716 | switch (hitter->type) |
709 | switch (hitter->type) |
717 | { |
710 | { |
718 | case POTION: |
711 | case POTION: |
719 | /* should player get a save throw instead of checking magic protection? */ |
712 | /* should player get a save throw instead of checking magic protection? */ |
720 | 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)) |
721 | apply_potion (victim, hitter); |
714 | apply_potion (victim, hitter); |
722 | break; |
715 | break; |
723 | |
716 | |
724 | case POISON: /* poison drinks */ |
717 | case POISON: /* poison drinks */ |
725 | /* As with potions, should monster get a save? */ |
718 | /* As with potions, should monster get a save? */ |
726 | 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)) |
727 | apply_poison (victim, hitter); |
720 | apply_poison (victim, hitter); |
728 | break; |
721 | break; |
729 | |
722 | |
730 | /* Removed case statements that did nothing. |
723 | /* Removed case statements that did nothing. |
731 | * 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, |
… | |
… | |
738 | |
731 | |
739 | /* determine if the object is an 'aimed' missile */ |
732 | /* determine if the object is an 'aimed' missile */ |
740 | static int |
733 | static int |
741 | is_aimed_missile (object *op) |
734 | is_aimed_missile (object *op) |
742 | { |
735 | { |
743 | |
|
|
744 | /* 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 |
745 | * ones so that figuring out the logic is at least possible. |
737 | * ones so that figuring out the logic is at least possible. |
746 | */ |
738 | */ |
747 | if (op && (op->move_type & MOVE_FLYING)) |
739 | if (op && (op->move_type & MOVE_FLYING)) |
748 | if (op->type == ARROW || op->type == THROWN_OBJ) |
740 | if (op->type == ARROW || op->type == THROWN_OBJ) |
… | |
… | |
772 | if ((attacker = hitter->owner) == NULL) |
764 | if ((attacker = hitter->owner) == NULL) |
773 | attacker = hitter; |
765 | attacker = hitter; |
774 | /* 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 |
775 | * owned by him - need to handle that case to avoid crashes. |
767 | * owned by him - need to handle that case to avoid crashes. |
776 | */ |
768 | */ |
777 | if (QUERY_FLAG (attacker, FLAG_REMOVED)) |
769 | if (attacker->flag [FLAG_REMOVED]) |
778 | attacker = hitter; |
770 | attacker = hitter; |
779 | } |
771 | } |
780 | else if (!QUERY_FLAG (hitter, FLAG_ALIVE)) |
772 | else if (!hitter->flag [FLAG_ALIVE]) |
781 | return 0; |
773 | return 0; |
782 | |
774 | |
783 | /* determine the condtions under which we make an attack. |
775 | /* determine the condtions under which we make an attack. |
784 | * Add more cases, as the need occurs. */ |
776 | * Add more cases, as the need occurs. */ |
785 | |
777 | |
786 | if (!can_see_enemy (attacker, target)) |
778 | if (!can_see_enemy (attacker, target)) |
787 | { |
779 | { |
788 | /* target is unseen */ |
780 | /* target is unseen */ |
789 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
781 | if (target->invisible || attacker->flag [FLAG_BLIND]) |
790 | adjust -= 10; |
782 | adjust -= 10; |
791 | /* 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). */ |
792 | else if (!stand_in_light (target)) |
784 | else if (!stand_in_light (target)) |
793 | adjust -= target->map->darklevel (); |
785 | adjust -= target->map->darklevel (); |
794 | } |
786 | } |
795 | |
787 | |
796 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
788 | if (attacker->flag [FLAG_SCARED]) |
797 | adjust -= 3; |
789 | adjust -= 3; |
798 | |
790 | |
799 | if (QUERY_FLAG (target, FLAG_UNAGGRESSIVE)) |
791 | if (target->flag [FLAG_UNAGGRESSIVE]) |
800 | adjust += 1; |
792 | adjust += 1; |
801 | |
793 | |
802 | if (QUERY_FLAG (target, FLAG_SCARED)) |
794 | if (target->flag [FLAG_SCARED]) |
803 | adjust += 1; |
795 | adjust += 1; |
804 | |
796 | |
805 | if (QUERY_FLAG (attacker, FLAG_CONFUSED)) |
797 | if (attacker->flag [FLAG_CONFUSED]) |
806 | adjust -= 3; |
798 | adjust -= 3; |
807 | |
799 | |
808 | /* if we attack at a different 'altitude' its harder */ |
800 | /* if we attack at a different 'altitude' its harder */ |
809 | if ((attacker->move_type & target->move_type) == 0) |
801 | if ((attacker->move_type & target->move_type) == 0) |
810 | adjust -= 2; |
802 | adjust -= 2; |
… | |
… | |
846 | |
838 | |
847 | /* |
839 | /* |
848 | * 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 |
849 | * to avoid ever being hit by monsters. |
841 | * to avoid ever being hit by monsters. |
850 | */ |
842 | */ |
851 | 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) |
852 | { |
844 | { |
853 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
845 | /* Decrease speed BEFORE calling process_object. Otherwise, an |
854 | * infinite loop occurs, with process_object calling move_monster, |
846 | * infinite loop occurs, with process_object calling move_monster, |
855 | * which then gets here again. By decreasing the speed before |
847 | * which then gets here again. By decreasing the speed before |
856 | * we call process_object, the 'if' statement above will fail. |
848 | * we call process_object, the 'if' statement above will fail. |
… | |
… | |
878 | if (!simple_attack) |
870 | if (!simple_attack) |
879 | { |
871 | { |
880 | /* If you hit something, the victim should *always* wake up. |
872 | /* If you hit something, the victim should *always* wake up. |
881 | * Before, invisible hitters could avoid doing this. |
873 | * Before, invisible hitters could avoid doing this. |
882 | * -b.t. */ |
874 | * -b.t. */ |
883 | if (QUERY_FLAG (op, FLAG_SLEEP)) |
875 | if (op->flag [FLAG_SLEEP]) |
884 | CLEAR_FLAG (op, FLAG_SLEEP); |
876 | op->clr_flag (FLAG_SLEEP); |
885 | |
877 | |
886 | /* 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 |
887 | * for help. */ |
879 | * for help. */ |
888 | 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)) |
889 | npc_call_help (op); |
881 | npc_call_help (op); |
… | |
… | |
909 | } |
901 | } |
910 | |
902 | |
911 | /* 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 |
912 | * to go further and it will cause FPE's below. |
904 | * to go further and it will cause FPE's below. |
913 | */ |
905 | */ |
914 | if (hitdam <= 0) |
906 | max_it (hitdam, 1); |
915 | hitdam = 1; |
|
|
916 | |
907 | |
917 | type = hitter->attacktype; |
908 | type = hitter->attacktype; |
918 | |
909 | |
919 | /* 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* |
920 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
911 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
… | |
… | |
928 | */ |
919 | */ |
929 | if (!type) |
920 | if (!type) |
930 | type = AT_PHYSICAL; |
921 | type = AT_PHYSICAL; |
931 | |
922 | |
932 | /* Handle monsters that hit back */ |
923 | /* Handle monsters that hit back */ |
933 | 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]) |
934 | { |
925 | { |
935 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
926 | if (op->attacktype & AT_ACID && hitter->type == PLAYER) |
936 | 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"); |
937 | |
928 | |
938 | 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); |
… | |
… | |
964 | } |
955 | } |
965 | |
956 | |
966 | int |
957 | int |
967 | attack_ob (object *op, object *hitter) |
958 | attack_ob (object *op, object *hitter) |
968 | { |
959 | { |
969 | hitter = hitter->head_ (); |
|
|
970 | |
|
|
971 | 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); |
972 | } |
961 | } |
973 | |
962 | |
974 | /* op is the arrow, tmp is what is stopping the arrow. |
963 | /* op is the arrow, tmp is what is stopping the arrow. |
975 | * |
964 | * |
976 | * 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. |
… | |
… | |
1029 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1018 | * arrow, move_apply() calls this function, arrow sticks in demon, |
1030 | * 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 |
1031 | * 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 |
1032 | * other places as well!) |
1021 | * other places as well!) |
1033 | */ |
1022 | */ |
1034 | if (hitter->destroyed () || hitter->env != NULL) |
1023 | if (hitter->destroyed () || hitter->env) |
1035 | { |
1024 | { |
1036 | if (container) |
1025 | if (container) |
1037 | container->destroy (); |
1026 | container->destroy (); |
1038 | |
1027 | |
1039 | return 0; |
1028 | return 0; |
1040 | } |
1029 | } |
1041 | |
1030 | |
1042 | /* Missile hit victim */ |
1031 | /* Missile hit victim */ |
1043 | /* 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 |
1044 | * through the target |
1033 | * through the target |
1045 | */ |
1034 | */ |
1046 | if (hit_something && op->speed <= 10.0) |
1035 | if (hit_something) |
|
|
1036 | if (op->speed < 10.0) |
1047 | { |
1037 | { |
1048 | /* Stop arrow */ |
1038 | /* Stop arrow */ |
1049 | if (!container) |
1039 | if (!container) |
1050 | { |
1040 | { |
1051 | hitter = fix_stopped_arrow (hitter); |
1041 | hitter = fix_stopped_arrow (hitter); |
1052 | if (!hitter) |
1042 | if (!hitter) |
1053 | return 0; |
1043 | return 0; |
1054 | } |
1044 | } |
1055 | else |
1045 | else |
1056 | container->destroy (); |
1046 | container->destroy (); |
1057 | |
1047 | |
1058 | /* Try to stick arrow into victim */ |
1048 | /* Try to stick arrow into victim */ |
1059 | 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 | |
1060 | return 0; |
1075 | return 0; |
1061 | |
|
|
1062 | /* Else try to put arrow on victim's map square |
|
|
1063 | * remove check for P_WALL here. If the arrow got to this |
|
|
1064 | * space, that is good enough - with the new movement code, |
|
|
1065 | * there is now the potential for lots of spaces where something |
|
|
1066 | * can fly over but not otherwise move over. What is the correct |
|
|
1067 | * way to handle those otherwise? |
|
|
1068 | */ |
|
|
1069 | if (victim->x != hitter->x || victim->y != hitter->y) |
|
|
1070 | { |
|
|
1071 | if (victim->destroyed ()) |
|
|
1072 | hitter->destroy (); |
|
|
1073 | else |
|
|
1074 | { |
|
|
1075 | hitter->remove (); |
|
|
1076 | hitter->x = victim->x; |
|
|
1077 | hitter->y = victim->y; |
|
|
1078 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
1079 | } |
|
|
1080 | } |
1076 | } |
1081 | else |
1077 | else |
1082 | /* Else leave arrow where it is */ |
1078 | op->set_speed (op->speed - 1.f); |
1083 | merge_ob (hitter, NULL); |
|
|
1084 | |
|
|
1085 | return 0; |
|
|
1086 | } |
|
|
1087 | |
|
|
1088 | if (hit_something && op->speed >= 10.0) |
|
|
1089 | op->speed -= 1.0; |
|
|
1090 | |
1079 | |
1091 | /* Missile missed victim - reassemble missile */ |
1080 | /* Missile missed victim - reassemble missile */ |
1092 | if (container) |
1081 | if (container) |
1093 | { |
1082 | { |
1094 | hitter->remove (); |
1083 | hitter->remove (); |
… | |
… | |
1162 | * MSW 2002-07-17 |
1151 | * MSW 2002-07-17 |
1163 | */ |
1152 | */ |
1164 | int |
1153 | int |
1165 | kill_object (object *op, int dam, object *hitter, int type) |
1154 | kill_object (object *op, int dam, object *hitter, int type) |
1166 | { |
1155 | { |
1167 | char buf[MAX_BUF]; |
|
|
1168 | shstr skill; |
1156 | shstr skill; |
1169 | int maxdam = 0; |
1157 | int maxdam = 0; |
1170 | int battleg = 0; /* true if op standing on battleground */ |
1158 | int battleg = 0; /* true if op standing on battleground */ |
1171 | 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 */ |
1172 | object *owner = 0; |
1160 | object *owner = 0; |
… | |
… | |
1182 | * this creature. The function(s) that call us have already |
1170 | * this creature. The function(s) that call us have already |
1183 | * adjusted the creatures HP total, so that is negative. |
1171 | * adjusted the creatures HP total, so that is negative. |
1184 | */ |
1172 | */ |
1185 | maxdam = dam + op->stats.hp + 1; |
1173 | maxdam = dam + op->stats.hp + 1; |
1186 | |
1174 | |
1187 | if (QUERY_FLAG (op, FLAG_BLOCKSVIEW)) |
1175 | if (op->flag [FLAG_BLOCKSVIEW]) |
1188 | 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 */ |
1189 | |
1177 | |
1190 | if (op->type == DOOR) |
1178 | if (op->type == DOOR) |
1191 | { |
1179 | { |
1192 | op->set_speed (0.1f); |
1180 | op->set_speed (0.1f); |
1193 | op->speed_left = -0.05f; |
1181 | op->speed_left = -0.05f; |
1194 | return maxdam; |
1182 | return maxdam; |
1195 | } |
1183 | } |
1196 | |
1184 | |
1197 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1185 | if (op->flag [FLAG_FRIENDLY] && op->type != PLAYER) |
1198 | { |
1186 | { |
1199 | op->drop_and_destroy (); |
1187 | op->drop_and_destroy (); |
1200 | return maxdam; |
1188 | return maxdam; |
1201 | } |
1189 | } |
1202 | |
1190 | |
… | |
… | |
1269 | else if (owner->chosen_skill) |
1257 | else if (owner->chosen_skill) |
1270 | { |
1258 | { |
1271 | skop = owner->chosen_skill; |
1259 | skop = owner->chosen_skill; |
1272 | skill = skop->skill; |
1260 | skill = skop->skill; |
1273 | } |
1261 | } |
1274 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1262 | else if (owner->flag [FLAG_READY_WEAPON] && owner->current_weapon) |
1275 | skill = owner->current_weapon->skill; |
1263 | skill = owner->current_weapon->skill; |
1276 | else |
1264 | else |
1277 | { |
1265 | { |
|
|
1266 | LOG (llevError | logBacktrace, |
1278 | 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" |
1279 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
1268 | "op: %s\n" "hitter: %s\n" "op: %s\n", |
1280 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1269 | op->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
1281 | skill = 0; |
1270 | skill = 0; |
1282 | } |
1271 | } |
1283 | |
1272 | |
1284 | /* 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 |
1285 | * 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! |
… | |
… | |
1295 | |
1284 | |
1296 | if (!skill && skop) |
1285 | if (!skill && skop) |
1297 | skill = skop->skill; |
1286 | skill = skop->skill; |
1298 | |
1287 | |
1299 | /* If you didn't kill yourself, and your not the wizard */ |
1288 | /* If you didn't kill yourself, and your not the wizard */ |
1300 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1289 | if (owner != op && !op->flag [FLAG_WIZ]) |
1301 | { |
1290 | { |
1302 | int exp; |
1291 | int exp; |
1303 | |
1292 | |
1304 | /* Really don't give much experience for killing other players */ |
1293 | /* Really don't give much experience for killing other players */ |
1305 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
1294 | // schmorp: temporarily? reduce the amount of exp gained for pking enourmously |
… | |
… | |
1362 | } /* else part of a party */ |
1351 | } /* else part of a party */ |
1363 | } /* end if person didn't kill himself */ |
1352 | } /* end if person didn't kill himself */ |
1364 | |
1353 | |
1365 | if (op->type != PLAYER) |
1354 | if (op->type != PLAYER) |
1366 | { |
1355 | { |
1367 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
1356 | if (op->flag [FLAG_FRIENDLY]) |
1368 | { |
1357 | { |
1369 | object *owner1 = op->owner; |
1358 | object *owner1 = op->owner; |
1370 | |
1359 | |
1371 | if (owner1 && owner1->type == PLAYER) |
1360 | if (owner1 && owner1->type == PLAYER) |
1372 | { |
1361 | { |
… | |
… | |
1437 | int |
1426 | int |
1438 | 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) |
1439 | { |
1428 | { |
1440 | int magic = type & AT_MAGIC; |
1429 | int magic = type & AT_MAGIC; |
1441 | 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? */ |
1442 | int maxdam = 0, ndam = 0, attacktype = 1; |
1431 | int maxdam = 0, ndam = 0; |
1443 | int maxattacktype; |
1432 | int maxattacktype; |
1444 | int simple_attack; |
1433 | int simple_attack; |
1445 | int rtn_kill = 0; |
1434 | int rtn_kill = 0; |
1446 | int friendlyfire; |
1435 | int friendlyfire; |
1447 | |
1436 | |
1448 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1437 | if (get_attack_mode (&op, &hitter, &simple_attack)) |
1449 | return 0; |
1438 | return 0; |
1450 | |
1439 | |
1451 | /* 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 */ |
1452 | if (QUERY_FLAG (op, FLAG_WIZ) || QUERY_FLAG (op, FLAG_NO_DAMAGE)) |
1441 | if (op->flag [FLAG_WIZ] || op->flag [FLAG_NO_DAMAGE]) |
1453 | return 0; |
1442 | return 0; |
1454 | |
1443 | |
1455 | // only allow pk for hostile players |
1444 | // only allow pk for hostile players |
1456 | if (op->type == PLAYER) |
1445 | if (op->type == PLAYER) |
1457 | { |
1446 | { |
… | |
… | |
1499 | |
1488 | |
1500 | break; |
1489 | break; |
1501 | } |
1490 | } |
1502 | } |
1491 | } |
1503 | |
1492 | |
1504 | if (!QUERY_FLAG (op, FLAG_ALIVE) || op->stats.hp < 0) |
1493 | if (!op->flag [FLAG_ALIVE] || op->stats.hp < 0) |
1505 | { |
1494 | { |
1506 | /* 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 |
1507 | * destroyed() check above doesn't return, and might get here. |
1496 | * destroyed() check above doesn't return, and might get here. |
1508 | */ |
1497 | */ |
1509 | |
1498 | |
… | |
… | |
1550 | object *god; |
1539 | object *god; |
1551 | |
1540 | |
1552 | if ((!hitter->slaying |
1541 | if ((!hitter->slaying |
1553 | || (!(op->race && hitter->slaying.contains (op->race)) |
1542 | || (!(op->race && hitter->slaying.contains (op->race)) |
1554 | && !(op->name && hitter->slaying.contains (op->name)))) |
1543 | && !(op->name && hitter->slaying.contains (op->name)))) |
1555 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1544 | && (!op->flag [FLAG_UNDEAD] |
1556 | || (hitter->title |
1545 | || (hitter->title |
1557 | && (god = find_god (determine_god (hitter))) != NULL |
1546 | && (god = find_god (determine_god (hitter))) != NULL |
1558 | && god->race.contains (shstr_undead)))) |
1547 | && god->race.contains (shstr_undead)))) |
1559 | return 0; |
1548 | return 0; |
1560 | } |
1549 | } |
… | |
… | |
1632 | // 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 |
1633 | // for an non-active objetc to know its enemy. |
1622 | // for an non-active objetc to know its enemy. |
1634 | if (op->active) |
1623 | if (op->active) |
1635 | if (hitter->owner) |
1624 | if (hitter->owner) |
1636 | op->enemy = hitter->owner; |
1625 | op->enemy = hitter->owner; |
1637 | else if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1626 | else if (hitter->flag [FLAG_ALIVE]) |
1638 | op->enemy = hitter; |
1627 | op->enemy = hitter; |
1639 | |
1628 | |
1640 | if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE) && op->type != PLAYER) |
1629 | if (op->flag [FLAG_UNAGGRESSIVE] && op->type != PLAYER) |
1641 | { |
1630 | { |
1642 | /* The unaggressives look after themselves 8) */ |
1631 | /* The unaggressives look after themselves 8) */ |
1643 | CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); |
1632 | op->clr_flag (FLAG_UNAGGRESSIVE); |
1644 | npc_call_help (op); |
1633 | npc_call_help (op); |
1645 | } |
1634 | } |
1646 | |
1635 | |
1647 | if (magic && did_make_save (op, op->level, 0)) |
1636 | if (magic && did_make_save (op, op->level, 0)) |
1648 | maxdam = maxdam / 2; |
1637 | maxdam = maxdam / 2; |
… | |
… | |
1651 | |
1640 | |
1652 | op->stats.hp -= maxdam; |
1641 | op->stats.hp -= maxdam; |
1653 | |
1642 | |
1654 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1643 | /* Eneq(@csd.uu.se): Check to see if monster runs away. */ |
1655 | if (op->stats.hp >= 0 |
1644 | if (op->stats.hp >= 0 |
1656 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
1645 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
1657 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1646 | && op->stats.hp * 100 < op->stats.maxhp * op->run_away) |
1658 | { |
1647 | { |
1659 | |
1648 | |
1660 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
1649 | if (op->flag [FLAG_MONSTER]) |
1661 | SET_FLAG (op, FLAG_RUN_AWAY); |
1650 | op->set_flag (FLAG_RUN_AWAY); |
1662 | else |
1651 | else |
1663 | scare_creature (op, hitter); |
1652 | scare_creature (op, hitter); |
1664 | } |
1653 | } |
1665 | |
1654 | |
1666 | if (QUERY_FLAG (op, FLAG_TEAR_DOWN)) |
1655 | if (op->flag [FLAG_TEAR_DOWN]) |
1667 | { |
1656 | { |
1668 | if (maxdam) |
1657 | if (maxdam) |
1669 | tear_down_wall (op); |
1658 | tear_down_wall (op); |
1670 | |
1659 | |
1671 | return maxdam; /* nothing more to do for wall */ |
1660 | return maxdam; /* nothing more to do for wall */ |
… | |
… | |
1678 | |
1667 | |
1679 | /* 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 |
1680 | * that before if the player was immune to ghosthit, the monster |
1669 | * that before if the player was immune to ghosthit, the monster |
1681 | * remained - that is no longer the case. |
1670 | * remained - that is no longer the case. |
1682 | */ |
1671 | */ |
1683 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1672 | if (hitter->flag [FLAG_ONE_HIT]) |
1684 | hitter->drop_and_destroy (); |
1673 | hitter->drop_and_destroy (); |
1685 | /* Lets handle creatures that are splitting now */ |
1674 | /* Lets handle creatures that are splitting now */ |
1686 | 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]) |
1687 | { |
1676 | { |
1688 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1677 | int friendly = op->flag [FLAG_FRIENDLY]; |
1689 | int unaggressive = QUERY_FLAG (op, FLAG_UNAGGRESSIVE); |
1678 | int unaggressive = op->flag [FLAG_UNAGGRESSIVE]; |
1690 | object *owner = op->owner; |
1679 | object *owner = op->owner; |
1691 | |
1680 | |
1692 | if (!op->other_arch) |
1681 | if (!op->other_arch) |
1693 | { |
1682 | { |
1694 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
1683 | LOG (llevError, "SPLITTING without other_arch error.\n"); |
… | |
… | |
1711 | if (owner) |
1700 | if (owner) |
1712 | tmp->set_owner (owner); |
1701 | tmp->set_owner (owner); |
1713 | } |
1702 | } |
1714 | |
1703 | |
1715 | if (unaggressive) |
1704 | if (unaggressive) |
1716 | SET_FLAG (tmp, FLAG_UNAGGRESSIVE); |
1705 | tmp->set_flag (FLAG_UNAGGRESSIVE); |
1717 | |
1706 | |
1718 | 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); |
1719 | |
1708 | |
1720 | if (j == -1) /* No spot to put this monster */ |
1709 | if (j == -1) /* No spot to put this monster */ |
1721 | tmp->destroy (); |
1710 | tmp->destroy (); |
… | |
… | |
1738 | poison_player (object *op, object *hitter, int dam) |
1727 | poison_player (object *op, object *hitter, int dam) |
1739 | { |
1728 | { |
1740 | archetype *at = archetype::find (shstr_poisoning); |
1729 | archetype *at = archetype::find (shstr_poisoning); |
1741 | object *tmp = present_arch_in_ob (at, op); |
1730 | object *tmp = present_arch_in_ob (at, op); |
1742 | |
1731 | |
1743 | if (tmp == NULL) |
1732 | if (!tmp) |
1744 | { |
1733 | { |
1745 | tmp = insert_ob_in_ob (at->instance (), op); |
1734 | tmp = insert_ob_in_ob (at->instance (), op); |
1746 | /* peterm: give poisoning some teeth. It should |
1735 | /* peterm: give poisoning some teeth. It should |
1747 | * be able to kill things better than it does: |
1736 | * be able to kill things better than it does: |
1748 | * damage should be dependent something--I choose to |
1737 | * damage should be dependent something--I choose to |
1749 | * do this: if it's a monster, the damage from the |
1738 | * do this: if it's a monster, the damage from the |
1750 | * poisoning goes as the level of the monster/2. |
1739 | * poisoning goes as the level of the monster/2. |
1751 | * If anything else, goes as damage. |
1740 | * If anything else, goes as damage. |
1752 | */ |
1741 | */ |
1753 | |
1742 | |
1754 | if (QUERY_FLAG (hitter, FLAG_ALIVE)) |
1743 | if (hitter->flag [FLAG_ALIVE]) |
1755 | tmp->stats.dam += hitter->level / 2; |
1744 | tmp->stats.dam += hitter->level / 2; |
1756 | else |
1745 | else |
1757 | tmp->stats.dam = dam; |
1746 | tmp->stats.dam = dam; |
1758 | |
1747 | |
1759 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
1748 | tmp->set_owner (hitter); /* so we get credit for poisoning kills */ |
… | |
… | |
1767 | /* player looses stats, maximum is -10 of each */ |
1756 | /* player looses stats, maximum is -10 of each */ |
1768 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1757 | tmp->stats.Con = max (-(dam / 4 + 1), -10); |
1769 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1758 | tmp->stats.Str = max (-(dam / 3 + 2), -10); |
1770 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1759 | tmp->stats.Dex = max (-(dam / 6 + 1), -10); |
1771 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1760 | tmp->stats.Int = max (-(dam / 7 ), -10); |
1772 | SET_FLAG (tmp, FLAG_APPLIED); |
1761 | tmp->set_flag (FLAG_APPLIED); |
1773 | op->update_stats (); |
1762 | op->update_stats (); |
1774 | 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."); |
1775 | op->play_sound (tmp->sound); |
1764 | op->play_sound (tmp->sound); |
1776 | } |
1765 | } |
1777 | |
1766 | |
… | |
… | |
1790 | slow_player (object *op, object *hitter, int dam) |
1779 | slow_player (object *op, object *hitter, int dam) |
1791 | { |
1780 | { |
1792 | archetype *at = archetype::find (shstr_slowness); |
1781 | archetype *at = archetype::find (shstr_slowness); |
1793 | object *tmp; |
1782 | object *tmp; |
1794 | |
1783 | |
1795 | if (at == NULL) |
1784 | if (!at) |
1796 | LOG (llevError, "Can't find slowness archetype.\n"); |
1785 | LOG (llevError, "Can't find slowness archetype.\n"); |
1797 | |
1786 | |
1798 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1787 | if ((tmp = present_arch_in_ob (at, op)) == NULL) |
1799 | { |
1788 | { |
1800 | tmp = at->instance (); |
1789 | tmp = at->instance (); |
… | |
… | |
1802 | 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!"); |
1803 | } |
1792 | } |
1804 | else |
1793 | else |
1805 | tmp->stats.food++; |
1794 | tmp->stats.food++; |
1806 | |
1795 | |
1807 | SET_FLAG (tmp, FLAG_APPLIED); |
1796 | tmp->set_flag (FLAG_APPLIED); |
1808 | tmp->speed_left = 0; |
1797 | tmp->speed_left = 0; |
1809 | op->update_stats (); |
1798 | op->update_stats (); |
1810 | } |
1799 | } |
1811 | |
1800 | |
1812 | void |
1801 | void |
… | |
… | |
1816 | int maxduration; |
1805 | int maxduration; |
1817 | |
1806 | |
1818 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1807 | tmp = present_in_ob_by_name (FORCE, shstr_confusion, op); |
1819 | if (!tmp) |
1808 | if (!tmp) |
1820 | { |
1809 | { |
1821 | tmp = get_archetype (FORCE_NAME); |
1810 | tmp = archetype::get (FORCE_NAME); |
1822 | tmp = insert_ob_in_ob (tmp, op); |
1811 | tmp = insert_ob_in_ob (tmp, op); |
1823 | } |
1812 | } |
1824 | |
1813 | |
1825 | /* Duration added per hit and max. duration of confusion both depend |
1814 | /* Duration added per hit and max. duration of confusion both depend |
1826 | * on the player's resistance |
1815 | * on the player's resistance |
1827 | */ |
1816 | */ |
1828 | tmp->speed = 0.05; |
1817 | tmp->set_speed (0.05); |
1829 | tmp->subtype = FORCE_CONFUSION; |
1818 | tmp->subtype = FORCE_CONFUSION; |
1830 | 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); |
1831 | tmp->name = shstr_confusion; |
1820 | tmp->name = shstr_confusion; |
1832 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1821 | maxduration = max (2, 30 * (100 - op->resist[ATNR_CONFUSION]) / 100); |
1833 | |
1822 | |
1834 | if (tmp->duration > maxduration) |
1823 | if (tmp->duration > maxduration) |
1835 | tmp->duration = maxduration; |
1824 | tmp->duration = maxduration; |
1836 | |
1825 | |
1837 | if (op->type == PLAYER && !QUERY_FLAG (op, FLAG_CONFUSED)) |
1826 | if (op->type == PLAYER && !op->flag [FLAG_CONFUSED]) |
1838 | 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!"); |
1839 | |
1828 | |
1840 | SET_FLAG (op, FLAG_CONFUSED); |
1829 | op->set_flag (FLAG_CONFUSED); |
1841 | } |
1830 | } |
1842 | |
1831 | |
1843 | void |
1832 | void |
1844 | blind_player (object *op, object *hitter, int dam) |
1833 | blind_player (object *op, object *hitter, int dam) |
1845 | { |
1834 | { |
1846 | object *tmp, *owner; |
|
|
1847 | |
|
|
1848 | /* 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 */ |
1849 | if (op->resist[ATNR_BLIND] == 100) |
1836 | if (op->resist[ATNR_BLIND] == 100) |
1850 | return; |
1837 | return; |
1851 | |
1838 | |
1852 | tmp = present_in_ob (BLINDNESS, op); |
1839 | object *tmp = present_in_ob (BLINDNESS, op); |
1853 | if (!tmp) |
1840 | if (!tmp) |
1854 | { |
1841 | { |
1855 | tmp = get_archetype (shstr_blindness); |
1842 | tmp = archetype::get (shstr_blindness); |
1856 | SET_FLAG (tmp, FLAG_BLIND); |
1843 | tmp->set_flag (FLAG_BLIND); |
1857 | SET_FLAG (tmp, FLAG_APPLIED); |
1844 | tmp->set_flag (FLAG_APPLIED); |
1858 | /* 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. |
1859 | * speed is a float anyways. |
1846 | tmp->set_speed (lerp<float> (op->resist [ATNR_BLIND], 0, 100, tmp->speed, MIN_ACTIVE_SPEED)); |
1860 | */ |
|
|
1861 | tmp->speed = tmp->speed * (100.0 - (float) op->resist[ATNR_BLIND]) / 100; |
|
|
1862 | |
1847 | |
1863 | tmp = insert_ob_in_ob (tmp, op); |
1848 | tmp = insert_ob_in_ob (tmp, op); |
1864 | change_abil (op, tmp); /* Mostly to display any messages */ |
1849 | change_abil (op, tmp); /* Mostly to display any messages */ |
1865 | op->update_stats (); /* This takes care of some other stuff */ |
1850 | op->update_stats (); /* This takes care of some other stuff */ |
1866 | |
1851 | |
1867 | if (hitter->owner) |
|
|
1868 | owner = hitter->owner; |
|
|
1869 | else |
|
|
1870 | owner = hitter; |
|
|
1871 | |
|
|
1872 | 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)); |
1873 | } |
1853 | } |
|
|
1854 | |
1874 | tmp->stats.food += dam; |
1855 | tmp->stats.food += dam; |
1875 | if (tmp->stats.food > 10) |
1856 | min_it (tmp->stats.food, 10); |
1876 | tmp->stats.food = 10; |
|
|
1877 | } |
1857 | } |
1878 | |
1858 | |
1879 | void |
1859 | void |
1880 | paralyze_player (object *op, object *hitter, int dam) |
1860 | paralyze_player (object *op, object *hitter, int dam) |
1881 | { |
1861 | { |
… | |
… | |
1920 | ** field of the deathstriking object */ |
1900 | ** field of the deathstriking object */ |
1921 | |
1901 | |
1922 | int atk_lev, def_lev, kill_lev; |
1902 | int atk_lev, def_lev, kill_lev; |
1923 | |
1903 | |
1924 | if (hitter->slaying) |
1904 | if (hitter->slaying) |
1925 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
1905 | if (!((op->flag [FLAG_UNDEAD] && hitter->slaying.contains (shstr_undead)) |
1926 | || (op->race && hitter->slaying.contains (op->race)))) |
1906 | || (op->race && hitter->slaying.contains (op->race)))) |
1927 | return; |
1907 | return; |
1928 | |
1908 | |
1929 | def_lev = op->level; |
1909 | def_lev = op->level; |
1930 | if (def_lev < 1) |
1910 | if (def_lev < 1) |
… | |
… | |
2055 | * Second, just getting hit doesn't mean it always affects |
2035 | * Second, just getting hit doesn't mean it always affects |
2056 | * you. Third, you still get a saving through against the |
2036 | * you. Third, you still get a saving through against the |
2057 | * effect. |
2037 | * effect. |
2058 | */ |
2038 | */ |
2059 | if (op->has_active_speed () |
2039 | if (op->has_active_speed () |
2060 | && (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER) |
2040 | && (op->flag [FLAG_MONSTER] || op->type == PLAYER) |
2061 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2041 | && !(rndm (0, (attacknum == ATNR_SLOW ? 6 : 3) - 1)) |
2062 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2042 | && !did_make_save (op, level_diff, op->resist[attacknum] / 10)) |
2063 | { |
2043 | { |
2064 | |
2044 | |
2065 | /* Player has been hit by something */ |
2045 | /* Player has been hit by something */ |
… | |
… | |
2075 | scare_creature (op, hitter); |
2055 | scare_creature (op, hitter); |
2076 | else if (attacknum == ATNR_CANCELLATION) |
2056 | else if (attacknum == ATNR_CANCELLATION) |
2077 | cancellation (op); |
2057 | cancellation (op); |
2078 | else if (attacknum == ATNR_DEPLETE) |
2058 | else if (attacknum == ATNR_DEPLETE) |
2079 | op->drain_stat (); |
2059 | op->drain_stat (); |
2080 | 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]) |
2081 | blind_player (op, hitter, dam); |
2061 | blind_player (op, hitter, dam); |
2082 | } |
2062 | } |
2083 | |
2063 | |
2084 | 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 */ |
2085 | } |
2065 | } |
… | |
… | |
2095 | { |
2075 | { |
2096 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2076 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2097 | { |
2077 | { |
2098 | if (tmp->invisible) |
2078 | if (tmp->invisible) |
2099 | continue; |
2079 | continue; |
2100 | if (!QUERY_FLAG (tmp, FLAG_APPLIED) || (tmp->resist[ATNR_ACID] >= 10)) |
2080 | if (!tmp->flag [FLAG_APPLIED] || (tmp->resist[ATNR_ACID] >= 10)) |
2101 | /* >= 10% acid res. on items will protect these */ |
2081 | /* >= 10% acid res. on items will protect these */ |
2102 | continue; |
2082 | continue; |
2103 | if (!(tmp->materials & M_IRON)) |
2083 | if (!(tmp->materials & M_IRON)) |
2104 | continue; |
2084 | continue; |
2105 | if (tmp->magic < -4) /* Let's stop at -5 */ |
2085 | if (tmp->magic < -4) /* Let's stop at -5 */ |
… | |
… | |
2169 | * 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, |
2170 | * nothing happens. |
2150 | * nothing happens. |
2171 | * 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 |
2172 | * attacks, hence all the != PLAYER checks. |
2152 | * attacks, hence all the != PLAYER checks. |
2173 | */ |
2153 | */ |
2174 | if (!op_on_battleground (hitter, NULL, NULL) && !QUERY_FLAG (op, FLAG_WIZ)) |
2154 | if (!op_on_battleground (hitter, NULL, NULL) && !op->flag [FLAG_WIZ]) |
2175 | { |
2155 | { |
2176 | object *owner = hitter->owner; |
2156 | object *owner = hitter->owner; |
2177 | |
2157 | |
2178 | if (owner && owner != hitter) |
2158 | if (owner && owner != hitter) |
2179 | { |
2159 | { |
2180 | if (op->type != PLAYER || owner->type != PLAYER) |
2160 | if (op->type != PLAYER || owner->type != PLAYER) |
2181 | change_exp (owner, op->stats.exp / (rate * 2), |
2161 | change_exp (owner, op->stats.exp / (rate * 2), |
2182 | 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); |
2183 | } |
2163 | } |
2184 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2164 | else if (op->type != PLAYER || hitter->type != PLAYER) |
2185 | change_exp (hitter, op->stats.exp / (rate * 2), |
2165 | change_exp (hitter, op->stats.exp / (rate * 2), |
2186 | hitter->chosen_skill ? hitter->chosen_skill->skill : (const char *) 0, 0); |
2166 | hitter->chosen_skill ? hitter->chosen_skill->skill : shstr (), 0); |
2187 | |
2167 | |
2188 | change_exp (op, -op->stats.exp / rate, NULL, 0); |
2168 | change_exp (op, -op->stats.exp / rate, shstr (), 0); |
2189 | } |
2169 | } |
2190 | |
2170 | |
2191 | 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 |
2192 | * 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, |
2193 | * as the messages will say you missed |
2173 | * as the messages will say you missed |
… | |
… | |
2196 | } |
2176 | } |
2197 | break; |
2177 | break; |
2198 | |
2178 | |
2199 | case ATNR_TURN_UNDEAD: |
2179 | case ATNR_TURN_UNDEAD: |
2200 | { |
2180 | { |
2201 | if (QUERY_FLAG (op, FLAG_UNDEAD)) |
2181 | if (op->flag [FLAG_UNDEAD]) |
2202 | { |
2182 | { |
2203 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2183 | object *owner = hitter->owner ? (object *)hitter->owner : hitter; |
2204 | object *god = find_god (determine_god (owner)); |
2184 | object *god = find_god (determine_god (owner)); |
2205 | int div = 1; |
2185 | int div = 1; |
2206 | |
2186 | |
… | |
… | |
2261 | * damage it does do to the player. Given that, |
2241 | * damage it does do to the player. Given that, |
2262 | * 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 |
2263 | * 1000). |
2243 | * 1000). |
2264 | */ |
2244 | */ |
2265 | /* You can't steal life from something undead */ |
2245 | /* You can't steal life from something undead */ |
2266 | if ((op->type == GOLEM) || (QUERY_FLAG (op, FLAG_UNDEAD))) |
2246 | if ((op->type == GOLEM) || (op->flag [FLAG_UNDEAD])) |
2267 | return 0; |
2247 | return 0; |
2268 | |
2248 | |
2269 | /* If drain protection is higher than life stealing, use that */ |
2249 | /* If drain protection is higher than life stealing, use that */ |
2270 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2250 | if (op->resist[ATNR_DRAIN] >= op->resist[ATNR_LIFE_STEALING]) |
2271 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |
2251 | dam = (dam * (100 - op->resist[ATNR_DRAIN])) / 3000; |