CArtifactInstance.h 2.5 KB

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