CRewardableObject.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 transfer 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 selectRewardWithMessage(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices, const MetaString & dialog) const;
  30. virtual void grantAllRewardsWithMessage(const CGHeroInstance * contextHero, const std::vector<ui32>& rewardIndices, bool markAsVisit) const;
  31. std::vector<Component> loadComponents(const CGHeroInstance * contextHero, const std::vector<ui32> & rewardIndices) const;
  32. std::string getDisplayTextImpl(PlayerColor player, const CGHeroInstance * hero, bool includeDescription) const;
  33. std::string getDescriptionMessage(PlayerColor player, const CGHeroInstance * hero) const;
  34. std::vector<Component> getPopupComponentsImpl(PlayerColor player, const CGHeroInstance * hero) const;
  35. void doHeroVisit(const CGHeroInstance *h) const;
  36. /// Returns true if this object might have guards present, whether they were cleared or not
  37. bool guardedPotentially() const;
  38. /// Returns true if this object is currently guarded
  39. bool guardedPresently() const;
  40. public:
  41. /// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
  42. bool wasVisited(PlayerColor player) const override;
  43. bool wasVisited(const CGHeroInstance * h) const override;
  44. /// Returns true if object was scouted by player and he is aware of its internal state
  45. bool wasScouted(PlayerColor player) const;
  46. /// gives reward to player or ask for choice in case of multiple rewards
  47. void onHeroVisit(const CGHeroInstance *h) const override;
  48. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  49. ///possibly resets object state
  50. void newTurn(vstd::RNG & rand) const override;
  51. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  52. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  53. /// applies player selection of reward
  54. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  55. void initObj(vstd::RNG & rand) override;
  56. void initializeGuards();
  57. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  58. CRewardableObject(IGameCallback *cb);
  59. std::string getHoverText(PlayerColor player) const override;
  60. std::string getHoverText(const CGHeroInstance * hero) const override;
  61. std::string getPopupText(PlayerColor player) const override;
  62. std::string getPopupText(const CGHeroInstance * hero) const override;
  63. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  64. std::vector<Component> getPopupComponents(const CGHeroInstance * hero) const override;
  65. template <typename Handler> void serialize(Handler &h)
  66. {
  67. h & static_cast<CArmedInstance&>(*this);
  68. h & static_cast<Rewardable::Interface&>(*this);
  69. h & onceVisitableObjectCleared;
  70. }
  71. };
  72. //TODO:
  73. // class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  74. // class DLL_LINKAGE CGKeymasterTent : public CGKeys
  75. // class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  76. // POSSIBLE
  77. // class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  78. VCMI_LIB_NAMESPACE_END