1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Fix problem with empty areas (#772)

* Fixes for obstacles and treasures
This commit is contained in:
Nordsoft91 2022-08-11 15:29:39 +04:00 committed by Andrii Danylchenko
parent 9ec0ca332c
commit ae63e0c30e
3 changed files with 10 additions and 2 deletions

View File

@ -135,6 +135,7 @@ rmg::Path ObjectManager::placeAndConnectObject(const rmg::Area & searchArea, rmg
{
auto & guardedArea = obj.instances().back()->getAccessibleArea();
accessibleArea.intersect(guardedArea);
accessibleArea.add(obj.instances().back()->getPosition(true));
}
auto path = zone.searchPath(accessibleArea, onlyStraight, [&obj, isGuarded](const int3 & t)
@ -145,6 +146,10 @@ rmg::Path ObjectManager::placeAndConnectObject(const rmg::Area & searchArea, rmg
auto & unguardedArea = obj.getAccessibleArea(isGuarded);
if(unguardedArea.contains(t) && !guardedArea.contains(t))
return false;
//guard position is always target
if(obj.instances().back()->getPosition(true) == t)
return true;
}
return !obj.getArea().contains(t);
});

View File

@ -88,7 +88,10 @@ void ObstaclePlacer::process()
if(!possibleObstacles[i].first)
continue;
for(auto & temp : possibleObstacles[i].second)
auto shuffledObstacles = possibleObstacles[i].second;
RandomGeneratorUtil::randomShuffle(shuffledObstacles, generator.rand);
for(auto & temp : shuffledObstacles)
{
auto handler = VLC->objtypeh->getHandlerFor(temp.id, temp.subid);
auto obj = handler->create(temp);

View File

@ -722,7 +722,7 @@ void TreasurePlacer::createTreasures(ObjectManager & manager)
if(areaToBlock.overlap(zone.freePaths()) || areaToBlock.overlap(manager.getVisitableArea()))
return -1.f;
return 1.f;
return ti.getNearestObjectDistance();
}, guarded, false, false);
}
else