… | |
… | |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
25 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
… | |
… | |
50 | slice_allocator< std::pair<const char *const, treasurelist *> > |
51 | slice_allocator< std::pair<const char *const, treasurelist *> > |
51 | > tl_map_t; |
52 | > tl_map_t; |
52 | |
53 | |
53 | static tl_map_t tl_map; |
54 | static tl_map_t tl_map; |
54 | |
55 | |
|
|
56 | //TODO: class method |
|
|
57 | static void |
|
|
58 | clear (treasurelist *tl) |
|
|
59 | { |
|
|
60 | void free_treasurestruct (treasure *t); |
|
|
61 | |
|
|
62 | if (tl->items) |
|
|
63 | { |
|
|
64 | free_treasurestruct (tl->items); |
|
|
65 | tl->items = 0; |
|
|
66 | } |
|
|
67 | |
|
|
68 | tl->total_chance = 0; |
|
|
69 | } |
|
|
70 | |
55 | /* |
71 | /* |
56 | * Searches for the given treasurelist |
72 | * Searches for the given treasurelist |
57 | */ |
73 | */ |
58 | treasurelist * |
74 | treasurelist * |
59 | treasurelist::find (const char *name) |
75 | treasurelist::find (const char *name) |
… | |
… | |
88 | |
104 | |
89 | tl_map.insert (std::make_pair (tl->name, tl)); |
105 | tl_map.insert (std::make_pair (tl->name, tl)); |
90 | } |
106 | } |
91 | |
107 | |
92 | return tl; |
108 | return tl; |
93 | } |
|
|
94 | |
|
|
95 | //TODO: class method |
|
|
96 | void |
|
|
97 | clear (treasurelist *tl) |
|
|
98 | { |
|
|
99 | if (tl->items) |
|
|
100 | { |
|
|
101 | free_treasurestruct (tl->items); |
|
|
102 | tl->items = 0; |
|
|
103 | } |
|
|
104 | |
|
|
105 | tl->total_chance = 0; |
|
|
106 | } |
109 | } |
107 | |
110 | |
108 | #ifdef TREASURE_DEBUG |
111 | #ifdef TREASURE_DEBUG |
109 | /* recursived checks the linked list. Treasurelist is passed only |
112 | /* recursived checks the linked list. Treasurelist is passed only |
110 | * so that the treasure name can be printed out |
113 | * so that the treasure name can be printed out |
… | |
… | |
772 | return i; |
775 | return i; |
773 | |
776 | |
774 | return 4; |
777 | return 4; |
775 | } |
778 | } |
776 | |
779 | |
|
|
780 | /* special_potion() - so that old potion code is still done right. */ |
|
|
781 | int |
|
|
782 | special_potion (object *op) |
|
|
783 | { |
|
|
784 | if (op->attacktype) |
|
|
785 | return 1; |
|
|
786 | |
|
|
787 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
|
|
788 | return 1; |
|
|
789 | |
|
|
790 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
791 | if (op->resist[i]) |
|
|
792 | return 1; |
|
|
793 | |
|
|
794 | return 0; |
|
|
795 | } |
|
|
796 | |
777 | #define DICE2 (get_magic(2)==2?2:1) |
797 | #define DICE2 (get_magic(2)==2?2:1) |
778 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
798 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
779 | |
799 | |
780 | /* |
800 | /* |
781 | * fix_generated_item(): This is called after an item is generated, in |
801 | * fix_generated_item(): This is called after an item is generated, in |
… | |
… | |
996 | op->value *= 5; |
1016 | op->value *= 5; |
997 | set_ring_bonus (op, d); |
1017 | set_ring_bonus (op, d); |
998 | } |
1018 | } |
999 | } |
1019 | } |
1000 | |
1020 | |
1001 | if (GET_ANIM_ID (op)) |
1021 | if (op->animation_id) |
1002 | SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); |
1022 | op->set_anim_frame (rndm (op->anim_frames ())); |
1003 | |
1023 | |
1004 | break; |
1024 | break; |
1005 | |
1025 | |
1006 | case BOOK: |
1026 | case BOOK: |
1007 | /* Is it an empty book?, if yes lets make a special· |
1027 | /* Is it an empty book?, if yes lets make a special· |
… | |
… | |
1022 | op->level = rndm (creator->level); |
1042 | op->level = rndm (creator->level); |
1023 | |
1043 | |
1024 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |
1044 | tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); |
1025 | /* books w/ info are worth more! */ |
1045 | /* books w/ info are worth more! */ |
1026 | op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); |
1046 | op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); |
1027 | /* creator related stuff */ |
|
|
1028 | |
|
|
1029 | /* for library, chained books. Note that some monsters have no_pick |
|
|
1030 | * set - we don't want to set no pick in that case. |
|
|
1031 | */ |
|
|
1032 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) |
|
|
1033 | SET_FLAG (op, FLAG_NO_PICK); |
|
|
1034 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
|
|
1035 | op->slaying = creator->slaying; |
|
|
1036 | |
1047 | |
1037 | /* add exp so reading it gives xp (once) */ |
1048 | /* add exp so reading it gives xp (once) */ |
1038 | op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; |
1049 | op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; |
1039 | } |
1050 | } |
|
|
1051 | |
|
|
1052 | /* creator related stuff */ |
|
|
1053 | |
|
|
1054 | /* for library, chained books. Note that some monsters have no_pick |
|
|
1055 | * set - we don't want to set no pick in that case. |
|
|
1056 | */ |
|
|
1057 | if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) |
|
|
1058 | SET_FLAG (op, FLAG_NO_PICK); |
|
|
1059 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
|
|
1060 | op->slaying = creator->slaying; |
1040 | break; |
1061 | break; |
1041 | |
1062 | |
1042 | case SPELLBOOK: |
1063 | case SPELLBOOK: |
1043 | op->value = op->value * op->inv->value; |
1064 | op->value = op->value * op->inv->value; |
1044 | /* add exp so learning gives xp */ |
1065 | /* add exp so learning gives xp */ |
… | |
… | |
1566 | #if 1 |
1587 | #if 1 |
1567 | LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); |
1588 | LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); |
1568 | #endif |
1589 | #endif |
1569 | return; |
1590 | return; |
1570 | } |
1591 | } |
1571 | if (!strcmp (art->item->name, "NONE")) |
1592 | |
|
|
1593 | if (art->item->name == shstr_NONE) |
1572 | return; |
1594 | return; |
|
|
1595 | |
1573 | if (FABS (op->magic) < art->item->magic) |
1596 | if (fabs (op->magic) < art->item->magic) |
1574 | continue; /* Not magic enough to be this item */ |
1597 | continue; /* Not magic enough to be this item */ |
1575 | |
1598 | |
1576 | /* Map difficulty not high enough */ |
1599 | /* Map difficulty not high enough */ |
1577 | if (difficulty < art->difficulty) |
1600 | if (difficulty < art->difficulty) |
1578 | continue; |
1601 | continue; |
… | |
… | |
1637 | |
1660 | |
1638 | SET_FLAG (item, FLAG_NO_STEAL); |
1661 | SET_FLAG (item, FLAG_NO_STEAL); |
1639 | } |
1662 | } |
1640 | } |
1663 | } |
1641 | |
1664 | |
1642 | /* special_potion() - so that old potion code is still done right. */ |
|
|
1643 | int |
|
|
1644 | special_potion (object *op) |
|
|
1645 | { |
|
|
1646 | if (op->attacktype) |
|
|
1647 | return 1; |
|
|
1648 | |
|
|
1649 | if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha) |
|
|
1650 | return 1; |
|
|
1651 | |
|
|
1652 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
1653 | if (op->resist[i]) |
|
|
1654 | return 1; |
|
|
1655 | |
|
|
1656 | return 0; |
|
|
1657 | } |
|
|
1658 | |
|
|
1659 | void |
1665 | void |
1660 | free_treasurestruct (treasure *t) |
1666 | free_treasurestruct (treasure *t) |
1661 | { |
1667 | { |
1662 | if (t->next) free_treasurestruct (t->next); |
1668 | if (t->next) free_treasurestruct (t->next); |
1663 | if (t->next_yes) free_treasurestruct (t->next_yes); |
1669 | if (t->next_yes) free_treasurestruct (t->next_yes); |