mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Refactoring - create underground rock for whole level at once.
This commit is contained in:
@@ -258,6 +258,14 @@ void CMapGenerator::fillZones()
|
||||
treasureZones.push_back(it.second);
|
||||
}
|
||||
|
||||
//set apriopriate free/occupied tiles, including blocked underground rock
|
||||
createObstaclesCommon();
|
||||
//place actual obstacles matching zone terrain
|
||||
for (auto it : zones)
|
||||
{
|
||||
it.second->createObstacles(this);
|
||||
}
|
||||
|
||||
//find place for Grail
|
||||
if (treasureZones.empty())
|
||||
{
|
||||
@@ -271,6 +279,89 @@ void CMapGenerator::fillZones()
|
||||
logGlobal->infoStream() << "Zones filled successfully";
|
||||
}
|
||||
|
||||
void CMapGenerator::createObstaclesCommon()
|
||||
{
|
||||
//tighten obstacles to improve visuals
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
int blockedTiles = 0;
|
||||
int freeTiles = 0;
|
||||
|
||||
for (int z = 0; z < (map->twoLevel ? 2 : 1); z++)
|
||||
{
|
||||
for (int x = 0; x < map->width; x++)
|
||||
{
|
||||
for (int y = 0; y < map->height; y++)
|
||||
{
|
||||
int3 tile(x, y, z);
|
||||
if (!isPossible(tile)) //only possible tiles can change
|
||||
continue;
|
||||
|
||||
int blockedNeighbours = 0;
|
||||
int freeNeighbours = 0;
|
||||
foreach_neighbour(tile, [this, &blockedNeighbours, &freeNeighbours](int3 &pos)
|
||||
{
|
||||
if (this->isBlocked(pos))
|
||||
blockedNeighbours++;
|
||||
if (this->isFree(pos))
|
||||
freeNeighbours++;
|
||||
});
|
||||
if (blockedNeighbours > 4)
|
||||
{
|
||||
setOccupied(tile, ETileType::BLOCKED);
|
||||
blockedTiles++;
|
||||
}
|
||||
else if (freeNeighbours > 4)
|
||||
{
|
||||
setOccupied(tile, ETileType::FREE);
|
||||
freeTiles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logGlobal->traceStream() << boost::format("Set %d tiles to BLOCKED and %d tiles to FREE") % blockedTiles % freeTiles;
|
||||
}
|
||||
|
||||
#define MAKE_COOL_UNDERGROUND_TUNNELS true
|
||||
if (map->twoLevel && MAKE_COOL_UNDERGROUND_TUNNELS) //underground
|
||||
{
|
||||
std::vector<int3> rockTiles;
|
||||
|
||||
for (int x = 0; x < map->width; x++)
|
||||
{
|
||||
for (int y = 0; y < map->height; y++)
|
||||
{
|
||||
int3 tile(x, y, 1);
|
||||
if (shouldBeBlocked(tile))
|
||||
{
|
||||
bool placeRock = true;
|
||||
foreach_neighbour(tile, [this, &placeRock](int3 &pos)
|
||||
{
|
||||
if (!(this->shouldBeBlocked(pos) || this->isPossible(pos)))
|
||||
placeRock = false;
|
||||
});
|
||||
if (placeRock)
|
||||
{
|
||||
rockTiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
editManager->getTerrainSelection().setSelection(rockTiles);
|
||||
editManager->drawTerrain(ETerrainType::ROCK, &rand);
|
||||
for (auto tile : rockTiles)
|
||||
{
|
||||
setOccupied(tile, ETileType::USED); //don't place obstacles in a rock
|
||||
//gen->foreach_neighbour (tile, [gen](int3 &pos)
|
||||
//{
|
||||
// if (!gen->isUsed(pos))
|
||||
// gen->setOccupied (pos, ETileType::BLOCKED);
|
||||
//});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMapGenerator::findZonesForQuestArts()
|
||||
{
|
||||
//we want to place arties in zones that were not yet filled (higher index)
|
||||
|
@@ -110,5 +110,6 @@ private:
|
||||
void initTiles();
|
||||
void genZones();
|
||||
void fillZones();
|
||||
void createObstaclesCommon();
|
||||
|
||||
};
|
||||
|
@@ -1339,74 +1339,7 @@ void CRmgTemplateZone::createTreasures(CMapGenerator* gen)
|
||||
|
||||
void CRmgTemplateZone::createObstacles(CMapGenerator* gen)
|
||||
{
|
||||
//tighten obstacles to improve visuals
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
int blockedTiles = 0;
|
||||
int freeTiles = 0;
|
||||
|
||||
for (auto tile : tileinfo)
|
||||
{
|
||||
if (!gen->isPossible(tile)) //only possible tiles can change
|
||||
continue;
|
||||
|
||||
int blockedNeighbours = 0;
|
||||
int freeNeighbours = 0;
|
||||
gen->foreach_neighbour(tile, [gen, &blockedNeighbours, &freeNeighbours](int3 &pos)
|
||||
{
|
||||
if (gen->isBlocked(pos))
|
||||
blockedNeighbours++;
|
||||
if (gen->isFree(pos))
|
||||
freeNeighbours++;
|
||||
});
|
||||
if (blockedNeighbours > 4)
|
||||
{
|
||||
gen->setOccupied(tile, ETileType::BLOCKED);
|
||||
blockedTiles++;
|
||||
}
|
||||
else if (freeNeighbours > 4)
|
||||
{
|
||||
gen->setOccupied(tile, ETileType::FREE);
|
||||
freeTiles++;
|
||||
}
|
||||
}
|
||||
logGlobal->traceStream() << boost::format("Set %d tiles to BLOCKED and %d tiles to FREE") % blockedTiles % freeTiles;
|
||||
}
|
||||
|
||||
#define MAKE_COOL_UNDERGROUND_TUNNELS true
|
||||
if (pos.z && MAKE_COOL_UNDERGROUND_TUNNELS) //underground
|
||||
{
|
||||
std::vector<int3> rockTiles;
|
||||
|
||||
for (auto tile : tileinfo)
|
||||
{
|
||||
if (gen->shouldBeBlocked(tile))
|
||||
{
|
||||
bool placeRock = true;
|
||||
gen->foreach_neighbour (tile, [gen, &placeRock](int3 &pos)
|
||||
{
|
||||
if (!(gen->shouldBeBlocked(pos) || gen->isPossible(pos)))
|
||||
placeRock = false;
|
||||
});
|
||||
if (placeRock)
|
||||
{
|
||||
rockTiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
gen->editManager->getTerrainSelection().setSelection(rockTiles);
|
||||
gen->editManager->drawTerrain(ETerrainType::ROCK, &gen->rand);
|
||||
for (auto tile : rockTiles)
|
||||
{
|
||||
gen->setOccupied (tile, ETileType::USED); //don't place obstacles in a rock
|
||||
//gen->foreach_neighbour (tile, [gen](int3 &pos)
|
||||
//{
|
||||
// if (!gen->isUsed(pos))
|
||||
// gen->setOccupied (pos, ETileType::BLOCKED);
|
||||
//});
|
||||
}
|
||||
}
|
||||
typedef std::vector<ObjectTemplate> obstacleVector;
|
||||
//obstacleVector possibleObstacles;
|
||||
|
||||
@@ -1483,7 +1416,6 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
|
||||
createRequiredObjects(gen);
|
||||
fractalize(gen); //after required objects are created and linked with their own paths
|
||||
createTreasures(gen);
|
||||
createObstacles(gen);
|
||||
|
||||
logGlobal->infoStream() << boost::format ("Zone %d filled successfully") %id;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user