SpecialAction.h 2.0 KB

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