TownBuildingInstance.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * TownBuildingInstance.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 TownBuildingInstance : public IObjectInterface
  17. {
  18. ///basic class for town structures handled as map objects
  19. public:
  20. TownBuildingInstance(CGTownInstance * town, const BuildingID & index);
  21. TownBuildingInstance(IGameCallback *cb);
  22. CGTownInstance * town;
  23. const BuildingID & getBuildingType() const
  24. {
  25. return bID;
  26. }
  27. PlayerColor getOwner() const override;
  28. MapObjectID getObjGroupIndex() const override;
  29. MapObjectSubID getObjTypeIndex() const override;
  30. int3 visitablePos() const override;
  31. int3 getPosition() const override;
  32. template <typename Handler> void serialize(Handler &h)
  33. {
  34. h & bID;
  35. if (h.version < Handler::Version::NEW_TOWN_BUILDINGS)
  36. {
  37. // compatibility code
  38. si32 indexOnTV = 0; //identifies its index on towns vector
  39. BuildingSubID::EBuildingSubID bType = BuildingSubID::NONE;
  40. h & indexOnTV;
  41. h & bType;
  42. }
  43. }
  44. private:
  45. BuildingID bID; //from building list
  46. };
  47. class DLL_LINKAGE TownRewardableBuildingInstance : public TownBuildingInstance, public Rewardable::Interface
  48. {
  49. /// reward selected by player, no serialize
  50. ui16 selectedReward = 0;
  51. std::set<ObjectInstanceID> visitors;
  52. bool wasVisitedBefore(const CGHeroInstance * contextHero) const;
  53. void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
  54. Rewardable::Configuration generateConfiguration(vstd::RNG & rand) const;
  55. public:
  56. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  57. void onHeroVisit(const CGHeroInstance * h) const override;
  58. void newTurn(vstd::RNG & rand) const override;
  59. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  60. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  61. void initObj(vstd::RNG & rand) override;
  62. /// applies player selection of reward
  63. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  64. TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
  65. TownRewardableBuildingInstance(IGameCallback *cb);
  66. template <typename Handler> void serialize(Handler &h)
  67. {
  68. h & static_cast<TownBuildingInstance&>(*this);
  69. if (h.version >= Handler::Version::NEW_TOWN_BUILDINGS)
  70. h & static_cast<Rewardable::Interface&>(*this);
  71. h & visitors;
  72. }
  73. };
  74. /// Compatibility for old code
  75. class DLL_LINKAGE CTownCompatBuilding1 : public TownRewardableBuildingInstance
  76. {
  77. public:
  78. using TownRewardableBuildingInstance::TownRewardableBuildingInstance;
  79. };
  80. /// Compatibility for old code
  81. class DLL_LINKAGE CTownCompatBuilding2 : public TownRewardableBuildingInstance
  82. {
  83. public:
  84. using TownRewardableBuildingInstance::TownRewardableBuildingInstance;
  85. };
  86. VCMI_LIB_NAMESPACE_END