Crossfire Server, Trunk  R20513
Data Structures | Typedefs | Functions | Variables
knowledge.c File Reference

Handling of player knowledge of various things. More...

#include "global.h"
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "sproto.h"
#include "output_file.h"
Include dependency graph for knowledge.c:

Go to the source code of this file.

Data Structures

struct  knowledge_item
 One known item for a player. More...
 
struct  knowledge_player
 Information about a player. More...
 
struct  knowledge_type
 One item type that may be known to the player. More...
 

Typedefs

typedef int(* knowledge_add_item) (struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)
 Add knowledge information to the player's knowledge. More...
 
typedef void(* knowledge_attempt) (player *pl, const struct knowledge_item *item)
 Attempt an alchemy based on the specified knowledge. More...
 
typedef StringBuffer *(* knowledge_can_use_alchemy) (sstring code, const char *item, StringBuffer *buf, int index)
 Check if an item can be used for a recipe, and fill the return buffer if it's the case. More...
 
typedef void(* knowledge_detail) (const char *code, StringBuffer *buf)
 Function to fill the StringBuffer with a detailed description of an item. More...
 
typedef unsigned(* knowledge_face) (sstring code)
 Get the face for a knowledge item. More...
 
typedef int(* knowledge_is_valid_item) (const char *code)
 Function to check if the specified item is valid. More...
 
typedef struct knowledge_item knowledge_item
 One known item for a player. More...
 
typedef struct knowledge_player knowledge_player
 Information about a player. More...
 
typedef void(* knowledge_summary) (const char *code, StringBuffer *buf)
 Function to fill the StringBuffer with the short description of an item. More...
 
typedef struct knowledge_type knowledge_type
 One item type that may be known to the player. More...
 

Functions

void command_knowledge (object *pl, const char *params)
 Handle the 'knowledge' for a player. More...
 
void free_knowledge (void)
 Free all knowledge data. More...
 
static void free_knowledge_items (knowledge_player *kp)
 Free all knowledge items for a player. More...
 
static void free_knowledge_player (knowledge_player *kp)
 Totally free a knowledge structure, and its items. More...
 
static int knowledge_add (knowledge_player *current, const char *item, const knowledge_type *kt, player *pl)
 Add a knowledge item to a player's store if not found yet. More...
 
static void knowledge_alchemy_attempt (player *pl, const knowledge_item *item)
 Attempt an alchemy recipe through the knowledge system. More...
 
static StringBufferknowledge_alchemy_can_use_item (sstring code, const char *item, StringBuffer *buf, int index)
 Check if an item can be used for a recipe, and fill the return buffer if it's the case. More...
 
static void knowledge_alchemy_detail (const char *value, StringBuffer *buf)
 Give the full description of the alchemy recpie. More...
 
static unsigned knowledge_alchemy_face (sstring code)
 Try to get a face for an alchemy recipe. More...
 
static const recipeknowledge_alchemy_get_recipe (const char *value)
 Get a recipe from the internal code. More...
 
static void knowledge_alchemy_summary (const char *value, StringBuffer *buf)
 Give the title of the alchemy recpie. More...
 
static int knowledge_alchemy_validate (const char *item)
 Check if an alchemy recipe is still ok. More...
 
static void knowledge_display (object *pl, const char *params)
 Display all a player's knowledge. More...
 
static void knowledge_do_attempt (object *pl, const char *params)
 Player attempts something on a knowledge, get item and try it. More...
 
static void knowledge_do_display (object *pl, const knowledge_type *show_only, const char *search)
 Actually display knowledge list. More...
 
static const knowledge_typeknowledge_find (const char *type)
 Find a knowledge handler from its type. More...
 
void knowledge_first_player_save (player *pl)
 Ensure the knowledge state is correctly saved for the player. More...
 
static knowledge_playerknowledge_get_or_create (const player *pl)
 Find or create the knowledge store for a player. More...
 
void knowledge_give (player *pl, const char *marker, const object *book)
 Give a knowledge item from its code. More...
 
static int knowledge_god_add (struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)
 Add god information to the player's knowledge, handling the multiple monster case. More...
 
static void knowledge_god_detail (const char *item, StringBuffer *buf)
 Describe in detail a god. More...
 
