2
0

CRewardableObject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. public:
  29. /// Visitability checks. Note that hero check includes check for hero owner (returns true if object was visited by player)
  30. bool wasVisited(PlayerColor player) const override;
  31. bool wasVisited(const CGHeroInstance * h) const override;
  32. /// gives reward to player or ask for choice in case of multiple rewards
  33. void onHeroVisit(const CGHeroInstance *h) const override;
  34. ///possibly resets object state
  35. void newTurn(CRandomGenerator & rand) const override;
  36. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  37. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  38. /// applies player selection of reward
  39. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  40. void initObj(CRandomGenerator & rand) override;
  41. void setPropertyDer(ui8 what, ui32 val) override;
  42. CRewardableObject();
  43. std::string getHoverText(PlayerColor player) const override;
  44. std::string getHoverText(const CGHeroInstance * hero) const override;
  45. template <typename Handler> void serialize(Handler &h, const int version)
  46. {
  47. h & static_cast<CArmedInstance&>(*this);
  48. h & static_cast<Rewardable::Interface&>(*this);
  49. h & onceVisitableObjectCleared;
  50. }
  51. };
  52. //TODO:
  53. // MAX
  54. // class DLL_LINKAGE CGPandoraBox : public CArmedInstance
  55. // class DLL_LINKAGE CGEvent : public CGPandoraBox //event objects
  56. // class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward
  57. // class DLL_LINKAGE CGQuestGuard : public CGSeerHut
  58. // class DLL_LINKAGE CBank : public CArmedInstance
  59. // class DLL_LINKAGE CGPyramid : public CBank
  60. // EXTRA
  61. // class DLL_LINKAGE COPWBonus : public CGTownBuilding
  62. // class DLL_LINKAGE CTownBonus : public CGTownBuilding
  63. // class DLL_LINKAGE CGKeys : public CGObjectInstance //Base class for Keymaster and guards
  64. // class DLL_LINKAGE CGKeymasterTent : public CGKeys
  65. // class DLL_LINKAGE CGBorderGuard : public CGKeys, public IQuestObject
  66. // POSSIBLE
  67. // class DLL_LINKAGE CGSignBottle : public CGObjectInstance //signs and ocean bottles
  68. // class DLL_LINKAGE CGWitchHut : public CPlayersVisited
  69. // class DLL_LINKAGE CGScholar : public CGObjectInstance
  70. VCMI_LIB_NAMESPACE_END