36 #define ALLOWED_COMBINATION
44 #define TREASURE_DEBUG
144 while (fgets(buf,
MAX_BUF, fp) != NULL) {
149 if ((cp = strchr(buf,
'\n')) != NULL)
155 if (sscanf(cp,
"arch %s", variable)) {
157 LOG(
llevError,
"Treasure lacks archetype: %s\n", variable);
158 }
else if (sscanf(cp,
"list %s", variable))
160 else if (sscanf(cp,
"change_name %s", variable))
162 else if (sscanf(cp,
"change_title %s", variable))
164 else if (sscanf(cp,
"change_slaying %s", variable))
166 else if (sscanf(cp,
"chance %d", &value))
168 else if (sscanf(cp,
"nrof %d", &value))
170 else if (sscanf(cp,
"magic %d", &value))
172 else if (!strcmp(cp,
"yes"))
174 else if (!strcmp(cp,
"no"))
176 else if (!strcmp(cp,
"end"))
178 else if (!strcmp(cp,
"more")) {
182 LOG(
llevError,
"Unknown treasure-command: '%s', last entry %s, line %d\n", cp, t->
name ? t->
name :
"null", *line);
188 #ifdef TREASURE_DEBUG
201 if (t->
item == NULL && t->
name == NULL)
202 LOG(
llevError,
"Treasurelist %s has element with no name or archetype\n", tl->
name);
204 LOG(
llevError,
"Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", tl->
name);
206 if (t->
name && strcmp(t->
name,
"NONE"))
236 while (fgets(buf,
MAX_BUF, fp) != NULL) {
241 if (sscanf(buf,
"treasureone %s\n", name) || sscanf(buf,
"treasure %s\n", name)) {
245 if (previous == NULL)
256 if (!strncmp(buf,
"treasureone", 11)) {
257 for (t = tl->
items; t != NULL; t = t->
next) {
258 #ifdef TREASURE_DEBUG
261 LOG(
llevError,
" the next_yes or next_no field is set\n");
268 LOG(
llevError,
"Treasure-list didn't understand: %s, line %d\n", buf, line);
272 #ifdef TREASURE_DEBUG
310 LOG(
llevError,
"Couldn't find treasurelist %s\n", name);
394 if ((
int)t->
chance >= 100 || (RANDOM()%100+1) < (
int)t->
chance) {
396 if (strcmp(t->
name,
"NONE") && difficulty >= t->
magic)
402 tmp->
nrof = RANDOM()%((int)t->
nrof)+1;
440 LOG(
llevDebug,
"create_one_treasure: tries exceeded 100, returning without making treasure\n");
444 for (t = tl->
items; t != NULL; t = t->
next) {
450 if (!t || value >= 0) {
451 LOG(
llevError,
"create_one_treasure: got null object or not able to find treasure\n");
456 if (!strcmp(t->
name,
"NONE"))
458 if (difficulty >= t->
magic)
477 tmp->
nrof = RANDOM()%((int)t->
nrof)+1;
501 LOG(
llevDebug,
"createtreasure: tries exceeded 100, returning without making treasure\n");
534 LOG(
llevError,
"In generate treasure, created multiple objects.\n");
555 int level, mult, olevel;
580 olevel = mult*
rndm(0, difficulty)+level;
647 { 70, 2, 7, 11, 10 },
648 { 70, 2, 7, 11, 10 },
649 { 70, 2, 7, 11, 10 },
650 { 70, 2, 7, 11, 10 },
651 { 70, 2, 7, 11, 10 },
652 { 70, 2, 5, 12, 11 },
653 { 70, 2, 5, 12, 11 },
654 { 70, 2, 5, 12, 11 },
655 { 70, 2, 5, 12, 11 },
656 { 70, 2, 5, 12, 11 },
657 { 70, 2, 3, 13, 12 },
658 { 70, 2, 3, 13, 12 },
659 { 70, 2, 3, 13, 12 },
660 { 70, 2, 3, 13, 12 },
661 { 70, 2, 3, 13, 12 },
662 { 70, 2, 3, 12, 13 },
663 { 70, 2, 3, 12, 13 },
664 { 70, 2, 3, 12, 13 },
665 { 70, 2, 3, 12, 13 },
666 { 70, 2, 3, 12, 13 },
667 { 70, 2, 3, 11, 14 },
668 { 70, 2, 3, 11, 14 },
669 { 70, 2, 3, 11, 14 },
670 { 70, 2, 3, 11, 14 },
671 { 70, 2, 3, 11, 14 },
672 { 70, 2, 3, 10, 15 },
673 { 70, 2, 3, 10, 15 },
674 { 70, 2, 3, 10, 15 },
675 { 70, 2, 3, 10, 15 },
676 { 70, 2, 3, 10, 15 },
818 percent = RANDOM()%100;
820 for (loop = 0; loop < (
MAXMAGIC+1); ++loop) {
826 LOG(
llevError,
"Warning, table for difficulty %d bad.\n", difficulty);
830 return (RANDOM()%3) ? loop : -loop;
853 if (magic < 0 && !(RANDOM()%3))
859 if (magic < 0 && !(RANDOM()%3))
910 int r = RANDOM()%(bonus > 0 ? 25 : 11);
967 val = 10+RANDOM()%b+RANDOM()%b+RANDOM()%b+RANDOM()%b;
975 val = 2*-val-RANDOM()%b;
1017 op->
value *= 2*bonus;
1035 for (i = 0; i < 4; i++)
1041 #define DICE2 (get_magic(2) == 2 ? 2 : 1)
1042 #define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)
1071 int was_magic = op->
magic, num_enchantments = 0, save_item_power;
1073 if (!creator || creator->
type == op->
type)
1083 LOG(
llevDebug,
"fix_generated_item: Unable to generate treasure for %s\n", op->
name);
1092 set_magic(difficulty > 25 ? 30 : difficulty+5, op, max_magic, flags);
1096 if (!op->
magic && max_magic)
1097 set_magic(difficulty, op, max_magic, flags);
1101 || difficulty >= 999)
1116 if (save_item_power)
1120 }
else if (save_item_power) {
1147 if (flags>_MINIMAL) {
1157 }
else if (!op->
title) {
1177 int too_many_tries = 0, is_special = 0;
1190 if (too_many_tries++ > 10)
1199 op->
level = op->
inv->
level/2+RANDOM()%difficulty+RANDOM()%difficulty;
1213 if (op->
arch == NULL) {
1228 if (!(RANDOM()%4)) {
1233 if (!(RANDOM()%4)) {
1249 if (!op->
msg && RANDOM()%10) {
1255 op->
level = RANDOM()%20+1;
1284 if (!(flags>_ONLY_GOOD) &&
rndm(1, 100) <= 5) {
1285 if (
rndm(1, 6) <= 1)
1289 }
else if (
rndm(1, 100) <= 1) {
1343 if (!(flags>_ONLY_GOOD) &&
rndm(1, 100) <= 20) {
1344 if (
rndm(1, 6) <= 1)
1348 }
else if (
rndm(1, 100) <= 2) {
1435 if (al->
type == type)
1454 for (art = al->
items; art != NULL; art = art->
next) {
1457 fprintf(
logfile,
"\tAllowed combinations:");
1458 for (next = art->
allowed; next != NULL; next = next->
next)
1478 if (t->
name != NULL) {
1479 for (i = 0; i < depth; i++)
1484 for (i = 0; i < depth; i++)
1486 fprintf(
logfile,
"} (end of list: %s)\n", t->
name);
1488 for (i = 0; i < depth; i++)
1496 for (i = 0; i < depth; i++)
1498 fprintf(
logfile,
" (if yes)\n");
1502 for (i = 0; i < depth; i++)
1504 fprintf(
logfile,
" (if no)\n");
1527 fprintf(
logfile,
"(nothing)\n");
1532 fprintf(
logfile,
"No objects have the name %s!\n\n", name);
1540 static int has_been_inited = 0;
1549 memset(&dummy_archetype, 0,
sizeof(
archetype));
1551 if (has_been_inited)
1554 has_been_inited = 1;
1559 LOG(
llevDebug,
"Reading artifacts from %s...\n", filename);
1565 while (fgets(buf,
HUGE_BUF, fp) != NULL) {
1568 if ((cp = strchr(buf,
'\n')) != NULL)
1576 if (!strncmp(cp,
"Allowed", 7)) {
1582 cp = strchr(cp,
' ')+1;
1583 while (*(cp+strlen(cp)-1) ==
' ')
1584 cp[strlen(cp)-1] =
'\0';
1586 if (!strcmp(cp,
"all"))
1593 if ((next = strchr(cp,
',')) != NULL)
1599 }
while ((cp = next) != NULL);
1600 }
else if (sscanf(cp,
"chance %d", &value))
1602 else if (sscanf(cp,
"difficulty %d", &value))
1604 else if (!strncmp(cp,
"Object", 6)) {
1605 art->
item = (
object *)calloc(1,
sizeof(
object));
1606 if (art->
item == NULL) {
1607 LOG(
llevError,
"init_artifacts: memory allocation failure.\n");
1611 art->
item->
arch = &dummy_archetype;
1613 LOG(
llevError,
"Init_Artifacts: Could not load object.\n");
1627 LOG(
llevError,
"Unknown input in artifact file: %s\n", buf);
1633 for (art = al->
items; art != NULL; art = art->
next) {
1657 #ifdef TREASURE_VERBOSE
1711 op->
nrof = RANDOM()%((int)change->
nrof)+1;
1757 if (change->
level < 0)
1834 object *inv = change->
inv;
1850 int neg, success = 0;
1857 #ifdef TREASURE_VERBOSE
1860 if (*tmp->
name ==
'!')
1868 if (!strcmp(name, op->
name) || (op->
arch && !strcmp(name, op->
arch->
name)))
1887 snprintf(new_name,
sizeof(new_name),
"of %s", artifact->
name);
1897 #define ARTIFACT_TRIES 2
1920 for (art = al->
items; art != NULL; art = art->
next) {
1926 if (art == NULL || roll >= 0) {
1927 LOG(
llevError,
"Got null entry and non zero roll in generate_artifact, type %d\n", op->
type);
1930 if (!strcmp(art->
item->
name,
"NONE"))
1936 if (difficulty < art->difficulty)
1940 #ifdef TREASURE_VERBOSE
1983 LOG(
llevError,
"could not find original archetype %s for custom monster!\n", donor->
arch->
name);
1990 if ((item->
weight = (
signed long)(((
double)item->
weight/(
double)100.0)*(
double)donor->
weight)) == 0)
2119 for (; al != NULL; al = nextal) {
int legal_artifact_combination(object *op, artifact *art)
archetype * find_archetype(const char *name)
static void free_treasurestruct(treasure *t)
const char *const spell_mapping[]
struct _change_arch change_arch
sstring add_refcount(sstring str)
int get_power_from_ench(int ench)
void dump_artifacts(void)
struct artifactstruct * items
static void free_charlinks(linked_char *lc)
treasurelist * find_treasurelist(const char *name)
sint8 get_attr_value(const living *stats, int attr)
void free_string(sstring str)
#define SET_ANIMATION(ob, newanim)
struct treasureliststruct * randomitems
struct treasureliststruct * next
static int level_for_item(const object *op, int difficulty, int retmult)
void close_and_delete(FILE *fp, int compressed)
void change_attr_value(living *stats, int attr, sint8 value)
static artifactlist * get_empty_artifactlist(void)
struct archt * other_arch
static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries)
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
static int get_magic(int diff)
void trap_adjust(object *trap, int difficulty)
void set_materialname(object *op, int difficulty, materialtype_t *nmt)
void add_abilities(object *op, object *change)
int rndm(int min, int max)
EXTERN archetype * amulet_arch
void remove_ob(object *op)
sstring find_string(const char *str)
static artifact * get_empty_artifact(void)
struct artifactliststruct * next
object * create_archetype(const char *name)
#define FLAG_OBJ_ORIGINAL
artifactlist * find_artifactlist(int type)
static void change_treasure(treasure *t, object *op)
const char * materialname
void free_all_treasures(void)
static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1]
#define CHANCE_FOR_ARTIFACT
static int special_potion(object *op)
#define MAX_SPELLITEM_LEVEL
void set_attr_value(living *stats, int attr, sint8 value)
static void check_treasurelist(const treasure *t, const treasurelist *tl)
struct linked_char * next
void monster_check_apply(object *mon, object *item)
#define ARMOUR_SPEED(xyz)
void load_treasures(void)
void generate_artifact(object *op, int difficulty)
void tailor_readable_ob(object *book, int msg_type)
EXTERN int resist_table[]
static treasurelist * get_empty_treasurelist(void)
static treasure * load_treasure(FILE *fp, int *line)
EXTERN treasurelist * first_treasurelist
struct treasurestruct * next_no
#define QUERY_FLAG(xyz, p)
#define CLEAR_FLAG(xyz, p)
EXTERN artifactlist * first_artifactlist
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
object * insert_ob_in_ob(object *op, object *where)
object * get_object(void)
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
struct treasurestruct * items
EXTERN archetype * crown_arch
static void set_magic(int difficulty, object *op, int max_magic, int flags)
static const flag_definition flags[]
void animate_object(object *op, int dir)
sint16 resist[NROFATTACKS]
EXTERN long nrofartifacts
static void put_treasure(object *op, object *creator, int flags)
EXTERN long nrofallowedstr
int snprintf(char *dest, int max, const char *format,...)
static void free_artifact(artifact *at)
struct treasurestruct * next_yes
#define FREE_AND_COPY(sv, nv)
#define NUM_ANIMATIONS(ob)
int load_object(FILE *fp, object *op, int bufstate, int map_flags)
void dump_monster_treasure(const char *name)
EXTERN archetype * staff_arch
void reset_object(object *op)
static int magic_from_difficulty(int difficulty)
void free_key_values(object *op)
void update_ob_speed(object *op)
sstring add_string(const char *str)
int strcasecmp(const char *s1, const char *s2)
void give_artifact_abilities(object *op, object *artifact)
void LOG(LogLevel logLevel, const char *format,...)
static void fix_flesh_item(object *item, object *donor)
EXTERN long warn_archetypes
EXTERN archetype * ring_arch
void set_abs_magic(object *op, int magic)
void copy_object(object *op2, object *op)
int calc_item_power(const object *op, int flag)
static void free_artifactlist(artifactlist *al)
object * generate_treasure(treasurelist *t, int difficulty)
void free_object(object *ob)
static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries)
static void set_ring_bonus(object *op, int bonus)
struct treasurestruct * next
#define FLAG_REFL_MISSILE
void init_archetype_pointers(void)
EXTERN archetype * first_archetype
object * arch_to_object(archetype *at)
FILE * open_and_uncompress(const char *name, int flag, int *compressed)
static treasure * get_empty_treasure(void)
struct artifactstruct * next
void init_artifacts(void)
static void dump_monster_treasure_rec(const char *name, treasure *t, int depth)
EXTERN long nroftreasures