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

Return-To-The-Roots / s25client / 21218532072

21 Jan 2026 05:04PM UTC coverage: 50.717% (+0.05%) from 50.663%
21218532072

Pull #1679

github

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

92 of 168 new or added lines in 12 files covered. (54.76%)

7 existing lines in 5 files now uncovered.

22788 of 44932 relevant lines covered (50.72%)

42042.91 hits per line

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

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

5
#include "CheatCommandTracker.h"
6
#include "Cheats.h"
7
#include "driver/KeyEvent.h"
8

9
namespace {
10
auto makeCircularBuffer(const std::string& str)
9✔
11
{
12
    return boost::circular_buffer<char>{cbegin(str), cend(str)};
9✔
13
}
14
const auto enableCheatsStr = makeCircularBuffer("winter");
15
} // namespace
16

17
CheatCommandTracker::CheatCommandTracker(Cheats& cheats) : cheats_(cheats), lastChars_(enableCheatsStr.size()) {}
11✔
18

19
void CheatCommandTracker::onKeyEvent(const KeyEvent& ke)
106✔
20
{
21
    if(!cheats_.areCheatsAllowed())
106✔
22
        return;
6✔
23

24
    if(checkSpeedKeyEvent(ke))
100✔
25
        lastChars_.clear();
1✔
26
    else if(ke.kt == KeyType::Char)
99✔
27
        onCharKeyEvent(ke);
98✔
28
    else
29
    {
30
        onSpecialKeyEvent(ke);
1✔
31
        lastChars_.clear();
1✔
32
    }
33
}
34

35
void CheatCommandTracker::onChatCommand(const std::string& cmd)
×
36
{
37
    if(!cheats_.areCheatsAllowed())
×
38
        return;
×
39

40
    if(cmd == "apocalypsis")
×
41
        cheats_.armageddon();
×
42
    else if(cmd == "impulse9")
×
43
        cheats_.toggleAllBuildingsEnabled();
×
44
    else if(cmd == "spies")
×
45
        cheats_.toggleShowEnemyProductivityOverlay();
×
46
}
47

48
void CheatCommandTracker::onSpecialKeyEvent(const KeyEvent& ke)
1✔
49
{
50
    if(ke.ctrl && ke.shift)
1✔
51
    {
NEW
52
        if(ke.kt >= KeyType::F1 && ke.kt <= KeyType::F8)
×
NEW
53
            cheats_.destroyBuildings({static_cast<unsigned>(ke.kt) - static_cast<unsigned>(KeyType::F1)});
×
NEW
54
        else if(ke.kt == KeyType::F9)
×
NEW
55
            cheats_.destroyAllAIBuildings();
×
56

NEW
57
        return;
×
58
    }
59

60
    switch(ke.kt)
1✔
61
    {
NEW
62
        case KeyType::F7:
×
63
        {
NEW
64
            if(ke.alt)
×
NEW
65
                cheats_.toggleResourceRevealMode();
×
66
            else
NEW
67
                cheats_.toggleAllVisible();
×
68
        }
NEW
69
        break;
×
70
        case KeyType::F10: cheats_.toggleHumanAIPlayer(); break;
1✔
71
        default: break;
×
72
    }
73
}
74

75
bool CheatCommandTracker::checkSpeedKeyEvent(const KeyEvent& ke)
100✔
76
{
77
    const char32_t c = ke.c;
100✔
78
    if(ke.alt && c >= '1' && c <= '6')
100✔
79
    {
80
        cheats_.setGameSpeed(c - '1');
1✔
81
        return true;
1✔
82
    }
83
    return false;
99✔
84
}
85

86
void CheatCommandTracker::onCharKeyEvent(const KeyEvent& ke)
98✔
87
{
88
    // Handle only ASCII chars
89
    if(ke.c > 0x7F)
98✔
90
        lastChars_.clear();
×
91
    else
92
    {
93
        lastChars_.push_back(static_cast<char>(ke.c));
98✔
94

95
        if(lastChars_ == enableCheatsStr)
98✔
96
            cheats_.toggleCheatMode();
6✔
97
    }
98
}
98✔
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