CRmgTemplateZone.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. class CMapGenerator;
  16. class CTileInfo;
  17. class int3;
  18. class CGObjectInstance;
  19. namespace ETemplateZoneType
  20. {
  21. enum ETemplateZoneType
  22. {
  23. PLAYER_START,
  24. CPU_START,
  25. TREASURE,
  26. JUNCTION
  27. };
  28. }
  29. class DLL_LINKAGE CTileInfo
  30. {
  31. public:
  32. CTileInfo();
  33. int getNearestObjectDistance() const;
  34. void setNearestObjectDistance(int value);
  35. bool isBlocked() const;
  36. bool shouldBeBlocked() const;
  37. bool isPossible() const;
  38. bool isFree() const;
  39. void setOccupied(ETileType::ETileType value);
  40. ETerrainType getTerrainType() const;
  41. void setTerrainType(ETerrainType value);
  42. private:
  43. int nearestObjectDistance;
  44. ETileType::ETileType occupied;
  45. ETerrainType terrain;
  46. };
  47. /// The CRmgTemplateZone describes a zone in a template.
  48. class DLL_LINKAGE CRmgTemplateZone
  49. {
  50. public:
  51. class DLL_LINKAGE CTownInfo
  52. {
  53. public:
  54. CTownInfo();
  55. int getTownCount() const; /// Default: 0
  56. void setTownCount(int value);
  57. int getCastleCount() const; /// Default: 0
  58. void setCastleCount(int value);
  59. int getTownDensity() const; /// Default: 0
  60. void setTownDensity(int value);
  61. int getCastleDensity() const; /// Default: 0
  62. void setCastleDensity(int value);
  63. private:
  64. int townCount, castleCount, townDensity, castleDensity;
  65. };
  66. CRmgTemplateZone();
  67. TRmgTemplateZoneId getId() const; /// Default: 0
  68. void setId(TRmgTemplateZoneId value);
  69. ETemplateZoneType::ETemplateZoneType getType() const; /// Default: ETemplateZoneType::PLAYER_START
  70. void setType(ETemplateZoneType::ETemplateZoneType value);
  71. int getSize() const; /// Default: 1
  72. void setSize(int value);
  73. boost::optional<int> getOwner() const;
  74. void setOwner(boost::optional<int> value);
  75. const CTownInfo & getPlayerTowns() const;
  76. void setPlayerTowns(const CTownInfo & value);
  77. const CTownInfo & getNeutralTowns() const;
  78. void setNeutralTowns(const CTownInfo & value);
  79. bool getTownsAreSameType() const; /// Default: false
  80. void setTownsAreSameType(bool value);
  81. const std::set<TFaction> & getTownTypes() const; /// Default: all
  82. void setTownTypes(const std::set<TFaction> & value);
  83. std::set<TFaction> getDefaultTownTypes() const;
  84. bool getMatchTerrainToTown() const; /// Default: true
  85. void setMatchTerrainToTown(bool value);
  86. const std::set<ETerrainType> & getTerrainTypes() const; /// Default: all
  87. void setTerrainTypes(const std::set<ETerrainType> & value);
  88. std::set<ETerrainType> getDefaultTerrainTypes() const;
  89. boost::optional<TRmgTemplateZoneId> getTerrainTypeLikeZone() const;
  90. void setTerrainTypeLikeZone(boost::optional<TRmgTemplateZoneId> value);
  91. boost::optional<TRmgTemplateZoneId> getTownTypeLikeZone() const;
  92. void setTownTypeLikeZone(boost::optional<TRmgTemplateZoneId> value);
  93. float3 getCenter() const;
  94. void setCenter(const float3 &f);
  95. int3 getPos() const;
  96. void setPos(const int3 &pos);
  97. void addTile (const int3 &pos);
  98. std::set<int3> getTileInfo () const;
  99. void addRequiredObject(CGObjectInstance * obj, si32 guardStrength=0);
  100. void addMonster(CMapGenerator* gen, int3 &pos, si32 strength);
  101. bool fill(CMapGenerator* gen);
  102. void createBorder(CMapGenerator* gen);
  103. bool crunchPath (CMapGenerator* gen, const int3 &src, const int3 &dst, TRmgTemplateZoneId zone);
  104. void addConnection(TRmgTemplateZoneId otherZone);
  105. std::vector<TRmgTemplateZoneId> getConnections() const;
  106. private:
  107. //template info
  108. TRmgTemplateZoneId id;
  109. ETemplateZoneType::ETemplateZoneType type;
  110. int size;
  111. boost::optional<int> owner;
  112. CTownInfo playerTowns, neutralTowns;
  113. bool townsAreSameType;
  114. std::set<TFaction> townTypes;
  115. bool matchTerrainToTown;
  116. std::set<ETerrainType> terrainTypes;
  117. boost::optional<TRmgTemplateZoneId> terrainTypeLikeZone, townTypeLikeZone;
  118. //content info
  119. std::vector<int3> shape; //TODO: remove
  120. std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
  121. std::vector<CGObjectInstance*> objects;
  122. //placement info
  123. int3 pos;
  124. float3 center;
  125. std::set<int3> tileinfo; //irregular area assined to zone
  126. std::vector<TRmgTemplateZoneId> connections; //list of adjacent zones
  127. std::map<TRmgTemplateZoneId, bool> alreadyConnected; //TODO: allow multiple connections between two zones?
  128. bool pointIsIn(int x, int y);
  129. bool findPlaceForObject(CMapGenerator* gen, CGObjectInstance* obj, si32 min_dist, int3 &pos);
  130. void checkAndPlaceObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos);
  131. void placeObject(CMapGenerator* gen, CGObjectInstance* object, const int3 &pos);
  132. bool guardObject(CMapGenerator* gen, CGObjectInstance* object, si32 str);
  133. };