MapFormatH3M.h 8.4 KB

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