fixed and extended auto-replay modes from command line
[rocksndiamonds.git] / src / tape.c
index 2ddd754ddbdfeb49c51b2336a2b22606233062d4..6d90ca96e093b9a3b9c5cfd3a8edcd9a2f2ddc76 100644 (file)
@@ -356,20 +356,26 @@ void DrawVideoDisplaySymbol(unsigned int state)
   DrawVideoDisplay(state, VIDEO_DISPLAY_SYMBOL_ONLY);
 }
 
-void DrawVideoDisplayPlayState()
+void DrawVideoDisplayCurrentState()
 {
   int state = 0;
 
   DrawVideoDisplay(VIDEO_STATE_OFF, 0);
 
-  state |= VIDEO_STATE_PLAY_ON;
-
   if (tape.pausing)
-  {
     state |= VIDEO_STATE_PAUSE_ON;
+
+  if (tape.recording)
+  {
+    state |= VIDEO_STATE_REC_ON;
+
+    if (tape.single_step)
+      state |= VIDEO_STATE_1STEP_ON;
   }
-  else
+  else if (tape.playing)
   {
+    state |= VIDEO_STATE_PLAY_ON;
+
     if (tape.deactivate_display)
       state |= VIDEO_STATE_WARP2_ON;
     else if (tape.warp_forward)
@@ -666,14 +672,24 @@ void TapeRecordAction(byte action_raw[MAX_PLAYERS])
   }
 }
 
-void TapeTogglePause(boolean toggle_manual)
+void TapeTogglePause(boolean toggle_mode)
 {
+  if (tape.playing && tape.pausing && (toggle_mode & TAPE_TOGGLE_PLAY_PAUSE))
+  {
+    // continue playing in normal mode
+    tape.fast_forward = FALSE;
+    tape.warp_forward = FALSE;
+    tape.deactivate_display = FALSE;
+
+    tape.pause_before_end = FALSE;
+  }
+
   tape.pausing = !tape.pausing;
 
-  if (tape.single_step && toggle_manual)
+  if (tape.single_step && (toggle_mode & TAPE_TOGGLE_MANUAL))
     tape.single_step = FALSE;
 
-  DrawVideoDisplayPlayState();
+  DrawVideoDisplayCurrentState();
 
   if (tape.deactivate_display)
   {
@@ -765,9 +781,6 @@ byte *TapePlayAction()
   {
     if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
     {
-      tape.fast_forward = FALSE;
-      tape.pause_before_end = FALSE;
-
       TapeStopWarpForward();
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
 
@@ -778,9 +791,14 @@ byte *TapePlayAction()
   if (tape.counter >= tape.length)     /* end of tape reached */
   {
     if (tape.warp_forward && !tape.auto_play)
+    {
+      TapeStopWarpForward();
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
+    }
     else
+    {
       TapeStop();
+    }
 
     return NULL;
   }
@@ -871,33 +889,31 @@ unsigned int GetTapeLengthSeconds()
   return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
 }
 
-static void TapeStartWarpForward()
+static void TapeStartWarpForward(int mode)
 {
-  tape.warp_forward = TRUE;
+  tape.fast_forward = (mode & AUTOPLAY_FFWD);
+  tape.warp_forward = (mode & AUTOPLAY_WARP);
+  tape.deactivate_display = (mode & AUTOPLAY_WARP_NO_DISPLAY);
 
-  if (!tape.fast_forward && !tape.pause_before_end)
-  {
-    tape.pausing = FALSE;
-    tape.pause_before_end = TRUE;
-    tape.deactivate_display = TRUE;
+  tape.pausing = FALSE;
 
+  if (tape.deactivate_display)
     TapeDeactivateDisplayOn();
-  }
 
-  DrawVideoDisplayPlayState();
+  DrawVideoDisplayCurrentState();
 }
 
 static void TapeStopWarpForward()
 {
-  if (tape.deactivate_display)
-    tape.pause_before_end = FALSE;
-
+  tape.fast_forward = FALSE;
   tape.warp_forward = FALSE;
   tape.deactivate_display = FALSE;
 
+  tape.pause_before_end = FALSE;
+
   TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
 
-  DrawVideoDisplayPlayState();
+  DrawVideoDisplayCurrentState();
 }
 
 static void TapeSingleStep()
@@ -990,7 +1006,7 @@ void TapeQuickLoad()
   if (!TAPE_IS_EMPTY(tape))
   {
     TapeStartGamePlaying();
-    TapeStartWarpForward();
+    TapeStartWarpForward(AUTOPLAY_MODE_WARP_NO_DISPLAY);
 
     tape.quick_resume = TRUE;
   }
@@ -1120,12 +1136,7 @@ void AutoPlayTape()
     printf("playing tape ... ");
 
     TapeStartGamePlaying();
-
-    if (global.autoplay_mode == AUTOPLAY_FFWD)
-      tape.fast_forward = TRUE;
-
-    if (global.autoplay_mode != AUTOPLAY_PLAY)
-      TapeStartWarpForward();
+    TapeStartWarpForward(global.autoplay_mode);
 
     return;
   }
@@ -1307,35 +1318,32 @@ static void HandleTapeButtonsExt(int id)
     case TAPE_CTRL_ID_EXTRA:
       if (tape.playing)
       {
-       if (!tape.warp_forward)                 /* PLAY -> WARP FORWARD PLAY */
-       {
-         TapeStartWarpForward();
-       }
-       else if (tape.pausing)                  /* PAUSE -> WARP FORWARD PLAY */
-       {
-         TapeTogglePause(TAPE_TOGGLE_MANUAL);
-       }
-       else                                    /* WARP FORWARD PLAY -> PLAY */
-       {
-         TapeStopWarpForward();
-       }
+       tape.pause_before_end = !tape.pause_before_end;
+
+       DrawVideoDisplayCurrentState();
       }
       else if (tape.recording)
+      {
        TapeSingleStep();
+      }
 
       break;
 
     case TAPE_CTRL_ID_STOP:
       TapeStop();
+
       break;
 
     case TAPE_CTRL_ID_PAUSE:
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
+
       break;
 
     case TAPE_CTRL_ID_RECORD:
       if (TAPE_IS_STOPPED(tape))
+      {
        TapeStartGameRecording();
+      }
       else if (tape.pausing)
       {
        if (tape.playing)                       /* PLAY -> PAUSE -> RECORD */
@@ -1343,6 +1351,7 @@ static void HandleTapeButtonsExt(int id)
        else
          TapeTogglePause(TAPE_TOGGLE_MANUAL);
       }
+
       break;
 
     case TAPE_CTRL_ID_PLAY:
@@ -1364,45 +1373,34 @@ static void HandleTapeButtonsExt(int id)
       {
        if (tape.pausing)                       /* PAUSE -> PLAY */
        {
-         // continue playing in normal mode
-         tape.fast_forward = FALSE;
-         tape.warp_forward = FALSE;
-         tape.pause_before_end = FALSE;
-         tape.deactivate_display = FALSE;
-
-         TapeTogglePause(TAPE_TOGGLE_MANUAL);
+         TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE);
        }
-       else if (tape.warp_forward &&
-                !tape.fast_forward)            /* WARP FORWARD PLAY -> PLAY */
+       else if (!tape.fast_forward)            /* PLAY -> FFWD */
        {
-         TapeStopWarpForward();
+         tape.fast_forward = TRUE;
        }
-       else if (!tape.fast_forward)            /* PLAY -> FAST FORWARD PLAY */
+       else if (!tape.warp_forward)            /* FFWD -> WARP */
        {
-         tape.fast_forward = TRUE;
-
-         DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
+         tape.warp_forward = TRUE;
        }
-       else if (!tape.pause_before_end)        /* FFWD PLAY -> AUTO PAUSE */
+       else if (!tape.deactivate_display)      /* WARP -> WARP BLIND */
        {
-         tape.pause_before_end = TRUE;
-
-         DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
+         tape.deactivate_display = TRUE;
 
-         if (tape.warp_forward)
-           DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
+         TapeDeactivateDisplayOn();
        }
-       else                                    /* AUTO PAUSE -> NORMAL PLAY */
+       else                                    /* WARP BLIND -> PLAY */
        {
-         if (tape.warp_forward)
-           TapeStopWarpForward();
-
          tape.fast_forward = FALSE;
-         tape.pause_before_end = FALSE;
+         tape.warp_forward = FALSE;
+         tape.deactivate_display = FALSE;
 
-         DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
+         TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
        }
+
+       DrawVideoDisplayCurrentState();
       }
+
       break;
 
     default: