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

Return-To-The-Roots / s25client / 26253516618

21 May 2026 09:14PM UTC coverage: 50.373% (+0.08%) from 50.29%
26253516618

Pull #1925

github

web-flow
Merge 70b841fe8 into 64b706b67
Pull Request #1925: Ignore isolated fish resources for fisheries

36 of 63 new or added lines in 4 files covered. (57.14%)

5 existing lines in 2 files now uncovered.

23185 of 46027 relevant lines covered (50.37%)

44209.73 hits per line

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

90.79
/libs/s25main/Cheats.cpp
1
// Copyright (C) 2024 - 2026 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "Cheats.h"
6
#include "GameInterface.h"
7
#include "GamePlayer.h"
8
#include "RttrForeachPt.h"
9
#include "buildings/nobHQ.h"
10
#include "factories/BuildingFactory.h"
11
#include "factories/GameCommandFactory.h"
12
#include "network/GameClient.h"
13
#include "world/GameWorldBase.h"
14

15
Cheats::Cheats(GameWorldBase& world, GameCommandFactory& gcFactory) : world_(world), gcFactory_(gcFactory) {}
33✔
16

17
bool Cheats::areCheatsAllowed() const
130✔
18
{
19
    return world_.IsSinglePlayer();
130✔
20
}
21

22
void Cheats::toggleCheatMode()
32✔
23
{
24
    // In S2, if you enabled cheat mode, revealed the map and disabled cheat mode, the map would remain revealed and you
25
    // would be unable to unreveal the map.
26
    // In RTTR, disabling cheat mode turns all cheats off and they have to be turned on again manually.
27
    if(isCheatModeOn_)
32✔
28
        turnAllCheatsOff();
7✔
29

30
    isCheatModeOn_ = !isCheatModeOn_;
32✔
31
}
32✔
32

33
void Cheats::toggleAllVisible()
10✔
34
{
35
    if(isCheatModeOn())
10✔
36
    {
37
        isAllVisible_ = !isAllVisible_;
7✔
38

39
        // In S2, the minimap is not updated immediately.
40
        // In RTTR, the minimap would become messed up if it wasn't updated here.
41
        if(GameInterface* gi = world_.GetGameInterface())
7✔
42
            gi->GI_UpdateMapVisibility();
3✔
43
    }
44
}
10✔
45

46
void Cheats::toggleAllBuildingsEnabled()
12✔
47
{
48
    // In S2, if you enabled cheats you would automatically have all buildings enabled.
49
    // In RTTR, because this may have unintended consequences when playing campaigns, the user must explicitly enable
50
    // all buildings after enabling cheats.
51
    if(isCheatModeOn())
12✔
52
        areAllBuildingsEnabled_ = !areAllBuildingsEnabled_;
10✔
53
}
12✔
54

55
void Cheats::toggleShowEnemyProductivityOverlay()
8✔
56
{
57
    // In S2, if you enabled cheats you would automatically see the enemy productivity overlay - most importantly what
58
    // buildings the enemy intends to build.
59
    // In RTTR, the user must explicitly enable this feature after enabling cheats.
60
    if(isCheatModeOn())
8✔
61
        shouldShowEnemyProductivityOverlay_ = !shouldShowEnemyProductivityOverlay_;
6✔
62
}
8✔
63

64
bool Cheats::canPlaceCheatBuilding(const MapPoint& mp) const
14✔
65
{
66
    if(!isCheatModeOn())
14✔
67
        return false;
3✔
68

69
    // It seems that in the original game you can only build headquarters in unoccupied territory at least 2 nodes
70
    // away from any border markers and that it doesn't need more bq than a hut.
71
    const MapNode& node = world_.GetNode(mp);
11✔
72
    return !node.owner && !world_.IsAnyNeighborOwned(mp) && node.bq >= BuildingQuality::Hut;
11✔
73
}
74

75
void Cheats::placeCheatBuilding(const MapPoint& mp, const GamePlayer& player)
7✔
76
{
77
    if(!canPlaceCheatBuilding(mp))
7✔
78
        return;
1✔
79

80
    world_.DestroyNO(mp, false); // if CanPlaceCheatBuilding is true then this must be safe to destroy
6✔
81
    auto* hq =
82
      BuildingFactory::CreateBuilding(world_, BuildingType::Headquarters, mp, player.GetPlayerId(), player.nation);
6✔
83
    checkedCast<nobHQ*>(hq)->SetIsTent(player.IsHQTent());
6✔
84
}
85

UNCOV
86
void Cheats::toggleHumanAIPlayer()
×
87
{
UNCOV
88
    if(isCheatModeOn() && !GAMECLIENT.IsReplayModeOn())
×
89
    {
90
        GAMECLIENT.ToggleHumanAIPlayer(AI::Info{AI::Type::Default, AI::Level::Easy});
×
91
        isHumanAIPlayer_ = !isHumanAIPlayer_;
×
92
    }
UNCOV
93
}
×
94

95
void Cheats::armageddon()
2✔
96
{
97
    if(isCheatModeOn())
2✔
98
        gcFactory_.CheatArmageddon();
1✔
99
}
2✔
100

101
Cheats::ResourceRevealMode Cheats::getResourceRevealMode() const
11✔
102
{
103
    return isCheatModeOn() ? resourceRevealMode_ : ResourceRevealMode::Nothing;
11✔
104
}
105

106
void Cheats::toggleResourceRevealMode()
8✔
107
{
108
    switch(resourceRevealMode_)
8✔
109
    {
110
        case ResourceRevealMode::Nothing: resourceRevealMode_ = ResourceRevealMode::Ores; break;
3✔
111
        case ResourceRevealMode::Ores: resourceRevealMode_ = ResourceRevealMode::Fish; break;
3✔
112
        case ResourceRevealMode::Fish: resourceRevealMode_ = ResourceRevealMode::Water; break;
1✔
113
        default: resourceRevealMode_ = ResourceRevealMode::Nothing; break;
1✔
114
    }
115
}
8✔
116

117
void Cheats::destroyBuildings(const PlayerIDSet& playerIds)
6✔
118
{
119
    if(!isCheatModeOn())
6✔
120
        return;
1✔
121

122
    RTTR_FOREACH_PT(MapPoint, world_.GetSize())
15,109✔
123
    {
124
        if(world_.GetNO(pt)->GetType() == NodalObjectType::Building && playerIds.count(world_.GetNode(pt).owner - 1))
14,848✔
125
            world_.DestroyNO(pt);
8✔
126
    }
127
}
128

129
void Cheats::destroyAllAIBuildings()
3✔
130
{
131
    if(!isCheatModeOn())
3✔
132
        return;
1✔
133

134
    PlayerIDSet ais;
4✔
135
    for(auto i = 0u; i < world_.GetNumPlayers(); ++i)
9✔
136
    {
137
        if(!world_.GetPlayer(i).isHuman())
7✔
138
            ais.insert(i);
5✔
139
    }
140
    destroyBuildings(ais);
2✔
141
}
142

143
void Cheats::turnAllCheatsOff()
7✔
144
{
145
    if(isAllVisible_)
7✔
146
        toggleAllVisible();
1✔
147
    if(areAllBuildingsEnabled_)
7✔
148
        toggleAllBuildingsEnabled();
2✔
149
    if(shouldShowEnemyProductivityOverlay_)
7✔
150
        toggleShowEnemyProductivityOverlay();
1✔
151
    if(isHumanAIPlayer_)
7✔
152
    {
153
        toggleHumanAIPlayer();
×
154
        isHumanAIPlayer_ = false;
×
155
    }
156
}
7✔
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