Zone.h 3.4 KB

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