added support for playing/testing tape by filename
[rocksndiamonds.git] / src / tape.c
index 2300f00b2d89b9f34015ca76998fbeac4de6e7e9..08ea8f8036b046ee3e28ff8ddd13ce0f95845c77 100644 (file)
@@ -540,8 +540,14 @@ void TapeErase(void)
   tape.length_frames = 0;
   tape.length_seconds = 0;
 
+  tape.score_tape_basename[0] = '\0';
+
   if (leveldir_current)
-    setString(&tape.level_identifier, leveldir_current->identifier);
+  {
+    strncpy(tape.level_identifier, leveldir_current->identifier,
+           MAX_FILENAME_LEN);
+    tape.level_identifier[MAX_FILENAME_LEN] = '\0';
+  }
 
   tape.level_nr = level_nr;
   tape.pos[tape.counter].delay = 0;
@@ -1160,12 +1166,7 @@ static boolean checkTapesFromSameLevel(struct TapeInfo *t1, struct TapeInfo *t2)
 
 static void CopyTape(struct TapeInfo *tape_from, struct TapeInfo *tape_to)
 {
-  if (tape_to->level_identifier != NULL)
-    checked_free(tape_to->level_identifier);
-
   *tape_to = *tape_from;
-
-  tape_to->level_identifier = getStringCopy(tape_from->level_identifier);
 }
 
 static void SwapTapes(struct TapeInfo *t1, struct TapeInfo *t2)
@@ -1234,6 +1235,7 @@ void AutoPlayTapes(void)
   static int num_tapes_patched = 0;
   static int num_tape_missing = 0;
   static boolean level_failed[MAX_TAPES_PER_SET];
+  static char *tape_filename = NULL;
   static int patch_nr = 0;
   static char *patch_name[] =
   {
@@ -1326,6 +1328,20 @@ void AutoPlayTapes(void)
     audio.sound_enabled = FALSE;
     setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
 
+    if (strSuffix(global.autoplay_leveldir, ".tape"))
+    {
+      tape_filename = global.autoplay_leveldir;
+
+      LoadTapeFromFilename(tape_filename);
+
+      global.autoplay_leveldir = tape.level_identifier;
+
+      if (tape.level_nr >= 0 && tape.level_nr < MAX_TAPES_PER_SET)
+        global.autoplay_level[tape.level_nr] = TRUE;
+
+      global.autoplay_all = FALSE;
+    }
+
     autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
                                                  global.autoplay_leveldir);
 
@@ -1398,7 +1414,9 @@ void AutoPlayTapes(void)
     continue;
 #endif
 
-    if (options.mytapes)
+    if (tape_filename)
+      LoadTapeFromFilename(tape_filename);
+    else if (options.mytapes)
       LoadTape(level_nr);
     else
       LoadSolutionTape(level_nr);