Angband
Functions | Variables
obj-knowledge.c File Reference

Object knowledge. More...

#include "angband.h"
#include "cave.h"
#include "init.h"
#include "obj-curse.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-pile.h"
#include "obj-properties.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player.h"
#include "player-calcs.h"
#include "player-history.h"
#include "project.h"
#include "store.h"

Functions

static void init_rune (void)
 Initialise the rune module. More...
 
static int rune_index (size_t variety, int index)
 Get a rune by variety and index. More...
 
static void cleanup_rune (void)
 Cleanup the rune module. More...
 
int max_runes (void)
 

Rune knowledge functions These functions provide details about the rune list for use in

player knowledge screens

More...
 
enum rune_variety rune_variety (size_t i)
 The variety of a rune. More...
 
bool player_knows_rune (struct player *p, size_t i)
 Reports if the player knows a given rune. More...
 
char * rune_name (size_t i)
 The name of a rune. More...
 
char * rune_desc (size_t i)
 The description of a rune. More...
 
quark_t rune_note (size_t i)
 The autoinscription index (if any) of a rune. More...
 
void rune_set_note (size_t i, const char *inscription)
 Set an autoinscription on a rune. More...
 
bool player_knows_brand (struct player *p, int i)
 

Object knowledge predicates

These functions tell how much the player knows about an object

More...
 
bool player_knows_slay (struct player *p, int i)
 Check if a slay is known to the player. More...
 
bool player_knows_curse (struct player *p, int index)
 Check if a curse is known to the player. More...
 
bool player_knows_ego (struct player *p, struct ego_item *ego)
 Check if an ego item type is known to the player. More...
 
bool object_effect_is_known (const struct object *obj)
 Checks whether the player is aware of the object's effect when used. More...
 
bool object_is_known_artifact (const struct object *obj)
 Checks whether the object is known to be an artifact. More...
 
bool object_is_in_store (const struct object *obj)
 Checks whether the object is in a store. More...
 
bool object_has_standard_to_h (const struct object *obj)
 Checks whether the object has the usual to-hit value. More...
 
bool object_has_rune (const struct object *obj, int rune_no)
 Check if an object has a rune. More...
 
bool object_runes_known (const struct object *obj)
 Check if all the runes on an object are known to the player. More...
 
bool object_fully_known (const struct object *obj)
 Check if an object is fully known to the player. More...
 
bool object_flag_is_known (const struct object *obj, int flag)
 Checks whether the player knows whether an object has a given flag. More...
 
bool object_element_is_known (const struct object *obj, int element)
 Checks whether the player knows the given element properties of an object. More...
 
void object_set_base_known (struct object *obj)
 

Object knowledge propagators

These functions transfer player knowledge to objects

More...
 
void object_sense (struct player *p, struct object *obj)
 Gain knowledge based on sensing an object on the floor. More...
 
void object_see (struct player *p, struct object *obj)
 Gain knowledge based on seeing an object on the floor. More...
 
void object_touch (struct player *p, struct object *obj)
 Gain knowledge based on being an the same square as an object. More...
 
void player_know_object (struct player *p, struct object *obj)
 Transfer player object knowledge to an object. More...
 
void update_player_object_knowledge (struct player *p)
 Propagate player knowledge of objects to all objects. More...
 
static void player_learn_rune (struct player *p, size_t i, bool message)
 

Object knowledge learners

These functions are for increasing player knowledge of object properties

More...
 
void player_learn_flag (struct player *p, int flag)
 Learn a flag. More...
 
void player_learn_curse (struct player *p, struct curse *curse)
 Learn a curse. More...
 
void player_learn_everything (struct player *p)
 Learn absolutely everything. More...
 
void mod_message (struct object *obj, int mod)
 

Functions for learning from the behaviour of indvidual objects

More...
 
void object_curses_find_to_a (struct player *p, struct object *obj)
 
void object_curses_find_to_h (struct player *p, struct object *obj)
 
void object_curses_find_to_d (struct player *p, struct object *obj)
 
bool object_curses_find_flags (struct player *p, struct object *obj, bitflag *test_flags)
 
void object_curses_find_modifiers (struct player *p, struct object *obj)
 
bool object_curses_find_element (struct player *p, struct object *obj, int elem)
 
int object_find_unknown_rune (struct player *p, struct object *obj)
 Get a random unknown rune from an object. More...
 
void object_learn_unknown_rune (struct player *p, struct object *obj)
 Learn a random unknown rune from an object. More...
 
void object_learn_on_wield (struct player *p, struct object *obj)
 Learn object properties that become obvious on wielding or wearing. More...
 
void object_learn_on_use (struct player *p, struct object *obj)
 Learn object properties that become obvious on use, mark it as aware and reward the player with some experience. More...
 
void object_learn_slay (struct player *p, struct object *obj, int index)
 Notice any slays on a particular object which affect a particular monster. More...
 
void object_learn_brand (struct player *p, struct object *obj, int index)
 Notice any brands on a particular object which affect a particular monster. More...
 
void missile_learn_on_ranged_attack (struct player *p, struct object *obj)
 Learn attack bonus on making a ranged attack. More...
 
void equip_learn_on_defend (struct player *p)
 

Functions for learning about equipment properties These functions are for gaining object knowledge from the behaviour of

the player's equipment

More...
 
void equip_learn_on_ranged_attack (struct player *p)
 Learn to-hit bonus on making a ranged attack. More...
 
void equip_learn_on_melee_attack (struct player *p)
 Learn things which happen on making a melee attack. More...
 
void equip_learn_flag (struct player *p, int flag)
 Learn a given object flag on wielded items. More...
 
void equip_learn_element (struct player *p, int element)
 Learn the elemental resistance properties on wielded items. More...
 
void equip_learn_after_time (struct player *p)
 Learn things that would be noticed in time. More...
 
bool easy_know (const struct object *obj)
 

Object kind functions

These deal with knowledge of an object's kind

More...
 
bool object_flavor_is_aware (const struct object *obj)
 Checks whether the player is aware of the object's flavour. More...
 
bool object_flavor_was_tried (const struct object *obj)
 Checks whether the player has tried to use other objects of the same kind. More...
 
void object_flavor_aware (struct object *obj)
 Mark an object's flavour as as one the player is aware of. More...
 
void object_flavor_tried (struct object *obj)
 Mark an object's flavour as tried. More...
 

Variables

static size_t rune_max
 

Overview

This file deals with the new "rune-based ID" system. More...
 
static struct runerune_list
 
static char * c_rune []
 
struct init_module rune_module
 

Detailed Description

Object knowledge.

Copyright (c) 2016 Nick McConnell

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.

Function Documentation

static void cleanup_rune ( void  )
static

Cleanup the rune module.

References mem_free().

bool easy_know ( const struct object obj)


Object kind functions

These deal with knowledge of an object's kind

Checks whether an object counts as "known" due to EASY_KNOW status

Parameters
objis the object

References object_kind::aware, kf_has, object::kind, and object_kind::kind_flags.

Referenced by object_flags_known().

void equip_learn_after_time ( struct player p)
void equip_learn_element ( struct player p,
int  element 
)
void equip_learn_flag ( struct player p,
int  flag 
)
void equip_learn_on_defend ( struct player p)


Functions for learning about equipment properties These functions are for gaining object knowledge from the behaviour of

the player's equipment

Learn things which happen on defending.

Parameters
pis the player

References player::body, COMBAT_RUNE_TO_A, player_body::count, i, index, object::known, player::obj_k, object_curses_find_to_a(), player_learn_rune(), rune_index(), RUNE_VAR_COMBAT, slot_object(), and object::to_a.

Referenced by check_hit().

void equip_learn_on_melee_attack ( struct player p)
void equip_learn_on_ranged_attack ( struct player p)

Learn to-hit bonus on making a ranged attack.

Does not apply to weapon or bow

Parameters
pis the player

References player::body, COMBAT_RUNE_TO_H, player_body::count, i, index, object::known, player::obj_k, object_curses_find_to_h(), object_has_standard_to_h(), player_learn_rune(), rune_index(), RUNE_VAR_COMBAT, slot_by_name(), slot_object(), and object::to_h.

Referenced by ranged_helper().

static void init_rune ( void  )
static
int max_runes ( void  )


Rune knowledge functions These functions provide details about the rune list for use in

player knowledge screens

The number of runes

References rune_max.

Referenced by do_cmd_knowledge_runes(), runes_autoinscribe(), textui_browse_knowledge(), and wr_ignore().

void missile_learn_on_ranged_attack ( struct player p,
struct object obj 
)

Learn attack bonus on making a ranged attack.

Can be applied to the missile or the missile launcher

Parameters
pis the player
objis the missile or launcher

References COMBAT_RUNE_TO_D, COMBAT_RUNE_TO_H, index, object::known, player::obj_k, object_curses_find_to_d(), object_curses_find_to_h(), object_has_standard_to_h(), player_learn_rune(), rune_index(), RUNE_VAR_COMBAT, object::to_d, and object::to_h.

Referenced by make_ranged_shot(), and ranged_helper().

