Add [filter_second_weapon] to leadership and resistance abilities
Closes #2761
(cherry-picked from commit 7f60fb0fbc
)
This commit is contained in:
parent
b79cb16edd
commit
47dd4eb377
6 changed files with 22 additions and 22 deletions
|
@ -183,7 +183,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit& u,
|
|||
resources::gameboard->units(), resources::gameboard->map(), u_loc, u.alignment(), u.is_fearless());
|
||||
|
||||
// Leadership bonus.
|
||||
int leader_bonus = under_leadership(units, u_loc, weapon).first;
|
||||
int leader_bonus = under_leadership(units, u_loc, weapon, opp_weapon).first;
|
||||
if(leader_bonus != 0) {
|
||||
damage_multiplier += leader_bonus;
|
||||
}
|
||||
|
@ -1589,14 +1589,14 @@ void attack_unit_and_advance(const map_location& attacker,
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<int, map_location> under_leadership(const unit_map& units, const map_location& loc, const_attack_ptr weapon)
|
||||
std::pair<int, map_location> under_leadership(const unit_map& units, const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
|
||||
{
|
||||
const unit_map::const_iterator un = units.find(loc);
|
||||
if(un == units.end()) {
|
||||
return {0, map_location::null_location()};
|
||||
}
|
||||
|
||||
unit_ability_list abil = un->get_abilities("leadership", weapon);
|
||||
unit_ability_list abil = un->get_abilities("leadership", weapon, opp_weapon);
|
||||
return abil.highest("value");
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ void attack_unit_and_advance(const map_location& attacker,
|
|||
* Returns a pair of bonus percentage and the leader's location if the unit is affected,
|
||||
* or 0 and map_location::null_location() otherwise.
|
||||
*/
|
||||
std::pair<int, map_location> under_leadership(const unit_map& units, const map_location& loc, const_attack_ptr weapon);
|
||||
std::pair<int, map_location> under_leadership(const unit_map& units, const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon = nullptr);
|
||||
|
||||
/**
|
||||
* Returns the amount that a unit's damage should be multiplied by
|
||||
|
|
|
@ -222,7 +222,7 @@ void attack_predictions::set_data(window& window, const combatant_data& attacker
|
|||
}
|
||||
|
||||
// Leadership bonus.
|
||||
const int leadership_bonus = under_leadership(resources::gameboard->units(), attacker.unit_.get_location(), weapon).first;
|
||||
const int leadership_bonus = under_leadership(resources::gameboard->units(), attacker.unit_.get_location(), weapon, opp_weapon).first;
|
||||
|
||||
if(leadership_bonus != 0) {
|
||||
set_label_helper("leadership_modifier", utils::signed_percent(leadership_bonus));
|
||||
|
|
|
@ -177,14 +177,15 @@ bool unit::get_ability_bool(const std::string& tag_name, const map_location& loc
|
|||
return false;
|
||||
}
|
||||
|
||||
unit_ability_list unit::get_abilities(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon) const
|
||||
unit_ability_list unit::get_abilities(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon) const
|
||||
{
|
||||
unit_ability_list res(loc_);
|
||||
|
||||
for (const config &i : this->abilities_.child_range(tag_name)) {
|
||||
if (ability_active(tag_name, i, loc) &&
|
||||
ability_affects_self(tag_name, i, loc) &&
|
||||
ability_affects_weapon(tag_name, i, loc, weapon))
|
||||
ability_affects_weapon(i, weapon, false) &&
|
||||
ability_affects_weapon(i, opp_weapon, true))
|
||||
{
|
||||
res.push_back(unit_ability(&i, loc));
|
||||
}
|
||||
|
@ -210,7 +211,8 @@ unit_ability_list unit::get_abilities(const std::string& tag_name, const map_loc
|
|||
if (affects_side(j, resources::gameboard->teams(), side(), it->side()) &&
|
||||
it->ability_active(tag_name, j, adjacent[i]) &&
|
||||
ability_affects_adjacent(tag_name, j, i, loc, *it) &&
|
||||
ability_affects_weapon(tag_name, j, adjacent[i], weapon))
|
||||
ability_affects_weapon(j, weapon, false) &&
|
||||
ability_affects_weapon(j, opp_weapon, true))
|
||||
{
|
||||
res.push_back(unit_ability(&j, adjacent[i]));
|
||||
}
|
||||
|
@ -412,21 +414,19 @@ bool unit::ability_affects_self(const std::string& ability,const config& cfg,con
|
|||
return unit_filter(vconfig(filter)).set_use_flat_tod(ability == "illuminates").matches(*this, loc);
|
||||
}
|
||||
|
||||
bool unit::ability_affects_weapon(const std::string&, const config& cfg, const map_location&, const_attack_ptr weapon) const
|
||||
bool unit::ability_affects_weapon(const config& cfg, const_attack_ptr weapon, bool is_opp) const
|
||||
{
|
||||
if(!cfg.has_child("filter_weapon")) {
|
||||
const std::string filter_tag_name = is_opp ? "filter_second_weapon" : "filter_weapon";
|
||||
if(!cfg.has_child(filter_tag_name)) {
|
||||
return true;
|
||||
}
|
||||
const config& filter = cfg.child("filter_weapon");
|
||||
const config& filter = cfg.child(filter_tag_name);
|
||||
if(!weapon) {
|
||||
// Not sure if this is the correct behaviour here
|
||||
return false;
|
||||
}
|
||||
|
||||
return weapon->matches_filter(filter);
|
||||
}
|
||||
|
||||
|
||||
bool unit::has_ability_type(const std::string& ability) const
|
||||
{
|
||||
return !abilities_.child_range(ability).empty();
|
||||
|
|
|
@ -1589,11 +1589,11 @@ bool unit::resistance_filter_matches(const config& cfg, bool attacker, const std
|
|||
return true;
|
||||
}
|
||||
|
||||
int unit::resistance_against(const std::string& damage_name,bool attacker,const map_location& loc, const_attack_ptr weapon) const
|
||||
int unit::resistance_against(const std::string& damage_name,bool attacker,const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon) const
|
||||
{
|
||||
int res = movement_type_.resistance_against(damage_name);
|
||||
|
||||
unit_ability_list resistance_abilities = get_abilities("resistance",loc, weapon);
|
||||
unit_ability_list resistance_abilities = get_abilities("resistance",loc, weapon, opp_weapon);
|
||||
for(unit_ability_list::iterator i = resistance_abilities.begin(); i != resistance_abilities.end();) {
|
||||
if(!resistance_filter_matches(*i->first, attacker, damage_name, 100-res)) {
|
||||
i = resistance_abilities.erase(i);
|
||||
|
|
|
@ -887,7 +887,7 @@ public:
|
|||
* @param attacker True if this unit is on the offensive (to resolve [resistance] abilities)
|
||||
* @param loc The unit's location (to resolve [resistance] abilities)
|
||||
*/
|
||||
int resistance_against(const std::string& damage_name, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const;
|
||||
int resistance_against(const std::string& damage_name, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const;
|
||||
|
||||
/**
|
||||
* The unit's resistance against a given attack
|
||||
|
@ -897,7 +897,7 @@ public:
|
|||
*/
|
||||
int resistance_against(const attack_type& atk, bool attacker, const map_location& loc, const_attack_ptr weapon = nullptr) const
|
||||
{
|
||||
return resistance_against(atk.type(), attacker, loc , weapon);
|
||||
return resistance_against(atk.type(), attacker, loc , weapon, atk.shared_from_this());
|
||||
}
|
||||
|
||||
/** Gets resistances without any abilities applied. */
|
||||
|
@ -1468,16 +1468,16 @@ public:
|
|||
* @param loc The location to use for resolving abilities
|
||||
* @return A list of active abilities, paired with the location they are active on
|
||||
*/
|
||||
unit_ability_list get_abilities(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon = nullptr) const;
|
||||
unit_ability_list get_abilities(const std::string& tag_name, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const;
|
||||
|
||||
/**
|
||||
* Gets the unit's active abilities of a particular type.
|
||||
* @param tag_name The type of ability to check for
|
||||
* @return A list of active abilities, paired with the location they are active on
|
||||
*/
|
||||
unit_ability_list get_abilities(const std::string& tag_name, const_attack_ptr weapon = nullptr) const
|
||||
unit_ability_list get_abilities(const std::string& tag_name, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr) const
|
||||
{
|
||||
return get_abilities(tag_name, loc_, weapon);
|
||||
return get_abilities(tag_name, loc_, weapon, opp_weapon);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1543,7 +1543,7 @@ private:
|
|||
*/
|
||||
bool ability_affects_self(const std::string& ability, const config& cfg, const map_location& loc) const;
|
||||
|
||||
bool ability_affects_weapon(const std::string& ability,const config& cfg,const map_location& loc, const_attack_ptr weapon) const;
|
||||
bool ability_affects_weapon(const config& cfg, const_attack_ptr weapon, bool is_opp) const;
|
||||
|
||||
public:
|
||||
/** Get the unit formula manager. */
|
||||
|
|
Loading…
Add table
Reference in a new issue