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-gear.h"
#include "obj-identify.h"
#include "obj-ignore.h"
#include "obj-tval.h"
#include "obj-util.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.
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.
static void update_inventory (void)
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)
static void calc_spells (void)
 Calculate number of spells player should have, and forget, or remember, spells until that number is properly reflected.
int mana_per_level (struct player *p)
 Get the player's max spell points per effective level.
static void calc_mana (void)
 Calculate maximum mana.
static void calc_hitpoints (void)
 Calculate the players (maximal) hit points.
static void calc_torch (void)
 Calculate and set the current light radius.
void calc_digging_chances (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.
int calc_blows (const object_type *o_ptr, player_state *state, int extra_blows)
 Calculate the blows a player would get.
static int weight_limit (player_state *state)
 Computes current weight limit.
int weight_remaining (void)
 Computes weight remaining before burdened.
void calc_bonuses (struct object *gear, player_state *state, bool known_only)
 Calculate the players current "state", taking into account not only race/class intrinsics, but also objects being worn and temporary spell effects.
static void update_bonuses (void)
 Calculate bonuses, and print various things on changes.
void health_track (struct player_upkeep *upkeep, struct monster *m_ptr)
 

Monster and object tracking functions


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

Generic "deal with" functions


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

Variables

const byte adj_int_dev [STAT_RANGE]
 Stat Table (INT) – Magic devices.
const byte adj_wis_sav [STAT_RANGE]
 Stat Table (WIS) – Saving throw.
const byte adj_dex_dis [STAT_RANGE]
 Stat Table (DEX) – disarming.
const byte adj_int_dis [STAT_RANGE]
 Stat Table (INT) – disarming.
const byte adj_dex_ta [STAT_RANGE]
 Stat Table (DEX) – bonus to ac (plus 128)
const byte adj_str_td [STAT_RANGE]
 Stat Table (STR) – bonus to dam (plus 128)
const byte adj_dex_th [STAT_RANGE]
 Stat Table (DEX) – bonus to hit (plus 128)
const byte adj_str_th [STAT_RANGE]
 Stat Table (STR) – bonus to hit (plus 128)
const byte adj_str_wgt [STAT_RANGE]
 Stat Table (STR) – weight limit in deca-pounds.
const byte adj_str_hold [STAT_RANGE]
 Stat Table (STR) – weapon weight limit in pounds.
const byte adj_str_dig [STAT_RANGE]
 Stat Table (STR) – digging value.
const byte adj_str_blow [STAT_RANGE]
 Stat Table (STR) – help index into the "blow" table.
const byte adj_dex_blow [STAT_RANGE]
 Stat Table (DEX) – index into the "blow" table.
const byte adj_dex_safe [STAT_RANGE]
 Stat Table (DEX) – chance of avoiding "theft" and "falling".
const byte adj_con_fix [STAT_RANGE]
 Stat Table (CON) – base regeneration rate.
const int adj_con_mhp [STAT_RANGE]
 Stat Table (CON) – extra 1/100th hitpoints per level.
const int adj_mag_study [STAT_RANGE]
const int adj_mag_mana [STAT_RANGE]
 Stat Table (INT/WIS) – extra 1/100 mana-points per level.
const byte 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.
static struct flag_event_trigger redraw_events []
 Events triggered by the various flags.

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 ( const object_type o_ptr,
player_state state,
int  extra_blows 
)

Calculate the blows a player would get.

Parameters
o_ptris 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, player_state::stat_ind, and object::weight.

Referenced by calc_bonuses(), and obj_known_blows().

void calc_bonuses ( struct object gear,
player_state state,
bool  known_only 
)

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(), player::class, player_body::count, player::csp, player_race::el_info, player_state::el_info, object::el_info, ELEM_MAX, equipped_item_by_slot_name(), FALSE, player_state::flags, player_state::heavy_shoot, player_state::heavy_wield, i, player_state::icky_wield, player_race::infra, int, kf_has, object::kind, object_kind::kind_flags, player::lev, object::modifiers, modify_stat_value(), player_state::noise, player_state::num_blows, player_state::num_shots, object_attack_plusses_are_visible(), object_defence_plusses_are_visible(), object_element_is_known(), object_flags(), object_flags_known(), object_is_known(), of_has, of_on, OF_SIZE, of_union, pf_copy, pf_on, pf_union, pf_wipe, player_race::pflags, player_state::pflags, player_class::pflags, player_flags(), player_has, player_of_has(), object::pval, player_race::r_adj, player_race::r_skills, player::race, element_info::res_level, player::searching, player_state::see_infra, SKILL_DEVICE, SKILL_DIGGING, SKILL_DISARM, SKILL_MAX, SKILL_SAVE, SKILL_SEARCH, SKILL_SEARCH_FREQUENCY, 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, TRUE, 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 ( 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 ( void  )
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 ( void  )
static
static void calc_spells ( void  )
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, p, 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 ( void  )
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 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::cost, FALSE, object::kind, obj_can_browse(), object_flavor_is_aware(), object_is_known(), object::pval, object::sval, TRUE, object::tval, 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_upkeep upkeep)
void health_track ( struct player_upkeep upkeep,
struct monster m_ptr 
)
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)

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().

int mana_per_level ( struct player p)

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, player_state::stat_ind, and player::state.

Referenced by calc_mana().

void monster_race_track ( struct player_upkeep upkeep,
monster_race race 
)
void notice_stuff ( struct player_upkeep upkeep)
void redraw_stuff ( struct player_upkeep upkeep)
void track_object ( struct player_upkeep upkeep,
struct object obj 
)
void track_object_kind ( struct player_upkeep upkeep,
struct object_kind kind 
)

Track the given object kind.

References object::kind, 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 gear_object_for_use().

static void update_bonuses ( void  )
static
static void update_inventory ( void  )
static
void update_stuff ( struct player_upkeep upkeep)
static int weight_limit ( 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 ( void  )

Variable Documentation

const byte adj_con_fix[STAT_RANGE]

Stat Table (CON) – base regeneration rate.

Referenced by decrease_timeouts().

const int adj_con_mhp[STAT_RANGE]

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

Referenced by calc_hitpoints().

const byte adj_dex_blow[STAT_RANGE]

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

Referenced by calc_blows().

const byte adj_dex_dis[STAT_RANGE]

Stat Table (DEX) – disarming.

Referenced by calc_bonuses().

const byte adj_dex_safe[STAT_RANGE]

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

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

const byte adj_dex_ta[STAT_RANGE]

Stat Table (DEX) – bonus to ac (plus 128)

Referenced by calc_bonuses().

const byte adj_dex_th[STAT_RANGE]

Stat Table (DEX) – bonus to hit (plus 128)

Referenced by calc_bonuses().

const byte adj_int_dev[STAT_RANGE]

Stat Table (INT) – Magic devices.

Referenced by calc_bonuses().

const byte adj_int_dis[STAT_RANGE]

Stat Table (INT) – disarming.

Referenced by calc_bonuses().

const int adj_mag_mana[STAT_RANGE]

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

Referenced by mana_per_level().

const int adj_mag_study[STAT_RANGE]

Referenced by level_spells().

const byte adj_str_blow[STAT_RANGE]

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

Referenced by calc_blows(), and do_cmd_throw().

const byte adj_str_dig[STAT_RANGE]

Stat Table (STR) – digging value.

Referenced by calc_bonuses().

const byte adj_str_hold[STAT_RANGE]

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

Referenced by calc_bonuses().

const byte adj_str_td[STAT_RANGE]

Stat Table (STR) – bonus to dam (plus 128)

Referenced by calc_bonuses().

const byte adj_str_th[STAT_RANGE]

Stat Table (STR) – bonus to hit (plus 128)

Referenced by calc_bonuses().

const byte adj_str_wgt[STAT_RANGE]

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

Referenced by weight_limit(), and weight_remaining().

const byte adj_wis_sav[STAT_RANGE]

Stat Table (WIS) – Saving throw.

Referenced by calc_bonuses().

const byte 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.

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().

struct flag_event_trigger redraw_events[]
static