--- deliantra/server/common/readable.C 2007/05/28 21:21:40 1.25 +++ deliantra/server/common/readable.C 2008/09/29 10:32:50 1.37 @@ -1,25 +1,24 @@ /* - * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * 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. + * Deliantra 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 3 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 Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . * - * The authors can be reached via e-mail to + * The authors can be reached via e-mail to */ /* This file contains code relevant to the BOOKS hack -- designed @@ -437,68 +436,68 @@ * subtype paramater in arch files! */ static readable_message_type readable_message_types[] = { - /*subtype 0 */ {0, 0}, + /*subtype 0 */ {0, 0, "info"}, /* 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); @@ -750,14 +749,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++; @@ -971,7 +969,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; @@ -1005,116 +1003,114 @@ 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. - */ - - if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) - { - object *tmpbook; + 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. + */ - /* alter book properties */ - if ((tmpbook = get_archetype (t->archname)) != NULL) - { - tmpbook->msg = book->msg; - tmpbook->copy_to (book); - tmpbook->destroy (); - } + if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) + { + /* alter book properties */ + if (object *tmpbook = get_archetype (t->archname)) + { + 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; + 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++; } - /* 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); + 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. - */ + /* 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); - - book->name = new_name; - } - 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; - } + if (RANDOM () % 4) + { + /* Lets give the book a description to individualize it some */ + char new_name[MAX_BUF]; - default: - LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); - return; + snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); + + book->name = new_name; + } + 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: + LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); + return; } } @@ -1444,16 +1440,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))) { - assign (tmpbuf, at->clone.name); + assign (tmpbuf, at->object::name); if (book_overflow (retbuf, tmpbuf, booksize)) break; @@ -1537,7 +1533,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); @@ -1557,12 +1553,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 ! */ @@ -1578,7 +1574,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) { @@ -1595,6 +1591,21 @@ } } +#define DESCRIBE_PATH(retbuf, variable, name) \ + if(variable) { \ + int i,j=0; \ + strcat(retbuf,"(" name ": "); \ + for(i=0; i 0) { sprintf (buf, " "); @@ -1846,8 +1856,7 @@ * and add_authour(). * 4) you may want separate authour/book name arrays in read.h */ - - msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); + msg_type = msg_type > 0 ? msg_type : (RANDOM () % 8); switch (msg_type) { case 1: /* monster attrib */ @@ -1881,7 +1890,6 @@ /* lets give the "book" a new name, which may be a compound word */ change_book (book, msg_type); } - } @@ -1986,6 +1994,7 @@ uint8 subtype = readable->subtype; if (subtype > last_readable_subtype) - return &(readable_message_types[0]); - return &(readable_message_types[subtype]); + return &readable_message_types[0]; + + return &readable_message_types[subtype]; }