SpecialAction.h 1.8 KB

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