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.86 by root, Mon Oct 12 14:00:57 2009 UTC vs.
Revision 1.92 by root, Sat Nov 7 18:30:05 2009 UTC

51 slice_allocator< std::pair<const char *const, treasurelist *> > 51 slice_allocator< std::pair<const char *const, treasurelist *> >
52> tl_map_t; 52> tl_map_t;
53 53
54static tl_map_t tl_map; 54static tl_map_t tl_map;
55 55
56//TODO: class method
57static void free_treasurestruct (treasure *t); // bleh desu
58static void
59clear (treasurelist *tl)
60{
61 if (tl->items)
62 {
63 free_treasurestruct (tl->items);
64 tl->items = 0;
65 }
66
67 tl->total_chance = 0;
68}
69
56/* 70/*
57 * Searches for the given treasurelist 71 * Searches for the given treasurelist
58 */ 72 */
59treasurelist * 73treasurelist *
60treasurelist::find (const char *name) 74treasurelist::find (const char *name)
89 103
90 tl_map.insert (std::make_pair (tl->name, tl)); 104 tl_map.insert (std::make_pair (tl->name, tl));
91 } 105 }
92 106
93 return tl; 107 return tl;
94}
95
96//TODO: class method
97void
98clear (treasurelist *tl)
99{
100 if (tl->items)
101 {
102 free_treasurestruct (tl->items);
103 tl->items = 0;
104 }
105
106 tl->total_chance = 0;
107} 108}
108 109
109#ifdef TREASURE_DEBUG 110#ifdef TREASURE_DEBUG
110/* recursived checks the linked list. Treasurelist is passed only 111/* recursived checks the linked list. Treasurelist is passed only
111 * so that the treasure name can be printed out 112 * so that the treasure name can be printed out
495 * This code presumes that op has had its spell object created (in op->inv) 496 * This code presumes that op has had its spell object created (in op->inv)
496 * 497 *
497 * elmex Wed Aug 9 17:44:59 CEST 2006: 498 * elmex Wed Aug 9 17:44:59 CEST 2006:
498 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 499 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
499 */ 500 */
500int 501static int
501level_for_item (const object *op, int difficulty) 502level_for_item (const object *op, int difficulty)
502{ 503{
503 if (!op->inv) 504 if (!op->inv)
504 { 505 {
505 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); 506 LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name);
522 * elmex Thu Aug 10 18:45:44 CEST 2006: 523 * elmex Thu Aug 10 18:45:44 CEST 2006:
523 * Scaling difficulty by max_level, as difficulty is a level and not some 524 * Scaling difficulty by max_level, as difficulty is a level and not some
524 * weird integer between 1-31. 525 * weird integer between 1-31.
525 * 526 *
526 */ 527 */
527int 528static int
528magic_from_difficulty (int difficulty) 529magic_from_difficulty (int difficulty)
529{ 530{
530 int percent = 0, magic = 0; 531 int percent = 0, magic = 0;
531 int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); 532 int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS);
532 533
622 * 1) Since rings can have multiple bonuses, if the same bonus 623 * 1) Since rings can have multiple bonuses, if the same bonus
623 * is rolled again, increase it - the bonuses now stack with 624 * is rolled again, increase it - the bonuses now stack with
624 * other bonuses previously rolled and ones the item might natively have. 625 * other bonuses previously rolled and ones the item might natively have.
625 * 2) Add code to deal with new PR method. 626 * 2) Add code to deal with new PR method.
626 */ 627 */
627void 628static void
628set_ring_bonus (object *op, int bonus) 629set_ring_bonus (object *op, int bonus)
629{ 630{
630
631 int r = rndm (bonus > 0 ? 25 : 11); 631 int r = rndm (bonus > 0 ? 25 : 11);
632 632
633 if (op->type == AMULET) 633 if (op->type == AMULET)
634 { 634 {
635 if (!(rndm (21))) 635 if (!(rndm (21)))
758 * higher is the chance of returning a low number. 758 * higher is the chance of returning a low number.
759 * It is only used in fix_generated_treasure() to set bonuses on 759 * It is only used in fix_generated_treasure() to set bonuses on
760 * rings and amulets. 760 * rings and amulets.
761 * Another scheme is used to calculate the magic of weapons and armours. 761 * Another scheme is used to calculate the magic of weapons and armours.
762 */ 762 */
763int 763static int
764get_magic (int diff) 764get_magic (int diff)
765{ 765{
766 int i; 766 int i;
767 767
768 if (diff < 3) 768 if (diff < 3)
771 for (i = 0; i < 4; i++) 771 for (i = 0; i < 4; i++)
772 if (rndm (diff)) 772 if (rndm (diff))
773 return i; 773 return i;
774 774
775 return 4; 775 return 4;
776}
777
778/* special_potion() - so that old potion code is still done right. */
779static int
780special_potion (object *op)
781{
782 if (op->attacktype)
783 return 1;
784
785 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
786 return 1;
787
788 for (int i = 0; i < NROFATTACKS; i++)
789 if (op->resist[i])
790 return 1;
791
792 return 0;
776} 793}
777 794
778#define DICE2 (get_magic(2)==2?2:1) 795#define DICE2 (get_magic(2)==2?2:1)
779#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) 796#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
780 797
1023 op->level = rndm (creator->level); 1040 op->level = rndm (creator->level);
1024 1041
1025 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); 1042 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1);
1026 /* books w/ info are worth more! */ 1043 /* books w/ info are worth more! */
1027 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); 1044 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1));
1028 /* creator related stuff */
1029
1030 /* for library, chained books. Note that some monsters have no_pick
1031 * set - we don't want to set no pick in that case.
1032 */
1033 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1034 SET_FLAG (op, FLAG_NO_PICK);
1035 if (creator->slaying && !op->slaying) /* for check_inv floors */
1036 op->slaying = creator->slaying;
1037 1045
1038 /* add exp so reading it gives xp (once) */ 1046 /* add exp so reading it gives xp (once) */
1039 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; 1047 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10;
1040 } 1048 }
1049
1050 /* creator related stuff */
1051
1052 /* for library, chained books. Note that some monsters have no_pick
1053 * set - we don't want to set no pick in that case.
1054 */
1055 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1056 SET_FLAG (op, FLAG_NO_PICK);
1057 if (creator->slaying && !op->slaying) /* for check_inv floors */
1058 op->slaying = creator->slaying;
1041 break; 1059 break;
1042 1060
1043 case SPELLBOOK: 1061 case SPELLBOOK:
1044 op->value = op->value * op->inv->value; 1062 op->value = op->value * op->inv->value;
1045 /* add exp so learning gives xp */ 1063 /* add exp so learning gives xp */
1079 * 10 time multiplier). This way, the value are a bit more reasonable. 1097 * 10 time multiplier). This way, the value are a bit more reasonable.
1080 */ 1098 */
1081 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); 1099 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1082 /* 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 */
1083 if (op->stats.maxhp) 1101 if (op->stats.maxhp)
1084 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);
1085 else 1103 else
1086 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);
1087 1105
1088 op->stats.hp = op->stats.maxhp; 1106 op->stats.hp = op->stats.maxhp;
1089 break; 1107 break;
1090 1108
1091 case SCROLL: 1109 case SCROLL:
1640 1658
1641 SET_FLAG (item, FLAG_NO_STEAL); 1659 SET_FLAG (item, FLAG_NO_STEAL);
1642 } 1660 }
1643} 1661}
1644 1662
1645/* special_potion() - so that old potion code is still done right. */ 1663static void
1646int
1647special_potion (object *op)
1648{
1649 if (op->attacktype)
1650 return 1;
1651
1652 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1653 return 1;
1654
1655 for (int i = 0; i < NROFATTACKS; i++)
1656 if (op->resist[i])
1657 return 1;
1658
1659 return 0;
1660}
1661
1662void
1663free_treasurestruct (treasure *t) 1664free_treasurestruct (treasure *t)
1664{ 1665{
1665 if (t->next) free_treasurestruct (t->next); 1666 if (t->next) free_treasurestruct (t->next);
1666 if (t->next_yes) free_treasurestruct (t->next_yes); 1667 if (t->next_yes) free_treasurestruct (t->next_yes);
1667 if (t->next_no) free_treasurestruct (t->next_no); 1668 if (t->next_no) free_treasurestruct (t->next_no);
1668 1669
1669 delete t; 1670 delete t;
1670} 1671}
1671 1672
1672void 1673static void
1673free_charlinks (linked_char *lc) 1674free_charlinks (linked_char *lc)
1674{ 1675{
1675 if (lc->next) 1676 if (lc->next)
1676 free_charlinks (lc->next); 1677 free_charlinks (lc->next);
1677 1678
1678 delete lc; 1679 delete lc;
1679} 1680}
1680 1681
1681void 1682static void
1682free_artifact (artifact *at) 1683free_artifact (artifact *at)
1683{ 1684{
1684 if (at->next) free_artifact (at->next); 1685 if (at->next) free_artifact (at->next);
1685 if (at->allowed) free_charlinks (at->allowed); 1686 if (at->allowed) free_charlinks (at->allowed);
1686 1687
1687 at->item->destroy (); 1688 at->item->destroy ();
1688 1689
1689 sfree (at); 1690 sfree (at);
1690} 1691}
1691 1692
1692void
1693free_artifactlist (artifactlist *al)
1694{
1695 artifactlist *nextal;
1696
1697 for (al = first_artifactlist; al; al = nextal)
1698 {
1699 nextal = al->next;
1700
1701 if (al->items)
1702 free_artifact (al->items);
1703
1704 sfree (al);
1705 }
1706}
1707
1708void
1709free_all_treasures (void)
1710{
1711 treasurelist *tl, *next;
1712
1713 for (tl = first_treasurelist; tl; tl = next)
1714 {
1715 clear (tl);
1716
1717 next = tl->next;
1718 delete tl;
1719 }
1720
1721 free_artifactlist (first_artifactlist);
1722}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines