1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Making sure that treasure piles and other objects will always be accessible from the center of zone.

This commit is contained in:
DjWarmonger 2014-06-12 21:51:16 +02:00
parent 236b3ec807
commit 2c1001f8e0

View File

@ -652,21 +652,15 @@ bool CRmgTemplateZone::createTreasurePile (CMapGenerator* gen, int3 &pos)
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
for (auto tile : boundary)
crunchPath (gen, pos, getPos(), id); //make sure pile is connected to the middle of zone
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
continue;
bool possible = false;
gen->foreach_neighbour(tile, [gen, &accessibleTiles, &possible, boundary](int3 pos)
if (gen->isFree(tile)) //this tile could be already blocked, don't place a monster here
{
if (gen->isPossible(pos) && !vstd::contains(boundary, pos)) //do not check tiles that are going to be blocked
possible = true;
});
if (possible)
accessibleTiles.push_back(tile);
guardPos = tile;
break;
}
}
guardPos = *RandomGeneratorUtil::nextItem(accessibleTiles, gen->rand);
if (addMonster(gen, guardPos, currentValue))
{//block only if object is guarded
@ -770,6 +764,7 @@ bool CRmgTemplateZone::fill(CMapGenerator* gen)
logGlobal->traceStream() << "Place found";
placeObject(gen, obj.first, pos);
crunchPath (gen, pos, getPos(), id); //make sure pile is connected to the middle of zone
if (obj.second)
{
guardObject (gen, obj.first, obj.second);