Angband
Data Structures | Macros | Enumerations | Functions | Variables
mon-spell.c File Reference

Monster spell casting and selection. More...

#include "angband.h"
#include "effects.h"
#include "mon-attack.h"
#include "mon-desc.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-predicate.h"
#include "mon-spell.h"
#include "mon-timed.h"
#include "mon-util.h"
#include "obj-knowledge.h"
#include "player-timed.h"
#include "player-util.h"
#include "project.h"
#include "list-mon-spells.h"

Data Structures

struct  mon_spell_info
 

Spell selection

More...
 

Macros

#define RSF(a, b)   { RSF_##a, b },
 

Enumerations

enum  spell_tag_t { SPELL_TAG_NONE, SPELL_TAG_NAME, SPELL_TAG_PRONOUN }
 

Spell casting

More...
 

Functions

static spell_tag_t spell_tag_lookup (const char *tag)
 
static void spell_message (struct monster *mon, const struct monster_spell *spell, bool seen, bool hits)
 Print a monster spell message. More...
 
const struct monster_spellmonster_spell_by_index (int index)
 
static void spell_check_for_fail_rune (const struct monster_spell *spell)
 Check if a spell effect which has been saved against would also have been prevented by an object property, and learn the appropriate rune. More...
 
void do_mon_spell (int index, struct monster *mon, bool seen)
 Process a monster spell. More...
 
static bool mon_spell_is_valid (int index)
 
static bool monster_spell_is_projectable (int index)
 
static bool monster_spell_is_breath (int index)
 
static bool mon_spell_has_damage (int index)
 
bool mon_spell_is_innate (int index)
 
bool test_spells (bitflag *f, int types)
 Test a spell bitflag for a type of spell. More...
 
void ignore_spells (bitflag *f, int types)
 Set a spell bitflag to ignore a specific set of spell types. More...
 
void unset_spells (bitflag *spells, bitflag *flags, bitflag *pflags, struct element_info *el, const struct monster *mon)
 Turn off spells with a side effect or a proj_type that is resisted by something in flags, subject to intelligence and chance. More...
 
