CRewardableObject.h 3.3 KB

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