rnd-20051123-1-src
[rocksndiamonds.git] / src / tape.c
index 6b1b011cca8a628b6699e38d54108ebfc14f40b3..4406288567f7453dd81a7da6b3fb7b253e922b9c 100644 (file)
@@ -711,13 +711,19 @@ static void TapeRewind()
   InitRND(tape.random_seed);
 }
 
-void TapeStartRecording()
+static void TapeSetRandomSeed(long random_seed)
+{
+  tape.random_seed = InitRND(random_seed);
+}
+
+void TapeStartRecording(long random_seed)
 {
   if (!TAPE_IS_STOPPED(tape))
     TapeStop();
 
   TapeErase();
   TapeRewind();
+  TapeSetRandomSeed(random_seed);
 
   tape.recording = TRUE;
 
@@ -732,7 +738,7 @@ void TapeStartRecording()
 
 static void TapeStartGameRecording()
 {
-  TapeStartRecording();
+  TapeStartRecording(NEW_RANDOMIZE);
 
 #if defined(NETWORK_AVALIABLE)
   if (options.network)
@@ -776,8 +782,10 @@ void TapeHaltRecording()
 
 void TapeStopRecording()
 {
+#if 0
   if (!tape.recording)
     return;
+#endif
 
   TapeHaltRecording();
 
@@ -800,7 +808,7 @@ void TapeRecordAction(byte action[MAX_PLAYERS])
     return;
 #endif
 
-  if (tape.counter >= MAX_TAPELEN - 1)
+  if (tape.counter >= MAX_TAPE_LEN - 1)
   {
     TapeStopRecording();
     return;
@@ -923,8 +931,10 @@ static void TapeStartGamePlaying()
 
 void TapeStopPlaying()
 {
+#if 0
   if (!tape.playing)
     return;
+#endif
 
   tape.playing = FALSE;
   tape.pausing = FALSE;
@@ -944,7 +954,7 @@ byte *TapePlayAction()
   if (!tape.playing || tape.pausing)
     return NULL;
 
-  if (tape.pause_before_death) /* STOP 10s BEFORE PLAYER GETS KILLED... */
+  if (tape.pause_before_death) /* stop 10 seconds before player gets killed */
   {
     if (!(FrameCounter % 20))
     {
@@ -965,6 +975,7 @@ byte *TapePlayAction()
     if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
     {
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
+
       return NULL;
     }
   }
@@ -983,6 +994,7 @@ byte *TapePlayAction()
        DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
     }
   }
+
 #if 0
   /* !!! this makes things much slower !!! */
   else if (tape.warp_forward)
@@ -1209,8 +1221,6 @@ void InsertSolutionTape()
  * tape autoplay functions
  * ------------------------------------------------------------------------- */
 
-#define MAX_NUM_AUTOPLAY_LEVELS                1000
-
 void AutoPlayTape()
 {
   static LevelDirTree *autoplay_leveldir = NULL;
@@ -1218,7 +1228,9 @@ void AutoPlayTape()
   static int autoplay_level_nr = -1;
   static int num_levels_played = 0;
   static int num_levels_solved = 0;
-  static boolean levels_failed[MAX_NUM_AUTOPLAY_LEVELS];
+  static int num_tape_missing = 0;
+  static boolean level_failed[MAX_TAPES_PER_SET];
+  static boolean tape_missing[MAX_TAPES_PER_SET];
   int i;
 
   if (autoplay_initialized)
@@ -1227,10 +1239,11 @@ void AutoPlayTape()
     printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
 
     num_levels_played++;
+
     if (tape.auto_play_level_solved)
       num_levels_solved++;
-    else if (level_nr >= 0 && level_nr < MAX_NUM_AUTOPLAY_LEVELS)
-      levels_failed[level_nr] = TRUE;
+    else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
+      level_failed[level_nr] = TRUE;
   }
   else
   {
@@ -1246,11 +1259,10 @@ void AutoPlayTape()
 
     leveldir_current = autoplay_leveldir;
 
-    if (global.autoplay_level_nr != -1)
-    {
-      autoplay_leveldir->first_level = global.autoplay_level_nr;
-      autoplay_leveldir->last_level  = global.autoplay_level_nr;
-    }
+    if (autoplay_leveldir->first_level < 0)
+      autoplay_leveldir->first_level = 0;
+    if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
+      autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
 
     autoplay_level_nr = autoplay_leveldir->first_level;
 
@@ -1264,8 +1276,11 @@ void AutoPlayTape()
     printf_line("=", 79);
     printf("\n");
 
-    for (i = 0; i < MAX_NUM_AUTOPLAY_LEVELS; i++)
-      levels_failed[i] = FALSE;
+    for (i = 0; i < MAX_TAPES_PER_SET; i++)
+    {
+      level_failed[i] = FALSE;
+      tape_missing[i] = FALSE;
+    }
 
     autoplay_initialized = TRUE;
   }
@@ -1274,6 +1289,9 @@ void AutoPlayTape()
   {
     level_nr = autoplay_level_nr++;
 
+    if (!global.autoplay_all && !global.autoplay_level[level_nr])
+      continue;
+
     TapeErase();
 
     printf("Level %03d: ", level_nr);
@@ -1285,6 +1303,12 @@ void AutoPlayTape()
       continue;
     }
 
+#if 0
+    /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
+    printf("(only testing level)\n");
+    continue;
+#endif
+
     LoadSolutionTape(level_nr);
 #if 1
     if (tape.no_valid_file)
@@ -1292,6 +1316,10 @@ void AutoPlayTape()
     if (TAPE_IS_EMPTY(tape))
 #endif
     {
+      num_tape_missing++;
+      if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
+       tape_missing[level_nr] = TRUE;
+
       printf("(no tape)\n");
       continue;
     }
@@ -1318,11 +1346,21 @@ void AutoPlayTape()
   if (num_levels_played != num_levels_solved)
   {
     printf(", FAILED:");
-    for (i = 0; i < MAX_NUM_AUTOPLAY_LEVELS; i++)
-      if (levels_failed[i])
+    for (i = 0; i < MAX_TAPES_PER_SET; i++)
+      if (level_failed[i])
        printf(" %03d", i);
   }
 
+#if 0
+  if (num_tape_missing > 0)
+  {
+    printf(", NO TAPE:");
+    for (i = 0; i < MAX_TAPES_PER_SET; i++)
+      if (tape_missing[i])
+       printf(" %03d", i);
+  }
+#endif
+
   printf("\n");
   printf_line("=", 79);