static unsigned knowledge_god_face (sstring code)
 Get the face for a god. More...
 
static void knowledge_god_summary (const char *item, StringBuffer *buf)
 God information summary. More...
 
static int knowledge_god_validate (const char *item)
 Check if a god knowledge item is still valid. More...
 
void knowledge_item_can_be_used_alchemy (object *op, const object *item)
 Displays known alchemy recipes an item can be used in. More...
 
static int knowledge_known (const knowledge_player *current, const char *item, const knowledge_type *kt)
 Check whether a player already knows a knowledge item or not. More...
 
static void knowledge_message_detail (const char *value, StringBuffer *buf)
 Give the full description of a message. More...
 
static unsigned knowledge_message_face (sstring code)
 Get the face for a message. More...
 
static void knowledge_message_summary (const char *value, StringBuffer *buf)
 Give the title of a message. More...
 
static int knowledge_message_validate (const char *item)
 Check if a message is still valid. More...
 
static int knowledge_monster_add (struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)
 Add monster information to the player's knowledge, handling the multiple monster case. More...
 
static void knowledge_monster_detail (const char *item, StringBuffer *buf)
 Describe in detail a monster. More...
 
static unsigned knowledge_monster_face (sstring code)
 Get the face for a monster. More...
 
static void knowledge_monster_summary (const char *item, StringBuffer *buf)
 Monster information summary. More...
 
static int knowledge_monster_validate (const char *item)
 Check if a monster knowledge item is still valid. More...
 
int knowledge_player_knows (const player *pl, const char *knowledge)
 Determines whether a player knows a specific knowledge or not. More...
 
void knowledge_process_incremental (void)
 Incrementally send knowledge information to players, and remove information for players who left. More...
 
void knowledge_read (player *pl, object *book)
 Player is reading a book, give knowledge if needed, warn player, and such. More...
 
static void knowledge_read_player_data (knowledge_player *kp)
 Read all knowledge data for a player from disk, discarding invalid data. More...
 
void knowledge_send_info (socket_struct *ns)
 Send the reply_info for 'knowledge_info'. More...
 
void knowledge_send_known (player *pl)
 Send initial known knowledge to player, if requested. More...
 
static void knowledge_show (object *pl, const char *params)
 Show the details of a knowledge item. More...
 
void knowledge_show_monster_detail (object *op, const char *name)
 Display the details of a monster if the player knows them. More...
 
static void knowledge_write_player_data (const knowledge_player *kp)
 Store all knowledge data for a player to disk. More...
 

Variables

static knowledge_playerknowledge_global = NULL
 All known loaded knowledge for a player. More...
 
static const knowledge_type knowledges []
 All handled knowledge items. More...
 

Detailed Description

Handling of player knowledge of various things.

Right now, the following items are considered:

Knowledge is specific for a player, and organized in 'items'. One item is a specific formulae or monster, whatever is coded.

Note that some things are done through functions in readable.c, especially item marking.

Knowledge is persistent and without errors. Maybe that could be changed in the future?

Only use non static functions when using this file.

Loading is done on a per-demand basis, writing at each change.

Knowledge is stored in a "player.knowledge" file in the player's directory.

Knowledge relies on key/values. Key is "knowledge_marker", value is specific to the item class considered and must have a left-side part, delimited by a double dot, specifying a type.

The value should be enough to determine a unique formulae or monster etc.

A type is linked to various functions for displaying, checking the key value.

During loading, obsolete items (eg formula changed) are discarded.

If the client has notifications support of at least 2, then knowledge information is sent as needed, incrementally as to not freeze the server.

Todo:
  • make knowledge shareable between players
  • more things to keep trace of

Definition in file knowledge.c.

Typedef Documentation

typedef int(* knowledge_add_item) (struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)

Add knowledge information to the player's knowledge.

Parameters
currentwhere to add the information to.
itemwhat to add, format specific to the type.
typepointer of the handler type.
plwho we're adding the information for.
Returns
count of actually added items.

Definition at line 100 of file knowledge.c.

typedef void(* knowledge_attempt) (player *pl, const struct knowledge_item *item)

Attempt an alchemy based on the specified knowledge.

Parameters
plwho attempts the recipe.
itemitem to attempt, must not be NULL.

