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.38 by root, Sat Dec 27 02:31:19 2008 UTC

1084 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames); 1084 LOG (llevDebug, "Failed to obtain unique title for %s %s (names:%d/%d)\n", book->name, book->title, numb, maxnames);
1085#endif 1085#endif
1086 /* restore old book properties here */ 1086 /* restore old book properties here */
1087 book->title = old_title; 1087 book->title = old_title;
1088 1088
1089 if (RANDOM () % 4) 1089 if (rndm (4))
1090 { 1090 {
1091 /* Lets give the book a description to individualize it some */ 1091 /* Lets give the book a description to individualize it some */
1092 char new_name[MAX_BUF]; 1092 char new_name[MAX_BUF];
1093 1093
1094 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); 1094 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name);
1143 return (object *) NULL; 1143 return (object *) NULL;
1144 1144
1145 if (!level) 1145 if (!level)
1146 { 1146 {
1147 /* lets get a random monster from the mon_info linked list */ 1147 /* lets get a random monster from the mon_info linked list */
1148 monnr = RANDOM () % nrofmon; 1148 monnr = rndm (nrofmon);
1149 1149
1150 for (mon = first_mon_info, i = 0; mon; mon = mon->next) 1150 for (mon = first_mon_info, i = 0; mon; mon = mon->next)
1151 if (i++ == monnr) 1151 if (i++ == monnr)
1152 break; 1152 break;
1153 1153
1180 { 1180 {
1181 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);
1182 return NULL; 1182 return NULL;
1183 } 1183 }
1184 1184
1185 monnr = RANDOM () % i; 1185 monnr = rndm (i);
1186 for (mon = first_mon_info; mon; mon = mon->next) 1186 for (mon = first_mon_info; mon; mon = mon->next)
1187 if (mon->ob->level >= level && monnr-- == 0) 1187 if (mon->ob->level >= level && monnr-- == 0)
1188 return mon->ob; 1188 return mon->ob;
1189 1189
1190 if (!mon) 1190 if (!mon)
1294artifact_msg (int level, int booksize) 1294artifact_msg (int level, int booksize)
1295{ 1295{
1296 artifactlist *al = NULL; 1296 artifactlist *al = NULL;
1297 artifact *art; 1297 artifact *art;
1298 int chance, i, type, index; 1298 int chance, i, type, index;
1299 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;
1300 const char *ch; 1300 const char *ch;
1301 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF]; 1301 char name[MAX_BUF], buf[BOOK_BUF], sbuf[MAX_BUF];
1302 static char retbuf[BOOK_BUF]; 1302 static char retbuf[BOOK_BUF];
1303 object *tmp = NULL; 1303 object *tmp = NULL;
1304 1304
1312 * for that type exists! 1312 * for that type exists!
1313 */ 1313 */
1314 i = 0; 1314 i = 0;
1315 do 1315 do
1316 { 1316 {
1317 index = RANDOM () % (sizeof (art_name_array) / sizeof (arttypename)); 1317 index = rndm (sizeof (art_name_array) / sizeof (arttypename));
1318 type = art_name_array[index].type; 1318 type = art_name_array[index].type;
1319 al = find_artifactlist (type); 1319 al = find_artifactlist (type);
1320 i++; 1320 i++;
1321 } 1321 }
1322 while ((al == NULL) && (i < 10)); 1322 while ((al == NULL) && (i < 10));
1325 return "None"; 1325 return "None";
1326 1326
1327 /* 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
1328 * take our starting position randomly... */ 1328 * take our starting position randomly... */
1329 art = al->items; 1329 art = al->items;
1330 for (i = RANDOM () % level + RANDOM () % 2 + 1; i > 0; i--) 1330 for (i = rndm (level) + rndm (2) + 1; i > 0; i--)
1331 { 1331 {
1332 if (art == NULL) 1332 if (!art)
1333 art = al->items; /* hmm, out of stuff, loop back around */ 1333 art = al->items; /* hmm, out of stuff, loop back around */
1334
1334 art = art->next; 1335 art = art->next;
1335 } 1336 }
1336 1337
1337 /* the base 'generic' name for our artifact */ 1338 /* the base 'generic' name for our artifact */
1338 assign (name, art_name_array[index].name); 1339 assign (name, art_name_array[index].name);
1360 do 1361 do
1361 { 1362 {
1362 temp = next; 1363 temp = next;
1363 next = next->next; 1364 next = next->next;
1364 } 1365 }
1365 while (next && !RANDOM () % 2); 1366 while (next && rndm (2));
1366 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);
1367 } 1368 }
1368 else /* default name is used */ 1369 else /* default name is used */
1369 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);
1370 1371
1383 /* value of artifact */ 1384 /* value of artifact */
1384 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);
1385 1386
1386 /* include the message about the artifact, if exists, and book 1387 /* include the message about the artifact, if exists, and book
1387 * level is kinda high */ 1388 * level is kinda high */
1388 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))
1389 strcat (buf, art->item->msg); 1392 strcat (buf, art->item->msg);
1390 1393
1391 /* properties of the artifact */ 1394 /* properties of the artifact */
1392 tmp = object::create (); 1395 tmp = object::create ();
1393 add_abilities (tmp, art->item); 1396 add_abilities (tmp, art->item);
1425char * 1428char *
1426spellpath_msg (int level, int booksize) 1429spellpath_msg (int level, int booksize)
1427{ 1430{
1428 static char retbuf[BOOK_BUF]; 1431 static char retbuf[BOOK_BUF];
1429 char tmpbuf[BOOK_BUF]; 1432 char tmpbuf[BOOK_BUF];
1430 int path = RANDOM () % NRSPELLPATHS, prayers = RANDOM () % 2; 1433 int path = rndm (NRSPELLPATHS), prayers = rndm (2);
1431 int did_first_sp = 0; 1434 int did_first_sp = 0;
1432 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1435 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1433 archetype *at; 1436 archetype *at;
1434 1437
1435 /* Preamble */ 1438 /* Preamble */
1463 } 1466 }
1464 } 1467 }
1465 /* Geez, no spells were generated. */ 1468 /* Geez, no spells were generated. */
1466 if (!did_first_sp) 1469 if (!did_first_sp)
1467 { 1470 {
1468 if (RANDOM () % 4) /* usually, lets make a recursive call... */ 1471 if (rndm (4)) /* usually, lets make a recursive call... */
1469 spellpath_msg (level, booksize); 1472 spellpath_msg (level, booksize);
1470 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. */
1471 strcat (retbuf, "\n - no known spells exist -\n"); 1474 strcat (retbuf, "\n - no known spells exist -\n");
1472 } 1475 }
1473 else 1476 else
1489 int chance; 1492 int chance;
1490 1493
1491 /* the higher the book level, the more complex (ie number of 1494 /* the higher the book level, the more complex (ie number of
1492 * ingredients) the formula can be. 1495 * ingredients) the formula can be.
1493 */ 1496 */
1494 fl = get_formulalist (((RANDOM () % level) / 3) + 1); 1497 fl = get_formulalist (rndm (level) / 3 + 1);
1495 1498
1496 if (!fl) 1499 if (!fl)
1497 fl = get_formulalist (1); /* safety */ 1500 fl = get_formulalist (1); /* safety */
1498 1501
1499 if (fl->total_chance == 0) 1502 if (fl->total_chance == 0)
1503 add_author (book, 4); 1506 add_author (book, 4);
1504 return; 1507 return;
1505 } 1508 }
1506 1509
1507 /* get a random formula, weighted by its bookchance */ 1510 /* get a random formula, weighted by its bookchance */
1508 chance = RANDOM () % fl->total_chance; 1511 chance = rndm (fl->total_chance);
1509 for (formula = fl->items; formula != NULL; formula = formula->next) 1512 for (formula = fl->items; formula; formula = formula->next)
1510 { 1513 {
1511 chance -= formula->chance; 1514 chance -= formula->chance;
1512 if (chance <= 0) 1515 if (chance <= 0)
1513 break; 1516 break;
1514 } 1517 }
1524 { 1527 {
1525 /* looks like a formula was found. Base the amount 1528 /* looks like a formula was found. Base the amount
1526 * of information on the booklevel and the spellevel 1529 * of information on the booklevel and the spellevel
1527 * of the formula. */ 1530 * of the formula. */
1528 1531
1529 const char *op_name = formula->arch_name[RANDOM () % formula->arch_names]; 1532 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1530 archetype *at; 1533 archetype *at;
1531 1534
1532 /* preamble */ 1535 /* preamble */
1533 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");
1534 1537
1545 * while philo. sulfur may look better, without this, 1548 * while philo. sulfur may look better, without this,
1546 * you get things like 'the wise' because its missing the 1549 * you get things like 'the wise' because its missing the
1547 * water of section. 1550 * water of section.
1548 */ 1551 */
1549 sprintf (title, "%s: %s of %s", 1552 sprintf (title, "%s: %s of %s",
1550 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);
1551 } 1554 }
1552 else 1555 else
1553 { 1556 {
1554 sprintf (retbuf, "%sThe %s", retbuf, op_name); 1557 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1555 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);
1556 if (at->title) 1559 if (at->title)
1557 { 1560 {
1558 strcat (retbuf, " "); 1561 strcat (retbuf, " ");
1559 strcat (retbuf, at->title); 1562 strcat (retbuf, at->title);
1560 strcat (title, " "); 1563 strcat (title, " ");
1644 * this ... 1647 * this ...
1645 */ 1648 */
1646 while (level > 0) 1649 while (level > 0)
1647 { 1650 {
1648 sprintf (buf, " "); 1651 sprintf (buf, " ");
1649 if (level == 2 && RANDOM () % 2) 1652 if (level == 2 && rndm (2))
1650 { /* enemy god */ 1653 { /* enemy god */
1651 const char *enemy = god->title; 1654 const char *enemy = god->title;
1652 1655
1653 if (enemy) 1656 if (enemy)
1654 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);
1655 } 1658 }
1656 1659
1657 if (level == 3 && RANDOM () % 2) 1660 if (level == 3 && rndm (2))
1658 { /* enemy race, what the god's holy word effects */ 1661 { /* enemy race, what the god's holy word effects */
1659 const char *enemy = god->slaying; 1662 const char *enemy = god->slaying;
1660 1663
1661 if (enemy && !(god->path_denied & PATH_TURNING)) 1664 if (enemy && !(god->path_denied & PATH_TURNING))
1662 if ((i = nstrtok (enemy, ",")) > 0) 1665 if ((i = nstrtok (enemy, ",")) > 0)
1671 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1674 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ","));
1672 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1675 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1673 } 1676 }
1674 } 1677 }
1675 1678
1676 if (level == 4 && RANDOM () % 2) 1679 if (level == 4 && rndm (2))
1677 { /* Priest of god gets these protect,vulnerable... */ 1680 { /* Priest of god gets these protect,vulnerable... */
1678 char tmpbuf[MAX_BUF]; 1681 char tmpbuf[MAX_BUF];
1679 1682
1680 if (const char *cp = describe_resistance (god, 1)) 1683 if (const char *cp = describe_resistance (god, 1))
1681 { /* This god does have protections */ 1684 { /* This god does have protections */
1687 } 1690 }
1688 else 1691 else
1689 sprintf (buf, " "); 1692 sprintf (buf, " ");
1690 } 1693 }
1691 1694
1692 if (level == 5 && RANDOM () % 2) 1695 if (level == 5 && rndm (2))
1693 { /* aligned race, summoning */ 1696 { /* aligned race, summoning */
1694 const char *race = god->race; /* aligned race */ 1697 const char *race = god->race; /* aligned race */
1695 1698
1696 if (race && !(god->path_denied & PATH_SUMMON)) 1699 if (race && !(god->path_denied & PATH_SUMMON))
1697 if ((i = nstrtok (race, ",")) > 0) 1700 if ((i = nstrtok (race, ",")) > 0)
1705 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1708 sprintf (tmpbuf, "race of%s", strtoktolin (race, ","));
1706 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1709 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf);
1707 } 1710 }
1708 } 1711 }
1709 1712
1710 if (level == 6 && RANDOM () % 2) 1713 if (level == 6 && rndm (2))
1711 { /* blessing,curse properties of the god */ 1714 { /* blessing,curse properties of the god */
1712 char tmpbuf[MAX_BUF]; 1715 char tmpbuf[MAX_BUF];
1713 1716
1714 if (const char *cp = describe_resistance (god, 1)) 1717 if (const char *cp = describe_resistance (god, 1))
1715 { /* This god does have protections */ 1718 { /* This god does have protections */
1722 else 1725 else
1723 sprintf (buf, " "); 1726 sprintf (buf, " ");
1724 1727
1725 } 1728 }
1726 1729
1727 if (level == 8 && RANDOM () % 2) 1730 if (level == 8 && rndm (2))
1728 { /* immunity, holy possession */ 1731 { /* immunity, holy possession */
1729 int has_effect = 0, tmpvar; 1732 int has_effect = 0, tmpvar;
1730 char tmpbuf[MAX_BUF]; 1733 char tmpbuf[MAX_BUF];
1731 1734
1732 sprintf (tmpbuf, "\n"); 1735 sprintf (tmpbuf, "\n");
1750 } 1753 }
1751 else 1754 else
1752 sprintf (buf, " "); 1755 sprintf (buf, " ");
1753 } 1756 }
1754 1757
1755 if (level == 12 && RANDOM () % 2) 1758 if (level == 12 && rndm (2))
1756 { /* spell paths */ 1759 { /* spell paths */
1757 int has_effect = 0, tmpvar; 1760 int has_effect = 0, tmpvar;
1758 char tmpbuf[MAX_BUF]; 1761 char tmpbuf[MAX_BUF];
1759 1762
1760 sprintf (tmpbuf, "\n"); 1763 sprintf (tmpbuf, "\n");
1830 */ 1833 */
1831void 1834void
1832tailor_readable_ob (object *book, int msg_type) 1835tailor_readable_ob (object *book, int msg_type)
1833{ 1836{
1834 char msgbuf[BOOK_BUF]; 1837 char msgbuf[BOOK_BUF];
1835 int level = book->level ? (RANDOM () % book->level) + 1 : 1; 1838 int level = book->level ? rndm (book->level) + 1 : 1;
1836 int book_buf_size; 1839 int book_buf_size;
1837 1840
1838 /* safety */ 1841 /* safety */
1839 if (book->type != BOOK) 1842 if (book->type != BOOK)
1840 return; 1843 return;
1854 * 2) make sure there is an entry in max_titles[] array. 1857 * 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() 1858 * 3) make sure there are entries for your case in new_text_title()
1856 * and add_authour(). 1859 * and add_authour().
1857 * 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
1858 */ 1861 */
1859 msg_type = msg_type > 0 ? msg_type : (RANDOM () % 8); 1862 msg_type = msg_type > 0 ? msg_type : rndm (8);
1860 switch (msg_type) 1863 switch (msg_type)
1861 { 1864 {
1862 case 1: /* monster attrib */ 1865 case 1: /* monster attrib */
1863 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1866 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1864 break; 1867 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines