1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
12 #include "libgame/libgame.h"
22 #define DEBUG_TAPE_WHEN_PLAYING FALSE
24 // tape button identifiers
25 #define TAPE_CTRL_ID_EJECT 0
26 #define TAPE_CTRL_ID_EXTRA 1
27 #define TAPE_CTRL_ID_STOP 2
28 #define TAPE_CTRL_ID_PAUSE 3
29 #define TAPE_CTRL_ID_RECORD 4
30 #define TAPE_CTRL_ID_PLAY 5
31 #define TAPE_CTRL_ID_INSERT_SOLUTION 6
32 #define TAPE_CTRL_ID_PLAY_SOLUTION 7
34 #define NUM_TAPE_BUTTONS 8
36 // values for tape handling
37 #define TAPE_PAUSE_SECONDS_BEFORE_DEATH 5
38 #define TAPE_MIN_SECONDS_FOR_UNDO_BUFFER 20
40 // forward declaration for internal use
41 static void HandleTapeButtons(struct GadgetInfo *);
42 static void TapeStopWarpForward(void);
43 static float GetTapeLengthSecondsFloat(void);
44 static void CopyTapeToUndoBuffer(void);
46 static struct GadgetInfo *tape_gadget[NUM_TAPE_BUTTONS];
47 static struct TapeInfo tape_undo_buffer;
50 // ============================================================================
51 // video tape definitions
52 // ============================================================================
54 #define VIDEO_INFO_OFF (VIDEO_STATE_DATE_OFF | \
55 VIDEO_STATE_TIME_OFF | \
56 VIDEO_STATE_FRAME_OFF)
57 #define VIDEO_STATE_OFF (VIDEO_STATE_PLAY_OFF | \
58 VIDEO_STATE_REC_OFF | \
59 VIDEO_STATE_PAUSE_OFF | \
60 VIDEO_STATE_FFWD_OFF | \
61 VIDEO_STATE_WARP_OFF | \
62 VIDEO_STATE_WARP2_OFF | \
63 VIDEO_STATE_PBEND_OFF | \
64 VIDEO_STATE_1STEP_OFF)
65 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
66 VIDEO_PRESS_REC_OFF | \
67 VIDEO_PRESS_PAUSE_OFF | \
68 VIDEO_PRESS_STOP_OFF | \
69 VIDEO_PRESS_EJECT_OFF)
70 #define VIDEO_ALL_OFF (VIDEO_INFO_OFF | \
74 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
75 VIDEO_STATE_TIME_ON | \
77 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
78 VIDEO_STATE_REC_ON | \
79 VIDEO_STATE_PAUSE_ON | \
80 VIDEO_STATE_FFWD_ON | \
81 VIDEO_STATE_WARP_ON | \
82 VIDEO_STATE_WARP2_ON | \
83 VIDEO_STATE_PBEND_ON | \
85 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
86 VIDEO_PRESS_REC_ON | \
87 VIDEO_PRESS_PAUSE_ON | \
88 VIDEO_PRESS_STOP_ON | \
90 #define VIDEO_ALL_ON (VIDEO_INFO_ON | \
94 #define VIDEO_INFO (VIDEO_INFO_ON | VIDEO_INFO_OFF)
95 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
96 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
97 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
99 #define NUM_TAPE_FUNCTIONS 11
100 #define NUM_TAPE_FUNCTION_PARTS 2
101 #define NUM_TAPE_FUNCTION_STATES 2
104 // ============================================================================
105 // video display functions
106 // ============================================================================
108 static void DrawVideoDisplay_Graphics(unsigned int state, unsigned int value)
117 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
120 { IMG_GFX_TAPE_LABEL_PLAY, &tape.label.play },
121 { IMG_GFX_TAPE_SYMBOL_PLAY, &tape.symbol.play },
124 { IMG_GFX_TAPE_LABEL_RECORD, &tape.label.record },
125 { IMG_GFX_TAPE_SYMBOL_RECORD, &tape.symbol.record },
128 { IMG_GFX_TAPE_LABEL_PAUSE, &tape.label.pause },
129 { IMG_GFX_TAPE_SYMBOL_PAUSE, &tape.symbol.pause },
132 { IMG_GFX_TAPE_LABEL_DATE, &tape.label.date },
136 { IMG_GFX_TAPE_LABEL_TIME, &tape.label.time },
140 // (no label for displaying optional frame)
145 { IMG_GFX_TAPE_LABEL_FAST_FORWARD, &tape.label.fast_forward },
146 { IMG_GFX_TAPE_SYMBOL_FAST_FORWARD, &tape.symbol.fast_forward },
149 { IMG_GFX_TAPE_LABEL_WARP_FORWARD, &tape.label.warp_forward },
150 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD, &tape.symbol.warp_forward },
153 { IMG_GFX_TAPE_LABEL_WARP_FORWARD_BLIND, &tape.label.warp_forward_blind},
154 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD_BLIND, &tape.symbol.warp_forward_blind},
157 { IMG_GFX_TAPE_LABEL_PAUSE_BEFORE_END, &tape.label.pause_before_end },
158 { IMG_GFX_TAPE_SYMBOL_PAUSE_BEFORE_END, &tape.symbol.pause_before_end },
161 { IMG_GFX_TAPE_LABEL_SINGLE_STEP, &tape.label.single_step },
162 { IMG_GFX_TAPE_SYMBOL_SINGLE_STEP, &tape.symbol.single_step },
166 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) // on or off states
168 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) // record, play, ...
170 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) // label or symbol
172 int graphic = video_pos[i][j].graphic;
173 struct XY *pos = video_pos[i][j].pos;
180 if (state & (1 << (i * 2 + k)))
182 struct GraphicInfo *gfx_bg = &graphic_info[IMG_BACKGROUND_TAPE];
183 struct GraphicInfo *gfx = &graphic_info[graphic];
187 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
189 if (value == skip_value)
194 gd_bitmap = gfx->bitmap;
200 gd_bitmap = gfx_bg->bitmap;
201 gd_x = gfx_bg->src_x + pos->x;
202 gd_y = gfx_bg->src_y + pos->y;
205 // some tape graphics may be undefined -- only draw if defined
206 if (gd_bitmap != NULL)
207 BlitBitmap(gd_bitmap, drawto, gd_x, gd_y, gfx->width, gfx->height,
208 VX + pos->x, VY + pos->y);
210 redraw_mask |= REDRAW_DOOR_2;
218 #define DATETIME_NONE (0)
220 #define DATETIME_DATE_YYYY (1 << 0)
221 #define DATETIME_DATE_YY (1 << 1)
222 #define DATETIME_DATE_MON (1 << 2)
223 #define DATETIME_DATE_MM (1 << 3)
224 #define DATETIME_DATE_DD (1 << 4)
226 #define DATETIME_TIME_HH (1 << 5)
227 #define DATETIME_TIME_MIN (1 << 6)
228 #define DATETIME_TIME_MM (1 << 7)
229 #define DATETIME_TIME_SS (1 << 8)
231 #define DATETIME_FRAME (1 << 9)
233 #define DATETIME_XOFFSET_1 (1 << 10)
234 #define DATETIME_XOFFSET_2 (1 << 11)
236 #define DATETIME_DATE (DATETIME_DATE_YYYY | \
238 DATETIME_DATE_MON | \
242 #define DATETIME_TIME (DATETIME_TIME_HH | \
243 DATETIME_TIME_MIN | \
247 #define MAX_DATETIME_STRING_SIZE 32
249 static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value)
253 static char *month_shortnames[] =
271 struct TextPosInfo *pos;
276 { &tape.text.date, DATETIME_DATE_DD },
277 { &tape.text.date, DATETIME_DATE_MON | DATETIME_XOFFSET_1 },
278 { &tape.text.date, DATETIME_DATE_YY | DATETIME_XOFFSET_2 },
279 { &tape.text.date_yyyy, DATETIME_DATE_YYYY },
280 { &tape.text.date_yy, DATETIME_DATE_YY },
281 { &tape.text.date_mon, DATETIME_DATE_MON },
282 { &tape.text.date_mm, DATETIME_DATE_MM },
283 { &tape.text.date_dd, DATETIME_DATE_DD },
285 { &tape.text.time, DATETIME_TIME_MIN },
286 { &tape.text.time, DATETIME_TIME_SS | DATETIME_XOFFSET_1 },
287 { &tape.text.time_hh, DATETIME_TIME_HH },
288 { &tape.text.time_mm, DATETIME_TIME_MM },
289 { &tape.text.time_ss, DATETIME_TIME_SS },
291 { &tape.text.frame, DATETIME_FRAME },
293 { NULL, DATETIME_NONE },
296 for (i = 0; datetime_info[i].pos != NULL; i++)
298 struct TextPosInfo *pos = datetime_info[i].pos;
299 int type = datetime_info[i].type;
306 xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset :
307 type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0);
310 if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON))
312 char s[MAX_DATETIME_STRING_SIZE];
313 int year2 = value / 10000;
314 int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
315 int month_index = (value / 100) % 100;
316 int month = month_index + 1;
317 int day = value % 100;
319 strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) :
320 type & DATETIME_DATE_YY ? int2str(year2, 2) :
321 type & DATETIME_DATE_MON ? month_shortnames[month_index] :
322 type & DATETIME_DATE_MM ? int2str(month, 2) :
323 type & DATETIME_DATE_DD ? int2str(day, 2) : ""));
325 DrawText(xpos, ypos, s, pos->font);
327 else if ((type & DATETIME_TIME) && (state & VIDEO_STATE_TIME_ON))
329 char s[MAX_DATETIME_STRING_SIZE];
330 int hh = (value / 3600) % 100;
331 int min = value / 60;
332 int mm = (value / 60) % 60;
335 strcpy(s, (type & DATETIME_TIME_HH ? int2str(hh, 2) :
336 type & DATETIME_TIME_MIN ? int2str(min, 2) :
337 type & DATETIME_TIME_MM ? int2str(mm, 2) :
338 type & DATETIME_TIME_SS ? int2str(ss, 2) : ""));
340 DrawText(xpos, ypos, s, pos->font);
342 else if ((type & DATETIME_FRAME) && (state & VIDEO_STATE_FRAME_ON))
344 DrawText(xpos, ypos, int2str(value, pos->size), pos->font);
349 void DrawVideoDisplay(unsigned int state, unsigned int value)
351 DrawVideoDisplay_Graphics(state, value);
352 DrawVideoDisplay_DateTime(state, value);
355 static void DrawVideoDisplayLabel(unsigned int state)
357 DrawVideoDisplay(state, VIDEO_DISPLAY_LABEL_ONLY);
360 static void DrawVideoDisplaySymbol(unsigned int state)
362 DrawVideoDisplay(state, VIDEO_DISPLAY_SYMBOL_ONLY);
365 static void DrawVideoDisplayCurrentState(void)
369 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
372 state |= VIDEO_STATE_PAUSE_ON;
376 state |= VIDEO_STATE_REC_ON;
378 if (tape.single_step)
379 state |= VIDEO_STATE_1STEP_ON;
381 else if (tape.playing)
383 state |= VIDEO_STATE_PLAY_ON;
387 if (tape.deactivate_display)
388 state |= VIDEO_STATE_WARP2_ON;
389 else if (tape.warp_forward)
390 state |= VIDEO_STATE_WARP_ON;
391 else if (tape.fast_forward)
392 state |= VIDEO_STATE_FFWD_ON;
394 if (tape.pause_before_end)
395 state |= VIDEO_STATE_PBEND_ON;
399 // draw labels and symbols separately to prevent labels overlapping symbols
400 DrawVideoDisplayLabel(state);
401 DrawVideoDisplaySymbol(state);
404 void DrawCompleteVideoDisplay(void)
406 struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
408 // draw tape background
409 BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
410 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
412 // draw tape buttons (forced)
413 RedrawOrRemapTapeButtons();
415 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
419 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
420 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
421 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
422 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
425 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
427 else if (tape.playing)
429 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
430 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
431 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
432 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
435 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
437 else if (tape.date && tape.length)
439 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
440 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
441 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
444 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
448 void TapeDeactivateDisplayOn(void)
450 SetDrawDeactivationMask(REDRAW_FIELD);
451 audio.sound_deactivated = TRUE;
454 void TapeDeactivateDisplayOff(boolean redraw_display)
456 SetDrawDeactivationMask(REDRAW_NONE);
457 audio.sound_deactivated = FALSE;
463 UpdateGameDoorValues();
464 DrawGameDoorValues();
469 // ============================================================================
470 // tape logging functions
471 // ============================================================================
473 static char tape_patch_info[MAX_OUTPUT_LINESIZE];
475 static void PrintTapeReplayProgress(boolean replay_finished)
477 static unsigned int counter_last = -1;
478 unsigned int counter = Counter();
479 unsigned int counter_seconds = counter / 1000;
481 if (!replay_finished)
483 unsigned int counter_delay = 50;
485 if (counter > counter_last + counter_delay)
488 PrintNoLog("Tape %03d %s[%02d:%02d]: [%02d:%02d] - playing tape ... ",
489 level_nr, tape_patch_info,
490 tape.length_seconds / 60, tape.length_seconds % 60,
491 TapeTime / 60, TapeTime % 60);
493 counter_last = counter;
498 float tape_length_seconds = GetTapeLengthSecondsFloat();
501 Print("Tape %03d %s[%02d:%02d]: (%02d:%02d.%03d / %.2f %%) - %s.\n",
502 level_nr, tape_patch_info,
503 tape.length_seconds / 60, tape.length_seconds % 60,
504 counter_seconds / 60, counter_seconds % 60, counter % 1000,
505 (float)counter / tape_length_seconds / 10,
506 tape.auto_play_level_fixed ? "solved and fixed" :
507 tape.auto_play_level_solved ? "solved" :
508 tape.auto_play_level_not_fixable ? "NOT SOLVED, NOT FIXED" :
516 // ============================================================================
517 // tape control functions
518 // ============================================================================
520 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
522 struct tm *lt = localtime(&epoch_seconds);
524 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
527 void TapeSetDateFromNow(void)
529 TapeSetDateFromEpochSeconds(time(NULL));
536 CopyTapeToUndoBuffer();
540 tape.length_frames = 0;
541 tape.length_seconds = 0;
543 if (leveldir_current)
545 strncpy(tape.level_identifier, leveldir_current->identifier,
547 tape.level_identifier[MAX_FILENAME_LEN] = '\0';
550 tape.level_nr = level_nr;
551 tape.pos[tape.counter].delay = 0;
554 tape.random_seed = InitRND(level.random_seed);
556 tape.file_version = FILE_VERSION_ACTUAL;
557 tape.game_version = GAME_VERSION_ACTUAL;
558 tape.engine_version = level.game_version;
560 TapeSetDateFromNow();
562 for (i = 0; i < MAX_PLAYERS; i++)
563 tape.player_participates[i] = FALSE;
565 tape.centered_player_nr_next = -1;
566 tape.set_centered_player = FALSE;
568 // set flags for game actions to default values (may be overwritten later)
569 tape.use_key_actions = TRUE;
570 tape.use_mouse_actions = FALSE;
573 static void TapeRewind(void)
576 tape.delay_played = 0;
577 tape.pause_before_end = FALSE;
578 tape.recording = FALSE;
579 tape.playing = FALSE;
580 tape.fast_forward = FALSE;
581 tape.warp_forward = FALSE;
582 tape.deactivate_display = FALSE;
583 tape.auto_play = (global.autoplay_leveldir != NULL);
584 tape.auto_play_level_solved = FALSE;
585 tape.auto_play_level_fixed = FALSE;
586 tape.auto_play_level_not_fixable = FALSE;
587 tape.quick_resume = FALSE;
588 tape.single_step = FALSE;
590 tape.centered_player_nr_next = -1;
591 tape.set_centered_player = FALSE;
593 InitRND(tape.random_seed);
596 static void TapeSetRandomSeed(int random_seed)
598 tape.random_seed = InitRND(random_seed);
601 void TapeStartRecording(int random_seed)
603 if (!TAPE_IS_STOPPED(tape))
608 TapeSetRandomSeed(random_seed);
610 tape.recording = TRUE;
612 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
613 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
614 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
615 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
619 SetDrawDeactivationMask(REDRAW_NONE);
620 audio.sound_deactivated = FALSE;
622 // required here to update video display if tape door is closed
623 if (GetDoorState() & DOOR_CLOSE_2)
624 OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW);
627 static void TapeStartGameRecording(void)
629 StartGameActions(network.enabled, TRUE, level.random_seed);
632 static void TapeAppendRecording(void)
634 if (!tape.playing || !tape.pausing)
638 tape.playing = FALSE;
639 tape.fast_forward = FALSE;
640 tape.warp_forward = FALSE;
641 tape.pause_before_end = FALSE;
642 tape.deactivate_display = FALSE;
645 tape.recording = TRUE;
648 // set current delay (for last played move)
649 tape.pos[tape.counter].delay = tape.delay_played;
652 TapeSetDateFromNow();
654 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
655 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
657 UpdateAndDisplayGameControlValues();
660 void TapeHaltRecording(void)
664 // initialize delay for next tape entry (to be able to continue recording)
665 if (tape.counter < MAX_TAPE_LEN)
666 tape.pos[tape.counter].delay = 0;
668 tape.length = tape.counter;
669 tape.length_frames = GetTapeLengthFrames();
670 tape.length_seconds = GetTapeLengthSeconds();
673 void TapeStopRecording(void)
678 tape.recording = FALSE;
679 tape.pausing = FALSE;
681 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
682 MapTapeEjectButton();
685 boolean TapeAddAction(byte action[MAX_TAPE_ACTIONS])
689 if (tape.pos[tape.counter].delay > 0) // already stored action
691 boolean changed_events = FALSE;
693 for (i = 0; i < MAX_TAPE_ACTIONS; i++)
694 if (tape.pos[tape.counter].action[i] != action[i])
695 changed_events = TRUE;
697 if (changed_events || tape.pos[tape.counter].delay >= 255)
699 if (tape.counter >= MAX_TAPE_LEN - 1)
703 tape.pos[tape.counter].delay = 0;
706 tape.pos[tape.counter].delay++;
709 if (tape.pos[tape.counter].delay == 0) // store new action
711 for (i = 0; i < MAX_TAPE_ACTIONS; i++)
712 tape.pos[tape.counter].action[i] = action[i];
714 tape.pos[tape.counter].delay++;
720 void TapeRecordAction(byte action_raw[MAX_TAPE_ACTIONS])
722 byte action[MAX_TAPE_ACTIONS];
725 if (!tape.recording) // (record action even when tape is paused)
728 for (i = 0; i < MAX_TAPE_ACTIONS; i++)
729 action[i] = action_raw[i];
731 if (tape.use_key_actions && tape.set_centered_player)
733 for (i = 0; i < MAX_PLAYERS; i++)
734 if (tape.centered_player_nr_next == i ||
735 tape.centered_player_nr_next == -1)
736 action[i] |= KEY_SET_FOCUS;
738 tape.set_centered_player = FALSE;
741 if (!TapeAddAction(action))
745 void TapeTogglePause(boolean toggle_mode)
747 if (tape.playing && tape.pausing && (toggle_mode & TAPE_TOGGLE_PLAY_PAUSE))
749 // continue playing in normal mode
750 tape.fast_forward = FALSE;
751 tape.warp_forward = FALSE;
752 tape.deactivate_display = FALSE;
754 tape.pause_before_end = FALSE;
757 tape.pausing = !tape.pausing;
759 if (tape.single_step && (toggle_mode & TAPE_TOGGLE_MANUAL))
760 tape.single_step = FALSE;
762 DrawVideoDisplayCurrentState();
764 if (tape.deactivate_display)
767 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
769 TapeDeactivateDisplayOn();
772 if (tape.quick_resume)
774 tape.quick_resume = FALSE;
776 TapeStopWarpForward();
777 TapeAppendRecording();
779 if (!CheckEngineSnapshotSingle())
780 SaveEngineSnapshotSingle();
782 // restart step/move snapshots after quick loading tape
783 SaveEngineSnapshotToListInitial();
785 // do not map undo/redo buttons after quick loading tape
789 if (game_status == GAME_MODE_PLAYING)
791 if (setup.show_snapshot_buttons && CheckEngineSnapshotList())
794 MapUndoRedoButtons();
795 else if (!tape.single_step)
796 UnmapUndoRedoButtons();
799 ModifyPauseButtons();
803 void TapeStartPlaying(void)
805 if (TAPE_IS_EMPTY(tape))
808 if (!TAPE_IS_STOPPED(tape))
815 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
816 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
817 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
818 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
822 SetDrawDeactivationMask(REDRAW_NONE);
823 audio.sound_deactivated = FALSE;
826 static void TapeStartGamePlaying(void)
833 void TapeStopPlaying(void)
835 tape.playing = FALSE;
836 tape.pausing = FALSE;
838 if (tape.warp_forward)
839 TapeStopWarpForward();
841 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
842 MapTapeEjectButton();
845 byte *TapePlayAction(void)
847 int update_delay = FRAMES_PER_SECOND / 2;
848 boolean update_video_display = (FrameCounter % update_delay == 0);
849 boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
850 static byte action[MAX_TAPE_ACTIONS];
853 if (!tape.playing || tape.pausing)
856 if (tape.pause_before_end) // stop some seconds before end of tape
858 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
860 TapeStopWarpForward();
861 TapeTogglePause(TAPE_TOGGLE_MANUAL);
867 if (tape.counter >= tape.length) // end of tape reached
869 if (tape.warp_forward && !tape.auto_play)
871 TapeStopWarpForward();
872 TapeTogglePause(TAPE_TOGGLE_MANUAL);
882 if (update_video_display && !tape.deactivate_display)
886 if (tape.warp_forward)
887 state |= VIDEO_STATE_WARP(update_draw_label_on);
888 else if (tape.fast_forward)
889 state |= VIDEO_STATE_FFWD(update_draw_label_on);
891 if (tape.pause_before_end)
892 state |= VIDEO_STATE_PBEND(update_draw_label_on);
894 // draw labels and symbols separately to prevent labels overlapping symbols
895 DrawVideoDisplayLabel(state);
896 DrawVideoDisplaySymbol(state);
899 for (i = 0; i < MAX_TAPE_ACTIONS; i++)
900 action[i] = tape.pos[tape.counter].action[i];
902 #if DEBUG_TAPE_WHEN_PLAYING
903 DebugContinued("", "%05d", FrameCounter);
904 for (i = 0; i < MAX_TAPE_ACTIONS; i++)
905 DebugContinued("", " %08x", action[i]);
906 DebugContinued("tape:play", "\n");
909 tape.set_centered_player = FALSE;
910 tape.centered_player_nr_next = -999;
912 if (tape.use_key_actions)
914 for (i = 0; i < MAX_PLAYERS; i++)
916 if (action[i] & KEY_SET_FOCUS)
918 tape.set_centered_player = TRUE;
919 tape.centered_player_nr_next =
920 (tape.centered_player_nr_next == -999 ? i : -1);
923 action[i] &= ~KEY_SET_FOCUS;
928 if (tape.delay_played >= tape.pos[tape.counter].delay)
931 tape.delay_played = 0;
935 PrintTapeReplayProgress(FALSE);
943 TapeTogglePause(TAPE_TOGGLE_MANUAL);
948 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
950 if (tape.date && tape.length)
952 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
953 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
954 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
958 unsigned int GetTapeLengthFrames(void)
960 unsigned int tape_length_frames = 0;
963 if (TAPE_IS_EMPTY(tape))
966 for (i = 0; i < tape.length; i++)
967 tape_length_frames += tape.pos[i].delay;
969 return tape_length_frames;
972 unsigned int GetTapeLengthSeconds(void)
974 return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
977 static float GetTapeLengthSecondsFloat(void)
979 return ((float)GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
982 static void TapeStartWarpForward(int mode)
984 tape.fast_forward = (mode & AUTOPLAY_FFWD);
985 tape.warp_forward = (mode & AUTOPLAY_WARP);
986 tape.deactivate_display = (mode & AUTOPLAY_WARP_NO_DISPLAY);
988 tape.pausing = FALSE;
990 if (tape.deactivate_display)
991 TapeDeactivateDisplayOn();
993 DrawVideoDisplayCurrentState();
996 static void TapeStopWarpForward(void)
998 tape.fast_forward = FALSE;
999 tape.warp_forward = FALSE;
1000 tape.deactivate_display = FALSE;
1002 tape.pause_before_end = FALSE;
1004 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
1006 DrawVideoDisplayCurrentState();
1009 static void TapeSingleStep(void)
1011 if (network.enabled)
1015 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1017 tape.single_step = !tape.single_step;
1019 DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
1022 void TapeQuickSave(void)
1024 if (game_status == GAME_MODE_MAIN)
1026 Request("No game that can be saved!", REQ_CONFIRM);
1031 if (game_status != GAME_MODE_PLAYING)
1035 TapeHaltRecording(); // prepare tape for saving on-the-fly
1037 if (TAPE_IS_EMPTY(tape))
1039 Request("No tape that can be saved!", REQ_CONFIRM);
1044 if (SaveTapeChecked(tape.level_nr))
1045 SaveEngineSnapshotSingle();
1048 void TapeQuickLoad(void)
1050 char *filename = getTapeFilename(level_nr);
1052 if (!fileExists(filename))
1054 Request("No tape for this level!", REQ_CONFIRM);
1059 if (tape.recording && !Request("Stop recording and load tape?",
1060 REQ_ASK | REQ_STAY_CLOSED))
1062 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1067 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
1070 if (CheckEngineSnapshotSingle())
1072 TapeStartGamePlaying();
1074 LoadEngineSnapshotSingle();
1076 DrawCompleteVideoDisplay();
1078 tape.playing = TRUE;
1079 tape.pausing = TRUE;
1081 TapeStopWarpForward();
1082 TapeAppendRecording();
1084 // restart step/move snapshots after quick loading tape
1085 SaveEngineSnapshotToListInitial();
1087 if (FrameCounter > 0)
1096 if (!TAPE_IS_EMPTY(tape))
1098 TapeStartGamePlaying();
1099 TapeStartWarpForward(AUTOPLAY_MODE_WARP_NO_DISPLAY);
1101 tape.quick_resume = TRUE;
1103 else // this should not happen (basically checked above)
1105 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1107 Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1111 boolean hasSolutionTape(void)
1113 boolean tape_file_exists = fileExists(getSolutionTapeFilename(level_nr));
1114 boolean level_has_tape = (level.game_engine_type == GAME_ENGINE_TYPE_SP &&
1115 level.native_sp_level->demo.is_available);
1117 return (tape_file_exists || level_has_tape);
1120 boolean InsertSolutionTape(void)
1122 if (!hasSolutionTape())
1124 Request("No solution tape for this level!", REQ_CONFIRM);
1129 if (!TAPE_IS_STOPPED(tape))
1132 // if tape recorder already contains a tape, remove it without asking
1135 LoadSolutionTape(level_nr);
1137 DrawCompleteVideoDisplay();
1139 if (TAPE_IS_EMPTY(tape))
1141 Request("Loading solution tape for this level failed!", REQ_CONFIRM);
1149 boolean PlaySolutionTape(void)
1151 if (!InsertSolutionTape())
1154 TapeStartGamePlaying();
1159 static boolean checkTapesFromSameLevel(struct TapeInfo *t1, struct TapeInfo *t2)
1161 return (strEqual(t1->level_identifier, t2->level_identifier) &&
1162 t1->level_nr == t2->level_nr);
1165 static void CopyTape(struct TapeInfo *tape_from, struct TapeInfo *tape_to)
1167 *tape_to = *tape_from;
1170 static void SwapTapes(struct TapeInfo *t1, struct TapeInfo *t2)
1172 struct TapeInfo tmp = *t1;
1178 static void CopyTapeToUndoBuffer(void)
1180 // copy tapes to undo buffer if large enough (or larger than last undo tape)
1181 // or if the last undo tape is from a different level set or level number
1182 if (tape.length_seconds >= TAPE_MIN_SECONDS_FOR_UNDO_BUFFER ||
1183 tape.length_seconds >= tape_undo_buffer.length_seconds ||
1184 !checkTapesFromSameLevel(&tape, &tape_undo_buffer))
1186 CopyTape(&tape, &tape_undo_buffer);
1192 // only undo tapes from same level set and with same level number
1193 if (!checkTapesFromSameLevel(&tape, &tape_undo_buffer))
1196 if (!TAPE_IS_STOPPED(tape))
1199 // swap last recorded tape with undo buffer, so undo can be reversed
1200 SwapTapes(&tape, &tape_undo_buffer);
1202 DrawCompleteVideoDisplay();
1205 void FixTape_ForceSinglePlayer(void)
1209 /* fix single-player tapes that contain player input for more than one
1210 player (due to a bug in 3.3.1.2 and earlier versions), which results
1211 in playing levels with more than one player in multi-player mode,
1212 even though the tape was originally recorded in single-player mode */
1214 // remove player input actions for all players but the first one
1215 for (i = 1; i < MAX_PLAYERS; i++)
1216 tape.player_participates[i] = FALSE;
1218 tape.changed = TRUE;
1222 // ----------------------------------------------------------------------------
1223 // tape autoplay functions
1224 // ----------------------------------------------------------------------------
1226 void AutoPlayTapes(void)
1228 static LevelDirTree *autoplay_leveldir = NULL;
1229 static boolean autoplay_initialized = FALSE;
1230 static int autoplay_level_nr = -1;
1231 static int num_levels_played = 0;
1232 static int num_levels_solved = 0;
1233 static int num_tapes_patched = 0;
1234 static int num_tape_missing = 0;
1235 static boolean level_failed[MAX_TAPES_PER_SET];
1236 static int patch_nr = 0;
1237 static char *patch_name[] =
1245 static int patch_version_first[] =
1247 VERSION_IDENT(0,0,0,0),
1248 VERSION_IDENT(3,3,1,0),
1249 VERSION_IDENT(0,0,0,0),
1253 static int patch_version_last[] =
1255 VERSION_IDENT(9,9,9,9),
1256 VERSION_IDENT(4,0,1,1),
1257 VERSION_IDENT(4,2,2,0),
1261 static byte patch_property_bit[] =
1264 TAPE_PROPERTY_EM_RANDOM_BUG,
1271 if (autoplay_initialized)
1273 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1275 if (tape.auto_play_level_solved)
1279 // level solved by patched tape -- save fixed tape
1280 char *filename = getTapeFilename(level_nr);
1281 char *filename_orig = getStringCat2(filename, ".orig");
1283 // create backup from old tape, if not yet existing
1284 if (!fileExists(filename_orig))
1285 rename(filename, filename_orig);
1287 SaveTapeToFilename(filename);
1289 tape.auto_play_level_fixed = TRUE;
1290 num_tapes_patched++;
1293 // continue with next tape
1296 else if (patch_name[patch_nr + 1] != NULL)
1298 // level not solved by patched tape -- continue with next patch
1303 // level not solved by any patched tape -- continue with next tape
1304 tape.auto_play_level_not_fixable = TRUE;
1309 // just finished auto-playing tape
1310 PrintTapeReplayProgress(TRUE);
1313 num_levels_played++;
1315 if (tape.auto_play_level_solved)
1316 num_levels_solved++;
1318 if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1319 level_failed[level_nr] = !tape.auto_play_level_solved;
1323 DrawCompleteVideoDisplay();
1325 audio.sound_enabled = FALSE;
1326 setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1328 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1329 global.autoplay_leveldir);
1331 if (autoplay_leveldir == NULL)
1332 Fail("no such level identifier: '%s'", global.autoplay_leveldir);
1334 leveldir_current = autoplay_leveldir;
1336 if (autoplay_leveldir->first_level < 0)
1337 autoplay_leveldir->first_level = 0;
1338 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1339 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1341 autoplay_level_nr = autoplay_leveldir->first_level;
1344 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1345 Print("Automatically fixing level tapes\n");
1347 Print("Automatically playing level tapes\n");
1349 Print("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1350 Print("Level series name: '%s'\n", autoplay_leveldir->name);
1351 Print("Level series author: '%s'\n", autoplay_leveldir->author);
1352 Print("Number of levels: %d\n", autoplay_leveldir->levels);
1356 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1357 level_failed[i] = FALSE;
1359 // only private tapes may be modified
1360 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1361 options.mytapes = TRUE;
1363 autoplay_initialized = TRUE;
1368 if (global.autoplay_mode != AUTOPLAY_MODE_FIX || patch_nr == 0)
1369 level_nr = autoplay_level_nr++;
1371 if (level_nr > autoplay_leveldir->last_level)
1374 // set patch info (required for progress output)
1375 strcpy(tape_patch_info, "");
1376 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1377 snprintf(tape_patch_info, MAX_OUTPUT_LINESIZE, "[%-13s] ",
1378 patch_name[patch_nr]);
1380 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1385 LoadLevel(level_nr);
1387 if (level.no_level_file || level.no_valid_file)
1389 Print("Tape %03d: (no level found)\n", level_nr);
1395 // ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY
1396 Print("Tape %03d: (only testing level)\n", level_nr);
1400 if (options.mytapes)
1403 LoadSolutionTape(level_nr);
1405 if (tape.no_valid_file)
1409 Print("Tape %03d: (no tape found)\n", level_nr);
1414 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1416 boolean skip_patch = FALSE;
1418 if (tape.engine_version < patch_version_first[patch_nr] ||
1419 tape.engine_version > patch_version_last[patch_nr])
1421 Print("Tape %03d %s[%02d:%02d]: (%s %d.%d.%d.%d) - skipped.\n",
1422 level_nr, tape_patch_info,
1423 tape.length_seconds / 60, tape.length_seconds % 60,
1424 "not suitable for version",
1425 (tape.engine_version / 1000000) % 100,
1426 (tape.engine_version / 10000 ) % 100,
1427 (tape.engine_version / 100 ) % 100,
1428 (tape.engine_version ) % 100);
1433 if (strEqual(patch_name[patch_nr], "screen_34x34") &&
1434 tape.num_participating_players == 1)
1436 Print("Tape %03d %s[%02d:%02d]: (%s) - skipped.\n",
1437 level_nr, tape_patch_info,
1438 tape.length_seconds / 60, tape.length_seconds % 60,
1439 "not suitable for single player tapes");
1446 if (patch_name[patch_nr + 1] != NULL)
1448 // continue with next patch
1453 // continue with next tape
1460 if (strEqual(patch_name[patch_nr], "screen_34x34"))
1462 tape.scr_fieldx = SCR_FIELDX_DEFAULT * 2;
1463 tape.scr_fieldy = SCR_FIELDY_DEFAULT * 2;
1467 tape.property_bits |= patch_property_bit[patch_nr];
1473 TapeStartGamePlaying();
1474 TapeStartWarpForward(global.autoplay_mode);
1481 Print("Number of levels played: %d\n", num_levels_played);
1482 Print("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1483 (num_levels_played ? num_levels_solved * 100 / num_levels_played : 0));
1484 if (global.autoplay_mode == AUTOPLAY_MODE_FIX)
1485 Print("Number of tapes fixed: %d\n", num_tapes_patched);
1487 Print("Summary (for automatic parsing by scripts):\n");
1488 Print("LEVELDIR [%s] '%s', SOLVED %d/%d (%d%%)",
1489 (num_levels_played == num_levels_solved ? " OK " : "WARN"),
1490 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1491 (num_levels_played ? num_levels_solved * 100 / num_levels_played : 0));
1493 if (num_levels_played != num_levels_solved)
1496 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1497 if (level_failed[i])
1508 // ----------------------------------------------------------------------------
1509 // tape patch functions
1510 // ----------------------------------------------------------------------------
1512 static boolean PatchTape(struct TapeInfo *tape, char *mode)
1514 Print("[%d.%d.%d.%d]: ",
1515 (tape->engine_version / 1000000) % 100,
1516 (tape->engine_version / 10000 ) % 100,
1517 (tape->engine_version / 100 ) % 100,
1518 (tape->engine_version ) % 100);
1520 if (strEqual(mode, "info"))
1522 Print("property bits == 0x%02x\n", tape->property_bits);
1527 boolean unpatch_tape = FALSE;
1528 boolean use_property_bit = FALSE;
1529 byte property_bitmask = 0;
1531 if (strSuffix(mode, ":0") ||
1532 strSuffix(mode, ":off") ||
1533 strSuffix(mode, ":clear"))
1534 unpatch_tape = TRUE;
1536 if (strEqual(mode, "em_random_bug") || strPrefix(mode, "em_random_bug:"))
1538 // this bug was introduced in version 3.3.1.0 and fixed in version 4.0.1.2
1539 if (tape->engine_version < VERSION_IDENT(3,3,1,0) ||
1540 tape->engine_version >= VERSION_IDENT(4,0,1,2))
1542 Print("This tape version cannot be patched against EM random bug!\n");
1547 property_bitmask = TAPE_PROPERTY_EM_RANDOM_BUG;
1549 use_property_bit = TRUE;
1551 else if (strEqual(mode, "screen_34x34") || strPrefix(mode, "screen_34x34:"))
1553 // this bug only affects team mode tapes
1554 if (tape->num_participating_players == 1)
1556 Print("Only team mode tapes can be patched against screen size bug!\n");
1561 // this bug (that always existed before) was fixed in version 4.2.2.1
1562 if (tape->engine_version >= VERSION_IDENT(4,2,2,1))
1564 Print("This tape version cannot be patched against screen size bug!\n");
1569 int factor = (unpatch_tape ? 1 : 2);
1570 int scr_fieldx_new = SCR_FIELDX_DEFAULT * factor;
1571 int scr_fieldy_new = SCR_FIELDY_DEFAULT * factor;
1573 if (scr_fieldx_new == tape->scr_fieldx &&
1574 scr_fieldy_new == tape->scr_fieldy)
1576 Print("Tape already patched for '%s'!\n", mode);
1581 tape->scr_fieldx = scr_fieldx_new;
1582 tape->scr_fieldy = scr_fieldy_new;
1586 Print("Unknown patch mode '%s'!\n", mode);
1591 // patching tapes using property bits may be used for several patch modes
1592 if (use_property_bit)
1594 byte property_bits = tape->property_bits;
1595 boolean set_property_bit = (unpatch_tape ? FALSE : TRUE);
1597 if (set_property_bit)
1598 property_bits |= property_bitmask;
1600 property_bits &= ~property_bitmask;
1602 if (property_bits == tape->property_bits)
1604 Print("Tape already patched for '%s'!\n", mode);
1609 tape->property_bits = property_bits;
1612 Print("Patching for '%s' ... ", mode);
1617 void PatchTapes(void)
1619 static LevelDirTree *patchtapes_leveldir = NULL;
1620 static int num_tapes_found = 0;
1621 static int num_tapes_patched = 0;
1622 char *mode = global.patchtapes_mode;
1625 if (strEqual(mode, "help"))
1628 Print("Supported patch modes:\n");
1629 Print("- \"em_random_bug\" - use 64-bit random value bug for EM engine\n");
1630 Print("- \"screen_34x34\" - force visible playfield size of 34 x 34\n");
1632 Print("Supported modifiers:\n");
1633 Print("- add \":0\", \":off\" or \":clear\" to patch mode to un-patch tape file\n");
1639 patchtapes_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1640 global.patchtapes_leveldir);
1642 if (patchtapes_leveldir == NULL)
1643 Fail("no such level identifier: '%s'", global.patchtapes_leveldir);
1645 leveldir_current = patchtapes_leveldir;
1647 if (patchtapes_leveldir->first_level < 0)
1648 patchtapes_leveldir->first_level = 0;
1649 if (patchtapes_leveldir->last_level >= MAX_TAPES_PER_SET)
1650 patchtapes_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1653 Print("Patching level tapes for patch mode '%s'\n", mode);
1655 Print("Level series identifier: '%s'\n", patchtapes_leveldir->identifier);
1656 Print("Level series name: '%s'\n", patchtapes_leveldir->name);
1657 Print("Level series author: '%s'\n", patchtapes_leveldir->author);
1658 Print("Number of levels: %d\n", patchtapes_leveldir->levels);
1662 int first_level = patchtapes_leveldir->first_level;
1663 int last_level = patchtapes_leveldir->last_level;
1665 for (i = first_level; i <= last_level; i++)
1667 if (!global.patchtapes_all && !global.patchtapes_level[i])
1670 Print("Tape %03d: ", i);
1675 if (tape.no_valid_file)
1677 Print("(no tape found)\n");
1684 if (PatchTape(&tape, mode))
1686 char *filename = getTapeFilename(i);
1687 char *filename_orig = getStringCat2(filename, ".orig");
1689 if (!fileExists(filename_orig))
1690 rename(filename, filename_orig);
1692 SaveTapeToFilename(filename);
1694 Print("patched tape saved.\n");
1696 num_tapes_patched++;
1702 Print("Number of tapes found: %d\n", num_tapes_found);
1703 Print("Number of tapes patched: %d\n", num_tapes_patched);
1710 // ---------- new tape button stuff -------------------------------------------
1718 } tapebutton_info[NUM_TAPE_BUTTONS] =
1721 IMG_GFX_TAPE_BUTTON_EJECT, &tape.button.eject,
1722 TAPE_CTRL_ID_EJECT, "eject tape"
1725 // (same position as "eject" button)
1726 IMG_GFX_TAPE_BUTTON_EXTRA, &tape.button.eject,
1727 TAPE_CTRL_ID_EXTRA, "extra functions"
1730 IMG_GFX_TAPE_BUTTON_STOP, &tape.button.stop,
1731 TAPE_CTRL_ID_STOP, "stop tape"
1734 IMG_GFX_TAPE_BUTTON_PAUSE, &tape.button.pause,
1735 TAPE_CTRL_ID_PAUSE, "pause tape"
1738 IMG_GFX_TAPE_BUTTON_RECORD, &tape.button.record,
1739 TAPE_CTRL_ID_RECORD, "record tape"
1742 IMG_GFX_TAPE_BUTTON_PLAY, &tape.button.play,
1743 TAPE_CTRL_ID_PLAY, "play tape"
1746 IMG_GFX_TAPE_BUTTON_INSERT_SOLUTION,&tape.button.insert_solution,
1747 TAPE_CTRL_ID_INSERT_SOLUTION, "insert solution tape"
1750 IMG_GFX_TAPE_BUTTON_PLAY_SOLUTION, &tape.button.play_solution,
1751 TAPE_CTRL_ID_PLAY_SOLUTION, "play solution tape"
1755 void CreateTapeButtons(void)
1759 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1761 int graphic = tapebutton_info[i].graphic;
1762 struct GraphicInfo *gfx = &graphic_info[graphic];
1763 struct XY *pos = tapebutton_info[i].pos;
1764 struct GadgetInfo *gi;
1765 int gd_x = gfx->src_x;
1766 int gd_y = gfx->src_y;
1767 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1768 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1771 gi = CreateGadget(GDI_CUSTOM_ID, id,
1772 GDI_IMAGE_ID, graphic,
1773 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1776 GDI_WIDTH, gfx->width,
1777 GDI_HEIGHT, gfx->height,
1778 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1779 GDI_STATE, GD_BUTTON_UNPRESSED,
1780 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1781 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1782 GDI_DIRECT_DRAW, FALSE,
1783 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1784 GDI_CALLBACK_ACTION, HandleTapeButtons,
1788 Fail("cannot create gadget");
1790 tape_gadget[id] = gi;
1794 void FreeTapeButtons(void)
1798 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1799 FreeGadget(tape_gadget[i]);
1802 void MapTapeEjectButton(void)
1804 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1805 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1808 void MapTapeWarpButton(void)
1810 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1811 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1814 void MapTapeButtons(void)
1818 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1819 if (i != TAPE_CTRL_ID_EXTRA)
1820 MapGadget(tape_gadget[i]);
1822 if (tape.recording || tape.playing)
1823 MapTapeWarpButton();
1825 if (tape.show_game_buttons)
1826 MapGameButtonsOnTape();
1829 void UnmapTapeButtons(void)
1833 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1834 UnmapGadget(tape_gadget[i]);
1836 if (tape.show_game_buttons)
1837 UnmapGameButtonsOnTape();
1840 void RedrawTapeButtons(void)
1844 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1845 RedrawGadget(tape_gadget[i]);
1847 if (tape.show_game_buttons)
1848 RedrawGameButtonsOnTape();
1851 void RedrawOrRemapTapeButtons(void)
1853 if (tape_gadget[TAPE_CTRL_ID_PLAY]->mapped)
1855 // tape buttons already mapped
1856 RedrawTapeButtons();
1865 static void HandleTapeButtonsExt(int id)
1867 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1872 case TAPE_CTRL_ID_EJECT:
1875 if (TAPE_IS_EMPTY(tape))
1879 if (TAPE_IS_EMPTY(tape))
1880 Request("No tape for this level!", REQ_CONFIRM);
1885 SaveTapeChecked(level_nr);
1890 DrawCompleteVideoDisplay();
1893 case TAPE_CTRL_ID_EXTRA:
1896 tape.pause_before_end = !tape.pause_before_end;
1898 DrawVideoDisplayCurrentState();
1900 else if (tape.recording)
1907 case TAPE_CTRL_ID_STOP:
1912 case TAPE_CTRL_ID_PAUSE:
1913 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1917 case TAPE_CTRL_ID_RECORD:
1918 if (TAPE_IS_STOPPED(tape))
1920 TapeStartGameRecording();
1922 else if (tape.pausing)
1924 if (tape.playing) // PLAY -> PAUSE -> RECORD
1925 TapeAppendRecording();
1927 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1932 case TAPE_CTRL_ID_PLAY:
1933 if (tape.recording && tape.pausing) // PAUSE -> RECORD
1935 // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1937 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1940 if (TAPE_IS_EMPTY(tape))
1943 if (TAPE_IS_STOPPED(tape))
1945 TapeStartGamePlaying();
1947 else if (tape.playing)
1949 if (tape.pausing) // PAUSE -> PLAY
1951 TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE);
1953 else if (!tape.fast_forward) // PLAY -> FFWD
1955 tape.fast_forward = TRUE;
1957 else if (!tape.warp_forward) // FFWD -> WARP
1959 tape.warp_forward = TRUE;
1961 else if (!tape.deactivate_display) // WARP -> WARP BLIND
1963 tape.deactivate_display = TRUE;
1965 TapeDeactivateDisplayOn();
1967 else // WARP BLIND -> PLAY
1969 tape.fast_forward = FALSE;
1970 tape.warp_forward = FALSE;
1971 tape.deactivate_display = FALSE;
1973 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
1976 DrawVideoDisplayCurrentState();
1981 case TAPE_CTRL_ID_INSERT_SOLUTION:
1982 InsertSolutionTape();
1986 case TAPE_CTRL_ID_PLAY_SOLUTION:
1996 static void HandleTapeButtons(struct GadgetInfo *gi)
1998 HandleTapeButtonsExt(gi->custom_id);
2001 void HandleTapeButtonKeys(Key key)
2003 boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
2004 boolean extra_button_is_active = !eject_button_is_active;
2006 if (key == setup.shortcut.tape_eject && eject_button_is_active)
2007 HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
2008 else if (key == setup.shortcut.tape_extra && extra_button_is_active)
2009 HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
2010 else if (key == setup.shortcut.tape_stop)
2011 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
2012 else if (key == setup.shortcut.tape_pause)
2013 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
2014 else if (key == setup.shortcut.tape_record)
2015 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
2016 else if (key == setup.shortcut.tape_play)
2017 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);