CGoal.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * CGoal.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 "AbstractGoal.h"
  12. #include "../FuzzyHelper.h"
  13. #include "../VCAI.h"
  14. struct HeroPtr;
  15. class VCAI;
  16. namespace Goals
  17. {
  18. template<typename T>
  19. class DLL_EXPORT CGoal : public AbstractGoal
  20. {
  21. public:
  22. CGoal(EGoals goal = INVALID) : AbstractGoal(goal)
  23. {
  24. priority = 0;
  25. isElementar = false;
  26. isAbstract = false;
  27. value = 0;
  28. aid = -1;
  29. objid = -1;
  30. resID = -1;
  31. tile = int3(-1, -1, -1);
  32. town = nullptr;
  33. }
  34. OSETTER(bool, isElementar)
  35. OSETTER(bool, isAbstract)
  36. OSETTER(float, priority)
  37. OSETTER(int, value)
  38. OSETTER(int, resID)
  39. OSETTER(int, objid)
  40. OSETTER(int, aid)
  41. OSETTER(int3, tile)
  42. OSETTER(HeroPtr, hero)
  43. OSETTER(CGTownInstance *, town)
  44. OSETTER(int, bid)
  45. void accept(VCAI * ai) override
  46. {
  47. ai->tryRealize(static_cast<T &>(*this)); //casting enforces template instantiation
  48. }
  49. float accept(FuzzyHelper * f) override
  50. {
  51. return f->evaluate(static_cast<T &>(*this)); //casting enforces template instantiation
  52. }
  53. CGoal * clone() const override
  54. {
  55. return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
  56. }
  57. TSubgoal iAmElementar() const
  58. {
  59. TSubgoal ptr;
  60. ptr.reset(clone());
  61. ptr->setisElementar(true);
  62. return ptr;
  63. }
  64. bool operator==(const AbstractGoal & g) const override
  65. {
  66. if(goalType != g.goalType)
  67. return false;
  68. return (*this) == (static_cast<const T &>(g));
  69. }
  70. virtual bool operator==(const T & other) const = 0;
  71. };
  72. }