--- deliantra/server/common/readable.C 2009/10/15 23:02:28 1.46 +++ deliantra/server/common/readable.C 2009/10/15 23:24:38 1.47 @@ -1572,148 +1572,136 @@ static const char * god_info_msg (int level, int booksize) { - static char retbuf[BOOK_BUF]; const char *name = NULL; - char buf[BOOK_BUF]; - int i; - size_t introlen; object *god = pntr_to_god_obj (get_rand_god ()); + static dynbuf_text buf; buf.clear (); + if (!god) - return (char *) NULL; /* oops, problems... */ + return 0; /* oops, problems... */ + name = god->name; /* preamble.. */ - sprintf (retbuf, "This document contains knowledge concerning\n"); - sprintf (retbuf, "%sthe diety %s", retbuf, name); + buf << "This document contains knowledge concerning the diety B<< " + << name << " >>"; /* Always have as default information the god's descriptive terms. */ if (nstrtok (god->msg, ",") > 0) - { - strcat (retbuf, ", known as"); - strcat (retbuf, strtoktolin (god->msg, ",")); - } + buf << ", known as" << strtoktolin (god->msg, ","); else - strcat (retbuf, "..."); + buf << "..."; + + buf << "\n\n"; - strcat (retbuf, "\n ---\n"); - introlen = strlen (retbuf); /* so we will know if no new info is added later */ + int introlen = buf.size (); /* so we will know if no new info is added later */ /* Information about the god is random, and based on the level of the * 'book'. Probably there is a more intellegent way to implement * this ... */ - while (level > 0) + while (level > 0 && buf.size () < BOOK_BUF) { - sprintf (buf, " "); if (level == 2 && rndm (2)) { /* enemy god */ const char *enemy = god->title; if (enemy) - sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); + buf.printf ("The gods %s and %s are enemies.\r", name, enemy); } if (level == 3 && rndm (2)) { /* enemy race, what the god's holy word effects */ const char *enemy = god->slaying; + int i; if (enemy && !(god->path_denied & PATH_TURNING)) if ((i = nstrtok (enemy, ",")) > 0) { char tmpbuf[MAX_BUF]; - sprintf (buf, "The holy words of %s have the power to\n", name); - strcat (buf, "slay creatures belonging to the "); + buf << "The holy words of " << name + << " have the power to slay creatures belonging to the "; + if (i > 1) - sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ",")); + buf << "following races:" << strtoktolin (enemy, ","); else - sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); - sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); + buf << "race of" << strtoktolin (enemy, ","); + + buf << '\r'; } } if (level == 4 && rndm (2)) { /* Priest of god gets these protect,vulnerable... */ - char tmpbuf[MAX_BUF]; - if (const char *cp = describe_resistance (god, 1)) { /* This god does have protections */ - sprintf (tmpbuf, "%s has a potent aura which is extended\n", name); - strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); - strcat (tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); + buf << name + << " has a potent aura which is extended to" + " faithful priests. The effects of this aura include: " + << cp + << ".\r"; } - else - sprintf (buf, " "); } if (level == 5 && rndm (2)) { /* aligned race, summoning */ const char *race = god->race; /* aligned race */ + int i; if (race && !(god->path_denied & PATH_SUMMON)) if ((i = nstrtok (race, ",")) > 0) { - char tmpbuf[MAX_BUF]; - - sprintf (buf, "Creatures sacred to %s include the \n", name); + buf << "Creatures sacred to " << name << " include the "; if (i > 1) - sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ",")); + buf << "following races:" << strtoktolin (race, ","); else - sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); - sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); + buf << "race of" << strtoktolin (race, ","); + + buf << '\r'; } } if (level == 6 && rndm (2)) { /* blessing,curse properties of the god */ - char tmpbuf[MAX_BUF]; - if (const char *cp = describe_resistance (god, 1)) { /* This god does have protections */ - sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name); - strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); - strcat (tmpbuf, cp); - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); + buf << "The priests of " << name + << " are known to be able to " + "bestow a blessing which makes the recipient " + << cp + << '\r'; } - else - sprintf (buf, " "); - } if (level == 8 && rndm (2)) { /* immunity, holy possession */ - int has_effect = 0, tmpvar; - char tmpbuf[MAX_BUF]; - - sprintf (tmpbuf, "\n"); - sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n", name); + buf << "The priests of " << name + << " are known to make cast a mighty" + " prayer of possession"; + + int first = 1; - strcat (tmpbuf, "prayer of possession which gives the recipient\n"); + for (int i = 0; i < NROFATTACKS; i++) + if (god->resist[i] == 100) + { + if (first) + { + buf << " which gives the recipient"; + first = 0; + } + else + buf << ", "; - for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++) - { - if (god->resist[tmpvar] == 100) - { - has_effect = 1; - sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]); - } + buf << " immunity to " << attacktype_desc[i]; } - if (has_effect) - { - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } - else - sprintf (buf, " "); + buf << ".\r"; } if (level == 12 && rndm (2)) { /* spell paths */ + //TODO: int has_effect = 0, tmpvar; char tmpbuf[MAX_BUF]; @@ -1740,36 +1728,19 @@ } if (has_effect) - { - strcat (buf, tmpbuf); - strcat (buf, "\n ---\n"); - } + buf << tmpbuf << '\r'; else - sprintf (buf, " "); + buf << '\r'; } - /* check to be sure new buffer size dont exceed either - * the maximum buffer size, or the 'natural' size of the - * book... - */ - if (book_overflow (retbuf, buf, booksize)) - break; - else if (strlen (buf) > 1) - strcat (retbuf, buf); - level--; } - if (strlen (retbuf) == introlen) - { /* we got no information beyond the preamble! */ - strcat (retbuf, " [Unfortunately the rest of the information is\n"); - strcat (retbuf, " hopelessly garbled!]\n ---\n"); - } -#ifdef BOOK_MSG_DEBUG - LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf)); - LOG (llevDebug, " MADE THIS:\n%s", retbuf); -#endif - return retbuf; + if (buf.size () == introlen) + /* we got no information beyond the preamble! */ + buf << "[Unfortunately the rest of the information is hopelessly garbled!]"; + + return buf; } /* tailor_readable_ob()- The main routine. This chooses a random @@ -1817,7 +1788,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*0+4)//D + switch (msg_type) { case 1: /* monster attrib */ strcpy (msgbuf, mon_info_msg (level, book_buf_size)); @@ -1832,13 +1803,13 @@ make_formula_book (book, level); /* make_formula_book already gives title */ return; - break; case 5: /* bits of information about a god */ strcpy (msgbuf, god_info_msg (level, book_buf_size)); break; case 0: /* use info list in lib/ */ default: cfperl_make_book (book, level); + /* already gives title */ return; } @@ -1869,7 +1840,7 @@ LOG (llevDebug, "freeing all book information\n"); - for (tlist = booklist; tlist != NULL; tlist = tnext) + for (tlist = booklist; tlist; tlist = tnext) { tnext = tlist->next;