CArtifactInstance.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. VCMI_LIB_NAMESPACE_BEGIN
  15. struct ArtifactLocation;
  16. class DLL_LINKAGE CCombinedArtifactInstance
  17. {
  18. protected:
  19. CCombinedArtifactInstance() = default;
  20. public:
  21. struct PartInfo
  22. {
  23. ConstTransitivePtr<CArtifactInstance> art;
  24. ArtifactPosition slot;
  25. template <typename Handler> void serialize(Handler & h, const int version)
  26. {
  27. h & art;
  28. h & slot;
  29. }
  30. PartInfo(CArtifactInstance * art = nullptr, const ArtifactPosition & slot = ArtifactPosition::PRE_FIRST)
  31. : art(art), slot(slot) {};
  32. };
  33. void addPart(CArtifactInstance * art, const ArtifactPosition & slot);
  34. // Checks if supposed part inst is part of this combined art inst
  35. bool isPart(const CArtifactInstance * supposedPart) const;
  36. std::vector<PartInfo> & getPartsInfo();
  37. const std::vector<PartInfo> & getPartsInfo() const;
  38. template <typename Handler> void serialize(Handler & h, const int version)
  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
  60. : public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance, public CGrowingArtifactInstance
  61. {
  62. protected:
  63. void init();
  64. ArtifactInstanceID id;
  65. public:
  66. ConstTransitivePtr<CArtifact> artType;
  67. CArtifactInstance(CArtifact * art);
  68. CArtifactInstance();
  69. void setType(CArtifact * art);
  70. std::string nodeName() const override;
  71. std::string getDescription() const;
  72. ArtifactID getTypeId() const;
  73. ArtifactInstanceID getId() const;
  74. void setId(ArtifactInstanceID id);
  75. bool canBePutAt(const ArtifactLocation & al, bool assumeDestRemoved = false) const;
  76. bool isCombined() const;
  77. void putAt(const ArtifactLocation & al);
  78. void removeFrom(const ArtifactLocation & al);
  79. void move(const ArtifactLocation & src, const ArtifactLocation & dst);
  80. void deserializationFix();
  81. template <typename Handler> void serialize(Handler & h, const int version)
  82. {
  83. h & static_cast<CBonusSystemNode&>(*this);
  84. h & static_cast<CCombinedArtifactInstance&>(*this);
  85. h & artType;
  86. h & id;
  87. BONUS_TREE_DESERIALIZATION_FIX
  88. }
  89. };
  90. VCMI_LIB_NAMESPACE_END