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_WARP_OFF | \
56 VIDEO_STATE_WARP2_OFF | \
57 VIDEO_STATE_PBEND_OFF | \
58 VIDEO_STATE_1STEP_OFF)
59 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
60 VIDEO_PRESS_REC_OFF | \
61 VIDEO_PRESS_PAUSE_OFF | \
62 VIDEO_PRESS_STOP_OFF | \
63 VIDEO_PRESS_EJECT_OFF)
64 #define VIDEO_ALL_OFF (VIDEO_INFO_OFF | \
68 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
69 VIDEO_STATE_TIME_ON | \
71 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
72 VIDEO_STATE_REC_ON | \
73 VIDEO_STATE_PAUSE_ON | \
74 VIDEO_STATE_FFWD_ON | \
75 VIDEO_STATE_WARP_ON | \
76 VIDEO_STATE_WARP2_ON | \
77 VIDEO_STATE_PBEND_ON | \
79 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
80 VIDEO_PRESS_REC_ON | \
81 VIDEO_PRESS_PAUSE_ON | \
82 VIDEO_PRESS_STOP_ON | \
84 #define VIDEO_ALL_ON (VIDEO_INFO_ON | \
88 #define VIDEO_INFO (VIDEO_INFO_ON | VIDEO_INFO_OFF)
89 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
90 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
91 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
93 #define NUM_TAPE_FUNCTIONS 11
94 #define NUM_TAPE_FUNCTION_PARTS 2
95 #define NUM_TAPE_FUNCTION_STATES 2
98 /* ========================================================================= */
99 /* video display functions */
100 /* ========================================================================= */
102 static void DrawVideoDisplay_Graphics(unsigned int state, unsigned int value)
111 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
114 { IMG_GFX_TAPE_LABEL_PLAY, &tape.label.play },
115 { IMG_GFX_TAPE_SYMBOL_PLAY, &tape.symbol.play },
118 { IMG_GFX_TAPE_LABEL_RECORD, &tape.label.record },
119 { IMG_GFX_TAPE_SYMBOL_RECORD, &tape.symbol.record },
122 { IMG_GFX_TAPE_LABEL_PAUSE, &tape.label.pause },
123 { IMG_GFX_TAPE_SYMBOL_PAUSE, &tape.symbol.pause },
126 { IMG_GFX_TAPE_LABEL_DATE, &tape.label.date },
130 { IMG_GFX_TAPE_LABEL_TIME, &tape.label.time },
134 /* (no label for displaying optional frame) */
139 { IMG_GFX_TAPE_LABEL_FAST_FORWARD, &tape.label.fast_forward },
140 { IMG_GFX_TAPE_SYMBOL_FAST_FORWARD, &tape.symbol.fast_forward },
143 { IMG_GFX_TAPE_LABEL_WARP_FORWARD, &tape.label.warp_forward },
144 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD, &tape.symbol.warp_forward },
147 { IMG_GFX_TAPE_LABEL_WARP_FORWARD_BLIND, &tape.label.warp_forward_blind},
148 { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD_BLIND, &tape.symbol.warp_forward_blind},
151 { IMG_GFX_TAPE_LABEL_PAUSE_BEFORE_END, &tape.label.pause_before_end },
152 { IMG_GFX_TAPE_SYMBOL_PAUSE_BEFORE_END, &tape.symbol.pause_before_end },
155 { IMG_GFX_TAPE_LABEL_SINGLE_STEP, &tape.label.single_step },
156 { IMG_GFX_TAPE_SYMBOL_SINGLE_STEP, &tape.symbol.single_step },
160 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */
162 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */
164 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */
166 int graphic = video_pos[i][j].graphic;
167 struct XY *pos = video_pos[i][j].pos;
174 if (state & (1 << (i * 2 + k)))
176 struct GraphicInfo *gfx_bg = &graphic_info[IMG_BACKGROUND_TAPE];
177 struct GraphicInfo *gfx = &graphic_info[graphic];
181 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
183 if (value == skip_value)
188 gd_bitmap = gfx->bitmap;
194 gd_bitmap = gfx_bg->bitmap;
195 gd_x = gfx_bg->src_x + pos->x;
196 gd_y = gfx_bg->src_y + pos->y;
199 /* some tape graphics may be undefined -- only draw if defined */
200 if (gd_bitmap != NULL)
201 BlitBitmap(gd_bitmap, drawto, gd_x, gd_y, gfx->width, gfx->height,
202 VX + pos->x, VY + pos->y);
204 redraw_mask |= REDRAW_DOOR_2;
212 #define DATETIME_NONE (0)
214 #define DATETIME_DATE_YYYY (1 << 0)
215 #define DATETIME_DATE_YY (1 << 1)
216 #define DATETIME_DATE_MON (1 << 2)
217 #define DATETIME_DATE_MM (1 << 3)
218 #define DATETIME_DATE_DD (1 << 4)
220 #define DATETIME_TIME_HH (1 << 5)
221 #define DATETIME_TIME_MIN (1 << 6)
222 #define DATETIME_TIME_MM (1 << 7)
223 #define DATETIME_TIME_SS (1 << 8)
225 #define DATETIME_FRAME (1 << 9)
227 #define DATETIME_XOFFSET_1 (1 << 10)
228 #define DATETIME_XOFFSET_2 (1 << 11)
230 #define DATETIME_DATE (DATETIME_DATE_YYYY | \
232 DATETIME_DATE_MON | \
236 #define DATETIME_TIME (DATETIME_TIME_HH | \
237 DATETIME_TIME_MIN | \
241 #define MAX_DATETIME_STRING_SIZE 32
243 static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value)
247 static char *month_shortnames[] =
265 struct TextPosInfo *pos;
270 { &tape.text.date, DATETIME_DATE_DD },
271 { &tape.text.date, DATETIME_DATE_MON | DATETIME_XOFFSET_1 },
272 { &tape.text.date, DATETIME_DATE_YY | DATETIME_XOFFSET_2 },
273 { &tape.text.date_yyyy, DATETIME_DATE_YYYY },
274 { &tape.text.date_yy, DATETIME_DATE_YY },
275 { &tape.text.date_mon, DATETIME_DATE_MON },
276 { &tape.text.date_mm, DATETIME_DATE_MM },
277 { &tape.text.date_dd, DATETIME_DATE_DD },
279 { &tape.text.time, DATETIME_TIME_MIN },
280 { &tape.text.time, DATETIME_TIME_SS | DATETIME_XOFFSET_1 },
281 { &tape.text.time_hh, DATETIME_TIME_HH },
282 { &tape.text.time_mm, DATETIME_TIME_MM },
283 { &tape.text.time_ss, DATETIME_TIME_SS },
285 { &tape.text.frame, DATETIME_FRAME },
287 { NULL, DATETIME_NONE },
290 for (i = 0; datetime_info[i].pos != NULL; i++)
292 struct TextPosInfo *pos = datetime_info[i].pos;
293 int type = datetime_info[i].type;
300 xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset :
301 type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0);
304 if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON))
306 char s[MAX_DATETIME_STRING_SIZE];
307 int year2 = value / 10000;
308 int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
309 int month_index = (value / 100) % 100;
310 int month = month_index + 1;
311 int day = value % 100;
313 strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) :
314 type & DATETIME_DATE_YY ? int2str(year2, 2) :
315 type & DATETIME_DATE_MON ? month_shortnames[month_index] :
316 type & DATETIME_DATE_MM ? int2str(month, 2) :
317 type & DATETIME_DATE_DD ? int2str(day, 2) : ""));
319 DrawText(xpos, ypos, s, pos->font);
321 else if ((type & DATETIME_TIME) && (state & VIDEO_STATE_TIME_ON))
323 char s[MAX_DATETIME_STRING_SIZE];
324 int hh = (value / 3600) % 100;
325 int min = value / 60;
326 int mm = (value / 60) % 60;
329 strcpy(s, (type & DATETIME_TIME_HH ? int2str(hh, 2) :
330 type & DATETIME_TIME_MIN ? int2str(min, 2) :
331 type & DATETIME_TIME_MM ? int2str(mm, 2) :
332 type & DATETIME_TIME_SS ? int2str(ss, 2) : ""));
334 DrawText(xpos, ypos, s, pos->font);
336 else if ((type & DATETIME_FRAME) && (state & VIDEO_STATE_FRAME_ON))
338 DrawText(xpos, ypos, int2str(value, pos->size), pos->font);
343 void DrawVideoDisplay(unsigned int state, unsigned int value)
345 DrawVideoDisplay_Graphics(state, value);
346 DrawVideoDisplay_DateTime(state, value);
349 void DrawVideoDisplayLabel(unsigned int state)
351 DrawVideoDisplay(state, VIDEO_DISPLAY_LABEL_ONLY);
354 void DrawVideoDisplaySymbol(unsigned int state)
356 DrawVideoDisplay(state, VIDEO_DISPLAY_SYMBOL_ONLY);
359 void DrawVideoDisplayPlayState()
363 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
365 state |= VIDEO_STATE_PLAY_ON;
369 state |= VIDEO_STATE_PAUSE_ON;
373 if (tape.deactivate_display)
374 state |= VIDEO_STATE_WARP2_ON;
375 else if (tape.warp_forward)
376 state |= VIDEO_STATE_WARP_ON;
377 else if (tape.fast_forward)
378 state |= VIDEO_STATE_FFWD_ON;
380 if (tape.pause_before_end)
381 state |= VIDEO_STATE_PBEND_ON;
384 // draw labels and symbols separately to prevent labels overlapping symbols
385 DrawVideoDisplayLabel(state);
386 DrawVideoDisplaySymbol(state);
389 void DrawCompleteVideoDisplay()
391 struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
393 /* draw tape background */
394 BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
395 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
397 /* draw tape buttons (forced) */
401 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
405 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
406 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
407 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
408 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
411 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
413 else if (tape.playing)
415 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
416 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
417 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
418 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
421 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
423 else if (tape.date && tape.length)
425 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
426 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
427 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
430 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
434 void TapeDeactivateDisplayOn()
436 SetDrawDeactivationMask(REDRAW_FIELD);
437 audio.sound_deactivated = TRUE;
440 void TapeDeactivateDisplayOff(boolean redraw_display)
442 SetDrawDeactivationMask(REDRAW_NONE);
443 audio.sound_deactivated = FALSE;
448 DrawGameDoorValues();
453 /* ========================================================================= */
454 /* tape control functions */
455 /* ========================================================================= */
457 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
459 struct tm *lt = localtime(&epoch_seconds);
461 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
464 void TapeSetDateFromNow()
466 TapeSetDateFromEpochSeconds(time(NULL));
475 tape.length_frames = 0;
476 tape.length_seconds = 0;
478 if (leveldir_current)
479 setString(&tape.level_identifier, leveldir_current->identifier);
481 tape.level_nr = level_nr;
482 tape.pos[tape.counter].delay = 0;
485 tape.random_seed = InitRND(level.random_seed);
487 tape.file_version = FILE_VERSION_ACTUAL;
488 tape.game_version = GAME_VERSION_ACTUAL;
489 tape.engine_version = level.game_version;
491 TapeSetDateFromNow();
493 for (i = 0; i < MAX_PLAYERS; i++)
494 tape.player_participates[i] = FALSE;
496 tape.centered_player_nr_next = -1;
497 tape.set_centered_player = FALSE;
500 static void TapeRewind()
503 tape.delay_played = 0;
504 tape.pause_before_end = FALSE;
505 tape.recording = FALSE;
506 tape.playing = FALSE;
507 tape.fast_forward = FALSE;
508 tape.warp_forward = FALSE;
509 tape.deactivate_display = FALSE;
510 tape.auto_play = (global.autoplay_leveldir != NULL);
511 tape.auto_play_level_solved = FALSE;
512 tape.quick_resume = FALSE;
513 tape.single_step = FALSE;
515 tape.centered_player_nr_next = -1;
516 tape.set_centered_player = FALSE;
518 InitRND(tape.random_seed);
521 static void TapeSetRandomSeed(int random_seed)
523 tape.random_seed = InitRND(random_seed);
526 void TapeStartRecording(int random_seed)
528 if (!TAPE_IS_STOPPED(tape))
533 TapeSetRandomSeed(random_seed);
535 tape.recording = TRUE;
537 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
538 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
539 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
540 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
544 SetDrawDeactivationMask(REDRAW_NONE);
545 audio.sound_deactivated = FALSE;
548 static void TapeStartGameRecording()
550 TapeStartRecording(level.random_seed);
552 #if defined(NETWORK_AVALIABLE)
555 SendToServer_StartPlaying();
564 static void TapeAppendRecording()
566 if (!tape.playing || !tape.pausing)
570 tape.playing = FALSE;
571 tape.fast_forward = FALSE;
572 tape.warp_forward = FALSE;
573 tape.pause_before_end = FALSE;
574 tape.deactivate_display = FALSE;
577 tape.recording = TRUE;
580 // set current delay (for last played move)
581 tape.pos[tape.counter].delay = tape.delay_played;
584 TapeSetDateFromNow();
586 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
587 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
589 UpdateAndDisplayGameControlValues();
592 void TapeHaltRecording()
598 tape.pos[tape.counter].delay = 0;
600 tape.length = tape.counter;
601 tape.length_frames = GetTapeLengthFrames();
602 tape.length_seconds = GetTapeLengthSeconds();
605 void TapeStopRecording()
609 tape.recording = FALSE;
610 tape.pausing = FALSE;
612 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
613 MapTapeEjectButton();
616 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
618 byte action[MAX_PLAYERS];
621 if (!tape.recording) /* (record action even when tape is paused) */
624 if (tape.counter >= MAX_TAPE_LEN - 1)
630 for (i = 0; i < MAX_PLAYERS; i++)
631 action[i] = action_raw[i];
633 if (tape.set_centered_player)
635 for (i = 0; i < MAX_PLAYERS; i++)
636 if (tape.centered_player_nr_next == i ||
637 tape.centered_player_nr_next == -1)
638 action[i] |= KEY_SET_FOCUS;
640 tape.set_centered_player = FALSE;
643 if (tape.pos[tape.counter].delay > 0) /* already stored action */
645 boolean changed_events = FALSE;
647 for (i = 0; i < MAX_PLAYERS; i++)
648 if (tape.pos[tape.counter].action[i] != action[i])
649 changed_events = TRUE;
651 if (changed_events || tape.pos[tape.counter].delay >= 255)
654 tape.pos[tape.counter].delay = 0;
657 tape.pos[tape.counter].delay++;
660 if (tape.pos[tape.counter].delay == 0) /* store new action */
662 for (i = 0; i < MAX_PLAYERS; i++)
663 tape.pos[tape.counter].action[i] = action[i];
665 tape.pos[tape.counter].delay++;
669 void TapeTogglePause(boolean toggle_manual)
671 tape.pausing = !tape.pausing;
673 if (tape.single_step && toggle_manual)
674 tape.single_step = FALSE;
676 DrawVideoDisplayPlayState();
678 if (tape.warp_forward)
682 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
684 else if (tape.deactivate_display)
686 TapeDeactivateDisplayOn();
688 DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
692 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
695 if (tape.quick_resume)
697 tape.quick_resume = FALSE;
699 TapeStopWarpForward();
700 TapeAppendRecording();
702 if (!CheckEngineSnapshotSingle())
703 SaveEngineSnapshotSingle();
705 // restart step/move snapshots after quick loading tape
706 SaveEngineSnapshotToListInitial();
710 if (setup.show_snapshot_buttons &&
711 game_status == GAME_MODE_PLAYING &&
712 CheckEngineSnapshotList())
715 MapUndoRedoButtons();
716 else if (!tape.single_step)
717 UnmapUndoRedoButtons();
721 void TapeStartPlaying()
723 if (TAPE_IS_EMPTY(tape))
726 if (!TAPE_IS_STOPPED(tape))
733 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
734 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
735 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
736 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
740 SetDrawDeactivationMask(REDRAW_NONE);
741 audio.sound_deactivated = FALSE;
744 static void TapeStartGamePlaying()
751 void TapeStopPlaying()
753 tape.playing = FALSE;
754 tape.pausing = FALSE;
756 if (tape.warp_forward)
757 TapeStopWarpForward();
759 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
760 MapTapeEjectButton();
763 byte *TapePlayAction()
765 int update_delay = FRAMES_PER_SECOND / 2;
766 boolean update_video_display = (FrameCounter % update_delay == 0);
767 boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
768 static byte action[MAX_PLAYERS];
771 if (!tape.playing || tape.pausing)
774 if (tape.pause_before_end) // stop some seconds before end of tape
776 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
778 tape.fast_forward = FALSE;
779 tape.pause_before_end = FALSE;
781 TapeStopWarpForward();
782 TapeTogglePause(TAPE_TOGGLE_MANUAL);
788 if (update_video_display && !tape.deactivate_display)
790 if (tape.pause_before_end)
791 DrawVideoDisplayLabel(VIDEO_STATE_PBEND(update_draw_label_on));
792 else if (tape.fast_forward)
793 DrawVideoDisplayLabel(VIDEO_STATE_FFWD(update_draw_label_on));
795 if (tape.warp_forward)
796 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
799 if (tape.counter >= tape.length) /* end of tape reached */
801 if (tape.warp_forward && !tape.auto_play)
802 TapeTogglePause(TAPE_TOGGLE_MANUAL);
809 for (i = 0; i < MAX_PLAYERS; i++)
810 action[i] = tape.pos[tape.counter].action[i];
812 #if DEBUG_TAPE_WHEN_PLAYING
813 printf("%05d", FrameCounter);
814 for (i = 0; i < MAX_PLAYERS; i++)
815 printf(" %08x", action[i]);
819 tape.set_centered_player = FALSE;
820 tape.centered_player_nr_next = -999;
822 for (i = 0; i < MAX_PLAYERS; i++)
824 if (action[i] & KEY_SET_FOCUS)
826 tape.set_centered_player = TRUE;
827 tape.centered_player_nr_next =
828 (tape.centered_player_nr_next == -999 ? i : -1);
831 action[i] &= ~KEY_SET_FOCUS;
835 if (tape.delay_played >= tape.pos[tape.counter].delay)
838 tape.delay_played = 0;
849 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
851 if (tape.date && tape.length)
853 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
854 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
855 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
859 unsigned int GetTapeLengthFrames()
861 unsigned int tape_length_frames = 0;
864 if (TAPE_IS_EMPTY(tape))
867 for (i = 0; i < tape.length; i++)
868 tape_length_frames += tape.pos[i].delay;
870 return tape_length_frames;
873 unsigned int GetTapeLengthSeconds()
875 return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
878 static void TapeStartWarpForward()
880 tape.warp_forward = TRUE;
882 if (!tape.fast_forward && !tape.pause_before_end)
884 tape.pausing = FALSE;
885 tape.pause_before_end = TRUE;
886 tape.deactivate_display = TRUE;
888 TapeDeactivateDisplayOn();
890 DrawVideoDisplay(VIDEO_STATE_PBEND_ON, 0);
891 DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
895 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
899 static void TapeStopWarpForward()
901 int state = VIDEO_STATE_PAUSE(tape.pausing);
903 if (tape.deactivate_display)
904 tape.pause_before_end = FALSE;
906 tape.warp_forward = FALSE;
907 tape.deactivate_display = FALSE;
909 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
911 state |= VIDEO_STATE_WARP_OFF;
912 state |= (tape.pause_before_end ? VIDEO_STATE_PBEND_ON :
913 tape.fast_forward ? VIDEO_STATE_FFWD_ON :
914 VIDEO_STATE_PLAY_ON);
916 DrawVideoDisplay(state, 0);
919 static void TapeSingleStep()
925 TapeTogglePause(TAPE_TOGGLE_MANUAL);
927 tape.single_step = !tape.single_step;
929 DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
934 if (game_status == GAME_MODE_MAIN)
936 Request("No game that can be saved!", REQ_CONFIRM);
941 if (game_status != GAME_MODE_PLAYING)
945 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
947 if (TAPE_IS_EMPTY(tape))
949 Request("No tape that can be saved!", REQ_CONFIRM);
954 if (SaveTapeChecked(tape.level_nr))
955 SaveEngineSnapshotSingle();
960 char *filename = getTapeFilename(level_nr);
962 if (!fileExists(filename))
964 Request("No tape for this level!", REQ_CONFIRM);
969 if (tape.recording && !Request("Stop recording and load tape?",
970 REQ_ASK | REQ_STAY_CLOSED))
972 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
977 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
980 if (CheckEngineSnapshotSingle())
982 TapeStartGamePlaying();
984 LoadEngineSnapshotSingle();
986 DrawCompleteVideoDisplay();
991 TapeStopWarpForward();
992 TapeAppendRecording();
994 // restart step/move snapshots after quick loading tape
995 SaveEngineSnapshotToListInitial();
997 if (FrameCounter > 0)
1006 if (!TAPE_IS_EMPTY(tape))
1008 TapeStartGamePlaying();
1009 TapeStartWarpForward();
1011 tape.quick_resume = TRUE;
1013 else /* this should not happen (basically checked above) */
1015 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1017 Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1021 void InsertSolutionTape()
1023 if (!TAPE_IS_EMPTY(tape))
1026 LoadSolutionTape(level_nr);
1028 if (TAPE_IS_EMPTY(tape))
1029 Request("No solution tape for this level!", REQ_CONFIRM);
1031 DrawCompleteVideoDisplay();
1035 /* ------------------------------------------------------------------------- *
1036 * tape autoplay functions
1037 * ------------------------------------------------------------------------- */
1041 static LevelDirTree *autoplay_leveldir = NULL;
1042 static boolean autoplay_initialized = FALSE;
1043 static int autoplay_level_nr = -1;
1044 static int num_levels_played = 0;
1045 static int num_levels_solved = 0;
1046 static int num_tape_missing = 0;
1047 static boolean level_failed[MAX_TAPES_PER_SET];
1050 if (autoplay_initialized)
1052 /* just finished auto-playing tape */
1053 printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1055 num_levels_played++;
1057 if (tape.auto_play_level_solved)
1058 num_levels_solved++;
1059 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1060 level_failed[level_nr] = TRUE;
1064 DrawCompleteVideoDisplay();
1066 audio.sound_enabled = FALSE;
1067 setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1069 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1070 global.autoplay_leveldir);
1072 if (autoplay_leveldir == NULL)
1073 Error(ERR_EXIT, "no such level identifier: '%s'",
1074 global.autoplay_leveldir);
1076 leveldir_current = autoplay_leveldir;
1078 if (autoplay_leveldir->first_level < 0)
1079 autoplay_leveldir->first_level = 0;
1080 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1081 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1083 autoplay_level_nr = autoplay_leveldir->first_level;
1085 printf_line("=", 79);
1086 printf("Automatically playing level tapes\n");
1087 printf_line("-", 79);
1088 printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1089 printf("Level series name: '%s'\n", autoplay_leveldir->name);
1090 printf("Level series author: '%s'\n", autoplay_leveldir->author);
1091 printf("Number of levels: %d\n", autoplay_leveldir->levels);
1092 printf_line("=", 79);
1095 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1096 level_failed[i] = FALSE;
1098 autoplay_initialized = TRUE;
1101 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1103 level_nr = autoplay_level_nr++;
1105 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1110 printf("Level %03d: ", level_nr);
1112 LoadLevel(level_nr);
1113 if (level.no_valid_file)
1115 printf("(no level)\n");
1120 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1121 printf("(only testing level)\n");
1125 LoadSolutionTape(level_nr);
1127 if (tape.no_valid_file)
1131 printf("(no tape)\n");
1136 printf("playing tape ... ");
1138 TapeStartGamePlaying();
1140 if (global.autoplay_mode == AUTOPLAY_FFWD)
1141 tape.fast_forward = TRUE;
1143 if (global.autoplay_mode != AUTOPLAY_PLAY)
1144 TapeStartWarpForward();
1150 printf_line("=", 79);
1151 printf("Number of levels played: %d\n", num_levels_played);
1152 printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1153 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1154 printf_line("-", 79);
1155 printf("Summary (for automatic parsing by scripts):\n");
1156 printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1157 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1158 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1160 if (num_levels_played != num_levels_solved)
1162 printf(", FAILED:");
1163 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1164 if (level_failed[i])
1169 printf_line("=", 79);
1175 /* ---------- new tape button stuff ---------------------------------------- */
1183 } tapebutton_info[NUM_TAPE_BUTTONS] =
1186 IMG_GFX_TAPE_BUTTON_EJECT, &tape.button.eject,
1187 TAPE_CTRL_ID_EJECT, "eject tape"
1190 /* (same position as "eject" button) */
1191 IMG_GFX_TAPE_BUTTON_EXTRA, &tape.button.eject,
1192 TAPE_CTRL_ID_EXTRA, "extra functions"
1195 IMG_GFX_TAPE_BUTTON_STOP, &tape.button.stop,
1196 TAPE_CTRL_ID_STOP, "stop tape"
1199 IMG_GFX_TAPE_BUTTON_PAUSE, &tape.button.pause,
1200 TAPE_CTRL_ID_PAUSE, "pause tape"
1203 IMG_GFX_TAPE_BUTTON_RECORD, &tape.button.record,
1204 TAPE_CTRL_ID_RECORD, "record tape"
1207 IMG_GFX_TAPE_BUTTON_PLAY, &tape.button.play,
1208 TAPE_CTRL_ID_PLAY, "play tape"
1212 void CreateTapeButtons()
1216 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1218 struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1219 struct XY *pos = tapebutton_info[i].pos;
1220 struct GadgetInfo *gi;
1221 int gd_x = gfx->src_x;
1222 int gd_y = gfx->src_y;
1223 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1224 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1227 gi = CreateGadget(GDI_CUSTOM_ID, id,
1228 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1231 GDI_WIDTH, gfx->width,
1232 GDI_HEIGHT, gfx->height,
1233 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1234 GDI_STATE, GD_BUTTON_UNPRESSED,
1235 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1236 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1237 GDI_DIRECT_DRAW, FALSE,
1238 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1239 GDI_CALLBACK_ACTION, HandleTapeButtons,
1243 Error(ERR_EXIT, "cannot create gadget");
1245 tape_gadget[id] = gi;
1249 void FreeTapeButtons()
1253 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1254 FreeGadget(tape_gadget[i]);
1257 void MapTapeEjectButton()
1259 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1260 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1263 void MapTapeWarpButton()
1265 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1266 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1269 void MapTapeButtons()
1273 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1274 if (i != TAPE_CTRL_ID_EXTRA)
1275 MapGadget(tape_gadget[i]);
1277 if (tape.recording || tape.playing)
1278 MapTapeWarpButton();
1280 if (tape.show_game_buttons)
1284 void UnmapTapeButtons()
1288 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1289 UnmapGadget(tape_gadget[i]);
1291 if (tape.show_game_buttons)
1295 static void HandleTapeButtonsExt(int id)
1297 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1302 case TAPE_CTRL_ID_EJECT:
1305 if (TAPE_IS_EMPTY(tape))
1309 if (TAPE_IS_EMPTY(tape))
1310 Request("No tape for this level!", REQ_CONFIRM);
1315 SaveTapeChecked(tape.level_nr);
1320 DrawCompleteVideoDisplay();
1323 case TAPE_CTRL_ID_EXTRA:
1326 if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
1328 TapeStartWarpForward();
1330 else if (tape.pausing) /* PAUSE -> WARP FORWARD PLAY */
1332 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1334 else /* WARP FORWARD PLAY -> PLAY */
1336 TapeStopWarpForward();
1339 else if (tape.recording)
1344 case TAPE_CTRL_ID_STOP:
1348 case TAPE_CTRL_ID_PAUSE:
1349 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1352 case TAPE_CTRL_ID_RECORD:
1353 if (TAPE_IS_STOPPED(tape))
1354 TapeStartGameRecording();
1355 else if (tape.pausing)
1357 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1358 TapeAppendRecording();
1360 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1364 case TAPE_CTRL_ID_PLAY:
1365 if (tape.recording && tape.pausing) /* PAUSE -> RECORD */
1367 // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1369 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1372 if (TAPE_IS_EMPTY(tape))
1375 if (TAPE_IS_STOPPED(tape))
1377 TapeStartGamePlaying();
1379 else if (tape.playing)
1381 if (tape.pausing) /* PAUSE -> PLAY */
1383 // continue playing in normal mode
1384 tape.fast_forward = FALSE;
1385 tape.warp_forward = FALSE;
1386 tape.pause_before_end = FALSE;
1387 tape.deactivate_display = FALSE;
1389 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1391 else if (tape.warp_forward &&
1392 !tape.fast_forward) /* WARP FORWARD PLAY -> PLAY */
1394 TapeStopWarpForward();
1396 else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
1398 tape.fast_forward = TRUE;
1400 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1402 else if (!tape.pause_before_end) /* FFWD PLAY -> AUTO PAUSE */
1404 tape.pause_before_end = TRUE;
1406 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1408 if (tape.warp_forward)
1409 DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
1411 else /* AUTO PAUSE -> NORMAL PLAY */
1413 if (tape.warp_forward)
1414 TapeStopWarpForward();
1416 tape.fast_forward = FALSE;
1417 tape.pause_before_end = FALSE;
1419 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
1429 static void HandleTapeButtons(struct GadgetInfo *gi)
1431 HandleTapeButtonsExt(gi->custom_id);
1434 void HandleTapeButtonKeys(Key key)
1436 boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1437 boolean extra_button_is_active = !eject_button_is_active;
1439 if (key == setup.shortcut.tape_eject && eject_button_is_active)
1440 HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1441 else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1442 HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1443 else if (key == setup.shortcut.tape_stop)
1444 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1445 else if (key == setup.shortcut.tape_pause)
1446 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1447 else if (key == setup.shortcut.tape_record)
1448 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1449 else if (key == setup.shortcut.tape_play)
1450 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);