TownBuildingInstance.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 getPosition() 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;
  54. void grantReward(ui32 rewardID, const CGHeroInstance * hero) const;
  55. Rewardable::Configuration generateConfiguration(vstd::RNG & rand) const;
  56. public:
  57. void setProperty(ObjProperty what, ObjPropertyID identifier) override;
  58. void onHeroVisit(const CGHeroInstance * h) const override;
  59. bool wasVisited(const CGHeroInstance * contextHero) const override;
  60. void newTurn(vstd::RNG & rand) const override;
  61. /// gives second part of reward after hero level-ups for proper granting of spells/mana
  62. void heroLevelUpDone(const CGHeroInstance *hero) const override;
  63. void initObj(vstd::RNG & rand) override;
  64. /// applies player selection of reward
  65. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  66. TownRewardableBuildingInstance(CGTownInstance * town, const BuildingID & index, vstd::RNG & rand);
  67. TownRewardableBuildingInstance(IGameCallback *cb);
  68. template <typename Handler> void serialize(Handler &h)
  69. {
  70. h & static_cast<TownBuildingInstance&>(*this);
  71. if (h.version >= Handler::Version::NEW_TOWN_BUILDINGS)
  72. h & static_cast<Rewardable::Interface&>(*this);
  73. h & visitors;
  74. }
  75. };
  76. VCMI_LIB_NAMESPACE_END