--- deliantra/server/common/readable.C 2006/09/03 00:18:40 1.3 +++ deliantra/server/common/readable.C 2007/02/05 01:24:45 1.21 @@ -1,31 +1,27 @@ /* - * static char *rcsid_readable_c = - * "$Id: readable.C,v 1.3 2006/09/03 00:18:40 root Exp $"; + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * Copyright (C) 1992 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. + * + * 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 */ -/* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - Copyright (C) 1992 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. - - 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 crossfire-devel@real-time.com -*/ - /* This file contains code relevant to the BOOKS hack -- designed * to allow randomly occuring messages in non-magical texts. @@ -69,9 +65,11 @@ */ /* This flag is useful to see what kind of output messages are created */ + /* #define BOOK_MSG_DEBUG */ /* This flag is useful for debuging archiving action */ + /* #define ARCHIVE_DEBUG */ /* Moved these structures from struct.h to this file in 0.94.3 - they @@ -79,33 +77,30 @@ */ /* 'title' and 'titlelist' are used by the readable code */ -typedef struct titlestruct : zero_initialised +struct title : zero_initialised { - shstr name; /* the name of the book */ - shstr authour; /* the name of the book authour */ - shstr archname; /* the archetype name of the book */ - int level; /* level of difficulty of this message */ - int size; /* size of the book message */ - int msg_index; /* an index value derived from book message */ - struct titlestruct *next; -} title; - -typedef struct titleliststruct : zero_initialised -{ - int number; /* number of items in the list */ - struct titlestruct *first_book; /* pointer to first book in this list */ - struct titleliststruct *next; /* pointer to next book list */ -} titlelist; - -/* special structure, used only by art_name_array[] */ + shstr name; /* the name of the book */ + shstr authour; /* the name of the book authour */ + shstr archname; /* the archetype name of the book */ + int level; /* level of difficulty of this message */ + int size; /* size of the book message */ + int msg_index; /* an index value derived from book message */ + title *next; +}; -typedef struct namebytype - { - const char *name; /* generic name to call artifacts of this type */ - int type; /* matching type */ - } -arttypename; +struct titlelist : zero_initialised +{ + int number; /* number of items in the list */ + title *first_book; /* pointer to first book in this list */ + titlelist *next; /* pointer to next book list */ +}; +/* special structure, used only by art_name_array[] */ +struct arttypename +{ + const char *name; /* generic name to call artifacts of this type */ + int type; /* matching type */ +}; /* booklist is the buffer of books read in from the bookarch file */ static titlelist *booklist = NULL; @@ -115,10 +110,10 @@ /* these are needed for creation of a linked list of * pointers to all (hostile) monster objects */ -static int nrofmon = 0, need_to_write_bookarchive=0; +static int nrofmon = 0, need_to_write_bookarchive = 0; -/* this is needed to keep track of status of initialization +/* this is needed to keep track of status of initialisation * of the message file */ static int nrofmsg = 0; @@ -131,56 +126,53 @@ * Spellpath information */ -static uint32 spellpathdef[NRSPELLPATHS] = -{ - PATH_PROT, - PATH_FIRE, - PATH_FROST, - PATH_ELEC, - PATH_MISSILE, - PATH_SELF, - PATH_SUMMON, - PATH_ABJURE, - PATH_RESTORE, - PATH_DETONATE, - PATH_MIND, - PATH_CREATE, - PATH_TELE, - PATH_INFO, - PATH_TRANSMUTE, - PATH_TRANSFER, - PATH_TURNING, - PATH_WOUNDING, - PATH_DEATH, - PATH_LIGHT -}; - -static const char* const path_book_name[] = -{ - "codex", - "compendium", - "exposition", - "tables", - "treatise" +static uint32 spellpathdef[NRSPELLPATHS] = { + PATH_PROT, + PATH_FIRE, + PATH_FROST, + PATH_ELEC, + PATH_MISSILE, + PATH_SELF, + PATH_SUMMON, + PATH_ABJURE, + PATH_RESTORE, + PATH_DETONATE, + PATH_MIND, + PATH_CREATE, + PATH_TELE, + PATH_INFO, + PATH_TRANSMUTE, + PATH_TRANSFER, + PATH_TURNING, + PATH_WOUNDING, + PATH_DEATH, + PATH_LIGHT +}; + +static const char *const path_book_name[] = { + "codex", + "compendium", + "exposition", + "tables", + "treatise" }; /* used by spellpath texts */ -static const char* const path_author[] = -{ - "aether", - "astral byways", - "connections", - "the Grey Council", - "deep pathways", - "knowledge", - "magic", - "mystic ways", - "pathways", - "power", - "spells", - "transforms", - "the mystic veil", - "unknown spells" +static const char *const path_author[] = { + "aether", + "astral byways", + "connections", + "the Grey Council", + "deep pathways", + "knowledge", + "magic", + "mystic ways", + "pathways", + "power", + "spells", + "transforms", + "the mystic veil", + "unknown spells" }; /* @@ -190,126 +182,119 @@ /* if it isnt listed here, then art_attr_msg will never generate * a message for this type of artifact. -b.t. */ -static arttypename art_name_array[] = -{ - {"Helmet", HELMET}, - {"Amulet", AMULET}, - {"Shield", SHIELD}, - {"Bracers", BRACERS}, - {"Boots", BOOTS}, - {"Cloak", CLOAK}, - {"Gloves", GLOVES}, - {"Gridle", GIRDLE}, - {"Ring", RING}, - {"Horn", HORN}, - {"Missile Weapon", BOW}, - {"Missile", ARROW}, - {"Hand Weapon", WEAPON}, - {"Artifact", SKILL}, - {"Food", FOOD}, - {"Body Armour", ARMOUR} -}; - -static const char* const art_book_name[] = -{ - "collection", - "file", - "files", - "guide", - "handbook", - "index", - "inventory", - "list", - "listing", - "record", - "record book" +static arttypename art_name_array[] = { + {"Helmet", HELMET}, + {"Amulet", AMULET}, + {"Shield", SHIELD}, + {"Bracers", BRACERS}, + {"Boots", BOOTS}, + {"Cloak", CLOAK}, + {"Gloves", GLOVES}, + {"Girdle", GIRDLE}, + {"Ring", RING}, + {"Horn", HORN}, + {"Missile Weapon", BOW}, + {"Missile", ARROW}, + {"Hand Weapon", WEAPON}, + {"Artifact", SKILL}, + {"Food", FOOD}, + {"Body Armour", ARMOUR} +}; + +static const char *const art_book_name[] = { + "collection", + "file", + "files", + "guide", + "handbook", + "index", + "inventory", + "list", + "listing", + "record", + "record book" }; /* used by artifact texts */ -static const char* const art_author[] = -{ - "ancient things", - "artifacts", - "Havlor", /* ancient warrior scribe :) */ - "items", - "lost artifacts", - "the ancients", - "useful things" +static const char *const art_author[] = { + "ancient things", + "artifacts", + "Havlor", /* ancient warrior scribe :) */ + "items", + "lost artifacts", + "the ancients", + "useful things" }; /* * Monster book information */ -static const char* const mon_book_name[] = -{ - "beastuary", - "catalog", - "compilation", - "collection", - "encyclopedia", - "guide", - "handbook", - "list", - "manual", - "notes", - "record", - "register", - "volume" +static const char *const mon_book_name[] = { + "beastuary", + "catalog", + "compilation", + "collection", + "encyclopedia", + "guide", + "handbook", + "list", + "manual", + "notes", + "record", + "register", + "volume" }; /* used by monster beastuary texts */ -static const char* const mon_author[] = -{ - "beasts", - "creatures", - "dezidens", - "dwellers", - "evil nature", - "life", - "monsters", - "nature", - "new life", - "residents", - "the spawn", - "the living", - "things" +static const char *const mon_author[] = { + "beasts", + "creatures", + "dezidens", + "dwellers", + "evil nature", + "life", + "monsters", + "nature", + "new life", + "residents", + "the spawn", + "the living", + "things" }; /* * God book information */ -static const char* const gods_book_name[] = -{ - "devotional", - "devout notes", - "divine text", - "divine work", - "holy book", - "holy record", - "moral text", - "sacred guide", - "testament", - "transcript" +static const char *const gods_book_name[] = { + "devotional", + "devout notes", + "divine text", + "divine work", + "holy book", + "holy record", + "moral text", + "sacred guide", + "testament", + "transcript" }; /* used by gods texts */ -static const char* const gods_author[] = -{ - "cults", - "joy", - "lasting curse", - "madness", - "religions", - "the dead", - "the gods", - "the heirophant", - "the poor priest", - "the priestess", - "pain", - "white" +static const char *const gods_author[] = { + "cults", + "joy", + "lasting curse", + "madness", + "religions", + "the dead", + "the gods", + "the heirophant", + "the poor priest", + "the priestess", + "pain", + "white" }; @@ -317,35 +302,33 @@ * Alchemy (formula) information */ -static const char* const formula_book_name[] = -{ - "cookbook", - "formulary", - "lab book", - "lab notes", - "recipe book", - "experiment record", - "work plan", - "design notes" +static const char *const formula_book_name[] = { + "cookbook", + "formulary", + "lab book", + "lab notes", + "recipe book", + "experiment record", + "work plan", + "design notes" }; /* this isn't used except for empty books */ -static const char* const formula_author[] = -{ - "Albertus Magnus", - "alchemy", - "balms", - "creation", - "dusts", - "magical manufacture", - "making", - "philosophical items", - "potions", - "powders", - "the cauldron", - "the lamp black", - "transmutation", - "waters" +static const char *const formula_author[] = { + "Albertus Magnus", + "alchemy", + "balms", + "creation", + "dusts", + "magical manufacture", + "making", + "philosophical items", + "potions", + "powders", + "the cauldron", + "the lamp black", + "transmutation", + "waters" }; /* @@ -353,185 +336,180 @@ */ /* used by msg file and 'generic' books */ -static const char* const light_book_name[] = -{ - "calendar", - "datebook", - "diary", - "guidebook", - "handbook", - "ledger", - "notes", - "notebook", - "octavo", - "pamphlet", - "practicum", - "script", - "transcript" -}; - -static const char* const heavy_book_name[] = -{ - "catalog", - "compendium", - "guide", - "manual", - "opus", - "tome", - "treatise", - "volume", - "work" +static const char *const light_book_name[] = { + "calendar", + "datebook", + "diary", + "guidebook", + "handbook", + "ledger", + "notes", + "notebook", + "octavo", + "pamphlet", + "practicum", + "script", + "transcript" +}; + +static const char *const heavy_book_name[] = { + "catalog", + "compendium", + "guide", + "manual", + "opus", + "tome", + "treatise", + "volume", + "work" }; /* used by 'generic' books */ -static const char* const book_author[] = -{ - "Abdulah", - "Al'hezred", - "Alywn", - "Arundel", - "Arvind", - "Aerlingas", - "Bacon", - "Baliqendii", - "Bosworth", - "Beathis", - "Bertil", - "Cauchy", - "Chakrabarti", - "der Waalis", - "Dirk", - "Djwimii", - "Eisenstaadt", - "Fendris", - "Frank", - "Habbi", - "Harlod", - "Ichibod", - "Janus", - "June", - "Magnuson", - "Nandii", - "Nitfeder", - "Norris", - "Parael", - "Penhew", - "Sophia", - "Skilly", - "Tahir", - "Thockmorton", - "Thomas", - "van Helsing", - "van Pelt", - "Voormis", - "Xavier", - "Xeno", - "Zardoz", - "Zagy" -}; - -static const char* const book_descrpt[] = -{ - "ancient", - "cryptic", - "cryptical", - "dusty", - "hiearchical", - "grizzled", - "gold-guilt", - "great", - "lost", - "magnificent", - "musty", - "mythical", - "mystical", - "rustic", - "stained", - "silvered", - "transcendental", - "weathered" +static const char *const book_author[] = { + "Abdulah", + "Al'hezred", + "Alywn", + "Arundel", + "Arvind", + "Aerlingas", + "Bacon", + "Baliqendii", + "Bosworth", + "Beathis", + "Bertil", + "Cauchy", + "Chakrabarti", + "der Waalis", + "Dirk", + "Djwimii", + "Eisenstaadt", + "Fendris", + "Frank", + "Habbi", + "Harlod", + "Ichibod", + "Janus", + "June", + "Magnuson", + "Nandii", + "Nitfeder", + "Norris", + "Parael", + "Penhew", + "Sophia", + "Skilly", + "Tahir", + "Thockmorton", + "Thomas", + "van Helsing", + "van Pelt", + "Voormis", + "Xavier", + "Xeno", + "Zardoz", + "Zagy" }; + +static const char *const book_descrpt[] = { + "ancient", + "cryptic", + "cryptical", + "dusty", + "hiearchical", + "grizzled", + "gold-guilt", + "great", + "lost", + "magnificent", + "musty", + "mythical", + "mystical", + "rustic", + "stained", + "silvered", + "transcendental", + "weathered" +}; + /* Each line of this array is a readable subtype * Be careful to keep the order. If you add readable subtype, add them * at the bottom of the list. Never delete a subtype because index is used as * subtype paramater in arch files! */ -static readable_message_type readable_message_types[] = -{ - /*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}, - /* 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}, - - /* 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}, - - /* 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}, - - /* 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} -}; -int last_readable_subtype = sizeof(readable_message_types)/sizeof(readable_message_type); - -static int max_titles[6] = -{ - ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), - (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)), - (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), - (sizeof (path_book_name) / sizeof (char *)) * (sizeof (path_author) / sizeof (char *)), - (sizeof (formula_book_name) / sizeof (char *)) * (sizeof (formula_author) / sizeof (char *)), - (sizeof (gods_book_name) / sizeof (char *)) * (sizeof (gods_author) / sizeof (char *)) +static readable_message_type readable_message_types[] = { + /*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}, + /* 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}, + + /* 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}, + + /* 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}, + + /* 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} +}; +int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); + +static int max_titles[6] = { + ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), + (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)), + (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), + (sizeof (path_book_name) / sizeof (char *)) * (sizeof (path_author) / sizeof (char *)), + (sizeof (formula_book_name) / sizeof (char *)) * (sizeof (formula_author) / sizeof (char *)), + (sizeof (gods_book_name) / sizeof (char *)) * (sizeof (gods_author) / sizeof (char *)) }; /****************************************************************************** @@ -543,27 +521,27 @@ static titlelist * get_empty_booklist (void) { - titlelist *bl = new titlelist; + titlelist *bl = new titlelist; - bl->number = 0; - bl->first_book = NULL; - bl->next = NULL; - return bl; + bl->number = 0; + bl->first_book = NULL; + bl->next = NULL; + return bl; } -static title * +static title * get_empty_book (void) { - title *t = new title; + title *t = new title; - t->name = NULL; - t->archname = NULL; - t->authour = NULL; - t->level = 0; - t->size = 0; - t->msg_index = 0; - t->next = NULL; - return t; + t->name = NULL; + t->archname = NULL; + t->authour = NULL; + t->level = 0; + t->size = 0; + t->msg_index = 0; + t->next = NULL; + return t; } /* get_titlelist() - returns pointer to the title list referanced by i */ @@ -571,21 +549,22 @@ static titlelist * get_titlelist (int i) { - titlelist *tl = booklist; - int number = i; + titlelist *tl = booklist; + int number = i; - if (number < 0) - return tl; + if (number < 0) + return tl; - while (tl && number) - { - if (!tl->next) - tl->next = get_empty_booklist (); - tl = tl->next; - number--; - } + while (tl && number) + { + if (!tl->next) + tl->next = get_empty_booklist (); - return tl; + tl = tl->next; + number--; + } + + return tl; } /* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file @@ -595,23 +574,23 @@ * items in buf1 as separated by the value of buf2 */ -int +int nstrtok (const char *buf1, const char *buf2) { - char *tbuf, sbuf[12], buf[MAX_BUF]; - int number = 0; + char *tbuf, sbuf[12], buf[MAX_BUF]; + int number = 0; - if (!buf1 || !buf2) - return 0; - sprintf (buf, "%s", buf1); - sprintf (sbuf, "%s", buf2); - tbuf = strtok (buf, sbuf); - while (tbuf) - { - number++; - tbuf = strtok (NULL, sbuf); - } - return number; + if (!buf1 || !buf2) + return 0; + sprintf (buf, "%s", buf1); + sprintf (sbuf, "%s", buf2); + tbuf = strtok (buf, sbuf); + while (tbuf) + { + number++; + tbuf = strtok (NULL, sbuf); + } + return number; } /* strtoktolin() - takes a string in buf1 and separates it into @@ -619,265 +598,268 @@ * separated string w/ decent punctuation. */ -char * +char * strtoktolin (const char *buf1, const char *buf2) { - int maxi, i = nstrtok (buf1, buf2); - char *tbuf, buf[MAX_BUF], sbuf[12]; - static char rbuf[BOOK_BUF]; - - maxi = i; - strcpy(buf, buf1); - strcpy(sbuf, buf2); - strcpy(rbuf, " "); - tbuf = strtok (buf, sbuf); - while (tbuf && i > 0) - { - strcat (rbuf, tbuf); - i--; - if (i == 1 && maxi > 1) - strcat (rbuf, " and "); - else if (i > 0 && maxi > 1) - strcat (rbuf, ", "); - else - strcat (rbuf, "."); - tbuf = strtok (NULL, sbuf); - } - return (char *) rbuf; + int maxi, i = nstrtok (buf1, buf2); + char *tbuf, buf[MAX_BUF], sbuf[12]; + static char rbuf[BOOK_BUF]; + + maxi = i; + strcpy (buf, buf1); + strcpy (sbuf, buf2); + strcpy (rbuf, " "); + tbuf = strtok (buf, sbuf); + while (tbuf && i > 0) + { + strcat (rbuf, tbuf); + i--; + if (i == 1 && maxi > 1) + strcat (rbuf, " and "); + else if (i > 0 && maxi > 1) + strcat (rbuf, ", "); + else + strcat (rbuf, "."); + tbuf = strtok (NULL, sbuf); + } + return (char *) rbuf; } -int +int book_overflow (const char *buf1, const char *buf2, int booksize) { - if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ - || buf_overflow (buf1, buf2, booksize)) - return 1; - return 0; + if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */ + || buf_overflow (buf1, buf2, booksize)) + return 1; + return 0; } /***************************************************************************** * - * Start of initialization related functions. + * Start of initialisation related functions. * ****************************************************************************/ -/* init_msgfile() - if not called before, initialize the info list +/* init_msgfile() - if not called before, initialise the info list * reads the messages file into the list pointed to by first_msg */ -static void +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...", fname); - - if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) - { - linked_char *tmp = NULL; - while (fgets (buf, MAX_BUF, fp) != NULL) + 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 (*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", 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"); - } + 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; } - close_and_delete (fp, comp); - } + 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, "\ninit_info_listfile() got %d messages.\n", nrofmsg); + LOG (llevDebug, "init_info_listfile() got %d messages.\n", nrofmsg); #endif - LOG (llevDebug, "done.\n"); + LOG (llevDebug, "done.\n"); } -/* init_book_archive() - if not called before, initialize the info list +/* 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 +static void init_book_archive (void) { - FILE *fp; - int comp, nroftitle = 0; - char buf[MAX_BUF], fname[MAX_BUF], *cp; - title *book = NULL; - titlelist *bl = get_empty_booklist (); - static int did_init_barch; - - if (did_init_barch) - return; - did_init_barch = 1; - - if (!booklist) - booklist = bl; - - sprintf (fname, "%s/bookarch", settings.localdir); - LOG (llevDebug, " Reading bookarch from %s...\n", fname); - - if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) - { - int value, type = 0; - size_t i; + FILE *fp; + int comp, nroftitle = 0; + char buf[MAX_BUF], fname[MAX_BUF], *cp; + title *book = NULL; + titlelist *bl = get_empty_booklist (); + static int did_init_barch; + + if (did_init_barch) + return; + + did_init_barch = 1; + + if (!booklist) + booklist = bl; + + sprintf (fname, "%s/bookarch", settings.localdir); + LOG (llevDebug, " Reading bookarch from %s...\n", fname); + + if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) + { + int value, type = 0; + size_t i; - while (fgets (buf, MAX_BUF, fp) != 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, "title", 4)) { - if (*buf == '#') - continue; - if ((cp = strchr (buf, '\n')) != NULL) - *cp = '\0'; - cp = buf; - while (*cp == ' ') /* Skip blanks */ - cp++; - if (!strncmp (cp, "title", 4)) - { - book = get_empty_book (); /* init new book entry */ - book->name = strchr (cp, ' ') + 1; - type = -1; - nroftitle++; - continue; - } - if (!strncmp (cp, "authour", 4)) - { - book->authour = strchr (cp, ' ') + 1; - } - if (!strncmp (cp, "arch", 4)) - { - book->archname = strchr (cp, ' ') + 1; - } - else if (sscanf (cp, "level %d", &value)) - { - book->level = (uint16) value; - } - else if (sscanf (cp, "type %d", &value)) - { - type = (uint16) value; - } - else if (sscanf (cp, "size %d", &value)) - { - book->size = (uint16) value; - } - else if (sscanf (cp, "index %d", &value)) - { - book->msg_index = (uint16) value; - } - else if (!strncmp (cp, "end", 3)) - { /* link it */ - bl = get_titlelist (type); - book->next = bl->first_book; - bl->first_book = book; - bl->number++; - } + book = get_empty_book (); /* init new book entry */ + book->name = strchr (cp, ' ') + 1; + type = -1; + nroftitle++; + continue; + } + if (!strncmp (cp, "authour", 4)) + { + book->authour = strchr (cp, ' ') + 1; } - LOG (llevDebug, " book archives(used/avail): "); - for (bl = booklist, i = 0; bl != NULL && i < sizeof(max_titles)/sizeof(*max_titles); bl = bl->next, i++) + if (!strncmp (cp, "arch", 4)) { - LOG (llevDebug, "(%d/%d)", bl->number, max_titles[i]); + book->archname = strchr (cp, ' ') + 1; + } + else if (sscanf (cp, "level %d", &value)) + { + book->level = (uint16) value; + } + else if (sscanf (cp, "type %d", &value)) + { + type = (uint16) value; + } + else if (sscanf (cp, "size %d", &value)) + { + book->size = (uint16) value; + } + else if (sscanf (cp, "index %d", &value)) + { + book->msg_index = (uint16) value; + } + else if (!strncmp (cp, "end", 3)) + { /* link it */ + bl = get_titlelist (type); + book->next = bl->first_book; + bl->first_book = book; + bl->number++; } - LOG (llevDebug, "\n"); - close_and_delete (fp, comp); - } + } + LOG (llevDebug, "book archives(used/avail): \n"); + for (bl = booklist, i = 0; bl != NULL && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) + { + LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); + } + close_and_delete (fp, comp); + } #ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n init_book_archive() got %d titles.\n", nroftitle); + LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); #endif - LOG (llevDebug, " done.\n"); + LOG (llevDebug, " done.\n"); } /* init_mon_info() - creates the linked list of pointers to * monster archetype objects if not called previously */ -static void +static void init_mon_info (void) { - archetype *at; - static int did_init_mon_info = 0; + archetype *at; + static int did_init_mon_info = 0; - if (did_init_mon_info) - return; - did_init_mon_info = 1; + if (did_init_mon_info) + return; + did_init_mon_info = 1; - for (at = first_archetype; at != NULL; at = at->next) - { - if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && - (!QUERY_FLAG (&at->clone, FLAG_CHANGING) - || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE)) - ) - { - objectlink *mon = (objectlink *) malloc (sizeof (objectlink)); - mon->ob = &at->clone; - mon->id = nrofmon; - mon->next = first_mon_info; - first_mon_info = mon; - nrofmon++; - } - } - LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); + + for (at = first_archetype; at != NULL; at = at->next) + { + if (QUERY_FLAG (&at->clone, FLAG_MONSTER) && (!QUERY_FLAG (&at->clone, FLAG_CHANGING) || QUERY_FLAG (&at->clone, FLAG_UNAGGRESSIVE))) + { + objectlink *mon = new objectlink; + + mon->ob = &at->clone; + mon->next = first_mon_info; + first_mon_info = mon; + nrofmon++; + } + } + + LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); } -/* init_readable() - initialize linked lists utilized by +/* init_readable() - initialise linked lists utilized by * message functions in tailor_readable_ob() * - * This is the function called by the main routine to initialize + * This is the function called by the main routine to initialise * all the readable information. */ -void +void init_readable (void) { - static int did_this; + static int did_this; + + if (did_this) + return; - if (did_this) return; - did_this = 1; + did_this = 1; - LOG (llevDebug, "Initializing reading data..."); - init_msgfile (); - init_book_archive (); - init_mon_info (); - LOG (llevDebug, " Done\n"); + LOG (llevDebug, "Initialising reading data...\n"); + init_msgfile (); + init_book_archive (); + init_mon_info (); + LOG (llevDebug, " Done\n"); } @@ -893,32 +875,32 @@ * book matches something already there. IF so, return that title. */ -static title * +static title * find_title (const object *book, int msgtype) { - title *t = NULL; - titlelist *tl = get_titlelist (msgtype); - int length = strlen (book->msg); - int index = strtoint (book->msg); - - if (msgtype < 0) - return (title *) NULL; - - if (tl) - t = tl->first_book; - while (t) - if (t->size == length && t->msg_index == index) - break; - else - t = t->next; + title *t = NULL; + titlelist *tl = get_titlelist (msgtype); + int length = strlen (book->msg); + int index = strtoint (book->msg); + + if (msgtype < 0) + return (title *) NULL; + + if (tl) + t = tl->first_book; + + while (t) + if (t->size == length && t->msg_index == index) + break; + else + t = t->next; #ifdef ARCHIVE_DEBUG - if (t) - LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", - msgtype, t->name, t->authour, t->msg_index); + if (t) + LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index); #endif - return t; + return t; } /* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is @@ -928,53 +910,53 @@ * is given is based on various criteria */ -static void +static void new_text_name (object *book, int msgtype) { - int nbr; - char name[MAX_BUF]; + int nbr; + char name[MAX_BUF]; - if (book->type != BOOK) - return; + if (book->type != BOOK) + return; - 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 */ + switch (msgtype) + { + 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 *); - 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; - } + 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; + book->name = name; } /* add_book_author() @@ -982,44 +964,44 @@ * and sets op->title to that value */ -static void +static void add_author (object *op, int msgtype) { - char title[MAX_BUF], name[MAX_BUF]; - int nbr = sizeof (book_author) / sizeof (char *); + char title[MAX_BUF], name[MAX_BUF]; + int nbr = sizeof (book_author) / sizeof (char *); - if (msgtype < 0 || strlen (op->msg) < 5) - return; + if (msgtype < 0 || strlen (op->msg) < 5) + return; - 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 */ + switch (msgtype) + { + 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: - strcpy (name, book_author[RANDOM () % nbr]); - } + assign (name, book_author[rndm (nbr)]); + } - sprintf (title, "of %s", name); - op->title = title; + sprintf (title, "of %s", name); + op->title = title; } /* unique_book() - check to see if the book title/msg is unique. We @@ -1027,56 +1009,56 @@ * a match, then unique_book returns true (because inst unique). */ -static int +static int unique_book (const object *book, int msgtype) { - title *test; + title *test; - if (!booklist) - return 1; /* No archival entries! Must be unique! */ + if (!booklist) + return 1; /* No archival entries! Must be unique! */ - /* Go through the booklist. If the author and name match, not unique so - * return 0. - */ - for (test = get_titlelist (msgtype)->first_book; test; test=test->next) { - if (!strcmp(test->name, book->name) && !strcmp(book->title, test->authour)) - return 0; + /* Go through the booklist. If the author and name match, not unique so + * return 0. + */ + for (test = get_titlelist (msgtype)->first_book; test; test = test->next) + { + if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour)) + return 0; } - return 1; + return 1; } /* add_book_to_list() */ -static void +static void add_book_to_list (const object *book, int msgtype) { - titlelist *tl = get_titlelist (msgtype); - title *t; + titlelist *tl = get_titlelist (msgtype); + title *t; - if (!tl) - { - LOG (llevError, "add_book_to_list can't get booklist!\n"); - return; - } + if (!tl) + { + LOG (llevError, "add_book_to_list can't get booklist!\n"); + return; + } - t = get_empty_book (); - t->name = book->name; - t->authour = book->title; - t->size = strlen (book->msg); - t->msg_index = strtoint (book->msg); - t->archname = book->arch->name; - t->level = book->level; - - t->next = tl->first_book; - tl->first_book = t; - tl->number++; + t = get_empty_book (); + t->name = book->name; + t->authour = book->title; + t->size = strlen (book->msg); + t->msg_index = strtoint (book->msg); + t->archname = book->arch->name; + t->level = book->level; + + t->next = tl->first_book; + tl->first_book = t; + tl->number++; - /* We have stuff we need to write now */ - need_to_write_bookarchive=1; + /* We have stuff we need to write now */ + need_to_write_bookarchive = 1; #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, - book->title, msgtype); + LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, book->title, msgtype); #endif } @@ -1092,120 +1074,124 @@ #define MAX_TITLE_CHECK 20 -void +void change_book (object *book, int msgtype) { - int nbr = sizeof (book_descrpt) / sizeof (char *); + int nbr = sizeof (book_descrpt) / sizeof (char *); - switch (book->type) - { - case BOOK: + switch (book->type) + { + case BOOK: { - titlelist *tl = get_titlelist (msgtype); - title *t = NULL; - int tries = 0; - /* look to see if our msg already been archived. If so, alter - * the book to match the archival text. If we fail to match, - * then we archive the new title/name/msg combo if there is - * room on the titlelist. - */ + titlelist *tl = get_titlelist (msgtype); + title *t = NULL; + int tries = 0; + + /* look to see if our msg already been archived. If so, alter + * the book to match the archival text. If we fail to match, + * then we archive the new title/name/msg combo if there is + * room on the titlelist. + */ - if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) - { - object *tmpbook; + if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) + { + object *tmpbook; - /* alter book properties */ - if ((tmpbook = get_archetype (t->archname)) != NULL) - { - tmpbook->msg = book->msg; - copy_object (tmpbook, book); - free_object (tmpbook); - } + /* alter book properties */ + if ((tmpbook = get_archetype (t->archname)) != NULL) + { + tmpbook->msg = book->msg; + tmpbook->copy_to (book); + tmpbook->destroy (); + } - book->title = t->authour; - book->name = t->name; - book->level = t->level; - } - /* Don't have any default title, so lets make up a new one */ - else - { - int numb, maxnames = max_titles[msgtype]; - const char *old_title; - const char *old_name; - - old_title = book->title; - old_name = book->name; - - /* some pre-generated books have title already set (from - * maps), also don't bother looking for unique title if - * we already used up all the available names! */ + book->title = t->authour; + book->name = t->name; + book->level = t->level; + } + /* Don't have any default title, so lets make up a new one */ + else + { + int numb, maxnames = max_titles[msgtype]; + const char *old_title; + const char *old_name; + + old_title = book->title; + old_name = book->name; + + /* some pre-generated books have title already set (from + * maps), also don't bother looking for unique title if + * we already used up all the available names! */ - if (!tl) - { - LOG (llevError, "change_book_name(): can't find title list\n"); - numb = 0; - } - else - numb = tl->number; + if (!tl) + { + LOG (llevError, "change_book_name(): can't find title list\n"); + numb = 0; + } + else + numb = tl->number; - if (numb == maxnames) - { + if (numb == maxnames) + { #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "titles for list %d full (%d possible).\n", - msgtype, maxnames); + LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); #endif - break; - } - /* shouldnt change map-maker books */ - else if (!book->title) - do - { - /* random book name */ - new_text_name (book, msgtype); - add_author (book, msgtype); /* random author */ - tries++; - } - while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); - - /* Now deal with 2 cases. - * 1)If no space for a new title exists lets just restore - * the old book properties. Remember, if the book had - * matchd an older entry on the titlelist, we shouldnt - * have called this routine in the first place! - * 2) If we got a unique title, we need to add it to - * the list. - */ + break; + } + /* shouldnt change map-maker books */ + else if (!book->title) + do + { + /* random book name */ + new_text_name (book, msgtype); + add_author (book, msgtype); /* random author */ + tries++; + } + while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); + + /* Now deal with 2 cases. + * 1)If no space for a new title exists lets just restore + * the old book properties. Remember, if the book had + * matchd an older entry on the titlelist, we shouldnt + * have called this routine in the first place! + * 2) If we got a unique title, we need to add it to + * the list. + */ - if (tries == MAX_TITLE_CHECK || numb == maxnames) - { /* got to check maxnames again */ + if (tries == MAX_TITLE_CHECK || numb == maxnames) + { /* got to check maxnames again */ #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", - book->name, book->title, numb, maxnames); + LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); #endif - /* restore old book properties here */ - book->title = old_title; + /* restore old book properties here */ + book->title = old_title; + + if (RANDOM () % 4) + { + /* Lets give the book a description to individualize it some */ + char new_name[MAX_BUF]; + + snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); - if (RANDOM () % 4) { - /* 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); - - book->name = new_name; - } else { - book->name = old_name; - } + book->name = new_name; } - else if (book->title && strlen (book->msg) > 5) { /* archive if long msg texts */ - add_book_to_list (book, msgtype); - } - } - break; + else + { + book->name = old_name; + } + } + else if (book->title && strlen (book->msg) > 5) + { /* archive if long msg texts */ + add_book_to_list (book, msgtype); + } + } + break; } - default: + default: LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); return; - } + } } /***************************************************************************** @@ -1229,65 +1215,64 @@ object * get_random_mon (int level) { - objectlink *mon = first_mon_info; - int i = 0, monnr; + objectlink *mon = first_mon_info; + int i = 0, monnr; - /* safety check. Problem w/ init_mon_info list? */ - if (!nrofmon || !mon) - return (object *) NULL; - - if (!level) - { - /* lets get a random monster from the mon_info linked list */ - monnr = RANDOM () % nrofmon; - - for (mon = first_mon_info, i = 0; mon; mon = mon->next) - if (i++ == monnr) - break; + /* safety check. Problem w/ init_mon_info list? */ + if (!nrofmon || !mon) + return (object *) NULL; + + if (!level) + { + /* lets get a random monster from the mon_info linked list */ + monnr = RANDOM () % nrofmon; - if (!mon) - { - LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n"); - return NULL; - } - return mon->ob; - } + for (mon = first_mon_info, i = 0; mon; mon = mon->next) + if (i++ == monnr) + break; - /* Case where we are searching by level. Redone 971225 to be clearer - * and more random. Before, it looks like it took a random monster from - * the list, and then returned the first monster after that which was - * appropriate level. This wasn't very random because if you had a - * bunch of low level monsters and then a high level one, if the random - * determine took one of the low level ones, it would just forward to the - * high level one and return that. Thus, monsters that immediatly followed - * a bunch of low level monsters would be more heavily returned. It also - * means some of the dragons would be poorly represented, since they - * are a group of high level monsters all around each other. - */ - - /* First count number of monsters meeting level criteria */ - for (mon = first_mon_info, i = 0; mon; mon = mon->next) - if (mon->ob->level >= level) - i++; - - if (i == 0) - { - LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", - level); + if (!mon) + { + LOG (llevError, "get_random_mon: Didn't find a monster when we should have\n"); return NULL; - } + } + return mon->ob; + } - monnr = RANDOM () % i; - for (mon = first_mon_info; mon; mon = mon->next) - if (mon->ob->level >= level && monnr-- == 0) - return mon->ob; - - if (!mon) - { - LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n"); - return NULL; - } - return NULL; /* Should be unreached, by keeps warnings down */ + /* Case where we are searching by level. Redone 971225 to be clearer + * and more random. Before, it looks like it took a random monster from + * the list, and then returned the first monster after that which was + * appropriate level. This wasn't very random because if you had a + * bunch of low level monsters and then a high level one, if the random + * determine took one of the low level ones, it would just forward to the + * high level one and return that. Thus, monsters that immediatly followed + * a bunch of low level monsters would be more heavily returned. It also + * means some of the dragons would be poorly represented, since they + * are a group of high level monsters all around each other. + */ + + /* First count number of monsters meeting level criteria */ + for (mon = first_mon_info, i = 0; mon; mon = mon->next) + if (mon->ob->level >= level) + i++; + + if (i == 0) + { + LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); + return NULL; + } + + monnr = RANDOM () % i; + for (mon = first_mon_info; mon; mon = mon->next) + if (mon->ob->level >= level && monnr-- == 0) + return mon->ob; + + if (!mon) + { + LOG (llevError, "get_random_mon(): didn't find a monster when we should have\n"); + return NULL; + } + return NULL; /* Should be unreached, by keeps warnings down */ } /* @@ -1295,15 +1280,15 @@ * redone, as describe_item really gives a pretty internal description. */ -char * +char * mon_desc (const object *mon) { - static char retbuf[HUGE_BUF]; + static char retbuf[HUGE_BUF]; - sprintf (retbuf, " *** %s ***\n", &mon->name); - strcat (retbuf, describe_item(mon, NULL)); + sprintf (retbuf, " *** %s ***\n", &mon->name); + strcat (retbuf, describe_item (mon, NULL)); - return retbuf; + return retbuf; } @@ -1315,19 +1300,19 @@ object * get_next_mon (object *tmp) { - objectlink *mon; + objectlink *mon; - for (mon = first_mon_info; mon; mon = mon->next) - if (mon->ob == tmp) - break; - - /* didn't find a match */ - if (!mon) - return NULL; - if (mon->next) - return mon->next->ob; - else - return first_mon_info->ob; + for (mon = first_mon_info; mon; mon = mon->next) + if (mon->ob == tmp) + break; + + /* didn't find a match */ + if (!mon) + return NULL; + if (mon->next) + return mon->next->ob; + else + return first_mon_info->ob; } @@ -1337,43 +1322,44 @@ * of a randomly selected monster. */ -char * +char * mon_info_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; - char tmpbuf[HUGE_BUF]; - object *tmp; - - /*preamble */ - strcpy (retbuf, "This beastiary contains:"); - - /* lets print info on as many monsters as will fit in our - * document. - * 8-96 Had to change this a bit, otherwise there would - * have been an impossibly large number of combinations - * of text! (and flood out the available number of titles - * in the archive in a snap!) -b.t. - */ - tmp = get_random_mon (level * 3); - while (tmp) { - /* monster description */ - sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); + static char retbuf[BOOK_BUF]; + char tmpbuf[HUGE_BUF]; + object *tmp; + + /*preamble */ + strcpy (retbuf, "This beastiary contains:"); + + /* lets print info on as many monsters as will fit in our + * document. + * 8-96 Had to change this a bit, otherwise there would + * have been an impossibly large number of combinations + * of text! (and flood out the available number of titles + * in the archive in a snap!) -b.t. + */ + tmp = get_random_mon (level * 3); + while (tmp) + { + /* monster description */ + sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); + + if (!book_overflow (retbuf, tmpbuf, booksize)) + strcat (retbuf, tmpbuf); + else + break; - if (!book_overflow (retbuf, tmpbuf, booksize)) - strcat (retbuf, tmpbuf); - else - break; - - /* Note that the value this returns is not based on level */ - tmp = get_next_mon (tmp); + /* Note that the value this returns is not based on level */ + tmp = get_next_mon (tmp); } #ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf)); - fprintf (logfile, " MADE THIS:\n%s\n", retbuf); + LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf)); + fprintf (logfile, " MADE THIS:\n%s\n", retbuf); #endif - return retbuf; + return retbuf; } @@ -1385,127 +1371,126 @@ * of 1-6 artifacts drawn sequentially from the artifact list. */ -char * +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]; - static char retbuf[BOOK_BUF]; - object *tmp = NULL; - - /* values greater than 5 create msg buffers that are too big! */ - if (book_entries > 5) - book_entries = 5; - - /* lets determine what kind of artifact type randomly. - * Right now legal artifacts only come from those listed - * in art_name_array. Also, we check to be sure an artifactlist - * for that type exists! - */ - i=0; - do { - index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); - type = art_name_array[index].type; - al = find_artifactlist (type); - i++; - } while ((al == NULL) && (i<10)); - - if (i==10) /* Unable to find a message */ - return("None"); - - /* There is no reason to start on the artifact list at the begining. Lets - * take our starting position randomly... */ - art = al->items; - for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) - { - if (art == NULL) - art = al->items; /* hmm, out of stuff, loop back around */ - art = art->next; - } - - /* the base 'generic' name for our artifact */ - strcpy(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"); - - /* artifact msg attributes loop. Lets keep adding entries to the 'book' - * as long as we have space up to the allowed max # (book_entires) - */ - while (book_entries > 0) - { + 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]; + static char retbuf[BOOK_BUF]; + object *tmp = NULL; + + /* values greater than 5 create msg buffers that are too big! */ + if (book_entries > 5) + book_entries = 5; + + /* lets determine what kind of artifact type randomly. + * Right now legal artifacts only come from those listed + * in art_name_array. Also, we check to be sure an artifactlist + * for that type exists! + */ + i = 0; + do + { + index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); + type = art_name_array[index].type; + al = find_artifactlist (type); + i++; + } + while ((al == NULL) && (i < 10)); + + if (i == 10) /* Unable to find a message */ + return ("None"); + + /* There is no reason to start on the artifact list at the begining. Lets + * take our starting position randomly... */ + art = al->items; + for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) + { + if (art == NULL) + art = al->items; /* hmm, out of stuff, loop back around */ + art = art->next; + } - if (art == NULL) - art = al->items; + /* the base 'generic' name for our artifact */ + assign (name, art_name_array[index].name); - /* separator of items */ - strcpy (buf, "--- \n"); + /* 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"); - /* Name */ - if (art->allowed != NULL && strcmp (art->allowed->name, "All")) + /* artifact msg attributes loop. Lets keep adding entries to the 'book' + * as long as we have space up to the allowed max # (book_entires) + */ + while (book_entries > 0) + { + + if (art == NULL) + art = al->items; + + /* separator of items */ + strcpy (buf, "--- \n"); + + /* Name */ + if (art->allowed != NULL && strcmp (art->allowed->name, "All")) + { + linked_char *temp, *next = art->allowed; + + do { - linked_char *temp, *next = art->allowed; - do - { - temp = next; - next = next->next; - } - while (next && !RANDOM () % 2); - sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); + temp = next; + next = next->next; } - else /* default name is used */ - sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); - - /* chance of finding */ - chance = (int) (100 * ((float) art->chance / al->total_chance)); - if (chance >= 20) - sprintf (sbuf, "an uncommon"); - else if (chance >= 10) - sprintf (sbuf, "an unusual"); - else if (chance >= 5) - sprintf (sbuf, "a rare"); - else - sprintf (sbuf, "a very rare"); - sprintf (buf, "%s is %s\n", buf, sbuf); + while (next && !RANDOM () % 2); + sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); + } + else /* default name is used */ + sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); - /* value of artifact */ - sprintf (buf, "%s item with a value that is %d times normal.\n", - buf, art->item->value); - - /* include the message about the artifact, if exists, and book - * level is kinda high */ - if (art->item->msg && (RANDOM () % 4 + 1) < level && - !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) - strcat(buf, art->item->msg); - - /* properties of the artifact */ - tmp = get_object (); - add_abilities (tmp, art->item); - tmp->type = type; - SET_FLAG (tmp, FLAG_IDENTIFIED); - if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) - sprintf (buf, "%s Properties of this artifact include: \n %s \n", - buf, ch); - free_object(tmp); - /* add the buf if it will fit */ - if (!book_overflow (retbuf, buf, booksize)) - strcat (retbuf, buf); - else - break; + /* chance of finding */ + chance = (int) (100 * ((float) art->chance / al->total_chance)); + if (chance >= 20) + sprintf (sbuf, "an uncommon"); + else if (chance >= 10) + sprintf (sbuf, "an unusual"); + else if (chance >= 5) + sprintf (sbuf, "a rare"); + else + sprintf (sbuf, "a very rare"); + sprintf (buf, "%s is %s\n", buf, sbuf); + + /* value of artifact */ + sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); + + /* include the message about the artifact, if exists, and book + * level is kinda high */ + if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) + strcat (buf, art->item->msg); + + /* properties of the artifact */ + tmp = object::create (); + add_abilities (tmp, art->item); + tmp->type = type; + SET_FLAG (tmp, FLAG_IDENTIFIED); + if ((ch = describe_item (tmp, NULL)) != NULL && strlen (ch) > 1) + sprintf (buf, "%s Properties of this artifact include: \n %s \n", buf, ch); + tmp->destroy (); + /* add the buf if it will fit */ + if (!book_overflow (retbuf, buf, booksize)) + strcat (retbuf, buf); + else + break; - art = art->next; - book_entries--; - } + art = art->next; + book_entries--; + } #ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf)); - fprintf (logfile, " MADE THIS:\n%s", retbuf); + LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf)); + fprintf (logfile, " MADE THIS:\n%s", retbuf); #endif - return retbuf; + return retbuf; } /***************************************************************************** @@ -1517,57 +1502,59 @@ * a given spellpath. */ -char * +char * spellpath_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; - char tmpbuf[BOOK_BUF]; - int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; - int did_first_sp = 0; - uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; - archetype *at; - - /* Preamble */ - sprintf (retbuf, "Herein are detailed the names of %s\n", - prayers ? "prayers": "incantations"); - - if (path == -1) - strcat (retbuf, "having no known spell path.\n"); - else - sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, - spellpathnames[path]); - - for (at=first_archetype; at != NULL; at=at->next) { - /* 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))) { - strcpy (tmpbuf, at->clone.name); + static char retbuf[BOOK_BUF]; + char tmpbuf[BOOK_BUF]; + int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; + int did_first_sp = 0; + uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; + archetype *at; + + /* Preamble */ + sprintf (retbuf, "Herein are detailed the names of %s\n", prayers ? "prayers" : "incantations"); + + if (path == -1) + strcat (retbuf, "having no known spell path.\n"); + else + sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); + + for (at = first_archetype; at != NULL; at = at->next) + { + /* 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))) + { + assign (tmpbuf, at->clone.name); - if (book_overflow (retbuf, tmpbuf, booksize)) - break; - else { - if (did_first_sp) - strcat (retbuf, ",\n"); - did_first_sp = 1; - strcat (retbuf, tmpbuf); - } + if (book_overflow (retbuf, tmpbuf, booksize)) + break; + else + { + if (did_first_sp) + strcat (retbuf, ",\n"); + did_first_sp = 1; + strcat (retbuf, tmpbuf); } + } } - /* Geez, no spells were generated. */ - if (!did_first_sp) { - if (RANDOM () % 4) /* usually, lets make a recursive call... */ - spellpath_msg (level, booksize); - else /* give up, cause knowing no spells exist for path is info too. */ - strcat (retbuf, "\n - no known spells exist -\n"); + /* Geez, no spells were generated. */ + if (!did_first_sp) + { + if (RANDOM () % 4) /* usually, lets make a recursive call... */ + spellpath_msg (level, booksize); + else /* give up, cause knowing no spells exist for path is info too. */ + strcat (retbuf, "\n - no known spells exist -\n"); } - else { - strcat (retbuf, "\n"); + else + { + strcat (retbuf, "\n"); } - return retbuf; + return retbuf; } @@ -1576,113 +1563,114 @@ * of a randomly selected alchemical formula. */ -void make_formula_book(object *book, int level) { - char retbuf[BOOK_BUF], title[MAX_BUF]; - recipelist *fl; - recipe *formula = NULL; - int chance; - - /* the higher the book level, the more complex (ie number of - * ingredients) the formula can be. - */ - fl = get_formulalist (((RANDOM () % level) / 3) + 1); - - if (!fl) - fl = get_formulalist (1); /* safety */ - - if (fl->total_chance == 0) - { - book->msg = "\n"; - new_text_name(book, 4); - add_author(book,4); - return; - } - - /* get a random formula, weighted by its bookchance */ - chance = RANDOM () % fl->total_chance; - for (formula = fl->items; formula != NULL; formula = formula->next) { - chance -= formula->chance; - if (chance <= 0) - break; +void +make_formula_book (object *book, int level) +{ + char retbuf[BOOK_BUF], title[MAX_BUF]; + recipelist *fl; + recipe *formula = NULL; + int chance; + + /* the higher the book level, the more complex (ie number of + * ingredients) the formula can be. + */ + fl = get_formulalist (((RANDOM () % level) / 3) + 1); + + if (!fl) + fl = get_formulalist (1); /* safety */ + + if (fl->total_chance == 0) + { + book->msg = "\n"; + new_text_name (book, 4); + add_author (book, 4); + return; } - if (!formula || formula->arch_names <= 0) { - book->msg = "\n"; - new_text_name(book, 4); - add_author(book,4); - - } else { - /* looks like a formula was found. Base the amount - * of information on the booklevel and the spellevel - * of the formula. */ - - const char *op_name = formula->arch_name[RANDOM()%formula->arch_names]; - archetype *at; - - /* preamble */ - sprintf(retbuf, "Herein is described a project using %s: \n", - formula->skill?formula->skill:"an unknown skill"); - - if ((at = find_archetype (op_name)) != (archetype *) NULL) - op_name = at->clone.name; - else - LOG (llevError, "formula_msg() can't find arch %s for formula.\n", - op_name); - - /* item name */ - if (strcmp (formula->title, "NONE")) { - 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); + /* get a random formula, weighted by its bookchance */ + chance = RANDOM () % fl->total_chance; + for (formula = fl->items; formula != NULL; formula = formula->next) + { + chance -= formula->chance; + if (chance <= 0) + break; + } + + if (!formula || formula->arch_names <= 0) + { + book->msg = "\n"; + new_text_name (book, 4); + add_author (book, 4); + + } + else + { + /* looks like a formula was found. Base the amount + * of information on the booklevel and the spellevel + * of the formula. */ + + const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; + archetype *at; + + /* preamble */ + 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; + else + LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); + + /* item name */ + if (strcmp (formula->title, "NONE")) + { + 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(title,"%s: %s", - formula_book_name[RANDOM() % (sizeof(formula_book_name) / sizeof(char*))], - op_name); - if (at->clone.title) + 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) { - strcat (retbuf, " "); - strcat (retbuf, at->clone.title); - strcat(title, " "); - strcat(title, at->clone.title); + strcat (retbuf, " "); + strcat (retbuf, at->clone.title); + strcat (title, " "); + strcat (title, at->clone.title); } } - /* Lets name the book something meaningful ! */ - book->name = title; - book->title = NULL; + /* Lets name the book something meaningful ! */ + book->name = title; + book->title = NULL; - /* ingredients to make it */ - if (formula->ingred != NULL) + /* ingredients to make it */ + if (formula->ingred != NULL) { - linked_char *next; - archetype *at; + linked_char *next; + archetype *at; - at = find_archetype(formula->cauldron); + 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"); + sprintf (retbuf + strlen (retbuf), + " may be made at %s using the following ingredients:\n", at ? query_name (&at->clone) : "an unknown place"); - for (next = formula->ingred; next != NULL; next = next->next) + for (next = formula->ingred; next != NULL; next = next->next) { - strcat (retbuf, next->name); - strcat (retbuf, "\n"); + strcat (retbuf, next->name); + strcat (retbuf, "\n"); } } - else - LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", - op_name, formula->title); - if (retbuf[strlen(retbuf)-1]!= '\n') strcat(retbuf, "\n"); + else + LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title); + if (retbuf[strlen (retbuf) - 1] != '\n') + strcat (retbuf, "\n"); - book->msg = retbuf; + book->msg = retbuf; } } @@ -1692,33 +1680,33 @@ * which is returned. */ -char * +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; - } + 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 "); + if (msg && !book_overflow (retbuf, msg->name, booksize)) + assign (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); + LOG (llevDebug, "\n info_list_msg() created strng: %d\n", strlen (retbuf)); + LOG (llevDebug, " MADE THIS:\n%s\n", retbuf); #endif - return retbuf; + return retbuf; } @@ -1726,194 +1714,199 @@ * of a random god. Used by the book hack. b.t. */ -const char * +const char * god_info_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; - const char *name = NULL; - char buf[BOOK_BUF]; - int i; - size_t introlen; - object *god = pntr_to_god_obj (get_rand_god ()); - - if (!god) - return (char *) NULL; /* oops, problems... */ - name = god->name; - - /* preamble.. */ - sprintf (retbuf, "This document contains knowledge concerning\n"); - sprintf (retbuf, "%sthe diety %s", retbuf, name); - - /* Always have as default information the god's descriptive terms. */ - if (nstrtok (god->msg, ",") > 0) - { - strcat (retbuf, ", known as"); - strcat (retbuf, strtoktolin (god->msg, ",")); - } - else - strcat (retbuf, "..."); + static char retbuf[BOOK_BUF]; + const char *name = NULL; + char buf[BOOK_BUF]; + int i; + size_t introlen; + object *god = pntr_to_god_obj (get_rand_god ()); + + if (!god) + return (char *) NULL; /* oops, problems... */ + name = god->name; + + /* preamble.. */ + sprintf (retbuf, "This document contains knowledge concerning\n"); + sprintf (retbuf, "%sthe diety %s", retbuf, name); + + /* Always have as default information the god's descriptive terms. */ + if (nstrtok (god->msg, ",") > 0) + { + strcat (retbuf, ", known as"); + strcat (retbuf, strtoktolin (god->msg, ",")); + } + else + strcat (retbuf, "..."); - strcat (retbuf, "\n ---\n"); - introlen = strlen (retbuf); /* so we will know if no new info is added later */ + strcat (retbuf, "\n ---\n"); + introlen = strlen (retbuf); /* so we will know if no new info is added later */ - /* Information about the god is random, and based on the level of the - * 'book'. Probably there is a more intellegent way to implement - * this ... - */ - - while (level > 0) - { - sprintf (buf, " "); - if (level == 2 && RANDOM () % 2) - { /* enemy god */ - const char *enemy = god->title; - 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; - if (enemy && !(god->path_denied & PATH_TURNING)) - if ((i = nstrtok (enemy, ",")) > 0) - { - char tmpbuf[MAX_BUF]; - sprintf (buf, "The holy words of %s have the power to\n", name); - strcat (buf, "slay creatures belonging to the "); - if (i > 1) - sprintf (tmpbuf, "following \n races:%s", - strtoktolin (enemy, ",")); - else - sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); - 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); - - if (*cp) { /* 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"); - strcat(tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } + /* Information about the god is random, and based on the level of the + * 'book'. Probably there is a more intellegent way to implement + * this ... + */ + + while (level > 0) + { + sprintf (buf, " "); + if (level == 2 && RANDOM () % 2) + { /* enemy god */ + const char *enemy = god->title; + + 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; + + if (enemy && !(god->path_denied & PATH_TURNING)) + if ((i = nstrtok (enemy, ",")) > 0) + { + char tmpbuf[MAX_BUF]; + + sprintf (buf, "The holy words of %s have the power to\n", name); + strcat (buf, "slay creatures belonging to the "); + if (i > 1) + sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ",")); else - sprintf (buf, " "); - } - if (level == 5 && RANDOM () % 2) - { /* aligned race, summoning */ - const char *race = god->race; /* aligned race */ - if (race && !(god->path_denied & PATH_SUMMON)) - if ((i = nstrtok (race, ",")) > 0) - { - char tmpbuf[MAX_BUF]; - sprintf (buf, "Creatures sacred to %s include the \n", name); - if (i > 1) - sprintf (tmpbuf, "following \n races:%s", - strtoktolin (race, ",")); - else - sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); - sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); - } + sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); + 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); + + if (*cp) + { /* 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"); + strcat (tmpbuf, cp); + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); } - if (level == 6 && RANDOM () % 2) - { /* blessing,curse properties of the god */ - char tmpbuf[MAX_BUF],*cp; - - cp = describe_resistance(god, 1); - - if (*cp) { /* 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"); - strcat(tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } + else + sprintf (buf, " "); + } + if (level == 5 && RANDOM () % 2) + { /* aligned race, summoning */ + const char *race = god->race; /* aligned race */ + + if (race && !(god->path_denied & PATH_SUMMON)) + if ((i = nstrtok (race, ",")) > 0) + { + char tmpbuf[MAX_BUF]; + + sprintf (buf, "Creatures sacred to %s include the \n", name); + if (i > 1) + sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ",")); else - sprintf (buf, " "); - + sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); + 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); + + if (*cp) + { /* 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"); + strcat (tmpbuf, cp); + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); } - if (level == 8 && RANDOM () % 2) - { /* immunity, holy possession */ - int has_effect = 0, tmpvar; - char tmpbuf[MAX_BUF]; - sprintf (tmpbuf, "\n"); - sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n" - ,name); - - strcat (tmpbuf, "prayer of possession which gives the recipient\n"); - - for (tmpvar=0; tmpvarresist[tmpvar]==100) { - has_effect = 1; - sprintf(tmpbuf + strlen(tmpbuf),"Immunity to %s", attacktype_desc[tmpvar]); - } - } - if (has_effect) { - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); + else + sprintf (buf, " "); + + } + if (level == 8 && RANDOM () % 2) + { /* immunity, holy possession */ + int has_effect = 0, tmpvar; + char tmpbuf[MAX_BUF]; + + sprintf (tmpbuf, "\n"); + sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n", name); + + strcat (tmpbuf, "prayer of possession which gives the recipient\n"); + + for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++) + { + if (god->resist[tmpvar] == 100) + { + has_effect = 1; + sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]); } - else - sprintf (buf, " "); } - if (level == 12 && RANDOM () % 2) - { /* spell paths */ - int has_effect = 0, tmpvar; - char tmpbuf[MAX_BUF]; - 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); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); + if (has_effect) + { + strcat (buf, tmpbuf); + strcat (buf, "\n ---\n"); + } + else + sprintf (buf, " "); + } + if (level == 12 && RANDOM () % 2) + { /* spell paths */ + int has_effect = 0, tmpvar; + char tmpbuf[MAX_BUF]; + + 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); + strcat (buf, "\n ---\n"); } + else + sprintf (buf, " "); + } - /* check to be sure new buffer size dont exceed either - * the maximum buffer size, or the 'natural' size of the - * book... - */ - if (book_overflow (retbuf, buf, booksize)) - 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"); - strcat (retbuf, " hopelessly garbled!]\n ---\n"); - } + /* check to be sure new buffer size dont exceed either + * the maximum buffer size, or the 'natural' size of the + * book... + */ + if (book_overflow (retbuf, buf, booksize)) + 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"); + strcat (retbuf, " hopelessly garbled!]\n ---\n"); + } #ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); - fprintf (logfile, " MADE THIS:\n%s", retbuf); + LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf)); + fprintf (logfile, " MADE THIS:\n%s", retbuf); #endif - return retbuf; + return retbuf; } /* tailor_readable_ob()- The main routine. This chooses a random @@ -1933,68 +1926,69 @@ * */ -void +void tailor_readable_ob (object *book, int msg_type) { - char msgbuf[BOOK_BUF]; - int level = book->level ? (RANDOM () % book->level) + 1 : 1; - int book_buf_size; - - /* safety */ - if (book->type != BOOK) - return; - - if (level <= 0) - return; /* if no level no point in doing any more... */ - - /* Max text length this book can have. */ - book_buf_size = BOOKSIZE (book); - - /* &&& The message switch &&& */ - /* Below all of the possible types of messages in the "book"s. - */ - /* - * IF you add a new type of book msg, you will have to do several things. - * 1) make sure there is an entry in the msg switch below! - * 2) make sure there is an entry in max_titles[] array. - * 3) make sure there are entries for your case in new_text_title() - * and add_authour(). - * 4) you may want separate authour/book name arrays in read.h - */ - - msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); - switch (msg_type) - { - case 1: /* monster attrib */ + char msgbuf[BOOK_BUF]; + int level = book->level ? (RANDOM () % book->level) + 1 : 1; + int book_buf_size; + + /* safety */ + if (book->type != BOOK) + return; + + if (level <= 0) + return; /* if no level no point in doing any more... */ + + /* Max text length this book can have. */ + book_buf_size = BOOKSIZE (book); + + /* &&& The message switch &&& */ + /* Below all of the possible types of messages in the "book"s. + */ + /* + * IF you add a new type of book msg, you will have to do several things. + * 1) make sure there is an entry in the msg switch below! + * 2) make sure there is an entry in max_titles[] array. + * 3) make sure there are entries for your case in new_text_title() + * and add_authour(). + * 4) you may want separate authour/book name arrays in read.h + */ + + 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 */ + case 2: /* artifact attrib */ strcpy (msgbuf, artifact_msg (level, book_buf_size)); break; - case 3: /* grouping incantations/prayers by path */ + 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 */ + 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: + case 0: /* use info list in lib/ */ + default: strcpy (msgbuf, msgfile_msg (level, book_buf_size)); break; - } + } - strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ - if (strlen (msgbuf) > 1) - { - book->msg = msgbuf; - /* lets give the "book" a new name, which may be a compound word */ - change_book (book, msg_type); - } + strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ + + if (strlen (msgbuf) > 1) + { + book->msg = msgbuf; + /* lets give the "book" a new name, which may be a compound word */ + change_book (book, msg_type); + } } @@ -2005,38 +1999,40 @@ * *****************************************************************************/ -void +void free_all_readable (void) { - titlelist *tlist, *tnext; - title *title1, *titlenext; - linked_char *lmsg, *nextmsg; - objectlink *monlink, *nextmon; - - LOG (llevDebug, "freeing all book information\n"); - - for (tlist = booklist; tlist != NULL; tlist = tnext) - { - tnext = tlist->next; + titlelist *tlist, *tnext; + title *title1, *titlenext; + linked_char *lmsg, *nextmsg; + objectlink *monlink, *nextmon; + + LOG (llevDebug, "freeing all book information\n"); + + for (tlist = booklist; tlist != NULL; tlist = tnext) + { + tnext = tlist->next; - for (title1 = tlist->first_book; title1; title1 = titlenext) - { - titlenext = title1->next; - delete title1; - } + for (title1 = tlist->first_book; title1; title1 = titlenext) + { + titlenext = title1->next; + delete title1; + } + + delete tlist; + } + + for (lmsg = first_msg; lmsg; lmsg = nextmsg) + { + nextmsg = lmsg->next; + delete lmsg; + } - delete tlist; - } - for (lmsg = first_msg; lmsg; lmsg = nextmsg) - { - nextmsg = lmsg->next; - delete lmsg; - } - for (monlink = first_mon_info; monlink; monlink = nextmon) - { - nextmon = monlink->next; - free (monlink); - } + for (monlink = first_mon_info; monlink; monlink = nextmon) + { + nextmon = monlink->next; + delete monlink; + } } @@ -2048,52 +2044,56 @@ /* write_book_archive() - write out the updated book archive */ -void +void write_book_archive (void) { - FILE *fp; - int index = 0; - char fname[MAX_BUF]; - title *book = NULL; - titlelist *bl = get_titlelist (0); - - /* If nothing changed, don't write anything */ - if (!need_to_write_bookarchive) return; - need_to_write_bookarchive=0; - - sprintf (fname, "%s/bookarch", settings.localdir); - LOG (llevDebug, "Updating book archive: %s...\n", fname); - - if ((fp = fopen (fname, "w")) == NULL) - { - LOG (llevDebug, "Can't open book archive file %s\n", fname); - } - else - { - while (bl) - { - for (book = bl->first_book; book; book = book->next) - if (book && book->authour) - { - fprintf (fp, "title %s\n", &book->name); - fprintf (fp, "authour %s\n", &book->authour); - fprintf (fp, "arch %s\n", &book->archname); - fprintf (fp, "level %d\n", book->level); - fprintf (fp, "type %d\n", index); - fprintf (fp, "size %d\n", book->size); - fprintf (fp, "index %d\n", book->msg_index); - fprintf (fp, "end\n"); - } - bl = bl->next; - index++; - } - fclose (fp); - chmod (fname, SAVE_MODE); - } -} -readable_message_type* get_readable_message_type(object* readable){ - uint8 subtype = readable->subtype; - if (subtype>last_readable_subtype) - return &(readable_message_types[0]); - return &(readable_message_types[subtype]); + FILE *fp; + int index = 0; + char fname[MAX_BUF]; + title *book = NULL; + titlelist *bl = get_titlelist (0); + + /* If nothing changed, don't write anything */ + if (!need_to_write_bookarchive) + return; + need_to_write_bookarchive = 0; + + sprintf (fname, "%s/bookarch", settings.localdir); + LOG (llevDebug, "Updating book archive: %s...\n", fname); + + if ((fp = fopen (fname, "w")) == NULL) + { + LOG (llevDebug, "Can't open book archive file %s\n", fname); + } + else + { + while (bl) + { + for (book = bl->first_book; book; book = book->next) + if (book && book->authour) + { + fprintf (fp, "title %s\n", &book->name); + fprintf (fp, "authour %s\n", &book->authour); + fprintf (fp, "arch %s\n", &book->archname); + fprintf (fp, "level %d\n", book->level); + fprintf (fp, "type %d\n", index); + fprintf (fp, "size %d\n", book->size); + fprintf (fp, "index %d\n", book->msg_index); + fprintf (fp, "end\n"); + } + bl = bl->next; + index++; + } + fclose (fp); + chmod (fname, SAVE_MODE); + } +} +readable_message_type * +get_readable_message_type (object *readable) +{ + uint8 subtype = readable->subtype; + + if (subtype > last_readable_subtype) + return &(readable_message_types[0]); + return &(readable_message_types[subtype]); }