fixed crash bug caused by accessing invalid (off-playfield) array positions
[rocksndiamonds.git] / src / tape.c
index 793bf0cec0145eb04ddaea56a01f898092558626..a6ab98561aa32c9f2dcc213cbc07312941cfa3d2 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);
@@ -1381,8 +1381,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;
@@ -1612,6 +1614,7 @@ static int AutoPlayTapesExt(boolean initialize)
         global.autoplay_level[tape.level_nr] = TRUE;
 
       global.autoplay_all = FALSE;
+      options.mytapes = FALSE;
     }
 
     if (autoplay.all_levelsets)
@@ -1667,6 +1670,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++;
 
@@ -1680,6 +1718,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);
 
@@ -1701,12 +1742,8 @@ static int AutoPlayTapesExt(boolean initialize)
     if (!global.autoplay_all && !global.autoplay_level[level_nr])
       continue;
 
-    char *tape_filename = (autoplay.tape_filename ? autoplay.tape_filename :
-                           options.mytapes ? getTapeFilename(level_nr) :
-                           getSolutionTapeFilename(level_nr));
-
-    // speed things up in case of missing tapes (by skipping loading level)
-    if (!fileExists(tape_filename))
+    // speed things up in case of missing private tapes (skip loading level)
+    if (options.mytapes && !fileExists(getTapeFilename(level_nr)))
     {
       autoplay.num_tape_missing++;
 
@@ -1744,7 +1781,7 @@ static int AutoPlayTapesExt(boolean initialize)
     {
       autoplay.num_tape_missing++;
 
-      Print("Tape %03d: (invalid tape)\n", level_nr);
+      Print("Tape %03d: (no tape found)\n", level_nr);
 
       continue;
     }
@@ -1844,7 +1881,7 @@ static int AutoPlayTapesExt(boolean initialize)
 
       if (!success)
       {
-       num_tapes = -1;
+       num_tapes = -num_tapes;
 
        break;
       }