Zone.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "threadpool/JobProvider.h"
  15. #include "CRmgTemplate.h"
  16. #include "RmgArea.h"
  17. #include "RmgPath.h"
  18. #include "RmgObject.h"
  19. #include "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. class Zone : public rmg::ZoneOptions, public IJobProvider
  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. TRMGJob getNextJob() override;
  54. bool hasJobs() override;
  55. template<class T>
  56. T* getModificator()
  57. {
  58. //TODO: Protect with recursive mutex?
  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. void processModificators();
  71. protected:
  72. CMapGenerator & generator;
  73. RmgMap & map;
  74. std::list<std::unique_ptr<Modificator>> modificators;
  75. //placement info
  76. int3 pos;
  77. float3 center;
  78. rmg::Area dArea; //irregular area assined to zone
  79. rmg::Area dAreaPossible;
  80. rmg::Area dAreaFree; //core paths of free tiles that all other objects will be linked to
  81. rmg::Area dAreaUsed;
  82. std::vector<int3> possibleQuestArtifactPos;
  83. //template info
  84. si32 townType;
  85. TerrainId terrainType;
  86. };
  87. VCMI_LIB_NAMESPACE_END