mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
Fix possible crash on hovering over inaccessible hexes on other side of
the battlefield when war machine is making turn
This commit is contained in:
@ -392,8 +392,8 @@ BattleHexArray BattleFieldController::getHighlightedHexesForMovementTarget()
|
|||||||
|
|
||||||
if (stack->doubleWide())
|
if (stack->doubleWide())
|
||||||
{
|
{
|
||||||
const bool canMoveHeadHere = availableHexes.contains(hoveredHex);
|
const bool canMoveHeadHere = hoveredHex.isAvailable() && availableHexes.contains(hoveredHex);
|
||||||
const bool canMoveTailHere = availableHexes.contains(hoveredHex.cloneInDirection(stack->destShiftDir()));
|
const bool canMoveTailHere = hoveredHex.isAvailable() && availableHexes.contains(hoveredHex.cloneInDirection(stack->destShiftDir()));
|
||||||
const bool backwardsMove = stack->unitSide() == BattleSide::ATTACKER ?
|
const bool backwardsMove = stack->unitSide() == BattleSide::ATTACKER ?
|
||||||
hoveredHex.getX() < stack->getPosition().getX():
|
hoveredHex.getX() < stack->getPosition().getX():
|
||||||
hoveredHex.getX() > stack->getPosition().getX();
|
hoveredHex.getX() > stack->getPosition().getX();
|
||||||
@ -822,7 +822,7 @@ bool BattleFieldController::isTileAttackable(const BattleHex & number) const
|
|||||||
|
|
||||||
for (auto & elem : occupiableHexes)
|
for (auto & elem : occupiableHexes)
|
||||||
{
|
{
|
||||||
if (BattleHex::mutualPosition(elem, number) != -1 || elem == number)
|
if (BattleHex::mutualPosition(elem, number) != BattleHex::EDir::NONE || elem == number)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -212,8 +212,17 @@ public:
|
|||||||
[[nodiscard]] static EDir mutualPosition(const BattleHex & hex1, const BattleHex & hex2)
|
[[nodiscard]] static EDir mutualPosition(const BattleHex & hex1, const BattleHex & hex2)
|
||||||
{
|
{
|
||||||
for(auto dir : hexagonalDirections())
|
for(auto dir : hexagonalDirections())
|
||||||
if(hex2 == hex1.cloneInDirection(dir, false))
|
{
|
||||||
return dir;
|
try
|
||||||
|
{
|
||||||
|
if(hex2 == hex1.cloneInDirection(dir, true))
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
catch (const std::out_of_range &)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user