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 c47be32b25
commit 967201a68e
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(); auto & guardedArea = obj.instances().back()->getAccessibleArea();
accessibleArea.intersect(guardedArea); accessibleArea.intersect(guardedArea);
accessibleArea.add(obj.instances().back()->getPosition(true));
} }
auto path = zone.searchPath(accessibleArea, onlyStraight, [&obj, isGuarded](const int3 & t) 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); auto & unguardedArea = obj.getAccessibleArea(isGuarded);
if(unguardedArea.contains(t) && !guardedArea.contains(t)) if(unguardedArea.contains(t) && !guardedArea.contains(t))
return false; return false;
//guard position is always target
if(obj.instances().back()->getPosition(true) == t)
return true;
} }
return !obj.getArea().contains(t); return !obj.getArea().contains(t);
}); });

View File

@ -88,7 +88,10 @@ void ObstaclePlacer::process()
if(!possibleObstacles[i].first) if(!possibleObstacles[i].first)
continue; 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 handler = VLC->objtypeh->getHandlerFor(temp.id, temp.subid);
auto obj = handler->create(temp); 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())) if(areaToBlock.overlap(zone.freePaths()) || areaToBlock.overlap(manager.getVisitableArea()))
return -1.f; return -1.f;
return 1.f; return ti.getNearestObjectDistance();
}, guarded, false, false); }, guarded, false, false);
} }
else else