void mod_message ( struct object obj,
int  mod 
)


Functions for learning from the behaviour of indvidual objects

Print a message when an object modifier is identified by use.

Parameters
objis the object
modis the modifier being noticed

References object::modifiers, and msg.

Referenced by object_curses_find_modifiers(), and object_learn_on_wield().

bool object_curses_find_element ( struct player p,
struct object obj,
int  elem 
)
bool object_curses_find_flags ( struct player p,
struct object obj,
bitflag test_flags 
)
void object_curses_find_modifiers ( struct player p,
struct object obj 
)
void object_curses_find_to_a ( struct player p,
struct object obj 
)
void object_curses_find_to_d ( struct player p,
struct object obj 
)
void object_curses_find_to_h ( struct player p,
struct object obj 
)
bool object_effect_is_known ( const struct object obj)

Checks whether the player is aware of the object's effect when used.

Parameters
objis the object

References object::effect, and object::known.

Referenced by obj_known_effect(), object_fully_known(), and show_obj().

bool object_element_is_known ( const struct object obj,
int  element 
)

Checks whether the player knows the given element properties of an object.

Parameters
objis the object
elementis the element

References object::el_info, ELEM_MAX, object::known, player::obj_k, object_fully_known(), and element_info::res_level.

Referenced by display_resistance_panel().

int object_find_unknown_rune ( struct player p,
struct object obj 
)

Get a random unknown rune from an object.

Parameters
pis the player
objis the object
Returns
the index into the rune list, or -1 for no unknown runes

References i, mem_free(), mem_zalloc(), num, object_has_rune(), object_runes_known(), player_knows_rune(), randint0, and rune_max.

Referenced by object_learn_unknown_rune().

bool object_flag_is_known ( const struct object obj,
int  flag 
)

Checks whether the player knows whether an object has a given flag.

Parameters
objis the object
flagis the flag

References object::flags, object::known, player::obj_k, object_fully_known(), and of_has.

Referenced by display_player_sust_info(), display_resistance_panel(), and store_will_buy().

void object_flavor_aware ( struct object obj)
bool object_flavor_is_aware ( const struct object obj)
void object_flavor_tried ( struct object obj)

Mark an object's flavour as tried.

Parameters
objis the object whose flavour should be marked

References object::kind, and object_kind::tried.

Referenced by object_learn_on_wield(), and use_aux().

bool object_flavor_was_tried ( const struct object obj)

Checks whether the player has tried to use other objects of the same kind.

Parameters
objis the object

References object::kind, and object_kind::tried.

Referenced by obj_desc_inscrip().

bool object_fully_known ( const struct object obj)
bool object_has_rune ( const struct object obj,
int  rune_no 
)
bool object_has_standard_to_h ( const struct object obj)
bool object_is_in_store ( const struct object obj)

Checks whether the object is in a store.

Parameters
objis the object

References i, MAX_STORES, object::next, store::stock, and stores.

Referenced by obj_known_effect().

bool object_is_known_artifact ( const struct object obj)

Checks whether the object is known to be an artifact.

Parameters
objis the object

References object::artifact, and object::known.

Referenced by artifact_is_known(), compare_items(), obj_desc_get_basename(), obj_desc_name(), obj_desc_name_prefix(), and object_list_format_name().

void object_learn_brand ( struct player p,
struct object obj,
int  index 
)

Notice any brands on a particular object which affect a particular monster.

Parameters
objis the object on which we are noticing brands
monthe monster we are trying to brand

References angband_constants::brand_max, brand_max, brands, i, player_knows_brand(), player_learn_rune(), rune_index(), RUNE_VAR_BRAND, streq, update_player_object_knowledge(), and z_info.

Referenced by improve_attack_modifier().

void object_learn_on_use ( struct player p,
struct object obj 
)

Learn object properties that become obvious on use, mark it as aware and reward the player with some experience.

Parameters
pis the player
objis the used object

References object::effect, object::kind, object::known, player::lev, object_kind::level, player_upkeep::notice, object_flavor_aware(), player_exp_gain(), PN_IGNORE, and player::upkeep.

Referenced by use_aux().

void object_learn_on_wield ( struct player p,
struct object obj 
)
void object_learn_slay ( struct player p,
struct object obj,
int  index 
)

Notice any slays on a particular object which affect a particular monster.

Parameters
objis the object on which we are noticing slays
monthe monster we are trying to slay

References i, player_knows_slay(), player_learn_rune(), rune_index(), RUNE_VAR_SLAY, same_monsters_slain(), angband_constants::slay_max, slay_max, update_player_object_knowledge(), and z_info.

