fixed bug which could cause saving tapes with a wrong level number filename
[rocksndiamonds.git] / src / tape.c
index e97dc086c5c2318771d48d50f78527e350ff0bba..831659b62cb881ac47353c1e37992d3917c8d57b 100644 (file)
@@ -376,15 +376,18 @@ void DrawVideoDisplayCurrentState()
   {
     state |= VIDEO_STATE_PLAY_ON;
 
-    if (tape.deactivate_display)
-      state |= VIDEO_STATE_WARP2_ON;
-    else if (tape.warp_forward)
-      state |= VIDEO_STATE_WARP_ON;
-    else if (tape.fast_forward)
-      state |= VIDEO_STATE_FFWD_ON;
-
-    if (tape.pause_before_end)
-      state |= VIDEO_STATE_PBEND_ON;
+    if (!tape.pausing)
+    {
+      if (tape.deactivate_display)
+       state |= VIDEO_STATE_WARP2_ON;
+      else if (tape.warp_forward)
+       state |= VIDEO_STATE_WARP_ON;
+      else if (tape.fast_forward)
+       state |= VIDEO_STATE_FFWD_ON;
+
+      if (tape.pause_before_end)
+       state |= VIDEO_STATE_PBEND_ON;
+    }
   }
 
   // draw labels and symbols separately to prevent labels overlapping symbols
@@ -455,6 +458,44 @@ void TapeDeactivateDisplayOff(boolean redraw_display)
 }
 
 
+/* ========================================================================= */
+/* tape logging functions                                                    */
+/* ========================================================================= */
+
+void PrintTapeReplayProgress(boolean replay_finished)
+{
+  static unsigned int counter_last = -1;
+  unsigned int counter = Counter();
+  unsigned int counter_seconds  = counter / 1000;
+
+  if (!replay_finished)
+  {
+    unsigned int counter_delay = 50;
+
+    if (counter > counter_last + counter_delay)
+    {
+      PrintNoLog("\r");
+      PrintNoLog("Level %03d [%02d:%02d]: [%02d:%02d] - playing tape ... ",
+                level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
+                TapeTime / 60, TapeTime % 60);
+
+      counter_last = counter;
+    }
+  }
+  else
+  {
+    PrintNoLog("\r");
+    Print("Level %03d [%02d:%02d]: (%02d:%02d.%03d / %.2f %%) - %s.\n",
+         level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
+         counter_seconds / 60, counter_seconds % 60, counter % 1000,
+         (float)counter / tape.length_seconds / 10,
+         tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
+
+    counter_last = -1;
+  }
+}
+
+
 /* ========================================================================= */
 /* tape control functions                                                    */
 /* ========================================================================= */
@@ -854,6 +895,9 @@ byte *TapePlayAction()
     tape.delay_played = 0;
   }
 
+  if (tape.auto_play)
+    PrintTapeReplayProgress(FALSE);
+
   return action;
 }
 
@@ -1022,13 +1066,23 @@ void TapeQuickLoad()
 
 void InsertSolutionTape()
 {
-  if (!TAPE_IS_EMPTY(tape))
+  boolean level_has_tape = (level.game_engine_type == GAME_ENGINE_TYPE_SP &&
+                           level.native_sp_level->demo.is_available);
+
+  if (!fileExists(getSolutionTapeFilename(level_nr)) && !level_has_tape)
+  {
+    Request("No solution tape for this level!", REQ_CONFIRM);
+
     return;
+  }
+
+  // if tape recorder already contains a tape, remove it without asking
+  TapeErase();
 
   LoadSolutionTape(level_nr);
 
   if (TAPE_IS_EMPTY(tape))
-    Request("No solution tape for this level!", REQ_CONFIRM);
+    Request("Loading solution tape for this level failed!", REQ_CONFIRM);
 
   DrawCompleteVideoDisplay();
 }
@@ -1052,7 +1106,7 @@ void AutoPlayTape()
   if (autoplay_initialized)
   {
     /* just finished auto-playing tape */
-    Print("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
+    PrintTapeReplayProgress(TRUE);
 
     num_levels_played++;
 
@@ -1109,18 +1163,18 @@ void AutoPlayTape()
 
     TapeErase();
 
-    Print("Level %03d: ", level_nr);
-
     LoadLevel(level_nr);
-    if (level.no_valid_file)
+
+    if (level.no_level_file || level.no_valid_file)
     {
-      Print("(no level)\n");
+      Print("Level %03d: (no level)\n", level_nr);
+
       continue;
     }
 
 #if 0
     /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
-    Print("(only testing level)\n");
+    Print("Level %03d: (only testing level)\n", level_nr);
     continue;
 #endif
 
@@ -1133,12 +1187,12 @@ void AutoPlayTape()
     {
       num_tape_missing++;
 
-      Print("(no tape)\n");
+      Print("Level %03d: (no tape)\n", level_nr);
 
       continue;
     }
 
-    Print("playing tape ... ");
+    InitCounter();
 
     TapeStartGamePlaying();
     TapeStartWarpForward(global.autoplay_mode);
@@ -1340,7 +1394,7 @@ static void HandleTapeButtonsExt(int id)
       else
       {
        if (tape.changed)
-         SaveTapeChecked(tape.level_nr);
+         SaveTapeChecked(level_nr);
 
        TapeErase();
       }