Zone.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. //uncomment to generate dumps afger every step of map generation
  19. //#define RMG_DUMP
  20. #define MODIFICATOR(x) x(Zone & z, RmgMap & m, CMapGenerator & g): Modificator(z, m, g) {setName(#x);}
  21. #define DEPENDENCY(x) dependency(zone.getModificator<x>());
  22. #define POSTFUNCTION(x) postfunction(zone.getModificator<x>());
  23. #define DEPENDENCY_ALL(x) for(auto & z : map.getZones()) \
  24. { \
  25. dependency(z.second->getModificator<x>()); \
  26. }
  27. #define POSTFUNCTION_ALL(x) for(auto & z : map.getZones()) \
  28. { \
  29. postfunction(z.second->getModificator<x>()); \
  30. }
  31. VCMI_LIB_NAMESPACE_BEGIN
  32. class RmgMap;
  33. class CMapGenerator;
  34. class Zone;
  35. class Modificator
  36. {
  37. public:
  38. Modificator() = delete;
  39. Modificator(Zone & zone, RmgMap & map, CMapGenerator & generator);
  40. virtual void process() = 0;
  41. virtual void init() {/*override to add dependencies*/}
  42. virtual char dump(const int3 &);
  43. virtual ~Modificator() = default;
  44. void setName(const std::string & n);
  45. const std::string & getName() const;
  46. void run();
  47. void dependency(Modificator * modificator);
  48. void postfunction(Modificator * modificator);
  49. protected:
  50. RmgMap & map;
  51. CMapGenerator & generator;
  52. Zone & zone;
  53. bool isFinished() const;
  54. private:
  55. std::string name;
  56. bool started = false;
  57. bool finished = false;
  58. std::list<Modificator*> preceeders; //must be ordered container
  59. void dump();
  60. };
  61. extern std::function<bool(const int3 &)> AREA_NO_FILTER;
  62. class Zone : public rmg::ZoneOptions
  63. {
  64. public:
  65. Zone(RmgMap & map, CMapGenerator & generator);
  66. Zone(const Zone &) = delete;
  67. void setOptions(const rmg::ZoneOptions & options);
  68. bool isUnderground() const;
  69. float3 getCenter() const;
  70. void setCenter(const float3 &f);
  71. int3 getPos() const;
  72. void setPos(const int3 &pos);
  73. const rmg::Area & getArea() const;
  74. rmg::Area & area();
  75. rmg::Area & areaPossible();
  76. rmg::Area & freePaths();
  77. rmg::Area & areaUsed();
  78. std::vector<int3> getPossibleQuestArtifactPos() const;
  79. void initFreeTiles();
  80. void clearTiles();
  81. void fractalize();
  82. FactionID getTownType() const;
  83. void setTownType(si32 town);
  84. TerrainId getTerrainType() const;
  85. void setTerrainType(TerrainId terrain);
  86. void connectPath(const rmg::Path & path);
  87. rmg::Path searchPath(const rmg::Area & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  88. rmg::Path searchPath(const int3 & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  89. template<class T>
  90. T* getModificator()
  91. {
  92. for(auto & m : modificators)
  93. if(auto * mm = dynamic_cast<T*>(m.get()))
  94. return mm;
  95. return nullptr;
  96. }
  97. template<class T>
  98. void addModificator()
  99. {
  100. modificators.emplace_back(new T(*this, map, generator));
  101. }
  102. void initModificators();
  103. void processModificators();
  104. protected:
  105. CMapGenerator & generator;
  106. RmgMap & map;
  107. std::list<std::unique_ptr<Modificator>> modificators;
  108. //placement info
  109. int3 pos;
  110. float3 center;
  111. rmg::Area dArea; //irregular area assined to zone
  112. rmg::Area dAreaPossible;
  113. rmg::Area dAreaFree; //core paths of free tiles that all other objects will be linked to
  114. rmg::Area dAreaUsed;
  115. std::vector<int3> possibleQuestArtifactPos;
  116. //template info
  117. si32 townType;
  118. TerrainId terrainType;
  119. };
  120. VCMI_LIB_NAMESPACE_END