… | |
… | |
255 | return; |
255 | return; |
256 | } |
256 | } |
257 | |
257 | |
258 | op->expand_tail (); |
258 | op->expand_tail (); |
259 | |
259 | |
|
|
260 | if (!creator->is_on_map () |
260 | if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) |
261 | || (op->weight && op->blocked (creator->map, creator->x, creator->y))) |
261 | op->destroy (); |
262 | op->destroy (); |
262 | else |
263 | else |
263 | { |
264 | { |
264 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
265 | op->flag [FLAG_OBJ_ORIGINAL] = true; |
265 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
266 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
266 | } |
267 | } |
267 | } |
268 | } |
268 | else |
269 | else |
269 | { |
270 | { |
270 | op = creator->insert (op); |
271 | op = creator->insert (op); |
271 | |
272 | |
272 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
273 | if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER]) |
273 | monster_check_apply (creator, op); |
274 | monster_check_apply (creator, op); |
274 | } |
275 | } |
275 | } |
276 | } |
276 | |
277 | |
277 | /* if there are change_xxx commands in the treasure, we include the changes |
278 | /* if there are change_xxx commands in the treasure, we include the changes |
… | |
… | |
509 | int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); |
510 | int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); |
510 | |
511 | |
511 | if (olevel <= 0) |
512 | if (olevel <= 0) |
512 | olevel = rndm (1, op->inv->level); |
513 | olevel = rndm (1, op->inv->level); |
513 | |
514 | |
514 | return min (olevel, MAXLEVEL); |
515 | return min (olevel, MAXLEVEL_TREASURE); |
515 | } |
516 | } |
516 | |
517 | |
517 | /* |
518 | /* |
518 | * Based upon the specified difficulty and upon the difftomagic_list array, |
519 | * Based upon the specified difficulty and upon the difftomagic_list array, |
519 | * a random magical bonus is returned. This is used when determine |
520 | * a random magical bonus is returned. This is used when determine |
… | |
… | |
525 | * |
526 | * |
526 | */ |
527 | */ |
527 | static int |
528 | static int |
528 | magic_from_difficulty (int difficulty) |
529 | magic_from_difficulty (int difficulty) |
529 | { |
530 | { |
530 | int percent = 0, magic = 0; |
|
|
531 | int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); |
531 | int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1); |
|
|
532 | scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1); |
532 | |
533 | |
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); |
534 | int percent = rndm (100); |
|
|
535 | int magic; |
542 | |
536 | |
543 | for (magic = 0; magic < (MAXMAGIC + 1); magic++) |
537 | for (magic = 0; magic <= MAXMAGIC; magic++) |
544 | { |
538 | { |
545 | percent -= difftomagic_list[scaled_diff][magic]; |
539 | percent -= difftomagic_list[scaled_diff][magic]; |
546 | |
540 | |
547 | if (percent < 0) |
541 | if (percent < 0) |
548 | break; |
542 | break; |
549 | } |
543 | } |
550 | |
544 | |
551 | if (magic == (MAXMAGIC + 1)) |
545 | if (magic > MAXMAGIC) |
552 | { |
546 | { |
553 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
547 | LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
554 | magic = 0; |
548 | magic = 0; |
555 | } |
549 | } |
556 | |
550 | |
… | |
… | |
564 | * Sets magical bonus in an object, and recalculates the effect on |
558 | * Sets magical bonus in an object, and recalculates the effect on |
565 | * the armour variable, and the effect on speed of armour. |
559 | * the armour variable, and the effect on speed of armour. |
566 | * This function doesn't work properly, should add use of archetypes |
560 | * This function doesn't work properly, should add use of archetypes |
567 | * to make it truly absolute. |
561 | * to make it truly absolute. |
568 | */ |
562 | */ |
569 | |
|
|
570 | void |
563 | void |
571 | set_abs_magic (object *op, int magic) |
564 | set_abs_magic (object *op, int magic) |
572 | { |
565 | { |
573 | if (!magic) |
566 | if (!magic) |
574 | return; |
567 | return; |
… | |
… | |
602 | */ |
595 | */ |
603 | |
596 | |
604 | static void |
597 | static void |
605 | set_magic (int difficulty, object *op, int max_magic, int flags) |
598 | set_magic (int difficulty, object *op, int max_magic, int flags) |
606 | { |
599 | { |
607 | int i; |
|
|
608 | |
|
|
609 | i = magic_from_difficulty (difficulty); |
600 | int i = magic_from_difficulty (difficulty); |
|
|
601 | |
610 | if ((flags & GT_ONLY_GOOD) && i < 0) |
602 | if ((flags & GT_ONLY_GOOD) && i < 0) |
611 | i = -i; |
603 | i = -i; |
|
|
604 | |
612 | if (i > max_magic) |
605 | i = min (i, max_magic); |
613 | i = max_magic; |
606 | |
614 | set_abs_magic (op, i); |
607 | set_abs_magic (op, i); |
615 | if (i < 0) |
608 | if (i < 0) |
616 | SET_FLAG (op, FLAG_CURSED); |
609 | op->set_flag (FLAG_CURSED); |
617 | } |
610 | } |
618 | |
611 | |
619 | /* |
612 | /* |
620 | * Randomly adds one magical ability to the given object. |
613 | * Randomly adds one magical ability to the given object. |
621 | * Modified for Partial Resistance in many ways: |
614 | * Modified for Partial Resistance in many ways: |
… | |
… | |
628 | set_ring_bonus (object *op, int bonus) |
621 | set_ring_bonus (object *op, int bonus) |
629 | { |
622 | { |
630 | int r = rndm (bonus > 0 ? 25 : 11); |
623 | int r = rndm (bonus > 0 ? 25 : 11); |
631 | |
624 | |
632 | if (op->type == AMULET) |
625 | if (op->type == AMULET) |
633 | { |
|
|
634 | if (!(rndm (21))) |
626 | if (!rndm (21)) |
635 | r = 20 + rndm (2); |
627 | r = 20 + rndm (2); |
|
|
628 | else if (rndm (2)) |
|
|
629 | r = 10; |
636 | else |
630 | else |
637 | { |
|
|
638 | if (rndm (2)) |
|
|
639 | r = 10; |
|
|
640 | else |
|
|
641 | r = 11 + rndm (9); |
631 | r = 11 + rndm (9); |
642 | } |
|
|
643 | } |
|
|
644 | |
632 | |
645 | switch (r) |
633 | switch (r) |
646 | { |
634 | { |
647 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
635 | /* Redone by MSW 2000-11-26 to have much less code. Also, |
648 | * bonuses and penalties will stack and add to existing values. |
636 | * bonuses and penalties will stack and add to existing values. |
649 | * of the item. |
637 | * of the item. |
650 | */ |
638 | */ |
651 | case 0: |
639 | case 0: |
652 | case 1: |
640 | case 1: |
653 | case 2: |
641 | case 2: |
654 | case 3: |
642 | case 3: |
655 | case 4: |
643 | case 4: |
… | |
… | |
695 | * little random element in since that they don't always end up with |
683 | * little random element in since that they don't always end up with |
696 | * even values. |
684 | * even values. |
697 | */ |
685 | */ |
698 | if (bonus < 0) |
686 | if (bonus < 0) |
699 | val = 2 * -val - rndm (b); |
687 | val = 2 * -val - rndm (b); |
700 | if (val > 35) |
688 | |
701 | val = 35; /* Upper limit */ |
689 | val = min (35, val); /* Upper limit */ |
|
|
690 | |
702 | b = 0; |
691 | b = 0; |
703 | |
692 | |
704 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
693 | while (op->resist[resist_table[resist]] != 0 && b < 4) |
705 | resist = rndm (num_resist_table); |
694 | resist = rndm (num_resist_table); |
706 | |
695 | |
… | |
… | |
714 | break; |
703 | break; |
715 | } |
704 | } |
716 | case 20: |
705 | case 20: |
717 | if (op->type == AMULET) |
706 | if (op->type == AMULET) |
718 | { |
707 | { |
719 | SET_FLAG (op, FLAG_REFL_SPELL); |
708 | op->set_flag (FLAG_REFL_SPELL); |
720 | op->value *= 11; |
709 | op->value *= 11; |
721 | } |
710 | } |
722 | else |
711 | else |
723 | { |
712 | { |
724 | op->stats.hp = 1; /* regenerate hit points */ |
713 | op->stats.hp = 1; /* regenerate hit points */ |
… | |
… | |
727 | break; |
716 | break; |
728 | |
717 | |
729 | case 21: |
718 | case 21: |
730 | if (op->type == AMULET) |
719 | if (op->type == AMULET) |
731 | { |
720 | { |
732 | SET_FLAG (op, FLAG_REFL_MISSILE); |
721 | op->set_flag (FLAG_REFL_MISSILE); |
733 | op->value *= 9; |
722 | op->value *= 9; |
734 | } |
723 | } |
735 | else |
724 | else |
736 | { |
725 | { |
737 | op->stats.sp = 1; /* regenerate spell points */ |
726 | op->stats.sp = 1; /* regenerate spell points */ |
… | |
… | |
739 | } |
728 | } |
740 | break; |
729 | break; |
741 | |
730 | |
742 | case 22: |
731 | case 22: |
743 | op->stats.exp += bonus; /* Speed! */ |
732 | op->stats.exp += bonus; /* Speed! */ |
744 | op->value = (op->value * 2) / 3; |
733 | op->value = op->value * 2 / 3; |
745 | break; |
734 | break; |
746 | } |
735 | } |
747 | |
736 | |
748 | if (bonus > 0) |
737 | if (bonus > 0) |
749 | op->value *= 2 * bonus; |
738 | op->value = 2 * op->value * bonus; |
750 | else |
739 | else |
751 | op->value = -(op->value * 2 * bonus) / 3; |
740 | op->value = -2 * op->value * bonus / 3; |
752 | } |
741 | } |
753 | |
742 | |
754 | /* |
743 | /* |
755 | * get_magic(diff) will return a random number between 0 and 4. |
744 | * 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 |
745 | * 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. |
749 | * Another scheme is used to calculate the magic of weapons and armours. |
761 | */ |
750 | */ |
762 | static int |
751 | static int |
763 | get_magic (int diff) |
752 | get_magic (int diff) |
764 | { |
753 | { |
765 | int i; |
754 | diff = min (3, diff); |
766 | |
755 | |
767 | if (diff < 3) |
|
|
768 | diff = 3; |
|
|
769 | |
|
|
770 | for (i = 0; i < 4; i++) |
756 | for (int i = 0; i < 4; i++) |
771 | if (rndm (diff)) |
757 | if (rndm (diff)) |
772 | return i; |
758 | return i; |
773 | |
759 | |
774 | return 4; |
760 | return 4; |
775 | } |
761 | } |
… | |
… | |
789 | return 1; |
775 | return 1; |
790 | |
776 | |
791 | return 0; |
777 | return 0; |
792 | } |
778 | } |
793 | |
779 | |
|
|
780 | static double |
|
|
781 | value_factor_from_spell_item (object *spell, object *item) |
|
|
782 | { |
|
|
783 | double factor = |
|
|
784 | pow ((spell->value > 0 ? spell->value : 1) |
|
|
785 | * spell->level, 1.5); |
|
|
786 | |
|
|
787 | if (item) // this if for: wands/staffs/rods: |
|
|
788 | { |
|
|
789 | /* Old crossfire comment ahead: |
|
|
790 | * Add 50 to both level an divisor to keep prices a little more |
|
|
791 | * reasonable. Otherwise, a high level version of a low level |
|
|
792 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
|
|
793 | * 10 time multiplier). This way, the value are a bit more reasonable. |
|
|
794 | */ |
|
|
795 | |
|
|
796 | factor *= item->level + 50; |
|
|
797 | factor /= item->inv->level + 50; |
|
|
798 | } |
|
|
799 | |
|
|
800 | return factor; |
|
|
801 | } |
|
|
802 | |
794 | #define DICE2 (get_magic(2)==2?2:1) |
803 | #define DICE2 (get_magic(2) == 2 ? 2 : 1) |
795 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
804 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
796 | |
805 | |
797 | /* |
806 | /* |
798 | * fix_generated_item(): This is called after an item is generated, in |
807 | * 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 |
808 | * order to set it up right. This produced magical bonuses, puts spells |
… | |
… | |
923 | case WEAPON: |
932 | case WEAPON: |
924 | case ARMOUR: |
933 | case ARMOUR: |
925 | case SHIELD: |
934 | case SHIELD: |
926 | case HELMET: |
935 | case HELMET: |
927 | case CLOAK: |
936 | case CLOAK: |
928 | if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) |
937 | if (op->flag [FLAG_CURSED] && !(rndm (4))) |
929 | set_ring_bonus (op, -DICE2); |
938 | set_ring_bonus (op, -DICE2); |
930 | break; |
939 | break; |
931 | |
940 | |
932 | case BRACERS: |
941 | case BRACERS: |
933 | if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) |
942 | if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20)) |
934 | { |
943 | { |
935 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
944 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
936 | if (!QUERY_FLAG (op, FLAG_CURSED)) |
945 | if (!op->flag [FLAG_CURSED]) |
937 | op->value *= 3; |
946 | op->value *= 3; |
938 | } |
947 | } |
939 | break; |
948 | break; |
940 | |
949 | |
941 | case POTION: |
950 | case POTION: |
… | |
… | |
966 | op->value *= op->inv->value; |
975 | op->value *= op->inv->value; |
967 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
976 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
968 | } |
977 | } |
969 | else |
978 | else |
970 | { |
979 | { |
971 | op->name = "potion"; |
980 | op->name = shstr_potion; |
972 | op->name_pl = "potions"; |
981 | op->name_pl = shstr_potions; |
973 | } |
982 | } |
974 | |
983 | |
975 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
984 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
976 | SET_FLAG (op, FLAG_CURSED); |
985 | op->set_flag (FLAG_CURSED); |
977 | |
986 | |
978 | break; |
987 | break; |
979 | } |
988 | } |
980 | |
989 | |
981 | case AMULET: |
990 | case AMULET: |
… | |
… | |
985 | case RING: |
994 | case RING: |
986 | if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ |
995 | if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ |
987 | break; |
996 | break; |
988 | |
997 | |
989 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
998 | if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) |
990 | SET_FLAG (op, FLAG_CURSED); |
999 | op->set_flag (FLAG_CURSED); |
991 | |
1000 | |
992 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
1001 | set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2); |
993 | |
1002 | |
994 | if (op->type != RING) /* Amulets have only one ability */ |
1003 | if (op->type != RING) /* Amulets have only one ability */ |
995 | break; |
1004 | break; |
996 | |
1005 | |
997 | if (!(rndm (4))) |
1006 | if (!rndm (4)) |
998 | { |
1007 | { |
999 | int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1008 | int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
1000 | |
1009 | |
1001 | if (d > 0) |
1010 | if (d > 0) |
1002 | op->value *= 3; |
1011 | op->value *= 3; |
1003 | |
1012 | |
1004 | set_ring_bonus (op, d); |
1013 | set_ring_bonus (op, d); |
1005 | |
1014 | |
1006 | if (!(rndm (4))) |
1015 | if (!rndm (4)) |
1007 | { |
1016 | { |
1008 | int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
1017 | int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2; |
1009 | |
1018 | |
1010 | if (d > 0) |
1019 | if (d > 0) |
1011 | op->value *= 5; |
1020 | op->value *= 5; |
|
|
1021 | |
1012 | set_ring_bonus (op, d); |
1022 | set_ring_bonus (op, d); |
1013 | } |
1023 | } |
1014 | } |
1024 | } |
1015 | |
1025 | |
1016 | if (op->animation_id) |
1026 | if (op->animation_id) |
… | |
… | |
1024 | * creator and/or map level we found it on. |
1034 | * creator and/or map level we found it on. |
1025 | */ |
1035 | */ |
1026 | if (!op->msg && rndm (10)) |
1036 | if (!op->msg && rndm (10)) |
1027 | { |
1037 | { |
1028 | /* set the book level properly */ |
1038 | /* set the book level properly */ |
1029 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
1039 | if (creator->level == 0 || creator->flag [FLAG_ALIVE]) |
1030 | { |
1040 | { |
1031 | if (op->map && op->map->difficulty) |
1041 | if (op->map && op->map->difficulty) |
1032 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1042 | op->level = rndm (op->map->difficulty) + rndm (10) + 1; |
1033 | else |
1043 | else |
1034 | op->level = rndm (20) + 1; |
1044 | op->level = rndm (20) + 1; |
… | |
… | |
1047 | /* creator related stuff */ |
1057 | /* creator related stuff */ |
1048 | |
1058 | |
1049 | /* for library, chained books. Note that some monsters have no_pick |
1059 | /* for library, chained books. Note that some monsters have no_pick |
1050 | * set - we don't want to set no pick in that case. |
1060 | * set - we don't want to set no pick in that case. |
1051 | */ |
1061 | */ |
1052 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) |
1062 | if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER]) |
1053 | SET_FLAG (op, FLAG_NO_PICK); |
1063 | op->set_flag (FLAG_NO_PICK); |
1054 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1064 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1055 | op->slaying = creator->slaying; |
1065 | op->slaying = creator->slaying; |
1056 | break; |
1066 | break; |
1057 | |
1067 | |
1058 | case SPELLBOOK: |
1068 | case SPELLBOOK: |
1059 | op->value = op->value * op->inv->value; |
1069 | op->value *= value_factor_from_spell_item (op->inv, 0); |
|
|
1070 | |
1060 | /* add exp so learning gives xp */ |
1071 | /* add exp so learning gives xp */ |
1061 | op->level = op->inv->level; |
1072 | op->level = op->inv->level; |
1062 | op->stats.exp = op->value; |
1073 | op->stats.exp = op->value; |
1063 | break; |
1074 | break; |
1064 | |
1075 | |
… | |
… | |
1068 | * and reset nrof. |
1079 | * and reset nrof. |
1069 | */ |
1080 | */ |
1070 | op->stats.food = op->inv->nrof; |
1081 | op->stats.food = op->inv->nrof; |
1071 | op->nrof = 1; |
1082 | op->nrof = 1; |
1072 | /* If the spell changes by level, choose a random level |
1083 | /* If the spell changes by level, choose a random level |
1073 | * for it, and adjust price. If the spell doesn't |
1084 | * for it. |
1074 | * change by level, just set the wand to the level of |
|
|
1075 | * the spell, and value calculation is simpler. |
|
|
1076 | */ |
1085 | */ |
1077 | if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) |
1086 | if (op->inv->duration_modifier |
1078 | { |
1087 | || op->inv->dam_modifier |
|
|
1088 | || op->inv->range_modifier) |
1079 | op->level = level_for_item (op, difficulty); |
1089 | 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 |
1090 | else |
1083 | { |
|
|
1084 | op->level = op->inv->level; |
1091 | op->level = op->inv->level; |
1085 | op->value = op->value * op->inv->value; |
1092 | |
1086 | } |
1093 | op->value *= value_factor_from_spell_item (op->inv, op); |
1087 | break; |
1094 | break; |
1088 | |
1095 | |
1089 | case ROD: |
1096 | case ROD: |
1090 | op->level = level_for_item (op, difficulty); |
1097 | op->level = level_for_item (op, difficulty); |
1091 | /* Add 50 to both level an divisor to keep prices a little more |
1098 | op->value *= value_factor_from_spell_item (op->inv, op); |
1092 | * reasonable. Otherwise, a high level version of a low level |
1099 | |
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 */ |
1100 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1098 | if (op->stats.maxhp) |
1101 | if (op->stats.maxhp) |
1099 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1102 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1100 | else |
1103 | else |
1101 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
1104 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
… | |
… | |
1103 | op->stats.hp = op->stats.maxhp; |
1106 | op->stats.hp = op->stats.maxhp; |
1104 | break; |
1107 | break; |
1105 | |
1108 | |
1106 | case SCROLL: |
1109 | case SCROLL: |
1107 | op->level = level_for_item (op, difficulty); |
1110 | op->level = level_for_item (op, difficulty); |
1108 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1111 | op->value *= value_factor_from_spell_item (op->inv, op); |
1109 | |
1112 | |
1110 | /* add exp so reading them properly gives xp */ |
1113 | /* add exp so reading them properly gives xp */ |
1111 | op->stats.exp = op->value / 5; |
1114 | op->stats.exp = op->value / 5; |
1112 | op->nrof = op->inv->nrof; |
1115 | op->nrof = op->inv->nrof; |
1113 | break; |
1116 | break; |
… | |
… | |
1121 | break; |
1124 | break; |
1122 | } /* switch type */ |
1125 | } /* switch type */ |
1123 | |
1126 | |
1124 | if (flags & GT_STARTEQUIP) |
1127 | if (flags & GT_STARTEQUIP) |
1125 | { |
1128 | { |
1126 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) |
1129 | if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN]) |
1127 | SET_FLAG (op, FLAG_STARTEQUIP); |
1130 | op->set_flag (FLAG_STARTEQUIP); |
1128 | else if (op->type != MONEY) |
1131 | else if (op->type != MONEY) |
1129 | op->value = 0; |
1132 | op->value = 0; |
1130 | } |
1133 | } |
1131 | |
1134 | |
1132 | if (!(flags & GT_ENVIRONMENT)) |
1135 | if (!(flags & GT_ENVIRONMENT)) |
… | |
… | |
1178 | */ |
1181 | */ |
1179 | void |
1182 | void |
1180 | init_artifacts () |
1183 | init_artifacts () |
1181 | { |
1184 | { |
1182 | static int has_been_inited = 0; |
1185 | static int has_been_inited = 0; |
1183 | char filename[MAX_BUF]; |
|
|
1184 | artifact *art = NULL; |
1186 | artifact *art = NULL; |
1185 | artifactlist *al; |
1187 | artifactlist *al; |
1186 | |
1188 | |
1187 | if (has_been_inited) |
1189 | if (has_been_inited) |
1188 | return; |
1190 | return; |
1189 | else |
1191 | else |
1190 | has_been_inited = 1; |
1192 | has_been_inited = 1; |
1191 | |
1193 | |
1192 | sprintf (filename, "%s/artifacts", settings.datadir); |
1194 | object_thawer f (settings.datadir, "artifacts"); |
1193 | object_thawer f (filename); |
|
|
1194 | |
1195 | |
1195 | if (!f) |
1196 | if (!f) |
1196 | return; |
1197 | return; |
1197 | |
1198 | |
1198 | for (;;) |
1199 | for (;;) |
… | |
… | |
1283 | } |
1284 | } |
1284 | #if 0 |
1285 | #if 0 |
1285 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1286 | LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); |
1286 | #endif |
1287 | #endif |
1287 | } |
1288 | } |
1288 | |
|
|
1289 | LOG (llevDebug, "done.\n"); |
|
|
1290 | } |
1289 | } |
1291 | |
1290 | |
1292 | /* |
1291 | /* |
1293 | * Used in artifact generation. The bonuses of the first object |
1292 | * Used in artifact generation. The bonuses of the first object |
1294 | * is modified by the bonuses of the second object. |
1293 | * is modified by the bonuses of the second object. |
1295 | */ |
1294 | */ |
1296 | void |
1295 | void |
1297 | add_abilities (object *op, object *change) |
1296 | add_abilities (object *op, object *change) |
1298 | { |
1297 | { |
1299 | int i, tmp; |
|
|
1300 | |
|
|
1301 | if (change->face != blank_face) |
1298 | 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; |
1299 | op->face = change->face; |
1307 | } |
|
|
1308 | |
1300 | |
1309 | for (i = 0; i < NUM_STATS; i++) |
1301 | for (int i = 0; i < NUM_STATS; i++) |
1310 | change_attr_value (&(op->stats), i, change->stats.stat (i)); |
1302 | change_attr_value (&(op->stats), i, change->stats.stat (i)); |
1311 | |
1303 | |
1312 | op->attacktype |= change->attacktype; |
1304 | op->attacktype |= change->attacktype; |
1313 | op->path_attuned |= change->path_attuned; |
1305 | op->path_attuned |= change->path_attuned; |
1314 | op->path_repelled |= change->path_repelled; |
1306 | op->path_repelled |= change->path_repelled; |
1315 | op->path_denied |= change->path_denied; |
1307 | op->path_denied |= change->path_denied; |
1316 | op->move_type |= change->move_type; |
1308 | op->move_type |= change->move_type; |
1317 | op->stats.luck += change->stats.luck; |
1309 | op->stats.luck += change->stats.luck; |
1318 | |
1310 | |
1319 | if (QUERY_FLAG (change, FLAG_CURSED)) |
1311 | static const struct copyflags : object::flags_t |
1320 | SET_FLAG (op, FLAG_CURSED); |
1312 | { |
1321 | if (QUERY_FLAG (change, FLAG_DAMNED)) |
1313 | copyflags () |
1322 | SET_FLAG (op, FLAG_DAMNED); |
1314 | { |
1323 | if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) |
1315 | set (FLAG_CURSED); |
|
|
1316 | set (FLAG_DAMNED); |
|
|
1317 | set (FLAG_LIFESAVE); |
|
|
1318 | set (FLAG_REFL_SPELL); |
|
|
1319 | set (FLAG_STEALTH); |
|
|
1320 | set (FLAG_XRAYS); |
|
|
1321 | set (FLAG_BLIND); |
|
|
1322 | set (FLAG_SEE_IN_DARK); |
|
|
1323 | set (FLAG_REFL_MISSILE); |
|
|
1324 | set (FLAG_MAKE_INVIS); |
|
|
1325 | } |
|
|
1326 | } copyflags; |
|
|
1327 | |
|
|
1328 | // we might want to just copy, but or'ing is what the original code did |
|
|
1329 | op->flag |= change->flag & copyflags; |
|
|
1330 | |
|
|
1331 | if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0) |
1324 | set_abs_magic (op, -op->magic); |
1332 | set_abs_magic (op, -op->magic); |
1325 | |
1333 | |
1326 | if (QUERY_FLAG (change, FLAG_LIFESAVE)) |
1334 | 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 | { |
1335 | { |
1345 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1336 | op->clr_flag (FLAG_ANIMATE); |
|
|
1337 | |
1346 | /* so artifacts will join */ |
1338 | /* so artifacts will join */ |
1347 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1339 | if (!op->flag [FLAG_ALIVE]) |
1348 | op->speed = 0.0; |
1340 | op->speed = 0.; |
1349 | |
1341 | |
1350 | op->set_speed (op->speed); |
1342 | op->set_speed (op->speed); |
1351 | } |
1343 | } |
1352 | |
1344 | |
1353 | if (change->nrof) |
1345 | if (change->nrof) |
1354 | op->nrof = rndm (change->nrof) + 1; |
1346 | op->nrof = rndm (change->nrof) + 1; |
1355 | |
1347 | |
1356 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1348 | op->stats.exp += change->stats.exp; /* Speed modifier */ |
1357 | op->stats.wc += change->stats.wc; |
1349 | op->stats.wc += change->stats.wc; |
1358 | op->stats.ac += change->stats.ac; |
1350 | op->stats.ac += change->stats.ac; |
1359 | |
1351 | |
1360 | if (change->other_arch) |
1352 | if (change->other_arch) |
1361 | { |
1353 | { |
1362 | /* Basically, for horns & potions, the other_arch field is the spell |
1354 | /* 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 |
1355 | * to cast. So convert that to into a spell and put it into |
… | |
… | |
1369 | op->destroy_inv (false); |
1361 | op->destroy_inv (false); |
1370 | |
1362 | |
1371 | object *tmp = change->other_arch->instance (); |
1363 | object *tmp = change->other_arch->instance (); |
1372 | insert_ob_in_ob (tmp, op); |
1364 | insert_ob_in_ob (tmp, op); |
1373 | } |
1365 | } |
|
|
1366 | |
1374 | /* No harm setting this for potions/horns */ |
1367 | /* No harm setting this for potions/horns */ |
1375 | op->other_arch = change->other_arch; |
1368 | op->other_arch = change->other_arch; |
1376 | } |
1369 | } |
1377 | |
1370 | |
1378 | if (change->stats.hp < 0) |
1371 | if (change->stats.hp < 0) |
… | |
… | |
1394 | op->stats.maxsp = -change->stats.maxsp; |
1387 | op->stats.maxsp = -change->stats.maxsp; |
1395 | else |
1388 | else |
1396 | op->stats.maxsp += change->stats.maxsp; |
1389 | op->stats.maxsp += change->stats.maxsp; |
1397 | |
1390 | |
1398 | if (change->stats.food < 0) |
1391 | if (change->stats.food < 0) |
1399 | op->stats.food = -(change->stats.food); |
1392 | op->stats.food = -change->stats.food; |
1400 | else |
1393 | else |
1401 | op->stats.food += change->stats.food; |
1394 | op->stats.food += change->stats.food; |
1402 | |
1395 | |
1403 | if (change->level < 0) |
1396 | if (change->level < 0) |
1404 | op->level = -(change->level); |
1397 | op->level = -change->level; |
1405 | else |
1398 | else |
1406 | op->level += change->level; |
1399 | op->level += change->level; |
1407 | |
1400 | |
1408 | if (change->gen_sp_armour < 0) |
1401 | if (change->gen_sp_armour < 0) |
1409 | op->gen_sp_armour = -(change->gen_sp_armour); |
1402 | op->gen_sp_armour = -change->gen_sp_armour; |
1410 | else |
1403 | else |
1411 | op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; |
1404 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1412 | |
1405 | |
1413 | op->item_power = change->item_power; |
1406 | op->item_power = change->item_power; |
1414 | |
1407 | |
1415 | for (i = 0; i < NROFATTACKS; i++) |
1408 | for (int i = 0; i < NROFATTACKS; i++) |
1416 | if (change->resist[i]) |
|
|
1417 | op->resist[i] += change->resist[i]; |
1409 | op->resist[i] += change->resist[i]; |
1418 | |
1410 | |
1419 | if (change->stats.dam) |
1411 | if (change->stats.dam) |
1420 | { |
1412 | { |
1421 | if (change->stats.dam < 0) |
1413 | if (change->stats.dam < 0) |
1422 | op->stats.dam = (-change->stats.dam); |
1414 | op->stats.dam = -change->stats.dam; |
1423 | else if (op->stats.dam) |
1415 | else if (op->stats.dam) |
1424 | { |
1416 | { |
1425 | tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10); |
1417 | int tmp = op->stats.dam * change->stats.dam / 10; |
|
|
1418 | |
1426 | if (tmp == op->stats.dam) |
1419 | if (tmp == op->stats.dam) |
1427 | { |
1420 | { |
1428 | if (change->stats.dam < 10) |
1421 | if (change->stats.dam < 10) |
1429 | op->stats.dam--; |
1422 | op->stats.dam--; |
1430 | else |
1423 | else |
… | |
… | |
1436 | } |
1429 | } |
1437 | |
1430 | |
1438 | if (change->weight) |
1431 | if (change->weight) |
1439 | { |
1432 | { |
1440 | if (change->weight < 0) |
1433 | if (change->weight < 0) |
1441 | op->weight = (-change->weight); |
1434 | op->weight = -change->weight; |
1442 | else |
1435 | else |
1443 | op->weight = (op->weight * (change->weight)) / 100; |
1436 | op->weight = op->weight * change->weight / 100; |
1444 | } |
1437 | } |
1445 | |
1438 | |
1446 | if (change->last_sp) |
1439 | if (change->last_sp) |
1447 | { |
1440 | { |
1448 | if (change->last_sp < 0) |
1441 | if (change->last_sp < 0) |
1449 | op->last_sp = (-change->last_sp); |
1442 | op->last_sp = -change->last_sp; |
1450 | else |
1443 | else |
1451 | op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100); |
1444 | op->last_sp = op->last_sp * (int)change->last_sp / 100; |
1452 | } |
1445 | } |
1453 | |
1446 | |
1454 | if (change->gen_sp_armour) |
1447 | if (change->gen_sp_armour) |
1455 | { |
1448 | { |
1456 | if (change->gen_sp_armour < 0) |
1449 | if (change->gen_sp_armour < 0) |
1457 | op->gen_sp_armour = (-change->gen_sp_armour); |
1450 | op->gen_sp_armour = -change->gen_sp_armour; |
1458 | else |
1451 | else |
1459 | op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); |
1452 | op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100; |
1460 | } |
1453 | } |
1461 | |
1454 | |
1462 | op->value *= change->value; |
1455 | op->value *= change->value; |
1463 | |
1456 | |
1464 | if (change->materials) |
1457 | if (change->materials) |
… | |
… | |
1496 | name = tmp->name + 1, neg = 1; |
1489 | name = tmp->name + 1, neg = 1; |
1497 | else |
1490 | else |
1498 | name = tmp->name, neg = 0; |
1491 | name = tmp->name, neg = 0; |
1499 | |
1492 | |
1500 | /* If we match name, then return the opposite of 'neg' */ |
1493 | /* If we match name, then return the opposite of 'neg' */ |
1501 | if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) |
1494 | if (!strcmp (name, op->arch->archname)) |
1502 | return !neg; |
1495 | return !neg; |
1503 | |
1496 | |
1504 | /* Set success as true, since if the match was an inverse, it means |
1497 | /* Set success as true, since if the match was an inverse, it means |
1505 | * everything is allowed except what we match |
1498 | * everything is allowed except what we match |
1506 | */ |
1499 | */ |
… | |
… | |
1517 | */ |
1510 | */ |
1518 | |
1511 | |
1519 | void |
1512 | void |
1520 | give_artifact_abilities (object *op, object *artifct) |
1513 | give_artifact_abilities (object *op, object *artifct) |
1521 | { |
1514 | { |
1522 | char new_name[MAX_BUF]; |
1515 | op->title = format ("of %s", &artifct->name); |
1523 | |
1516 | |
1524 | sprintf (new_name, "of %s", &artifct->name); |
|
|
1525 | op->title = new_name; |
|
|
1526 | add_abilities (op, artifct); /* Give out the bonuses */ |
1517 | add_abilities (op, artifct); /* Give out the bonuses */ |
1527 | |
1518 | |
1528 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1519 | #if 0 /* Bit verbose, but keep it here until next time I need it... */ |
1529 | { |
1520 | { |
1530 | char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); |
1521 | char identified = op->flag [FLAG_IDENTIFIED]; |
1531 | |
1522 | |
1532 | SET_FLAG (op, FLAG_IDENTIFIED); |
1523 | op->set_flag (FLAG_IDENTIFIED); |
1533 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1524 | LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); |
1534 | if (!identified) |
1525 | if (!identified) |
1535 | CLEAR_FLAG (op, FLAG_IDENTIFIED); |
1526 | op->clr_flag (FLAG_IDENTIFIED); |
1536 | } |
1527 | } |
1537 | #endif |
1528 | #endif |
1538 | return; |
1529 | return; |
1539 | } |
1530 | } |
1540 | |
1531 | |
… | |
… | |
1550 | #define ARTIFACT_TRIES 2 |
1541 | #define ARTIFACT_TRIES 2 |
1551 | |
1542 | |
1552 | void |
1543 | void |
1553 | generate_artifact (object *op, int difficulty) |
1544 | generate_artifact (object *op, int difficulty) |
1554 | { |
1545 | { |
1555 | artifactlist *al; |
|
|
1556 | artifact *art; |
1546 | artifact *art; |
1557 | int i; |
|
|
1558 | |
1547 | |
1559 | al = find_artifactlist (op->type); |
1548 | artifactlist *al = find_artifactlist (op->type); |
1560 | |
1549 | |
1561 | if (al == NULL) |
1550 | if (al == NULL) |
1562 | { |
1551 | { |
1563 | #if 0 /* This is too verbose, usually */ |
1552 | #if 0 /* This is too verbose, usually */ |
1564 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1553 | LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); |
1565 | #endif |
1554 | #endif |
1566 | return; |
1555 | return; |
1567 | } |
1556 | } |
1568 | |
1557 | |
1569 | for (i = 0; i < ARTIFACT_TRIES; i++) |
1558 | for (int i = 0; i < ARTIFACT_TRIES; i++) |
1570 | { |
1559 | { |
1571 | int roll = rndm (al->total_chance); |
1560 | int roll = rndm (al->total_chance); |
1572 | |
1561 | |
1573 | for (art = al->items; art; art = art->next) |
1562 | for (art = al->items; art; art = art->next) |
1574 | { |
1563 | { |
… | |
… | |
1614 | */ |
1603 | */ |
1615 | |
1604 | |
1616 | void |
1605 | void |
1617 | fix_flesh_item (object *item, object *donor) |
1606 | fix_flesh_item (object *item, object *donor) |
1618 | { |
1607 | { |
1619 | char tmpbuf[MAX_BUF]; |
|
|
1620 | int i; |
|
|
1621 | |
|
|
1622 | if (item->type == FLESH && donor) |
1608 | if (item->type == FLESH && donor) |
1623 | { |
1609 | { |
1624 | /* change the name */ |
1610 | /* change the name */ |
1625 | sprintf (tmpbuf, "%s's %s", &donor->name, &item->name); |
1611 | 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); |
1612 | item->name_pl = format ("%s's %s", &donor->name, &item->name_pl); |
1628 | item->name_pl = tmpbuf; |
|
|
1629 | |
1613 | |
1630 | /* weight is FLESH weight/100 * donor */ |
1614 | /* weight is FLESH weight/100 * donor */ |
1631 | if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0) |
1615 | item->weight = max (1, item->weight * donor->weight / 100); |
1632 | item->weight = 1; |
|
|
1633 | |
1616 | |
1634 | /* value is multiplied by level of donor */ |
1617 | /* value is multiplied by level of donor */ |
1635 | item->value *= isqrt (donor->level * 2); |
1618 | item->value *= isqrt (donor->level * 2); |
1636 | |
1619 | |
1637 | /* food value */ |
1620 | /* food value */ |
1638 | item->stats.food += (donor->stats.hp / 100) + donor->stats.Con; |
1621 | item->stats.food += donor->stats.hp / 100 + donor->stats.Con; |
1639 | |
1622 | |
1640 | /* flesh items inherit some abilities of donor, but not |
1623 | /* flesh items inherit some abilities of donor, but not |
1641 | * full effect. |
1624 | * full effect. |
1642 | */ |
1625 | */ |
1643 | for (i = 0; i < NROFATTACKS; i++) |
1626 | for (int i = 0; i < NROFATTACKS; i++) |
1644 | item->resist[i] = donor->resist[i] / 2; |
1627 | item->resist[i] = donor->resist[i] / 2; |
1645 | |
1628 | |
1646 | /* item inherits donor's level (important for quezals) */ |
1629 | /* item inherits donor's level (important for quezals) */ |
1647 | item->level = donor->level; |
1630 | item->level = donor->level; |
1648 | |
1631 | |
1649 | /* if donor has some attacktypes, the flesh is poisonous */ |
1632 | /* if donor has some attacktypes, the flesh is poisonous */ |
1650 | if (donor->attacktype & AT_POISON) |
1633 | if (donor->attacktype & AT_POISON) |
1651 | item->type = POISON; |
1634 | item->type = POISON; |
1652 | |
1635 | |
1653 | if (donor->attacktype & AT_ACID) |
1636 | if (donor->attacktype & AT_ACID) |
1654 | item->stats.hp = -1 * item->stats.food; |
1637 | item->stats.hp = -item->stats.food; |
1655 | |
1638 | |
1656 | SET_FLAG (item, FLAG_NO_STEAL); |
1639 | item->set_flag (FLAG_NO_STEAL); |
1657 | } |
1640 | } |
1658 | } |
1641 | } |
1659 | |
1642 | |
1660 | static void |
1643 | static void |
1661 | free_treasurestruct (treasure *t) |
1644 | free_treasurestruct (treasure *t) |