CRewardableObject.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * CRewardableObject.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 "CArmedInstance.h"
  12. #include "../rewardable/Interface.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. /// Base class that can handle granting rewards to visiting heroes.
  15. /// Inherits from CArmedInstance for proper trasfer of armies
  16. class DLL_LINKAGE CRewardableObject : public CArmedInstance, public Rewardable::Interface
  17. {
  18. protected:
  19. bool onceVisitableObjectCleared = false;
  20. /// reward selected by player, no serialize
  21. ui16 selectedReward = 0;
  22. void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
  23. void markAsVisited(const CGHeroInstance * hero) const;
  24. /// return true if this object was "cleared" before and no longer has rewards applicable to selected hero
  25. /// unlike wasVisited, this method uses information not available to player owner, for example, if object was cleared by another player before
  26. bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
  27. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  28. virtual void grantRewardWithMessage(const CGHeroInstance * contextHero, int rewardIndex, bool markAsVisit) const;
  29. virtual void selectRewardWthMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, const MetaString & dialog) const;
  30. public:
  31. /// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
  32. bool wasVisited(PlayerColor player) const override;
  33. bool wasVisited(const CGHeroInstance * h) const override;
  34. /// gives reward to player or ask for choice in case of multiple rewards
  35. void onHeroVisit(const CGHeroInstance *h) const override;
  36. ///possibly resets object state
  37. void newTurn(CRandomGenerator & rand) const override;
  38. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  39. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  40. /// applies player selection of reward
  41. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  42. void initObj(CRandomGenerator & rand) override;
  43. void setPropertyDer(ui8 what, ui32 val) override;
  44. CRewardableObject();
  45. std::string getHoverText(PlayerColor player) const override;
  46. std::string getHoverText(const CGHeroInstance * hero) const override;
  47. template <typename Handler> void serialize(Handler &h, const int version)
  48. {
  49. h & static_cast<CArmedInstance&>(*this);
  50. h & static_cast<Rewardable::Interface&>(*this);
  51. h & onceVisitableObjectCleared;
  52. }
  53. };
  54. //TODO:
  55. // MAX
  56. // class DLL_LINKAGE CGPandoraBox : public CArmedInstance
  57. // class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  58. // class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
  59. // class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  60. // class DLL_LINKAGE CBank : public CArmedInstance
  61. // class DLL_LINKAGE CGPyramid : public CBank
  62. // EXTRA
  63. // class DLL_LINKAGE COPWBonus : public CGTownBuilding
  64. // class DLL_LINKAGE CTownBonus : public CGTownBuilding
  65. // class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  66. // class DLL_LINKAGE CGKeymasterTent : public CGKeys
  67. // class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  68. // POSSIBLE
  69. // class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  70. VCMI_LIB_NAMESPACE_END