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.51 by root, Fri Nov 6 13:03:34 2009 UTC vs.
Revision 1.58 by root, Thu Apr 15 21:49:15 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
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,
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;
545/* get_titlelist() - returns pointer to the title list referanced by i */ 534/* get_titlelist() - returns pointer to the title list referanced by i */
546 535
547static titlelist * 536static titlelist *
548get_titlelist (int i) 537get_titlelist (int i)
549{ 538{
539 if (!booklist)
540 booklist = get_empty_booklist ();
541
550 titlelist *tl = booklist; 542 titlelist *tl = booklist;
551 int number = i; 543 int number = i;
552 544
553 if (number < 0) 545 if (number < 0)
554 return tl; 546 return tl;
557 { 549 {
558 if (!tl->next) 550 if (!tl->next)
559 tl->next = get_empty_booklist (); 551 tl->next = get_empty_booklist ();
560 552
561 tl = tl->next; 553 tl = tl->next;
562 number--; 554 --number;
563 } 555 }
564 556
565 return tl; 557 return tl;
566} 558}
567 559
619 tbuf = strtok (NULL, sbuf); 611 tbuf = strtok (NULL, sbuf);
620 } 612 }
621 return (char *) rbuf; 613 return (char *) rbuf;
622} 614}
623 615
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/***************************************************************************** 616/*****************************************************************************
635 * 617 *
636 * Start of initialisation related functions. 618 * Start of initialisation related functions.
637 * 619 *
638 ****************************************************************************/ 620 ****************************************************************************/
640/* init_book_archive() - if not called before, initialise the info list 622/* init_book_archive() - if not called before, initialise the info list
641 * This reads in the bookarch file into memory. bookarch is the file 623 * This reads in the bookarch file into memory. bookarch is the file
642 * created and updated across multiple runs of the program. 624 * created and updated across multiple runs of the program.
643 */ 625 */
644static void 626static void
645init_book_archive (void) 627init_book_archive ()
646{ 628{
647 FILE *fp;
648 int comp, nroftitle = 0; 629 int nroftitle = 0;
649 char buf[MAX_BUF], fname[MAX_BUF], *cp; 630 char fname[MAX_BUF];
650 title *book = NULL;
651 titlelist *bl = get_empty_booklist (); 631 titlelist *bl = get_empty_booklist ();
652 static int did_init_barch;
653
654 if (did_init_barch)
655 return;
656
657 did_init_barch = 1;
658
659 if (!booklist)
660 booklist = bl;
661 632
662 sprintf (fname, "%s/bookarch", settings.localdir); 633 sprintf (fname, "%s/bookarch", settings.localdir);
663 LOG (llevDebug, " Reading bookarch from %s...\n", fname); 634 LOG (llevDebug, " Reading bookarch from %s...\n", fname);
664 635
665 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL) 636 object_thawer thawer (fname);
637
638 if (!thawer)
639 {
640 LOG (llevDebug, "could not read bookarch file\n");
641 return;
666 { 642 }
643
644 while (thawer.kw)
645 {
646 if (thawer.kw != KW_title)
647 if (!thawer.parse_error ("bookarch file"))
648 break;
649
650 title *book = get_empty_book (); /* init new book entry */
651 thawer.get (book->name);
652
667 int value, type = 0; 653 int type = -1;
668 size_t i;
669 654
670 while (fgets (buf, MAX_BUF, fp) != NULL) 655 for (;;)
671 { 656 {
672 if (*buf == '#') 657 thawer.next ();
673 continue; 658
674 if ((cp = strchr (buf, '\n')) != NULL) 659 switch (thawer.kw)
675 *cp = '\0';
676 cp = buf;
677 while (*cp == ' ') /* Skip blanks */
678 cp++;
679 if (!strncmp (cp, "title", 4))
680 { 660 {
681 book = get_empty_book (); /* init new book entry */ 661 case KW_type: thawer.get (type ); break;
682 book->name = strchr (cp, ' ') + 1; 662 case KW_authour: thawer.get (book->authour ); break;
683 type = -1; 663 case KW_arch: thawer.get (book->archname ); break;
684 nroftitle++; 664 case KW_level: thawer.get (book->level ); break;
685 continue; 665 case KW_size: thawer.get (book->size ); break;
686 } 666 case KW_index: thawer.get (book->msg_index); break;
687 if (!strncmp (cp, "authour", 4)) 667
688 { 668 case KW_end:
689 book->authour = strchr (cp, ' ') + 1;
690 }
691 if (!strncmp (cp, "arch", 4))
692 {
693 book->archname = strchr (cp, ' ') + 1;
694 }
695 else if (sscanf (cp, "level %d", &value))
696 {
697 book->level = (uint16) value;
698 }
699 else if (sscanf (cp, "type %d", &value))
700 {
701 type = (uint16) value;
702 }
703 else if (sscanf (cp, "size %d", &value))
704 {
705 book->size = (uint16) value;
706 }
707 else if (sscanf (cp, "index %d", &value))
708 {
709 book->msg_index = (uint16) value;
710 }
711 else if (!strncmp (cp, "end", 3))
712 { /* link it */ 669 /* link it */
713 bl = get_titlelist (type); 670 bl = get_titlelist (type);
714 book->next = bl->first_book; 671 book->next = bl->first_book;
715 bl->first_book = book; 672 bl->first_book = book;
716 bl->number++; 673 bl->number++;
674 ++nroftitle;
675 goto book_done;
676
677 default:
678 delete book;
679 goto book_done;
717 } 680 }
718 } 681 }
682
683book_done:
684 thawer.next ();
685 }
686
719 LOG (llevDebug, "book archives(used/avail): \n"); 687 LOG (llevDebug, "book archives(used/avail): \n");
688 int i;
720 for (bl = booklist, i = 0; bl != NULL && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) 689 for (bl = booklist, i = 0; bl && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++)
721 {
722 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); 690 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]);
723 }
724 close_and_delete (fp, comp);
725 }
726 691
727#ifdef BOOK_MSG_DEBUG
728 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); 692 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle);
729#endif
730 LOG (llevDebug, " done.\n"); 693 LOG (llevDebug, " done.\n");
731} 694}
732 695
733/* init_mon_info() - creates the linked list of pointers to 696/* init_mon_info() - creates the linked list of pointers to
734 * monster archetype objects if not called previously 697 * monster archetype objects if not called previously
765 * 728 *
766 * This is the function called by the main routine to initialise 729 * This is the function called by the main routine to initialise
767 * all the readable information. 730 * all the readable information.
768 */ 731 */
769void 732void
770init_readable (void) 733init_readable ()
771{ 734{
772 static int did_this; 735 static int did_this;
773 736
774 if (did_this) 737 if (did_this)
775 return; 738 return;
1369 1332
1370 /* properties of the artifact */ 1333 /* properties of the artifact */
1371 tmp = object::create (); 1334 tmp = object::create ();
1372 add_abilities (tmp, art->item); 1335 add_abilities (tmp, art->item);
1373 tmp->type = type; 1336 tmp->type = type;
1374 SET_FLAG (tmp, FLAG_IDENTIFIED); 1337 tmp->set_flag (FLAG_IDENTIFIED);
1375 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) 1338 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1)
1376 buf << "\rProperties of this artifact include:\r" << ch << "\n"; 1339 buf << "\rProperties of this artifact include:\r" << ch << "\n";
1377 1340
1378 tmp->destroy (); 1341 tmp->destroy ();
1379 1342
1817 } 1780 }
1818} 1781}
1819 1782
1820/***************************************************************************** 1783/*****************************************************************************
1821 * 1784 *
1822 * Cleanup routine for readble stuff.
1823 *
1824 *****************************************************************************/
1825static void
1826free_all_readable (void)
1827{
1828 titlelist *tlist, *tnext;
1829 title *title1, *titlenext;
1830 linked_char *lmsg, *nextmsg;
1831 objectlink *monlink, *nextmon;
1832
1833 LOG (llevDebug, "freeing all book information\n");
1834
1835 for (tlist = booklist; tlist; tlist = tnext)
1836 {
1837 tnext = tlist->next;
1838
1839 for (title1 = tlist->first_book; title1; title1 = titlenext)
1840 {
1841 titlenext = title1->next;
1842 delete title1;
1843 }
1844
1845 delete tlist;
1846 }
1847
1848 for (lmsg = first_msg; lmsg; lmsg = nextmsg)
1849 {
1850 nextmsg = lmsg->next;
1851 delete lmsg;
1852 }
1853
1854 for (monlink = first_mon_info; monlink; monlink = nextmon)
1855 {
1856 nextmon = monlink->next;
1857 delete monlink;
1858 }
1859}
1860
1861/*****************************************************************************
1862 *
1863 * Writeback routine for updating the bookarchive. 1785 * Writeback routine for updating the bookarchive.
1864 * 1786 *
1865 ****************************************************************************/ 1787 ****************************************************************************/
1866/* write_book_archive() - write out the updated book archive */ 1788/* write_book_archive() - write out the updated book archive */
1867void 1789void
1868write_book_archive (void) 1790write_book_archive ()
1869{ 1791{
1870 FILE *fp; 1792 FILE *fp;
1871 int index = 0; 1793 int index = 0;
1872 char fname[MAX_BUF]; 1794 char fname[MAX_BUF];
1873 title *book = NULL; 1795 title *book = NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines