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.93 by root, Tue Nov 10 04:38:45 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
887 * again below */ 904 * again below */
888 } 905 }
889 } 906 }
890 907
891 /* materialtype modifications. Note we allow this on artifacts. */ 908 /* materialtype modifications. Note we allow this on artifacts. */
892 set_materialname (op, difficulty, NULL); 909 select_material (op, difficulty);
893 910
894 if (flags & GT_MINIMAL) 911 if (flags & GT_MINIMAL)
895 { 912 {
896 if (op->type == POTION) 913 if (op->type == POTION)
897 /* Handle healing and magic power potions */ 914 /* Handle healing and magic power potions */
1080 * 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.
1081 */ 1098 */
1082 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);
1083 /* 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 */
1084 if (op->stats.maxhp) 1101 if (op->stats.maxhp)
1085 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);
1086 else 1103 else
1087 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);
1088 1105
1089 op->stats.hp = op->stats.maxhp; 1106 op->stats.hp = op->stats.maxhp;
1090 break; 1107 break;
1091 1108
1092 case SCROLL: 1109 case SCROLL:
1448 op->value *= change->value; 1465 op->value *= change->value;
1449 1466
1450 if (change->materials) 1467 if (change->materials)
1451 op->materials = change->materials; 1468 op->materials = change->materials;
1452 1469
1453 if (change->materialname) 1470 if (change->material != &material_null)
1454 op->materialname = change->materialname; 1471 op->material = change->material;
1455 1472
1456 if (change->slaying) 1473 if (change->slaying)
1457 op->slaying = change->slaying; 1474 op->slaying = change->slaying;
1458 1475
1459 if (change->race) 1476 if (change->race)
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
1694free_artifactlist (artifactlist *al)
1695{
1696 artifactlist *nextal;
1697
1698 for (al = first_artifactlist; al; al = nextal)
1699 {
1700 nextal = al->next;
1701
1702 if (al->items)
1703 free_artifact (al->items);
1704
1705 sfree (al);
1706 }
1707}
1708
1709void
1710free_all_treasures (void)
1711{
1712 treasurelist *tl, *next;
1713
1714 for (tl = first_treasurelist; tl; tl = next)
1715 {
1716 clear (tl);
1717
1718 next = tl->next;
1719 delete tl;
1720 }
1721
1722 free_artifactlist (first_artifactlist);
1723}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines