ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/treasure.C
(Generate patch)

Comparing deliantra/server/common/treasure.C (file contents):
Revision 1.34 by root, Sat Jan 20 22:09:51 2007 UTC vs.
Revision 1.35 by root, Sat Jan 27 02:19:36 2007 UTC

348 { 348 {
349 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE))) 349 if (t->item && (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)))
350 { 350 {
351 tmp = arch_to_object (t->item); 351 tmp = arch_to_object (t->item);
352 if (t->nrof && tmp->nrof <= 1) 352 if (t->nrof && tmp->nrof <= 1)
353 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 353 tmp->nrof = rndm (t->nrof) + 1;
354
354 fix_generated_item (tmp, op, difficulty, t->magic, flag); 355 fix_generated_item (tmp, op, difficulty, t->magic, flag);
355 change_treasure (t, tmp); 356 change_treasure (t, tmp);
356 put_treasure (tmp, op, flag); 357 put_treasure (tmp, op, flag);
357 } 358 }
358 } 359 }
366 if (t->next != NULL) 367 if (t->next != NULL)
367 create_all_treasures (t->next, op, flag, difficulty, tries); 368 create_all_treasures (t->next, op, flag, difficulty, tries);
368} 369}
369 370
370void 371void
371create_one_treasure (treasurelist * tl, object *op, int flag, int difficulty, int tries) 372create_one_treasure (treasurelist *tl, object *op, int flag, int difficulty, int tries)
372{ 373{
373 int value = RANDOM () % tl->total_chance; 374 int value = rndm (tl->total_chance);
374 treasure *t; 375 treasure *t;
375 376
376 if (tries++ > 100) 377 if (tries++ > 100)
377 { 378 {
378 LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n"); 379 LOG (llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n");
414 415
415 if (!tmp) 416 if (!tmp)
416 return; 417 return;
417 418
418 if (t->nrof && tmp->nrof <= 1) 419 if (t->nrof && tmp->nrof <= 1)
419 tmp->nrof = RANDOM () % ((int) t->nrof) + 1; 420 tmp->nrof = rndm (t->nrof) + 1;
420 421
421 fix_generated_item (tmp, op, difficulty, t->magic, flag); 422 fix_generated_item (tmp, op, difficulty, t->magic, flag);
422 change_treasure (t, tmp); 423 change_treasure (t, tmp);
423 put_treasure (tmp, op, flag); 424 put_treasure (tmp, op, flag);
424 } 425 }
658 659
659void 660void
660set_ring_bonus (object *op, int bonus) 661set_ring_bonus (object *op, int bonus)
661{ 662{
662 663
663 int r = RANDOM () % (bonus > 0 ? 25 : 11); 664 int r = rndm (bonus > 0 ? 25 : 11);
664 665
665 if (op->type == AMULET) 666 if (op->type == AMULET)
666 { 667 {
667 if (!(rndm (21))) 668 if (!(rndm (21)))
668 r = 20 + rndm (2); 669 r = 20 + rndm (2);
669 else 670 else
670 { 671 {
671 if (RANDOM () & 2) 672 if (rndm (2))
672 r = 10; 673 r = 10;
673 else 674 else
674 r = 11 + rndm (9); 675 r = 11 + rndm (9);
675 } 676 }
676 } 677 }
727 * positive values for how protections work out. Put another 728 * positive values for how protections work out. Put another
728 * little random element in since that they don't always end up with 729 * little random element in since that they don't always end up with
729 * even values. 730 * even values.
730 */ 731 */
731 if (bonus < 0) 732 if (bonus < 0)
732 val = 2 * -val - RANDOM () % b; 733 val = 2 * -val - rndm (b);
733 if (val > 35) 734 if (val > 35)
734 val = 35; /* Upper limit */ 735 val = 35; /* Upper limit */
735 b = 0; 736 b = 0;
736 737
737 while (op->resist[resist_table[resist]] != 0 && b < 4) 738 while (op->resist[resist_table[resist]] != 0 && b < 4)
790 * higher is the chance of returning a low number. 791 * higher is the chance of returning a low number.
791 * It is only used in fix_generated_treasure() to set bonuses on 792 * It is only used in fix_generated_treasure() to set bonuses on
792 * rings and amulets. 793 * rings and amulets.
793 * Another scheme is used to calculate the magic of weapons and armours. 794 * Another scheme is used to calculate the magic of weapons and armours.
794 */ 795 */
795
796int 796int
797get_magic (int diff) 797get_magic (int diff)
798{ 798{
799 int i; 799 int i;
800 800
801 if (diff < 3) 801 if (diff < 3)
802 diff = 3; 802 diff = 3;
803
803 for (i = 0; i < 4; i++) 804 for (i = 0; i < 4; i++)
804 if (RANDOM () % diff) 805 if (rndm (diff))
805 return i; 806 return i;
807
806 return 4; 808 return 4;
807} 809}
808 810
809#define DICE2 (get_magic(2)==2?2:1) 811#define DICE2 (get_magic(2)==2?2:1)
810#define DICESPELL (rndm (3)+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3) 812#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
811 813
812/* 814/*
813 * fix_generated_item(): This is called after an item is generated, in 815 * fix_generated_item(): This is called after an item is generated, in
814 * order to set it up right. This produced magical bonuses, puts spells 816 * order to set it up right. This produced magical bonuses, puts spells
815 * into scrolls/books/wands, makes it unidentified, hides the value, etc. 817 * into scrolls/books/wands, makes it unidentified, hides the value, etc.
876 if (!op->magic && max_magic) 878 if (!op->magic && max_magic)
877 set_magic (difficulty, op, max_magic, flags); 879 set_magic (difficulty, op, max_magic, flags);
878 880
879 num_enchantments = calc_item_power (op, 1); 881 num_enchantments = calc_item_power (op, 1);
880 882
881 if ((!was_magic && !(RANDOM () % CHANCE_FOR_ARTIFACT)) || op->type == HORN || difficulty >= settings.max_level) /* high difficulties always generate an artifact, 883 if ((!was_magic && !rndm (CHANCE_FOR_ARTIFACT))
884 || op->type == HORN
885 || difficulty >= settings.max_level) /* high difficulties always generate an artifact,
882 * used for shop_floors or treasures */ 886 * used for shop_floors or treasures */
883 generate_artifact (op, difficulty); 887 generate_artifact (op, difficulty);
884 } 888 }
885 889
886 /* Object was made an artifact. Calculate its item_power rating. 890 /* Object was made an artifact. Calculate its item_power rating.
949 if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) 953 if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4)))
950 set_ring_bonus (op, -DICE2); 954 set_ring_bonus (op, -DICE2);
951 break; 955 break;
952 956
953 case BRACERS: 957 case BRACERS:
954 if (!(RANDOM () % (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))) 958 if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20))
955 { 959 {
956 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); 960 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2);
957 if (!QUERY_FLAG (op, FLAG_CURSED)) 961 if (!QUERY_FLAG (op, FLAG_CURSED))
958 op->value *= 3; 962 op->value *= 3;
959 } 963 }
985 */ 989 */
986 if (op->inv && op->randomitems) 990 if (op->inv && op->randomitems)
987 { 991 {
988 /* value multiplier is same as for scrolls */ 992 /* value multiplier is same as for scrolls */
989 op->value = (op->value * op->inv->value); 993 op->value = (op->value * op->inv->value);
990 op->level = op->inv->level / 2 + RANDOM () % difficulty + RANDOM () % difficulty; 994 op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty);
991 } 995 }
992 else 996 else
993 { 997 {
994 op->name = "potion"; 998 op->name = "potion";
995 op->name_pl = "potions"; 999 op->name_pl = "potions";
1041 set_ring_bonus (op, d); 1045 set_ring_bonus (op, d);
1042 } 1046 }
1043 } 1047 }
1044 1048
1045 if (GET_ANIM_ID (op)) 1049 if (GET_ANIM_ID (op))
1046 SET_ANIMATION (op, RANDOM () % ((int) NUM_ANIMATIONS (op))); 1050 SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op)));
1047 1051
1048 break; 1052 break;
1049 1053
1050 case BOOK: 1054 case BOOK:
1051 /* Is it an empty book?, if yes lets make a specialĀ· 1055 /* Is it an empty book?, if yes lets make a specialĀ·
1056 { 1060 {
1057 /* set the book level properly */ 1061 /* set the book level properly */
1058 if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) 1062 if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE))
1059 { 1063 {
1060 if (op->map && op->map->difficulty) 1064 if (op->map && op->map->difficulty)
1061 op->level = RANDOM () % (op->map->difficulty) + rndm (10) + 1; 1065 op->level = rndm (op->map->difficulty) + rndm (10) + 1;
1062 else 1066 else
1063 op->level = rndm (20) + 1; 1067 op->level = rndm (20) + 1;
1064 } 1068 }
1065 else 1069 else
1066 op->level = RANDOM () % creator->level; 1070 op->level = rndm (creator->level);
1067 1071
1068 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); 1072 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1);
1069 /* books w/ info are worth more! */ 1073 /* books w/ info are worth more! */
1070 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); 1074 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1));
1071 /* creator related stuff */ 1075 /* creator related stuff */
1502 1506
1503 op->set_speed (op->speed); 1507 op->set_speed (op->speed);
1504 } 1508 }
1505 1509
1506 if (change->nrof) 1510 if (change->nrof)
1507 op->nrof = RANDOM () % ((int) change->nrof) + 1; 1511 op->nrof = rndm (change->nrof) + 1;
1508 1512
1509 op->stats.exp += change->stats.exp; /* Speed modifier */ 1513 op->stats.exp += change->stats.exp; /* Speed modifier */
1510 op->stats.wc += change->stats.wc; 1514 op->stats.wc += change->stats.wc;
1511 op->stats.ac += change->stats.ac; 1515 op->stats.ac += change->stats.ac;
1512 1516
1720 return; 1724 return;
1721 } 1725 }
1722 1726
1723 for (i = 0; i < ARTIFACT_TRIES; i++) 1727 for (i = 0; i < ARTIFACT_TRIES; i++)
1724 { 1728 {
1725 int roll = RANDOM () % al->total_chance; 1729 int roll = rndm (al->total_chance);
1726 1730
1727 for (art = al->items; art != NULL; art = art->next) 1731 for (art = al->items; art; art = art->next)
1728 { 1732 {
1729 roll -= art->chance; 1733 roll -= art->chance;
1730 if (roll < 0) 1734 if (roll < 0)
1731 break; 1735 break;
1732 } 1736 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines