CGPandoraBox.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(IGameRandomizer & gameRandomizer) override;
  21. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  22. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  23. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t 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(IGameEventCallback & gameEvents, 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. CGEvent(IGameInfoCallback *cb);
  38. //players whom this event is available for
  39. std::set<PlayerColor> availableFor;
  40. //true if event is removed after occurring
  41. bool removeAfterVisit = false;
  42. //true if computer player can activate this event
  43. bool computerActivate = false;
  44. //true if human player can activate this event
  45. bool humanActivate = false;
  46. template <typename Handler> void serialize(Handler &h)
  47. {
  48. h & static_cast<CGPandoraBox &>(*this);
  49. h & removeAfterVisit;
  50. h & availableFor;
  51. h & computerActivate;
  52. h & humanActivate;
  53. }
  54. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  55. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  56. protected:
  57. void grantRewardWithMessage(IGameEventCallback & gameEvents, const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const override;
  58. void init() override;
  59. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  60. private:
  61. void activated(IGameEventCallback & gameEvents, const CGHeroInstance * h) const;
  62. };
  63. VCMI_LIB_NAMESPACE_END