--- deliantra/server/common/readable.C 2009/10/15 21:40:42 1.44 +++ deliantra/server/common/readable.C 2009/10/15 22:50:41 1.45 @@ -1271,10 +1271,11 @@ int chance, i, type, index; int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; const char *ch; - char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; - static char retbuf[BOOK_BUF]; + char name[MAX_BUF]; object *tmp = NULL; + static dynbuf_text buf; buf.clear (); + /* values greater than 5 create msg buffers that are too big! */ if (book_entries > 5) book_entries = 5; @@ -1312,19 +1313,20 @@ assign (name, art_name_array[index].name); /* Ok, lets print out the contents */ - sprintf (retbuf, "Herein %s detailed %s...\n", book_entries > 1 ? "are" : "is", book_entries > 1 ? "some artifacts" : "an artifact"); + buf.printf ("Herein %s detailed %s...\n", + book_entries > 1 ? "are" : "is", + book_entries > 1 ? "some artifacts" : "an artifact"); /* artifact msg attributes loop. Lets keep adding entries to the 'book' * as long as we have space up to the allowed max # (book_entires) */ - while (book_entries > 0) + while (book_entries > 0 && buf.size () < BOOK_BUF) { - if (art == NULL) + if (!art) art = al->items; - /* separator of items */ - strcpy (buf, "--- \n"); + buf << '\n'; /* Name */ if (art->allowed && art->allowed->name != shstr_All) @@ -1337,56 +1339,49 @@ next = next->next; } while (next && rndm (2)); - sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); + + buf.printf ("A B<< %s of %s >>", &temp->name, &art->item->name); } else /* default name is used */ - sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); + buf.printf ("The B<< %s of %s >>", name, &art->item->name); + + buf << " is "; /* chance of finding */ chance = (int) (100 * ((float) art->chance / al->total_chance)); if (chance >= 20) - sprintf (sbuf, "an uncommon"); + buf << "an uncommon"; else if (chance >= 10) - sprintf (sbuf, "an unusual"); + buf << "an unusual"; else if (chance >= 5) - sprintf (sbuf, "a rare"); + buf << "a rare"; else - sprintf (sbuf, "a very rare"); - sprintf (buf, "%s is %s\n", buf, sbuf); + buf << "a very rare"; /* value of artifact */ - sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); + buf << " item with a value that is " << art->item->value << " times normal.\n"; /* include the message about the artifact, if exists, and book * level is kinda high */ if (art->item->msg - && rndm (4) + 1 < level - && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF)) - strcat (buf, art->item->msg); + && rndm (4) + 1 < level) + buf << art->item->msg; /* properties of the artifact */ 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); + if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) + buf << "\rProperties of this artifact include:\r" << ch << "\n"; + tmp->destroy (); - /* add the buf if it will fit */ - if (!book_overflow (retbuf, buf, booksize)) - strcat (retbuf, buf); - else - break; art = art->next; book_entries--; } -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "artifact_msg() created string: %d\n", strlen (retbuf)); - LOG (llevDebug, " MADE THIS:\n%s", retbuf); -#endif - return retbuf; + return buf; } /***************************************************************************** @@ -1400,61 +1395,45 @@ static char * spellpath_msg (int level, int booksize) { + static dynbuf_text buf; buf.clear (); + static char retbuf[BOOK_BUF]; char tmpbuf[BOOK_BUF]; int path = rndm (NRSPELLPATHS), prayers = rndm (2); - int did_first_sp = 0; uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; archetype *at; /* Preamble */ - sprintf (retbuf, "Herein are detailed the names of %s\n", prayers ? "prayers" : "incantations"); + buf << "Herein are detailed the names of " + << (prayers ? "prayers" : "incantations"); if (path == -1) - strcat (retbuf, "having no known spell path.\n"); + buf << " having no known spell path.\n"; else - sprintf (retbuf, "%sbelonging to the path of %s:\n", retbuf, spellpathnames[path]); + buf << " belonging to the path of B<< " << spellpathnames[path] << " >>:\n\n"; + + int seen = 0; 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->type == SPELL && at->path_attuned & pnum && - ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) - { - assign (tmpbuf, at->object::name); + /* 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->type == SPELL && at->path_attuned & pnum && + ((at->stats.grace && prayers) || (at->stats.sp && !prayers)) && (at->level < (level * 8))) + { + seen = 1; + buf << at->object::name << '\r'; + } - if (book_overflow (retbuf, tmpbuf, booksize)) - break; - else - { - if (did_first_sp) - strcat (retbuf, ",\n"); - did_first_sp = 1; - strcat (retbuf, tmpbuf); - } - } - } /* Geez, no spells were generated. */ - if (!did_first_sp) - { - if (rndm (4)) /* usually, lets make a recursive call... */ - spellpath_msg (level, booksize); - else /* give up, cause knowing no spells exist for path is info too. */ - strcat (retbuf, "\n - no known spells exist -\n"); - } - else - { - strcat (retbuf, "\n"); - } + if (!seen) + if (rndm (4)) /* usually, lets make a recursive call... */ + return spellpath_msg (level, booksize); + else /* give up, cause knowing no spells exist for path is info too. */ + buf << "- no known spells exist.\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; + return buf; } /* formula_msg() - generate a message detailing the properties @@ -1838,7 +1817,7 @@ * 4) you may want separate authour/book name arrays in read.h */ msg_type = msg_type > 0 ? msg_type : rndm (8); - switch (msg_type) + switch (msg_type*0+2)//D { case 1: /* monster attrib */ strcpy (msgbuf, mon_info_msg (level, book_buf_size));