Skip to content

Commit 4cee71b

Browse files
committed
Don't look for ship path when the start and goal are the same.
There is no meaningful result for all out-parameters in the base pathfinding implementation.
1 parent 3d707b9 commit 4cee71b

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

external/turtle

libs/s25main/figures/nofCarrier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,14 @@ void nofCarrier::LostWork()
630630

631631
// Look for the shore
632632
const unsigned maxNodeDistance = 5;
633-
std::vector<MapPoint> coastPoints =
633+
const auto coastPoints =
634634
world->GetMatchingPointsInRadius(tmpPos, maxNodeDistance, IsCoastalAndForFigs(*world));
635+
shore_path.clear();
635636
for(const auto& it : coastPoints)
636637
{
637638
// 10x the node distance should be enough, otherwise it would be to far to paddle
638639
const unsigned maxDistance = maxNodeDistance * 10;
639-
if(world->FindShipPath(tmpPos, it, maxDistance, &shore_path, nullptr))
640+
if(it == tmpPos || world->FindShipPath(tmpPos, it, maxDistance, &shore_path, nullptr))
640641
{
641642
// Ok let's paddle to the coast
642643
rs_pos = 0;

libs/s25main/pathfinding/ShipPathData.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ void ShipPathData::initHarborConnections()
8484
// Connections are unique
8585
RTTR_Assert(!helpers::contains_if(curConnections, HarborConnection::Matcher{nb.id, nb.sea}));
8686
curConnections.push_back(HarborConnection{nb.id, nb.sea, {}});
87-
unsigned len;
87+
unsigned len = 0;
88+
const auto startPoint = world_.GetCoastalPoint(startHbId, nb.sea);
89+
const auto nbPoint = world_.GetCoastalPoint(nb.id, nb.sea);
8890
const bool found =
89-
world_.FindShipPath(world_.GetCoastalPoint(startHbId, nb.sea), world_.GetCoastalPoint(nb.id, nb.sea),
90-
nb.distance, &curConnections.back().route, &len);
91+
(startPoint == nbPoint)
92+
|| world_.FindShipPath(startPoint, nbPoint, nb.distance, &curConnections.back().route, &len);
9193
RTTR_Assert(found);
9294
RTTR_Assert(len == nb.distance);
9395
}

libs/s25main/world/MapSerializer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,14 @@ void MapSerializer::Deserialize(GameWorldBase& world, SerializedGameData& sgd, G
200200
{
201201
if(!helpers::contains(otherSeas, sea))
202202
continue;
203-
unsigned len;
203+
unsigned len = 0;
204+
const auto startPoint = world.GetCoastalPoint(startHbId, sea);
205+
const auto nbPoint = world.GetCoastalPoint(neighbor.id, sea);
206+
if(neighbor.distance == 0 && startPoint == nbPoint)
207+
{
208+
neighbor.sea = sea;
209+
break;
210+
}
204211
if(world.FindShipPath(world.GetCoastalPoint(startHbId, sea),
205212
world.GetCoastalPoint(neighbor.id, sea), neighbor.distance, nullptr, &len)
206213
&& len == neighbor.distance)

0 commit comments

Comments
 (0)