CGTownBuilding.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * CGTownBuilding.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 "IObjectInterface.h"
  12. #include "../rewardable/Interface.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGTownInstance;
  15. class CBuilding;
  16. class DLL_LINKAGE CGTownBuilding : public IObjectInterface
  17. {
  18. ///basic class for town structures handled as map objects
  19. public:
  20. CGTownBuilding(CGTownInstance * town);
  21. CGTownBuilding(IGameCallback *cb);
  22. si32 indexOnTV = 0; //identifies its index on towns vector
  23. CGTownInstance * town;
  24. STRONG_INLINE
  25. BuildingSubID::EBuildingSubID getBuildingSubtype() const
  26. {
  27. return bType;
  28. }
  29. STRONG_INLINE
  30. const BuildingID & getBuildingType() const
  31. {
  32. return bID;
  33. }
  34. STRONG_INLINE
  35. void setBuildingSubtype(BuildingSubID::EBuildingSubID subId)
  36. {
  37. bType = subId;
  38. }
  39. PlayerColor getOwner() const override;
  40. MapObjectID getObjGroupIndex() const override;
  41. MapObjectSubID getObjTypeIndex() const override;
  42. int3 visitablePos() const override;
  43. int3 getPosition() const override;
  44. template <typename Handler> void serialize(Handler &h)
  45. {
  46. h & bID;
  47. h & indexOnTV;
  48. h & bType;
  49. }
  50. protected:
  51. BuildingID bID; //from buildig list
  52. BuildingSubID::EBuildingSubID bType = BuildingSubID::NONE;
  53. std::string getVisitingBonusGreeting() const;
  54. std::string getCustomBonusGreeting(const Bonus & bonus) const;
  55. };
  56. class DLL_LINKAGE COPWBonus : public CGTownBuilding
  57. {///used for OPW bonusing structures
  58. public:
  59. std::set<ObjectInstanceID> visitors;
  60. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  61. void onHeroVisit (const CGHeroInstance * h) const override;
  62. COPWBonus(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * TOWN);
  63. COPWBonus(IGameCallback *cb);
  64. template <typename Handler> void serialize(Handler &h)
  65. {
  66. h & static_cast<CGTownBuilding&>(*this);
  67. h & visitors;
  68. }
  69. };
  70. class DLL_LINKAGE CTownBonus : public CGTownBuilding
  71. {
  72. ///used for one-time bonusing structures
  73. ///feel free to merge inheritance tree
  74. public:
  75. std::set<ObjectInstanceID> visitors;
  76. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  77. void onHeroVisit (const CGHeroInstance * h) const override;
  78. CTownBonus(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * TOWN);
  79. CTownBonus(IGameCallback *cb);
  80. template <typename Handler> void serialize(Handler &h)
  81. {
  82. h & static_cast<CGTownBuilding&>(*this);
  83. h & visitors;
  84. }
  85. private:
  86. void applyBonuses(CGHeroInstance * h, const BonusList & bonuses) const;
  87. };
  88. class DLL_LINKAGE CTownRewardableBuilding : public CGTownBuilding, public Rewardable::Interface
  89. {
  90. /// reward selected by player, no serialize
  91. ui16 selectedReward = 0;
  92. std::set<ObjectInstanceID> visitors;
  93. bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
  94. void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
  95. public:
  96. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  97. void onHeroVisit(const CGHeroInstance * h) const override;
  98. void newTurn(CRandomGenerator & rand) const override;
  99. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  100. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  101. void initObj(CRandomGenerator & rand) override;
  102. /// applies player selection of reward
  103. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  104. CTownRewardableBuilding(const BuildingID & index, BuildingSubID::EBuildingSubID subId, CGTownInstance * town, CRandomGenerator & rand);
  105. CTownRewardableBuilding(IGameCallback *cb);
  106. template <typename Handler> void serialize(Handler &h)
  107. {
  108. h & static_cast<CGTownBuilding&>(*this);
  109. h & static_cast<Rewardable::Interface&>(*this);
  110. h & visitors;
  111. }
  112. };
  113. VCMI_LIB_NAMESPACE_END