1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-03 14:52:11 +02:00

Correct implementation for previous fix.

This commit is contained in:
DjWarmonger 2016-07-25 18:37:42 +02:00
parent d9556332e1
commit 5a1383fea8

View File

@ -491,14 +491,21 @@ void CMapGenerator::createConnections()
middleTiles.push_back(tile);
});
}
boost::sort(middleTiles, [](int3 &lhs, int3 &rhs) -> bool
//find tiles with minimum manhattan distance from center of the mass of zone border
size_t tilesCount = middleTiles.size() ? middleTiles.size() : 1;
int3 middleTile = std::accumulate(middleTiles.begin(), middleTiles.end(), int3(0, 0, 0));
middleTile.x /= tilesCount;
middleTile.y /= tilesCount;
middleTile.z /= tilesCount; //TODO: implement division operator for int3?
boost::sort(middleTiles, [middleTile](int3 &lhs, int3 &rhs) -> bool
{
//choose tiles with both corrdinates in the middle
return lhs.x + lhs.y < rhs.x + rhs.y;
return lhs.mandist2d(middleTile) < rhs.mandist2d(middleTile);
});
//remove 1/4 tiles from each side - path shoudl cross zone borders at smooth angle
size_t removedCount = middleTiles.size() / 4; //rounded down
//remove 1/4 tiles from each side - path should cross zone borders at smooth angle
size_t removedCount = tilesCount / 4; //rounded down
middleTiles.erase(middleTiles.end() - removedCount, middleTiles.end());
middleTiles.erase(middleTiles.begin(), middleTiles.begin() + removedCount);