CRmgTemplateZone.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * CRmgTemplateZone.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 "../GameConstants.h"
  12. #include "CMapGenerator.h"
  13. #include "float3.h"
  14. #include "../int3.h"
  15. #include "../ResourceSet.h" //for TResource (?)
  16. #include "../mapObjects/ObjectTemplate.h"
  17. class CMapGenerator;
  18. class CTileInfo;
  19. class int3;
  20. class CGObjectInstance;
  21. class ObjectTemplate;
  22. namespace ETemplateZoneType
  23. {
  24. enum ETemplateZoneType
  25. {
  26. PLAYER_START,
  27. CPU_START,
  28. TREASURE,
  29. JUNCTION
  30. };
  31. }
  32. class DLL_LINKAGE CTileInfo
  33. {
  34. public:
  35. CTileInfo();
  36. int getNearestObjectDistance() const;
  37. void setNearestObjectDistance(int value);
  38. bool isBlocked() const;
  39. bool shouldBeBlocked() const;
  40. bool isPossible() const;
  41. bool isFree() const;
  42. bool isUsed() const;
  43. void setOccupied(ETileType::ETileType value);
  44. ETerrainType getTerrainType() const;
  45. void setTerrainType(ETerrainType value);
  46. private:
  47. int nearestObjectDistance;
  48. ETileType::ETileType occupied;
  49. ETerrainType terrain;
  50. };
  51. class DLL_LINKAGE CTreasureInfo
  52. {
  53. public:
  54. ui32 min;
  55. ui32 max;
  56. ui16 density;
  57. ui16 threshold; //how much must RNG roll to pick that zone
  58. };
  59. struct DLL_LINKAGE ObjectInfo
  60. {
  61. ObjectTemplate templ;
  62. ui32 value;
  63. ui16 probability;
  64. std::function<CGObjectInstance *()> generateObject;
  65. void setTemplate (si32 type, si32 subtype, ETerrainType terrain);
  66. };
  67. struct DLL_LINKAGE CTreasurePileInfo
  68. {
  69. std::set<int3> visitablePositions; //can be visited only from bottom or side
  70. std::set<int3> visitableFromTopPositions; //they can be visited from any direction
  71. std::set<int3> occupiedPositions;
  72. int3 nextTreasurePos;
  73. };
  74. /// The CRmgTemplateZone describes a zone in a template.
  75. class DLL_LINKAGE CRmgTemplateZone
  76. {
  77. public:
  78. class DLL_LINKAGE CTownInfo
  79. {
  80. public:
  81. CTownInfo();
  82. int getTownCount() const; /// Default: 0
  83. void setTownCount(int value);
  84. int getCastleCount() const; /// Default: 0
  85. void setCastleCount(int value);
  86. int getTownDensity() const; /// Default: 0
  87. void setTownDensity(int value);
  88. int getCastleDensity() const; /// Default: 0
  89. void setCastleDensity(int value);
  90. private:
  91. int townCount, castleCount, townDensity, castleDensity;
  92. };
  93. CRmgTemplateZone();
  94. TRmgTemplateZoneId getId() const; /// Default: 0
  95. void setId(TRmgTemplateZoneId value);
  96. ETemplateZoneType::ETemplateZoneType getType() const; /// Default: ETemplateZoneType::PLAYER_START
  97. void setType(ETemplateZoneType::ETemplateZoneType value);
  98. int getSize() const; /// Default: 1
  99. void setSize(int value);
  100. boost::optional<int> getOwner() const;
  101. void setOwner(boost::optional<int> value);
  102. const CTownInfo & getPlayerTowns() const;
  103. void setPlayerTowns(const CTownInfo & value);
  104. const CTownInfo & getNeutralTowns() const;
  105. void setNeutralTowns(const CTownInfo & value);
  106. bool getTownsAreSameType() const; /// Default: false
  107. void setTownsAreSameType(bool value);
  108. const std::set<TFaction> & getTownTypes() const; /// Default: all
  109. void setTownTypes(const std::set<TFaction> & value);
  110. std::set<TFaction> getDefaultTownTypes() const;
  111. bool getMatchTerrainToTown() const; /// Default: true
  112. void setMatchTerrainToTown(bool value);
  113. const std::set<ETerrainType> & getTerrainTypes() const; /// Default: all
  114. void setTerrainTypes(const std::set<ETerrainType> & value);
  115. std::set<ETerrainType> getDefaultTerrainTypes() const;
  116. void setMinesAmount (TResource res, ui16 amount);
  117. std::map<TResource, ui16> getMinesInfo() const;
  118. void setMonsterStrength (EMonsterStrength::EMonsterStrength val);
  119. float3 getCenter() const;
  120. void setCenter(const float3 &f);
  121. int3 getPos() const;
  122. void setPos(const int3 &pos);
  123. void addTile (const int3 &pos);
  124. std::set<int3> getTileInfo () const;
  125. void discardDistantTiles (CMapGenerator* gen, float distance);
  126. void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0);
  127. bool addMonster(CMapGenerator* gen, int3 &pos, si32 strength);
  128. bool createTreasurePile (CMapGenerator* gen, int3 &pos);
  129. bool fill (CMapGenerator* gen);
  130. bool placeMines (CMapGenerator* gen);
  131. void initTownType (CMapGenerator* gen);
  132. void paintZoneTerrain (CMapGenerator* gen, ETerrainType terrainType);
  133. void initTerrainType (CMapGenerator* gen);
  134. void createBorder(CMapGenerator* gen);
  135. void fractalize(CMapGenerator* gen);
  136. bool createRequiredObjects(CMapGenerator* gen);
  137. void createTreasures(CMapGenerator* gen);
  138. void createObstacles(CMapGenerator* gen);
  139. bool crunchPath (CMapGenerator* gen, const int3 &src, const int3 &dst, TRmgTemplateZoneId zone, std::set<int3>* clearedTiles = nullptr);
  140. std::vector<int3> getAccessibleOffsets (CMapGenerator* gen, CGObjectInstance* object);
  141. void setTotalDensity (ui16 val);
  142. ui16 getTotalDensity () const;
  143. void addConnection(TRmgTemplateZoneId otherZone);
  144. std::vector<TRmgTemplateZoneId> getConnections() const;
  145. void addTreasureInfo(CTreasureInfo & info);
  146. std::vector<CTreasureInfo> getTreasureInfo();
  147. std::set<int3>* getFreePaths();
  148. ObjectInfo getRandomObject (CMapGenerator* gen, CTreasurePileInfo &info, ui32 value);
  149. void placeAndGuardObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos, si32 str);
  150. private:
  151. //template info
  152. TRmgTemplateZoneId id;
  153. ETemplateZoneType::ETemplateZoneType type;
  154. int size;
  155. boost::optional<int> owner;
  156. CTownInfo playerTowns, neutralTowns;
  157. bool townsAreSameType;
  158. std::set<TFaction> townTypes;
  159. bool matchTerrainToTown;
  160. std::set<ETerrainType> terrainTypes;
  161. std::map<TResource, ui16> mines; //obligatory mines to spawn in this zone
  162. si32 townType;
  163. ETerrainType terrainType;
  164. EMonsterStrength::EMonsterStrength zoneMonsterStrength;
  165. ui16 totalDensity;
  166. std::vector<CTreasureInfo> treasureInfo;
  167. std::vector<ObjectInfo> possibleObjects;
  168. std::vector<ObjectTemplate> possibleObstacles;
  169. //content info
  170. std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
  171. std::vector<CGObjectInstance*> objects;
  172. //placement info
  173. int3 pos;
  174. float3 center;
  175. std::set<int3> tileinfo; //irregular area assined to zone
  176. std::vector<TRmgTemplateZoneId> connections; //list of adjacent zones
  177. std::set<int3> freePaths; //core paths of free tiles that all other objects will be linked to
  178. bool pointIsIn(int x, int y);
  179. void addAllPossibleObjects (CMapGenerator* gen); //add objects, including zone-specific, to possibleObjects
  180. bool findPlaceForObject(CMapGenerator* gen, CGObjectInstance* obj, si32 min_dist, int3 &pos);
  181. bool findPlaceForTreasurePile(CMapGenerator* gen, si32 min_dist, int3 &pos);
  182. bool canObstacleBePlacedHere(CMapGenerator* gen, ObjectTemplate &temp, int3 &pos);
  183. void checkAndPlaceObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos);
  184. void placeObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos);
  185. bool guardObject(CMapGenerator* gen, CGObjectInstance* object, si32 str);
  186. };