CGPandoraBox.h 3.1 KB

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