ReachabilityInfo.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "BattleHexArray.h"
  12. #include "CBattleInfoEssentials.h"
  13. #include "AccessibilityInfo.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class BattleHexArray;
  16. // Reachability info is result of BFS calculation. It's dependent on stack (it's owner, whether it's flying),
  17. // startPosition and perspective.
  18. struct DLL_LINKAGE ReachabilityInfo
  19. {
  20. using TDistances = std::array<uint32_t, GameConstants::BFIELD_SIZE>;
  21. using TPredecessors = std::array<BattleHex, GameConstants::BFIELD_SIZE>;
  22. enum { INFINITE_DIST = 1000000 };
  23. struct DLL_LINKAGE Parameters
  24. {
  25. BattleSide side = BattleSide::NONE;
  26. bool doubleWide = false;
  27. bool flying = false;
  28. bool ignoreKnownAccessible = false; //Ignore obstacles if it is in accessible hexes
  29. bool bypassEnemyStacks = false; // in case of true will count amount of turns needed to kill enemy and thus move forward
  30. const BattleHexArray * 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)
  31. TBattlefieldTurnsArray destructibleEnemyTurns; // how many turns it is needed to kill enemy on specific hex (index <=> hex)
  32. BattleHex startPosition; //assumed position of stack
  33. BattleSide perspective = BattleSide::ALL_KNOWING; //some obstacles (eg. quicksands) may be invisible for some side
  34. Parameters()
  35. {
  36. destructibleEnemyTurns.fill(-1);
  37. }
  38. Parameters(const battle::Unit * Stack, const BattleHex & StartPosition);
  39. };
  40. Parameters params;
  41. AccessibilityInfo accessibility;
  42. TDistances distances;
  43. TPredecessors predecessors;
  44. ReachabilityInfo();
  45. bool isReachable(const BattleHex & hex) const;
  46. uint32_t distToNearestNeighbour(
  47. const BattleHexArray & targetHexes,
  48. BattleHex * chosenHex = nullptr) const;
  49. uint32_t distToNearestNeighbour(
  50. const battle::Unit * attacker,
  51. const battle::Unit * defender,
  52. BattleHex * chosenHex = nullptr) const;
  53. };
  54. VCMI_LIB_NAMESPACE_END