CArtifact.h 4.4 KB

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