mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	BattleAI: stacks should not measure damage against turret
This commit is contained in:
		| @@ -50,7 +50,22 @@ int64_t AttackPossibility::calculateDamageReduce( | ||||
| 	vstd::amin(damageDealt, defender->getAvailableHealth()); | ||||
|  | ||||
| 	// FIXME: provide distance info for Jousting bonus | ||||
| 	auto enemyDamageBeforeAttack = cb.battleEstimateDamage(defender, attacker, 0); | ||||
| 	auto attackerUnitForMeasurement = attacker; | ||||
|  | ||||
| 	if(attackerUnitForMeasurement->isTurret()) | ||||
| 	{ | ||||
| 		auto ourUnits = cb.battleGetUnitsIf([&](const battle::Unit * u) -> bool | ||||
| 			{ | ||||
| 				return u->unitSide() == attacker->unitSide() && !u->isTurret(); | ||||
| 			}); | ||||
|  | ||||
| 		if(ourUnits.empty()) | ||||
| 			attackerUnitForMeasurement = defender; | ||||
| 		else | ||||
| 			attackerUnitForMeasurement = ourUnits.front(); | ||||
| 	} | ||||
|  | ||||
| 	auto enemyDamageBeforeAttack = cb.battleEstimateDamage(defender, attackerUnitForMeasurement, 0); | ||||
| 	auto enemiesKilled = damageDealt / defender->getMaxHealth() + (damageDealt % defender->getMaxHealth() >= defender->getFirstHPleft() ? 1 : 0); | ||||
| 	auto enemyDamage = averageDmg(enemyDamageBeforeAttack.damage); | ||||
| 	auto damagePerEnemy = enemyDamage / (double)defender->getCount(); | ||||
|   | ||||
| @@ -386,9 +386,13 @@ int64_t BattleExchangeEvaluator::calculateExchange( | ||||
|  | ||||
| 	for(auto unit : exchangeUnits) | ||||
| 	{ | ||||
| 		if(unit->isTurret()) | ||||
| 			continue; | ||||
|  | ||||
| 		bool isOur = cb->battleMatchOwner(ap.attack.attacker, unit, true); | ||||
| 		auto & attackerQueue = isOur ? ourStacks : enemyStacks; | ||||
|  | ||||
|  | ||||
| 		if(!vstd::contains(attackerQueue, unit)) | ||||
| 		{ | ||||
| 			attackerQueue.push_back(unit); | ||||
| @@ -593,6 +597,9 @@ void BattleExchangeEvaluator::updateReachabilityMap(HypotheticBattle & hb) | ||||
|  | ||||
| 		for(const battle::Unit * unit : turnQueue) | ||||
| 		{ | ||||
| 			if(unit->isTurret()) | ||||
| 				continue; | ||||
|  | ||||
| 			if(turnBattle.battleCanShoot(unit)) | ||||
| 			{ | ||||
| 				for(BattleHex hex = BattleHex::TOP_LEFT; hex.isValid(); hex = hex + 1) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user