SpecialAction.h 2.4 KB

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