WaterRoutes.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. //prohibit to place objects on sealed off lakes
  43. for(const auto & lake : wproxy->getLakes())
  44. {
  45. if((lake.area * zone.freePaths()).getTilesVector().size() == 1)
  46. {
  47. zone.freePaths().subtract(lake.area);
  48. zone.areaPossible().subtract(lake.area);
  49. }
  50. }
  51. //prohibit to place objects on the borders
  52. for(const auto & t : zone.area().getBorder())
  53. {
  54. if(zone.areaPossible().contains(t))
  55. {
  56. std::vector<int3> landTiles;
  57. map.foreachDirectNeighbour(t, [this, &landTiles, &t](const int3 & c)
  58. {
  59. if(map.isOnMap(c) && map.getZoneID(c) != zone.getId())
  60. {
  61. landTiles.push_back(c - t);
  62. }
  63. });
  64. if(landTiles.size() == 2)
  65. {
  66. int3 o = landTiles[0] + landTiles[1];
  67. if(o.x * o.x * o.y * o.y == 1)
  68. {
  69. zone.areaPossible().erase(t);
  70. zone.areaUsed().add(t);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. void WaterRoutes::init()
  77. {
  78. for(auto & z : map.getZones())
  79. {
  80. dependency(z.second->getModificator<ConnectionsPlacer>());
  81. postfunction(z.second->getModificator<ObjectManager>());
  82. postfunction(z.second->getModificator<TreasurePlacer>());
  83. }
  84. dependency(zone.getModificator<WaterProxy>());
  85. postfunction(zone.getModificator<TreasurePlacer>());
  86. }
  87. char WaterRoutes::dump(const int3 & t)
  88. {
  89. for(auto & i : result)
  90. {
  91. if(t == i.boarding)
  92. return 'B';
  93. if(t == i.visitable)
  94. return '@';
  95. if(i.blocked.contains(t))
  96. return '#';
  97. if(i.water.contains(t))
  98. {
  99. if(zone.freePaths().contains(t))
  100. return '+';
  101. else
  102. return '-';
  103. }
  104. }
  105. if(zone.freePaths().contains(t))
  106. return '.';
  107. if(zone.area().contains(t))
  108. return '~';
  109. return ' ';
  110. }
  111. VCMI_LIB_NAMESPACE_END