--- deliantra/server/common/readable.C 2006/09/13 23:32:04 1.6 +++ deliantra/server/common/readable.C 2007/01/18 19:42:09 1.19 @@ -1,32 +1,27 @@ - /* - * static char *rcsid_readable_c = - * "$Id: readable.C,v 1.6 2006/09/13 23:32:04 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. @@ -118,7 +113,7 @@ 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; @@ -644,11 +639,11 @@ /***************************************************************************** * - * 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 */ @@ -665,7 +660,7 @@ did_init_msgfile = 1; sprintf (fname, "%s/messages", settings.datadir); - LOG (llevDebug, "Reading messages from %s...", fname); + LOG (llevDebug, "Reading messages from %s...\n", fname); if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) { @@ -685,7 +680,7 @@ if (strlen (msgbuf) > BOOK_BUF) { LOG (llevDebug, "Warning: this string exceeded max book buf size:"); - LOG (llevDebug, " %s", msgbuf); + LOG (llevDebug, " %s\n", msgbuf); } tmp->name = msgbuf; tmp->next = first_msg; @@ -710,13 +705,13 @@ } #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"); } -/* 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. */ @@ -796,17 +791,16 @@ bl->number++; } } - LOG (llevDebug, " book archives(used/avail): "); + 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)", bl->number, max_titles[i]); + LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); } - LOG (llevDebug, "\n"); 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"); } @@ -823,6 +817,7 @@ if (did_init_mon_info) return; + did_init_mon_info = 1; @@ -830,23 +825,23 @@ { 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)); + objectlink *mon = new 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); } -/* 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. */ @@ -857,9 +852,10 @@ if (did_this) return; + did_this = 1; - LOG (llevDebug, "Initializing reading data..."); + LOG (llevDebug, "Initialising reading data...\n"); init_msgfile (); init_book_archive (); init_mon_info (); @@ -927,35 +923,35 @@ { case 1: /*monster */ nbr = sizeof (mon_book_name) / sizeof (char *); - strcpy (name, mon_book_name[RANDOM () % nbr]); + strcpy (name, mon_book_name[rndm (nbr)]); break; case 2: /*artifact */ nbr = sizeof (art_book_name) / sizeof (char *); - strcpy (name, art_book_name[RANDOM () % nbr]); + strcpy (name, art_book_name[rndm (nbr)]); break; case 3: /*spellpath */ nbr = sizeof (path_book_name) / sizeof (char *); - strcpy (name, path_book_name[RANDOM () % nbr]); + strcpy (name, path_book_name[rndm (nbr)]); break; case 4: /*alchemy */ nbr = sizeof (formula_book_name) / sizeof (char *); - strcpy (name, formula_book_name[RANDOM () % nbr]); + strcpy (name, formula_book_name[rndm (nbr)]); break; case 5: /*gods */ nbr = sizeof (gods_book_name) / sizeof (char *); - strcpy (name, gods_book_name[RANDOM () % nbr]); + strcpy (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]); + strcpy (name, heavy_book_name[rndm (nbr)]); } else if (book->weight < 2001) { nbr = sizeof (light_book_name) / sizeof (char *); - strcpy (name, light_book_name[RANDOM () % nbr]); + strcpy (name, light_book_name[rndm (nbr)]); } break; } @@ -981,27 +977,27 @@ { case 1: /* monster */ nbr = sizeof (mon_author) / sizeof (char *); - strcpy (name, mon_author[RANDOM () % nbr]); + strcpy (name, mon_author[rndm (nbr)]); break; case 2: /* artifacts */ nbr = sizeof (art_author) / sizeof (char *); - strcpy (name, art_author[RANDOM () % nbr]); + strcpy (name, art_author[rndm (nbr)]); break; case 3: /* spellpath */ nbr = sizeof (path_author) / sizeof (char *); - strcpy (name, path_author[RANDOM () % nbr]); + strcpy (name, path_author[rndm (nbr)]); break; case 4: /* alchemy */ nbr = sizeof (formula_author) / sizeof (char *); - strcpy (name, formula_author[RANDOM () % nbr]); + strcpy (name, formula_author[rndm (nbr)]); break; case 5: /* gods */ nbr = sizeof (gods_author) / sizeof (char *); - strcpy (name, gods_author[RANDOM () % nbr]); + strcpy (name, gods_author[rndm (nbr)]); break; case 6: /* msg file */ default: - strcpy (name, book_author[RANDOM () % nbr]); + strcpy (name, book_author[rndm (nbr)]); } sprintf (title, "of %s", name); @@ -1105,8 +1101,8 @@ if ((tmpbook = get_archetype (t->archname)) != NULL) { tmpbook->msg = book->msg; - copy_object (tmpbook, book); - free_object (tmpbook); + tmpbook->copy_to (book); + tmpbook->destroy (); } book->title = t->authour; @@ -1175,7 +1171,7 @@ /* Lets give the book a description to individualize it some */ char new_name[MAX_BUF]; - snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[RANDOM () % nbr], old_name); + snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); book->name = new_name; } @@ -1473,13 +1469,13 @@ strcat (buf, art->item->msg); /* properties of the artifact */ - tmp = get_object (); + 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); - free_object (tmp); + tmp->destroy (); /* add the buf if it will fit */ if (!book_overflow (retbuf, buf, booksize)) strcat (retbuf, buf); @@ -1619,7 +1615,7 @@ /* 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) + 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); @@ -1658,7 +1654,7 @@ 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"); @@ -1986,6 +1982,7 @@ } strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ + if (strlen (msgbuf) > 1) { book->msg = msgbuf; @@ -2024,15 +2021,17 @@ 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); + delete monlink; } }