ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/readable.C
(Generate patch)

Comparing deliantra/server/common/readable.C (file contents):
Revision 1.28 by root, Sun Jun 24 04:09:28 2007 UTC vs.
Revision 1.38 by root, Sat Dec 27 02:31:19 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25/* This file contains code relevant to the BOOKS hack -- designed 24/* This file contains code relevant to the BOOKS hack -- designed
26 * to allow randomly occuring messages in non-magical texts. 25 * to allow randomly occuring messages in non-magical texts.
27 */ 26 */
435 * Be careful to keep the order. If you add readable subtype, add them 434 * Be careful to keep the order. If you add readable subtype, add them
436 * at the bottom of the list. Never delete a subtype because index is used as 435 * at the bottom of the list. Never delete a subtype because index is used as
437 * subtype paramater in arch files! 436 * subtype paramater in arch files!
438 */ 437 */
439static readable_message_type readable_message_types[] = { 438static readable_message_type readable_message_types[] = {
440 /*subtype 0 */ {0, 0, ""}, 439 /*subtype 0 */ {0, 0, "info"},
441 /* book messages subtypes */ 440 /* book messages subtypes */
442 /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1, "readable-book-clasp-1"}, 441 /*subtype 1 */ {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_1, "readable-book-clasp-1"},
443 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2, "readable-book-clasp-2"}, 442 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_CLASP_2, "readable-book-clasp-2"},
444 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1, "readable-book-elegant-1"}, 443 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_1, "readable-book-elegant-1"},
445 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2, "readable-book-elegant-2"}, 444 {MSG_TYPE_BOOK, MSG_TYPE_BOOK_ELEGANT_2, "readable-book-elegant-2"},
1002{ 1001{
1003 int nbr = sizeof (book_descrpt) / sizeof (char *); 1002 int nbr = sizeof (book_descrpt) / sizeof (char *);
1004 1003
1005 switch (book->type) 1004 switch (book->type)
1006 { 1005 {
1007 case BOOK: 1006 case BOOK:
1008 { 1007 {
1009 titlelist *tl = get_titlelist (msgtype); 1008 titlelist *tl = get_titlelist (msgtype);
1010 title *t = NULL; 1009 title *t = NULL;
1011 int tries = 0; 1010 int tries = 0;
1012 1011
1013 /* look to see if our msg already been archived. If so, alter 1012 /* look to see if our msg already been archived. If so, alter
1014 * the book to match the archival text. If we fail to match, 1013 * the book to match the archival text. If we fail to match,
1015 * then we archive the new title/name/msg combo if there is 1014 * then we archive the new title/name/msg combo if there is
1016 * room on the titlelist. 1015 * room on the titlelist.
1017 */ 1016 */
1018 1017
1019 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) 1018 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype)))
1020 { 1019 {
1021 object *tmpbook;
1022
1023 /* alter book properties */ 1020 /* alter book properties */
1024 if ((tmpbook = get_archetype (t->archname)) != NULL) 1021 if (object *tmpbook = get_archetype (t->archname))
1022 {
1023 tmpbook->msg = book->msg;
1024 tmpbook->copy_to (book);
1025 tmpbook->destroy ();
1026 }
1027
1028 book->title = t->authour;
1029 book->name = t->name;
1030 book->level = t->level;
1031 }
1032 /* Don't have any default title, so lets make up a new one */
1033 else
1034 {
1035 int numb, maxnames = max_titles[msgtype];
1036 const char *old_title;
1037 const char *old_name;
1038
1039 old_title = book->title;
1040 old_name = book->name;
1041
1042 /* some pre-generated books have title already set (from
1043 * maps), also don't bother looking for unique title if
1044 * we already used up all the available names! */
1045
1046 if (!tl)
1047 {
1048 LOG (llevError, "change_book_name(): can't find title list\n");
1049 numb = 0;
1050 }
1051 else
1052 numb = tl->number;
1053
1054 if (numb == maxnames)
1055 {
1056#ifdef ARCHIVE_DEBUG
1057 LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames);
1058#endif
1059 break;
1060 }
1061 /* shouldnt change map-maker books */
1062 else if (!book->title)
1063 do
1025 { 1064 {
1026 tmpbook->msg = book->msg; 1065 /* random book name */
1027 tmpbook->copy_to (book); 1066 new_text_name (book, msgtype);
1028 tmpbook->destroy (); 1067 add_author (book, msgtype); /* random author */
1068 tries++;
1029 } 1069 }
1070 while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK);
1030 1071
1031 book->title = t->authour; 1072 /* Now deal with 2 cases.
1032 book->name = t->name; 1073 * 1)If no space for a new title exists lets just restore
1033 book->level = t->level; 1074 * the old book properties. Remember, if the book had
1075 * matchd an older entry on the titlelist, we shouldnt
1076 * have called this routine in the first place!
1077 * 2) If we got a unique title, we need to add it to
1078 * the list.
1034 } 1079 */
1035 /* Don't have any default title, so lets make up a new one */
1036 else
1037 {
1038 int numb, maxnames = max_titles[msgtype];
1039 const char *old_title;
1040 const char *old_name;
1041 1080
1042 old_title = book->title; 1081 if (tries == MAX_TITLE_CHECK || numb == maxnames)
1043 old_name = book->name; 1082 { /* got to check maxnames again */
1044
1045 /* some pre-generated books have title already set (from
1046 * maps), also don't bother looking for unique title if
1047 * we already used up all the available names! */
1048
1049 if (!tl)
1050 {
1051 LOG (llevError, "change_book_name(): can't find title list\n");
1052 numb = 0;
1053 }
1054 else
1055 numb = tl->number;
1056
1057 if (numb == maxnames)
1058 {
1059#ifdef ARCHIVE_DEBUG 1083#ifdef ARCHIVE_DEBUG
1060 LOG (llevDebug, "titles for list %d full (%d possible).\n", msgtype, maxnames); 1084 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames);
1061#endif 1085#endif
1062 break; 1086 /* restore old book properties here */
1063 } 1087 book->title = old_title;
1064 /* shouldnt change map-maker books */ 1088
1065 else if (!book->title) 1089 if (rndm (4))
1066 do
1067 { 1090 {
1068 /* random book name */ 1091 /* Lets give the book a description to individualize it some */
1069 new_text_name (book, msgtype); 1092 char new_name[MAX_BUF];
1070 add_author (book, msgtype); /* random author */ 1093
1071 tries++; 1094 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name);
1095
1096 book->name = new_name;
1072 } 1097 }
1073 while (!unique_book (book, msgtype) && tries < MAX_TITLE_CHECK);
1074
1075 /* Now deal with 2 cases.
1076 * 1)If no space for a new title exists lets just restore
1077 * the old book properties. Remember, if the book had
1078 * matchd an older entry on the titlelist, we shouldnt
1079 * have called this routine in the first place!
1080 * 2) If we got a unique title, we need to add it to
1081 * the list.
1082 */
1083
1084 if (tries == MAX_TITLE_CHECK || numb == maxnames)
1085 { /* got to check maxnames again */
1086#ifdef ARCHIVE_DEBUG
1087 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames);
1088#endif
1089 /* restore old book properties here */
1090 book->title = old_title;
1091
1092 if (RANDOM () % 4)
1093 {
1094 /* Lets give the book a description to individualize it some */
1095 char new_name[MAX_BUF];
1096
1097 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name);
1098
1099 book->name = new_name;
1100 }
1101 else 1098 else
1102 { 1099 {
1103 book->name = old_name; 1100 book->name = old_name;
1104 } 1101 }
1105 } 1102 }
1106 else if (book->title && strlen (book->msg) > 5) 1103 else if (book->title && strlen (book->msg) > 5)
1107 { /* archive if long msg texts */ 1104 { /* archive if long msg texts */
1108 add_book_to_list (book, msgtype); 1105 add_book_to_list (book, msgtype);
1109 } 1106 }
1110 } 1107 }
1111 break; 1108 break;
1112 } 1109 }
1113 1110
1114 default: 1111 default:
1115 LOG (llevError, "change_book_name() called w/ illegal obj type.\n"); 1112 LOG (llevError, "change_book_name() called w/ illegal obj type.\n");
1116 return; 1113 return;
1117 } 1114 }
1118} 1115}
1119 1116
1120/***************************************************************************** 1117/*****************************************************************************
1121 * 1118 *
1146 return (object *) NULL; 1143 return (object *) NULL;
1147 1144
1148 if (!level) 1145 if (!level)
1149 { 1146 {
1150 /* lets get a random monster from the mon_info linked list */ 1147 /* lets get a random monster from the mon_info linked list */
1151 monnr = RANDOM () % nrofmon; 1148 monnr = rndm (nrofmon);
1152 1149
1153 for (mon = first_mon_info, i = 0; mon; mon = mon->next) 1150 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1154 if (i++ == monnr) 1151 if (i++ == monnr)
1155 break; 1152 break;
1156 1153
1183 { 1180 {
1184 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); 1181 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level);
1185 return NULL; 1182 return NULL;
1186 } 1183 }
1187 1184
1188 monnr = RANDOM () % i; 1185 monnr = rndm (i);
1189 for (mon = first_mon_info; mon; mon = mon->next) 1186 for (mon = first_mon_info; mon; mon = mon->next)
1190 if (mon->ob->level >= level && monnr-- == 0) 1187 if (mon->ob->level >= level && monnr-- == 0)
1191 return mon->ob; 1188 return mon->ob;
1192 1189
1193 if (!mon) 1190 if (!mon)
1297artifact_msg (int level, int booksize) 1294artifact_msg (int level, int booksize)
1298{ 1295{
1299 artifactlist *al = NULL; 1296 artifactlist *al = NULL;
1300 artifact *art; 1297 artifact *art;
1301 int chance, i, type, index; 1298 int chance, i, type, index;
1302 int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; 1299 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1303 const char *ch; 1300 const char *ch;
1304 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; 1301 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF];
1305 static char retbuf[BOOK_BUF]; 1302 static char retbuf[BOOK_BUF];
1306 object *tmp = NULL; 1303 object *tmp = NULL;
1307 1304
1315 * for that type exists! 1312 * for that type exists!
1316 */ 1313 */
1317 i = 0; 1314 i = 0;
1318 do 1315 do
1319 { 1316 {
1320 index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); 1317 index = rndm (sizeof (art_name_array) / sizeof (arttypename));
1321 type = art_name_array[index].type; 1318 type = art_name_array[index].type;
1322 al = find_artifactlist (type); 1319 al = find_artifactlist (type);
1323 i++; 1320 i++;
1324 } 1321 }
1325 while ((al == NULL) && (i < 10)); 1322 while ((al == NULL) && (i < 10));
1328 return "None"; 1325 return "None";
1329 1326
1330 /* There is no reason to start on the artifact list at the begining. Lets 1327 /* There is no reason to start on the artifact list at the begining. Lets
1331 * take our starting position randomly... */ 1328 * take our starting position randomly... */
1332 art = al->items; 1329 art = al->items;
1333 for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) 1330 for (i = rndm (level) + rndm (2) + 1; i > 0; i--)
1334 { 1331 {
1335 if (art == NULL) 1332 if (!art)
1336 art = al->items; /* hmm, out of stuff, loop back around */ 1333 art = al->items; /* hmm, out of stuff, loop back around */
1334
1337 art = art->next; 1335 art = art->next;
1338 } 1336 }
1339 1337
1340 /* the base 'generic' name for our artifact */ 1338 /* the base 'generic' name for our artifact */
1341 assign (name, art_name_array[index].name); 1339 assign (name, art_name_array[index].name);
1363 do 1361 do
1364 { 1362 {
1365 temp = next; 1363 temp = next;
1366 next = next->next; 1364 next = next->next;
1367 } 1365 }
1368 while (next && !RANDOM () % 2); 1366 while (next && rndm (2));
1369 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); 1367 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name);
1370 } 1368 }
1371 else /* default name is used */ 1369 else /* default name is used */
1372 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); 1370 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name);
1373 1371
1386 /* value of artifact */ 1384 /* value of artifact */
1387 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); 1385 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value);
1388 1386
1389 /* include the message about the artifact, if exists, and book 1387 /* include the message about the artifact, if exists, and book
1390 * level is kinda high */ 1388 * level is kinda high */
1391 if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) 1389 if (art->item->msg
1390 && rndm (4) + 1 < level
1391 && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF))
1392 strcat (buf, art->item->msg); 1392 strcat (buf, art->item->msg);
1393 1393
1394 /* properties of the artifact */ 1394 /* properties of the artifact */
1395 tmp = object::create (); 1395 tmp = object::create ();
1396 add_abilities (tmp, art->item); 1396 add_abilities (tmp, art->item);
1428char * 1428char *
1429spellpath_msg (int level, int booksize) 1429spellpath_msg (int level, int booksize)
1430{ 1430{
1431 static char retbuf[BOOK_BUF]; 1431 static char retbuf[BOOK_BUF];
1432 char tmpbuf[BOOK_BUF]; 1432 char tmpbuf[BOOK_BUF];
1433 int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; 1433 int path = rndm (NRSPELLPATHS), prayers = rndm (2);
1434 int did_first_sp = 0; 1434 int did_first_sp = 0;
1435 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1435 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1436 archetype *at; 1436 archetype *at;
1437 1437
1438 /* Preamble */ 1438 /* Preamble */
1466 } 1466 }
1467 } 1467 }
1468 /* Geez, no spells were generated. */ 1468 /* Geez, no spells were generated. */
1469 if (!did_first_sp) 1469 if (!did_first_sp)
1470 { 1470 {
1471 if (RANDOM () % 4) /* usually, lets make a recursive call... */ 1471 if (rndm (4)) /* usually, lets make a recursive call... */
1472 spellpath_msg (level, booksize); 1472 spellpath_msg (level, booksize);
1473 else /* give up, cause knowing no spells exist for path is info too. */ 1473 else /* give up, cause knowing no spells exist for path is info too. */
1474 strcat (retbuf, "\n - no known spells exist -\n"); 1474 strcat (retbuf, "\n - no known spells exist -\n");
1475 } 1475 }
1476 else 1476 else
1492 int chance; 1492 int chance;
1493 1493
1494 /* the higher the book level, the more complex (ie number of 1494 /* the higher the book level, the more complex (ie number of
1495 * ingredients) the formula can be. 1495 * ingredients) the formula can be.
1496 */ 1496 */
1497 fl = get_formulalist (((RANDOM () % level) / 3) + 1); 1497 fl = get_formulalist (rndm (level) / 3 + 1);
1498 1498
1499 if (!fl) 1499 if (!fl)
1500 fl = get_formulalist (1); /* safety */ 1500 fl = get_formulalist (1); /* safety */
1501 1501
1502 if (fl->total_chance == 0) 1502 if (fl->total_chance == 0)
1506 add_author (book, 4); 1506 add_author (book, 4);
1507 return; 1507 return;
1508 } 1508 }
1509 1509
1510 /* get a random formula, weighted by its bookchance */ 1510 /* get a random formula, weighted by its bookchance */
1511 chance = RANDOM () % fl->total_chance; 1511 chance = rndm (fl->total_chance);
1512 for (formula = fl->items; formula != NULL; formula = formula->next) 1512 for (formula = fl->items; formula; formula = formula->next)
1513 { 1513 {
1514 chance -= formula->chance; 1514 chance -= formula->chance;
1515 if (chance <= 0) 1515 if (chance <= 0)
1516 break; 1516 break;
1517 } 1517 }
1527 { 1527 {
1528 /* looks like a formula was found. Base the amount 1528 /* looks like a formula was found. Base the amount
1529 * of information on the booklevel and the spellevel 1529 * of information on the booklevel and the spellevel
1530 * of the formula. */ 1530 * of the formula. */
1531 1531
1532 const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; 1532 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1533 archetype *at; 1533 archetype *at;
1534 1534
1535 /* preamble */ 1535 /* preamble */
1536 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); 1536 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1537 1537
1548 * while philo. sulfur may look better, without this, 1548 * while philo. sulfur may look better, without this,
1549 * you get things like 'the wise' because its missing the 1549 * you get things like 'the wise' because its missing the
1550 * water of section. 1550 * water of section.
1551 */ 1551 */
1552 sprintf (title, "%s: %s of %s", 1552 sprintf (title, "%s: %s of %s",
1553 formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); 1553 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1554 } 1554 }
1555 else 1555 else
1556 { 1556 {
1557 sprintf (retbuf, "%sThe %s", retbuf, op_name); 1557 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1558 sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name); 1558 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1559 if (at->title) 1559 if (at->title)
1560 { 1560 {
1561 strcat (retbuf, " "); 1561 strcat (retbuf, " ");
1562 strcat (retbuf, at->title); 1562 strcat (retbuf, at->title);
1563 strcat (title, " "); 1563 strcat (title, " ");
1592 1592
1593 book->msg = retbuf; 1593 book->msg = retbuf;
1594 } 1594 }
1595} 1595}
1596 1596
1597#define DESCRIBE_PATH(retbuf, variable, name) \
1598 if(variable) { \
1599 int i,j=0; \
1600 strcat(retbuf,"(" name ": "); \
1601 for(i=0; i<NRSPELLPATHS; i++) \
1602 if(variable & (1<<i)) { \
1603 if (j) \
1604 strcat(retbuf,", "); \
1605 else \
1606 j = 1; \
1607 strcat(retbuf, spellpathnames[i]); \
1608 } \
1609 strcat(retbuf,")"); \
1610 }
1611
1597/* god_info_msg() - generate a message detailing the properties 1612/* god_info_msg() - generate a message detailing the properties
1598 * of a random god. Used by the book hack. b.t. 1613 * of a random god. Used by the book hack. b.t.
1599 */ 1614 */
1600const char * 1615const char *
1601god_info_msg (int level, int booksize) 1616god_info_msg (int level, int booksize)
1629 1644
1630 /* Information about the god is random, and based on the level of the 1645 /* Information about the god is random, and based on the level of the
1631 * 'book'. Probably there is a more intellegent way to implement 1646 * 'book'. Probably there is a more intellegent way to implement
1632 * this ... 1647 * this ...
1633 */ 1648 */
1634
1635 while (level > 0) 1649 while (level > 0)
1636 { 1650 {
1637 sprintf (buf, " "); 1651 sprintf (buf, " ");
1638 if (level == 2 && RANDOM () % 2) 1652 if (level == 2 && rndm (2))
1639 { /* enemy god */ 1653 { /* enemy god */
1640 const char *enemy = god->title; 1654 const char *enemy = god->title;
1641 1655
1642 if (enemy) 1656 if (enemy)
1643 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); 1657 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy);
1644 } 1658 }
1645 1659
1646 if (level == 3 && RANDOM () % 2) 1660 if (level == 3 && rndm (2))
1647 { /* enemy race, what the god's holy word effects */ 1661 { /* enemy race, what the god's holy word effects */
1648 const char *enemy = god->slaying; 1662 const char *enemy = god->slaying;
1649 1663
1650 if (enemy && !(god->path_denied & PATH_TURNING)) 1664 if (enemy && !(god->path_denied & PATH_TURNING))
1651 if ((i = nstrtok (enemy, ",")) > 0) 1665 if ((i = nstrtok (enemy, ",")) > 0)
1660 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1674 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ","));
1661 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1675 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1662 } 1676 }
1663 } 1677 }
1664 1678
1665 if (level == 4 && RANDOM () % 2) 1679 if (level == 4 && rndm (2))
1666 { /* Priest of god gets these protect,vulnerable... */ 1680 { /* Priest of god gets these protect,vulnerable... */
1667 char tmpbuf[MAX_BUF]; 1681 char tmpbuf[MAX_BUF];
1668 1682
1669 if (const char *cp = describe_resistance (god, 1)) 1683 if (const char *cp = describe_resistance (god, 1))
1670 { /* This god does have protections */ 1684 { /* This god does have protections */
1676 } 1690 }
1677 else 1691 else
1678 sprintf (buf, " "); 1692 sprintf (buf, " ");
1679 } 1693 }
1680 1694
1681 if (level == 5 && RANDOM () % 2) 1695 if (level == 5 && rndm (2))
1682 { /* aligned race, summoning */ 1696 { /* aligned race, summoning */
1683 const char *race = god->race; /* aligned race */ 1697 const char *race = god->race; /* aligned race */
1684 1698
1685 if (race && !(god->path_denied & PATH_SUMMON)) 1699 if (race && !(god->path_denied & PATH_SUMMON))
1686 if ((i = nstrtok (race, ",")) > 0) 1700 if ((i = nstrtok (race, ",")) > 0)
1694 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1708 sprintf (tmpbuf, "race of%s", strtoktolin (race, ","));
1695 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1709 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1696 } 1710 }
1697 } 1711 }
1698 1712
1699 if (level == 6 && RANDOM () % 2) 1713 if (level == 6 && rndm (2))
1700 { /* blessing,curse properties of the god */ 1714 { /* blessing,curse properties of the god */
1701 char tmpbuf[MAX_BUF]; 1715 char tmpbuf[MAX_BUF];
1702 1716
1703 if (const char *cp = describe_resistance (god, 1)) 1717 if (const char *cp = describe_resistance (god, 1))
1704 { /* This god does have protections */ 1718 { /* This god does have protections */
1711 else 1725 else
1712 sprintf (buf, " "); 1726 sprintf (buf, " ");
1713 1727
1714 } 1728 }
1715 1729
1716 if (level == 8 && RANDOM () % 2) 1730 if (level == 8 && rndm (2))
1717 { /* immunity, holy possession */ 1731 { /* immunity, holy possession */
1718 int has_effect = 0, tmpvar; 1732 int has_effect = 0, tmpvar;
1719 char tmpbuf[MAX_BUF]; 1733 char tmpbuf[MAX_BUF];
1720 1734
1721 sprintf (tmpbuf, "\n"); 1735 sprintf (tmpbuf, "\n");
1739 } 1753 }
1740 else 1754 else
1741 sprintf (buf, " "); 1755 sprintf (buf, " ");
1742 } 1756 }
1743 1757
1744 if (level == 12 && RANDOM () % 2) 1758 if (level == 12 && rndm (2))
1745 { /* spell paths */ 1759 { /* spell paths */
1746 int has_effect = 0, tmpvar; 1760 int has_effect = 0, tmpvar;
1747 char tmpbuf[MAX_BUF]; 1761 char tmpbuf[MAX_BUF];
1748 1762
1749 sprintf (tmpbuf, "\n"); 1763 sprintf (tmpbuf, "\n");
1819 */ 1833 */
1820void 1834void
1821tailor_readable_ob (object *book, int msg_type) 1835tailor_readable_ob (object *book, int msg_type)
1822{ 1836{
1823 char msgbuf[BOOK_BUF]; 1837 char msgbuf[BOOK_BUF];
1824 int level = book->level ? (RANDOM () % book->level) + 1 : 1; 1838 int level = book->level ? rndm (book->level) + 1 : 1;
1825 int book_buf_size; 1839 int book_buf_size;
1826 1840
1827 /* safety */ 1841 /* safety */
1828 if (book->type != BOOK) 1842 if (book->type != BOOK)
1829 return; 1843 return;
1843 * 2) make sure there is an entry in max_titles[] array. 1857 * 2) make sure there is an entry in max_titles[] array.
1844 * 3) make sure there are entries for your case in new_text_title() 1858 * 3) make sure there are entries for your case in new_text_title()
1845 * and add_authour(). 1859 * and add_authour().
1846 * 4) you may want separate authour/book name arrays in read.h 1860 * 4) you may want separate authour/book name arrays in read.h
1847 */ 1861 */
1848
1849 msg_type = msg_type > 0 ? msg_type : (RANDOM () % 6); 1862 msg_type = msg_type > 0 ? msg_type : rndm (8);
1850 switch (msg_type) 1863 switch (msg_type)
1851 { 1864 {
1852 case 1: /* monster attrib */ 1865 case 1: /* monster attrib */
1853 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1866 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1854 break; 1867 break;
1878 { 1891 {
1879 book->msg = msgbuf; 1892 book->msg = msgbuf;
1880 /* lets give the "book" a new name, which may be a compound word */ 1893 /* lets give the "book" a new name, which may be a compound word */
1881 change_book (book, msg_type); 1894 change_book (book, msg_type);
1882 } 1895 }
1883
1884} 1896}
1885 1897
1886 1898
1887/***************************************************************************** 1899/*****************************************************************************
1888 * 1900 *
1983get_readable_message_type (object *readable) 1995get_readable_message_type (object *readable)
1984{ 1996{
1985 uint8 subtype = readable->subtype; 1997 uint8 subtype = readable->subtype;
1986 1998
1987 if (subtype > last_readable_subtype) 1999 if (subtype > last_readable_subtype)
1988 return &(readable_message_types[0]); 2000 return &readable_message_types[0];
2001
1989 return &(readable_message_types[subtype]); 2002 return &readable_message_types[subtype];
1990} 2003}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines