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 "mon-summon.h"
#include "mon-util.h"
#include "obj-curse.h"
#include "obj-gear.h"
#include "obj-info.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "project.h"
#include "z-textblock.h"
#include "list-origins.h"
#include "list-effects.h"

Data Structures

struct  blow_info
 Describes the number of blows possible for given stat bonuses. More...
 
struct  origin_type
 

Data tables

More...
 

Macros

#define ORIGIN(a, b, c)   { ORIGIN_##a, b, c },
 
#define EFFECT(x, a, b, c, d, e)   { EF_##x, c, d, e },
 

Functions

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

List-writiing utility code

More...
 
static size_t element_info_collect (const bool list[], const char *recepticle[])
 Fills recepticle with all the elements that correspond to the given list. More...
 
static bool describe_curses (textblock *tb, const struct object *obj, const bitflag flags[OF_SIZE])
 

Code that makes use of the data tables to describe aspects of an

object's information

More...
 
static bool describe_stats (textblock *tb, const struct object *obj, oinfo_detail_t mode)
 Describe stat modifications. More...
 
static bool describe_elements (textblock *tb, const struct element_info el_info[])
 Describe immunities, resistances and vulnerabilities granted by an object. More...
 
static bool describe_protects (textblock *tb, const bitflag flags[OF_SIZE])
 Describe protections granted by an object. More...
 
static bool describe_ignores (textblock *tb, const struct element_info el_info[])
 Describe elements an object ignores. More...
 
static bool describe_hates (textblock *tb, const struct element_info el_info[])
 Describe elements that damage or destroy an object. More...
 
static bool describe_sustains (textblock *tb, const bitflag flags[OF_SIZE])
 Describe stat sustains. More...
 
static bool describe_misc_magic (textblock *tb, const bitflag flags[OF_SIZE])
 Describe miscellaneous powers. More...
 
static bool describe_slays (textblock *tb, const struct object *obj)
 Describe slays and brands on weapons. More...
 
static bool describe_brands (textblock *tb, const struct object *obj)
 Describe slays and brands on weapons. More...
 
static void calculate_melee_crits (struct player_state *state, int weight, int plus, int *mult, int *add, int *div)
 Account for criticals in the calculation of melee prowess. More...
 
static void calculate_missile_crits (struct player_state *state, int weight, int plus, int *mult, int *add, int *div)
 Missile crits follow the same approach as melee crits. More...
 
static void get_known_flags (const struct object *obj, 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. More...
 
static void get_known_elements (const struct object *obj, 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. More...
 
static int obj_known_blows (const struct object *obj, int max_num, struct blow_info possible_blows[])
 Gets information about the number of blows possible for the player with the given object. More...
 
static bool describe_blows (textblock *tb, const struct object *obj)
 Describe blows. More...
 
static bool obj_known_damage (const struct object *obj, int *normal_damage, int *brand_damage, int *slay_damage, bool *nonweap_slay)
 Gets information about the average damage/turn that can be inflicted if the player wields the given weapon. More...
 
static bool describe_damage (textblock *tb, const struct object *obj)
 Describe damage. More...
 
static void obj_known_misc_combat (const struct object *obj, bool *thrown_effect, int *range, int *break_chance, bool *heavy)
 Gets miscellaneous combat information about the given object. More...
 
static bool describe_combat (textblock *tb, const struct object *obj)
 Describe combat advantages. More...
 
static bool obj_known_digging (struct object *obj, int deciturns[])
 Returns information about objects that can be used for digging. More...
 
static bool describe_digger (textblock *tb, const struct object *obj)
 Describe objects that can be used for digging. More...
 
static bool obj_known_light (const struct object *obj, oinfo_detail_t mode, int *rad, bool *uses_fuel, int *refuel_turns)
 Gives the known light-sourcey characteristics of the given object. More...
 
static bool describe_light (textblock *tb, const struct object *obj, oinfo_detail_t mode)
 Describe things that look like lights. More...
 
static bool obj_known_effect (const struct object *obj, struct effect **effect, bool *aimed, int *min_recharge, int *max_recharge, int *failure_chance)
 Gives the known effects of using the given item. More...
 
static bool describe_effect (textblock *tb, const struct object *obj, bool only_artifacts, bool subjective)
 Describe an object's effect, if any. More...
 
static bool describe_origin (textblock *tb, const struct object *obj, bool terse)
 Describe an item's origin. More...
 
static void describe_flavor_text (textblock *tb, const struct object *obj, bool ego)
 Print an item's flavour text. More...
 
static bool describe_ego (textblock *tb, const struct ego_item *ego)
 Describe random properties that an ego item may have. More...
 
static textblockobject_info_out (const struct object *obj, int mode)
 

Output code

More...
 
textblockobject_info (const struct object *obj, oinfo_detail_t mode)
 Provide information on an item, including how it would affect the current player's state. More...
 
textblockobject_info_ego (struct ego_item *ego)
 Provide information on an ego-item type. More...
 
void object_info_chardump (ang_file *f, const struct object *obj, int indent, int wrap)
 Provide information on an item suitable for writing to the character dump. More...
 
void object_info_spoil (ang_file *f, const struct object *obj, int wrap)
 Provide spoiler information on an item. More...
 

Variables

static const struct origin_type origins []
 
struct {
   int   index
 
   int   args
 
   int   efinfo_flag
 
   const char *   desc
 
base_descs []
 

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 EFFECT (   x,
  a,
  b,
  c,
  d,
 
)    { EF_##x, c, d, e },
#define ORIGIN (   a,
  b,
 
)    { ORIGIN_##a, b, c },

Function Documentation

static void calculate_melee_crits ( struct 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 ( struct 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 struct object obj 
)
static
static bool describe_brands ( textblock tb,
const struct object obj 
)
static
static bool describe_combat ( textblock tb,
const struct object obj 
)
static
static bool describe_curses ( textblock tb,
const struct object obj,
const bitflag  flags[OF_SIZE] 
)
static


Code that makes use of the data tables to describe aspects of an

object's information

Describe an item's curses.

References COLOUR_L_RED, angband_constants::curse_max, curses, object::curses, desc, i, object::known, curse_data::power, textblock_append(), textblock_append_c(), and z_info.

Referenced by object_info_out().

static bool describe_damage ( textblock tb,
const struct object obj 
)
static
static bool describe_digger ( textblock tb,
const struct object obj 
)
static
static bool describe_effect ( textblock tb,
const struct object obj,
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 kf_has, ego_item::kind_flags, and textblock_append().

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 ELEM_MAX, element_info_collect(), i, info_out_list(), prev, and textblock_append().

Referenced by object_info_out().

static void describe_flavor_text ( textblock tb,
const struct object obj,
bool  ego 
)
static

Print an item's flavour text.

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

References object::artifact, object::ego, object::kind, object::known, NULL, object_flavor_is_aware(), OPT, object_kind::text, artifact::text, ego_item::text, and textblock_append().

Referenced by object_info_out().

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, ELEM_MAX, element_info_collect(), flags, i, info_out_list(), and textblock_append().

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, ELEM_MAX, element_info_collect(), flags, i, info_out_list(), and textblock_append().

Referenced by object_info_out().

static bool describe_light ( textblock tb,
const struct object obj,
oinfo_detail_t  mode 
)
static
static bool describe_misc_magic ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static
static bool describe_origin ( textblock tb,
const struct object obj,
bool  terse 
)
static
static bool describe_protects ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static
static bool describe_slays ( textblock tb,
const struct object obj 
)
static

Describe slays and brands on weapons.

References i, object::known, angband_constants::slay_max, slays, object::slays, textblock_append(), tval_is_fuel(), tval_is_weapon(), and z_info.

Referenced by object_info_out().

static bool describe_stats ( textblock tb,
const struct object obj,
oinfo_detail_t  mode 
)
static
static bool describe_sustains ( textblock tb,
const bitflag  flags[OF_SIZE] 
)
static
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 ELEM_MAX, i, projection::name, and projections.

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

static void get_known_elements ( const struct object obj,
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, ELEM_MAX, element_info::flags, i, object::known, player::obj_k, OINFO_SPOIL, OINFO_TERSE, and element_info::res_level.

Referenced by object_info_out().

static void get_known_flags ( const struct object obj,
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 object_info_out().

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


List-writiing utility code

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 struct object 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, i, object::known, object::modifiers, num, player_state::num_blows, equip_slot::obj, slot_by_name(), slot_object(), player_body::slots, player_state::stat_ind, STAT_RANGE, blow_info::str_plus, and tval_is_melee_weapon().

Referenced by describe_blows().

static bool obj_known_damage ( const struct object obj,
int normal_damage,
int brand_damage,
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, angband_constants::brand_max, brands, object::brands, calc_bonuses(), calculate_melee_crits(), calculate_missile_crits(), copy_brands(), copy_slays(), player_body::count, object::dd, object::ds, equipped_item_by_slot_name(), i, object::known, mem_free(), mem_zalloc(), brand::multiplier, slay::multiplier, player_state::num_blows, player_state::num_shots, equip_slot::obj, angband_constants::slay_max, slays, object::slays, slot_by_name(), slot_object(), player_body::slots, player::state, player_state::to_d, object::to_d, object::to_h, object::tval, tval_is_melee_weapon(), object::weight, and z_info.

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, i, object::known, MIN, object::modifiers, equip_slot::obj, slot_object(), player_body::slots, tval_is_melee_weapon(), tval_is_wearable(), and wield_slot().

Referenced by describe_digger().

static bool obj_known_effect ( const struct object obj,
struct effect **  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
  • 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, effect_aim(), get_use_device_chance(), MAXIMISE, MINIMISE, NULL, object_effect(), object_effect_is_known(), object_is_in_store(), randcalc(), object::time, object::timeout, tval_is_edible(), tval_is_potion(), tval_is_scroll(), and tval_is_useable().

Referenced by describe_effect().

static bool obj_known_light ( const struct object obj,
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, object::flags, angband_constants::fuel_lamp, object::known, object::modifiers, of_has, 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,
int break_chance,
bool *  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), the percentage chance of breakage and whether it is too heavy to be wielded 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(), player_state::heavy_wield, angband_constants::max_range, MIN, equip_slot::obj, object_flavor_is_aware(), slot_by_name(), player_body::slots, player::state, object::tval, tval_is_melee_weapon(), tval_is_potion(), and z_info.

Referenced by describe_combat().

textblock* object_info ( const struct object obj,
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 struct object obj,
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 struct object obj,
int  mode 
)
static
void object_info_spoil ( ang_file f,
const struct object obj,
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_SPOIL, textblock_free(), and textblock_to_file().

Referenced by spoil_artifact().

Variable Documentation

int args
struct { ... } base_descs[]

Referenced by describe_effect().

const char* desc
int efinfo_flag
int index
const struct origin_type origins[]
static

Referenced by describe_origin().