fixed bugs with request dialog on game over in MM engine
authorHolger Schemel <info@artsoft.org>
Thu, 29 Dec 2022 01:35:10 +0000 (02:35 +0100)
committerHolger Schemel <info@artsoft.org>
Thu, 29 Dec 2022 01:35:49 +0000 (02:35 +0100)
src/game_mm/mm_game.c
src/game_mm/mm_main.h

index a3c22be01a129c6764956c55dca15d229906cee5..9d32be5e813033793684fdcf3a1940cb3f43ed93 100644 (file)
@@ -740,6 +740,27 @@ static void FadeOutLaser(boolean overloaded)
     StopSound_MM(SND_MM_GAME_HEALTH_CHARGING);
 }
 
+static void GameOver_MM(int game_over_cause)
+{
+  // do not handle game over if request dialog is already active
+  if (game.request_active)
+    return;
+
+  game_mm.game_over = TRUE;
+  game_mm.game_over_cause = game_over_cause;
+
+  if (setup.ask_on_game_over)
+    game.restart_game_message = (game_over_cause == GAME_OVER_BOMB ?
+                                "Bomb killed Mc Duffin! Play it again?" :
+                                game_over_cause == GAME_OVER_NO_ENERGY ?
+                                "Out of magic energy! Play it again?" :
+                                game_over_cause == GAME_OVER_OVERLOADED ?
+                                "Magic spell hit Mc Duffin! Play it again?" :
+                                NULL);
+
+  SetTileCursorActive(FALSE);
+}
+
 void AddLaserEdge(int lx, int ly)
 {
   int clx = dSX + lx;
@@ -2512,10 +2533,7 @@ static void Explode_MM(int x, int y, int phase, int mode)
       Bang_MM(laser.start_edge.x, laser.start_edge.y);
       Store[x][y] = EL_EMPTY;
 
-      game_mm.game_over = TRUE;
-      game_mm.game_over_cause = GAME_OVER_BOMB;
-
-      SetTileCursorActive(FALSE);
+      GameOver_MM(GAME_OVER_DELAYED);
 
       laser.overloaded = FALSE;
     }
@@ -2523,7 +2541,7 @@ static void Explode_MM(int x, int y, int phase, int mode)
     {
       Store[x][y] = EL_EMPTY;
 
-      game.restart_game_message = "Bomb killed Mc Duffin! Play it again?";
+      GameOver_MM(GAME_OVER_BOMB);
     }
 
     Tile[x][y] = Store[x][y];
@@ -3190,12 +3208,7 @@ static void GameActions_MM_Ext(void)
     {
       FadeOutLaser(FALSE);
 
-      game_mm.game_over = TRUE;
-      game_mm.game_over_cause = GAME_OVER_NO_ENERGY;
-
-      SetTileCursorActive(FALSE);
-
-      game.restart_game_message = "Out of magic energy! Play it again?";
+      GameOver_MM(GAME_OVER_NO_ENERGY);
 
       return;
     }
@@ -3297,12 +3310,7 @@ static void GameActions_MM_Ext(void)
 
       FadeOutLaser(TRUE);
 
-      game_mm.game_over = TRUE;
-      game_mm.game_over_cause = GAME_OVER_OVERLOADED;
-
-      SetTileCursorActive(FALSE);
-
-      game.restart_game_message = "Magic spell hit Mc Duffin! Play it again?";
+      GameOver_MM(GAME_OVER_OVERLOADED);
 
       return;
     }
index af5b832faaaacd3e4e5d40b519b18a33e123f0e4..e33e8f19acc1e66f5c9d6c76168adfaebf5da5dc 100644 (file)
@@ -1104,6 +1104,7 @@ extern int                num_element_info;
 #define GAME_OVER_NO_ENERGY    1
 #define GAME_OVER_OVERLOADED   2
 #define GAME_OVER_BOMB         3
+#define GAME_OVER_DELAYED      4
 
 // values for color_status
 #define STATIC_COLORS          0