TownBuildingInstance.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. VCMI_LIB_NAMESPACE_END