CGPandoraBox.h 2.0 KB

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