RockPlacer.cpp 2.7 KB

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