Angband
Data Structures | Macros | Typedefs | Functions | Variables
ui-knowledge.c File Reference

Player knowledge functions. More...

#include "angband.h"
#include "cave.h"
#include "cmds.h"
#include "game-input.h"
#include "grafmode.h"
#include "init.h"
#include "mon-lore.h"
#include "mon-util.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-identify.h"
#include "obj-ignore.h"
#include "obj-info.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "object.h"
#include "player-history.h"
#include "store.h"
#include "target.h"
#include "ui-context.h"
#include "ui-history.h"
#include "ui-menu.h"
#include "ui-mon-list.h"
#include "ui-mon-lore.h"
#include "ui-obj.h"
#include "ui-obj-list.h"
#include "ui-options.h"
#include "ui-output.h"
#include "ui-prefs.h"
#include "ui-score.h"
#include "ui-store.h"
#include "ui-target.h"
#include "wizard.h"

Data Structures

struct  group_funcs
 The first part of this file contains the knowledge menus. More...
struct  member_funcs
struct  join
 Helper class for generating joins. More...

Macros

#define swap(a, b)   (swapspace = (void*)(a)), ((a) = (b)), ((b) = swapspace)
#define MISSING   -17
#define GET_ITEM_PARAMS   (USE_EQUIP | USE_INVEN | USE_QUIVER | USE_FLOOR | SHOW_QUIVER | SHOW_EMPTY | IS_HARMLESS)
#define PANEL_SIZE   11
 Number of basic grids per panel, vertically and horizontally.

Typedefs

typedef struct join join_t
 Helper class for generating joins.

Functions

static int default_item_id (int oid)
 

Knowledge menu utilities


static int default_group_id (int oid)
static int feat_order (int feat)
 Return a specific ordering for the features.
static int actual_width (int width)
 Return the actual width of a symbol.
static int actual_height (int height)
 Return the actual height of a symbol.
static int logical_width (int width)
 From an actual width, return the logical width.
static int logical_height (int height)
 From an actual height, return the logical height.
static void display_tiles (int col, int row, int height, int width, byte attr_top, byte char_left)
 Display tiles.
static void place_tile_cursor (int col, int row, byte a, byte c, byte attr_top, byte char_left)
 Place the cursor at the correct position for tile picking.
static void remove_tiles (int col, int row, bool *picker_ptr, int width, int height)
 Remove the tile display and clear the screen.
static bool tile_picker_command (ui_event ke, bool *tile_picker_ptr, int height, int width, byte *attr_top_ptr, byte *char_left_ptr, byte *cur_attr_ptr, byte *cur_char_ptr, int col, int row, int *delay)
 Do tile picker command – Change tiles.
static void display_glyphs (int col, int row, int height, int width, byte a, wchar_t c)
 Display glyph and colours.
static bool glyph_command (ui_event ke, bool *glyph_picker_ptr, int height, int width, byte *cur_attr_ptr, wchar_t *cur_char_ptr, int col, int row)
 Do glyph picker command – Change glyphs.
static void display_group_member (struct menu *menu, int oid, bool cursor, int row, int col, int wid)
static const char * recall_prompt (int oid)
static void display_knowledge (const char *title, int *obj_list, int o_count, group_funcs g_funcs, member_funcs o_funcs, const char *otherfields)
 Interactive group by.
static void display_monster (int col, int row, bool cursor, int oid)
 Display a monster.
static int m_cmp_race (const void *a, const void *b)
static wchar_t * m_xchar (int oid)
static bytem_xattr (int oid)
static const char * race_name (int gid)
static void mon_lore (int oid)
static void mon_summary (int gid, const int *item_list, int n, int top, int row, int col)
static int count_known_monsters (void)
static void do_cmd_knowledge_monsters (const char *name, int row)
 Display known monsters.
static void get_artifact_display_name (char *o_name, size_t namelen, int a_idx)
static void display_artifact (int col, int row, bool cursor, int oid)
 Display an artifact label.
static struct objectfind_artifact (struct artifact *artifact)
 Look for an artifact, either on the ground, in inventory or store.
static void desc_art_fake (int a_idx)
 Show artifact lore.
