Crossfire Server, Trunk  R22047
readable.c File Reference
#include "global.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "book.h"
#include "living.h"
#include "output_file.h"
#include "spells.h"
#include "assets.h"
+ Include dependency graph for readable.c:

Go to the source code of this file.

Data Structures

struct  namebytype
 
struct  titleliststruct
 
struct  titlestruct
 

Macros

#define arraysize(arrayname)   (sizeof(arrayname)/sizeof(*(arrayname)))
 
#define MAX_TITLE_CHECK   20
 
#define MSGTYPE_ALCHEMY   4
 
#define MSGTYPE_ARTIFACT   2
 
#define MSGTYPE_GODS   5
 
#define MSGTYPE_LIB   0
 
#define MSGTYPE_MONSTER   1
 
#define MSGTYPE_MSGFILE   6
 
#define MSGTYPE_SPELLPATH   3
 

Typedefs

typedef struct namebytype arttypename
 
typedef struct titlestruct title
 
typedef struct titleliststruct titlelist
 

Functions

static void add_author (object *op, int msgtype)
 
static void add_book (title *book, int type, const char *fname, int lineno)
 
static void add_book_to_list (const object *book, int msgtype)
 
static StringBufferartifact_describe (const artifact *art, const artifactlist *al, int message, int art_name, int separator)
 
static StringBufferartifact_msg (unsigned int level, size_t booksize)
 
int book_overflow (const char *buf1, const char *buf2, size_t booksize)
 
static void change_book (object *book, int msgtype)
 
static void do_monster (archetype *at)
 
static void do_spellpath_msg (archetype *at)
 
static titlefind_title (const object *book, int msgtype)
 
void free_all_readable (void)
 
static titleget_empty_book (void)
 
static titlelistget_empty_booklist (void)
 
sstring get_message_body (const GeneralMessage *message)
 
const Faceget_message_face (const GeneralMessage *message)
 
sstring get_message_title (const GeneralMessage *message)
 
static object * get_next_mon (const object *tmp)
 
object * get_random_mon (int level)
 
const readable_message_typeget_readable_message_type (object *readable)
 
static titlelistget_titlelist (int i)
 
static StringBuffergod_info_msg (int level, size_t booksize, object *book)
 
static void init_book_archive (void)
 
static void init_mon_info (void)
 
void init_readable (void)
 
static void make_formula_book (object *book, int level)
 
static StringBuffermon_desc (const object *mon)
 
static StringBuffermon_info_msg (int level, size_t booksize, object *book)
 
static StringBuffermsgfile_msg (object *book, size_t booksize)
 
static void new_text_name (object *book, int msgtype)
 
int nstrtok (const char *buf1, const char *buf2)
 
static StringBufferspellpath_msg (int level, size_t booksize, StringBuffer *buf)
 
char * strtoktolin (const char *buf1, const char *buf2, char *retbuf, size_t size)
 
void tailor_readable_ob (object *book, int msg_type)
 
static int unique_book (const object *book, int msgtype)
 
void write_book_archive (void)
 

Variables

static const char *const art_author []
 
static const char *const art_book_name []
 
static const arttypename art_name_array []
 
static const char *const book_author []
 
static const char *const book_descrpt []
 
static titlelistbooklist = NULL
 
static objectlink * first_mon_info = NULL
 
static const char *const formula_author []
 
static const char *const formula_book_name []
 
static const char *const gods_author []
 
static const char *const gods_book_name []
 
static const char *const heavy_book_name []
 
static const int last_readable_subtype = arraysize(readable_message_types)
 
static const char *const light_book_name []
 
static const int max_titles [6]
 
static const char *const mon_author []
 
static const char *const mon_book_name []
 
static int need_to_write_bookarchive = 0
 
static int nrofmon = 0
 
static const char *const path_author []
 
static const char *const path_book_name []
 
static const readable_message_type readable_message_types []
 
struct {
   size_t   booksize
 
   StringBuffer *   buf
 
   int   did_first_sp
 
   int   done
 
   int   level
 
   uint32_t   pnum
 
