The Battle for Wesnoth  1.15.0-dev
Macros | Functions | Variables
attack.cpp File Reference

Fighting. More...

#include "actions/attack.hpp"
#include "actions/advancement.hpp"
#include "actions/vision.hpp"
#include "ai/lua/aspect_advancements.hpp"
#include "game_config.hpp"
#include "game_data.hpp"
#include "game_events/pump.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "map/map.hpp"
#include "mouse_handler_base.hpp"
#include "play_controller.hpp"
#include "preferences/game.hpp"
#include "random.hpp"
#include "replay.hpp"
#include "resources.hpp"
#include "statistics.hpp"
#include "synced_checkup.hpp"
#include "synced_user_choice.hpp"
#include "team.hpp"
#include "tod_manager.hpp"
#include "units/abilities.hpp"
#include "units/animation_component.hpp"
#include "units/helper.hpp"
#include "units/filter.hpp"
#include "units/map.hpp"
#include "units/udisplay.hpp"
#include "units/unit.hpp"
#include "whiteboard/manager.hpp"
#include "wml_exception.hpp"
Include dependency graph for attack.cpp:

Go to the source code of this file.

Macros

#define DBG_NG   LOG_STREAM(debug, log_engine)
 
#define LOG_NG   LOG_STREAM(info, log_engine)
 
#define WRN_NG   LOG_STREAM(err, log_engine)
 
#define ERR_NG   LOG_STREAM(err, log_engine)
 
#define DBG_AT   LOG_STREAM(debug, log_attack)
 
#define LOG_AT   LOG_STREAM(info, log_attack)
 
#define WRN_AT   LOG_STREAM(err, log_attack)
 
#define ERR_AT   LOG_STREAM(err, log_attack)
 
#define LOG_CF   LOG_STREAM(info, log_config)
 

Functions

void attack_unit (const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display)
 Performs an attack. More...
 
void attack_unit_and_advance (const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display, const ai::unit_advancements_aspect &ai_advancement)
 Performs an attack, and advanced the units afterwards. More...
 
