MapFormatH3M.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * MapFormatH3M.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CMapService.h"
  12. #include "MapFeaturesH3M.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGHeroInstance;
  15. class MapReaderH3M;
  16. class MetaString;
  17. class CArtifactInstance;
  18. class CGObjectInstance;
  19. class CGSeerHut;
  20. class IQuestObject;
  21. class CGTownInstance;
  22. class CCreatureSet;
  23. class CInputStream;
  24. class TextIdentifier;
  25. class CGPandoraBox;
  26. class ObjectInstanceID;
  27. class BuildingID;
  28. class ObjectTemplate;
  29. class SpellID;
  30. class PlayerColor;
  31. class int3;
  32. class DLL_LINKAGE CMapLoaderH3M : public IMapLoader
  33. {
  34. public:
  35. /**
  36. * Default constructor.
  37. *
  38. * @param stream a stream containing the map data
  39. */
  40. CMapLoaderH3M(const std::string & mapName, const std::string & modName, const std::string & encodingName, CInputStream * stream);
  41. /**
  42. * Destructor.
  43. */
  44. ~CMapLoaderH3M();
  45. /**
  46. * Loads the VCMI/H3 map file.
  47. *
  48. * @return a unique ptr of the loaded map class
  49. */
  50. std::unique_ptr<CMap> loadMap() override;
  51. /**
  52. * Loads the VCMI/H3 map header.
  53. *
  54. * @return a unique ptr of the loaded map header class
  55. */
  56. std::unique_ptr<CMapHeader> loadMapHeader() override;
  57. private:
  58. /**
  59. * Initializes the map object from parsing the input buffer.
  60. */
  61. void init();
  62. /**
  63. * Reads the map header.
  64. */
  65. void readHeader();
  66. /**
  67. * Reads player information.
  68. */
  69. void readPlayerInfo();
  70. /**
  71. * Reads victory/loss conditions.
  72. */
  73. void readVictoryLossConditions();
  74. /**
  75. * Reads team information.
  76. */
  77. void readTeamInfo();
  78. /**
  79. * Reads the list of map flags.
  80. */
  81. void readMapOptions();
  82. /**
  83. * Reads the list of allowed heroes.
  84. */
  85. void readAllowedHeroes();
  86. /**
  87. * Reads the list of disposed heroes.
  88. */
  89. void readDisposedHeroes();
  90. /**
  91. * Reads the list of allowed artifacts.
  92. */
  93. void readAllowedArtifacts();
  94. /**
  95. * Reads the list of allowed spells and abilities.
  96. */
  97. void readAllowedSpellsAbilities();
  98. /**
  99. * Loads artifacts of a hero.
  100. *
  101. * @param hero the hero which should hold those artifacts
  102. */
  103. void loadArtifactsOfHero(CGHeroInstance * hero);
  104. /**
  105. * Loads an artifact to the given slot of the specified hero.
  106. *
  107. * @param hero the hero which should hold that artifact
  108. * @param slot the artifact slot where to place that artifact
  109. * @return true if it loaded an artifact
  110. */
  111. bool loadArtifactToSlot(CGHeroInstance * hero, int slot);
  112. /**
  113. * Read rumors.
  114. */
  115. void readRumors();
  116. /**
  117. * Reads predefined heroes.
  118. */
  119. void readPredefinedHeroes();
  120. /**
  121. * Reads terrain data.
  122. */
  123. void readTerrain();
  124. /**
  125. * Reads custom(map) def information.
  126. */
  127. void readObjectTemplates();
  128. /**
  129. * Reads objects(towns, mines,...).
  130. */
  131. void readObjects();
  132. /// Reads single object from input stream based on template
  133. CGObjectInstance * readObject(std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  134. CGObjectInstance * readEvent(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  135. CGObjectInstance * readMonster(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  136. CGObjectInstance * readHero(const int3 & initialPos, const ObjectInstanceID & idToBeGiven);
  137. CGObjectInstance * readSeerHut(const int3 & initialPos, const ObjectInstanceID & idToBeGiven);
  138. CGObjectInstance * readTown(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  139. CGObjectInstance * readSign(const int3 & position);
  140. CGObjectInstance * readWitchHut(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  141. CGObjectInstance * readScholar(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  142. CGObjectInstance * readGarrison(const int3 & mapPosition);
  143. CGObjectInstance * readArtifact(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  144. CGObjectInstance * readResource(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  145. CGObjectInstance * readMine(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  146. CGObjectInstance * readPandora(const int3 & position, const ObjectInstanceID & idToBeGiven);
  147. CGObjectInstance * readDwelling(const int3 & position);
  148. CGObjectInstance * readDwellingRandom(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  149. CGObjectInstance * readShrine(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  150. CGObjectInstance * readHeroPlaceholder(const int3 & position);
  151. CGObjectInstance * readGrail(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  152. CGObjectInstance * readPyramid(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  153. CGObjectInstance * readQuestGuard(const int3 & position);
  154. CGObjectInstance * readShipyard(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate);
  155. CGObjectInstance * readLighthouse(const int3 & mapPosition);
  156. CGObjectInstance * readGeneric(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  157. CGObjectInstance * readBank(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  158. /**
  159. * Reads a creature set.
  160. *
  161. * @param out the loaded creature set
  162. * @param number the count of creatures to read
  163. */
  164. void readCreatureSet(CCreatureSet * out, int number);
  165. /**
  166. * Reads a quest for the given quest guard.
  167. *
  168. * @param guard the quest guard where that quest should be applied to
  169. */
  170. void readBoxContent(CGPandoraBox * object, const int3 & position, const ObjectInstanceID & idToBeGiven);
  171. /**
  172. * Reads a quest for the given quest guard.
  173. *
  174. * @param guard the quest guard where that quest should be applied to
  175. */
  176. int readQuest(IQuestObject * guard, const int3 & position);
  177. void readSeerHutQuest(CGSeerHut * hut, const int3 & position, const ObjectInstanceID & idToBeGiven);
  178. /**
  179. * Reads events.
  180. */
  181. void readEvents();
  182. /**
  183. * read optional message and optional guards
  184. */
  185. void readMessageAndGuards(MetaString & message, CCreatureSet * guards, const int3 & position);
  186. /// reads string from input stream and converts it to unicode
  187. std::string readBasicString();
  188. /// reads string from input stream, converts it to unicode and attempts to translate it
  189. std::string readLocalizedString(const TextIdentifier & identifier);
  190. void setOwnerAndValidate(const int3 & mapPosition, CGObjectInstance * object, const PlayerColor & owner);
  191. void afterRead();
  192. MapFormatFeaturesH3M features;
  193. /** List of templates loaded from the map, used on later stage to create
  194. * objects but not needed for fully functional CMap */
  195. std::vector<std::shared_ptr<const ObjectTemplate>> templates;
  196. /** ptr to the map object which gets filled by data from the buffer */
  197. CMap * map;
  198. /**
  199. * ptr to the map header object which gets filled by data from the buffer.
  200. * (when loading a map then the mapHeader ptr points to the same object)
  201. */
  202. std::unique_ptr<CMapHeader> mapHeader;
  203. std::unique_ptr<MapReaderH3M> reader;
  204. CInputStream * inputStream;
  205. std::string mapName;
  206. std::string modName;
  207. std::string fileEncoding;
  208. };
  209. VCMI_LIB_NAMESPACE_END