|
3 | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
4 | 4 |
|
5 | 5 | #include "Cheats.h" |
6 | | -#include "CheatCommandTracker.h" |
7 | 6 | #include "network/GameClient.h" |
8 | 7 | #include "world/GameWorldBase.h" |
9 | 8 |
|
10 | | -Cheats::Cheats(GameWorldBase& world) : cheatCmdTracker_(std::make_unique<CheatCommandTracker>(*this)), world_(world) {} |
| 9 | +Cheats::Cheats(GameWorldBase& world) : cheatCmdTracker_(*this), world_(world) {} |
11 | 10 |
|
12 | 11 | Cheats::~Cheats() = default; |
13 | 12 |
|
14 | 13 | void Cheats::trackKeyEvent(const KeyEvent& ke) |
15 | 14 | { |
16 | | - if(!canCheatModeBeOn()) |
17 | | - return; |
18 | | - |
19 | | - cheatCmdTracker_->trackKeyEvent(ke); |
| 15 | + if(areCheatsAllowed()) |
| 16 | + cheatCmdTracker_.trackKeyEvent(ke); |
20 | 17 | } |
21 | 18 |
|
22 | 19 | void Cheats::trackChatCommand(const std::string& cmd) |
23 | 20 | { |
24 | | - if(!canCheatModeBeOn()) |
25 | | - return; |
26 | | - |
27 | | - cheatCmdTracker_->trackChatCommand(cmd); |
| 21 | + if(areCheatsAllowed()) |
| 22 | + cheatCmdTracker_.trackChatCommand(cmd); |
28 | 23 | } |
29 | 24 |
|
30 | 25 | void Cheats::toggleCheatMode() |
31 | 26 | { |
32 | | - if(!canCheatModeBeOn()) |
33 | | - return; |
34 | | - |
35 | | - isCheatModeOn_ = !isCheatModeOn_; |
| 27 | + if(areCheatsAllowed()) |
| 28 | + isCheatModeOn_ = !isCheatModeOn_; |
36 | 29 | } |
37 | 30 |
|
38 | 31 | void Cheats::toggleHumanAIPlayer() |
39 | 32 | { |
40 | | - if(!isCheatModeOn()) |
41 | | - return; |
42 | | - |
43 | | - if(GAMECLIENT.IsReplayModeOn()) |
44 | | - return; |
45 | | - |
46 | | - GAMECLIENT.ToggleHumanAIPlayer(AI::Info{AI::Type::Default, AI::Level::Easy}); |
| 33 | + if(isCheatModeOn() && !GAMECLIENT.IsReplayModeOn()) |
| 34 | + GAMECLIENT.ToggleHumanAIPlayer(AI::Info{AI::Type::Default, AI::Level::Easy}); |
47 | 35 | } |
48 | 36 |
|
49 | 37 | void Cheats::armageddon() |
50 | 38 | { |
51 | | - if(!isCheatModeOn()) |
52 | | - return; |
53 | | - |
54 | | - GAMECLIENT.CheatArmageddon(); |
| 39 | + if(isCheatModeOn()) |
| 40 | + GAMECLIENT.CheatArmageddon(); |
55 | 41 | } |
56 | 42 |
|
57 | | -bool Cheats::canCheatModeBeOn() const |
| 43 | +bool Cheats::areCheatsAllowed() const |
58 | 44 | { |
59 | 45 | return world_.IsSinglePlayer(); |
60 | 46 | } |
0 commit comments