2017-06-24 15:51:07 +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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-01 20:05:10 +02:00
|
|
|
#include "StdInc.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
#include "AccessibilityInfo.h"
|
2017-07-20 06:08:49 +02:00
|
|
|
#include "Unit.h"
|
2017-07-01 10:34:00 +02:00
|
|
|
#include "../GameConstants.h"
|
2017-06-24 15:51:07 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
bool AccessibilityInfo::accessible(BattleHex tile, const battle::Unit * stack) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
return accessible(tile, stack->doubleWide(), stack->unitSide());
|
2017-06-24 15:51:07 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 10:34:00 +02:00
|
|
|
bool AccessibilityInfo::accessible(BattleHex tile, bool doubleWide, ui8 side) const
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
|
|
|
// All hexes that stack would cover if standing on tile have to be accessible.
|
2017-07-20 06:08:49 +02:00
|
|
|
//do not use getHexes for speed reasons
|
|
|
|
if(!tile.isValid())
|
|
|
|
return false;
|
|
|
|
if(at(tile) != EAccessibility::ACCESSIBLE && !(at(tile) == EAccessibility::GATE && side == BattleSide::DEFENDER))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(doubleWide)
|
2017-06-24 15:51:07 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
auto otherHex = battle::Unit::occupiedHex(tile, doubleWide, side);
|
|
|
|
if(!otherHex.isValid())
|
2017-06-24 15:51:07 +02:00
|
|
|
return false;
|
2017-07-20 06:08:49 +02:00
|
|
|
if(at(otherHex) != EAccessibility::ACCESSIBLE && !(at(otherHex) == EAccessibility::GATE && side == BattleSide::DEFENDER))
|
2017-06-24 15:51:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2017-06-24 15:51:07 +02:00
|
|
|
return true;
|
|
|
|
}
|