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.37 by root, Mon Sep 29 10:32:50 2008 UTC vs.
Revision 1.41 by root, Mon Oct 12 14:00:57 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License 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 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/* This file contains code relevant to the BOOKS hack -- designed 25/* This file contains code relevant to the BOOKS hack -- designed
932 */ 933 */
933 934
934static int 935static int
935unique_book (const object *book, int msgtype) 936unique_book (const object *book, int msgtype)
936{ 937{
937 title *test;
938
939 if (!booklist) 938 if (!booklist)
940 return 1; /* No archival entries! Must be unique! */ 939 return 1; /* No archival entries! Must be unique! */
941 940
942 /* Go through the booklist. If the author and name match, not unique so 941 /* Go through the booklist. If the author and name match, not unique so
943 * return 0. 942 * return 0.
944 */ 943 */
945 for (test = get_titlelist (msgtype)->first_book; test; test = test->next) 944 for (title *test = get_titlelist (msgtype)->first_book; test; test = test->next)
946 {
947 if (!strcmp (test->name, book->name) && !strcmp (book->title, test->authour)) 945 if (test->name == book->name && book->title == test->authour)
948 return 0; 946 return 0;
949 } 947
950 return 1; 948 return 1;
951} 949}
952 950
953/* add_book_to_list() */ 951/* add_book_to_list() */
954 952
1084 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); 1082 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames);
1085#endif 1083#endif
1086 /* restore old book properties here */ 1084 /* restore old book properties here */
1087 book->title = old_title; 1085 book->title = old_title;
1088 1086
1089 if (RANDOM () % 4) 1087 if (rndm (4))
1090 { 1088 {
1091 /* Lets give the book a description to individualize it some */ 1089 /* Lets give the book a description to individualize it some */
1092 char new_name[MAX_BUF]; 1090 char new_name[MAX_BUF];
1093 1091
1094 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); 1092 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name);
1143 return (object *) NULL; 1141 return (object *) NULL;
1144 1142
1145 if (!level) 1143 if (!level)
1146 { 1144 {
1147 /* lets get a random monster from the mon_info linked list */ 1145 /* lets get a random monster from the mon_info linked list */
1148 monnr = RANDOM () % nrofmon; 1146 monnr = rndm (nrofmon);
1149 1147
1150 for (mon = first_mon_info, i = 0; mon; mon = mon->next) 1148 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1151 if (i++ == monnr) 1149 if (i++ == monnr)
1152 break; 1150 break;
1153 1151
1180 { 1178 {
1181 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level); 1179 LOG (llevError, "get_random_mon() couldn't return monster for level %d\n", level);
1182 return NULL; 1180 return NULL;
1183 } 1181 }
1184 1182
1185 monnr = RANDOM () % i; 1183 monnr = rndm (i);
1186 for (mon = first_mon_info; mon; mon = mon->next) 1184 for (mon = first_mon_info; mon; mon = mon->next)
1187 if (mon->ob->level >= level && monnr-- == 0) 1185 if (mon->ob->level >= level && monnr-- == 0)
1188 return mon->ob; 1186 return mon->ob;
1189 1187
1190 if (!mon) 1188 if (!mon)
1294artifact_msg (int level, int booksize) 1292artifact_msg (int level, int booksize)
1295{ 1293{
1296 artifactlist *al = NULL; 1294 artifactlist *al = NULL;
1297 artifact *art; 1295 artifact *art;
1298 int chance, i, type, index; 1296 int chance, i, type, index;
1299 int book_entries = level > 5 ? RANDOM () % 3 + RANDOM () % 3 + 2 : RANDOM () % level + 1; 1297 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1300 const char *ch; 1298 const char *ch;
1301 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; 1299 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF];
1302 static char retbuf[BOOK_BUF]; 1300 static char retbuf[BOOK_BUF];
1303 object *tmp = NULL; 1301 object *tmp = NULL;
1304 1302
1312 * for that type exists! 1310 * for that type exists!
1313 */ 1311 */
1314 i = 0; 1312 i = 0;
1315 do 1313 do
1316 { 1314 {
1317 index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); 1315 index = rndm (sizeof (art_name_array) / sizeof (arttypename));
1318 type = art_name_array[index].type; 1316 type = art_name_array[index].type;
1319 al = find_artifactlist (type); 1317 al = find_artifactlist (type);
1320 i++; 1318 i++;
1321 } 1319 }
1322 while ((al == NULL) && (i < 10)); 1320 while ((al == NULL) && (i < 10));
1325 return "None"; 1323 return "None";
1326 1324
1327 /* There is no reason to start on the artifact list at the begining. Lets 1325 /* There is no reason to start on the artifact list at the begining. Lets
1328 * take our starting position randomly... */ 1326 * take our starting position randomly... */
1329 art = al->items; 1327 art = al->items;
1330 for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) 1328 for (i = rndm (level) + rndm (2) + 1; i > 0; i--)
1331 { 1329 {
1332 if (art == NULL) 1330 if (!art)
1333 art = al->items; /* hmm, out of stuff, loop back around */ 1331 art = al->items; /* hmm, out of stuff, loop back around */
1332
1334 art = art->next; 1333 art = art->next;
1335 } 1334 }
1336 1335
1337 /* the base 'generic' name for our artifact */ 1336 /* the base 'generic' name for our artifact */
1338 assign (name, art_name_array[index].name); 1337 assign (name, art_name_array[index].name);
1351 1350
1352 /* separator of items */ 1351 /* separator of items */
1353 strcpy (buf, "--- \n"); 1352 strcpy (buf, "--- \n");
1354 1353
1355 /* Name */ 1354 /* Name */
1356 if (art->allowed != NULL && strcmp (art->allowed->name, "All")) 1355 if (art->allowed && art->allowed->name != shstr_All)
1357 { 1356 {
1358 linked_char *temp, *next = art->allowed; 1357 linked_char *temp, *next = art->allowed;
1359 1358
1360 do 1359 do
1361 { 1360 {
1362 temp = next; 1361 temp = next;
1363 next = next->next; 1362 next = next->next;
1364 } 1363 }
1365 while (next && !RANDOM () % 2); 1364 while (next && rndm (2));
1366 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name); 1365 sprintf (buf, "%s A %s of %s", buf, &temp->name, &art->item->name);
1367 } 1366 }
1368 else /* default name is used */ 1367 else /* default name is used */
1369 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name); 1368 sprintf (buf, "%s The %s of %s", buf, name, &art->item->name);
1370 1369
1383 /* value of artifact */ 1382 /* value of artifact */
1384 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value); 1383 sprintf (buf, "%s item with a value that is %d times normal.\n", buf, art->item->value);
1385 1384
1386 /* include the message about the artifact, if exists, and book 1385 /* include the message about the artifact, if exists, and book
1387 * level is kinda high */ 1386 * level is kinda high */
1388 if (art->item->msg && (RANDOM () % 4 + 1) < level && !((strlen (art->item->msg) + strlen (buf)) > BOOK_BUF)) 1387 if (art->item->msg
1388 && rndm (4) + 1 < level
1389 && !(strlen (art->item->msg) + strlen (buf) > BOOK_BUF))
1389 strcat (buf, art->item->msg); 1390 strcat (buf, art->item->msg);
1390 1391
1391 /* properties of the artifact */ 1392 /* properties of the artifact */
1392 tmp = object::create (); 1393 tmp = object::create ();
1393 add_abilities (tmp, art->item); 1394 add_abilities (tmp, art->item);
1425char * 1426char *
1426spellpath_msg (int level, int booksize) 1427spellpath_msg (int level, int booksize)
1427{ 1428{
1428 static char retbuf[BOOK_BUF]; 1429 static char retbuf[BOOK_BUF];
1429 char tmpbuf[BOOK_BUF]; 1430 char tmpbuf[BOOK_BUF];
1430 int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; 1431 int path = rndm (NRSPELLPATHS), prayers = rndm (2);
1431 int did_first_sp = 0; 1432 int did_first_sp = 0;
1432 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1433 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1433 archetype *at; 1434 archetype *at;
1434 1435
1435 /* Preamble */ 1436 /* Preamble */
1463 } 1464 }
1464 } 1465 }
1465 /* Geez, no spells were generated. */ 1466 /* Geez, no spells were generated. */
1466 if (!did_first_sp) 1467 if (!did_first_sp)
1467 { 1468 {
1468 if (RANDOM () % 4) /* usually, lets make a recursive call... */ 1469 if (rndm (4)) /* usually, lets make a recursive call... */
1469 spellpath_msg (level, booksize); 1470 spellpath_msg (level, booksize);
1470 else /* give up, cause knowing no spells exist for path is info too. */ 1471 else /* give up, cause knowing no spells exist for path is info too. */
1471 strcat (retbuf, "\n - no known spells exist -\n"); 1472 strcat (retbuf, "\n - no known spells exist -\n");
1472 } 1473 }
1473 else 1474 else
1489 int chance; 1490 int chance;
1490 1491
1491 /* the higher the book level, the more complex (ie number of 1492 /* the higher the book level, the more complex (ie number of
1492 * ingredients) the formula can be. 1493 * ingredients) the formula can be.
1493 */ 1494 */
1494 fl = get_formulalist (((RANDOM () % level) / 3) + 1); 1495 fl = get_formulalist (rndm (level) / 3 + 1);
1495 1496
1496 if (!fl) 1497 if (!fl)
1497 fl = get_formulalist (1); /* safety */ 1498 fl = get_formulalist (1); /* safety */
1498 1499
1499 if (fl->total_chance == 0) 1500 if (fl->total_chance == 0)
1503 add_author (book, 4); 1504 add_author (book, 4);
1504 return; 1505 return;
1505 } 1506 }
1506 1507
1507 /* get a random formula, weighted by its bookchance */ 1508 /* get a random formula, weighted by its bookchance */
1508 chance = RANDOM () % fl->total_chance; 1509 chance = rndm (fl->total_chance);
1509 for (formula = fl->items; formula != NULL; formula = formula->next) 1510 for (formula = fl->items; formula; formula = formula->next)
1510 { 1511 {
1511 chance -= formula->chance; 1512 chance -= formula->chance;
1512 if (chance <= 0) 1513 if (chance <= 0)
1513 break; 1514 break;
1514 } 1515 }
1524 { 1525 {
1525 /* looks like a formula was found. Base the amount 1526 /* looks like a formula was found. Base the amount
1526 * of information on the booklevel and the spellevel 1527 * of information on the booklevel and the spellevel
1527 * of the formula. */ 1528 * of the formula. */
1528 1529
1529 const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; 1530 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1530 archetype *at; 1531 archetype *at;
1531 1532
1532 /* preamble */ 1533 /* preamble */
1533 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill"); 1534 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1534 1535
1536 op_name = at->object::name; 1537 op_name = at->object::name;
1537 else 1538 else
1538 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name); 1539 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1539 1540
1540 /* item name */ 1541 /* item name */
1541 if (strcmp (formula->title, "NONE")) 1542 if (formula->title != shstr_NONE)
1542 { 1543 {
1543 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title); 1544 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
1544 /* This results in things like pile of philo. sulfur. 1545 /* This results in things like pile of philo. sulfur.
1545 * while philo. sulfur may look better, without this, 1546 * while philo. sulfur may look better, without this,
1546 * you get things like 'the wise' because its missing the 1547 * you get things like 'the wise' because its missing the
1547 * water of section. 1548 * water of section.
1548 */ 1549 */
1549 sprintf (title, "%s: %s of %s", 1550 sprintf (title, "%s: %s of %s",
1550 formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title); 1551 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1551 } 1552 }
1552 else 1553 else
1553 { 1554 {
1554 sprintf (retbuf, "%sThe %s", retbuf, op_name); 1555 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1555 sprintf (title, "%s: %s", formula_book_name[RANDOM () % (sizeof (formula_book_name) / sizeof (char *))], op_name); 1556 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1556 if (at->title) 1557 if (at->title)
1557 { 1558 {
1558 strcat (retbuf, " "); 1559 strcat (retbuf, " ");
1559 strcat (retbuf, at->title); 1560 strcat (retbuf, at->title);
1560 strcat (title, " "); 1561 strcat (title, " ");
1561 strcat (title, at->title); 1562 strcat (title, at->title);
1562 } 1563 }
1563 } 1564 }
1565
1564 /* Lets name the book something meaningful ! */ 1566 /* Lets name the book something meaningful ! */
1565 book->name = title; 1567 book->name = title;
1566 book->title = NULL; 1568 book->title = NULL;
1567 1569
1568 /* ingredients to make it */ 1570 /* ingredients to make it */
1644 * this ... 1646 * this ...
1645 */ 1647 */
1646 while (level > 0) 1648 while (level > 0)
1647 { 1649 {
1648 sprintf (buf, " "); 1650 sprintf (buf, " ");
1649 if (level == 2 && RANDOM () % 2) 1651 if (level == 2 && rndm (2))
1650 { /* enemy god */ 1652 { /* enemy god */
1651 const char *enemy = god->title; 1653 const char *enemy = god->title;
1652 1654
1653 if (enemy) 1655 if (enemy)
1654 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); 1656 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy);
1655 } 1657 }
1656 1658
1657 if (level == 3 && RANDOM () % 2) 1659 if (level == 3 && rndm (2))
1658 { /* enemy race, what the god's holy word effects */ 1660 { /* enemy race, what the god's holy word effects */
1659 const char *enemy = god->slaying; 1661 const char *enemy = god->slaying;
1660 1662
1661 if (enemy && !(god->path_denied & PATH_TURNING)) 1663 if (enemy && !(god->path_denied & PATH_TURNING))
1662 if ((i = nstrtok (enemy, ",")) > 0) 1664 if ((i = nstrtok (enemy, ",")) > 0)
1671 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1673 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ","));
1672 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1674 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1673 } 1675 }
1674 } 1676 }
1675 1677
1676 if (level == 4 && RANDOM () % 2) 1678 if (level == 4 && rndm (2))
1677 { /* Priest of god gets these protect,vulnerable... */ 1679 { /* Priest of god gets these protect,vulnerable... */
1678 char tmpbuf[MAX_BUF]; 1680 char tmpbuf[MAX_BUF];
1679 1681
1680 if (const char *cp = describe_resistance (god, 1)) 1682 if (const char *cp = describe_resistance (god, 1))
1681 { /* This god does have protections */ 1683 { /* This god does have protections */
1687 } 1689 }
1688 else 1690 else
1689 sprintf (buf, " "); 1691 sprintf (buf, " ");
1690 } 1692 }
1691 1693
1692 if (level == 5 && RANDOM () % 2) 1694 if (level == 5 && rndm (2))
1693 { /* aligned race, summoning */ 1695 { /* aligned race, summoning */
1694 const char *race = god->race; /* aligned race */ 1696 const char *race = god->race; /* aligned race */
1695 1697
1696 if (race && !(god->path_denied & PATH_SUMMON)) 1698 if (race && !(god->path_denied & PATH_SUMMON))
1697 if ((i = nstrtok (race, ",")) > 0) 1699 if ((i = nstrtok (race, ",")) > 0)
1705 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1707 sprintf (tmpbuf, "race of%s", strtoktolin (race, ","));
1706 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1708 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1707 } 1709 }
1708 } 1710 }
1709 1711
1710 if (level == 6 && RANDOM () % 2) 1712 if (level == 6 && rndm (2))
1711 { /* blessing,curse properties of the god */ 1713 { /* blessing,curse properties of the god */
1712 char tmpbuf[MAX_BUF]; 1714 char tmpbuf[MAX_BUF];
1713 1715
1714 if (const char *cp = describe_resistance (god, 1)) 1716 if (const char *cp = describe_resistance (god, 1))
1715 { /* This god does have protections */ 1717 { /* This god does have protections */
1722 else 1724 else
1723 sprintf (buf, " "); 1725 sprintf (buf, " ");
1724 1726
1725 } 1727 }
1726 1728
1727 if (level == 8 && RANDOM () % 2) 1729 if (level == 8 && rndm (2))
1728 { /* immunity, holy possession */ 1730 { /* immunity, holy possession */
1729 int has_effect = 0, tmpvar; 1731 int has_effect = 0, tmpvar;
1730 char tmpbuf[MAX_BUF]; 1732 char tmpbuf[MAX_BUF];
1731 1733
1732 sprintf (tmpbuf, "\n"); 1734 sprintf (tmpbuf, "\n");
1750 } 1752 }
1751 else 1753 else
1752 sprintf (buf, " "); 1754 sprintf (buf, " ");
1753 } 1755 }
1754 1756
1755 if (level == 12 && RANDOM () % 2) 1757 if (level == 12 && rndm (2))
1756 { /* spell paths */ 1758 { /* spell paths */
1757 int has_effect = 0, tmpvar; 1759 int has_effect = 0, tmpvar;
1758 char tmpbuf[MAX_BUF]; 1760 char tmpbuf[MAX_BUF];
1759 1761
1760 sprintf (tmpbuf, "\n"); 1762 sprintf (tmpbuf, "\n");
1830 */ 1832 */
1831void 1833void
1832tailor_readable_ob (object *book, int msg_type) 1834tailor_readable_ob (object *book, int msg_type)
1833{ 1835{
1834 char msgbuf[BOOK_BUF]; 1836 char msgbuf[BOOK_BUF];
1835 int level = book->level ? (RANDOM () % book->level) + 1 : 1; 1837 int level = book->level ? rndm (book->level) + 1 : 1;
1836 int book_buf_size; 1838 int book_buf_size;
1837 1839
1838 /* safety */ 1840 /* safety */
1839 if (book->type != BOOK) 1841 if (book->type != BOOK)
1840 return; 1842 return;
1854 * 2) make sure there is an entry in max_titles[] array. 1856 * 2) make sure there is an entry in max_titles[] array.
1855 * 3) make sure there are entries for your case in new_text_title() 1857 * 3) make sure there are entries for your case in new_text_title()
1856 * and add_authour(). 1858 * and add_authour().
1857 * 4) you may want separate authour/book name arrays in read.h 1859 * 4) you may want separate authour/book name arrays in read.h
1858 */ 1860 */
1859 msg_type = msg_type > 0 ? msg_type : (RANDOM () % 8); 1861 msg_type = msg_type > 0 ? msg_type : rndm (8);
1860 switch (msg_type) 1862 switch (msg_type)
1861 { 1863 {
1862 case 1: /* monster attrib */ 1864 case 1: /* monster attrib */
1863 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1865 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1864 break; 1866 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines