RockPlacer.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "../CRandomGenerator.h"
  20. #include "../mapping/CMapEditManager.h"
  21. void RockPlacer::process()
  22. {
  23. rockTerrain = Terrain::Manager::getInfo(zone.getTerrainType()).rockTerrain;
  24. assert(!rockTerrain.isPassable());
  25. accessibleArea = zone.freePaths() + zone.areaUsed();
  26. if(auto * m = zone.getModificator<ObjectManager>())
  27. accessibleArea.unite(m->getVisitableArea());
  28. //negative approach - create rock tiles first, then make sure all accessible tiles have no rock
  29. rockArea = zone.area().getSubarea([this](const int3 & t)
  30. {
  31. return map.shouldBeBlocked(t);
  32. });
  33. for(auto & z : map.getZones())
  34. {
  35. if(auto * m = z.second->getModificator<RockPlacer>())
  36. {
  37. if(m != this && !m->isFinished())
  38. return;
  39. }
  40. }
  41. processMap();
  42. }
  43. void RockPlacer::processMap()
  44. {
  45. //merge all areas
  46. for(auto & z : map.getZones())
  47. {
  48. if(auto * m = z.second->getModificator<RockPlacer>())
  49. {
  50. map.getEditManager()->getTerrainSelection().setSelection(m->rockArea.getTilesVector());
  51. map.getEditManager()->drawTerrain(m->rockTerrain, &generator.rand);
  52. }
  53. }
  54. for(auto & z : map.getZones())
  55. {
  56. if(auto * m = z.second->getModificator<RockPlacer>())
  57. {
  58. //now make sure all accessible tiles have no additional rock on them
  59. map.getEditManager()->getTerrainSelection().setSelection(m->accessibleArea.getTilesVector());
  60. map.getEditManager()->drawTerrain(z.second->getTerrainType(), &generator.rand);
  61. m->postProcess();
  62. }
  63. }
  64. }
  65. void RockPlacer::postProcess()
  66. {
  67. //finally mark rock tiles as occupied, spawn no obstacles there
  68. rockArea = zone.area().getSubarea([this](const int3 & t)
  69. {
  70. return !map.map().getTile(t).terType.isPassable();
  71. });
  72. zone.areaUsed().unite(rockArea);
  73. zone.areaPossible().subtract(rockArea);
  74. if(auto * m = zone.getModificator<RiverPlacer>())
  75. m->riverProhibit().unite(rockArea);
  76. if(auto * m = zone.getModificator<RoadPlacer>())
  77. m->areaIsolated().unite(rockArea);
  78. }
  79. void RockPlacer::init()
  80. {
  81. POSTFUNCTION_ALL(RoadPlacer);
  82. DEPENDENCY(TreasurePlacer);
  83. }
  84. char RockPlacer::dump(const int3 & t)
  85. {
  86. if(!map.map().getTile(t).terType.isPassable())
  87. {
  88. return zone.area().contains(t) ? 'R' : 'E';
  89. }
  90. return Modificator::dump(t);
  91. }