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.58 by root, Thu Apr 15 21:49:15 2010 UTC vs.
Revision 1.66 by root, Mon Nov 12 03:14:32 2012 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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 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
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.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25/* This file contains code relevant to the BOOKS hack -- designed 25/* This file contains code relevant to the BOOKS hack -- designed
26 * to allow randomly occuring messages in non-magical texts. 26 * to allow randomly occuring messages in non-magical texts.
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",
569 char *tbuf, sbuf[12], buf[MAX_BUF]; 569 char *tbuf, sbuf[12], buf[MAX_BUF];
570 int number = 0; 570 int number = 0;
571 571
572 if (!buf1 || !buf2) 572 if (!buf1 || !buf2)
573 return 0; 573 return 0;
574 sprintf (buf, "%s", buf1); 574
575 sprintf (sbuf, "%s", buf2); 575 strcpy (buf, buf1);
576 strcpy (sbuf, buf2);
577
576 tbuf = strtok (buf, sbuf); 578 tbuf = strtok (buf, sbuf);
577 while (tbuf) 579 while (tbuf)
578 { 580 {
579 number++; 581 number++;
580 tbuf = strtok (NULL, sbuf); 582 tbuf = strtok (NULL, sbuf);
599 strcpy (rbuf, " "); 601 strcpy (rbuf, " ");
600 tbuf = strtok (buf, sbuf); 602 tbuf = strtok (buf, sbuf);
601 while (tbuf && i > 0) 603 while (tbuf && i > 0)
602 { 604 {
603 strcat (rbuf, tbuf); 605 strcat (rbuf, tbuf);
606
604 i--; 607 i--;
605 if (i == 1 && maxi > 1) 608 if (i == 1 && maxi > 1)
606 strcat (rbuf, " and "); 609 strcat (rbuf, " and ");
607 else if (i > 0 && maxi > 1) 610 else if (i > 0 && maxi > 1)
608 strcat (rbuf, ", "); 611 strcat (rbuf, ", ");
609 else 612 else
610 strcat (rbuf, "."); 613 strcat (rbuf, ".");
614
611 tbuf = strtok (NULL, sbuf); 615 tbuf = strtok (NULL, sbuf);
612 } 616 }
617
613 return (char *) rbuf; 618 return rbuf;
614} 619}
615 620
616/***************************************************************************** 621/*****************************************************************************
617 * 622 *
618 * Start of initialisation related functions. 623 * Start of initialisation related functions.
625 */ 630 */
626static void 631static void
627init_book_archive () 632init_book_archive ()
628{ 633{
629 int nroftitle = 0; 634 int nroftitle = 0;
630 char fname[MAX_BUF];
631 titlelist *bl = get_empty_booklist (); 635 titlelist *bl = get_empty_booklist ();
632 636
633 sprintf (fname, "%s/bookarch", settings.localdir); 637 object_thawer thawer (settings.localdir, "bookarch");
634 LOG (llevDebug, " Reading bookarch from %s...\n", fname);
635
636 object_thawer thawer (fname);
637 638
638 if (!thawer) 639 if (!thawer)
639 { 640 {
640 LOG (llevDebug, "could not read bookarch file\n"); 641 LOG (llevDebug, "could not read bookarch file\n");
641 return; 642 return;
688 int i; 689 int i;
689 for (bl = booklist, i = 0; bl && 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++)
690 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); 691 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]);
691 692
692 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); 693 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle);
693 LOG (llevDebug, " done.\n");
694} 694}
695 695
696/* init_mon_info() - creates the linked list of pointers to 696/* init_mon_info() - creates the linked list of pointers to
697 * monster archetype objects if not called previously 697 * monster archetype objects if not called previously
698 */ 698 */
790 * is given is based on various criteria 790 * is given is based on various criteria
791 */ 791 */
792static void 792static void
793new_text_name (object *book, int msgtype) 793new_text_name (object *book, int msgtype)
794{ 794{
795 int nbr; 795 const char *name;
796 char name[MAX_BUF];
797 796
798 if (book->type != BOOK) 797 if (book->type != BOOK)
799 return; 798 return;
800 799
801 switch (msgtype) 800 switch (msgtype)
802 { 801 {
803 case 1: /*monster */ 802 case 1: /*monster */
804 nbr = sizeof (mon_book_name) / sizeof (char *); 803 name = mon_book_name[rndm (array_length (mon_book_name))];
805 assign (name, mon_book_name[rndm (nbr)]);
806 break; 804 break;
807 case 2: /*artifact */ 805 case 2: /*artifact */
808 nbr = sizeof (art_book_name) / sizeof (char *); 806 name = art_book_name[rndm (array_length (art_book_name))];
809 assign (name, art_book_name[rndm (nbr)]);
810 break; 807 break;
811 case 3: /*spellpath */ 808 case 3: /*spellpath */
812 nbr = sizeof (path_book_name) / sizeof (char *); 809 name = path_book_name[rndm (array_length (path_book_name))];
813 assign (name, path_book_name[rndm (nbr)]);
814 break; 810 break;
815 case 4: /*alchemy */ 811 case 4: /*alchemy */
816 nbr = sizeof (formula_book_name) / sizeof (char *); 812 name = formula_book_name[rndm (array_length (formula_book_name))];
817 assign (name, formula_book_name[rndm (nbr)]);
818 break; 813 break;
819 case 5: /*gods */ 814 case 5: /*gods */
820 nbr = sizeof (gods_book_name) / sizeof (char *); 815 name = gods_book_name[rndm (array_length (gods_book_name))];
821 assign (name, gods_book_name[rndm (nbr)]);
822 break; 816 break;
823 case 6: /*msg file */ 817 case 6: /*msg file */
824 default: 818 default:
825 if (book->weight > 2000) 819 name = book->weight > 2000 /* based on weight */
826 { /* based on weight */ 820 ? heavy_book_name [rndm (array_length (heavy_book_name))]
827 nbr = sizeof (heavy_book_name) / sizeof (char *); 821 : light_book_name [rndm (array_length (light_book_name))];
828 assign (name, heavy_book_name[rndm (nbr)]);
829 }
830 else if (book->weight < 2001)
831 {
832 nbr = sizeof (light_book_name) / sizeof (char *);
833 assign (name, light_book_name[rndm (nbr)]);
834 }
835 break; 822 break;
836 } 823 }
837 824
838 book->name = name; 825 book->name = name;
839} 826}
840 827
841/* add_book_author() 828/* add_book_author()
842 * A lot like new_text_name above, but instead chooses an author 829 * A lot like new_text_name above, but instead chooses an author
843 * and sets op->title to that value 830 * and sets op->title to that value
844 */ 831 */
845 832
846static void 833static void
847add_author (object *op, int msgtype) 834add_author (object *op, int msgtype)
848{ 835{
849 char title[MAX_BUF], name[MAX_BUF]; 836 const char *name;
850 int nbr = sizeof (book_author) / sizeof (char *);
851 837
852 if (msgtype < 0 || strlen (op->msg) < 5) 838 if (msgtype < 0 || strlen (op->msg) < 5)
853 return; 839 return;
854 840
855 switch (msgtype) 841 switch (msgtype)
856 { 842 {
857 case 1: /* monster */ 843 case 1: /* monster */
858 nbr = sizeof (mon_author) / sizeof (char *); 844 name = mon_author[rndm (array_length (mon_author))];
859 assign (name, mon_author[rndm (nbr)]);
860 break; 845 break;
861 case 2: /* artifacts */ 846 case 2: /* artifacts */
862 nbr = sizeof (art_author) / sizeof (char *); 847 name = art_author[rndm (array_length (art_author))];
863 assign (name, art_author[rndm (nbr)]);
864 break; 848 break;
865 case 3: /* spellpath */ 849 case 3: /* spellpath */
866 nbr = sizeof (path_author) / sizeof (char *); 850 name = path_author[rndm (array_length (path_author))];
867 assign (name, path_author[rndm (nbr)]);
868 break; 851 break;
869 case 4: /* alchemy */ 852 case 4: /* alchemy */
870 nbr = sizeof (formula_author) / sizeof (char *); 853 name = formula_author[rndm (array_length (formula_author))];
871 assign (name, formula_author[rndm (nbr)]);
872 break; 854 break;
873 case 5: /* gods */ 855 case 5: /* gods */
874 nbr = sizeof (gods_author) / sizeof (char *); 856 name = gods_author[rndm (array_length (gods_author))];
875 assign (name, gods_author[rndm (nbr)]);
876 break; 857 break;
877 case 6: /* msg file */ 858 case 6: /* msg file */
878 default: 859 default:
879 assign (name, book_author[rndm (nbr)]); 860 name = book_author[rndm (array_length (book_author))];
880 } 861 }
881 862
882 sprintf (title, "of %s", name); 863 op->title = format ("of %s", name);
883 op->title = title;
884} 864}
885 865
886/* unique_book() - check to see if the book title/msg is unique. We 866/* unique_book() - check to see if the book title/msg is unique. We
887 * go through the entire list of possibilities each time. If we find 867 * go through the entire list of possibilities each time. If we find
888 * a match, then unique_book returns true (because inst unique). 868 * a match, then unique_book returns true (because inst unique).
970 */ 950 */
971 951
972 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) 952 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype)))
973 { 953 {
974 /* alter book properties */ 954 /* alter book properties */
975 if (object *tmpbook = get_archetype (t->archname)) 955 if (object *tmpbook = archetype::get (t->archname))
976 { 956 {
977 tmpbook->msg = book->msg; 957 tmpbook->msg = book->msg;
978 tmpbook->copy_to (book); 958 tmpbook->copy_to (book);
979 tmpbook->destroy (); 959 tmpbook->destroy ();
980 } 960 }
1038#endif 1018#endif
1039 /* restore old book properties here */ 1019 /* restore old book properties here */
1040 book->title = old_title; 1020 book->title = old_title;
1041 1021
1042 if (rndm (4)) 1022 if (rndm (4))
1043 {
1044 /* Lets give the book a description to individualize it some */ 1023 /* Lets give the book a description to individualize it some */
1045 char new_name[MAX_BUF];
1046
1047 snprintf (new_name, MAX_BUF, "%s %s", book_descrpt[rndm (nbr)], old_name); 1024 book->name = format ("%s %s", book_descrpt[rndm (nbr)], old_name);
1048
1049 book->name = new_name;
1050 }
1051 else 1025 else
1052 {
1053 book->name = old_name; 1026 book->name = old_name;
1054 }
1055 } 1027 }
1056 else if (book->title && strlen (book->msg) > 5) 1028 else if (book->title && strlen (book->msg) > 5)
1057 { /* archive if long msg texts */ 1029 { /* archive if long msg texts */
1058 add_book_to_list (book, msgtype); 1030 add_book_to_list (book, msgtype);
1059 } 1031 }
1249 * for that type exists! 1221 * for that type exists!
1250 */ 1222 */
1251 i = 0; 1223 i = 0;
1252 do 1224 do
1253 { 1225 {
1254 index = rndm (sizeof (art_name_array) / sizeof (arttypename)); 1226 index = rndm (array_length (art_name_array));
1255 type = art_name_array[index].type; 1227 type = art_name_array[index].type;
1256 al = find_artifactlist (type); 1228 al = find_artifactlist (type);
1257 i++; 1229 i++;
1258 } 1230 }
1259 while ((al == NULL) && (i < 10)); 1231 while ((al == NULL) && (i < 10));
1358static char * 1330static char *
1359spellpath_msg (int level) 1331spellpath_msg (int level)
1360{ 1332{
1361 static dynbuf_text buf; buf.clear (); 1333 static dynbuf_text buf; buf.clear ();
1362 1334
1363 static char retbuf[BOOK_BUF];
1364 char tmpbuf[BOOK_BUF];
1365 int path = rndm (NRSPELLPATHS), prayers = rndm (2); 1335 int path = rndm (NRSPELLPATHS), prayers = rndm (2);
1366 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; 1336 uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path];
1367 archetype *at; 1337 archetype *at;
1368 1338
1369 /* Preamble */ 1339 /* Preamble */
1579 int i; 1549 int i;
1580 1550
1581 if (enemy && !(god->path_denied & PATH_TURNING)) 1551 if (enemy && !(god->path_denied & PATH_TURNING))
1582 if ((i = nstrtok (enemy, ",")) > 0) 1552 if ((i = nstrtok (enemy, ",")) > 0)
1583 { 1553 {
1584 char tmpbuf[MAX_BUF];
1585
1586 buf << "The holy words of " << name 1554 buf << "The holy words of " << name
1587 << " have the power to slay creatures belonging to the "; 1555 << " have the power to slay creatures belonging to the ";
1588 1556
1589 if (i > 1) 1557 if (i > 1)
1590 buf << "following races:" << strtoktolin (enemy, ","); 1558 buf << "following races:" << strtoktolin (enemy, ",");
1666 { /* spell paths */ 1634 { /* spell paths */
1667 //TODO: 1635 //TODO:
1668 int has_effect = 0, tmpvar; 1636 int has_effect = 0, tmpvar;
1669 char tmpbuf[MAX_BUF]; 1637 char tmpbuf[MAX_BUF];
1670 1638
1671 sprintf (tmpbuf, "\n");
1672 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name); 1639 sprintf (tmpbuf, "It is rarely known fact that the priests of %s\n", name);
1673 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n"); 1640 strcat (tmpbuf, "are mystically transformed. Effects of this include:\n");
1674 1641
1675 if ((tmpvar = god->path_attuned)) 1642 if ((tmpvar = god->path_attuned))
1676 { 1643 {
1704 buf << "[Unfortunately the rest of the information is hopelessly garbled!]"; 1671 buf << "[Unfortunately the rest of the information is hopelessly garbled!]";
1705 1672
1706 return buf; 1673 return buf;
1707} 1674}
1708 1675
1709/* tailor_readable_ob()- The main routine. This chooses a random 1676/* tailor_readable_ob()- The main routine. This chooses a random
1710 * message to put in given readable object (type==BOOK) which will 1677 * message to put in given readable object (type==BOOK) which will
1711 * be referred hereafter as a 'book'. We use the book level to de- 1678 * be referred hereafter as a 'book'. We use the book level to de-
1712 * termine the value of the information we will insert. Higher 1679 * termine the value of the information we will insert. Higher
1713 * values mean the book will (generally) have better/more info. 1680 * values mean the book will (generally) have better/more info.
1714 * See individual cases as to how this will be utilized. 1681 * See individual cases as to how this will be utilized.
1715 * "Book" name/content length are based on the weight of the 1682 * "Book" name/content length are based on the weight of the
1716 * document. If the value of msg_type is negative, we will randomly 1683 * document. If the value of msg_type is negative, we will randomly
1717 * choose the kind of message to generate. 1684 * choose the kind of message to generate.
1718 * -b.t. thomas@astro.psu.edu 1685 * -b.t. thomas@astro.psu.edu
1719 * 1686 *
1720 * book is the object we are creating into. 1687 * book is the object we are creating into.
1721 * If msg_type is a positive value, we use that to determine the 1688 * If msg_type is a positive value, we use that to determine the
1722 * message type - otherwise a random value is used. 1689 * message type - otherwise a random value is used.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines