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.49 by root, Fri Oct 16 00:02:22 2009 UTC vs.
Revision 1.50 by root, Sat Oct 24 00:43:30 2009 UTC

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}
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 const char *name = NULL; 1575 const char *name = NULL;
1576 object *god = pntr_to_god_obj (get_rand_god ()); 1576 object *god = pntr_to_god_obj (get_rand_god ());
1577 1577
1578 static dynbuf_text buf; buf.clear (); 1578 static dynbuf_text buf; buf.clear ();
1760 * 1760 *
1761 */ 1761 */
1762void 1762void
1763tailor_readable_ob (object *book, int msg_type) 1763tailor_readable_ob (object *book, int msg_type)
1764{ 1764{
1765 char msgbuf[BOOK_BUF];
1766 int level = book->level ? rndm (book->level) + 1 : 1; 1765 int level = book->level ? rndm (book->level) + 1 : 1;
1767 int book_buf_size;
1768 1766
1769 /* safety */ 1767 /* safety */
1770 if (book->type != BOOK) 1768 if (book->type != BOOK)
1771 return; 1769 return;
1772 1770
1773 if (level <= 0) 1771 if (level <= 0)
1774 return; /* if no level no point in doing any more... */ 1772 return; /* if no level no point in doing any more... */
1775
1776 /* Max text length this book can have. */
1777 book_buf_size = BOOKSIZE (book);
1778 1773
1779 /* &&& The message switch &&& */ 1774 /* &&& The message switch &&& */
1780 /* 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.
1781 */ 1776 */
1782 /* 1777 /*
1785 * 2) make sure there is an entry in max_titles[] array. 1780 * 2) make sure there is an entry in max_titles[] array.
1786 * 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()
1787 * and add_authour(). 1782 * and add_authour().
1788 * 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
1789 */ 1784 */
1785 const char *new_msg = "";
1790 msg_type = msg_type > 0 ? msg_type : rndm (8); 1786 msg_type = msg_type > 0 ? msg_type : rndm (8);
1791 switch (msg_type) 1787 switch (msg_type)
1792 { 1788 {
1793 case 1: /* monster attrib */ 1789 case 1: /* monster attrib */
1794 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1790 new_msg = mon_info_msg (level);
1795 break; 1791 break;
1796 case 2: /* artifact attrib */ 1792 case 2: /* artifact attrib */
1797 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1793 new_msg = artifact_msg (level);
1798 break; 1794 break;
1799 case 3: /* grouping incantations/prayers by path */ 1795 case 3: /* grouping incantations/prayers by path */
1800 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1796 new_msg = spellpath_msg (level);
1801 break; 1797 break;
1802 case 4: /* describe an alchemy formula */ 1798 case 4: /* describe an alchemy formula */
1803 make_formula_book (book, level); 1799 make_formula_book (book, level);
1804 /* make_formula_book already gives title */ 1800 /* make_formula_book already gives title */
1805 return; 1801 return;
1806 case 5: /* bits of information about a god */ 1802 case 5: /* bits of information about a god */
1807 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1803 new_msg = god_info_msg (level);
1808 break; 1804 break;
1809 case 0: /* use info list in lib/ */ 1805 case 0: /* use info list in lib/ */
1810 default: 1806 default:
1811 cfperl_make_book (book, level); 1807 cfperl_make_book (book, level);
1812 /* already gives title */ 1808 /* already gives title */
1813 return; 1809 return;
1814 } 1810 }
1815 1811
1816 if (strlen (msgbuf) > 1) 1812 if (strlen (new_msg) > 1)
1817 { 1813 {
1818 book->msg = msgbuf; 1814 book->msg = new_msg;
1819 /* 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 */
1820 change_book (book, msg_type); 1816 change_book (book, msg_type);
1821 } 1817 }
1822} 1818}
1823
1824 1819
1825/***************************************************************************** 1820/*****************************************************************************
1826 * 1821 *
1827 * Cleanup routine for readble stuff. 1822 * Cleanup routine for readble stuff.
1828 * 1823 *
1829 *****************************************************************************/ 1824 *****************************************************************************/
1830
1831void 1825void
1832free_all_readable (void) 1826free_all_readable (void)
1833{ 1827{
1834 titlelist *tlist, *tnext; 1828 titlelist *tlist, *tnext;
1835 title *title1, *titlenext; 1829 title *title1, *titlenext;
1862 nextmon = monlink->next; 1856 nextmon = monlink->next;
1863 delete monlink; 1857 delete monlink;
1864 } 1858 }
1865} 1859}
1866 1860
1867
1868/***************************************************************************** 1861/*****************************************************************************
1869 * 1862 *
1870 * Writeback routine for updating the bookarchive. 1863 * Writeback routine for updating the bookarchive.
1871 * 1864 *
1872 ****************************************************************************/ 1865 ****************************************************************************/
1873
1874/* write_book_archive() - write out the updated book archive */ 1866/* write_book_archive() - write out the updated book archive */
1875
1876void 1867void
1877write_book_archive (void) 1868write_book_archive (void)
1878{ 1869{
1879 FILE *fp; 1870 FILE *fp;
1880 int index = 0; 1871 int index = 0;
1883 titlelist *bl = get_titlelist (0); 1874 titlelist *bl = get_titlelist (0);
1884 1875
1885 /* If nothing changed, don't write anything */ 1876 /* If nothing changed, don't write anything */
1886 if (!need_to_write_bookarchive) 1877 if (!need_to_write_bookarchive)
1887 return; 1878 return;
1879
1888 need_to_write_bookarchive = 0; 1880 need_to_write_bookarchive = 0;
1889 1881
1890 sprintf (fname, "%s/bookarch", settings.localdir); 1882 sprintf (fname, "%s/bookarch", settings.localdir);
1891 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1883 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1892 1884
1893 if ((fp = fopen (fname, "w")) == NULL) 1885 if ((fp = fopen (fname, "w")) == NULL)
1894 {
1895 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1886 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1896 }
1897 else 1887 else
1898 { 1888 {
1899 while (bl) 1889 while (bl)
1900 { 1890 {
1901 for (book = bl->first_book; book; book = book->next) 1891 for (book = bl->first_book; book; book = book->next)
1908 fprintf (fp, "type %d\n", index); 1898 fprintf (fp, "type %d\n", index);
1909 fprintf (fp, "size %d\n", book->size); 1899 fprintf (fp, "size %d\n", book->size);
1910 fprintf (fp, "index %d\n", book->msg_index); 1900 fprintf (fp, "index %d\n", book->msg_index);
1911 fprintf (fp, "end\n"); 1901 fprintf (fp, "end\n");
1912 } 1902 }
1903
1913 bl = bl->next; 1904 bl = bl->next;
1914 index++; 1905 index++;
1915 } 1906 }
1907
1916 fclose (fp); 1908 fclose (fp);
1917 chmod (fname, SAVE_MODE); 1909 chmod (fname, SAVE_MODE);
1918 } 1910 }
1919} 1911}
1912
1920readable_message_type * 1913readable_message_type *
1921get_readable_message_type (object *readable) 1914get_readable_message_type (object *readable)
1922{ 1915{
1923 uint8 subtype = readable->subtype; 1916 uint8 subtype = readable->subtype;
1924 1917

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines