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.45 by root, Thu Oct 15 22:50:41 2009 UTC vs.
Revision 1.51 by root, Fri Nov 6 13:03:34 2009 UTC

497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, 497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"},
498 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"}, 498 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_1, "readable-monument-wall-1"},
499 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"}, 499 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_2, "readable-monument-wall-2"},
500 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"} 500 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"}
501}; 501};
502int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); 502static int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
503 503
504static int max_titles[6] = { 504static int max_titles[6] = {
505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)),
506 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)), 506 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
731} 731}
732 732
733/* init_mon_info() - creates the linked list of pointers to 733/* init_mon_info() - creates the linked list of pointers to
734 * monster archetype objects if not called previously 734 * monster archetype objects if not called previously
735 */ 735 */
736
737static void 736static void
738init_mon_info (void) 737init_mon_info ()
739{ 738{
740 archetype *at; 739 archetype *at;
741 static int did_init_mon_info = 0; 740 static int did_init_mon_info = 0;
742 741
743 if (did_init_mon_info) 742 if (did_init_mon_info)
744 return; 743 return;
745 744
746 did_init_mon_info = 1; 745 did_init_mon_info = 1;
747 746
748 for_all_archetypes (at) 747 for_all_archetypes (at)
749 { 748 if (at->flag [FLAG_MONSTER]
750 if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) 749 && at->is_head ()
750 && (!at->flag [FLAG_CHANGING] || at->flag [FLAG_UNAGGRESSIVE]))
751 { 751 {
752 objectlink *mon = new objectlink; 752 objectlink *mon = new objectlink;
753 753
754 mon->ob = at; 754 mon->ob = at;
755 mon->next = first_mon_info; 755 mon->next = first_mon_info;
756 first_mon_info = mon; 756 first_mon_info = mon;
757 nrofmon++; 757 nrofmon++;
758 } 758 }
759 }
760 759
761 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 760 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
762} 761}
763 762
764/* init_readable() - initialise linked lists utilized by 763/* init_readable() - initialise linked lists utilized by
1215 break; 1214 break;
1216 1215
1217 /* didn't find a match */ 1216 /* didn't find a match */
1218 if (!mon) 1217 if (!mon)
1219 return NULL; 1218 return NULL;
1219
1220 if (mon->next) 1220 if (mon->next)
1221 return mon->next->ob; 1221 return mon->next->ob;
1222 else 1222 else
1223 return first_mon_info->ob; 1223 return first_mon_info->ob;
1224 1224
1226 1226
1227/* mon_info_msg() - generate a message detailing the properties 1227/* mon_info_msg() - generate a message detailing the properties
1228 * of a randomly selected monster. 1228 * of a randomly selected monster.
1229 */ 1229 */
1230static const char * 1230static const char *
1231mon_info_msg (int level, int booksize) 1231mon_info_msg (int level)
1232{ 1232{
1233 static dynbuf_text buf; buf.clear (); 1233 static dynbuf_text buf; buf.clear ();
1234 1234
1235 /*preamble */ 1235 /*preamble */
1236 buf << "This beastiary contains:\n"; 1236 buf << "This beastiary contains:\n";
1262 1262
1263/* artifact_msg() - generate a message detailing the properties 1263/* artifact_msg() - generate a message detailing the properties
1264 * of 1-6 artifacts drawn sequentially from the artifact list. 1264 * of 1-6 artifacts drawn sequentially from the artifact list.
1265 */ 1265 */
1266static const char * 1266static const char *
1267artifact_msg (int level, int booksize) 1267artifact_msg (int level)
1268{ 1268{
1269 artifactlist *al = NULL; 1269 artifactlist *al = NULL;
1270 artifact *art; 1270 artifact *art;
1271 int chance, i, type, index; 1271 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1391/* spellpath_msg() - generate a message detailing the member 1391/* spellpath_msg() - generate a message detailing the member
1392 * incantations/prayers (and some of their properties) belonging to 1392 * incantations/prayers (and some of their properties) belonging to
1393 * a given spellpath. 1393 * a given spellpath.
1394 */ 1394 */
1395static char * 1395static char *
1396spellpath_msg (int level, int booksize) 1396spellpath_msg (int level)
1397{ 1397{
1398 static dynbuf_text buf; buf.clear (); 1398 static dynbuf_text buf; buf.clear ();
1399 1399
1400 static char retbuf[BOOK_BUF]; 1400 static char retbuf[BOOK_BUF];
1401 char tmpbuf[BOOK_BUF]; 1401 char tmpbuf[BOOK_BUF];
1427 } 1427 }
1428 1428
1429 /* Geez, no spells were generated. */ 1429 /* Geez, no spells were generated. */
1430 if (!seen) 1430 if (!seen)
1431 if (rndm (4)) /* usually, lets make a recursive call... */ 1431 if (rndm (4)) /* usually, lets make a recursive call... */
1432 return spellpath_msg (level, booksize); 1432 return spellpath_msg (level);
1433 else /* give up, cause knowing no spells exist for path is info too. */ 1433 else /* give up, cause knowing no spells exist for path is info too. */
1434 buf << "- no known spells exist.\n"; 1434 buf << "- no known spells exist.\n";
1435 1435
1436 return buf; 1436 return buf;
1437} 1437}
1440 * of a randomly selected alchemical formula. 1440 * of a randomly selected alchemical formula.
1441 */ 1441 */
1442static void 1442static void
1443make_formula_book (object *book, int level) 1443make_formula_book (object *book, int level)
1444{ 1444{
1445 char retbuf[BOOK_BUF], title[MAX_BUF]; 1445 char title[MAX_BUF];
1446 recipelist *fl; 1446 recipelist *fl;
1447 recipe *formula = NULL; 1447 recipe *formula = NULL;
1448 int chance; 1448 int chance;
1449
1450 static dynbuf_text buf; buf.clear ();
1449 1451
1450 /* the higher the book level, the more complex (ie number of 1452 /* the higher the book level, the more complex (ie number of
1451 * ingredients) the formula can be. 1453 * ingredients) the formula can be.
1452 */ 1454 */
1453 fl = get_formulalist (rndm (level) / 3 + 1); 1455 fl = get_formulalist (rndm (level) / 3 + 1);
1466 /* get a random formula, weighted by its bookchance */ 1468 /* get a random formula, weighted by its bookchance */
1467 chance = rndm (fl->total_chance); 1469 chance = rndm (fl->total_chance);
1468 for (formula = fl->items; formula; formula = formula->next) 1470 for (formula = fl->items; formula; formula = formula->next)
1469 { 1471 {
1470 chance -= formula->chance; 1472 chance -= formula->chance;
1473
1471 if (chance <= 0) 1474 if (chance <= 0)
1472 break; 1475 break;
1473 } 1476 }
1474 1477
1475 if (!formula || formula->arch_names <= 0) 1478 if (!formula || formula->arch_names <= 0)
1476 { 1479 {
1477 book->msg = "<indecipherable text>\n"; 1480 book->msg = "<indecipherable text>\n";
1478 new_text_name (book, 4); 1481 new_text_name (book, 4);
1479 add_author (book, 4); 1482 add_author (book, 4);
1480 1483 return;
1481 } 1484 }
1485
1486 /* looks like a formula was found. Base the amount
1487 * of information on the booklevel and the spellevel
1488 * of the formula. */
1489
1490 const char *op_name = formula->arch_name [rndm (formula->arch_names)];
1491 archetype *at;
1492
1493 /* preamble */
1494 buf << "Herein is described a project using B<< "
1495 << (formula->skill ? &formula->skill : "an unknown skill")
1496 << " >>:\n\n";
1497
1498 if ((at = archetype::find (op_name)))
1499 op_name = at->object::name;
1482 else 1500 else
1501 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1502
1503 /* item name */
1504 if (formula->title != shstr_NONE)
1505 {
1506 buf.printf ("The B<< %s of %s >>", op_name, &formula->title);
1507 /* This results in things like pile of philo. sulfur.
1508 * while philo. sulfur may look better, without this,
1509 * you get things like 'the wise' because its missing the
1510 * water of section.
1511 */
1512 sprintf (title, "%s: %s of %s",
1513 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1483 { 1514 }
1484 /* looks like a formula was found. Base the amount 1515 else
1485 * of information on the booklevel and the spellevel 1516 {
1486 * of the formula. */ 1517 buf << "The B<< " << op_name;
1487 1518
1488 const char *op_name = formula->arch_name [rndm (formula->arch_names)]; 1519 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1520 if (at->title)
1521 {
1522 buf << " " << at->title;
1523 strcat (title, " ");
1524 strcat (title, at->title);
1525 }
1526
1527 buf << " >>";
1528 }
1529
1530 /* Lets name the book something meaningful ! */
1531 book->name = title;
1532 book->title = NULL;
1533
1534 /* ingredients to make it */
1535 if (formula->ingred)
1536 {
1537 linked_char *next;
1489 archetype *at; 1538 archetype *at;
1490 1539
1491 /* preamble */
1492 sprintf (retbuf, "Herein is described a project using %s: \n", formula->skill ? &formula->skill : "an unknown skill");
1493
1494 if ((at = archetype::find (op_name)) != (archetype *) NULL)
1495 op_name = at->object::name;
1496 else
1497 LOG (llevError, "formula_msg() can't find arch %s for formula.\n", op_name);
1498
1499 /* item name */
1500 if (formula->title != shstr_NONE)
1501 {
1502 sprintf (retbuf, "%sThe %s of %s", retbuf, op_name, &formula->title);
1503 /* This results in things like pile of philo. sulfur.
1504 * while philo. sulfur may look better, without this,
1505 * you get things like 'the wise' because its missing the
1506 * water of section.
1507 */
1508 sprintf (title, "%s: %s of %s",
1509 formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name, &formula->title);
1510 }
1511 else
1512 {
1513 sprintf (retbuf, "%sThe %s", retbuf, op_name);
1514 sprintf (title, "%s: %s", formula_book_name [rndm (sizeof (formula_book_name) / sizeof (char *))], op_name);
1515 if (at->title)
1516 {
1517 strcat (retbuf, " ");
1518 strcat (retbuf, at->title);
1519 strcat (title, " ");
1520 strcat (title, at->title);
1521 }
1522 }
1523
1524 /* Lets name the book something meaningful ! */
1525 book->name = title;
1526 book->title = NULL;
1527
1528 /* ingredients to make it */
1529 if (formula->ingred != NULL)
1530 {
1531 linked_char *next;
1532 archetype *at;
1533
1534 at = archetype::find (formula->cauldron); 1540 at = archetype::find (formula->cauldron);
1535 1541
1536 sprintf (retbuf + strlen (retbuf), 1542 buf.printf (" may be made at %s using the following ingredients:\n\n",
1537 " may be made at %s using the following ingredients:\n", at ? query_name (at) : "an unknown place"); 1543 at ? query_name (at) : "an appropriate place");
1538 1544
1539 for (next = formula->ingred; next != NULL; next = next->next) 1545 for (next = formula->ingred; next; next = next->next)
1540 { 1546 buf << next->name << '\r';
1541 strcat (retbuf, next->name); 1547 }
1542 strcat (retbuf, "\n");
1543 }
1544 }
1545 else 1548 else
1546 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title); 1549 LOG (llevError, "formula_msg() no ingredient list for object %s of %s\n", op_name, &formula->title);
1547 if (retbuf[strlen (retbuf) - 1] != '\n')
1548 strcat (retbuf, "\n");
1549 1550
1550 book->msg = retbuf; 1551 book->msg = buf;
1551 }
1552} 1552}
1553 1553
1554#define DESCRIBE_PATH(retbuf, variable, name) \ 1554#define DESCRIBE_PATH(retbuf, variable, name) \
1555 if(variable) { \ 1555 if(variable) { \
1556 int i,j=0; \ 1556 int i,j=0; \
1568 1568
1569/* god_info_msg() - generate a message detailing the properties 1569/* god_info_msg() - generate a message detailing the properties
1570 * of a random god. Used by the book hack. b.t. 1570 * of a random god. Used by the book hack. b.t.
1571 */ 1571 */
1572static const char * 1572static const char *
1573god_info_msg (int level, int booksize) 1573god_info_msg (int level)
1574{ 1574{
1575 static char retbuf[BOOK_BUF];
1576 const char *name = NULL; 1575 const char *name = NULL;
1577 char buf[BOOK_BUF];
1578 int i;
1579 size_t introlen;
1580 object *god = pntr_to_god_obj (get_rand_god ()); 1576 object *god = pntr_to_god_obj (get_rand_god ());
1581 1577
1578 static dynbuf_text buf; buf.clear ();
1579
1582 if (!god) 1580 if (!god)
1583 return (char *) NULL; /* oops, problems... */ 1581 return 0; /* oops, problems... */
1582
1584 name = god->name; 1583 name = god->name;
1585 1584
1586 /* preamble.. */ 1585 /* preamble.. */
1587 sprintf (retbuf, "This document contains knowledge concerning\n"); 1586 buf << "This document contains knowledge concerning the diety B<< "
1588 sprintf (retbuf, "%sthe diety %s", retbuf, name); 1587 << name << " >>";
1589 1588
1590 /* Always have as default information the god's descriptive terms. */ 1589 /* Always have as default information the god's descriptive terms. */
1591 if (nstrtok (god->msg, ",") > 0) 1590 if (nstrtok (god->msg, ",") > 0)
1592 { 1591 buf << ", known as" << strtoktolin (god->msg, ",");
1593 strcat (retbuf, ", known as");
1594 strcat (retbuf, strtoktolin (god->msg, ","));
1595 }
1596 else 1592 else
1597 strcat (retbuf, "..."); 1593 buf << "...";
1598 1594
1599 strcat (retbuf, "\n ---\n"); 1595 buf << "\n\n";
1596
1600 introlen = strlen (retbuf); /* so we will know if no new info is added later */ 1597 int introlen = buf.size (); /* so we will know if no new info is added later */
1601 1598
1602 /* Information about the god is random, and based on the level of the 1599 /* Information about the god is random, and based on the level of the
1603 * 'book'. Probably there is a more intellegent way to implement 1600 * 'book'. Probably there is a more intellegent way to implement
1604 * this ... 1601 * this ...
1605 */ 1602 */
1606 while (level > 0) 1603 while (level > 0 && buf.size () < BOOK_BUF)
1607 { 1604 {
1608 sprintf (buf, " ");
1609 if (level == 2 && rndm (2)) 1605 if (level == 2 && rndm (2))
1610 { /* enemy god */ 1606 { /* enemy god */
1611 const char *enemy = god->title; 1607 const char *enemy = god->title;
1612 1608
1613 if (enemy) 1609 if (enemy)
1614 sprintf (buf, "The gods %s and %s are enemies.\n ---\n", name, enemy); 1610 buf.printf ("The gods %s and %s are enemies.\r", name, enemy);
1615 } 1611 }
1616 1612
1617 if (level == 3 && rndm (2)) 1613 if (level == 3 && rndm (2))
1618 { /* enemy race, what the god's holy word effects */ 1614 { /* enemy race, what the god's holy word effects */
1619 const char *enemy = god->slaying; 1615 const char *enemy = god->slaying;
1616 int i;
1620 1617
1621 if (enemy && !(god->path_denied & PATH_TURNING)) 1618 if (enemy && !(god->path_denied & PATH_TURNING))
1622 if ((i = nstrtok (enemy, ",")) > 0) 1619 if ((i = nstrtok (enemy, ",")) > 0)
1623 { 1620 {
1624 char tmpbuf[MAX_BUF]; 1621 char tmpbuf[MAX_BUF];
1625 1622
1626 sprintf (buf, "The holy words of %s have the power to\n", name); 1623 buf << "The holy words of " << name
1627 strcat (buf, "slay creatures belonging to the "); 1624 << " have the power to slay creatures belonging to the ";
1625
1628 if (i > 1) 1626 if (i > 1)
1629 sprintf (tmpbuf, "following \n races:%s", strtoktolin (enemy, ",")); 1627 buf << "following races:" << strtoktolin (enemy, ",");
1630 else 1628 else
1631 sprintf (tmpbuf, "race of%s", strtoktolin (enemy, ",")); 1629 buf << "race of" << strtoktolin (enemy, ",");
1632 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1630
1631 buf << '\r';
1633 } 1632 }
1634 } 1633 }
1635 1634
1636 if (level == 4 && rndm (2)) 1635 if (level == 4 && rndm (2))
1637 { /* Priest of god gets these protect,vulnerable... */ 1636 { /* Priest of god gets these protect,vulnerable... */
1638 char tmpbuf[MAX_BUF];
1639
1640 if (const char *cp = describe_resistance (god, 1)) 1637 if (const char *cp = describe_resistance (god, 1))
1641 { /* This god does have protections */ 1638 { /* This god does have protections */
1642 sprintf (tmpbuf, "%s has a potent aura which is extended\n", name); 1639 buf << name
1640 << " has a potent aura which is extended to"
1643 strcat (tmpbuf, "faithful priests. The effects of this aura include:\n"); 1641 " faithful priests. The effects of this aura include: "
1644 strcat (tmpbuf, cp); 1642 << cp
1645 strcat (buf, tmpbuf); 1643 << ".\r";
1646 strcat (buf, "\n ---\n");
1647 } 1644 }
1648 else
1649 sprintf (buf, " ");
1650 } 1645 }
1651 1646
1652 if (level == 5 && rndm (2)) 1647 if (level == 5 && rndm (2))
1653 { /* aligned race, summoning */ 1648 { /* aligned race, summoning */
1654 const char *race = god->race; /* aligned race */ 1649 const char *race = god->race; /* aligned race */
1650 int i;
1655 1651
1656 if (race && !(god->path_denied & PATH_SUMMON)) 1652 if (race && !(god->path_denied & PATH_SUMMON))
1657 if ((i = nstrtok (race, ",")) > 0) 1653 if ((i = nstrtok (race, ",")) > 0)
1658 { 1654 {
1659 char tmpbuf[MAX_BUF]; 1655 buf << "Creatures sacred to " << name << " include the ";
1660
1661 sprintf (buf, "Creatures sacred to %s include the \n", name);
1662 if (i > 1) 1656 if (i > 1)
1663 sprintf (tmpbuf, "following \n races:%s", strtoktolin (race, ",")); 1657 buf << "following races:" << strtoktolin (race, ",");
1664 else 1658 else
1665 sprintf (tmpbuf, "race of%s", strtoktolin (race, ",")); 1659 buf << "race of" << strtoktolin (race, ",");
1666 sprintf (buf, "%s%s\n ---\n", buf, tmpbuf); 1660
1661 buf << '\r';
1667 } 1662 }
1668 } 1663 }
1669 1664
1670 if (level == 6 && rndm (2)) 1665 if (level == 6 && rndm (2))
1671 { /* blessing,curse properties of the god */ 1666 { /* blessing,curse properties of the god */
1672 char tmpbuf[MAX_BUF];
1673
1674 if (const char *cp = describe_resistance (god, 1)) 1667 if (const char *cp = describe_resistance (god, 1))
1675 { /* This god does have protections */ 1668 { /* This god does have protections */
1676 sprintf (tmpbuf, "\nThe priests of %s are known to be able to \n", name); 1669 buf << "The priests of " << name
1670 << " are known to be able to "
1677 strcat (tmpbuf, "bestow a blessing which makes the recipient\n"); 1671 "bestow a blessing which makes the recipient "
1678 strcat (tmpbuf, cp); 1672 << cp
1679 strcat (buf, tmpbuf); 1673 << '\r';
1680 strcat (buf, "\n ---\n");
1681 } 1674 }
1682 else
1683 sprintf (buf, " ");
1684
1685 } 1675 }
1686 1676
1687 if (level == 8 && rndm (2)) 1677 if (level == 8 && rndm (2))
1688 { /* immunity, holy possession */ 1678 { /* immunity, holy possession */
1689 int has_effect = 0, tmpvar; 1679 buf << "The priests of " << name
1690 char tmpbuf[MAX_BUF]; 1680 << " are known to make cast a mighty"
1681 " prayer of possession";
1682
1683 int first = 1;
1691 1684
1692 sprintf (tmpbuf, "\n");
1693 sprintf (tmpbuf, "The priests of %s are known to make cast a mighty \n", name);
1694
1695 strcat (tmpbuf, "prayer of possession which gives the recipient\n");
1696
1697 for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++) 1685 for (int i = 0; i < NROFATTACKS; i++)
1686 if (god->resist[i] == 100)
1698 { 1687 {
1699 if (god->resist[tmpvar] == 100) 1688 if (first)
1700 { 1689 {
1690 buf << " which gives the recipient";
1701 has_effect = 1; 1691 first = 0;
1702 sprintf (tmpbuf + strlen (tmpbuf), "Immunity to %s", attacktype_desc[tmpvar]);
1703 } 1692 }
1693 else
1694 buf << ", ";
1695
1696 buf << " immunity to " << attacktype_desc[i];
1704 } 1697 }
1705 1698
1706 if (has_effect) 1699 buf << ".\r";
1707 {
1708 strcat (buf, tmpbuf);
1709 strcat (buf, "\n ---\n");
1710 }
1711 else
1712 sprintf (buf, " ");
1713 } 1700 }
1714 1701
1715 if (level == 12 && rndm (2)) 1702 if (level == 12 && rndm (2))
1716 { /* spell paths */ 1703 { /* spell paths */
1704 //TODO:
1717 int has_effect = 0, tmpvar; 1705 int has_effect = 0, tmpvar;
1718 char tmpbuf[MAX_BUF]; 1706 char tmpbuf[MAX_BUF];
1719 1707
1720 sprintf (tmpbuf, "\n"); 1708 sprintf (tmpbuf, "\n");
1721 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); 1709 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1738 has_effect = 1; 1726 has_effect = 1;
1739 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied"); 1727 DESCRIBE_PATH (tmpbuf, tmpvar, "Denied");
1740 } 1728 }
1741 1729
1742 if (has_effect) 1730 if (has_effect)
1743 { 1731 buf << tmpbuf << '\r';
1744 strcat (buf, tmpbuf);
1745 strcat (buf, "\n ---\n");
1746 }
1747 else 1732 else
1748 sprintf (buf, " "); 1733 buf << '\r';
1749 } 1734 }
1750 1735
1751 /* check to be sure new buffer size dont exceed either
1752 * the maximum buffer size, or the 'natural' size of the
1753 * book...
1754 */
1755 if (book_overflow (retbuf, buf, booksize))
1756 break;
1757 else if (strlen (buf) > 1)
1758 strcat (retbuf, buf);
1759
1760 level--; 1736 level--;
1761 } 1737 }
1762 1738
1763 if (strlen (retbuf) == introlen) 1739 if (buf.size () == introlen)
1764 { /* we got no information beyond the preamble! */ 1740 /* we got no information beyond the preamble! */
1765 strcat (retbuf, " [Unfortunately the rest of the information is\n"); 1741 buf << "[Unfortunately the rest of the information is hopelessly garbled!]";
1766 strcat (retbuf, " hopelessly garbled!]\n ---\n"); 1742
1767 }
1768#ifdef BOOK_MSG_DEBUG
1769 LOG (llevDebug, "\n god_info_msg() created string: %d\n", strlen (retbuf));
1770 LOG (llevDebug, " MADE THIS:\n%s", retbuf);
1771#endif
1772 return retbuf; 1743 return buf;
1773} 1744}
1774 1745
1775/* tailor_readable_ob()- The main routine. This chooses a random 1746/* tailor_readable_ob()- The main routine. This chooses a random
1776 * message to put in given readable object (type==BOOK) which will 1747 * message to put in given readable object (type==BOOK) which will
1777 * be referred hereafter as a 'book'. We use the book level to de- 1748 * be referred hereafter as a 'book'. We use the book level to de-
1789 * 1760 *
1790 */ 1761 */
1791void 1762void
1792tailor_readable_ob (object *book, int msg_type) 1763tailor_readable_ob (object *book, int msg_type)
1793{ 1764{
1794 char msgbuf[BOOK_BUF];
1795 int level = book->level ? rndm (book->level) + 1 : 1; 1765 int level = book->level ? rndm (book->level) + 1 : 1;
1796 int book_buf_size;
1797 1766
1798 /* safety */ 1767 /* safety */
1799 if (book->type != BOOK) 1768 if (book->type != BOOK)
1800 return; 1769 return;
1801 1770
1802 if (level <= 0) 1771 if (level <= 0)
1803 return; /* if no level no point in doing any more... */ 1772 return; /* if no level no point in doing any more... */
1804
1805 /* Max text length this book can have. */
1806 book_buf_size = BOOKSIZE (book);
1807 1773
1808 /* &&& The message switch &&& */ 1774 /* &&& The message switch &&& */
1809 /* Below all of the possible types of messages in the "book"s. 1775 /* Below all of the possible types of messages in the "book"s.
1810 */ 1776 */
1811 /* 1777 /*
1814 * 2) make sure there is an entry in max_titles[] array. 1780 * 2) make sure there is an entry in max_titles[] array.
1815 * 3) make sure there are entries for your case in new_text_title() 1781 * 3) make sure there are entries for your case in new_text_title()
1816 * and add_authour(). 1782 * and add_authour().
1817 * 4) you may want separate authour/book name arrays in read.h 1783 * 4) you may want separate authour/book name arrays in read.h
1818 */ 1784 */
1785 const char *new_msg = "";
1819 msg_type = msg_type > 0 ? msg_type : rndm (8); 1786 msg_type = msg_type > 0 ? msg_type : rndm (8);
1820 switch (msg_type*0+2)//D 1787 switch (msg_type)
1821 { 1788 {
1822 case 1: /* monster attrib */ 1789 case 1: /* monster attrib */
1823 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1790 new_msg = mon_info_msg (level);
1824 break; 1791 break;
1825 case 2: /* artifact attrib */ 1792 case 2: /* artifact attrib */
1826 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1793 new_msg = artifact_msg (level);
1827 break; 1794 break;
1828 case 3: /* grouping incantations/prayers by path */ 1795 case 3: /* grouping incantations/prayers by path */
1829 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1796 new_msg = spellpath_msg (level);
1830 break; 1797 break;
1831 case 4: /* describe an alchemy formula */ 1798 case 4: /* describe an alchemy formula */
1832 make_formula_book (book, level); 1799 make_formula_book (book, level);
1833 /* make_formula_book already gives title */ 1800 /* make_formula_book already gives title */
1834 return; 1801 return;
1835 break;
1836 case 5: /* bits of information about a god */ 1802 case 5: /* bits of information about a god */
1837 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1803 new_msg = god_info_msg (level);
1838 break; 1804 break;
1839 case 0: /* use info list in lib/ */ 1805 case 0: /* use info list in lib/ */
1840 default: 1806 default:
1841 cfperl_make_book (book, level); 1807 cfperl_make_book (book, level);
1808 /* already gives title */
1842 return; 1809 return;
1843 } 1810 }
1844 1811
1845 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1846
1847 if (strlen (msgbuf) > 1) 1812 if (strlen (new_msg) > 1)
1848 { 1813 {
1849 book->msg = msgbuf; 1814 book->msg = new_msg;
1850 /* lets give the "book" a new name, which may be a compound word */ 1815 /* lets give the "book" a new name, which may be a compound word */
1851 change_book (book, msg_type); 1816 change_book (book, msg_type);
1852 } 1817 }
1853} 1818}
1854
1855 1819
1856/***************************************************************************** 1820/*****************************************************************************
1857 * 1821 *
1858 * Cleanup routine for readble stuff. 1822 * Cleanup routine for readble stuff.
1859 * 1823 *
1860 *****************************************************************************/ 1824 *****************************************************************************/
1861 1825static void
1862void
1863free_all_readable (void) 1826free_all_readable (void)
1864{ 1827{
1865 titlelist *tlist, *tnext; 1828 titlelist *tlist, *tnext;
1866 title *title1, *titlenext; 1829 title *title1, *titlenext;
1867 linked_char *lmsg, *nextmsg; 1830 linked_char *lmsg, *nextmsg;
1868 objectlink *monlink, *nextmon; 1831 objectlink *monlink, *nextmon;
1869 1832
1870 LOG (llevDebug, "freeing all book information\n"); 1833 LOG (llevDebug, "freeing all book information\n");
1871 1834
1872 for (tlist = booklist; tlist != NULL; tlist = tnext) 1835 for (tlist = booklist; tlist; tlist = tnext)
1873 { 1836 {
1874 tnext = tlist->next; 1837 tnext = tlist->next;
1875 1838
1876 for (title1 = tlist->first_book; title1; title1 = titlenext) 1839 for (title1 = tlist->first_book; title1; title1 = titlenext)
1877 { 1840 {
1893 nextmon = monlink->next; 1856 nextmon = monlink->next;
1894 delete monlink; 1857 delete monlink;
1895 } 1858 }
1896} 1859}
1897 1860
1898
1899/***************************************************************************** 1861/*****************************************************************************
1900 * 1862 *
1901 * Writeback routine for updating the bookarchive. 1863 * Writeback routine for updating the bookarchive.
1902 * 1864 *
1903 ****************************************************************************/ 1865 ****************************************************************************/
1904
1905/* write_book_archive() - write out the updated book archive */ 1866/* write_book_archive() - write out the updated book archive */
1906
1907void 1867void
1908write_book_archive (void) 1868write_book_archive (void)
1909{ 1869{
1910 FILE *fp; 1870 FILE *fp;
1911 int index = 0; 1871 int index = 0;
1914 titlelist *bl = get_titlelist (0); 1874 titlelist *bl = get_titlelist (0);
1915 1875
1916 /* If nothing changed, don't write anything */ 1876 /* If nothing changed, don't write anything */
1917 if (!need_to_write_bookarchive) 1877 if (!need_to_write_bookarchive)
1918 return; 1878 return;
1879
1919 need_to_write_bookarchive = 0; 1880 need_to_write_bookarchive = 0;
1920 1881
1921 sprintf (fname, "%s/bookarch", settings.localdir); 1882 sprintf (fname, "%s/bookarch", settings.localdir);
1922 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1883 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1923 1884
1924 if ((fp = fopen (fname, "w")) == NULL) 1885 if ((fp = fopen (fname, "w")) == NULL)
1925 {
1926 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1886 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1927 }
1928 else 1887 else
1929 { 1888 {
1930 while (bl) 1889 while (bl)
1931 { 1890 {
1932 for (book = bl->first_book; book; book = book->next) 1891 for (book = bl->first_book; book; book = book->next)
1939 fprintf (fp, "type %d\n", index); 1898 fprintf (fp, "type %d\n", index);
1940 fprintf (fp, "size %d\n", book->size); 1899 fprintf (fp, "size %d\n", book->size);
1941 fprintf (fp, "index %d\n", book->msg_index); 1900 fprintf (fp, "index %d\n", book->msg_index);
1942 fprintf (fp, "end\n"); 1901 fprintf (fp, "end\n");
1943 } 1902 }
1903
1944 bl = bl->next; 1904 bl = bl->next;
1945 index++; 1905 index++;
1946 } 1906 }
1907
1947 fclose (fp); 1908 fclose (fp);
1948 chmod (fname, SAVE_MODE); 1909 chmod (fname, SAVE_MODE);
1949 } 1910 }
1950} 1911}
1912
1951readable_message_type * 1913readable_message_type *
1952get_readable_message_type (object *readable) 1914get_readable_message_type (object *readable)
1953{ 1915{
1954 uint8 subtype = readable->subtype; 1916 uint8 subtype = readable->subtype;
1955 1917

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines