CArtifact.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * CArtifact.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 "StdInc.h"
  12. #include "ArtBearer.h"
  13. #include "EArtifactClass.h"
  14. #include "../../bonuses/CBonusSystemNode.h"
  15. #include "../../networkPacks/ArtifactLocation.h"
  16. #include <vcmi/Artifact.h>
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class CArtifactSet;
  19. class DLL_LINKAGE CCombinedArtifact
  20. {
  21. protected:
  22. CCombinedArtifact()
  23. : fused(false){};
  24. std::vector<const CArtifact *> constituents; // Artifacts IDs a combined artifact consists of, or nullptr.
  25. std::set<const CArtifact *> partOf; // Reverse map of constituents - combined arts that include this art
  26. bool fused;
  27. public:
  28. bool isCombined() const;
  29. const std::vector<const CArtifact *> & getConstituents() const;
  30. const std::set<const CArtifact *> & getPartOf() const;
  31. void setFused(bool isFused);
  32. bool isFused() const;
  33. bool hasParts() const;
  34. };
  35. class DLL_LINKAGE CScrollArtifact
  36. {
  37. protected:
  38. CScrollArtifact() = default;
  39. public:
  40. bool isScroll() const;
  41. };
  42. class DLL_LINKAGE CGrowingArtifact
  43. {
  44. protected:
  45. CGrowingArtifact() = default;
  46. std::vector<std::pair<ui16, Bonus>> bonusesPerLevel; // Bonus given each n levels
  47. std::vector<std::pair<ui16, Bonus>> thresholdBonuses; // After certain level they will be added once
  48. public:
  49. bool isGrowing() const;
  50. std::vector<std::pair<ui16, Bonus>> & getBonusesPerLevel();
  51. const std::vector<std::pair<ui16, Bonus>> & getBonusesPerLevel() const;
  52. std::vector<std::pair<ui16, Bonus>> & getThresholdBonuses();
  53. const std::vector<std::pair<ui16, Bonus>> & getThresholdBonuses() const;
  54. };
  55. class DLL_LINKAGE CChargedArtifact
  56. {
  57. std::optional<DischargeArtifactCondition> condition;
  58. bool removeOnDepletion;
  59. uint16_t defaultStartCharges;
  60. protected:
  61. CChargedArtifact();
  62. public:
  63. bool isCharged() const;
  64. void setCondition(const DischargeArtifactCondition & condition);
  65. void setRemoveOnDepletion(const bool remove);
  66. void setDefaultStartCharges(const uint16_t charges);
  67. uint16_t getDefaultStartCharges() const;
  68. std::optional<DischargeArtifactCondition> getDischargeCondition() const;
  69. bool getRemoveOnDepletion() const;
  70. };
  71. // Container for artifacts. Not for instances.
  72. class DLL_LINKAGE CArtifact final : public Artifact, public CBonusSystemNode,
  73. public CCombinedArtifact, public CScrollArtifact, public CGrowingArtifact, public CChargedArtifact
  74. {
  75. ArtifactID id;
  76. std::string image;
  77. std::string large; // big image for custom artifacts, used in drag & drop
  78. std::string advMapDef; // used for adventure map object
  79. std::string modScope;
  80. std::string identifier;
  81. int32_t iconIndex;
  82. uint32_t price;
  83. CreatureID warMachine;
  84. // Bearer Type => ids of slots where artifact can be placed
  85. std::map<ArtBearer, std::vector<ArtifactPosition>> possibleSlots;
  86. public:
  87. EArtifactClass aClass = EArtifactClass::ART_SPECIAL;
  88. bool onlyOnWaterMap;
  89. int32_t getIndex() const override;
  90. int32_t getIconIndex() const override;
  91. std::string getJsonKey() const override;
  92. std::string getModScope() const override;
  93. void registerIcons(const IconRegistar & cb) const override;
  94. ArtifactID getId() const override;
  95. const IBonusBearer * getBonusBearer() const override;
  96. std::string getDescriptionTranslated() const override;
  97. std::string getEventTranslated() const override;
  98. std::string getNameTranslated() const override;
  99. std::string getDescriptionTextID() const override;
  100. std::string getEventTextID() const override;
  101. std::string getNameTextID() const override;
  102. uint32_t getPrice() const override;
  103. CreatureID getWarMachine() const override;
  104. bool isBig() const override;
  105. bool isTradable() const override;
  106. int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
  107. std::string nodeName() const override;
  108. void addNewBonus(const std::shared_ptr<Bonus> & b) override;
  109. const std::map<ArtBearer, std::vector<ArtifactPosition>> & getPossibleSlots() const;
  110. virtual bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE, bool assumeDestRemoved = false) const;
  111. void updateFrom(const JsonNode & data);
  112. // Is used for testing purposes only
  113. void setImage(int32_t iconIndex, const std::string & image, const std::string & large);
  114. CArtifact();
  115. ~CArtifact();
  116. friend class CArtHandler;
  117. };
  118. VCMI_LIB_NAMESPACE_END