From 9659bd58837dfa25ee8dfa8bbe737ba2aff35308 Mon Sep 17 00:00:00 2001 From: Jakub Audykowicz Date: Sat, 14 Dec 2024 20:18:49 +0100 Subject: [PATCH 1/4] Show enemy productivity overlay when cheat mode is on (S2 behavior) --- libs/s25main/world/GameWorldView.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/s25main/world/GameWorldView.cpp b/libs/s25main/world/GameWorldView.cpp index 5907cc91f6..2b6f86a021 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 draw when object visible and cheat mode is on + if(gwv.GetVisibility(pt) != Visibility::Visible + || !GetWorld().GetGameInterface()->GI_GetCheats().isCheatModeOn()) + continue; } // Draw object name From 503f7666fe53f6031627be88128ee062cabc9895 Mon Sep 17 00:00:00 2001 From: Jakub Audykowicz Date: Sun, 22 Dec 2024 12:02:56 +0100 Subject: [PATCH 2/4] Add toggleShowEnemyProductivityOverlay instead of enabling this when cheat mode is on --- libs/s25main/CheatCommandTracker.cpp | 2 ++ libs/s25main/Cheats.cpp | 11 +++++++++++ libs/s25main/Cheats.h | 4 ++++ libs/s25main/ingameWindows/iwChat.cpp | 2 +- libs/s25main/world/GameWorldView.cpp | 4 ++-- tests/s25Main/integration/testCheats.cpp | 21 +++++++++++++++++++-- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/libs/s25main/CheatCommandTracker.cpp b/libs/s25main/CheatCommandTracker.cpp index f1b4e1aceb..b2a4c019a4 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 == "iq") + cheats_.toggleShowEnemyProductivityOverlay(); } bool CheatCommandTracker::checkSpecialKeyEvent(const KeyEvent& ke) diff --git a/libs/s25main/Cheats.cpp b/libs/s25main/Cheats.cpp index fedd5cf7e4..2cfc3ee0f4 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 a850e892d2..f88a058b0e 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/ingameWindows/iwChat.cpp b/libs/s25main/ingameWindows/iwChat.cpp index 096a8f28a9..65eb622a2a 100644 --- a/libs/s25main/ingameWindows/iwChat.cpp +++ b/libs/s25main/ingameWindows/iwChat.cpp @@ -57,7 +57,7 @@ void iwChat::Msg_EditEnter(const unsigned /*ctrl_id*/) std::string text = edit->GetText(); edit->SetText(""); - if(text.size() > 3u && text[0] == '!') + if(text[0] == '!') { auto* listener = dynamic_cast(GetParent()); if(listener) diff --git a/libs/s25main/world/GameWorldView.cpp b/libs/s25main/world/GameWorldView.cpp index 2b6f86a021..424d557271 100644 --- a/libs/s25main/world/GameWorldView.cpp +++ b/libs/s25main/world/GameWorldView.cpp @@ -372,9 +372,9 @@ void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRe auto* attackAidImage = LOADER.GetImageN("map_new", 20000); attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight())); } - // DO draw when object visible and cheat mode is on + // DO draw when object visible and cheat to show enemy productivity overlay is on if(gwv.GetVisibility(pt) != Visibility::Visible - || !GetWorld().GetGameInterface()->GI_GetCheats().isCheatModeOn()) + || !GetWorld().GetGameInterface()->GI_GetCheats().shouldShowEnemyProductivityOverlay()) continue; } diff --git a/tests/s25Main/integration/testCheats.cpp b/tests/s25Main/integration/testCheats.cpp index 284b8276f6..97997bc636 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() From ce9e1d9c8aadecbea017249cf98bcf9b32a6f13c Mon Sep 17 00:00:00 2001 From: Jakub Audykowicz Date: Tue, 21 Jan 2025 23:31:37 +0100 Subject: [PATCH 3/4] Restore iwChat logic and change show productivity cheat string --- libs/s25main/CheatCommandTracker.cpp | 2 +- libs/s25main/ingameWindows/iwChat.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/s25main/CheatCommandTracker.cpp b/libs/s25main/CheatCommandTracker.cpp index b2a4c019a4..e6983aa55b 100644 --- a/libs/s25main/CheatCommandTracker.cpp +++ b/libs/s25main/CheatCommandTracker.cpp @@ -36,7 +36,7 @@ void CheatCommandTracker::onChatCommand(const std::string& cmd) cheats_.armageddon(); else if(cmd == "impulse9") cheats_.toggleAllBuildingsEnabled(); - else if(cmd == "iq") + else if(cmd == "spies") cheats_.toggleShowEnemyProductivityOverlay(); } diff --git a/libs/s25main/ingameWindows/iwChat.cpp b/libs/s25main/ingameWindows/iwChat.cpp index 65eb622a2a..096a8f28a9 100644 --- a/libs/s25main/ingameWindows/iwChat.cpp +++ b/libs/s25main/ingameWindows/iwChat.cpp @@ -57,7 +57,7 @@ void iwChat::Msg_EditEnter(const unsigned /*ctrl_id*/) std::string text = edit->GetText(); edit->SetText(""); - if(text[0] == '!') + if(text.size() > 3u && text[0] == '!') { auto* listener = dynamic_cast(GetParent()); if(listener) From 35a55bb58559b0b7ea25ce594b7019c61915bc4c Mon Sep 17 00:00:00 2001 From: Jakub Audykowicz Date: Tue, 21 Jan 2025 23:42:16 +0100 Subject: [PATCH 4/4] Reverse logic in DrawNameProductivityOverlay --- libs/s25main/world/GameWorldView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/s25main/world/GameWorldView.cpp b/libs/s25main/world/GameWorldView.cpp index 424d557271..8021628919 100644 --- a/libs/s25main/world/GameWorldView.cpp +++ b/libs/s25main/world/GameWorldView.cpp @@ -372,9 +372,9 @@ void GameWorldView::DrawNameProductivityOverlay(const TerrainRenderer& terrainRe auto* attackAidImage = LOADER.GetImageN("map_new", 20000); attackAidImage->DrawFull(curPos - DrawPoint(0, attackAidImage->getHeight())); } - // DO draw when object visible and cheat to show enemy productivity overlay is on - if(gwv.GetVisibility(pt) != Visibility::Visible - || !GetWorld().GetGameInterface()->GI_GetCheats().shouldShowEnemyProductivityOverlay()) + // 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; }