1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Fix problems with water zone

This commit is contained in:
nordsoft 2022-08-27 03:21:27 +04:00
parent 4458cdf6c9
commit 035857c190
6 changed files with 21 additions and 7 deletions

View File

@ -85,8 +85,15 @@ bool Area::connected() const
return connected.empty();
}
std::list<Area> connectedAreas(const Area & area)
std::list<Area> connectedAreas(const Area & area, bool disableDiagonalConnections)
{
auto allDirs = int3::getDirs();
std::vector<int3> dirs;
if(disableDiagonalConnections)
dirs.insert(dirs.begin(), allDirs.begin(), allDirs.begin() + 4);
else
dirs.insert(dirs.begin(), allDirs.begin(), allDirs.end());
std::list<Area> result;
Tileset connected = area.getTiles();
while(!connected.empty())
@ -101,7 +108,7 @@ std::list<Area> connectedAreas(const Area & area)
result.back().add(t);
queue.pop_front();
for(auto & i : int3::getDirs())
for(auto & i : dirs)
{
auto tile = t + i;
if(!queueSet.count(tile) && connected.count(tile) && !result.back().contains(tile))

View File

@ -66,7 +66,7 @@ namespace rmg
friend Area operator* (const Area & l, const Area & r); //intersection
friend Area operator- (const Area & l, const Area & r); //AreaL reduced by tiles from AreaR
friend bool operator== (const Area & l, const Area & r);
friend std::list<Area> connectedAreas(const Area & area);
friend std::list<Area> connectedAreas(const Area & area, bool disableDiagonalConnections);
private:

View File

@ -715,7 +715,10 @@ void TreasurePlacer::createTreasures(ObjectManager & manager)
{
auto treasurePileInfos = prepareTreasurePile(t);
if(treasurePileInfos.empty())
break;
{
++attempt;
continue;
}
int value = std::accumulate(treasurePileInfos.begin(), treasurePileInfos.end(), 0, [](int v, const ObjectInfo * oi){return v + oi->value;});

View File

@ -93,7 +93,7 @@ const std::vector<WaterProxy::Lake> & WaterProxy::getLakes() const
void WaterProxy::collectLakes()
{
int lakeId = 0;
for(auto lake : connectedAreas(zone.getArea()))
for(auto lake : connectedAreas(zone.getArea(), true))
{
lakes.push_back(Lake{});
lakes.back().area = lake;
@ -267,6 +267,7 @@ bool WaterProxy::placeShipyard(Zone & land, const Lake & lake, si32 guard, Route
bool guarded = manager->addGuard(rmgObject, guard);
auto waterAvailable = zone.areaPossible() + zone.freePaths();
waterAvailable.intersect(lake.area);
rmg::Area coast = lake.neighbourZones.at(land.getId()); //having land tiles
coast.intersect(land.areaPossible() + land.freePaths()); //having only available land tiles
auto boardingPositions = coast.getSubarea([&waterAvailable](const int3 & tile) //tiles where boarding is possible

View File

@ -34,6 +34,9 @@ void WaterRoutes::process()
if(!wproxy)
return;
if(auto * manager = zone.getModificator<ObjectManager>())
manager->createDistancesPriorityQueue();
for(auto & z : map.getZones())
{
if(z.first != zone.getId())

View File

@ -159,7 +159,7 @@ rmg::Path Zone::searchPath(const rmg::Area & src, bool onlyStraight, std::functi
freePath.connect(dAreaFree);
//connect to all pieces
auto goals = connectedAreas(src);
auto goals = connectedAreas(src, onlyStraight);
for(auto & goal : goals)
{
auto path = freePath.search(goal, onlyStraight, movementCost);
@ -235,7 +235,7 @@ void Zone::fractalize()
}
//cut straight paths towards the center. A* is too slow for that.
auto areas = connectedAreas(clearedTiles);
auto areas = connectedAreas(clearedTiles, false);
for(auto & area : areas)
{
if(dAreaFree.overlap(area))