ReachabilityInfo.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. bool bypassEnemyStacks = false; // in case of true will count amount of turns needed to kill enemy and thus move forward
  29. 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)
  30. std::map<BattleHex, ui8> destructibleEnemyTurns; // hom many turns it is needed to kill enemy on specific hex
  31. BattleHex startPosition; //assumed position of stack
  32. BattleSide perspective = BattleSide::ALL_KNOWING; //some obstacles (eg. quicksands) may be invisible for some side
  33. Parameters() = default;
  34. Parameters(const battle::Unit * Stack, BattleHex StartPosition);
  35. };
  36. Parameters params;
  37. AccessibilityInfo accessibility;
  38. TDistances distances;
  39. TPredecessors predecessors;
  40. ReachabilityInfo();
  41. bool isReachable(BattleHex hex) const;
  42. uint32_t distToNearestNeighbour(
  43. const std::vector<BattleHex> & targetHexes,
  44. BattleHex * chosenHex = nullptr) const;
  45. uint32_t distToNearestNeighbour(
  46. const battle::Unit * attacker,
  47. const battle::Unit * defender,
  48. BattleHex * chosenHex = nullptr) const;
  49. };
  50. VCMI_LIB_NAMESPACE_END