Definition at line 126 of file knowledge.c.

typedef StringBuffer*(* knowledge_can_use_alchemy) (sstring code, const char *item, StringBuffer *buf, int index)

Check if an item can be used for a recipe, and fill the return buffer if it's the case.

Parameters
codeknowledge internal code.
itemitem's name, including title if there is one.
bufwhere to put the results. If NULL a new one can be allocated.
indexthe knowledge index for this item.
Returns
buf, if it was NULL and the recipe uses the item, a new one is allocated.

Definition at line 110 of file knowledge.c.

typedef void(* knowledge_detail) (const char *code, StringBuffer *buf)

Function to fill the StringBuffer with a detailed description of an item.

Parameters
codeknowledge internal code.
bufwhere to write the description, must not be NULL.

Definition at line 83 of file knowledge.c.

typedef unsigned(* knowledge_face) (sstring code)

Get the face for a knowledge item.

Parameters
codeknowledge internal code.
Returns
face number, -1 (as unsigned) for invalid.

Definition at line 117 of file knowledge.c.

typedef int(* knowledge_is_valid_item) (const char *code)

Function to check if the specified item is valid.

Parameters
codeknowledge internal code.
Returns
0 if invalid, non 0 if valid.

Definition at line 90 of file knowledge.c.

One known item for a player.

Information about a player.

typedef void(* knowledge_summary) (const char *code, StringBuffer *buf)

Function to fill the StringBuffer with the short description of an item.

Parameters
codeknowledge internal code.
bufwhere to write the summary, must not be NULL.

Definition at line 76 of file knowledge.c.

One item type that may be known to the player.

Function Documentation

void command_knowledge ( object pl,
const char *  params 
)

Handle the 'knowledge' for a player.

Parameters
plwho is using the command.
paramsadditional parameters.

Definition at line 1221 of file knowledge.c.

References command_help(), obj::contr, knowledge_display(), knowledge_do_attempt(), knowledge_do_display(), knowledge_show(), llevError, LOG(), and obj::name.

Here is the call graph for this function:

void free_knowledge ( void  )

Free all knowledge data.

Definition at line 1288 of file knowledge.c.

References free_knowledge_player(), knowledge_global, and knowledge_player::next.

Referenced by cleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_knowledge_items ( knowledge_player kp)
static

Free all knowledge items for a player.

Parameters
kpwhat to free.

Definition at line 1260 of file knowledge.c.

References free_string(), knowledge_item::item, knowledge_player::item_allocated, knowledge_player::item_count, and knowledge_player::items.

Referenced by free_knowledge_player().

Here is the call graph for this function:

Here is the caller graph for this function:

static void free_knowledge_player ( knowledge_player kp)
static

Totally free a knowledge structure, and its items.

Parameters
kpstructure to free, becomes invalid.

Definition at line 1279 of file knowledge.c.

References free_knowledge_items(), free_string(), and knowledge_player::player_name.

Referenced by free_knowledge(), and knowledge_process_incremental().

Here is the call graph for this function:

Here is the caller graph for this function:

static int knowledge_add ( knowledge_player current,
const char *  item,
const knowledge_type kt,
player pl 
)
static

Add a knowledge item to a player's store if not found yet.

Parameters
currentwhere to look for the knowledge.
iteminternal value of the item to give, considered atomic.
kthow to handle the knowledge type.
plwho we're adding the information to.
Returns
0 if item was already known, 1 else.

Use malloc instead of calloc here. We're setting all relevant values, anyway.

Definition at line 561 of file knowledge.c.

