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.78 by root, Sun Jul 20 16:56:34 2008 UTC vs.
Revision 1.88 by root, Fri Nov 6 12:27:05 2009 UTC

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.
45typedef std::tr1::unordered_map< 46typedef std::tr1::unordered_map<
46 const char *, 47 const char *,
47 treasurelist *, 48 treasurelist *,
48 str_hash, 49 str_hash,
49 str_equal, 50 str_equal,
50 slice_allocator< std::pair<const char *const, treasurelist *> >, 51 slice_allocator< std::pair<const char *const, treasurelist *> >
51 true
52> tl_map_t; 52> tl_map_t;
53 53
54static tl_map_t tl_map; 54static tl_map_t tl_map;
55
56//TODO: class method
57static void
58clear (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}
55 70
56/* 71/*
57 * Searches for the given treasurelist 72 * Searches for the given treasurelist
58 */ 73 */
59treasurelist * 74treasurelist *
89 104
90 tl_map.insert (std::make_pair (tl->name, tl)); 105 tl_map.insert (std::make_pair (tl->name, tl));
91 } 106 }
92 107
93 return tl; 108 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} 109}
108 110
109#ifdef TREASURE_DEBUG 111#ifdef TREASURE_DEBUG
110/* recursived checks the linked list. Treasurelist is passed only 112/* recursived checks the linked list. Treasurelist is passed only
111 * so that the treasure name can be printed out 113 * so that the treasure name can be printed out
442 444
443 if (ob->inv) 445 if (ob->inv)
444 LOG (llevError, "In generate treasure, created multiple objects.\n"); 446 LOG (llevError, "In generate treasure, created multiple objects.\n");
445 447
446 ob->destroy (); 448 ob->destroy ();
449
447 return tmp; 450 return tmp;
448} 451}
449 452
450/* 453/*
451 * This is a new way of calculating the chance for an item to have 454 * This is a new way of calculating the chance for an item to have
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. */
781int
782special_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
966 case AMULET: 986 case AMULET:
967 if (IS_ARCH (op->arch, amulet)) 987 if (IS_ARCH (op->arch, amulet))
968 op->value *= 5; /* Since it's not just decoration */ 988 op->value *= 5; /* Since it's not just decoration */
969 989
970 case RING: 990 case RING:
971 if (!op->arch) // wtf? schmorp
972 {
973 op->destroy ();
974 op = 0;
975 break;
976 }
977
978 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ 991 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
979 break; 992 break;
980 993
981 if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) 994 if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
982 SET_FLAG (op, FLAG_CURSED); 995 SET_FLAG (op, FLAG_CURSED);
1003 op->value *= 5; 1016 op->value *= 5;
1004 set_ring_bonus (op, d); 1017 set_ring_bonus (op, d);
1005 } 1018 }
1006 } 1019 }
1007 1020
1008 if (GET_ANIM_ID (op)) 1021 if (op->animation_id)
1009 SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); 1022 op->set_anim_frame (rndm (op->anim_frames ()));
1010 1023
1011 break; 1024 break;
1012 1025
1013 case BOOK: 1026 case BOOK:
1014 /* Is it an empty book?, if yes lets make a special· 1027 /* Is it an empty book?, if yes lets make a special·
1029 op->level = rndm (creator->level); 1042 op->level = rndm (creator->level);
1030 1043
1031 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);
1032 /* books w/ info are worth more! */ 1045 /* books w/ info are worth more! */
1033 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));
1034 /* creator related stuff */
1035
1036 /* for library, chained books. Note that some monsters have no_pick
1037 * set - we don't want to set no pick in that case.
1038 */
1039 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1040 SET_FLAG (op, FLAG_NO_PICK);
1041 if (creator->slaying && !op->slaying) /* for check_inv floors */
1042 op->slaying = creator->slaying;
1043 1047
1044 /* add exp so reading it gives xp (once) */ 1048 /* add exp so reading it gives xp (once) */
1045 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;
1046 } 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;
1047 break; 1061 break;
1048 1062
1049 case SPELLBOOK: 1063 case SPELLBOOK:
1050 op->value = op->value * op->inv->value; 1064 op->value = op->value * op->inv->value;
1051 /* add exp so learning gives xp */ 1065 /* add exp so learning gives xp */
1354 * to cast. So convert that to into a spell and put it into 1368 * to cast. So convert that to into a spell and put it into
1355 * this object. 1369 * this object.
1356 */ 1370 */
1357 if (op->type == HORN || op->type == POTION) 1371 if (op->type == HORN || op->type == POTION)
1358 { 1372 {
1359 object *tmp_obj;
1360
1361 /* Remove any spells this object currently has in it */ 1373 /* Remove any spells this object currently has in it */
1362 while (op->inv)
1363 op->inv->destroy (); 1374 op->destroy_inv (false);
1364 1375
1365 tmp_obj = arch_to_object (change->other_arch); 1376 object *tmp = arch_to_object (change->other_arch);
1366 insert_ob_in_ob (tmp_obj, op); 1377 insert_ob_in_ob (tmp, op);
1367 } 1378 }
1368 /* No harm setting this for potions/horns */ 1379 /* No harm setting this for potions/horns */
1369 op->other_arch = change->other_arch; 1380 op->other_arch = change->other_arch;
1370 } 1381 }
1371 1382
1576#if 1 1587#if 1
1577 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);
1578#endif 1589#endif
1579 return; 1590 return;
1580 } 1591 }
1581 if (!strcmp (art->item->name, "NONE")) 1592
1593 if (art->item->name == shstr_NONE)
1582 return; 1594 return;
1595
1583 if (FABS (op->magic) < art->item->magic) 1596 if (fabs (op->magic) < art->item->magic)
1584 continue; /* Not magic enough to be this item */ 1597 continue; /* Not magic enough to be this item */
1585 1598
1586 /* Map difficulty not high enough */ 1599 /* Map difficulty not high enough */
1587 if (difficulty < art->difficulty) 1600 if (difficulty < art->difficulty)
1588 continue; 1601 continue;
1639 item->level = donor->level; 1652 item->level = donor->level;
1640 1653
1641 /* if donor has some attacktypes, the flesh is poisonous */ 1654 /* if donor has some attacktypes, the flesh is poisonous */
1642 if (donor->attacktype & AT_POISON) 1655 if (donor->attacktype & AT_POISON)
1643 item->type = POISON; 1656 item->type = POISON;
1657
1644 if (donor->attacktype & AT_ACID) 1658 if (donor->attacktype & AT_ACID)
1645 item->stats.hp = -1 * item->stats.food; 1659 item->stats.hp = -1 * item->stats.food;
1660
1646 SET_FLAG (item, FLAG_NO_STEAL); 1661 SET_FLAG (item, FLAG_NO_STEAL);
1647 } 1662 }
1648}
1649
1650/* special_potion() - so that old potion code is still done right. */
1651int
1652special_potion (object *op)
1653{
1654 if (op->attacktype)
1655 return 1;
1656
1657 if (op->stats.Str || op->stats.Dex || op->stats.Con || op->stats.Pow || op->stats.Wis || op->stats.Int || op->stats.Cha)
1658 return 1;
1659
1660 for (int i = 0; i < NROFATTACKS; i++)
1661 if (op->resist[i])
1662 return 1;
1663
1664 return 0;
1665} 1663}
1666 1664
1667void 1665void
1668free_treasurestruct (treasure *t) 1666free_treasurestruct (treasure *t)
1669{ 1667{
1687free_artifact (artifact *at) 1685free_artifact (artifact *at)
1688{ 1686{
1689 if (at->next) free_artifact (at->next); 1687 if (at->next) free_artifact (at->next);
1690 if (at->allowed) free_charlinks (at->allowed); 1688 if (at->allowed) free_charlinks (at->allowed);
1691 1689
1692 at->item->destroy (1); 1690 at->item->destroy ();
1693 1691
1694 sfree (at); 1692 sfree (at);
1695} 1693}
1696 1694
1697void 1695void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines