mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Merge pull request #4161 from vcmi/fix-4142
#4142 - sometimes Battle AI wants to attack unit which is behind a lo…
This commit is contained in:
commit
a9cf322f61
@ -259,27 +259,46 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
|
|||||||
return BattleAction::makeDefend(stack);
|
return BattleAction::makeDefend(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(hexes.begin(), hexes.end(), [&](BattleHex h1, BattleHex h2) -> bool
|
std::vector<BattleHex> targetHexes = hexes;
|
||||||
{
|
|
||||||
return reachability.distances[h1] < reachability.distances[h2];
|
|
||||||
});
|
|
||||||
|
|
||||||
for(auto hex : hexes)
|
for(int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
if(vstd::contains(avHexes, hex))
|
std::sort(targetHexes.begin(), targetHexes.end(), [&](BattleHex h1, BattleHex h2) -> bool
|
||||||
|
{
|
||||||
|
return reachability.distances[h1] < reachability.distances[h2];
|
||||||
|
});
|
||||||
|
|
||||||
|
for(auto hex : targetHexes)
|
||||||
{
|
{
|
||||||
return BattleAction::makeMove(stack, hex);
|
if(vstd::contains(avHexes, hex))
|
||||||
|
{
|
||||||
|
return BattleAction::makeMove(stack, hex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stack->coversPos(hex))
|
||||||
|
{
|
||||||
|
logAi->warn("Warning: already standing on neighbouring tile!");
|
||||||
|
//We shouldn't even be here...
|
||||||
|
return BattleAction::makeDefend(stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stack->coversPos(hex))
|
if(reachability.distances[targetHexes.front()] <= GameConstants::BFIELD_SIZE)
|
||||||
{
|
{
|
||||||
logAi->warn("Warning: already standing on neighbouring tile!");
|
break;
|
||||||
//We shouldn't even be here...
|
|
||||||
return BattleAction::makeDefend(stack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<BattleHex> copy = targetHexes;
|
||||||
|
|
||||||
|
for(auto hex : copy)
|
||||||
|
{
|
||||||
|
vstd::concatenate(targetHexes, hex.allNeighbouringTiles());
|
||||||
|
}
|
||||||
|
|
||||||
|
vstd::removeDuplicates(targetHexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleHex bestNeighbor = hexes.front();
|
BattleHex bestNeighbor = targetHexes.front();
|
||||||
|
|
||||||
if(reachability.distances[bestNeighbor] > GameConstants::BFIELD_SIZE)
|
if(reachability.distances[bestNeighbor] > GameConstants::BFIELD_SIZE)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user