CGDwelling.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * CGDwelling.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 "CArmedInstance.h"
  12. #include "IOwnableObject.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGDwelling;
  15. class DLL_LINKAGE CGDwellingRandomizationInfo
  16. {
  17. public:
  18. std::set<FactionID> allowedFactions;
  19. std::string instanceId;//vcmi map instance identifier
  20. int32_t identifier = 0;//h3m internal identifier
  21. uint8_t minLevel = 1;
  22. uint8_t maxLevel = 7; //minimal and maximal level of creature in dwelling: <1, 7>
  23. void serializeJson(JsonSerializeFormat & handler);
  24. };
  25. class DLL_LINKAGE CGDwelling : public CArmedInstance, public IOwnableObject
  26. {
  27. public:
  28. using TCreaturesSet = std::vector<std::pair<ui32, std::vector<CreatureID> > >;
  29. std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
  30. TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  31. CGDwelling(IGameInfoCallback *cb);
  32. ~CGDwelling() override;
  33. const IOwnableObject * asOwnable() const final;
  34. ResourceSet dailyIncome() const override;
  35. std::vector<CreatureID> providedCreatures() const override;
  36. protected:
  37. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  38. private:
  39. FactionID randomizeFaction(IGameRandomizer & gameRandomizer);
  40. int randomizeLevel(vstd::RNG & rand);
  41. void pickRandomObject(IGameRandomizer & gameRandomizer) override;
  42. void initObj(IGameRandomizer & gameRandomizer) override;
  43. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  44. void newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const override;
  45. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  46. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  47. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
  48. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  49. bool wasVisited (PlayerColor player) const override;
  50. void updateGuards(IGameEventCallback & gameEvents) const;
  51. void heroAcceptsCreatures(IGameEventCallback & gameEvents, const CGHeroInstance *h) const;
  52. public:
  53. template <typename Handler> void serialize(Handler &h)
  54. {
  55. h & static_cast<CArmedInstance&>(*this);
  56. h & creatures;
  57. }
  58. };
  59. VCMI_LIB_NAMESPACE_END