The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
battle_context Class Reference

Computes the statistics of a battle between an attacker and a defender unit. More...

#include <attack.hpp>

Public Member Functions

 battle_context (const unit_map &units, const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon=-1, int defender_weapon=-1, double aggression=0.0, const combatant *prev_def=nullptr, const unit *attacker_ptr=nullptr)
 If no attacker_weapon is given, we select the best one, based on harm_weight (1.0 means 1 hp lost counters 1 hp damage, 0.0 means we ignore harm weight). More...
 
 battle_context (const battle_context_unit_stats &att, const battle_context_unit_stats &def)
 Used by the AI which caches battle_context_unit_stats. More...
 
 battle_context (const battle_context &other)
 
battle_contextoperator= (const battle_context &other)
 
const battle_context_unit_statsget_attacker_stats () const
 This method returns the statistics of the attacker. More...
 
const battle_context_unit_statsget_defender_stats () const
 This method returns the statistics of the defender. More...
 
const combatantget_attacker_combatant (const combatant *prev_def=nullptr)
 Get the simulation results. More...
 
const combatantget_defender_combatant (const combatant *prev_def=nullptr)
 
bool better_attack (class battle_context &that, double harm_weight)
 Given this harm_weight, is this attack better than that? More...
 

Static Public Member Functions

static bool better_combat (const combatant &us_a, const combatant &them_a, const combatant &us_b, const combatant &them_b, double harm_weight)
 

Private Member Functions

int choose_attacker_weapon (const unit &attacker, const unit &defender, const unit_map &units, const map_location &attacker_loc, const map_location &defender_loc, double harm_weight, int *defender_weapon, const combatant *prev_def)
 
int choose_defender_weapon (const unit &attacker, const unit &defender, unsigned attacker_weapon, const unit_map &units, const map_location &attacker_loc, const map_location &defender_loc, const combatant *prev_def)
 

Private Attributes

std::unique_ptr
< battle_context_unit_stats
attacker_stats_
 Statistics of the units. More...
 
std::unique_ptr
< battle_context_unit_stats
defender_stats_
 
std::unique_ptr< combatantattacker_combatant_
 Outcome of simulated fight. More...
 
std::unique_ptr< combatantdefender_combatant_
 

Detailed Description

Computes the statistics of a battle between an attacker and a defender unit.

Definition at line 170 of file attack.hpp.

Constructor & Destructor Documentation

battle_context::battle_context ( const unit_map units,
const map_location attacker_loc,
const map_location defender_loc,
int  attacker_weapon = -1,
int  defender_weapon = -1,
double  aggression = 0.0,
const combatant prev_def = nullptr,
const unit attacker_ptr = nullptr 
)

If no attacker_weapon is given, we select the best one, based on harm_weight (1.0 means 1 hp lost counters 1 hp damage, 0.0 means we ignore harm weight).

prev_def is for predicting multiple attacks against a defender.

Definition at line 350 of file attack.cpp.

References _(), attacker_combatant_, attacker_stats_, unit::attacks(), choose_attacker_weapon(), choose_defender_weapon(), defender_combatant_, defender_stats_, unit_map::find(), and VALIDATE.

battle_context::battle_context ( const battle_context_unit_stats att,
const battle_context_unit_stats def 
)

Used by the AI which caches battle_context_unit_stats.

Definition at line 417 of file attack.cpp.

battle_context::battle_context ( const battle_context other)

Definition at line 425 of file attack.cpp.

Member Function Documentation

bool battle_context::better_attack ( class battle_context that,
double  harm_weight 
)

Given this harm_weight, is this attack better than that?

Definition at line 483 of file attack.cpp.

References better_combat(), get_attacker_combatant(), and get_defender_combatant().

bool battle_context::better_combat ( const combatant us_a,
const combatant them_a,
const combatant us_b,
const combatant them_b,
double  harm_weight 
)
static
int battle_context::choose_attacker_weapon ( const unit attacker,
const unit defender,
const unit_map units,
const map_location attacker_loc,
const map_location defender_loc,
double  harm_weight,
int *  defender_weapon,
const combatant prev_def 
)
private
int battle_context::choose_defender_weapon ( const unit attacker,
const unit defender,
unsigned  attacker_weapon,
const unit_map units,
const map_location attacker_loc,
const map_location defender_loc,
const combatant prev_def 
)
private
const combatant & battle_context::get_attacker_combatant ( const combatant prev_def = nullptr)

Get the simulation results.

Todo:
FIXME: better to initialize combatant initially (move into battle_context_unit_stats?), just do fight() when required.

Definition at line 452 of file attack.cpp.

References attacker_combatant_, attacker_stats_, defender_combatant_, and defender_stats_.

Referenced by ai::attack_analysis::analyze(), better_attack(), and ai::attack_result::do_execute().

const battle_context_unit_stats& battle_context::get_attacker_stats ( ) const
inline

This method returns the statistics of the attacker.

Definition at line 196 of file attack.hpp.

References attacker_stats_.

Referenced by ai::attack_analysis::analyze(), ai::attack_result::do_execute(), and wfl::attack_callable::weapon().

const combatant & battle_context::get_defender_combatant ( const combatant prev_def = nullptr)
const battle_context_unit_stats& battle_context::get_defender_stats ( ) const
inline

This method returns the statistics of the defender.

Definition at line 202 of file attack.hpp.

References defender_stats_.

Referenced by ai::attack_analysis::analyze(), wfl::attack_callable::defender_weapon(), and ai::attack_result::do_execute().

battle_context & battle_context::operator= ( const battle_context other)

Definition at line 434 of file attack.cpp.

References attacker_combatant_, attacker_stats_, defender_combatant_, and defender_stats_.

Member Data Documentation

std::unique_ptr<combatant> battle_context::attacker_combatant_
private
std::unique_ptr<battle_context_unit_stats> battle_context::attacker_stats_
private
std::unique_ptr<combatant> battle_context::defender_combatant_
private
std::unique_ptr<battle_context_unit_stats> battle_context::defender_stats_
private

The documentation for this class was generated from the following files: