CGoal.h 1.9 KB

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