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.107 by root, Sun Apr 25 07:08:57 2010 UTC vs.
Revision 1.120 by root, Sat Nov 17 23:33:17 2018 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 (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * 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 9 * 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 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * 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 Affero GNU General Public License 18 * 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 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * 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>
23 */ 23 */
24 24
25/* TREASURE_DEBUG does some checking on the treasurelists after loading. 25/* TREASURE_DEBUG does some checking on the treasurelists after loading.
26 * It is useful for finding bugs in the treasures file. Since it only 26 * It is useful for finding bugs in the treasures file. Since it only
34//#define TREASURE_VERBOSE 34//#define TREASURE_VERBOSE
35 35
36#include <global.h> 36#include <global.h>
37#include <treasure.h> 37#include <treasure.h>
38 38
39#include <flat_hash_map.hpp>
40
39extern char *spell_mapping[]; 41extern char *spell_mapping[];
40 42
41static treasurelist *first_treasurelist; 43static treasurelist *first_treasurelist;
42 44
43static void change_treasure (treasure *t, object *op); /* overrule default values */ 45static void change_treasure (treasure *t, object *op); /* overrule default values */
44 46
45typedef std::tr1::unordered_map< 47typedef ska::flat_hash_map<
46 const char *, 48 const char *,
47 treasurelist *, 49 treasurelist *,
48 str_hash, 50 str_hash,
49 str_equal, 51 str_equal,
50 slice_allocator< std::pair<const char *const, treasurelist *> > 52 slice_allocator< std::pair<const char *const, treasurelist *> >
51> tl_map_t; 53> tl_map_t;
52 54
53static tl_map_t tl_map; 55static tl_map_t tl_map;
54 56
55//TODO: class method 57//TODO: class method
490 { 0, 0, 0, 3, 97}, // 29 492 { 0, 0, 0, 3, 97}, // 29
491 { 0, 0, 0, 0, 100}, // 30 493 { 0, 0, 0, 0, 100}, // 30
492 { 0, 0, 0, 0, 100}, // 31 494 { 0, 0, 0, 0, 100}, // 31
493}; 495};
494 496
495/* calculate the appropriate level for wands staves and scrolls. 497/* calculate the appropriate level for wands staves and scrolls.
496 * This code presumes that op has had its spell object created (in op->inv) 498 * This code presumes that op has had its spell object created (in op->inv)
497 * 499 *
498 * elmex Wed Aug 9 17:44:59 CEST 2006: 500 * elmex Wed Aug 9 17:44:59 CEST 2006:
499 * Removed multiplicator, too many high-level items were generated on low-difficulty maps. 501 * Removed multiplicator, too many high-level items were generated on low-difficulty maps.
500 */ 502 */
775 return 1; 777 return 1;
776 778
777 return 0; 779 return 0;
778} 780}
779 781
782static double
783value_factor_from_spell_item (object *spell, object *item)
784{
785 double factor =
786 pow ((spell->value > 0 ? spell->value : 1)
787 * spell->level, 1.5);
788
789 if (item) // this if for: wands/staffs/rods:
790 {
791 /* Old crossfire comment ahead:
792 * Add 50 to both level an divisor to keep prices a little more
793 * reasonable. Otherwise, a high level version of a low level
794 * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
795 * 10 time multiplier). This way, the value are a bit more reasonable.
796 */
797
798 factor *= item->level + 50;
799 factor /= item->inv->level + 50;
800 }
801
802 return factor;
803}
804
780#define DICE2 (get_magic(2) == 2 ? 2 : 1) 805#define DICE2 (get_magic(2) == 2 ? 2 : 1)
781#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) 806#define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3))
782 807
783/* 808/*
784 * fix_generated_item(): This is called after an item is generated, in 809 * fix_generated_item(): This is called after an item is generated, in
785 * order to set it up right. This produced magical bonuses, puts spells 810 * order to set it up right. This produced magical bonuses, puts spells
786 * into scrolls/books/wands, makes it unidentified, hides the value, etc. 811 * into scrolls/books/wands, makes it unidentified, hides the value, etc.
787 */ 812 */
788 813
789/* 4/28/96 added creator object from which op may now inherit properties based on 814/* 4/28/96 added creator object from which op may now inherit properties based on
790 * op->type. Right now, which stuff the creator passes on is object type 815 * op->type. Right now, which stuff the creator passes on is object type
791 * dependant. I know this is a spagetti manuever, but is there a cleaner 816 * dependant. I know this is a spagetti manuever, but is there a cleaner
792 * way to do this? b.t. */ 817 * way to do this? b.t. */
793 818
794/* 819/*
795 * ! (flags & GT_ENVIRONMENT): 820 * ! (flags & GT_ENVIRONMENT):
796 * Automatically calls fix_flesh_item(). 821 * Automatically calls fix_flesh_item().
896 { 921 {
897 if (op->type == POTION) 922 if (op->type == POTION)
898 /* Handle healing and magic power potions */ 923 /* Handle healing and magic power potions */
899 if (op->stats.sp && !op->randomitems) 924 if (op->stats.sp && !op->randomitems)
900 { 925 {
901 object *tmp = get_archetype (spell_mapping [op->stats.sp]); 926 object *tmp = archetype::get (spell_mapping [op->stats.sp]);
902 insert_ob_in_ob (tmp, op); 927 insert_ob_in_ob (tmp, op);
903 op->stats.sp = 0; 928 op->stats.sp = 0;
904 } 929 }
905 } 930 }
906 else if (!op->title) /* Only modify object if not special */ 931 else if (!op->title) /* Only modify object if not special */
924 } 949 }
925 break; 950 break;
926 951
927 case POTION: 952 case POTION:
928 { 953 {
929 int too_many_tries = 0, is_special = 0; 954 int too_many_tries = 0;
930 955
931 /* Handle healing and magic power potions */ 956 /* Handle healing and magic power potions */
932 if (op->stats.sp && !op->randomitems) 957 if (op->stats.sp && !op->randomitems)
933 { 958 {
934 object *tmp = get_archetype (spell_mapping[op->stats.sp]); 959 object *tmp = archetype::get (spell_mapping[op->stats.sp]);
935 insert_ob_in_ob (tmp, op); 960 insert_ob_in_ob (tmp, op);
936 op->stats.sp = 0; 961 op->stats.sp = 0;
937 } 962 }
938 963
939 while (!(is_special = special_potion (op)) && !op->inv) 964 while (!special_potion (op) && !op->inv)
940 { 965 {
941 generate_artifact (op, difficulty); 966 generate_artifact (op, difficulty);
942 if (too_many_tries++ > 10) 967 if (too_many_tries++ > 10)
943 break; 968 break;
944 } 969 }
1041 if (creator->slaying && !op->slaying) /* for check_inv floors */ 1066 if (creator->slaying && !op->slaying) /* for check_inv floors */
1042 op->slaying = creator->slaying; 1067 op->slaying = creator->slaying;
1043 break; 1068 break;
1044 1069
1045 case SPELLBOOK: 1070 case SPELLBOOK:
1046 op->value *= pow ((op->inv->value > 0 ? op->inv->value : 1) 1071 op->value *= value_factor_from_spell_item (op->inv, 0);
1047 * op->inv->level,
1048 1.5);
1049 1072
1050 /* add exp so learning gives xp */ 1073 /* add exp so learning gives xp */
1051 op->level = op->inv->level; 1074 op->level = op->inv->level;
1052 op->stats.exp = op->value; 1075 op->stats.exp = op->value;
1053 break; 1076 break;
1058 * and reset nrof. 1081 * and reset nrof.
1059 */ 1082 */
1060 op->stats.food = op->inv->nrof; 1083 op->stats.food = op->inv->nrof;
1061 op->nrof = 1; 1084 op->nrof = 1;
1062 /* If the spell changes by level, choose a random level 1085 /* If the spell changes by level, choose a random level
1063 * for it, and adjust price. If the spell doesn't 1086 * for it.
1064 * change by level, just set the wand to the level of
1065 * the spell, and value calculation is simpler.
1066 */ 1087 */
1067 if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) 1088 if (op->inv->duration_modifier
1068 { 1089 || op->inv->dam_modifier
1090 || op->inv->range_modifier)
1069 op->level = level_for_item (op, difficulty); 1091 op->level = level_for_item (op, difficulty);
1070 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1071 }
1072 else 1092 else
1073 {
1074 op->level = op->inv->level; 1093 op->level = op->inv->level;
1075 op->value = op->value * op->inv->value; 1094
1076 } 1095 op->value *= value_factor_from_spell_item (op->inv, op);
1077 break; 1096 break;
1078 1097
1079 case ROD: 1098 case ROD:
1080 op->level = level_for_item (op, difficulty); 1099 op->level = level_for_item (op, difficulty);
1081 /* Add 50 to both level an divisor to keep prices a little more 1100 op->value *= value_factor_from_spell_item (op->inv, op);
1082 * reasonable. Otherwise, a high level version of a low level
1083 * spell can be worth tons a money (eg, level 20 rod, level 2 spell =
1084 * 10 time multiplier). This way, the value are a bit more reasonable.
1085 */
1086 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50);
1087 1101
1088 /* maxhp is used to denote how many 'charges' the rod holds before */ 1102 /* maxhp is used to denote how many 'charges' the rod holds before */
1089 if (op->stats.maxhp) 1103 if (op->stats.maxhp)
1090 op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); 1104 op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace);
1091 else 1105 else
1094 op->stats.hp = op->stats.maxhp; 1108 op->stats.hp = op->stats.maxhp;
1095 break; 1109 break;
1096 1110
1097 case SCROLL: 1111 case SCROLL:
1098 op->level = level_for_item (op, difficulty); 1112 op->level = level_for_item (op, difficulty);
1099 op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); 1113 op->value *= value_factor_from_spell_item (op->inv, op);
1100 1114
1101 /* add exp so reading them properly gives xp */ 1115 /* add exp so reading them properly gives xp */
1102 op->stats.exp = op->value / 5; 1116 op->stats.exp = op->value / 5;
1103 op->nrof = op->inv->nrof; 1117 op->nrof = op->inv->nrof;
1104 break; 1118 break;
1169 */ 1183 */
1170void 1184void
1171init_artifacts () 1185init_artifacts ()
1172{ 1186{
1173 static int has_been_inited = 0; 1187 static int has_been_inited = 0;
1174 char filename[MAX_BUF];
1175 artifact *art = NULL; 1188 artifact *art = NULL;
1176 artifactlist *al; 1189 artifactlist *al;
1177 1190
1178 if (has_been_inited) 1191 if (has_been_inited)
1179 return; 1192 return;
1180 else 1193 else
1181 has_been_inited = 1; 1194 has_been_inited = 1;
1182 1195
1183 sprintf (filename, "%s/artifacts", settings.datadir); 1196 object_thawer f (settings.datadir, "artifacts");
1184 object_thawer f (filename);
1185 1197
1186 if (!f) 1198 if (!f)
1187 return; 1199 return;
1188 1200
1189 for (;;) 1201 for (;;)
1274 } 1286 }
1275#if 0 1287#if 0
1276 LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance); 1288 LOG (llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
1277#endif 1289#endif
1278 } 1290 }
1279
1280 LOG (llevDebug, "done.\n");
1281} 1291}
1282 1292
1283/* 1293/*
1284 * Used in artifact generation. The bonuses of the first object 1294 * Used in artifact generation. The bonuses of the first object
1285 * is modified by the bonuses of the second object. 1295 * is modified by the bonuses of the second object.
1286 */ 1296 */
1287void 1297void
1288add_abilities (object *op, object *change) 1298add_abilities (object *op, object *change)
1289{ 1299{
1290 if (change->face != blank_face) 1300 if (change->face != blank_face)
1291 {
1292#ifdef TREASURE_VERBOSE
1293 LOG (llevDebug, "add_abilities change face: %d\n", change->face);
1294#endif
1295 op->face = change->face; 1301 op->face = change->face;
1296 }
1297 1302
1298 for (int i = 0; i < NUM_STATS; i++) 1303 for (int i = 0; i < NUM_STATS; i++)
1299 change_attr_value (&(op->stats), i, change->stats.stat (i)); 1304 change_attr_value (&(op->stats), i, change->stats.stat (i));
1300 1305
1301 op->attacktype |= change->attacktype; 1306 op->attacktype |= change->attacktype;
1486 name = tmp->name + 1, neg = 1; 1491 name = tmp->name + 1, neg = 1;
1487 else 1492 else
1488 name = tmp->name, neg = 0; 1493 name = tmp->name, neg = 0;
1489 1494
1490 /* If we match name, then return the opposite of 'neg' */ 1495 /* If we match name, then return the opposite of 'neg' */
1491 if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) 1496 if (!strcmp (name, op->arch->archname))
1492 return !neg; 1497 return !neg;
1493 1498
1494 /* Set success as true, since if the match was an inverse, it means 1499 /* Set success as true, since if the match was an inverse, it means
1495 * everything is allowed except what we match 1500 * everything is allowed except what we match
1496 */ 1501 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines