CCampaignHandler.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. HEROES_FROM_PREVIOUS_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. struct DLL_LINKAGE SScenarioPrologEpilog
  70. {
  71. bool hasPrologEpilog;
  72. ui8 prologVideo; // from CmpMovie.txt
  73. ui8 prologMusic; // from CmpMusic.txt
  74. std::string prologText;
  75. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  76. {
  77. h & hasPrologEpilog & prologVideo & prologMusic & prologText;
  78. }
  79. };
  80. std::string mapName; //*.h3m
  81. std::string scenarioName; //from header. human-readble
  82. ui32 packedMapSize; //generally not used
  83. std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
  84. ui8 regionColor;
  85. ui8 difficulty;
  86. bool conquered;
  87. std::string regionText;
  88. SScenarioPrologEpilog prolog, epilog;
  89. CScenarioTravel travelOptions;
  90. std::vector<CGHeroInstance *> crossoverHeroes; // contains all heroes with the same state when the campaign scenario was finished
  91. const CGHeroInstance * strongestHero(PlayerColor owner) const;
  92. void loadPreconditionRegions(ui32 regions);
  93. bool isNotVoid() const;
  94. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  95. {
  96. h & mapName & scenarioName & packedMapSize & preconditionRegions & regionColor & difficulty & conquered & regionText &
  97. prolog & epilog & travelOptions & crossoverHeroes;
  98. }
  99. };
  100. class DLL_LINKAGE CCampaign
  101. {
  102. public:
  103. CCampaignHeader header;
  104. std::vector<CCampaignScenario> scenarios;
  105. std::map<int, std::string > mapPieces; //binary h3ms, scenario number -> map data
  106. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  107. {
  108. h & header & scenarios & mapPieces;
  109. }
  110. bool conquerable(int whichScenario) const;
  111. CCampaign();
  112. };
  113. class DLL_LINKAGE CCampaignState
  114. {
  115. public:
  116. unique_ptr<CCampaign> camp;
  117. std::string campaignName;
  118. std::vector<ui8> mapsConquered, mapsRemaining;
  119. boost::optional<si32> currentMap;
  120. std::map<ui8, ui8> chosenCampaignBonuses;
  121. //void initNewCampaign(const StartInfo &si);
  122. void setCurrentMapAsConquered(const std::vector<CGHeroInstance*> & heroes);
  123. boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const;
  124. const CCampaignScenario &getCurrentScenario() const;
  125. ui8 currentBonusID() const;
  126. CCampaignState();
  127. CCampaignState(unique_ptr<CCampaign> _camp);
  128. ~CCampaignState(){};
  129. template <typename Handler> void serialize(Handler &h, const int version)
  130. {
  131. h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
  132. h & chosenCampaignBonuses;
  133. }
  134. };
  135. class DLL_LINKAGE CCampaignHandler
  136. {
  137. static CCampaignHeader readHeaderFromMemory( const ui8 *buffer, int & outIt );
  138. static CCampaignScenario readScenarioFromMemory( const ui8 *buffer, int & outIt, int version, int mapVersion );
  139. static CScenarioTravel readScenarioTravelFromMemory( const ui8 * buffer, int & outIt , int version);
  140. /// returns h3c split in parts. 0 = h3c header, 1-end - maps (binary h3m)
  141. /// headerOnly - only header will be decompressed, returned vector wont have any maps
  142. static std::vector< std::vector<ui8> > getFile(const std::string & name, bool headerOnly);
  143. public:
  144. static std::string prologVideoName(ui8 index);
  145. static std::string prologMusicName(ui8 index);
  146. static std::string prologVoiceName(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. };