References add_string(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_allocated, knowledge_player::item_count, knowledge_player::items, and knowledge_known().

Referenced by knowledge_god_add(), and knowledge_monster_add().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_alchemy_attempt ( player pl,
const knowledge_item item 
)
static
static StringBuffer* knowledge_alchemy_can_use_item ( sstring  code,
const char *  item,
StringBuffer buf,
int  index 
)
static

Check if an item can be used for a recipe, and fill the return buffer if it's the case.

Parameters
coderecipe internal code.
itemitem's name, including title if there is one.
bufwhere to put the results. If NULL a new one can be allocated.
indexthe knowledge index for this item.
Returns
buf, if it was null and the recipe uses the item, a new one is allocated.

Definition at line 294 of file knowledge.c.

References recipestruct::arch_name, recipestruct::arch_names, archt::clone, find_archetype(), recipestruct::ingred, knowledge_alchemy_get_recipe(), linked_char::name, knowledge_type::name, obj::name, linked_char::next, knowledge_player::next, RANDOM, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_new(), recipestruct::title, and obj::title.

Here is the call graph for this function:

static void knowledge_alchemy_detail ( const char *  value,
StringBuffer buf 
)
static

Give the full description of the alchemy recpie.

Parameters
valuerecipe internal value.
bufwhere to store the detail.
Todo:
merge with stuff in readable.c

Definition at line 237 of file knowledge.c.

References recipestruct::arch_name, recipestruct::arch_names, recipestruct::cauldron, archt::clone, find_archetype(), recipestruct::ingred, knowledge_alchemy_get_recipe(), MAX_BUF, linked_char::name, knowledge_type::name, obj::name, linked_char::next, knowledge_player::next, query_name(), RANDOM, snprintf, stringbuffer_append_printf(), recipestruct::title, and obj::title.

Here is the call graph for this function:

static unsigned knowledge_alchemy_face ( sstring  code)
static
static const recipe* knowledge_alchemy_get_recipe ( const char *  value)
static

Get a recipe from the internal code.

Parameters
valuecode to get value for.
Returns
recipe, NULL if not found.

Definition at line 169 of file knowledge.c.

References get_formulalist(), recipestruct::index, recipeliststruct::items, recipestruct::next, and recipestruct::title.

Referenced by knowledge_alchemy_attempt(), knowledge_alchemy_can_use_item(), knowledge_alchemy_detail(), knowledge_alchemy_face(), knowledge_alchemy_summary(), and knowledge_alchemy_validate().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_alchemy_summary ( const char *  value,
StringBuffer buf 
)
static

Give the title of the alchemy recpie.

Parameters
valuerecipe internal value.
bufwhere to put the information.
Todo:
merge with stuff in readable.c

Definition at line 207 of file knowledge.c.

References recipestruct::arch_name, recipestruct::arch_names, archt::clone, find_archetype(), knowledge_alchemy_get_recipe(), obj::name, RANDOM, stringbuffer_append_printf(), recipestruct::title, and obj::title.

Here is the call graph for this function:

static int knowledge_alchemy_validate ( const char *  item)
static

Check if an alchemy recipe is still ok.

Parameters
itemwhat to check for
Returns
0 if non valid, 1 else.

Definition at line 282 of file knowledge.c.

References knowledge_alchemy_get_recipe().

Here is the call graph for this function:

static void knowledge_display ( object pl,
const char *  params 
)
static

Display all a player's knowledge.

Parameters
plwho to display knowledge of.
paramsadditionnal parameters.

Definition at line 1141 of file knowledge.c.

References draw_ext_info(), draw_ext_info_format(), knowledge_do_display(), MSG_TYPE_CLIENT_NOTICE, MSG_TYPE_MISC, knowledge_type::name, NDI_UNIQUE, and knowledge_type::type.

Referenced by command_knowledge().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_do_attempt ( object pl,
const char *  params 
)
static

Player attempts something on a knowledge, get item and try it.

Parameters
plwho is trying.
paramscommand parameters.

Definition at line 1197 of file knowledge.c.

References knowledge_type::attempt_alchemy, obj::contr, draw_ext_info(), knowledge_item::handler, knowledge_player::item_count, knowledge_player::items, knowledge_get_or_create(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, and NDI_UNIQUE.

Referenced by command_knowledge().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_do_display ( object pl,
const knowledge_type show_only,
const char *  search 
)
static

Actually display knowledge list.

Parameters
plwho to display to.
show_onlyif not NULL, only display this knowledge type.
searchif not NULL, only display items having the summary or detail contain the string. Must be either NULL or a non empty string.

Definition at line 1076 of file knowledge.c.

References obj::contr, knowledge_type::detail, draw_ext_info(), draw_ext_info_format(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, knowledge_get_or_create(), MSG_TYPE_CLIENT_NOTICE, MSG_TYPE_MISC, knowledge_type::name, NDI_UNIQUE, stringbuffer_finish(), stringbuffer_new(), knowledge_type::summary, and knowledge_type::type.

Referenced by command_knowledge(), and knowledge_display().

Here is the call graph for this function:

Here is the caller graph for this function:

static const knowledge_type* knowledge_find ( const char *  type)
static

Find a knowledge handler from its type.

Parameters
typeinternal type name.
Returns
handler, NULL if not found.

Definition at line 880 of file knowledge.c.

Referenced by knowledge_give(), knowledge_player_knows(), and knowledge_read_player_data().

Here is the caller graph for this function:

void knowledge_first_player_save ( player pl)

Ensure the knowledge state is correctly saved for the player.

This function should only be called once, when the player's save directory is created. All other knowledge functions save the state automatically, but save can only happen when the player directory exists.

Parameters
plwho to save the state for.

Definition at line 1431 of file knowledge.c.

References knowledge_global, knowledge_write_player_data(), obj::name, knowledge_player::next, pl::ob, and knowledge_player::player_name.

Referenced by save_player().

Here is the call graph for this function:

Here is the caller graph for this function:

static knowledge_player* knowledge_get_or_create ( const player pl)
static

Find or create the knowledge store for a player.

Will load data if required. fatal() will be called if memory failure.

Parameters
plwho to find data for.
Returns
data store, never NULL.

Definition at line 981 of file knowledge.c.

References add_refcount(), fatal(), knowledge_global, knowledge_read_player_data(), obj::name, knowledge_player::next, socket_struct::notifications, pl::ob, OUT_OF_MEMORY, knowledge_player::player_name, knowledge_player::sent_up_to, and pl::socket.

Referenced by knowledge_do_attempt(), knowledge_do_display(), knowledge_give(), knowledge_item_can_be_used_alchemy(), knowledge_player_knows(), knowledge_send_known(), knowledge_show(), and knowledge_show_monster_detail().

Here is the call graph for this function:

Here is the caller graph for this function:

void knowledge_give ( player pl,
const char *  marker,
const object book 
)

Give a knowledge item from its code.

Parameters
plwho to give the knowldge to.
markerknowledge's code.
bookoptional item containing the knowledge code.

Definition at line 1009 of file knowledge.c.

References knowledge_type::add, draw_ext_info(), fatal(), pl::has_directory, knowledge_player::items, knowledge_find(), knowledge_get_or_create(), knowledge_write_player_data(), llevError, LOG(), MSG_TYPE_CLIENT_NOTICE, MSG_TYPE_MISC, obj::name, NDI_UNIQUE, pl::ob, OUT_OF_MEMORY, knowledge_type::type, and knowledge_type::validate.

Referenced by cfapi_player_knowledge(), and knowledge_read().

Here is the call graph for this function:

Here is the caller graph for this function:

static int knowledge_god_add ( struct knowledge_player current,
const char *  item,
const struct knowledge_type type,
player pl 
)
static

Add god information to the player's knowledge, handling the multiple monster case.

Parameters
currentwhere to add the information to.
itemgod to add, a dot separating the exact knowledge.
typepointer of the monster type.
plwho we're adding the information to.
Returns
count of actually added items.

Definition at line 741 of file knowledge.c.

References free_string(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, knowledge_add(), llevError, LOG(), strdup_local, stringbuffer_append_printf(), stringbuffer_finish_shared(), and stringbuffer_new().

Here is the call graph for this function:

static void knowledge_god_detail ( const char *  item,
StringBuffer buf 
)
static

Describe in detail a god.

Parameters
itemknowledge item for the god (object name and what is known).
bufwhere to put the description.
Todo:
merge with stuff in readable.c

Definition at line 689 of file knowledge.c.

References archt::clone, describe_god(), find_archetype_by_object_name(), llevError, LOG(), and strdup_local.

Here is the call graph for this function:

static unsigned knowledge_god_face ( sstring  code)
static

Get the face for a god.

Parameters
codegod's code.
Returns
face, -1 as unsigned if invalid.

Definition at line 787 of file knowledge.c.

References archt::clone, obj::face, find_archetype(), MAX_BUF, new_face_struct::number, snprintf, and tolower.

Here is the call graph for this function:

static void knowledge_god_summary ( const char *  item,
StringBuffer buf 
)
static

God information summary.

Parameters
itemknowledge item.
bufwhere to put the information.
Todo:
merge with stuff in readable.c

Definition at line 673 of file knowledge.c.

References strdup_local, and stringbuffer_append_printf().

Here is the call graph for this function:

static int knowledge_god_validate ( const char *  item)
static

Check if a god knowledge item is still valid.

Parameters
itemmonster to check
Returns
0 if invalid, 1 if valid.

Definition at line 718 of file knowledge.c.

References find_archetype_by_object_name(), llevError, LOG(), and strdup_local.

Here is the call graph for this function:

void knowledge_item_can_be_used_alchemy ( object op,
const object item 
)

Displays known alchemy recipes an item can be used in.

Parameters
opwho to display recipes for.
itemwhat to check formulae for.

Definition at line 1342 of file knowledge.c.

References obj::contr, draw_ext_info(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, knowledge_get_or_create(), MAX_BUF, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE, knowledge_type::name, obj::name, NDI_UNIQUE, PLAYER, snprintf, stringbuffer_append_string(), stringbuffer_finish(), obj::title, obj::type, and knowledge_type::use_alchemy.

Referenced by examine().

Here is the call graph for this function:

Here is the caller graph for this function:

static int knowledge_known ( const knowledge_player current,
const char *  item,
const knowledge_type kt 
)
static

Check whether a player already knows a knowledge item or not.

Parameters
currentplayer to check.
itemwhat to check for.
ktthe knowledge type for item.
Returns
0 if item is known, 1 else.

Definition at line 542 of file knowledge.c.

References knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, and knowledge_type::type.

Referenced by knowledge_add(), knowledge_player_knows(), and knowledge_show_monster_detail().

Here is the caller graph for this function:

static void knowledge_message_detail ( const char *  value,
StringBuffer buf 
)
static

Give the full description of a message.

Parameters
valuemessage internal value.
bufwhere to store the detail.
Todo:
merge with stuff in readable.c

Definition at line 831 of file knowledge.c.

References get_message_body(), get_message_from_identifier(), and stringbuffer_append_printf().

Here is the call graph for this function:

static unsigned knowledge_message_face ( sstring  code)
static

Get the face for a message.

Parameters
codemessage's code.
Returns
face, -1 as unsigned if invalid.

Definition at line 855 of file knowledge.c.

References get_message_face(), and get_message_from_identifier().

Here is the call graph for this function:

static void knowledge_message_summary ( const char *  value,
StringBuffer buf 
)
static

Give the title of a message.

Parameters
valuemessage internal value.
bufwhere to put the information.
Todo:
merge with stuff in readable.c

Definition at line 815 of file knowledge.c.

References get_message_from_identifier(), get_message_title(), and stringbuffer_append_printf().

Here is the call graph for this function:

static int knowledge_message_validate ( const char *  item)
static

Check if a message is still valid.

Parameters
itemwhat to check for
Returns
0 if non valid, 1 else.

Definition at line 846 of file knowledge.c.

References get_message_from_identifier().

Here is the call graph for this function:

static int knowledge_monster_add ( struct knowledge_player current,
const char *  item,
const struct knowledge_type type,
player pl 
)
static

Add monster information to the player's knowledge, handling the multiple monster case.

Parameters
currentwhere to add the information to.
itemmonster to add, can be separated by dots for multiple ones.
typepointer of the monster type.
plwho we're adding the information to.
Returns
count of actually added items.

Definition at line 636 of file knowledge.c.

References knowledge_add(), and strdup_local.

Here is the call graph for this function:

static void knowledge_monster_detail ( const char *  item,
StringBuffer buf 
)
static

Describe in detail a monster.

Parameters
itemknowledge item for the monster (archetype name).
bufwhere to put the description.
Todo:
merge with stuff in readable.c

Definition at line 606 of file knowledge.c.

References archt::clone, describe_item(), find_archetype(), obj::name, and stringbuffer_append_printf().

Referenced by knowledge_show_monster_detail().

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned knowledge_monster_face ( sstring  code)
static

Get the face for a monster.

Parameters
codemonster's code.
Returns
face, -1 as unsigned if invalid.

Definition at line 658 of file knowledge.c.

References blank_face, archt::clone, obj::face, find_archetype(), and new_face_struct::number.

Here is the call graph for this function:

static void knowledge_monster_summary ( const char *  item,
StringBuffer buf 
)
static

Monster information summary.

Parameters
itemknowledge item.
bufwhere to put the information.
Todo:
merge with stuff in readable.c

Definition at line 592 of file knowledge.c.

References archt::clone, find_archetype(), obj::name, and stringbuffer_append_printf().

Here is the call graph for this function:

static int knowledge_monster_validate ( const char *  item)
static

Check if a monster knowledge item is still valid.

Parameters
itemmonster to check
Returns
0 if invalid, 1 if valid.

Definition at line 621 of file knowledge.c.

References archt::clone, try_find_archetype(), and obj::type.

Here is the call graph for this function:

int knowledge_player_knows ( const player pl,
const char *  knowledge 
)

Determines whether a player knows a specific knowledge or not.

Parameters
plwho to check knowledge for.
knowledgewhat to check for, in format "type:(type specific value)".
Returns
0 if item is known, 1 else.

Definition at line 1306 of file knowledge.c.

References knowledge_find(), knowledge_get_or_create(), knowledge_known(), llevError, LOG(), MAX_BUF, snprintf, and knowledge_type::type.

Referenced by cfapi_player_knowledge().

Here is the call graph for this function:

Here is the caller graph for this function:

void knowledge_process_incremental ( void  )
void knowledge_read ( player pl,
object book 
)

Player is reading a book, give knowledge if needed, warn player, and such.

Parameters
plwho is reading.
bookwhat is read.

Definition at line 1064 of file knowledge.c.

References knowledge_give(), and object_get_value().

Referenced by book_type_apply().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_read_player_data ( knowledge_player kp)
static

Read all knowledge data for a player from disk, discarding invalid data.

Parameters
kpplayer structure to load data into.

Definition at line 926 of file knowledge.c.

References add_string(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_allocated, knowledge_player::item_count, knowledge_player::items, knowledge_find(), llevDebug, llevError, Settings::localdir, LOG(), MAX_BUF, knowledge_player::player_name, Settings::playerdir, settings, snprintf, knowledge_type::type, and knowledge_type::validate.

Referenced by knowledge_get_or_create().

Here is the call graph for this function:

Here is the caller graph for this function:

void knowledge_send_info ( socket_struct ns)

Send the reply_info for 'knowledge_info'.

Parameters
nssocket to send information to.

Definition at line 1382 of file knowledge.c.

References knowledge_type::attempt_alchemy, esrv_send_face(), knowledge_type::face, socket_struct::faces_sent, find_face(), knowledge_type::name, NS_FACESENT_FACE, Send_With_Handling(), SockList_AddPrintf(), SockList_AddString(), SockList_Init(), SockList_Term(), and knowledge_type::type.

Referenced by request_info_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void knowledge_send_known ( player pl)

Send initial known knowledge to player, if requested.

Parameters
plwho to send knowledge for.

Definition at line 1411 of file knowledge.c.

References knowledge_get_or_create(), socket_struct::notifications, knowledge_player::sent_up_to, and pl::socket.

Referenced by check_login().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_show ( object pl,
const char *  params 
)
static

Show the details of a knowledge item.

Parameters
plwho is asking for details.
paramsadditional parameters, should contain the knowledge item number.

Definition at line 1171 of file knowledge.c.

References obj::contr, knowledge_type::detail, draw_ext_info(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, knowledge_get_or_create(), MSG_TYPE_CLIENT_NOTICE, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, MSG_TYPE_MISC, NDI_UNIQUE, stringbuffer_finish(), and stringbuffer_new().

Referenced by command_knowledge().

Here is the call graph for this function:

Here is the caller graph for this function:

void knowledge_show_monster_detail ( object op,
const char *  name 
)

Display the details of a monster if the player knows them.

Parameters
opplayer asking for details.
namemonster's archetype name.

Definition at line 1536 of file knowledge.c.

References obj::contr, draw_ext_info(), knowledge_get_or_create(), knowledge_known(), knowledge_monster_detail(), MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_EXAMINE, NDI_UNIQUE, stringbuffer_finish(), and stringbuffer_new().

Referenced by examine_monster().

Here is the call graph for this function:

Here is the caller graph for this function:

static void knowledge_write_player_data ( const knowledge_player kp)
static

Store all knowledge data for a player to disk.

Parameters
kpplayer data to store.
Todo:
rename/backup, stuff like that

Definition at line 895 of file knowledge.c.

References draw_ext_info(), knowledge_item::handler, knowledge_item::item, knowledge_player::item_count, knowledge_player::items, Settings::localdir, MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOADSAVE, NDI_ALL_DMS, NDI_UNIQUE, of_close(), of_open(), knowledge_player::player_name, Settings::playerdir, settings, snprintf, and knowledge_type::type.

Referenced by knowledge_first_player_save(), and knowledge_give().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

knowledge_player* knowledge_global = NULL
static

All known loaded knowledge for a player.

Definition at line 161 of file knowledge.c.

Referenced by free_knowledge(), knowledge_first_player_save(), knowledge_get_or_create(), and knowledge_process_incremental().

const knowledge_type knowledges[]
static
Initial value:
= {
{ "message", knowledge_message_summary, knowledge_message_detail, knowledge_message_validate, knowledge_add, "messages", NULL, NULL, "knowledge_messages.111", knowledge_message_face },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
}
static unsigned knowledge_god_face(sstring code)
Get the face for a god.
Definition: knowledge.c:787
static int knowledge_add(knowledge_player *current, const char *item, const knowledge_type *kt, player *pl)
Add a knowledge item to a player&#39;s store if not found yet.
Definition: knowledge.c:561
static int knowledge_god_add(struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)
Add god information to the player&#39;s knowledge, handling the multiple monster case.
Definition: knowledge.c:741
static void knowledge_alchemy_summary(const char *value, StringBuffer *buf)
Give the title of the alchemy recpie.
Definition: knowledge.c:207
static void knowledge_message_detail(const char *value, StringBuffer *buf)
Give the full description of a message.
Definition: knowledge.c:831
static void knowledge_monster_summary(const char *item, StringBuffer *buf)
Monster information summary.
Definition: knowledge.c:592
static int knowledge_monster_validate(const char *item)
Check if a monster knowledge item is still valid.
Definition: knowledge.c:621
static int knowledge_god_validate(const char *item)
Check if a god knowledge item is still valid.
Definition: knowledge.c:718
static void knowledge_message_summary(const char *value, StringBuffer *buf)
Give the title of a message.
Definition: knowledge.c:815
static void knowledge_alchemy_attempt(player *pl, const knowledge_item *item)
Attempt an alchemy recipe through the knowledge system.
Definition: knowledge.c:344
static int knowledge_alchemy_validate(const char *item)
Check if an alchemy recipe is still ok.
Definition: knowledge.c:282
static unsigned knowledge_alchemy_face(sstring code)
Try to get a face for an alchemy recipe.
Definition: knowledge.c:500
static void knowledge_alchemy_detail(const char *value, StringBuffer *buf)
Give the full description of the alchemy recpie.
Definition: knowledge.c:237
static void knowledge_monster_detail(const char *item, StringBuffer *buf)
Describe in detail a monster.
Definition: knowledge.c:606
static int knowledge_message_validate(const char *item)
Check if a message is still valid.
Definition: knowledge.c:846
static void knowledge_god_detail(const char *item, StringBuffer *buf)
Describe in detail a god.
Definition: knowledge.c:689
static StringBuffer * knowledge_alchemy_can_use_item(sstring code, const char *item, StringBuffer *buf, int index)
Check if an item can be used for a recipe, and fill the return buffer if it&#39;s the case...
Definition: knowledge.c:294
static int knowledge_monster_add(struct knowledge_player *current, const char *item, const struct knowledge_type *type, player *pl)
Add monster information to the player&#39;s knowledge, handling the multiple monster case.
Definition: knowledge.c:636
static void knowledge_god_summary(const char *item, StringBuffer *buf)
God information summary.
Definition: knowledge.c:673
static unsigned knowledge_message_face(sstring code)
Get the face for a message.
Definition: knowledge.c:855
static unsigned knowledge_monster_face(sstring code)
Get the face for a monster.
Definition: knowledge.c:658

All handled knowledge items.

Definition at line 866 of file knowledge.c.