PathfinderOptions.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * PathfinderOptions.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. VCMI_LIB_NAMESPACE_BEGIN
  12. class INodeStorage;
  13. class IPathfindingRule;
  14. class CPathfinderHelper;
  15. class CGameState;
  16. class CGHeroInstance;
  17. class IGameInfoCallback;
  18. struct PathNodeInfo;
  19. struct CPathsInfo;
  20. struct DLL_LINKAGE PathfinderOptions
  21. {
  22. bool useFlying;
  23. bool useWaterWalking;
  24. bool ignoreGuards;
  25. bool useEmbarkAndDisembark;
  26. bool useTeleportTwoWay; // Two-way monoliths and Subterranean Gate
  27. bool useTeleportOneWay; // One-way monoliths with one known exit only
  28. bool useTeleportOneWayRandom; // One-way monoliths with more than one known exit
  29. bool useTeleportWhirlpool; // Force enabled if hero protected or unaffected (have one stack of one creature)
  30. bool forceUseTeleportWhirlpool; // Force enabled if hero protected or unaffected (have one stack of one creature)
  31. /// TODO: Find out with client and server code, merge with normal teleporters.
  32. /// Likely proper implementation would require some refactoring of CGTeleport.
  33. /// So for now this is unfinished and disabled by default.
  34. bool useCastleGate;
  35. /// If true transition into air layer only possible from initial node.
  36. /// This is drastically decrease path calculation complexity (and time).
  37. /// Downside is less MP effective paths calculation.
  38. ///
  39. /// TODO: If this option end up useful for slow devices it's can be improved:
  40. /// - Allow transition into air layer not only from initial position, but also from teleporters.
  41. /// Movement into air can be also allowed when hero disembarked.
  42. /// - Other idea is to allow transition into air within certain radius of N tiles around hero.
  43. /// Patrol support need similar functionality so it's won't be ton of useless code.
  44. /// Such limitation could be useful as it's can be scaled depend on device performance.
  45. bool lightweightFlyingMode;
  46. /// This option enable one turn limitation for flying and water walking.
  47. /// So if we're out of MP while cp is blocked or water tile we won't add dest tile to queue.
  48. ///
  49. /// Following imitation is default H3 mechanics, but someone may want to disable it in mods.
  50. /// After all this limit should benefit performance on maps with tons of water or blocked tiles.
  51. ///
  52. /// TODO:
  53. /// - Behavior when option is disabled not implemented and will lead to crashes.
  54. bool oneTurnSpecialLayersLimit;
  55. /// VCMI have different movement rules to solve flaws original engine has.
  56. /// If this option enabled you'll able to do following things in fly:
  57. /// - Move from blocked tiles to visitable one
  58. /// - Move from guarded tiles to blockvis tiles without being attacked
  59. /// - Move from guarded tiles to guarded visitable tiles with being attacked after
  60. /// TODO:
  61. /// - Option should also allow same tile land <-> air layer transitions.
  62. /// Current implementation only allow go into (from) air layer only to neighbour tiles.
  63. /// I find it's reasonable limitation, but it's will make some movements more expensive than in H3.
  64. /// Further work can also be done to mimic SoD quirks if needed
  65. /// (such as picking unoptimal paths on purpose when targeting guards or being interrupted on guarded resource tile when picking it during diagonal u-turn)
  66. bool originalFlyRules;
  67. /// Max number of turns to compute. Default = infinite
  68. uint8_t turnLimit;
  69. /// <summary>
  70. /// For AI. Allows water walk and fly layers if hero can cast appropriate spells
  71. /// </summary>
  72. bool canUseCast;
  73. /// <summary>
  74. /// For AI. AI pathfinder needs to ignore this rule as it simulates battles on the way
  75. /// </summary>
  76. bool allowLayerTransitioningAfterBattle;
  77. PathfinderOptions(const IGameInfoCallback & callback);
  78. };
  79. class DLL_LINKAGE PathfinderConfig
  80. {
  81. public:
  82. std::shared_ptr<INodeStorage> nodeStorage;
  83. std::vector<std::shared_ptr<IPathfindingRule>> rules;
  84. PathfinderOptions options;
  85. PathfinderConfig(
  86. std::shared_ptr<INodeStorage> nodeStorage,
  87. const IGameInfoCallback & callback,
  88. std::vector<std::shared_ptr<IPathfindingRule>> rules);
  89. virtual ~PathfinderConfig() = default;
  90. virtual CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo) = 0;
  91. };
  92. class DLL_LINKAGE SingleHeroPathfinderConfig : public PathfinderConfig
  93. {
  94. private:
  95. std::unique_ptr<CPathfinderHelper> pathfinderHelper;
  96. const CGHeroInstance * hero;
  97. public:
  98. SingleHeroPathfinderConfig(CPathsInfo & out, const IGameInfoCallback & gs, const CGHeroInstance * hero);
  99. virtual ~SingleHeroPathfinderConfig();
  100. CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, const IGameInfoCallback & gameInfo) override;
  101. static std::vector<std::shared_ptr<IPathfindingRule>> buildRuleSet();
  102. };
  103. VCMI_LIB_NAMESPACE_END