Skip to content

Commit e59dcfb

Browse files
committed
Address frontier distance review comments
1 parent 5b07479 commit e59dcfb

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

libs/s25main/pathfinding/FindPathReachable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace {
1212

13+
// Keep this narrower than PathConditionHuman, but reject permanently blocking static objects:
14+
// Human pathing can never accept them and they cannot be removed.
1315
struct PathConditionReachableWithStaticBlockers : PathConditionReachable
1416
{
1517
PathConditionReachableWithStaticBlockers(const World& world) : PathConditionReachable(world) {}

tests/s25Main/integration/testFrontierDistance.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

55
#include "GamePlayer.h"
6+
#include "RttrForeachPt.h"
67
#include "buildings/nobMilitary.h"
78
#include "factories/BuildingFactory.h"
89
#include "helpers/Range.h"
@@ -359,23 +360,19 @@ BOOST_FIXTURE_TEST_CASE(FrontierDistanceReachabilityConsidersStaticObjectBlocker
359360
const MapPoint endPt(10, corridorY);
360361
constexpr unsigned maxPathLen = 8;
361362

362-
for(const auto y : helpers::range(0, +world.GetHeight()))
363+
RTTR_FOREACH_PT(MapPoint, world.GetSize())
363364
{
364-
for(const auto x : helpers::range(0, +world.GetWidth()))
365-
{
366-
const MapPoint pt(x, y);
367-
if(pt.y == corridorY && pt.x >= startPt.x && pt.x <= endPt.x)
368-
continue;
365+
if(pt.y == corridorY && pt.x >= startPt.x && pt.x <= endPt.x)
366+
continue;
369367

370-
MapNode& node = world.GetNodeWriteable(pt);
371-
node.t1 = tWater;
372-
node.t2 = tWater;
373-
}
368+
MapNode& node = world.GetNodeWriteable(pt);
369+
node.t1 = tWater;
370+
node.t2 = tWater;
374371
}
375372

376373
BOOST_TEST_REQUIRE(DoesReachablePathExist(world, startPt, endPt, maxPathLen));
377374

378-
for(unsigned x = startPt.x + 1; x < endPt.x; ++x)
375+
for(const unsigned x : helpers::range<MapCoord>(startPt.x + 1, endPt.x))
379376
{
380377
const MapPoint passablePt(x, corridorY);
381378
world.DestroyNO(passablePt, false);
@@ -384,7 +381,7 @@ BOOST_FIXTURE_TEST_CASE(FrontierDistanceReachabilityConsidersStaticObjectBlocker
384381

385382
BOOST_TEST_REQUIRE(DoesReachablePathExist(world, startPt, endPt, maxPathLen));
386383

387-
for(unsigned x = startPt.x + 1; x < endPt.x; ++x)
384+
for(const unsigned x : helpers::range<MapCoord>(startPt.x + 1, endPt.x))
388385
{
389386
const MapPoint passablePt(x, corridorY);
390387
world.DestroyNO(passablePt, false);
@@ -393,7 +390,7 @@ BOOST_FIXTURE_TEST_CASE(FrontierDistanceReachabilityConsidersStaticObjectBlocker
393390

394391
BOOST_TEST_REQUIRE(DoesReachablePathExist(world, startPt, endPt, maxPathLen));
395392

396-
for(unsigned x = startPt.x + 1; x < endPt.x; ++x)
393+
for(const unsigned x : helpers::range<MapCoord>(startPt.x + 1, endPt.x))
397394
{
398395
const MapPoint blockerPt(x, corridorY);
399396
world.DestroyNO(blockerPt, false);

0 commit comments

Comments
 (0)