MapFormatH3M.h 7.8 KB

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