2
0

Zone.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. void initFreeTiles();
  79. void clearTiles();
  80. void fractalize();
  81. si32 getTownType() const;
  82. void setTownType(si32 town);
  83. TerrainId getTerrainType() const;
  84. void setTerrainType(TerrainId terrain);
  85. void connectPath(const rmg::Path & path);
  86. rmg::Path searchPath(const rmg::Area & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  87. rmg::Path searchPath(const int3 & src, bool onlyStraight, const std::function<bool(const int3 &)> & areafilter = AREA_NO_FILTER) const;
  88. template<class T>
  89. T* getModificator()
  90. {
  91. for(auto & m : modificators)
  92. if(auto * mm = dynamic_cast<T*>(m.get()))
  93. return mm;
  94. return nullptr;
  95. }
  96. template<class T>
  97. void addModificator()
  98. {
  99. modificators.emplace_back(new T(*this, map, generator));
  100. }
  101. void initModificators();
  102. void processModificators();
  103. protected:
  104. CMapGenerator & generator;
  105. RmgMap & map;
  106. std::list<std::unique_ptr<Modificator>> modificators;
  107. //placement info
  108. int3 pos;
  109. float3 center;
  110. rmg::Area dArea; //irregular area assined to zone
  111. rmg::Area dAreaPossible;
  112. rmg::Area dAreaFree; //core paths of free tiles that all other objects will be linked to
  113. rmg::Area dAreaUsed;
  114. //template info
  115. si32 townType;
  116. TerrainId terrainType;
  117. };
  118. VCMI_LIB_NAMESPACE_END