CGDwelling.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 CSpecObjInfo
  15. {
  16. public:
  17. CSpecObjInfo();
  18. virtual ~CSpecObjInfo() = default;
  19. virtual void serializeJson(JsonSerializeFormat & handler) = 0;
  20. const CGDwelling * owner;
  21. };
  22. class DLL_LINKAGE CCreGenAsCastleInfo : public virtual CSpecObjInfo
  23. {
  24. public:
  25. bool asCastle = false;
  26. ui32 identifier = 0;//h3m internal identifier
  27. std::vector<bool> allowedFactions;
  28. std::string instanceId;//vcmi map instance identifier
  29. void serializeJson(JsonSerializeFormat & handler) override;
  30. };
  31. class DLL_LINKAGE CCreGenLeveledInfo : public virtual CSpecObjInfo
  32. {
  33. public:
  34. ui8 minLevel = 1;
  35. ui8 maxLevel = 7; //minimal and maximal level of creature in dwelling: <1, 7>
  36. void serializeJson(JsonSerializeFormat & handler) override;
  37. };
  38. class DLL_LINKAGE CCreGenLeveledCastleInfo : public CCreGenAsCastleInfo, public CCreGenLeveledInfo
  39. {
  40. public:
  41. CCreGenLeveledCastleInfo() = default;
  42. void serializeJson(JsonSerializeFormat & handler) override;
  43. };
  44. class DLL_LINKAGE CGDwelling : public CArmedInstance
  45. {
  46. public:
  47. typedef std::vector<std::pair<ui32, std::vector<CreatureID> > > TCreaturesSet;
  48. CSpecObjInfo * info; //random dwelling options; not serialized
  49. TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  50. CGDwelling();
  51. ~CGDwelling() override;
  52. void initRandomObjectInfo();
  53. protected:
  54. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  55. private:
  56. void initObj(CRandomGenerator & rand) override;
  57. void onHeroVisit(const CGHeroInstance * h) const override;
  58. void newTurn(CRandomGenerator & rand) const override;
  59. void setPropertyDer(ui8 what, ui32 val) override;
  60. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  61. void blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const override;
  62. void updateGuards() const;
  63. void heroAcceptsCreatures(const CGHeroInstance *h) const;
  64. public:
  65. template <typename Handler> void serialize(Handler &h, const int version)
  66. {
  67. h & static_cast<CArmedInstance&>(*this);
  68. h & creatures;
  69. }
  70. };
  71. VCMI_LIB_NAMESPACE_END