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.54 by root, Sun Nov 29 10:55:18 2009 UTC

108/* these are needed for creation of a linked list of 108/* these are needed for creation of a linked list of
109 * pointers to all (hostile) monster objects */ 109 * pointers to all (hostile) monster objects */
110 110
111static int nrofmon = 0, need_to_write_bookarchive = 0; 111static int nrofmon = 0, need_to_write_bookarchive = 0;
112 112
113
114/* this is needed to keep track of status of initialisation
115 * of the message file */
116static int nrofmsg = 0;
117
118/* first_msg is the started of the linked list of messages as read from
119 * the messages file
120 */
121static linked_char *first_msg = NULL;
122
123/* 113/*
124 * Spellpath information 114 * Spellpath information
125 */ 115 */
126
127static uint32 spellpathdef[NRSPELLPATHS] = { 116static uint32 spellpathdef[NRSPELLPATHS] = {
128 PATH_PROT, 117 PATH_PROT,
129 PATH_FIRE, 118 PATH_FIRE,
130 PATH_FROST, 119 PATH_FROST,
131 PATH_ELEC, 120 PATH_ELEC,
497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, 486 /*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"}, 487 {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"}, 488 {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"} 489 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"}
501}; 490};
502int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); 491static int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
503 492
504static int max_titles[6] = { 493static int max_titles[6] = {
505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 494 ((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 *)), 495 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 496 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
515 * Start of misc. readable functions used by others functions in this file 504 * Start of misc. readable functions used by others functions in this file
516 * 505 *
517 *****************************************************************************/ 506 *****************************************************************************/
518 507
519static titlelist * 508static titlelist *
520get_empty_booklist (void) 509get_empty_booklist ()
521{ 510{
522 titlelist *bl = new titlelist; 511 titlelist *bl = new titlelist;
523 512
524 bl->number = 0; 513 bl->number = 0;
525 bl->first_book = NULL; 514 bl->first_book = NULL;
526 bl->next = NULL; 515 bl->next = NULL;
527 return bl; 516 return bl;
528} 517}
529 518
530static title * 519static title *
531get_empty_book (void) 520get_empty_book ()
532{ 521{
533 title *t = new title; 522 title *t = new title;
534 523
535 t->name = NULL; 524 t->name = NULL;
536 t->archname = NULL; 525 t->archname = NULL;
619 tbuf = strtok (NULL, sbuf); 608 tbuf = strtok (NULL, sbuf);
620 } 609 }
621 return (char *) rbuf; 610 return (char *) rbuf;
622} 611}
623 612
624static int
625book_overflow (const char *buf1, const char *buf2, int booksize)
626{
627 if (buf_overflow (buf1, buf2, BOOK_BUF - 2) /* 2 less so always room for trailing \n */
628 || buf_overflow (buf1, buf2, booksize))
629 return 1;
630
631 return 0;
632}
633
634/***************************************************************************** 613/*****************************************************************************
635 * 614 *
636 * Start of initialisation related functions. 615 * Start of initialisation related functions.
637 * 616 *
638 ****************************************************************************/ 617 ****************************************************************************/
640/* init_book_archive() - if not called before, initialise the info list 619/* init_book_archive() - if not called before, initialise the info list
641 * This reads in the bookarch file into memory. bookarch is the file 620 * This reads in the bookarch file into memory. bookarch is the file
642 * created and updated across multiple runs of the program. 621 * created and updated across multiple runs of the program.
643 */ 622 */
644static void 623static void
645init_book_archive (void) 624init_book_archive ()
646{ 625{
647 FILE *fp; 626 FILE *fp;
648 int comp, nroftitle = 0; 627 int comp, nroftitle = 0;
649 char buf[MAX_BUF], fname[MAX_BUF], *cp; 628 char buf[MAX_BUF], fname[MAX_BUF], *cp;
650 title *book = NULL; 629 title *book = NULL;
765 * 744 *
766 * This is the function called by the main routine to initialise 745 * This is the function called by the main routine to initialise
767 * all the readable information. 746 * all the readable information.
768 */ 747 */
769void 748void
770init_readable (void) 749init_readable ()
771{ 750{
772 static int did_this; 751 static int did_this;
773 752
774 if (did_this) 753 if (did_this)
775 return; 754 return;
1226 1205
1227/* mon_info_msg() - generate a message detailing the properties 1206/* mon_info_msg() - generate a message detailing the properties
1228 * of a randomly selected monster. 1207 * of a randomly selected monster.
1229 */ 1208 */
1230static const char * 1209static const char *
1231mon_info_msg (int level, int booksize) 1210mon_info_msg (int level)
1232{ 1211{
1233 static dynbuf_text buf; buf.clear (); 1212 static dynbuf_text buf; buf.clear ();
1234 1213
1235 /*preamble */ 1214 /*preamble */
1236 buf << "This beastiary contains:\n"; 1215 buf << "This beastiary contains:\n";
1262 1241
1263/* artifact_msg() - generate a message detailing the properties 1242/* artifact_msg() - generate a message detailing the properties
1264 * of 1-6 artifacts drawn sequentially from the artifact list. 1243 * of 1-6 artifacts drawn sequentially from the artifact list.
1265 */ 1244 */
1266static const char * 1245static const char *
1267artifact_msg (int level, int booksize) 1246artifact_msg (int level)
1268{ 1247{
1269 artifactlist *al = NULL; 1248 artifactlist *al = NULL;
1270 artifact *art; 1249 artifact *art;
1271 int chance, i, type, index; 1250 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1251 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1391/* spellpath_msg() - generate a message detailing the member 1370/* spellpath_msg() - generate a message detailing the member
1392 * incantations/prayers (and some of their properties) belonging to 1371 * incantations/prayers (and some of their properties) belonging to
1393 * a given spellpath. 1372 * a given spellpath.
1394 */ 1373 */
1395static char * 1374static char *
1396spellpath_msg (int level, int booksize) 1375spellpath_msg (int level)
1397{ 1376{
1398 static dynbuf_text buf; buf.clear (); 1377 static dynbuf_text buf; buf.clear ();
1399 1378
1400 static char retbuf[BOOK_BUF]; 1379 static char retbuf[BOOK_BUF];
1401 char tmpbuf[BOOK_BUF]; 1380 char tmpbuf[BOOK_BUF];
1427 } 1406 }
1428 1407
1429 /* Geez, no spells were generated. */ 1408 /* Geez, no spells were generated. */
1430 if (!seen) 1409 if (!seen)
1431 if (rndm (4)) /* usually, lets make a recursive call... */ 1410 if (rndm (4)) /* usually, lets make a recursive call... */
1432 return spellpath_msg (level, booksize); 1411 return spellpath_msg (level);
1433 else /* give up, cause knowing no spells exist for path is info too. */ 1412 else /* give up, cause knowing no spells exist for path is info too. */
1434 buf << "- no known spells exist.\n"; 1413 buf << "- no known spells exist.\n";
1435 1414
1436 return buf; 1415 return buf;
1437} 1416}
1568 1547
1569/* god_info_msg() - generate a message detailing the properties 1548/* god_info_msg() - generate a message detailing the properties
1570 * of a random god. Used by the book hack. b.t. 1549 * of a random god. Used by the book hack. b.t.
1571 */ 1550 */
1572static const char * 1551static const char *
1573god_info_msg (int level, int booksize) 1552god_info_msg (int level)
1574{ 1553{
1575 const char *name = NULL; 1554 const char *name = NULL;
1576 object *god = pntr_to_god_obj (get_rand_god ()); 1555 object *god = pntr_to_god_obj (get_rand_god ());
1577 1556
1578 static dynbuf_text buf; buf.clear (); 1557 static dynbuf_text buf; buf.clear ();
1760 * 1739 *
1761 */ 1740 */
1762void 1741void
1763tailor_readable_ob (object *book, int msg_type) 1742tailor_readable_ob (object *book, int msg_type)
1764{ 1743{
1765 char msgbuf[BOOK_BUF];
1766 int level = book->level ? rndm (book->level) + 1 : 1; 1744 int level = book->level ? rndm (book->level) + 1 : 1;
1767 int book_buf_size;
1768 1745
1769 /* safety */ 1746 /* safety */
1770 if (book->type != BOOK) 1747 if (book->type != BOOK)
1771 return; 1748 return;
1772 1749
1773 if (level <= 0) 1750 if (level <= 0)
1774 return; /* if no level no point in doing any more... */ 1751 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 1752
1779 /* &&& The message switch &&& */ 1753 /* &&& The message switch &&& */
1780 /* Below all of the possible types of messages in the "book"s. 1754 /* Below all of the possible types of messages in the "book"s.
1781 */ 1755 */
1782 /* 1756 /*
1785 * 2) make sure there is an entry in max_titles[] array. 1759 * 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() 1760 * 3) make sure there are entries for your case in new_text_title()
1787 * and add_authour(). 1761 * and add_authour().
1788 * 4) you may want separate authour/book name arrays in read.h 1762 * 4) you may want separate authour/book name arrays in read.h
1789 */ 1763 */
1764 const char *new_msg = "";
1790 msg_type = msg_type > 0 ? msg_type : rndm (8); 1765 msg_type = msg_type > 0 ? msg_type : rndm (8);
1791 switch (msg_type) 1766 switch (msg_type)
1792 { 1767 {
1793 case 1: /* monster attrib */ 1768 case 1: /* monster attrib */
1794 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1769 new_msg = mon_info_msg (level);
1795 break; 1770 break;
1796 case 2: /* artifact attrib */ 1771 case 2: /* artifact attrib */
1797 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1772 new_msg = artifact_msg (level);
1798 break; 1773 break;
1799 case 3: /* grouping incantations/prayers by path */ 1774 case 3: /* grouping incantations/prayers by path */
1800 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1775 new_msg = spellpath_msg (level);
1801 break; 1776 break;
1802 case 4: /* describe an alchemy formula */ 1777 case 4: /* describe an alchemy formula */
1803 make_formula_book (book, level); 1778 make_formula_book (book, level);
1804 /* make_formula_book already gives title */ 1779 /* make_formula_book already gives title */
1805 return; 1780 return;
1806 case 5: /* bits of information about a god */ 1781 case 5: /* bits of information about a god */
1807 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1782 new_msg = god_info_msg (level);
1808 break; 1783 break;
1809 case 0: /* use info list in lib/ */ 1784 case 0: /* use info list in lib/ */
1810 default: 1785 default:
1811 cfperl_make_book (book, level); 1786 cfperl_make_book (book, level);
1812 /* already gives title */ 1787 /* already gives title */
1813 return; 1788 return;
1814 } 1789 }
1815 1790
1816 if (strlen (msgbuf) > 1) 1791 if (strlen (new_msg) > 1)
1817 { 1792 {
1818 book->msg = msgbuf; 1793 book->msg = new_msg;
1819 /* lets give the "book" a new name, which may be a compound word */ 1794 /* lets give the "book" a new name, which may be a compound word */
1820 change_book (book, msg_type); 1795 change_book (book, msg_type);
1821 } 1796 }
1822} 1797}
1823
1824
1825/*****************************************************************************
1826 *
1827 * Cleanup routine for readble stuff.
1828 *
1829 *****************************************************************************/
1830
1831void
1832free_all_readable (void)
1833{
1834 titlelist *tlist, *tnext;
1835 title *title1, *titlenext;
1836 linked_char *lmsg, *nextmsg;
1837 objectlink *monlink, *nextmon;
1838
1839 LOG (llevDebug, "freeing all book information\n");
1840
1841 for (tlist = booklist; tlist; tlist = tnext)
1842 {
1843 tnext = tlist->next;
1844
1845 for (title1 = tlist->first_book; title1; title1 = titlenext)
1846 {
1847 titlenext = title1->next;
1848 delete title1;
1849 }
1850
1851 delete tlist;
1852 }
1853
1854 for (lmsg = first_msg; lmsg; lmsg = nextmsg)
1855 {
1856 nextmsg = lmsg->next;
1857 delete lmsg;
1858 }
1859
1860 for (monlink = first_mon_info; monlink; monlink = nextmon)
1861 {
1862 nextmon = monlink->next;
1863 delete monlink;
1864 }
1865}
1866
1867 1798
1868/***************************************************************************** 1799/*****************************************************************************
1869 * 1800 *
1870 * Writeback routine for updating the bookarchive. 1801 * Writeback routine for updating the bookarchive.
1871 * 1802 *
1872 ****************************************************************************/ 1803 ****************************************************************************/
1873
1874/* write_book_archive() - write out the updated book archive */ 1804/* write_book_archive() - write out the updated book archive */
1875
1876void 1805void
1877write_book_archive (void) 1806write_book_archive ()
1878{ 1807{
1879 FILE *fp; 1808 FILE *fp;
1880 int index = 0; 1809 int index = 0;
1881 char fname[MAX_BUF]; 1810 char fname[MAX_BUF];
1882 title *book = NULL; 1811 title *book = NULL;
1883 titlelist *bl = get_titlelist (0); 1812 titlelist *bl = get_titlelist (0);
1884 1813
1885 /* If nothing changed, don't write anything */ 1814 /* If nothing changed, don't write anything */
1886 if (!need_to_write_bookarchive) 1815 if (!need_to_write_bookarchive)
1887 return; 1816 return;
1817
1888 need_to_write_bookarchive = 0; 1818 need_to_write_bookarchive = 0;
1889 1819
1890 sprintf (fname, "%s/bookarch", settings.localdir); 1820 sprintf (fname, "%s/bookarch", settings.localdir);
1891 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1821 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1892 1822
1893 if ((fp = fopen (fname, "w")) == NULL) 1823 if ((fp = fopen (fname, "w")) == NULL)
1894 {
1895 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1824 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1896 }
1897 else 1825 else
1898 { 1826 {
1899 while (bl) 1827 while (bl)
1900 { 1828 {
1901 for (book = bl->first_book; book; book = book->next) 1829 for (book = bl->first_book; book; book = book->next)
1908 fprintf (fp, "type %d\n", index); 1836 fprintf (fp, "type %d\n", index);
1909 fprintf (fp, "size %d\n", book->size); 1837 fprintf (fp, "size %d\n", book->size);
1910 fprintf (fp, "index %d\n", book->msg_index); 1838 fprintf (fp, "index %d\n", book->msg_index);
1911 fprintf (fp, "end\n"); 1839 fprintf (fp, "end\n");
1912 } 1840 }
1841
1913 bl = bl->next; 1842 bl = bl->next;
1914 index++; 1843 index++;
1915 } 1844 }
1845
1916 fclose (fp); 1846 fclose (fp);
1917 chmod (fname, SAVE_MODE); 1847 chmod (fname, SAVE_MODE);
1918 } 1848 }
1919} 1849}
1850
1920readable_message_type * 1851readable_message_type *
1921get_readable_message_type (object *readable) 1852get_readable_message_type (object *readable)
1922{ 1853{
1923 uint8 subtype = readable->subtype; 1854 uint8 subtype = readable->subtype;
1924 1855

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines