CGPandoraBox.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. 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;
  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; //true if event is removed after occurring
  68. ui8 availableFor; //players whom this event is available for
  69. bool computerActivate; //true if computer player can activate this event
  70. bool humanActivate; //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. CGEvent();
  80. void onHeroVisit(const CGHeroInstance * h) const override;
  81. protected:
  82. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  83. private:
  84. void activated(const CGHeroInstance * h) const;
  85. void afterSuccessfulVisit() const override;
  86. };