CCampaignHandler.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  44. {
  45. h & type & info1 & info2 & info3;
  46. }
  47. };
  48. std::vector<STravelBonus> bonusesToChoose;
  49. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  50. {
  51. h & whatHeroKeeps & monstersKeptByHero & artifsKeptByHero & startOptions & playerColor & bonusesToChoose;
  52. }
  53. };
  54. class DLL_EXPORT CCampaignScenario
  55. {
  56. public:
  57. std::string mapName;
  58. ui32 packedMapSize; //generally not used
  59. ui16 preconditionRegion; //what we need to conquer to conquer this one (bitfield!)
  60. ui8 regionColor;
  61. ui8 difficulty;
  62. ui8 conquered;
  63. std::string regionText;
  64. struct DLL_EXPORT SScenarioPrologEpilog
  65. {
  66. ui8 hasPrologEpilog;
  67. ui8 prologVideo; // from CmpMovie.txt
  68. ui8 prologMusic; // from CmpMusic.txt
  69. std::string prologText;
  70. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  71. {
  72. h & hasPrologEpilog & prologVideo & prologMusic & prologText;
  73. }
  74. };
  75. SScenarioPrologEpilog prolog, epilog;
  76. CScenarioTravel travelOptions;
  77. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  78. {
  79. h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & conquered & regionText &
  80. prolog & epilog & travelOptions;
  81. }
  82. };
  83. class DLL_EXPORT CCampaign
  84. {
  85. public:
  86. CCampaignHeader header;
  87. std::vector<CCampaignScenario> scenarios;
  88. std::vector<std::string> mapPieces; //binary h3ms
  89. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  90. {
  91. h & header & scenarios & mapPieces;
  92. }
  93. bool conquerable(int whichScenario) const;
  94. CCampaign();
  95. };
  96. class DLL_EXPORT CCampaignHandler
  97. {
  98. static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
  99. static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion );
  100. static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version);
  101. static std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
  102. static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos
  103. static unsigned char * getFile(const std::string & name, bool fromLod, int & outSize);
  104. public:
  105. enum GetMode {RoE, AB, SoD, WoG, Custom, ALL};
  106. static std::vector<CCampaignHeader> getCampaignHeaders(GetMode mode);
  107. static CCampaignHeader getHeader( const std::string & name, bool fromLod ); //name - name of appropriate file
  108. static CCampaign * getCampaign(const std::string & name, bool fromLod); //name - name of appropriate file
  109. };
  110. #endif /* __CCAMPAIGNHANDLER_H__ */