+
+static void TapeStartWarpForward()
+{
+ tape.warp_forward = TRUE;
+
+#if 1
+ if (!tape.fast_forward && !tape.pause_before_death)
+ {
+ tape.pausing = FALSE;
+ tape.deactivate_display = TRUE;
+
+ TapeDeactivateDisplayOn();
+ }
+#else
+ if (!tape.fast_forward || tape.pause_before_death)
+ {
+ tape.pausing = FALSE;
+ tape.deactivate_display = TRUE;
+
+ TapeDeactivateDisplayOn();
+ }
+#endif
+
+ if (tape.fast_forward || tape.pause_before_death)
+ DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
+ else
+ DrawVideoDisplay(VIDEO_STATE_WARP_ON, 0);
+}
+
+static void TapeStopWarpForward()
+{
+ int state = (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
+
+ tape.warp_forward = FALSE;
+ tape.deactivate_display = FALSE;
+
+ TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
+
+#if 0
+#if 1
+ if (game_status == GAME_MODE_PLAYING)
+#endif
+ {
+ RedrawPlayfield(TRUE, 0,0,0,0);
+ DrawGameDoorValues();
+ }
+#endif
+
+ if (tape.pause_before_death)
+ state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PBEND_ON;
+ else if (tape.fast_forward)
+ state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_FFWD_ON;
+ else
+ state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PLAY_ON;
+
+ DrawVideoDisplay(state, 0);
+}
+
+static void TapeSingleStep()
+{
+ if (options.network)
+ return;
+
+ if (!tape.pausing)
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+
+ tape.single_step = !tape.single_step;
+
+ DrawVideoDisplay((tape.single_step ? VIDEO_STATE_1STEP_ON :
+ VIDEO_STATE_1STEP_OFF), 0);
+}
+
+void TapeQuickSave()
+{
+ if (game_status == GAME_MODE_PLAYING)
+ {
+ if (tape.recording)
+ TapeHaltRecording(); /* prepare tape for saving on-the-fly */
+
+ if (TAPE_IS_EMPTY(tape))
+ Request("No tape that can be saved !", REQ_CONFIRM);
+ else
+ SaveTape(tape.level_nr);
+ }
+ else if (game_status == GAME_MODE_MAIN)
+ Request("No game that can be saved !", REQ_CONFIRM);
+}
+
+void TapeQuickLoad()
+{
+ char *filename = getTapeFilename(level_nr);
+
+ if (!fileExists(filename))
+ {
+ Request("No tape for this level !", REQ_CONFIRM);
+
+ return;
+ }
+
+ if (tape.recording && !Request("Stop recording and load tape ?",
+ REQ_ASK | REQ_STAY_CLOSED))
+ {
+ OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
+
+ return;
+ }
+
+ if (game_status == GAME_MODE_PLAYING || game_status == GAME_MODE_MAIN)
+ {
+ TapeStop();
+ TapeErase();
+
+ LoadTape(level_nr);
+ if (!TAPE_IS_EMPTY(tape))
+ {
+ TapeStartGamePlaying();
+ TapeStartWarpForward();
+
+ tape.quick_resume = TRUE;
+ }
+ else /* this should not happen (basically checked above) */
+ {
+ int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
+
+ Request("No tape for this level !", REQ_CONFIRM | reopen_door);
+ }
+ }
+}
+
+void InsertSolutionTape()
+{
+ if (!TAPE_IS_EMPTY(tape))
+ return;
+
+ LoadSolutionTape(level_nr);
+
+ if (TAPE_IS_EMPTY(tape))
+ Request("No solution tape for this level !", REQ_CONFIRM);
+
+ DrawCompleteVideoDisplay();
+}
+
+
+/* ------------------------------------------------------------------------- *
+ * tape autoplay functions
+ * ------------------------------------------------------------------------- */
+
+void AutoPlayTape()
+{
+ static LevelDirTree *autoplay_leveldir = NULL;
+ static boolean autoplay_initialized = FALSE;
+ static int autoplay_level_nr = -1;
+ static int num_levels_played = 0;
+ static int num_levels_solved = 0;
+ 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)
+ {
+ /* just finished auto-playing tape */
+ 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_TAPES_PER_SET)
+ level_failed[level_nr] = TRUE;
+ }
+ else
+ {
+ DrawCompleteVideoDisplay();
+ audio.sound_enabled = FALSE;
+
+ autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+ global.autoplay_leveldir);
+
+ if (autoplay_leveldir == NULL)
+ Error(ERR_EXIT, "no such level identifier: '%s'",
+ global.autoplay_leveldir);
+
+ leveldir_current = autoplay_leveldir;
+
+ 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;
+
+ printf_line("=", 79);
+ printf("Automatically playing level tapes\n");
+ printf_line("-", 79);
+ printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
+ printf("Level series name: '%s'\n", autoplay_leveldir->name);
+ printf("Level series author: '%s'\n", autoplay_leveldir->author);
+ printf("Number of levels: %d\n", autoplay_leveldir->levels);
+ printf_line("=", 79);
+ printf("\n");
+
+ for (i = 0; i < MAX_TAPES_PER_SET; i++)
+ {
+ level_failed[i] = FALSE;
+ tape_missing[i] = FALSE;
+ }
+
+ autoplay_initialized = TRUE;
+ }
+
+ while (autoplay_level_nr <= autoplay_leveldir->last_level)
+ {
+ level_nr = autoplay_level_nr++;
+
+ if (!global.autoplay_all && !global.autoplay_level[level_nr])
+ continue;
+
+ TapeErase();
+
+ printf("Level %03d: ", level_nr);
+
+ LoadLevel(level_nr);
+ if (level.no_valid_file)
+ {
+ printf("(no level)\n");
+ continue;
+ }
+
+ LoadSolutionTape(level_nr);
+#if 1
+ if (tape.no_valid_file)
+#else
+ 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;
+ }
+
+ printf("playing tape ... ");
+
+ TapeStartGamePlaying();
+ TapeStartWarpForward();
+
+ return;
+ }
+
+ printf("\n");
+ printf_line("=", 79);
+ printf("Number of levels played: %d\n", num_levels_played);
+ printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
+ (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
+ printf_line("-", 79);
+ printf("Summary (for automatic parsing by scripts):\n");
+ printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
+ autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
+ (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
+
+ if (num_levels_played != num_levels_solved)
+ {
+ printf(", FAILED:");
+ 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);
+
+ CloseAllAndExit(0);
+}
+
+
+/* ---------- new tape button stuff ---------------------------------------- */
+
+/* graphic position values for tape buttons */
+#define TAPE_BUTTON_XSIZE 18
+#define TAPE_BUTTON_YSIZE 18
+#define TAPE_BUTTON_XPOS 5
+#define TAPE_BUTTON_YPOS 77
+
+#define TAPE_BUTTON_EJECT_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_EXTRA_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_STOP_XPOS (TAPE_BUTTON_XPOS + 1 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_PAUSE_XPOS (TAPE_BUTTON_XPOS + 2 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_RECORD_XPOS (TAPE_BUTTON_XPOS + 3 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_PLAY_XPOS (TAPE_BUTTON_XPOS + 4 * TAPE_BUTTON_XSIZE)
+
+static struct
+{
+ int x, y;
+ int gadget_id;
+ char *infotext;
+} tapebutton_info[NUM_TAPE_BUTTONS] =
+{
+ {
+ TAPE_BUTTON_EJECT_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_EJECT,
+ "eject tape"
+ },
+ {
+ TAPE_BUTTON_EXTRA_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_EXTRA,
+ "extra functions"
+ },
+ {
+ TAPE_BUTTON_STOP_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_STOP,
+ "stop tape"
+ },
+ {
+ TAPE_BUTTON_PAUSE_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_PAUSE,
+ "pause tape"
+ },
+ {
+ TAPE_BUTTON_RECORD_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_RECORD,
+ "record tape"
+ },
+ {
+ TAPE_BUTTON_PLAY_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_PLAY,
+ "play tape"
+ }
+};
+
+void CreateTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ {
+ Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
+ struct GadgetInfo *gi;
+ int gd_xoffset, gd_yoffset;
+ int gd_x1, gd_x2, gd_y;
+ int id = i;
+
+ gd_xoffset = tapebutton_info[i].x;
+ gd_yoffset = tapebutton_info[i].y;
+ gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
+ gd_y = DOOR_GFX_PAGEY2 + gd_yoffset;
+
+ if (i == TAPE_CTRL_ID_EXTRA)
+ {
+ gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
+ }
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, tapebutton_info[i].infotext,
+ GDI_X, VX + gd_xoffset,
+ GDI_Y, VY + gd_yoffset,
+ GDI_WIDTH, TAPE_BUTTON_XSIZE,
+ GDI_HEIGHT, TAPE_BUTTON_YSIZE,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
+ GDI_EVENT_MASK, GD_EVENT_RELEASED,
+ GDI_CALLBACK_ACTION, HandleTapeButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ tape_gadget[id] = gi;
+ }
+}
+
+void FreeTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ FreeGadget(tape_gadget[i]);
+}
+
+void MapTapeEjectButton()
+{
+ UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
+ MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
+}
+
+void MapTapeWarpButton()
+{
+ UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
+ MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
+}
+
+void MapTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ if (i != TAPE_CTRL_ID_EXTRA)
+ MapGadget(tape_gadget[i]);
+
+ if (tape.recording || tape.playing)
+ MapTapeWarpButton();
+}
+
+void UnmapTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ UnmapGadget(tape_gadget[i]);
+}
+
+static void HandleTapeButtons(struct GadgetInfo *gi)
+{
+ int id = gi->custom_id;
+
+ if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
+ return;
+
+ switch (id)
+ {
+ case TAPE_CTRL_ID_EJECT:
+ TapeStop();
+ if (TAPE_IS_EMPTY(tape))
+ {
+ LoadTape(level_nr);
+ if (TAPE_IS_EMPTY(tape))
+ Request("No tape for this level !", REQ_CONFIRM);
+ }
+ else
+ {
+ if (tape.changed)
+ SaveTape(tape.level_nr);
+ TapeErase();
+ }
+ DrawCompleteVideoDisplay();
+ break;
+
+ case TAPE_CTRL_ID_EXTRA:
+ if (tape.playing)
+ {
+ if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
+ {
+ TapeStartWarpForward();
+ }
+ else /* WARP FORWARD PLAY -> PLAY */
+ {
+ TapeStopWarpForward();
+
+#if 0
+ if (tape.pause_before_death)
+ DrawVideoDisplay(VIDEO_STATE_WARP_OFF | VIDEO_STATE_PLAY_ON, 0);
+ else if (tape.fast_forward)
+ DrawVideoDisplay(VIDEO_STATE_WARP_OFF | VIDEO_STATE_FFWD_ON, 0);
+ else
+ DrawVideoDisplay(VIDEO_STATE_WARP_OFF | VIDEO_STATE_PBEND_ON, 0);
+#endif
+ }
+ }
+ 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 */
+ TapeAppendRecording();
+ else
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ }
+ break;
+
+ case TAPE_CTRL_ID_PLAY:
+ if (TAPE_IS_EMPTY(tape))
+ break;
+
+ if (TAPE_IS_STOPPED(tape))
+ {
+ TapeStartGamePlaying();
+ }
+ else if (tape.playing)
+ {
+ if (tape.pausing) /* PAUSE -> PLAY */
+ {
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ }
+ else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
+ {
+ tape.fast_forward = TRUE;
+ DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
+ }
+ else if (!tape.pause_before_death) /* FFWD PLAY -> AUTO PAUSE */
+ {
+ tape.pause_before_death = TRUE;
+#if 1
+ DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
+#else
+ DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY);
+#endif
+ }
+ else /* AUTO PAUSE -> NORMAL PLAY */
+ {
+#if 1
+ if (tape.warp_forward)
+ TapeStopWarpForward();
+#else
+ tape.warp_forward = FALSE;
+#endif
+ tape.fast_forward = FALSE;
+ tape.pause_before_death = FALSE;
+
+#if 1
+ DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
+#else
+ DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_OFF, 0);
+#endif
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}