--- deliantra/server/common/readable.C 2010/04/15 21:49:15 1.58 +++ deliantra/server/common/readable.C 2012/10/29 23:55:52 1.65 @@ -1,24 +1,24 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. - * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen - * + * * 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 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 */ @@ -403,7 +403,7 @@ "cryptic", "cryptical", "dusty", - "hiearchical", + "hierarchical", "grizzled", "gold-guilt", "great", @@ -571,8 +571,10 @@ if (!buf1 || !buf2) return 0; - sprintf (buf, "%s", buf1); - sprintf (sbuf, "%s", buf2); + + strcpy (buf, buf1); + strcpy (sbuf, buf2); + tbuf = strtok (buf, sbuf); while (tbuf) { @@ -601,6 +603,7 @@ while (tbuf && i > 0) { strcat (rbuf, tbuf); + i--; if (i == 1 && maxi > 1) strcat (rbuf, " and "); @@ -608,9 +611,11 @@ strcat (rbuf, ", "); else strcat (rbuf, "."); + tbuf = strtok (NULL, sbuf); } - return (char *) rbuf; + + return rbuf; } /***************************************************************************** @@ -627,13 +632,9 @@ init_book_archive () { int nroftitle = 0; - char fname[MAX_BUF]; titlelist *bl = get_empty_booklist (); - sprintf (fname, "%s/bookarch", settings.localdir); - LOG (llevDebug, " Reading bookarch from %s...\n", fname); - - object_thawer thawer (fname); + object_thawer thawer (settings.localdir, "bookarch"); if (!thawer) { @@ -690,7 +691,6 @@ LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); - LOG (llevDebug, " done.\n"); } /* init_mon_info() - creates the linked list of pointers to @@ -792,8 +792,7 @@ static void new_text_name (object *book, int msgtype) { - int nbr; - char name[MAX_BUF]; + const char *name; if (book->type != BOOK) return; @@ -801,36 +800,29 @@ switch (msgtype) { case 1: /*monster */ - nbr = sizeof (mon_book_name) / sizeof (char *); - assign (name, mon_book_name[rndm (nbr)]); + name = mon_book_name[rndm (array_length (mon_book_name))]; break; case 2: /*artifact */ - nbr = sizeof (art_book_name) / sizeof (char *); - assign (name, art_book_name[rndm (nbr)]); + name = art_book_name[rndm (array_length (art_book_name))]; break; case 3: /*spellpath */ - nbr = sizeof (path_book_name) / sizeof (char *); - assign (name, path_book_name[rndm (nbr)]); + name = path_book_name[rndm (array_length (path_book_name))]; break; case 4: /*alchemy */ - nbr = sizeof (formula_book_name) / sizeof (char *); - assign (name, formula_book_name[rndm (nbr)]); + name = formula_book_name[rndm (array_length (formula_book_name))]; break; case 5: /*gods */ - nbr = sizeof (gods_book_name) / sizeof (char *); - assign (name, gods_book_name[rndm (nbr)]); + name = gods_book_name[rndm (array_length (gods_book_name))]; break; case 6: /*msg file */ default: if (book->weight > 2000) { /* based on weight */ - nbr = sizeof (heavy_book_name) / sizeof (char *); - assign (name, heavy_book_name[rndm (nbr)]); + name = heavy_book_name[rndm (array_length (heavy_book_name))]; } else if (book->weight < 2001) { - nbr = sizeof (light_book_name) / sizeof (char *); - assign (name, light_book_name[rndm (nbr)]); + name = light_book_name[rndm (array_length (light_book_name))]; } break; } @@ -846,8 +838,7 @@ static void add_author (object *op, int msgtype) { - char title[MAX_BUF], name[MAX_BUF]; - int nbr = sizeof (book_author) / sizeof (char *); + const char *name; if (msgtype < 0 || strlen (op->msg) < 5) return; @@ -855,32 +846,26 @@ switch (msgtype) { case 1: /* monster */ - nbr = sizeof (mon_author) / sizeof (char *); - assign (name, mon_author[rndm (nbr)]); + name = mon_author[rndm (array_length (mon_author))]; break; case 2: /* artifacts */ - nbr = sizeof (art_author) / sizeof (char *); - assign (name, art_author[rndm (nbr)]); + name = art_author[rndm (array_length (art_author))]; break; case 3: /* spellpath */ - nbr = sizeof (path_author) / sizeof (char *); - assign (name, path_author[rndm (nbr)]); + name = path_author[rndm (array_length (path_author))]; break; case 4: /* alchemy */ - nbr = sizeof (formula_author) / sizeof (char *); - assign (name, formula_author[rndm (nbr)]); + name = formula_author[rndm (array_length (formula_author))]; break; case 5: /* gods */ - nbr = sizeof (gods_author) / sizeof (char *); - assign (name, gods_author[rndm (nbr)]); + name = gods_author[rndm (array_length (gods_author))]; break; case 6: /* msg file */ default: - assign (name, book_author[rndm (nbr)]); + name = book_author[rndm (array_length (book_author))]; } - sprintf (title, "of %s", name); - op->title = title; + op->title = format ("of %s", name); } /* unique_book() - check to see if the book title/msg is unique. We @@ -972,7 +957,7 @@ if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) { /* alter book properties */ - if (object *tmpbook = get_archetype (t->archname)) + if (object *tmpbook = archetype::get (t->archname)) { tmpbook->msg = book->msg; tmpbook->copy_to (book); @@ -1040,18 +1025,10 @@ book->title = old_title; if (rndm (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; - } + /* Lets give the book a description to individualize it some */ + book->name = format ("%s %s", book_descrpt[rndm (nbr)], old_name); else - { - book->name = old_name; - } + book->name = old_name; } else if (book->title && strlen (book->msg) > 5) { /* archive if long msg texts */ @@ -1251,7 +1228,7 @@ i = 0; do { - index = rndm (sizeof (art_name_array) / sizeof (arttypename)); + index = rndm (array_length (art_name_array)); type = art_name_array[index].type; al = find_artifactlist (type); i++; @@ -1360,8 +1337,6 @@ { static dynbuf_text buf; buf.clear (); - static char retbuf[BOOK_BUF]; - char tmpbuf[BOOK_BUF]; int path = rndm (NRSPELLPATHS), prayers = rndm (2); uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; archetype *at; @@ -1581,8 +1556,6 @@ if (enemy && !(god->path_denied & PATH_TURNING)) if ((i = nstrtok (enemy, ",")) > 0) { - char tmpbuf[MAX_BUF]; - buf << "The holy words of " << name << " have the power to slay creatures belonging to the "; @@ -1668,7 +1641,6 @@ 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");