Various functions that implement attacks and attack calculations. More...
Go to the source code of this file.
Classes | |
struct | battle_context_unit_stats |
Structure describing the statistics of a unit involved in the battle. More... | |
class | battle_context |
Computes the statistics of a battle between an attacker and a defender unit. More... | |
struct | advance_unit_params |
advances the unit at loc if it has enough experience, maximum 20 times. More... | |
Functions | |
unsigned | swarm_blows (unsigned min_blows, unsigned max_blows, unsigned hp, unsigned max_hp) |
Calculates the number of blows resulting from swarm. More... | |
void | attack_unit (const map_location &attacker, const map_location &defender, int attack_with, int defend_with, bool update_display=true) |
Performs an attack. More... | |
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. More... | |
void | advance_unit_at (const advance_unit_params ¶ms) |
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). More... | |
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). More... | |
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'. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
Various functions that implement attacks and attack calculations.
Unit advancements are also included, as they usually occur as a result of combat.
Definition in file attack.hpp.
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'.
(Unless mod_option is supplied, in which case an AMLA is performed.) Note that 'loc' is not a reference, because if it were a reference, we couldn't safely pass in a reference to the item in the map that we're going to delete, since deletion would invalidate the reference.
Definition at line 1573 of file attack.cpp.
References actions::actor_sighted(), statistics::advance_unit(), actions::shroud_clearer::clear_unit(), preferences::encountered_units(), unit_map::find(), game_events::t_pump::fire(), actions::shroud_clearer::fire_events(), resources::game_events, get_advanced_unit(), get_amla_unit(), actions::get_sides_not_seeing(), LOG_CF, LOG_NG, game_events::manager::pump(), unit_map::replace(), resources::units, unit_map::iterator_base< iter_types >::valid(), and resources::whiteboard.
Referenced by dialogs::animate_unit_advancement(), and ai::helper_advance_unit().
void advance_unit_at | ( | const advance_unit_params & | params | ) |
Definition at line 1478 of file attack.cpp.
References advance_unit_params::ai_advancements_, advance_unit_params::animate_, dialogs::animate_unit_advancement(), DBG_NG, ERR_NG, unit_map::find(), game_events::t_pump::fire(), advance_unit_params::fire_events_, advance_unit_params::force_dialog_, resources::game_events, resources::gamedata, mp_sync::get_user_choice(), advance_unit_params::loc_, LOG_NG, unit_helper::number_of_possible_advances(), game_data::phase(), game_data::PLAY, game_events::manager::pump(), game_config::images::selected, resources::units, unit_map::iterator_base< iter_types >::valid(), unit_helper::will_certainly_advance(), and WRN_NG.
Referenced by advance_unit_at(), attack_unit_and_advance(), intf_advance_unit(), and SYNCED_COMMAND_HANDLER_FUNCTION().
void attack_unit | ( | const map_location & | attacker, |
const map_location & | defender, | ||
int | attack_with, | ||
int | defend_with, | ||
bool | update_display = true |
||
) |
Performs an attack.
Definition at line 1384 of file attack.cpp.
Referenced by attack_unit_and_advance(), and ai::simulated_attack().
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.
Definition at line 1524 of file attack.cpp.
References advance_unit_at(), attack_unit(), unit_map::find(), and resources::units.
Referenced by ai::attack_result::do_execute(), and SYNCED_COMMAND_HANDLER_FUNCTION().
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.
Input:
Definition at line 1684 of file attack.cpp.
References unit_map::end(), unit_map::find(), get_adjacent_tiles(), and i.
Referenced by battle_context_unit_stats::battle_context_unit_stats(), and ai::ai_default_rca::aspect_attacks_base::do_attack_analysis().
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.
Definition at line 1649 of file attack.cpp.
References generic_combat_modifier(), tod_manager::get_illuminated_time_of_day(), time_of_day::lawful_bonus, and resources::tod_manager.
Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), battle_prediction_pane::get_unit_strings(), and unit_alignment().
Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus.
Definition at line 1657 of file attack.cpp.
Referenced by battle_context_unit_stats::battle_context_unit_stats(), and combat_modifier().
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).
Definition at line 1541 of file attack.cpp.
References unit_type_data::find(), unit::STATE_PETRIFIED, unit::STATE_POISONED, unit::STATE_SLOWED, and unit_types.
Referenced by advance_unit(), and dialogs::advance_unit_dialog().
Returns the AMLA-advanced version of a unit (with traits and items retained).
Definition at line 1564 of file attack.cpp.
Referenced by advance_unit(), and dialogs::advance_unit_dialog().
|
inline |
Calculates the number of blows resulting from swarm.
Definition at line 39 of file attack.hpp.
Referenced by attack_info(), and battle_context_unit_stats::calc_blows().
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.
(i.e. has a higher-level 'leadership' unit next to it). If it does, then the location of the leader unit will be returned, Otherwise map_location::null_location() will be returned. If 'bonus' is not nullptr, the % bonus will be stored in it.
Definition at line 1635 of file attack.cpp.
References unit_map::end(), unit_map::find(), unit_ability_list::highest(), and map_location::null_location().
Referenced by attack_info(), battle_context_unit_stats::battle_context_unit_stats(), and battle_prediction_pane::get_unit_strings().