Angband
Data Structures | Macros | Functions | Variables
obj-info.c File Reference

Object description code. More...

#include "angband.h"
#include "cmds.h"
#include "effects.h"
#include "game-world.h"
#include "init.h"
#include "monster.h"
#include "obj-gear.h"
#include "obj-identify.h"
#include "obj-info.h"
#include "obj-make.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-attack.h"
#include "project.h"
#include "z-textblock.h"
#include "list-elements.h"
#include "list-stats.h"
#include "list-object-modifiers.h"
#include "list-origins.h"

Data Structures

struct  flag_type
 Describes a flag-name pair. More...
struct  blow_info
 Describes the number of blows possible for given stat bonuses. More...
struct  origin_type

Macros

#define OBJ_KNOWN_PRESENT   -1
#define ELEM(a, b, c, d, e, f, g, col)   { ELEM_##a, b },
#define STAT(a, b, c, d, e, f, g, h)   { OBJ_MOD_##a, h },
#define OBJ_MOD(a, b, c, d)   { OBJ_MOD_##a, d },
#define STAT(a, b, c, d, e, f, g, h)   { OF_##c, h },
#define ORIGIN(a, b, c)   { ORIGIN_##a, b, c },

Functions

static void info_out_list (textblock *tb, const char *list[], size_t count)
 Given an array of strings, as so: { "intelligence", "fish", "lens", "prime", "number" },.
static size_t flag_info_collect (const flag_type list[], size_t max, const bitflag flags[OF_SIZE], const char *recepticle[])
 Fills recepticle with all the flags in flags that are in the given list.
static size_t element_info_collect (const bool list[], const char *recepticle[])
 Fills recepticle with all the elements that correspond to the given list.
static bool describe_curses (textblock *tb, const object_type *o_ptr, const bitflag flags[OF_SIZE])
 Describe an item's curses.
static bool describe_stats (textblock *tb, const object_type *o_ptr, oinfo_detail_t mode)
 Describe stat modifications.
static bool describe_elements (textblock *tb, const struct element_info el_info[])
 Describe immunities, resistances and vulnerabilities granted by an object.
static bool describe_protects (textblock *tb, const bitflag flags[OF_SIZE])
 Describe protections granted by an object.
static bool describe_ignores (textblock *tb, const struct element_info el_info[])
 Describe elements an object ignores.
static bool describe_hates (textblock *tb, const struct element_info el_info[])
 Describe elements that damage or destroy an object.
static bool describe_sustains (textblock *tb, const bitflag flags[OF_SIZE])
 Describe stat sustains.
static bool describe_misc_magic (textblock *tb, const bitflag flags[OF_SIZE])
 Describe miscellaneous powers.
static bool describe_slays (textblock *tb, const struct object *o_ptr)
 Describe slays and brands on weapons.
static bool describe_brands (textblock *tb, const struct object *o_ptr)
 Describe slays and brands on weapons.
static void calculate_melee_crits (player_state *state, int weight, int plus, int *mult, int *add, int *div)
 Account for criticals in the calculation of melee prowess.
static void calculate_missile_crits (player_state *state, int weight, int plus, int *mult, int *add, int *div)
 Missile crits follow the same approach as melee crits.
static void get_known_flags (const object_type *o_ptr, const oinfo_detail_t mode, bitflag flags[OF_SIZE])
 Get the object flags the player should know about for the given object/ viewing mode combination.
static void get_known_elements (const object_type *o_ptr, const oinfo_detail_t mode, struct element_info el_info[])
 Get the object element info the player should know about for the given object/viewing mode combination.
static int obj_known_blows (const object_type *obj, int max_num, struct blow_info possible_blows[])
 Gets information about the number of blows possible for the player with the given object.
static bool describe_blows (textblock *tb, const object_type *o_ptr)
 Describe blows.
static int obj_known_damage (const object_type *obj, int *normal_damage, struct brand **brand_list, int **brand_damage, struct slay **slay_list, int **slay_damage, bool *nonweap_slay)
 Gets information about the average damage/turn that can be inflicted if the player wields the given weapon.
static bool describe_damage (textblock *tb, const object_type *o_ptr)
 Describe damage.
static void obj_known_misc_combat (const struct object *obj, bool *thrown_effect, int *range, bool *impactful, int *break_chance, bool *too_heavy)
 Gets miscellaneous combat information about the given object.
static bool describe_combat (textblock *tb, const object_type *o_ptr)
 Describe combat advantages.
static bool obj_known_digging (struct object *obj, int deciturns[])
 Returns information about objects that can be used for digging.
static bool describe_digger (textblock *tb, const object_type *o_ptr)
 Describe objects that can be used for digging.
static int obj_known_food (const object_type *o_ptr)
 Gives the known nutritional value of the given object.
static bool describe_food (textblock *tb, const object_type *o_ptr, bool subjective)
 Describes a food item.
static bool obj_known_light (const object_type *o_ptr, oinfo_detail_t mode, int *rad, bool *uses_fuel, int *refuel_turns)
 Gives the known light-sourcey characteristics of the given object.
static bool describe_light (textblock *tb, const object_type *o_ptr, oinfo_detail_t mode)
 Describe things that look like lights.
static bool obj_known_effect (const object_type *o_ptr, int *effect, bool *aimed, int *min_recharge, int *max_recharge, int *failure_chance)
 Gives the known effects of using the given item.
static bool describe_effect (textblock *tb, const object_type *o_ptr, bool only_artifacts, bool subjective)
 Describe an object's effect, if any.
static bool describe_origin (textblock *tb, const object_type *o_ptr, bool terse)
 Describe an item's origin.
static void describe_flavor_text (textblock *tb, const object_type *o_ptr, bool ego)
 Print an item's flavour text.
static bool describe_ego (textblock *tb, const struct ego_item *ego)
 Describe random properties that an ego item may have.
static textblockobject_info_out (const object_type *o_ptr, int mode)
 Output object information.
textblockobject_info (const object_type *o_ptr, oinfo_detail_t mode)
 Provide information on an item, including how it would affect the current player's state.
textblockobject_info_ego (struct ego_item *ego)
 Provide information on an ego-item type.
void object_info_chardump (ang_file *f, const object_type *o_ptr, int indent, int wrap)
 Provide information on an item suitable for writing to the character dump.
void object_info_spoil (ang_file *f, const object_type *o_ptr, int wrap)
 Provide spoiler information on an item.

Variables

static const flag_type elements []
static const flag_type mod_flags []
static const flag_type protect_flags []
static const flag_type sustain_flags []
static const flag_type misc_flags []
static struct origin_type origins []

Detailed Description

Object description code.

