--- deliantra/server/common/readable.C 2007/01/15 21:06:18 1.18 +++ deliantra/server/common/readable.C 2007/06/24 04:09:28 1.28 @@ -1,28 +1,27 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Crossfire TRT is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * You should have received a copy of the GNU General Public License along + * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ - /* This file contains code relevant to the BOOKS hack -- designed * to allow randomly occuring messages in non-magical texts. */ @@ -190,7 +189,7 @@ {"Boots", BOOTS}, {"Cloak", CLOAK}, {"Gloves", GLOVES}, - {"Gridle", GIRDLE}, + {"Girdle", GIRDLE}, {"Ring", RING}, {"Horn", HORN}, {"Missile Weapon", BOW}, @@ -438,68 +437,68 @@ * subtype paramater in arch files! */ static readable_message_type readable_message_types[] = { - /*subtype 0 */ {0, 0}, + /*subtype 0 */ {0, 0, ""}, /* book messages subtypes */ - /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO}, - /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER}, - {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER}, + /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1, "readable-book-clasp-1"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2, "readable-book-clasp-2"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1, "readable-book-elegant-1"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2, "readable-book-elegant-2"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_1, "readable-book-quarto-1"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_QUARTO_2, "readable-book-quarto-2"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_EVOKER, "readable-book-spell-evocation"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PRAYER, "readable-book-spell-praying"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_PYRO, "readable-book-spell-pyromancy"}, + /*subtype 10 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SORCERER, "readable-book-spell-sorcery"}, + {MSG_TYPE_BOOK, MSG_TYPE_BOOK_SPELL_SUMMONER, "readable-book-spell-summoning"}, /* card messages subtypes */ - {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2}, - /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2}, - {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_1, "readable-card-simple-1"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_2, "readable-card-simple-2"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_SIMPLE_3, "readable-card-simple-3"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_1, "readable-card-elegant-1"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_2, "readable-card-elegant-2"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_ELEGANT_3, "readable-card-elegant-3"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_1, "readable-card-strange-1"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_2, "readable-card-strange-2"}, + /*subtype 20 */ {MSG_TYPE_CARD, MSG_TYPE_CARD_STRANGE_3, "readable-card-strange-3"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_1, "readable-card-money-1"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_2, "readable-card-money-2"}, + {MSG_TYPE_CARD, MSG_TYPE_CARD_MONEY_3, "readable-card-money-3"}, /* Paper messages subtypes */ - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1}, - /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2}, - {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_1, "readable-paper-note-1"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_2, "readable-paper-note-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_NOTE_3, "readable-paper-note-3"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_1, "readable-paper-letter-old-1"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_OLD_2, "readable-paper-letter-old-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_1, "readable-paper-letter-new-1"}, + /*subtype 30 */ {MSG_TYPE_PAPER, MSG_TYPE_PAPER_LETTER_NEW_2, "readable-paper-letter-new-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_1, "readable-paper-envelope-1"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_ENVELOPE_2, "readable-paper-envelope-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_1, "readable-paper-scroll-old-1"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_OLD_2, "readable-paper-scroll-old-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_1, "readable-paper-scroll-new-1"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_NEW_2, "readable-paper-scroll-new-2"}, + {MSG_TYPE_PAPER, MSG_TYPE_PAPER_SCROLL_MAGIC, "readable-paper-scroll-magic"}, /* road signs messages subtypes */ - {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC}, - {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT}, - /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT}, - {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH}, + {MSG_TYPE_SIGN, MSG_TYPE_SIGN_BASIC, "readable-sign-basic"}, + {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_LEFT, "readable-sign-dir-left"}, + /*subtype 40 */ {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_RIGHT, "readable-sign-dir-right"}, + {MSG_TYPE_SIGN, MSG_TYPE_SIGN_DIR_BOTH, "readable-sign-dir-both"}, /* stones and monument messages */ - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2}, - /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2}, - {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3} + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_1, "readable-monument-stone-1"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_2, "readable-monument-stone-2"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STONE_3, "readable-monument-stone-3"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_1, "readable-monument-statue-1"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_2, "readable-monument-statue-2"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_STATUE_3, "readable-monument-statue-3"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_1, "readable-monument-gravestone-1"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_2, "readable-monument-gravestone-2"}, + /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"}, + {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"} }; int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); @@ -643,79 +642,10 @@ * ****************************************************************************/ -/* init_msgfile() - if not called before, initialise the info list - * reads the messages file into the list pointed to by first_msg -*/ - -static void -init_msgfile (void) -{ - FILE *fp; - char buf[MAX_BUF], msgbuf[HUGE_BUF], fname[MAX_BUF], *cp; - int comp; - static int did_init_msgfile; - - if (did_init_msgfile) - return; - did_init_msgfile = 1; - - sprintf (fname, "%s/messages", settings.datadir); - LOG (llevDebug, "Reading messages from %s...\n", fname); - - if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) - { - linked_char *tmp = NULL; - - while (fgets (buf, MAX_BUF, fp) != NULL) - { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (!strncmp (cp, "ENDMSG", 6)) - { - if (strlen (msgbuf) > BOOK_BUF) - { - LOG (llevDebug, "Warning: this string exceeded max book buf size:"); - LOG (llevDebug, " %s\n", msgbuf); - } - tmp->name = msgbuf; - tmp->next = first_msg; - first_msg = tmp; - nrofmsg++; - continue; - } - else if (!strncmp (cp, "MSG", 3)) - { - tmp = new linked_char; - - strcpy (msgbuf, " "); /* reset msgbuf for new message */ - continue; - } - else if (!buf_overflow (msgbuf, cp, HUGE_BUF - 1)) - { - strcat (msgbuf, cp); - strcat (msgbuf, "\n"); - } - } - close_and_delete (fp, comp); - } - -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "init_info_listfile() got %d messages.\n", nrofmsg); -#endif - LOG (llevDebug, "done.\n"); -} - - /* init_book_archive() - if not called before, initialise the info list * This reads in the bookarch file into memory. bookarch is the file * created and updated across multiple runs of the program. */ - static void init_book_archive (void) { @@ -820,14 +750,13 @@ did_init_mon_info = 1; - - for (at = first_archetype; at != NULL; at = at->next) + for_all_archetypes (at) { - if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && (!QUERY_FLAG (&at->clone, FLAG_CHANGING) || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE))) + if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) { objectlink *mon = new objectlink; - mon->ob = &at->clone; + mon->ob = at; mon->next = first_mon_info; first_mon_info = mon; nrofmon++; @@ -837,14 +766,12 @@ LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); } - /* init_readable() - initialise linked lists utilized by * message functions in tailor_readable_ob() * * This is the function called by the main routine to initialise * all the readable information. */ - void init_readable (void) { @@ -856,11 +783,9 @@ did_this = 1; LOG (llevDebug, "Initialising reading data...\n"); - init_msgfile (); init_book_archive (); init_mon_info (); LOG (llevDebug, " Done\n"); - } /***************************************************************************** @@ -870,11 +795,9 @@ * *****************************************************************************/ - /* find_title() - Search the titlelist (based on msgtype) to see if * book matches something already there. IF so, return that title. */ - static title * find_title (const object *book, int msgtype) { @@ -921,39 +844,39 @@ switch (msgtype) { - case 1: /*monster */ - nbr = sizeof (mon_book_name) / sizeof (char *); - strcpy (name, mon_book_name[RANDOM () % nbr]); - break; - case 2: /*artifact */ - nbr = sizeof (art_book_name) / sizeof (char *); - strcpy (name, art_book_name[RANDOM () % nbr]); - break; - case 3: /*spellpath */ - nbr = sizeof (path_book_name) / sizeof (char *); - strcpy (name, path_book_name[RANDOM () % nbr]); - break; - case 4: /*alchemy */ - nbr = sizeof (formula_book_name) / sizeof (char *); - strcpy (name, formula_book_name[RANDOM () % nbr]); - break; - case 5: /*gods */ - nbr = sizeof (gods_book_name) / sizeof (char *); - strcpy (name, gods_book_name[RANDOM () % nbr]); - break; - case 6: /*msg file */ - default: - if (book->weight > 2000) - { /* based on weight */ - nbr = sizeof (heavy_book_name) / sizeof (char *); - strcpy (name, heavy_book_name[RANDOM () % nbr]); - } - else if (book->weight < 2001) - { - nbr = sizeof (light_book_name) / sizeof (char *); - strcpy (name, light_book_name[RANDOM () % nbr]); - } - break; + case 1: /*monster */ + nbr = sizeof (mon_book_name) / sizeof (char *); + assign (name, mon_book_name[rndm (nbr)]); + break; + case 2: /*artifact */ + nbr = sizeof (art_book_name) / sizeof (char *); + assign (name, art_book_name[rndm (nbr)]); + break; + case 3: /*spellpath */ + nbr = sizeof (path_book_name) / sizeof (char *); + assign (name, path_book_name[rndm (nbr)]); + break; + case 4: /*alchemy */ + nbr = sizeof (formula_book_name) / sizeof (char *); + assign (name, formula_book_name[rndm (nbr)]); + break; + case 5: /*gods */ + nbr = sizeof (gods_book_name) / sizeof (char *); + assign (name, gods_book_name[rndm (nbr)]); + break; + case 6: /*msg file */ + default: + if (book->weight > 2000) + { /* based on weight */ + nbr = sizeof (heavy_book_name) / sizeof (char *); + assign (name, heavy_book_name[rndm (nbr)]); + } + else if (book->weight < 2001) + { + nbr = sizeof (light_book_name) / sizeof (char *); + assign (name, light_book_name[rndm (nbr)]); + } + break; } book->name = name; @@ -975,29 +898,29 @@ switch (msgtype) { - case 1: /* monster */ - nbr = sizeof (mon_author) / sizeof (char *); - strcpy (name, mon_author[RANDOM () % nbr]); - break; - case 2: /* artifacts */ - nbr = sizeof (art_author) / sizeof (char *); - strcpy (name, art_author[RANDOM () % nbr]); - break; - case 3: /* spellpath */ - nbr = sizeof (path_author) / sizeof (char *); - strcpy (name, path_author[RANDOM () % nbr]); - break; - case 4: /* alchemy */ - nbr = sizeof (formula_author) / sizeof (char *); - strcpy (name, formula_author[RANDOM () % nbr]); - break; - case 5: /* gods */ - nbr = sizeof (gods_author) / sizeof (char *); - strcpy (name, gods_author[RANDOM () % nbr]); - break; - case 6: /* msg file */ - default: - strcpy (name, book_author[RANDOM () % nbr]); + case 1: /* monster */ + nbr = sizeof (mon_author) / sizeof (char *); + assign (name, mon_author[rndm (nbr)]); + break; + case 2: /* artifacts */ + nbr = sizeof (art_author) / sizeof (char *); + assign (name, art_author[rndm (nbr)]); + break; + case 3: /* spellpath */ + nbr = sizeof (path_author) / sizeof (char *); + assign (name, path_author[rndm (nbr)]); + break; + case 4: /* alchemy */ + nbr = sizeof (formula_author) / sizeof (char *); + assign (name, formula_author[rndm (nbr)]); + break; + case 5: /* gods */ + nbr = sizeof (gods_author) / sizeof (char *); + assign (name, gods_author[rndm (nbr)]); + break; + case 6: /* msg file */ + default: + assign (name, book_author[rndm (nbr)]); } sprintf (title, "of %s", name); @@ -1047,7 +970,7 @@ t->authour = book->title; t->size = strlen (book->msg); t->msg_index = strtoint (book->msg); - t->archname = book->arch->name; + t->archname = book->arch->archname; t->level = book->level; t->next = tl->first_book; @@ -1171,7 +1094,7 @@ /* Lets give the book a description to individualize it some */ char new_name[MAX_BUF]; - snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name); + snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); book->name = new_name; } @@ -1370,15 +1293,15 @@ /* artifact_msg() - generate a message detailing the properties * of 1-6 artifacts drawn sequentially from the artifact list. */ - -char * +const char * artifact_msg (int level, int booksize) { artifactlist *al = NULL; artifact *art; int chance, i, type, index; int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; - char *ch, name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; + const char *ch; + char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; static char retbuf[BOOK_BUF]; object *tmp = NULL; @@ -1402,7 +1325,7 @@ while ((al == NULL) && (i < 10)); if (i == 10) /* Unable to find a message */ - return ("None"); + return "None"; /* There is no reason to start on the artifact list at the begining. Lets * take our starting position randomly... */ @@ -1415,7 +1338,7 @@ } /* the base 'generic' name for our artifact */ - strcpy (name, art_name_array[index].name); + assign (name, art_name_array[index].name); /* Ok, lets print out the contents */ sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", book_entries > 1 ? "some artifacts" : "an artifact"); @@ -1520,16 +1443,16 @@ else sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); - for (at = first_archetype; at != NULL; at = at->next) + for_all_archetypes (at) { /* Determine if this is an appropriate spell. Must * be of matching path, must be of appropriate type (prayer * or not), and must be within the valid level range. */ - if (at->clone.type == SPELL && at->clone.path_attuned & pnum && - ((at->clone.stats.grace && prayers) || (at->clone.stats.sp && !prayers)) && (at->clone.level < (level * 8))) + if (at->type == SPELL && at->path_attuned & pnum && + ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) { - strcpy (tmpbuf, at->clone.name); + assign (tmpbuf, at->object::name); if (book_overflow (retbuf, tmpbuf, booksize)) break; @@ -1557,12 +1480,9 @@ return retbuf; } - - /* formula_msg() - generate a message detailing the properties * of a randomly selected alchemical formula. */ - void make_formula_book (object *book, int level) { @@ -1616,7 +1536,7 @@ sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); if ((at = archetype::find (op_name)) != (archetype *) NULL) - op_name = at->clone.name; + op_name = at->object::name; else LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); @@ -1636,12 +1556,12 @@ { 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->title) { strcat (retbuf, " "); - strcat (retbuf, at->clone.title); + strcat (retbuf, at->title); strcat (title, " "); - strcat (title, at->clone.title); + strcat (title, at->title); } } /* Lets name the book something meaningful ! */ @@ -1657,7 +1577,7 @@ at = archetype::find (formula->cauldron); sprintf (retbuf + strlen (retbuf), - " may be made at %s using the following ingredients:\n", at ? query_name (&at->clone) : "an unknown place"); + " may be made at %s using the following ingredients:\n", at ? query_name (at) : "an unknown place"); for (next = formula->ingred; next != NULL; next = next->next) { @@ -1674,46 +1594,9 @@ } } - -/* msgfile_msg() - generate a message drawn randomly from a - * file in lib/. Level currently has no effect on the message - * which is returned. - */ - -char * -msgfile_msg (int level, int booksize) -{ - static char retbuf[BOOK_BUF]; - int i, msgnum; - linked_char *msg = NULL; - - /* get a random message for the 'book' from linked list */ - if (nrofmsg > 1) - { - msg = first_msg; - msgnum = RANDOM () % nrofmsg; - for (i = 0; msg && i < nrofmsg && i != msgnum; i++) - msg = msg->next; - } - - if (msg && !book_overflow (retbuf, msg->name, booksize)) - strcpy (retbuf, msg->name); - else - sprintf (retbuf, "\n "); - -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf)); - LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); -#endif - - return retbuf; -} - - /* god_info_msg() - generate a message detailing the properties * of a random god. Used by the book hack. b.t. */ - const char * god_info_msg (int level, int booksize) { @@ -1759,6 +1642,7 @@ if (enemy) sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); } + if (level == 3 && RANDOM () % 2) { /* enemy race, what the god's holy word effects */ const char *enemy = god->slaying; @@ -1777,13 +1661,12 @@ sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); } } + if (level == 4 && RANDOM () % 2) { /* Priest of god gets these protect,vulnerable... */ - char tmpbuf[MAX_BUF], *cp; - - cp = describe_resistance (god, 1); + char tmpbuf[MAX_BUF]; - if (*cp) + if (const char *cp = describe_resistance (god, 1)) { /* This god does have protections */ sprintf (tmpbuf, "%s has a potent aura which is extended\n", name); strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); @@ -1794,6 +1677,7 @@ else sprintf (buf, " "); } + if (level == 5 && RANDOM () % 2) { /* aligned race, summoning */ const char *race = god->race; /* aligned race */ @@ -1811,13 +1695,12 @@ sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); } } + if (level == 6 && RANDOM () % 2) { /* blessing,curse properties of the god */ - char tmpbuf[MAX_BUF], *cp; - - cp = describe_resistance (god, 1); + char tmpbuf[MAX_BUF]; - if (*cp) + if (const char *cp = describe_resistance (god, 1)) { /* This god does have protections */ sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name); strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); @@ -1829,6 +1712,7 @@ sprintf (buf, " "); } + if (level == 8 && RANDOM () % 2) { /* immunity, holy possession */ int has_effect = 0, tmpvar; @@ -1847,6 +1731,7 @@ sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]); } } + if (has_effect) { strcat (buf, tmpbuf); @@ -1855,6 +1740,7 @@ else sprintf (buf, " "); } + if (level == 12 && RANDOM () % 2) { /* spell paths */ int has_effect = 0, tmpvar; @@ -1863,21 +1749,25 @@ sprintf (tmpbuf, "\n"); sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); + if ((tmpvar = god->path_attuned)) { has_effect = 1; DESCRIBE_PATH (tmpbuf, tmpvar, "Attuned"); } + if ((tmpvar = god->path_repelled)) { has_effect = 1; DESCRIBE_PATH (tmpbuf, tmpvar, "Repelled"); } + if ((tmpvar = god->path_denied)) { has_effect = 1; DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); } + if (has_effect) { strcat (buf, tmpbuf); @@ -1895,8 +1785,10 @@ break; else if (strlen (buf) > 1) strcat (retbuf, buf); + level--; } + if (strlen (retbuf) == introlen) { /* we got no information beyond the preamble! */ strcat (retbuf, " [Unfortunately the rest of the information is\n"); @@ -1925,7 +1817,6 @@ * message type - otherwise a random value is used. * */ - void tailor_readable_ob (object *book, int msg_type) { @@ -1958,27 +1849,27 @@ msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); switch (msg_type) { - case 1: /* monster attrib */ - strcpy (msgbuf, mon_info_msg (level, book_buf_size)); - break; - case 2: /* artifact attrib */ - strcpy (msgbuf, artifact_msg (level, book_buf_size)); - break; - case 3: /* grouping incantations/prayers by path */ - strcpy (msgbuf, spellpath_msg (level, book_buf_size)); - break; - case 4: /* describe an alchemy formula */ - make_formula_book (book, level); - /* make_formula_book already gives title */ - return; - break; - case 5: /* bits of information about a god */ - strcpy (msgbuf, god_info_msg (level, book_buf_size)); - break; - case 0: /* use info list in lib/ */ - default: - strcpy (msgbuf, msgfile_msg (level, book_buf_size)); - break; + case 1: /* monster attrib */ + strcpy (msgbuf, mon_info_msg (level, book_buf_size)); + break; + case 2: /* artifact attrib */ + strcpy (msgbuf, artifact_msg (level, book_buf_size)); + break; + case 3: /* grouping incantations/prayers by path */ + strcpy (msgbuf, spellpath_msg (level, book_buf_size)); + break; + case 4: /* describe an alchemy formula */ + make_formula_book (book, level); + /* make_formula_book already gives title */ + return; + break; + case 5: /* bits of information about a god */ + strcpy (msgbuf, god_info_msg (level, book_buf_size)); + break; + case 0: /* use info list in lib/ */ + default: + cfperl_make_book (book, level); + return; } strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */