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 "effects.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-predicate.h"
#include "mon-timed.h"
#include "mon-util.h"
#include "monster.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-knowledge.h"
#include "obj-pile.h"
#include "obj-slays.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-calcs.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. More...
 
static int chance_of_missile_hit (const struct player *p, const struct object *missile, const struct object *launcher, int y, int x)
 
bool test_hit (int chance, int ac, int vis)
 Determine if the player "hits" a monster. More...
 
static int melee_damage (struct object *obj, int b, int s)
 Determine standard melee damage. More...
 
static int ranged_damage (struct object *missile, struct object *launcher, int b, int s, int mult)
 Determine standard ranged damage. More...
 
static bool is_debuffed (const struct monster *monster)
 Check if a monster is debuffed in such a way as to make a critical hit more likely. More...
 
static int critical_shot (const struct player *p, const struct monster *monster, int weight, int plus, int dam, u32b *msg_type)
 Determine damage for critical hits from shooting. More...
 
static int critical_norm (const struct player *p, const struct monster *monster, int weight, int plus, int dam, u32b *msg_type)
 Determine damage for critical hits from melee. More...
 
static int player_damage_bonus (struct player_state *state)
 Apply the player damage bonuses. More...
 
static void blow_side_effects (struct player *p, struct monster *mon)
 Apply blow side effects. More...
 
static bool blow_after_effects (int y, int x, bool quake)
 Apply blow after effects. More...
 
int py_attack_hit_chance (const struct player *p, const struct object *weapon)
 Return the player's chance to hit with a particular weapon. More...
 
static bool py_attack_real (struct player *p, int y, int x, bool *fear)
 Attack the monster at the given location with a single blow. More...
 
void py_attack (struct player *p, int y, int x)
 Attack the monster at the given location. More...
 
static void ranged_helper (struct player *p, struct object *obj, int dir, int range, int shots, ranged_attack attack, const struct hit_types *hit_types, int num_types)
 This is a helper function used by do_cmd_throw and do_cmd_fire. More...
 
static struct attack_result make_ranged_shot (struct player *p, struct object *ammo, int y, int x)
 Helper function used with ranged_helper by do_cmd_fire. More...
 
static struct attack_result make_ranged_throw (struct player *p, struct object *obj, int y, int x)
 Helper function used with ranged_helper by do_cmd_throw. More...
 
void do_cmd_fire (struct command *cmd)
 Fire an object from the quiver, pack or floor at a target. More...
 
void do_cmd_throw (struct command *cmd)
 Throw an object from the quiver, pack or floor. More...
 
void do_cmd_fire_at_nearest (void)
 Front-end command which fires at the nearest target with default ammo. More...
 

Variables

static const struct hit_types melee_hit_types []
 
static const struct hit_types 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(), NULL, source_player(), and square_monster().

Referenced by py_attack_real().

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

Apply blow side effects.

References player::confusing, 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 ( const struct player p,
const struct object missile,
const struct object launcher,
int  y,
int  x 
)
static
static int critical_norm ( const struct player p,
const struct monster monster,
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 DEBUFF_CRITICAL_HIT, is_debuffed(), player::lev, randint1, player::state, and player_state::to_h.

Referenced by make_ranged_throw(), and py_attack_real().

static int critical_shot ( const struct player p,
const struct monster monster,
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 DEBUFF_CRITICAL_HIT, is_debuffed(), player::lev, 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 bool is_debuffed ( const struct monster monster)
static

Check if a monster is debuffed in such a way as to make a critical hit more likely.

References monster::m_timed.

Referenced by critical_norm(), and critical_shot().

static struct attack_result make_ranged_shot ( struct player p,
struct object ammo,
int  y,
int  x 
)
static
static struct attack_result make_ranged_throw ( struct player p,
struct object obj,
int  y,
int  x 
)
static
static int melee_damage ( struct object obj,
int  b,
int  s 
)
static

Determine standard melee damage.

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

References damroll(), object::dd, object::ds, slay::multiplier, slays, 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 ( struct player p,
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, monster_is_visible(), angband_constants::move_energy, player_state::num_blows, py_attack_real(), square_monster(), player::state, 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 struct player p,
const struct object 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, player_state::to_h, and object::to_h.

Referenced by lore_append_toughness(), and py_attack_real().

static bool py_attack_real ( struct player p,
int  y,
int  x,
bool *  fear 
)
static
static int ranged_damage ( struct object missile,
struct object launcher,
int  b,
int  s,
int  mult 
)
static

Determine standard ranged damage.

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

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

Referenced by make_ranged_shot(), and make_ranged_throw().

static void ranged_helper ( struct player p,
struct object obj,
int  dir,
int  range,
int  shots,
ranged_attack  attack,
const struct hit_types hit_types,
int  num_types 
)
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

const struct hit_types melee_hit_types[]
static
Initial value:
= {
{ MSG_MISS, NULL },
{ MSG_HIT, NULL },
{ MSG_HIT_GOOD, "It was a good hit!" },
{ MSG_HIT_GREAT, "It was a great hit!" },
{ MSG_HIT_SUPERB, "It was a superb hit!" },
{ MSG_HIT_HI_GREAT, "It was a *GREAT* hit!" },
{ MSG_HIT_HI_SUPERB, "It was a *SUPERB* hit!" },
}
NULL
Definition: list-summon-types.h:18
const struct hit_types ranged_hit_types[]
static
Initial value:
= {
{ MSG_MISS, NULL },
{ MSG_SHOOT_HIT, NULL },
{ MSG_HIT_GOOD, "It was a good hit!" },
{ MSG_HIT_GREAT, "It was a great hit!" },
{ MSG_HIT_SUPERB, "It was a superb hit!" }
}
NULL
Definition: list-summon-types.h:18