changed code position of check when stopping tape recording
[rocksndiamonds.git] / src / tape.c
index a8ac4cea12a6d9974f541302ac0f85fb3e782abc..38edafc59d6503b61e167c97f1ec16c1f8aadbe5 100644 (file)
@@ -637,11 +637,11 @@ static void TapeAppendRecording()
 
 void TapeHaltRecording()
 {
-  if (!tape.recording)
-    return;
-
   tape.counter++;
-  tape.pos[tape.counter].delay = 0;
+
+  // initialize delay for next tape entry (to be able to continue recording)
+  if (tape.counter < MAX_TAPE_LEN)
+    tape.pos[tape.counter].delay = 0;
 
   tape.length = tape.counter;
   tape.length_frames = GetTapeLengthFrames();
@@ -650,7 +650,8 @@ void TapeHaltRecording()
 
 void TapeStopRecording()
 {
-  TapeHaltRecording();
+  if (tape.recording)
+    TapeHaltRecording();
 
   tape.recording = FALSE;
   tape.pausing = FALSE;
@@ -659,33 +660,10 @@ void TapeStopRecording()
   MapTapeEjectButton();
 }
 
-void TapeRecordAction(byte action_raw[MAX_PLAYERS])
+void TapeAddAction(byte action[MAX_PLAYERS])
 {
-  byte action[MAX_PLAYERS];
   int i;
 
-  if (!tape.recording)         /* (record action even when tape is paused) */
-    return;
-
-  if (tape.counter >= MAX_TAPE_LEN - 1)
-  {
-    TapeStopRecording();
-    return;
-  }
-
-  for (i = 0; i < MAX_PLAYERS; i++)
-    action[i] = action_raw[i];
-
-  if (tape.set_centered_player)
-  {
-    for (i = 0; i < MAX_PLAYERS; i++)
-      if (tape.centered_player_nr_next == i ||
-         tape.centered_player_nr_next == -1)
-       action[i] |= KEY_SET_FOCUS;
-
-    tape.set_centered_player = FALSE;
-  }
-
   if (tape.pos[tape.counter].delay > 0)                /* already stored action */
   {
     boolean changed_events = FALSE;
@@ -712,6 +690,36 @@ void TapeRecordAction(byte action_raw[MAX_PLAYERS])
   }
 }
 
+void TapeRecordAction(byte action_raw[MAX_PLAYERS])
+{
+  byte action[MAX_PLAYERS];
+  int i;
+
+  if (!tape.recording)         /* (record action even when tape is paused) */
+    return;
+
+  if (tape.counter >= MAX_TAPE_LEN - 1)
+  {
+    TapeStopRecording();
+    return;
+  }
+
+  for (i = 0; i < MAX_PLAYERS; i++)
+    action[i] = action_raw[i];
+
+  if (tape.set_centered_player)
+  {
+    for (i = 0; i < MAX_PLAYERS; i++)
+      if (tape.centered_player_nr_next == i ||
+         tape.centered_player_nr_next == -1)
+       action[i] |= KEY_SET_FOCUS;
+
+    tape.set_centered_player = FALSE;
+  }
+
+  TapeAddAction(action);
+}
+
 void TapeTogglePause(boolean toggle_mode)
 {
   if (tape.playing && tape.pausing && (toggle_mode & TAPE_TOGGLE_PLAY_PAUSE))
@@ -1066,13 +1074,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();
 }
@@ -1384,7 +1402,7 @@ static void HandleTapeButtonsExt(int id)
       else
       {
        if (tape.changed)
-         SaveTapeChecked(tape.level_nr);
+         SaveTapeChecked(level_nr);
 
        TapeErase();
       }