diff --git a/libs/s25main/CheatCommandTracker.cpp b/libs/s25main/CheatCommandTracker.cpp index f1b4e1ace..e6983aa55 100644 --- a/libs/s25main/CheatCommandTracker.cpp +++ b/libs/s25main/CheatCommandTracker.cpp @@ -36,6 +36,8 @@ void CheatCommandTracker::onChatCommand(const std::string& cmd) cheats_.armageddon(); else if(cmd == "impulse9") cheats_.toggleAllBuildingsEnabled(); + else if(cmd == "spies") + cheats_.toggleShowEnemyProductivityOverlay(); } bool CheatCommandTracker::checkSpecialKeyEvent(const KeyEvent& ke) diff --git a/libs/s25main/Cheats.cpp b/libs/s25main/Cheats.cpp index fedd5cf7e..2cfc3ee0f 100644 --- a/libs/s25main/Cheats.cpp +++ b/libs/s25main/Cheats.cpp @@ -47,6 +47,15 @@ void Cheats::toggleAllBuildingsEnabled() areAllBuildingsEnabled_ = !areAllBuildingsEnabled_; } +void Cheats::toggleShowEnemyProductivityOverlay() +{ + // In S2, if you enabled cheats you would automatically see the enemy productivity overlay - most importantly what + // buildings the enemy intends to build. + // In RTTR, the user must explicitly enable this feature after enabling cheats. + if(isCheatModeOn()) + shouldShowEnemyProductivityOverlay_ = !shouldShowEnemyProductivityOverlay_; +} + void Cheats::toggleHumanAIPlayer() { if(isCheatModeOn() && !GAMECLIENT.IsReplayModeOn()) @@ -68,6 +77,8 @@ void Cheats::turnAllCheatsOff() toggleAllVisible(); if(areAllBuildingsEnabled_) toggleAllBuildingsEnabled(); + if(shouldShowEnemyProductivityOverlay_) + toggleShowEnemyProductivityOverlay(); if(isHumanAIPlayer_) toggleHumanAIPlayer(); } diff --git a/libs/s25main/Cheats.h b/libs/s25main/Cheats.h index a850e892d..f88a058b0 100644 --- a/libs/s25main/Cheats.h +++ b/libs/s25main/Cheats.h @@ -23,6 +23,9 @@ class Cheats void toggleAllBuildingsEnabled(); bool areAllBuildingsEnabled() const { return areAllBuildingsEnabled_; } + void toggleShowEnemyProductivityOverlay(); + bool shouldShowEnemyProductivityOverlay() const { return shouldShowEnemyProductivityOverlay_; } + // RTTR cheats void toggleHumanAIPlayer(); void armageddon() const; @@ -33,6 +36,7 @@ class Cheats bool isCheatModeOn_ = false; bool isAllVisible_ = false; bool areAllBuildingsEnabled_ = false; + bool shouldShowEnemyProductivityOverlay_ = false; bool isHumanAIPlayer_ = false; GameWorldBase& world_; }; diff --git a/libs/s25main/world/GameWorldView.cpp b/libs/s25main/world/GameWorldView.cpp index 5907cc91f..802162891 100644 --- a/libs/s25main/world/GameWorldView.cpp +++ b/libs/s25main/world/GameWorldView.cpp @@ -4,7 +4,9 @@ #include "world/GameWorldView.h" #include "CatapultStone.h" +#include "Cheats.h" #include "FOWObjects.h" +#include "GameInterface.h" #include "GamePlayer.h" #include "GlobalGameSettings.h" #include "Loader.h" @@ -370,7 +372,10 @@ void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRe auto* attackAidImage = LOADER.GetImageN("map_new", 20000); attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight())); } - continue; + // Do not draw enemy productivity overlay unless the object is visible AND the related cheat is on + if(!(gwv.GetVisibility(pt) == Visibility::Visible + && GetWorld().GetGameInterface()->GI_GetCheats().shouldShowEnemyProductivityOverlay())) + continue; } // Draw object name diff --git a/tests/s25Main/integration/testCheats.cpp b/tests/s25Main/integration/testCheats.cpp index 284b8276f..97997bc63 100644 --- a/tests/s25Main/integration/testCheats.cpp +++ b/tests/s25Main/integration/testCheats.cpp @@ -48,12 +48,16 @@ BOOST_FIXTURE_TEST_CASE(TurningCheatModeOffDisablesAllCheats, CheatsFixture) { cheats.toggleCheatMode(); cheats.toggleAllVisible(); - BOOST_TEST_REQUIRE(cheats.isAllVisible() == true); cheats.toggleAllBuildingsEnabled(); + cheats.toggleShowEnemyProductivityOverlay(); + BOOST_TEST_REQUIRE(cheats.isAllVisible() == true); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == true); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == true); + cheats.toggleCheatMode(); BOOST_TEST_REQUIRE(cheats.isAllVisible() == false); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == false); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == false); // testing toggleHumanAIPlayer would require GameClient::state==Loaded, which is guaranteed in code (because Cheats // only exist after the game is loaded) but is not the case in tests - skipping } @@ -107,18 +111,31 @@ BOOST_FIXTURE_TEST_CASE(CanToggleAllVisible_IfCheatModeIsOn, CheatsFixture) BOOST_TEST_REQUIRE((viewer.GetVisibility(farawayPos) == Visibility::Visible) == true); } -BOOST_FIXTURE_TEST_CASE(CanToggleAllBuildingsEnabled_IfCheatModeIsOn, CheatsFixture) +BOOST_FIXTURE_TEST_CASE(CanToggleAllBuildingsEnabled_AndShowEnemyProductivityOverlay_IfCheatModeIsOn, CheatsFixture) { BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == false); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == false); + cheats.toggleAllBuildingsEnabled(); + cheats.toggleShowEnemyProductivityOverlay(); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == false); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == false); + cheats.toggleCheatMode(); cheats.toggleAllBuildingsEnabled(); + cheats.toggleShowEnemyProductivityOverlay(); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == true); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == true); + cheats.toggleAllBuildingsEnabled(); + cheats.toggleShowEnemyProductivityOverlay(); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == false); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == false); + cheats.toggleAllBuildingsEnabled(); + cheats.toggleShowEnemyProductivityOverlay(); BOOST_TEST_REQUIRE(cheats.areAllBuildingsEnabled() == true); + BOOST_TEST_REQUIRE(cheats.shouldShowEnemyProductivityOverlay() == true); } BOOST_AUTO_TEST_SUITE_END()