The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Static 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, unit_const_ptr attacker_ptr=unit_const_ptr(), unit_const_ptr defender_ptr=unit_const_ptr(), bool use_biased_rng=false)
 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).
 
 battle_context (const battle_context_unit_stats &att, const battle_context_unit_stats &def)
 Used by the AI which caches battle_context_unit_stats.
 
 battle_context (battle_context &&other)=default
 
battle_context & operator= (battle_context &&other)=default
 
const battle_context_unit_stats & get_attacker_stats () const
 This method returns the statistics of the attacker.
 
const battle_context_unit_stats & get_defender_stats () const
 This method returns the statistics of the defender.
 
const combatant & get_attacker_combatant (const combatant *prev_def=nullptr)
 Get the simulation results.
 
const combatant & get_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?
 
bool better_defense (class battle_context &that, double harm_weight)
 Given this harm_weight, is this attack better than that?
 
void simulate (const combatant *prev_def)
 

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

 battle_context (nonempty_unit_const_ptr attacker, const map_location &attacker_loc, int attacker_weapon, nonempty_unit_const_ptr defender, const map_location &defender_loc, int defender_weapon, bool use_biased_rng=false)
 

Static Private Member Functions

static battle_context choose_attacker_weapon (nonempty_unit_const_ptr attacker, const nonempty_unit_const_ptr &defender, const map_location &attacker_loc, const map_location &defender_loc, double harm_weight, const combatant *prev_def, bool use_biased_rng)
 
static battle_context choose_defender_weapon (nonempty_unit_const_ptr attacker, nonempty_unit_const_ptr defender, unsigned attacker_weapon, const map_location &attacker_loc, const map_location &defender_loc, const combatant *prev_def, bool use_biased_rng)
 

Private Attributes

std::unique_ptr< battle_context_unit_stats > attacker_stats_
 Statistics of the units.
 
std::unique_ptr< battle_context_unit_stats > defender_stats_
 
std::unique_ptr< combatant > attacker_combatant_
 Outcome of simulated fight.
 
std::unique_ptr< combatant > defender_combatant_
 
bool use_biased_rng_ = false
 

Detailed Description

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

Definition at line 182 of file attack.hpp.

Constructor & Destructor Documentation

◆ battle_context() [1/4]

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,
unit_const_ptr  attacker_ptr = unit_const_ptr(),
unit_const_ptr  defender_ptr = unit_const_ptr(),
bool  use_biased_rng = false 
)

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. use_biased_rng determines whether or not to simulate fights in Reduced RNG mode.

Definition at line 304 of file attack.cpp.

References attacker_stats_, choose_attacker_weapon(), choose_defender_weapon(), defender_stats_, unit_map::find(), and unit_map::iterator_base< iter_types >::get_shared_ptr().

◆ battle_context() [2/4]

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 350 of file attack.cpp.

◆ battle_context() [3/4]

battle_context::battle_context ( battle_context &&  other)
default

◆ battle_context() [4/4]

battle_context::battle_context ( nonempty_unit_const_ptr  attacker,
const map_location &  attacker_loc,
int  attacker_weapon,
nonempty_unit_const_ptr  defender,
const map_location &  defender_loc,
int  defender_weapon,
bool  use_biased_rng = false 
)
private

Definition at line 267 of file attack.cpp.

References attacker_stats_, unit::attacks(), and defender_stats_.

Member Function Documentation

◆ better_attack()

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 376 of file attack.cpp.

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

Referenced by choose_attacker_weapon(), and events::mouse_handler::fill_weapon_choices().

◆ better_combat()

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

◆ better_defense()

bool battle_context::better_defense ( class battle_context &  that,
double  harm_weight 
)

Given this harm_weight, is this attack better than that?

Definition at line 388 of file attack.cpp.

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

Referenced by choose_defender_weapon().

◆ choose_attacker_weapon()

battle_context battle_context::choose_attacker_weapon ( nonempty_unit_const_ptr  attacker,
const nonempty_unit_const_ptr &  defender,
const map_location &  attacker_loc,
const map_location &  defender_loc,
double  harm_weight,
const combatant *  prev_def,
bool  use_biased_rng 
)
staticprivate

◆ choose_defender_weapon()

battle_context battle_context::choose_defender_weapon ( nonempty_unit_const_ptr  attacker,
nonempty_unit_const_ptr  defender,
unsigned  attacker_weapon,
const map_location &  attacker_loc,
const map_location &  defender_loc,
const combatant *  prev_def,
bool  use_biased_rng 
)
staticprivate

◆ get_attacker_combatant()

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 361 of file attack.cpp.

References attacker_combatant_, and simulate().

Referenced by better_attack(), better_defense(), ai::attack_result::do_execute(), and game_lua_kernel::intf_simulate_combat().

◆ get_attacker_stats()

const battle_context_unit_stats & battle_context::get_attacker_stats ( ) const
inline

This method returns the statistics of the attacker.

Definition at line 211 of file attack.hpp.

References attacker_stats_.

Referenced by ai::attack_result::do_execute(), events::mouse_handler::fill_weapon_choices(), and game_lua_kernel::intf_simulate_combat().

◆ get_defender_combatant()

const combatant & battle_context::get_defender_combatant ( const combatant *  prev_def = nullptr)

◆ get_defender_stats()

const battle_context_unit_stats & battle_context::get_defender_stats ( ) const
inline

This method returns the statistics of the defender.

Definition at line 217 of file attack.hpp.

References defender_stats_.

Referenced by ai::attack_result::do_execute(), and game_lua_kernel::intf_simulate_combat().

◆ operator=()

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

◆ simulate()

void battle_context::simulate ( const combatant *  prev_def)

Member Data Documentation

◆ attacker_combatant_

std::unique_ptr<combatant> battle_context::attacker_combatant_
private

Outcome of simulated fight.

Definition at line 269 of file attack.hpp.

Referenced by get_attacker_combatant(), and simulate().

◆ attacker_stats_

std::unique_ptr<battle_context_unit_stats> battle_context::attacker_stats_
private

Statistics of the units.

Definition at line 265 of file attack.hpp.

Referenced by battle_context(), battle_context(), choose_attacker_weapon(), choose_defender_weapon(), get_attacker_stats(), and simulate().

◆ defender_combatant_

std::unique_ptr<combatant> battle_context::defender_combatant_
private

Definition at line 270 of file attack.hpp.

Referenced by get_defender_combatant(), and simulate().

◆ defender_stats_

std::unique_ptr<battle_context_unit_stats> battle_context::defender_stats_
private

◆ use_biased_rng_

bool battle_context::use_biased_rng_ = false
private

Definition at line 272 of file attack.hpp.

Referenced by simulate().


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