RockPlacer.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. for (const auto& zone : map.getZones())
  61. {
  62. if (zone.second->isUnderground())
  63. {
  64. auto * tp = zone.second->getModificator<TreasurePlacer>();
  65. if (tp)
  66. {
  67. dependency(tp);
  68. }
  69. }
  70. }
  71. }
  72. char RockPlacer::dump(const int3 & t)
  73. {
  74. if(!map.getTile(t).terType->isPassable())
  75. {
  76. return zone.area().contains(t) ? 'R' : 'E';
  77. }
  78. return Modificator::dump(t);
  79. }
  80. VCMI_LIB_NAMESPACE_END