Angband
Functions
mon-attack.c File Reference

Monster attacks. More...

#include "angband.h"
#include "cave.h"
#include "effects.h"
#include "init.h"
#include "mon-attack.h"
#include "mon-blows.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "mon-predicate.h"
#include "mon-spell.h"
#include "mon-timed.h"
#include "mon-util.h"
#include "obj-knowledge.h"
#include "player-attack.h"
#include "player-timed.h"
#include "player-util.h"
#include "project.h"

Functions

static bool monster_can_cast (struct monster *mon, bool innate)
 This file deals with monster attacks (including spells) as follows: More...
 
static void remove_bad_spells (struct monster *mon, bitflag f[RSF_SIZE])
 Remove the "bad" spells from a spell list. More...
 
static bool summon_possible (struct loc grid)
 Determine if there is a space near the selected spot in which a summoned creature can appear. More...
 
int choose_attack_spell (bitflag *f, bool innate, bool non_innate)
 Have a monster choose a spell to cast. More...
 
static int monster_spell_failrate (struct monster *mon)
 Failure rate of a monster's spell, based on spell power and current status. More...
 
bool make_ranged_attack (struct monster *mon)
 Creatures can cast spells, shoot missiles, and breathe. More...
 
static int monster_critical (random_value dice, int rlev, int dam)
 Critical blow. More...
 
bool check_hit (struct player *p, int power, int level, int accuracy)
 Determine if a monster attack against the player succeeds. More...
 
bool check_hit_monster (struct monster *mon, int power, int level, int accuracy)
 Determine if a monster attack against a monster succeeds. More...
 
int adjust_dam_armor (int damage, int ac)
 Calculate how much damage remains after armor is taken into account (does for a physical attack what adjust_dam does for an elemental attack). More...
 
bool make_attack_normal (struct monster *mon, struct player *p)
 Attack the player via physical attacks. More...
 
bool monster_attack_monster (struct monster *mon, struct monster *t_mon)
 Attack the player via physical attacks. More...
 

Detailed Description

Monster attacks.

Monster ranged attacks - choosing an attack spell or shot and making it. Monster melee attacks - monster critical blows, whether a monster attack hits, what happens when a monster attacks an adjacent player.

Copyright (c) 1997 Ben Harrison, David Reeve Sward, Keldon Jones.

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

◆ adjust_dam_armor()

int adjust_dam_armor ( int  damage,
int  ac 
)

Calculate how much damage remains after armor is taken into account (does for a physical attack what adjust_dam does for an elemental attack).

Referenced by melee_effect_elemental(), melee_effect_handler_HURT(), and melee_effect_handler_SHATTER().

◆ check_hit()

bool check_hit ( struct player p,
int  power,
int  level,
int  accuracy 
)

Determine if a monster attack against the player succeeds.

References player_state::ac, equip_learn_on_defend(), player::state, test_hit(), and player_state::to_a.

Referenced by do_mon_spell(), and make_attack_normal().

◆ check_hit_monster()

bool check_hit_monster ( struct monster mon,
int  power,
int  level,
int  accuracy 
)

Determine if a monster attack against a monster succeeds.

References monster_race::ac, monster::race, and test_hit().

Referenced by do_mon_spell(), and monster_attack_monster().

◆ choose_attack_spell()

int choose_attack_spell ( bitflag f,
bool  innate,
bool  non_innate 
)

Have a monster choose a spell to cast.

Note that the monster's spell list has already had "useless" spells (bolts that won't hit the player, summons without room, etc.) removed. Perhaps that should be done by this function.

Stupid monsters will just pick a spell randomly. Smart monsters will choose more "intelligently".

This function could be an efficiency bottleneck.

References FLAG_START, i, mon_spell_is_innate(), num, randint0, and rsf_has.

Referenced by do_cmd_mon_command(), and make_ranged_attack().

◆ make_attack_normal()

bool make_attack_normal ( struct monster mon,
struct player p 
)

◆ make_ranged_attack()

bool make_ranged_attack ( struct monster mon)

Creatures can cast spells, shoot missiles, and breathe.

Returns "true" if a spell (or whatever) was (successfully) cast.

Perhaps monsters should breathe at locations near the player, since this would allow them to inflict "partial" damage.

