CArtHandler.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 //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. ui32 price;
  29. std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
  30. std::vector<ui32> * constituents; // Artifacts IDs a combined artifact consists of, or NULL.
  31. EartClass aClass;
  32. ui32 id;
  33. std::list<HeroBonus> bonuses; //bonuses given by artifact
  34. template <typename Handler> void serialize(Handler &h, const int version)
  35. {
  36. h & name & description & price & possibleSlots & constituents & aClass & id & bonuses;
  37. }
  38. };
  39. class DLL_EXPORT CArtHandler //handles artifacts
  40. {
  41. void giveArtBonus(int aid, HeroBonus::BonusType type, int val, int subtype = -1);
  42. public:
  43. std::vector<CArtifact*> treasures, minors, majors, relics;
  44. std::vector<CArtifact> artifacts;
  45. std::set<ui32> bigArtifacts; // Artifacts that cannot be moved to backpack, e.g. war machines.
  46. void loadArtifacts(bool onlyTxt);
  47. void sortArts();
  48. void addBonuses();
  49. void clear();
  50. bool isBigArtifact (ui32 artID) {return bigArtifacts.find(artID) != bigArtifacts.end();}
  51. void equipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID, ui32 artifactID);
  52. void unequipArtifact (std::map<ui16, ui32> &artifWorn, ui16 slotID);
  53. static int convertMachineID(int id, bool creToArt);
  54. CArtHandler();
  55. template <typename Handler> void serialize(Handler &h, const int version)
  56. {
  57. h & artifacts;
  58. if(!h.saving)
  59. sortArts();
  60. }
  61. };
  62. #endif // __CARTHANDLER_H__