Zone.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Zone.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 "float3.h"
  13. #include "../int3.h"
  14. #include "../CRandomGenerator.h"
  15. #include "CRmgTemplate.h"
  16. #include "RmgArea.h"
  17. #include "RmgPath.h"
  18. #include "RmgObject.h"
  19. #include "modificators/Modificator.h"
  20. //uncomment to generate dumps afger every step of map generation
  21. //#define RMG_DUMP
  22. VCMI_LIB_NAMESPACE_BEGIN
  23. class RmgMap;
  24. class CMapGenerator;
  25. class Modificator;
  26. class CRandomGenerator;
  27. extern const std::function<bool(const int3 &)> AREA_NO_FILTER;
  28. typedef std::list<std::shared_ptr<Modificator>> TModificators;
  29. class Zone : public rmg::ZoneOptions
  30. {
  31. public:
  32. Zone(RmgMap & map, CMapGenerator & generator, CRandomGenerator & rand);
  33. Zone(const Zone &) = delete;
  34. void setOptions(const rmg::ZoneOptions & options);
  35. bool isUnderground() const;
  36. float3 getCenter() const;
  37. void setCenter(const float3 &f);
  38. int3 getPos() const;
  39. void setPos(const int3 &pos);
  40. const rmg::Area & getArea() const;
  41. rmg::Area & area();
  42. rmg::Area & areaPossible();
  43. rmg::Area & freePaths();
  44. rmg::Area & areaUsed();
  45. void initFreeTiles();
  46. void clearTiles();
  47. void fractalize();
  48. FactionID getTownType() const;
  49. void setTownType(FactionID town);
  50. TerrainId getTerrainType() const;
  51. void setTerrainType(TerrainId terrain);
  52. void connectPath(const rmg::Path & path);
  53. rmg::Path searchPath(const rmg::Area & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  54. rmg::Path searchPath(const int3 & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  55. rmg::Path searchPath(const rmg::Area & src, bool onlyStraight, const rmg::Area & searchArea) const;
  56. TModificators getModificators();
  57. template<class T>
  58. T* getModificator()
  59. {
  60. for(auto & m : modificators)
  61. if(auto * mm = dynamic_cast<T*>(m.get()))
  62. return mm;
  63. return nullptr;
  64. }
  65. template<class T>
  66. void addModificator()
  67. {
  68. modificators.emplace_back(new T(*this, map, generator));
  69. }
  70. void initModificators();
  71. CRandomGenerator & getRand();
  72. public:
  73. boost::recursive_mutex areaMutex;
  74. using Lock = boost::unique_lock<boost::recursive_mutex>;
  75. protected:
  76. CMapGenerator & generator;
  77. CRandomGenerator rand;
  78. RmgMap & map;
  79. TModificators modificators;
  80. bool finished;
  81. //placement info
  82. int3 pos;
  83. float3 center;
  84. rmg::Area dArea; //irregular area assined to zone
  85. rmg::Area dAreaPossible;
  86. rmg::Area dAreaFree; //core paths of free tiles that all other objects will be linked to
  87. rmg::Area dAreaUsed;
  88. std::vector<int3> possibleQuestArtifactPos;
  89. //template info
  90. FactionID townType;
  91. TerrainId terrainType;
  92. };
  93. VCMI_LIB_NAMESPACE_END