1 | |
1 | |
2 | /* |
2 | /* |
3 | * static char *rcs_treasure_c = |
3 | * static char *rcs_treasure_c = |
4 | * "$Id: treasure.c,v 1.1.1.2 2006/02/22 18:01:23 elmex Exp $"; |
4 | * "$Id: treasure.c,v 1.6 2006/08/13 17:16:01 elmex dead $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
220 | #endif |
220 | #endif |
221 | tl->total_chance += t->chance; |
221 | tl->total_chance += t->chance; |
222 | } |
222 | } |
223 | } |
223 | } |
224 | } else |
224 | } else |
225 | LOG(llevError,"Treasure-list didn't understand: %s, line %d\n",buf, line); |
225 | LOG(llevError,"Treasure-list %s didn't understand: %s, line %d\n", filename, buf, line); |
226 | } |
226 | } |
227 | close_and_delete(fp, comp); |
227 | close_and_delete(fp, comp); |
228 | |
228 | |
229 | #ifdef TREASURE_DEBUG |
229 | #ifdef TREASURE_DEBUG |
230 | /* Perform some checks on how valid the treasure data actually is. |
230 | /* Perform some checks on how valid the treasure data actually is. |
… | |
… | |
331 | |
331 | |
332 | |
332 | |
333 | if((int)t->chance >= 100 || (RANDOM()%100 + 1) < (int) t->chance) { |
333 | if((int)t->chance >= 100 || (RANDOM()%100 + 1) < (int) t->chance) { |
334 | if (t->name) { |
334 | if (t->name) { |
335 | if (strcmp(t->name,"NONE") && difficulty>=t->magic) |
335 | if (strcmp(t->name,"NONE") && difficulty>=t->magic) |
|
|
336 | { |
336 | create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); |
337 | create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); |
|
|
338 | } |
337 | } |
339 | } |
338 | else { |
340 | else { |
339 | if(t->item->clone.invisible != 0 || ! (flag & GT_INVISIBLE)) { |
341 | if(t->item->clone.invisible != 0 || ! (flag & GT_INVISIBLE)) { |
340 | tmp=arch_to_object(t->item); |
342 | tmp=arch_to_object(t->item); |
341 | if(t->nrof&&tmp->nrof<=1) |
343 | if(t->nrof&&tmp->nrof<=1) |
… | |
… | |
478 | { 0, 0, 0, 0,100}, /*30*/ |
480 | { 0, 0, 0, 0,100}, /*30*/ |
479 | { 0, 0, 0, 0,100}, /*31*/ |
481 | { 0, 0, 0, 0,100}, /*31*/ |
480 | }; |
482 | }; |
481 | |
483 | |
482 | |
484 | |
483 | /* calculate the appropriate level for wands staves and scrolls. If |
485 | /* calculate the appropriate level for wands staves and scrolls. |
484 | * retmult is 1, return the multiplier, not the level, for computing value |
|
|
485 | * This code presumes that op has had its spell object created (in op->inv) |
486 | * This code presumes that op has had its spell object created (in op->inv) |
486 | */ |
487 | * |
|
|
488 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
|
|
489 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
|
|
490 | */ |
487 | |
491 | |
488 | int level_for_item(const object *op, int difficulty, int retmult) |
492 | int level_for_item (const object *op, int difficulty) |
489 | { |
493 | { |
490 | int level, mult, olevel; |
494 | int mult = 0, olevel = 0; |
491 | |
495 | |
492 | mult = 0; |
|
|
493 | if (!op->inv) { |
496 | if (!op->inv) |
|
|
497 | { |
494 | LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name); |
498 | LOG(llevError,"level_for_item: Object %s has no inventory!\n", op->name); |
495 | return 0; |
499 | return 0; |
496 | } |
500 | } |
497 | level = op->inv->level; |
|
|
498 | |
501 | |
499 | /* Basically, we set mult to the lowest spell increase attribute that is |
502 | olevel = op->inv->level + (double) difficulty * (1 - drand48 () * drand48 () * 2); |
500 | * not zero - zero's mean no modification is done, so we don't want those. |
|
|
501 | * given we want non zero results, we can't just use a few MIN's here. |
|
|
502 | */ |
|
|
503 | mult = op->inv->dam_modifier; |
|
|
504 | if (op->inv->range_modifier && (op->inv->range_modifier<mult || mult == 0)) |
|
|
505 | mult = op->inv->range_modifier; |
|
|
506 | if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult==0)) |
|
|
507 | mult = op->inv->duration_modifier; |
|
|
508 | |
503 | |
509 | if (mult == 0) |
504 | if (olevel <= 0) |
510 | mult = 5; |
505 | olevel = rndm (1, MIN (op->inv->level, 1)); |
511 | |
506 | |
512 | if (retmult) |
507 | if (olevel > MAXLEVEL) |
513 | return mult; |
508 | olevel = MAXLEVEL; |
514 | |
509 | |
515 | olevel = mult * rndm(0, difficulty) + level; |
|
|
516 | if (olevel > MAXLEVEL) olevel = MAXLEVEL; |
|
|
517 | |
|
|
518 | return olevel; |
510 | return olevel; |
519 | } |
511 | } |
520 | |
512 | |
521 | /* |
513 | /* |
522 | * Based upon the specified difficulty and upon the difftomagic_list array, |
514 | * Based upon the specified difficulty and upon the difftomagic_list array, |
523 | * a random magical bonus is returned. This is used when determine |
515 | * a random magical bonus is returned. This is used when determine |
524 | * the magical bonus created on specific maps. |
516 | * the magical bonus created on specific maps. |
|
|
517 | * |
|
|
518 | * elmex Thu Aug 10 18:45:44 CEST 2006: |
|
|
519 | * Scaling difficulty by max_level, as difficulty is a level and not some |
|
|
520 | * weird integer between 1-31. |
|
|
521 | * |
525 | */ |
522 | */ |
526 | |
523 | |
527 | int magic_from_difficulty(int difficulty) |
524 | int magic_from_difficulty(int difficulty) |
528 | { |
525 | { |
529 | int percent,loop; |
526 | int percent = 0, magic = 0; |
|
|
527 | int scaled_diff = ((double) difficulty / settings.max_level) * DIFFLEVELS; |
530 | |
528 | |
531 | difficulty--; |
529 | scaled_diff--; |
532 | if(difficulty<0) |
|
|
533 | difficulty=0; |
|
|
534 | |
530 | |
|
|
531 | if(scaled_diff < 0) |
|
|
532 | scaled_diff = 0; |
|
|
533 | |
535 | if (difficulty>=DIFFLEVELS) |
534 | if (scaled_diff >= DIFFLEVELS) |
536 | difficulty=DIFFLEVELS-1; |
535 | scaled_diff = DIFFLEVELS-1; |
537 | |
536 | |
538 | percent = RANDOM()%100; |
537 | percent = RANDOM()%100; |
539 | |
538 | |
540 | for(loop=0;loop<(MAXMAGIC+1);++loop) { |
539 | for(magic = 0; magic < (MAXMAGIC + 1); magic++) |
|
|
540 | { |
541 | percent -= difftomagic_list[difficulty][loop]; |
541 | percent -= difftomagic_list[scaled_diff][magic]; |
|
|
542 | |
542 | if (percent<0) |
543 | if (percent < 0) |
543 | break; |
544 | break; |
544 | } |
545 | } |
545 | if (loop==(MAXMAGIC+1)) { |
546 | |
|
|
547 | if (magic == (MAXMAGIC + 1)) |
|
|
548 | { |
546 | LOG(llevError,"Warning, table for difficulty %d bad.\n",difficulty); |
549 | LOG(llevError,"Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); |
547 | loop=0; |
550 | magic = 0; |
548 | } |
551 | } |
|
|
552 | |
|
|
553 | magic = (RANDOM() % 3) ? magic : -magic; |
|
|
554 | |
549 | /* LOG(llevDebug, "Chose magic %d for difficulty %d\n", loop, difficulty);*/ |
555 | /* LOG(llevDebug, "Chose magic %d for difficulty (scaled %d) %d\n", magic, scaled_diff, difficulty); */ |
550 | return (RANDOM()%3)?loop:-loop; |
556 | |
|
|
557 | return magic; |
551 | } |
558 | } |
552 | |
559 | |
553 | /* |
560 | /* |
554 | * Sets magical bonus in an object, and recalculates the effect on |
561 | * Sets magical bonus in an object, and recalculates the effect on |
555 | * the armour variable, and the effect on speed of armour. |
562 | * the armour variable, and the effect on speed of armour. |
… | |
… | |
755 | * value. |
762 | * value. |
756 | * GT_MINIMAL: Does minimal processing on the object - just enough to make it |
763 | * GT_MINIMAL: Does minimal processing on the object - just enough to make it |
757 | * a working object - don't change magic, value, etc, but set it material |
764 | * a working object - don't change magic, value, etc, but set it material |
758 | * type as appropriate, for objects that need spell objects, set those, etc |
765 | * type as appropriate, for objects that need spell objects, set those, etc |
759 | */ |
766 | */ |
|
|
767 | |
760 | void fix_generated_item (object *op, object *creator, int difficulty, |
768 | void fix_generated_item (object * op, object * creator, int difficulty, |
761 | int max_magic, int flags) |
769 | int max_magic, int flags) |
762 | { |
770 | { |
763 | int was_magic = op->magic, num_enchantments=0, save_item_power; |
771 | int was_magic = op->magic, num_enchantments = 0, save_item_power = 0; |
764 | |
772 | |
765 | if(!creator||creator->type==op->type) creator=op; /*safety & to prevent polymorphed |
773 | if (!creator || creator->type == op->type) |
766 | * objects giving attributes */ |
774 | creator = op; /*safety & to prevent polymorphed objects giving attributes */ |
767 | |
775 | |
768 | /* If we make an artifact, this information will be destroyed */ |
776 | /* If we make an artifact, this information will be destroyed */ |
769 | save_item_power = op->item_power; |
777 | save_item_power = op->item_power; |
770 | op->item_power = 0; |
778 | op->item_power = 0; |
771 | |
779 | |
772 | if (op->randomitems && op->type != SPELL) { |
780 | if (op->randomitems && op->type != SPELL) |
|
|
781 | { |
773 | create_treasure(op->randomitems, op,flags ,difficulty, 0); |
782 | create_treasure (op->randomitems, op, flags, difficulty, 0); |
774 | if (!op->inv) LOG(llevDebug,"fix_generated_item: Unable to generate treasure for %s\n", |
783 | if (!op->inv) |
775 | op->name); |
784 | LOG (llevDebug, |
|
|
785 | "fix_generated_item: Unable to generate treasure for %s\n", |
|
|
786 | op->name); |
|
|
787 | |
776 | /* So the treasure doesn't get created again */ |
788 | /* So the treasure doesn't get created again */ |
777 | op->randomitems = NULL; |
789 | op->randomitems = NULL; |
778 | } |
790 | } |
779 | |
791 | |
780 | if (difficulty<1) difficulty=1; |
792 | if (difficulty < 1) |
|
|
793 | difficulty = 1; |
|
|
794 | |
781 | if (!(flags & GT_MINIMAL)) { |
795 | if (!(flags & GT_MINIMAL)) |
|
|
796 | { |
782 | if (op->arch == crown_arch) { |
797 | if (op->arch == crown_arch) |
|
|
798 | { |
783 | set_magic(difficulty>25?30:difficulty+5, op, max_magic, flags); |
799 | set_magic (difficulty, op, max_magic, flags); |
784 | num_enchantments = calc_item_power(op, 1); |
800 | num_enchantments = calc_item_power (op, 1); |
785 | generate_artifact(op,difficulty); |
801 | generate_artifact (op, difficulty); |
786 | } else { |
802 | } |
|
|
803 | else |
|
|
804 | { |
787 | if(!op->magic && max_magic) |
805 | if (!op->magic && max_magic) |
788 | set_magic(difficulty,op,max_magic, flags); |
806 | set_magic (difficulty, op, max_magic, flags); |
|
|
807 | |
789 | num_enchantments = calc_item_power(op, 1); |
808 | num_enchantments = calc_item_power (op, 1); |
|
|
809 | |
790 | if ((!was_magic && !(RANDOM()%CHANCE_FOR_ARTIFACT)) || op->type == HORN || |
810 | if ((!was_magic && !(RANDOM () % CHANCE_FOR_ARTIFACT)) |
791 | difficulty >= 999 ) |
811 | || op->type == HORN |
|
|
812 | || difficulty >= settings.max_level) /* high difficulties always generate an artifact, |
|
|
813 | * used for shop_floors or treasures */ |
792 | generate_artifact(op, difficulty); |
814 | generate_artifact (op, difficulty); |
793 | } |
815 | } |
794 | |
816 | |
795 | /* Object was made an artifact. Calculate its item_power rating. |
817 | /* Object was made an artifact. Calculate its item_power rating. |
796 | * the item_power in the object is what the artfiact adds. |
818 | * the item_power in the object is what the artfiact adds. |
797 | */ |
819 | */ |
798 | if (op->title) { |
820 | if (op->title) |
|
|
821 | { |
799 | /* if save_item_power is set, then most likely we started with an |
822 | /* if save_item_power is set, then most likely we started with an |
800 | * artifact and have added new abilities to it - this is rare, but |
823 | * artifact and have added new abilities to it - this is rare, but |
801 | * but I have seen things like 'strange rings of fire'. So just figure |
824 | * but I have seen things like 'strange rings of fire'. So just figure |
802 | * out the power from the base power plus what this one adds. Note |
825 | * out the power from the base power plus what this one adds. Note |
803 | * that since item_power is not quite linear, this actually ends up |
826 | * that since item_power is not quite linear, this actually ends up |
804 | * being somewhat of a bonus |
827 | * being somewhat of a bonus |
805 | */ |
828 | */ |
806 | if (save_item_power) { |
829 | if (save_item_power) |
|
|
830 | op->item_power = |
807 | op->item_power = save_item_power + get_power_from_ench(op->item_power); |
831 | save_item_power + get_power_from_ench (op->item_power); |
808 | } else { |
832 | else |
|
|
833 | op->item_power = |
809 | op->item_power = get_power_from_ench(op->item_power + num_enchantments); |
834 | get_power_from_ench (op->item_power + num_enchantments); |
810 | } |
835 | } |
811 | } else if (save_item_power) { |
836 | else if (save_item_power) |
|
|
837 | { |
812 | /* restore the item_power field to the object if we haven't changed it. |
838 | /* restore the item_power field to the object if we haven't changed it. |
813 | * we don't care about num_enchantments - that will basically just |
839 | * we don't care about num_enchantments - that will basically just |
814 | * have calculated some value from the base attributes of the archetype. |
840 | * have calculated some value from the base attributes of the archetype. |
815 | */ |
841 | */ |
816 | op->item_power = save_item_power; |
842 | op->item_power = save_item_power; |
817 | } |
843 | } |
|
|
844 | else |
|
|
845 | { |
|
|
846 | /* item_power was zero. This is suspicious, as it may be because it |
|
|
847 | * was never previously calculated. Let's compute a value and see if |
|
|
848 | * it is non-zero. If it indeed is, then assign it as the new |
|
|
849 | * item_power value. |
|
|
850 | * - gros, 21th of July 2006. |
|
|
851 | */ |
|
|
852 | op->item_power = calc_item_power(op,0); |
|
|
853 | save_item_power = op->item_power; /* Just in case it would get used |
|
|
854 | * again below */ |
|
|
855 | } |
818 | } |
856 | } |
819 | |
857 | |
820 | /* materialtype modifications. Note we allow this on artifacts. */ |
858 | /* materialtype modifications. Note we allow this on artifacts. */ |
821 | |
|
|
822 | set_materialname(op, difficulty, NULL); |
859 | set_materialname (op, difficulty, NULL); |
823 | |
860 | |
824 | if (flags & GT_MINIMAL) { |
861 | if (flags & GT_MINIMAL) |
|
|
862 | { |
825 | if (op->type == POTION) |
863 | if (op->type == POTION) |
826 | /* Handle healing and magic power potions */ |
864 | /* Handle healing and magic power potions */ |
827 | if (op->stats.sp && !op->randomitems) { |
865 | if (op->stats.sp && !op->randomitems) |
828 | object *tmp; |
866 | { |
|
|
867 | object *tmp; |
829 | |
868 | |
830 | tmp = get_archetype(spell_mapping[op->stats.sp]); |
869 | tmp = get_archetype (spell_mapping[op->stats.sp]); |
831 | insert_ob_in_ob(tmp, op); |
870 | insert_ob_in_ob (tmp, op); |
832 | op->stats.sp=0; |
871 | op->stats.sp = 0; |
|
|
872 | } |
833 | } |
873 | } |
834 | } |
|
|
835 | else if (!op->title) /* Only modify object if not special */ |
874 | else if (!op->title) /* Only modify object if not special */ |
836 | switch(op->type) { |
875 | switch (op->type) |
|
|
876 | { |
837 | case WEAPON: |
877 | case WEAPON: |
838 | case ARMOUR: |
878 | case ARMOUR: |
839 | case SHIELD: |
879 | case SHIELD: |
840 | case HELMET: |
880 | case HELMET: |
841 | case CLOAK: |
881 | case CLOAK: |
842 | if (QUERY_FLAG(op, FLAG_CURSED) && !(RANDOM()%4)) |
882 | if (QUERY_FLAG (op, FLAG_CURSED) && !(RANDOM () % 4)) |
843 | set_ring_bonus(op, -DICE2); |
883 | set_ring_bonus (op, -DICE2); |
844 | break; |
884 | break; |
845 | |
885 | |
846 | case BRACERS: |
886 | case BRACERS: |
847 | if (!(RANDOM()%(QUERY_FLAG(op, FLAG_CURSED)?5:20))) { |
887 | if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) |
|
|
888 | { |
848 | set_ring_bonus(op,QUERY_FLAG(op, FLAG_CURSED)?-DICE2:DICE2); |
889 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
849 | if (!QUERY_FLAG(op, FLAG_CURSED)) |
890 | if (!QUERY_FLAG (op, FLAG_CURSED)) |
850 | op->value*=3; |
891 | op->value *= 3; |
851 | } |
892 | } |
852 | break; |
893 | break; |
853 | |
894 | |
854 | case POTION: { |
895 | case POTION: |
|
|
896 | { |
855 | int too_many_tries=0,is_special=0; |
897 | int too_many_tries = 0, is_special = 0; |
856 | |
898 | |
857 | /* Handle healing and magic power potions */ |
899 | /* Handle healing and magic power potions */ |
858 | if (op->stats.sp && !op->randomitems) { |
900 | if (op->stats.sp && !op->randomitems) |
859 | object *tmp; |
901 | { |
|
|
902 | object *tmp; |
860 | |
903 | |
861 | tmp = get_archetype(spell_mapping[op->stats.sp]); |
904 | tmp = get_archetype (spell_mapping[op->stats.sp]); |
862 | insert_ob_in_ob(tmp, op); |
905 | insert_ob_in_ob (tmp, op); |
863 | op->stats.sp=0; |
906 | op->stats.sp = 0; |
864 | } |
907 | } |
865 | |
908 | |
866 | while(!(is_special=special_potion(op)) && !op->inv) { |
909 | while (!(is_special = special_potion (op)) && !op->inv) |
|
|
910 | { |
867 | generate_artifact(op,difficulty); |
911 | generate_artifact (op, difficulty); |
868 | if(too_many_tries++ > 10) break; |
912 | if (too_many_tries++ > 10) |
869 | } |
913 | break; |
|
|
914 | } |
|
|
915 | |
870 | /* don't want to change value for healing/magic power potions, |
916 | /* don't want to change value for healing/magic power potions, |
871 | * since the value set on those is already correct. |
917 | * since the value set on those is already correct. |
872 | */ |
918 | */ |
873 | if (op->inv && op->randomitems) { |
919 | if (op->inv && op->randomitems) |
|
|
920 | { |
874 | /* value multiplier is same as for scrolls */ |
921 | /* value multiplier is same as for scrolls */ |
875 | op->value=(op->value*op->inv->value); |
922 | op->value = (op->value * op->inv->value); |
876 | op->level = op->inv->level/2+ RANDOM()%difficulty + RANDOM()%difficulty; |
923 | op->level = |
877 | } else { |
924 | op->inv->level / 2 + RANDOM () % difficulty |
|
|
925 | + RANDOM () % difficulty; |
|
|
926 | } |
|
|
927 | else |
|
|
928 | { |
878 | FREE_AND_COPY(op->name, "potion"); |
929 | FREE_AND_COPY (op->name, "potion"); |
879 | FREE_AND_COPY(op->name_pl, "potions"); |
930 | FREE_AND_COPY (op->name_pl, "potions"); |
880 | } |
931 | } |
881 | if ( ! (flags & GT_ONLY_GOOD) && RANDOM() % 2) |
932 | if (!(flags & GT_ONLY_GOOD) && RANDOM () % 2) |
882 | SET_FLAG(op, FLAG_CURSED); |
933 | SET_FLAG (op, FLAG_CURSED); |
883 | break; |
934 | break; |
884 | } |
935 | } |
885 | |
936 | |
886 | case AMULET: |
937 | case AMULET: |
887 | if(op->arch==amulet_arch) |
938 | if (op->arch == amulet_arch) |
888 | op->value*=5; /* Since it's not just decoration */ |
939 | op->value *= 5; /* Since it's not just decoration */ |
889 | |
940 | |
890 | case RING: |
941 | case RING: |
891 | if(op->arch==NULL) { |
942 | if (op->arch == NULL) |
|
|
943 | { |
892 | remove_ob(op); |
944 | remove_ob (op); |
893 | free_object(op); |
945 | free_object (op); |
894 | op=NULL; |
946 | op = NULL; |
895 | break; |
947 | break; |
896 | } |
948 | } |
|
|
949 | |
897 | if(op->arch!=ring_arch&&op->arch!=amulet_arch) /* It's a special artifact!*/ |
950 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
898 | break; |
951 | break; |
899 | |
952 | |
900 | if ( ! (flags & GT_ONLY_GOOD) && ! (RANDOM() % 3)) |
953 | if (!(flags & GT_ONLY_GOOD) && !(RANDOM () % 3)) |
901 | SET_FLAG(op, FLAG_CURSED); |
954 | SET_FLAG (op, FLAG_CURSED); |
|
|
955 | |
902 | set_ring_bonus(op,QUERY_FLAG(op, FLAG_CURSED)?-DICE2:DICE2); |
956 | set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); |
|
|
957 | |
903 | if(op->type!=RING) /* Amulets have only one ability */ |
958 | if (op->type != RING) /* Amulets have only one ability */ |
904 | break; |
959 | break; |
905 | if(!(RANDOM()%4)) { |
960 | |
906 | int d=(RANDOM()%2 || QUERY_FLAG(op, FLAG_CURSED))?-DICE2:DICE2; |
961 | if (!(RANDOM () % 4)) |
907 | if(d>0) |
962 | { |
908 | op->value*=3; |
963 | int d = (RANDOM () % 2 |
|
|
964 | || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
|
|
965 | |
|
|
966 | if (d > 0) |
|
|
967 | op->value *= 3; |
|
|
968 | |
909 | set_ring_bonus(op,d); |
969 | set_ring_bonus (op, d); |
910 | if(!(RANDOM()%4)) { |
970 | |
911 | int d=(RANDOM()%3 || QUERY_FLAG(op, FLAG_CURSED))?-DICE2:DICE2; |
971 | if (!(RANDOM () % 4)) |
912 | if(d>0) |
972 | { |
913 | op->value*=5; |
973 | int d = (RANDOM () % 3 |
914 | set_ring_bonus(op,d); |
974 | || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; |
915 | } |
975 | if (d > 0) |
916 | } |
976 | op->value *= 5; |
|
|
977 | set_ring_bonus (op, d); |
|
|
978 | } |
|
|
979 | } |
|
|
980 | |
917 | if(GET_ANIM_ID(op)) |
981 | if (GET_ANIM_ID (op)) |
918 | SET_ANIMATION(op, RANDOM()%((int) NUM_ANIMATIONS(op))); |
982 | SET_ANIMATION (op, RANDOM () % ((int) NUM_ANIMATIONS (op))); |
919 | break; |
|
|
920 | |
983 | |
|
|
984 | break; |
|
|
985 | |
921 | case BOOK: |
986 | case BOOK: |
922 | /* Is it an empty book?, if yes lets make a special |
987 | /* Is it an empty book?, if yes lets make a special |
923 | * msg for it, and tailor its properties based on the |
988 | * msg for it, and tailor its properties based on the |
924 | * creator and/or map level we found it on. |
989 | * creator and/or map level we found it on. |
925 | */ |
990 | */ |
926 | if(!op->msg&&RANDOM()%10) { |
991 | if (!op->msg && RANDOM () % 10) |
|
|
992 | { |
927 | /* set the book level properly */ |
993 | /* set the book level properly */ |
928 | if(creator->level==0 || QUERY_FLAG(creator,FLAG_ALIVE)) { |
994 | if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) |
929 | if(op->map&&op->map->difficulty) |
995 | { |
930 | op->level=RANDOM()%(op->map->difficulty)+RANDOM()%10+1; |
996 | if (op->map && op->map->difficulty) |
931 | else |
997 | op->level = |
932 | op->level=RANDOM()%20+1; |
998 | RANDOM () % (op->map->difficulty) + RANDOM () % 10 + 1; |
933 | } else |
999 | else |
|
|
1000 | op->level = RANDOM () % 20 + 1; |
|
|
1001 | } |
|
|
1002 | else |
934 | op->level=RANDOM()%creator->level; |
1003 | op->level = RANDOM () % creator->level; |
935 | |
1004 | |
936 | tailor_readable_ob(op,(creator&&creator->stats.sp)?creator->stats.sp:-1); |
1005 | tailor_readable_ob (op, |
|
|
1006 | (creator |
|
|
1007 | && creator->stats.sp) ? creator->stats. |
|
|
1008 | sp : -1); |
937 | /* books w/ info are worth more! */ |
1009 | /* books w/ info are worth more! */ |
938 | op->value*=((op->level>10?op->level:(op->level+1)/2)*((strlen(op->msg)/250)+1)); |
1010 | op->value *= |
|
|
1011 | ((op->level > |
|
|
1012 | 10 ? op->level : (op->level + |
|
|
1013 | 1) / 2) * ((strlen (op->msg) / 250) + 1)); |
939 | /* creator related stuff */ |
1014 | /* creator related stuff */ |
940 | |
1015 | |
941 | /* for library, chained books. Note that some monsters have no_pick |
1016 | /* for library, chained books. Note that some monsters have no_pick |
942 | * set - we don't want to set no pick in that case. |
1017 | * set - we don't want to set no pick in that case. |
943 | */ |
1018 | */ |
944 | if(QUERY_FLAG(creator,FLAG_NO_PICK) && |
1019 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && |
945 | !QUERY_FLAG(creator, FLAG_MONSTER)) |
1020 | !QUERY_FLAG (creator, FLAG_MONSTER)) |
946 | SET_FLAG(op,FLAG_NO_PICK); |
1021 | SET_FLAG (op, FLAG_NO_PICK); |
947 | if(creator->slaying&&!op->slaying) /* for check_inv floors */ |
1022 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
948 | op->slaying = add_string(creator->slaying); |
1023 | op->slaying = add_string (creator->slaying); |
949 | |
1024 | |
950 | /* add exp so reading it gives xp (once)*/ |
1025 | /* add exp so reading it gives xp (once) */ |
951 | op->stats.exp = op->value>10000?op->value/5:op->value/10; |
1026 | op->stats.exp = |
952 | } |
1027 | op->value > 10000 ? op->value / 5 : op->value / 10; |
953 | break; |
1028 | } |
|
|
1029 | break; |
954 | |
1030 | |
955 | case SPELLBOOK: |
1031 | case SPELLBOOK: |
956 | op->value=op->value* op->inv->value; |
|
|
957 | /* add exp so learning gives xp */ |
|
|
958 | op->level = op->inv->level; |
|
|
959 | op->stats.exp = op->value; |
|
|
960 | break; |
|
|
961 | |
|
|
962 | case WAND: |
|
|
963 | /* nrof in the treasure list is number of charges, |
|
|
964 | * not number of wands. So copy that into food (charges), |
|
|
965 | * and reset nrof. |
|
|
966 | */ |
|
|
967 | op->stats.food=op->inv->nrof; |
|
|
968 | op->nrof=1; |
|
|
969 | /* If the spell changes by level, choose a random level |
|
|
970 | * for it, and adjust price. If the spell doesn't |
|
|
971 | * change by level, just set the wand to the level of |
|
|
972 | * the spell, and value calculation is simpler. |
|
|
973 | */ |
|
|
974 | if (op->inv->duration_modifier || op->inv->dam_modifier || |
|
|
975 | op->inv->range_modifier) { |
|
|
976 | op->level = level_for_item(op, difficulty, 0); |
|
|
977 | op->value= op->value* op->inv->value * (op->level +50)/ |
|
|
978 | (op->inv->level + 50); |
|
|
979 | } |
|
|
980 | else { |
|
|
981 | op->level = op->inv->level; |
|
|
982 | op->value = op->value * op->inv->value; |
1032 | op->value = op->value * op->inv->value; |
983 | } |
1033 | /* add exp so learning gives xp */ |
984 | break; |
1034 | op->level = op->inv->level; |
|
|
1035 | op->stats.exp = op->value; |
|
|
1036 | break; |
985 | |
1037 | |
|
|
1038 | case WAND: |
|
|
1039 | /* nrof in the treasure list is number of charges, |
|
|
1040 | * not number of wands. So copy that into food (charges), |
|
|
1041 | * and reset nrof. |
|
|
1042 | */ |
|
|
1043 | op->stats.food = op->inv->nrof; |
|
|
1044 | op->nrof = 1; |
|
|
1045 | /* If the spell changes by level, choose a random level |
|
|
1046 | * for it, and adjust price. If the spell doesn't |
|
|
1047 | * change by level, just set the wand to the level of |
|
|
1048 | * the spell, and value calculation is simpler. |
|
|
1049 | */ |
|
|
1050 | if (op->inv->duration_modifier || op->inv->dam_modifier || |
|
|
1051 | op->inv->range_modifier) |
|
|
1052 | { |
|
|
1053 | op->level = level_for_item (op, difficulty); |
|
|
1054 | op->value = op->value * op->inv->value * (op->level + 50) / |
|
|
1055 | (op->inv->level + 50); |
|
|
1056 | } |
|
|
1057 | else |
|
|
1058 | { |
|
|
1059 | op->level = op->inv->level; |
|
|
1060 | op->value = op->value * op->inv->value; |
|
|
1061 | } |
|
|
1062 | break; |
|
|
1063 | |
986 | case ROD: |
1064 | case ROD: |
987 | op->level = level_for_item(op, difficulty, 0); |
1065 | op->level = level_for_item (op, difficulty); |
988 | /* Add 50 to both level an divisor to keep prices a little more |
1066 | /* Add 50 to both level an divisor to keep prices a little more |
989 | * reasonable. Otherwise, a high level version of a low level |
1067 | * reasonable. Otherwise, a high level version of a low level |
990 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
1068 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
991 | * 10 time multiplier). This way, the value are a bit more reasonable. |
1069 | * 10 time multiplier). This way, the value are a bit more reasonable. |
992 | */ |
1070 | */ |
|
|
1071 | op->value = |
993 | op->value= op->value * op->inv->value * (op->level +50) / (op->inv->level + 50); |
1072 | op->value * op->inv->value * (op->level + 50) / (op->inv->level + |
|
|
1073 | 50); |
994 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1074 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
995 | if (op->stats.maxhp) |
1075 | if (op->stats.maxhp) |
996 | op->stats.maxhp *= MAX(op->inv->stats.sp, op->inv->stats.grace); |
1076 | op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); |
997 | else |
1077 | else |
998 | op->stats.maxhp = 2 * MAX(op->inv->stats.sp, op->inv->stats.grace); |
1078 | op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); |
999 | |
1079 | |
1000 | op->stats.hp = op->stats.maxhp; |
1080 | op->stats.hp = op->stats.maxhp; |
1001 | break; |
1081 | break; |
1002 | |
1082 | |
1003 | case SCROLL: |
1083 | case SCROLL: |
1004 | op->level = level_for_item(op, difficulty, 0); |
1084 | op->level = level_for_item (op, difficulty); |
1005 | op->value= op->value * op->inv->value * (op->level +50) / (op->inv->level + 50); |
1085 | op->value = |
|
|
1086 | op->value * op->inv->value |
|
|
1087 | * (op->level + 50) / (op->inv->level + 50); |
|
|
1088 | |
1006 | /* add exp so reading them properly gives xp */ |
1089 | /* add exp so reading them properly gives xp */ |
1007 | op->stats.exp = op->value/5; |
1090 | op->stats.exp = op->value / 5; |
1008 | op->nrof = op->inv->nrof; |
1091 | op->nrof = op->inv->nrof; |
1009 | break; |
1092 | break; |
1010 | |
1093 | |
1011 | case RUNE: |
1094 | case RUNE: |
1012 | trap_adjust(op,difficulty); |
1095 | trap_adjust (op, difficulty); |
1013 | break; |
1096 | break; |
1014 | |
1097 | |
1015 | case TRAP: |
1098 | case TRAP: |
1016 | trap_adjust(op,difficulty); |
1099 | trap_adjust (op, difficulty); |
1017 | break; |
1100 | break; |
1018 | } /* switch type */ |
1101 | } /* switch type */ |
1019 | |
1102 | |
1020 | if (flags & GT_STARTEQUIP) { |
1103 | if (flags & GT_STARTEQUIP) |
|
|
1104 | { |
1021 | if (op->nrof < 2 && op->type != CONTAINER |
1105 | if (op->nrof < 2 && op->type != CONTAINER |
1022 | && op->type != MONEY && ! QUERY_FLAG (op, FLAG_IS_THROWN)) |
1106 | && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) |
1023 | SET_FLAG (op, FLAG_STARTEQUIP); |
1107 | SET_FLAG (op, FLAG_STARTEQUIP); |
1024 | else if (op->type != MONEY) |
1108 | else if (op->type != MONEY) |
1025 | op->value = 0; |
1109 | op->value = 0; |
1026 | } |
1110 | } |
1027 | |
1111 | |
1028 | if ( ! (flags & GT_ENVIRONMENT)) |
1112 | if (!(flags & GT_ENVIRONMENT)) |
1029 | fix_flesh_item (op, creator); |
1113 | fix_flesh_item (op, creator); |
1030 | } |
1114 | } |
1031 | |
1115 | |
1032 | /* |
1116 | /* |
1033 | * |
1117 | * |
1034 | * |
1118 | * |