소스 검색

Merge pull request #4241 from vcmi/fix_damage_estimation

Limit predicted damage / loses to actual stack health
Ivan Savenko 1 년 전
부모
커밋
7ec702bac3
2개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 0
      AI/StupidAI/StupidAI.cpp
  2. 1 1
      lib/battle/DamageCalculator.cpp

+ 9 - 0
AI/StupidAI/StupidAI.cpp

@@ -77,6 +77,15 @@ public:
 		// FIXME: provide distance info for Jousting bonus
 		DamageEstimation retal;
 		DamageEstimation dmg = cb->getBattle(battleID)->battleEstimateDamage(ourStack, s, 0, &retal);
+		// Clip damage dealt to total stack health
+		auto totalHealth = s->getTotalHealth();
+		vstd::amin(dmg.damage.min, totalHealth);
+		vstd::amin(dmg.damage.max, totalHealth);
+
+		auto ourHealth = s->getTotalHealth();
+		vstd::amin(retal.damage.min, ourHealth);
+		vstd::amin(retal.damage.max, ourHealth);
+
 		adi = static_cast<int>((dmg.damage.min + dmg.damage.max) / 2);
 		adr = static_cast<int>((retal.damage.min + retal.damage.max) / 2);
 	}

+ 1 - 1
lib/battle/DamageCalculator.cpp

@@ -509,7 +509,7 @@ int64_t DamageCalculator::getCasualties(int64_t damageDealt) const
 	int64_t damageLeft = damageDealt - info.defender->getFirstHPleft();
 	int64_t killsLeft = damageLeft / info.defender->getMaxHealth();
 
-	return 1 + killsLeft;
+	return std::min<int32_t>(1 + killsLeft, info.defender->getCount());
 }
 
 int DamageCalculator::battleBonusValue(const IBonusBearer * bearer, const CSelector & selector) const