resolve problem of negative value for leadership (#3774)

This commit is contained in:
newfrenchy83 2018-12-23 16:37:08 +01:00 committed by jostephd
parent 0e2b415177
commit 4bb1b4a8e4
3 changed files with 5 additions and 4 deletions

View file

@ -1567,7 +1567,9 @@ void attack_unit_and_advance(const map_location& attacker,
int under_leadership(const unit &u, const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon)
{
unit_ability_list abil = u.get_abilities("leadership", loc, weapon, opp_weapon);
return abil.highest("value").first;
int leader_up = std::max(0, abil.highest("value").first);
int leader_down = std::min(0, abil.lowest("value").first);
return leader_up + leader_down;
}
//begin of weapon emulates function.

View file

@ -278,7 +278,7 @@ void attack_unit_and_advance(const map_location& attacker,
*
* Returns the bonus percentage (possibly 0 if there's no leader adjacent).
*/
int under_leadership(const unit &u, const map_location& loc, const_attack_ptr weapon, const_attack_ptr opp_weapon = nullptr);
int under_leadership(const unit &u, const map_location& loc, const_attack_ptr weapon = nullptr, const_attack_ptr opp_weapon = nullptr);
bool leadership_affects_self(const std::string& ability,const unit_map& units, const map_location& loc, bool attacker=true, const_attack_ptr weapon=nullptr,const_attack_ptr opp_weapon=nullptr);
bool leadership_affects_opponent(const std::string& ability,const unit_map& units, const map_location& loc, bool attacker=true, const_attack_ptr weapon=nullptr,const_attack_ptr opp_weapon=nullptr);
std::pair<int, bool> ability_leadership(const std::string& ability, const unit_map& units, const map_location& loc, const map_location& opp_loc, bool attacker=true, int abil_value=0, bool backstab_pos=false, const_attack_ptr weapon=nullptr, const_attack_ptr opp_weapon=nullptr);

View file

@ -259,8 +259,7 @@ void aspect_attacks_base::do_attack_analysis(
}
}
unit_ability_list abil = unit_itor->get_abilities("leadership",tiles[j]);
int best_leadership_bonus = abil.highest("value").first;
int best_leadership_bonus = under_leadership(*unit_itor, tiles[j]);
double leadership_bonus = static_cast<double>(best_leadership_bonus+100)/100.0;
if (leadership_bonus > 1.1) {
LOG_AI << unit_itor->name() << " is getting leadership " << leadership_bonus << "\n";