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.97 by root, Sun Nov 29 10:55:18 2009 UTC vs.
Revision 1.125 by root, Sat Oct 8 21:54:05 2022 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25/* TREASURE_DEBUG does some checking on the treasurelists after loading. 26/* TREASURE_DEBUG does some checking on the treasurelists after loading.
26 * It is useful for finding bugs in the treasures file. Since it only 27 * It is useful for finding bugs in the treasures file. Since it only
33 34
34//#define TREASURE_VERBOSE 35//#define TREASURE_VERBOSE
35 36
36#include <global.h> 37#include <global.h>
37#include <treasure.h> 38#include <treasure.h>
38#include <loader.h> 39
40#include <flat_hash_map.hpp>
41
42// used only by treasure.C, does not handle null arch ptrs
43#define IS_ARCH(arch,name) ((arch)->archname == shstr_ ## name)
39 44
40extern char *spell_mapping[]; 45extern char *spell_mapping[];
41 46
42static treasurelist *first_treasurelist; 47static treasurelist *first_treasurelist;
43 48
44static void change_treasure (treasure *t, object *op); /* overrule default values */ 49static void change_treasure (treasure *t, object *op); /* overrule default values */
45 50
46typedef std::tr1::unordered_map< 51typedef ska::flat_hash_map
52 <
47 const char *, 53 const char *,
48 treasurelist *, 54 treasurelist *,
49 str_hash, 55 str_hash,
50 str_equal, 56 str_equal,
51 slice_allocator< std::pair<const char *const, treasurelist *> > 57 slice_allocator< std::pair<const char *const, treasurelist *> >
52> tl_map_t; 58 > tl_map_t;
53 59
54static tl_map_t tl_map; 60static tl_map_t tl_map;
55 61
56//TODO: class method 62//TODO: class method
57static void free_treasurestruct (treasure *t); // bleh desu 63static void free_treasurestruct (treasure *t); // bleh desu
74treasurelist::find (const char *name) 80treasurelist::find (const char *name)
75{ 81{
76 if (!name) 82 if (!name)
77 return 0; 83 return 0;
78 84
79 auto (i, tl_map.find (name)); 85 auto i = tl_map.find (name);
80 86
81 if (i == tl_map.end ()) 87 if (i == tl_map.end ())
82 return 0; 88 return 0;
83 89
84 return i->second; 90 return i->second;
215 { 221 {
216 for (treasure *t = tl->items; t; t = t->next) 222 for (treasure *t = tl->items; t; t = t->next)
217 { 223 {
218 if (t->next_yes || t->next_no) 224 if (t->next_yes || t->next_no)
219 { 225 {
220 LOG (llevError, "Treasure %s is one item, but on treasure %s\n", &tl->name, t->item ? &t->item->archname : &t->name); 226 LOG (llevError, "Treasure %s is one item, but on treasure %s%s\n",
227 &tl->name,
228 t->item ? "item " : "",
229 t->item ? &t->item->archname : &t->name);
221 LOG (llevError, " the next_yes or next_no field is set\n"); 230 LOG (llevError, " the next_yes or next_no field is set\n");
222 } 231 }
223 232
224 tl->total_chance += t->chance; 233 tl->total_chance += t->chance;
225 } 234 }
256 return; 265 return;
257 } 266 }
258 267
259 op->expand_tail (); 268 op->expand_tail ();
260 269
270 if (!creator->is_on_map ()
261 if (!creator->is_on_map () || op->blocked (creator->map, creator->x, creator->y)) 271 || (op->weight && op->blocked (creator->map, creator->x, creator->y)))
262 op->destroy (); 272 op->destroy ();
263 else 273 else
264 { 274 {
265 SET_FLAG (op, FLAG_OBJ_ORIGINAL); 275 op->flag [FLAG_OBJ_ORIGINAL] = true;
266 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); 276 op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON);
267 } 277 }
268 } 278 }
269 else 279 else
270 { 280 {
271 op = creator->insert (op); 281 op = creator->insert (op);
272 282
273 if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) 283 if ((flags & GT_APPLY) && creator->flag [FLAG_MONSTER])
274 monster_check_apply (creator, op); 284 monster_check_apply (creator, op);
275 } 285 }
276} 286}
277 287
278/* if there are change_xxx commands in the treasure, we include the changes 288/* if there are change_xxx commands in the treasure, we include the changes
310 } 320 }
311 else 321 else
312 { 322 {
313 if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE))) 323 if (t->item && (t->item->invisible != 0 || !(flag & GT_INVISIBLE)))
314 { 324 {
315 object *tmp = arch_to_object (t->item); 325 object *tmp = t->item->instance ();
316 326
317 if (t->nrof && tmp->nrof <= 1) 327 if (t->nrof && tmp->nrof <= 1)
318 tmp->nrof = rndm (t->nrof) + 1; 328 tmp->nrof = rndm (t->nrof) + 1;
319 329
320 fix_generated_item (tmp, op, difficulty, t->magic, flag); 330 fix_generated_item (tmp, op, difficulty, t->magic, flag);
367 else if (t->nrof) 377 else if (t->nrof)
368 create_one_treasure (tl, op, flag, difficulty, tries); 378 create_one_treasure (tl, op, flag, difficulty, tries);
369 } 379 }
370 else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE)) 380 else if (t->item && (t->item->invisible != 0 || flag != GT_INVISIBLE))
371 { 381 {
372 if (object *tmp = arch_to_object (t->item)) 382 if (object *tmp = t->item->instance ())
373 { 383 {
374 if (t->nrof && tmp->nrof <= 1) 384 if (t->nrof && tmp->nrof <= 1)
375 tmp->nrof = rndm (t->nrof) + 1; 385 tmp->nrof = rndm (t->nrof) + 1;
376 386
377 fix_generated_item (tmp, op, difficulty, t->magic, flag); 387 fix_generated_item (tmp, op, difficulty, t->magic, flag);
490 { 0, 0, 0, 3, 97}, // 29 500 { 0, 0, 0, 3, 97}, // 29
491 { 0, 0, 0, 0, 100}, // 30 501 { 0, 0, 0, 0, 100}, // 30
492 { 0, 0, 0, 0, 100}, // 31 502 { 0, 0, 0, 0, 100}, // 31
493}; 503};
494 504
495/* calculate the appropriate level for wands staves and scrolls. 505/* calculate the appropriate level for wands staves and scrolls.
496 * This code presumes that op has had its spell object created (in op->inv) 506 * This code presumes that op has had its spell object created (in op->inv)
497 * 507 *
498 * elmex Wed Aug 9 17:44:59 CEST 2006: 508 * elmex Wed Aug 9 17:44:59 CEST 2006:
499 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 509 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
500 */ 510 */
510 int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.)); 520 int olevel = op->inv->level + int (difficulty * (1. - rndm () * rndm () * 2.));
511 521
512 if (olevel <= 0) 522 if (olevel <= 0)
513 olevel = rndm (1, op->inv->level); 523 olevel = rndm (1, op->inv->level);
514 524
515 return min (olevel, MAXLEVEL); 525 return min (olevel, MAXLEVEL_TREASURE);
516} 526}
517 527
518/* 528/*
519 * Based upon the specified difficulty and upon the difftomagic_list array, 529 * Based upon the specified difficulty and upon the difftomagic_list array,
520 * a random magical bonus is returned. This is used when determine 530 * a random magical bonus is returned. This is used when determine
526 * 536 *
527 */ 537 */
528static int 538static int
529magic_from_difficulty (int difficulty) 539magic_from_difficulty (int difficulty)
530{ 540{
531 int percent = 0, magic = 0;
532 int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); 541 int scaled_diff = lerp (difficulty, 0, settings.max_level, 0, DIFFLEVELS - 1);
542 scaled_diff = clamp (scaled_diff, 0, DIFFLEVELS - 1);
533 543
534 scaled_diff--;
535
536 if (scaled_diff < 0)
537 scaled_diff = 0;
538
539 if (scaled_diff >= DIFFLEVELS)
540 scaled_diff = DIFFLEVELS - 1;
541
542 percent = rndm (100); 544 int percent = rndm (100);
545 int magic;
543 546
544 for (magic = 0; magic < (MAXMAGIC + 1); magic++) 547 for (magic = 0; magic <= MAXMAGIC; magic++)
545 { 548 {
546 percent -= difftomagic_list[scaled_diff][magic]; 549 percent -= difftomagic_list[scaled_diff][magic];
547 550
548 if (percent < 0) 551 if (percent < 0)
549 break; 552 break;
550 } 553 }
551 554
552 if (magic == (MAXMAGIC + 1)) 555 if (magic > MAXMAGIC)
553 { 556 {
554 LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty); 557 LOG (llevError, "Warning, table for difficulty (scaled %d) %d bad.\n", scaled_diff, difficulty);
555 magic = 0; 558 magic = 0;
556 } 559 }
557 560
565 * Sets magical bonus in an object, and recalculates the effect on 568 * Sets magical bonus in an object, and recalculates the effect on
566 * the armour variable, and the effect on speed of armour. 569 * the armour variable, and the effect on speed of armour.
567 * This function doesn't work properly, should add use of archetypes 570 * This function doesn't work properly, should add use of archetypes
568 * to make it truly absolute. 571 * to make it truly absolute.
569 */ 572 */
570
571void 573void
572set_abs_magic (object *op, int magic) 574set_abs_magic (object *op, int magic)
573{ 575{
574 if (!magic) 576 if (!magic)
575 return; 577 return;
603 */ 605 */
604 606
605static void 607static void
606set_magic (int difficulty, object *op, int max_magic, int flags) 608set_magic (int difficulty, object *op, int max_magic, int flags)
607{ 609{
608 int i;
609
610 i = magic_from_difficulty (difficulty); 610 int i = magic_from_difficulty (difficulty);
611
611 if ((flags & GT_ONLY_GOOD) && i < 0) 612 if ((flags & GT_ONLY_GOOD) && i < 0)
612 i = -i; 613 i = -i;
614
613 if (i > max_magic) 615 i = min (i, max_magic);
614 i = max_magic; 616
615 set_abs_magic (op, i); 617 set_abs_magic (op, i);
616 if (i < 0) 618 if (i < 0)
617 SET_FLAG (op, FLAG_CURSED); 619 op->set_flag (FLAG_CURSED);
618} 620}
619 621
620/* 622/*
621 * Randomly adds one magical ability to the given object. 623 * Randomly adds one magical ability to the given object.
622 * Modified for Partial Resistance in many ways: 624 * Modified for Partial Resistance in many ways:
629set_ring_bonus (object *op, int bonus) 631set_ring_bonus (object *op, int bonus)
630{ 632{
631 int r = rndm (bonus > 0 ? 25 : 11); 633 int r = rndm (bonus > 0 ? 25 : 11);
632 634
633 if (op->type == AMULET) 635 if (op->type == AMULET)
634 {
635 if (!(rndm (21))) 636 if (!rndm (21))
636 r = 20 + rndm (2); 637 r = 20 + rndm (2);
638 else if (rndm (2))
639 r = 10;
637 else 640 else
638 {
639 if (rndm (2))
640 r = 10;
641 else
642 r = 11 + rndm (9); 641 r = 11 + rndm (9);
643 }
644 }
645 642
646 switch (r) 643 switch (r)
647 { 644 {
648 /* Redone by MSW 2000-11-26 to have much less code. Also, 645 /* Redone by MSW 2000-11-26 to have much less code. Also,
649 * bonuses and penalties will stack and add to existing values. 646 * bonuses and penalties will stack and add to existing values.
650 * of the item. 647 * of the item.
651 */ 648 */
652 case 0: 649 case 0:
653 case 1: 650 case 1:
654 case 2: 651 case 2:
655 case 3: 652 case 3:
656 case 4: 653 case 4:
696 * little random element in since that they don't always end up with 693 * little random element in since that they don't always end up with
697 * even values. 694 * even values.
698 */ 695 */
699 if (bonus < 0) 696 if (bonus < 0)
700 val = 2 * -val - rndm (b); 697 val = 2 * -val - rndm (b);
701 if (val > 35) 698
702 val = 35; /* Upper limit */ 699 val = min (35, val); /* Upper limit */
700
703 b = 0; 701 b = 0;
704 702
705 while (op->resist[resist_table[resist]] != 0 && b < 4) 703 while (op->resist[resist_table[resist]] != 0 && b < 4)
706 resist = rndm (num_resist_table); 704 resist = rndm (num_resist_table);
707 705
715 break; 713 break;
716 } 714 }
717 case 20: 715 case 20:
718 if (op->type == AMULET) 716 if (op->type == AMULET)
719 { 717 {
720 SET_FLAG (op, FLAG_REFL_SPELL); 718 op->set_flag (FLAG_REFL_SPELL);
721 op->value *= 11; 719 op->value *= 11;
722 } 720 }
723 else 721 else
724 { 722 {
725 op->stats.hp = 1; /* regenerate hit points */ 723 op->stats.hp = 1; /* regenerate hit points */
728 break; 726 break;
729 727
730 case 21: 728 case 21:
731 if (op->type == AMULET) 729 if (op->type == AMULET)
732 { 730 {
733 SET_FLAG (op, FLAG_REFL_MISSILE); 731 op->set_flag (FLAG_REFL_MISSILE);
734 op->value *= 9; 732 op->value *= 9;
735 } 733 }
736 else 734 else
737 { 735 {
738 op->stats.sp = 1; /* regenerate spell points */ 736 op->stats.sp = 1; /* regenerate spell points */
740 } 738 }
741 break; 739 break;
742 740
743 case 22: 741 case 22:
744 op->stats.exp += bonus; /* Speed! */ 742 op->stats.exp += bonus; /* Speed! */
745 op->value = (op->value * 2) / 3; 743 op->value = op->value * 2 / 3;
746 break; 744 break;
747 } 745 }
748 746
749 if (bonus > 0) 747 if (bonus > 0)
750 op->value *= 2 * bonus; 748 op->value = 2 * op->value * bonus;
751 else 749 else
752 op->value = -(op->value * 2 * bonus) / 3; 750 op->value = -2 * op->value * bonus / 3;
753} 751}
754 752
755/* 753/*
756 * get_magic(diff) will return a random number between 0 and 4. 754 * get_magic(diff) will return a random number between 0 and 4.
757 * diff can be any value above 2. The higher the diff-variable, the 755 * diff can be any value above 2. The higher the diff-variable, the
761 * Another scheme is used to calculate the magic of weapons and armours. 759 * Another scheme is used to calculate the magic of weapons and armours.
762 */ 760 */
763static int 761static int
764get_magic (int diff) 762get_magic (int diff)
765{ 763{
766 int i; 764 diff = min (3, diff);
767 765
768 if (diff < 3)
769 diff = 3;
770
771 for (i = 0; i < 4; i++) 766 for (int i = 0; i < 4; i++)
772 if (rndm (diff)) 767 if (rndm (diff))
773 return i; 768 return i;
774 769
775 return 4; 770 return 4;
776} 771}
790 return 1; 785 return 1;
791 786
792 return 0; 787 return 0;
793} 788}
794 789
790static double
791value_factor_from_spell_item (object *spell, object *item)
792{
793 double factor =
794 pow ((spell->value > 0 ? spell->value : 1)
795 * spell->level, 1.5);
796
797 if (item) // this if for: wands/staffs/rods:
798 {
799 /* Old crossfire comment ahead:
800 * Add 50 to both level an divisor to keep prices a little more
801 * reasonable. Otherwise, a high level version of a low level
802 * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
803 * 10 time multiplier). This way, the value are a bit more reasonable.
804 */
805
806 factor *= item->level + 50;
807 factor /= item->inv->level + 50;
808 }
809
810 return factor;
811}
812
795#define DICE2 (get_magic(2)==2?2:1) 813#define DICE2 (get_magic(2) == 2 ? 2 : 1)
796#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) 814#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
797 815
798/* 816/*
799 * fix_generated_item(): This is called after an item is generated, in 817 * fix_generated_item(): This is called after an item is generated, in
800 * order to set it up right. This produced magical bonuses, puts spells 818 * order to set it up right. This produced magical bonuses, puts spells
801 * into scrolls/books/wands, makes it unidentified, hides the value, etc. 819 * into scrolls/books/wands, makes it unidentified, hides the value, etc.
802 */ 820 */
803 821
804/* 4/28/96 added creator object from which op may now inherit properties based on 822/* 4/28/96 added creator object from which op may now inherit properties based on
805 * op->type. Right now, which stuff the creator passes on is object type 823 * op->type. Right now, which stuff the creator passes on is object type
806 * dependant. I know this is a spagetti manuever, but is there a cleaner 824 * dependant. I know this is a spagetti manuever, but is there a cleaner
807 * way to do this? b.t. */ 825 * way to do this? b.t. */
808 826
809/* 827/*
810 * ! (flags & GT_ENVIRONMENT): 828 * ! (flags & GT_ENVIRONMENT):
811 * Automatically calls fix_flesh_item(). 829 * Automatically calls fix_flesh_item().
911 { 929 {
912 if (op->type == POTION) 930 if (op->type == POTION)
913 /* Handle healing and magic power potions */ 931 /* Handle healing and magic power potions */
914 if (op->stats.sp && !op->randomitems) 932 if (op->stats.sp && !op->randomitems)
915 { 933 {
916 object *tmp = get_archetype (spell_mapping [op->stats.sp]); 934 object *tmp = archetype::get (spell_mapping [op->stats.sp]);
917 insert_ob_in_ob (tmp, op); 935 insert_ob_in_ob (tmp, op);
918 op->stats.sp = 0; 936 op->stats.sp = 0;
919 } 937 }
920 } 938 }
921 else if (!op->title) /* Only modify object if not special */ 939 else if (!op->title) /* Only modify object if not special */
924 case WEAPON: 942 case WEAPON:
925 case ARMOUR: 943 case ARMOUR:
926 case SHIELD: 944 case SHIELD:
927 case HELMET: 945 case HELMET:
928 case CLOAK: 946 case CLOAK:
929 if (QUERY_FLAG (op, FLAG_CURSED) && !(rndm (4))) 947 if (op->flag [FLAG_CURSED] && !(rndm (4)))
930 set_ring_bonus (op, -DICE2); 948 set_ring_bonus (op, -DICE2);
931 break; 949 break;
932 950
933 case BRACERS: 951 case BRACERS:
934 if (!rndm (QUERY_FLAG (op, FLAG_CURSED) ? 5 : 20)) 952 if (!rndm (op->flag [FLAG_CURSED] ? 5 : 20))
935 { 953 {
936 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); 954 set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2);
937 if (!QUERY_FLAG (op, FLAG_CURSED)) 955 if (!op->flag [FLAG_CURSED])
938 op->value *= 3; 956 op->value *= 3;
939 } 957 }
940 break; 958 break;
941 959
942 case POTION: 960 case POTION:
943 { 961 {
944 int too_many_tries = 0, is_special = 0; 962 int too_many_tries = 0;
945 963
946 /* Handle healing and magic power potions */ 964 /* Handle healing and magic power potions */
947 if (op->stats.sp && !op->randomitems) 965 if (op->stats.sp && !op->randomitems)
948 { 966 {
949 object *tmp = get_archetype (spell_mapping[op->stats.sp]); 967 object *tmp = archetype::get (spell_mapping[op->stats.sp]);
950 insert_ob_in_ob (tmp, op); 968 insert_ob_in_ob (tmp, op);
951 op->stats.sp = 0; 969 op->stats.sp = 0;
952 } 970 }
953 971
954 while (!(is_special = special_potion (op)) && !op->inv) 972 while (!special_potion (op) && !op->inv)
955 { 973 {
956 generate_artifact (op, difficulty); 974 generate_artifact (op, difficulty);
957 if (too_many_tries++ > 10) 975 if (too_many_tries++ > 10)
958 break; 976 break;
959 } 977 }
967 op->value *= op->inv->value; 985 op->value *= op->inv->value;
968 op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); 986 op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty);
969 } 987 }
970 else 988 else
971 { 989 {
972 op->name = "potion"; 990 op->name = shstr_potion;
973 op->name_pl = "potions"; 991 op->name_pl = shstr_potions;
974 } 992 }
975 993
976 if (!(flags & GT_ONLY_GOOD) && rndm (2)) 994 if (!(flags & GT_ONLY_GOOD) && rndm (2))
977 SET_FLAG (op, FLAG_CURSED); 995 op->set_flag (FLAG_CURSED);
978 996
979 break; 997 break;
980 } 998 }
981 999
982 case AMULET: 1000 case AMULET:
986 case RING: 1004 case RING:
987 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */ 1005 if (!IS_ARCH (op->arch, ring) && !IS_ARCH (op->arch, amulet)) /* It's a special artifact! */
988 break; 1006 break;
989 1007
990 if (!(flags & GT_ONLY_GOOD) && !(rndm (3))) 1008 if (!(flags & GT_ONLY_GOOD) && !(rndm (3)))
991 SET_FLAG (op, FLAG_CURSED); 1009 op->set_flag (FLAG_CURSED);
992 1010
993 set_ring_bonus (op, QUERY_FLAG (op, FLAG_CURSED) ? -DICE2 : DICE2); 1011 set_ring_bonus (op, op->flag [FLAG_CURSED] ? -DICE2 : DICE2);
994 1012
995 if (op->type != RING) /* Amulets have only one ability */ 1013 if (op->type != RING) /* Amulets have only one ability */
996 break; 1014 break;
997 1015
998 if (!(rndm (4))) 1016 if (!rndm (4))
999 { 1017 {
1000 int d = (rndm (2) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; 1018 int d = (rndm (2) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2;
1001 1019
1002 if (d > 0) 1020 if (d > 0)
1003 op->value *= 3; 1021 op->value *= 3;
1004 1022
1005 set_ring_bonus (op, d); 1023 set_ring_bonus (op, d);
1006 1024
1007 if (!(rndm (4))) 1025 if (!rndm (4))
1008 { 1026 {
1009 int d = (rndm (3) || QUERY_FLAG (op, FLAG_CURSED)) ? -DICE2 : DICE2; 1027 int d = (rndm (3) || op->flag [FLAG_CURSED]) ? -DICE2 : DICE2;
1010 1028
1011 if (d > 0) 1029 if (d > 0)
1012 op->value *= 5; 1030 op->value *= 5;
1031
1013 set_ring_bonus (op, d); 1032 set_ring_bonus (op, d);
1014 } 1033 }
1015 } 1034 }
1016 1035
1017 if (op->animation_id) 1036 if (op->animation_id)
1025 * creator and/or map level we found it on. 1044 * creator and/or map level we found it on.
1026 */ 1045 */
1027 if (!op->msg && rndm (10)) 1046 if (!op->msg && rndm (10))
1028 { 1047 {
1029 /* set the book level properly */ 1048 /* set the book level properly */
1030 if (creator->level == 0 || QUERY_FLAG (creator, FLAG_ALIVE)) 1049 if (creator->level == 0 || creator->flag [FLAG_ALIVE])
1031 { 1050 {
1032 if (op->map && op->map->difficulty) 1051 if (op->map && op->map->difficulty)
1033 op->level = rndm (op->map->difficulty) + rndm (10) + 1; 1052 op->level = rndm (op->map->difficulty) + rndm (10) + 1;
1034 else 1053 else
1035 op->level = rndm (20) + 1; 1054 op->level = rndm (20) + 1;
1048 /* creator related stuff */ 1067 /* creator related stuff */
1049 1068
1050 /* for library, chained books. Note that some monsters have no_pick 1069 /* for library, chained books. Note that some monsters have no_pick
1051 * set - we don't want to set no pick in that case. 1070 * set - we don't want to set no pick in that case.
1052 */ 1071 */
1053 if (QUERY_FLAG (creator, FLAG_NO_PICK) && !QUERY_FLAG (creator, FLAG_MONSTER)) 1072 if (creator->flag [FLAG_NO_PICK] && !creator->flag [FLAG_MONSTER])
1054 SET_FLAG (op, FLAG_NO_PICK); 1073 op->set_flag (FLAG_NO_PICK);
1055 if (creator->slaying && !op->slaying) /* for check_inv floors */ 1074 if (creator->slaying && !op->slaying) /* for check_inv floors */
1056 op->slaying = creator->slaying; 1075 op->slaying = creator->slaying;
1057 break; 1076 break;
1058 1077
1059 case SPELLBOOK: 1078 case SPELLBOOK:
1060 op->value = op->value * op->inv->value; 1079 op->value *= value_factor_from_spell_item (op->inv, 0);
1080
1061 /* add exp so learning gives xp */ 1081 /* add exp so learning gives xp */
1062 op->level = op->inv->level; 1082 op->level = op->inv->level;
1063 op->stats.exp = op->value; 1083 op->stats.exp = op->value;
1064 break; 1084 break;
1065 1085
1069 * and reset nrof. 1089 * and reset nrof.
1070 */ 1090 */
1071 op->stats.food = op->inv->nrof; 1091 op->stats.food = op->inv->nrof;
1072 op->nrof = 1; 1092 op->nrof = 1;
1073 /* If the spell changes by level, choose a random level 1093 /* If the spell changes by level, choose a random level
1074 * for it, and adjust price. If the spell doesn't 1094 * for it.
1075 * change by level, just set the wand to the level of
1076 * the spell, and value calculation is simpler.
1077 */ 1095 */
1078 if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) 1096 if (op->inv->duration_modifier
1079 { 1097 || op->inv->dam_modifier
1098 || op->inv->range_modifier)
1080 op->level = level_for_item (op, difficulty); 1099 op->level = level_for_item (op, difficulty);
1081 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1082 }
1083 else 1100 else
1084 {
1085 op->level = op->inv->level; 1101 op->level = op->inv->level;
1086 op->value = op->value * op->inv->value; 1102
1087 } 1103 op->value *= value_factor_from_spell_item (op->inv, op);
1088 break; 1104 break;
1089 1105
1090 case ROD: 1106 case ROD:
1091 op->level = level_for_item (op, difficulty); 1107 op->level = level_for_item (op, difficulty);
1092 /* Add 50 to both level an divisor to keep prices a little more 1108 op->value *= value_factor_from_spell_item (op->inv, op);
1093 * reasonable. Otherwise, a high level version of a low level 1109
1094 * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
1095 * 10 time multiplier). This way, the value are a bit more reasonable.
1096 */
1097 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1098 /* maxhp is used to denote how many 'charges' the rod holds before */ 1110 /* maxhp is used to denote how many 'charges' the rod holds before */
1099 if (op->stats.maxhp) 1111 if (op->stats.maxhp)
1100 op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); 1112 op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace);
1101 else 1113 else
1102 op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); 1114 op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace);
1104 op->stats.hp = op->stats.maxhp; 1116 op->stats.hp = op->stats.maxhp;
1105 break; 1117 break;
1106 1118
1107 case SCROLL: 1119 case SCROLL:
1108 op->level = level_for_item (op, difficulty); 1120 op->level = level_for_item (op, difficulty);
1109 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); 1121 op->value *= value_factor_from_spell_item (op->inv, op);
1110 1122
1111 /* add exp so reading them properly gives xp */ 1123 /* add exp so reading them properly gives xp */
1112 op->stats.exp = op->value / 5; 1124 op->stats.exp = op->value / 5;
1113 op->nrof = op->inv->nrof; 1125 op->nrof = op->inv->nrof;
1114 break; 1126 break;
1122 break; 1134 break;
1123 } /* switch type */ 1135 } /* switch type */
1124 1136
1125 if (flags & GT_STARTEQUIP) 1137 if (flags & GT_STARTEQUIP)
1126 { 1138 {
1127 if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !QUERY_FLAG (op, FLAG_IS_THROWN)) 1139 if (op->nrof < 2 && op->type != CONTAINER && op->type != MONEY && !op->flag [FLAG_IS_THROWN])
1128 SET_FLAG (op, FLAG_STARTEQUIP); 1140 op->set_flag (FLAG_STARTEQUIP);
1129 else if (op->type != MONEY) 1141 else if (op->type != MONEY)
1130 op->value = 0; 1142 op->value = 0;
1131 } 1143 }
1132 1144
1133 if (!(flags & GT_ENVIRONMENT)) 1145 if (!(flags & GT_ENVIRONMENT))
1179 */ 1191 */
1180void 1192void
1181init_artifacts () 1193init_artifacts ()
1182{ 1194{
1183 static int has_been_inited = 0; 1195 static int has_been_inited = 0;
1184 char filename[MAX_BUF];
1185 artifact *art = NULL; 1196 artifact *art = NULL;
1186 artifactlist *al; 1197 artifactlist *al;
1187 1198
1188 if (has_been_inited) 1199 if (has_been_inited)
1189 return; 1200 return;
1190 else 1201 else
1191 has_been_inited = 1; 1202 has_been_inited = 1;
1192 1203
1193 sprintf (filename, "%s/artifacts", settings.datadir); 1204 object_thawer f (settings.datadir, "artifacts");
1194 object_thawer f (filename);
1195 1205
1196 if (!f) 1206 if (!f)
1197 return; 1207 return;
1198 1208
1199 for (;;) 1209 for (;;)
1210 1220
1211 const char *cp = f.get_str (); 1221 const char *cp = f.get_str ();
1212 char *next; 1222 char *next;
1213 do 1223 do
1214 { 1224 {
1215 if ((next = strchr (cp, ','))) 1225 if ((next = (char *)strchr (cp, ',')))
1216 *next++ = '\0'; 1226 *next++ = '\0';
1217 1227
1218 linked_char *tmp = new linked_char; 1228 linked_char *tmp = new linked_char;
1219 1229
1220 tmp->name = cp; 1230 tmp->name = cp;
1284 } 1294 }
1285#if 0 1295#if 0
1286 LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); 1296 LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
1287#endif 1297#endif
1288 } 1298 }
1289
1290 LOG (llevDebug, "done.\n");
1291} 1299}
1292 1300
1293/* 1301/*
1294 * Used in artifact generation. The bonuses of the first object 1302 * Used in artifact generation. The bonuses of the first object
1295 * is modified by the bonuses of the second object. 1303 * is modified by the bonuses of the second object.
1296 */ 1304 */
1297void 1305void
1298add_abilities (object *op, object *change) 1306add_abilities (object *op, object *change)
1299{ 1307{
1300 int i, tmp;
1301
1302 if (change->face != blank_face) 1308 if (change->face != blank_face)
1303 {
1304#ifdef TREASURE_VERBOSE
1305 LOG (llevDebug, "add_abilities change face: %d\n", change->face);
1306#endif
1307 op->face = change->face; 1309 op->face = change->face;
1308 }
1309 1310
1310 for (i = 0; i < NUM_STATS; i++) 1311 for (int i = 0; i < NUM_STATS; i++)
1311 change_attr_value (&(op->stats), i, change->stats.stat (i)); 1312 change_attr_value (&(op->stats), i, change->stats.stat (i));
1312 1313
1313 op->attacktype |= change->attacktype; 1314 op->attacktype |= change->attacktype;
1314 op->path_attuned |= change->path_attuned; 1315 op->path_attuned |= change->path_attuned;
1315 op->path_repelled |= change->path_repelled; 1316 op->path_repelled |= change->path_repelled;
1316 op->path_denied |= change->path_denied; 1317 op->path_denied |= change->path_denied;
1317 op->move_type |= change->move_type; 1318 op->move_type |= change->move_type;
1318 op->stats.luck += change->stats.luck; 1319 op->stats.luck += change->stats.luck;
1319 1320
1320 if (QUERY_FLAG (change, FLAG_CURSED)) 1321 static const struct copyflags : object::flags_t
1321 SET_FLAG (op, FLAG_CURSED); 1322 {
1322 if (QUERY_FLAG (change, FLAG_DAMNED)) 1323 copyflags ()
1323 SET_FLAG (op, FLAG_DAMNED); 1324 {
1324 if ((QUERY_FLAG (change, FLAG_CURSED) || QUERY_FLAG (change, FLAG_DAMNED)) && op->magic > 0) 1325 set (FLAG_CURSED);
1326 set (FLAG_DAMNED);
1327 set (FLAG_LIFESAVE);
1328 set (FLAG_REFL_SPELL);
1329 set (FLAG_STEALTH);
1330 set (FLAG_XRAYS);
1331 set (FLAG_BLIND);
1332 set (FLAG_SEE_IN_DARK);
1333 set (FLAG_REFL_MISSILE);
1334 set (FLAG_MAKE_INVIS);
1335 }
1336 } copyflags;
1337
1338 // we might want to just copy, but or'ing is what the original code did
1339 op->flag |= change->flag & copyflags;
1340
1341 if ((change->flag [FLAG_CURSED] || change->flag [FLAG_DAMNED]) && op->magic > 0)
1325 set_abs_magic (op, -op->magic); 1342 set_abs_magic (op, -op->magic);
1326 1343
1327 if (QUERY_FLAG (change, FLAG_LIFESAVE)) 1344 if (change->flag [FLAG_STAND_STILL])
1328 SET_FLAG (op, FLAG_LIFESAVE);
1329 if (QUERY_FLAG (change, FLAG_REFL_SPELL))
1330 SET_FLAG (op, FLAG_REFL_SPELL);
1331 if (QUERY_FLAG (change, FLAG_STEALTH))
1332 SET_FLAG (op, FLAG_STEALTH);
1333 if (QUERY_FLAG (change, FLAG_XRAYS))
1334 SET_FLAG (op, FLAG_XRAYS);
1335 if (QUERY_FLAG (change, FLAG_BLIND))
1336 SET_FLAG (op, FLAG_BLIND);
1337 if (QUERY_FLAG (change, FLAG_SEE_IN_DARK))
1338 SET_FLAG (op, FLAG_SEE_IN_DARK);
1339 if (QUERY_FLAG (change, FLAG_REFL_MISSILE))
1340 SET_FLAG (op, FLAG_REFL_MISSILE);
1341 if (QUERY_FLAG (change, FLAG_MAKE_INVIS))
1342 SET_FLAG (op, FLAG_MAKE_INVIS);
1343
1344 if (QUERY_FLAG (change, FLAG_STAND_STILL))
1345 { 1345 {
1346 CLEAR_FLAG (op, FLAG_ANIMATE); 1346 op->clr_flag (FLAG_ANIMATE);
1347
1347 /* so artifacts will join */ 1348 /* so artifacts will join */
1348 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1349 if (!op->flag [FLAG_ALIVE])
1349 op->speed = 0.0; 1350 op->speed = 0.;
1350 1351
1351 op->set_speed (op->speed); 1352 op->set_speed (op->speed);
1352 } 1353 }
1353 1354
1354 if (change->nrof) 1355 if (change->nrof)
1355 op->nrof = rndm (change->nrof) + 1; 1356 op->nrof = rndm (change->nrof) + 1;
1356 1357
1357 op->stats.exp += change->stats.exp; /* Speed modifier */ 1358 op->stats.exp += change->stats.exp; /* Speed modifier */
1358 op->stats.wc += change->stats.wc; 1359 op->stats.wc += change->stats.wc;
1359 op->stats.ac += change->stats.ac; 1360 op->stats.ac += change->stats.ac;
1360 1361
1361 if (change->other_arch) 1362 if (change->other_arch)
1362 { 1363 {
1363 /* Basically, for horns & potions, the other_arch field is the spell 1364 /* Basically, for horns & potions, the other_arch field is the spell
1364 * to cast. So convert that to into a spell and put it into 1365 * to cast. So convert that to into a spell and put it into
1367 if (op->type == HORN || op->type == POTION) 1368 if (op->type == HORN || op->type == POTION)
1368 { 1369 {
1369 /* Remove any spells this object currently has in it */ 1370 /* Remove any spells this object currently has in it */
1370 op->destroy_inv (false); 1371 op->destroy_inv (false);
1371 1372
1372 object *tmp = arch_to_object (change->other_arch); 1373 object *tmp = change->other_arch->instance ();
1373 insert_ob_in_ob (tmp, op); 1374 insert_ob_in_ob (tmp, op);
1374 } 1375 }
1376
1375 /* No harm setting this for potions/horns */ 1377 /* No harm setting this for potions/horns */
1376 op->other_arch = change->other_arch; 1378 op->other_arch = change->other_arch;
1377 } 1379 }
1378 1380
1379 if (change->stats.hp < 0) 1381 if (change->stats.hp < 0)
1395 op->stats.maxsp = -change->stats.maxsp; 1397 op->stats.maxsp = -change->stats.maxsp;
1396 else 1398 else
1397 op->stats.maxsp += change->stats.maxsp; 1399 op->stats.maxsp += change->stats.maxsp;
1398 1400
1399 if (change->stats.food < 0) 1401 if (change->stats.food < 0)
1400 op->stats.food = -(change->stats.food); 1402 op->stats.food = -change->stats.food;
1401 else 1403 else
1402 op->stats.food += change->stats.food; 1404 op->stats.food += change->stats.food;
1403 1405
1404 if (change->level < 0) 1406 if (change->level < 0)
1405 op->level = -(change->level); 1407 op->level = -change->level;
1406 else 1408 else
1407 op->level += change->level; 1409 op->level += change->level;
1408 1410
1409 if (change->gen_sp_armour < 0) 1411 if (change->gen_sp_armour < 0)
1410 op->gen_sp_armour = -(change->gen_sp_armour); 1412 op->gen_sp_armour = -change->gen_sp_armour;
1411 else 1413 else
1412 op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; 1414 op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100;
1413 1415
1414 op->item_power = change->item_power; 1416 op->item_power = change->item_power;
1415 1417
1416 for (i = 0; i < NROFATTACKS; i++) 1418 for (int i = 0; i < NROFATTACKS; i++)
1417 if (change->resist[i])
1418 op->resist[i] += change->resist[i]; 1419 op->resist[i] += change->resist[i];
1419 1420
1420 if (change->stats.dam) 1421 if (change->stats.dam)
1421 { 1422 {
1422 if (change->stats.dam < 0) 1423 if (change->stats.dam < 0)
1423 op->stats.dam = (-change->stats.dam); 1424 op->stats.dam = -change->stats.dam;
1424 else if (op->stats.dam) 1425 else if (op->stats.dam)
1425 { 1426 {
1426 tmp = (signed char) (((int) op->stats.dam * (int) change->stats.dam) / 10); 1427 int tmp = op->stats.dam * change->stats.dam / 10;
1428
1427 if (tmp == op->stats.dam) 1429 if (tmp == op->stats.dam)
1428 { 1430 {
1429 if (change->stats.dam < 10) 1431 if (change->stats.dam < 10)
1430 op->stats.dam--; 1432 op->stats.dam--;
1431 else 1433 else
1437 } 1439 }
1438 1440
1439 if (change->weight) 1441 if (change->weight)
1440 { 1442 {
1441 if (change->weight < 0) 1443 if (change->weight < 0)
1442 op->weight = (-change->weight); 1444 op->weight = -change->weight;
1443 else 1445 else
1444 op->weight = (op->weight * (change->weight)) / 100; 1446 op->weight = op->weight * change->weight / 100;
1445 } 1447 }
1446 1448
1447 if (change->last_sp) 1449 if (change->last_sp)
1448 { 1450 {
1449 if (change->last_sp < 0) 1451 if (change->last_sp < 0)
1450 op->last_sp = (-change->last_sp); 1452 op->last_sp = -change->last_sp;
1451 else 1453 else
1452 op->last_sp = (signed char) (((int) op->last_sp * (int) change->last_sp) / (int) 100); 1454 op->last_sp = op->last_sp * (int)change->last_sp / 100;
1453 } 1455 }
1454 1456
1455 if (change->gen_sp_armour) 1457 if (change->gen_sp_armour)
1456 { 1458 {
1457 if (change->gen_sp_armour < 0) 1459 if (change->gen_sp_armour < 0)
1458 op->gen_sp_armour = (-change->gen_sp_armour); 1460 op->gen_sp_armour = -change->gen_sp_armour;
1459 else 1461 else
1460 op->gen_sp_armour = (signed char) (((int) op->gen_sp_armour * ((int) change->gen_sp_armour)) / (int) 100); 1462 op->gen_sp_armour = op->gen_sp_armour * (int)change->gen_sp_armour / 100;
1461 } 1463 }
1462 1464
1463 op->value *= change->value; 1465 op->value *= change->value;
1464 1466
1465 if (change->materials) 1467 if (change->materials)
1497 name = tmp->name + 1, neg = 1; 1499 name = tmp->name + 1, neg = 1;
1498 else 1500 else
1499 name = tmp->name, neg = 0; 1501 name = tmp->name, neg = 0;
1500 1502
1501 /* If we match name, then return the opposite of 'neg' */ 1503 /* If we match name, then return the opposite of 'neg' */
1502 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) 1504 if (!strcmp (name, op->arch->archname))
1503 return !neg; 1505 return !neg;
1504 1506
1505 /* Set success as true, since if the match was an inverse, it means 1507 /* Set success as true, since if the match was an inverse, it means
1506 * everything is allowed except what we match 1508 * everything is allowed except what we match
1507 */ 1509 */
1518 */ 1520 */
1519 1521
1520void 1522void
1521give_artifact_abilities (object *op, object *artifct) 1523give_artifact_abilities (object *op, object *artifct)
1522{ 1524{
1523 char new_name[MAX_BUF]; 1525 op->title = format ("of %s", &artifct->name);
1524 1526
1525 sprintf (new_name, "of %s", &artifct->name);
1526 op->title = new_name;
1527 add_abilities (op, artifct); /* Give out the bonuses */ 1527 add_abilities (op, artifct); /* Give out the bonuses */
1528 1528
1529#if 0 /* Bit verbose, but keep it here until next time I need it... */ 1529#if 0 /* Bit verbose, but keep it here until next time I need it... */
1530 { 1530 {
1531 char identified = QUERY_FLAG (op, FLAG_IDENTIFIED); 1531 char identified = op->flag [FLAG_IDENTIFIED];
1532 1532
1533 SET_FLAG (op, FLAG_IDENTIFIED); 1533 op->set_flag (FLAG_IDENTIFIED);
1534 LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL)); 1534 LOG (llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item (op, NULL));
1535 if (!identified) 1535 if (!identified)
1536 CLEAR_FLAG (op, FLAG_IDENTIFIED); 1536 op->clr_flag (FLAG_IDENTIFIED);
1537 } 1537 }
1538#endif 1538#endif
1539 return; 1539 return;
1540} 1540}
1541 1541
1551#define ARTIFACT_TRIES 2 1551#define ARTIFACT_TRIES 2
1552 1552
1553void 1553void
1554generate_artifact (object *op, int difficulty) 1554generate_artifact (object *op, int difficulty)
1555{ 1555{
1556 artifactlist *al;
1557 artifact *art; 1556 artifact *art;
1558 int i;
1559 1557
1560 al = find_artifactlist (op->type); 1558 artifactlist *al = find_artifactlist (op->type);
1561 1559
1562 if (al == NULL) 1560 if (al == NULL)
1563 { 1561 {
1564#if 0 /* This is too verbose, usually */ 1562#if 0 /* This is too verbose, usually */
1565 LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name); 1563 LOG (llevDebug, "Couldn't change %s into artifact - no table.\n", op->name);
1566#endif 1564#endif
1567 return; 1565 return;
1568 } 1566 }
1569 1567
1570 for (i = 0; i < ARTIFACT_TRIES; i++) 1568 for (int i = 0; i < ARTIFACT_TRIES; i++)
1571 { 1569 {
1572 int roll = rndm (al->total_chance); 1570 int roll = rndm (al->total_chance);
1573 1571
1574 for (art = al->items; art; art = art->next) 1572 for (art = al->items; art; art = art->next)
1575 { 1573 {
1615 */ 1613 */
1616 1614
1617void 1615void
1618fix_flesh_item (object *item, object *donor) 1616fix_flesh_item (object *item, object *donor)
1619{ 1617{
1620 char tmpbuf[MAX_BUF];
1621 int i;
1622
1623 if (item->type == FLESH && donor) 1618 if (item->type == FLESH && donor)
1624 { 1619 {
1625 /* change the name */ 1620 /* change the name */
1626 sprintf (tmpbuf, "%s's %s", &donor->name, &item->name); 1621 item->name = format ("%s's %s", &donor->name, &item->name);
1627 item->name = tmpbuf;
1628 sprintf (tmpbuf, "%s's %s", &donor->name, &item->name_pl); 1622 item->name_pl = format ("%s's %s", &donor->name, &item->name_pl);
1629 item->name_pl = tmpbuf;
1630 1623
1631 /* weight is FLESH weight/100 * donor */ 1624 /* weight is FLESH weight/100 * donor */
1632 if ((item->weight = (signed long) (((double) item->weight / (double) 100.0) * (double) donor->weight)) == 0) 1625 item->weight = max (1, item->weight * donor->weight / 100);
1633 item->weight = 1;
1634 1626
1635 /* value is multiplied by level of donor */ 1627 /* value is multiplied by level of donor */
1636 item->value *= isqrt (donor->level * 2); 1628 item->value *= isqrt (donor->level * 2);
1637 1629
1638 /* food value */ 1630 /* food value */
1639 item->stats.food += (donor->stats.hp / 100) + donor->stats.Con; 1631 item->stats.food += donor->stats.hp / 100 + donor->stats.Con;
1640 1632
1641 /* flesh items inherit some abilities of donor, but not 1633 /* flesh items inherit some abilities of donor, but not
1642 * full effect. 1634 * full effect.
1643 */ 1635 */
1644 for (i = 0; i < NROFATTACKS; i++) 1636 for (int i = 0; i < NROFATTACKS; i++)
1645 item->resist[i] = donor->resist[i] / 2; 1637 item->resist[i] = donor->resist[i] / 2;
1646 1638
1647 /* item inherits donor's level (important for quezals) */ 1639 /* item inherits donor's level (important for quezals) */
1648 item->level = donor->level; 1640 item->level = donor->level;
1649 1641
1650 /* if donor has some attacktypes, the flesh is poisonous */ 1642 /* if donor has some attacktypes, the flesh is poisonous */
1651 if (donor->attacktype & AT_POISON) 1643 if (donor->attacktype & AT_POISON)
1652 item->type = POISON; 1644 item->type = POISON;
1653 1645
1654 if (donor->attacktype & AT_ACID) 1646 if (donor->attacktype & AT_ACID)
1655 item->stats.hp = -1 * item->stats.food; 1647 item->stats.hp = -item->stats.food;
1656 1648
1657 SET_FLAG (item, FLAG_NO_STEAL); 1649 item->set_flag (FLAG_NO_STEAL);
1658 } 1650 }
1659} 1651}
1660 1652
1661static void 1653static void
1662free_treasurestruct (treasure *t) 1654free_treasurestruct (treasure *t)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines