Angband
|
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 | average_spell_stat (struct player *p, struct player_state *state) |
Average of the player's spell stats across all the realms they can cast from, rounded up. 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 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... | |
static void | calc_shapechange (struct player_state *state, struct player_shape *shape, int *blows, int *shots, int *might, int *moves) |
Calculate the effect of a shapechange on player state. 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 functionsMore... | |
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" functionsMore... | |
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... | |
const int | adj_str_td [STAT_RANGE] |
Stat Table (STR) – bonus to dam. More... | |
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... | |
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.
|
static |
Average of the player's spell stats across all the realms they can cast from, rounded up.
If the player can only cast from a single realm, this is simple the stat for that realm
References player::class, class_magic_realms(), i, mem_free(), magic_realm::next, magic_realm::stat, and player_state::stat_ind.
Referenced by calc_mana(), and calc_spells().
int calc_blows | ( | struct player * | p, |
const struct object * | obj, | ||
struct player_state * | state, | ||
int | extra_blows | ||
) |
Calculate the blows a player would get.
obj | is the object for which we are calculating blows |
state | is the player state for which we are calculating blows |
extra_blows | is 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().
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_state::bless_wield, player::body, player_class::c_adj, player_class::c_skills, calc_blows(), calc_mana(), calc_shapechange(), calc_torch(), character_dungeon, player::class, player_body::count, curse_max, curses, object::curses, player_state::dam_red, 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, index, player_race::infra, kf_has, object::kind, object_kind::kind_flags, object::known, player::lev, MAX, MIN, object::modifiers, modify_stat_value(), player::msp, player_state::num_blows, player_state::num_moves, player_state::num_shots, curse::obj, player::obj_k, 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, player::shape, 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(), 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().
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 | ||
) |
Put the player's inventory and quiver into easily accessible arrays.
The pack may be overfull by one item
References character_dungeon, earlier_object(), i, player_upkeep::inven, player_upkeep::inven_cnt, mem_free(), mem_zalloc(), msg, object::next, object::note, object::number, object_is_equipped(), object_learn_on_wield(), angband_constants::pack_size, quark_str(), player_upkeep::quiver, player_upkeep::quiver_cnt, angband_constants::quiver_size, tval_is_ammo(), and z_info.
Referenced by combine_pack(), gear_excise_object(), rd_gear(), and update_inventory().
|
static |
Calculate maximum mana.
You do not need to know any spells. Note that mana is lowered by heavy (or inappropriate) armor.
This function induces status messages.
References adj_mag_mana, average_spell_stat(), player::body, player::class, player_body::count, player::csp, player::csp_frac, player_state::cumber_armor, i, player::lev, levels(), player_class::magic, player::msp, PR_MANA, player_upkeep::redraw, slot_object(), slot_type_is(), class_magic::spell_first, class_magic::spell_weight, class_magic::total_spells, player::upkeep, and object::weight.
Referenced by calc_bonuses(), and update_stuff().
|
static |
Calculate the effect of a shapechange on player state.
References player_state::dam_red, player_shape::el_info, player_state::el_info, ELEM_MAX, player_shape::flags, player_state::flags, i, player_shape::modifiers, of_union, pf_union, player_shape::pflags, player_state::pflags, element_info::res_level, player_state::see_infra, SKILL_DIGGING, SKILL_MAX, SKILL_SEARCH, SKILL_STEALTH, player_shape::skills, player_state::skills, player_state::speed, player_state::stat_add, STAT_MAX, player_shape::to_a, player_state::to_a, player_shape::to_d, player_state::to_d, player_shape::to_h, and player_state::to_h.
Referenced by calc_bonuses().
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 adj_mag_study, average_spell_stat(), buf, character_generated, player::class, class_magic_realms(), i, player::lev, levels(), player_class::magic, mem_free(), msg, my_strcat(), my_strcpy(), class_spell::name, player_upkeep::new_spells, magic_realm::next, player_upkeep::only_partial, PR_OBJECT, PR_STUDY, PY_SPELL_FORGOTTEN, PY_SPELL_LEARNED, class_spell::realm, player_upkeep::redraw, class_spell::slevel, spell_by_index(), class_magic::spell_first, player::spell_flags, magic_realm::spell_noun, player::spell_order, player::state, class_magic::total_spells, and player::upkeep.
Referenced by update_stuff().
|
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().
Decide which object comes earlier in the standard inventory listing, defaulting to the first if nothing separates them.
References object_kind::flavor, object::kind, 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 | ||
) |
References player_body::count, i, equip_slot::obj, and player_body::slots.
Referenced by do_cmd_wield(), gear_to_label(), and inven_takeoff().
Handle "player->upkeep->update" and "player->upkeep->redraw".
References player_upkeep::redraw, redraw_stuff(), player_upkeep::update, update_stuff(), and player::upkeep.
Referenced by adjust_level(), close_game(), death_knowledge(), desc_art_fake(), desc_obj_fake(), display_knowledge(), do_cmd_buy(), do_cmd_locate(), do_cmd_query_symbol(), do_cmd_redraw(), do_cmd_rerate(), do_cmd_rest(), do_cmd_retrieve(), do_cmd_sell(), do_cmd_stash(), do_cmd_study_book(), do_cmd_wiz_advance(), effect_handler_DEEP_DESCENT(), effect_handler_RECALL(), effect_handler_SHAPECHANGE(), effect_handler_TELEPORT(), effect_handler_TELEPORT_TO(), mon_lore(), player_resume_normal_shape(), player_set_food(), player_set_timed(), pre_turn_refresh(), process_player(), project(), ranged_helper(), run_game_loop(), save_game(), store_menu_handle(), target_set_interactive(), target_set_interactive_aux(), textui_get_spell_from_book(), textui_spell_browse(), and wiz_create_item().
void health_track | ( | struct player_upkeep * | upkeep, |
struct monster * | mon | ||
) |
Track the given monster
References player_upkeep::health_who, PR_HEALTH, and player_upkeep::redraw.
Referenced by delete_monster_idx(), on_new_level(), project(), py_attack_real(), ranged_helper(), target_set_closest(), target_set_interactive(), target_set_interactive_aux(), textui_process_click(), and wipe_mon_list().
void monster_race_track | ( | struct player_upkeep * | upkeep, |
struct monster_race * | race | ||
) |
Track the given monster race.
References player_upkeep::monster_race, PR_MONSTER, and player_upkeep::redraw.
Referenced by do_cmd_query_symbol(), mon_lore(), player_kill_monster(), project(), py_attack_real(), ranged_helper(), target_set_closest(), target_set_interactive(), target_set_interactive_aux(), and textui_process_click().
Handle "player->upkeep->notice"
References combine_pack(), ignore_drop(), player_upkeep::notice, PN_COMBINE, PN_IGNORE, PN_MON_MESSAGE, show_monster_messages(), and player::upkeep.
Referenced by do_cmd_sell(), on_leave_level(), on_new_level(), pack_overflow(), player_kill_monster(), process_player(), run_game_loop(), and store_menu_handle().
Handle "player->upkeep->redraw".
References character_generated, flag_event_trigger::event, EVENT_END, EVENT_MAP, event_signal(), event_signal_point(), flag_event_trigger::flag, i, map_is_visible(), N_ELEMENTS, player_resting_count(), PR_MAP, PR_MESSAGE, PR_SUBWINDOW, player_upkeep::redraw, player_upkeep::running, and player::upkeep.
Referenced by display_bolt(), display_explosion(), display_missile(), handle_stuff(), idle_update(), modify_panel(), new_level_display_update(), on_leave_level(), on_new_level(), pack_overflow(), process_player_cleanup(), screen_save(), textui_get_item(), and ui_enter_world().
void track_object | ( | struct player_upkeep * | upkeep, |
struct object * | obj | ||
) |
Track the given object.
References player_upkeep::object, player_upkeep::object_kind, PR_OBJECT, and player_upkeep::redraw.
Referenced by context_menu_player_display_floor(), desc_obj_fake(), do_cmd_equip(), do_cmd_inven(), do_cmd_quiver(), do_cmd_study_book(), floor_object_for_use(), gear_object_for_use(), target_set_interactive_aux(), textui_get_spell_from_book(), textui_obj_examine(), textui_spell_browse(), and use_aux().
void track_object_cancel | ( | struct player_upkeep * | upkeep | ) |
Cancel all object tracking.
References 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 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().
Calculate bonuses, and print various things on changes.
References player_state::ac, player_state::bless_wield, calc_bonuses(), player_state::cumber_armor, player_state::cur_light, equipped_item_by_slot_name(), player_state::flags, player_state::heavy_shoot, player_state::heavy_wield, i, player::known_state, msg, of_has, player_upkeep::only_partial, PR_ARMOR, PR_SPEED, PR_STATS, PU_HP, PU_MANA, PU_MONSTERS, PU_SPELLS, PU_UPDATE_VIEW, player_upkeep::redraw, player_state::speed, player_state::stat_ind, STAT_MAX, player_state::stat_top, player_state::stat_use, player::state, player_state::to_a, player_upkeep::update, and player::upkeep.
Referenced by update_stuff().
References player::body, calc_inventory(), player::gear, and player::upkeep.
Referenced by update_stuff().
Handle "player->upkeep->update".
References calc_hitpoints(), calc_mana(), calc_spells(), calc_torch(), cave, character_generated, player::class, EVENT_PLAYERMOVED, event_signal(), player_class::magic, map_is_visible(), PU_BONUS, PU_DISTANCE, PU_HP, PU_INVEN, PU_MANA, PU_MONSTERS, PU_PANEL, PU_SPELLS, PU_TORCH, PU_UPDATE_VIEW, player::state, class_magic::total_spells, player_upkeep::update, update_bonuses(), update_inventory(), update_monsters(), update_view(), and player::upkeep.
Referenced by effect_handler_RESTORE_EXP(), effect_handler_RESTORE_STAT(), get_bonuses(), handle_stuff(), inven_carry(), inven_takeoff(), inven_wield(), light_room(), new_level_display_update(), on_leave_level(), on_new_level(), pack_overflow(), process_player_cleanup(), and project().
|
static |
Computes current weight limit.
References adj_str_wgt, i, and player_state::stat_ind.
Referenced by calc_bonuses().
Computes weight remaining before burdened.
References adj_str_wgt, i, player_state::stat_ind, player::state, player_upkeep::total_weight, and player::upkeep.
Referenced by context_menu_player_display_floor(), get_panel_midleft(), and show_inven().
const int adj_con_fix[STAT_RANGE] |
Stat Table (CON) – base regeneration rate.
Referenced by decrease_timeouts().
|
static |
Stat Table (CON) – extra 1/100th hitpoints per level.
Referenced by calc_hitpoints().
|
static |
Stat Table (DEX) – index into the "blow" table.
Referenced by calc_blows().
|
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().
|
static |
Stat Table (DEX) – bonus to ac.
Referenced by calc_bonuses().
const int adj_dex_th[STAT_RANGE] |
Stat Table (DEX) – bonus to hit.
Referenced by attempt_shield_bash(), calc_bonuses(), and steal_monster_item().
|
static |
Stat Table (INT) – Magic devices.
Referenced by calc_bonuses().
|
static |
Stat Table (INT) – disarming.
Referenced by calc_bonuses().
|
static |
Stat Table (INT/WIS) – extra 1/100 mana-points per level.
Referenced by calc_mana().
|
static |
Referenced by calc_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().
|
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] |
Stat Table (STR) – bonus to dam.
Referenced by attempt_shield_bash(), and calc_bonuses().
|
static |
Stat Table (STR) – bonus to hit.
Referenced by calc_bonuses().
|
static |
Stat Table (STR) – weight limit in deca-pounds.
Referenced by weight_limit(), and weight_remaining().
|
static |
Stat Table (WIS) – Saving throw.
Referenced by calc_bonuses().
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().
|
static |
Events triggered by the various flags.