CArtifactInstance.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * CArtifactInstance.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 "bonuses/CBonusSystemNode.h"
  12. #include "GameConstants.h"
  13. #include "ConstTransitivePtr.h"
  14. #include "CArtHandler.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. struct ArtifactLocation;
  17. class DLL_LINKAGE CCombinedArtifactInstance
  18. {
  19. protected:
  20. CCombinedArtifactInstance() = default;
  21. public:
  22. struct PartInfo
  23. {
  24. CArtifactInstance * art;
  25. ArtifactPosition slot;
  26. template <typename Handler> void serialize(Handler & h)
  27. {
  28. h & art;
  29. h & slot;
  30. }
  31. PartInfo(CArtifactInstance * art = nullptr, const ArtifactPosition & slot = ArtifactPosition::PRE_FIRST)
  32. : art(art), slot(slot) {};
  33. };
  34. void addPart(CArtifactInstance * art, const ArtifactPosition & slot);
  35. // Checks if supposed part inst is part of this combined art inst
  36. bool isPart(const CArtifactInstance * supposedPart) const;
  37. bool hasParts() const;
  38. const std::vector<PartInfo> & getPartsInfo() const;
  39. void addPlacementMap(const CArtifactSet::ArtPlacementMap & placementMap);
  40. template <typename Handler> void serialize(Handler & h)
  41. {
  42. h & partsInfo;
  43. }
  44. protected:
  45. std::vector<PartInfo> partsInfo;
  46. };
  47. class DLL_LINKAGE CScrollArtifactInstance
  48. {
  49. protected:
  50. CScrollArtifactInstance() = default;
  51. public:
  52. SpellID getScrollSpellID() const;
  53. };
  54. class DLL_LINKAGE CGrowingArtifactInstance
  55. {
  56. protected:
  57. CGrowingArtifactInstance() = default;
  58. public:
  59. void growingUp();
  60. };
  61. class DLL_LINKAGE CArtifactInstance
  62. : public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance, public CGrowingArtifactInstance
  63. {
  64. protected:
  65. void init();
  66. ArtifactInstanceID id;
  67. public:
  68. const CArtifact * artType = nullptr;
  69. CArtifactInstance(const CArtifact * art);
  70. CArtifactInstance();
  71. void setType(const CArtifact * art);
  72. std::string nodeName() const override;
  73. std::string getDescription() const;
  74. ArtifactID getTypeId() const;
  75. ArtifactInstanceID getId() const;
  76. void setId(ArtifactInstanceID id);
  77. bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE,
  78. bool assumeDestRemoved = false) const;
  79. bool isCombined() const;
  80. bool isScroll() const;
  81. void deserializationFix();
  82. template <typename Handler> void serialize(Handler & h)
  83. {
  84. h & static_cast<CBonusSystemNode&>(*this);
  85. h & static_cast<CCombinedArtifactInstance&>(*this);
  86. h & artType;
  87. h & id;
  88. BONUS_TREE_DESERIALIZATION_FIX
  89. }
  90. };
  91. VCMI_LIB_NAMESPACE_END