Angband
|
Player utility functions. More...
#include "player.h"
Go to the source code of this file.
Macros | |
#define | PY_REGEN_NORMAL 197 /* Regen factor*2^16 when full */ |
#define | PY_REGEN_WEAK 98 /* Regen factor*2^16 when weak */ |
#define | PY_REGEN_FAINT 33 /* Regen factor*2^16 when fainting */ |
#define | PY_REGEN_HPBASE 1442 /* Min amount hp regen*2^16 */ |
#define | PY_REGEN_MNBASE 524 /* Min amount mana regen*2^16 */ |
#define | REST_REQUIRED_FOR_REGEN 5 |
Minimum number of turns required for regeneration to kick in during resting. More... | |
Enumerations | |
enum | { REST_COMPLETE = -2, REST_ALL_POINTS = -1, REST_SOME_POINTS = -3 } |
Special values for the number of turns to rest, these need to be negative numbers, as postive numbers are taken to be a turncount, and zero means "not resting". More... | |
Functions | |
int | dungeon_get_next_level (int dlev, int added) |
Increment to the next or decrement to the preceeding level accounting for the stair skip value in constants Keep in mind to check all intermediate level for unskippable quests. More... | |
void | dungeon_change_level (struct player *p, int dlev) |
Change dungeon level - e.g. More... | |
void | take_hit (struct player *p, int dam, const char *kb_str) |
Decreases players hit points and sets death flag if necessary. More... | |
void | death_knowledge (struct player *p) |
Win or not, know inventory, home items and history upon death, enter score. More... | |
s16b | modify_stat_value (int value, int amount) |
Modify a stat value by a "modifier", return new value. More... | |
void | player_regen_hp (struct player *p) |
Regenerate hit points. More... | |
void | player_regen_mana (struct player *p) |
Regenerate mana points. More... | |
void | player_update_light (struct player *p) |
Update the player's light fuel. More... | |
int | player_check_terrain_damage (struct player *p, int y, int x) |
See how much damage the player will take from damaging terrain. More... | |
void | player_take_terrain_damage (struct player *p, int y, int x) |
Terrain damages the player. More... | |
bool | player_can_cast (struct player *p, bool show_msg) |
Return true if the player can cast a spell. More... | |
bool | player_can_study (struct player *p, bool show_msg) |
Return true if the player can study a spell. More... | |
bool | player_can_read (struct player *p, bool show_msg) |
Return true if the player can read scrolls or books. More... | |
bool | player_can_fire (struct player *p, bool show_msg) |
Return true if the player can fire something with a launcher. More... | |
bool | player_can_refuel (struct player *p, bool show_msg) |
Return true if the player can refuel their light source. More... | |
bool | player_can_cast_prereq (void) |
Prerequiste function for command. More... | |
bool | player_can_study_prereq (void) |
Prerequiste function for command. More... | |
bool | player_can_read_prereq (void) |
Prerequiste function for command. More... | |
bool | player_can_fire_prereq (void) |
Prerequiste function for command. More... | |
bool | player_can_refuel_prereq (void) |
Prerequiste function for command. More... | |
bool | player_book_has_unlearned_spells (struct player *p) |
Return true if the player has access to a book that has unlearned spells. More... | |
bool | player_confuse_dir (struct player *p, int *dir, bool too) |
Apply confusion, if needed, to a direction. More... | |
bool | player_resting_is_special (s16b count) |
Return true if the provided count is one of the conditional REST_ flags. More... | |
bool | player_is_resting (struct player *p) |
Return true if the player is resting. More... | |
s16b | player_resting_count (struct player *p) |
Return the remaining number of resting turns. More... | |
void | player_resting_set_count (struct player *p, s16b count) |
Set the number of resting turns. More... | |
void | player_resting_cancel (struct player *p, bool disturb) |
Cancel current rest. More... | |
bool | player_resting_can_regenerate (struct player *p) |
Return true if the player should get a regeneration bonus for the current rest. More... | |
void | player_resting_step_turn (struct player *p) |
Perform one turn of resting. More... | |
void | player_resting_complete_special (struct player *p) |
Handle the conditions for conditional resting (resting with the REST_ constants). More... | |
int | player_get_resting_repeat_count (struct player *p) |
Get the number of resting turns to repeat. More... | |
void | player_set_resting_repeat_count (struct player *p, s16b count) |
Set the number of resting turns to repeat. More... | |
bool | player_of_has (struct player *p, int flag) |
Check if the player state has the given OF_ flag. More... | |
bool | player_resists (struct player *p, int element) |
Check if the player resists (or better) an element. More... | |
bool | player_is_immune (struct player *p, int element) |
Check if the player resists (or better) an element. More... | |
int | coords_to_dir (struct player *p, int y, int x) |
void | player_place (struct chunk *c, struct player *p, int y, int x) |
Places the player at the given coordinates in the cave. More... | |
void | disturb (struct player *p, int stop_search) |
void | search (struct player *p) |
Search for traps or secret doors. More... | |
Player utility functions.
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.
#define PY_REGEN_FAINT 33 /* Regen factor*2^16 when fainting */ |
Referenced by player_regen_hp().
#define PY_REGEN_HPBASE 1442 /* Min amount hp regen*2^16 */ |
Referenced by player_regen_hp().
#define PY_REGEN_MNBASE 524 /* Min amount mana regen*2^16 */ |
Referenced by player_regen_mana().
#define PY_REGEN_NORMAL 197 /* Regen factor*2^16 when full */ |
Referenced by player_regen_hp(), and player_regen_mana().
#define PY_REGEN_WEAK 98 /* Regen factor*2^16 when weak */ |
Referenced by player_regen_hp().
#define REST_REQUIRED_FOR_REGEN 5 |
Minimum number of turns required for regeneration to kick in during resting.
Referenced by player_resting_can_regenerate().
anonymous enum |
References motion_dir(), player::px, and player::py.
Referenced by context_menu_cave(), do_cmd_close(), do_cmd_disarm(), do_cmd_open(), and textui_process_click().
Win or not, know inventory, home items and history upon death, enter score.
References object::activation, player::au, player::depth, player::died_from, object::effect, enter_score(), player::exp, player::gear, handle_stuff(), history_unmask_unknown(), object::known, player::lev, player::max_exp, player::max_lev, my_strcpy(), object::next, object_flavor_aware(), player_learn_everything(), PU_BONUS, store::stock, STORE_HOME, stores, object::time, player::total_winner, player_upkeep::update, player::upkeep, and void().
Referenced by close_game().
References cmd_cancel_repeat(), EVENT_INPUT_FLUSH, EVENT_MAP, EVENT_PLAYERMOVED, event_signal(), event_signal_point(), player_is_resting(), player_resting_cancel(), PR_STATE, PU_TORCH, player_upkeep::redraw, player_upkeep::running, player_upkeep::update, and player::upkeep.
Referenced by check_for_player_interrupt(), display_feeling(), do_autopickup(), do_cmd_alter_aux(), do_cmd_close(), do_cmd_disarm(), do_cmd_hold(), do_cmd_open(), do_cmd_tunnel(), do_cmd_walk_test(), do_mon_spell(), effect_handler_DETECT_TRAPS(), hit_trap(), make_attack_normal(), make_attack_spell(), monster_turn(), monster_turn_can_move(), move_player(), on_new_level(), pack_overflow(), player_resting_cancel(), player_resting_complete_special(), player_set_food(), player_set_timed(), player_update_light(), process_world(), project_p(), py_attack(), recharged_notice(), run_step(), save_game(), search(), set_cut(), set_stun(), take_hit(), and update_mon().
Change dungeon level - e.g.
by going up stairs or with WoR.
References player_upkeep::autosave, daycount, player::depth, player_upkeep::generate_level, store_update(), and player::upkeep.
Referenced by do_cmd_go_down(), do_cmd_go_up(), do_cmd_wiz_jump(), effect_handler_ALTER_REALITY(), effect_handler_TELEPORT_LEVEL(), hit_trap(), process_world(), and wiz_cheat_death().
Increment to the next or decrement to the preceeding level accounting for the stair skip value in constants Keep in mind to check all intermediate level for unskippable quests.
References i, is_quest(), angband_constants::max_depth, angband_constants::stair_skip, and z_info.
Referenced by do_cmd_go_down(), do_cmd_go_up(), effect_handler_DEEP_DESCENT(), effect_handler_RECALL(), effect_handler_TELEPORT_LEVEL(), hit_trap(), and process_world().
Modify a stat value by a "modifier", return new value.
Stats go up: 3,4,...,17,18,18/10,18/20,...,18/220 Or even: 18/13, 18/23, 18/33, ..., 18/220
Stats go down: 18/220, 18/210,..., 18/10, 18, 17, ..., 3 Or even: 18/13, 18/03, 18, 17, ..., 3
References i.
Referenced by calc_bonuses(), and get_stats().
bool player_book_has_unlearned_spells | ( | struct player * | p | ) |
Return true if the player has access to a book that has unlearned spells.
p | is the player |
References angband_constants::floor_size, i, mem_free(), mem_zalloc(), player_upkeep::new_spells, class_book::num_spells, obj_can_study(), object_to_book(), angband_constants::pack_size, scan_items(), class_spell::sidx, spell_okay_to_study(), class_book::spells, player::upkeep, USE_FLOOR, USE_INVEN, and z_info.
Referenced by prt_study().
bool player_can_cast | ( | struct player * | p, |
bool | show_msg | ||
) |
Return true if the player can cast a spell.
p | is the player |
show_msg | should be set to true if a failure message should be displayed. |
References player::class, player_class::magic, msg, no_light(), class_magic::spell_realm, and player::timed.
Referenced by context_menu_cave(), context_menu_object(), context_menu_player(), do_cmd_cast(), player_can_cast_prereq(), and player_can_study().
bool player_can_cast_prereq | ( | void | ) |
Prerequiste function for command.
See struct cmd_info in cmd-process.c.
References player_can_cast().
bool player_can_fire | ( | struct player * | p, |
bool | show_msg | ||
) |
Return true if the player can fire something with a launcher.
p | is the player |
show_msg | should be set to true if a failure message should be displayed. |
References player_state::ammo_tval, equipped_item_by_slot_name(), msg, and player::state.
Referenced by context_menu_cave(), and player_can_fire_prereq().
bool player_can_fire_prereq | ( | void | ) |
Prerequiste function for command.
See struct cmd_info in cmd-process.c.
References player_can_fire().
bool player_can_read | ( | struct player * | p, |
bool | show_msg | ||
) |
Return true if the player can read scrolls or books.
p | is the player |
show_msg | should be set to true if a failure message should be displayed. |
References msg, no_light(), and player::timed.
Referenced by context_menu_object(), do_cmd_read_scroll(), and player_can_read_prereq().
bool player_can_read_prereq | ( | void | ) |
Prerequiste function for command.
See struct cmd_info in cmd-process.c.
References player_can_read().
bool player_can_refuel | ( | struct player * | p, |
bool | show_msg | ||
) |
Return true if the player can refuel their light source.
p | is the player |
show_msg | should be set to true if a failure message should be displayed. |
References equipped_item_by_slot_name(), object::flags, msg, and of_has.
Referenced by player_can_refuel_prereq().
bool player_can_refuel_prereq | ( | void | ) |
Prerequiste function for command.
See struct cmd_info in cmd-process.c.
References player_can_refuel().
bool player_can_study | ( | struct player * | p, |
bool | show_msg | ||
) |
Return true if the player can study a spell.
p | is the player |
show_msg | should be set to true if a failure message should be displayed. |
References player::class, player_class::magic, msg, player_upkeep::new_spells, player_can_cast(), magic_realm::spell_noun, class_magic::spell_realm, and player::upkeep.
Referenced by context_menu_object(), do_cmd_study_book(), do_cmd_study_spell(), and player_can_study_prereq().
bool player_can_study_prereq | ( | void | ) |
Prerequiste function for command.
See struct cmd_info in cmd-process.c.
References player_can_study().
See how much damage the player will take from damaging terrain.
References adjust_dam(), cave, player_state::el_info, player_of_has(), randint1, RANDOMISE, element_info::res_level, square_isfiery(), and player::state.
Referenced by move_player(), and player_take_terrain_damage().
Apply confusion, if needed, to a direction.
Display a message and return true if direction changes.
References ddd, msg, randint0, and player::timed.
Referenced by do_cmd_alter_aux(), do_cmd_cast(), do_cmd_close(), do_cmd_disarm(), do_cmd_fire(), do_cmd_jump(), do_cmd_open(), do_cmd_run(), do_cmd_throw(), do_cmd_tunnel(), do_cmd_walk(), and use_aux().
Get the number of resting turns to repeat.
p | The current player. |
References player_resting_repeat_count.
Referenced by do_cmd_rest().
Check if the player resists (or better) an element.
References player_state::el_info, element_info::res_level, and player::state.
Referenced by player_set_timed(), project_player_handler_ACID(), project_player_handler_COLD(), project_player_handler_ELEC(), project_player_handler_FIRE(), and project_player_handler_ICE().
bool player_is_resting | ( | struct player * | p | ) |
Return true if the player is resting.
References player_resting_is_special(), player_upkeep::resting, and player::upkeep.
Referenced by check_for_player_interrupt(), disturb(), do_cmd_rest(), and prt_state().
Check if the player state has the given OF_ flag.
References player_state::flags, of_has, and player::state.
Referenced by do_cmd_walk_test(), effect_handler_DRAIN_STAT(), effect_handler_LOSE_EXP(), effect_handler_TELEPORT(), hit_trap(), melee_effect_experience(), monster_reduce_sleep(), player_check_terrain_damage(), player_inc_check(), player_regen_hp(), player_regen_mana(), player_set_timed(), process_world(), project_player_handler_CHAOS(), project_player_handler_GRAVITY(), project_player_handler_NETHER(), project_player_handler_PLASMA(), project_player_handler_SOUND(), py_attack_real(), spell_chance(), update_mon(), and update_smart_learn().
Places the player at the given coordinates in the cave.
References player_upkeep::create_down_stair, player_upkeep::create_up_stair, square::mon, player::px, player::py, chunk::squares, and player::upkeep.
Referenced by new_player_spot(), rd_dungeon(), town_gen(), and town_gen_layout().
Regenerate hit points.
References player::chp, player::chp_frac, equip_learn_flag(), player::food, player::mhp, player_of_has(), player_resting_can_regenerate(), PR_HP, PY_FOOD_FAINT, PY_FOOD_STARVE, PY_FOOD_WEAK, PY_REGEN_FAINT, PY_REGEN_HPBASE, PY_REGEN_NORMAL, PY_REGEN_WEAK, player_upkeep::redraw, player::timed, and player::upkeep.
Referenced by process_world().
Regenerate mana points.
References player::csp, player::csp_frac, equip_learn_flag(), player::msp, player_of_has(), player_resting_can_regenerate(), PR_MANA, PY_REGEN_MNBASE, PY_REGEN_NORMAL, player_upkeep::redraw, and player::upkeep.
Referenced by process_world().
Check if the player resists (or better) an element.
References player_state::el_info, element_info::res_level, and player::state.
Referenced by effect_handler_DARKEN_AREA(), effect_handler_DESTRUCTION(), effect_handler_TELEPORT_LEVEL(), melee_effect_handler_DISENCHANT(), project_player_handler_CHAOS(), project_player_handler_DARK(), project_player_handler_DARK_WEAK(), project_player_handler_DISEN(), project_player_handler_ICE(), project_player_handler_LIGHT(), project_player_handler_NETHER(), project_player_handler_NEXUS(), project_player_handler_SHARD(), and project_player_handler_SOUND().
bool player_resting_can_regenerate | ( | struct player * | p | ) |
Return true if the player should get a regeneration bonus for the current rest.
References player_resting_is_special(), player_turns_rested, REST_REQUIRED_FOR_REGEN, player_upkeep::resting, and player::upkeep.
Referenced by player_regen_hp(), and player_regen_mana().
Cancel current rest.
References disturb(), player_rest_disturb, player_resting_set_count(), and player_turns_rested.
Referenced by disturb(), and do_cmd_rest().
Handle the conditions for conditional resting (resting with the REST_ constants).
References player::chp, player::csp, player::deep_descent, disturb(), player::mhp, player::msp, player_resting_is_special(), REST_ALL_POINTS, REST_COMPLETE, REST_SOME_POINTS, player_upkeep::resting, player::timed, player::upkeep, and player::word_recall.
Referenced by process_player().
Return the remaining number of resting turns.
References player_upkeep::resting, and player::upkeep.
Referenced by do_cmd_rest(), prt_state(), redraw_stuff(), and update_minimap_subwindow().
bool player_resting_is_special | ( | s16b | count | ) |
Return true if the provided count is one of the conditional REST_ flags.
References REST_ALL_POINTS, REST_COMPLETE, and REST_SOME_POINTS.
Referenced by do_cmd_rest(), player_is_resting(), player_resting_can_regenerate(), player_resting_complete_special(), and player_resting_set_count().
Set the number of resting turns.
count | is the number of turns to rest or one of the REST_ constants. |
References player_rest_disturb, player_resting_is_special(), player_upkeep::resting, and player::upkeep.
Referenced by do_cmd_rest(), and player_resting_cancel().
Perform one turn of resting.
This only handles the bookkeeping of resting itself, and does not calculate any possible other effects of resting (see process_world() for regeneration).
References player_upkeep::energy_use, angband_constants::move_energy, player_turns_rested, PR_STATE, player_upkeep::redraw, player_upkeep::resting, player::resting_turn, player::upkeep, and z_info.
Referenced by do_cmd_rest().
Set the number of resting turns to repeat.
count | is the number of turns requested for rest most recently. |
References player_resting_repeat_count.
Referenced by do_cmd_rest().
Terrain damages the player.
References cave, inven_damage(), msg, player_check_terrain_damage(), square_feat(), square_isfiery(), and take_hit().
Referenced by process_player_cleanup().
Update the player's light fuel.
References player::depth, disturb(), equipped_item_by_slot_name(), object::flags, gear_object_for_use(), is_daytime(), object::known, msg, object_delete(), of_has, PR_EQUIP, PU_TORCH, player_upkeep::redraw, player::timed, object::timeout, tval_is_light(), player_upkeep::update, and player::upkeep.
Referenced by process_world().
Search for traps or secret doors.
References cave, disturb(), is_trapped_chest(), object::known, msg, object::next, no_light(), place_closed_door(), object::pval, player::px, player::py, square_issecretdoor(), square_object(), and player::timed.
Referenced by do_cmd_hold(), message_sound_define(), and move_player().
Decreases players hit points and sets death flag if necessary.
Hack – this function allows the user to save (or quit) the game when he dies, since the "You die." message is shown before setting the player to "dead".
References bell(), player::chp, player::died_from, disturb(), EVENT_CHEAT_DEATH, EVENT_MESSAGE_FLUSH, event_signal(), get_check(), player_options::hitpoint_warn, player::is_dead, player::mhp, msgt(), my_strcpy(), OPT, player::opts, PR_HP, player_upkeep::redraw, player::timed, player::total_winner, player::upkeep, and player::wizard.
Referenced by chest_trap(), effect_handler_BANISH(), effect_handler_DAMAGE(), effect_handler_DRAIN_STAT(), effect_handler_EARTHQUAKE(), effect_handler_MASS_BANISH(), melee_effect_elemental(), melee_effect_experience(), melee_effect_handler_DISENCHANT(), melee_effect_handler_DRAIN_CHARGES(), melee_effect_handler_EAT_FOOD(), melee_effect_handler_EAT_GOLD(), melee_effect_handler_EAT_ITEM(), melee_effect_handler_EAT_LIGHT(), melee_effect_handler_HALLU(), melee_effect_handler_HURT(), melee_effect_handler_LOSE_ALL(), melee_effect_handler_SHATTER(), melee_effect_stat(), melee_effect_timed(), player_take_terrain_damage(), process_world(), project_p(), and uncurse_object().