CArtifactInstance.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "GameCallbackHolder.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. struct ArtifactLocation;
  15. class CGameState;
  16. class CArtifactSet;
  17. class DLL_LINKAGE CCombinedArtifactInstance : public GameCallbackHolder
  18. {
  19. protected:
  20. using GameCallbackHolder::GameCallbackHolder;
  21. public:
  22. using ArtPlacementMap = std::map<const CArtifactInstance *, ArtifactPosition>;
  23. struct PartInfo
  24. {
  25. private:
  26. const CArtifactInstance * artifactPtr = nullptr;
  27. ArtifactInstanceID artifactID;
  28. public:
  29. PartInfo() = default;
  30. PartInfo(const CArtifactInstance * artifact, ArtifactPosition slot);
  31. ArtifactPosition slot;
  32. const CArtifactInstance * getArtifact() const;
  33. ArtifactInstanceID getArtifactID() const;
  34. template <typename Handler>
  35. void serialize(Handler & h);
  36. };
  37. void addPart(const CArtifactInstance * art, const ArtifactPosition & slot);
  38. // Checks if supposed part inst is part of this combined art inst
  39. bool isPart(const CArtifactInstance * supposedPart) const;
  40. bool hasParts() const;
  41. const std::vector<PartInfo> & getPartsInfo() const;
  42. void addPlacementMap(const ArtPlacementMap & placementMap);
  43. template <typename Handler> void serialize(Handler & h)
  44. {
  45. h & partsInfo;
  46. }
  47. protected:
  48. std::vector<PartInfo> partsInfo;
  49. };
  50. class DLL_LINKAGE CScrollArtifactInstance
  51. {
  52. protected:
  53. CScrollArtifactInstance() = default;
  54. public:
  55. SpellID getScrollSpellID() const;
  56. };
  57. class DLL_LINKAGE CGrowingArtifactInstance
  58. {
  59. protected:
  60. CGrowingArtifactInstance() = default;
  61. public:
  62. void growingUp();
  63. };
  64. class DLL_LINKAGE CArtifactInstance final
  65. : public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance, public CGrowingArtifactInstance
  66. {
  67. ArtifactInstanceID id;
  68. ArtifactID artTypeID;
  69. public:
  70. CArtifactInstance(IGameCallback *cb, const CArtifact * art);
  71. CArtifactInstance(IGameCallback *cb);
  72. void setType(const CArtifact * art);
  73. std::string nodeName() const override;
  74. ArtifactID getTypeId() const;
  75. const CArtifact * getType() const;
  76. ArtifactInstanceID getId() const;
  77. void setId(ArtifactInstanceID id);
  78. static void saveCompatibilityFixArtifactID(std::shared_ptr<CArtifactInstance> self);
  79. bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE,
  80. bool assumeDestRemoved = false) const;
  81. bool isCombined() const;
  82. bool isScroll() const;
  83. void attachToBonusSystem(CGameState & gs);
  84. template <typename Handler> void serialize(Handler & h)
  85. {
  86. h & static_cast<CBonusSystemNode&>(*this);
  87. h & static_cast<CCombinedArtifactInstance&>(*this);
  88. h & artTypeID;
  89. h & id;
  90. if(!h.saving && h.loadingGamestate)
  91. setType(artTypeID.toArtifact());
  92. }
  93. };
  94. template <typename Handler>
  95. void CCombinedArtifactInstance::PartInfo::serialize(Handler & h)
  96. {
  97. if (h.saving || h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
  98. {
  99. h & artifactID;
  100. }
  101. else
  102. {
  103. std::shared_ptr<CArtifactInstance> pointer;
  104. h & pointer;
  105. if (pointer->getId() == ArtifactInstanceID())
  106. CArtifactInstance::saveCompatibilityFixArtifactID(pointer);
  107. artifactID = pointer->getId();
  108. }
  109. h & slot;
  110. }
  111. VCMI_LIB_NAMESPACE_END