1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

First attempt to enforce curved paths

This commit is contained in:
Tomasz Zieliński
2024-11-21 22:00:24 +01:00
parent 03273ed324
commit 855ab0f0e9
5 changed files with 55 additions and 11 deletions

View File

@ -419,6 +419,11 @@ bool ObjectManager::createMonoliths()
return false;
}
// Once it can be created, replace with curved path
auto costFunction = rmg::Path::createCurvedCostFunction(zone.area()->getBorder());
rmg::Path curvedPath(zone.areaPossible() + zone.freePaths());
path = curvedPath.search(rmgObject.getVisitablePosition(), true, costFunction);
zone.connectPath(path);
placeObject(rmgObject, guarded, true, objInfo.createRoad);
}
@ -449,6 +454,24 @@ bool ObjectManager::createRequiredObjects()
logGlobal->error("Failed to fill zone %d due to lack of space", zone.getId());
return false;
}
if (objInfo.createRoad)
{
// Once valid path can be created, replace with curved path
auto costFunction = rmg::Path::createCurvedCostFunction(zone.area()->getBorder());
auto pathArea = zone.areaPossible() + zone.freePaths();
rmg::Path curvedPath(pathArea);
curvedPath.connect(zone.freePaths().get());
curvedPath = curvedPath.search(rmgObject.getVisitablePosition(), false, costFunction);
if (curvedPath.valid())
{
path = curvedPath;
}
else
{
logGlobal->warn("Failed to create curved path for required object at %s", rmgObject.getPosition().toString());
}
}
zone.connectPath(path);
placeObject(rmgObject, guarded, true, objInfo.createRoad);