static int a_cmp_tval (const void *a, const void *b)
static const char * kind_name (int gid)
static int art2gid (int oid)
static bool artifact_is_known (int a_idx)
 Check if the given artifact idx is something we should "Know" about.
static int collect_known_artifacts (int *artifacts, size_t artifacts_len)
 If 'artifacts' is NULL, it counts the number of known artifacts, otherwise it collects the list of known artifacts into 'artifacts' as well.
static void do_cmd_knowledge_artifacts (const char *name, int row)
 Display known artifacts.
static const char * ego_grp_name (int gid)
 

EGO ITEMS


static void display_ego_item (int col, int row, bool cursor, int oid)
static void desc_ego_fake (int oid)
 Describe fake ego item "lore".
static int e_cmp_tval (const void *a, const void *b)
static void do_cmd_knowledge_ego_items (const char *name, int row)
 Display known ego_items.
static int get_artifact_from_kind (object_kind *kind)
 

ORDINARY OBJECTS


static void display_object (int col, int row, bool cursor, int oid)
 Display the objects in a group.
static void desc_obj_fake (int k_idx)
 Describe fake object.
static int o_cmp_tval (const void *a, const void *b)
static int obj2gid (int oid)
static wchar_t * o_xchar (int oid)
static byteo_xattr (int oid)
static const char * o_xtra_prompt (int oid)
 Display special prompt for object inscription.
static void o_xtra_act (struct keypress ch, int oid)
 Special key actions for object inscription.
void textui_browse_object_knowledge (const char *name, int row)
 Display known objects.
static void display_feature (int col, int row, bool cursor, int oid)
 Display the features in a group.
static int f_cmp_fkind (const void *a, const void *b)
static const char * fkind_name (int gid)
static bytef_xattr (int oid)
static wchar_t * f_xchar (int oid)
static void feat_lore (int oid)
static const char * feat_prompt (int oid)
static void f_xtra_act (struct keypress ch, int oid)
 Special key actions for cycling lighting.
static void do_cmd_knowledge_features (const char *name, int row)
 Interact with feature visuals.
static void do_cmd_knowledge_store (const char *name, int row)
 

Main knowledge menus


static void do_cmd_knowledge_scores (const char *name, int row)
static void do_cmd_knowledge_history (const char *name, int row)
static void cleanup_cmds (void)
 Keep macro counts happy.
void textui_knowledge_init (void)
void textui_browse_knowledge (void)
 Display the "player knowledge" menu.
void do_cmd_message_one (void)
 

Other knowledge functions


void do_cmd_messages (void)
 Show previous messages to the user.
void do_cmd_inven (void)
 Display inventory.
void do_cmd_equip (void)
 Display equipment.
void do_cmd_look (void)
 Look command.
void do_cmd_locate (void)
 Allow the player to examine other sectors on the map.
static int cmp_mexp (const void *a, const void *b)
static int cmp_level (const void *a, const void *b)
static int cmp_tkill (const void *a, const void *b)
static int cmp_pkill (const void *a, const void *b)
int cmp_monsters (const void *a, const void *b)
static void lookup_symbol (char sym, char *buf, size_t max)
 Search the monster, item, and feature types to find the meaning for the given symbol.
void do_cmd_query_symbol (void)
 Identify a character, allow recall of monsters.
void do_cmd_center_map (void)
 Centers the map on the player.
void do_cmd_monlist (void)
 Display the main-screen monster list.
void do_cmd_itemlist (void)
 Display the main-screen item list.

Variables

static join_tdefault_join
 A default group-by.
static byte attr_idx = 0
 Clipboard variables for copy & paste in visual mode.
