CaptureObjectsBehavior.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * CaptureObjectsBehavior.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 "../../../lib/VCMI_Lib.h"
  12. #include "../AIUtility.h"
  13. #include "../Goals/CGoal.h"
  14. #include "../Pathfinding/AINodeStorage.h"
  15. namespace NKAI
  16. {
  17. namespace Goals
  18. {
  19. class CaptureObjectsBehavior : public CGoal<CaptureObjectsBehavior>
  20. {
  21. private:
  22. std::vector<int> objectTypes;
  23. std::vector<int> objectSubTypes;
  24. std::vector<const CGObjectInstance *> objectsToCapture;
  25. bool specificObjects;
  26. public:
  27. CaptureObjectsBehavior()
  28. :CGoal(CAPTURE_OBJECTS)
  29. {
  30. objectTypes = std::vector<int>();
  31. specificObjects = false;
  32. }
  33. CaptureObjectsBehavior(std::vector<const CGObjectInstance *> objectsToCapture)
  34. :CGoal(CAPTURE_OBJECTS)
  35. {
  36. this->objectsToCapture = objectsToCapture;
  37. specificObjects = true;
  38. }
  39. CaptureObjectsBehavior(const CGObjectInstance * objectToCapture)
  40. :CGoal(CAPTURE_OBJECTS)
  41. {
  42. objectsToCapture = std::vector<const CGObjectInstance *>();
  43. objectsToCapture.push_back(objectToCapture);
  44. specificObjects = true;
  45. }
  46. Goals::TGoalVec decompose() const override;
  47. std::string toString() const override;
  48. CaptureObjectsBehavior & ofType(int type)
  49. {
  50. objectTypes.push_back(type);
  51. return *this;
  52. }
  53. CaptureObjectsBehavior & ofType(int type, int subType)
  54. {
  55. objectTypes.push_back(type);
  56. objectSubTypes.push_back(subType);
  57. return *this;
  58. }
  59. bool operator==(const CaptureObjectsBehavior & other) const override;
  60. static Goals::TGoalVec getVisitGoals(const std::vector<AIPath> & paths, const CGObjectInstance * objToVisit = nullptr);
  61. private:
  62. bool objectMatchesFilter(const CGObjectInstance * obj) const;
  63. };
  64. }
  65. }