… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your 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 GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * 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> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <assert.h> |
25 | #include <assert.h> |
… | |
… | |
79 | int i, roll, saves = 0, attacks = 0, number; |
80 | int i, roll, saves = 0, attacks = 0, number; |
80 | materialtype_t *mt; |
81 | materialtype_t *mt; |
81 | |
82 | |
82 | if (!op->materialname) |
83 | if (!op->materialname) |
83 | { |
84 | { |
84 | for (mt = materialt; mt && mt->next; mt = mt->next) |
85 | for (mt = materialt; mt; mt = mt->next) |
85 | if (op->materials & mt->material) |
86 | if (op->materials & mt->material) |
86 | break; |
87 | break; |
87 | } |
88 | } |
88 | else |
89 | else |
89 | mt = name_to_material (op->materialname); |
90 | mt = name_to_material (op->materialname); |
… | |
… | |
148 | object *env = op->env; |
149 | object *env = op->env; |
149 | int x = op->x, y = op->y; |
150 | int x = op->x, y = op->y; |
150 | maptile *m = op->map; |
151 | maptile *m = op->map; |
151 | |
152 | |
152 | op = stop_item (op); |
153 | op = stop_item (op); |
153 | if (op == NULL) |
154 | if (!op) |
154 | return; |
155 | return; |
155 | |
156 | |
156 | /* Hacked the following so that type LIGHTER will work. |
157 | /* Hacked the following so that type LIGHTER will work. |
157 | * Also, objects which are potential "lights" that are hit by |
158 | * Also, objects which are potential "lights" that are hit by |
158 | * flame/elect attacks will be set to glow. "lights" are any |
159 | * flame/elect attacks will be set to glow. "lights" are any |
159 | * object with +/- glow_radius and an "other_arch" to change to. |
160 | * object with +/- glow_radius and an "other_arch" to change to. |
160 | * (and please note that we cant fail our save and reach this |
161 | * (and please note that we cant fail our save and reach this |
161 | * function if the object doesnt contain a material that can burn. |
162 | * function if the object doesnt contain a material that can burn. |
162 | * So forget lighting magical swords on fire with this!) -b.t. |
163 | * So forget lighting magical swords on fire with this!) -b.t. |
163 | */ |
164 | */ |
164 | if (type & (AT_FIRE | AT_ELECTRICITY) && op->other_arch && QUERY_FLAG (op, FLAG_IS_LIGHTABLE)) |
165 | if (type & (AT_FIRE | AT_ELECTRICITY) |
|
|
166 | && (QUERY_FLAG (op, FLAG_IS_LIGHTABLE) |
|
|
167 | || op->type == LAMP |
|
|
168 | || op->type == TORCH |
165 | { |
169 | )) |
166 | const char *arch = op->other_arch->archname; |
170 | { |
167 | |
171 | switch (op->type) |
168 | if (op->decrease ()) |
|
|
169 | fix_stopped_item (op, m, originator); |
|
|
170 | |
|
|
171 | if ((op = archetype::get (arch))) |
|
|
172 | { |
172 | { |
|
|
173 | case LAMP: |
|
|
174 | case TORCH: |
|
|
175 | // turn on a lamp |
|
|
176 | apply_lamp (op, true); |
|
|
177 | break; |
|
|
178 | |
|
|
179 | default: |
|
|
180 | // for instance icecubes: |
|
|
181 | if (op->other_arch) |
|
|
182 | { |
|
|
183 | const char *arch = op->other_arch->archname; |
|
|
184 | |
|
|
185 | if (op->decrease ()) |
|
|
186 | fix_stopped_item (op, m, originator); |
|
|
187 | |
|
|
188 | if ((op = archetype::get (arch))) |
|
|
189 | { |
173 | if (env) |
190 | if (env) |
174 | env->insert (op); |
191 | env->insert (op); |
175 | else |
192 | else |
176 | m->insert (op, x, y, originator); |
193 | m->insert (op, x, y, originator); |
|
|
194 | } |
|
|
195 | } |
177 | } |
196 | } |
178 | |
|
|
179 | return; |
197 | return; |
180 | } |
198 | } |
181 | |
199 | |
182 | if (type & AT_CANCELLATION) |
200 | if (type & AT_CANCELLATION) |
183 | { /* Cancellation. */ |
201 | { /* Cancellation. */ |
… | |
… | |
192 | fix_stopped_item (op, m, originator); |
210 | fix_stopped_item (op, m, originator); |
193 | } |
211 | } |
194 | else |
212 | else |
195 | { |
213 | { |
196 | // drop everything to the ground, if possible |
214 | // drop everything to the ground, if possible |
197 | while (op->inv) |
|
|
198 | op->inv->insert_at (originator); |
215 | op->insert_at (originator); |
199 | |
|
|
200 | op->destroy (); |
216 | op->drop_and_destroy (); |
201 | } |
217 | } |
202 | |
218 | |
203 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
219 | if (type & (AT_FIRE | AT_ELECTRICITY)) |
204 | if (env) |
220 | if (env) |
205 | { |
221 | { |
… | |
… | |
212 | |
228 | |
213 | return; |
229 | return; |
214 | } |
230 | } |
215 | |
231 | |
216 | /* The value of 50 is arbitrary. */ |
232 | /* The value of 50 is arbitrary. */ |
217 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && (RANDOM () & 2)) |
233 | if (type & AT_COLD && (op->resist[ATNR_COLD] < 50) && !QUERY_FLAG (op, FLAG_NO_PICK) && rndm (2)) |
218 | { |
234 | { |
219 | archetype *at = archetype::find (shstr_icecube); |
235 | archetype *at = archetype::find (shstr_icecube); |
220 | |
236 | |
221 | if (at == NULL) |
237 | if (at == NULL) |
222 | return; |
238 | return; |
… | |
… | |
374 | |
390 | |
375 | /* put in a few special messages for some of the common attacktypes |
391 | /* put in a few special messages for some of the common attacktypes |
376 | * a player might have. For example, fire, electric, cold, etc |
392 | * a player might have. For example, fire, electric, cold, etc |
377 | * [garbled 20010919] |
393 | * [garbled 20010919] |
378 | */ |
394 | */ |
379 | |
|
|
380 | if (dam == 9998 && op->type == DOOR) |
395 | if (dam == 9998 && op->type == DOOR) |
381 | { |
396 | { |
382 | sprintf (buf1, "unlock %s", &op->name); |
397 | sprintf (buf1, "unlock %s", &op->name); |
383 | sprintf (buf2, " unlocks"); |
398 | sprintf (buf2, " unlocks"); |
384 | found++; |
399 | found++; |
385 | } |
400 | } |
386 | if (dam < 0) |
401 | else if (dam < 0) |
387 | { |
402 | { |
388 | sprintf (buf1, "hit %s", &op->name); |
403 | sprintf (buf1, "hit %s", &op->name); |
389 | sprintf (buf2, " hits"); |
404 | sprintf (buf2, " hits"); |
390 | found++; |
405 | found++; |
391 | } |
406 | } |
… | |
… | |
513 | strcpy (buf2, attack_mess[ATM_FIRE][i].buf3); |
528 | strcpy (buf2, attack_mess[ATM_FIRE][i].buf3); |
514 | found++; |
529 | found++; |
515 | break; |
530 | break; |
516 | } |
531 | } |
517 | } |
532 | } |
518 | else if (hitter->current_weapon != NULL) |
533 | else if (hitter->current_weapon) |
519 | { |
534 | { |
520 | int mtype; |
535 | int mtype; |
521 | |
536 | |
522 | switch (hitter->current_weapon->weapontype) |
537 | switch (hitter->current_weapon->weapontype) |
523 | { |
538 | { |
… | |
… | |
661 | op->play_sound (sound_find ("player_hits4")); |
676 | op->play_sound (sound_find ("player_hits4")); |
662 | new_draw_info (NDI_BLACK, 0, hitter->owner, buf); |
677 | new_draw_info (NDI_BLACK, 0, hitter->owner, buf); |
663 | } |
678 | } |
664 | } |
679 | } |
665 | |
680 | |
666 | |
|
|
667 | static int |
681 | static int |
668 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
682 | get_attack_mode (object **target, object **hitter, int *simple_attack) |
669 | { |
683 | { |
670 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
684 | if (QUERY_FLAG (*target, FLAG_FREED) || QUERY_FLAG (*hitter, FLAG_FREED)) |
671 | { |
685 | { |
672 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
686 | LOG (llevError, "BUG: get_attack_mode(): freed object\n"); |
673 | return 1; |
687 | return 1; |
674 | } |
688 | } |
675 | |
689 | |
676 | if ((*target)->head) |
|
|
677 | *target = (*target)->head; |
690 | *target = (*target)->head_ (); |
678 | |
|
|
679 | if ((*hitter)->head) |
|
|
680 | *hitter = (*hitter)->head; |
691 | *hitter = (*hitter)->head_ (); |
681 | |
692 | |
682 | if ((*target)->type == LOCKED_DOOR) |
693 | if ((*target)->type == LOCKED_DOOR) |
683 | return 1; // locked doors cannot be hit |
694 | return 1; // locked doors cannot be hit |
684 | |
695 | |
685 | if ((*hitter)->env || (*target)->env) |
696 | if ((*hitter)->env || (*target)->env) |
… | |
… | |
703 | } |
714 | } |
704 | |
715 | |
705 | static int |
716 | static int |
706 | abort_attack (object *target, object *hitter, int simple_attack) |
717 | abort_attack (object *target, object *hitter, int simple_attack) |
707 | { |
718 | { |
708 | |
|
|
709 | /* Check if target and hitter are still in a relation similar to the one |
719 | /* Check if target and hitter are still in a relation similar to the one |
710 | * determined by get_attack_mode(). Returns true if the relation has changed. |
720 | * determined by get_attack_mode(). Returns true if the relation has changed. |
711 | */ |
721 | */ |
712 | int new_mode; |
722 | int new_mode; |
713 | |
723 | |
714 | if (hitter->env == target || target->env == hitter) |
724 | if (hitter->env == target || target->env == hitter) |
715 | new_mode = 1; |
725 | new_mode = 1; |
716 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) || hitter->map == NULL || !on_same_map (hitter, target)) |
726 | else if (QUERY_FLAG (hitter, FLAG_REMOVED) || QUERY_FLAG (target, FLAG_REMOVED) |
|
|
727 | || hitter->map == NULL || !on_same_map (hitter, target)) |
717 | return 1; |
728 | return 1; |
718 | else |
729 | else |
719 | new_mode = 0; |
730 | new_mode = 0; |
|
|
731 | |
720 | return new_mode != simple_attack; |
732 | return new_mode != simple_attack; |
721 | } |
733 | } |
722 | |
734 | |
723 | static void thrown_item_effect (object *, object *); |
735 | static void thrown_item_effect (object *, object *); |
724 | |
736 | |
… | |
… | |
782 | * for help. */ |
794 | * for help. */ |
783 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
795 | if (op->type != PLAYER && !can_see_enemy (op, hitter) && !op->owner && rndm (0, op->stats.Int)) |
784 | npc_call_help (op); |
796 | npc_call_help (op); |
785 | |
797 | |
786 | /* if you were hidden and hit by a creature, you are discovered */ |
798 | /* if you were hidden and hit by a creature, you are discovered */ |
787 | if (op->hide && QUERY_FLAG (hitter, FLAG_ALIVE)) |
799 | if (op->flag [FLAG_HIDDEN] && hitter->flag [FLAG_ALIVE]) |
788 | { |
800 | { |
789 | make_visible (op); |
801 | make_visible (op); |
790 | |
802 | |
791 | if (op->type == PLAYER) |
803 | if (op->type == PLAYER) |
792 | new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. " "You are no longer hidden!"); |
804 | new_draw_info (NDI_UNIQUE, 0, op, "You were hit by a wild attack. You are no longer hidden!"); |
793 | } |
805 | } |
794 | |
806 | |
795 | /* thrown items (hitter) will have various effects |
807 | /* thrown items (hitter) will have various effects |
796 | * when they hit the victim. For things like thrown daggers, |
808 | * when they hit the victim. For things like thrown daggers, |
797 | * this sets 'hitter' to the actual dagger, and not the |
809 | * this sets 'hitter' to the actual dagger, and not the |
… | |
… | |
809 | if (hitdam <= 0) |
821 | if (hitdam <= 0) |
810 | hitdam = 1; |
822 | hitdam = 1; |
811 | |
823 | |
812 | type = hitter->attacktype; |
824 | type = hitter->attacktype; |
813 | |
825 | |
|
|
826 | /* Ok, because some of the brainfucks of the good *sigh* old *sigh* |
|
|
827 | * Crossfire we have to default the attacktype here to AT_PHYSICAL. |
|
|
828 | * This check is important for the most simple monsters out there in the |
|
|
829 | * game content (maps, archs). For example orcs: They would have |
|
|
830 | * no attacktype at all. |
|
|
831 | * |
|
|
832 | * Some time in the future someone should just go into the game data |
|
|
833 | * and fix every monster out there ;-/ Until then we will kill some |
|
|
834 | * more trees in the african rain forests with this check. |
|
|
835 | */ |
814 | if (!type) |
836 | if (!type) |
815 | type = AT_PHYSICAL; |
837 | type = AT_PHYSICAL; |
816 | |
838 | |
817 | /* Handle monsters that hit back */ |
839 | /* Handle monsters that hit back */ |
818 | if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) |
840 | if (!simple_attack && QUERY_FLAG (op, FLAG_HITBACK) && QUERY_FLAG (hitter, FLAG_ALIVE)) |
… | |
… | |
893 | /* Disassemble missile */ |
915 | /* Disassemble missile */ |
894 | if (op->inv) |
916 | if (op->inv) |
895 | { |
917 | { |
896 | container = op; |
918 | container = op; |
897 | hitter = op->inv; |
919 | hitter = op->inv; |
898 | hitter->remove (); |
|
|
899 | insert_ob_in_map (hitter, container->map, hitter, INS_NO_MERGE | INS_NO_WALK_ON); |
920 | hitter->insert_at (container, hitter, INS_NO_MERGE | INS_NO_WALK_ON); |
900 | /* Note that we now have an empty THROWN_OBJ on the map. Code that |
921 | /* Note that we now have an empty THROWN_OBJ on the map. Code that |
901 | * might be called until this THROWN_OBJ is either reassembled or |
922 | * might be called until this THROWN_OBJ is either reassembled or |
902 | * removed at the end of this function must be able to deal with empty |
923 | * removed at the end of this function must be able to deal with empty |
903 | * THROWN_OBJs. */ |
924 | * THROWN_OBJs. */ |
904 | } |
925 | } |
… | |
… | |
918 | * other places as well!) |
939 | * other places as well!) |
919 | */ |
940 | */ |
920 | if (hitter->destroyed () || hitter->env != NULL) |
941 | if (hitter->destroyed () || hitter->env != NULL) |
921 | { |
942 | { |
922 | if (container) |
943 | if (container) |
923 | { |
|
|
924 | container->remove (); |
|
|
925 | container->destroy (); |
944 | container->destroy (); |
926 | } |
|
|
927 | |
945 | |
928 | return 0; |
946 | return 0; |
929 | } |
947 | } |
930 | |
948 | |
931 | /* Missile hit victim */ |
949 | /* Missile hit victim */ |
… | |
… | |
955 | * can fly over but not otherwise move over. What is the correct |
973 | * can fly over but not otherwise move over. What is the correct |
956 | * way to handle those otherwise? |
974 | * way to handle those otherwise? |
957 | */ |
975 | */ |
958 | if (victim->x != hitter->x || victim->y != hitter->y) |
976 | if (victim->x != hitter->x || victim->y != hitter->y) |
959 | { |
977 | { |
|
|
978 | if (victim->destroyed ()) |
|
|
979 | hitter->destroy (); |
|
|
980 | else |
|
|
981 | { |
960 | hitter->remove (); |
982 | hitter->remove (); |
961 | hitter->x = victim->x; |
983 | hitter->x = victim->x; |
962 | hitter->y = victim->y; |
984 | hitter->y = victim->y; |
963 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
985 | insert_ob_in_map (hitter, victim->map, hitter, 0); |
|
|
986 | } |
964 | } |
987 | } |
965 | else |
988 | else |
966 | /* Else leave arrow where it is */ |
989 | /* Else leave arrow where it is */ |
967 | merge_ob (hitter, NULL); |
990 | merge_ob (hitter, NULL); |
968 | |
991 | |
… | |
… | |
983 | } |
1006 | } |
984 | |
1007 | |
985 | void |
1008 | void |
986 | tear_down_wall (object *op) |
1009 | tear_down_wall (object *op) |
987 | { |
1010 | { |
988 | int perc = 0; |
|
|
989 | |
|
|
990 | if (!op->stats.maxhp) |
1011 | if (!op->stats.maxhp) |
991 | { |
|
|
992 | LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name); |
1012 | LOG (llevError, "TEAR_DOWN wall %s had no maxhp.\n", &op->name); |
993 | perc = 1; |
1013 | else if (!op->has_anim ()) |
994 | } |
|
|
995 | else if (!GET_ANIM_ID (op)) |
|
|
996 | { |
1014 | { |
997 | /* Object has been called - no animations, so remove it */ |
1015 | /* Object has been called - no animations, so remove it */ |
998 | if (op->stats.hp < 0) |
1016 | if (op->stats.hp < 0) |
999 | op->destroy (); |
1017 | op->destroy (); |
1000 | |
1018 | |
1001 | return; /* no animations, so nothing more to do */ |
1019 | return; /* no animations, so nothing more to do */ |
1002 | } |
1020 | } |
1003 | |
1021 | |
1004 | perc = NUM_ANIMATIONS (op) - ((int) NUM_ANIMATIONS (op) * op->stats.hp) / op->stats.maxhp; |
1022 | // we use frames 1..num-2 as intermediate frames, so |
|
|
1023 | // the last frame is used only when hp < 0. |
|
|
1024 | int perc = clamp ( |
|
|
1025 | lerp_ru<int> (op->stats.hp, 0, op->stats.maxhp, op->anim_frames () - 2, 0), |
|
|
1026 | 0, op->anim_frames () - 1 |
|
|
1027 | ); |
1005 | |
1028 | |
1006 | if (perc >= (int) NUM_ANIMATIONS (op)) |
1029 | op->set_anim_frame (perc); |
1007 | perc = NUM_ANIMATIONS (op) - 1; |
|
|
1008 | else if (perc < 1) |
|
|
1009 | perc = 1; |
|
|
1010 | |
|
|
1011 | SET_ANIMATION (op, perc); |
|
|
1012 | update_object (op, UP_OBJ_FACE); |
1030 | update_object (op, UP_OBJ_FACE); |
1013 | |
1031 | |
1014 | if (perc == NUM_ANIMATIONS (op) - 1) |
1032 | if (op->stats.hp < 0) |
1015 | { /* Reached the last animation */ |
1033 | { /* Reached the last animation */ |
1016 | if (op->face == blank_face) |
1034 | if (op->face == blank_face) |
1017 | /* If the last face is blank, remove the ob */ |
1035 | /* If the last face is blank, remove the ob */ |
1018 | op->destroy (); |
1036 | op->destroy (); |
1019 | else |
1037 | else |
1020 | { /* The last face was not blank, leave an image */ |
1038 | { /* The last face was not blank, leave an image */ |
1021 | CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
1039 | op->flag [FLAG_BLOCKSVIEW] = false; |
1022 | update_all_los (op->map, op->x, op->y); |
1040 | update_all_los (op->map, op->x, op->y); |
1023 | op->move_block = 0; |
1041 | op->move_block = 0; |
1024 | CLEAR_FLAG (op, FLAG_ALIVE); |
1042 | op->flag [FLAG_ALIVE] = false; |
1025 | } |
1043 | } |
1026 | } |
1044 | } |
1027 | } |
1045 | } |
1028 | |
1046 | |
1029 | void |
1047 | void |
1030 | scare_creature (object *target, object *hitter) |
1048 | scare_creature (object *target, object *hitter) |
1031 | { |
1049 | { |
1032 | object *owner = hitter->owner; |
1050 | target->flag [FLAG_SCARED] = true; |
1033 | |
1051 | |
1034 | if (!owner) |
|
|
1035 | owner = hitter; |
|
|
1036 | |
|
|
1037 | SET_FLAG (target, FLAG_SCARED); |
|
|
1038 | if (!target->enemy) |
1052 | if (!target->enemy) |
1039 | target->enemy = owner; |
1053 | target->enemy = hitter->outer_owner (); |
1040 | } |
1054 | } |
1041 | |
1055 | |
1042 | /* This returns the amount of damage hitter does to op with the |
1056 | /* This returns the amount of damage hitter does to op with the |
1043 | * appropriate attacktype. Only 1 attacktype should be set at a time. |
1057 | * appropriate attacktype. Only 1 attacktype should be set at a time. |
1044 | * This doesn't damage the player, but returns how much it should |
1058 | * This doesn't damage the player, but returns how much it should |
… | |
… | |
1069 | if (attacknum == ATNR_INTERNAL) |
1083 | if (attacknum == ATNR_INTERNAL) |
1070 | return dam; |
1084 | return dam; |
1071 | |
1085 | |
1072 | if (hitter->slaying) |
1086 | if (hitter->slaying) |
1073 | { |
1087 | { |
1074 | if ((op->race && strstr (hitter->slaying, op->race)) |
1088 | if ((op->race && hitter->slaying.contains (op->race)) |
1075 | || (op->arch && op->arch->archname && strstr (op->arch->archname, hitter->slaying))) |
1089 | || (op->arch && op->arch->archname.contains (hitter->slaying))) |
1076 | { |
1090 | { |
1077 | doesnt_slay = 0; |
1091 | doesnt_slay = 0; |
1078 | dam *= 3; |
1092 | dam *= 3; |
1079 | } |
1093 | } |
1080 | } |
1094 | } |
… | |
… | |
1282 | object *god = find_god (determine_god (owner)); |
1296 | object *god = find_god (determine_god (owner)); |
1283 | int div = 1; |
1297 | int div = 1; |
1284 | |
1298 | |
1285 | /* if undead are not an enemy of your god, you turn them |
1299 | /* if undead are not an enemy of your god, you turn them |
1286 | * at half strength */ |
1300 | * at half strength */ |
1287 | if (!god || !god->slaying || strstr (god->slaying, shstr_undead) == NULL) |
1301 | if (!god || !god->slaying.contains (shstr_undead)) |
1288 | div = 2; |
1302 | div = 2; |
1289 | |
1303 | |
1290 | /* Give a bonus if you resist turn undead */ |
1304 | /* Give a bonus if you resist turn undead */ |
1291 | if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) |
1305 | if (op->level * div < (turn_bonus[owner->stats.Wis] + owner->level + (op->resist[ATNR_TURN_UNDEAD] / 100))) |
1292 | scare_creature (op, owner); |
1306 | scare_creature (op, owner); |
… | |
… | |
1383 | */ |
1397 | */ |
1384 | int |
1398 | int |
1385 | kill_object (object *op, int dam, object *hitter, int type) |
1399 | kill_object (object *op, int dam, object *hitter, int type) |
1386 | { |
1400 | { |
1387 | char buf[MAX_BUF]; |
1401 | char buf[MAX_BUF]; |
1388 | const char *skill; |
1402 | shstr skill; |
1389 | int maxdam = 0; |
1403 | int maxdam = 0; |
1390 | int battleg = 0; /* true if op standing on battleground */ |
1404 | int battleg = 0; /* true if op standing on battleground */ |
1391 | int pk = 0; /* true if op and what controls hitter are both players */ |
1405 | int pk = 0; /* true if op and what controls hitter are both players */ |
1392 | object *owner = 0; |
1406 | object *owner = 0; |
1393 | object *skop = 0; |
1407 | object *skop = 0; |
… | |
… | |
1414 | return maxdam; |
1428 | return maxdam; |
1415 | } |
1429 | } |
1416 | |
1430 | |
1417 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1431 | if (QUERY_FLAG (op, FLAG_FRIENDLY) && op->type != PLAYER) |
1418 | { |
1432 | { |
1419 | op->destroy (); |
1433 | op->drop_and_destroy (); |
1420 | return maxdam; |
1434 | return maxdam; |
1421 | } |
1435 | } |
1422 | |
1436 | |
1423 | /* Now lets start dealing with experience we get for killing something */ |
1437 | /* Now lets start dealing with experience we get for killing something */ |
1424 | |
1438 | |
1425 | owner = hitter->owner; |
1439 | owner = hitter->outer_owner (); |
1426 | if (!owner) |
1440 | if (!owner) |
1427 | owner = hitter; |
1441 | owner = hitter; |
1428 | |
1442 | |
1429 | /* is the victim (op) standing on battleground? */ |
1443 | /* is the victim (op) standing on battleground? */ |
1430 | if (op_on_battleground (op, NULL, NULL)) |
1444 | if (op_on_battleground (op, NULL, NULL)) |
… | |
… | |
1482 | |
1496 | |
1483 | /* This code below deals with finding the appropriate skill |
1497 | /* This code below deals with finding the appropriate skill |
1484 | * to credit exp to. This is a bit problematic - we should |
1498 | * to credit exp to. This is a bit problematic - we should |
1485 | * probably never really have to look at current_weapon->skill |
1499 | * probably never really have to look at current_weapon->skill |
1486 | */ |
1500 | */ |
1487 | skill = 0; |
|
|
1488 | |
|
|
1489 | if (hitter->skill && hitter->type != PLAYER) |
1501 | if (hitter->skill && hitter->type != PLAYER) |
1490 | skill = hitter->skill; |
1502 | skill = hitter->skill; |
1491 | else if (owner->chosen_skill) |
1503 | else if (owner->chosen_skill) |
1492 | { |
1504 | { |
1493 | skop = owner->chosen_skill; |
1505 | skop = owner->chosen_skill; |
1494 | skill = skop->skill; |
1506 | skill = skop->skill; |
1495 | } |
1507 | } |
1496 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON)) |
1508 | else if (QUERY_FLAG (owner, FLAG_READY_WEAPON) && owner->current_weapon) |
1497 | skill = owner->current_weapon->skill; |
1509 | skill = owner->current_weapon->skill; |
1498 | else |
1510 | else |
|
|
1511 | { |
1499 | LOG (llevError, "kill_object - unable to find skill that killed monster\n"); |
1512 | LOG (llevError, "BUG: kill_object - unable to find skill that killed monster\n" |
|
|
1513 | "op: %s\n" "hitter: %s\n" "owner: %s\n", |
|
|
1514 | owner->debug_desc (), hitter->debug_desc (), op->debug_desc ()); |
|
|
1515 | skill = 0; |
|
|
1516 | } |
1500 | |
1517 | |
1501 | /* We have the skill we want to credit to - now find the object this goes |
1518 | /* We have the skill we want to credit to - now find the object this goes |
1502 | * to. Make sure skop is an actual skill, and not a skill tool! |
1519 | * to. Make sure skop is an actual skill, and not a skill tool! |
1503 | */ |
1520 | */ |
1504 | if ((!skop || skop->type != SKILL) && skill) |
1521 | skop = owner->contr->find_skill (skill); |
1505 | { |
|
|
1506 | int i; |
|
|
1507 | |
|
|
1508 | for (i = 0; i < NUM_SKILLS; i++) |
|
|
1509 | if (owner->contr->last_skill_ob[i] && !strcmp (owner->contr->last_skill_ob[i]->skill, skill)) |
|
|
1510 | { |
|
|
1511 | skop = owner->contr->last_skill_ob[i]; |
|
|
1512 | break; |
|
|
1513 | } |
|
|
1514 | } |
|
|
1515 | } /* Was it a player that hit somethign */ |
1522 | } /* Was it a player that hit somethign */ |
1516 | else |
1523 | else |
1517 | skill = 0; |
1524 | skill = 0; |
1518 | |
1525 | |
1519 | /* Pet (or spell) killed something. */ |
|
|
1520 | if (owner != hitter) |
|
|
1521 | sprintf (buf, "%s killed %s with %s%s%s.", &owner->name, |
|
|
1522 | query_name (op), query_name (hitter), battleg ? " (duel)" : "", pk ? " (pk)" : ""); |
|
|
1523 | else |
|
|
1524 | sprintf (buf, "%s killed %s%s%s%s.", &hitter->name, &op->name, |
|
|
1525 | (QUERY_FLAG (hitter, FLAG_MONSTER)) || hitter->type == PLAYER ? |
|
|
1526 | " in hand to hand combat" : "", battleg ? " (duel)" : "", pk ? " (pk)" : ""); |
|
|
1527 | |
|
|
1528 | /* These may have been set in the player code section above */ |
1526 | /* These may have been set in the player code section above */ |
1529 | if (!skop) |
1527 | if (!skop) |
1530 | skop = hitter->chosen_skill; |
1528 | skop = hitter->chosen_skill; |
1531 | |
1529 | |
1532 | if (!skill && skop) |
1530 | if (!skill && skop) |
1533 | skill = skop->skill; |
1531 | skill = skop->skill; |
1534 | |
|
|
1535 | new_draw_info (NDI_ALL, op->type == PLAYER ? 1 : 10, NULL, buf); |
|
|
1536 | |
1532 | |
1537 | /* If you didn't kill yourself, and your not the wizard */ |
1533 | /* If you didn't kill yourself, and your not the wizard */ |
1538 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1534 | if (owner != op && !QUERY_FLAG (op, FLAG_WIZ)) |
1539 | { |
1535 | { |
1540 | int exp; |
1536 | int exp; |
… | |
… | |
1612 | |
1608 | |
1613 | if (owner1 && owner1->type == PLAYER) |
1609 | if (owner1 && owner1->type == PLAYER) |
1614 | { |
1610 | { |
1615 | owner1->contr->play_sound (sound_find ("pet_is_killed")); |
1611 | owner1->contr->play_sound (sound_find ("pet_is_killed")); |
1616 | /* Maybe we should include the owner that killed this, maybe not */ |
1612 | /* Maybe we should include the owner that killed this, maybe not */ |
1617 | new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, is killed by %s.", &op->name, &hitter->name); |
1613 | new_draw_info_format (NDI_UNIQUE, 0, owner1, "Your pet, the %s, was killed by %s.", &op->name, &hitter->name); |
1618 | } |
1614 | } |
1619 | |
1615 | |
1620 | remove_friendly_object (op); |
1616 | remove_friendly_object (op); |
1621 | } |
1617 | } |
1622 | |
1618 | |
1623 | op->destroy (); |
1619 | op->drop_and_destroy (); |
1624 | } |
1620 | } |
1625 | else |
1621 | else |
1626 | /* Player has been killed! */ |
1622 | /* Player has been killed! */ |
1627 | op->contr->killer = owner->type == PLAYER ? owner : hitter; |
1623 | op->contr->killer = owner->type == PLAYER ? owner : hitter; |
1628 | |
1624 | |
… | |
… | |
1788 | */ |
1784 | */ |
1789 | if (type & AT_HOLYWORD) |
1785 | if (type & AT_HOLYWORD) |
1790 | { |
1786 | { |
1791 | object *god; |
1787 | object *god; |
1792 | |
1788 | |
1793 | if ((!hitter->slaying || |
1789 | if ((!hitter->slaying |
1794 | (!(op->race && strstr (hitter->slaying, op->race)) && |
1790 | || (!(op->race && hitter->slaying.contains (op->race)) |
1795 | !(op->name && strstr (hitter->slaying, op->name)))) && |
1791 | && !(op->name && hitter->slaying.contains (op->name)))) |
1796 | (!QUERY_FLAG (op, FLAG_UNDEAD) || |
1792 | && (!QUERY_FLAG (op, FLAG_UNDEAD) |
1797 | (hitter->title != NULL |
1793 | || (hitter->title |
1798 | && (god = find_god (determine_god (hitter))) != NULL && god->race != NULL && strstr (god->race, shstr_undead) != NULL))) |
1794 | && (god = find_god (determine_god (hitter))) != NULL |
|
|
1795 | && god->race.contains (shstr_undead)))) |
1799 | return 0; |
1796 | return 0; |
1800 | } |
1797 | } |
1801 | |
1798 | |
1802 | maxattacktype = type; /* initialise this to something */ |
1799 | maxattacktype = type; /* initialise this to something */ |
1803 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) |
1800 | for (attacknum = 0; attacknum < NROFATTACKS; attacknum++, attacktype = 1 << attacknum) |
… | |
… | |
1914 | /* See if the creature has been killed */ |
1911 | /* See if the creature has been killed */ |
1915 | rtn_kill = kill_object (op, maxdam, hitter, type); |
1912 | rtn_kill = kill_object (op, maxdam, hitter, type); |
1916 | if (rtn_kill != -1) |
1913 | if (rtn_kill != -1) |
1917 | return rtn_kill; |
1914 | return rtn_kill; |
1918 | |
1915 | |
1919 | |
|
|
1920 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1916 | /* Used to be ghosthit removal - we now use the ONE_HIT flag. Note |
1921 | * that before if the player was immune to ghosthit, the monster |
1917 | * that before if the player was immune to ghosthit, the monster |
1922 | * remained - that is no longer the case. |
1918 | * remained - that is no longer the case. |
1923 | */ |
1919 | */ |
1924 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1920 | if (QUERY_FLAG (hitter, FLAG_ONE_HIT)) |
1925 | hitter->destroy (); |
1921 | hitter->drop_and_destroy (); |
1926 | |
|
|
1927 | /* Lets handle creatures that are splitting now */ |
1922 | /* Lets handle creatures that are splitting now */ |
1928 | else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) |
1923 | else if (type & AT_PHYSICAL && !QUERY_FLAG (op, FLAG_FREED) && QUERY_FLAG (op, FLAG_SPLITTING)) |
1929 | { |
1924 | { |
1930 | int i; |
1925 | int i; |
1931 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
1926 | int friendly = QUERY_FLAG (op, FLAG_FRIENDLY); |
… | |
… | |
1971 | } |
1966 | } |
1972 | |
1967 | |
1973 | op->destroy (); |
1968 | op->destroy (); |
1974 | } |
1969 | } |
1975 | else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) |
1970 | else if (type & AT_DRAIN && hitter->type == GRIMREAPER && hitter->value++ > 10) |
1976 | hitter->destroy (); |
1971 | hitter->drop_and_destroy (); |
1977 | |
1972 | |
1978 | return maxdam; |
1973 | return maxdam; |
1979 | } |
1974 | } |
1980 | |
1975 | |
1981 | void |
1976 | void |
… | |
… | |
2178 | ** field of the deathstriking object */ |
2173 | ** field of the deathstriking object */ |
2179 | |
2174 | |
2180 | int atk_lev, def_lev, kill_lev; |
2175 | int atk_lev, def_lev, kill_lev; |
2181 | |
2176 | |
2182 | if (hitter->slaying) |
2177 | if (hitter->slaying) |
2183 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && strstr (hitter->slaying, shstr_undead)) || (op->race && strstr (hitter->slaying, op->race)))) |
2178 | if (!((QUERY_FLAG (op, FLAG_UNDEAD) && hitter->slaying.contains (shstr_undead)) |
|
|
2179 | || (op->race && hitter->slaying.contains (op->race)))) |
2184 | return; |
2180 | return; |
2185 | |
2181 | |
2186 | def_lev = op->level; |
2182 | def_lev = op->level; |
2187 | if (def_lev < 1) |
2183 | if (def_lev < 1) |
2188 | { |
2184 | { |
2189 | LOG (llevError, "BUG: arch %s, name %s with level < 1\n", &op->arch->archname, &op->name); |
2185 | LOG (llevError, "BUG: arch %s with level < 1 (%s)\n", &op->arch->archname, op->debug_desc ()); |
2190 | def_lev = 1; |
2186 | def_lev = 1; |
2191 | } |
2187 | } |
2192 | |
2188 | |
2193 | atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; |
2189 | atk_lev = (hitter->chosen_skill ? hitter->chosen_skill->level : hitter->level) / 2; |
2194 | /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", |
2190 | /* LOG(llevDebug,"Deathstrike - attack level %d, defender level %d\n", |
… | |
… | |
2287 | { |
2283 | { |
2288 | /* target is unseen */ |
2284 | /* target is unseen */ |
2289 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
2285 | if (target->invisible || QUERY_FLAG (attacker, FLAG_BLIND)) |
2290 | adjust -= 10; |
2286 | adjust -= 10; |
2291 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
2287 | /* dark map penalty for the hitter (lacks infravision if we got here). */ |
2292 | else if (target->map && target->map->darkness > 0 && !stand_in_light (target)) |
2288 | else if (!stand_in_light (target)) |
2293 | adjust -= target->map->darkness; |
2289 | adjust -= target->map->darklevel (); |
2294 | } |
2290 | } |
2295 | |
2291 | |
2296 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
2292 | if (QUERY_FLAG (attacker, FLAG_SCARED)) |
2297 | adjust -= 3; |
2293 | adjust -= 3; |
2298 | |
2294 | |