moved code to create restart message to separate function
[rocksndiamonds.git] / src / game.c
index 8d713df727b83175c5b3a6a0f500fa1d0b76c632..2ae8886f5c6d7fe80f49c4676c4ccc7568240b21 100644 (file)
@@ -13999,8 +13999,6 @@ void BuryPlayer(struct PlayerInfo *player)
 
   PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
 
-  PlaySound(SND_GAME_LOSING);
-
   RemovePlayer(player);
 
   player->buried = TRUE;
@@ -15641,15 +15639,21 @@ void RequestRestartGame(char *message)
 
   boolean has_started_game = hasStartedNetworkGame();
   int request_mode = (has_started_game ? REQ_ASK : REQ_CONFIRM);
+  int door_state = DOOR_CLOSE_1;
 
-  if (Request(message, request_mode | REQ_STAY_CLOSED) && has_started_game)
+  if (Request(message, request_mode | REQ_STAY_OPEN) && has_started_game)
   {
+    CloseDoor(door_state);
+
     StartGameActions(network.enabled, setup.autorecord, level.random_seed);
   }
   else
   {
-    // needed in case of envelope request to close game panel
-    CloseDoor(DOOR_CLOSE_1);
+    // if game was invoked from level editor, also close tape recorder door
+    if (level_editor_test_game)
+      door_state = DOOR_CLOSE_ALL;
+
+    CloseDoor(door_state);
 
     SetGameStatus(GAME_MODE_MAIN);
 
@@ -15657,6 +15661,19 @@ void RequestRestartGame(char *message)
   }
 }
 
+static char *getRestartGameMessage(void)
+{
+  boolean play_again = hasStartedNetworkGame();
+  static char message[MAX_OUTPUT_LINESIZE];
+  char *game_over_text = "Game over!";
+  char *play_again_text = " Play it again?";
+
+  snprintf(message, MAX_OUTPUT_LINESIZE, "%s%s", game_over_text,
+          (play_again ? play_again_text : ""));
+
+  return message;
+}
+
 void CheckGameOver(void)
 {
   static boolean last_game_over = FALSE;
@@ -15682,15 +15699,16 @@ void CheckGameOver(void)
 
   if (game_over_delay > 0)
   {
+    if (game_over_delay == game_over_delay_value / 2)
+      PlaySound(SND_GAME_LOSING);
+
     game_over_delay--;
 
     return;
   }
 
   if (last_game_over != game_over)
-    game.restart_game_message = (hasStartedNetworkGame() ?
-                                "Game over! Play it again?" :
-                                "Game over!");
+    game.restart_game_message = getRestartGameMessage();
 
   last_game_over = game_over;
 }