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.73 by root, Sun Apr 20 05:24:55 2008 UTC vs.
Revision 1.87 by sf-marcmagus, Thu Oct 15 16:00:37 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.
32 33
33//#define TREASURE_VERBOSE 34//#define TREASURE_VERBOSE
34 35
35#include <global.h> 36#include <global.h>
36#include <treasure.h> 37#include <treasure.h>
37#include <funcpoint.h>
38#include <loader.h> 38#include <loader.h>
39 39
40extern char *spell_mapping[]; 40extern char *spell_mapping[];
41 41
42static treasurelist *first_treasurelist; 42static treasurelist *first_treasurelist;
46typedef std::tr1::unordered_map< 46typedef std::tr1::unordered_map<
47 const char *, 47 const char *,
48 treasurelist *, 48 treasurelist *,
49 str_hash, 49 str_hash,
50 str_equal, 50 str_equal,
51 slice_allocator< std::pair<const char *const, treasurelist *> >, 51 slice_allocator< std::pair<const char *const, treasurelist *> >
52 true
53> tl_map_t; 52> tl_map_t;
54 53
55static tl_map_t tl_map; 54static tl_map_t tl_map;
56 55
57/* 56/*
256 return; 255 return;
257 } 256 }
258 257
259 op->expand_tail (); 258 op->expand_tail ();
260 259
261 if (op->blocked (creator->map, creator->x, creator->y)) 260 if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y))
262 op->destroy (); 261 op->destroy ();
263 else 262 else
264 { 263 {
265 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 264 SET_FLAG (op, FLAG_OBJ_ORIGINAL);
266 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 265 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
270 { 269 {
271 op = creator->insert (op); 270 op = creator->insert (op);
272 271
273 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 272 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER))
274 monster_check_apply (creator, op); 273 monster_check_apply (creator, op);
275
276 if (flags & GT_UPDATE_INV)
277 if (object *tmp = creator->in_player ())
278 esrv_send_item (tmp, op);
279 } 274 }
280} 275}
281 276
282/* if there are change_xxx commands in the treasure, we include the changes 277/* if there are change_xxx commands in the treasure, we include the changes
283 * in the generated object 278 * in the generated object
447 442
448 if (ob->inv) 443 if (ob->inv)
449 LOG (llevError, "In generate treasure, created multiple objects.\n"); 444 LOG (llevError, "In generate treasure, created multiple objects.\n");
450 445
451 ob->destroy (); 446 ob->destroy ();
447
452 return tmp; 448 return tmp;
453} 449}
454 450
455/* 451/*
456 * This is a new way of calculating the chance for an item to have 452 * This is a new way of calculating the chance for an item to have
583 if (op->type == ARMOUR) 579 if (op->type == ARMOUR)
584 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op->arch) * (100 + magic * 10)) / 100; 580 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op->arch) * (100 + magic * 10)) / 100;
585 581
586 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ 582 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
587 magic = (-magic); 583 magic = (-magic);
584
588 op->weight = (op->arch->weight * (100 - magic * 10)) / 100; 585 op->weight = (op->arch->weight * (100 - magic * 10)) / 100;
589 } 586 }
590 else 587 else
591 { 588 {
592 if (op->type == ARMOUR) 589 if (op->type == ARMOUR)
593 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100; 590 ARMOUR_SPEED (op) = (ARMOUR_SPEED (op) * (100 + magic * 10)) / 100;
591
594 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */ 592 if (magic < 0 && !(rndm (3))) /* You can't just check the weight always */
595 magic = (-magic); 593 magic = (-magic);
594
596 op->weight = (op->weight * (100 - magic * 10)) / 100; 595 op->weight = (op->weight * (100 - magic * 10)) / 100;
597 } 596 }
598} 597}
599 598
600/* 599/*
968 case AMULET: 967 case AMULET:
969 if (IS_ARCH (op->arch, amulet)) 968 if (IS_ARCH (op->arch, amulet))
970 op->value *= 5; /* Since it's not just decoration */ 969 op->value *= 5; /* Since it's not just decoration */
971 970
972 case RING: 971 case RING:
973 if (!op->arch) // wtf? schmorp
974 {
975 op->destroy ();
976 op = 0;
977 break;
978 }
979
980 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ 972 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
981 break; 973 break;
982 974
983 if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) 975 if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
984 SET_FLAG (op, FLAG_CURSED); 976 SET_FLAG (op, FLAG_CURSED);
1005 op->value *= 5; 997 op->value *= 5;
1006 set_ring_bonus (op, d); 998 set_ring_bonus (op, d);
1007 } 999 }
1008 } 1000 }
1009 1001
1010 if (GET_ANIM_ID (op)) 1002 if (op->animation_id)
1011 SET_ANIMATION (op, rndm (NUM_ANIMATIONS (op))); 1003 op->set_anim_frame (rndm (op->anim_frames ()));
1012 1004
1013 break; 1005 break;
1014 1006
1015 case BOOK: 1007 case BOOK:
1016 /* Is it an empty book?, if yes lets make a special· 1008 /* Is it an empty book?, if yes lets make a special·
1031 op->level = rndm (creator->level); 1023 op->level = rndm (creator->level);
1032 1024
1033 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1); 1025 tailor_readable_ob (op, (creator && creator->stats.sp) ? creator->stats.sp : -1);
1034 /* books w/ info are worth more! */ 1026 /* books w/ info are worth more! */
1035 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1)); 1027 op->value *= ((op->level > 10 ? op->level : (op->level + 1) / 2) * ((strlen (op->msg) / 250) + 1));
1036 /* creator related stuff */
1037
1038 /* for library, chained books. Note that some monsters have no_pick
1039 * set - we don't want to set no pick in that case.
1040 */
1041 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1042 SET_FLAG (op, FLAG_NO_PICK);
1043 if (creator->slaying && !op->slaying) /* for check_inv floors */
1044 op->slaying = creator->slaying;
1045 1028
1046 /* add exp so reading it gives xp (once) */ 1029 /* add exp so reading it gives xp (once) */
1047 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10; 1030 op->stats.exp = op->value > 10000 ? op->value / 5 : op->value / 10;
1048 } 1031 }
1032
1033 /* creator related stuff */
1034
1035 /* for library, chained books. Note that some monsters have no_pick
1036 * set - we don't want to set no pick in that case.
1037 */
1038 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER))
1039 SET_FLAG (op, FLAG_NO_PICK);
1040 if (creator->slaying && !op->slaying) /* for check_inv floors */
1041 op->slaying = creator->slaying;
1049 break; 1042 break;
1050 1043
1051 case SPELLBOOK: 1044 case SPELLBOOK:
1052 op->value = op->value * op->inv->value; 1045 op->value = op->value * op->inv->value;
1053 /* add exp so learning gives xp */ 1046 /* add exp so learning gives xp */
1356 * to cast. So convert that to into a spell and put it into 1349 * to cast. So convert that to into a spell and put it into
1357 * this object. 1350 * this object.
1358 */ 1351 */
1359 if (op->type == HORN || op->type == POTION) 1352 if (op->type == HORN || op->type == POTION)
1360 { 1353 {
1361 object *tmp_obj;
1362
1363 /* Remove any spells this object currently has in it */ 1354 /* Remove any spells this object currently has in it */
1364 while (op->inv)
1365 op->inv->destroy (); 1355 op->destroy_inv (false);
1366 1356
1367 tmp_obj = arch_to_object (change->other_arch); 1357 object *tmp = arch_to_object (change->other_arch);
1368 insert_ob_in_ob (tmp_obj, op); 1358 insert_ob_in_ob (tmp, op);
1369 } 1359 }
1370 /* No harm setting this for potions/horns */ 1360 /* No harm setting this for potions/horns */
1371 op->other_arch = change->other_arch; 1361 op->other_arch = change->other_arch;
1372 } 1362 }
1373 1363
1578#if 1 1568#if 1
1579 LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type); 1569 LOG (llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type);
1580#endif 1570#endif
1581 return; 1571 return;
1582 } 1572 }
1583 if (!strcmp (art->item->name, "NONE")) 1573
1574 if (art->item->name == shstr_NONE)
1584 return; 1575 return;
1576
1585 if (FABS (op->magic) < art->item->magic) 1577 if (fabs (op->magic) < art->item->magic)
1586 continue; /* Not magic enough to be this item */ 1578 continue; /* Not magic enough to be this item */
1587 1579
1588 /* Map difficulty not high enough */ 1580 /* Map difficulty not high enough */
1589 if (difficulty < art->difficulty) 1581 if (difficulty < art->difficulty)
1590 continue; 1582 continue;
1641 item->level = donor->level; 1633 item->level = donor->level;
1642 1634
1643 /* if donor has some attacktypes, the flesh is poisonous */ 1635 /* if donor has some attacktypes, the flesh is poisonous */
1644 if (donor->attacktype & AT_POISON) 1636 if (donor->attacktype & AT_POISON)
1645 item->type = POISON; 1637 item->type = POISON;
1638
1646 if (donor->attacktype & AT_ACID) 1639 if (donor->attacktype & AT_ACID)
1647 item->stats.hp = -1 * item->stats.food; 1640 item->stats.hp = -1 * item->stats.food;
1641
1648 SET_FLAG (item, FLAG_NO_STEAL); 1642 SET_FLAG (item, FLAG_NO_STEAL);
1649 } 1643 }
1650} 1644}
1651 1645
1652/* special_potion() - so that old potion code is still done right. */ 1646/* special_potion() - so that old potion code is still done right. */
1689free_artifact (artifact *at) 1683free_artifact (artifact *at)
1690{ 1684{
1691 if (at->next) free_artifact (at->next); 1685 if (at->next) free_artifact (at->next);
1692 if (at->allowed) free_charlinks (at->allowed); 1686 if (at->allowed) free_charlinks (at->allowed);
1693 1687
1694 at->item->destroy (1); 1688 at->item->destroy ();
1695 1689
1696 sfree (at); 1690 sfree (at);
1697} 1691}
1698 1692
1699void 1693void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines