CGPandoraBox.h 3.1 KB

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