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

Return-To-The-Roots / s25client / 15710993999

17 Jun 2025 03:05PM UTC coverage: 50.459% (+0.01%) from 50.448%
15710993999

Pull #1780

github

web-flow
Merge 745d4e607 into 819c9b82c
Pull Request #1780: Replace magic numbers with constants, unify spacing

0 of 124 new or added lines in 1 file covered. (0.0%)

13 existing lines in 2 files now uncovered.

22512 of 44614 relevant lines covered (50.46%)

35135.94 hits per line

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

96.97
/libs/s25main/mapGenerator/Rivers.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 "mapGenerator/Rivers.h"
6
#include "mapGenerator/Terrain.h"
7
#include "mapGenerator/TextureHelper.h"
8

9
namespace rttr::mapGenerator {
10

11
River CreateStream(RandomUtility& rnd, Map& map, const MapPoint& source, Direction direction, unsigned length,
34✔
12
                   unsigned splitRate)
13
{
14
    const MapExtent& size = map.size;
34✔
15

16
    River river;
34✔
17
    std::vector<Direction> exlcuded{direction + 2, direction + 3, direction + 4};
68✔
18

19
    auto& textures = map.textureMap;
34✔
20
    const auto water = textures.Find(IsWater);
34✔
21

22
    MapPoint currentNode = source;
34✔
23
    Direction currentDir = direction;
34✔
24

25
    for(unsigned node = 0; node < length; ++node)
428✔
26
    {
27
        const auto& triangles = GetTriangles(currentNode, size, currentDir);
403✔
28

29
        for(const auto& triangle : triangles)
1,209✔
30
        {
31
            textures.Set(triangle, water);
806✔
32

33
            const auto& edges = GetTriangleEdges(triangle, size);
806✔
34
            for(const MapPoint& edge : edges)
3,224✔
35
            {
36
                river.insert(edge);
2,418✔
37
            }
38
        }
39

40
        if(map.z[currentNode] == map.height.minimum)
403✔
41
        {
42
            return river;
9✔
43
        }
44

45
        const auto lastDir = currentDir;
394✔
46

47
        while(currentDir == lastDir || helpers::contains(exlcuded, currentDir))
993✔
48
        {
49
            currentDir = lastDir + (rnd.ByChance(50) ? 5 : 1);
599✔
50
        }
51

52
        currentNode = map.getTextures().GetNeighbour(currentNode, lastDir);
394✔
53

54
        if(rnd.ByChance(splitRate))
394✔
55
        {
56
            auto splitDirection = direction + (rnd.ByChance(50) ? 5 : 1);
2✔
57
            auto anotherRivers = CreateStream(rnd, map, currentNode, splitDirection, length / 2, splitRate / 2);
4✔
58

59
            for(const MapPoint& node : anotherRivers)
140✔
60
            {
61
                river.insert(node);
138✔
62
            }
63
        }
64
    }
65

66
    auto seaLevel = static_cast<unsigned>(map.height.minimum);
25✔
67
    auto& z = map.z;
25✔
68

69
    for(const MapPoint& node : river)
515✔
70
    {
71
        if(z[node] > 0)
490✔
72
        {
73
            z[node] = std::max(static_cast<unsigned>(z[node] - 1), seaLevel);
490✔
74
        } else
75
        {
UNCOV
76
            z[node] = seaLevel;
×
77
        }
78
    }
79

80
    return river;
25✔
81
}
82

83
} // namespace rttr::mapGenerator
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