SpecialAction.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SpecialAction.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 "../../AIUtility.h"
  12. #include "../../Goals/AbstractGoal.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct PathNodeInfo;
  15. struct CDestinationNodeInfo;
  16. VCMI_LIB_NAMESPACE_END
  17. namespace NKAI
  18. {
  19. struct AIPathNode;
  20. class SpecialAction
  21. {
  22. public:
  23. virtual ~SpecialAction() = default;
  24. virtual bool canAct(const AIPathNode * source) const
  25. {
  26. return true;
  27. }
  28. virtual Goals::TSubgoal decompose(const CGHeroInstance * hero) const;
  29. virtual void execute(const CGHeroInstance * hero) const;
  30. virtual void applyOnDestination(
  31. const CGHeroInstance * hero,
  32. CDestinationNodeInfo & destination,
  33. const PathNodeInfo & source,
  34. AIPathNode * dstNode,
  35. const AIPathNode * srcNode) const
  36. {
  37. }
  38. virtual std::string toString() const = 0;
  39. virtual const CGObjectInstance * targetObject() const { return nullptr; }
  40. virtual std::vector<std::shared_ptr<const SpecialAction>> getParts() const
  41. {
  42. return {};
  43. }
  44. };
  45. class CompositeAction : public SpecialAction
  46. {
  47. private:
  48. std::vector<std::shared_ptr<const SpecialAction>> parts;
  49. public:
  50. CompositeAction(std::vector<std::shared_ptr<const SpecialAction>> parts) : parts(parts) {}
  51. bool canAct(const AIPathNode * source) const override;
  52. void execute(const CGHeroInstance * hero) const override;
  53. std::string toString() const override;
  54. const CGObjectInstance * targetObject() const override;
  55. Goals::TSubgoal decompose(const CGHeroInstance * hero) const override;
  56. std::vector<std::shared_ptr<const SpecialAction>> getParts() const override
  57. {
  58. return parts;
  59. }
  60. void applyOnDestination(
  61. const CGHeroInstance * hero,
  62. CDestinationNodeInfo & destination,
  63. const PathNodeInfo & source,
  64. AIPathNode * dstNode,
  65. const AIPathNode * srcNode) const override;
  66. };
  67. }