CCampaignHandler.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  24. {
  25. h & version & mapVersion & name & description & difficultyChoosenByPlayer & music;
  26. }
  27. };
  28. class DLL_EXPORT CScenarioTravel
  29. {
  30. public:
  31. ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
  32. ui8 monstersKeptByHero[19];
  33. ui8 artifsKeptByHero[18];
  34. ui8 startOptions; //1 - start bonus, 2 - traveling hero, 3 - hero options
  35. ui8 playerColor; //only for startOptions == 1
  36. struct DLL_EXPORT STravelBonus
  37. {
  38. ui8 type; //0 - spell, 1 - monster, 2 - building, 3 - artifact, 4 - spell scroll, 5 - prim skill, 6 - sec skill, 7 - resource,
  39. //8 - player from previous scenario, 9 - hero [???]
  40. si32 info1, info2, info3; //purpose depends on type
  41. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  42. {
  43. h & type & info1 & info2 & info3;
  44. }
  45. };
  46. std::vector<STravelBonus> bonusesToChoose;
  47. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  48. {
  49. h & whatHeroKeeps & monstersKeptByHero & artifsKeptByHero & startOptions & playerColor & bonusesToChoose;
  50. }
  51. };
  52. class DLL_EXPORT CCampaignScenario
  53. {
  54. public:
  55. std::string mapName;
  56. ui32 packedMapSize;
  57. ui8 preconditionRegion;
  58. ui8 regionColor;
  59. ui8 difficulty;
  60. std::string regionText;
  61. struct DLL_EXPORT SScenarioPrologEpilog
  62. {
  63. ui8 hasPrologEpilog;
  64. ui8 prologVideo; // from CmpMovie.txt
  65. ui8 prologMusic; // from CmpMusic.txt
  66. std::string prologText;
  67. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  68. {
  69. h & hasPrologEpilog & prologVideo & prologMusic & prologText;
  70. }
  71. };
  72. SScenarioPrologEpilog prolog, epilog;
  73. CScenarioTravel travelOptions;
  74. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  75. {
  76. h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & regionText & prolog & epilog & travelOptions;
  77. }
  78. };
  79. class DLL_EXPORT CCampaign
  80. {
  81. public:
  82. CCampaignHeader header;
  83. std::vector<CCampaignScenario> scenarios;
  84. std::vector<std::string> mapPieces; //binary h3ms
  85. template <typename Handler> void serialize(Handler &h, const int formatVersion)
  86. {
  87. h & header & scenarios & mapPieces;
  88. }
  89. };
  90. class DLL_EXPORT CCampaignHandler
  91. {
  92. static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
  93. static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt );
  94. static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt );
  95. static std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
  96. static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos
  97. public:
  98. static std::vector<CCampaignHeader> getCampaignHeaders();
  99. static CCampaignHeader getHeader( const std::string & name );
  100. static CCampaign * getCampaign(const std::string & name);
  101. };
  102. #endif __CCAMPAIGNHANDLER_H__