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

Return-To-The-Roots / s25client / 21283273387

23 Jan 2026 10:39AM UTC coverage: 50.757% (+0.09%) from 50.663%
21283273387

Pull #1679

github

web-flow
Merge c392aa0ea into 12da8bf44
Pull Request #1679: Add all classic S2 cheats and a few more

94 of 155 new or added lines in 12 files covered. (60.65%)

7 existing lines in 5 files now uncovered.

22798 of 44916 relevant lines covered (50.76%)

41539.59 hits per line

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

94.74
/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
129✔
18
{
19
    return world_.IsSinglePlayer();
129✔
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
    // The new HQ will have default resources.
81
    // In the original game, new HQs created in the Roman campaign had no resources.
82
    world_.DestroyNO(mp, false); // if CanPlaceCheatBuilding is true then this must be safe to destroy
6✔
83
    auto* hq =
84
      BuildingFactory::CreateBuilding(world_, BuildingType::Headquarters, mp, player.GetPlayerId(), player.nation);
6✔
85
    static_cast<nobHQ*>(hq)->SetIsTent(player.IsHQTent());
6✔
86
}
87

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

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

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

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

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

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

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

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

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