ReachabilityInfo.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * ReachabilityInfo.h, 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. #pragma once
  11. #include "BattleHex.h"
  12. #include "CBattleInfoEssentials.h"
  13. #include "AccessibilityInfo.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. // Reachability info is result of BFS calculation. It's dependent on stack (it's owner, whether it's flying),
  16. // startPosition and perspective.
  17. struct DLL_LINKAGE ReachabilityInfo
  18. {
  19. using TDistances = std::array<uint32_t, GameConstants::BFIELD_SIZE>;
  20. using TPredecessors = std::array<BattleHex, GameConstants::BFIELD_SIZE>;
  21. enum { INFINITE_DIST = 1000000 };
  22. struct DLL_LINKAGE Parameters
  23. {
  24. BattleSide side = BattleSide::NONE;
  25. bool doubleWide = false;
  26. bool flying = false;
  27. bool ignoreKnownAccessible = false; //Ignore obstacles if it is in accessible hexes
  28. std::vector<BattleHex> knownAccessible; //hexes that will be treated as accessible, even if they're occupied by stack (by default - tiles occupied by stack we do reachability for, so it doesn't block itself)
  29. BattleHex startPosition; //assumed position of stack
  30. BattleSide perspective = BattleSide::ALL_KNOWING; //some obstacles (eg. quicksands) may be invisible for some side
  31. Parameters() = default;
  32. Parameters(const battle::Unit * Stack, BattleHex StartPosition);
  33. };
  34. Parameters params;
  35. AccessibilityInfo accessibility;
  36. TDistances distances;
  37. TPredecessors predecessors;
  38. ReachabilityInfo();
  39. bool isReachable(BattleHex hex) const;
  40. uint32_t distToNearestNeighbour(
  41. const std::vector<BattleHex> & targetHexes,
  42. BattleHex * chosenHex = nullptr) const;
  43. uint32_t distToNearestNeighbour(
  44. const battle::Unit * attacker,
  45. const battle::Unit * defender,
  46. BattleHex * chosenHex = nullptr) const;
  47. };
  48. VCMI_LIB_NAMESPACE_END