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.87 by sf-marcmagus, Thu Oct 15 16:00:37 2009 UTC vs.
Revision 1.89 by root, Fri Nov 6 13:03:34 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
1641 1658
1642 SET_FLAG (item, FLAG_NO_STEAL); 1659 SET_FLAG (item, FLAG_NO_STEAL);
1643 } 1660 }
1644} 1661}
1645 1662
1646/* special_potion() - so that old potion code is still done right. */ 1663static void
1647int
1648special_potion (object *op)
1649{
1650 if (op->attacktype)
1651 return 1;
1652
1653 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1654 return 1;
1655
1656 for (int i = 0; i < NROFATTACKS; i++)
1657 if (op->resist[i])
1658 return 1;
1659
1660 return 0;
1661}
1662
1663void
1664free_treasurestruct (treasure *t) 1664free_treasurestruct (treasure *t)
1665{ 1665{
1666 if (t->next) free_treasurestruct (t->next); 1666 if (t->next) free_treasurestruct (t->next);
1667 if (t->next_yes) free_treasurestruct (t->next_yes); 1667 if (t->next_yes) free_treasurestruct (t->next_yes);
1668 if (t->next_no) free_treasurestruct (t->next_no); 1668 if (t->next_no) free_treasurestruct (t->next_no);
1669 1669
1670 delete t; 1670 delete t;
1671} 1671}
1672 1672
1673void 1673static void
1674free_charlinks (linked_char *lc) 1674free_charlinks (linked_char *lc)
1675{ 1675{
1676 if (lc->next) 1676 if (lc->next)
1677 free_charlinks (lc->next); 1677 free_charlinks (lc->next);
1678 1678
1679 delete lc; 1679 delete lc;
1680} 1680}
1681 1681
1682void 1682static void
1683free_artifact (artifact *at) 1683free_artifact (artifact *at)
1684{ 1684{
1685 if (at->next) free_artifact (at->next); 1685 if (at->next) free_artifact (at->next);
1686 if (at->allowed) free_charlinks (at->allowed); 1686 if (at->allowed) free_charlinks (at->allowed);
1687 1687
1688 at->item->destroy (); 1688 at->item->destroy ();
1689 1689
1690 sfree (at); 1690 sfree (at);
1691} 1691}
1692 1692
1693void 1693static void
1694free_artifactlist (artifactlist *al) 1694free_artifactlist (artifactlist *al)
1695{ 1695{
1696 artifactlist *nextal; 1696 artifactlist *nextal;
1697 1697
1698 for (al = first_artifactlist; al; al = nextal) 1698 for (al = first_artifactlist; al; al = nextal)
1704 1704
1705 sfree (al); 1705 sfree (al);
1706 } 1706 }
1707} 1707}
1708 1708
1709void 1709static void
1710free_all_treasures (void) 1710free_all_treasures (void)
1711{ 1711{
1712 treasurelist *tl, *next; 1712 treasurelist *tl, *next;
1713 1713
1714 for (tl = first_treasurelist; tl; tl = next) 1714 for (tl = first_treasurelist; tl; tl = next)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines