--- deliantra/server/common/readable.C 2008/12/27 02:31:19 1.38 +++ deliantra/server/common/readable.C 2009/10/15 21:40:42 1.44 @@ -1,22 +1,23 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * 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. + * Deliantra is free software: you can redistribute it and/or modify it under + * the terms of the Affero 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. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * You should have received a copy of the Affero GNU General Public License + * and the GNU General Public License along with this program. If not, see + * . * * The authors can be reached via e-mail to */ @@ -32,7 +33,6 @@ #include #include - /* Define this if you want to archive book titles by contents. * This option should enforce UNIQUE combinations of titles,authors and * msg contents during and *between* game sessions. @@ -571,8 +571,7 @@ /* nstrtok() - simple routine to return the number of list * items in buf1 as separated by the value of buf2 */ - -int +static int nstrtok (const char *buf1, const char *buf2) { char *tbuf, sbuf[12], buf[MAX_BUF]; @@ -595,8 +594,7 @@ * a list of strings delimited by buf2. Then returns a comma * separated string w/ decent punctuation. */ - -char * +static char * strtoktolin (const char *buf1, const char *buf2) { int maxi, i = nstrtok (buf1, buf2); @@ -623,16 +621,14 @@ return (char *) rbuf; } -int +static 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; - + return 0; } /***************************************************************************** @@ -819,7 +815,7 @@ #ifdef ARCHIVE_DEBUG if (t) - LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index); + LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, &t->name, &t->authour, t->msg_index); #endif return t; @@ -831,7 +827,6 @@ * this sets book book->name based on msgtype given. What name * is given is based on various criteria */ - static void new_text_name (object *book, int msgtype) { @@ -934,19 +929,16 @@ static int unique_book (const object *book, int msgtype) { - title *test; - 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; - } + for (title *test = get_titlelist (msgtype)->first_book; test; test = test->next) + if (test->name == book->name && book->title == test->authour) + return 0; + return 1; } @@ -980,7 +972,7 @@ 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 } @@ -996,7 +988,7 @@ #define MAX_TITLE_CHECK 20 -void +static void change_book (object *book, int msgtype) { int nbr = sizeof (book_descrpt) / sizeof (char *); @@ -1056,7 +1048,6 @@ #ifdef ARCHIVE_DEBUG LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); #endif - break; } /* shouldnt change map-maker books */ else if (!book->title) @@ -1081,7 +1072,7 @@ 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; @@ -1131,7 +1122,6 @@ * Changed 971225 to be greater than equal to level passed. Also * made choosing by level more random. */ - object * get_random_mon (int level) { @@ -1199,16 +1189,15 @@ * Returns a description of the monster. This really needs to be * redone, as describe_item really gives a pretty internal description. */ - -char * +static const char * mon_desc (const object *mon) { - static char retbuf[HUGE_BUF]; + static dynbuf_text buf; buf.clear (); - sprintf (retbuf, " *** %s ***\n", &mon->name); - strcat (retbuf, describe_item (mon, NULL)); + buf.printf ("B<< %s >>\r", &mon->name); + buf << describe_item (mon, 0); - return retbuf; + return buf; } @@ -1216,8 +1205,7 @@ * found, it returns NULL (changed 0.94.3 to do this, since the * calling function (mon_info_msg) seems to expect that. */ - -object * +static object * get_next_mon (object *tmp) { objectlink *mon; @@ -1236,21 +1224,16 @@ } - - /* mon_info_msg() - generate a message detailing the properties * of a randomly selected monster. */ - -char * +static const char * mon_info_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; - char tmpbuf[HUGE_BUF]; - object *tmp; + static dynbuf_text buf; buf.clear (); /*preamble */ - strcpy (retbuf, "This beastiary contains:"); + buf << "This beastiary contains:\n"; /* lets print info on as many monsters as will fit in our * document. @@ -1259,27 +1242,17 @@ * 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) + object *tmp = get_random_mon (level * 3); + while (tmp && buf.size () < BOOK_BUF) { /* monster description */ - sprintf (tmpbuf, "\n---\n%s", mon_desc (tmp)); - - if (!book_overflow (retbuf, tmpbuf, booksize)) - strcat (retbuf, tmpbuf); - else - break; + buf.printf ("\n%s\n", mon_desc (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); -#endif - - return retbuf; + return buf; } @@ -1290,7 +1263,7 @@ /* artifact_msg() - generate a message detailing the properties * of 1-6 artifacts drawn sequentially from the artifact list. */ -const char * +static const char * artifact_msg (int level, int booksize) { artifactlist *al = NULL; @@ -1354,7 +1327,7 @@ strcpy (buf, "--- \n"); /* Name */ - if (art->allowed != NULL && strcmp (art->allowed->name, "All")) + if (art->allowed && art->allowed->name != shstr_All) { linked_char *temp, *next = art->allowed; @@ -1410,8 +1383,8 @@ } #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 string: %d\n", strlen (retbuf)); + LOG (llevDebug, " MADE THIS:\n%s", retbuf); #endif return retbuf; } @@ -1424,8 +1397,7 @@ * incantations/prayers (and some of their properties) belonging to * a given spellpath. */ - -char * +static char * spellpath_msg (int level, int booksize) { static char retbuf[BOOK_BUF]; @@ -1477,13 +1449,18 @@ { strcat (retbuf, "\n"); } + +#ifdef BOOK_MSG_DEBUG + LOG (llevDebug, "spellpath_msg() created string: %d\n", strlen (retbuf)); + LOG (llevDebug, " MADE THIS:\n%s", retbuf); +#endif return retbuf; } /* formula_msg() - generate a message detailing the properties * of a randomly selected alchemical formula. */ -void +static void make_formula_book (object *book, int level) { char retbuf[BOOK_BUF], title[MAX_BUF]; @@ -1541,7 +1518,7 @@ LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); /* item name */ - if (strcmp (formula->title, "NONE")) + if (formula->title != shstr_NONE) { sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); /* This results in things like pile of philo. sulfur. @@ -1564,6 +1541,7 @@ strcat (title, at->title); } } + /* Lets name the book something meaningful ! */ book->name = title; book->title = NULL; @@ -1612,7 +1590,7 @@ /* god_info_msg() - generate a message detailing the properties * of a random god. Used by the book hack. b.t. */ -const char * +static const char * god_info_msg (int level, int booksize) { static char retbuf[BOOK_BUF]; @@ -1809,8 +1787,8 @@ 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 string: %d\n", strlen (retbuf)); + LOG (llevDebug, " MADE THIS:\n%s", retbuf); #endif return retbuf; }