40 inline unsigned swarm_blows(
unsigned min_blows,
unsigned max_blows,
unsigned hp,
unsigned max_hp)
44 : max_blows < min_blows
45 ? min_blows - (min_blows - max_blows) * hp / max_hp
46 : min_blows + (max_blows - min_blows) * hp / max_hp;
96 unsigned int opp_terrain_defense,
97 int lawful_bonus = 0);
109 #if defined(BENCHMARK) || defined(CHECK)
141 ,
rounds(berserk ? 30 : 1)
142 ,
hp(std::max<int>(0, hitpoints))
143 ,
max_hp(std::max<int>(1, maximum_hp))
145 ,
damage(std::max(0, dmg))
178 int attacker_weapon = -1,
179 int defender_weapon = -1,
180 double aggression = 0.0,
227 int defender_weapon);
238 unsigned attacker_weapon,
257 bool update_display =
true);
264 bool update_display =
true);
312 const std::vector<team>& teams);
void attack_unit(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true)
Performs an attack.
int generic_combat_modifier(int lawful_bonus, unit_alignments::type alignment, bool is_fearless, int max_liminal_bonus)
Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus.
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.
int combat_modifier(const unit_map &units, const gamemap &map, const map_location &loc, unit_alignments::type alignment, bool is_fearless)
Returns the amount that a unit's damage should be multiplied by due to the current time of day.
unsigned swarm_blows(unsigned min_blows, unsigned max_blows, unsigned hp, unsigned max_hp)
Calculates the number of blows resulting from swarm.
int under_leadership(const unit &u, const map_location &loc, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr)
Tests if the unit at loc is currently affected by leadership.
void attack_unit_and_advance(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true)
Performs an attack, and advanced the units afterwards.
Computes the statistics of a battle between an attacker and a defender unit.
std::unique_ptr< battle_context_unit_stats > defender_stats_
std::unique_ptr< combatant > defender_combatant_
std::unique_ptr< battle_context_unit_stats > attacker_stats_
Statistics of the units.
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)
std::unique_ptr< combatant > attacker_combatant_
Outcome of simulated fight.
void simulate(const combatant *prev_def)
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 battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
battle_context(battle_context &&other)=default
battle_context & operator=(battle_context &&other)=default
const combatant & get_defender_combatant(const combatant *prev_def=nullptr)
static bool better_combat(const combatant &us_a, const combatant &them_a, const combatant &us_b, const combatant &them_b, double harm_weight)
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)
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 cou...
bool better_defense(class battle_context &that, double harm_weight)
Given this harm_weight, is this attack better than that?
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.
This class stores all the data for a single 'side' (in game nomenclature).
Container associating units to locations.
A single unit type that the player may recruit.
This class represents a single unit of a specific type.
constexpr 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
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< const attack_type > const_attack_ptr
Structure describing the statistics of a unit involved in the battle.
bool slows
Attack slows opponent when it hits.
unsigned int num_blows
Effective number of blows, takes swarm into account.
std::string plague_type
The plague type used by the attack, if any.
battle_context_unit_stats(nonempty_unit_const_ptr u, const map_location &u_loc, int u_attack_num, bool attacking, nonempty_unit_const_ptr opp, const map_location &opp_loc, const const_attack_ptr &opp_weapon)
bool petrifies
Attack petrifies opponent when it hits.
int drain_percent
Percentage of damage recovered as health.
unsigned int hp
Hitpoints of the unit at the beginning of the battle.
int slow_damage
Effective damage if unit becomes slowed (== damage, if already slowed)
unsigned int max_experience
bool drains
Attack drains opponent when it hits.
unsigned int swarm_min
Minimum number of blows with swarm (equal to num_blows if swarm isn't used).
bool swarm
Attack has swarm special.
bool is_attacker
True if the unit is the attacker.
~battle_context_unit_stats()
bool is_poisoned
True if the unit is poisoned at the beginning of the battle.
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
bool is_slowed
True if the unit is slowed at the beginning of the battle.
unsigned int rounds
Berserk special can force us to fight more than one round.
unsigned int swarm_max
Maximum number of blows with swarm (equal to num_blows if swarm isn't used).
unsigned int calc_blows(unsigned new_hp) const
Calculates the number of blows we would have if we had new_hp instead of the recorded hp.
unsigned int max_hp
Maximum hitpoints of the unit.
int damage
Effective damage of the weapon (all factors accounted for).
bool disable
Attack has disable special.
bool poisons
Attack poisons opponent when it hits.
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
int drain_constant
Base HP drained regardless of damage dealt.
bool firststrike
Attack has firststrike special.
int attack_num
Index into unit->attacks() or -1 for none.
bool plagues
Attack turns opponent into a zombie when fatal.
Encapsulates the map of the game.
Object which defines a time of day with associated bonuses, image, sounds etc.