CArtHandler.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 CArtifact;
  20. class DLL_EXPORT CArtifact : public CBonusSystemNode //container for artifacts
  21. {
  22. protected:
  23. std::string name, description; //set if custom
  24. public:
  25. enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
  26. const std::string &Name() const; //getter
  27. const std::string &Description() const; //getter
  28. bool isBig () const;
  29. bool isModable () const;
  30. bool fitsAt (const std::map<ui16, CArtifact*> &artifWorn, ui16 slot) const;
  31. bool canBeAssembledTo (const std::map<ui16, CArtifact*> &artifWorn, ui32 artifactID) const;
  32. void addBonusesTo (BonusList *otherBonuses) const;
  33. void removeBonusesFrom (BonusList *otherBonuses) const;
  34. virtual void SetProperty (int mod){};
  35. virtual void Init(){};
  36. int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
  37. ui32 price;
  38. std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
  39. std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
  40. std::vector<ui32> * constituentOf; // Reverse map of constituents.
  41. EartClass aClass;
  42. si32 id;
  43. template <typename Handler> void serialize(Handler &h, const int version)
  44. {
  45. h & static_cast<CBonusSystemNode&>(*this);;
  46. h & name & description & price & possibleSlots & constituents & constituentOf & aClass & id;
  47. }
  48. CArtifact();
  49. ~CArtifact();
  50. //override
  51. //void getParents(TCNodes &out, const CBonusSystemNode *root = NULL) const;
  52. };
  53. class DLL_EXPORT IModableArt : public CArtifact //artifact which can have different properties, such as scroll or banner
  54. { //used only for dynamic cast :P
  55. public:
  56. si32 ID; //used for smart serialization
  57. template <typename Handler> void serialize(Handler &h, const int version)
  58. {
  59. h & static_cast<CArtifact&>(*this);
  60. h & ID;
  61. }
  62. };
  63. class DLL_EXPORT CScroll : public IModableArt // Spell Scroll
  64. {
  65. public:
  66. CScroll(){spellid=0;};
  67. CScroll(spelltype sid){spellid = sid;};
  68. spelltype spellid;
  69. void Init();
  70. void SetProperty (int mod){spellid = mod;};
  71. template <typename Handler> void serialize(Handler &h, const int version)
  72. {
  73. h & static_cast<IModableArt&>(*this);
  74. h & spellid;
  75. }
  76. };
  77. class DLL_EXPORT CCustomizableArt : public IModableArt // Warlord's Banner with multiple options
  78. {
  79. public:
  80. ui8 mode;
  81. CCustomizableArt(){mode=0;};
  82. void Init(){};
  83. void SetProperty (int mod){};
  84. template <typename Handler> void serialize(Handler &h, const int version)
  85. {
  86. h & static_cast<IModableArt&>(*this);
  87. h & mode;
  88. }
  89. };
  90. class DLL_EXPORT CCommanderArt : public IModableArt // Growing with time
  91. {
  92. public:
  93. ui32 level;
  94. CCommanderArt(){level = 0;};
  95. void Init(){};
  96. void SetProperty (int mod){level = mod;};
  97. void Upgrade(){level++;};
  98. template <typename Handler> void serialize(Handler &h, const int version)
  99. {
  100. h & static_cast<IModableArt&>(*this);
  101. h & level;
  102. }
  103. };
  104. class DLL_EXPORT CArtHandler //handles artifacts
  105. {
  106. void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL);
  107. public:
  108. std::vector<CArtifact*> treasures, minors, majors, relics;
  109. std::vector<CArtifact *> artifacts;
  110. std::vector<CArtifact *> allowedArtifacts;
  111. std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
  112. std::map<ui32, ui8> modableArtifacts; //1-scroll, 2-banner, 3-commander art with progressive bonus
  113. void loadArtifacts(bool onlyTxt);
  114. void sortArts();
  115. void addBonuses();
  116. void clear();
  117. void clearHlpLists();
  118. ui16 getRandomArt (int flags);
  119. ui16 getArtSync (ui32 rand, int flags);
  120. void getAllowedArts(std::vector<CArtifact*> &out, std::vector<CArtifact*> *arts, int flag);
  121. void getAllowed(std::vector<CArtifact*> &out, int flags);
  122. void erasePickedArt (si32 id);
  123. bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
  124. void equipArtifact (std::map<ui16, CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art);
  125. void unequipArtifact (std::map<ui16, CArtifact*> &artifWorn, ui16 slotID);
  126. void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
  127. static int convertMachineID(int id, bool creToArt);
  128. CArtHandler();
  129. ~CArtHandler();
  130. template <typename Handler> void serialize(Handler &h, const int version)
  131. {
  132. h & artifacts & allowedArtifacts & treasures & minors & majors & relics;
  133. //if(!h.saving) sortArts();
  134. }
  135. };
  136. #endif // __CARTHANDLER_H__