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.48 by root, Thu Oct 15 23:25:53 2009 UTC vs.
Revision 1.52 by root, Fri Nov 6 13:31:47 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 113/* first_msg is the started of the linked list of messages as read from
119 * the messages file 114 * the messages file
120 */ 115 */
121static linked_char *first_msg = NULL; 116static linked_char *first_msg = NULL;
122 117
123/* 118/*
124 * Spellpath information 119 * Spellpath information
125 */ 120 */
126
127static uint32 spellpathdef[NRSPELLPATHS] = { 121static uint32 spellpathdef[NRSPELLPATHS] = {
128 PATH_PROT, 122 PATH_PROT,
129 PATH_FIRE, 123 PATH_FIRE,
130 PATH_FROST, 124 PATH_FROST,
131 PATH_ELEC, 125 PATH_ELEC,
497 /*subtype 50 */ {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_GRAVESTONE_3, "readable-monument-gravestone-3"}, 491 /*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"}, 492 {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"}, 493 {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"} 494 {MSG_TYPE_MONUMENT, MSG_TYPE_MONUMENT_WALL_3, "readable-monument-wall-3"}
501}; 495};
502int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type); 496static int last_readable_subtype = sizeof (readable_message_types) / sizeof (readable_message_type);
503 497
504static int max_titles[6] = { 498static int max_titles[6] = {
505 ((sizeof (light_book_name) / sizeof (char *)) + (sizeof (heavy_book_name) / sizeof (char *))) * (sizeof (book_author) / sizeof (char *)), 499 ((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 *)), 500 (sizeof (mon_book_name) / sizeof (char *)) * (sizeof (mon_author) / sizeof (char *)),
507 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)), 501 (sizeof (art_book_name) / sizeof (char *)) * (sizeof (art_author) / sizeof (char *)),
617 else 611 else
618 strcat (rbuf, "."); 612 strcat (rbuf, ".");
619 tbuf = strtok (NULL, sbuf); 613 tbuf = strtok (NULL, sbuf);
620 } 614 }
621 return (char *) rbuf; 615 return (char *) rbuf;
622}
623
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} 616}
633 617
634/***************************************************************************** 618/*****************************************************************************
635 * 619 *
636 * Start of initialisation related functions. 620 * Start of initialisation related functions.
731} 715}
732 716
733/* init_mon_info() - creates the linked list of pointers to 717/* init_mon_info() - creates the linked list of pointers to
734 * monster archetype objects if not called previously 718 * monster archetype objects if not called previously
735 */ 719 */
736
737static void 720static void
738init_mon_info (void) 721init_mon_info ()
739{ 722{
740 archetype *at; 723 archetype *at;
741 static int did_init_mon_info = 0; 724 static int did_init_mon_info = 0;
742 725
743 if (did_init_mon_info) 726 if (did_init_mon_info)
744 return; 727 return;
745 728
746 did_init_mon_info = 1; 729 did_init_mon_info = 1;
747 730
748 for_all_archetypes (at) 731 for_all_archetypes (at)
749 { 732 if (at->flag [FLAG_MONSTER]
750 if (QUERY_FLAG (at, FLAG_MONSTER) && (!QUERY_FLAG (at, FLAG_CHANGING) || QUERY_FLAG (at, FLAG_UNAGGRESSIVE))) 733 && at->is_head ()
734 && (!at->flag [FLAG_CHANGING] || at->flag [FLAG_UNAGGRESSIVE]))
751 { 735 {
752 objectlink *mon = new objectlink; 736 objectlink *mon = new objectlink;
753 737
754 mon->ob = at; 738 mon->ob = at;
755 mon->next = first_mon_info; 739 mon->next = first_mon_info;
756 first_mon_info = mon; 740 first_mon_info = mon;
757 nrofmon++; 741 nrofmon++;
758 } 742 }
759 }
760 743
761 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 744 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
762} 745}
763 746
764/* init_readable() - initialise linked lists utilized by 747/* init_readable() - initialise linked lists utilized by
1215 break; 1198 break;
1216 1199
1217 /* didn't find a match */ 1200 /* didn't find a match */
1218 if (!mon) 1201 if (!mon)
1219 return NULL; 1202 return NULL;
1203
1220 if (mon->next) 1204 if (mon->next)
1221 return mon->next->ob; 1205 return mon->next->ob;
1222 else 1206 else
1223 return first_mon_info->ob; 1207 return first_mon_info->ob;
1224 1208
1226 1210
1227/* mon_info_msg() - generate a message detailing the properties 1211/* mon_info_msg() - generate a message detailing the properties
1228 * of a randomly selected monster. 1212 * of a randomly selected monster.
1229 */ 1213 */
1230static const char * 1214static const char *
1231mon_info_msg (int level, int booksize) 1215mon_info_msg (int level)
1232{ 1216{
1233 static dynbuf_text buf; buf.clear (); 1217 static dynbuf_text buf; buf.clear ();
1234 1218
1235 /*preamble */ 1219 /*preamble */
1236 buf << "This beastiary contains:\n"; 1220 buf << "This beastiary contains:\n";
1262 1246
1263/* artifact_msg() - generate a message detailing the properties 1247/* artifact_msg() - generate a message detailing the properties
1264 * of 1-6 artifacts drawn sequentially from the artifact list. 1248 * of 1-6 artifacts drawn sequentially from the artifact list.
1265 */ 1249 */
1266static const char * 1250static const char *
1267artifact_msg (int level, int booksize) 1251artifact_msg (int level)
1268{ 1252{
1269 artifactlist *al = NULL; 1253 artifactlist *al = NULL;
1270 artifact *art; 1254 artifact *art;
1271 int chance, i, type, index; 1255 int chance, i, type, index;
1272 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1; 1256 int book_entries = level > 5 ? rndm (3) + rndm (3) + 2 : rndm (level) + 1;
1391/* spellpath_msg() - generate a message detailing the member 1375/* spellpath_msg() - generate a message detailing the member
1392 * incantations/prayers (and some of their properties) belonging to 1376 * incantations/prayers (and some of their properties) belonging to
1393 * a given spellpath. 1377 * a given spellpath.
1394 */ 1378 */
1395static char * 1379static char *
1396spellpath_msg (int level, int booksize) 1380spellpath_msg (int level)
1397{ 1381{
1398 static dynbuf_text buf; buf.clear (); 1382 static dynbuf_text buf; buf.clear ();
1399 1383
1400 static char retbuf[BOOK_BUF]; 1384 static char retbuf[BOOK_BUF];
1401 char tmpbuf[BOOK_BUF]; 1385 char tmpbuf[BOOK_BUF];
1427 } 1411 }
1428 1412
1429 /* Geez, no spells were generated. */ 1413 /* Geez, no spells were generated. */
1430 if (!seen) 1414 if (!seen)
1431 if (rndm (4)) /* usually, lets make a recursive call... */ 1415 if (rndm (4)) /* usually, lets make a recursive call... */
1432 return spellpath_msg (level, booksize); 1416 return spellpath_msg (level);
1433 else /* give up, cause knowing no spells exist for path is info too. */ 1417 else /* give up, cause knowing no spells exist for path is info too. */
1434 buf << "- no known spells exist.\n"; 1418 buf << "- no known spells exist.\n";
1435 1419
1436 return buf; 1420 return buf;
1437} 1421}
1568 1552
1569/* god_info_msg() - generate a message detailing the properties 1553/* god_info_msg() - generate a message detailing the properties
1570 * of a random god. Used by the book hack. b.t. 1554 * of a random god. Used by the book hack. b.t.
1571 */ 1555 */
1572static const char * 1556static const char *
1573god_info_msg (int level, int booksize) 1557god_info_msg (int level)
1574{ 1558{
1575 const char *name = NULL; 1559 const char *name = NULL;
1576 object *god = pntr_to_god_obj (get_rand_god ()); 1560 object *god = pntr_to_god_obj (get_rand_god ());
1577 1561
1578 static dynbuf_text buf; buf.clear (); 1562 static dynbuf_text buf; buf.clear ();
1760 * 1744 *
1761 */ 1745 */
1762void 1746void
1763tailor_readable_ob (object *book, int msg_type) 1747tailor_readable_ob (object *book, int msg_type)
1764{ 1748{
1765 char msgbuf[BOOK_BUF];
1766 int level = book->level ? rndm (book->level) + 1 : 1; 1749 int level = book->level ? rndm (book->level) + 1 : 1;
1767 int book_buf_size;
1768 1750
1769 /* safety */ 1751 /* safety */
1770 if (book->type != BOOK) 1752 if (book->type != BOOK)
1771 return; 1753 return;
1772 1754
1773 if (level <= 0) 1755 if (level <= 0)
1774 return; /* if no level no point in doing any more... */ 1756 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 1757
1779 /* &&& The message switch &&& */ 1758 /* &&& The message switch &&& */
1780 /* Below all of the possible types of messages in the "book"s. 1759 /* Below all of the possible types of messages in the "book"s.
1781 */ 1760 */
1782 /* 1761 /*
1785 * 2) make sure there is an entry in max_titles[] array. 1764 * 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() 1765 * 3) make sure there are entries for your case in new_text_title()
1787 * and add_authour(). 1766 * and add_authour().
1788 * 4) you may want separate authour/book name arrays in read.h 1767 * 4) you may want separate authour/book name arrays in read.h
1789 */ 1768 */
1769 const char *new_msg = "";
1790 msg_type = msg_type > 0 ? msg_type : rndm (8); 1770 msg_type = msg_type > 0 ? msg_type : rndm (8);
1791 switch (msg_type) 1771 switch (msg_type)
1792 { 1772 {
1793 case 1: /* monster attrib */ 1773 case 1: /* monster attrib */
1794 strcpy (msgbuf, mon_info_msg (level, book_buf_size)); 1774 new_msg = mon_info_msg (level);
1795 break; 1775 break;
1796 case 2: /* artifact attrib */ 1776 case 2: /* artifact attrib */
1797 strcpy (msgbuf, artifact_msg (level, book_buf_size)); 1777 new_msg = artifact_msg (level);
1798 break; 1778 break;
1799 case 3: /* grouping incantations/prayers by path */ 1779 case 3: /* grouping incantations/prayers by path */
1800 strcpy (msgbuf, spellpath_msg (level, book_buf_size)); 1780 new_msg = spellpath_msg (level);
1801 break; 1781 break;
1802 case 4: /* describe an alchemy formula */ 1782 case 4: /* describe an alchemy formula */
1803 make_formula_book (book, level); 1783 make_formula_book (book, level);
1804 /* make_formula_book already gives title */ 1784 /* make_formula_book already gives title */
1805 return; 1785 return;
1806 case 5: /* bits of information about a god */ 1786 case 5: /* bits of information about a god */
1807 strcpy (msgbuf, god_info_msg (level, book_buf_size)); 1787 new_msg = god_info_msg (level);
1808 break; 1788 break;
1809 case 0: /* use info list in lib/ */ 1789 case 0: /* use info list in lib/ */
1810 default: 1790 default:
1811 cfperl_make_book (book, level); 1791 cfperl_make_book (book, level);
1812 /* already gives title */ 1792 /* already gives title */
1813 return; 1793 return;
1814 } 1794 }
1815 1795
1816 if (strlen (msgbuf) > 1) 1796 if (strlen (new_msg) > 1)
1817 { 1797 {
1818 book->msg = msgbuf; 1798 book->msg = new_msg;
1819 /* lets give the "book" a new name, which may be a compound word */ 1799 /* lets give the "book" a new name, which may be a compound word */
1820 change_book (book, msg_type); 1800 change_book (book, msg_type);
1821 } 1801 }
1822} 1802}
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 1803
1868/***************************************************************************** 1804/*****************************************************************************
1869 * 1805 *
1870 * Writeback routine for updating the bookarchive. 1806 * Writeback routine for updating the bookarchive.
1871 * 1807 *
1872 ****************************************************************************/ 1808 ****************************************************************************/
1873
1874/* write_book_archive() - write out the updated book archive */ 1809/* write_book_archive() - write out the updated book archive */
1875
1876void 1810void
1877write_book_archive (void) 1811write_book_archive (void)
1878{ 1812{
1879 FILE *fp; 1813 FILE *fp;
1880 int index = 0; 1814 int index = 0;
1883 titlelist *bl = get_titlelist (0); 1817 titlelist *bl = get_titlelist (0);
1884 1818
1885 /* If nothing changed, don't write anything */ 1819 /* If nothing changed, don't write anything */
1886 if (!need_to_write_bookarchive) 1820 if (!need_to_write_bookarchive)
1887 return; 1821 return;
1822
1888 need_to_write_bookarchive = 0; 1823 need_to_write_bookarchive = 0;
1889 1824
1890 sprintf (fname, "%s/bookarch", settings.localdir); 1825 sprintf (fname, "%s/bookarch", settings.localdir);
1891 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1826 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1892 1827
1893 if ((fp = fopen (fname, "w")) == NULL) 1828 if ((fp = fopen (fname, "w")) == NULL)
1894 {
1895 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1829 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1896 }
1897 else 1830 else
1898 { 1831 {
1899 while (bl) 1832 while (bl)
1900 { 1833 {
1901 for (book = bl->first_book; book; book = book->next) 1834 for (book = bl->first_book; book; book = book->next)
1908 fprintf (fp, "type %d\n", index); 1841 fprintf (fp, "type %d\n", index);
1909 fprintf (fp, "size %d\n", book->size); 1842 fprintf (fp, "size %d\n", book->size);
1910 fprintf (fp, "index %d\n", book->msg_index); 1843 fprintf (fp, "index %d\n", book->msg_index);
1911 fprintf (fp, "end\n"); 1844 fprintf (fp, "end\n");
1912 } 1845 }
1846
1913 bl = bl->next; 1847 bl = bl->next;
1914 index++; 1848 index++;
1915 } 1849 }
1850
1916 fclose (fp); 1851 fclose (fp);
1917 chmod (fname, SAVE_MODE); 1852 chmod (fname, SAVE_MODE);
1918 } 1853 }
1919} 1854}
1855
1920readable_message_type * 1856readable_message_type *
1921get_readable_message_type (object *readable) 1857get_readable_message_type (object *readable)
1922{ 1858{
1923 uint8 subtype = readable->subtype; 1859 uint8 subtype = readable->subtype;
1924 1860

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines