Zone.h 2.6 KB

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