PathfinderOptions.h 3.9 KB

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