2
0

CArtHandler.h 1.9 KB

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