2023-10-19 16:19:09 +02:00
|
|
|
/*
|
|
|
|
* AccessibilityInfo.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "AccessibilityInfo.h"
|
|
|
|
#include "BattleHex.h"
|
|
|
|
#include "Unit.h"
|
|
|
|
#include "../GameConstants.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
bool AccessibilityInfo::tileAccessibleWithGate(BattleHex tile, BattleSide side) const
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
//at(otherHex) != EAccessibility::ACCESSIBLE && (at(otherHex) != EAccessibility::GATE || side != BattleSide::DEFENDER)
|
2024-07-19 12:44:44 +02:00
|
|
|
auto accessibility = at(tile);
|
|
|
|
|
|
|
|
if(accessibility == EAccessibility::ALIVE_STACK)
|
|
|
|
{
|
|
|
|
auto destructible = destructibleEnemyTurns.find(tile);
|
|
|
|
|
|
|
|
return destructible != destructibleEnemyTurns.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(accessibility != EAccessibility::ACCESSIBLE)
|
|
|
|
if(accessibility != EAccessibility::GATE || side != BattleSide::DEFENDER)
|
2023-10-19 16:19:09 +02:00
|
|
|
return false;
|
2024-07-19 12:44:44 +02:00
|
|
|
|
2023-10-19 16:19:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AccessibilityInfo::accessible(BattleHex tile, const battle::Unit * stack) const
|
|
|
|
{
|
|
|
|
return accessible(tile, stack->doubleWide(), stack->unitSide());
|
|
|
|
}
|
|
|
|
|
2024-08-11 22:22:35 +02:00
|
|
|
bool AccessibilityInfo::accessible(BattleHex tile, bool doubleWide, BattleSide side) const
|
2023-10-19 16:19:09 +02:00
|
|
|
{
|
|
|
|
// All hexes that stack would cover if standing on tile have to be accessible.
|
|
|
|
//do not use getHexes for speed reasons
|
|
|
|
if(!tile.isValid())
|
|
|
|
return false;
|
|
|
|
if(!tileAccessibleWithGate(tile, side))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(doubleWide)
|
|
|
|
{
|
|
|
|
auto otherHex = battle::Unit::occupiedHex(tile, doubleWide, side);
|
|
|
|
if(!otherHex.isValid())
|
|
|
|
return false;
|
|
|
|
if(!tileAccessibleWithGate(otherHex, side))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|