CArtHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef __CARTHANDLER_H__
  2. #define __CARTHANDLER_H__
  3. #include "../global.h"
  4. #include "../lib/HeroBonus.h"
  5. #include <set>
  6. #include <list>
  7. #include <string>
  8. #include <vector>
  9. /*
  10. * CArtHandler.h, part of VCMI engine
  11. *
  12. * Authors: listed in file AUTHORS in main folder
  13. *
  14. * License: GNU General Public License v2.0 or later
  15. * Full text of license available in license.txt file, in main folder
  16. *
  17. */
  18. class CDefHandler;
  19. class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
  20. {
  21. std::string name, description; //set if custom
  22. public:
  23. enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
  24. const std::string &Name() const; //getter
  25. const std::string &Description() const; //getter
  26. bool isBig () const;
  27. bool fitsAt (const std::map<ui16, ui32> &artifWorn, ui16 slot) const;
  28. bool canBeAssembledTo (const std::map<ui16, ui32> &artifWorn, ui32 artifactID) const;
  29. void addBonusesTo (BonusList *otherBonuses) const;
  30. void removeBonusesFrom (BonusList *otherBonuses) const;
  31. int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
  32. ui32 price;
  33. std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
  34. std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
  35. std::vector<ui32> * constituentOf; // Reverse map of constituents.
  36. EartClass aClass;
  37. si32 id;
  38. template <typename Handler> void serialize(Handler &h, const int version)
  39. {
  40. h & static_cast<CBonusSystemNode&>(*this);;
  41. h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
  42. }
  43. CArtifact();
  44. ~CArtifact();
  45. //override
  46. void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
  47. };
  48. class DLL_EXPORT IModableArt //artifact which can have different properties, such as scroll or banner
  49. {
  50. public:
  51. virtual void Init() = 0;
  52. };
  53. class DLL_EXPORT CScroll : public CArtifact, public IModableArt // Spell Scroll
  54. {
  55. public:
  56. spelltype spellid;
  57. void Init(){};
  58. template <typename Handler> void serialize(Handler &h, const int version)
  59. {
  60. h & static_cast<CArtifact&>(*this);
  61. h & spellid;
  62. }
  63. };
  64. class DLL_EXPORT CCustomizableArt : public CArtifact, public IModableArt // Warlord's Banner with multiple options
  65. {
  66. public:
  67. ui8 mode;
  68. void Init(){};
  69. void SelectMode (int mod){};
  70. template <typename Handler> void serialize(Handler &h, const int version)
  71. {
  72. h & static_cast<CArtifact&>(*this);
  73. h & mode;
  74. }
  75. };
  76. class DLL_EXPORT CCommanderArt : public CArtifact, public IModableArt // Growing with time
  77. {
  78. public:
  79. ui32 level;
  80. void Init(){};
  81. void Upgrade(){level++;};
  82. template <typename Handler> void serialize(Handler &h, const int version)
  83. {
  84. h & static_cast<CArtifact&>(*this);
  85. h & level;
  86. }
  87. };
  88. class DLL_EXPORT CArtHandler //handles artifacts
  89. {
  90. void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL);
  91. public:
  92. std::vector<CArtifact*> treasures, minors, majors, relics;
  93. std::vector<CArtifact *> artifacts;
  94. std::vector<CArtifact *> allowedArtifacts;
  95. std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
  96. void loadArtifacts(bool onlyTxt);
  97. void sortArts();
  98. void addBonuses();
  99. void clear();
  100. void clearHlpLists();
  101. ui16 getRandomArt (int flags);
  102. ui16 getArtSync (ui32 rand, int flags);
  103. void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> *arts, int flag);
  104. void getAllowed(std::vector<CArtifact*> &out, int flags);
  105. void erasePickedArt (si32 id);
  106. bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
  107. void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
  108. void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
  109. void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
  110. static int convertMachineID(int id, bool creToArt);
  111. CArtHandler();
  112. ~CArtHandler();
  113. template <typename Handler> void serialize(Handler &h, const int version)
  114. {
  115. h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
  116. //if(!h.saving) sortArts();
  117. }
  118. };
  119. #endif // __CARTHANDLER_H__