CArtHandler.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 "../lib/ConstTransitivePtr.h"
  8. /*
  9. * CArtHandler.h, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. class CDefHandler;
  18. class CArtifact;
  19. class CGHeroInstance;
  20. struct ArtifactLocation;
  21. class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
  22. {
  23. protected:
  24. std::string name, description; //set if custom
  25. public:
  26. enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
  27. const std::string &Name() const; //getter
  28. const std::string &Description() const; //getter
  29. bool isBig () const;
  30. bool isModable () const;
  31. bool fitsAt (const std::map<ui16, const CArtifact*> &artifWorn, ui16 slot) const;
  32. bool canBeAssembledTo (const std::map<ui16, const CArtifact*> &artifWorn, ui32 artifactID) const;
  33. void addBonusesTo (BonusList *otherBonuses) const;
  34. void removeBonusesFrom (BonusList *otherBonuses) const;
  35. virtual void SetProperty (int mod){};
  36. virtual void Init(){};
  37. int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
  38. std::string nodeName() const OVERRIDE;
  39. ui32 price;
  40. std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
  41. std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
  42. std::vector<ui32> * constituentOf; // Reverse map of constituents.
  43. EartClass aClass;
  44. si32 id;
  45. template <typename Handler> void serialize(Handler &h, const int version)
  46. {
  47. h & static_cast<CBonusSystemNode&>(*this);;
  48. h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
  49. }
  50. CArtifact();
  51. ~CArtifact();
  52. //override
  53. //void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
  54. };
  55. class DLL_EXPORT CArtifactInstance : public CBonusSystemNode
  56. {
  57. void init();
  58. public:
  59. ConstTransitivePtr<CArtifact> artType;
  60. si32 id; //id of the instance
  61. CArtifactInstance();
  62. CArtifactInstance(CArtifact *Art);
  63. std::string nodeName() const OVERRIDE;
  64. void setType(CArtifact *Art);
  65. int firstAvailableSlot(const CGHeroInstance *h) const;
  66. int firstBackpackSlot(const CGHeroInstance *h) const;
  67. virtual bool canBePutAt(const ArtifactLocation &al, bool assumeDestRemoved = false) const;
  68. virtual bool canBeDisassembled() const;
  69. std::vector<const CArtifact *> assemblyPossibilities(const CGHeroInstance *h) const;
  70. void putAt(CGHeroInstance *h, ui16 slot);
  71. void removeFrom(CGHeroInstance *h, ui16 slot);
  72. template <typename Handler> void serialize(Handler &h, const int version)
  73. {
  74. h & static_cast<CBonusSystemNode&>(*this);
  75. h & artType & id;
  76. }
  77. static CArtifactInstance *createScroll(const CSpell *s);
  78. };
  79. class DLL_EXPORT CCombinedArtifactInstance : public CArtifactInstance
  80. {
  81. public:
  82. bool canBePutAt(const ArtifactLocation &al, bool assumeDestRemoved = false) const OVERRIDE;
  83. bool canBeDisassembled() const OVERRIDE;
  84. };
  85. class DLL_EXPORT IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner
  86. { //used only for dynamic cast :P
  87. public:
  88. si32 ID; //used for smart serialization
  89. template <typename Handler> void serialize(Handler &h, const int version)
  90. {
  91. h & static_cast<CArtifact&>(*this);
  92. h & ID;
  93. }
  94. };
  95. class DLL_EXPORT CScroll : public IModableArt // Spell Scroll
  96. {
  97. public:
  98. CScroll(){spellid=0;};
  99. CScroll(spelltype sid){spellid = sid;};
  100. spelltype spellid;
  101. void Init();
  102. void SetProperty (int mod){spellid = mod;};
  103. template <typename Handler> void serialize(Handler &h, const int version)
  104. {
  105. h & static_cast<IModableArt&>(*this);
  106. h & spellid;
  107. }
  108. };
  109. class DLL_EXPORT CCustomizableArt : public IModableArt // Warlord's Banner with multiple options
  110. {
  111. public:
  112. ui8 mode;
  113. CCustomizableArt(){mode=0;};
  114. void Init(){};
  115. void SetProperty (int mod){};
  116. template <typename Handler> void serialize(Handler &h, const int version)
  117. {
  118. h & static_cast<IModableArt&>(*this);
  119. h & mode;
  120. }
  121. };
  122. class DLL_EXPORT CCommanderArt : public IModableArt // Growing with time
  123. {
  124. public:
  125. ui32 level;
  126. CCommanderArt(){level = 0;};
  127. void Init(){};
  128. void SetProperty (int mod){level = mod;};
  129. void Upgrade(){level++;};
  130. template <typename Handler> void serialize(Handler &h, const int version)
  131. {
  132. h & static_cast<IModableArt&>(*this);
  133. h & level;
  134. }
  135. };
  136. class DLL_EXPORT CArtHandler //handles artifacts
  137. {
  138. void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL);
  139. public:
  140. std::vector<CArtifact*> treasures, minors, majors, relics;
  141. std::vector< ConstTransitivePtr<CArtifact> > artifacts;
  142. std::vector<CArtifact *> allowedArtifacts;
  143. std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
  144. std::map<ui32, ui8> modableArtifacts; //1-scroll, 2-banner, 3-commander art with progressive bonus
  145. void loadArtifacts(bool onlyTxt);
  146. void sortArts();
  147. void addBonuses();
  148. void clear();
  149. void clearHlpLists();
  150. ui16 getRandomArt (int flags);
  151. ui16 getArtSync (ui32 rand, int flags);
  152. void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag);
  153. void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
  154. void erasePickedArt (si32 id);
  155. bool isBigArtifact (ui32 artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
  156. void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const;
  157. void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const;
  158. void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
  159. static int convertMachineID(int id, bool creToArt);
  160. CArtHandler();
  161. ~CArtHandler();
  162. template <typename Handler> void serialize(Handler &h, const int version)
  163. {
  164. h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
  165. //if(!h.saving) sortArts();
  166. }
  167. };
  168. #endif // __CARTHANDLER_H__