AccessibilityInfo.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. bool AccessibilityInfo::accessible(BattleHex tile, const CStack *stack) const
  14. {
  15. return accessible(tile, stack->doubleWide(), stack->attackerOwned);
  16. }
  17. bool AccessibilityInfo::accessible(BattleHex tile, bool doubleWide, bool attackerOwned) const
  18. {
  19. // All hexes that stack would cover if standing on tile have to be accessible.
  20. for(auto hex : CStack::getHexes(tile, doubleWide, attackerOwned))
  21. {
  22. // If the hex is out of range then the tile isn't accessible
  23. if(!hex.isValid())
  24. return false;
  25. // If we're no defender which step on gate and the hex isn't accessible, then the tile
  26. // isn't accessible
  27. else if(at(hex) != EAccessibility::ACCESSIBLE &&
  28. !(at(hex) == EAccessibility::GATE && !attackerOwned))
  29. {
  30. return false;
  31. }
  32. }
  33. return true;
  34. }
  35. bool AccessibilityInfo::occupiable(const CStack *stack, BattleHex tile) const
  36. {
  37. //obviously, we can occupy tile by standing on it
  38. if(accessible(tile, stack))
  39. return true;
  40. if(stack->doubleWide())
  41. {
  42. //Check the tile next to -> if stack stands there, it'll also occupy considered hex
  43. const BattleHex anotherTile = tile + (stack->attackerOwned ? BattleHex::RIGHT : BattleHex::LEFT);
  44. if(accessible(anotherTile, stack))
  45. return true;
  46. }
  47. return false;
  48. }