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.46 by root, Thu Oct 15 23:02:28 2009 UTC vs.
Revision 1.47 by root, Thu Oct 15 23:24:38 2009 UTC

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, int booksize)
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-
1815 * 3) make sure there are entries for your case in new_text_title() 1786 * 3) make sure there are entries for your case in new_text_title()
1816 * and add_authour(). 1787 * and add_authour().
1817 * 4) you may want separate authour/book name arrays in read.h 1788 * 4) you may want separate authour/book name arrays in read.h
1818 */ 1789 */
1819 msg_type = msg_type > 0 ? msg_type : rndm (8); 1790 msg_type = msg_type > 0 ? msg_type : rndm (8);
1820 switch (msg_type*0+4)//D 1791 switch (msg_type)
1821 { 1792 {
1822 case 1: /* monster attrib */ 1793 case 1: /* monster attrib */
1823 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1794 strcpy (msgbuf, mon_info_msg (level, book_buf_size));
1824 break; 1795 break;
1825 case 2: /* artifact attrib */ 1796 case 2: /* artifact attrib */
1830 break; 1801 break;
1831 case 4: /* describe an alchemy formula */ 1802 case 4: /* describe an alchemy formula */
1832 make_formula_book (book, level); 1803 make_formula_book (book, level);
1833 /* make_formula_book already gives title */ 1804 /* make_formula_book already gives title */
1834 return; 1805 return;
1835 break;
1836 case 5: /* bits of information about a god */ 1806 case 5: /* bits of information about a god */
1837 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1807 strcpy (msgbuf, god_info_msg (level, book_buf_size));
1838 break; 1808 break;
1839 case 0: /* use info list in lib/ */ 1809 case 0: /* use info list in lib/ */
1840 default: 1810 default:
1841 cfperl_make_book (book, level); 1811 cfperl_make_book (book, level);
1812 /* already gives title */
1842 return; 1813 return;
1843 } 1814 }
1844 1815
1845 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */ 1816 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1846 1817
1867 linked_char *lmsg, *nextmsg; 1838 linked_char *lmsg, *nextmsg;
1868 objectlink *monlink, *nextmon; 1839 objectlink *monlink, *nextmon;
1869 1840
1870 LOG (llevDebug, "freeing all book information\n"); 1841 LOG (llevDebug, "freeing all book information\n");
1871 1842
1872 for (tlist = booklist; tlist != NULL; tlist = tnext) 1843 for (tlist = booklist; tlist; tlist = tnext)
1873 { 1844 {
1874 tnext = tlist->next; 1845 tnext = tlist->next;
1875 1846
1876 for (title1 = tlist->first_book; title1; title1 = titlenext) 1847 for (title1 = tlist->first_book; title1; title1 = titlenext)
1877 { 1848 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines