Zone.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 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(si32 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. TModificators getModificators();
  56. template<class T>
  57. T* getModificator()
  58. {
  59. for(auto & m : modificators)
  60. if(auto * mm = dynamic_cast<T*>(m.get()))
  61. return mm;
  62. return nullptr;
  63. }
  64. template<class T>
  65. void addModificator()
  66. {
  67. modificators.emplace_back(new T(*this, map, generator));
  68. }
  69. void initModificators();
  70. CRandomGenerator & getRand();
  71. public:
  72. boost::recursive_mutex areaMutex;
  73. using Lock = boost::unique_lock<boost::recursive_mutex>;
  74. protected:
  75. CMapGenerator & generator;
  76. CRandomGenerator rand;
  77. RmgMap & map;
  78. TModificators modificators;
  79. bool finished;
  80. //placement info
  81. int3 pos;
  82. float3 center;
  83. rmg::Area dArea; //irregular area assined to zone
  84. rmg::Area dAreaPossible;
  85. rmg::Area dAreaFree; //core paths of free tiles that all other objects will be linked to
  86. rmg::Area dAreaUsed;
  87. std::vector<int3> possibleQuestArtifactPos;
  88. //template info
  89. si32 townType;
  90. TerrainId terrainType;
  91. };
  92. VCMI_LIB_NAMESPACE_END