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,2010 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 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 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 |
… | |
… | |
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 | |
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) |
|
|
44 | |
39 | extern char *spell_mapping[]; |
45 | extern char *spell_mapping[]; |
40 | |
46 | |
41 | static treasurelist *first_treasurelist; |
47 | static treasurelist *first_treasurelist; |
42 | |
48 | |
43 | static void change_treasure (treasure *t, object *op); /* overrule default values */ |
49 | static void change_treasure (treasure *t, object *op); /* overrule default values */ |
44 | |
50 | |
45 | typedef std::tr1::unordered_map< |
51 | typedef ska::flat_hash_map< |
46 | const char *, |
52 | const char *, |
47 | treasurelist *, |
53 | treasurelist *, |
48 | str_hash, |
54 | str_hash, |
49 | str_equal, |
55 | str_equal, |
50 | slice_allocator< std::pair<const char *const, treasurelist *> > |
56 | slice_allocator< std::pair<const char *const, treasurelist *> > |
51 | > tl_map_t; |
57 | > tl_map_t; |
52 | |
58 | |
53 | static tl_map_t tl_map; |
59 | static tl_map_t tl_map; |
54 | |
60 | |
55 | //TODO: class method |
61 | //TODO: class method |
… | |
… | |
490 | { 0, 0, 0, 3, 97}, // 29 |
496 | { 0, 0, 0, 3, 97}, // 29 |
491 | { 0, 0, 0, 0, 100}, // 30 |
497 | { 0, 0, 0, 0, 100}, // 30 |
492 | { 0, 0, 0, 0, 100}, // 31 |
498 | { 0, 0, 0, 0, 100}, // 31 |
493 | }; |
499 | }; |
494 | |
500 | |
495 | /* calculate the appropriate level for wands staves and scrolls. |
501 | /* calculate the appropriate level for wands staves and scrolls. |
496 | * This code presumes that op has had its spell object created (in op->inv) |
502 | * This code presumes that op has had its spell object created (in op->inv) |
497 | * |
503 | * |
498 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
504 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
499 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
505 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
500 | */ |
506 | */ |
… | |
… | |
775 | return 1; |
781 | return 1; |
776 | |
782 | |
777 | return 0; |
783 | return 0; |
778 | } |
784 | } |
779 | |
785 | |
|
|
786 | static double |
|
|
787 | value_factor_from_spell_item (object *spell, object *item) |
|
|
788 | { |
|
|
789 | double factor = |
|
|
790 | pow ((spell->value > 0 ? spell->value : 1) |
|
|
791 | * spell->level, 1.5); |
|
|
792 | |
|
|
793 | if (item) // this if for: wands/staffs/rods: |
|
|
794 | { |
|
|
795 | /* Old crossfire comment ahead: |
|
|
796 | * Add 50 to both level an divisor to keep prices a little more |
|
|
797 | * reasonable. Otherwise, a high level version of a low level |
|
|
798 | * spell can be worth tons a money (eg, level 20 rod, level 2 spell = |
|
|
799 | * 10 time multiplier). This way, the value are a bit more reasonable. |
|
|
800 | */ |
|
|
801 | |
|
|
802 | factor *= item->level + 50; |
|
|
803 | factor /= item->inv->level + 50; |
|
|
804 | } |
|
|
805 | |
|
|
806 | return factor; |
|
|
807 | } |
|
|
808 | |
780 | #define DICE2 (get_magic(2) == 2 ? 2 : 1) |
809 | #define DICE2 (get_magic(2) == 2 ? 2 : 1) |
781 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
810 | #define DICESPELL (rndm (3) + rndm (3) + rndm (3) + rndm (3) + rndm (3)) |
782 | |
811 | |
783 | /* |
812 | /* |
784 | * fix_generated_item(): This is called after an item is generated, in |
813 | * 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 |
814 | * order to set it up right. This produced magical bonuses, puts spells |
786 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
815 | * into scrolls/books/wands, makes it unidentified, hides the value, etc. |
787 | */ |
816 | */ |
788 | |
817 | |
789 | /* 4/28/96 added creator object from which op may now inherit properties based on |
818 | /* 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 |
819 | * 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 |
820 | * dependant. I know this is a spagetti manuever, but is there a cleaner |
792 | * way to do this? b.t. */ |
821 | * way to do this? b.t. */ |
793 | |
822 | |
794 | /* |
823 | /* |
795 | * ! (flags & GT_ENVIRONMENT): |
824 | * ! (flags & GT_ENVIRONMENT): |
796 | * Automatically calls fix_flesh_item(). |
825 | * Automatically calls fix_flesh_item(). |
… | |
… | |
896 | { |
925 | { |
897 | if (op->type == POTION) |
926 | if (op->type == POTION) |
898 | /* Handle healing and magic power potions */ |
927 | /* Handle healing and magic power potions */ |
899 | if (op->stats.sp && !op->randomitems) |
928 | if (op->stats.sp && !op->randomitems) |
900 | { |
929 | { |
901 | object *tmp = get_archetype (spell_mapping [op->stats.sp]); |
930 | object *tmp = archetype::get (spell_mapping [op->stats.sp]); |
902 | insert_ob_in_ob (tmp, op); |
931 | insert_ob_in_ob (tmp, op); |
903 | op->stats.sp = 0; |
932 | op->stats.sp = 0; |
904 | } |
933 | } |
905 | } |
934 | } |
906 | else if (!op->title) /* Only modify object if not special */ |
935 | else if (!op->title) /* Only modify object if not special */ |
… | |
… | |
924 | } |
953 | } |
925 | break; |
954 | break; |
926 | |
955 | |
927 | case POTION: |
956 | case POTION: |
928 | { |
957 | { |
929 | int too_many_tries = 0, is_special = 0; |
958 | int too_many_tries = 0; |
930 | |
959 | |
931 | /* Handle healing and magic power potions */ |
960 | /* Handle healing and magic power potions */ |
932 | if (op->stats.sp && !op->randomitems) |
961 | if (op->stats.sp && !op->randomitems) |
933 | { |
962 | { |
934 | object *tmp = get_archetype (spell_mapping[op->stats.sp]); |
963 | object *tmp = archetype::get (spell_mapping[op->stats.sp]); |
935 | insert_ob_in_ob (tmp, op); |
964 | insert_ob_in_ob (tmp, op); |
936 | op->stats.sp = 0; |
965 | op->stats.sp = 0; |
937 | } |
966 | } |
938 | |
967 | |
939 | while (!(is_special = special_potion (op)) && !op->inv) |
968 | while (!special_potion (op) && !op->inv) |
940 | { |
969 | { |
941 | generate_artifact (op, difficulty); |
970 | generate_artifact (op, difficulty); |
942 | if (too_many_tries++ > 10) |
971 | if (too_many_tries++ > 10) |
943 | break; |
972 | break; |
944 | } |
973 | } |
… | |
… | |
1041 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1070 | if (creator->slaying && !op->slaying) /* for check_inv floors */ |
1042 | op->slaying = creator->slaying; |
1071 | op->slaying = creator->slaying; |
1043 | break; |
1072 | break; |
1044 | |
1073 | |
1045 | case SPELLBOOK: |
1074 | case SPELLBOOK: |
1046 | op->value *= pow ((op->inv->value > 0 ? op->inv->value : 1) |
1075 | op->value *= value_factor_from_spell_item (op->inv, 0); |
1047 | * op->inv->level, |
|
|
1048 | 1.5); |
|
|
1049 | |
1076 | |
1050 | /* add exp so learning gives xp */ |
1077 | /* add exp so learning gives xp */ |
1051 | op->level = op->inv->level; |
1078 | op->level = op->inv->level; |
1052 | op->stats.exp = op->value; |
1079 | op->stats.exp = op->value; |
1053 | break; |
1080 | break; |
… | |
… | |
1058 | * and reset nrof. |
1085 | * and reset nrof. |
1059 | */ |
1086 | */ |
1060 | op->stats.food = op->inv->nrof; |
1087 | op->stats.food = op->inv->nrof; |
1061 | op->nrof = 1; |
1088 | op->nrof = 1; |
1062 | /* If the spell changes by level, choose a random level |
1089 | /* If the spell changes by level, choose a random level |
1063 | * for it, and adjust price. If the spell doesn't |
1090 | * for it. |
1064 | * change by level, just set the wand to the level of |
|
|
1065 | * the spell, and value calculation is simpler. |
|
|
1066 | */ |
1091 | */ |
1067 | if (op->inv->duration_modifier || op->inv->dam_modifier || op->inv->range_modifier) |
1092 | if (op->inv->duration_modifier |
1068 | { |
1093 | || op->inv->dam_modifier |
|
|
1094 | || op->inv->range_modifier) |
1069 | op->level = level_for_item (op, difficulty); |
1095 | 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 |
1096 | else |
1073 | { |
|
|
1074 | op->level = op->inv->level; |
1097 | op->level = op->inv->level; |
1075 | op->value = op->value * op->inv->value; |
1098 | |
1076 | } |
1099 | op->value *= value_factor_from_spell_item (op->inv, op); |
1077 | break; |
1100 | break; |
1078 | |
1101 | |
1079 | case ROD: |
1102 | case ROD: |
1080 | op->level = level_for_item (op, difficulty); |
1103 | op->level = level_for_item (op, difficulty); |
1081 | /* Add 50 to both level an divisor to keep prices a little more |
1104 | 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 | |
1105 | |
1088 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1106 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1089 | if (op->stats.maxhp) |
1107 | if (op->stats.maxhp) |
1090 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1108 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1091 | else |
1109 | else |
… | |
… | |
1094 | op->stats.hp = op->stats.maxhp; |
1112 | op->stats.hp = op->stats.maxhp; |
1095 | break; |
1113 | break; |
1096 | |
1114 | |
1097 | case SCROLL: |
1115 | case SCROLL: |
1098 | op->level = level_for_item (op, difficulty); |
1116 | op->level = level_for_item (op, difficulty); |
1099 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1117 | op->value *= value_factor_from_spell_item (op->inv, op); |
1100 | |
1118 | |
1101 | /* add exp so reading them properly gives xp */ |
1119 | /* add exp so reading them properly gives xp */ |
1102 | op->stats.exp = op->value / 5; |
1120 | op->stats.exp = op->value / 5; |
1103 | op->nrof = op->inv->nrof; |
1121 | op->nrof = op->inv->nrof; |
1104 | break; |
1122 | break; |
… | |
… | |
1477 | name = tmp->name + 1, neg = 1; |
1495 | name = tmp->name + 1, neg = 1; |
1478 | else |
1496 | else |
1479 | name = tmp->name, neg = 0; |
1497 | name = tmp->name, neg = 0; |
1480 | |
1498 | |
1481 | /* If we match name, then return the opposite of 'neg' */ |
1499 | /* If we match name, then return the opposite of 'neg' */ |
1482 | if (!strcmp (name, op->name) || (op->arch && !strcmp (name, op->arch->archname))) |
1500 | if (!strcmp (name, op->arch->archname)) |
1483 | return !neg; |
1501 | return !neg; |
1484 | |
1502 | |
1485 | /* Set success as true, since if the match was an inverse, it means |
1503 | /* Set success as true, since if the match was an inverse, it means |
1486 | * everything is allowed except what we match |
1504 | * everything is allowed except what we match |
1487 | */ |
1505 | */ |