CGPandoraBox.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. 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() : gainedExp(0), manaDiff(0), moraleDiff(0), luckDiff(0){};
  33. void initObj() 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. };
  51. class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  52. {
  53. public:
  54. bool removeAfterVisit; //true if event is removed after occurring
  55. ui8 availableFor; //players whom this event is available for
  56. bool computerActivate; //true if computer player can activate this event
  57. bool humanActivate; //true if human player can activate this event
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & static_cast<CGPandoraBox &>(*this);
  61. h & removeAfterVisit & availableFor & computerActivate & humanActivate;
  62. }
  63. CGEvent() : CGPandoraBox(){};
  64. void onHeroVisit(const CGHeroInstance * h) const override;
  65. private:
  66. void activated(const CGHeroInstance * h) const;
  67. };