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.55 by root, Fri Mar 26 00:59:20 2010 UTC vs.
Revision 1.60 by root, Sun Oct 24 21:24:09 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 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 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
401static const char *const book_descrpt[] = { 401static const char *const book_descrpt[] = {
402 "ancient", 402 "ancient",
403 "cryptic", 403 "cryptic",
404 "cryptical", 404 "cryptical",
405 "dusty", 405 "dusty",
406 "hiearchical", 406 "hierarchical",
407 "grizzled", 407 "grizzled",
408 "gold-guilt", 408 "gold-guilt",
409 "great", 409 "great",
410 "lost", 410 "lost",
411 "magnificent", 411 "magnificent",
534/* get_titlelist() - returns pointer to the title list referanced by i */ 534/* get_titlelist() - returns pointer to the title list referanced by i */
535 535
536static titlelist * 536static titlelist *
537get_titlelist (int i) 537get_titlelist (int i)
538{ 538{
539 if (!booklist)
540 booklist = get_empty_booklist ();
541
539 titlelist *tl = booklist; 542 titlelist *tl = booklist;
540 int number = i; 543 int number = i;
541 544
542 if (number < 0) 545 if (number < 0)
543 return tl; 546 return tl;
546 { 549 {
547 if (!tl->next) 550 if (!tl->next)
548 tl->next = get_empty_booklist (); 551 tl->next = get_empty_booklist ();
549 552
550 tl = tl->next; 553 tl = tl->next;
551 number--; 554 --number;
552 } 555 }
553 556
554 return tl; 557 return tl;
555} 558}
556 559
566 char *tbuf, sbuf[12], buf[MAX_BUF]; 569 char *tbuf, sbuf[12], buf[MAX_BUF];
567 int number = 0; 570 int number = 0;
568 571
569 if (!buf1 || !buf2) 572 if (!buf1 || !buf2)
570 return 0; 573 return 0;
571 sprintf (buf, "%s", buf1); 574
572 sprintf (sbuf, "%s", buf2); 575 strcpy (buf, buf1);
576 strcpy (sbuf, buf2);
577
573 tbuf = strtok (buf, sbuf); 578 tbuf = strtok (buf, sbuf);
574 while (tbuf) 579 while (tbuf)
575 { 580 {
576 number++; 581 number++;
577 tbuf = strtok (NULL, sbuf); 582 tbuf = strtok (NULL, sbuf);
596 strcpy (rbuf, " "); 601 strcpy (rbuf, " ");
597 tbuf = strtok (buf, sbuf); 602 tbuf = strtok (buf, sbuf);
598 while (tbuf && i > 0) 603 while (tbuf && i > 0)
599 { 604 {
600 strcat (rbuf, tbuf); 605 strcat (rbuf, tbuf);
606
601 i--; 607 i--;
602 if (i == 1 && maxi > 1) 608 if (i == 1 && maxi > 1)
603 strcat (rbuf, " and "); 609 strcat (rbuf, " and ");
604 else if (i > 0 && maxi > 1) 610 else if (i > 0 && maxi > 1)
605 strcat (rbuf, ", "); 611 strcat (rbuf, ", ");
606 else 612 else
607 strcat (rbuf, "."); 613 strcat (rbuf, ".");
614
608 tbuf = strtok (NULL, sbuf); 615 tbuf = strtok (NULL, sbuf);
609 } 616 }
617
610 return (char *) rbuf; 618 return rbuf;
611} 619}
612 620
613/***************************************************************************** 621/*****************************************************************************
614 * 622 *
615 * Start of initialisation related functions. 623 * Start of initialisation related functions.
621 * created and updated across multiple runs of the program. 629 * created and updated across multiple runs of the program.
622 */ 630 */
623static void 631static void
624init_book_archive () 632init_book_archive ()
625{ 633{
626 FILE *fp;
627 int comp, nroftitle = 0; 634 int nroftitle = 0;
628 char buf[MAX_BUF], fname[MAX_BUF], *cp;
629 title *book = NULL;
630 titlelist *bl = get_empty_booklist (); 635 titlelist *bl = get_empty_booklist ();
631 static int did_init_barch;
632 636
633 if (did_init_barch) 637 object_thawer thawer (settings.localdir, "bookarch");
638
639 if (!thawer)
640 {
641 LOG (llevDebug, "could not read bookarch file\n");
634 return; 642 return;
635
636 did_init_barch = 1;
637
638 if (!booklist)
639 booklist = bl;
640
641 sprintf (fname, "%s/bookarch", settings.localdir);
642 LOG (llevDebug, " Reading bookarch from %s...\n", fname);
643
644 if ((fp = open_and_uncompress (fname, 0, &comp)) != NULL)
645 { 643 }
644
645 while (thawer.kw)
646 {
647 if (thawer.kw != KW_title)
648 if (!thawer.parse_error ("bookarch file"))
649 break;
650
651 title *book = get_empty_book (); /* init new book entry */
652 thawer.get (book->name);
653
646 int value, type = 0; 654 int type = -1;
647 size_t i;
648 655
649 while (fgets (buf, MAX_BUF, fp) != NULL) 656 for (;;)
650 { 657 {
651 if (*buf == '#') 658 thawer.next ();
652 continue; 659
653 if ((cp = strchr (buf, '\n')) != NULL) 660 switch (thawer.kw)
654 *cp = '\0';
655 cp = buf;
656 while (*cp == ' ') /* Skip blanks */
657 cp++;
658 if (!strncmp (cp, "title", 4))
659 { 661 {
660 book = get_empty_book (); /* init new book entry */ 662 case KW_type: thawer.get (type ); break;
661 book->name = strchr (cp, ' ') + 1; 663 case KW_authour: thawer.get (book->authour ); break;
662 type = -1; 664 case KW_arch: thawer.get (book->archname ); break;
663 nroftitle++; 665 case KW_level: thawer.get (book->level ); break;
664 continue; 666 case KW_size: thawer.get (book->size ); break;
665 } 667 case KW_index: thawer.get (book->msg_index); break;
666 if (!strncmp (cp, "authour", 4)) 668
667 { 669 case KW_end:
668 book->authour = strchr (cp, ' ') + 1;
669 }
670 if (!strncmp (cp, "arch", 4))
671 {
672 book->archname = strchr (cp, ' ') + 1;
673 }
674 else if (sscanf (cp, "level %d", &value))
675 {
676 book->level = (uint16) value;
677 }
678 else if (sscanf (cp, "type %d", &value))
679 {
680 type = (uint16) value;
681 }
682 else if (sscanf (cp, "size %d", &value))
683 {
684 book->size = (uint16) value;
685 }
686 else if (sscanf (cp, "index %d", &value))
687 {
688 book->msg_index = (uint16) value;
689 }
690 else if (!strncmp (cp, "end", 3))
691 { /* link it */ 670 /* link it */
692 bl = get_titlelist (type); 671 bl = get_titlelist (type);
693 book->next = bl->first_book; 672 book->next = bl->first_book;
694 bl->first_book = book; 673 bl->first_book = book;
695 bl->number++; 674 bl->number++;
675 ++nroftitle;
676 goto book_done;
677
678 default:
679 delete book;
680 goto book_done;
696 } 681 }
697 } 682 }
683
684book_done:
685 thawer.next ();
686 }
687
698 LOG (llevDebug, "book archives(used/avail): \n"); 688 LOG (llevDebug, "book archives(used/avail): \n");
689 int i;
699 for (bl = booklist, i = 0; bl != NULL && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++) 690 for (bl = booklist, i = 0; bl && i < sizeof (max_titles) / sizeof (*max_titles); bl = bl->next, i++)
700 {
701 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); 691 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]);
702 }
703 close_and_delete (fp, comp);
704 }
705 692
706#ifdef BOOK_MSG_DEBUG
707 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); 693 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle);
708#endif
709 LOG (llevDebug, " done.\n");
710} 694}
711 695
712/* init_mon_info() - creates the linked list of pointers to 696/* init_mon_info() - creates the linked list of pointers to
713 * monster archetype objects if not called previously 697 * monster archetype objects if not called previously
714 */ 698 */
806 * is given is based on various criteria 790 * is given is based on various criteria
807 */ 791 */
808static void 792static void
809new_text_name (object *book, int msgtype) 793new_text_name (object *book, int msgtype)
810{ 794{
811 int nbr; 795 const char *name;
812 char name[MAX_BUF];
813 796
814 if (book->type != BOOK) 797 if (book->type != BOOK)
815 return; 798 return;
816 799
817 switch (msgtype) 800 switch (msgtype)
818 { 801 {
819 case 1: /*monster */ 802 case 1: /*monster */
820 nbr = sizeof (mon_book_name) / sizeof (char *); 803 name = mon_book_name[rndm (array_length (mon_book_name))];
821 assign (name, mon_book_name[rndm (nbr)]);
822 break; 804 break;
823 case 2: /*artifact */ 805 case 2: /*artifact */
824 nbr = sizeof (art_book_name) / sizeof (char *); 806 name = art_book_name[rndm (array_length (art_book_name))];
825 assign (name, art_book_name[rndm (nbr)]);
826 break; 807 break;
827 case 3: /*spellpath */ 808 case 3: /*spellpath */
828 nbr = sizeof (path_book_name) / sizeof (char *); 809 name = path_book_name[rndm (array_length (path_book_name))];
829 assign (name, path_book_name[rndm (nbr)]);
830 break; 810 break;
831 case 4: /*alchemy */ 811 case 4: /*alchemy */
832 nbr = sizeof (formula_book_name) / sizeof (char *); 812 name = formula_book_name[rndm (array_length (formula_book_name))];
833 assign (name, formula_book_name[rndm (nbr)]);
834 break; 813 break;
835 case 5: /*gods */ 814 case 5: /*gods */
836 nbr = sizeof (gods_book_name) / sizeof (char *); 815 name = gods_book_name[rndm (array_length (gods_book_name))];
837 assign (name, gods_book_name[rndm (nbr)]);
838 break; 816 break;
839 case 6: /*msg file */ 817 case 6: /*msg file */
840 default: 818 default:
841 if (book->weight > 2000) 819 if (book->weight > 2000)
842 { /* based on weight */ 820 { /* based on weight */
843 nbr = sizeof (heavy_book_name) / sizeof (char *); 821 name = heavy_book_name[rndm (array_length (heavy_book_name))];
844 assign (name, heavy_book_name[rndm (nbr)]);
845 } 822 }
846 else if (book->weight < 2001) 823 else if (book->weight < 2001)
847 { 824 {
848 nbr = sizeof (light_book_name) / sizeof (char *); 825 name = light_book_name[rndm (array_length (light_book_name))];
849 assign (name, light_book_name[rndm (nbr)]);
850 } 826 }
851 break; 827 break;
852 } 828 }
853 829
854 book->name = name; 830 book->name = name;
860 */ 836 */
861 837
862static void 838static void
863add_author (object *op, int msgtype) 839add_author (object *op, int msgtype)
864{ 840{
865 char title[MAX_BUF], name[MAX_BUF]; 841 const char *name;
866 int nbr = sizeof (book_author) / sizeof (char *);
867 842
868 if (msgtype < 0 || strlen (op->msg) < 5) 843 if (msgtype < 0 || strlen (op->msg) < 5)
869 return; 844 return;
870 845
871 switch (msgtype) 846 switch (msgtype)
872 { 847 {
873 case 1: /* monster */ 848 case 1: /* monster */
874 nbr = sizeof (mon_author) / sizeof (char *); 849 name = mon_author[rndm (array_length (mon_author))];
875 assign (name, mon_author[rndm (nbr)]);
876 break; 850 break;
877 case 2: /* artifacts */ 851 case 2: /* artifacts */
878 nbr = sizeof (art_author) / sizeof (char *); 852 name = art_author[rndm (array_length (art_author))];
879 assign (name, art_author[rndm (nbr)]);
880 break; 853 break;
881 case 3: /* spellpath */ 854 case 3: /* spellpath */
882 nbr = sizeof (path_author) / sizeof (char *); 855 name = path_author[rndm (array_length (path_author))];
883 assign (name, path_author[rndm (nbr)]);
884 break; 856 break;
885 case 4: /* alchemy */ 857 case 4: /* alchemy */
886 nbr = sizeof (formula_author) / sizeof (char *); 858 name = formula_author[rndm (array_length (formula_author))];
887 assign (name, formula_author[rndm (nbr)]);
888 break; 859 break;
889 case 5: /* gods */ 860 case 5: /* gods */
890 nbr = sizeof (gods_author) / sizeof (char *); 861 name = gods_author[rndm (array_length (gods_author))];
891 assign (name, gods_author[rndm (nbr)]);
892 break; 862 break;
893 case 6: /* msg file */ 863 case 6: /* msg file */
894 default: 864 default:
895 assign (name, book_author[rndm (nbr)]); 865 name = book_author[rndm (array_length (book_author))];
896 } 866 }
897 867
898 sprintf (title, "of %s", name); 868 op->title = format ("of %s", name);
899 op->title = title;
900} 869}
901 870
902/* unique_book() - check to see if the book title/msg is unique. We 871/* unique_book() - check to see if the book title/msg is unique. We
903 * go through the entire list of possibilities each time. If we find 872 * go through the entire list of possibilities each time. If we find
904 * a match, then unique_book returns true (because inst unique). 873 * a match, then unique_book returns true (because inst unique).
1054#endif 1023#endif
1055 /* restore old book properties here */ 1024 /* restore old book properties here */
1056 book->title = old_title; 1025 book->title = old_title;
1057 1026
1058 if (rndm (4)) 1027 if (rndm (4))
1059 {
1060 /* Lets give the book a description to individualize it some */ 1028 /* Lets give the book a description to individualize it some */
1061 char new_name[MAX_BUF];
1062
1063 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); 1029 book->name = format ("%s %s", book_descrpt[rndm (nbr)], old_name);
1064
1065 book->name = new_name;
1066 }
1067 else 1030 else
1068 {
1069 book->name = old_name; 1031 book->name = old_name;
1070 }
1071 } 1032 }
1072 else if (book->title && strlen (book->msg) > 5) 1033 else if (book->title && strlen (book->msg) > 5)
1073 { /* archive if long msg texts */ 1034 { /* archive if long msg texts */
1074 add_book_to_list (book, msgtype); 1035 add_book_to_list (book, msgtype);
1075 } 1036 }
1265 * for that type exists! 1226 * for that type exists!
1266 */ 1227 */
1267 i = 0; 1228 i = 0;
1268 do 1229 do
1269 { 1230 {
1270 index = rndm (sizeof (art_name_array) / sizeof (arttypename)); 1231 index = rndm (array_length (art_name_array));
1271 type = art_name_array[index].type; 1232 type = art_name_array[index].type;
1272 al = find_artifactlist (type); 1233 al = find_artifactlist (type);
1273 i++; 1234 i++;
1274 } 1235 }
1275 while ((al == NULL) && (i < 10)); 1236 while ((al == NULL) && (i < 10));
1348 1309
1349 /* properties of the artifact */ 1310 /* properties of the artifact */
1350 tmp = object::create (); 1311 tmp = object::create ();
1351 add_abilities (tmp, art->item); 1312 add_abilities (tmp, art->item);
1352 tmp->type = type; 1313 tmp->type = type;
1353 SET_FLAG (tmp, FLAG_IDENTIFIED); 1314 tmp->set_flag (FLAG_IDENTIFIED);
1354 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1) 1315 if ((ch = describe_item (tmp, 0)) && strlen (ch) > 1)
1355 buf << "\rProperties of this artifact include:\r" << ch << "\n"; 1316 buf << "\rProperties of this artifact include:\r" << ch << "\n";
1356 1317
1357 tmp->destroy (); 1318 tmp->destroy ();
1358 1319
1595 int i; 1556 int i;
1596 1557
1597 if (enemy && !(god->path_denied & PATH_TURNING)) 1558 if (enemy && !(god->path_denied & PATH_TURNING))
1598 if ((i = nstrtok (enemy, ",")) > 0) 1559 if ((i = nstrtok (enemy, ",")) > 0)
1599 { 1560 {
1600 char tmpbuf[MAX_BUF];
1601
1602 buf << "The holy words of " << name 1561 buf << "The holy words of " << name
1603 << " have the power to slay creatures belonging to the "; 1562 << " have the power to slay creatures belonging to the ";
1604 1563
1605 if (i > 1) 1564 if (i > 1)
1606 buf << "following races:" << strtoktolin (enemy, ","); 1565 buf << "following races:" << strtoktolin (enemy, ",");
1682 { /* spell paths */ 1641 { /* spell paths */
1683 //TODO: 1642 //TODO:
1684 int has_effect = 0, tmpvar; 1643 int has_effect = 0, tmpvar;
1685 char tmpbuf[MAX_BUF]; 1644 char tmpbuf[MAX_BUF];
1686 1645
1687 sprintf (tmpbuf, "\n");
1688 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); 1646 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1689 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); 1647 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n");
1690 1648
1691 if ((tmpvar = god->path_attuned)) 1649 if ((tmpvar = god->path_attuned))
1692 { 1650 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines