CArtifact.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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, std::shared_ptr<Bonus>>> bonusesPerLevel; // Bonus given each n levels
  46. std::vector<std::pair<ui16, std::shared_ptr<Bonus>>> thresholdBonuses; // After certain level they will be added once
  47. public:
  48. bool isGrowing() const;
  49. std::vector<std::pair<ui16, std::shared_ptr<Bonus>>> & getBonusesPerLevel();
  50. const std::vector<std::pair<ui16, std::shared_ptr<Bonus>>> & getBonusesPerLevel() const;
  51. std::vector<std::pair<ui16, std::shared_ptr<Bonus>>> & getThresholdBonuses();
  52. const std::vector<std::pair<ui16, std::shared_ptr<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. std::optional<uint16_t> getChargeCost(const SpellID & id) 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 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. std::string scenarioBonus;
  89. EArtifactClass aClass = EArtifactClass::ART_SPECIAL;
  90. bool onlyOnWaterMap;
  91. int32_t getIndex() const override;
  92. int32_t getIconIndex() const override;
  93. std::string getJsonKey() const override;
  94. std::string getModScope() const override;
  95. void registerIcons(const IconRegistar & cb) const override;
  96. ArtifactID getId() const override;
  97. const IBonusBearer * getBonusBearer() const override;
  98. std::string getDescriptionTranslated() const override;
  99. std::string getEventTranslated() const override;
  100. std::string getNameTranslated() const override;
  101. std::string getDescriptionTextID() const override;
  102. std::string getEventTextID() const override;
  103. std::string getNameTextID() const override;
  104. std::string getBonusTextID(const std::string & bonusID) const;
  105. uint32_t getPrice() const override;
  106. CreatureID getWarMachine() const override;
  107. bool isBig() const override;
  108. bool isTradable() const override;
  109. int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
  110. std::string nodeName() const override;
  111. void addNewBonus(const std::shared_ptr<Bonus> & b) override;
  112. const std::map<ArtBearer, std::vector<ArtifactPosition>> & getPossibleSlots() const;
  113. virtual bool canBePutAt(const CArtifactSet * artSet, ArtifactPosition slot = ArtifactPosition::FIRST_AVAILABLE, bool assumeDestRemoved = false) const;
  114. void updateFrom(const JsonNode & data);
  115. // Is used for testing purposes only
  116. void setImage(int32_t iconIndex, const std::string & image, const std::string & large);
  117. CArtifact();
  118. ~CArtifact();
  119. friend class CArtHandler;
  120. };
  121. VCMI_LIB_NAMESPACE_END