added key shortcuts to restart and replay/resume (before end) the game
[rocksndiamonds.git] / src / tape.c
index 03ecf68944bc6cec9726be31cd6e6ff808d70b49..68ffadcf92677d6d126deb3075b6b5e1f417fdeb 100644 (file)
@@ -985,7 +985,7 @@ byte *TapePlayAction(void)
 
   if (tape.pause_before_end)  // stop some seconds before end of tape
   {
-    if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
+    if (TapeTime > (int)tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
     {
       TapeStopWarpForward();
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
@@ -1244,6 +1244,59 @@ void TapeQuickLoad(void)
   }
 }
 
+static boolean checkRestartGame(char *message)
+{
+  if (game_status == GAME_MODE_MAIN)
+    return TRUE;
+
+  if (!hasStartedNetworkGame())
+    return FALSE;
+
+  if (level_editor_test_game)
+    return TRUE;
+
+  if (game.all_players_gone)
+    return TRUE;
+
+  if (!setup.ask_on_quit_game)
+    return TRUE;
+
+  if (Request(message, REQ_ASK | REQ_STAY_CLOSED))
+    return TRUE;
+
+  OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
+
+  return FALSE;
+}
+
+void TapeRestartGame(void)
+{
+  if (!checkRestartGame("Restart game?"))
+    return;
+
+  StartGameActions(network.enabled, setup.autorecord, level.random_seed);
+}
+
+void TapeReplayAndPauseBeforeEnd(void)
+{
+  if (TAPE_IS_EMPTY(tape) && !tape.recording)
+  {
+    Request("No tape for this level!", REQ_CONFIRM);
+
+    return;
+  }
+
+  if (!checkRestartGame("Replay game and pause before end?"))
+    return;
+
+  TapeStop();
+  TapeStartGamePlaying();
+  TapeStartWarpForward(AUTOPLAY_MODE_WARP_NO_DISPLAY);
+
+  tape.pause_before_end = TRUE;
+  tape.quick_resume = TRUE;
+}
+
 boolean hasSolutionTape(void)
 {
   boolean tape_file_exists = fileExists(getSolutionTapeFilename(level_nr));
@@ -1381,8 +1434,10 @@ static TreeInfo *getFirstValidAutoPlayEntry(TreeInfo *node)
 
 static void AutoPlayTapes_SetScoreEntry(int score, int time)
 {
+  char *name = (options.mytapes ? setup.player_name : options.player_name);
+
   // set unique basename for score tape (for uploading to score server)
-  strcpy(tape.score_tape_basename, getScoreTapeBasename(setup.player_name));
+  strcpy(tape.score_tape_basename, getScoreTapeBasename(name));
 
   // store score in first score entry
   scores.last_added = 0;
@@ -1668,6 +1723,41 @@ static int AutoPlayTapesExt(boolean initialize)
       init_level_set = FALSE;
     }
 
+    if (autoplay.all_levelsets && global.autoplay_mode == AUTOPLAY_MODE_UPLOAD)
+    {
+      boolean skip_levelset = FALSE;
+
+      if (!directoryExists(getTapeDir(autoplay.leveldir->subdir)))
+      {
+       Print("No tape directory for this level set found -- skipping.\n");
+
+       skip_levelset = TRUE;
+      }
+
+      if (CheckTapeDirectoryUploadsComplete(autoplay.leveldir->subdir))
+      {
+       Print("All tapes for this level set already uploaded -- skipping.\n");
+
+       skip_levelset = TRUE;
+      }
+
+      if (skip_levelset)
+      {
+       PrintTapeReplaySummary(&autoplay);
+
+       // continue with next level set
+       autoplay.leveldir = getNextValidAutoPlayEntry(autoplay.leveldir);
+
+       // all level sets processed
+       if (autoplay.leveldir == NULL)
+         break;
+
+       init_level_set = TRUE;
+
+       continue;
+      }
+    }
+
     if (global.autoplay_mode != AUTOPLAY_MODE_FIX || patch_nr == 0)
       level_nr = autoplay.level_nr++;
 
@@ -1681,6 +1771,9 @@ static int AutoPlayTapesExt(boolean initialize)
       if (!autoplay.all_levelsets)
        break;
 
+      if (global.autoplay_mode == AUTOPLAY_MODE_UPLOAD)
+       MarkTapeDirectoryUploadsAsComplete(autoplay.leveldir->subdir);
+
       // continue with next level set
       autoplay.leveldir = getNextValidAutoPlayEntry(autoplay.leveldir);
 
@@ -1841,7 +1934,7 @@ static int AutoPlayTapesExt(boolean initialize)
 
       if (!success)
       {
-       num_tapes = -1;
+       num_tapes = -num_tapes;
 
        break;
       }