It will not be possible to "correctly" handle the case in which a monster attempts to attack a location which is thought to contain the player, but which in fact is nowhere near the player, since this might induce all sorts of messages about the attack itself, and about the effects of the attack, which the player might or might not be in a position to observe. Thus, for simplicity, it is probably best to only allow "faulty" attacks by a monster if one of the important grids (probably the initial or final grid) is in fact in view of the player. It may be necessary to actually prevent spell attacks except when the monster actually has line of sight to the player. Note that a monster could be left in a bizarre situation after the player ducked behind a pillar and then teleported away, for example.

Note that this function attempts to optimize the use of spells for the cases in which the monster has no spells, or has spells but cannot use them, or has spells but they will have no "useful" effect. Note that this function has been an efficiency bottleneck in the past.

Note the special "MFLAG_NICE" flag, which prevents a monster from using any spell attacks until the player has had a single chance to move.

Note the interaction between innate attacks and non-innate attacks (true spells). Because the check for spells is done first, actual innate attack frequencies are affected by the spell frequency.

References become_aware(), monster_lore::cast_innate, monster_lore::cast_spell, cave, choose_attack_spell(), monster_lore::deaths, disturb(), do_mon_spell(), get_lore(), monster::grid, player::grid, monster::hp, ignore_spells(), player::is_dead, lore_update(), monster::maxhp, MDESC_STANDARD, mon_spell_is_innate(), monster_can_cast(), monster_desc(), monster_is_camouflaged(), monster_is_smart(), monster_is_stupid(), monster_is_visible(), monster_spell_failrate(), msg, one_in_, PROJECT_STOP, projectable(), monster::race, randint0, remove_bad_spells(), rsf_copy, rsf_is_empty, rsf_on, RSF_SIZE, RST_BOLT, RST_DAMAGE, RST_SUMMON, monster_lore::spell_flags, monster_race::spell_flags, summon_possible(), test_spells(), and player::timed.

Referenced by monster_turn().

◆ monster_attack_monster()

bool monster_attack_monster ( struct monster mon,
struct monster t_mon 
)

◆ monster_can_cast()

static bool monster_can_cast ( struct monster mon,
bool  innate 
)
static

This file deals with monster attacks (including spells) as follows:

Give monsters more intelligent attack/spell selection based on observations of previous attacks on the player, and/or by allowing the monster to "cheat" and know the player status.

Maintain an idea of the player status, and use that information to occasionally eliminate "ineffective" spell attacks. We could also eliminate ineffective normal attacks, but there is no reason for the monster to do this, since he gains no benefit. Note that MINDLESS monsters are not allowed to use this code. And non-INTELLIGENT monsters only use it partially effectively.

Actually learn what the player resists, and use that information to remove attacks or spells before using them. Check if a monster has a chance of casting a spell this turn

References cave, monster::cdis, monster_race::freq_innate, monster_race::freq_spell, monster::grid, player::grid, angband_constants::max_range, monster::mflag, mflag_has, PROJECT_NONE, projectable(), monster::race, randint0, and z_info.

Referenced by make_ranged_attack().

◆ monster_critical()

static int monster_critical ( random_value  dice,
int  rlev,
int  dam 
)
static

Critical blow.

All hits that do 95% of total possible damage, and which also do at least 20 damage, or, sometimes, N damage. This is used only to determine "cuts" and "stuns".

References MAXIMISE, randcalc(), and randint0.

Referenced by make_attack_normal(), and monster_attack_monster().

◆ monster_spell_failrate()

static int monster_spell_failrate ( struct monster mon)
static

Failure rate of a monster's spell, based on spell power and current status.

References monster::m_timed, MIN, monster_is_stupid(), monster::race, and monster_race::spell_power.

Referenced by make_ranged_attack().

◆ remove_bad_spells()

static void remove_bad_spells ( struct monster mon,
bitflag  f[RSF_SIZE] 
)
static

◆ summon_possible()

static bool summon_possible ( struct loc  grid)
static

Determine if there is a space near the selected spot in which a summoned creature can appear.

References player_upkeep::arena_level, cave, distance(), loc(), los(), square_in_bounds(), square_isempty(), square_iswarded(), player::upkeep, loc::x, and loc::y.

Referenced by make_ranged_attack().