--- deliantra/server/common/readable.C 2006/09/10 16:00:23 1.5 +++ deliantra/server/common/readable.C 2007/01/02 23:39:21 1.14 @@ -1,9 +1,3 @@ - -/* - * static char *rcsid_readable_c = - * "$Id: readable.C,v 1.5 2006/09/10 16:00:23 root Exp $"; - */ - /* CrossFire, A Multiplayer game for X-windows @@ -24,7 +18,7 @@ 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 + The authors can be reached via e-mail at */ @@ -82,7 +76,7 @@ */ /* '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 */ @@ -90,25 +84,22 @@ 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; + title *next; +}; -typedef struct titleliststruct:zero_initialised +struct titlelist : 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; + 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[] */ - -typedef struct namebytype +struct arttypename { const char *name; /* generic name to call artifacts of this type */ int type; /* matching type */ -} -arttypename; - +}; /* booklist is the buffer of books read in from the bookarch file */ static titlelist *booklist = NULL; @@ -567,6 +558,7 @@ { if (!tl->next) tl->next = get_empty_booklist (); + tl = tl->next; number--; } @@ -667,7 +659,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) { @@ -687,7 +679,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; @@ -712,7 +704,7 @@ } #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"); } @@ -735,6 +727,7 @@ if (did_init_barch) return; + did_init_barch = 1; if (!booklist) @@ -797,7 +790,7 @@ 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]); @@ -824,6 +817,7 @@ if (did_init_mon_info) return; + did_init_mon_info = 1; @@ -831,15 +825,15 @@ { 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); } @@ -858,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 (); @@ -893,6 +888,7 @@ if (tl) t = tl->first_book; + while (t) if (t->size == length && t->msg_index == index) break; @@ -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; @@ -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; } }