49 static void build_stringlist(
const char *str,
char ***result_list,
size_t *result_size);
116 while (fl && number > 1) {
117 if (!(fl = fl->
next))
143 if (!art && strcmp(rp->
title,
"NONE") != 0) {
160 static int has_been_done = 0;
177 LOG(
llevDebug,
"Reading alchemical formulae from %s...\n", filename);
183 while (fgets(buf,
MAX_BUF, fp) != NULL) {
186 if ((cp = strchr(buf,
'\n')) != NULL)
192 if (!strncmp(cp,
"Object", 6)) {
195 }
else if (!strncmp(cp,
"keycode", 7)) {
197 }
else if (sscanf(cp,
"trans %d", &value)) {
199 }
else if (sscanf(cp,
"yield %d", &value)) {
200 formula->
yield = value;
201 }
else if (sscanf(cp,
"chance %d", &value)) {
203 }
else if (sscanf(cp,
"exp %d", &value)) {
204 formula->
exp = value;
205 }
else if (sscanf(cp,
"diff %d", &value)) {
206 formula->
diff = value;
207 }
else if (!strncmp(cp,
"ingred", 6)) {
209 cp = strchr(cp,
' ')+1;
211 if ((next = strchr(cp,
',')) != NULL) {
224 }
while ((cp = next) != NULL);
227 while (numb_ingred != 1) {
237 }
else if (!strncmp(cp,
"arch", 4)) {
240 }
else if (!strncmp(cp,
"skill", 5)) {
242 }
else if (!strncmp(cp,
"cauldron", 8)) {
245 LOG(
llevError,
"Unknown input in file %s: %s\n", filename, buf);
272 for (fl = formulalist; fl != NULL; fl = fl->
next) {
273 for (formula = fl->
items; formula != NULL; formula = formula->
next)
274 for (check = formula->
next; check != NULL; check = check->
next)
301 fprintf(
logfile,
"\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", num_ingred, num_ingred > 1 ?
"s." :
".", fl->
number, fl->
total_chance);
302 for (formula = fl->
items; formula != NULL; formula = formula->
next) {
308 const char *
string = formula->
arch_name[i];
312 if (!art && strcmp(formula->
title,
"NONE"))
315 if (strcmp(formula->
title,
"NONE"))
316 snprintf(buf,
sizeof(buf),
"%s of %s",
string, formula->
title);
318 snprintf(buf,
sizeof(buf),
"%s",
string);
322 if (formula->
ingred != NULL) {
323 int nval = 0, tval = 0;
324 fprintf(
logfile,
"\tIngred: ");
325 for (next = formula->
ingred; next != NULL; next = next->
next) {
332 if (tval != formula->
index)
333 fprintf(
logfile,
"WARNING:ingredient list and formula values not equal.\n");
335 if (formula->
skill != NULL)
336 fprintf(
logfile,
"\tSkill Required: %s", formula->
skill);
339 fprintf(
logfile,
"\tDifficulty: %d\t Exp: %d\n", formula->
diff, formula->
exp);
342 LOG(
llevError,
"Can't find archetype:%s for formula %s\n",
string, formula->
title);
373 if (t->
name != NULL) {
428 while (isdigit(*name)) {
429 mult = 10*mult+(*name-
'0');
448 cp = strstr(name,
" of ");
451 part1[cp-name] =
'\0';
461 for (art = al->
items; art != NULL; art = art->
next)
468 cp = strstr(name,
"'s ");
471 part1[cp-name] =
'\0';
506 fprintf(
logfile,
"\n Formulae with %d ingredient%s %d Formulae with total_chance=%d\n", num_ingred, num_ingred > 1 ?
"s." :
".", fl->
number, fl->
total_chance);
507 for (formula = fl->
items; formula != NULL; formula = formula->
next) {
514 const char *
string = formula->
arch_name[i];
518 if (!art && strcmp(formula->
title,
"NONE"))
521 if (!strcmp(formula->
title,
"NONE"))
522 snprintf(buf,
sizeof(buf),
"%s",
string);
524 snprintf(buf,
sizeof(buf),
"%s of %s",
string, formula->
title);
525 fprintf(
logfile,
"\n%-40s bookchance %3d skill %s\n", buf, formula->
chance, formula->
skill);
526 if (formula->
ingred != NULL) {
528 for (next = formula->
ingred; next != NULL; next = next->
next) {
532 fprintf(
logfile,
"\t%-33s%5ld\n", next->
name, cost);
533 if (cost < 0 || tcost < 0)
538 if (art != NULL && art->
item != NULL)
542 fprintf(
logfile,
"\t\tBuying result costs: %5ld", cost);
543 if (formula->
yield > 1) {
544 fprintf(
logfile,
" to %ld (max %d items)\n", cost*formula->
yield, formula->
yield);
545 cost = cost*(formula->
yield+1L)/2L;
548 fprintf(
logfile,
"\t\tIngredients cost: %5ld\n\t\tComment: ", tcost);
550 fprintf(
logfile,
"Could not find some ingredients. Check the formula!\n");
551 else if (tcost > cost)
552 fprintf(
logfile,
"Ingredients are much too expensive. Useless formula.\n");
553 else if (tcost*2L > cost)
554 fprintf(
logfile,
"Ingredients are too expensive.\n");
555 else if (tcost*10L < cost)
556 fprintf(
logfile,
"Ingredients are too cheap.\n");
562 LOG(
llevError,
"Can't find archetype:%s for formula %s\n",
string, formula->
title);
570 fprintf(
logfile,
"WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors);
582 const char *cp = name;
585 cp = strchr(cp,
' ')+1;
600 if ((numb = atoi(buf)))
618 int val = 0, len = strlen(cp), mult =
numb_ingred(buf);
646 for (art = at->
items; art; art = art->
next)
663 int number = 0, roll = 0;
671 roll = RANDOM()%number;
682 LOG(
llevError,
"get_random_recipelist(): no recipelists found!\n");
709 for (rp = fl->
items; rp; rp = rp->
next) {
723 recipe *formula = NULL, *next;
727 for (fl = formulalist; fl != NULL; fl = flnext) {
730 for (formula = fl->
items; formula != NULL; formula = next) {
731 next = formula->
next;
741 for (lchar = formula->
ingred; lchar; lchar = charnext) {
742 charnext = lchar->
next;
775 for (p = strtok(dup,
","); p != NULL; p = strtok(NULL,
","))
778 *result_list = malloc(size*
sizeof(*result_list));
779 if (*result_list == NULL)
783 for (i = 0; i < size; i++) {
784 (*result_list)[i] = dup;
785 dup = dup+strlen(dup)+1;
int legal_artifact_combination(object *op, artifact *art)
static void check_formulae(void)
archetype * find_archetype(const char *name)
archetype * find_treasure_by_name(const treasure *t, const char *name, int depth)
static void build_stringlist(const char *str, char ***result_list, size_t *result_size)
recipe * get_random_recipe(recipelist *rpl)
struct recipeliststruct * next
static int check_recipe(const recipe *rp)
struct artifactstruct * items
treasurelist * find_treasurelist(const char *name)
void free_string(sstring str)
struct treasureliststruct * randomitems
static int numb_ingred(const char *buf)
static recipelist * init_recipelist(void)
void close_and_delete(FILE *fp, int compressed)
static recipelist * get_random_recipelist(void)
void dump_alchemy_costs(void)
struct artifactliststruct * next
object * create_archetype(const char *name)
artifactlist * find_artifactlist(int type)
static const char * ingred_name(const char *name)
struct linked_char * next
int strtoint(const char *buf)
struct treasurestruct * next_no
EXTERN artifactlist * first_artifactlist
char * strdup_local(const char *str)
static recipelist * formulalist
struct treasurestruct * items
void free_all_recipes(void)
int snprintf(char *dest, int max, const char *format,...)
struct treasurestruct * next_yes
struct recipestruct * next
sstring add_string(const char *str)
int strcasecmp(const char *s1, const char *s2)
void LOG(LogLevel logLevel, const char *format,...)
artifact * locate_recipe_artifact(const recipe *rp, size_t idx)
static long find_ingred_cost(const char *name)
static recipe * get_empty_formula(void)
void free_object(object *ob)
struct treasurestruct * next
EXTERN archetype * first_archetype
FILE * open_and_uncompress(const char *name, int flag, int *compressed)
struct recipestruct * items
recipelist * get_formulalist(int i)
struct artifactstruct * next