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.47 by root, Thu Oct 15 23:24:38 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}
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 strcat (msgbuf, "\n"); /* safety -- we get ugly map saves/crashes w/o this */
1817
1818 if (strlen (msgbuf) > 1) 1812 if (strlen (new_msg) > 1)
1819 { 1813 {
1820 book->msg = msgbuf; 1814 book->msg = new_msg;
1821 /* 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 */
1822 change_book (book, msg_type); 1816 change_book (book, msg_type);
1823 } 1817 }
1824} 1818}
1825
1826 1819
1827/***************************************************************************** 1820/*****************************************************************************
1828 * 1821 *
1829 * Cleanup routine for readble stuff. 1822 * Cleanup routine for readble stuff.
1830 * 1823 *
1831 *****************************************************************************/ 1824 *****************************************************************************/
1832 1825static void
1833void
1834free_all_readable (void) 1826free_all_readable (void)
1835{ 1827{
1836 titlelist *tlist, *tnext; 1828 titlelist *tlist, *tnext;
1837 title *title1, *titlenext; 1829 title *title1, *titlenext;
1838 linked_char *lmsg, *nextmsg; 1830 linked_char *lmsg, *nextmsg;
1864 nextmon = monlink->next; 1856 nextmon = monlink->next;
1865 delete monlink; 1857 delete monlink;
1866 } 1858 }
1867} 1859}
1868 1860
1869
1870/***************************************************************************** 1861/*****************************************************************************
1871 * 1862 *
1872 * Writeback routine for updating the bookarchive. 1863 * Writeback routine for updating the bookarchive.
1873 * 1864 *
1874 ****************************************************************************/ 1865 ****************************************************************************/
1875
1876/* write_book_archive() - write out the updated book archive */ 1866/* write_book_archive() - write out the updated book archive */
1877
1878void 1867void
1879write_book_archive (void) 1868write_book_archive (void)
1880{ 1869{
1881 FILE *fp; 1870 FILE *fp;
1882 int index = 0; 1871 int index = 0;
1885 titlelist *bl = get_titlelist (0); 1874 titlelist *bl = get_titlelist (0);
1886 1875
1887 /* If nothing changed, don't write anything */ 1876 /* If nothing changed, don't write anything */
1888 if (!need_to_write_bookarchive) 1877 if (!need_to_write_bookarchive)
1889 return; 1878 return;
1879
1890 need_to_write_bookarchive = 0; 1880 need_to_write_bookarchive = 0;
1891 1881
1892 sprintf (fname, "%s/bookarch", settings.localdir); 1882 sprintf (fname, "%s/bookarch", settings.localdir);
1893 LOG (llevDebug, "Updating book archive: %s...\n", fname); 1883 LOG (llevDebug, "Updating book archive: %s...\n", fname);
1894 1884
1895 if ((fp = fopen (fname, "w")) == NULL) 1885 if ((fp = fopen (fname, "w")) == NULL)
1896 {
1897 LOG (llevDebug, "Can't open book archive file %s\n", fname); 1886 LOG (llevDebug, "Can't open book archive file %s\n", fname);
1898 }
1899 else 1887 else
1900 { 1888 {
1901 while (bl) 1889 while (bl)
1902 { 1890 {
1903 for (book = bl->first_book; book; book = book->next) 1891 for (book = bl->first_book; book; book = book->next)
1910 fprintf (fp, "type %d\n", index); 1898 fprintf (fp, "type %d\n", index);
1911 fprintf (fp, "size %d\n", book->size); 1899 fprintf (fp, "size %d\n", book->size);
1912 fprintf (fp, "index %d\n", book->msg_index); 1900 fprintf (fp, "index %d\n", book->msg_index);
1913 fprintf (fp, "end\n"); 1901 fprintf (fp, "end\n");
1914 } 1902 }
1903
1915 bl = bl->next; 1904 bl = bl->next;
1916 index++; 1905 index++;
1917 } 1906 }
1907
1918 fclose (fp); 1908 fclose (fp);
1919 chmod (fname, SAVE_MODE); 1909 chmod (fname, SAVE_MODE);
1920 } 1910 }
1921} 1911}
1912
1922readable_message_type * 1913readable_message_type *
1923get_readable_message_type (object *readable) 1914get_readable_message_type (object *readable)
1924{ 1915{
1925 uint8 subtype = readable->subtype; 1916 uint8 subtype = readable->subtype;
1926 1917

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines