RockPlacer.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * RockPlacer.cpp, 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. #include "StdInc.h"
  11. #include "RockPlacer.h"
  12. #include "TreasurePlacer.h"
  13. #include "ObjectManager.h"
  14. #include "RoadPlacer.h"
  15. #include "RiverPlacer.h"
  16. #include "../RmgMap.h"
  17. #include "../CMapGenerator.h"
  18. #include "../Functions.h"
  19. #include "../../TerrainHandler.h"
  20. #include "../../CRandomGenerator.h"
  21. #include "../../mapping/CMapEditManager.h"
  22. #include "../../VCMI_Lib.h"
  23. #include "../TileInfo.h"
  24. VCMI_LIB_NAMESPACE_BEGIN
  25. class TileInfo;
  26. void RockPlacer::process()
  27. {
  28. blockRock();
  29. }
  30. void RockPlacer::blockRock()
  31. {
  32. rockTerrain = VLC->terrainTypeHandler->getById(zone.getTerrainType())->rockTerrain;
  33. assert(!VLC->terrainTypeHandler->getById(rockTerrain)->isPassable());
  34. accessibleArea = zone.freePaths() + zone.areaUsed();
  35. if(auto * rp = zone.getModificator<RoadPlacer>())
  36. {
  37. accessibleArea.unite(rp->getRoads());
  38. }
  39. if(auto * m = zone.getModificator<ObjectManager>())
  40. {
  41. accessibleArea.unite(m->getVisitableArea());
  42. }
  43. //negative approach - create rock tiles first, then make sure all accessible tiles have no rock
  44. rockArea = zone.area()->getSubarea([this](const int3 & t)
  45. {
  46. return map.shouldBeBlocked(t);
  47. });
  48. }
  49. void RockPlacer::postProcess()
  50. {
  51. {
  52. Zone::Lock lock(zone.areaMutex);
  53. //Finally mark rock tiles as occupied, spawn no obstacles there
  54. rockArea = zone.area()->getSubarea([this](const int3 & t)
  55. {
  56. return !map.getTile(t).terType->isPassable();
  57. });
  58. // Do not place rock on roads
  59. if(auto * rp = zone.getModificator<RoadPlacer>())
  60. {
  61. rockArea.subtract(rp->getRoads());
  62. }
  63. zone.areaUsed()->unite(rockArea);
  64. zone.areaPossible()->subtract(rockArea);
  65. }
  66. //RecursiveLock lock(externalAccessMutex);
  67. if(auto * m = zone.getModificator<RiverPlacer>())
  68. m->riverProhibit().unite(rockArea);
  69. if(auto * m = zone.getModificator<RoadPlacer>())
  70. m->areaIsolated().unite(rockArea);
  71. }
  72. void RockPlacer::init()
  73. {
  74. DEPENDENCY(RoadPlacer);
  75. for (const auto& zone : map.getZonesOnLevel(1))
  76. {
  77. auto * tp = zone.second->getModificator<TreasurePlacer>();
  78. if (tp)
  79. {
  80. dependency(tp);
  81. }
  82. }
  83. }
  84. char RockPlacer::dump(const int3 & t)
  85. {
  86. if(!map.getTile(t).terType->isPassable())
  87. {
  88. return zone.area()->contains(t) ? 'R' : 'E';
  89. }
  90. return Modificator::dump(t);
  91. }
  92. VCMI_LIB_NAMESPACE_END