mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Satisfy SonarCloud
This commit is contained in:
parent
ee27a79aa1
commit
5a979e42e2
@ -73,9 +73,7 @@ bool RoadPlacer::createRoad(const int3 & destination)
|
||||
rmg::Path path(searchArea);
|
||||
path.connect(roads);
|
||||
|
||||
const float VISITABLE_PENALTY = 1.33f;
|
||||
|
||||
auto simpleRoutig = [this, &border, &VISITABLE_PENALTY](const int3& src, const int3& dst)
|
||||
auto simpleRoutig = [this, &border](const int3& src, const int3& dst)
|
||||
{
|
||||
if(areaIsolated().contains(dst))
|
||||
{
|
||||
@ -101,36 +99,8 @@ bool RoadPlacer::createRoad(const int3 & destination)
|
||||
auto res = path.search(destination, true, simpleRoutig);
|
||||
if(!res.valid())
|
||||
{
|
||||
auto desperateRoutig = [this, &VISITABLE_PENALTY](const int3& src, const int3& dst) -> float
|
||||
{
|
||||
//Do not allow connections straight up through object not visitable from top
|
||||
if(std::abs((src - dst).y) == 1)
|
||||
{
|
||||
if(areaIsolated().contains(dst) || areaIsolated().contains(src))
|
||||
{
|
||||
return 1e12;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(areaIsolated().contains(dst))
|
||||
{
|
||||
return 1e6;
|
||||
}
|
||||
}
|
||||
|
||||
float weight = dst.dist2dSQ(src);
|
||||
auto ret = weight * weight; // Still prefer straight paths
|
||||
|
||||
if (visitableTiles.contains(src) || visitableTiles.contains(dst))
|
||||
{
|
||||
ret *= VISITABLE_PENALTY;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
res = path.search(destination, false, desperateRoutig);
|
||||
|
||||
if(!res.valid())
|
||||
res = createRoadDesperate(path, destination);
|
||||
if (!res.valid())
|
||||
{
|
||||
logGlobal->warn("Failed to create road to node %s", destination.toString());
|
||||
return false;
|
||||
@ -141,6 +111,38 @@ bool RoadPlacer::createRoad(const int3 & destination)
|
||||
|
||||
}
|
||||
|
||||
rmg::Path RoadPlacer::createRoadDesperate(rmg::Path & path, const int3 & destination)
|
||||
{
|
||||
auto desperateRoutig = [this](const int3& src, const int3& dst) -> float
|
||||
{
|
||||
//Do not allow connections straight up through object not visitable from top
|
||||
if(std::abs((src - dst).y) == 1)
|
||||
{
|
||||
if(areaIsolated().contains(dst) || areaIsolated().contains(src))
|
||||
{
|
||||
return 1e12;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(areaIsolated().contains(dst))
|
||||
{
|
||||
return 1e6;
|
||||
}
|
||||
}
|
||||
|
||||
float weight = dst.dist2dSQ(src);
|
||||
auto ret = weight * weight; // Still prefer straight paths
|
||||
|
||||
if (visitableTiles.contains(src) || visitableTiles.contains(dst))
|
||||
{
|
||||
ret *= VISITABLE_PENALTY;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
return path.search(destination, false, desperateRoutig);
|
||||
}
|
||||
|
||||
void RoadPlacer::drawRoads(bool secondary)
|
||||
{
|
||||
//Do not draw roads on underground rock or water
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
const float VISITABLE_PENALTY = 1.33f;
|
||||
|
||||
class RoadPlacer: public Modificator
|
||||
{
|
||||
public:
|
||||
@ -34,6 +36,7 @@ public:
|
||||
|
||||
protected:
|
||||
bool createRoad(const int3 & dst);
|
||||
rmg::Path createRoadDesperate(rmg::Path & path, const int3 & destination);
|
||||
void drawRoads(bool secondary = false); //actually updates tiles
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user