+
+static void TapeStartWarpForward()
+{
+ tape.warp_forward = TRUE;
+
+ if (!tape.fast_forward && !tape.pause_before_death)
+ {
+ tape.pausing = FALSE;
+ tape.deactivate_display = TRUE;
+
+ TapeDeactivateDisplayOn();
+ }
+
+ 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 (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_MAIN)
+ {
+ Request("No game that can be saved!", REQ_CONFIRM);
+
+ return;
+ }
+
+ if (game_status != GAME_MODE_PLAYING)
+ return;
+
+ 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);
+
+ return;
+ }
+
+ if (SaveTapeChecked(tape.level_nr))
+ SaveEngineSnapshot();
+}
+
+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)
+ return;
+
+ if (CheckEngineSnapshot())
+ {
+ TapeStartGamePlaying();
+
+ LoadEngineSnapshot();
+
+ DrawCompleteVideoDisplay();
+
+ tape.playing = TRUE;
+ tape.pausing = TRUE;
+
+ TapeStopWarpForward();
+ TapeAppendRecording();
+
+ if (FrameCounter > 0)
+ return;
+ }
+
+ 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];
+ 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;
+
+ 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;
+ }
+
+#if 0
+ /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
+ printf("(only testing level)\n");
+ continue;
+#endif
+
+ LoadSolutionTape(level_nr);
+
+ if (tape.no_valid_file)
+ {
+ num_tape_missing++;
+
+ 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);
+ }
+
+ printf("\n");
+ printf_line("=", 79);
+
+ CloseAllAndExit(0);
+}
+
+
+/* ---------- new tape button stuff ---------------------------------------- */
+
+static struct
+{
+ int graphic;
+ struct Rect *pos;
+ int gadget_id;
+ char *infotext;
+} tapebutton_info[NUM_TAPE_BUTTONS] =
+{
+ {
+ IMG_TAPE_BUTTON_GFX_EJECT, &tape.button.eject,
+ TAPE_CTRL_ID_EJECT, "eject tape"
+ },
+ {
+ /* (same position as "eject" button) */
+ IMG_TAPE_BUTTON_GFX_EXTRA, &tape.button.eject,
+ TAPE_CTRL_ID_EXTRA, "extra functions"
+ },
+ {
+ IMG_TAPE_BUTTON_GFX_STOP, &tape.button.stop,
+ TAPE_CTRL_ID_STOP, "stop tape"
+ },
+ {
+ IMG_TAPE_BUTTON_GFX_PAUSE, &tape.button.pause,
+ TAPE_CTRL_ID_PAUSE, "pause tape"
+ },
+ {
+ IMG_TAPE_BUTTON_GFX_RECORD, &tape.button.record,
+ TAPE_CTRL_ID_RECORD, "record tape"
+ },
+ {
+ IMG_TAPE_BUTTON_GFX_PLAY, &tape.button.play,
+ TAPE_CTRL_ID_PLAY, "play tape"
+ }
+};
+
+void CreateTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ {
+ struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
+ struct Rect *pos = tapebutton_info[i].pos;
+ struct GadgetInfo *gi;
+ int gd_x = gfx->src_x;
+ int gd_y = gfx->src_y;
+ int gd_xp = gfx->src_x + gfx->pressed_xoffset;
+ int gd_yp = gfx->src_y + gfx->pressed_yoffset;
+ int id = i;
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, tapebutton_info[i].infotext,
+ GDI_X, VX + pos->x,
+ GDI_Y, VY + pos->y,
+ GDI_WIDTH, gfx->width,
+ GDI_HEIGHT, gfx->height,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
+ GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
+ GDI_DIRECT_DRAW, FALSE,
+ 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();
+
+ if (tape.show_game_buttons)
+ MapGameButtons();
+}
+
+void UnmapTapeButtons()
+{
+ int i;
+
+ for (i = 0; i < NUM_TAPE_BUTTONS; i++)
+ UnmapGadget(tape_gadget[i]);
+}
+
+static void HandleTapeButtonsExt(int 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)
+ SaveTapeChecked(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();
+ }
+ }
+ 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;
+ DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
+ }
+ else /* AUTO PAUSE -> NORMAL PLAY */
+ {
+ if (tape.warp_forward)
+ TapeStopWarpForward();
+
+ tape.fast_forward = FALSE;
+ tape.pause_before_death = FALSE;
+
+ DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void HandleTapeButtons(struct GadgetInfo *gi)
+{
+ HandleTapeButtonsExt(gi->custom_id);
+}
+
+void HandleTapeButtonKeys(Key key)
+{
+ boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
+ boolean extra_button_is_active = !eject_button_is_active;
+
+ if (key == setup.shortcut.tape_eject && eject_button_is_active)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
+ else if (key == setup.shortcut.tape_extra && extra_button_is_active)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
+ else if (key == setup.shortcut.tape_stop)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
+ else if (key == setup.shortcut.tape_pause)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
+ else if (key == setup.shortcut.tape_record)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
+ else if (key == setup.shortcut.tape_play)
+ HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);
+}