MapFormatH3M.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. enum class EQuestMission;
  33. enum class EVictoryConditionType : int8_t
  34. {
  35. WINSTANDARD = -1,
  36. ARTIFACT = 0,
  37. GATHERTROOP = 1,
  38. GATHERRESOURCE = 2,
  39. BUILDCITY = 3,
  40. BUILDGRAIL = 4,
  41. BEATHERO = 5,
  42. CAPTURECITY = 6,
  43. BEATMONSTER = 7,
  44. TAKEDWELLINGS = 8,
  45. TAKEMINES = 9,
  46. TRANSPORTITEM = 10,
  47. HOTA_ELIMINATE_ALL_MONSTERS = 11,
  48. HOTA_SURVIVE_FOR_DAYS = 12
  49. };
  50. enum class ELossConditionType : int8_t
  51. {
  52. LOSSSTANDARD = -1,
  53. LOSSCASTLE = 0,
  54. LOSSHERO = 1,
  55. TIMEEXPIRES = 2
  56. };
  57. class DLL_LINKAGE CMapLoaderH3M : public IMapLoader
  58. {
  59. public:
  60. /**
  61. * Default constructor.
  62. *
  63. * @param stream a stream containing the map data
  64. */
  65. CMapLoaderH3M(const std::string & mapName, const std::string & modName, const std::string & encodingName, CInputStream * stream);
  66. /**
  67. * Destructor.
  68. */
  69. ~CMapLoaderH3M();
  70. /**
  71. * Loads the VCMI/H3 map file.
  72. *
  73. * @return a unique ptr of the loaded map class
  74. */
  75. std::unique_ptr<CMap> loadMap(IGameCallback * cb) override;
  76. /**
  77. * Loads the VCMI/H3 map header.
  78. *
  79. * @return a unique ptr of the loaded map header class
  80. */
  81. std::unique_ptr<CMapHeader> loadMapHeader() override;
  82. private:
  83. /**
  84. * Initializes the map object from parsing the input buffer.
  85. */
  86. void init();
  87. /**
  88. * Reads the map header.
  89. */
  90. void readHeader();
  91. /**
  92. * Reads player information.
  93. */
  94. void readPlayerInfo();
  95. /**
  96. * Reads victory/loss conditions.
  97. */
  98. void readVictoryLossConditions();
  99. /**
  100. * Reads team information.
  101. */
  102. void readTeamInfo();
  103. /**
  104. * Reads the list of map flags.
  105. */
  106. void readMapOptions();
  107. /**
  108. * Reads the list of allowed heroes.
  109. */
  110. void readAllowedHeroes();
  111. /**
  112. * Reads the list of disposed heroes.
  113. */
  114. void readDisposedHeroes();
  115. /**
  116. * Reads the list of allowed artifacts.
  117. */
  118. void readAllowedArtifacts();
  119. /**
  120. * Reads the list of allowed spells and abilities.
  121. */
  122. void readAllowedSpellsAbilities();
  123. /**
  124. * Loads artifacts of a hero.
  125. *
  126. * @param hero the hero which should hold those artifacts
  127. */
  128. void loadArtifactsOfHero(CGHeroInstance * hero);
  129. /**
  130. * Loads an artifact to the given slot of the specified hero.
  131. *
  132. * @param hero the hero which should hold that artifact
  133. * @param slot the artifact slot where to place that artifact
  134. * @return true if it loaded an artifact
  135. */
  136. bool loadArtifactToSlot(CGHeroInstance * hero, int slot);
  137. /**
  138. * Read rumors.
  139. */
  140. void readRumors();
  141. /**
  142. * Reads predefined heroes.
  143. */
  144. void readPredefinedHeroes();
  145. /**
  146. * Reads terrain data.
  147. */
  148. void readTerrain();
  149. /**
  150. * Reads custom(map) def information.
  151. */
  152. void readObjectTemplates();
  153. /**
  154. * Reads objects(towns, mines,...).
  155. */
  156. void readObjects();
  157. /// Reads single object from input stream based on template
  158. CGObjectInstance * readObject(std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  159. CGObjectInstance * readEvent(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  160. CGObjectInstance * readMonster(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
  161. CGObjectInstance * readHero(const int3 & initialPos, const ObjectInstanceID & idToBeGiven);
  162. CGObjectInstance * readSeerHut(const int3 & initialPos, const ObjectInstanceID & idToBeGiven);
  163. CGObjectInstance * readTown(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  164. CGObjectInstance * readSign(const int3 & position);
  165. CGObjectInstance * readWitchHut(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  166. CGObjectInstance * readScholar(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  167. CGObjectInstance * readGarrison(const int3 & mapPosition);
  168. CGObjectInstance * readArtifact(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  169. CGObjectInstance * readResource(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  170. CGObjectInstance * readMine(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  171. CGObjectInstance * readPandora(const int3 & position, const ObjectInstanceID & idToBeGiven);
  172. CGObjectInstance * readDwelling(const int3 & position);
  173. CGObjectInstance * readDwellingRandom(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  174. CGObjectInstance * readShrine(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  175. CGObjectInstance * readHeroPlaceholder(const int3 & position);
  176. CGObjectInstance * readGrail(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  177. CGObjectInstance * readPyramid(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
  178. CGObjectInstance * readQuestGuard(const int3 & position);
  179. CGObjectInstance * readShipyard(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate);
  180. CGObjectInstance * readLighthouse(const int3 & mapPosition);
  181. CGObjectInstance * readGeneric(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  182. CGObjectInstance * readBank(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
  183. /**
  184. * Reads a creature set.
  185. *
  186. * @param out the loaded creature set
  187. * @param number the count of creatures to read
  188. */
  189. void readCreatureSet(CCreatureSet * out, int number);
  190. /**
  191. * Reads a quest for the given quest guard.
  192. *
  193. * @param guard the quest guard where that quest should be applied to
  194. */
  195. void readBoxContent(CGPandoraBox * object, const int3 & position, const ObjectInstanceID & idToBeGiven);
  196. /**
  197. * Reads a quest for the given quest guard.
  198. *
  199. * @param guard the quest guard where that quest should be applied to
  200. */
  201. EQuestMission readQuest(IQuestObject * guard, const int3 & position);
  202. void readSeerHutQuest(CGSeerHut * hut, const int3 & position, const ObjectInstanceID & idToBeGiven);
  203. /**
  204. * Reads events.
  205. */
  206. void readEvents();
  207. /**
  208. * read optional message and optional guards
  209. */
  210. void readMessageAndGuards(MetaString & message, CCreatureSet * guards, const int3 & position);
  211. /// reads string from input stream and converts it to unicode
  212. std::string readBasicString();
  213. /// reads string from input stream, converts it to unicode and attempts to translate it
  214. std::string readLocalizedString(const TextIdentifier & identifier);
  215. void setOwnerAndValidate(const int3 & mapPosition, CGObjectInstance * object, const PlayerColor & owner);
  216. void afterRead();
  217. MapFormatFeaturesH3M features;
  218. /** List of templates loaded from the map, used on later stage to create
  219. * objects but not needed for fully functional CMap */
  220. std::vector<std::shared_ptr<const ObjectTemplate>> templates;
  221. /** ptr to the map object which gets filled by data from the buffer */
  222. CMap * map;
  223. /**
  224. * ptr to the map header object which gets filled by data from the buffer.
  225. * (when loading a map then the mapHeader ptr points to the same object)
  226. */
  227. std::unique_ptr<CMapHeader> mapHeader;
  228. std::unique_ptr<MapReaderH3M> reader;
  229. CInputStream * inputStream;
  230. std::string mapName;
  231. std::string modName;
  232. std::string fileEncoding;
  233. };
  234. VCMI_LIB_NAMESPACE_END