Copyright (c) 2010 Andi Sidwell Copyright (c) 2004 Robert Ruehlmann

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 ELEM (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  col 
)    { ELEM_##a, b },
#define OBJ_KNOWN_PRESENT   -1
#define OBJ_MOD (   a,
  b,
  c,
 
)    { OBJ_MOD_##a, d },
#define ORIGIN (   a,
  b,
 
)    { ORIGIN_##a, b, c },
#define STAT (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h 
)    { OBJ_MOD_##a, h },
#define STAT (   a,
  b,
  c,
  d,
  e,
  f,
  g,
  h 
)    { OF_##c, h },

Function Documentation

static void calculate_melee_crits ( player_state state,
int  weight,
int  plus,
int mult,
int add,
int div 
)
static

Account for criticals in the calculation of melee prowess.

Note – This relies on the criticals being an affine function of previous damage, since we are used to transform the mean of a roll.

Also note – rounding error makes this not completely accurate (but for the big crit weapons like Grond an odd point of damage won't be missed)

This code written according to the KISS principle. 650 adds are cheaper than a FOV call and get the job done fine.

References player::lev, MAX, MIN, and player_state::to_h.

Referenced by obj_known_damage().

static void calculate_missile_crits ( player_state state,
int  weight,
int  plus,
int mult,
int add,
int div 
)
static

Missile crits follow the same approach as melee crits.

References player::lev, MAX, MIN, and player_state::to_h.

Referenced by obj_known_damage().

static bool describe_blows ( textblock tb,
const object_type o_ptr 
)
static
static bool describe_brands ( textblock tb,
const struct object o_ptr 
)
static

Describe slays and brands on weapons.

References object::brands, FALSE, brand::multiplier, brand::name, brand::next, textblock_append(), TRUE, tval_is_fuel(), and tval_is_weapon().

Referenced by object_info_out().

static bool describe_combat ( textblock tb,
const object_type o_ptr 
)
static
static bool describe_curses ( textblock tb,
const object_type o_ptr,
const bitflag  flags[OF_SIZE] 
)
static

Describe an item's curses.

References COLOUR_L_RED, FALSE, flags, of_has, textblock_append_c(), and TRUE.

Referenced by object_info_out().

static bool describe_damage ( textblock tb,
const object_type o_ptr 
)
static
static bool describe_digger ( textblock tb,
const object_type o_ptr 
)
static
static bool describe_effect ( textblock tb,
const object_type o_ptr,
bool  only_artifacts,
bool  subjective 
)
static
static bool describe_ego ( textblock tb,
const struct ego_item ego 
)
static

Describe random properties that an ego item may have.

References FALSE, i, kf_has, ego_item::kind_flags, num, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_elements ( textblock tb,
const struct element_info  el_info[] 
)
static

Describe immunities, resistances and vulnerabilities granted by an object.

References element_info_collect(), FALSE, i, info_out_list(), N_ELEMENTS, prev, textblock_append(), and TRUE.

Referenced by object_info_out().

static void describe_flavor_text ( textblock tb,
const object_type o_ptr,
bool  ego 
)
static

Print an item's flavour text.

Parameters
tbis the textblock to which we are adding.
o_ptris the object we are describing.
egois whether we're describing an ego template (as opposed to a real object)

References object::artifact, object::ego, FALSE, object::kind, object_ego_is_visible(), object_flavor_is_aware(), object_is_known(), OPT, object_kind::text, artifact::text, ego_item::text, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_food ( textblock tb,
const object_type o_ptr,
bool  subjective 
)
static
static bool describe_hates ( textblock tb,
const struct element_info  el_info[] 
)
static

Describe elements that damage or destroy an object.

References EL_INFO_HATES, element_info_collect(), FALSE, flags, i, info_out_list(), N_ELEMENTS, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_ignores ( textblock tb,
const struct element_info  el_info[] 
)
static

Describe elements an object ignores.

References EL_INFO_IGNORE, element_info_collect(), FALSE, flags, i, info_out_list(), N_ELEMENTS, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_light ( textblock tb,
const object_type o_ptr,
oinfo_detail_t  mode 
)
static

Describe things that look like lights.

References object::artifact, COLOUR_L_GREEN, FALSE, format(), obj_known_light(), OINFO_TERSE, textblock_append(), textblock_append_c(), and TRUE.

Referenced by object_info_out().

static bool describe_misc_magic ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static

Describe miscellaneous powers.

References FALSE, flag, flags, i, N_ELEMENTS, of_has, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_origin ( textblock tb,
const object_type o_ptr,
bool  terse 
)
static
static bool describe_protects ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static

Describe protections granted by an object.

References FALSE, flag_info_collect(), flags, info_out_list(), N_ELEMENTS, textblock_append(), and TRUE.

Referenced by object_info_out().

static bool describe_slays ( textblock tb,
const struct object o_ptr 
)
static

Describe slays and brands on weapons.

References FALSE, slay::multiplier, slay::name, slay::next, object::slays, textblock_append(), TRUE, tval_is_fuel(), and tval_is_weapon().

Referenced by object_info_out().

static bool describe_stats ( textblock tb,
const object_type o_ptr,
oinfo_detail_t  mode 
)
static
static bool describe_sustains ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static

Describe stat sustains.

References FALSE, flag_info_collect(), flags, info_out_list(), N_ELEMENTS, textblock_append(), and TRUE.

Referenced by object_info_out().

static size_t element_info_collect ( const bool  list[],
const char *  recepticle[] 
)
static

Fills recepticle with all the elements that correspond to the given list.

References i, N_ELEMENTS, and flag_type::name.

Referenced by describe_elements(), describe_hates(), and describe_ignores().

static size_t flag_info_collect ( const flag_type  list[],
size_t  max,
const bitflag  flags[OF_SIZE],
const char *  recepticle[] 
)
static

Fills recepticle with all the flags in flags that are in the given list.

References flag, flags, i, flag_type::name, and of_has.

Referenced by describe_protects(), and describe_sustains().

static void get_known_elements ( const object_type o_ptr,
const oinfo_detail_t  mode,
struct element_info  el_info[] 
)
static

Get the object element info the player should know about for the given object/viewing mode combination.

References object::el_info, EL_INFO_HATES, EL_INFO_IGNORE, EL_INFO_KNOWN, element_info::flags, i, N_ELEMENTS, OINFO_EGO, OINFO_TERSE, and element_info::res_level.

Referenced by object_info_out().

static void get_known_flags ( const object_type o_ptr,
const oinfo_detail_t  mode,
bitflag  flags[OF_SIZE] 
)
static

Get the object flags the player should know about for the given object/ viewing mode combination.

References object_kind::base, object_base::flags, flags, object::kind, object_flags(), object_flags_known(), of_diff, OINFO_EGO, and OINFO_TERSE.

Referenced by obj_known_light(), obj_known_misc_combat(), and object_info_out().

static void info_out_list ( textblock tb,
const char *  list[],
size_t  count 
)
static

Given an array of strings, as so: { "intelligence", "fish", "lens", "prime", "number" },.

... output a list like "intelligence, fish, lens, prime, number.\n".

References i, and textblock_append().

Referenced by describe_elements(), describe_hates(), describe_ignores(), describe_protects(), and describe_sustains().

static int obj_known_blows ( const object_type obj,
int  max_num,
struct blow_info  possible_blows[] 
)
static

Gets information about the number of blows possible for the player with the given object.

Fills in whether the object is too_heavy to wield effectively, and the possible_blows[] information of .str_plus and .dex_plus needed to achieve the approximate number of blows in centiblows.

max_blows must be at least 1 to hold the current number of blows possible_blows must be at least [max_blows] in size, and will be limited to that number of entries. The theoretical maximum is STAT_RANGE * 2 if an extra blow/speed boost was given for each combination of STR and DEX.

Returns the number of entries made in the possible_blows[] table, or 0 if the object is not a weapon.

Note that the results are meaningless if called on a fake ego object as the actual ego may have different properties.

References player::body, calc_blows(), calc_bonuses(), blow_info::centiblows, player_body::count, blow_info::dex_plus, player::gear, i, object::kind, object::modifiers, num, player_state::num_blows, equip_slot::obj, object_this_mod_is_visible(), slot_by_name(), slot_object(), player_body::slots, player_state::stat_ind, STAT_RANGE, blow_info::str_plus, TRUE, and tval_is_melee_weapon().

Referenced by describe_blows().

static int obj_known_damage ( const object_type obj,
int normal_damage,
struct brand **  brand_list,
int **  brand_damage,
struct slay **  slay_list,
int **  slay_damage,
bool nonweap_slay 
)
static

Gets information about the average damage/turn that can be inflicted if the player wields the given weapon.

Fills in the damage against normal adversaries in normal_damage, as well as the slays on the weapon in slay_list[] and corresponding damages in slay_damage[]. These must both be at least SL_MAX long to be safe. nonweap_slay is set to whether other items being worn could add to the damage done by branding attacks.

Returns the number of slays populated in slay_list[] and slay_damage[].

Note that the results are meaningless if called on a fake ego object as the actual ego may have different properties.

References player_state::ammo_mult, player_state::ammo_tval, player::body, brand_collect(), object::brands, calc_bonuses(), calculate_melee_crits(), calculate_missile_crits(), player_body::count, object_kind::dd, object::dd, object_kind::ds, object::ds, equipped_item_by_slot_name(), FALSE, player::gear, i, object::kind, brand::known, slay::known, mem_zalloc(), brand::next, slay::next, player_state::num_blows, player_state::num_shots, equip_slot::obj, object_attack_plusses_are_visible(), slay_collect(), object::slays, slot_by_name(), slot_object(), player_body::slots, player::state, player_state::to_d, object::to_d, object::to_h, TRUE, object::tval, tval_is_melee_weapon(), and object::weight.

Referenced by describe_damage().

static bool obj_known_digging ( struct object obj,
int  deciturns[] 
)
static

Returns information about objects that can be used for digging.

deciturns will be filled in with the avg number of deciturns it will take to dig through each type of diggable terrain, and must be at least [DIGGING_MAX].

Returns FALSE if the object has no effect on digging, or if the specifics are meaningless (i.e. the object is an ego template, not a real item).

References player::body, calc_bonuses(), calc_digging_chances(), DIGGING_MAX, DIGGING_RUBBLE, FALSE, player::gear, i, MIN, object::modifiers, equip_slot::obj, slot_object(), player_body::slots, TRUE, tval_is_melee_weapon(), tval_is_wearable(), and wield_slot().

Referenced by describe_digger().

static bool obj_known_effect ( const object_type o_ptr,
int effect,
bool aimed,
int min_recharge,
int max_recharge,
int failure_chance 
)
static

Gives the known effects of using the given item.

Fills in:

  • the effect id, or OBJ_KNOWN_PRESENT if there is an effect but details are unknown
  • whether the effect can be aimed
  • the minimum and maximum time in game turns for the item to recharge (or zero if it does not recharge)
  • the percentage chance of the effect failing when used

Return FALSE if the object has no effect.

References object::artifact, object::effect, effect_aim(), FALSE, get_use_device_chance(), MAXIMISE, MINIMISE, OBJ_KNOWN_PRESENT, object_effect(), object_effect_is_known(), randcalc(), object::time, object::timeout, TRUE, tval_is_food(), tval_is_potion(), and tval_is_scroll().

Referenced by describe_effect().

static int obj_known_food ( const object_type o_ptr)
static

Gives the known nutritional value of the given object.

Returns the number of player deciturns it will nourish for or -1 if the exact value not known.

References OBJ_KNOWN_PRESENT, object_is_known(), object::pval, and tval_can_have_nourishment().

Referenced by describe_food().

static bool obj_known_light ( const object_type o_ptr,
oinfo_detail_t  mode,
int rad,
bool uses_fuel,
int refuel_turns 
)
static

Gives the known light-sourcey characteristics of the given object.

Fills in the radius of the light in rad, whether it uses fuel and how many turns light it can refuel in similar items.

Return FALSE if the object is not known to be a light source (which includes it not actually being a light source).

References object::artifact, FALSE, flags, angband_constants::fuel_lamp, get_known_flags(), object::modifiers, object_is_known(), of_has, OF_SIZE, TRUE, tval_is_light(), and z_info.

Referenced by describe_light().

static void obj_known_misc_combat ( const struct object obj,
bool thrown_effect,
int range,
bool impactful,
int break_chance,
bool too_heavy 
)
static

Gets miscellaneous combat information about the given object.

Fills in whether there is a special effect when thrown in thrown effect, the range in ft (or zero if not ammo), whether the weapon has the impact flag set, the percentage chance of breakage and whether it is too heavy to be weilded effectively at the moment.

References player_state::ammo_mult, player_state::ammo_tval, player::body, breakage_chance(), calc_bonuses(), object::dd, object::ds, equipped_item_by_slot_name(), FALSE, player::gear, get_known_flags(), player_state::heavy_wield, equip_slot::obj, object_flavor_is_aware(), of_has, OF_SIZE, slot_by_name(), player_body::slots, player::state, TRUE, object::tval, tval_is_melee_weapon(), and tval_is_potion().

Referenced by describe_combat().

textblock* object_info ( const object_type o_ptr,
oinfo_detail_t  mode 
)

Provide information on an item, including how it would affect the current player's state.

returns TRUE if anything is printed.

References object_info_out(), and OINFO_SUBJ.

Referenced by context_menu_object(), death_examine(), desc_art_fake(), desc_obj_fake(), display_object_recall(), display_object_recall_interactive(), store_examine(), and textui_obj_examine().

void object_info_chardump ( ang_file f,
const object_type o_ptr,
int  indent,
int  wrap 
)

Provide information on an item suitable for writing to the character dump.

  • keep it brief.

References object_info_out(), OINFO_SUBJ, OINFO_TERSE, textblock_free(), and textblock_to_file().

Referenced by write_character_dump().

textblock* object_info_ego ( struct ego_item ego)
static textblock* object_info_out ( const object_type o_ptr,
int  mode 
)
static
void object_info_spoil ( ang_file f,
const object_type o_ptr,
int  wrap 
)

Provide spoiler information on an item.

Practically, this means that we should not print anything which relies upon the player's current state, since that is not suitable for spoiler material.

References object_info_out(), OINFO_NONE, textblock_free(), and textblock_to_file().

Referenced by spoil_artifact().

Variable Documentation

const flag_type elements[]
static
const flag_type misc_flags[]
static
Initial value:
{
{ OF_BLESSED, "Blessed by the gods" },
{ OF_SLOW_DIGEST, "Slows your metabolism" },
{ OF_IMPAIR_HP, "Impairs hitpoint recovery" },
{ OF_IMPAIR_MANA, "Impairs mana recovery" },
{ OF_AFRAID, "Makes you afraid of melee, and worse at shooting and casting spells" },
{ OF_FEATHER, "Feather Falling" },
{ OF_REGEN, "Speeds regeneration" },
{ OF_FREE_ACT, "Prevents paralysis" },
{ OF_HOLD_LIFE, "Sustains your life force" },
{ OF_TELEPATHY, "Grants telepathy" },
{ OF_SEE_INVIS, "Grants the ability to see invisible things" },
{ OF_AGGRAVATE, "Aggravates creatures nearby" },
{ OF_DRAIN_EXP, "Drains experience" },
{ OF_TELEPORT, "Induces random teleportation" },
}
const flag_type mod_flags[]
static
Initial value:
{
#define STAT(a, b, c, d, e, f, g, h)
#define OBJ_MOD(a, b, c, d)
}
struct origin_type origins[]
static

Referenced by describe_origin().

const flag_type protect_flags[]
static
Initial value:
{
{ OF_PROT_FEAR, "fear" },
{ OF_PROT_BLIND, "blindness" },
{ OF_PROT_CONF, "confusion" },
{ OF_PROT_STUN, "stunning" },
}
const flag_type sustain_flags[]
static
Initial value:
{
#define STAT(a, b, c, d, e, f, g, h)
}