CCampaignHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef __CCAMPAIGNHANDLER_H__
  2. #define __CCAMPAIGNHANDLER_H__
  3. #include "../global.h"
  4. #include <string>
  5. #include <vector>
  6. /*
  7. * CCampaignHandler.h, part of VCMI engine
  8. *
  9. * Authors: listed in file AUTHORS in main folder
  10. *
  11. * License: GNU General Public License v2.0 or later
  12. * Full text of license available in license.txt file, in main folder
  13. *
  14. */
  15. class DLL_EXPORT CCampaignHeader
  16. {
  17. public:
  18. si32 version; //5 - AB, 6 - SoD, WoG - ?!?
  19. ui8 mapVersion; //CampText.txt's format
  20. std::string name, description;
  21. ui8 difficultyChoosenByPlayer;
  22. ui8 music; //CmpMusic.txt, start from 0
  23. std::string filename;
  24. ui8 loadFromLod; //if true, this campaign must be loaded fro, .lod file
  25. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  26. {
  27. h & version & mapVersion & name & description & difficultyChoosenByPlayer & music & filename & loadFromLod;
  28. }
  29. };
  30. class DLL_EXPORT CScenarioTravel
  31. {
  32. public:
  33. ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
  34. ui8 monstersKeptByHero[19];
  35. ui8 artifsKeptByHero[18];
  36. ui8 startOptions; //1 - start bonus, 2 - traveling hero, 3 - hero options
  37. ui8 playerColor; //only for startOptions == 1
  38. struct DLL_EXPORT STravelBonus
  39. {
  40. ui8 type; //0 - spell, 1 - monster, 2 - building, 3 - artifact, 4 - spell scroll, 5 - prim skill, 6 - sec skill, 7 - resource,
  41. //8 - player from previous scenario, 9 - hero [???]
  42. si32 info1, info2, info3; //purpose depends on type
  43. bool isBonusForHero() const;
  44. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  45. {
  46. h & type & info1 & info2 & info3;
  47. }
  48. };
  49. std::vector<STravelBonus> bonusesToChoose;
  50. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  51. {
  52. h & whatHeroKeeps & monstersKeptByHero & artifsKeptByHero & startOptions & playerColor & bonusesToChoose;
  53. }
  54. };
  55. class DLL_EXPORT CCampaignScenario
  56. {
  57. public:
  58. std::string mapName;
  59. ui32 packedMapSize; //generally not used
  60. ui16 preconditionRegion; //what we need to conquer to conquer this one (bitfield!)
  61. ui8 regionColor;
  62. ui8 difficulty;
  63. ui8 conquered;
  64. std::string regionText;
  65. struct DLL_EXPORT SScenarioPrologEpilog
  66. {
  67. ui8 hasPrologEpilog;
  68. ui8 prologVideo; // from CmpMovie.txt
  69. ui8 prologMusic; // from CmpMusic.txt
  70. std::string prologText;
  71. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  72. {
  73. h & hasPrologEpilog & prologVideo & prologMusic & prologText;
  74. }
  75. };
  76. SScenarioPrologEpilog prolog, epilog;
  77. CScenarioTravel travelOptions;
  78. bool isNotVoid() const;
  79. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  80. {
  81. h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & conquered & regionText &
  82. prolog & epilog & travelOptions;
  83. }
  84. };
  85. class DLL_EXPORT CCampaign
  86. {
  87. public:
  88. CCampaignHeader header;
  89. std::vector<CCampaignScenario> scenarios;
  90. std::map<int, std::string> mapPieces; //binary h3ms, scenario number -> map data
  91. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  92. {
  93. h & header & scenarios & mapPieces;
  94. }
  95. bool conquerable(int whichScenario) const;
  96. CCampaign();
  97. };
  98. class DLL_EXPORT CCampaignHandler
  99. {
  100. static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
  101. static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion );
  102. static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version);
  103. static std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
  104. static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos
  105. static unsigned char * getFile(const std::string & name, bool fromLod, int & outSize);
  106. public:
  107. enum GetMode {RoE, AB, SoD, WoG, Custom, ALL};
  108. static std::vector<CCampaignHeader> getCampaignHeaders(GetMode mode);
  109. static CCampaignHeader getHeader( const std::string & name, bool fromLod ); //name - name of appropriate file
  110. static CCampaign * getCampaign(const std::string & name, bool fromLod); //name - name of appropriate file
  111. };
  112. #endif /* __CCAMPAIGNHANDLER_H__ */