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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * 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 |
10 | * 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 |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * 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 |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
26 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
26 | * It is useful for finding bugs in the treasures file. Since it only |
27 | * It is useful for finding bugs in the treasures file. Since it only |
… | |
… | |
34 | //#define TREASURE_VERBOSE |
35 | //#define TREASURE_VERBOSE |
35 | |
36 | |
36 | #include <global.h> |
37 | #include <global.h> |
37 | #include <treasure.h> |
38 | #include <treasure.h> |
38 | |
39 | |
|
|
40 | #include <flat_hash_map.hpp> |
|
|
41 | |
|
|
42 | // used only by treasure.C, does not handle null arch ptrs |
|
|
43 | #define IS_ARCH(arch,name) ((arch)->archname == shstr_ ## name) |
|
|
44 | |
39 | extern char *spell_mapping[]; |
45 | extern char *spell_mapping[]; |
40 | |
46 | |
41 | static treasurelist *first_treasurelist; |
47 | static treasurelist *first_treasurelist; |
42 | |
48 | |
43 | static void change_treasure (treasure *t, object *op); /* overrule default values */ |
49 | static void change_treasure (treasure *t, object *op); /* overrule default values */ |
44 | |
50 | |
45 | typedef std::tr1::unordered_map< |
51 | typedef ska::flat_hash_map |
|
|
52 | < |
46 | const char *, |
53 | const char *, |
47 | treasurelist *, |
54 | treasurelist *, |
48 | str_hash, |
55 | str_hash, |
49 | str_equal, |
56 | str_equal, |
50 | slice_allocator< std::pair<const char *const, treasurelist *> > |
57 | slice_allocator< std::pair<const char *const, treasurelist *> > |
51 | > tl_map_t; |
58 | > tl_map_t; |
52 | |
59 | |
53 | static tl_map_t tl_map; |
60 | static tl_map_t tl_map; |
54 | |
61 | |
55 | //TODO: class method |
62 | //TODO: class method |
56 | static void free_treasurestruct (treasure *t); // bleh desu |
63 | static void free_treasurestruct (treasure *t); // bleh desu |
… | |
… | |
255 | return; |
262 | return; |
256 | } |
263 | } |
257 | |
264 | |
258 | op->expand_tail (); |
265 | op->expand_tail (); |
259 | |
266 | |
|
|
267 | if (!creator->is_on_map () |
260 | if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) |
268 | || (op->weight && op->blocked (creator->map, creator->x, creator->y))) |
261 | op->destroy (); |
269 | op->destroy (); |
262 | else |
270 | else |
263 | { |
271 | { |
264 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
272 | op->flag [FLAG_OBJ_ORIGINAL] = true; |
265 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
273 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
266 | } |
274 | } |
267 | } |
275 | } |
268 | else |
276 | else |
269 | { |
277 | { |
270 | op = creator->insert (op); |
278 | op = creator->insert (op); |
271 | |
279 | |
272 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
280 | if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER]) |
273 | monster_check_apply (creator, op); |
281 | monster_check_apply (creator, op); |
274 | } |
282 | } |
275 | } |
283 | } |
276 | |
284 | |
277 | /* if there are change_xxx commands in the treasure, we include the changes |
285 | /* if there are change_xxx commands in the treasure, we include the changes |
… | |
… | |
489 | { 0, 0, 0, 3, 97}, // 29 |
497 | { 0, 0, 0, 3, 97}, // 29 |
490 | { 0, 0, 0, 0, 100}, // 30 |
498 | { 0, 0, 0, 0, 100}, // 30 |
491 | { 0, 0, 0, 0, 100}, // 31 |
499 | { 0, 0, 0, 0, 100}, // 31 |
492 | }; |
500 | }; |
493 | |
501 | |
494 | /* calculate the appropriate level for wands staves and scrolls. |
502 | /* calculate the appropriate level for wands staves and scrolls. |
495 | * This code presumes that op has had its spell object created (in op->inv) |
503 | * This code presumes that op has had its spell object created (in op->inv) |
496 | * |
504 | * |
497 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
505 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
498 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
506 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
499 | */ |
507 | */ |
… | |
… | |
509 | int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); |
517 | int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); |
510 | |
518 | |
511 | if (olevel <= 0) |
519 | if (olevel <= 0) |
512 | olevel = rndm (1, op->inv->level); |
520 | olevel = rndm (1, op->inv->level); |
513 | |
521 | |
514 | return min (olevel, MAXLEVEL); |
522 | return min (olevel, MAXLEVEL_TREASURE); |
515 | } |
523 | } |
516 | |
524 | |
517 | /* |
525 | /* |
518 | * Based upon the specified difficulty and upon the difftomagic_list array, |
526 | * Based upon the specified difficulty and upon the difftomagic_list array, |
519 | * a random magical bonus is returned. This is used when determine |
527 | * a random magical bonus is returned. This is used when determine |
… | |
… | |
525 | * |
533 | * |
526 | */ |
534 | */ |
527 | static int |
535 | static int |
528 | magic_from_difficulty (int difficulty) |
536 | magic_from_difficulty (int difficulty) |
529 | { |
537 | { |
530 | int percent = 0, magic = 0; |
|
|
531 | int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); |
538 | int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1); |
|
|
539 | scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1); |
532 | |
540 | |
533 | scaled_diff--; |
|
|
534 | |
|
|
535 | if (scaled_diff < 0) |
|
|
536 | scaled_diff = 0; |
|
|
537 | |
|
|
538 | if (scaled_diff >= DIFFLEVELS) |
|
|
539 | scaled_diff = DIFFLEVELS - 1; |
|
|
540 | |
|
|
541 | percent = rndm (100); |
541 | int percent = rndm (100); |
|
|
542 | int magic; |
542 | |
543 | |
543 | for (magic = 0; magic < (MAXMAGIC + 1); magic++) |
544 | for (magic = 0; magic <= MAXMAGIC; magic++) |
544 | { |
545 | { |
545 | percent -= difftomagic_list[scaled_diff][magic]; |
546 | percent -= difftomagic_list[scaled_diff][magic]; |
546 | |
547 | |
547 | if (percent < 0) |
548 | if (percent < 0) |
548 | break; |
549 | break; |
549 | } |
550 | } |
550 | |
551 | |
551 | if (magic == (MAXMAGIC + 1)) |
552 | if (magic > MAXMAGIC) |
552 | { |
553 | { |
553 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
554 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
554 | magic = 0; |
555 | magic = 0; |
555 | } |
556 | } |
556 | |
557 | |
… | |
… | |
564 | * Sets magical bonus in an object, and recalculates the effect on |
565 | * Sets magical bonus in an object, and recalculates the effect on |
565 | * the armour variable, and the effect on speed of armour. |
566 | * the armour variable, and the effect on speed of armour. |
566 | * This function doesn't work properly, should add use of archetypes |
567 | * This function doesn't work properly, should add use of archetypes |
567 | * to make it truly absolute. |
568 | * to make it truly absolute. |
568 | */ |
569 | */ |
569 | |
|
|
570 | void |
570 | void |
571 | set_abs_magic (object *op, int magic) |
571 | set_abs_magic (object *op, int magic) |
572 | { |
572 | { |
573 | if (!magic) |
573 | if (!magic) |
574 | return; |
574 | return; |
… | |
… | |
602 | */ |
602 | */ |
603 | |
603 | |
604 | static void |
604 | static void |
605 | set_magic (int difficulty, object *op, int max_magic, int flags) |
605 | set_magic (int difficulty, object *op, int max_magic, int flags) |
606 | { |
606 | { |
607 | int i; |
|
|
608 | |
|
|
609 | i = magic_from_difficulty (difficulty); |
607 | int i = magic_from_difficulty (difficulty); |
|
|
608 | |
610 | if ((flags & GT_ONLY_GOOD) && i < 0) |
609 | if ((flags & GT_ONLY_GOOD) && i < 0) |
611 | i = -i; |
610 | i = -i; |
|
|
611 | |
612 | if (i > max_magic) |
612 | i = min (i, max_magic); |
613 | i = max_magic; |
613 | |
614 | set_abs_magic (op, i); |
614 | set_abs_magic (op, i); |
615 | if (i < 0) |
615 | if (i < 0) |
616 | SET_FLAG (op, FLAG_CURSED); |
616 | op->set_flag (FLAG_CURSED); |
617 | } |
617 | } |
618 | |
618 | |
619 | /* |
619 | /* |
620 | * Randomly adds one magical ability to the given object. |
620 | * Randomly adds one magical ability to the given object. |
621 | * Modified for Partial Resistance in many ways: |
621 | * Modified for Partial Resistance in many ways: |
… | |
… | |
628 | set_ring_bonus (object *op, int bonus) |
628 | set_ring_bonus (object *op, int bonus) |
629 | { |
629 | { |
630 | int r = rndm (bonus > 0 ? 25 : 11); |
630 | int r = rndm (bonus > 0 ? 25 : 11); |
631 | |
631 | |
632 | if (op->type == AMULET) |
632 | if (op->type == AMULET) |
633 | { |
|
|
634 | if (!(rndm (21))) |
633 | if (!rndm (21)) |
635 | r = 20 + rndm (2); |
634 | r = 20 + rndm (2); |
|
|
635 | else if (rndm (2)) |
|
|
636 | r = 10; |
636 | else |
637 | else |
637 | { |
|
|
638 | if (rndm (2)) |
|
|
639 | r = 10; |
|
|
640 | else |
|
|
641 | r = 11 + rndm (9); |
638 | r = 11 + rndm (9); |
642 | } |
|
|
643 | } |
|
|
644 | |
639 | |
645 | switch (r) |
640 | switch (r) |
646 | { |
641 | { |
647 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
642 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
648 | * bonuses and penalties will stack and add to existing values. |
643 | * bonuses and penalties will stack and add to existing values. |
649 | * of the item. |
644 | * of the item. |
650 | */ |
645 | */ |
651 | case 0: |
646 | case 0: |
652 | case 1: |
647 | case 1: |
653 | case 2: |
648 | case 2: |
654 | case 3: |
649 | case 3: |
655 | case 4: |
650 | case 4: |
… | |
… | |
695 | * little random element in since that they don't always end up with |
690 | * little random element in since that they don't always end up with |
696 | * even values. |
691 | * even values. |
697 | */ |
692 | */ |
698 | if (bonus < 0) |
693 | if (bonus < 0) |
699 | val = 2 * -val - rndm (b); |
694 | val = 2 * -val - rndm (b); |
700 | if (val > 35) |
695 | |
701 | val = 35; /* Upper limit */ |
696 | val = min (35, val); /* Upper limit */ |
|
|
697 | |
702 | b = 0; |
698 | b = 0; |
703 | |
699 | |
704 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
700 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
705 | resist = rndm (num_resist_table); |
701 | resist = rndm (num_resist_table); |
706 | |
702 | |
… | |
… | |
714 | break; |
710 | break; |
715 | } |
711 | } |
716 | case 20: |
712 | case 20: |
717 | if (op->type == AMULET) |
713 | if (op->type == AMULET) |
718 | { |
714 | { |
719 | SET_FLAG (op, FLAG_REFL_SPELL); |
715 | op->set_flag (FLAG_REFL_SPELL); |
720 | op->value *= 11; |
716 | op->value *= 11; |
721 | } |
717 | } |
722 | else |
718 | else |
723 | { |
719 | { |
724 | op->stats.hp = 1; /* regenerate hit points */ |
720 | op->stats.hp = 1; /* regenerate hit points */ |
… | |
… | |
727 | break; |
723 | break; |
728 | |
724 | |
729 | case 21: |
725 | case 21: |
730 | if (op->type == AMULET) |
726 | if (op->type == AMULET) |
731 | { |
727 | { |
732 | SET_FLAG (op, FLAG_REFL_MISSILE); |
728 | op->set_flag (FLAG_REFL_MISSILE); |
733 | op->value *= 9; |
729 | op->value *= 9; |
734 | } |
730 | } |
735 | else |
731 | else |
736 | { |
732 | { |
737 | op->stats.sp = 1; /* regenerate spell points */ |
733 | op->stats.sp = 1; /* regenerate spell points */ |
… | |
… | |
739 | } |
735 | } |
740 | break; |
736 | break; |
741 | |
737 | |
742 | case 22: |
738 | case 22: |
743 | op->stats.exp += bonus; /* Speed! */ |
739 | op->stats.exp += bonus; /* Speed! */ |
744 | op->value = (op->value * 2) / 3; |
740 | op->value = op->value * 2 / 3; |
745 | break; |
741 | break; |
746 | } |
742 | } |
747 | |
743 | |
748 | if (bonus > 0) |
744 | if (bonus > 0) |
749 | op->value *= 2 * bonus; |
745 | op->value = 2 * op->value * bonus; |
750 | else |
746 | else |
751 | op->value = -(op->value * 2 * bonus) / 3; |
747 | op->value = -2 * op->value * bonus / 3; |
752 | } |
748 | } |
753 | |
749 | |
754 | /* |
750 | /* |
755 | * get_magic(diff) will return a random number between 0 and 4. |
751 | * get_magic(diff) will return a random number between 0 and 4. |
756 | * diff can be any value above 2. The higher the diff-variable, the |
752 | * diff can be any value above 2. The higher the diff-variable, the |
… | |
… | |
760 | * Another scheme is used to calculate the magic of weapons and armours. |
756 | * Another scheme is used to calculate the magic of weapons and armours. |
761 | */ |
757 | */ |
762 | static int |
758 | static int |
763 | get_magic (int diff) |
759 | get_magic (int diff) |
764 | { |
760 | { |
765 | int i; |
761 | diff = min (3, diff); |
766 | |
762 | |
767 | if (diff < 3) |
|
|
768 | diff = 3; |
|
|
769 | |
|
|
770 | for (i = 0; i < 4; i++) |
763 | for (int i = 0; i < 4; i++) |
771 | if (rndm (diff)) |
764 | if (rndm (diff)) |
772 | return i; |
765 | return i; |
773 | |
766 | |
774 | return 4; |
767 | return 4; |
775 | } |
768 | } |
… | |
… | |
789 | return 1; |
782 | return 1; |
790 | |
783 | |
791 | return 0; |
784 | return 0; |
792 | } |
785 | } |
793 | |
786 | |
|
|
787 | static double |
|
|
788 | value_factor_from_spell_item (object *spell, object *item) |
|
|
789 | { |
|
|
790 | double factor = |
|
|
791 | pow ((spell->value > 0 ? spell->value : 1) |
|
|
792 | * spell->level, 1.5); |
|
|
793 | |
|
|
794 | if (item) // this if for: wands/staffs/rods: |
|
|
795 | { |
|
|
796 | /* Old crossfire comment ahead: |
|
|
797 | * Add 50 to both level an divisor to keep prices a little more |
|
|
798 | * reasonable. Otherwise, a high level version of a low level |
|
|
799 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
|
|
800 | * 10 time multiplier). This way, the value are a bit more reasonable. |
|
|
801 | */ |
|
|
802 | |
|
|
803 | factor *= item->level + 50; |
|
|
804 | factor /= item->inv->level + 50; |
|
|
805 | } |
|
|
806 | |
|
|
807 | return factor; |
|
|
808 | } |
|
|
809 | |
794 | #define DICE2 (get_magic(2)==2?2:1) |
810 | #define DICE2 (get_magic(2) == 2 ? 2 : 1) |
795 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
811 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
796 | |
812 | |
797 | /* |
813 | /* |
798 | * fix_generated_item(): This is called after an item is generated, in |
814 | * fix_generated_item(): This is called after an item is generated, in |
799 | * order to set it up right. This produced magical bonuses, puts spells |
815 | * order to set it up right. This produced magical bonuses, puts spells |
800 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
816 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
801 | */ |
817 | */ |
802 | |
818 | |
803 | /* 4/28/96 added creator object from which op may now inherit properties based on |
819 | /* 4/28/96 added creator object from which op may now inherit properties based on |
804 | * op->type. Right now, which stuff the creator passes on is object type |
820 | * op->type. Right now, which stuff the creator passes on is object type |
805 | * dependant. I know this is a spagetti manuever, but is there a cleaner |
821 | * dependant. I know this is a spagetti manuever, but is there a cleaner |
806 | * way to do this? b.t. */ |
822 | * way to do this? b.t. */ |
807 | |
823 | |
808 | /* |
824 | /* |
809 | * ! (flags & GT_ENVIRONMENT): |
825 | * ! (flags & GT_ENVIRONMENT): |
810 | * Automatically calls fix_flesh_item(). |
826 | * Automatically calls fix_flesh_item(). |
… | |
… | |
910 | { |
926 | { |
911 | if (op->type == POTION) |
927 | if (op->type == POTION) |
912 | /* Handle healing and magic power potions */ |
928 | /* Handle healing and magic power potions */ |
913 | if (op->stats.sp && !op->randomitems) |
929 | if (op->stats.sp && !op->randomitems) |
914 | { |
930 | { |
915 | object *tmp = get_archetype (spell_mapping [op->stats.sp]); |
931 | object *tmp = archetype::get (spell_mapping [op->stats.sp]); |
916 | insert_ob_in_ob (tmp, op); |
932 | insert_ob_in_ob (tmp, op); |
917 | op->stats.sp = 0; |
933 | op->stats.sp = 0; |
918 | } |
934 | } |
919 | } |
935 | } |
920 | else if (!op->title) /* Only modify object if not special */ |
936 | else if (!op->title) /* Only modify object if not special */ |
… | |
… | |
923 | case WEAPON: |
939 | case WEAPON: |
924 | case ARMOUR: |
940 | case ARMOUR: |
925 | case SHIELD: |
941 | case SHIELD: |
926 | case HELMET: |
942 | case HELMET: |
927 | case CLOAK: |
943 | case CLOAK: |
928 | if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) |
944 | if (op->flag [FLAG_CURSED] && !(rndm (4))) |
929 | set_ring_bonus (op, -DICE2); |
945 | set_ring_bonus (op, -DICE2); |
930 | break; |
946 | break; |
931 | |
947 | |
932 | case BRACERS: |
948 | case BRACERS: |
933 | if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) |
949 | if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20)) |
934 | { |
950 | { |
935 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
951 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
936 | if (!QUERY_FLAG (op, FLAG_CURSED)) |
952 | if (!op->flag [FLAG_CURSED]) |
937 | op->value *= 3; |
953 | op->value *= 3; |
938 | } |
954 | } |
939 | break; |
955 | break; |
940 | |
956 | |
941 | case POTION: |
957 | case POTION: |
942 | { |
958 | { |
943 | int too_many_tries = 0, is_special = 0; |
959 | int too_many_tries = 0; |
944 | |
960 | |
945 | /* Handle healing and magic power potions */ |
961 | /* Handle healing and magic power potions */ |
946 | if (op->stats.sp && !op->randomitems) |
962 | if (op->stats.sp && !op->randomitems) |
947 | { |
963 | { |
948 | object *tmp = get_archetype (spell_mapping[op->stats.sp]); |
964 | object *tmp = archetype::get (spell_mapping[op->stats.sp]); |
949 | insert_ob_in_ob (tmp, op); |
965 | insert_ob_in_ob (tmp, op); |
950 | op->stats.sp = 0; |
966 | op->stats.sp = 0; |
951 | } |
967 | } |
952 | |
968 | |
953 | while (!(is_special = special_potion (op)) && !op->inv) |
969 | while (!special_potion (op) && !op->inv) |
954 | { |
970 | { |
955 | generate_artifact (op, difficulty); |
971 | generate_artifact (op, difficulty); |
956 | if (too_many_tries++ > 10) |
972 | if (too_many_tries++ > 10) |
957 | break; |
973 | break; |
958 | } |
974 | } |
… | |
… | |
966 | op->value *= op->inv->value; |
982 | op->value *= op->inv->value; |
967 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
983 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
968 | } |
984 | } |
969 | else |
985 | else |
970 | { |
986 | { |
971 | op->name = "potion"; |
987 | op->name = shstr_potion; |
972 | op->name_pl = "potions"; |
988 | op->name_pl = shstr_potions; |
973 | } |
989 | } |
974 | |
990 | |
975 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
991 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
976 | SET_FLAG (op, FLAG_CURSED); |
992 | op->set_flag (FLAG_CURSED); |
977 | |
993 | |
978 | break; |
994 | break; |
979 | } |
995 | } |
980 | |
996 | |
981 | case AMULET: |
997 | case AMULET: |
… | |
… | |
985 | case RING: |
1001 | case RING: |
986 | if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ |
1002 | if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ |
987 | break; |
1003 | break; |
988 | |
1004 | |
989 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
1005 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
990 | SET_FLAG (op, FLAG_CURSED); |
1006 | op->set_flag (FLAG_CURSED); |
991 | |
1007 | |
992 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
1008 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
993 | |
1009 | |
994 | if (op->type != RING) /* Amulets have only one ability */ |
1010 | if (op->type != RING) /* Amulets have only one ability */ |
995 | break; |
1011 | break; |
996 | |
1012 | |
997 | if (!(rndm (4))) |
1013 | if (!rndm (4)) |
998 | { |
1014 | { |
999 | int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1015 | int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
1000 | |
1016 | |
1001 | if (d > 0) |
1017 | if (d > 0) |
1002 | op->value *= 3; |
1018 | op->value *= 3; |
1003 | |
1019 | |
1004 | set_ring_bonus (op, d); |
1020 | set_ring_bonus (op, d); |
1005 | |
1021 | |
1006 | if (!(rndm (4))) |
1022 | if (!rndm (4)) |
1007 | { |
1023 | { |
1008 | int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1024 | int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
1009 | |
1025 | |
1010 | if (d > 0) |
1026 | if (d > 0) |
1011 | op->value *= 5; |
1027 | op->value *= 5; |
|
|
1028 | |
1012 | set_ring_bonus (op, d); |
1029 | set_ring_bonus (op, d); |
1013 | } |
1030 | } |
1014 | } |
1031 | } |
1015 | |
1032 | |
1016 | if (op->animation_id) |
1033 | if (op->animation_id) |
… | |
… | |
1024 | * creator and/or map level we found it on. |
1041 | * creator and/or map level we found it on. |
1025 | */ |
1042 | */ |
1026 | if (!op->msg && rndm (10)) |
1043 | if (!op->msg && rndm (10)) |
1027 | { |
1044 | { |
1028 | /* set the book level properly */ |
1045 | /* set the book level properly */ |
1029 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
1046 | if (creator->level == 0 || creator->flag [FLAG_ALIVE]) |
1030 | { |
1047 | { |
1031 | if (op->map && op->map->difficulty) |
1048 | if (op->map && op->map->difficulty) |
1032 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1049 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1033 | else |
1050 | else |
1034 | op->level = rndm (20) + 1; |
1051 | op->level = rndm (20) + 1; |
… | |
… | |
1047 | /* creator related stuff */ |
1064 | /* creator related stuff */ |
1048 | |
1065 | |
1049 | /* for library, chained books. Note that some monsters have no_pick |
1066 | /* for library, chained books. Note that some monsters have no_pick |
1050 | * set - we don't want to set no pick in that case. |
1067 | * set - we don't want to set no pick in that case. |
1051 | */ |
1068 | */ |
1052 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) |
1069 | if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER]) |
1053 | SET_FLAG (op, FLAG_NO_PICK); |
1070 | op->set_flag (FLAG_NO_PICK); |
1054 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1071 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1055 | op->slaying = creator->slaying; |
1072 | op->slaying = creator->slaying; |
1056 | break; |
1073 | break; |
1057 | |
1074 | |
1058 | case SPELLBOOK: |
1075 | case SPELLBOOK: |
1059 | op->value = op->value * op->inv->value; |
1076 | op->value *= value_factor_from_spell_item (op->inv, 0); |
|
|
1077 | |
1060 | /* add exp so learning gives xp */ |
1078 | /* add exp so learning gives xp */ |
1061 | op->level = op->inv->level; |
1079 | op->level = op->inv->level; |
1062 | op->stats.exp = op->value; |
1080 | op->stats.exp = op->value; |
1063 | break; |
1081 | break; |
1064 | |
1082 | |
… | |
… | |
1068 | * and reset nrof. |
1086 | * and reset nrof. |
1069 | */ |
1087 | */ |
1070 | op->stats.food = op->inv->nrof; |
1088 | op->stats.food = op->inv->nrof; |
1071 | op->nrof = 1; |
1089 | op->nrof = 1; |
1072 | /* If the spell changes by level, choose a random level |
1090 | /* If the spell changes by level, choose a random level |
1073 | * for it, and adjust price. If the spell doesn't |
1091 | * for it. |
1074 | * change by level, just set the wand to the level of |
|
|
1075 | * the spell, and value calculation is simpler. |
|
|
1076 | */ |
1092 | */ |
1077 | if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) |
1093 | if (op->inv->duration_modifier |
1078 | { |
1094 | || op->inv->dam_modifier |
|
|
1095 | || op->inv->range_modifier) |
1079 | op->level = level_for_item (op, difficulty); |
1096 | op->level = level_for_item (op, difficulty); |
1080 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
|
|
1081 | } |
|
|
1082 | else |
1097 | else |
1083 | { |
|
|
1084 | op->level = op->inv->level; |
1098 | op->level = op->inv->level; |
1085 | op->value = op->value * op->inv->value; |
1099 | |
1086 | } |
1100 | op->value *= value_factor_from_spell_item (op->inv, op); |
1087 | break; |
1101 | break; |
1088 | |
1102 | |
1089 | case ROD: |
1103 | case ROD: |
1090 | op->level = level_for_item (op, difficulty); |
1104 | op->level = level_for_item (op, difficulty); |
1091 | /* Add 50 to both level an divisor to keep prices a little more |
1105 | op->value *= value_factor_from_spell_item (op->inv, op); |
1092 | * reasonable. Otherwise, a high level version of a low level |
1106 | |
1093 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
|
|
1094 | * 10 time multiplier). This way, the value are a bit more reasonable. |
|
|
1095 | */ |
|
|
1096 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
|
|
1097 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1107 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1098 | if (op->stats.maxhp) |
1108 | if (op->stats.maxhp) |
1099 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1109 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1100 | else |
1110 | else |
1101 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
1111 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
… | |
… | |
1103 | op->stats.hp = op->stats.maxhp; |
1113 | op->stats.hp = op->stats.maxhp; |
1104 | break; |
1114 | break; |
1105 | |
1115 | |
1106 | case SCROLL: |
1116 | case SCROLL: |
1107 | op->level = level_for_item (op, difficulty); |
1117 | op->level = level_for_item (op, difficulty); |
1108 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1118 | op->value *= value_factor_from_spell_item (op->inv, op); |
1109 | |
1119 | |
1110 | /* add exp so reading them properly gives xp */ |
1120 | /* add exp so reading them properly gives xp */ |
1111 | op->stats.exp = op->value / 5; |
1121 | op->stats.exp = op->value / 5; |
1112 | op->nrof = op->inv->nrof; |
1122 | op->nrof = op->inv->nrof; |
1113 | break; |
1123 | break; |
… | |
… | |
1121 | break; |
1131 | break; |
1122 | } /* switch type */ |
1132 | } /* switch type */ |
1123 | |
1133 | |
1124 | if (flags & GT_STARTEQUIP) |
1134 | if (flags & GT_STARTEQUIP) |
1125 | { |
1135 | { |
1126 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) |
1136 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN]) |
1127 | SET_FLAG (op, FLAG_STARTEQUIP); |
1137 | op->set_flag (FLAG_STARTEQUIP); |
1128 | else if (op->type != MONEY) |
1138 | else if (op->type != MONEY) |
1129 | op->value = 0; |
1139 | op->value = 0; |
1130 | } |
1140 | } |
1131 | |
1141 | |
1132 | if (!(flags & GT_ENVIRONMENT)) |
1142 | if (!(flags & GT_ENVIRONMENT)) |
… | |
… | |
1178 | */ |
1188 | */ |
1179 | void |
1189 | void |
1180 | init_artifacts () |
1190 | init_artifacts () |
1181 | { |
1191 | { |
1182 | static int has_been_inited = 0; |
1192 | static int has_been_inited = 0; |
1183 | char filename[MAX_BUF]; |
|
|
1184 | artifact *art = NULL; |
1193 | artifact *art = NULL; |
1185 | artifactlist *al; |
1194 | artifactlist *al; |
1186 | |
1195 | |
1187 | if (has_been_inited) |
1196 | if (has_been_inited) |
1188 | return; |
1197 | return; |
1189 | else |
1198 | else |
1190 | has_been_inited = 1; |
1199 | has_been_inited = 1; |
1191 | |
1200 | |
1192 | sprintf (filename, "%s/artifacts", settings.datadir); |
1201 | object_thawer f (settings.datadir, "artifacts"); |
1193 | object_thawer f (filename); |
|
|
1194 | |
1202 | |
1195 | if (!f) |
1203 | if (!f) |
1196 | return; |
1204 | return; |
1197 | |
1205 | |
1198 | for (;;) |
1206 | for (;;) |
… | |
… | |
1283 | } |
1291 | } |
1284 | #if 0 |
1292 | #if 0 |
1285 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1293 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1286 | #endif |
1294 | #endif |
1287 | } |
1295 | } |
1288 | |
|
|
1289 | LOG (llevDebug, "done.\n"); |
|
|
1290 | } |
1296 | } |
1291 | |
1297 | |
1292 | /* |
1298 | /* |
1293 | * Used in artifact generation. The bonuses of the first object |
1299 | * Used in artifact generation. The bonuses of the first object |
1294 | * is modified by the bonuses of the second object. |
1300 | * is modified by the bonuses of the second object. |
1295 | */ |
1301 | */ |
1296 | void |
1302 | void |
1297 | add_abilities (object *op, object *change) |
1303 | add_abilities (object *op, object *change) |
1298 | { |
1304 | { |
1299 | int i, tmp; |
|
|
1300 | |
|
|
1301 | if (change->face != blank_face) |
1305 | if (change->face != blank_face) |
1302 | { |
|
|
1303 | #ifdef TREASURE_VERBOSE |
|
|
1304 | LOG (llevDebug, "add_abilities change face: %d\n", change->face); |
|
|
1305 | #endif |
|
|
1306 | op->face = change->face; |
1306 | op->face = change->face; |
1307 | } |
|
|
1308 | |
1307 | |
1309 | for (i = 0; i < NUM_STATS; i++) |
1308 | for (int i = 0; i < NUM_STATS; i++) |
1310 | change_attr_value (&(op->stats), i, change->stats.stat (i)); |
1309 | change_attr_value (&(op->stats), i, change->stats.stat (i)); |
1311 | |
1310 | |
1312 | op->attacktype |= change->attacktype; |
1311 | op->attacktype |= change->attacktype; |
1313 | op->path_attuned |= change->path_attuned; |
1312 | op->path_attuned |= change->path_attuned; |
1314 | op->path_repelled |= change->path_repelled; |
1313 | op->path_repelled |= change->path_repelled; |
1315 | op->path_denied |= change->path_denied; |
1314 | op->path_denied |= change->path_denied; |
1316 | op->move_type |= change->move_type; |
1315 | op->move_type |= change->move_type; |
1317 | op->stats.luck += change->stats.luck; |
1316 | op->stats.luck += change->stats.luck; |
1318 | |
1317 | |
1319 | if (QUERY_FLAG (change, FLAG_CURSED)) |
1318 | static const struct copyflags : object::flags_t |
1320 | SET_FLAG (op, FLAG_CURSED); |
1319 | { |
1321 | if (QUERY_FLAG (change, FLAG_DAMNED)) |
1320 | copyflags () |
1322 | SET_FLAG (op, FLAG_DAMNED); |
1321 | { |
1323 | if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) |
1322 | set (FLAG_CURSED); |
|
|
1323 | set (FLAG_DAMNED); |
|
|
1324 | set (FLAG_LIFESAVE); |
|
|
1325 | set (FLAG_REFL_SPELL); |
|
|
1326 | set (FLAG_STEALTH); |
|
|
1327 | set (FLAG_XRAYS); |
|
|
1328 | set (FLAG_BLIND); |
|
|
1329 | set (FLAG_SEE_IN_DARK); |
|
|
1330 | set (FLAG_REFL_MISSILE); |
|
|
1331 | set (FLAG_MAKE_INVIS); |
|
|
1332 | } |
|
|
1333 | } copyflags; |
|
|
1334 | |
|
|
1335 | // we might want to just copy, but or'ing is what the original code did |
|
|
1336 | op->flag |= change->flag & copyflags; |
|
|
1337 | |
|
|
1338 | if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0) |
1324 | set_abs_magic (op, -op->magic); |
1339 | set_abs_magic (op, -op->magic); |
1325 | |
1340 | |
1326 | if (QUERY_FLAG (change, FLAG_LIFESAVE)) |
1341 | if (change->flag [FLAG_STAND_STILL]) |
1327 | SET_FLAG (op, FLAG_LIFESAVE); |
|
|
1328 | if (QUERY_FLAG (change, FLAG_REFL_SPELL)) |
|
|
1329 | SET_FLAG (op, FLAG_REFL_SPELL); |
|
|
1330 | if (QUERY_FLAG (change, FLAG_STEALTH)) |
|
|
1331 | SET_FLAG (op, FLAG_STEALTH); |
|
|
1332 | if (QUERY_FLAG (change, FLAG_XRAYS)) |
|
|
1333 | SET_FLAG (op, FLAG_XRAYS); |
|
|
1334 | if (QUERY_FLAG (change, FLAG_BLIND)) |
|
|
1335 | SET_FLAG (op, FLAG_BLIND); |
|
|
1336 | if (QUERY_FLAG (change, FLAG_SEE_IN_DARK)) |
|
|
1337 | SET_FLAG (op, FLAG_SEE_IN_DARK); |
|
|
1338 | if (QUERY_FLAG (change, FLAG_REFL_MISSILE)) |
|
|
1339 | SET_FLAG (op, FLAG_REFL_MISSILE); |
|
|
1340 | if (QUERY_FLAG (change, FLAG_MAKE_INVIS)) |
|
|
1341 | SET_FLAG (op, FLAG_MAKE_INVIS); |
|
|
1342 | |
|
|
1343 | if (QUERY_FLAG (change, FLAG_STAND_STILL)) |
|
|
1344 | { |
1342 | { |
1345 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1343 | op->clr_flag (FLAG_ANIMATE); |
|
|
1344 | |
1346 | /* so artifacts will join */ |
1345 | /* so artifacts will join */ |
1347 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1346 | if (!op->flag [FLAG_ALIVE]) |
1348 | op->speed = 0.0; |
1347 | op->speed = 0.; |
1349 | |
1348 | |
1350 | op->set_speed (op->speed); |
1349 | op->set_speed (op->speed); |
1351 | } |
1350 | } |
1352 | |
1351 | |
1353 | if (change->nrof) |
1352 | if (change->nrof) |
1354 | op->nrof = rndm (change->nrof) + 1; |
1353 | op->nrof = rndm (change->nrof) + 1; |
1355 | |
1354 | |
1356 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1355 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1357 | op->stats.wc += change->stats.wc; |
1356 | op->stats.wc += change->stats.wc; |
1358 | op->stats.ac += change->stats.ac; |
1357 | op->stats.ac += change->stats.ac; |
1359 | |
1358 | |
1360 | if (change->other_arch) |
1359 | if (change->other_arch) |
1361 | { |
1360 | { |
1362 | /* Basically, for horns & potions, the other_arch field is the spell |
1361 | /* Basically, for horns & potions, the other_arch field is the spell |
1363 | * to cast. So convert that to into a spell and put it into |
1362 | * to cast. So convert that to into a spell and put it into |
… | |
… | |
1369 | op->destroy_inv (false); |
1368 | op->destroy_inv (false); |
1370 | |
1369 | |
1371 | object *tmp = change->other_arch->instance (); |
1370 | object *tmp = change->other_arch->instance (); |
1372 | insert_ob_in_ob (tmp, op); |
1371 | insert_ob_in_ob (tmp, op); |
1373 | } |
1372 | } |
|
|
1373 | |
1374 | /* No harm setting this for potions/horns */ |
1374 | /* No harm setting this for potions/horns */ |
1375 | op->other_arch = change->other_arch; |
1375 | op->other_arch = change->other_arch; |
1376 | } |
1376 | } |
1377 | |
1377 | |
1378 | if (change->stats.hp < 0) |
1378 | if (change->stats.hp < 0) |
… | |
… | |
1394 | op->stats.maxsp = -change->stats.maxsp; |
1394 | op->stats.maxsp = -change->stats.maxsp; |
1395 | else |
1395 | else |
1396 | op->stats.maxsp += change->stats.maxsp; |
1396 | op->stats.maxsp += change->stats.maxsp; |
1397 | |
1397 | |
1398 | if (change->stats.food < 0) |
1398 | if (change->stats.food < 0) |
1399 | op->stats.food = -(change->stats.food); |
1399 | op->stats.food = -change->stats.food; |
1400 | else |
1400 | else |
1401 | op->stats.food += change->stats.food; |
1401 | op->stats.food += change->stats.food; |
1402 | |
1402 | |
1403 | if (change->level < 0) |
1403 | if (change->level < 0) |
1404 | op->level = -(change->level); |
1404 | op->level = -change->level; |
1405 | else |
1405 | else |
1406 | op->level += change->level; |
1406 | op->level += change->level; |
1407 | |
1407 | |
1408 | if (change->gen_sp_armour < 0) |
1408 | if (change->gen_sp_armour < 0) |
1409 | op->gen_sp_armour = -(change->gen_sp_armour); |
1409 | op->gen_sp_armour = -change->gen_sp_armour; |
1410 | else |
1410 | else |
1411 | op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; |
1411 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1412 | |
1412 | |
1413 | op->item_power = change->item_power; |
1413 | op->item_power = change->item_power; |
1414 | |
1414 | |
1415 | for (i = 0; i < NROFATTACKS; i++) |
1415 | for (int i = 0; i < NROFATTACKS; i++) |
1416 | if (change->resist[i]) |
|
|
1417 | op->resist[i] += change->resist[i]; |
1416 | op->resist[i] += change->resist[i]; |
1418 | |
1417 | |
1419 | if (change->stats.dam) |
1418 | if (change->stats.dam) |
1420 | { |
1419 | { |
1421 | if (change->stats.dam < 0) |
1420 | if (change->stats.dam < 0) |
1422 | op->stats.dam = (-change->stats.dam); |
1421 | op->stats.dam = -change->stats.dam; |
1423 | else if (op->stats.dam) |
1422 | else if (op->stats.dam) |
1424 | { |
1423 | { |
1425 | tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10); |
1424 | int tmp = op->stats.dam * change->stats.dam / 10; |
|
|
1425 | |
1426 | if (tmp == op->stats.dam) |
1426 | if (tmp == op->stats.dam) |
1427 | { |
1427 | { |
1428 | if (change->stats.dam < 10) |
1428 | if (change->stats.dam < 10) |
1429 | op->stats.dam--; |
1429 | op->stats.dam--; |
1430 | else |
1430 | else |
… | |
… | |
1436 | } |
1436 | } |
1437 | |
1437 | |
1438 | if (change->weight) |
1438 | if (change->weight) |
1439 | { |
1439 | { |
1440 | if (change->weight < 0) |
1440 | if (change->weight < 0) |
1441 | op->weight = (-change->weight); |
1441 | op->weight = -change->weight; |
1442 | else |
1442 | else |
1443 | op->weight = (op->weight * (change->weight)) / 100; |
1443 | op->weight = op->weight * change->weight / 100; |
1444 | } |
1444 | } |
1445 | |
1445 | |
1446 | if (change->last_sp) |
1446 | if (change->last_sp) |
1447 | { |
1447 | { |
1448 | if (change->last_sp < 0) |
1448 | if (change->last_sp < 0) |
1449 | op->last_sp = (-change->last_sp); |
1449 | op->last_sp = -change->last_sp; |
1450 | else |
1450 | else |
1451 | op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100); |
1451 | op->last_sp = op->last_sp * (int)change->last_sp / 100; |
1452 | } |
1452 | } |
1453 | |
1453 | |
1454 | if (change->gen_sp_armour) |
1454 | if (change->gen_sp_armour) |
1455 | { |
1455 | { |
1456 | if (change->gen_sp_armour < 0) |
1456 | if (change->gen_sp_armour < 0) |
1457 | op->gen_sp_armour = (-change->gen_sp_armour); |
1457 | op->gen_sp_armour = -change->gen_sp_armour; |
1458 | else |
1458 | else |
1459 | op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); |
1459 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1460 | } |
1460 | } |
1461 | |
1461 | |
1462 | op->value *= change->value; |
1462 | op->value *= change->value; |
1463 | |
1463 | |
1464 | if (change->materials) |
1464 | if (change->materials) |
… | |
… | |
1496 | name = tmp->name + 1, neg = 1; |
1496 | name = tmp->name + 1, neg = 1; |
1497 | else |
1497 | else |
1498 | name = tmp->name, neg = 0; |
1498 | name = tmp->name, neg = 0; |
1499 | |
1499 | |
1500 | /* If we match name, then return the opposite of 'neg' */ |
1500 | /* If we match name, then return the opposite of 'neg' */ |
1501 | if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) |
1501 | if (!strcmp (name, op->arch->archname)) |
1502 | return !neg; |
1502 | return !neg; |
1503 | |
1503 | |
1504 | /* Set success as true, since if the match was an inverse, it means |
1504 | /* Set success as true, since if the match was an inverse, it means |
1505 | * everything is allowed except what we match |
1505 | * everything is allowed except what we match |
1506 | */ |
1506 | */ |
… | |
… | |
1517 | */ |
1517 | */ |
1518 | |
1518 | |
1519 | void |
1519 | void |
1520 | give_artifact_abilities (object *op, object *artifct) |
1520 | give_artifact_abilities (object *op, object *artifct) |
1521 | { |
1521 | { |
1522 | char new_name[MAX_BUF]; |
1522 | op->title = format ("of %s", &artifct->name); |
1523 | |
1523 | |
1524 | sprintf (new_name, "of %s", &artifct->name); |
|
|
1525 | op->title = new_name; |
|
|
1526 | add_abilities (op, artifct); /* Give out the bonuses */ |
1524 | add_abilities (op, artifct); /* Give out the bonuses */ |
1527 | |
1525 | |
1528 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1526 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1529 | { |
1527 | { |
1530 | char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); |
1528 | char identified = op->flag [FLAG_IDENTIFIED]; |
1531 | |
1529 | |
1532 | SET_FLAG (op, FLAG_IDENTIFIED); |
1530 | op->set_flag (FLAG_IDENTIFIED); |
1533 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1531 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1534 | if (!identified) |
1532 | if (!identified) |
1535 | CLEAR_FLAG (op, FLAG_IDENTIFIED); |
1533 | op->clr_flag (FLAG_IDENTIFIED); |
1536 | } |
1534 | } |
1537 | #endif |
1535 | #endif |
1538 | return; |
1536 | return; |
1539 | } |
1537 | } |
1540 | |
1538 | |
… | |
… | |
1550 | #define ARTIFACT_TRIES 2 |
1548 | #define ARTIFACT_TRIES 2 |
1551 | |
1549 | |
1552 | void |
1550 | void |
1553 | generate_artifact (object *op, int difficulty) |
1551 | generate_artifact (object *op, int difficulty) |
1554 | { |
1552 | { |
1555 | artifactlist *al; |
|
|
1556 | artifact *art; |
1553 | artifact *art; |
1557 | int i; |
|
|
1558 | |
1554 | |
1559 | al = find_artifactlist (op->type); |
1555 | artifactlist *al = find_artifactlist (op->type); |
1560 | |
1556 | |
1561 | if (al == NULL) |
1557 | if (al == NULL) |
1562 | { |
1558 | { |
1563 | #if 0 /* This is too verbose, usually */ |
1559 | #if 0 /* This is too verbose, usually */ |
1564 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1560 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1565 | #endif |
1561 | #endif |
1566 | return; |
1562 | return; |
1567 | } |
1563 | } |
1568 | |
1564 | |
1569 | for (i = 0; i < ARTIFACT_TRIES; i++) |
1565 | for (int i = 0; i < ARTIFACT_TRIES; i++) |
1570 | { |
1566 | { |
1571 | int roll = rndm (al->total_chance); |
1567 | int roll = rndm (al->total_chance); |
1572 | |
1568 | |
1573 | for (art = al->items; art; art = art->next) |
1569 | for (art = al->items; art; art = art->next) |
1574 | { |
1570 | { |
… | |
… | |
1614 | */ |
1610 | */ |
1615 | |
1611 | |
1616 | void |
1612 | void |
1617 | fix_flesh_item (object *item, object *donor) |
1613 | fix_flesh_item (object *item, object *donor) |
1618 | { |
1614 | { |
1619 | char tmpbuf[MAX_BUF]; |
|
|
1620 | int i; |
|
|
1621 | |
|
|
1622 | if (item->type == FLESH && donor) |
1615 | if (item->type == FLESH && donor) |
1623 | { |
1616 | { |
1624 | /* change the name */ |
1617 | /* change the name */ |
1625 | sprintf (tmpbuf, "%s's %s", &donor->name, &item->name); |
1618 | item->name = format ("%s's %s", &donor->name, &item->name); |
1626 | item->name = tmpbuf; |
|
|
1627 | sprintf (tmpbuf, "%s's %s", &donor->name, &item->name_pl); |
1619 | item->name_pl = format ("%s's %s", &donor->name, &item->name_pl); |
1628 | item->name_pl = tmpbuf; |
|
|
1629 | |
1620 | |
1630 | /* weight is FLESH weight/100 * donor */ |
1621 | /* weight is FLESH weight/100 * donor */ |
1631 | if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0) |
1622 | item->weight = max (1, item->weight * donor->weight / 100); |
1632 | item->weight = 1; |
|
|
1633 | |
1623 | |
1634 | /* value is multiplied by level of donor */ |
1624 | /* value is multiplied by level of donor */ |
1635 | item->value *= isqrt (donor->level * 2); |
1625 | item->value *= isqrt (donor->level * 2); |
1636 | |
1626 | |
1637 | /* food value */ |
1627 | /* food value */ |
1638 | item->stats.food += (donor->stats.hp / 100) + donor->stats.Con; |
1628 | item->stats.food += donor->stats.hp / 100 + donor->stats.Con; |
1639 | |
1629 | |
1640 | /* flesh items inherit some abilities of donor, but not |
1630 | /* flesh items inherit some abilities of donor, but not |
1641 | * full effect. |
1631 | * full effect. |
1642 | */ |
1632 | */ |
1643 | for (i = 0; i < NROFATTACKS; i++) |
1633 | for (int i = 0; i < NROFATTACKS; i++) |
1644 | item->resist[i] = donor->resist[i] / 2; |
1634 | item->resist[i] = donor->resist[i] / 2; |
1645 | |
1635 | |
1646 | /* item inherits donor's level (important for quezals) */ |
1636 | /* item inherits donor's level (important for quezals) */ |
1647 | item->level = donor->level; |
1637 | item->level = donor->level; |
1648 | |
1638 | |
1649 | /* if donor has some attacktypes, the flesh is poisonous */ |
1639 | /* if donor has some attacktypes, the flesh is poisonous */ |
1650 | if (donor->attacktype & AT_POISON) |
1640 | if (donor->attacktype & AT_POISON) |
1651 | item->type = POISON; |
1641 | item->type = POISON; |
1652 | |
1642 | |
1653 | if (donor->attacktype & AT_ACID) |
1643 | if (donor->attacktype & AT_ACID) |
1654 | item->stats.hp = -1 * item->stats.food; |
1644 | item->stats.hp = -item->stats.food; |
1655 | |
1645 | |
1656 | SET_FLAG (item, FLAG_NO_STEAL); |
1646 | item->set_flag (FLAG_NO_STEAL); |
1657 | } |
1647 | } |
1658 | } |
1648 | } |
1659 | |
1649 | |
1660 | static void |
1650 | static void |
1661 | free_treasurestruct (treasure *t) |
1651 | free_treasurestruct (treasure *t) |