CGTownBuilding.h 3.7 KB

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