--- deliantra/server/common/readable.C 2008/08/31 05:47:14 1.35
+++ deliantra/server/common/readable.C 2009/10/15 16:00:37 1.42
@@ -5,18 +5,19 @@
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992,2007 Frank Tore Johansen
*
- * 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.
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by the
+ * Free Software Foundation, either version 3 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, see .
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
*
* The authors can be reached via e-mail to
*/
@@ -819,7 +820,7 @@
#ifdef ARCHIVE_DEBUG
if (t)
- LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, t->name, t->authour, t->msg_index);
+ LOG (llevDebug, "Found title match (list %d): %s %s (%d)\n", msgtype, &t->name, &t->authour, t->msg_index);
#endif
return t;
@@ -934,19 +935,16 @@
static int
unique_book (const object *book, int msgtype)
{
- title *test;
-
if (!booklist)
return 1; /* No archival entries! Must be unique! */
/* Go through the booklist. If the author and name match, not unique so
* return 0.
*/
- for (test = get_titlelist (msgtype)->first_book; test; test = test->next)
- {
- if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour))
- return 0;
- }
+ for (title *test = get_titlelist (msgtype)->first_book; test; test = test->next)
+ if (test->name == book->name && book->title == test->authour)
+ return 0;
+
return 1;
}
@@ -980,7 +978,7 @@
need_to_write_bookarchive = 1;
#ifdef ARCHIVE_DEBUG
- LOG (llevDebug, "Archiving new title: %s %s (%d)\n", book->name, book->title, msgtype);
+ LOG (llevDebug, "Archiving new title: %s %s (%d)\n", &book->name, &book->title, msgtype);
#endif
}
@@ -1056,7 +1054,6 @@
#ifdef ARCHIVE_DEBUG
LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames);
#endif
- break;
}
/* shouldnt change map-maker books */
else if (!book->title)
@@ -1081,12 +1078,12 @@
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;
- if (RANDOM () % 4)
+ if (rndm (4))
{
/* Lets give the book a description to individualize it some */
char new_name[MAX_BUF];
@@ -1145,7 +1142,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)
@@ -1182,7 +1179,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;
@@ -1275,8 +1272,8 @@
}
#ifdef BOOK_MSG_DEBUG
- LOG (llevDebug, "\n mon_info_msg() created strng: %d\n", strlen (retbuf));
- fprintf (logfile, " MADE THIS:\n%s\n", retbuf);
+ LOG (llevDebug, "\n mon_info_msg() created string: %d\n", strlen (retbuf));
+ LOG (llevDebug, " MADE THIS:\n%s\n", retbuf);
#endif
return retbuf;
@@ -1296,7 +1293,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];
@@ -1314,7 +1311,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++;
@@ -1327,10 +1324,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;
}
@@ -1353,7 +1351,7 @@
strcpy (buf, "--- \n");
/* Name */
- if (art->allowed != NULL && strcmp (art->allowed->name, "All"))
+ if (art->allowed && art->allowed->name != shstr_All)
{
linked_char *temp, *next = art->allowed;
@@ -1362,7 +1360,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 */
@@ -1385,7 +1383,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 */
@@ -1407,8 +1407,8 @@
}
#ifdef BOOK_MSG_DEBUG
- LOG (llevDebug, "artifact_msg() created strng: %d\n", strlen (retbuf));
- fprintf (logfile, " MADE THIS:\n%s", retbuf);
+ LOG (llevDebug, "artifact_msg() created string: %d\n", strlen (retbuf));
+ LOG (llevDebug, " MADE THIS:\n%s", retbuf);
#endif
return retbuf;
}
@@ -1427,7 +1427,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;
@@ -1465,7 +1465,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");
@@ -1474,6 +1474,11 @@
{
strcat (retbuf, "\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;
}
@@ -1491,7 +1496,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 */
@@ -1505,8 +1510,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)
@@ -1526,7 +1531,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 */
@@ -1538,7 +1543,7 @@
LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
/* item name */
- if (strcmp (formula->title, "NONE"))
+ if (formula->title != shstr_NONE)
{
sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
/* This results in things like pile of philo. sulfur.
@@ -1547,12 +1552,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, " ");
@@ -1561,6 +1566,7 @@
strcat (title, at->title);
}
}
+
/* Lets name the book something meaningful ! */
book->name = title;
book->title = NULL;
@@ -1646,7 +1652,7 @@
while (level > 0)
{
sprintf (buf, " ");
- if (level == 2 && RANDOM () % 2)
+ if (level == 2 && rndm (2))
{ /* enemy god */
const char *enemy = god->title;
@@ -1654,7 +1660,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;
@@ -1673,7 +1679,7 @@
}
}
- if (level == 4 && RANDOM () % 2)
+ if (level == 4 && rndm (2))
{ /* Priest of god gets these protect,vulnerable... */
char tmpbuf[MAX_BUF];
@@ -1689,7 +1695,7 @@
sprintf (buf, " ");
}
- if (level == 5 && RANDOM () % 2)
+ if (level == 5 && rndm (2))
{ /* aligned race, summoning */
const char *race = god->race; /* aligned race */
@@ -1707,7 +1713,7 @@
}
}
- if (level == 6 && RANDOM () % 2)
+ if (level == 6 && rndm (2))
{ /* blessing,curse properties of the god */
char tmpbuf[MAX_BUF];
@@ -1724,7 +1730,7 @@
}
- if (level == 8 && RANDOM () % 2)
+ if (level == 8 && rndm (2))
{ /* immunity, holy possession */
int has_effect = 0, tmpvar;
char tmpbuf[MAX_BUF];
@@ -1752,7 +1758,7 @@
sprintf (buf, " ");
}
- if (level == 12 && RANDOM () % 2)
+ if (level == 12 && rndm (2))
{ /* spell paths */
int has_effect = 0, tmpvar;
char tmpbuf[MAX_BUF];
@@ -1806,8 +1812,8 @@
strcat (retbuf, " hopelessly garbled!]\n ---\n");
}
#ifdef BOOK_MSG_DEBUG
- LOG (llevDebug, "\n god_info_msg() created strng: %d\n", strlen (retbuf));
- fprintf (logfile, " MADE THIS:\n%s", retbuf);
+ LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf));
+ LOG (llevDebug, " MADE THIS:\n%s", retbuf);
#endif
return retbuf;
}
@@ -1832,7 +1838,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 */
@@ -1856,7 +1862,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 */