From 949e99c9501965dfb7efe9ae213c46a698031d2c Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 22 Jun 2020 15:35:26 -0700 Subject: [PATCH] Use case-switch in mapmenuactionpress() This prevents from having to repeat 'if (game.menupage == ...)' everywhere, which makes for more concise code. I know you're technically supposed to indent the cases surrounded by if-guards, but I don't think indenting them here would help anything. I'd only indent it if the 'if' had an 'else', for example. But if it surrounds the whole case, then there's no need for indentation. --- desktop_version/src/Input.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 724c17d2..41826bcf 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -1996,7 +1996,10 @@ void mapinput() void mapmenuactionpress() { - if (game.menupage == 1 && obj.flags[67] && !game.insecretlab && !map.custommode) + switch (game.menupage) + { + case 1: + if (obj.flags[67] && !game.insecretlab && !map.custommode) { //Warp back to the ship graphics.resumegamemode = true; @@ -2019,8 +2022,9 @@ void mapmenuactionpress() game.state = 4000; game.statedelay = 0; } - - if (game.menupage == 3 && !game.gamesaved && !game.intimetrial + break; + case 3: + if (!game.gamesaved && !game.intimetrial && !game.nodeathmode && !game.insecretlab && !game.inintermission) { game.flashlight = 5; @@ -2045,14 +2049,13 @@ void mapmenuactionpress() game.savequick(); } } + break; - if (game.menupage == 10) - { + case 10: //return to game graphics.resumegamemode = true; - } - if (game.menupage == 11) - { + break; + case 11: //quit to menu //Kill contents of offset render buffer, since we do that for some reason. @@ -2063,21 +2066,20 @@ void mapmenuactionpress() map.nexttowercolour(); game.fadetomenu = true; game.fadetomenudelay = 16; - } + break; - if (game.menupage == 20) - { + case 20: //return to game graphics.resumegamemode = true; - } - if (game.menupage == 21) - { + break; + case 21: //quit to menu game.swnmode = false; graphics.fademode = 2; music.fadeout(); game.fadetolab = true; game.fadetolabdelay = 16; + break; } }