AccessibilityInfo.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * AccessibilityInfo.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "AccessibilityInfo.h"
  12. #include "../CStack.h"
  13. #include "../GameConstants.h"
  14. bool AccessibilityInfo::accessible(BattleHex tile, const CStack * stack) const
  15. {
  16. return accessible(tile, stack->doubleWide(), stack->side);
  17. }
  18. bool AccessibilityInfo::accessible(BattleHex tile, bool doubleWide, ui8 side) const
  19. {
  20. // All hexes that stack would cover if standing on tile have to be accessible.
  21. for(auto hex : CStack::getHexes(tile, doubleWide, side))
  22. {
  23. // If the hex is out of range then the tile isn't accessible
  24. if(!hex.isValid())
  25. return false;
  26. // If we're no defender which step on gate and the hex isn't accessible, then the tile
  27. // isn't accessible
  28. else if(at(hex) != EAccessibility::ACCESSIBLE &&
  29. !(at(hex) == EAccessibility::GATE && side == BattleSide::DEFENDER))
  30. {
  31. return false;
  32. }
  33. }
  34. return true;
  35. }