The Battle for Wesnoth  1.15.2+dev
Namespaces | Macros | Functions | Variables
abilities.cpp File Reference

Manage unit-abilities, like heal, cure, and weapon_specials. More...

#include "display.hpp"
#include "display_context.hpp"
#include "font/text_formatting.hpp"
#include "game_board.hpp"
#include "lexical_cast.hpp"
#include "log.hpp"
#include "map/map.hpp"
#include "resources.hpp"
#include "team.hpp"
#include "terrain/filter.hpp"
#include "units/unit.hpp"
#include "units/abilities.hpp"
#include "units/filter.hpp"
#include "units/map.hpp"
#include "filter_context.hpp"
#include "formula/callable_objects.hpp"
#include "formula/formula.hpp"
#include "formula/function_gamestate.hpp"
#include "serialization/string_view.hpp"
#include "deprecation.hpp"
#include <boost/dynamic_bitset.hpp>
#include <boost/algorithm/string/predicate.hpp>
Include dependency graph for abilities.cpp:

Go to the source code of this file.

Namespaces

 unit_abilities
 

Macros

#define ERR_NG   LOG_STREAM(err, log_engine)
 

Functions

template std::pair< int, map_locationunit_ability_list::get_extremum< std::less< int > > (const std::string &key, int def, const std::less< int > &comp) const
 
template std::pair< int, map_locationunit_ability_list::get_extremum< std::greater< int > > (const std::string &key, int def, const std::greater< int > &comp) const
 
static bool ability_filter_fighter (const std::string &ability, const std::string &filter_attacker, const config &cfg, const map_location &loc, unit_const_ptr &u, unit_const_ptr &u2, const_attack_ptr weapon)
 returns whether u matches cfg .child( filter_attacker ). More...
 
static bool ability_apply_filter (unit_const_ptr un, unit_const_ptr up, const std::string &ability, const config &cfg, const map_location &loc, const map_location &opp_loc, bool attacker, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 checks whether a single ability passes attack related filters, in particular for example [filter_student][filter_weapon] More...
 
static unit_ability_list list_leadership (const std::string &ability, unit_const_ptr un, unit_const_ptr up, const map_location &loc, const map_location &opp_loc, bool attacker, const_attack_ptr weapon, const_attack_ptr opp_weapon, bool affect_other)
 like to un->get_abilities() this returns the active abilities on this unit. More...
 
bool unit_abilities::filter_base_matches (const config &cfg, int def)
 

Variables

static lg::log_domain log_engine ("engine")
 

Detailed Description

Manage unit-abilities, like heal, cure, and weapon_specials.

Definition in file abilities.cpp.

Macro Definition Documentation

◆ ERR_NG

#define ERR_NG   LOG_STREAM(err, log_engine)

Definition at line 45 of file abilities.cpp.

Referenced by unit_abilities::effect::effect(), and attack_type::modified_attacks().

Function Documentation

◆ ability_apply_filter()

static bool ability_apply_filter ( unit_const_ptr  un,
unit_const_ptr  up,
const std::string &  ability,
const config cfg,
const map_location loc,
const map_location opp_loc,
bool  attacker,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon 
)
static

checks whether a single ability passes attack related filters, in particular for example [filter_student][filter_weapon]

Parameters
[in]un,upThe units filtered(in that example un is 'self and up 'other' unit)
[in]abilityThe tagname of the ability, needed because some tagnames need special handling
[in]loc,opp_locThe locations where we assume the filtered units un and up to be at(here loc is used)
[in]weapon,opp_weaponused for [filter_weapon](weapon in that example)
Returns
true if the units passed all filters.

Definition at line 1132 of file abilities.cpp.

References ability_filter_fighter().

Referenced by list_leadership().

◆ ability_filter_fighter()

static bool ability_filter_fighter ( const std::string &  ability,
const std::string &  filter_attacker,
const config cfg,
const map_location loc,
unit_const_ptr u,
unit_const_ptr u2,
const_attack_ptr  weapon 
)
static

returns whether u matches cfg .child( filter_attacker ).

But also check for [filter_weapon] subtags writ the current attack context.

Parameters
[in]abilityThe tagname of the ability, needed because some tagnames need special handling
[in]locThe location where we assume the filtered unit to be at
[in]u2the 'other unit' in the filter
[in]weaponused for [filter_weapon]
Returns
true if the unit passed the filter.

Definition at line 1094 of file abilities.cpp.

References config::child(), unit_filter::matches(), and unit_filter::set_use_flat_tod().

Referenced by ability_apply_filter().

◆ list_leadership()

static unit_ability_list list_leadership ( const std::string &  ability,
unit_const_ptr  un,
unit_const_ptr  up,
const map_location loc,
const map_location opp_loc,
bool  attacker,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon,
bool  affect_other 
)
static

like to un->get_abilities() this returns the active abilities on this unit.

That is. abilities of this unit and abilities of adjacent units that affect this unit. Unlike un->get_abilities() this also checks for attack related filters.

Parameters
[in]unThe current unit
[in]abilityThe tagname of the ability, for filtered the abilities type
[in]locThe location where we assume the un unit to be at
[in]upThe opponent
[in]opp_locThe location where we assume the opponent to be at
[in]attackerthe condition for matches 'active_on=offense/defense' and special_affects_self/opponent
[in]weapon,opp_weaponused for [filter_weapon] in ability_filter_fighter
[in]affect_otherif true we will only return abilities that affect the opponent otherwise we will return abilities that affect un
Returns
an unit_ability_list containing all abilities active in the current attack context.

Definition at line 1157 of file abilities.cpp.

References ability_apply_filter(), unit_ability_list::begin(), unit_ability_list::end(), unit_ability_list::erase(), and i.

Referenced by attack_type::list_ability().

◆ unit_ability_list::get_extremum< std::greater< int > >()

template std::pair<int, map_location> unit_ability_list::get_extremum< std::greater< int > > ( const std::string &  key,
int  def,
const std::greater< int > &  comp 
) const

◆ unit_ability_list::get_extremum< std::less< int > >()

template std::pair<int, map_location> unit_ability_list::get_extremum< std::less< int > > ( const std::string &  key,
int  def,
const std::less< int > &  comp 
) const

Variable Documentation

◆ log_engine

lg::log_domain log_engine("engine")
static