Public Member Functions | Private Member Functions | Private Attributes

battle_context Class Reference

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

#include <actions.hpp>

Collaboration diagram for battle_context:
Collaboration graph
[legend]

List of all members.

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=NULL, const unit *attacker_ptr=NULL)
 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 (const battle_context &other)
 ~battle_context ()
battle_contextoperator= (const battle_context &other)
const battle_context_unit_statsget_attacker_stats () const
 This method returns the statistics of the attacker.
const battle_context_unit_statsget_defender_stats () const
 This method returns the statistics of the defender.
const combatantget_attacker_combatant (const combatant *prev_def=NULL)
 Get the simulation results.
const combatantget_defender_combatant (const combatant *prev_def=NULL)
bool better_attack (class battle_context &that, double harm_weight)
 Given this harm_weight, is this attack better than that?

Private Member Functions

bool better_combat (const combatant &us_a, const combatant &them_a, const combatant &us_b, const combatant &them_b, double harm_weight)
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

battle_context_unit_statsattacker_stats_
 Statistics of the units.
battle_context_unit_statsdefender_stats_
combatantattacker_combatant_
 Outcome of simulated fight.
combatantdefender_combatant_

Detailed Description

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

Definition at line 177 of file actions.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 = NULL,
const unit attacker_ptr = NULL 
)

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 720 of file actions.cpp.

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

Here is the call graph for this function:

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 769 of file actions.cpp.

battle_context::battle_context ( const battle_context other  ) 

Definition at line 763 of file actions.cpp.

battle_context::~battle_context (  ) 

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 1207 of file actions.cpp.

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

Here is the call graph for this function:

bool battle_context::better_combat ( const combatant us_a,
const combatant them_a,
const combatant us_b,
const combatant them_b,
double  harm_weight 
) [private]

Definition at line 959 of file actions.cpp.

References combatant::average_hp(), combatant::hp_dist, game_config::poison_amount, and combatant::poisoned.

Referenced by better_attack(), choose_attacker_weapon(), and choose_defender_weapon().

Here is the call graph for this function:

Here is the caller graph for this function:

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]

Definition at line 882 of file actions.cpp.

References battle_context_unit_stats::attack_num, attack_type::attack_weight(), attacker_combatant_, attacker_stats_, unit::attacks(), better_combat(), choose_defender_weapon(), defender_combatant_, defender_stats_, and combatant::fight().

Referenced by battle_context().

Here is the call graph for this function:

Here is the caller graph for this function:

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 = NULL  ) 

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 991 of file actions.cpp.

References attacker_combatant_, attacker_stats_, defender_combatant_, defender_stats_, and combatant::fight().

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

Here is the call graph for this function:

Here is the caller graph for this function:

const battle_context_unit_stats& battle_context::get_attacker_stats (  )  const [inline]

This method returns the statistics of the attacker.

Definition at line 200 of file actions.hpp.

References attacker_stats_.

Referenced by ai::attack_analysis::analyze(), battle_prediction_pane::battle_prediction_pane(), attack::perform(), attack::refresh_bc(), unit_weapons(), and game_logic::attack_callable::weapon().

Here is the caller graph for this function:

const combatant & battle_context::get_defender_combatant ( const combatant prev_def = NULL  ) 

Definition at line 1003 of file actions.cpp.

References attacker_combatant_, attacker_stats_, defender_combatant_, defender_stats_, and combatant::fight().

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

Here is the call graph for this function:

Here is the caller graph for this function:

const battle_context_unit_stats& battle_context::get_defender_stats (  )  const [inline]

This method returns the statistics of the defender.

Definition at line 203 of file actions.hpp.

References defender_stats_.

Referenced by ai::attack_analysis::analyze(), battle_prediction_pane::battle_prediction_pane(), game_logic::attack_callable::defender_weapon(), attack::perform(), attack::refresh_bc(), and unit_weapons().

Here is the caller graph for this function:

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

Member Data Documentation


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:13:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs