2
0

WaterRoutes.cpp 2.7 KB

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