static int nonhp_dam (const struct monster_spell *spell, const struct monster_race *race, aspect dam_aspect)
 Determine the damage of a spell attack which ignores monster hp (i.e. More...
 
int breath_dam (int type, int hp)
 Determine the damage of a monster breath attack. More...
 
static int mon_spell_dam (int index, int hp, const struct monster_race *race, aspect dam_aspect)
 Calculate the damage of a monster spell. More...
 
int best_spell_power (const struct monster_race *race, int resist)
 Calculate a monster's maximum spell power. More...
 
void create_mon_spell_mask (bitflag *f,...)
 Create a mask of monster spell flags of a specific type. More...
 
const char * mon_spell_lore_description (int index, const struct monster_race *race)
 
int mon_spell_lore_damage (int index, const struct monster_race *race, bool know_hp)
 

Variables

static const struct mon_spell_info mon_spell_types []
 

Detailed Description

Monster spell casting and selection.

Copyright (c) 2010-14 Chris Carr and 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.

Macro Definition Documentation

#define RSF (   a,
 
)    { RSF_##a, b },

Enumeration Type Documentation


Spell casting

Enumerator
SPELL_TAG_NONE 
SPELL_TAG_NAME 
SPELL_TAG_PRONOUN 

Function Documentation

int best_spell_power ( const struct monster_race race,
int  resist 
)

Calculate a monster's maximum spell power.

Parameters
raceis the monster we're studying
resistis the degree of resistance we're assuming to any attack type (-1 = vulnerable ... 3 = immune)

References adjust_dam(), random::base, random::dice, monster_spell::effect, mon_spell_info::index, monster_race::level, random::m_bonus, MAX, MAXIMISE, mon_hp(), mon_spell_dam(), mon_spell_types, monster_spell_by_index(), monster_spell_is_projectable(), effect::params, monster_spell::power, rsf_has, monster_spell::save_message, random::sides, and monster_race::spell_flags.

int breath_dam ( int  type,
int  hp 
)

Determine the damage of a monster breath attack.

Functions.

Parameters
typeis the attack element type
hpis the monster's hp

References projection::damage_cap, projection::divisor, projections, and type.

Referenced by effect_handler_BREATH(), and mon_spell_dam().

void create_mon_spell_mask ( bitflag f,
  ... 
)

Create a mask of monster spell flags of a specific type.

Parameters
fis the flag array we're filling
...is the list of flags we're looking for

N.B. RST_NONE must be the last item in the ... list

References args, i, mon_spell_info::index, mon_spell_types, rsf_on, rsf_wipe, RST_NONE, and mon_spell_info::type.

Referenced by lore_append_spells().

void do_mon_spell ( int  index,
struct monster mon,
bool  seen 
)

Process a monster spell.

Parameters
indexis the monster spell flag (RSF_FOO)
monis the attacking monster
seenis whether the player can see the monster at this moment

References check_hit(), CONF_HIT_REDUCTION, disturb(), monster_spell::effect, effect_do(), monster_spell::hit, monster_race::level, monster::m_timed, MAX, monster::midx, monster_spell_by_index(), msg, NULL, monster::race, randint0, monster_spell::save_message, SKILL_SAVE, player_state::skills, source_monster(), spell_check_for_fail_rune(), spell_message(), and player::state.

Referenced by make_attack_spell().

void ignore_spells ( bitflag f,
int  types 
)

Set a spell bitflag to ignore a specific set of spell types.

Parameters
fis the set of spell flags we're pruning
typesis the spell type(s) we're ignoring

References mon_spell_info::index, mon_spell_types, rsf_has, rsf_off, and mon_spell_info::type.

Referenced by make_attack_spell().

static int mon_spell_dam ( int  index,
int  hp,
const struct monster_race race,
aspect  dam_aspect 
)
static

Calculate the damage of a monster spell.

Parameters
indexis the index of the spell in question.
hpis the hp of the casting monster.
raceis the race of the casting monster.
dam_aspectis the damage calc we want (min, max, avg, random).

References breath_dam(), monster_spell::effect, monster_spell_by_index(), monster_spell_is_breath(), nonhp_dam(), and effect::params.

Referenced by best_spell_power(), and mon_spell_lore_damage().

static bool mon_spell_has_damage ( int  index)
static
bool mon_spell_is_innate ( int  index)
static bool mon_spell_is_valid ( int  index)
static
int mon_spell_lore_damage ( int  index,
const struct monster_race race,
bool  know_hp 
)
const char* mon_spell_lore_description ( int  index,
const struct monster_race race 
)
const struct monster_spell* monster_spell_by_index ( int  index)
static bool monster_spell_is_breath ( int  index)
static

References mon_spell_types, RST_BREATH, and type.

Referenced by mon_spell_dam().

static bool monster_spell_is_projectable ( int  index)
static

References mon_spell_types, RST_BALL, RST_BOLT, RST_BREATH, and type.

Referenced by best_spell_power().

static int nonhp_dam ( const struct monster_spell spell,
const struct monster_race race,
aspect  dam_aspect 
)
static

Determine the damage of a spell attack which ignores monster hp (i.e.

bolts and balls, including arrows/boulders/storms/etc.)

Parameters
spellis the attack type
raceis the monster race of the attacker
dam_aspectis the damage calc required (min, avg, max, random)

References effect::dice, dice_roll(), monster_spell::effect, effect::next, NULL, randcalc(), and ref_race.

Referenced by mon_spell_dam().

static void spell_check_for_fail_rune ( const struct monster_spell spell)
static

Check if a spell effect which has been saved against would also have been prevented by an object property, and learn the appropriate rune.

References monster_spell::effect, equip_learn_element(), effect::index, effect::next, effect::params, player_inc_check(), and void().

Referenced by do_mon_spell().

static void spell_message ( struct monster mon,
const struct monster_spell spell,
bool  seen,
bool  hits 
)
static
static spell_tag_t spell_tag_lookup ( const char *  tag)
static
bool test_spells ( bitflag f,
int  types 
)

Test a spell bitflag for a type of spell.

Returns true if any desired type is among the flagset

Parameters
fis the set of spell flags we're testing
typesis the spell type(s) we're looking for

References mon_spell_info::index, mon_spell_types, rsf_has, and mon_spell_info::type.

Referenced by make_attack_spell().

void unset_spells ( bitflag spells,
bitflag flags,
bitflag pflags,
struct element_info el,
const struct monster mon 
)

Turn off spells with a side effect or a proj_type that is resisted by something in flags, subject to intelligence and chance.

Parameters
spellsis the set of spells we're pruning
flagsis the set of object flags we're testing
pflagsis the set of player flags we're testing
elis what we know about the monster's elemental resists
raceis the monster type we're operating on

References monster_spell::effect, timed_effect_data::fail, effect::index, mon_spell_info::index, mon_spell_types, monster_is_smart(), monster_spell_by_index(), effect::next, of_has, one_in_, effect::params, pf_has, randint0, element_info::res_level, rsf_has, rsf_off, RST_BALL, RST_BOLT, RST_BREATH, timed_effects, and mon_spell_info::type.

Referenced by remove_bad_spells().

Variable Documentation

const struct mon_spell_info mon_spell_types[]
static