CGPandoraBox.h 2.6 KB

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