22 #ifndef ACTIONS_ATTACK_H_INCLUDED
23 #define ACTIONS_ATTACK_H_INCLUDED
39 inline unsigned swarm_blows(
unsigned min_blows,
unsigned max_blows,
unsigned hp,
42 return hp >= max_hp ? max_blows :
43 max_blows < min_blows ? min_blows - (min_blows-max_blows) * hp / max_hp :
44 min_blows + (max_blows-min_blows) * hp / max_hp;
86 int u_attack_num,
bool attacking,
95 unsigned int opp_terrain_defense,
96 int lawful_bonus = 0);
104 {
return swarm_blows(swarm_min, swarm_max, new_hp, max_hp); }
106 #if defined(BENCHMARK) || defined(CHECK)
110 int hit_chance,
bool drain,
bool slows,
bool slowed,
111 bool berserk,
bool first,
bool do_swarm) :
112 weapon(nullptr), attack_num(0), is_attacker(true),
113 is_poisoned(false), is_slowed(slowed),
114 slows(slows), drains(drain), petrifies(false), plagues(false),
115 poisons(false), backstab_pos(false), swarm(do_swarm), firststrike(first), disable(false),
116 experience(0), max_experience(50), level(1),
117 rounds(berserk ? 30 : 1),
118 hp(
std::max<
int>(0, hitpoints)), max_hp(
std::max<
int>(1, maximum_hp)),
119 chance_to_hit(hit_chance),
121 drain_percent(drain ? 50 : 0), drain_constant(0),
122 num_blows(do_swarm ? blows * hp / max_hp : blows),
123 swarm_min(do_swarm ? 0 : blows), swarm_max(blows),
147 int attacker_weapon = -1,
int defender_weapon = -1,
148 double aggression = 0.0,
const combatant *prev_def =
nullptr,
149 const unit* attacker_ptr=
nullptr);
180 double harm_weight,
int *defender_weapon,
184 unsigned attacker_weapon,
const unit_map& units,
198 int attack_with,
int defend_with,
bool update_display =
true);
202 int attack_with,
int defend_with,
bool update_display =
true,
unsigned int calc_blows(unsigned new_hp) const
Calculates the number of blows we would have if we had new_hp.
const ai::unit_advancements_aspect * ai_advancements_
std::string plague_type
The plague type used by the attack, if any.
void advance_unit_at(const advance_unit_params ¶ms)
unsigned int hp
Hitpoints of the unit at the beginning of the battle.
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)
static bool better_combat(const combatant &us_a, const combatant &them_a, const combatant &us_b, const combatant &them_b, double harm_weight)
const combatant & get_attacker_combatant(const combatant *prev_def=nullptr)
Get the simulation results.
unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to)
Returns the advanced version of a unit (with traits and items retained).
friend void advance_unit_at(const advance_unit_params &)
advance_unit_params & force_dialog(bool value)
bool is_slowed
True if the unit is slowed at the beginning of the battle.
battle_context_unit_stats * attacker_stats_
Statistics of the units.
const attack_type * weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
advance_unit_params & fire_events(bool value)
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 cou...
bool slows
Attack slows opponent when it hits.
int drain_constant
Base HP drained regardless of damage dealt.
const map_location & loc_
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
void attack_unit(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true)
Performs an attack.
advance_unit_params & animate(bool value)
void attack_unit_and_advance(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true, const ai::unit_advancements_aspect &ai_advancement=ai::unit_advancements_aspect())
Performs an attack, and advanced the units afterwards.
bool poisons
Attack poisons opponent when it hits.
const combatant & get_defender_combatant(const combatant *prev_def=nullptr)
static std::vector< team > *& teams
bool backstab_pos
True if the attacker is in position to backstab the defender (this is used to determine whether to ap...
This class stores all the data for a single 'side' (in game nomenclature).
int damage
Effective damage of the weapon (all factors accounted for).
combatant * defender_combatant_
unsigned int rounds
Berserk special can force us to fight more than one round.
unsigned int swarm_min
Minimum number of blows with swarm (equal to num_blows if swarm isn't used).
GLsizei const GLfloat * value
advance_unit_params & ai_advancements(const ai::unit_advancements_aspect &value)
const battle_context_unit_stats & get_defender_stats() const
This method returns the statistics of the defender.
bool plagues
Attack turns opponent into a zombie when fatal.
bool better_attack(class battle_context &that, double harm_weight)
Given this harm_weight, is this attack better than that?
Encapsulates the map of the game.
Computes the statistics of a battle between an attacker and a defender unit.
int attack_num
Index into unit->attacks() or -1 for none.
Structure describing the statistics of a unit involved in the battle.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
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)
advances the unit at loc if it has enough experience, maximum 20 times.
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.
Encapsulates the map of the game.
battle_context_unit_stats(const unit &u, const map_location &u_loc, int u_attack_num, bool attacking, const unit &opp, const map_location &opp_loc, const attack_type *opp_weapon, const unit_map &units)
unsigned swarm_blows(unsigned min_blows, unsigned max_blows, unsigned hp, unsigned max_hp)
Calculates the number of blows resulting from swarm.
battle_context & operator=(const battle_context &other)
int round_damage(int base_damage, int bonus, int divisor)
round (base_damage * bonus / divisor) to the closest integer, but up or down towards base_damage ...
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...
bool swarm
Attack has swarm special.
int slow_damage
Effective damage if unit becomes slowed (== damage, if already slowed)
~battle_context_unit_stats()
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.
combatant * attacker_combatant_
Outcome of simulated fight.
bool disable
Attack has disable special.
bool firststrike
Attack has firststrike special.
bool is_poisoned
True if the unit is poisoned at the beginning of the battle.
advance_unit_params(const map_location &loc)
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
void advance_unit(map_location loc, const std::string &advance_to, const bool &fire_event=true, const config *mod_option=nullptr)
Function which will advance the unit at loc to 'advance_to'.
int drain_percent
Percentage of damage recovered as health.
Container associating units to locations.
unsigned int num_blows
Effective number of blows, takes swarm into account.
unsigned int max_hp
Maximum hitpoints of the unit.
const battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
bool is_attacker
True if the unit is the attacker.
unsigned int max_experience
bool petrifies
Attack petrifies opponent when it hits.
A config object defines a single node in a WML file, with access to child nodes.
map_location under_leadership(const unit_map &units, const map_location &loc, int *bonus=nullptr)
function which tests if the unit at loc is currently affected by leadership.
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
Returns the AMLA-advanced version of a unit (with traits and items retained).
bool drains
Attack drains opponent when it hits.
GLsizei const GLcharARB ** string
battle_context_unit_stats * defender_stats_
unsigned int swarm_max
Maximum number of blows with swarm (equal to num_blows if swarm isn't used).