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.66 by root, Mon Nov 12 03:14:32 2012 UTC vs.
Revision 1.69 by root, Sat Nov 17 23:40:00 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * the terms of the Affero GNU General Public License as published by the
31#include <global.h> 32#include <global.h>
32#include <book.h> 33#include <book.h>
33#include <living.h> 34#include <living.h>
34#include <spells.h> 35#include <spells.h>
35 36
36/* Define this if you want to archive book titles by contents. 37/* Define this if you want to archive book titles by contents.
37 * This option should enforce UNIQUE combinations of titles,authors and 38 * This option should enforce UNIQUE combinations of titles,authors and
38 * msg contents during and *between* game sessions. 39 * msg contents during and *between* game sessions.
39 * Note: a slight degeneracy exists since books are archived based on an integer 40 * Note: a slight degeneracy exists since books are archived based on an integer
40 * index value calculated from the message text (similar to alchemy formulae). 41 * index value calculated from the message text (similar to alchemy formulae).
41 * Sometimes two widely different messages have the same index value (rare). In 42 * Sometimes two widely different messages have the same index value (rare). In
42 * this case, it is possible to occasionally generate 2 books with same title and 43 * this case, it is possible to occasionally generate 2 books with same title and
43 * different message content. Not really a bug, but rather a feature. This action 44 * different message content. Not really a bug, but rather a feature. This action
44 * should keeps player on their toes ;). 45 * should keeps player on their toes ;).
45 * Also, note that there is *finite* space available for archiving message and titles. 46 * Also, note that there is *finite* space available for archiving message and titles.
46 * Once this space is used, books will stop being archived. Not a serious problem 47 * Once this space is used, books will stop being archived. Not a serious problem
47 * under the current regime, since there are generally fewer possible (random) 48 * under the current regime, since there are generally fewer possible (random)
48 * messages than space available on the titlelists. 49 * messages than space available on the titlelists.
49 * One exception (for sure) are the monster messages. But no worries, you should 50 * One exception (for sure) are the monster messages. But no worries, you should
50 * see all of the monster info in some order (but not all possble combinations) 51 * see all of the monster info in some order (but not all possble combinations)
51 * before the monster titlelist space is run out. You can increase titlelist 52 * before the monster titlelist space is run out. You can increase titlelist
52 * space by increasing the array sizes for the monster book_authours and book_names 53 * space by increasing the array sizes for the monster book_authours and book_names
53 * (see max_titles[] array and include/read.h). Since the unique_book algorthm is 54 * (see max_titles[] array and include/read.h). Since the unique_book algorthm is
54 * kinda stupid, this program *may* slow down program execution if defined (but I don't 55 * kinda stupid, this program *may* slow down program execution if defined (but I don't
55 * think its a significant problem, at least, I have no problems running this option 56 * think its a significant problem, at least, I have no problems running this option
56 * on a Sparc 10! Also, once archive title lists are filled and/or all possible msg 57 * on a Sparc 10! Also, once archive title lists are filled and/or all possible msg
57 * combinations have been generated, unique_book isnt called anymore. It takes 5-10 58 * combinations have been generated, unique_book isnt called anymore. It takes 5-10
58 * sessions for this to happen). 59 * sessions for this to happen).
59 * Final note: the game remembers book/title/msg combinations from reading the 60 * Final note: the game remembers book/title/msg combinations from reading the
60 * file lib/bookarch. If you REMOVE this file, you will lose your archive. So 61 * file lib/bookarch. If you REMOVE this file, you will lose your archive. So
61 * be sure to copy it over to the new lib directory when you change versions. 62 * be sure to copy it over to the new lib directory when you change versions.
62 * -b.t. 63 * -b.t.
63 */ 64 */
64 65
65/* This flag is useful to see what kind of output messages are created */ 66/* This flag is useful to see what kind of output messages are created */
66 67
555 } 556 }
556 557
557 return tl; 558 return tl;
558} 559}
559 560
560/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file 561/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file
561 * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */ 562 * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */
562 563
563/* nstrtok() - simple routine to return the number of list 564/* nstrtok() - simple routine to return the number of list
564 * items in buf1 as separated by the value of buf2 565 * items in buf1 as separated by the value of buf2
565 */ 566 */
691 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]); 692 LOG (llevDebug, " (%d/%d)\n", bl->number, max_titles[i]);
692 693
693 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); 694 LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle);
694} 695}
695 696
696/* init_mon_info() - creates the linked list of pointers to 697/* init_mon_info() - creates the linked list of pointers to
697 * monster archetype objects if not called previously 698 * monster archetype objects if not called previously
698 */ 699 */
699static void 700static void
700init_mon_info () 701init_mon_info ()
701{ 702{
721 } 722 }
722 723
723 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); 724 LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon);
724} 725}
725 726
726/* init_readable() - initialise linked lists utilized by 727/* init_readable() - initialise linked lists utilized by
727 * message functions in tailor_readable_ob() 728 * message functions in tailor_readable_ob()
728 * 729 *
729 * This is the function called by the main routine to initialise 730 * This is the function called by the main routine to initialise
730 * all the readable information. 731 * all the readable information.
731 */ 732 */
732void 733void
782 783
783 return t; 784 return t;
784} 785}
785 786
786/* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is 787/* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is
787 * handled directly in change_book_name(). Names are based on text 788 * handled directly in change_book_name(). Names are based on text
788 * msgtype 789 * msgtype
789 * this sets book book->name based on msgtype given. What name 790 * this sets book book->name based on msgtype given. What name
790 * is given is based on various criteria 791 * is given is based on various criteria
791 */ 792 */
792static void 793static void
861 } 862 }
862 863
863 op->title = format ("of %s", name); 864 op->title = format ("of %s", name);
864} 865}
865 866
866/* unique_book() - check to see if the book title/msg is unique. We 867/* unique_book() - check to see if the book title/msg is unique. We
867 * go through the entire list of possibilities each time. If we find 868 * go through the entire list of possibilities each time. If we find
868 * a match, then unique_book returns true (because inst unique). 869 * a match, then unique_book returns true (because inst unique).
869 */ 870 */
870 871
871static int 872static int
918#endif 919#endif
919 920
920} 921}
921 922
922 923
923/* change_book() - give a new, fancier name to generated 924/* change_book() - give a new, fancier name to generated
924 * objects of type BOOK and SPELLBOOK. 925 * objects of type BOOK and SPELLBOOK.
925 * Aug 96 I changed this so we will attempt to create consistent 926 * Aug 96 I changed this so we will attempt to create consistent
926 * authour/title and message content for BOOKs. Also, we will 927 * authour/title and message content for BOOKs. Also, we will
927 * alter books that match archive entries to the archival 928 * alter books that match archive entries to the archival
928 * levels and architypes. -b.t. 929 * levels and architypes. -b.t.
929 */ 930 */
930 931
931#define MAX_TITLE_CHECK 20 932#define MAX_TITLE_CHECK 20
932 933
933static void 934static void
943 title *t = NULL; 944 title *t = NULL;
944 int tries = 0; 945 int tries = 0;
945 946
946 /* look to see if our msg already been archived. If so, alter 947 /* look to see if our msg already been archived. If so, alter
947 * the book to match the archival text. If we fail to match, 948 * the book to match the archival text. If we fail to match,
948 * then we archive the new title/name/msg combo if there is 949 * then we archive the new title/name/msg combo if there is
949 * room on the titlelist. 950 * room on the titlelist.
950 */ 951 */
951 952
952 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) 953 if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype)))
953 { 954 {
954 /* alter book properties */ 955 /* alter book properties */
1004 1005
1005 /* Now deal with 2 cases. 1006 /* Now deal with 2 cases.
1006 * 1)If no space for a new title exists lets just restore 1007 * 1)If no space for a new title exists lets just restore
1007 * the old book properties. Remember, if the book had 1008 * the old book properties. Remember, if the book had
1008 * matchd an older entry on the titlelist, we shouldnt 1009 * matchd an older entry on the titlelist, we shouldnt
1009 * have called this routine in the first place! 1010 * have called this routine in the first place!
1010 * 2) If we got a unique title, we need to add it to 1011 * 2) If we got a unique title, we need to add it to
1011 * the list. 1012 * the list.
1012 */ 1013 */
1013 1014
1014 if (tries == MAX_TITLE_CHECK || numb == maxnames) 1015 if (tries == MAX_TITLE_CHECK || numb == maxnames)
1048 1049
1049/***************************************************************************** 1050/*****************************************************************************
1050 * Monster msg generation code. 1051 * Monster msg generation code.
1051 ****************************************************************************/ 1052 ****************************************************************************/
1052 1053
1053/* get_random_mon() - returns a random monster slected from linked 1054/* get_random_mon() - returns a random monster slected from linked
1054 * list of all monsters in the current game. If level is non-zero, 1055 * list of all monsters in the current game. If level is non-zero,
1055 * then only monsters greater than that level will be returned. 1056 * then only monsters greater than that level will be returned.
1056 * Changed 971225 to be greater than equal to level passed. Also 1057 * Changed 971225 to be greater than equal to level passed. Also
1057 * made choosing by level more random. 1058 * made choosing by level more random.
1058 */ 1059 */
1084 } 1085 }
1085 1086
1086 /* Case where we are searching by level. Redone 971225 to be clearer 1087 /* Case where we are searching by level. Redone 971225 to be clearer
1087 * and more random. Before, it looks like it took a random monster from 1088 * and more random. Before, it looks like it took a random monster from
1088 * the list, and then returned the first monster after that which was 1089 * the list, and then returned the first monster after that which was
1089 * appropriate level. This wasn't very random because if you had a 1090 * appropriate level. This wasn't very random because if you had a
1090 * bunch of low level monsters and then a high level one, if the random 1091 * bunch of low level monsters and then a high level one, if the random
1091 * determine took one of the low level ones, it would just forward to the 1092 * determine took one of the low level ones, it would just forward to the
1092 * high level one and return that. Thus, monsters that immediatly followed 1093 * high level one and return that. Thus, monsters that immediatly followed
1093 * a bunch of low level monsters would be more heavily returned. It also 1094 * a bunch of low level monsters would be more heavily returned. It also
1094 * means some of the dragons would be poorly represented, since they 1095 * means some of the dragons would be poorly represented, since they
1157 else 1158 else
1158 return first_mon_info->ob; 1159 return first_mon_info->ob;
1159 1160
1160} 1161}
1161 1162
1162/* mon_info_msg() - generate a message detailing the properties 1163/* mon_info_msg() - generate a message detailing the properties
1163 * of a randomly selected monster. 1164 * of a randomly selected monster.
1164 */ 1165 */
1165static const char * 1166static const char *
1166mon_info_msg (int level) 1167mon_info_msg (int level)
1167{ 1168{
1168 static dynbuf_text buf; buf.clear (); 1169 static dynbuf_text buf; buf.clear ();
1169 1170
1170 /*preamble */ 1171 /*preamble */
1171 buf << "This beastiary contains:\n"; 1172 buf << "This beastiary contains:\n";
1172 1173
1173 /* lets print info on as many monsters as will fit in our 1174 /* lets print info on as many monsters as will fit in our
1174 * document. 1175 * document.
1175 * 8-96 Had to change this a bit, otherwise there would 1176 * 8-96 Had to change this a bit, otherwise there would
1176 * have been an impossibly large number of combinations 1177 * have been an impossibly large number of combinations
1177 * of text! (and flood out the available number of titles 1178 * of text! (and flood out the available number of titles
1178 * in the archive in a snap!) -b.t. 1179 * in the archive in a snap!) -b.t.
1179 */ 1180 */
1180 object *tmp = get_random_mon (level * 3); 1181 object *tmp = get_random_mon (level * 3);
1181 while (tmp && buf.size () < BOOK_BUF) 1182 while (tmp && buf.size () < BOOK_BUF)
1182 { 1183 {
1183 /* monster description */ 1184 /* monster description */
1251 buf.printf ("Herein %s detailed %s...\n", 1252 buf.printf ("Herein %s detailed %s...\n",
1252 book_entries > 1 ? "are" : "is", 1253 book_entries > 1 ? "are" : "is",
1253 book_entries > 1 ? "some artifacts" : "an artifact"); 1254 book_entries > 1 ? "some artifacts" : "an artifact");
1254 1255
1255 /* artifact msg attributes loop. Lets keep adding entries to the 'book' 1256 /* artifact msg attributes loop. Lets keep adding entries to the 'book'
1256 * as long as we have space up to the allowed max # (book_entires) 1257 * as long as we have space up to the allowed max # (book_entires)
1257 */ 1258 */
1258 while (book_entries > 0 && buf.size () < BOOK_BUF) 1259 while (book_entries > 0 && buf.size () < BOOK_BUF)
1259 { 1260 {
1260 1261
1261 if (!art) 1262 if (!art)
1322/***************************************************************************** 1323/*****************************************************************************
1323 * Spellpath message generation 1324 * Spellpath message generation
1324 *****************************************************************************/ 1325 *****************************************************************************/
1325 1326
1326/* spellpath_msg() - generate a message detailing the member 1327/* spellpath_msg() - generate a message detailing the member
1327 * incantations/prayers (and some of their properties) belonging to 1328 * incantations/prayers (and some of their properties) belonging to
1328 * a given spellpath. 1329 * a given spellpath.
1329 */ 1330 */
1330static char * 1331static char *
1331spellpath_msg (int level) 1332spellpath_msg (int level)
1332{ 1333{
1333 static dynbuf_text buf; buf.clear (); 1334 static dynbuf_text buf; buf.clear ();
1381 int chance; 1382 int chance;
1382 1383
1383 static dynbuf_text buf; buf.clear (); 1384 static dynbuf_text buf; buf.clear ();
1384 1385
1385 /* the higher the book level, the more complex (ie number of 1386 /* the higher the book level, the more complex (ie number of
1386 * ingredients) the formula can be. 1387 * ingredients) the formula can be.
1387 */ 1388 */
1388 fl = get_formulalist (rndm (level) / 3 + 1); 1389 fl = get_formulalist (rndm (level) / 3 + 1);
1389 1390
1390 if (!fl) 1391 if (!fl)
1391 fl = get_formulalist (1); /* safety */ 1392 fl = get_formulalist (1); /* safety */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines