Angband
Functions | Variables
player-attack.c File Reference

Attacks (both throwing and melee) by the player. More...

#include "angband.h"
#include "cave.h"
#include "cmds.h"
#include "game-event.h"
#include "game-input.h"
#include "init.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-msg.h"
#include "mon-timed.h"
#include "mon-util.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-identify.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-util.h"
#include "project.h"
#include "target.h"

Functions

int breakage_chance (const struct object *obj, bool hit_target)
 Returns percent chance of an object breaking after throwing or shooting.
static int chance_of_missile_hit (struct player *p, struct object *missile, struct object *launcher, int y, int x)
bool test_hit (int chance, int ac, int vis)
 Determine if the player "hits" a monster.
static int melee_damage (struct object *obj, const struct brand *b, const struct slay *s)
 Determine standard melee damage.
static int ranged_damage (struct object *missile, struct object *launcher, const struct brand *b, const struct slay *s, int mult)
 Determine standard ranged damage.
static int critical_shot (int weight, int plus, int dam, u32b *msg_type)
 Determine damage for critical hits from shooting.
static int critical_norm (int weight, int plus, int dam, u32b *msg_type)
 Determine damage for critical hits from melee.
static int player_damage_bonus (struct player_state *state)
 Apply the player damage bonuses.
static void blow_side_effects (struct player *p, struct monster *mon)
 Apply blow side effects.
static bool blow_after_effects (int y, int x, bool quake)
 Apply blow after effects.
int py_attack_hit_chance (const object_type *weapon)
 Return the player's chance to hit with a particular weapon.
static bool py_attack_real (int y, int x, bool *fear)
 Attack the monster at the given location with a single blow.
void py_attack (int y, int x)
 Attack the monster at the given location.
static void ranged_helper (struct object *obj, int dir, int range, int shots, ranged_attack attack)
 This is a helper function used by do_cmd_throw and do_cmd_fire.
static struct attack_result make_ranged_shot (struct object *ammo, int y, int x)
 Helper function used with ranged_helper by do_cmd_fire.
static struct attack_result make_ranged_throw (struct object *obj, int y, int x)
 Helper function used with ranged_helper by do_cmd_throw.
void do_cmd_fire (struct command *cmd)
 Fire an object from the quiver, pack or floor at a target.
void do_cmd_throw (struct command *cmd)
 Throw an object from the quiver, pack or floor.
void do_cmd_fire_at_nearest (void)
 Front-end command which fires at the nearest target with default ammo.

Variables

struct {
   u32b   msg
   const char *   text
melee_hit_types []
struct {
   u32b   msg
   const char *   text
ranged_hit_types []

Detailed Description

Attacks (both throwing and melee) by the player.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke

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

static bool blow_after_effects ( int  y,
int  x,
bool  quake 
)
static

Apply blow after effects.

References cave, effect_simple(), FALSE, square_monster(), and TRUE.

Referenced by py_attack_real().

static void blow_side_effects ( struct player p,
struct monster mon 
)
static

Apply blow side effects.

References player::confusing, FALSE, player::lev, mon_inc_timed(), MON_TMD_FLG_NOTIFY, msg, and randint0.

Referenced by py_attack_real().

int breakage_chance ( const struct object obj,
bool  hit_target 
)

Returns percent chance of an object breaking after throwing or shooting.

Artifacts will never break.

Beyond that, each item kind has a percent chance to break (0-100). When the object hits its target this chance is used.

When an object misses it also has a chance to break. This is determined by squaring the normaly breakage probability. So an item that breaks 100% of the time on hit will also break 100% of the time on a miss, whereas a 50% hit-breakage chance gives a 25% miss-breakage chance, and a 10% hit breakage chance gives a 1% miss-breakage chance.

References object::artifact, object_kind::base, object_base::break_perc, and object::kind.

Referenced by obj_known_misc_combat(), ranged_helper(), and test_breakage_chance().

static int chance_of_missile_hit ( struct player p,
struct object missile,
struct object launcher,
int  y,
int  x 
)
static
static int critical_norm ( int  weight,
int  plus,
int  dam,
u32b msg_type 
)
static

Determine damage for critical hits from melee.

Factor in weapon weight, total plusses, player level.

References player::lev, power, randint1, player::state, and player_state::to_h.

Referenced by make_ranged_throw(), and py_attack_real().

static int critical_shot ( int  weight,
int  plus,
int  dam,
u32b msg_type 
)
static

Determine damage for critical hits from shooting.

Factor in item weight, total plusses, and player level.

References player::lev, power, randint1, player::state, and player_state::to_h.

Referenced by make_ranged_shot().

void do_cmd_fire ( struct command cmd)
void do_cmd_fire_at_nearest ( void  )
void do_cmd_throw ( struct command cmd)
static struct attack_result make_ranged_shot ( struct object ammo,
int  y,
int  x 
)
staticread
static struct attack_result make_ranged_throw ( struct object obj,
int  y,
int  x 
)
staticread
static int melee_damage ( struct object obj,
const struct brand b,
const struct slay s 
)
static

Determine standard melee damage.

Factor in damage dice, to-dam and any brand or slay.

References damroll(), object::dd, object::ds, brand::multiplier, slay::multiplier, and object::to_d.

Referenced by py_attack_real().

static int player_damage_bonus ( struct player_state state)
static

Apply the player damage bonuses.

References player_state::to_d.

Referenced by py_attack_real().

void py_attack ( int  y,
int  x 
)

Attack the monster at the given location.

We get blows until energy drops below that required for another blow, or until the target monster dies. Each blow is handled by py_attack_real(). We don't allow @ to spend more than 100 energy in one go, to avoid slower monsters getting double moves.

References add_monster_message(), cave, disturb(), player::energy, player_upkeep::energy_use, FALSE, MDESC_DEFAULT, monster::mflag, mflag_has, monster_desc(), angband_constants::move_energy, player_state::num_blows, py_attack_real(), square_monster(), player::state, TRUE, player::upkeep, and z_info.

Referenced by do_cmd_alter_aux(), do_cmd_close(), do_cmd_disarm(), do_cmd_open(), do_cmd_tunnel(), and move_player().

int py_attack_hit_chance ( const object_type weapon)

Return the player's chance to hit with a particular weapon.

References BTH_PLUS_ADJ, SKILL_TO_HIT_MELEE, player_state::skills, player::state, and player_state::to_h.

Referenced by lore_append_toughness(), and py_attack_real().

static bool py_attack_real ( int  y,
int  x,
bool fear 
)
static
static int ranged_damage ( struct object missile,
struct object launcher,
const struct brand b,
const struct slay s,
int  mult 
)
static

Determine standard ranged damage.

Factor in damage dice, to-dam, multiplier and any brand or slay.

References damroll(), object::dd, object::ds, brand::multiplier, slay::multiplier, and object::to_d.

Referenced by make_ranged_shot(), and make_ranged_throw().

static void ranged_helper ( struct object obj,
int  dir,
int  range,
int  shots,
ranged_attack  attack 
)
static
bool test_hit ( int  chance,
int  ac,
int  vis 
)

Determine if the player "hits" a monster.

References randint0.

Referenced by check_hit(), make_ranged_shot(), make_ranged_throw(), py_attack_real(), and trap_check_hit().

Variable Documentation

struct { ... } melee_hit_types[]

Referenced by py_attack_real().

u32b msg

Referenced by activation_message(), apply_autoinscription(), become_aware(), blow_side_effects(), brand_object(), build_quest_stairs(), calc_mana(), calc_spells(), cheat_death(), check_devices(), check_for_player_interrupt(), chest_trap(), close_game(), cmd_get_string(), combine_pack(), compact_monsters(), context_menu_cave(), context_menu_player(), death_file(), death_randarts(), disconnect_stats(), display_feeling(), display_message(), do_cmd_activate(), do_cmd_aim_wand(), do_cmd_alter_aux(), do_cmd_birth_init(), do_cmd_buy(), do_cmd_cast(), do_cmd_change_name(), do_cmd_close(), do_cmd_close_aux(), do_cmd_close_test(), do_cmd_disarm(), do_cmd_disarm_aux(), do_cmd_disarm_chest(), do_cmd_disarm_test(), do_cmd_drop(), do_cmd_equip(), do_cmd_fire(), do_cmd_fire_at_nearest(), do_cmd_go_down(), do_cmd_go_up(), do_cmd_inven(), do_cmd_load_screen(), do_cmd_lock_door(), do_cmd_look(), do_cmd_messages(), do_cmd_note(), do_cmd_open(), do_cmd_open_test(), do_cmd_pref_file_hack(), do_cmd_refill(), do_cmd_rerate(), do_cmd_retrieve(), do_cmd_save_screen_html(), do_cmd_save_screen_text(), do_cmd_sell(), do_cmd_stash(), do_cmd_study_book(), do_cmd_throw(), do_cmd_tunnel(), do_cmd_tunnel_aux(), do_cmd_tunnel_test(), do_cmd_uninscribe(), do_cmd_use(), do_cmd_use_staff(), do_cmd_version(), do_cmd_wield(), do_cmd_wiz_bamf(), do_cmd_wiz_cure_all(), do_cmd_wiz_effect(), do_cmd_wiz_features(), do_cmd_wiz_jump(), do_cmd_wiz_learn(), do_cmd_wiz_play(), do_cmd_wiz_query(), do_cmd_wizard(), do_cmd_zap_rod(), do_ident_item(), do_mon_spell(), do_randart(), drop_near(), dump_pref_file(), dump_save(), effect_do(), effect_handler_AGGRAVATE(), effect_handler_ALTER_REALITY(), effect_handler_BIZARRE(), effect_handler_CONFUSING(), effect_handler_CREATE_STAIRS(), effect_handler_CRUNCH(), effect_handler_CURSE_ARMOR(), effect_handler_CURSE_WEAPON(), effect_handler_DARKEN_AREA(), effect_handler_DESTRUCTION(), effect_handler_DETECT_DOORS(), effect_handler_DETECT_EVIL(), effect_handler_DETECT_GOLD(), effect_handler_DETECT_INVISIBLE_MONSTERS(), effect_handler_DETECT_OBJECTS(), effect_handler_DETECT_STAIRS(), effect_handler_DETECT_TRAPS(), effect_handler_DETECT_VISIBLE_MONSTERS(), effect_handler_DISENCHANT(), effect_handler_DRAIN_MANA(), effect_handler_DRAIN_STAT(), effect_handler_EARTHQUAKE(), effect_handler_ENLIGHTENMENT(), effect_handler_GAIN_EXP(), effect_handler_GAIN_STAT(), effect_handler_HEAL_HP(), effect_handler_LIGHT_AREA(), effect_handler_LOSE_EXP(), effect_handler_MON_HEAL_HP(), effect_handler_PROBE(), effect_handler_RECALL(), effect_handler_RECHARGE(), effect_handler_REMOVE_CURSE(), effect_handler_RESTORE_EXP(), effect_handler_RESTORE_MANA(), effect_handler_RESTORE_STAT(), effect_handler_RUNE(), effect_handler_SENSE_OBJECTS(), effect_handler_SUMMON(), effect_handler_TELEPORT(), effect_handler_TELEPORT_LEVEL(), effect_handler_THRUST_AWAY(), 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_GAS_BLIND(), effect_handler_TRAP_GAS_CONFUSE(), effect_handler_TRAP_GAS_POISON(), effect_handler_TRAP_GAS_SLEEP(), effect_handler_TRAP_PIT(), effect_handler_TRAP_PIT_POISON(), effect_handler_TRAP_PIT_SPIKES(), effect_handler_TRAP_RUNE_TELEPORT(), effect_handler_TRAP_SPOT_ACID(), effect_handler_TRAP_SPOT_FIRE(), effect_handler_WONDER(), enchant_curse(), enchant_spell(), enter_score(), equip_notice_element(), eval_monster_power(), flag_message(), floor_item_charges(), floor_object_for_use(), gear_object_for_use(), get_debug_command(), get_file_backup(), get_file_text(), grab_name(), highscore_write(), hit_trap(), init_graphics_modes(), inven_carry(), inven_drop(), inven_item_charges(), lookup_kind(), lore_save(), make_attack_normal(), make_attack_spell(), melee_effect_elemental(), melee_effect_experience(), 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_timed(), minus_ac(), mon_pop(), object_notice_brands(), object_notice_on_wield(), object_notice_slays(), object_value_real(), pack_overflow(), pick_and_place_distant_monster(), pit_stats(), place_new_monster_one(), player_can_cast(), player_can_fire(), player_can_read(), player_can_refuel(), player_can_study(), player_confuse_dir(), player_inc_timed(), player_restore_mana(), player_set_food(), player_update_light(), print_error(), process_monster_can_move(), process_monster_glyph(), process_monster_grab_objects(), process_monster_try_push(), process_pref_file_layered(), process_world(), project_feature_handler_KILL_DOOR(), project_feature_handler_KILL_TRAP(), project_feature_handler_KILL_WALL(), project_monster_resist_other(), project_o(), project_object_handler_KILL_DOOR(), project_object_handler_KILL_TRAP(), project_p(), project_player_drain_stats(), project_player_handler_CHAOS(), project_player_handler_DARK(), project_player_handler_DISEN(), project_player_handler_GRAVITY(), project_player_handler_ICE(), project_player_handler_LIGHT(), project_player_handler_NETHER(), project_player_handler_NEXUS(), project_player_handler_POIS(), project_player_handler_TIME(), project_player_swap_stats(), prt_welcome(), py_attack_real(), quest_check(), ranged_helper(), recharged_notice(), refill_lamp(), remove_old_dump(), remove_trap_aux(), search(), see_floor_items(), show_file(), spell_cast(), spell_learn(), spoil_artifact(), spoil_mon_desc(), spoil_mon_info(), spoil_obj_desc(), square_reveal_trap(), stats_collect(), store_purchase(), store_sell(), store_update(), target_set_closest(), textui_book_browse(), textui_cmd_debug(), textui_enter_store(), textui_get_item(), textui_process_click(), textui_target(), update_bonuses(), update_messages_subwindow(), use_aux(), visuals_reset(), wiz_cheat_death(), wiz_statistics(), wiz_test_kind(), and wiz_tweak_curse().

struct { ... } ranged_hit_types[]

Referenced by ranged_helper().

const char* text