RockPlacer.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "../TileInfo.h"
  23. VCMI_LIB_NAMESPACE_BEGIN
  24. class TileInfo;
  25. void RockPlacer::process()
  26. {
  27. blockRock();
  28. }
  29. void RockPlacer::blockRock()
  30. {
  31. rockTerrain = VLC->terrainTypeHandler->getById(zone.getTerrainType())->rockTerrain;
  32. assert(!VLC->terrainTypeHandler->getById(rockTerrain)->isPassable());
  33. accessibleArea = zone.freePaths() + zone.areaUsed();
  34. if(auto * m = zone.getModificator<ObjectManager>())
  35. accessibleArea.unite(m->getVisitableArea());
  36. //negative approach - create rock tiles first, then make sure all accessible tiles have no rock
  37. rockArea = zone.area()->getSubarea([this](const int3 & t)
  38. {
  39. return map.shouldBeBlocked(t);
  40. });
  41. }
  42. void RockPlacer::postProcess()
  43. {
  44. {
  45. Zone::Lock lock(zone.areaMutex);
  46. //Finally mark rock tiles as occupied, spawn no obstacles there
  47. rockArea = zone.area()->getSubarea([this](const int3 & t)
  48. {
  49. return !map.getTile(t).terType->isPassable();
  50. });
  51. zone.areaUsed()->unite(rockArea);
  52. zone.areaPossible()->subtract(rockArea);
  53. }
  54. //RecursiveLock lock(externalAccessMutex);
  55. if(auto * m = zone.getModificator<RiverPlacer>())
  56. m->riverProhibit().unite(rockArea);
  57. if(auto * m = zone.getModificator<RoadPlacer>())
  58. m->areaIsolated().unite(rockArea);
  59. }
  60. void RockPlacer::init()
  61. {
  62. for (const auto& zone : map.getZones())
  63. {
  64. if (zone.second->isUnderground())
  65. {
  66. auto * tp = zone.second->getModificator<TreasurePlacer>();
  67. if (tp)
  68. {
  69. dependency(tp);
  70. }
  71. }
  72. }
  73. }
  74. char RockPlacer::dump(const int3 & t)
  75. {
  76. if(!map.getTile(t).terType->isPassable())
  77. {
  78. return zone.area()->contains(t) ? 'R' : 'E';
  79. }
  80. return Modificator::dump(t);
  81. }
  82. VCMI_LIB_NAMESPACE_END