TownBuildingInstance.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. const IOwnableObject * asOwnable() const override;
  31. int3 visitablePos() const override;
  32. int3 anchorPos() const override;
  33. template <typename Handler> void serialize(Handler &h)
  34. {
  35. h & bID;
  36. if (h.version < Handler::Version::NEW_TOWN_BUILDINGS)
  37. {
  38. // compatibility code
  39. si32 indexOnTV = 0; //identifies its index on towns vector
  40. BuildingSubID::EBuildingSubID bType = BuildingSubID::NONE;
  41. h & indexOnTV;
  42. h & bType;
  43. }
  44. }
  45. private:
  46. BuildingID bID; //from building list
  47. };
  48. class DLL_LINKAGE TownRewardableBuildingInstance : public TownBuildingInstance, public Rewardable::Interface
  49. {
  50. /// reward selected by player, no serialize
  51. ui16 selectedReward = 0;
  52. std::set<ObjectInstanceID> visitors;
  53. bool wasVisitedBefore(const CGHeroInstance * contextHero) const override;
  54. void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override;
  55. Rewardable::Configuration generateConfiguration(vstd::RNG & rand) const;
  56. const IObjectInterface * getObject() const override;
  57. bool wasVisited(PlayerColor player) const override;
  58. void markAsVisited(const CGHeroInstance * hero) const override;
  59. void markAsScouted(const CGHeroInstance * hero) const override;
  60. public:
  61. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  62. void onHeroVisit(const CGHeroInstance * h) const override;
  63. bool wasVisited(const CGHeroInstance * contextHero) const override;
  64. void newTurn(vstd::RNG & rand) const override;
  65. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  66. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  67. /// applies player selection of reward
  68. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  69. TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
  70. TownRewardableBuildingInstance(IGameCallback *cb);
  71. template <typename Handler> void serialize(Handler &h)
  72. {
  73. h & static_cast<TownBuildingInstance&>(*this);
  74. if (h.version >= Handler::Version::NEW_TOWN_BUILDINGS)
  75. h & static_cast<Rewardable::Interface&>(*this);
  76. h & visitors;
  77. }
  78. };
  79. VCMI_LIB_NAMESPACE_END