From b3c2f56c79e1da6adf8ab7715a11f4b8a2957f77 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 3 May 2021 18:29:23 -0700 Subject: [PATCH] Factor out slowdown/invincibility conds to function This factors out the slowdown and invincibility conditionals to a function. This means less copy-pasted code, and it also conveys intent (that we don't want to allow competitive options if we have either of these cheats enabled). This function isn't implemented in the header because then we would have to include Map.h for map.invincibility, and transitive includes are evil. Although, map.invincibility ought to be on Game instead (it was only mapclass due to 2.2-and-previous argument passing), but that's a bunch of variable reshuffling that can be done later. --- desktop_version/src/Game.cpp | 11 ++++++++--- desktop_version/src/Game.h | 4 ++++ desktop_version/src/Input.cpp | 6 +++--- desktop_version/src/Render.cpp | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 19752004..2b599f35 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6251,7 +6251,7 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) //ok, secret lab! no notification, but test: if (unlock[8]) { - option("secret lab", !map.invincibility && slowdown == 30); + option("secret lab", !nocompetitive()); } option("play modes"); if (save_exists()) @@ -6285,9 +6285,9 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) menuyoff = 64; break; case Menu::playmodes: - option("time trials", !map.invincibility && slowdown == 30); + option("time trials", !nocompetitive()); option("intermissions", unlock[16]); - option("no death mode", unlock[17] && !map.invincibility && slowdown == 30); + option("no death mode", unlock[17] && !nocompetitive()); option("flip mode", unlock[18]); option("return to play menu"); menuyoff = 8; @@ -6810,3 +6810,8 @@ bool Game::incompetitive(void) { return insecretlab || intimetrial || nodeathmode; } + +bool Game::nocompetitive(void) +{ + return slowdown < 30 || map.invincibility; +} diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 81d25caf..2c05e201 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -451,6 +451,10 @@ public: return inintermission || insecretlab || intimetrial || nodeathmode; } + bool incompetitive(void); + + bool nocompetitive(void); + bool over30mode; bool glitchrunnermode; // Have fun speedrunners! <3 Misa diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 9bfd4e71..fa060af9 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -1252,7 +1252,7 @@ static void menuactionpress(void) } else if (game.currentmenuoption == 1 && game.unlock[8]) { - if(!map.invincibility && game.slowdown == 30){ + if(!game.nocompetitive()){ music.playef(11); startmode(11); }else{ @@ -1346,7 +1346,7 @@ static void menuactionpress(void) } break; case Menu::playmodes: - if (game.currentmenuoption == 0 && game.slowdown == 30 && !map.invincibility) //go to the time trial menu + if (game.currentmenuoption == 0 && !game.nocompetitive()) //go to the time trial menu { music.playef(11); game.createmenu(Menu::timetrials); @@ -1359,7 +1359,7 @@ static void menuactionpress(void) game.createmenu(Menu::intermissionmenu); map.nexttowercolour(); } - else if (game.currentmenuoption == 2 && game.unlock[17] && game.slowdown == 30 && !map.invincibility) //start a game in no death mode + else if (game.currentmenuoption == 2 && game.unlock[17] && !game.nocompetitive()) //start a game in no death mode { music.playef(11); game.createmenu(Menu::startnodeathmode); diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index da3974ca..e3edb052 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -713,7 +713,7 @@ static void menurender(void) graphics.Print( -1, 65, "Replay any level in the game in", tr, tg, tb, true); graphics.Print( -1, 75, "a competitive time trial mode.", tr, tg, tb, true); - if (game.slowdown < 30 || map.invincibility) + if (game.nocompetitive()) { graphics.Print( -1, 105, "Time Trials are not available", tr, tg, tb, true); graphics.Print( -1, 115, "with slowdown or invincibility.", tr, tg, tb, true); @@ -734,7 +734,7 @@ static void menurender(void) graphics.Print( -1, 65, "Play the entire game", tr, tg, tb, true); graphics.Print( -1, 75, "without dying once.", tr, tg, tb, true); - if (game.slowdown < 30 || map.invincibility) + if (game.nocompetitive()) { graphics.Print( -1, 105, "No Death Mode is not available", tr, tg, tb, true); graphics.Print( -1, 115, "with slowdown or invincibility.", tr, tg, tb, true);