WaterRoutes.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * WaterRoutes.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 "WaterRoutes.h"
  12. #include "WaterProxy.h"
  13. #include "../CMapGenerator.h"
  14. #include "../RmgMap.h"
  15. #include "../../mapping/CMap.h"
  16. #include "../../mapping/CMapEditManager.h"
  17. #include "../../mapObjects/CObjectClassesHandler.h"
  18. #include "../RmgPath.h"
  19. #include "../RmgObject.h"
  20. #include "ObjectManager.h"
  21. #include "../Functions.h"
  22. #include "RoadPlacer.h"
  23. #include "TreasurePlacer.h"
  24. #include "TownPlacer.h"
  25. #include "ConnectionsPlacer.h"
  26. #include "../TileInfo.h"
  27. #include "WaterAdopter.h"
  28. #include "../RmgArea.h"
  29. VCMI_LIB_NAMESPACE_BEGIN
  30. void WaterRoutes::process()
  31. {
  32. auto * wproxy = zone.getModificator<WaterProxy>();
  33. if(!wproxy)
  34. return;
  35. if(auto * manager = zone.getModificator<ObjectManager>())
  36. manager->createDistancesPriorityQueue();
  37. for(auto & z : map.getZones())
  38. {
  39. if(z.first != zone.getId())
  40. result.push_back(wproxy->waterRoute(*z.second));
  41. }
  42. Zone::Lock lock(zone.areaMutex);
  43. //prohibit to place objects on sealed off lakes
  44. for(const auto & lake : wproxy->getLakes())
  45. {
  46. if((lake.area * zone.freePaths()).getTilesVector().size() == 1)
  47. {
  48. zone.freePaths().subtract(lake.area);
  49. zone.areaPossible().subtract(lake.area);
  50. }
  51. }
  52. //prohibit to place objects on the borders
  53. for(const auto & t : zone.area().getBorder())
  54. {
  55. if(zone.areaPossible().contains(t))
  56. {
  57. std::vector<int3> landTiles;
  58. map.foreachDirectNeighbour(t, [this, &landTiles, &t](const int3 & c)
  59. {
  60. if(map.isOnMap(c) && map.getZoneID(c) != zone.getId())
  61. {
  62. landTiles.push_back(c - t);
  63. }
  64. });
  65. if(landTiles.size() == 2)
  66. {
  67. int3 o = landTiles[0] + landTiles[1];
  68. if(o.x * o.x * o.y * o.y == 1)
  69. {
  70. zone.areaPossible().erase(t);
  71. zone.areaUsed().add(t);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. void WaterRoutes::init()
  78. {
  79. for(auto & z : map.getZones())
  80. {
  81. dependency(z.second->getModificator<ConnectionsPlacer>());
  82. postfunction(z.second->getModificator<ObjectManager>());
  83. postfunction(z.second->getModificator<TreasurePlacer>());
  84. }
  85. dependency(zone.getModificator<WaterProxy>());
  86. postfunction(zone.getModificator<TreasurePlacer>());
  87. }
  88. char WaterRoutes::dump(const int3 & t)
  89. {
  90. for(auto & i : result)
  91. {
  92. if(t == i.boarding)
  93. return 'B';
  94. if(t == i.visitable)
  95. return '@';
  96. if(i.blocked.contains(t))
  97. return '#';
  98. if(i.water.contains(t))
  99. {
  100. if(zone.freePaths().contains(t))
  101. return '+';
  102. else
  103. return '-';
  104. }
  105. }
  106. if(zone.freePaths().contains(t))
  107. return '.';
  108. if(zone.area().contains(t))
  109. return '~';
  110. return ' ';
  111. }
  112. VCMI_LIB_NAMESPACE_END