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.52 by root, Fri Nov 6 13:31:47 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.
107 107
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
113/* first_msg is the started of the linked list of messages as read from
114 * the messages file
115 */
116static linked_char *first_msg = NULL;
117 112
118/* 113/*
119 * Spellpath information 114 * Spellpath information
120 */ 115 */
121static uint32 spellpathdef[NRSPELLPATHS] = { 116static uint32 spellpathdef[NRSPELLPATHS] = {
509 * 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
510 * 505 *
511 *****************************************************************************/ 506 *****************************************************************************/
512 507
513static titlelist * 508static titlelist *
514get_empty_booklist (void) 509get_empty_booklist ()
515{ 510{
516 titlelist *bl = new titlelist; 511 titlelist *bl = new titlelist;
517 512
518 bl->number = 0; 513 bl->number = 0;
519 bl->first_book = NULL; 514 bl->first_book = NULL;
520 bl->next = NULL; 515 bl->next = NULL;
521 return bl; 516 return bl;
522} 517}
523 518
524static title * 519static title *
525get_empty_book (void) 520get_empty_book ()
526{ 521{
527 title *t = new title; 522 title *t = new title;
528 523
529 t->name = NULL; 524 t->name = NULL;
530 t->archname = NULL; 525 t->archname = NULL;
539/* get_titlelist() - returns pointer to the title list referanced by i */ 534/* get_titlelist() - returns pointer to the title list referanced by i */
540 535
541static titlelist * 536static titlelist *
542get_titlelist (int i) 537get_titlelist (int i)
543{ 538{
539 if (!booklist)
540 booklist = get_empty_booklist ();
541
544 titlelist *tl = booklist; 542 titlelist *tl = booklist;
545 int number = i; 543 int number = i;
546 544
547 if (number < 0) 545 if (number < 0)
548 return tl; 546 return tl;
551 { 549 {
552 if (!tl->next) 550 if (!tl->next)
553 tl->next = get_empty_booklist (); 551 tl->next = get_empty_booklist ();
554 552
555 tl = tl->next; 553 tl = tl->next;
556 number--; 554 --number;
557 } 555 }
558 556
559 return tl; 557 return tl;
560} 558}
561 559
624/* init_book_archive() - if not called before, initialise the info list 622/* init_book_archive() - if not called before, initialise the info list
625 * 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
626 * created and updated across multiple runs of the program. 624 * created and updated across multiple runs of the program.
627 */ 625 */
628static void 626static void
629init_book_archive (void) 627init_book_archive ()
630{ 628{
631 FILE *fp;
632 int comp, nroftitle = 0; 629 int nroftitle = 0;
633 char buf[MAX_BUF], fname[MAX_BUF], *cp; 630 char fname[MAX_BUF];
634 title *book = NULL;
635 titlelist *bl = get_empty_booklist (); 631 titlelist *bl = get_empty_booklist ();
636 static int did_init_barch;
637
638 if (did_init_barch)
639 return;
640
641 did_init_barch = 1;
642
643 if (!booklist)
644 booklist = bl;
645 632
646 sprintf (fname, "%s/bookarch", settings.localdir); 633 sprintf (fname, "%s/bookarch", settings.localdir);
647 LOG (llevDebug, " Reading bookarch from %s...\n", fname); 634 LOG (llevDebug, " Reading bookarch from %s...\n", fname);
648 635
649 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;
650 { 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
651 int value, type = 0; 653 int type = -1;
652 size_t i;
653 654
654 while (fgets (buf, MAX_BUF, fp) != NULL) 655 for (;;)
655 { 656 {
656 if (*buf == '#') 657 thawer.next ();
657 continue; 658
658 if ((cp = strchr (buf, '\n')) != NULL) 659 switch (thawer.kw)
659 *cp = '\0';
660 cp = buf;
661 while (*cp == ' ') /* Skip blanks */
662 cp++;
663 if (!strncmp (cp, "title", 4))
664 { 660 {
665 book = get_empty_book (); /* init new book entry */ 661 case KW_type: thawer.get (type ); break;
666 book->name = strchr (cp, ' ') + 1; 662 case KW_authour: thawer.get (book->authour ); break;
667 type = -1; 663 case KW_arch: thawer.get (book->archname ); break;
668 nroftitle++; 664 case KW_level: thawer.get (book->level ); break;
669 continue; 665 case KW_size: thawer.get (book->size ); break;
670 } 666 case KW_index: thawer.get (book->msg_index); break;
671 if (!strncmp (cp, "authour", 4)) 667
672 { 668 case KW_end:
673 book->authour = strchr (cp, ' ') + 1;
674 }
675 if (!strncmp (cp, "arch", 4))
676 {
677 book->archname = strchr (cp, ' ') + 1;
678 }
679 else if (sscanf (cp, "level %d", &value))
680 {
681 book->level = (uint16) value;
682 }
683 else if (sscanf (cp, "type %d", &value))
684 {
685 type = (uint16) value;
686 }
687 else if (sscanf (cp, "size %d", &value))
688 {
689 book->size = (uint16) value;
690 }
691 else if (sscanf (cp, "index %d", &value))
692 {
693 book->msg_index = (uint16) value;
694 }
695 else if (!strncmp (cp, "end", 3))
696 { /* link it */ 669 /* link it */
697 bl = get_titlelist (type); 670 bl = get_titlelist (type);
698 book->next = bl->first_book; 671 book->next = bl->first_book;
699 bl->first_book = book; 672 bl->first_book = book;
700 bl->number++; 673 bl->number++;
674 ++nroftitle;
675 goto book_done;
676
677 default:
678 delete book;
679 goto book_done;
701 } 680 }
702 } 681 }
682
683book_done:
684 thawer.next ();
685 }
686
703 LOG (llevDebug, "book archives(used/avail): \n"); 687 LOG (llevDebug, "book archives(used/avail): \n");
688 int i;
704 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++)
705 {
706 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); 690 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]);
707 }
708 close_and_delete (fp, comp);
709 }
710 691
711#ifdef BOOK_MSG_DEBUG
712 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); 692 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle);
713#endif
714 LOG (llevDebug, " done.\n"); 693 LOG (llevDebug, " done.\n");
715} 694}
716 695
717/* init_mon_info() - creates the linked list of pointers to 696/* init_mon_info() - creates the linked list of pointers to
718 * monster archetype objects if not called previously 697 * monster archetype objects if not called previously
749 * 728 *
750 * This is the function called by the main routine to initialise 729 * This is the function called by the main routine to initialise
751 * all the readable information. 730 * all the readable information.
752 */ 731 */
753void 732void
754init_readable (void) 733init_readable ()
755{ 734{
756 static int did_this; 735 static int did_this;
757 736
758 if (did_this) 737 if (did_this)
759 return; 738 return;
1353 1332
1354 /* properties of the artifact */ 1333 /* properties of the artifact */
1355 tmp = object::create (); 1334 tmp = object::create ();
1356 add_abilities (tmp, art->item); 1335 add_abilities (tmp, art->item);
1357 tmp->type = type; 1336 tmp->type = type;
1358 SET_FLAG (tmp, FLAG_IDENTIFIED); 1337 tmp->set_flag (FLAG_IDENTIFIED);
1359 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) 1338 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1)
1360 buf << "\rProperties of this artifact include:\r" << ch << "\n"; 1339 buf << "\rProperties of this artifact include:\r" << ch << "\n";
1361 1340
1362 tmp->destroy (); 1341 tmp->destroy ();
1363 1342
1806 * Writeback routine for updating the bookarchive. 1785 * Writeback routine for updating the bookarchive.
1807 * 1786 *
1808 ****************************************************************************/ 1787 ****************************************************************************/
1809/* write_book_archive() - write out the updated book archive */ 1788/* write_book_archive() - write out the updated book archive */
1810void 1789void
1811write_book_archive (void) 1790write_book_archive ()
1812{ 1791{
1813 FILE *fp; 1792 FILE *fp;
1814 int index = 0; 1793 int index = 0;
1815 char fname[MAX_BUF]; 1794 char fname[MAX_BUF];
1816 title *book = NULL; 1795 title *book = NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines