--- deliantra/server/common/readable.C 2010/10/24 21:24:09 1.60 +++ deliantra/server/common/readable.C 2018/11/17 23:40:00 1.69 @@ -1,24 +1,25 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. - * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * + * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen - * + * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . - * + * * The authors can be reached via e-mail to */ @@ -33,32 +34,32 @@ #include #include -/* Define this if you want to archive book titles by contents. - * This option should enforce UNIQUE combinations of titles,authors and - * msg contents during and *between* game sessions. - * Note: a slight degeneracy exists since books are archived based on an integer - * index value calculated from the message text (similar to alchemy formulae). - * Sometimes two widely different messages have the same index value (rare). In - * this case, it is possible to occasionally generate 2 books with same title and - * different message content. Not really a bug, but rather a feature. This action - * should keeps player on their toes ;). - * Also, note that there is *finite* space available for archiving message and titles. - * Once this space is used, books will stop being archived. Not a serious problem - * under the current regime, since there are generally fewer possible (random) +/* Define this if you want to archive book titles by contents. + * This option should enforce UNIQUE combinations of titles,authors and + * msg contents during and *between* game sessions. + * Note: a slight degeneracy exists since books are archived based on an integer + * index value calculated from the message text (similar to alchemy formulae). + * Sometimes two widely different messages have the same index value (rare). In + * this case, it is possible to occasionally generate 2 books with same title and + * different message content. Not really a bug, but rather a feature. This action + * should keeps player on their toes ;). + * Also, note that there is *finite* space available for archiving message and titles. + * Once this space is used, books will stop being archived. Not a serious problem + * under the current regime, since there are generally fewer possible (random) * messages than space available on the titlelists. * One exception (for sure) are the monster messages. But no worries, you should * see all of the monster info in some order (but not all possble combinations) * before the monster titlelist space is run out. You can increase titlelist - * space by increasing the array sizes for the monster book_authours and book_names - * (see max_titles[] array and include/read.h). Since the unique_book algorthm is - * kinda stupid, this program *may* slow down program execution if defined (but I don't + * space by increasing the array sizes for the monster book_authours and book_names + * (see max_titles[] array and include/read.h). Since the unique_book algorthm is + * kinda stupid, this program *may* slow down program execution if defined (but I don't * think its a significant problem, at least, I have no problems running this option - * on a Sparc 10! Also, once archive title lists are filled and/or all possible msg - * combinations have been generated, unique_book isnt called anymore. It takes 5-10 - * sessions for this to happen). + * on a Sparc 10! Also, once archive title lists are filled and/or all possible msg + * combinations have been generated, unique_book isnt called anymore. It takes 5-10 + * sessions for this to happen). * Final note: the game remembers book/title/msg combinations from reading the * file lib/bookarch. If you REMOVE this file, you will lose your archive. So - * be sure to copy it over to the new lib directory when you change versions. + * be sure to copy it over to the new lib directory when you change versions. * -b.t. */ @@ -557,7 +558,7 @@ return tl; } -/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file +/* HANDMADE STRING FUNCTIONS.., perhaps these belong in another file * (shstr.c ?), but the quantity BOOK_BUF will need to be defined. */ /* nstrtok() - simple routine to return the number of list @@ -693,7 +694,7 @@ LOG (llevDebug, "init_book_archive() got %d titles.\n", nroftitle); } -/* init_mon_info() - creates the linked list of pointers to +/* init_mon_info() - creates the linked list of pointers to * monster archetype objects if not called previously */ static void @@ -723,8 +724,8 @@ LOG (llevDebug, "init_mon_info() got %d monsters\n", nrofmon); } -/* init_readable() - initialise linked lists utilized by - * message functions in tailor_readable_ob() +/* init_readable() - initialise linked lists utilized by + * message functions in tailor_readable_ob() * * This is the function called by the main routine to initialise * all the readable information. @@ -784,7 +785,7 @@ } /* new_text_name() - Only for objects of type BOOK. SPELLBOOK stuff is - * handled directly in change_book_name(). Names are based on text + * handled directly in change_book_name(). Names are based on text * msgtype * this sets book book->name based on msgtype given. What name * is given is based on various criteria @@ -816,21 +817,16 @@ break; case 6: /*msg file */ default: - if (book->weight > 2000) - { /* based on weight */ - name = heavy_book_name[rndm (array_length (heavy_book_name))]; - } - else if (book->weight < 2001) - { - name = light_book_name[rndm (array_length (light_book_name))]; - } + name = book->weight > 2000 /* based on weight */ + ? heavy_book_name [rndm (array_length (heavy_book_name))] + : light_book_name [rndm (array_length (light_book_name))]; break; } book->name = name; } -/* add_book_author() +/* add_book_author() * A lot like new_text_name above, but instead chooses an author * and sets op->title to that value */ @@ -868,7 +864,7 @@ op->title = format ("of %s", name); } -/* unique_book() - check to see if the book title/msg is unique. We +/* unique_book() - check to see if the book title/msg is unique. We * go through the entire list of possibilities each time. If we find * a match, then unique_book returns true (because inst unique). */ @@ -925,12 +921,12 @@ } -/* change_book() - give a new, fancier name to generated +/* change_book() - give a new, fancier name to generated * objects of type BOOK and SPELLBOOK. - * Aug 96 I changed this so we will attempt to create consistent + * Aug 96 I changed this so we will attempt to create consistent * authour/title and message content for BOOKs. Also, we will - * alter books that match archive entries to the archival - * levels and architypes. -b.t. + * alter books that match archive entries to the archival + * levels and architypes. -b.t. */ #define MAX_TITLE_CHECK 20 @@ -950,14 +946,14 @@ /* look to see if our msg already been archived. If so, alter * the book to match the archival text. If we fail to match, - * then we archive the new title/name/msg combo if there is - * room on the titlelist. + * then we archive the new title/name/msg combo if there is + * room on the titlelist. */ if ((strlen (book->msg) > 5) && (t = find_title (book, msgtype))) { /* alter book properties */ - if (object *tmpbook = get_archetype (t->archname)) + if (object *tmpbook = archetype::get (t->archname)) { tmpbook->msg = book->msg; tmpbook->copy_to (book); @@ -1011,7 +1007,7 @@ * 1)If no space for a new title exists lets just restore * the old book properties. Remember, if the book had * matchd an older entry on the titlelist, we shouldnt - * have called this routine in the first place! + * have called this routine in the first place! * 2) If we got a unique title, we need to add it to * the list. */ @@ -1055,7 +1051,7 @@ * Monster msg generation code. ****************************************************************************/ -/* get_random_mon() - returns a random monster slected from linked +/* get_random_mon() - returns a random monster slected from linked * list of all monsters in the current game. If level is non-zero, * then only monsters greater than that level will be returned. * Changed 971225 to be greater than equal to level passed. Also @@ -1091,7 +1087,7 @@ /* Case where we are searching by level. Redone 971225 to be clearer * and more random. Before, it looks like it took a random monster from * the list, and then returned the first monster after that which was - * appropriate level. This wasn't very random because if you had a + * appropriate level. This wasn't very random because if you had a * bunch of low level monsters and then a high level one, if the random * determine took one of the low level ones, it would just forward to the * high level one and return that. Thus, monsters that immediatly followed @@ -1164,7 +1160,7 @@ } -/* mon_info_msg() - generate a message detailing the properties +/* mon_info_msg() - generate a message detailing the properties * of a randomly selected monster. */ static const char * @@ -1175,12 +1171,12 @@ /*preamble */ buf << "This beastiary contains:\n"; - /* lets print info on as many monsters as will fit in our - * document. + /* lets print info on as many monsters as will fit in our + * document. * 8-96 Had to change this a bit, otherwise there would * have been an impossibly large number of combinations * of text! (and flood out the available number of titles - * in the archive in a snap!) -b.t. + * in the archive in a snap!) -b.t. */ object *tmp = get_random_mon (level * 3); while (tmp && buf.size () < BOOK_BUF) @@ -1258,7 +1254,7 @@ book_entries > 1 ? "some artifacts" : "an artifact"); /* artifact msg attributes loop. Lets keep adding entries to the 'book' - * as long as we have space up to the allowed max # (book_entires) + * as long as we have space up to the allowed max # (book_entires) */ while (book_entries > 0 && buf.size () < BOOK_BUF) { @@ -1329,16 +1325,14 @@ *****************************************************************************/ /* spellpath_msg() - generate a message detailing the member - * incantations/prayers (and some of their properties) belonging to - * a given spellpath. + * incantations/prayers (and some of their properties) belonging to + * a given spellpath. */ static char * spellpath_msg (int level) { static dynbuf_text buf; buf.clear (); - static char retbuf[BOOK_BUF]; - char tmpbuf[BOOK_BUF]; int path = rndm (NRSPELLPATHS), prayers = rndm (2); uint32 pnum = (path == -1) ? PATH_NULL : spellpathdef[path]; archetype *at; @@ -1390,7 +1384,7 @@ static dynbuf_text buf; buf.clear (); /* the higher the book level, the more complex (ie number of - * ingredients) the formula can be. + * ingredients) the formula can be. */ fl = get_formulalist (rndm (level) / 3 + 1); @@ -1680,15 +1674,15 @@ return buf; } -/* tailor_readable_ob()- The main routine. This chooses a random - * message to put in given readable object (type==BOOK) which will - * be referred hereafter as a 'book'. We use the book level to de- - * termine the value of the information we will insert. Higher - * values mean the book will (generally) have better/more info. +/* tailor_readable_ob()- The main routine. This chooses a random + * message to put in given readable object (type==BOOK) which will + * be referred hereafter as a 'book'. We use the book level to de- + * termine the value of the information we will insert. Higher + * values mean the book will (generally) have better/more info. * See individual cases as to how this will be utilized. - * "Book" name/content length are based on the weight of the + * "Book" name/content length are based on the weight of the * document. If the value of msg_type is negative, we will randomly - * choose the kind of message to generate. + * choose the kind of message to generate. * -b.t. thomas@astro.psu.edu * * book is the object we are creating into.