44 static void build_stringlist(
const char *str,
char ***result_list,
size_t *result_size);
100 while (fl && number > 1) {
101 if (!(fl = fl->
next))
127 if (!art && strcmp(rp->
title,
"NONE") != 0) {
144 static int has_been_done = 0;
161 LOG(
llevDebug,
"Reading alchemical formulae from %s...\n", filename);
162 if ((fp = fopen(filename,
"r")) == NULL) {
167 while (fgets(buf,
MAX_BUF, fp) != NULL) {
170 if ((cp = strchr(buf,
'\n')) != NULL)
176 if (!strncmp(cp,
"Object", 6)) {
179 }
else if (formula == NULL) {
180 LOG(
llevError,
"recipe.c: First key in formulae file is not \"Object\".\n");
182 }
else if (!strncmp(cp,
"keycode", 7)) {
184 }
else if (sscanf(cp,
"trans %d", &value)) {
186 }
else if (sscanf(cp,
"yield %d", &value)) {
187 formula->
yield = value;
188 }
else if (sscanf(cp,
"chance %d", &value)) {
190 }
else if (sscanf(cp,
"exp %d", &value)) {
191 formula->
exp = value;
192 }
else if (sscanf(cp,
"diff %d", &value)) {
193 formula->
diff = value;
194 }
else if (!strncmp(cp,
"ingred", 6)) {
197 cp = strchr(cp,
' ')+1;
199 if ((next = strchr(cp,
',')) != NULL) {
207 while (*cp !=
'\0' && cp[strlen(cp) - 1] ==
' ')
208 cp[strlen(cp) - 1] =
'\0';
217 }
while ((cp = next) != NULL);
221 while (numb_ingred != 1) {
231 }
else if (!strncmp(cp,
"arch", 4)) {
234 }
else if (!strncmp(cp,
"skill", 5)) {
236 }
else if (!strncmp(cp,
"cauldron", 8)) {
238 }
else if (!strncmp(cp,
"failure_arch ", 13)) {
240 }
else if (!strncmp(cp,
"failure_message ", 16)) {
242 }
else if (sscanf(cp,
"min_level %d", &value)) {
244 }
else if (!strncmp(cp,
"tool ", 5)) {
246 }
else if (sscanf(cp,
"combination %d", &value)) {
249 LOG(
llevError,
"Unknown input in file %s: %s\n", filename, buf);
274 int numb = 1, tool_match;
275 size_t tool_i,tool_j;
279 for (fl = formulalist; fl != NULL; fl = fl->
next) {
280 for (formula = fl->
items; formula != NULL; formula = formula->
next)
281 for (check = formula->
next; check != NULL; check = check->
next)
290 for (tool_i = 0; tool_i < formula->
tool_size; ++tool_i)
292 for (tool_j = 0; tool_j < check->
tool_size; ++tool_j)
293 if (strcmp(formula->
tool[tool_i], check->
tool[tool_j]) == 0) {
304 LOG(
llevError,
"Formulae [%s] of %s and [%s] of %s have matching index id (%d)\n",
329 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);
330 for (formula = fl->
items; formula != NULL; formula = formula->
next) {
336 const char *
string = formula->
arch_name[i];
340 if (!art && strcmp(formula->
title,
"NONE"))
343 if (strcmp(formula->
title,
"NONE"))
344 snprintf(buf,
sizeof(buf),
"%s of %s",
string, formula->
title);
346 strlcpy(buf,
string,
sizeof(buf));
350 if (formula->
ingred != NULL) {
351 int nval = 0, tval = 0;
352 fprintf(
logfile,
"\tIngred: ");
353 for (next = formula->
ingred; next != NULL; next = next->
next) {
360 if (tval != formula->
index)
361 fprintf(
logfile,
"WARNING:ingredient list and formula values not equal.\n");
363 if (formula->
skill != NULL)
364 fprintf(
logfile,
"\tSkill Required: %s", formula->
skill);
367 fprintf(
logfile,
"\tDifficulty: %d\t Exp: %d\n", formula->
diff, formula->
exp);
370 LOG(
llevError,
"Can't find archetype:%s for formula %s\n",
string, formula->
title);
401 if (t->
name != NULL) {
456 while (isdigit(*name)) {
457 mult = 10*mult+(*name-
'0');
476 cp = strstr(name,
" of ");
479 part1[cp-name] =
'\0';
489 for (art = al->
items; art != NULL; art = art->
next)
496 cp = strstr(name,
"'s ");
499 part1[cp-name] =
'\0';
534 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);
535 for (formula = fl->
items; formula != NULL; formula = formula->
next) {
542 const char *
string = formula->
arch_name[i];
546 if (!art && strcmp(formula->
title,
"NONE"))
549 if (!strcmp(formula->
title,
"NONE"))
550 strlcpy(buf,
string,
sizeof(buf));
552 snprintf(buf,
sizeof(buf),
"%s of %s",
string, formula->
title);
553 fprintf(
logfile,
"\n%-40s bookchance %3d skill %s\n", buf, formula->
chance, formula->
skill);
554 if (formula->
ingred != NULL) {
556 for (next = formula->
ingred; next != NULL; next = next->
next) {
560 fprintf(
logfile,
"\t%-33s%5ld\n", next->
name, cost);
561 if (cost < 0 || tcost < 0)
566 if (art != NULL && art->
item != NULL)
570 fprintf(
logfile,
"\t\tBuying result costs: %5ld", cost);
571 if (formula->
yield > 1) {
572 fprintf(
logfile,
" to %ld (max %d items)\n", cost*formula->
yield, formula->
yield);
573 cost = cost*(formula->
yield+1L)/2L;
576 fprintf(
logfile,
"\t\tIngredients cost: %5ld\n\t\tComment: ", tcost);
578 fprintf(
logfile,
"Could not find some ingredients. Check the formula!\n");
579 else if (tcost > cost)
580 fprintf(
logfile,
"Ingredients are much too expensive. Useless formula.\n");
581 else if (tcost*2L > cost)
582 fprintf(
logfile,
"Ingredients are too expensive.\n");
583 else if (tcost*10L < cost)
584 fprintf(
logfile,
"Ingredients are too cheap.\n");
590 LOG(
llevError,
"Can't find archetype:%s for formula %s\n",
string, formula->
title);
598 fprintf(
logfile,
"WARNING: %d objects required by the formulae do not exist in the game.\n", num_errors);
610 const char *cp = name;
613 cp = strchr(cp,
' ')+1;
628 if ((numb = atoi(buf)))
646 int val = 0, len = strlen(cp), mult =
numb_ingred(buf);
674 for (art = at->
items; art; art = art->
next)
691 int number = 0, roll = 0;
710 LOG(
llevError,
"get_random_recipelist(): no recipelists found!\n");
737 for (rp = fl->
items; rp; rp = rp->
next) {
751 recipe *formula = NULL, *next;
755 for (fl = formulalist; fl != NULL; fl = flnext) {
758 for (formula = fl->
items; formula != NULL; formula = next) {
759 next = formula->
next;
773 for (lchar = formula->
ingred; lchar; lchar = charnext) {
774 charnext = lchar->
next;
779 free(formula->
tool[0]);
810 for (p = strtok(dup,
","); p != NULL; p = strtok(NULL,
","))
814 *result_list = malloc(
sizeof(**result_list) * size);
815 if (*result_list == NULL)
819 for (i = 0; i < size; i++) {
820 (*result_list)[i] = dup;
821 dup = dup+strlen(dup)+1;
840 if (strcmp(test->
tool[t], tool) == 0) {
static void check_formulae(void)
archetype * find_archetype(const char *name)
archetype * find_treasure_by_name(const treasure *t, const char *name, int depth)
const artifactlist * find_artifactlist(int type)
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)
void fatal(enum fatal_error err)
struct artifactstruct * items
treasurelist * find_treasurelist(const char *name)
void free_string(sstring str)
struct treasureliststruct * randomitems
recipe * find_recipe_for_tool(const char *tool, recipe *from)
static int numb_ingred(const char *buf)
static recipelist * init_recipelist(void)
static recipelist * get_random_recipelist(void)
void dump_alchemy_costs(void)
void object_free_drop_inventory(object *ob)
int legal_artifact_combination(const object *op, const artifact *art)
struct artifactliststruct * next
object * create_archetype(const char *name)
static const char * ingred_name(const char *name)
const artifact * locate_recipe_artifact(const recipe *rp, size_t idx)
struct linked_char * next
int strtoint(const char *buf)
struct treasurestruct * next_no
EXTERN artifactlist * first_artifactlist
static recipelist * formulalist
struct treasurestruct * items
void free_all_recipes(void)
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,...)
static long find_ingred_cost(const char *name)
static recipe * get_empty_formula(void)
struct treasurestruct * next
EXTERN archetype * first_archetype
size_t strlcpy(char *dst, const char *src, size_t size)
struct recipestruct * items
recipelist * get_formulalist(int i)
struct artifactstruct * next