CGPandoraBox.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "CArmedInstance.h"
  12. #include "../ResourceSet.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct InfoWindow;
  15. class DLL_LINKAGE CGPandoraBox : public CArmedInstance
  16. {
  17. public:
  18. std::string message;
  19. mutable bool hasGuardians = false; //helper - after battle even though we have no stacks, allows us to know that there was battle
  20. //gained things:
  21. ui32 gainedExp = 0;
  22. si32 manaDiff = 0; //amount of gained / lost mana
  23. si32 moraleDiff = 0; //morale modifier
  24. si32 luckDiff = 0; //luck modifier
  25. TResources resources;//gained / lost resources
  26. std::vector<si32> primskills;//gained / lost prim skills
  27. std::vector<SecondarySkill> abilities; //gained abilities
  28. std::vector<si32> abilityLevels; //levels of gained abilities
  29. std::vector<ArtifactID> artifacts; //gained artifacts
  30. std::vector<SpellID> spells; //gained spells
  31. CCreatureSet creatures; //gained creatures
  32. void initObj(CRandomGenerator & rand) override;
  33. void onHeroVisit(const CGHeroInstance * h) const override;
  34. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  35. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  36. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  37. template <typename Handler> void serialize(Handler &h, const int version)
  38. {
  39. h & static_cast<CArmedInstance&>(*this);
  40. h & message;
  41. h & hasGuardians;
  42. h & gainedExp;
  43. h & manaDiff;
  44. h & moraleDiff;
  45. h & luckDiff;
  46. h & resources;
  47. h & primskills;
  48. h & abilities;
  49. h & abilityLevels;
  50. h & artifacts;
  51. h & spells;
  52. h & creatures;
  53. }
  54. protected:
  55. void giveContentsUpToExp(const CGHeroInstance *h) const;
  56. void giveContentsAfterExp(const CGHeroInstance *h) const;
  57. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  58. private:
  59. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  60. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  61. virtual void afterSuccessfulVisit() const;
  62. };
  63. class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  64. {
  65. public:
  66. bool removeAfterVisit = false; //true if event is removed after occurring
  67. std::set<PlayerColor> availableFor; //players whom this event is available for
  68. bool computerActivate = false; //true if computer player can activate this event
  69. bool humanActivate = false; //true if human player can activate this event
  70. template <typename Handler> void serialize(Handler &h, const int version)
  71. {
  72. h & static_cast<CGPandoraBox &>(*this);
  73. h & removeAfterVisit;
  74. h & availableFor;
  75. h & computerActivate;
  76. h & humanActivate;
  77. }
  78. void onHeroVisit(const CGHeroInstance * h) const override;
  79. protected:
  80. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  81. private:
  82. void activated(const CGHeroInstance * h) const;
  83. void afterSuccessfulVisit() const override;
  84. };
  85. VCMI_LIB_NAMESPACE_END