version 1.5 | | version 1.6 |
---|
| | |
/* | | /* |
* static char *rcsid_readable_c = | | * static char *rcsid_readable_c = |
* "$Id: readable.c,v 1.5 2001/05/09 06:58:12 mwedel Exp $"; | | * "$Id: readable.c,v 1.6 2001/05/26 07:29:22 mwedel Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
{ | | { |
"cookbook", | | "cookbook", |
"formulary", | | "formulary", |
"handbook", | | |
"lab book", | | "lab book", |
"lab notes", | | "lab notes", |
"recipe book" | | "recipe book" |
}; | | }; |
| | |
| | /* this isn't used except for empty books */ |
static char *formula_author[] = | | static char *formula_author[] = |
{ | | { |
"Albertus Magnus", | | "Albertus Magnus", |
| | |
* of a randomly selected alchemical formula. | | * of a randomly selected alchemical formula. |
*/ | | */ |
| | |
char * | | void make_formula_book(object *book, int level) { |
formula_msg (int level, int booksize) | | char retbuf[BOOK_BUF], title[MAX_BUF]; |
{ | | |
static char retbuf[BOOK_BUF]; | | |
recipelist *fl; | | recipelist *fl; |
recipe *formula = NULL; | | recipe *formula = NULL; |
int chance; | | int chance; |
| | |
| | |
if (fl->total_chance == 0) | | if (fl->total_chance == 0) |
{ | | { |
strcpy (retbuf, "\n <undecipherable message> \n"); | | book->msg = add_string(" <indescipherable text>\n"); |
return retbuf; | | new_text_name(book, 4); |
| | add_author(book,4); |
| | return; |
} | | } |
| | |
/* get a random formula, weighted by its bookchance */ | | /* get a random formula, weighted by its bookchance */ |
chance = RANDOM () % fl->total_chance; | | chance = RANDOM () % fl->total_chance; |
for (formula = fl->items; formula != NULL; formula = formula->next) | | for (formula = fl->items; formula != NULL; formula = formula->next) { |
{ | | |
chance -= formula->chance; | | chance -= formula->chance; |
if (chance <= 0) | | if (chance <= 0) |
break; | | break; |
| | |
/* preamble */ | | /* preamble */ |
strcpy (retbuf, "Herein is described an alchemical proceedure: \n"); | | strcpy (retbuf, "Herein is described an alchemical proceedure: \n"); |
| | |
| | if (!formula) { |
| | book->msg = add_string(" <indescipherable text>\n"); |
| | new_text_name(book, 4); |
| | add_author(book,4); |
| | |
| | } else { |
/* looks like a formula was found. Base the amount | | /* looks like a formula was found. Base the amount |
* of information on the booklevel and the spellevel | | * of information on the booklevel and the spellevel |
* of the formula. */ | | * of the formula. */ |
if (formula) | | |
{ | | |
char *op_name = NULL; | | char *op_name = NULL; |
archetype *at; | | archetype *at; |
int nindex = nstrtok (formula->arch_name, ","); | | int nindex = nstrtok (formula->arch_name, ","); |
| | |
} | | } |
else | | else |
op_name = formula->arch_name; | | op_name = formula->arch_name; |
| | |
if ((at = find_archetype (op_name)) != (archetype *) NULL) | | if ((at = find_archetype (op_name)) != (archetype *) NULL) |
op_name = at->clone.name; | | op_name = at->clone.name; |
else | | else |
LOG (llevError, "formula_msg() can't find arch %s for formula.", | | LOG (llevError, "formula_msg() can't find arch %s for formula.", |
op_name); | | op_name); |
| | |
/* item name */ | | /* item name */ |
if (strcmp (formula->title, "NONE")) | | if (strcmp (formula->title, "NONE")) { |
sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, formula->title); | | sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, formula->title); |
| | /* This results in things like pile of philo. sulfur. |
| | * while philo. sulfur may look better, without this, |
| | * you get things like 'the wise' because its missing the |
| | * water of section. |
| | */ |
| | sprintf(title,"%s: %s of %s", |
| | formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], |
| | op_name, formula->title); |
| | } |
else | | else |
{ | | { |
sprintf (retbuf, "%sThe %s", retbuf, op_name); | | sprintf (retbuf, "%sThe %s", retbuf, op_name); |
| | sprintf(title,"%s: %s", |
| | formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], |
| | op_name); |
if (at->clone.title) | | if (at->clone.title) |
{ | | { |
strcat (retbuf, " "); | | strcat (retbuf, " "); |
strcat (retbuf, at->clone.title); | | strcat (retbuf, at->clone.title); |
| | strcat(title, " "); |
| | strcat(title, at->clone.title); |
} | | } |
} | | } |
| | /* Lets name the book something meaningful ! */ |
| | if (book->name) free_string(book->name); |
| | book->name = add_string(title); |
| | if (book->title) { |
| | free_string(book->title); |
| | book->title = NULL; |
| | } |
| | |
/* ingredients to make it */ | | /* ingredients to make it */ |
if (formula->ingred != NULL) | | if (formula->ingred != NULL) |
{ | | { |
| | |
else | | else |
LOG (llevError, "formula_msg() no ingredient list for object %s of %s", | | LOG (llevError, "formula_msg() no ingredient list for object %s of %s", |
op_name, formula->title); | | op_name, formula->title); |
| | if (retbuf[strlen(retbuf)-1]!= '\n') strcat(retbuf, "\n"); |
| | if (book->msg) free_string(book->msg); |
| | book->msg = add_string(retbuf); |
} | | } |
else | | |
strcat (retbuf, " <indescipherable text>\n"); | | |
| | |
#ifdef BOOK_MSG_DEBUG | | |
LOG (llevDebug, "\n formula_msg() created strng: %d\n", strlen (retbuf)); | | |
fprintf (logfile, " MADE THIS:\n%s\n", retbuf); | | |
#endif | | |
| | |
return retbuf; | | |
} | | } |
#endif | | #endif |
| | |
| | |
break; | | break; |
case 4: /* describe an alchemy formula */ | | case 4: /* describe an alchemy formula */ |
#ifdef ALCHEMY | | #ifdef ALCHEMY |
strcpy (msgbuf, formula_msg (level, book_buf_size)); | | make_formula_book(book, level); |
| | /* make_formula_book already gives title */ |
| | return; |
#else | | #else |
strcpy (msgbuf, msgfile_msg (level, book_buf_size)); | | strcpy (msgbuf, msgfile_msg (level, book_buf_size)); |
msg_type = 0; | | msg_type = 0; |