CGPandoraBox.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include "CObjectHandler.h"
  3. #include "CArmedInstance.h"
  4. #include "../ResourceSet.h"
  5. /*
  6. * CGPandoraBox.h, part of VCMI engine
  7. *
  8. * Authors: listed in file AUTHORS in main folder
  9. *
  10. * License: GNU General Public License v2.0 or later
  11. * Full text of license available in license.txt file, in main folder
  12. *
  13. */
  14. struct InfoWindow;
  15. class DLL_LINKAGE CGPandoraBox : public CArmedInstance
  16. {
  17. public:
  18. std::string message;
  19. mutable bool hasGuardians; //helper - after battle even though we have no stacks, allows us to know that there was battle
  20. //gained things:
  21. ui32 gainedExp;
  22. si32 manaDiff; //amount of gained / lost mana
  23. si32 moraleDiff; //morale modifier
  24. si32 luckDiff; //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. CGPandoraBox();
  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 & hasGuardians & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
  42. & abilities & abilityLevels & artifacts & spells & creatures;
  43. }
  44. protected:
  45. void giveContentsUpToExp(const CGHeroInstance *h) const;
  46. void giveContentsAfterExp(const CGHeroInstance *h) const;
  47. private:
  48. void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
  49. void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
  50. virtual void afterSuccessfulVisit() const;
  51. };
  52. class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  53. {
  54. public:
  55. bool removeAfterVisit; //true if event is removed after occurring
  56. ui8 availableFor; //players whom this event is available for
  57. bool computerActivate; //true if computer player can activate this event
  58. bool humanActivate; //true if human player can activate this event
  59. template <typename Handler> void serialize(Handler &h, const int version)
  60. {
  61. h & static_cast<CGPandoraBox &>(*this);
  62. h & removeAfterVisit & availableFor & computerActivate & humanActivate;
  63. }
  64. CGEvent();
  65. void onHeroVisit(const CGHeroInstance * h) const override;
  66. private:
  67. void activated(const CGHeroInstance * h) const;
  68. void afterSuccessfulVisit() const override;
  69. };