Referenced by improve_attack_modifier().

void object_learn_unknown_rune ( struct player p,
struct object obj 
)

Learn a random unknown rune from an object.

Parameters
pis the player
objis the object

References i, object_find_unknown_rune(), and player_learn_rune().

Referenced by do_cmd_buy(), and effect_handler_IDENTIFY().

bool object_runes_known ( const struct object obj)
void object_see ( struct player p,
struct object obj 
)
void object_sense ( struct player p,
struct object obj 
)
void object_set_base_known ( struct object obj)
void object_touch ( struct player p,
struct object obj 
)

Gain knowledge based on being an the same square as an object.

References object::artifact, history_find_artifact(), object::known, object::notice, OBJ_NOTICE_ASSESSED, and player_know_object().

Referenced by square_know_pile().

void player_know_object ( struct player p,
struct object obj 
)
bool player_knows_brand ( struct player p,
int  i 
)


Object knowledge predicates

These functions tell how much the player knows about an object

Check if a brand is known to the player

Parameters
pis the player
bis the brand

References object::brands, i, and player::obj_k.

Referenced by improve_attack_modifier(), object_learn_brand(), player_know_object(), player_knows_ego(), and player_learn_rune().

bool player_knows_curse ( struct player p,
int  index 
)

Check if a curse is known to the player.

Parameters
pis the player
cis the curse

References object::curses, index, player::obj_k, and curse_data::power.

Referenced by do_curse_effect(), player_knows_ego(), and player_learn_rune().

bool player_knows_ego ( struct player p,
struct ego_item ego 
)
bool player_knows_rune ( struct player p,
size_t  i 
)
bool player_knows_slay ( struct player p,
int  i 
)

Check if a slay is known to the player.

Parameters
pis the player
sis the slay

References i, player::obj_k, and object::slays.

Referenced by improve_attack_modifier(), object_learn_slay(), player_know_object(), player_knows_ego(), and player_learn_rune().

void player_learn_curse ( struct player p,
struct curse curse 
)
void player_learn_everything ( struct player p)

Learn absolutely everything.

Parameters
pis the player

References i, player_learn_rune(), and rune_max.

Referenced by death_knowledge(), and do_cmd_accept_character().

void player_learn_flag ( struct player p,
int  flag 
)
static void player_learn_rune ( struct player p,
size_t  i,
bool  message 
)
static
char* rune_desc ( size_t  i)
static int rune_index ( size_t  variety,
int  index 
)
static
char* rune_name ( size_t  i)
quark_t rune_note ( size_t  i)

The autoinscription index (if any) of a rune.

References i, and rune::note.

Referenced by display_rune(), rune_add_autoinscription(), rune_xtra_act(), rune_xtra_prompt(), and wr_ignore().

void rune_set_note ( size_t  i,
const char *  inscription 
)

Set an autoinscription on a rune.

References i, rune::note, and quark_add().

Referenced by rd_ignore(), and rune_xtra_act().

enum rune_variety rune_variety ( size_t  i)

The variety of a rune.

References i, and rune::variety.

void update_player_object_knowledge ( struct player p)

Variable Documentation

char* c_rune[]
static
Initial value:
= {
"enchantment to armor",
"enchantment to hit",
"enchantment to damage"
}

Referenced by init_rune().

struct rune* rune_list
static
size_t rune_max
static

Overview

This file deals with the new "rune-based ID" system.

This system operates as follows:

  • struct player has an object struct attached to it (obj_k) which contains the player's knowledge of object properties (runes)
  • whenever the player learns a rune,
    • if it's an object flag, that flag is set in obj_k
    • if it's an integer value, that value in obj_k is set to 1
    • if it's element info, the res_level value is set to 1
    • if it's a brand, a brand is added to obj_k with the relevant element
    • if it's a slay, a slay is added to obj_k with the right race flag or name
  • every object has a known version which is filled in with details as the player learns them
  • whenever the player learns a rune, that knowledge is applied to the known version of every object that the player has picked up or walked over

    or seen in a shop

Object knowledge data

This section covers initialisation, access and cleanup of rune data

Referenced by do_cmd_knowledge_runes(), init_rune(), max_runes(), object_find_unknown_rune(), player_learn_everything(), rune_index(), runes_autoinscribe(), and textui_browse_knowledge().

struct init_module rune_module
Initial value:
= {
.name = "rune",
.init = init_rune,
.cleanup = cleanup_rune
}
static void init_rune(void)
Initialise the rune module.
Definition: obj-knowledge.c:74
static void cleanup_rune(void)
Cleanup the rune module.
Definition: obj-knowledge.c:205