   int   prayers
 
sp_params
 
static const uint32_t spellpathdef [NRSPELLPATHS]
 

Detailed Description

This file contains code relevant to the BOOKS hack – designed to allow randomly occuring messages in non-magical texts.

Todo:
replace message type with defines/enums & such things.

Definition in file readable.c.

Macro Definition Documentation

◆ arraysize

#define arraysize (   arrayname)    (sizeof(arrayname)/sizeof(*(arrayname)))

Returns the element size of an array.

Parameters
arraynamethe array's name
Returns
the number of elements

Definition at line 97 of file readable.c.

Referenced by add_author(), artifact_msg(), change_book(), get_titlelist(), init_book_archive(), make_formula_book(), new_text_name(), and tailor_readable_ob().

◆ MAX_TITLE_CHECK

#define MAX_TITLE_CHECK   20

How many times to try to generate a unique name for a book.

Definition at line 75 of file readable.c.

Referenced by change_book().

◆ MSGTYPE_ALCHEMY

#define MSGTYPE_ALCHEMY   4

Alchemy-related information.

Definition at line 86 of file readable.c.

Referenced by add_author(), make_formula_book(), new_text_name(), and tailor_readable_ob().

◆ MSGTYPE_ARTIFACT

#define MSGTYPE_ARTIFACT   2

Artifact-related information.

Definition at line 82 of file readable.c.

Referenced by add_author(), new_text_name(), and tailor_readable_ob().

◆ MSGTYPE_GODS

#define MSGTYPE_GODS   5

God-related information.

Definition at line 88 of file readable.c.

Referenced by add_author(), new_text_name(), and tailor_readable_ob().

◆ MSGTYPE_LIB

#define MSGTYPE_LIB   0

Message from the lib/messages file.

Definition at line 78 of file readable.c.

Referenced by tailor_readable_ob().

◆ MSGTYPE_MONSTER

#define MSGTYPE_MONSTER   1

Monster-related information.

Definition at line 80 of file readable.c.

Referenced by add_author(), new_text_name(), and tailor_readable_ob().

◆ MSGTYPE_MSGFILE

#define MSGTYPE_MSGFILE   6

Message from the lib/messages file.

Definition at line 90 of file readable.c.

Referenced by add_author(), and new_text_name().

◆ MSGTYPE_SPELLPATH

#define MSGTYPE_SPELLPATH   3

Spellpath-related information.

Definition at line 84 of file readable.c.

Referenced by add_author(), new_text_name(), and tailor_readable_ob().

Typedef Documentation

◆ arttypename

typedef struct namebytype arttypename

special structure, used only by art_name_array[]

◆ title

typedef struct titlestruct title

Information on one title. 'title' and 'titlelist' are used by the readable code

◆ titlelist

typedef struct titleliststruct titlelist

Titles for one message type.

Function Documentation

◆ add_author()

static void add_author ( object *  op,
int  msgtype 
)
static

A lot like new_text_name() above, but instead chooses an author and sets op->title to that value

Parameters
opbook to alter.
msgtypeinformation we want.

Definition at line 1005 of file readable.c.

References add_string(), arraysize, art_author, book_author, formula_author, gods_author, MAX_BUF, mon_author, MSGTYPE_ALCHEMY, MSGTYPE_ARTIFACT, MSGTYPE_GODS, MSGTYPE_MONSTER, MSGTYPE_MSGFILE, MSGTYPE_SPELLPATH, titlestruct::name, path_author, RANDOM, and snprintf.

Referenced by change_book(), and make_formula_book().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_book()

static void add_book ( title book,
int  type,
const char *  fname,
int  lineno 
)
static

Appends a book to the booklist.

Parameters
bookthe book to add
typethe book type
fnamethe file name; for error messages
linenothe line number; for error messages

Definition at line 834 of file readable.c.

References titleliststruct::first_book, get_titlelist(), llevInfo, LOG(), titlestruct::next, and titleliststruct::number.

Referenced by init_book_archive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_book_to_list()

static void add_book_to_list ( const object *  book,
int  msgtype 
)
static

Adds a book to the list of existing books.

Parameters
bookbook to add.
msgtypewhat information the book contains.

Definition at line 1077 of file readable.c.

References add_string(), titlestruct::archname, titlestruct::authour, titleliststruct::first_book, get_empty_book(), get_titlelist(), titlestruct::level, llevDebug, llevError, LOG(), titlestruct::msg_index, titlestruct::name, need_to_write_bookarchive, titlestruct::next, titleliststruct::number, titlestruct::size, and strtoint().

Referenced by change_book().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ artifact_describe()

static StringBuffer* artifact_describe ( const artifact art,
const artifactlist al,
int  message,
int  art_name,
int  separator 
)
static

Describe an artifact.

Parameters
artartifact to describe.
allist art is part of.
messageif non zero, and the artifact has a suitable message, add it to the description.
art_nameindex in art_name_array the artifact is in.
separatorif non zero, a separator is inserted at the start of the description.
Returns
newly allocated StringBuffer* containing the description.
Todo:
check archetype when loading archetypes, not here

Definition at line 1417 of file readable.c.

References add_abilities(), artifactstruct::allowed, artifactstruct::allowed_size, BOOK_BUF, artifactstruct::chance, describe_item(), find_archetype_by_object_name(), FLAG_IDENTIFIED, artifactstruct::item, llevError, LOG(), linked_char::name, titlestruct::name, linked_char::next, object_free_drop_inventory(), object_new(), RANDOM, SET_FLAG, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_append_stringbuffer(), stringbuffer_finish(), stringbuffer_length(), stringbuffer_new(), artifactliststruct::total_chance, try_find_archetype(), and artifactliststruct::type.

Referenced by artifact_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ artifact_msg()

static StringBuffer* artifact_msg ( unsigned int  level,
size_t  booksize 
)
static

Generate a message detailing the properties of 1-6 artifacts drawn sequentially from the artifact list.

Parameters
levellevel of the book.
booksizemaximum length of the book.
Returns
new StringBuffer containing the dsecription.

Definition at line 1512 of file readable.c.

References arraysize, artifact_describe(), find_artifactlist(), artifactstruct::item, artifactliststruct::items, titlestruct::level, artifactstruct::next, RANDOM, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_append_stringbuffer(), stringbuffer_delete(), stringbuffer_length(), stringbuffer_new(), and namebytype::type.

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ book_overflow()

int book_overflow ( const char *  buf1,
const char *  buf2,
size_t  booksize 
)

Checks if buf1 and buf2 can be combined.

Parameters
buf1
buf2buffer we plan on combining.
booksizemaximum book size.
Returns
0 if buffers can be combined, 1 else.

Definition at line 697 of file readable.c.

References BOOK_BUF, and buf_overflow().

Referenced by write_note().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ change_book()

static void change_book ( object *  book,
int  msgtype 
)
static

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 authour/title and message content for BOOKs. Also, we will alter books that match archive entries to the archival levels and architypes. -b.t.

Parameters
bookbook to alter. Should be of type BOOK.
msgtypewhat information the book contains.

Definition at line 1119 of file readable.c.

References add_author(), add_book_to_list(), add_string(), titlestruct::archname, arraysize, titlestruct::authour, book_descrpt, create_archetype(), find_title(), free_string(), get_titlelist(), titlestruct::level, llevDebug, llevError, LOG(), MAX_BUF, MAX_TITLE_CHECK, max_titles, titlestruct::name, new_text_name(), titleliststruct::number, object_copy(), object_free_drop_inventory(), object_get_value(), object_set_msg(), object_set_value(), RANDOM, snprintf, and unique_book().

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_monster()

static void do_monster ( archetype *  at)
static

Definition at line 848 of file readable.c.

References first_mon_info, FLAG_CHANGING, FLAG_MONSTER, FLAG_UNAGGRESSIVE, llevError, LOG(), mon, nrofmon, and QUERY_FLAG.

Referenced by init_mon_info().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_spellpath_msg()

static void do_spellpath_msg ( archetype *  at)
static

Callback to write spells in messages

Definition at line 1596 of file readable.c.

References sp_params, stringbuffer_append_string(), and stringbuffer_length().

Referenced by spellpath_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_title()

static title* find_title ( const object *  book,
int  msgtype 
)
static

Search the titlelist (based on msgtype) to see if book matches something already there. IF so, return that title.

Parameters
bookbook we're searching.
msgtypemessage type.
Returns
title if found, NULL if no match.

Definition at line 917 of file readable.c.

References titlestruct::authour, titleliststruct::first_book, get_titlelist(), llevDebug, LOG(), titlestruct::msg_index, titlestruct::name, titlestruct::next, titlestruct::size, and strtoint().

Referenced by change_book().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_all_readable()

void free_all_readable ( void  )

Free all readable-related information.

Definition at line 1994 of file readable.c.

References titlestruct::archname, titlestruct::authour, titleliststruct::first_book, first_mon_info, free_string(), llevDebug, LOG(), titlestruct::name, titlestruct::next, and titleliststruct::next.

Referenced by cleanup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_empty_book()

static title* get_empty_book ( void  )
static

Creates a title.

Returns
new title.
Note
if memory allocation failes, calls fatal().

Definition at line 581 of file readable.c.

References titlestruct::archname, titlestruct::authour, fatal(), titlestruct::level, titlestruct::msg_index, titlestruct::name, titlestruct::next, OUT_OF_MEMORY, and titlestruct::size.

Referenced by add_book_to_list(), and init_book_archive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_empty_booklist()

static titlelist* get_empty_booklist ( void  )
static

Creates a titlelist.

Returns
new titlelist.
Note
if memory allocation failes, calls fatal().

Definition at line 561 of file readable.c.

References fatal(), titleliststruct::first_book, titleliststruct::next, titleliststruct::number, and OUT_OF_MEMORY.

Referenced by get_titlelist(), and init_book_archive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_message_body()

sstring get_message_body ( const GeneralMessage message)

Get a message's body.

Parameters
messagemessage, must not be NULL.
Returns
body.

Definition at line 2103 of file readable.c.

References GeneralMessage::message.

Referenced by knowledge_message_detail().

+ Here is the caller graph for this function:

◆ get_message_face()

const Face* get_message_face ( const GeneralMessage message)

Get a message's face.

Parameters
messagemessage, must not be NULL.
Returns
face, -1 if not defined.

Definition at line 2112 of file readable.c.

References GeneralMessage::face.

Referenced by knowledge_message_face().

+ Here is the caller graph for this function:

◆ get_message_title()

sstring get_message_title ( const GeneralMessage message)

Get a message's title.

Parameters
messagemessage, must not be NULL.
Returns
title.

Definition at line 2094 of file readable.c.

References GeneralMessage::title.

Referenced by knowledge_message_summary().

+ Here is the caller graph for this function:

◆ get_next_mon()

static object* get_next_mon ( const object *  tmp)
static

This function returns the next monster after 'tmp' in the monster list.

Parameters
tmpmonster.
Returns
next monster, or if no match is found, it returns NULL.
Note
list is considered circular, asking for the next of the last element will return the first one.

Definition at line 1332 of file readable.c.

References first_mon_info, and mon.

Referenced by mon_info_msg().

+ Here is the caller graph for this function:

◆ get_random_mon()

object* get_random_mon ( int  level)

Returns a random monster selected from linked list of all monsters in the current game. Changed 971225 to be greater than equal to level passed. Also made choosing by level more random.

Parameters
levelif non-zero, then only monsters greater than that level will be returned.
Returns
random monster, or NULL if failure.

Definition at line 1251 of file readable.c.

References first_mon_info, llevError, LOG(), mon, nrofmon, and RANDOM.

Referenced by alchemy_failure_effect(), and mon_info_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_readable_message_type()

const readable_message_type* get_readable_message_type ( object *  readable)

Get the readable type for an object (hopefully book).

Parameters
readableobject for which we want the readable type.
Returns
type of the book. Will never be NULL.

Definition at line 2081 of file readable.c.

References last_readable_subtype.

Referenced by apply_sign(), book_type_apply(), and spellbook_type_apply().

+ Here is the caller graph for this function:

◆ get_titlelist()

static titlelist* get_titlelist ( int  i)
static

Gets the ith titlelist.

Will create items if they don't exist.

Parameters
iindex to get.
Returns
pointer to the title list referenced by i. Will never be NULL.

Definition at line 606 of file readable.c.

References arraysize, booklist, get_empty_booklist(), llevInfo, LOG(), max_titles, and titleliststruct::next.

Referenced by add_book(), add_book_to_list(), change_book(), find_title(), unique_book(), and write_book_archive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ god_info_msg()

static StringBuffer* god_info_msg ( int  level,
size_t  booksize,
object *  book 
)
static

Generate a message detailing the properties of a random god. Used by the book hack. b.t.

Parameters
levelnumber of elements to give.
booksizedesired length of the book.
bookbook we're writing the information to, for knowledge management.
Returns
StringBuffer with the information that the caller is responsible for cleaning, NULL if information overflows the booksize.

Definition at line 1842 of file readable.c.

References BOOK_BUF, buf, describe_god(), get_rand_god(), GOD_BLESSED, GOD_ENEMY, GOD_HOLYWORD, GOD_IMMUNITIES, GOD_PATHS, GOD_RESISTANCES, GOD_SACRED, llevError, LOG(), object_set_value(), pntr_to_god_obj(), RANDOM, snprintf, stringbuffer_delete(), stringbuffer_length(), and stringbuffer_new().

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_book_archive()

static void init_book_archive ( void  )
static

If not called before, initialize the info list.

This reads in the bookarch file into memory. bookarch is the file created and updated across multiple runs of the program.

Definition at line 716 of file readable.c.

References add_book(), add_string(), titlestruct::archname, arraysize, titlestruct::authour, buf, get_empty_book(), get_empty_booklist(), titlestruct::level, llevDebug, llevInfo, Settings::localdir, LOG(), MAX_BUF, max_titles, titlestruct::msg_index, titlestruct::name, titleliststruct::next, titleliststruct::number, settings, titlestruct::size, and snprintf.

Referenced by init_readable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_mon_info()

static void init_mon_info ( void  )
static

Creates the linked list of pointers to monster archetype objects if not called previously.

Definition at line 868 of file readable.c.

References archetypes_for_each(), do_monster(), llevDebug, LOG(), and nrofmon.

Referenced by init_readable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_readable()

void init_readable ( void  )

Initialize linked lists utilized by message functions in tailor_readable_ob()

This is the function called by the main routine to initialize all the readable information.

Definition at line 886 of file readable.c.

References init_book_archive(), init_mon_info(), llevDebug, and LOG().

Referenced by generate_map(), init_beforeplay(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_formula_book()

static void make_formula_book ( object *  book,
int  level 
)
static

◆ mon_desc()

static StringBuffer* mon_desc ( const object *  mon)
static

Returns a description of the monster. This really needs to be redone, as describe_item really gives a pretty internal description.

Parameters
monmonster to describe.
Returns
new StringBuffer containing the description.

Definition at line 1314 of file readable.c.

References describe_item(), stringbuffer_append_printf(), and stringbuffer_new().

Referenced by mon_info_msg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mon_info_msg()

static StringBuffer* mon_info_msg ( int  level,
size_t  booksize,
object *  book 
)
static

Generate a message detailing the properties of randomly monster(s), and add relevant knowledge markers.

Parameters
levelbook level.
booksizesize (in characters) of the book we want.
bookbook in which we will put the information.
Returns
StringBuffer containing the information.

Definition at line 1360 of file readable.c.

References free_string(), get_next_mon(), get_random_mon(), mon, mon_desc(), object_set_value(), stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_append_stringbuffer(), stringbuffer_delete(), stringbuffer_finish_shared(), stringbuffer_length(), and stringbuffer_new().

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msgfile_msg()

static StringBuffer* msgfile_msg ( object *  book,
size_t  booksize 
)
static

Generate a message drawn randomly from lib/messages.

Parameters
bookbook to fill.
booksizelength of the book we want.
Returns
message to put into book, newly allocated StringBuffer the caller should free.

knowledge marker

Todo:
this would be better in knowledge.c, except this file is in server, not common...

Definition at line 1798 of file readable.c.

References find_archetype(), FREE_AND_COPY, get_random_message(), HUGE_BUF, GeneralMessage::identifier, GeneralMessage::message, object_create_arch(), object_insert_in_ob(), object_set_value(), GeneralMessage::quest_code, snprintf, stringbuffer_append_string(), and stringbuffer_new().

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_text_name()

static void new_text_name ( object *  book,
int  msgtype 
)
static

Only for objects of type BOOK. SPELLBOOK stuff is 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

Parameters
bookbook we want to alter.
msgtypewhat information we want in the book.

Definition at line 956 of file readable.c.

References add_string(), arraysize, art_book_name, formula_book_name, free_string(), gods_book_name, heavy_book_name, light_book_name, mon_book_name, MSGTYPE_ALCHEMY, MSGTYPE_ARTIFACT, MSGTYPE_GODS, MSGTYPE_MONSTER, MSGTYPE_MSGFILE, MSGTYPE_SPELLPATH, titlestruct::name, path_book_name, and RANDOM.

Referenced by change_book(), and make_formula_book().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nstrtok()

int nstrtok ( const char *  buf1,
const char *  buf2 
)

Simple routine to return the number of list items in buf1 as separated by the value of buf2

Parameters
buf1items we want to split.
buf2what to split by.
Returns
number of elements.

Definition at line 637 of file readable.c.

References buf, MAX_BUF, and strlcpy().

Referenced by describe_god(), and strtoktolin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spellpath_msg()

static StringBuffer* spellpath_msg ( int  level,
size_t  booksize,
StringBuffer buf 
)
static

Generate a message detailing the member incantations/prayers (and some of their properties) belonging to a random spellpath.

Parameters
levellevel of the book.
booksizemaximumlength of the book.
bufwhere to store the message. If not NULL, it is supposed to contain the message header.
Returns
buf, newly allocated StringBuffer if buf is NULL.

Definition at line 1630 of file readable.c.

References archetypes_for_each(), booksize, buf, do_spellpath_msg(), titlestruct::level, NRSPELLPATHS, RANDOM, sp_params, spellpathdef, spellpathnames, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_delete(), and stringbuffer_new().

Referenced by tailor_readable_ob().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strtoktolin()

char* strtoktolin ( const char *  buf1,
const char *  buf2,
char *  retbuf,
size_t  size 
)

Takes a string in buf1 and separates it into a list of strings delimited by buf2. Then returns a comma separated string w/ decent punctuation.

Parameters
buf1buffer to split.
buf2what to split buf1 by.
retbufwhere to write the resulting string.
sizelength of retbuf.
Returns
retbuf.

Definition at line 667 of file readable.c.

References buf, MAX_BUF, nstrtok(), snprintf, and strlcpy().

Referenced by describe_god().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tailor_readable_ob()

void tailor_readable_ob ( object *  book,
int  msg_type 
)

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 document. If the value of msg_type is negative, we will randomly choose the kind of message to generate. -b.t. thoma.nosp@m.s@as.nosp@m.tro.p.nosp@m.su.e.nosp@m.du

Parameters
bookthe object we are creating into. Must be a book, can have a level.
msg_typeif it is a positive value, we use that to determine the message type - otherwise a random value is used.

Definition at line 1912 of file readable.c.

References arraysize, artifact_msg(), BOOK_BUF, BOOKSIZE, change_book(), god_info_msg(), titlestruct::level, make_formula_book(), max_titles, mon_info_msg(), msgfile_msg(), MSGTYPE_ALCHEMY, MSGTYPE_ARTIFACT, MSGTYPE_GODS, MSGTYPE_LIB, MSGTYPE_MONSTER, MSGTYPE_SPELLPATH, object_set_msg(), RANDOM, spellpath_msg(), stringbuffer_append_string(), and stringbuffer_finish().

Referenced by fix_generated_item().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unique_book()

static int unique_book ( const object *  book,
int  msgtype 
)
static

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).

Parameters
bookbook we're searching.
msgtypetype of information contained.
Returns

Definition at line 1053 of file readable.c.

References titlestruct::authour, get_titlelist(), titlestruct::name, and titlestruct::next.

Referenced by change_book().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_book_archive()

void write_book_archive ( void  )

Write out the updated book archive to bookarch file.

Definition at line 2031 of file readable.c.

References titlestruct::archname, titlestruct::authour, titleliststruct::first_book, get_titlelist(), titlestruct::level, llevDebug, llevError, Settings::localdir, LOG(), MAX_BUF, titlestruct::msg_index, titlestruct::name, need_to_write_bookarchive, titlestruct::next, titleliststruct::next, of_close(), of_open(), SAVE_MODE, settings, titlestruct::size, and snprintf.

Referenced by cleanup(), and do_specials().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ art_author

const char* const art_author[]
static
Initial value:
= {
"ancient things",
"artifacts",
"Havlor",
"items",
"lost artifacts",
"the ancients",
"treasures",
"useful things"
}

Used by artifact texts

Definition at line 243 of file readable.c.

Referenced by add_author().

◆ art_book_name

const char* const art_book_name[]
static
Initial value:
= {
"collection",
"file",
"files",
"guide",
"handbook",
"index",
"inventory",
"list",
"listing",
"omnibus",
"record",
"record book"
}

Book titles for artifact information.

Definition at line 227 of file readable.c.

Referenced by new_text_name().

◆ art_name_array

const arttypename art_name_array[]
static
Initial value:
= {
{ "Helmet", HELMET },
{ "Amulet", AMULET },
{ "Shield", SHIELD },
{ "Bracers", BRACERS },
{ "Boots", BOOTS },
{ "Cloak", CLOAK },
{ "Gloves", GLOVES },
{ "Gridle", GIRDLE },
{ "Ring", RING },
{ "Horn", ROD },
{ "Missile Weapon", BOW },
{ "Missile", ARROW },
{ "Hand Weapon", WEAPON },
{ "Artifact", SKILL },
{ "Food", FOOD },
{ "Body Armour", ARMOUR }
}

Artiface/item information.

if it isnt listed here, then art_attr_msg() will never generate a message for this type of artifact. -b.t.

Definition at line 207 of file readable.c.

◆ book_author

const char* const book_author[]
static

Used by 'generic' books.

Definition at line 396 of file readable.c.

Referenced by add_author().

◆ book_descrpt

const char* const book_descrpt[]
static
Initial value:
= {
"ancient",
"cryptic",
"cryptical",
"dusty",
"hierarchical",
"grizzled",
"gold-gilt",
"great",
"lost",
"magnificent",
"musty",
"mythical",
"mystical",
"rustic",
"stained",
"silvered",
"transcendental",
"weathered"
}

Book descriptions.

Definition at line 443 of file readable.c.

Referenced by change_book().

◆ booklist

titlelist* booklist = NULL
static

Buffer of books read in from the bookarch file. It's element size does not exceed arraysize(max_titles).

Definition at line 138 of file readable.c.

Referenced by get_titlelist().

◆ booksize

size_t booksize

Definition at line 1590 of file readable.c.

Referenced by spellpath_msg().

◆ buf

Definition at line 1591 of file readable.c.

Referenced by account_char_load(), accounts_load(), add_abilities(), adjust_sign_msg(), animate_weapon(), apply_anim_suffix(), apply_changes_to_player(), apply_check_race_restrictions(), apply_race_and_class(), assets_pack(), attack_message(), attempt_steal(), basic_emote(), can_pay(), cast_consecrate(), cf_get_maps_directory(), cf_log(), cf_object_get_string_property(), cfapi_get_hooks(), cfapi_map_set_map_property(), cfapi_object_get_property(), cfapi_object_split(), cfapi_player_message(), cfapi_set_random_map_variable(), cfpython_globalEventListener(), cfpython_runPluginCommand(), check_login(), check_path(), checkbanned(), checkdm(), choose_cult_monster(), command_addexp(), command_banish(), command_bowmode(), command_cointoss(), command_loadplugin(), command_loadtest(), command_me(), command_party(), command_players(), command_possess(), command_rename_item(), command_statistics(), command_title(), convert_newline(), copy_file(), cost_approx_str(), cost_string_from_value(), costStringFromValue(), create_pathname(), create_singularity(), Crossfire_Object_Say(), delete_character(), describe_attacktype(), describe_item(), describe_monster(), describe_resistance(), describe_spellpath_attenuation(), display_motd(), do_tell(), dragon_ability_gain(), dragon_eat_flesh(), draw_ext_info_format(), draw_one_high_score(), dump_alchemy(), dump_alchemy_costs(), eat_common(), enter_random_map(), esrv_draw_look(), esrv_send_inventory(), esrv_update_stats(), eventListener(), events_execute_global_event(), examine(), food_type_apply(), forbid_play(), generate_monster(), generate_random_map(), getPluginProperty(), globalEventListener(), god_enchants_weapon(), god_examines_item(), god_info_msg(), gravestone_text(), hiscore_load(), hiscore_save(), infect_object(), init_artifacts(), init_attackmess(), init_book_archive(), init_experience(), init_formulae(), init_server(), init_startup(), init_stats(), initPlugins(), key_change_class(), key_confirm_quit(), kill_object(), kill_player(), kill_player_not_permadeath(), kill_player_permadeath(), knowledge_alchemy_can_use_item(), knowledge_god_add(), knowledge_god_face(), knowledge_item_can_be_used_alchemy(), knowledge_process_incremental(), knowledge_show(), knowledge_show_monster_detail(), FacesetLoader::load(), MessageLoader::load(), PngLoader::load(), FaceLoader::load(), TreasureLoader::load(), load_map_header(), load_materials(), load_quests_from_file(), load_races(), load_settings(), load_table_float(), load_table_int(), FaceLoader::loadAnimationBlock(), QuestManager::loadQuestFile(), TreasureLoader::loadTreasure(), LOG(), main(), make_path_to_file(), metaserver2_init(), metaserver2_writer(), monster_format_say(), monster_npc_say(), new_connection(), npcSay(), nstrtok(), ob_describe(), Object_GetAnim(), Object_GetFace(), parse_regions(), party_form(), party_join(), party_leave(), perceive_self(), pets_summon_golem(), pick_up_object(), place_exits(), place_special_exit(), player_lvl_adj(), plugins_find_plugin(), pray(), prepare_weapon(), print_los(), read_ignore_list(), read_map_log(), read_type(), ready_map_name(), real_money_value(), remove_directory(), resurrect_player(), ring_desc(), ring_navar(), ring_scorn(), save_map(), send_arch_info(), send_file(), send_new_char_info(), send_news(), send_rules(), set_exception(), spellpath_msg(), ss_dump_table(), START_TEST(), strtoktolin(), tailor_god_spell(), teardown(), time_format_time(), verify_player(), EditMonstersDialog::write(), write_attribute_file(), write_attribute_index(), write_map_log(), write_map_parameters_to_string(), write_note(), write_rune(), write_type_file(), write_type_index(), and AssetWriter< Animations >::~AssetWriter().

◆ did_first_sp

int did_first_sp

Definition at line 1587 of file readable.c.

◆ done

◆ first_mon_info

objectlink* first_mon_info = NULL
static

Information on monsters.

Definition at line 141 of file readable.c.

Referenced by do_monster(), free_all_readable(), get_next_mon(), and get_random_mon().

◆ formula_author

const char* const formula_author[]
static
Initial value:
= {
"Albertus Magnus",
"alchemy",
"balms",
"creation",
"dusts",
"magical manufacture",
"making",
"philosophical items",
"potions",
"powders",
"the cauldron",
"the lamp black",
"transmutation",
"waters"
}

This isn't used except for empty books.

Definition at line 341 of file readable.c.

Referenced by add_author().

◆ formula_book_name

const char* const formula_book_name[]
static
Initial value:
= {
"cookbook",
"formulary",
"lab book",
"lab notes",
"recipe book",
"experiment record",
"work plan",
"design notes",
"research notes",
"crafting manual"
}

Alchemy (formula) information.

Definition at line 327 of file readable.c.

Referenced by make_formula_book(), and new_text_name().

◆ gods_author

const char* const gods_author[]
static
Initial value:
= {
"cults",
"joy",
"lasting curse",
"madness",
"religions",
"the dead",
"the gods",
"the heirophant",
"the poor priest",
"the priestess",
"pain",
"white"
}

Used by gods texts.

Definition at line 309 of file readable.c.

Referenced by add_author().

◆ gods_book_name

const char* const gods_book_name[]
static
Initial value:
= {
"devotional",
"devout notes",
"divine text",
"divine work",
"holy book",
"holy record",
"illuminated text",
"moral text",
"sacred guide",
"testament",
"transcript"
}

God book information.

Definition at line 294 of file readable.c.

Referenced by new_text_name().

◆ heavy_book_name

const char* const heavy_book_name[]
static
Initial value:
= {
"catalog",
"compendium",
"dissertation",
"guide",
"manual",
"opus",
"tome",
"treatise",
"volume",
"work"
}

Name for big books.

Definition at line 382 of file readable.c.

Referenced by new_text_name().

◆ last_readable_subtype

const int last_readable_subtype = arraysize(readable_message_types)
static

Number of elements in readable_message_types.

Definition at line 534 of file readable.c.

Referenced by get_readable_message_type().

◆ level

◆ light_book_name

const char* const light_book_name[]
static
Initial value:
= {
"calendar",
"datebook",
"diary",
"essay",
"guidebook",
"handbook",
"ledger",
"notes",
"notebook",
"octavo",
"opuscule",
"pamphlet",
"practicum",
"script",
"transcript"
}

Generic book informationUsed by msg file and 'generic' books.

Definition at line 363 of file readable.c.

Referenced by new_text_name().

◆ max_titles

const int max_titles[6]
static
Initial value:
= {
}
static const char *const heavy_book_name[]
Definition: readable.c:382
static const char *const path_book_name[]
Definition: readable.c:173
static const char *const mon_book_name[]
Definition: readable.c:257
static const char *const book_author[]
Definition: readable.c:396
#define arraysize(arrayname)
Definition: readable.c:97
static const char *const gods_author[]
Definition: readable.c:309
static const char *const mon_author[]
Definition: readable.c:275
static const char *const gods_book_name[]
Definition: readable.c:294
static const char *const art_author[]
Definition: readable.c:243
static const char *const formula_author[]
Definition: readable.c:341
static const char *const path_author[]
Definition: readable.c:183
static const char *const light_book_name[]
Definition: readable.c:363
static const char *const formula_book_name[]
Definition: readable.c:327
static const char *const art_book_name[]
Definition: readable.c:227

Number of titles for different name lists.

Definition at line 537 of file readable.c.

Referenced by change_book(), get_titlelist(), init_book_archive(), and tailor_readable_ob().

◆ mon_author

const char* const mon_author[]
static
Initial value:
= {
"beasts",
"creatures",
"dezidens",
"dwellers",
"evil nature",
"life",
"monsters",
"nature",
"new life",
"residents",
"the spawn",
"the living",
"things"
}

Used by monster beastuary texts.

Definition at line 275 of file readable.c.

Referenced by add_author().

◆ mon_book_name

const char* const mon_book_name[]
static
Initial value:
= {
"beastuary",
"catalog",
"compilation",
"collection",
"encyclopedia",
"guide",
"handbook",
"list",
"manual",
"notes",
"omnibus",
"record",
"register",
"volume"
}

Monster book information.

Definition at line 257 of file readable.c.

Referenced by new_text_name().

◆ need_to_write_bookarchive

int need_to_write_bookarchive = 0
static

If set then we have information to save.

Definition at line 144 of file readable.c.

Referenced by add_book_to_list(), and write_book_archive().

◆ nrofmon

int nrofmon = 0
static

Number of monsters in the first_mon_info list.

Definition at line 143 of file readable.c.

Referenced by do_monster(), get_random_mon(), and init_mon_info().

◆ path_author

const char* const path_author[]
static
Initial value:
= {
"aether",
"arcana",
"astral byways",
"connections",
"the Grey Council",
"deep pathways",
"knowledge",
"magic",
"mystic ways",
"pathways",
"power",
"spells",
"transforms",
"the mystic veil",
"unknown spells"
}

Used by spellpath texts.

Definition at line 183 of file readable.c.

Referenced by add_author().

◆ path_book_name

const char* const path_book_name[]
static
Initial value:
= {
"codex",
"compendium",
"documentary",
"exposition",
"tables",
"treatise"
}

Book names for path information.

Definition at line 173 of file readable.c.

Referenced by new_text_name().

◆ pnum

uint32_t pnum

Definition at line 1588 of file readable.c.

◆ prayers

int prayers

Definition at line 1586 of file readable.c.

◆ readable_message_types

const readable_message_type readable_message_types[]
static

Each line of this array is a readable subtype. Be careful to keep the order. If you add readable subtype, add them at the bottom of the list. Never delete a subtype because index is used as subtype parameter in arch files!

Definition at line 470 of file readable.c.

◆ sp_params

struct { ... } sp_params
Todo:
remove when C++ & lambdas

Referenced by do_spellpath_msg(), and spellpath_msg().

◆ spellpathdef

const uint32_t spellpathdef[NRSPELLPATHS]
static
Initial value:
= {
}
#define PATH_MISSILE
Definition: spells.h:17
#define PATH_MIND
Definition: spells.h:23
#define PATH_TURNING
Definition: spells.h:29
#define PATH_LIGHT
Definition: spells.h:32
#define PATH_RESTORE
Definition: spells.h:21
#define PATH_FIRE
Definition: spells.h:14
#define PATH_ELEC
Definition: spells.h:16
#define PATH_TRANSMUTE
Definition: spells.h:27
#define PATH_DEATH
Definition: spells.h:31
#define PATH_PROT
Definition: spells.h:13
#define PATH_SELF
Definition: spells.h:18
#define PATH_CREATE
Definition: spells.h:24
#define PATH_INFO
Definition: spells.h:26
#define PATH_FROST
Definition: spells.h:15
#define PATH_TRANSFER
Definition: spells.h:28
#define PATH_ABJURE
Definition: spells.h:20
#define PATH_DETONATE
Definition: spells.h:22
#define PATH_WOUNDING
Definition: spells.h:30
#define PATH_TELE
Definition: spells.h:25
#define PATH_SUMMON
Definition: spells.h:19

Spellpath information.

Definition at line 149 of file readable.c.

Referenced by spellpath_msg().