CArtifactInstance.h 2.6 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. ConstTransitivePtr<CArtifactInstance> art;
  25. ArtifactPosition slot;
  26. template <typename Handler> void serialize(Handler & h, const int version)
  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. const std::vector<PartInfo> & getPartsInfo() const;
  38. void addPlacementMap(CArtifactSet::ArtPlacementMap & placementMap);
  39. template <typename Handler> void serialize(Handler & h, const int version)
  40. {
  41. h & partsInfo;
  42. }
  43. protected:
  44. std::vector<PartInfo> partsInfo;
  45. };
  46. class DLL_LINKAGE CScrollArtifactInstance
  47. {
  48. protected:
  49. CScrollArtifactInstance() = default;
  50. public:
  51. SpellID getScrollSpellID() const;
  52. };
  53. class DLL_LINKAGE CGrowingArtifactInstance
  54. {
  55. protected:
  56. CGrowingArtifactInstance() = default;
  57. public:
  58. void growingUp();
  59. };
  60. class DLL_LINKAGE CArtifactInstance
  61. : public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance, public CGrowingArtifactInstance
  62. {
  63. protected:
  64. void init();
  65. ArtifactInstanceID id;
  66. public:
  67. ConstTransitivePtr<CArtifact> artType;
  68. CArtifactInstance(CArtifact * art);
  69. CArtifactInstance();
  70. void setType(CArtifact * art);
  71. std::string nodeName() const override;
  72. std::string getDescription() const;
  73. ArtifactID getTypeId() const;
  74. ArtifactInstanceID getId() const;
  75. void setId(ArtifactInstanceID id);
  76. bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const;
  77. bool isCombined() const;
  78. void putAt(const ArtifactLocation & al);
  79. void removeFrom(const ArtifactLocation & al);
  80. void move(const ArtifactLocation & src, const ArtifactLocation & dst);
  81. void deserializationFix();
  82. template <typename Handler> void serialize(Handler & h, const int version)
  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