CArtifactInstance.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 CGameState;
  16. class DLL_LINKAGE CCombinedArtifactInstance : public GameCallbackHolder
  17. {
  18. protected:
  19. using GameCallbackHolder::GameCallbackHolder;
  20. public:
  21. struct PartInfo : public GameCallbackHolder
  22. {
  23. explicit PartInfo(IGameCallback * cb);
  24. PartInfo(const CArtifactInstance * artifact, ArtifactPosition slot);
  25. ArtifactInstanceID artifactID;
  26. ArtifactPosition slot;
  27. const CArtifactInstance * getArtifact() const;
  28. template <typename Handler> void serialize(Handler & h)
  29. {
  30. h & artifactID;
  31. h & slot;
  32. }
  33. };
  34. void addPart(const 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. bool hasParts() const;
  38. const std::vector<PartInfo> & getPartsInfo() const;
  39. void addPlacementMap(const CArtifactSet::ArtPlacementMap & placementMap);
  40. template <typename Handler> void serialize(Handler & h)
  41. {
  42. h & partsInfo;
  43. }
  44. protected:
  45. std::vector<PartInfo> partsInfo;
  46. };
  47. class DLL_LINKAGE CScrollArtifactInstance
  48. {
  49. protected:
  50. CScrollArtifactInstance() = default;
  51. public:
  52. SpellID getScrollSpellID() const;
  53. };
  54. class DLL_LINKAGE CGrowingArtifactInstance
  55. {
  56. protected:
  57. CGrowingArtifactInstance() = default;
  58. public:
  59. void growingUp();
  60. };
  61. class DLL_LINKAGE CArtifactInstance final
  62. : public CBonusSystemNode, public CCombinedArtifactInstance, public CScrollArtifactInstance, public CGrowingArtifactInstance
  63. {
  64. ArtifactInstanceID id;
  65. ArtifactID artTypeID;
  66. public:
  67. CArtifactInstance(IGameCallback *cb, const CArtifact * art);
  68. CArtifactInstance(IGameCallback *cb);
  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 attachToBonusSystem(CGameState * gs);
  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. if(!h.saving && h.loadingGamestate)
  87. setType(artTypeID.toArtifact());
  88. }
  89. };
  90. VCMI_LIB_NAMESPACE_END