int under_leadership (const unit &u, const map_location &loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 Tests if the unit at loc is currently affected by leadership. More...
 
bool leadership_affects_self (const std::string &ability, const unit_map &units, const map_location &loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 
bool leadership_affects_opponent (const std::string &ability, const unit_map &units, const map_location &loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 
std::pair< int, bool > ability_leadership (const std::string &ability, const unit_map &units, const map_location &loc, const map_location &opp_loc, bool attacker, int abil_value, bool backstab_pos, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 
bool bool_leadership (const std::string &ability, const unit_map &units, const map_location &loc, const map_location &opp_loc, bool attacker, const_attack_ptr weapon, const_attack_ptr opp_weapon)
 
int combat_modifier (const unit_map &units, const gamemap &map, const map_location &loc, unit_type::ALIGNMENT alignment, bool is_fearless)
 Returns the amount that a unit's damage should be multiplied by due to the current time of day. More...
 
int combat_modifier (const time_of_day &effective_tod, unit_type::ALIGNMENT alignment, bool is_fearless)
 Returns the amount that a unit's damage should be multiplied by due to the current time of day. More...
 
int generic_combat_modifier (int lawful_bonus, unit_type::ALIGNMENT alignment, bool is_fearless)
 Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus. More...
 
bool backstab_check (const map_location &attacker_loc, const map_location &defender_loc, const unit_map &units, const std::vector< team > &teams)
 Function to check if an attack will satisfy the requirements for backstab. More...
 

Variables

static lg::log_domain log_engine ("engine")
 
static lg::log_domain log_attack ("engine/attack")
 
static lg::log_domain log_config ("config")
 

Detailed Description

Fighting.

Definition in file attack.cpp.

Macro Definition Documentation

◆ DBG_AT

#define DBG_AT   LOG_STREAM(debug, log_attack)

Definition at line 60 of file attack.cpp.

◆ DBG_NG

#define DBG_NG   LOG_STREAM(debug, log_engine)

Definition at line 54 of file attack.cpp.

Referenced by battle_context::choose_defender_weapon().

◆ ERR_AT

#define ERR_AT   LOG_STREAM(err, log_attack)

Definition at line 63 of file attack.cpp.

◆ ERR_NG

#define ERR_NG   LOG_STREAM(err, log_engine)

Definition at line 57 of file attack.cpp.

◆ LOG_AT

#define LOG_AT   LOG_STREAM(info, log_attack)

Definition at line 61 of file attack.cpp.

◆ LOG_CF

#define LOG_CF   LOG_STREAM(info, log_config)

Definition at line 66 of file attack.cpp.

Referenced by battle_context_unit_stats::battle_context_unit_stats().

◆ LOG_NG

#define LOG_NG   LOG_STREAM(info, log_engine)

Definition at line 55 of file attack.cpp.

Referenced by battle_context::choose_defender_weapon().

◆ WRN_AT

#define WRN_AT   LOG_STREAM(err, log_attack)

Definition at line 62 of file attack.cpp.

◆ WRN_NG

#define WRN_NG   LOG_STREAM(err, log_engine)

Definition at line 56 of file attack.cpp.

Function Documentation

◆ ability_leadership()

std::pair<int, bool> ability_leadership ( const std::string &  ability,
const unit_map units,
const map_location loc,
const map_location opp_loc,
bool  attacker,
int  abil_value,
bool  backstab_pos,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon 
)

◆ attack_unit()

void attack_unit ( const map_location attacker,
const map_location defender,
int  attack_with,
int  defend_with,
bool  update_display = true 
)

Performs an attack.

Definition at line 1537 of file attack.cpp.

References dummy.

Referenced by attack_unit_and_advance(), and ai::simulated_attack().

◆ attack_unit_and_advance()

void attack_unit_and_advance ( const map_location attacker,
const map_location defender,
int  attack_with,
int  defend_with,
bool  update_display,
const ai::unit_advancements_aspect ai_advancement 
)

Performs an attack, and advanced the units afterwards.

Definition at line 1547 of file attack.cpp.

References advance_unit_at(), attack_unit(), unit_map::find(), resources::gameboard, and game_board::units().

Referenced by ai::attack_result::do_execute(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ backstab_check()

bool backstab_check ( const map_location attacker_loc,
const map_location defender_loc,
const unit_map units,
const std::vector< team > &  teams 
)

Function to check if an attack will satisfy the requirements for backstab.

Input:

  • the location from which the attack will occur,
  • the defending unit location,
  • the list of units on the map and
  • the list of teams. The defender and opposite units should be in place already. The attacking unit doesn't need to be, but if it isn't, an external check should be made to make sure the opposite unit isn't also the attacker.

Definition at line 1773 of file attack.cpp.

References unit_map::end(), unit_map::find(), get_adjacent_tiles(), and i.

Referenced by battle_context_unit_stats::battle_context_unit_stats(), and ai::ai_default_rca::aspect_attacks_base::do_attack_analysis().

◆ bool_leadership()

bool bool_leadership ( const std::string &  ability,
const unit_map units,
const map_location loc,
const map_location opp_loc,
bool  attacker,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon 
)

◆ combat_modifier() [1/2]

int combat_modifier ( const unit_map units,
const gamemap map,
const map_location loc,
unit_type::ALIGNMENT  alignment,
bool  is_fearless 
)

Returns the amount that a unit's damage should be multiplied by due to the current time of day.

Definition at line 1726 of file attack.cpp.

References combat_modifier(), tod_manager::get_illuminated_time_of_day(), and resources::tod_manager.

Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), combat_modifier(), gui2::dialogs::attack_predictions::set_data(), and unit_alignment().

◆ combat_modifier() [2/2]

int combat_modifier ( const time_of_day effective_tod,
unit_type::ALIGNMENT  alignment,
bool  is_fearless 
)

Returns the amount that a unit's damage should be multiplied by due to the current time of day.

Definition at line 1737 of file attack.cpp.

References generic_combat_modifier(), and time_of_day::lawful_bonus.

◆ generic_combat_modifier()

int generic_combat_modifier ( int  lawful_bonus,
unit_type::ALIGNMENT  alignment,
bool  is_fearless 
)

Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus.

Definition at line 1745 of file attack.cpp.

Referenced by battle_context_unit_stats::battle_context_unit_stats(), and combat_modifier().

◆ leadership_affects_opponent()

bool leadership_affects_opponent ( const std::string &  ability,
const unit_map units,
const map_location loc,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon 
)

◆ leadership_affects_self()

bool leadership_affects_self ( const std::string &  ability,
const unit_map units,
const map_location loc,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon 
)

◆ under_leadership()

int under_leadership ( const unit u,
const map_location loc,
const_attack_ptr  weapon,
const_attack_ptr  opp_weapon = nullptr 
)

Tests if the unit at loc is currently affected by leadership.

(i.e. has a higher-level unit with the 'leadership' ability next to it).

Returns the bonus percentage (possibly 0 if there's no leader adjacent).

Definition at line 1567 of file attack.cpp.

References unit::get_abilities(), and unit_ability_list::highest().

Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), and gui2::dialogs::attack_predictions::set_data().

Variable Documentation

◆ log_attack

lg::log_domain log_attack("engine/attack")
static

◆ log_config

lg::log_domain log_config("config")
static

◆ log_engine

lg::log_domain log_engine("engine")
static