Zone.h 2.5 KB

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