CCampaignHandler.h 4.9 KB

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