Skip to content

Commit

Permalink
Improve AI behavior for Ghosts during battle
Browse files Browse the repository at this point in the history
Since Ghosts have Soul Eater ability it is important to calculate the possible growth of their numbers after the attack.

close #7685
  • Loading branch information
ihhub committed Sep 16, 2023
1 parent 6c040c7 commit ee6064c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/fheroes2/battle/battle_troop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,8 @@ int32_t Battle::Unit::GetScoreQuality( const Unit & defender ) const
const double attackerPowerLost = ( attacker.Modes( CAP_MIRRORIMAGE ) || defender.Modes( CAP_TOWER ) || defendersDamage >= hp ) ? 1.0 : defendersDamage / hp;
const bool attackerIsArchers = isArchers();

double attackerThreat = CalculateDamageUnit( defender, ( static_cast<double>( GetDamageMin() ) + GetDamageMax() ) / 2.0 );
const uint32_t initialDamage = CalculateDamageUnit( defender, ( static_cast<double>( GetDamageMin() ) + GetDamageMax() ) / 2.0 );
double attackerThreat = initialDamage;

if ( !canReach( defender ) && !defender.Modes( CAP_TOWER ) && !attackerIsArchers ) {
// Can't reach, so unit is not dangerous to defender at the moment
Expand Down Expand Up @@ -1188,6 +1189,11 @@ int32_t Battle::Unit::GetScoreQuality( const Unit & defender ) const
if ( !attackerIsArchers || defender.isArchers() )
attackerThreat *= attackerPowerLost;

if ( defender.isAbilityPresent( fheroes2::MonsterAbilityType::SOUL_EATER ) ) {
const uint32_t killedMonsters = HowManyWillBeKilled( initialDamage );
attackerThreat += ( killedMonsters * defender.GetHitPoints() );
}

return static_cast<int>( attackerThreat * 100 );
}

Expand Down

0 comments on commit ee6064c

Please sign in to comment.