static byte char_idx = 0
struct {
   const wchar_t *   chars
   const char *   name
monster_group []
 

MONSTERS


static const grouper object_text_order []
 

ARTIFACTS


static intobj_group_order = NULL
static const char * feature_group_text []
 

TERRAIN FEATURES


static enum grid_light_level f_uik_lighting = LIGHTING_LIT
 Disgusting hack to allow 4 in 1 editing of terrain visuals.
static menu_action knowledge_actions []
 Definition of the "player knowledge" menu.
static struct menu knowledge_menu

Detailed Description

Player knowledge functions.

Copyright (c) 2000-2007 Eytan Zweig, Andrew Doull, Pete Mack. Copyright (c) 2010 Peter Denison, Chris Carr.

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define GET_ITEM_PARAMS   (USE_EQUIP | USE_INVEN | USE_QUIVER | USE_FLOOR | SHOW_QUIVER | SHOW_EMPTY | IS_HARMLESS)

Referenced by do_cmd_equip(), and do_cmd_inven().

#define MISSING   -17

Referenced by display_knowledge().

#define PANEL_SIZE   11

Number of basic grids per panel, vertically and horizontally.

Referenced by do_cmd_locate().

#define swap (   a,
 
)    (swapspace = (void*)(a)), ((a) = (b)), ((b) = swapspace)

Referenced by display_knowledge().

Typedef Documentation

typedef struct join join_t

Helper class for generating joins.

Function Documentation

static int a_cmp_tval ( const void a,
const void b 
)
static
static int actual_height ( int  height)
static

Return the actual height of a symbol.

References tile_height.

Referenced by display_tiles(), place_tile_cursor(), and tile_picker_command().

static int actual_width ( int  width)
static

Return the actual width of a symbol.

References tile_width.

Referenced by display_tiles(), place_tile_cursor(), and tile_picker_command().

static int art2gid ( int  oid)
static

References a_info, and artifact::tval.

Referenced by do_cmd_knowledge_artifacts().

static bool artifact_is_known ( int  a_idx)
static

Check if the given artifact idx is something we should "Know" about.

References a_info, FALSE, find_artifact(), object_is_known_artifact(), TRUE, and player::wizard.

Referenced by collect_known_artifacts(), desc_obj_fake(), display_object(), and textui_browse_object_knowledge().

static void cleanup_cmds ( void  )
static

Keep macro counts happy.

References mem_free().

Referenced by textui_knowledge_init().

static int cmp_level ( const void a,
const void b 
)
static

References cmp_mexp(), level, and r_info.

Referenced by cmp_monsters(), cmp_tkill(), and do_cmd_query_symbol().

static int cmp_mexp ( const void a,
const void b 
)
static

References r_info.

Referenced by cmp_level().

int cmp_monsters ( const void a,
const void b 
)

References cmp_level().

Referenced by spoil_mon_desc(), and spoil_mon_info().

static int cmp_pkill ( const void a,
const void b 
)
static

References cmp_tkill(), and l_list.

Referenced by do_cmd_query_symbol().

static int cmp_tkill ( const void a,
const void b 
)
static

References cmp_level(), and l_list.

Referenced by cmp_pkill().

static int collect_known_artifacts ( int artifacts,
size_t  artifacts_len 
)
static

If 'artifacts' is NULL, it counts the number of known artifacts, otherwise it collects the list of known artifacts into 'artifacts' as well.

References a_info, angband_constants::a_max, artifact_is_known(), OPT, and z_info.

Referenced by do_cmd_knowledge_artifacts(), and textui_browse_knowledge().

static int count_known_monsters ( void  )
static
static int default_group_id ( int  oid)
static
static int default_item_id ( int  oid)
static


Knowledge menu utilities

References join::oid.

Referenced by desc_ego_fake(), display_ego_item(), display_monster(), e_cmp_tval(), m_cmp_race(), and mon_lore().

static void desc_art_fake ( int  a_idx)
static
static void desc_ego_fake ( int  oid)
static
static void desc_obj_fake ( int  k_idx)
static
static void display_artifact ( int  col,
int  row,
bool  cursor,
int  oid 
)
static

Display an artifact label.

References c_prt(), curs_attrs, CURS_KNOWN, get_artifact_display_name(), and int.

Referenced by do_cmd_knowledge_artifacts().

static void display_ego_item ( int  col,
int  row,
bool  cursor,
int  oid 
)
static
static void display_feature ( int  col,
int  row,
bool  cursor,
int  oid 
)
static
static void display_glyphs ( int  col,
int  row,
int  height,
int  width,
byte  a,
wchar_t  c 
)
static

Display glyph and colours.

References big_pad(), height, i, MAX_COLORS, prt(), Term_erase(), Term_gotoxy(), and Term_locate().

Referenced by display_knowledge().

static void display_group_member ( struct menu menu,
int  oid,
bool  cursor,
int  row,
int  col,
int  wid 
)
static
static void display_knowledge ( const char *  title,
int obj_list,
int  o_count,
group_funcs  g_funcs,
member_funcs  o_funcs,
const char *  otherfields 
)
static
static void display_monster ( int  col,
int  row,
bool  cursor,
int  oid 
)
static
static void display_object ( int  col,
int  row,
bool  cursor,
int  oid 
)
static
static void display_tiles ( int  col,
int  row,
int  height,
int  width,
byte  attr_top,
byte  char_left 
)
static
void do_cmd_center_map ( void  )

Centers the map on the player.

References center_panel().

Referenced by context_menu_player().

void do_cmd_equip ( void  )
void do_cmd_inven ( void  )
void do_cmd_itemlist ( void  )

Display the main-screen item list.

References term::hgt, object_list_show_interactive(), screen_load(), screen_save(), Term, and term::wid.

static void do_cmd_knowledge_artifacts ( const char *  name,
int  row 
)
static
static void do_cmd_knowledge_ego_items ( const char *  name,
int  row 
)
static
static void do_cmd_knowledge_features ( const char *  name,
int  row 
)
static
static void do_cmd_knowledge_history ( const char *  name,
int  row 
)
static

References history_display().

static void do_cmd_knowledge_monsters ( const char *  name,
int  row 
)
static
static void do_cmd_knowledge_scores ( const char *  name,
int  row 
)
static

References show_scores().

static void do_cmd_knowledge_store ( const char *  name,
int  row 
)
static


Main knowledge menus

References textui_store_knowledge().

void do_cmd_locate ( void  )
void do_cmd_look ( void  )

Look command.

References msg, TARGET_LOOK, and target_set_interactive().

void do_cmd_message_one ( void  )


Other knowledge functions

Recall the most recent message

References c_prt(), format(), message_color(), and message_str().

void do_cmd_messages ( void  )

Show previous messages to the user.

The screen format uses line 0 and 23 for headers and prompts, skips line 1 and 22, and uses line 2 thru 21 for old messages.

This command shows you which commands you are viewing, and allows you to "search" for strings in the recall.

Note that messages may be longer than 80 characters, but they are displayed using "infinite" length, with a special sub-command to "slide" the virtual display to the left or right.

Attempt to only highlight the matching portions of the string.

References ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT, ARROW_UP, askfor_aux(), mouseclick::button, keypress::code, COLOUR_YELLOW, menu::count, ESCAPE, EVT_KBRD, EVT_MOUSE, FALSE, format(), i, inkey_ex(), int, KC_ENTER, KC_PGDOWN, KC_PGUP, ui_event::key, message_color(), message_count(), message_str(), messages_num(), ui_event::mouse, msg, my_stristr(), prt(), screen_load(), screen_save(), Term_clear(), Term_get_size(), Term_putstr(), TRUE, ui_event::type, and mouseclick::y.

Referenced by death_messages(), and store_process_command_key().

void do_cmd_monlist ( void  )

Display the main-screen monster list.

References term::hgt, monster_list_show_interactive(), screen_load(), screen_save(), Term, and term::wid.

void do_cmd_query_symbol ( void  )

Identify a character, allow recall of monsters.

Several "special" responses recall "multiple" monsters: ^A (all monsters) ^U (all unique monsters) ^N (all non-unique monsters)

The responses may be sorted in several ways, see below.

Note that the player ghosts are ignored, since they do not exist.

References buf, char_matches_key(), cmp_level(), cmp_pkill(), keypress::code, monster_race::d_char, ESCAPE, FALSE, monster_race::flags, get_com(), handle_stuff(), i, inkey(), KTRL, l_list, lookup_symbol(), lore_show_interactive(), lore_title(), mem_free(), mem_zalloc(), monster_race_track(), my_strcpy(), OPT, prt(), put_str(), r_info, angband_constants::r_max, rf_has, SCREEN_REGION, monster_lore::sights, sort(), textblock_append(), textblock_free(), textblock_new(), textui_textblock_place(), TRUE, player::upkeep, and z_info.

