PathfinderOptions.h 4.6 KB

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