CCampaignHandler.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #pragma once
  2. #include "../../Global.h"
  3. #include "../../lib/GameConstants.h"
  4. /*
  5. * CCampaignHandler.h, part of VCMI engine
  6. *
  7. * Authors: listed in file AUTHORS in main folder
  8. *
  9. * License: GNU General Public License v2.0 or later
  10. * Full text of license available in license.txt file, in main folder
  11. *
  12. */
  13. struct StartInfo;
  14. class CGHeroInstance;
  15. namespace CampaignVersion
  16. {
  17. enum Version
  18. {
  19. RoE = 4,
  20. AB = 5,
  21. SoD = 6,
  22. WoG = 6
  23. };
  24. }
  25. class DLL_LINKAGE CCampaignHeader
  26. {
  27. public:
  28. si32 version; //4 - RoE, 5 - AB, 6 - SoD and WoG
  29. ui8 mapVersion; //CampText.txt's format
  30. std::string name, description;
  31. ui8 difficultyChoosenByPlayer;
  32. ui8 music; //CmpMusic.txt, start from 0
  33. std::string filename;
  34. ui8 loadFromLod; //if true, this campaign must be loaded fro, .lod file
  35. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  36. {
  37. h & version & mapVersion & name & description & difficultyChoosenByPlayer & music & filename & loadFromLod;
  38. }
  39. };
  40. class DLL_LINKAGE CScenarioTravel
  41. {
  42. public:
  43. ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
  44. ui8 monstersKeptByHero[19];
  45. ui8 artifsKeptByHero[18];
  46. ui8 startOptions; //1 - start bonus, 2 - traveling hero, 3 - hero options
  47. ui8 playerColor; //only for startOptions == 1
  48. struct DLL_LINKAGE STravelBonus
  49. {
  50. enum EBonusType {SPELL, MONSTER, BUILDING, ARTIFACT, SPELL_SCROLL, PRIMARY_SKILL, SECONDARY_SKILL, RESOURCE,
  51. PLAYER_PREV_SCENARIO, HERO};
  52. EBonusType type; //uses EBonusType
  53. si32 info1, info2, info3; //purpose depends on type
  54. bool isBonusForHero() const;
  55. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  56. {
  57. h & type & info1 & info2 & info3;
  58. }
  59. };
  60. std::vector<STravelBonus> bonusesToChoose;
  61. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  62. {
  63. h & whatHeroKeeps & monstersKeptByHero & artifsKeptByHero & startOptions & playerColor & bonusesToChoose;
  64. }
  65. };
  66. class DLL_LINKAGE CCampaignScenario
  67. {
  68. public:
  69. std::string mapName; //*.h3m
  70. std::string scenarioName; //from header. human-readble
  71. ui32 packedMapSize; //generally not used
  72. std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
  73. ui8 regionColor;
  74. ui8 difficulty;
  75. bool conquered;
  76. std::string regionText;
  77. struct DLL_LINKAGE SScenarioPrologEpilog
  78. {
  79. bool hasPrologEpilog;
  80. ui8 prologVideo; // from CmpMovie.txt
  81. ui8 prologMusic; // from CmpMusic.txt
  82. std::string prologText;
  83. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  84. {
  85. h & hasPrologEpilog & prologVideo & prologMusic & prologText;
  86. }
  87. };
  88. SScenarioPrologEpilog prolog, epilog;
  89. CScenarioTravel travelOptions;
  90. std::vector<CGHeroInstance *> crossoverHeroes;
  91. const CGHeroInstance * strongestHero(PlayerColor owner) const;
  92. void loadPreconditionRegions(ui32 regions);
  93. void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);
  94. bool isNotVoid() const;
  95. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  96. {
  97. h & mapName & scenarioName & packedMapSize & preconditionRegions & regionColor & difficulty & conquered & regionText &
  98. prolog & epilog & travelOptions & crossoverHeroes;
  99. }
  100. };
  101. class DLL_LINKAGE CCampaign
  102. {
  103. public:
  104. CCampaignHeader header;
  105. std::vector<CCampaignScenario> scenarios;
  106. std::map<int, std::string > mapPieces; //binary h3ms, scenario number -> map data
  107. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  108. {
  109. h & header & scenarios & mapPieces;
  110. }
  111. bool conquerable(int whichScenario) const;
  112. CCampaign();
  113. };
  114. class DLL_LINKAGE CCampaignState
  115. {
  116. public:
  117. unique_ptr<CCampaign> camp;
  118. std::string campaignName;
  119. std::vector<ui8> mapsConquered, mapsRemaining;
  120. ui8 currentMap;
  121. bmap<ui8, ui8> chosenCampaignBonuses; //used only for mode CAMPAIGN
  122. //void initNewCampaign(const StartInfo &si);
  123. void mapConquered(const std::vector<CGHeroInstance*> & heroes);
  124. boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const;
  125. const CCampaignScenario &getCurrentScenario() const;
  126. ui8 currentBonusID() const;
  127. CCampaignState();
  128. CCampaignState(unique_ptr<CCampaign> _camp);
  129. ~CCampaignState(){};
  130. template <typename Handler> void serialize(Handler &h, const int version)
  131. {
  132. h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
  133. h & chosenCampaignBonuses;
  134. }
  135. };
  136. class DLL_LINKAGE CCampaignHandler
  137. {
  138. static CCampaignHeader readHeaderFromMemory( const ui8 *buffer, int & outIt );
  139. static CCampaignScenario readScenarioFromMemory( const ui8 *buffer, int & outIt, int version, int mapVersion );
  140. static CScenarioTravel readScenarioTravelFromMemory( const ui8 * buffer, int & outIt , int version);
  141. /// returns h3c split in parts. 0 = h3c header, 1-end - maps (binary h3m)
  142. /// headerOnly - only header will be decompressed, returned vector wont have any maps
  143. static std::vector< std::vector<ui8> > getFile(const std::string & name, bool headerOnly);
  144. public:
  145. static std::string prologVideoName(ui8 index);
  146. static std::string prologMusicName(ui8 index);
  147. static CCampaignHeader getHeader( const std::string & name); //name - name of appropriate file
  148. static unique_ptr<CCampaign> getCampaign(const std::string & name); //name - name of appropriate file
  149. };