CGPandoraBox.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * CGPandoraBox.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 "CRewardableObject.h"
  12. #include "../ResourceSet.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct InfoWindow;
  15. class DLL_LINKAGE CGPandoraBox : public CRewardableObject
  16. {
  17. public:
  18. using CRewardableObject::CRewardableObject;
  19. MetaString message;
  20. void initObj(vstd::RNG & rand) override;
  21. void onHeroVisit(const CGHeroInstance * h) const override;
  22. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  23. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  24. template <typename Handler> void serialize(Handler &h)
  25. {
  26. h & static_cast<CRewardableObject&>(*this);
  27. h & message;
  28. }
  29. protected:
  30. void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const override;
  31. virtual void init();
  32. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  33. };
  34. class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  35. {
  36. public:
  37. using CGPandoraBox::CGPandoraBox;
  38. bool removeAfterVisit = false; //true if event is removed after occurring
  39. std::set<PlayerColor> availableFor; //players whom this event is available for
  40. bool computerActivate = false; //true if computer player can activate this event
  41. bool humanActivate = false; //true if human player can activate this event
  42. template <typename Handler> void serialize(Handler &h)
  43. {
  44. h & static_cast<CGPandoraBox &>(*this);
  45. h & removeAfterVisit;
  46. h & availableFor;
  47. h & computerActivate;
  48. h & humanActivate;
  49. }
  50. void onHeroVisit(const CGHeroInstance * h) const override;
  51. protected:
  52. void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const override;
  53. void init() override;
  54. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  55. private:
  56. void activated(const CGHeroInstance * h) const;
  57. };
  58. VCMI_LIB_NAMESPACE_END