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