Angband
Functions | Variables
player-util.c File Reference

Player utility functions. More...

#include "angband.h"
#include "cave.h"
#include "cmd-core.h"
#include "game-input.h"
#include "game-world.h"
#include "init.h"
#include "obj-gear.h"
#include "obj-identify.h"
#include "obj-tval.h"
#include "obj-pile.h"
#include "obj-util.h"
#include "player-history.h"
#include "player-spell.h"
#include "player-timed.h"
#include "player-util.h"
#include "score.h"
#include "store.h"
#include "target.h"

Functions

void dungeon_change_level (int dlev)
 Change dungeon level - e.g.
void take_hit (struct player *p, int dam, const char *kb_str)
 Decreases players hit points and sets death flag if necessary.
void death_knowledge (void)
 Win or not, know inventory, home items and history upon death, enter score.
s16b modify_stat_value (int value, int amount)
void player_regen_hp (void)
 Regenerate hit points.
void player_regen_mana (void)
 Regenerate mana points.
void player_update_light (void)
 Update the player's light fuel.
bool player_can_cast (struct player *p, bool show_msg)
 Return TRUE if the player can cast a spell.
bool player_can_study (struct player *p, bool show_msg)
 Return TRUE if the player can study a spell.
bool player_can_read (struct player *p, bool show_msg)
 Return TRUE if the player can read scrolls or books.
bool player_can_fire (struct player *p, bool show_msg)
 Return TRUE if the player can fire something with a launcher.
bool player_can_refuel (struct player *p, bool show_msg)
 Return TRUE if the player can refuel their light source.
bool player_can_cast_prereq (void)
 Prerequiste function for command.
bool player_can_study_prereq (void)
 Prerequiste function for command.
bool player_can_read_prereq (void)
 Prerequiste function for command.
bool player_can_fire_prereq (void)
 Prerequiste function for command.
bool player_can_refuel_prereq (void)
 Prerequiste function for command.
bool player_book_has_unlearned_spells (struct player *p)
 Return TRUE if the player has a book in their inventory that has unlearned spells.
bool player_confuse_dir (struct player *p, int *dp, bool too)
 Apply confusion, if needed, to a direction.
bool player_resting_is_special (s16b count)
 Return TRUE if the provided count is one of the conditional REST_ flags.
bool player_is_resting (struct player *p)
 Return TRUE if the player is resting.
s16b player_resting_count (struct player *p)
 Return the remaining number of resting turns.
void player_resting_set_count (struct player *p, s16b count)
 Set the number of resting turns.
void player_resting_cancel (struct player *p)
 Cancel current rest.
bool player_resting_can_regenerate (struct player *p)
 Return TRUE if the player should get a regeneration bonus for the current rest.
void player_resting_step_turn (struct player *p)
 Perform one turn of resting.
void player_resting_complete_special (struct player *p)
 Handle the conditions for conditional resting (resting with the REST_ constants).
bool player_of_has (struct player *p, int flag)
 Check if the player state has the given OF_ flag.
bool player_resists (struct player *p, int element)
 Check if the player resists (or better) an element.
bool player_is_immune (struct player *p, int element)
 Check if the player resists (or better) an element.
int coords_to_dir (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.
void disturb (struct player *p, int stop_search)

Variables

int resting
static int player_turns_rested = 0
 In order to prevent the regeneration bonus from the first few turns, we have to store the original number of turns the user entered.
static bool player_rest_disturb = FALSE

Detailed Description

Player utility functions.

Copyright (c) 2011 The Angband Developers. See COPYING.

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 coords_to_dir ( int  y,
int  x 
)
void death_knowledge ( void  )
void disturb ( struct player p,
int  stop_search 
)
void dungeon_change_level ( int  dlev)
s16b modify_stat_value ( int  value,
int  amount 
)

References i.

Referenced by calc_bonuses(), and get_stats().

bool player_book_has_unlearned_spells ( struct player p)

Return TRUE if the player has a book in their inventory that has unlearned spells.

Parameters
pis the player

References FALSE, i, player_upkeep::inven, player_upkeep::new_spells, class_book::num_spells, obj_can_browse(), object_to_book(), angband_constants::pack_size, class_spell::sidx, spell_okay_to_study(), class_book::spells, TRUE, player::upkeep, 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.

Parameters
pis the player
show_msgshould be set to TRUE if a failure message should be displayed.

References player::class, FALSE, magic_realm::index, player_class::magic, msg, no_light(), class_magic::spell_realm, player::timed, and TRUE.

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(), and TRUE.

bool player_can_fire ( struct player p,
bool  show_msg 
)

Return TRUE if the player can fire something with a launcher.

Parameters
pis the player
show_msgshould be set to TRUE if a failure message should be displayed.

References player_state::ammo_tval, equipped_item_by_slot_name(), FALSE, msg, player::state, and TRUE.

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(), and TRUE.

bool player_can_read ( struct player p,
bool  show_msg 
)

Return TRUE if the player can read scrolls or books.

Parameters
pis the player
show_msgshould be set to TRUE if a failure message should be displayed.

References FALSE, msg, no_light(), player::timed, and TRUE.

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(), and TRUE.

bool player_can_refuel ( struct player p,
bool  show_msg 
)

Return TRUE if the player can refuel their light source.

Parameters
pis the player
show_msgshould be set to TRUE if a failure message should be displayed.

References equipped_item_by_slot_name(), FALSE, object::flags, msg, of_has, and TRUE.

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(), and TRUE.

bool player_can_study ( struct player p,
bool  show_msg 
)

Return TRUE if the player can study a spell.

Parameters
pis the player
show_msgshould be set to TRUE if a failure message should be displayed.

References player::class, FALSE, player_class::magic, msg, player_upkeep::new_spells, player_can_cast(), magic_realm::spell_noun, class_magic::spell_realm, TRUE, 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(), and TRUE.

bool player_confuse_dir ( struct player p,
int dp,
bool  too 
)

Apply confusion, if needed, to a direction.

Display a message and return TRUE if direction changes.

References ddd, FALSE, msg, randint0, player::timed, and TRUE.

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

bool player_is_immune ( struct player p,
int  element 
)
bool player_is_resting ( struct player p)

Return TRUE if the player is resting.

References player_resting_is_special(), and resting.

Referenced by check_for_player_interrupt(), disturb(), do_cmd_rest(), and prt_state().

bool player_of_has ( struct player p,
int  flag 
)
void player_place ( struct chunk c,
struct player p,
int  y,
int  x 
)
void player_regen_hp ( void  )
void player_regen_mana ( void  )
bool player_resists ( struct player p,
int  element 
)
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, and resting.

Referenced by player_regen_hp(), and player_regen_mana().

void player_resting_cancel ( struct player p)

Cancel current rest.

References player_rest_disturb, player_resting_set_count(), player_turns_rested, and TRUE.

Referenced by disturb(), and do_cmd_rest().

void player_resting_complete_special ( struct player p)

Handle the conditions for conditional resting (resting with the REST_ constants).

References player::chp, player::csp, disturb(), player::mhp, player::msp, player_resting_is_special(), REST_ALL_POINTS, REST_COMPLETE, REST_SOME_POINTS, resting, player::timed, and player::word_recall.

Referenced by process_player().

s16b player_resting_count ( struct player p)

Return the remaining number of resting turns.

References resting.

Referenced by do_cmd_rest(), and prt_state().

bool player_resting_is_special ( s16b  count)

Return TRUE if the provided count is one of the conditional REST_ flags.

References FALSE, REST_ALL_POINTS, REST_COMPLETE, REST_SOME_POINTS, and TRUE.

Referenced by do_cmd_rest(), player_is_resting(), player_resting_can_regenerate(), player_resting_complete_special(), and player_resting_set_count().

void player_resting_set_count ( struct player p,
s16b  count 
)

Set the number of resting turns.

Parameters
countis the number of turns to rest or one of the REST_ constants.

References FALSE, player_rest_disturb, player_resting_is_special(), and resting.

Referenced by do_cmd_rest(), and player_resting_cancel().

void player_resting_step_turn ( struct player p)

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, resting, player::resting_turn, player::upkeep, and z_info.

Referenced by do_cmd_rest().

void player_update_light ( void  )
void take_hit ( struct player p,
int  dam,
const char *  kb_str 
)

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(), FALSE, get_check(), player_other::hitpoint_warn, player::is_dead, player::mhp, msgt(), my_strcpy(), op_ptr, OPT, PR_HP, player_upkeep::redraw, player::timed, player::total_winner, TRUE, 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(), effect_handler_TRAP_DART_LOSE_CON(), effect_handler_TRAP_DART_LOSE_DEX(), effect_handler_TRAP_DART_LOSE_STR(), effect_handler_TRAP_DART_SLOW(), effect_handler_TRAP_DOOR(), effect_handler_TRAP_PIT(), effect_handler_TRAP_PIT_POISON(), effect_handler_TRAP_PIT_SPIKES(), effect_handler_TRAP_SPOT_ACID(), effect_handler_TRAP_SPOT_FIRE(), 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(), process_world(), and project_p().

Variable Documentation

bool player_rest_disturb = FALSE
static
int player_turns_rested = 0
static

In order to prevent the regeneration bonus from the first few turns, we have to store the original number of turns the user entered.

Otherwise, the first few turns will have the bonus and the last few will not.

Referenced by player_resting_can_regenerate(), player_resting_cancel(), and player_resting_step_turn().

int resting