Angband
Data Structures | Functions | Variables
player-calcs.c File Reference

Player status calculation, signalling ui events based on status changes. More...

#include "angband.h"
#include "cave.h"
#include "game-event.h"
#include "game-input.h"
#include "game-world.h"
#include "init.h"
#include "mon-msg.h"
#include "mon-util.h"
#include "obj-curse.h"
#include "obj-gear.h"
#include "obj-ignore.h"
#include "obj-knowledge.h"
#include "obj-power.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-spell.h"
#include "player-timed.h"
#include "player-util.h"

Data Structures

struct  flag_event_trigger
 

Functions

bool earlier_object (struct object *orig, struct object *new, bool store)
 Decide which object comes earlier in the standard inventory listing, defaulting to the first if nothing separates them. More...
 
int equipped_item_slot (struct player_body body, struct object *item)
 
void calc_inventory (struct player_upkeep *upkeep, struct object *gear, struct player_body body)
 Put the player's inventory and quiver into easily accessible arrays. More...
 
static void update_inventory (struct player *p)
 
static int level_spells (struct player *p)
 "Percentage" (actually some complicated hack that needs redoing) of player's spells they can learn per level (-> realms - NRM) More...
 
static void calc_spells (struct player *p)
 Calculate number of spells player should have, and forget, or remember, spells until that number is properly reflected. More...
 
static int mana_per_level (struct player *p, struct player_state *state)
 Get the player's max spell points per effective level. More...
 
static void calc_mana (struct player *p, struct player_state *state, bool update)
 Calculate maximum mana. More...
 
static void calc_hitpoints (struct player *p)
 Calculate the players (maximal) hit points. More...
 
static void calc_torch (struct player *p, struct player_state *state, bool update)
 Calculate and set the current light radius. More...
 
void calc_digging_chances (struct player_state *state, int chances[DIGGING_MAX])
 Populates chances with the player's chance of digging through the diggable terrain types in one turn out of 1600. More...
 
int calc_blows (struct player *p, const struct object *obj, struct player_state *state, int extra_blows)
 Calculate the blows a player would get. More...
 
static int weight_limit (struct player_state *state)
 Computes current weight limit. More...
 
int weight_remaining (struct player *p)
 Computes weight remaining before burdened. More...
 
void calc_bonuses (struct player *p, struct player_state *state, bool known_only, bool update)
 Calculate the players current "state", taking into account not only race/class intrinsics, but also objects being worn and temporary spell effects. More...
 
static void update_bonuses (struct player *p)
 Calculate bonuses, and print various things on changes. More...
 
void health_track (struct player_upkeep *upkeep, struct monster *mon)
 

Monster and object tracking functions

More...
 
void monster_race_track (struct player_upkeep *upkeep, struct monster_race *race)
 Track the given monster race. More...
 
void track_object (struct player_upkeep *upkeep, struct object *obj)
 Track the given object. More...
 
void track_object_kind (struct player_upkeep *upkeep, struct object_kind *kind)
 Track the given object kind. More...
 
void track_object_cancel (struct player_upkeep *upkeep)
 Cancel all object tracking. More...
 
bool tracked_object_is (struct player_upkeep *upkeep, struct object *obj)
 Is the given item tracked? More...
 
void notice_stuff (struct player *p)
 

Generic "deal with" functions

More...
 
void update_stuff (struct player *p)
 Handle "player->upkeep->update". More...
 
void redraw_stuff (struct player *p)
 Handle "player->upkeep->redraw". More...
 
void handle_stuff (struct player *p)
 Handle "player->upkeep->update" and "player->upkeep->redraw". More...
 

Variables

static const int adj_int_dev [STAT_RANGE]
 Stat Table (INT) – Magic devices. More...
 
static const int adj_wis_sav [STAT_RANGE]
 Stat Table (WIS) – Saving throw. More...
 
static const int adj_dex_dis [STAT_RANGE]
 Stat Table (DEX) – disarming. More...
 
static const int adj_int_dis [STAT_RANGE]
 Stat Table (INT) – disarming. More...
 
static const int adj_dex_ta [STAT_RANGE]
 Stat Table (DEX) – bonus to ac. More...
 
static const int adj_str_td [STAT_RANGE]
 Stat Table (STR) – bonus to dam. More...
 
static const int adj_dex_th [STAT_RANGE]
 Stat Table (DEX) – bonus to hit. More...
 
static const int adj_str_th [STAT_RANGE]
 Stat Table (STR) – bonus to hit. More...
 
static const int adj_str_wgt [STAT_RANGE]
 Stat Table (STR) – weight limit in deca-pounds. More...
 
const int adj_str_hold [STAT_RANGE]
 Stat Table (STR) – weapon weight limit in pounds. More...
 
static const int adj_str_dig [STAT_RANGE]
 Stat Table (STR) – digging value. More...
 
const int adj_str_blow [STAT_RANGE]
 Stat Table (STR) – help index into the "blow" table. More...
 
static const int adj_dex_blow [STAT_RANGE]
 Stat Table (DEX) – index into the "blow" table. More...
 
const int adj_dex_safe [STAT_RANGE]
 Stat Table (DEX) – chance of avoiding "theft" and "falling". More...
 
const int adj_con_fix [STAT_RANGE]
 Stat Table (CON) – base regeneration rate. More...
 
static const int adj_con_mhp [STAT_RANGE]
 Stat Table (CON) – extra 1/100th hitpoints per level. More...
 
static const int adj_mag_study [STAT_RANGE]
 
static const int adj_mag_mana [STAT_RANGE]
 Stat Table (INT/WIS) – extra 1/100 mana-points per level. More...
 
static const int blows_table [12][12]
 This table is used to help calculate the number of blows the player can make in a single round of attacks (one player turn) with a normal weapon. More...
 
static const struct
flag_event_trigger 
redraw_events []
 Events triggered by the various flags. More...
 

Detailed Description

Player status calculation, signalling ui events based on status changes.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke Copyright (c) 2014 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

int calc_blows ( struct player p,
const struct object obj,
struct player_state state,
int  extra_blows 
)

Calculate the blows a player would get.

Parameters
objis the object for which we are calculating blows
stateis the player state for which we are calculating blows
extra_blowsis the number of +blows available from this object and this state

N.B. state->num_blows is now 100x the number of blows.

References adj_dex_blow, adj_str_blow, player_class::att_multiply, blows_table, player::class, MAX, player_class::max_attacks, MIN, player_class::min_weight, NULL, player_state::stat_ind, and object::weight.

Referenced by calc_bonuses(), and obj_known_blows().

void calc_bonuses ( struct player p,
struct player_state state,
bool  known_only,
bool  update 
)

Calculate the players current "state", taking into account not only race/class intrinsics, but also objects being worn and temporary spell effects.

See also calc_mana() and calc_hitpoints().

Take note of the new "speed code", in particular, a very strong player will start slowing down as soon as he reaches 150 pounds, but not until he reaches 450 pounds will he be half as fast as a normal kobold. This both hurts and helps the player, hurts because in the old days a player could just avoid 300 pounds, and helps because now carrying 300 pounds is not very painful.

The "weapon" and "bow" do not add to the bonuses to hit or to damage, since that would affect non-combat things. These values are actually added in later, at the appropriate place.

If known_only is true, calc_bonuses() will only use the known information of objects; thus it returns what the player knows the character state to be.

References player_state::ac, object::ac, adj_dex_dis, adj_dex_ta, adj_dex_th, adj_int_dev, adj_int_dis, adj_str_dig, adj_str_hold, adj_str_td, adj_str_th, adj_wis_sav, player_state::ammo_mult, player_state::ammo_tval, player::body, player_class::c_adj, player_class::c_skills, calc_blows(), calc_mana(), calc_torch(), player::class, player_body::count, player::csp, curse_max, curses, object::curses, player_race::el_info, player_state::el_info, object::el_info, ELEM_MAX, equipped_item_by_slot_name(), player_state::flags, object::flags, player_state::heavy_shoot, player_state::heavy_wield, i, player_state::icky_wield, index, player_race::infra, kf_has, object::kind, object_kind::kind_flags, object::known, player::lev, object::modifiers, modify_stat_value(), NULL, player_state::num_blows, player_state::num_shots, curse::obj, object_flags(), object_flags_known(), of_has, of_on, OF_SIZE, of_union, pf_copy, pf_on, pf_union, pf_wipe, player_race::pflags, player_class::pflags, player_state::pflags, player_flags(), player_has, curse_data::power, object::pval, player_race::r_adj, player_race::r_skills, player::race, element_info::res_level, player_state::see_infra, SKILL_DEVICE, SKILL_DIGGING, SKILL_DISARM_MAGIC, SKILL_DISARM_PHYS, SKILL_MAX, SKILL_SAVE, SKILL_SEARCH, SKILL_STEALTH, player_state::skills, slot_object(), slot_type_is(), player_state::speed, player_state::stat_add, player::stat_cur, player_state::stat_ind, STAT_MAX, player::stat_max, STAT_RANGE, player_state::stat_top, player_state::stat_use, player::timed, player_state::to_a, object::to_a, player_state::to_d, object::to_d, player_state::to_h, object::to_h, player_upkeep::total_weight, tval_is_digger(), tval_is_pointy(), player::upkeep, object::weight, weight_limit(), and player_class::x_skills.

Referenced by obj_known_blows(), obj_known_damage(), obj_known_digging(), obj_known_misc_combat(), and update_bonuses().

void calc_digging_chances ( struct player_state state,
int  chances[DIGGING_MAX] 
)

Populates chances with the player's chance of digging through the diggable terrain types in one turn out of 1600.

References DIGGING_DOORS, DIGGING_GRANITE, DIGGING_MAGMA, DIGGING_MAX, DIGGING_QUARTZ, DIGGING_RUBBLE, i, MAX, SKILL_DIGGING, and player_state::skills.

Referenced by do_cmd_tunnel_aux(), and obj_known_digging().

static void calc_hitpoints ( struct player p)
static

Calculate the players (maximal) hit points.

Adjust current hitpoints if necessary

References adj_con_mhp, player::chp, player::chp_frac, player::lev, player::mhp, player::player_hp, PR_HP, player_upkeep::redraw, player_state::stat_ind, player::state, and player::upkeep.

Referenced by update_stuff().

void calc_inventory ( struct player_upkeep upkeep,
struct object gear,
struct player_body  body 
)
static void calc_mana ( struct player p,
struct player_state state,
bool  update 
)
static
static void calc_spells ( struct player p)
static

Calculate number of spells player should have, and forget, or remember, spells until that number is properly reflected.

Note that this function induces various "status" messages, which must be bypasses until the character is created.

References character_generated, player::class, i, player::lev, level_spells(), player_class::magic, msg, class_spell::name, player_upkeep::new_spells, player_upkeep::only_partial, PR_OBJECT, PR_STUDY, PY_SPELL_FORGOTTEN, PY_SPELL_LEARNED, player_upkeep::redraw, class_spell::slevel, spell_by_index(), class_magic::spell_first, player::spell_flags, magic_realm::spell_noun, player::spell_order, class_magic::spell_realm, class_magic::total_spells, and player::upkeep.

Referenced by update_stuff().

static void calc_torch ( struct player p,
struct player_state state,
bool  update 
)
static

Calculate and set the current light radius.

The brightest wielded object counts as the light source; radii do not add up anymore.

Note that a cursed light source no longer emits light.

References player::body, player_body::count, player_state::cur_light, player::depth, object::flags, i, is_daytime(), MAX, MIN, object::modifiers, of_has, PU_MONSTERS, PU_UPDATE_VIEW, slot_object(), player::state, object::timeout, tval_is_light(), player_upkeep::update, and player::upkeep.

Referenced by calc_bonuses(), and update_stuff().

bool earlier_object ( struct object orig,
struct object new,
bool  store 
)

Decide which object comes earlier in the standard inventory listing, defaulting to the first if nothing separates them.

Returns
whether to replace the original object with the new one

References object_kind::flavor, object::kind, new, obj_can_browse(), object_flavor_is_aware(), object_value(), object::pval, object::sval, object::tval, tval_is_ammo(), and tval_is_light().

Referenced by calc_inventory(), and store_stock_list().

int equipped_item_slot ( struct player_body  body,
struct object item 
)
void handle_stuff ( struct player p)
void health_track ( struct player_upkeep upkeep,
struct monster mon 
)
static int level_spells ( struct player p)
static

"Percentage" (actually some complicated hack that needs redoing) of player's spells they can learn per level (-> realms - NRM)

References adj_mag_study, player::class, player_class::magic, class_magic::spell_realm, magic_realm::stat, player_state::stat_ind, and player::state.

Referenced by calc_spells().

static int mana_per_level ( struct player p,
struct player_state state 
)
static

Get the player's max spell points per effective level.

References adj_mag_mana, player::class, player_class::magic, class_magic::spell_realm, magic_realm::stat, and player_state::stat_ind.

Referenced by calc_mana().

void monster_race_track ( struct player_upkeep upkeep,
struct monster_race race 
)
void notice_stuff ( struct player p)
void redraw_stuff ( struct player p)
void track_object ( struct player_upkeep upkeep,
struct object obj 
)
void track_object_cancel ( struct player_upkeep upkeep)

Cancel all object tracking.

References NULL, player_upkeep::object, player_upkeep::object_kind, PR_OBJECT, and player_upkeep::redraw.

Referenced by desc_obj_fake().

void track_object_kind ( struct player_upkeep upkeep,
struct object_kind kind 
)

Track the given object kind.

References NULL, player_upkeep::object, player_upkeep::object_kind, PR_OBJECT, and player_upkeep::redraw.

Referenced by desc_obj_fake().

bool tracked_object_is ( struct player_upkeep upkeep,
struct object obj 
)

Is the given item tracked?

References player_upkeep::object.

Referenced by floor_object_for_use(), and gear_object_for_use().

static void update_bonuses ( struct player p)
static
static void update_inventory ( struct player p)
static
void update_stuff ( struct player p)
static int weight_limit ( struct player_state state)
static

Computes current weight limit.

References adj_str_wgt, i, and player_state::stat_ind.

Referenced by calc_bonuses().

int weight_remaining ( struct player p)

Variable Documentation

const int adj_con_fix[STAT_RANGE]

Stat Table (CON) – base regeneration rate.

Referenced by decrease_timeouts().

const int adj_con_mhp[STAT_RANGE]
static

Stat Table (CON) – extra 1/100th hitpoints per level.

Referenced by calc_hitpoints().

const int adj_dex_blow[STAT_RANGE]
static

Stat Table (DEX) – index into the "blow" table.

Referenced by calc_blows().

const int adj_dex_dis[STAT_RANGE]
static

Stat Table (DEX) – disarming.

Referenced by calc_bonuses().

const int adj_dex_safe[STAT_RANGE]

Stat Table (DEX) – chance of avoiding "theft" and "falling".

Referenced by blow_color(), melee_effect_handler_EAT_GOLD(), and melee_effect_handler_EAT_ITEM().

const int adj_dex_ta[STAT_RANGE]
static

Stat Table (DEX) – bonus to ac.

Referenced by calc_bonuses().

const int adj_dex_th[STAT_RANGE]
static

Stat Table (DEX) – bonus to hit.

Referenced by calc_bonuses().

const int adj_int_dev[STAT_RANGE]
static

Stat Table (INT) – Magic devices.

Referenced by calc_bonuses().

const int adj_int_dis[STAT_RANGE]
static

Stat Table (INT) – disarming.

Referenced by calc_bonuses().

const int adj_mag_mana[STAT_RANGE]
static

Stat Table (INT/WIS) – extra 1/100 mana-points per level.

Referenced by mana_per_level().

const int adj_mag_study[STAT_RANGE]
static

Referenced by level_spells().

const int adj_str_blow[STAT_RANGE]

Stat Table (STR) – help index into the "blow" table.

Referenced by calc_blows(), and do_cmd_throw().

const int adj_str_dig[STAT_RANGE]
static

Stat Table (STR) – digging value.

Referenced by calc_bonuses().

const int adj_str_hold[STAT_RANGE]

Stat Table (STR) – weapon weight limit in pounds.

Referenced by calc_bonuses().

const int adj_str_td[STAT_RANGE]
static

Stat Table (STR) – bonus to dam.

Referenced by calc_bonuses().

const int adj_str_th[STAT_RANGE]
static

Stat Table (STR) – bonus to hit.

Referenced by calc_bonuses().

const int adj_str_wgt[STAT_RANGE]
static

Stat Table (STR) – weight limit in deca-pounds.

Referenced by weight_limit(), and weight_remaining().

const int adj_wis_sav[STAT_RANGE]
static

Stat Table (WIS) – Saving throw.

Referenced by calc_bonuses().

const int blows_table[12][12]
static

This table is used to help calculate the number of blows the player can make in a single round of attacks (one player turn) with a normal weapon.

This number ranges from a single blow/round for weak players to up to six blows/round for powerful warriors.

Note that certain artifacts and ego-items give "bonus" blows/round.

First, from the player class, we extract some values:

Warrior –> num = 6; mul = 5; div = MAX(30, weapon_weight); Mage –> num = 4; mul = 2; div = MAX(40, weapon_weight); Priest –> num = 4; mul = 3; div = MAX(35, weapon_weight); Rogue –> num = 5; mul = 4; div = MAX(30, weapon_weight); Ranger –> num = 5; mul = 4; div = MAX(35, weapon_weight); Paladin –> num = 5; mul = 5; div = MAX(30, weapon_weight); (all specified in class.txt now)

To get "P", we look up the relevant "adj_str_blow[]" (see above), multiply it by "mul", and then divide it by "div", rounding down.

To get "D", we look up the relevant "adj_dex_blow[]" (see above).

Then we look up the energy cost of each blow using "blows_table[P][D]". The player gets blows/round equal to 100/this number, up to a maximum of "num" blows/round, plus any "bonus" blows/round.

Referenced by calc_blows().

const struct flag_event_trigger redraw_events[]
static
Initial value:
=
{
}
Definition: game-event.h:36
#define PR_STATE
Definition: player-calcs.h:65
#define PR_GOLD
Definition: player-calcs.h:59
#define PR_HEALTH
Definition: player-calcs.h:60
Definition: game-event.h:54
Definition: game-event.h:35
Definition: game-event.h:39
#define PR_STATS
Definition: player-calcs.h:55
Definition: game-event.h:45
Definition: game-event.h:58
#define PR_STATUS
Definition: player-calcs.h:64
#define PR_HP
Definition: player-calcs.h:57
Definition: game-event.h:56
Definition: game-event.h:34
#define PR_EQUIP
Definition: player-calcs.h:68
Definition: game-event.h:55
Definition: game-event.h:57
Definition: game-event.h:31
#define PR_MONLIST
Definition: player-calcs.h:72
Definition: game-event.h:44
#define PR_MONSTER
Definition: player-calcs.h:70
Definition: game-event.h:60
Definition: game-event.h:32
#define PR_MISC
Bit flags for the "player->upkeep->redraw" variable.
Definition: player-calcs.h:51
#define PR_LEV
Definition: player-calcs.h:53
#define PR_DEPTH
Definition: player-calcs.h:63
Definition: game-event.h:42
Definition: game-event.h:46
Definition: game-event.h:43
Definition: game-event.h:37
#define PR_STUDY
Definition: player-calcs.h:62
Definition: game-event.h:33
#define PR_TITLE
Definition: player-calcs.h:52
#define PR_SPEED
Definition: player-calcs.h:61
#define PR_MESSAGE
Definition: player-calcs.h:69
Definition: game-event.h:40
#define PR_EXP
Definition: player-calcs.h:54
#define PR_ARMOR
Definition: player-calcs.h:56
#define PR_ITEMLIST
Definition: player-calcs.h:73
#define PR_MANA
Definition: player-calcs.h:58
Definition: game-event.h:41
Definition: game-event.h:59
Definition: game-event.h:38
#define PR_INVEN
Definition: player-calcs.h:67
#define PR_FEELING
Definition: player-calcs.h:74
#define PR_OBJECT
Definition: player-calcs.h:71

Events triggered by the various flags.