mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Fixes crashes on trying to evaluate attacks of two double-wide melee units
This commit is contained in:
@@ -246,7 +246,6 @@ void CStack::prepareAttacked(BattleStackAttacked & bsa, vstd::RNG & rand, const
|
|||||||
|
|
||||||
BattleHexArray CStack::meleeAttackHexes(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos, BattleHex defenderPos)
|
BattleHexArray CStack::meleeAttackHexes(const battle::Unit * attacker, const battle::Unit * defender, BattleHex attackerPos, BattleHex defenderPos)
|
||||||
{
|
{
|
||||||
int mask = 0;
|
|
||||||
BattleHexArray res;
|
BattleHexArray res;
|
||||||
|
|
||||||
if (!attackerPos.isValid())
|
if (!attackerPos.isValid())
|
||||||
@@ -254,44 +253,16 @@ BattleHexArray CStack::meleeAttackHexes(const battle::Unit * attacker, const bat
|
|||||||
if (!defenderPos.isValid())
|
if (!defenderPos.isValid())
|
||||||
defenderPos = defender->getPosition();
|
defenderPos = defender->getPosition();
|
||||||
|
|
||||||
BattleHex otherAttackerPos = attackerPos.toInt() + (attacker->unitSide() == BattleSide::ATTACKER ? -1 : 1);
|
BattleHexArray attackableHxs = attacker->doubleWide() ? attackerPos.getNeighbouringTilesDoubleWide(attacker->unitSide()) : attackerPos.getNeighbouringTiles();
|
||||||
BattleHex otherDefenderPos = defenderPos.toInt() + (defender->unitSide() == BattleSide::ATTACKER ? -1 : 1);
|
|
||||||
|
|
||||||
if(BattleHex::mutualPosition(attackerPos, defenderPos) >= 0) //front <=> front
|
if (std::find(attackableHxs.begin(), attackableHxs.end(), defenderPos) != attackableHxs.end())
|
||||||
{
|
|
||||||
if((mask & 1) == 0)
|
|
||||||
{
|
|
||||||
mask |= 1;
|
|
||||||
res.insert(defenderPos);
|
res.insert(defenderPos);
|
||||||
}
|
if (defender->doubleWide())
|
||||||
}
|
|
||||||
if (attacker->doubleWide() //back <=> front
|
|
||||||
&& BattleHex::mutualPosition(otherAttackerPos, defenderPos) >= 0)
|
|
||||||
{
|
{
|
||||||
if((mask & 1) == 0)
|
BattleHex otherDefenderPos = defenderPos.toInt() + (defender->unitSide() == BattleSide::ATTACKER ? -1 : 1);
|
||||||
{
|
if (std::find(attackableHxs.begin(), attackableHxs.end(), otherDefenderPos) != attackableHxs.end())
|
||||||
mask |= 1;
|
|
||||||
res.insert(defenderPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (defender->doubleWide()//front <=> back
|
|
||||||
&& BattleHex::mutualPosition(attackerPos, otherDefenderPos) >= 0)
|
|
||||||
{
|
|
||||||
if((mask & 2) == 0)
|
|
||||||
{
|
|
||||||
mask |= 2;
|
|
||||||
res.insert(otherDefenderPos);
|
res.insert(otherDefenderPos);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (defender->doubleWide() && attacker->doubleWide()//back <=> back
|
|
||||||
&& BattleHex::mutualPosition(otherAttackerPos, otherDefenderPos) >= 0)
|
|
||||||
{
|
|
||||||
if((mask & 2) == 0)
|
|
||||||
{
|
|
||||||
mask |= 2;
|
|
||||||
res.insert(otherDefenderPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user