mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Fix handling of double-wide creatures by BattleAI
One of recently added sanity checks was causing crashes during BattleAI decision-making. Actual reason turned out to be due to invalid requests generated by BattleAI when attempting to attack enemy unit from behind with double- wide unit. This change should make BattleAI correctly estimate such attacks
This commit is contained in:
@@ -68,22 +68,28 @@ const BattleHexArray & Unit::getSurroundingHexes(const BattleHex & position, boo
|
||||
|
||||
BattleHexArray Unit::getAttackableHexes(const Unit * attacker) const
|
||||
{
|
||||
const BattleHexArray & defenderHexes = getHexes();
|
||||
|
||||
BattleHexArray targetableHexes;
|
||||
|
||||
for(const auto & defenderHex : defenderHexes)
|
||||
if (!attacker->doubleWide())
|
||||
{
|
||||
auto hexes = battle::Unit::getHexes(defenderHex);
|
||||
|
||||
if(hexes.size() == 2 && BattleHex::getDistance(hexes.front(), hexes.back()) != 1)
|
||||
hexes.pop_back();
|
||||
|
||||
for(const auto & hex : hexes)
|
||||
targetableHexes.insert(hex.getNeighbouringTiles());
|
||||
return getSurroundingHexes();
|
||||
}
|
||||
else
|
||||
{
|
||||
BattleHexArray result;
|
||||
|
||||
return targetableHexes;
|
||||
for (const auto & attackOrigin : getSurroundingHexes())
|
||||
{
|
||||
if (!coversPos(attacker->occupiedHex(attackOrigin)) && attackOrigin.isAvailable())
|
||||
result.insert(attackOrigin);
|
||||
|
||||
bool isAttacker = attacker->unitSide() == BattleSide::ATTACKER;
|
||||
BattleHex::EDir headDirection = isAttacker ? BattleHex::RIGHT : BattleHex::LEFT;
|
||||
BattleHex headHex = attackOrigin.cloneInDirection(headDirection);
|
||||
|
||||
if (!coversPos(headHex) && headHex.isAvailable())
|
||||
result.insert(headHex);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool Unit::coversPos(const BattleHex & pos) const
|
||||
|
||||
Reference in New Issue
Block a user