1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
7 // http://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
32 #define NUM_TAPE_BUTTONS 6
34 /* values for tape handling */
35 #define TAPE_PAUSE_SECONDS_BEFORE_DEATH 5
37 /* forward declaration for internal use */
38 static void HandleTapeButtons(struct GadgetInfo *);
39 static void TapeStopWarpForward();
41 static struct GadgetInfo *tape_gadget[NUM_TAPE_BUTTONS];
44 /* ========================================================================= */
45 /* video tape definitions */
46 /* ========================================================================= */
48 #define VIDEO_INFO_OFF (VIDEO_STATE_DATE_OFF | \
49 VIDEO_STATE_TIME_OFF | \
50 VIDEO_STATE_FRAME_OFF)
51 #define VIDEO_STATE_OFF (VIDEO_STATE_PLAY_OFF | \
52 VIDEO_STATE_REC_OFF | \
53 VIDEO_STATE_PAUSE_OFF | \
54 VIDEO_STATE_FFWD_OFF | \
55 VIDEO_STATE_PBEND_OFF | \
56 VIDEO_STATE_1STEP_OFF)
57 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
58 VIDEO_PRESS_REC_OFF | \
59 VIDEO_PRESS_PAUSE_OFF | \
60 VIDEO_PRESS_STOP_OFF | \
61 VIDEO_PRESS_EJECT_OFF)
62 #define VIDEO_ALL_OFF (VIDEO_INFO_OFF | \
66 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
67 VIDEO_STATE_TIME_ON | \
69 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
70 VIDEO_STATE_REC_ON | \
71 VIDEO_STATE_PAUSE_ON | \
72 VIDEO_STATE_FFWD_ON | \
73 VIDEO_STATE_PBEND_ON | \
75 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
76 VIDEO_PRESS_REC_ON | \
77 VIDEO_PRESS_PAUSE_ON | \
78 VIDEO_PRESS_STOP_ON | \
80 #define VIDEO_ALL_ON (VIDEO_INFO_ON | \
84 #define VIDEO_INFO (VIDEO_INFO_ON | VIDEO_INFO_OFF)
85 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
86 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
87 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
89 #define NUM_TAPE_FUNCTIONS 11
90 #define NUM_TAPE_FUNCTION_PARTS 2
91 #define NUM_TAPE_FUNCTION_STATES 2
94 /* ========================================================================= */
95 /* video display functions */
96 /* ========================================================================= */
98 static void DrawVideoDisplay_Graphics(unsigned int state, unsigned int value)
107 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
110 { IMG_GFX_TAPE_LABEL_PLAY, &tape.label.play },
111 { IMG_GFX_TAPE_SYMBOL_PLAY, &tape.symbol.play },
114 { IMG_GFX_TAPE_LABEL_RECORD, &tape.label.record },
115 { IMG_GFX_TAPE_SYMBOL_RECORD, &tape.symbol.record },
118 { IMG_GFX_TAPE_LABEL_PAUSE, &tape.label.pause },
119 { IMG_GFX_TAPE_SYMBOL_PAUSE, &tape.symbol.pause },
122 { IMG_GFX_TAPE_LABEL_DATE, &tape.label.date },
126 { IMG_GFX_TAPE_LABEL_TIME, &tape.label.time },
130 /* (no label for displaying optional frame) */
135 { IMG_GFX_TAPE_LABEL_FAST_FORWARD, &tape.label.fast_forward },
136 { IMG_GFX_TAPE_SYMBOL_FAST_FORWARD, &tape.symbol.fast_forward },
139 { IMG_GFX_TAPE_LABEL_WARP_FORWARD, &tape.label.warp_forward },
140 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD, &tape.symbol.warp_forward },
143 { IMG_GFX_TAPE_LABEL_WARP_FORWARD_BLIND, &tape.label.warp_forward_blind},
144 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD_BLIND, &tape.symbol.warp_forward_blind},
147 { IMG_GFX_TAPE_LABEL_PAUSE_BEFORE_END, &tape.label.pause_before_end },
148 { IMG_GFX_TAPE_SYMBOL_PAUSE_BEFORE_END, &tape.symbol.pause_before_end },
151 { IMG_GFX_TAPE_LABEL_SINGLE_STEP, &tape.label.single_step },
152 { IMG_GFX_TAPE_SYMBOL_SINGLE_STEP, &tape.symbol.single_step },
156 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */
158 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */
160 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */
162 int graphic = video_pos[i][j].graphic;
163 struct XY *pos = video_pos[i][j].pos;
170 if (state & (1 << (i * 2 + k)))
172 struct GraphicInfo *gfx_bg = &graphic_info[IMG_BACKGROUND_TAPE];
173 struct GraphicInfo *gfx = &graphic_info[graphic];
177 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
179 if (value == skip_value)
184 gd_bitmap = gfx->bitmap;
190 gd_bitmap = gfx_bg->bitmap;
191 gd_x = gfx_bg->src_x + pos->x;
192 gd_y = gfx_bg->src_y + pos->y;
195 /* some tape graphics may be undefined -- only draw if defined */
196 if (gd_bitmap != NULL)
197 BlitBitmap(gd_bitmap, drawto, gd_x, gd_y, gfx->width, gfx->height,
198 VX + pos->x, VY + pos->y);
200 redraw_mask |= REDRAW_DOOR_2;
208 #define DATETIME_NONE (0)
210 #define DATETIME_DATE_YYYY (1 << 0)
211 #define DATETIME_DATE_YY (1 << 1)
212 #define DATETIME_DATE_MON (1 << 2)
213 #define DATETIME_DATE_MM (1 << 3)
214 #define DATETIME_DATE_DD (1 << 4)
216 #define DATETIME_TIME_HH (1 << 5)
217 #define DATETIME_TIME_MIN (1 << 6)
218 #define DATETIME_TIME_MM (1 << 7)
219 #define DATETIME_TIME_SS (1 << 8)
221 #define DATETIME_FRAME (1 << 9)
223 #define DATETIME_XOFFSET_1 (1 << 10)
224 #define DATETIME_XOFFSET_2 (1 << 11)
226 #define DATETIME_DATE (DATETIME_DATE_YYYY | \
228 DATETIME_DATE_MON | \
232 #define DATETIME_TIME (DATETIME_TIME_HH | \
233 DATETIME_TIME_MIN | \
237 #define MAX_DATETIME_STRING_SIZE 32
239 static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value)
243 static char *month_shortnames[] =
261 struct TextPosInfo *pos;
266 { &tape.text.date, DATETIME_DATE_DD },
267 { &tape.text.date, DATETIME_DATE_MON | DATETIME_XOFFSET_1 },
268 { &tape.text.date, DATETIME_DATE_YY | DATETIME_XOFFSET_2 },
269 { &tape.text.date_yyyy, DATETIME_DATE_YYYY },
270 { &tape.text.date_yy, DATETIME_DATE_YY },
271 { &tape.text.date_mon, DATETIME_DATE_MON },
272 { &tape.text.date_mm, DATETIME_DATE_MM },
273 { &tape.text.date_dd, DATETIME_DATE_DD },
275 { &tape.text.time, DATETIME_TIME_MIN },
276 { &tape.text.time, DATETIME_TIME_SS | DATETIME_XOFFSET_1 },
277 { &tape.text.time_hh, DATETIME_TIME_HH },
278 { &tape.text.time_mm, DATETIME_TIME_MM },
279 { &tape.text.time_ss, DATETIME_TIME_SS },
281 { &tape.text.frame, DATETIME_FRAME },
283 { NULL, DATETIME_NONE },
286 for (i = 0; datetime_info[i].pos != NULL; i++)
288 struct TextPosInfo *pos = datetime_info[i].pos;
289 int type = datetime_info[i].type;
296 xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset :
297 type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0);
300 if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON))
302 char s[MAX_DATETIME_STRING_SIZE];
303 int year2 = value / 10000;
304 int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
305 int month_index = (value / 100) % 100;
306 int month = month_index + 1;
307 int day = value % 100;
309 strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) :
310 type & DATETIME_DATE_YY ? int2str(year2, 2) :
311 type & DATETIME_DATE_MON ? month_shortnames[month_index] :
312 type & DATETIME_DATE_MM ? int2str(month, 2) :
313 type & DATETIME_DATE_DD ? int2str(day, 2) : ""));
315 DrawText(xpos, ypos, s, pos->font);
317 else if ((type & DATETIME_TIME) && (state & VIDEO_STATE_TIME_ON))
319 char s[MAX_DATETIME_STRING_SIZE];
320 int hh = (value / 3600) % 100;
321 int min = value / 60;
322 int mm = (value / 60) % 60;
325 strcpy(s, (type & DATETIME_TIME_HH ? int2str(hh, 2) :
326 type & DATETIME_TIME_MIN ? int2str(min, 2) :
327 type & DATETIME_TIME_MM ? int2str(mm, 2) :
328 type & DATETIME_TIME_SS ? int2str(ss, 2) : ""));
330 DrawText(xpos, ypos, s, pos->font);
332 else if ((type & DATETIME_FRAME) && (state & VIDEO_STATE_FRAME_ON))
334 DrawText(xpos, ypos, int2str(value, pos->size), pos->font);
339 void DrawVideoDisplay(unsigned int state, unsigned int value)
341 DrawVideoDisplay_Graphics(state, value);
342 DrawVideoDisplay_DateTime(state, value);
345 void DrawVideoDisplayLabel(unsigned int state)
347 DrawVideoDisplay(state, VIDEO_DISPLAY_LABEL_ONLY);
350 void DrawVideoDisplaySymbol(unsigned int state)
352 DrawVideoDisplay(state, VIDEO_DISPLAY_SYMBOL_ONLY);
355 void DrawCompleteVideoDisplay()
357 struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
359 /* draw tape background */
360 BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
361 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
363 /* draw tape buttons (forced) */
367 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
371 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
372 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
373 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
374 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
377 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
379 else if (tape.playing)
381 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
382 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
383 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
384 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
387 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
389 else if (tape.date && tape.length)
391 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
392 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
393 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
396 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
400 void TapeDeactivateDisplayOn()
402 SetDrawDeactivationMask(REDRAW_FIELD);
403 audio.sound_deactivated = TRUE;
406 void TapeDeactivateDisplayOff(boolean redraw_display)
408 SetDrawDeactivationMask(REDRAW_NONE);
409 audio.sound_deactivated = FALSE;
414 DrawGameDoorValues();
419 /* ========================================================================= */
420 /* tape control functions */
421 /* ========================================================================= */
423 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
425 struct tm *lt = localtime(&epoch_seconds);
427 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
430 void TapeSetDateFromNow()
432 TapeSetDateFromEpochSeconds(time(NULL));
441 tape.length_frames = 0;
442 tape.length_seconds = 0;
444 if (leveldir_current)
445 setString(&tape.level_identifier, leveldir_current->identifier);
447 tape.level_nr = level_nr;
448 tape.pos[tape.counter].delay = 0;
451 tape.random_seed = InitRND(level.random_seed);
453 tape.file_version = FILE_VERSION_ACTUAL;
454 tape.game_version = GAME_VERSION_ACTUAL;
455 tape.engine_version = level.game_version;
457 TapeSetDateFromNow();
459 for (i = 0; i < MAX_PLAYERS; i++)
460 tape.player_participates[i] = FALSE;
462 tape.centered_player_nr_next = -1;
463 tape.set_centered_player = FALSE;
466 static void TapeRewind()
469 tape.delay_played = 0;
470 tape.pause_before_end = FALSE;
471 tape.recording = FALSE;
472 tape.playing = FALSE;
473 tape.fast_forward = FALSE;
474 tape.warp_forward = FALSE;
475 tape.deactivate_display = FALSE;
476 tape.auto_play = (global.autoplay_leveldir != NULL);
477 tape.auto_play_level_solved = FALSE;
478 tape.quick_resume = FALSE;
479 tape.single_step = FALSE;
481 tape.centered_player_nr_next = -1;
482 tape.set_centered_player = FALSE;
484 InitRND(tape.random_seed);
487 static void TapeSetRandomSeed(int random_seed)
489 tape.random_seed = InitRND(random_seed);
492 void TapeStartRecording(int random_seed)
494 if (!TAPE_IS_STOPPED(tape))
499 TapeSetRandomSeed(random_seed);
501 tape.recording = TRUE;
503 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
504 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
505 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
506 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
510 SetDrawDeactivationMask(REDRAW_NONE);
511 audio.sound_deactivated = FALSE;
514 static void TapeStartGameRecording()
516 TapeStartRecording(level.random_seed);
518 #if defined(NETWORK_AVALIABLE)
521 SendToServer_StartPlaying();
530 static void TapeAppendRecording()
532 if (!tape.playing || !tape.pausing)
536 tape.playing = FALSE;
537 tape.fast_forward = FALSE;
538 tape.warp_forward = FALSE;
539 tape.pause_before_end = FALSE;
540 tape.deactivate_display = FALSE;
543 tape.recording = TRUE;
546 // set current delay (for last played move)
547 tape.pos[tape.counter].delay = tape.delay_played;
550 TapeSetDateFromNow();
552 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
553 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
555 UpdateAndDisplayGameControlValues();
558 void TapeHaltRecording()
564 tape.pos[tape.counter].delay = 0;
566 tape.length = tape.counter;
567 tape.length_frames = GetTapeLengthFrames();
568 tape.length_seconds = GetTapeLengthSeconds();
571 void TapeStopRecording()
575 tape.recording = FALSE;
576 tape.pausing = FALSE;
578 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
579 MapTapeEjectButton();
582 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
584 byte action[MAX_PLAYERS];
587 if (!tape.recording) /* (record action even when tape is paused) */
590 if (tape.counter >= MAX_TAPE_LEN - 1)
596 for (i = 0; i < MAX_PLAYERS; i++)
597 action[i] = action_raw[i];
599 if (tape.set_centered_player)
601 for (i = 0; i < MAX_PLAYERS; i++)
602 if (tape.centered_player_nr_next == i ||
603 tape.centered_player_nr_next == -1)
604 action[i] |= KEY_SET_FOCUS;
606 tape.set_centered_player = FALSE;
609 if (tape.pos[tape.counter].delay > 0) /* already stored action */
611 boolean changed_events = FALSE;
613 for (i = 0; i < MAX_PLAYERS; i++)
614 if (tape.pos[tape.counter].action[i] != action[i])
615 changed_events = TRUE;
617 if (changed_events || tape.pos[tape.counter].delay >= 255)
620 tape.pos[tape.counter].delay = 0;
623 tape.pos[tape.counter].delay++;
626 if (tape.pos[tape.counter].delay == 0) /* store new action */
628 for (i = 0; i < MAX_PLAYERS; i++)
629 tape.pos[tape.counter].action[i] = action[i];
631 tape.pos[tape.counter].delay++;
635 void TapeTogglePause(boolean toggle_manual)
639 tape.pausing = !tape.pausing;
641 if (tape.single_step && toggle_manual)
642 tape.single_step = FALSE;
644 state |= VIDEO_STATE_PAUSE(tape.pausing);
646 if (tape.pause_before_end)
647 state |= VIDEO_STATE_PBEND(!tape.pausing);
648 else if (tape.fast_forward)
649 state |= VIDEO_STATE_FFWD(!tape.pausing);
652 state |= VIDEO_STATE_PLAY_ON;
654 state |= VIDEO_STATE_1STEP(tape.single_step);
656 DrawVideoDisplay(state, 0);
658 if (tape.warp_forward)
662 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
664 else if (tape.deactivate_display)
666 TapeDeactivateDisplayOn();
668 DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
672 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
675 if (tape.quick_resume)
677 tape.quick_resume = FALSE;
679 TapeStopWarpForward();
680 TapeAppendRecording();
682 if (!CheckEngineSnapshotSingle())
683 SaveEngineSnapshotSingle();
685 // restart step/move snapshots after quick loading tape
686 SaveEngineSnapshotToListInitial();
690 if (setup.show_snapshot_buttons &&
691 game_status == GAME_MODE_PLAYING &&
692 CheckEngineSnapshotList())
695 MapUndoRedoButtons();
696 else if (!tape.single_step)
697 UnmapUndoRedoButtons();
701 void TapeStartPlaying()
703 if (TAPE_IS_EMPTY(tape))
706 if (!TAPE_IS_STOPPED(tape))
713 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
714 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
715 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
716 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
720 SetDrawDeactivationMask(REDRAW_NONE);
721 audio.sound_deactivated = FALSE;
724 static void TapeStartGamePlaying()
731 void TapeStopPlaying()
733 tape.playing = FALSE;
734 tape.pausing = FALSE;
736 if (tape.warp_forward)
737 TapeStopWarpForward();
739 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
740 MapTapeEjectButton();
743 byte *TapePlayAction()
745 int update_delay = FRAMES_PER_SECOND / 2;
746 boolean update_video_display = (FrameCounter % update_delay == 0);
747 boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
748 static byte action[MAX_PLAYERS];
751 if (!tape.playing || tape.pausing)
754 if (tape.pause_before_end) // stop some seconds before end of tape
756 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
758 tape.fast_forward = FALSE;
759 tape.pause_before_end = FALSE;
761 TapeStopWarpForward();
762 TapeTogglePause(TAPE_TOGGLE_MANUAL);
768 if (update_video_display && !tape.deactivate_display)
770 if (tape.pause_before_end)
771 DrawVideoDisplayLabel(VIDEO_STATE_PBEND(update_draw_label_on));
772 else if (tape.fast_forward)
773 DrawVideoDisplayLabel(VIDEO_STATE_FFWD(update_draw_label_on));
775 if (tape.warp_forward)
776 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
779 if (tape.counter >= tape.length) /* end of tape reached */
781 if (tape.warp_forward && !tape.auto_play)
782 TapeTogglePause(TAPE_TOGGLE_MANUAL);
789 for (i = 0; i < MAX_PLAYERS; i++)
790 action[i] = tape.pos[tape.counter].action[i];
792 #if DEBUG_TAPE_WHEN_PLAYING
793 printf("%05d", FrameCounter);
794 for (i = 0; i < MAX_PLAYERS; i++)
795 printf(" %08x", action[i]);
799 tape.set_centered_player = FALSE;
800 tape.centered_player_nr_next = -999;
802 for (i = 0; i < MAX_PLAYERS; i++)
804 if (action[i] & KEY_SET_FOCUS)
806 tape.set_centered_player = TRUE;
807 tape.centered_player_nr_next =
808 (tape.centered_player_nr_next == -999 ? i : -1);
811 action[i] &= ~KEY_SET_FOCUS;
815 if (tape.delay_played >= tape.pos[tape.counter].delay)
818 tape.delay_played = 0;
829 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
831 if (tape.date && tape.length)
833 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
834 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
835 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
839 unsigned int GetTapeLengthFrames()
841 unsigned int tape_length_frames = 0;
844 if (TAPE_IS_EMPTY(tape))
847 for (i = 0; i < tape.length; i++)
848 tape_length_frames += tape.pos[i].delay;
850 return tape_length_frames;
853 unsigned int GetTapeLengthSeconds()
855 return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
858 static void TapeStartWarpForward()
860 tape.warp_forward = TRUE;
862 if (!tape.fast_forward && !tape.pause_before_end)
864 tape.pausing = FALSE;
865 tape.pause_before_end = TRUE;
866 tape.deactivate_display = TRUE;
868 TapeDeactivateDisplayOn();
870 DrawVideoDisplay(VIDEO_STATE_PBEND_ON, 0);
871 DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
875 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
879 static void TapeStopWarpForward()
881 int state = VIDEO_STATE_PAUSE(tape.pausing);
883 if (tape.deactivate_display)
884 tape.pause_before_end = FALSE;
886 tape.warp_forward = FALSE;
887 tape.deactivate_display = FALSE;
889 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
891 state |= VIDEO_STATE_WARP_OFF;
892 state |= (tape.pause_before_end ? VIDEO_STATE_PBEND_ON :
893 tape.fast_forward ? VIDEO_STATE_FFWD_ON :
894 VIDEO_STATE_PLAY_ON);
896 DrawVideoDisplay(state, 0);
899 static void TapeSingleStep()
905 TapeTogglePause(TAPE_TOGGLE_MANUAL);
907 tape.single_step = !tape.single_step;
909 DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
914 if (game_status == GAME_MODE_MAIN)
916 Request("No game that can be saved!", REQ_CONFIRM);
921 if (game_status != GAME_MODE_PLAYING)
925 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
927 if (TAPE_IS_EMPTY(tape))
929 Request("No tape that can be saved!", REQ_CONFIRM);
934 if (SaveTapeChecked(tape.level_nr))
935 SaveEngineSnapshotSingle();
940 char *filename = getTapeFilename(level_nr);
942 if (!fileExists(filename))
944 Request("No tape for this level!", REQ_CONFIRM);
949 if (tape.recording && !Request("Stop recording and load tape?",
950 REQ_ASK | REQ_STAY_CLOSED))
952 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
957 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
960 if (CheckEngineSnapshotSingle())
962 TapeStartGamePlaying();
964 LoadEngineSnapshotSingle();
966 DrawCompleteVideoDisplay();
971 TapeStopWarpForward();
972 TapeAppendRecording();
974 // restart step/move snapshots after quick loading tape
975 SaveEngineSnapshotToListInitial();
977 if (FrameCounter > 0)
986 if (!TAPE_IS_EMPTY(tape))
988 TapeStartGamePlaying();
989 TapeStartWarpForward();
991 tape.quick_resume = TRUE;
993 else /* this should not happen (basically checked above) */
995 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
997 Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1001 void InsertSolutionTape()
1003 if (!TAPE_IS_EMPTY(tape))
1006 LoadSolutionTape(level_nr);
1008 if (TAPE_IS_EMPTY(tape))
1009 Request("No solution tape for this level!", REQ_CONFIRM);
1011 DrawCompleteVideoDisplay();
1015 /* ------------------------------------------------------------------------- *
1016 * tape autoplay functions
1017 * ------------------------------------------------------------------------- */
1021 static LevelDirTree *autoplay_leveldir = NULL;
1022 static boolean autoplay_initialized = FALSE;
1023 static int autoplay_level_nr = -1;
1024 static int num_levels_played = 0;
1025 static int num_levels_solved = 0;
1026 static int num_tape_missing = 0;
1027 static boolean level_failed[MAX_TAPES_PER_SET];
1030 if (autoplay_initialized)
1032 /* just finished auto-playing tape */
1033 printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1035 num_levels_played++;
1037 if (tape.auto_play_level_solved)
1038 num_levels_solved++;
1039 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1040 level_failed[level_nr] = TRUE;
1044 DrawCompleteVideoDisplay();
1046 audio.sound_enabled = FALSE;
1047 setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1049 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1050 global.autoplay_leveldir);
1052 if (autoplay_leveldir == NULL)
1053 Error(ERR_EXIT, "no such level identifier: '%s'",
1054 global.autoplay_leveldir);
1056 leveldir_current = autoplay_leveldir;
1058 if (autoplay_leveldir->first_level < 0)
1059 autoplay_leveldir->first_level = 0;
1060 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1061 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1063 autoplay_level_nr = autoplay_leveldir->first_level;
1065 printf_line("=", 79);
1066 printf("Automatically playing level tapes\n");
1067 printf_line("-", 79);
1068 printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1069 printf("Level series name: '%s'\n", autoplay_leveldir->name);
1070 printf("Level series author: '%s'\n", autoplay_leveldir->author);
1071 printf("Number of levels: %d\n", autoplay_leveldir->levels);
1072 printf_line("=", 79);
1075 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1076 level_failed[i] = FALSE;
1078 autoplay_initialized = TRUE;
1081 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1083 level_nr = autoplay_level_nr++;
1085 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1090 printf("Level %03d: ", level_nr);
1092 LoadLevel(level_nr);
1093 if (level.no_valid_file)
1095 printf("(no level)\n");
1100 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1101 printf("(only testing level)\n");
1105 LoadSolutionTape(level_nr);
1107 if (tape.no_valid_file)
1111 printf("(no tape)\n");
1116 printf("playing tape ... ");
1118 TapeStartGamePlaying();
1120 if (global.autoplay_mode == AUTOPLAY_FFWD)
1121 tape.fast_forward = TRUE;
1123 if (global.autoplay_mode != AUTOPLAY_PLAY)
1124 TapeStartWarpForward();
1130 printf_line("=", 79);
1131 printf("Number of levels played: %d\n", num_levels_played);
1132 printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1133 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1134 printf_line("-", 79);
1135 printf("Summary (for automatic parsing by scripts):\n");
1136 printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1137 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1138 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1140 if (num_levels_played != num_levels_solved)
1142 printf(", FAILED:");
1143 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1144 if (level_failed[i])
1149 printf_line("=", 79);
1155 /* ---------- new tape button stuff ---------------------------------------- */
1163 } tapebutton_info[NUM_TAPE_BUTTONS] =
1166 IMG_GFX_TAPE_BUTTON_EJECT, &tape.button.eject,
1167 TAPE_CTRL_ID_EJECT, "eject tape"
1170 /* (same position as "eject" button) */
1171 IMG_GFX_TAPE_BUTTON_EXTRA, &tape.button.eject,
1172 TAPE_CTRL_ID_EXTRA, "extra functions"
1175 IMG_GFX_TAPE_BUTTON_STOP, &tape.button.stop,
1176 TAPE_CTRL_ID_STOP, "stop tape"
1179 IMG_GFX_TAPE_BUTTON_PAUSE, &tape.button.pause,
1180 TAPE_CTRL_ID_PAUSE, "pause tape"
1183 IMG_GFX_TAPE_BUTTON_RECORD, &tape.button.record,
1184 TAPE_CTRL_ID_RECORD, "record tape"
1187 IMG_GFX_TAPE_BUTTON_PLAY, &tape.button.play,
1188 TAPE_CTRL_ID_PLAY, "play tape"
1192 void CreateTapeButtons()
1196 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1198 struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1199 struct XY *pos = tapebutton_info[i].pos;
1200 struct GadgetInfo *gi;
1201 int gd_x = gfx->src_x;
1202 int gd_y = gfx->src_y;
1203 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1204 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1207 gi = CreateGadget(GDI_CUSTOM_ID, id,
1208 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1211 GDI_WIDTH, gfx->width,
1212 GDI_HEIGHT, gfx->height,
1213 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1214 GDI_STATE, GD_BUTTON_UNPRESSED,
1215 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1216 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1217 GDI_DIRECT_DRAW, FALSE,
1218 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1219 GDI_CALLBACK_ACTION, HandleTapeButtons,
1223 Error(ERR_EXIT, "cannot create gadget");
1225 tape_gadget[id] = gi;
1229 void FreeTapeButtons()
1233 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1234 FreeGadget(tape_gadget[i]);
1237 void MapTapeEjectButton()
1239 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1240 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1243 void MapTapeWarpButton()
1245 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1246 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1249 void MapTapeButtons()
1253 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1254 if (i != TAPE_CTRL_ID_EXTRA)
1255 MapGadget(tape_gadget[i]);
1257 if (tape.recording || tape.playing)
1258 MapTapeWarpButton();
1260 if (tape.show_game_buttons)
1264 void UnmapTapeButtons()
1268 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1269 UnmapGadget(tape_gadget[i]);
1271 if (tape.show_game_buttons)
1275 static void HandleTapeButtonsExt(int id)
1277 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1282 case TAPE_CTRL_ID_EJECT:
1285 if (TAPE_IS_EMPTY(tape))
1289 if (TAPE_IS_EMPTY(tape))
1290 Request("No tape for this level!", REQ_CONFIRM);
1295 SaveTapeChecked(tape.level_nr);
1300 DrawCompleteVideoDisplay();
1303 case TAPE_CTRL_ID_EXTRA:
1306 if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
1308 TapeStartWarpForward();
1310 else if (tape.pausing) /* PAUSE -> WARP FORWARD PLAY */
1312 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1314 else /* WARP FORWARD PLAY -> PLAY */
1316 TapeStopWarpForward();
1319 else if (tape.recording)
1324 case TAPE_CTRL_ID_STOP:
1328 case TAPE_CTRL_ID_PAUSE:
1329 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1332 case TAPE_CTRL_ID_RECORD:
1333 if (TAPE_IS_STOPPED(tape))
1334 TapeStartGameRecording();
1335 else if (tape.pausing)
1337 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1338 TapeAppendRecording();
1340 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1344 case TAPE_CTRL_ID_PLAY:
1345 if (tape.recording && tape.pausing) /* PAUSE -> RECORD */
1347 // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1349 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1352 if (TAPE_IS_EMPTY(tape))
1355 if (TAPE_IS_STOPPED(tape))
1357 TapeStartGamePlaying();
1359 else if (tape.playing)
1361 if (tape.pausing) /* PAUSE -> PLAY */
1363 // continue playing in normal mode
1364 tape.fast_forward = FALSE;
1365 tape.warp_forward = FALSE;
1366 tape.pause_before_end = FALSE;
1367 tape.deactivate_display = FALSE;
1369 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1371 else if (tape.warp_forward &&
1372 !tape.fast_forward) /* WARP FORWARD PLAY -> PLAY */
1374 TapeStopWarpForward();
1376 else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
1378 tape.fast_forward = TRUE;
1380 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1382 else if (!tape.pause_before_end) /* FFWD PLAY -> AUTO PAUSE */
1384 tape.pause_before_end = TRUE;
1386 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1388 if (tape.warp_forward)
1389 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
1391 else /* AUTO PAUSE -> NORMAL PLAY */
1393 if (tape.warp_forward)
1394 TapeStopWarpForward();
1396 tape.fast_forward = FALSE;
1397 tape.pause_before_end = FALSE;
1399 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
1409 static void HandleTapeButtons(struct GadgetInfo *gi)
1411 HandleTapeButtonsExt(gi->custom_id);
1414 void HandleTapeButtonKeys(Key key)
1416 boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1417 boolean extra_button_is_active = !eject_button_is_active;
1419 if (key == setup.shortcut.tape_eject && eject_button_is_active)
1420 HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1421 else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1422 HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1423 else if (key == setup.shortcut.tape_stop)
1424 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1425 else if (key == setup.shortcut.tape_pause)
1426 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1427 else if (key == setup.shortcut.tape_record)
1428 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1429 else if (key == setup.shortcut.tape_play)
1430 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);