CMap.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * CMap.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 "CMapHeader.h"
  12. #include "../MetaString.h"
  13. #include "../mapObjects/MiscObjects.h" // To serialize static props
  14. #include "../mapObjects/CQuest.h" // To serialize static props
  15. #include "../mapObjects/CGTownInstance.h" // To serialize static props
  16. #include "CMapDefines.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class CArtifactInstance;
  19. class CGObjectInstance;
  20. class CGHeroInstance;
  21. class CCommanderInstance;
  22. class CGCreature;
  23. class CQuest;
  24. class CGTownInstance;
  25. class IModableArt;
  26. class IQuestObject;
  27. class CInputStream;
  28. class CMapEditManager;
  29. class JsonSerializeFormat;
  30. struct TeleportChannel;
  31. /// The rumor struct consists of a rumor name and text.
  32. struct DLL_LINKAGE Rumor
  33. {
  34. std::string name;
  35. MetaString text;
  36. Rumor() = default;
  37. ~Rumor() = default;
  38. template <typename Handler>
  39. void serialize(Handler & h, const int version)
  40. {
  41. h & name;
  42. h & text;
  43. }
  44. void serializeJson(JsonSerializeFormat & handler);
  45. };
  46. /// The disposed hero struct describes which hero can be hired from which player.
  47. struct DLL_LINKAGE DisposedHero
  48. {
  49. DisposedHero();
  50. HeroTypeID heroId;
  51. HeroTypeID portrait; /// The portrait id of the hero, -1 is default.
  52. std::string name;
  53. std::set<PlayerColor> players; /// Who can hire this hero (bitfield).
  54. template <typename Handler>
  55. void serialize(Handler & h, const int version)
  56. {
  57. h & heroId;
  58. h & portrait;
  59. h & name;
  60. h & players;
  61. }
  62. };
  63. /// The map contains the map header, the tiles of the terrain, objects, heroes, towns, rumors...
  64. class DLL_LINKAGE CMap : public CMapHeader
  65. {
  66. public:
  67. CMap();
  68. ~CMap();
  69. void initTerrain();
  70. CMapEditManager * getEditManager();
  71. TerrainTile & getTile(const int3 & tile);
  72. const TerrainTile & getTile(const int3 & tile) const;
  73. bool isCoastalTile(const int3 & pos) const;
  74. bool isInTheMap(const int3 & pos) const;
  75. bool isWaterTile(const int3 & pos) const;
  76. bool canMoveBetween(const int3 &src, const int3 &dst) const;
  77. bool checkForVisitableDir(const int3 & src, const TerrainTile * pom, const int3 & dst) const;
  78. int3 guardingCreaturePosition (int3 pos) const;
  79. void addBlockVisTiles(CGObjectInstance * obj);
  80. void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
  81. void calculateGuardingGreaturePositions();
  82. void addNewArtifactInstance(ConstTransitivePtr<CArtifactInstance> art);
  83. void eraseArtifactInstance(CArtifactInstance * art);
  84. void addNewQuestInstance(CQuest * quest);
  85. void removeQuestInstance(CQuest * quest);
  86. void setUniqueInstanceName(CGObjectInstance * obj);
  87. ///Use only this method when creating new map object instances
  88. void addNewObject(CGObjectInstance * obj);
  89. void moveObject(CGObjectInstance * obj, const int3 & dst);
  90. void removeObject(CGObjectInstance * obj);
  91. bool isWaterMap() const;
  92. bool calculateWaterContent();
  93. void banWaterArtifacts();
  94. void banWaterHeroes();
  95. void banHero(const HeroTypeID& id);
  96. void banWaterSpells();
  97. void banWaterSkills();
  98. void banWaterContent();
  99. /// Gets object of specified type on requested position
  100. const CGObjectInstance * getObjectiveObjectFrom(const int3 & pos, Obj type);
  101. CGHeroInstance * getHero(HeroTypeID heroId);
  102. /// Sets the victory/loss condition objectives ??
  103. void checkForObjectives();
  104. void resetStaticData();
  105. ui32 checksum;
  106. std::vector<Rumor> rumors;
  107. std::vector<DisposedHero> disposedHeroes;
  108. std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
  109. std::set<SpellID> allowedSpells;
  110. std::set<ArtifactID> allowedArtifact;
  111. std::set<SecondarySkill> allowedAbilities;
  112. std::list<CMapEvent> events;
  113. int3 grailPos;
  114. int grailRadius;
  115. //Central lists of items in game. Position of item in the vectors below is their (instance) id.
  116. std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
  117. std::vector< ConstTransitivePtr<CGTownInstance> > towns;
  118. std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
  119. std::vector< ConstTransitivePtr<CQuest> > quests;
  120. std::vector< ConstTransitivePtr<CGHeroInstance> > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc.
  121. //Helper lists
  122. std::vector< ConstTransitivePtr<CGHeroInstance> > heroesOnMap;
  123. std::map<TeleportChannelID, std::shared_ptr<TeleportChannel> > teleportChannels;
  124. /// associative list to identify which hero/creature id belongs to which object id(index for objects)
  125. std::map<si32, ObjectInstanceID> questIdentifierToId;
  126. std::unique_ptr<CMapEditManager> editManager;
  127. boost::multi_array<int3, 3> guardingCreaturePositions;
  128. std::map<std::string, ConstTransitivePtr<CGObjectInstance> > instanceNames;
  129. bool waterMap;
  130. private:
  131. /// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground
  132. boost::multi_array<TerrainTile, 3> terrain;
  133. si32 uidCounter; //TODO: initialize when loading an old map
  134. public:
  135. template <typename Handler>
  136. void serialize(Handler &h, const int formatVersion)
  137. {
  138. h & static_cast<CMapHeader&>(*this);
  139. h & triggeredEvents; //from CMapHeader
  140. h & rumors;
  141. h & allowedSpells;
  142. h & allowedAbilities;
  143. h & allowedArtifact;
  144. h & events;
  145. h & grailPos;
  146. h & artInstances;
  147. h & quests;
  148. h & allHeroes;
  149. h & questIdentifierToId;
  150. //TODO: viccondetails
  151. h & terrain;
  152. h & guardingCreaturePositions;
  153. h & objects;
  154. h & heroesOnMap;
  155. h & teleportChannels;
  156. h & towns;
  157. h & artInstances;
  158. // static members
  159. h & CGObelisk::obeliskCount;
  160. h & CGObelisk::visited;
  161. h & CGTownInstance::merchantArtifacts;
  162. h & CGTownInstance::universitySkills;
  163. h & instanceNames;
  164. }
  165. };
  166. VCMI_LIB_NAMESPACE_END