fixed asking all network clients to "play again" after unsolved game end
[rocksndiamonds.git] / src / game.c
index 5bfa71db14d69900b035c2d31a0e60df472027bd..f359a2cbdfb406c6bf018873c7b14c5901397dfc 100644 (file)
@@ -11346,7 +11346,8 @@ static void GameActionsExt(void)
     if (game_status != GAME_MODE_PLAYING)
       return;
 
-    if (!network_player_action_received)
+    /* check if network player actions still missing and game still running */
+    if (!network_player_action_received && !checkGameEnded())
       return;          /* failed to get network player actions in time */
 
     /* do not yet reset "network_player_action_received" (for tape.pausing) */
@@ -11386,7 +11387,7 @@ static void GameActionsExt(void)
       stored_player[i].effective_action = stored_player[i].action;
   }
 
-  if (network_playing)
+  if (network_playing && !checkGameEnded())
     SendToServer_MovePlayer(summarized_player_action);
 
   // summarize all actions at local players mapped input device position
@@ -14937,7 +14938,10 @@ void RequestRestartGame(char *message)
 {
   game.restart_game_message = NULL;
 
-  if (Request(message, REQ_ASK | REQ_STAY_CLOSED))
+  boolean has_started_game = hasStartedNetworkGame();
+  int request_mode = (has_started_game ? REQ_ASK : REQ_CONFIRM);
+
+  if (Request(message, request_mode | REQ_STAY_CLOSED) && has_started_game)
   {
     StartGameActions(network.enabled, setup.autorecord, level.random_seed);
   }
@@ -14949,6 +14953,40 @@ void RequestRestartGame(char *message)
   }
 }
 
+void CheckGameOver(void)
+{
+  static boolean last_game_over = FALSE;
+  static int game_over_delay = 0;
+  int game_over_delay_value = 50;
+  boolean game_over = checkGameFailed();
+
+  /* do not handle game over if request dialog is already active */
+  if (game.request_active)
+    return;
+
+  if (!game_over)
+  {
+    last_game_over = FALSE;
+    game_over_delay = game_over_delay_value;
+
+    return;
+  }
+
+  if (game_over_delay > 0)
+  {
+    game_over_delay--;
+
+    return;
+  }
+
+  if (last_game_over != game_over)
+    game.restart_game_message = (hasStartedNetworkGame() ?
+                                "Game over! Play it again?" :
+                                "Game over!");
+
+  last_game_over = game_over;
+}
+
 boolean checkGameSolved(void)
 {
   /* set for all game engines if level was solved */