WaterRoutes.cpp 2.5 KB

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