--- deliantra/server/common/readable.C 2007/07/10 06:07:32 1.32 +++ deliantra/server/common/readable.C 2008/12/27 02:31:19 1.38 @@ -1,11 +1,11 @@ /* - * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. + * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * - * Crossfire TRT is free software: you can redistribute it and/or modify + * Deliantra 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 3 of the License, or * (at your option) any later version. @@ -18,7 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * The authors can be reached via e-mail to + * The authors can be reached via e-mail to */ /* This file contains code relevant to the BOOKS hack -- designed @@ -1003,116 +1003,114 @@ switch (book->type) { - case BOOK: - { - titlelist *tl = get_titlelist (msgtype); - title *t = NULL; - int tries = 0; - - /* look to see if our msg already been archived. If so, alter - * the book to match the archival text. If we fail to match, - * then we archive the new title/name/msg combo if there is - * room on the titlelist. - */ - - if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) - { - object *tmpbook; + case BOOK: + { + titlelist *tl = get_titlelist (msgtype); + title *t = NULL; + int tries = 0; + + /* look to see if our msg already been archived. If so, alter + * the book to match the archival text. If we fail to match, + * then we archive the new title/name/msg combo if there is + * room on the titlelist. + */ - /* alter book properties */ - if ((tmpbook = get_archetype (t->archname)) != NULL) - { - tmpbook->msg = book->msg; - tmpbook->copy_to (book); - tmpbook->destroy (); - } + if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) + { + /* alter book properties */ + if (object *tmpbook = get_archetype (t->archname)) + { + tmpbook->msg = book->msg; + tmpbook->copy_to (book); + tmpbook->destroy (); + } - book->title = t->authour; - book->name = t->name; - book->level = t->level; - } - /* Don't have any default title, so lets make up a new one */ - else - { - int numb, maxnames = max_titles[msgtype]; - const char *old_title; - const char *old_name; - - old_title = book->title; - old_name = book->name; - - /* some pre-generated books have title already set (from - * maps), also don't bother looking for unique title if - * we already used up all the available names! */ + book->title = t->authour; + book->name = t->name; + book->level = t->level; + } + /* Don't have any default title, so lets make up a new one */ + else + { + int numb, maxnames = max_titles[msgtype]; + const char *old_title; + const char *old_name; + + old_title = book->title; + old_name = book->name; + + /* some pre-generated books have title already set (from + * maps), also don't bother looking for unique title if + * we already used up all the available names! */ - if (!tl) - { - LOG (llevError, "change_book_name(): can't find title list\n"); - numb = 0; - } - else - numb = tl->number; + if (!tl) + { + LOG (llevError, "change_book_name(): can't find title list\n"); + numb = 0; + } + else + numb = tl->number; - if (numb == maxnames) - { + if (numb == maxnames) + { #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); + LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); #endif - break; + break; + } + /* shouldnt change map-maker books */ + else if (!book->title) + do + { + /* random book name */ + new_text_name (book, msgtype); + add_author (book, msgtype); /* random author */ + tries++; } - /* shouldnt change map-maker books */ - else if (!book->title) - do - { - /* random book name */ - new_text_name (book, msgtype); - add_author (book, msgtype); /* random author */ - tries++; - } - while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); + while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK); - /* Now deal with 2 cases. - * 1)If no space for a new title exists lets just restore - * the old book properties. Remember, if the book had - * matchd an older entry on the titlelist, we shouldnt - * have called this routine in the first place! - * 2) If we got a unique title, we need to add it to - * the list. - */ + /* Now deal with 2 cases. + * 1)If no space for a new title exists lets just restore + * the old book properties. Remember, if the book had + * matchd an older entry on the titlelist, we shouldnt + * have called this routine in the first place! + * 2) If we got a unique title, we need to add it to + * the list. + */ - if (tries == MAX_TITLE_CHECK || numb == maxnames) - { /* got to check maxnames again */ + if (tries == MAX_TITLE_CHECK || numb == maxnames) + { /* got to check maxnames again */ #ifdef ARCHIVE_DEBUG - LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); + LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); #endif - /* restore old book properties here */ - book->title = old_title; + /* restore old book properties here */ + book->title = old_title; - if (RANDOM () % 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; - } - else - { - book->name = old_name; - } - } - else if (book->title && strlen (book->msg) > 5) - { /* archive if long msg texts */ - add_book_to_list (book, msgtype); - } - } - break; - } + 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); - default: - LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); - return; + book->name = new_name; + } + else + { + book->name = old_name; + } + } + else if (book->title && strlen (book->msg) > 5) + { /* archive if long msg texts */ + add_book_to_list (book, msgtype); + } + } + break; + } + + default: + LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); + return; } } @@ -1147,7 +1145,7 @@ if (!level) { /* lets get a random monster from the mon_info linked list */ - monnr = RANDOM () % nrofmon; + monnr = rndm (nrofmon); for (mon = first_mon_info, i = 0; mon; mon = mon->next) if (i++ == monnr) @@ -1184,7 +1182,7 @@ return NULL; } - monnr = RANDOM () % i; + monnr = rndm (i); for (mon = first_mon_info; mon; mon = mon->next) if (mon->ob->level >= level && monnr-- == 0) return mon->ob; @@ -1298,7 +1296,7 @@ artifactlist *al = NULL; artifact *art; int chance, i, type, index; - int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; + 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]; @@ -1316,7 +1314,7 @@ i = 0; do { - index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); + index = rndm (sizeof (art_name_array) / sizeof (arttypename)); type = art_name_array[index].type; al = find_artifactlist (type); i++; @@ -1329,10 +1327,11 @@ /* There is no reason to start on the artifact list at the begining. Lets * take our starting position randomly... */ art = al->items; - for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) + for (i = rndm (level) + rndm (2) + 1; i > 0; i--) { - if (art == NULL) + if (!art) art = al->items; /* hmm, out of stuff, loop back around */ + art = art->next; } @@ -1364,7 +1363,7 @@ temp = next; next = next->next; } - while (next && !RANDOM () % 2); + while (next && rndm (2)); sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); } else /* default name is used */ @@ -1387,7 +1386,9 @@ /* include the message about the artifact, if exists, and book * level is kinda high */ - if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) + if (art->item->msg + && rndm (4) + 1 < level + && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF)) strcat (buf, art->item->msg); /* properties of the artifact */ @@ -1429,7 +1430,7 @@ { static char retbuf[BOOK_BUF]; char tmpbuf[BOOK_BUF]; - int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; + int path = rndm (NRSPELLPATHS), prayers = rndm (2); int did_first_sp = 0; uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; archetype *at; @@ -1467,7 +1468,7 @@ /* Geez, no spells were generated. */ if (!did_first_sp) { - if (RANDOM () % 4) /* usually, lets make a recursive call... */ + 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"); @@ -1493,7 +1494,7 @@ /* the higher the book level, the more complex (ie number of * ingredients) the formula can be. */ - fl = get_formulalist (((RANDOM () % level) / 3) + 1); + fl = get_formulalist (rndm (level) / 3 + 1); if (!fl) fl = get_formulalist (1); /* safety */ @@ -1507,8 +1508,8 @@ } /* get a random formula, weighted by its bookchance */ - chance = RANDOM () % fl->total_chance; - for (formula = fl->items; formula != NULL; formula = formula->next) + chance = rndm (fl->total_chance); + for (formula = fl->items; formula; formula = formula->next) { chance -= formula->chance; if (chance <= 0) @@ -1528,7 +1529,7 @@ * of information on the booklevel and the spellevel * of the formula. */ - const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; + const char *op_name = formula->arch_name [rndm (formula->arch_names)]; archetype *at; /* preamble */ @@ -1549,12 +1550,12 @@ * water of section. */ sprintf (title, "%s: %s of %s", - formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); + formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); } else { sprintf (retbuf, "%sThe %s", retbuf, op_name); - sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name); + sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name); if (at->title) { strcat (retbuf, " "); @@ -1648,7 +1649,7 @@ while (level > 0) { sprintf (buf, " "); - if (level == 2 && RANDOM () % 2) + if (level == 2 && rndm (2)) { /* enemy god */ const char *enemy = god->title; @@ -1656,7 +1657,7 @@ sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); } - if (level == 3 && RANDOM () % 2) + if (level == 3 && rndm (2)) { /* enemy race, what the god's holy word effects */ const char *enemy = god->slaying; @@ -1675,7 +1676,7 @@ } } - if (level == 4 && RANDOM () % 2) + if (level == 4 && rndm (2)) { /* Priest of god gets these protect,vulnerable... */ char tmpbuf[MAX_BUF]; @@ -1691,7 +1692,7 @@ sprintf (buf, " "); } - if (level == 5 && RANDOM () % 2) + if (level == 5 && rndm (2)) { /* aligned race, summoning */ const char *race = god->race; /* aligned race */ @@ -1709,7 +1710,7 @@ } } - if (level == 6 && RANDOM () % 2) + if (level == 6 && rndm (2)) { /* blessing,curse properties of the god */ char tmpbuf[MAX_BUF]; @@ -1726,7 +1727,7 @@ } - if (level == 8 && RANDOM () % 2) + if (level == 8 && rndm (2)) { /* immunity, holy possession */ int has_effect = 0, tmpvar; char tmpbuf[MAX_BUF]; @@ -1754,7 +1755,7 @@ sprintf (buf, " "); } - if (level == 12 && RANDOM () % 2) + if (level == 12 && rndm (2)) { /* spell paths */ int has_effect = 0, tmpvar; char tmpbuf[MAX_BUF]; @@ -1834,7 +1835,7 @@ tailor_readable_ob (object *book, int msg_type) { char msgbuf[BOOK_BUF]; - int level = book->level ? (RANDOM () % book->level) + 1 : 1; + int level = book->level ? rndm (book->level) + 1 : 1; int book_buf_size; /* safety */ @@ -1858,7 +1859,7 @@ * and add_authour(). * 4) you may want separate authour/book name arrays in read.h */ - msg_type = msg_type > 0 ? msg_type : (RANDOM () % 8); + msg_type = msg_type > 0 ? msg_type : rndm (8); switch (msg_type) { case 1: /* monster attrib */ @@ -1892,7 +1893,6 @@ /* lets give the "book" a new name, which may be a compound word */ change_book (book, msg_type); } - }