WaterRoutes.cpp 2.6 KB

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