static int e_cmp_tval ( const void a,
const void b 
)
static
static const char* ego_grp_name ( int  gid)
static


EGO ITEMS

References grouper::name.

Referenced by desc_ego_fake(), and do_cmd_knowledge_ego_items().

static int f_cmp_fkind ( const void a,
const void b 
)
static
static byte* f_xattr ( int  oid)
static

References f_uik_lighting, and feat_x_attr.

Referenced by do_cmd_knowledge_features().

static wchar_t* f_xchar ( int  oid)
static

References f_uik_lighting, and feat_x_char.

Referenced by do_cmd_knowledge_features().

static void f_xtra_act ( struct keypress  ch,
int  oid 
)
static

Special key actions for cycling lighting.

References keypress::code, LIGHTING_DARK, LIGHTING_LIT, LIGHTING_LOS, and LIGHTING_TORCH.

Referenced by do_cmd_knowledge_features().

static void feat_lore ( int  oid)
static

References void().

Referenced by do_cmd_knowledge_features().

static int feat_order ( int  feat)
static

Return a specific ordering for the features.

References feature::d_char, and f_info.

Referenced by do_cmd_knowledge_features(), and f_cmp_fkind().

static const char* feat_prompt ( int  oid)
static

References void().

Referenced by do_cmd_knowledge_features().

static struct object* find_artifact ( struct artifact artifact)
staticread

Look for an artifact, either on the ground, in inventory or store.

References object::artifact, cave, player::gear, chunk::height, store::next, object::next, square_object(), store::stock, stores, and chunk::width.

Referenced by artifact_is_known(), and desc_art_fake().

static const char* fkind_name ( int  gid)
static
static void get_artifact_display_name ( char *  o_name,
size_t  namelen,
int  a_idx 
)
static
static int get_artifact_from_kind ( object_kind kind)
static


ORDINARY OBJECTS

Looks up an artifact idx given an object_kind that's already known to be an artifact. Behaviour is distinctly unfriendly if passed flavours which don't correspond to an artifact.

References a_info, angband_constants::a_max, i, kf_has, object_kind::kind_flags, object_kind::sval, artifact::sval, object_kind::tval, artifact::tval, and z_info.

Referenced by desc_obj_fake(), display_object(), and textui_browse_object_knowledge().

static bool glyph_command ( ui_event  ke,
bool glyph_picker_ptr,
int  height,
int  width,
byte cur_attr_ptr,
wchar_t *  cur_char_ptr,
int  col,
int  row 
)
static
static const char* kind_name ( int  gid)
static
static int logical_height ( int  height)
static

From an actual height, return the logical height.

References tile_height.

Referenced by display_tiles(), and tile_picker_command().

static int logical_width ( int  width)
static

From an actual width, return the logical width.

References tile_width.

Referenced by display_tiles(), glyph_command(), and tile_picker_command().

static void lookup_symbol ( char  sym,
char *  buf,
size_t  max 
)
static

Search the monster, item, and feature types to find the meaning for the given symbol.

Note: We currently search items first, then features, then monsters, and we return the first hit for a symbol. This is to prevent mimics and lurkers from matching a symbol instead of the item or feature it is mimicking.

Todo: concatenate all matches into buf. This will be much easier once we can loop through item tvals instead of items (see note below.)

Todo: Should this take the user's pref files into account?

References char_matches_key(), monster_base::d_char, f_info, angband_constants::f_max, i, k_info, angband_constants::k_max, monster_base::next, rb_info, strnfmt(), monster_base::text, tval_find_name(), and z_info.

Referenced by do_cmd_query_symbol().

static int m_cmp_race ( const void a,
const void b 
)
static
static byte* m_xattr ( int  oid)
static

References monster_x_attr, and join::oid.

Referenced by do_cmd_knowledge_monsters().

static wchar_t* m_xchar ( int  oid)
static

References monster_x_char, and join::oid.

Referenced by do_cmd_knowledge_monsters().

