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;
101 unsigned int opp_terrain_defense,
102 int lawful_bonus = 0);
111 return swarm_blows(swarm_min, swarm_max, new_hp, max_hp);
114 #if defined(BENCHMARK) || defined(CHECK) 147 ,
rounds(berserk ? 30 : 1)
148 ,
hp(std::max<int>(0, hitpoints))
149 ,
max_hp(std::max<int>(1, maximum_hp))
151 ,
damage(std::max(0, dmg))
155 ,
num_blows(do_swarm ? blows * hp / max_hp : blows)
184 int attacker_weapon = -1,
185 int defender_weapon = -1,
186 double aggression = 0.0,
201 return *attacker_stats_;
207 return *defender_stats_;
215 bool better_attack(
class battle_context& that,
double harm_weight);
217 bool better_defense(
class battle_context& that,
double harm_weight);
219 static bool better_combat(
const combatant& us_a,
225 void simulate(
const combatant* prev_def);
246 unsigned attacker_weapon,
266 bool update_display =
true);
273 bool update_display =
true);
290 UNIT_ALIGNMENT alignment,
298 UNIT_ALIGNMENT alignment,
305 int generic_combat_modifier(
int lawful_bonus, UNIT_ALIGNMENT alignment,
bool is_fearless,
int max_liminal_bonus);
321 const std::vector<team>& teams);
const_attack_ptr weapon
The weapon used by the unit to attack the opponent, or nullptr if there is none.
std::unique_ptr< combatant > attacker_combatant_
Outcome of simulated fight.
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...
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.
std::string plague_type
The plague type used by the attack, if any.
This class represents a single unit of a specific type.
const battle_context_unit_stats & get_defender_stats() const
This method returns the statistics of the defender.
unsigned int hp
Hitpoints of the unit at the beginning of the battle.
bool is_slowed
True if the unit is slowed at the beginning of the battle.
bool slows
Attack slows opponent when it hits.
int drain_constant
Base HP drained regardless of damage dealt.
unsigned int chance_to_hit
Effective chance to hit as a percentage (all factors accounted for).
A single unit type that the player may recruit.
void attack_unit(const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true)
Performs an attack.
bool poisons
Attack poisons opponent when it hits.
std::shared_ptr< const unit > unit_const_ptr
Object which defines a time of day with associated bonuses, image, sounds etc.
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).
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.
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).
int generic_combat_modifier(int lawful_bonus, UNIT_ALIGNMENT 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.
std::unique_ptr< battle_context_unit_stats > defender_stats_
bool plagues
Attack turns opponent into a zombie when fatal.
int combat_modifier(const unit_map &units, const gamemap &map, const map_location &loc, UNIT_ALIGNMENT alignment, bool is_fearless)
Returns the amount that a unit's damage should be multiplied by due to the current time of day...
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.
std::unique_ptr< battle_context_unit_stats > attacker_stats_
Statistics of the units.
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.
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 ...
unsigned swarm_blows(unsigned min_blows, unsigned max_blows, unsigned hp, unsigned max_hp)
Calculates the number of blows resulting from swarm.
bool swarm
Attack has swarm special.
int slow_damage
Effective damage if unit becomes slowed (== damage, if already slowed)
~battle_context_unit_stats()
std::unique_ptr< combatant > defender_combatant_
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.
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.
bool is_attacker
True if the unit is the attacker.
unsigned int max_experience
bool petrifies
Attack petrifies opponent when it hits.
std::shared_ptr< const attack_type > const_attack_ptr
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_attack_ptr opp_weapon, const unit_map &units)
bool drains
Attack drains opponent when it hits.
const battle_context_unit_stats & get_attacker_stats() const
This method returns the statistics of the attacker.
unsigned int swarm_max
Maximum number of blows with swarm (equal to num_blows if swarm isn't used).