CGDwelling.h 2.0 KB

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