RockPlacer.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. Zone::Lock lock(zone.areaMutex);
  45. //Finally mark rock tiles as occupied, spawn no obstacles there
  46. rockArea = zone.area().getSubarea([this](const int3 & t)
  47. {
  48. return !map.getTile(t).terType->isPassable();
  49. });
  50. zone.areaUsed().unite(rockArea);
  51. zone.areaPossible().subtract(rockArea);
  52. //TODO: Might need mutex here as well
  53. if(auto * m = zone.getModificator<RiverPlacer>())
  54. m->riverProhibit().unite(rockArea);
  55. if(auto * m = zone.getModificator<RoadPlacer>())
  56. m->areaIsolated().unite(rockArea);
  57. }
  58. void RockPlacer::init()
  59. {
  60. DEPENDENCY_ALL(TreasurePlacer);
  61. }
  62. char RockPlacer::dump(const int3 & t)
  63. {
  64. if(!map.getTile(t).terType->isPassable())
  65. {
  66. return zone.area().contains(t) ? 'R' : 'E';
  67. }
  68. return Modificator::dump(t);
  69. }
  70. VCMI_LIB_NAMESPACE_END