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()) | |
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 (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. More... | |
const battle_context_unit_stats & | get_defender_stats () const |
This method returns the statistics of the defender. More... | |
const combatant & | get_attacker_combatant (const combatant *prev_def=nullptr) |
Get the simulation results. More... | |
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? More... | |
bool | better_defense (class battle_context &that, double harm_weight) |
Given this harm_weight, is this attack better than that? More... | |
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) | |
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) |
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) |
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< combatant > | attacker_combatant_ |
Outcome of simulated fight. More... | |
std::unique_ptr< combatant > | defender_combatant_ |
Computes the statistics of a battle between an attacker and a defender unit.
Definition at line 166 of file attack.hpp.
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() |
||
) |
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 386 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().
Referenced by choose_attacker_weapon(), and choose_defender_weapon().
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 430 of file attack.cpp.
|
default |
|
private |
Definition at line 351 of file attack.cpp.
References attacker_stats_, defender_stats_, and utf8::size().
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 456 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().
|
static |
Definition at line 480 of file attack.cpp.
References combatant::average_hp(), b, battle_context_unit_stats::hp, combatant::hp_dist, game_config::poison_amount, combatant::poisoned, combatant::u_, and battle_context_unit_stats::weapon.
Referenced by better_attack(), better_defense(), and ai::default_recruitment::attack_simulation::better_result().
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 468 of file attack.cpp.
References better_combat(), get_attacker_combatant(), and get_defender_combatant().
Referenced by choose_defender_weapon().
|
staticprivate |
Definition at line 527 of file attack.cpp.
References attack_type::attack_weight(), attacker_stats_, battle_context(), better_attack(), choose_defender_weapon(), i, log_attack, log_scope2, simulate(), and utf8::size().
Referenced by battle_context().
|
staticprivate |
Definition at line 580 of file attack.cpp.
References _(), attacker_stats_, battle_context(), better_defense(), battle_context_unit_stats::chance_to_hit, battle_context_unit_stats::damage, defender_stats_, attack_type::defense_weight(), i, log_attack, log_scope2, battle_context_unit_stats::num_blows, attack_type::range(), utf8::size(), and VALIDATE.
Referenced by battle_context(), and choose_attacker_weapon().
Get the simulation results.
Definition at line 441 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().
|
inline |
This method returns the statistics of the attacker.
Definition at line 193 of file attack.hpp.
References attacker_stats_.
Referenced by ai::attack_result::do_execute(), events::mouse_handler::fill_weapon_choices(), game_lua_kernel::intf_simulate_combat(), and wfl::attack_callable::weapon().
Definition at line 448 of file attack.cpp.
References defender_combatant_, and simulate().
Referenced by better_attack(), better_defense(), ai::attack_result::do_execute(), and game_lua_kernel::intf_simulate_combat().
|
inline |
This method returns the statistics of the defender.
Definition at line 199 of file attack.hpp.
References defender_stats_.
Referenced by wfl::attack_callable::defender_weapon(), ai::attack_result::do_execute(), and game_lua_kernel::intf_simulate_combat().
|
default |
void battle_context::simulate | ( | const combatant * | prev_def | ) |
Definition at line 373 of file attack.cpp.
References attacker_combatant_, attacker_stats_, defender_combatant_, and defender_stats_.
Referenced by choose_attacker_weapon(), get_attacker_combatant(), and get_defender_combatant().
|
private |
Outcome of simulated fight.
Definition at line 248 of file attack.hpp.
Referenced by get_attacker_combatant(), and simulate().
|
private |
Statistics of the units.
Definition at line 244 of file attack.hpp.
Referenced by battle_context(), choose_attacker_weapon(), choose_defender_weapon(), get_attacker_stats(), and simulate().
|
private |
Definition at line 249 of file attack.hpp.
Referenced by get_defender_combatant(), and simulate().
|
private |
Definition at line 245 of file attack.hpp.
Referenced by battle_context(), choose_defender_weapon(), get_defender_stats(), and simulate().