1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Implemented "junction" zone type.

This commit is contained in:
DjWarmonger
2015-01-16 17:39:16 +01:00
parent b7386250e9
commit ba604f4e43
2 changed files with 46 additions and 40 deletions

View File

@ -8,6 +8,7 @@ BATTLES:
* Implemented OH3 stack split / upgrade formulas according to AlexSpl * Implemented OH3 stack split / upgrade formulas according to AlexSpl
RANDOM MAP GENERATOR: RANDOM MAP GENERATOR:
* Implemented "junction" zone type
* Improved zone placing algorithm * Improved zone placing algorithm
* More balanced distribution of treasure piles * More balanced distribution of treasure piles
* More obstacles within zones * More obstacles within zones

View File

@ -429,57 +429,62 @@ void CRmgTemplateZone::fractalize(CMapGenerator* gen)
} }
assert (clearedTiles.size()); //this should come from zone connections assert (clearedTiles.size()); //this should come from zone connections
while (possibleTiles.size()) if (type != ETemplateZoneType::JUNCTION)
{ {
//link tiles in random order //junction is not fractalized, has only one straight path
std::vector<int3> tilesToMakePath(possibleTiles.begin(), possibleTiles.end()); //everything else remains blocked
RandomGeneratorUtil::randomShuffle(tilesToMakePath, gen->rand); while (possibleTiles.size())
for (auto tileToMakePath : tilesToMakePath)
{ {
//find closest free tile //link tiles in random order
float currentDistance = 1e10; std::vector<int3> tilesToMakePath(possibleTiles.begin(), possibleTiles.end());
int3 closestTile (-1,-1,-1); RandomGeneratorUtil::randomShuffle(tilesToMakePath, gen->rand);
for (auto clearTile : clearedTiles) for (auto tileToMakePath : tilesToMakePath)
{ {
float distance = tileToMakePath.dist2dSQ(clearTile); //find closest free tile
float currentDistance = 1e10;
int3 closestTile(-1, -1, -1);
if (distance < currentDistance) for (auto clearTile : clearedTiles)
{ {
currentDistance = distance; float distance = tileToMakePath.dist2dSQ(clearTile);
closestTile = clearTile;
if (distance < currentDistance)
{
currentDistance = distance;
closestTile = clearTile;
}
if (currentDistance <= minDistance)
{
//this tile is close enough. Forget about it and check next one
tilesToIgnore.insert(tileToMakePath);
break;
}
} }
if (currentDistance <= minDistance) //if tiles is not close enough, make path to it
if (currentDistance > minDistance)
{ {
//this tile is close enough. Forget about it and check next one crunchPath(gen, tileToMakePath, closestTile, id, &tilesToClear);
tilesToIgnore.insert (tileToMakePath); break; //next iteration - use already cleared tiles
break;
} }
} }
//if tiles is not close enough, make path to it
if (currentDistance > minDistance)
{
crunchPath (gen, tileToMakePath, closestTile, id, &tilesToClear);
break; //next iteration - use already cleared tiles
}
}
for (auto tileToClear : tilesToClear) for (auto tileToClear : tilesToClear)
{ {
//move cleared tiles from one set to another //move cleared tiles from one set to another
clearedTiles.push_back(tileToClear); clearedTiles.push_back(tileToClear);
vstd::erase_if_present(possibleTiles, tileToClear); vstd::erase_if_present(possibleTiles, tileToClear);
}
for (auto tileToClear : tilesToIgnore)
{
//these tiles are already connected, ignore them
vstd::erase_if_present(possibleTiles, tileToClear);
}
if (tilesToClear.empty()) //nothing else can be done (?)
break;
tilesToClear.clear(); //empty this container
tilesToIgnore.clear();
} }
for (auto tileToClear : tilesToIgnore)
{
//these tiles are already connected, ignore them
vstd::erase_if_present(possibleTiles, tileToClear);
}
if (tilesToClear.empty()) //nothing else can be done (?)
break;
tilesToClear.clear(); //empty this container
tilesToIgnore.clear();
} }
for (auto tile : clearedTiles) for (auto tile : clearedTiles)