• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 27551410928

15 Jun 2026 01:57PM UTC coverage: 50.354% (-0.4%) from 50.749%
27551410928

Pull #1947

github

web-flow
Merge 223793751 into f299328f2
Pull Request #1947: Replace `boost::optional` by `std::optional`

35 of 103 new or added lines in 52 files covered. (33.98%)

5 existing lines in 2 files now uncovered.

23178 of 46030 relevant lines covered (50.35%)

43858.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.96
/libs/s25main/Pathfinding.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "GamePlayer.h"
6
#include "helpers/EnumRange.h"
7
#include "pathfinding/FreePathFinder.h"
8
#include "pathfinding/FreePathFinderImpl.h"
9
#include "pathfinding/PathConditionHuman.h"
10
#include "pathfinding/PathConditionShip.h"
11
#include "pathfinding/PathConditionTrade.h"
12
#include "pathfinding/RoadPathFinder.h"
13
#include "world/GameWorld.h"
14
#include "gameTypes/ShipDirection.h"
15
#include "gameData/GameConsts.h"
16

17
/// Findet einen Weg für Figuren
18
helpers::OptionalEnum<Direction> GameWorldBase::FindHumanPath(const MapPoint start, const MapPoint dest,
5,441✔
19
                                                              const unsigned max_route, const bool random_route,
20
                                                              unsigned* length, std::vector<Direction>* route) const
21
{
22
    Direction first_dir{};
5,441✔
23
    if(GetFreePathFinder().FindPath(start, dest, random_route, max_route, route, length, &first_dir,
10,882✔
24
                                    PathConditionHuman(*this)))
10,882✔
25
        return first_dir;
4,737✔
26
    else
27
        return std::nullopt;
704✔
28
}
29

30
/// Wegfindung für Menschen im Straßennetz
31
RoadPathDirection GameWorld::FindHumanPathOnRoads(const noRoadNode& start, const noRoadNode& goal, unsigned* length,
282✔
32
                                                  MapPoint* firstPt, const RoadSegment* const forbidden)
33
{
34
    RoadPathDirection first_dir;
35
    if(GetRoadPathFinder().FindPath(start, goal, false, std::numeric_limits<unsigned>::max(), forbidden, length,
282✔
36
                                    &first_dir, firstPt))
37
        return first_dir;
281✔
38
    else
39
        return RoadPathDirection::None;
1✔
40
}
41

42
/// Wegfindung für Waren im Straßennetz
43
RoadPathDirection GameWorld::FindPathForWareOnRoads(const noRoadNode& start, const noRoadNode& goal, unsigned* length,
259✔
44
                                                    MapPoint* firstPt, unsigned max)
45
{
46
    RoadPathDirection first_dir;
47
    if(GetRoadPathFinder().FindPath(start, goal, true, max, nullptr, length, &first_dir, firstPt))
259✔
48
        return first_dir;
255✔
49
    else
50
        return RoadPathDirection::None;
4✔
51
}
52

53
bool GameWorldBase::FindShipPathToHarbor(const MapPoint start, HarborId harborId, SeaId seaId,
36✔
54
                                         std::vector<Direction>* route, unsigned* length)
55
{
56
    // Find the distance to the furthest harbor from the target harbor and take that as maximum
57
    unsigned maxDistance = 0;
36✔
58
    const MapPoint coastalPoint = GetCoastalPoint(harborId, seaId);
36✔
59

60
    // already arrived?
61
    if(start == coastalPoint)
36✔
62
    {
63
        if(length)
10✔
64
            *length = 0;
9✔
65
        if(route)
10✔
66
            route->clear();
10✔
67
        return true;
10✔
68
    }
69

70
    for(const auto dir : helpers::EnumRange<ShipDirection>{})
416✔
71
    {
72
        const std::vector<HarborPos::Neighbor>& neighbors = GetHarborNeighbors(harborId, dir);
156✔
73
        for(const HarborPos::Neighbor& neighbor : neighbors)
243✔
74
        {
75
            if(IsHarborAtSea(neighbor.id, seaId) && neighbor.distance > maxDistance)
87✔
76
                maxDistance = neighbor.distance;
51✔
77
        }
78
    }
79
    // Add a few fields reserve
80
    maxDistance += 6;
26✔
81
    return FindShipPath(start, coastalPoint, maxDistance, route, length);
26✔
82
}
83

84
bool GameWorldBase::FindShipPath(const MapPoint start, const MapPoint dest, unsigned maxDistance,
140✔
85
                                 std::vector<Direction>* route, unsigned* length)
86
{
87
    return GetFreePathFinder().FindPath(start, dest, true, maxDistance, route, length, nullptr,
280✔
88
                                        PathConditionShip(*this));
280✔
89
}
90

91
/// Prüft, ob eine Schiffsroute noch Gültigkeit hat
92
bool GameWorld::CheckShipRoute(const MapPoint start, const std::vector<Direction>& route, const unsigned pos,
391✔
93
                               MapPoint* dest)
94
{
95
    return GetFreePathFinder().CheckRoute(start, route, pos, PathConditionShip(*this), dest);
391✔
96
}
97

98
/// Find a route for trade caravanes
99
helpers::OptionalEnum<Direction> GameWorld::FindTradePath(const MapPoint start, const MapPoint dest,
36✔
100
                                                          unsigned char player, unsigned max_route, bool random_route,
101
                                                          std::vector<Direction>* route, unsigned* length) const
102
{
103
    unsigned char owner = GetNode(dest).owner;
36✔
104
    if(owner != 0 && !GetPlayer(player).IsAlly(owner - 1))
36✔
105
        return std::nullopt;
14✔
106

107
    RTTR_Assert(GetNO(dest)->GetType() == NodalObjectType::Flag); // Goal should be the flag of a wh
22✔
108

109
    if(!PathConditionHuman(*this).IsNodeOk(dest))
44✔
NEW
110
        return std::nullopt;
×
111

112
    Direction first_dir{};
22✔
113
    if(GetFreePathFinder().FindPath(start, dest, random_route, max_route, route, length, &first_dir,
44✔
114
                                    PathConditionTrade(*this, player)))
44✔
115
        return first_dir;
18✔
116
    else
117
        return std::nullopt;
4✔
118
}
119

120
bool GameWorld::CheckTradeRoute(const MapPoint start, const std::vector<Direction>& route, unsigned pos,
190✔
121
                                unsigned char player, MapPoint* dest) const
122
{
123
    return GetFreePathFinder().CheckRoute(start, route, pos, PathConditionTrade(*this, player), dest);
190✔
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc