mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-17 13:41:07 +02:00
Making sure that treasure piles and other objects will always be accessible from the center of zone.
This commit is contained in:
parent
236b3ec807
commit
2c1001f8e0
@ -652,21 +652,15 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
|
|||||||
placeObject(gen, treasure.second, treasure.first - treasure.second->getVisitableOffset());
|
placeObject(gen, treasure.second, treasure.first - treasure.second->getVisitableOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int3> accessibleTiles; //we can't place guard in dead-end of zone, make sure that at least one neightbouring tile is possible and not blocked
|
crunchPath (gen, pos, getPos(), id); //make sure pile is connected to the middle of zone
|
||||||
for (auto tile : boundary)
|
for (auto tile : boundary) //guard must be standing there
|
||||||
{
|
{
|
||||||
if (gen->shouldBeBlocked(tile)) //this tile could be already blocked, don't place a monster here
|
if (gen->isFree(tile)) //this tile could be already blocked, don't place a monster here
|
||||||
continue;
|
|
||||||
bool possible = false;
|
|
||||||
gen->foreach_neighbour(tile, [gen, &accessibleTiles, &possible, boundary](int3 pos)
|
|
||||||
{
|
{
|
||||||
if (gen->isPossible(pos) && !vstd::contains(boundary, pos)) //do not check tiles that are going to be blocked
|
guardPos = tile;
|
||||||
possible = true;
|
break;
|
||||||
});
|
}
|
||||||
if (possible)
|
|
||||||
accessibleTiles.push_back(tile);
|
|
||||||
}
|
}
|
||||||
guardPos = *RandomGeneratorUtil::nextItem(accessibleTiles, gen->rand);
|
|
||||||
|
|
||||||
if (addMonster(gen, guardPos, currentValue))
|
if (addMonster(gen, guardPos, currentValue))
|
||||||
{//block only if object is guarded
|
{//block only if object is guarded
|
||||||
@ -770,6 +764,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
|
|||||||
logGlobal->traceStream() << "Place found";
|
logGlobal->traceStream() << "Place found";
|
||||||
|
|
||||||
placeObject(gen, obj.first, pos);
|
placeObject(gen, obj.first, pos);
|
||||||
|
crunchPath (gen, pos, getPos(), id); //make sure pile is connected to the middle of zone
|
||||||
if (obj.second)
|
if (obj.second)
|
||||||
{
|
{
|
||||||
guardObject (gen, obj.first, obj.second);
|
guardObject (gen, obj.first, obj.second);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user