mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Merge pull request #2563 from vcmi/fix_resources_near_mines
Fix resources placed behind mines
This commit is contained in:
commit
f9564dc8e4
@ -413,23 +413,41 @@ bool ObjectManager::createRequiredObjects()
|
||||
|
||||
zone.connectPath(path);
|
||||
placeObject(rmgObject, guarded, true);
|
||||
|
||||
for(const auto & nearby : nearbyObjects)
|
||||
}
|
||||
|
||||
for(const auto & nearby : nearbyObjects)
|
||||
{
|
||||
auto * targetObject = nearby.nearbyTarget;
|
||||
if (!targetObject || !targetObject->appearance)
|
||||
{
|
||||
if(nearby.nearbyTarget != objInfo.obj)
|
||||
continue;
|
||||
|
||||
rmg::Object rmgNearObject(*nearby.obj);
|
||||
rmg::Area possibleArea(rmgObject.instances().front()->getBlockedArea().getBorderOutside());
|
||||
possibleArea.intersect(zone.areaPossible());
|
||||
if(possibleArea.empty())
|
||||
continue;
|
||||
}
|
||||
|
||||
rmg::Object rmgNearObject(*nearby.obj);
|
||||
rmg::Area possibleArea(rmg::Area(targetObject->getBlockedPos()).getBorderOutside());
|
||||
possibleArea.intersect(zone.areaPossible());
|
||||
if(possibleArea.empty())
|
||||
{
|
||||
rmgNearObject.clear();
|
||||
continue;
|
||||
}
|
||||
|
||||
rmgNearObject.setPosition(*RandomGeneratorUtil::nextItem(possibleArea.getTiles(), zone.getRand()));
|
||||
placeObject(rmgNearObject, false, false);
|
||||
auto path = zone.searchPath(rmgNearObject.getVisitablePosition(), false);
|
||||
if (path.valid())
|
||||
{
|
||||
zone.connectPath(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto* instance : rmgNearObject.instances())
|
||||
{
|
||||
rmgNearObject.clear();
|
||||
continue;
|
||||
logGlobal->error("Failed to connect nearby object %s at %s",
|
||||
instance->object().getObjectName(), instance->getPosition(true).toString());
|
||||
mapProxy->removeObject(&instance->object());
|
||||
}
|
||||
|
||||
rmgNearObject.setPosition(*RandomGeneratorUtil::nextItem(possibleArea.getTiles(), zone.getRand()));
|
||||
placeObject(rmgNearObject, false, false);
|
||||
rmgNearObject.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user