CRmgTemplateZone.h 5.5 KB

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