static void mon_lore ( int  oid)
static
static void mon_summary ( int  gid,
const int item_list,
int  n,
int  top,
int  row,
int  col 
)
static
static int o_cmp_tval ( const void a,
const void b 
)
static
static byte* o_xattr ( int  oid)
static
static wchar_t* o_xchar ( int  oid)
static
static void o_xtra_act ( struct keypress  ch,
int  oid 
)
static
static const char* o_xtra_prompt ( int  oid)
static

Display special prompt for object inscription.

References object_kind::aware, object_kind::flavor, object_kind::note, and objkind_byid().

Referenced by textui_browse_object_knowledge().

static int obj2gid ( int  oid)
static
static void place_tile_cursor ( int  col,
int  row,
byte  a,
byte  c,
byte  attr_top,
byte  char_left 
)
static

Place the cursor at the correct position for tile picking.

References actual_height(), actual_width(), i, and Term_gotoxy().

Referenced by display_knowledge().

static const char* race_name ( int  gid)
static
static const char* recall_prompt ( int  oid)
static
static void remove_tiles ( int  col,
int  row,
bool picker_ptr,
int  width,
int  height 
)
static

Remove the tile display and clear the screen.

References bigcurs, FALSE, height, i, and Term_erase().

Referenced by glyph_command(), and tile_picker_command().

void textui_browse_knowledge ( void  )
void textui_browse_object_knowledge ( const char *  name,
int  row 
)
void textui_knowledge_init ( void  )
static bool tile_picker_command ( ui_event  ke,
bool tile_picker_ptr,
int  height,
int  width,
byte attr_top_ptr,
byte char_left_ptr,
byte cur_attr_ptr,
byte cur_char_ptr,
int  col,
int  row,
int delay 
)
static

Variable Documentation

byte attr_idx = 0
static

Clipboard variables for copy & paste in visual mode.

Referenced by display_knowledge(), and tile_picker_command().

byte char_idx = 0
static
const wchar_t* chars

Referenced by bolt_pict(), gf_display(), and m_cmp_race().

join_t* default_join
static

A default group-by.

enum grid_light_level f_uik_lighting = LIGHTING_LIT
static

Disgusting hack to allow 4 in 1 editing of terrain visuals.

Referenced by f_xattr(), and f_xchar().

const char* feature_group_text[]
static
Initial value:
{
"Floors",
"Traps",
"Doors",
"Stairs",
"Walls",
"Streamers",
"Obstructions",
"Stores",
"Other",
NULL
}


TERRAIN FEATURES

Description of each feature group.

menu_action knowledge_actions[]
static
Initial value:
{
{ 0, 0, "Display object knowledge", textui_browse_object_knowledge },
{ 0, 0, "Display artifact knowledge", do_cmd_knowledge_artifacts },
{ 0, 0, "Display ego item knowledge", do_cmd_knowledge_ego_items },
{ 0, 0, "Display monster knowledge", do_cmd_knowledge_monsters },
{ 0, 0, "Display feature knowledge", do_cmd_knowledge_features },
{ 0, 0, "Display contents of general store", do_cmd_knowledge_store },
{ 0, 0, "Display contents of armourer", do_cmd_knowledge_store },
{ 0, 0, "Display contents of weaponsmith", do_cmd_knowledge_store },
{ 0, 0, "Display contents of temple", do_cmd_knowledge_store },
{ 0, 0, "Display contents of alchemist", do_cmd_knowledge_store },
{ 0, 0, "Display contents of magic shop", do_cmd_knowledge_store },
{ 0, 0, "Display contents of black market", do_cmd_knowledge_store },
{ 0, 0, "Display contents of home", do_cmd_knowledge_store },
{ 0, 0, "Display hall of fame", do_cmd_knowledge_scores },
{ 0, 0, "Display character history", do_cmd_knowledge_history },
}

Definition of the "player knowledge" menu.

struct menu knowledge_menu
static
struct { ... } monster_group[]


MONSTERS

Description of each monster group.

Referenced by count_known_monsters(), do_cmd_knowledge_monsters(), m_cmp_race(), and race_name().

const char* name
int* obj_group_order = NULL
static
const grouper object_text_order[]
static


ARTIFACTS

These are used for all the object sections