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.35 by root, Sun Aug 31 05:47:14 2008 UTC vs.
Revision 1.40 by root, Thu Jan 1 11:41:17 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines