CArtifact.h 3.7 KB

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