Skip to content

Commit 7ceb1d7

Browse files
committed
Add javadocs to cheat-related functions
1 parent 3d0ac3f commit 7ceb1d7

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

libs/s25main/CheatCommandTracker.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,41 @@ class CheatCommandTracker
1515
public:
1616
CheatCommandTracker(Cheats& cheats);
1717

18+
/** Tracks keyboard events related to cheats and triggers the actual cheats.
19+
* Calls related private methods of this class in order but returns at the first success (return true).
20+
*
21+
* @param ke - The keyboard event encountered.
22+
*/
1823
void trackKeyEvent(const KeyEvent& ke);
24+
25+
/** Tracks chat commands related to cheats and triggers the actual cheats.
26+
*
27+
* @param cmd - The chat command to track.
28+
*/
1929
void trackChatCommand(const std::string& cmd);
2030

2131
private:
32+
/** Tracks keyboard events related to cheats and triggers the actual cheats, but only tracks events of type
33+
* different than KeyType::Char (e.g. F-keys).
34+
*
35+
* @param ke - The keyboard event encountered.
36+
* @return true if keyboard event was NOT of type KeyType::Char, false otherwise
37+
*/
2238
bool trackSpecialKeyEvent(const KeyEvent& ke);
39+
40+
/** Tracks keyboard events related to game speed cheats (ALT+1..ALT+6) and triggers the actual cheats.
41+
*
42+
* @param ke - The keyboard event encountered.
43+
* @return true if keyboard event was related to game speed cheats, false otherwise
44+
*/
2345
bool trackSpeedKeyEvent(const KeyEvent& ke);
46+
47+
/** Tracks keyboard events related to cheats and triggers the actual cheats, but only tracks events of type
48+
* KeyType::Char (e.g. enabling cheat mode by typing "winter").
49+
*
50+
* @param ke - The keyboard event encountered.
51+
* @return always true
52+
*/
2453
bool trackCharKeyEvent(const KeyEvent& ke);
2554

2655
Cheats& cheats_;

libs/s25main/Cheats.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,71 @@ class Cheats
2020
Cheats(GameWorldBase& world);
2121
~Cheats(); // = default - for unique_ptr
2222

23+
/** In single player games, tracks keyboard events related to cheats.
24+
* Delegates this responsibility to CheatCommandTracker, which triggers the actual cheats.
25+
* In multiplayer games, does nothing. No cheats can be triggered in multiplayer.
26+
*
27+
* @param ke - The keyboard event encountered.
28+
*/
2329
void trackKeyEvent(const KeyEvent& ke);
30+
31+
/** In single player games, tracks chat commands related to cheats.
32+
* Delegates this responsibility to CheatCommandTracker, which triggers the actual cheats.
33+
* In multiplayer games, does nothing. No cheats can be triggered in multiplayer.
34+
*
35+
* @param cmd - The chat command to track.
36+
*/
2437
void trackChatCommand(const std::string& cmd);
2538

39+
/** Toggles cheat mode on and off.
40+
* Cheat mode needs to be on for any cheats to trigger.
41+
*/
2642
void toggleCheatMode();
43+
/** Used by clients to check if cheat mode is on (e.g. to draw special sprites or enable or all buildings).
44+
* Cheat mode needs to be on for any cheats to trigger.
45+
*
46+
* @return true if cheat mode is on, false otherwise
47+
*/
2748
bool isCheatModeOn() const { return isCheatModeOn_; }
2849

2950
// Classic S2 cheats
51+
52+
/** The classic F7 cheat.
53+
* Does not modify game state, merely tricks clients into revealing the whole map.
54+
* In the background, visibility is tracked as expected, i.e. if you reveal the map, send a scout and unreveal the
55+
* map, you will see what was scouted.
56+
*/
3057
void toggleAllVisible();
3158
bool isAllVisible() const { return isAllVisible_; }
3259

60+
/** The classic build headquarters cheat.
61+
* This function is used to check if the cheat building can be placed at the chosen point when opening the activity
62+
* window.
63+
*
64+
* @param mp - The map point where the user clicked to open the activity window.
65+
* @return true if the building can be placed, false otherwise
66+
*/
3367
bool canPlaceCheatBuilding(const MapPoint& mp) const;
68+
/** The classic build headquarters cheat.
69+
* This function is used to place the cheat building at the chosen point.
70+
* The building is immediately fully built, there is no need for a building site.
71+
*
72+
* @param mp - The map point at which to place the building.
73+
* @param player - The player to whom the building should belong.
74+
*/
3475
void placeCheatBuilding(const MapPoint& mp, const GamePlayer& player);
3576

77+
/** The classic ALT+1 through ALT+6 cheat which changes the game speed.
78+
*
79+
* @param speedIndex - 0 is normal, 1 is faster, 2 is even faster, etc.
80+
*/
3681
void setGameSpeed(uint8_t speedIndex);
3782

3883
// RTTR cheats
84+
85+
/** Shares control of the (human) user's country with the AI. Both the user and the AI retain full control of the
86+
* country, so the user can observe what the AI does or "cooperate" with it.
87+
*/
3988
void toggleHumanAIPlayer();
4089

4190
void armageddon();
@@ -47,14 +96,30 @@ class Cheats
4796
Fish,
4897
Water
4998
};
99+
/** Tells clients which resources to reveal:
100+
* Nothing - reveal nothing
101+
* Ores - reveal ores
102+
* Fish - reveal ores and fish
103+
* Water - reveal ores, fish and water
104+
*/
50105
ResourceRevealMode getResourceRevealMode() const;
51106
void toggleResourceRevealMode();
52107

53108
using PlayerIDSet = std::unordered_set<unsigned>;
109+
/** Destroys all buildings of given players, effectively defeating them.
110+
*
111+
* @param playerIds - Set of IDs of players.
112+
*/
54113
void destroyBuildings(const PlayerIDSet& playerIds);
114+
/** Destroys all buildings of AI players.
115+
*/
55116
void destroyAllAIBuildings();
56117

57118
private:
119+
/** Checks if cheats can be turned on at all.
120+
*
121+
* @return true if if cheats can be turned on, false otherwise
122+
*/
58123
bool canCheatModeBeOn() const;
59124

60125
std::unique_ptr<CheatCommandTracker> cheatCmdTracker_;

libs/s25main/world/GameWorldBase.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ class GameWorldBase : public World
9696
bool IsOnRoad(const MapPoint& pt) const;
9797
/// Check if a flag is at a neighbour node
9898
bool IsFlagAround(const MapPoint& pt) const;
99+
100+
/** Checks if any of the neighboring nodes of a given map point are owned by any player.
101+
*
102+
* @param pt - The map point whose neighbors should be checked.
103+
* @return true if any neighbor has an owner, false otherwise
104+
*/
99105
bool IsAnyNeighborOwned(const MapPoint& pt) const;
106+
100107
/// Berechnet BQ bei einer gebauten Stra�e
101108
void RecalcBQForRoad(MapPoint pt);
102109
/// Pr�ft, ob sich in unmittelbarer N�he (im Radius von 4) Milit�rgeb�ude befinden

0 commit comments

Comments
 (0)