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 DrawVideoDisplayCurrentState()
363 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
366 state |= VIDEO_STATE_PAUSE_ON;
370 state |= VIDEO_STATE_REC_ON;
372 if (tape.single_step)
373 state |= VIDEO_STATE_1STEP_ON;
375 else if (tape.playing)
377 state |= VIDEO_STATE_PLAY_ON;
381 if (tape.deactivate_display)
382 state |= VIDEO_STATE_WARP2_ON;
383 else if (tape.warp_forward)
384 state |= VIDEO_STATE_WARP_ON;
385 else if (tape.fast_forward)
386 state |= VIDEO_STATE_FFWD_ON;
388 if (tape.pause_before_end)
389 state |= VIDEO_STATE_PBEND_ON;
393 // draw labels and symbols separately to prevent labels overlapping symbols
394 DrawVideoDisplayLabel(state);
395 DrawVideoDisplaySymbol(state);
398 void DrawCompleteVideoDisplay()
400 struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
402 /* draw tape background */
403 BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
404 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
406 /* draw tape buttons (forced) */
407 RedrawOrRemapTapeButtons();
409 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
413 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
414 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
415 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
416 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
419 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
421 else if (tape.playing)
423 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
424 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
425 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
426 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
429 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
431 else if (tape.date && tape.length)
433 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
434 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
435 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
438 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
442 void TapeDeactivateDisplayOn()
444 SetDrawDeactivationMask(REDRAW_FIELD);
445 audio.sound_deactivated = TRUE;
448 void TapeDeactivateDisplayOff(boolean redraw_display)
450 SetDrawDeactivationMask(REDRAW_NONE);
451 audio.sound_deactivated = FALSE;
456 DrawGameDoorValues();
461 /* ========================================================================= */
462 /* tape logging functions */
463 /* ========================================================================= */
465 void PrintTapeReplayProgress(boolean replay_finished)
467 static unsigned int counter_last = -1;
468 unsigned int counter = Counter();
469 unsigned int counter_seconds = counter / 1000;
471 if (!replay_finished)
473 unsigned int counter_delay = 50;
475 if (counter > counter_last + counter_delay)
478 PrintNoLog("Level %03d [%02d:%02d]: [%02d:%02d] - playing tape ... ",
479 level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
480 TapeTime / 60, TapeTime % 60);
482 counter_last = counter;
488 Print("Level %03d [%02d:%02d]: (%02d:%02d.%03d / %.2f %%) - %s.\n",
489 level_nr, tape.length_seconds / 60, tape.length_seconds % 60,
490 counter_seconds / 60, counter_seconds % 60, counter % 1000,
491 (float)counter / tape.length_seconds / 10,
492 tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
499 /* ========================================================================= */
500 /* tape control functions */
501 /* ========================================================================= */
503 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
505 struct tm *lt = localtime(&epoch_seconds);
507 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
510 void TapeSetDateFromNow()
512 TapeSetDateFromEpochSeconds(time(NULL));
521 tape.length_frames = 0;
522 tape.length_seconds = 0;
524 if (leveldir_current)
525 setString(&tape.level_identifier, leveldir_current->identifier);
527 tape.level_nr = level_nr;
528 tape.pos[tape.counter].delay = 0;
531 tape.random_seed = InitRND(level.random_seed);
533 tape.file_version = FILE_VERSION_ACTUAL;
534 tape.game_version = GAME_VERSION_ACTUAL;
535 tape.engine_version = level.game_version;
537 TapeSetDateFromNow();
539 for (i = 0; i < MAX_PLAYERS; i++)
540 tape.player_participates[i] = FALSE;
542 tape.centered_player_nr_next = -1;
543 tape.set_centered_player = FALSE;
546 static void TapeRewind()
549 tape.delay_played = 0;
550 tape.pause_before_end = FALSE;
551 tape.recording = FALSE;
552 tape.playing = FALSE;
553 tape.fast_forward = FALSE;
554 tape.warp_forward = FALSE;
555 tape.deactivate_display = FALSE;
556 tape.auto_play = (global.autoplay_leveldir != NULL);
557 tape.auto_play_level_solved = FALSE;
558 tape.quick_resume = FALSE;
559 tape.single_step = FALSE;
561 tape.centered_player_nr_next = -1;
562 tape.set_centered_player = FALSE;
564 InitRND(tape.random_seed);
567 static void TapeSetRandomSeed(int random_seed)
569 tape.random_seed = InitRND(random_seed);
572 void TapeStartRecording(int random_seed)
574 if (!TAPE_IS_STOPPED(tape))
579 TapeSetRandomSeed(random_seed);
581 tape.recording = TRUE;
583 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
584 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
585 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
586 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
590 SetDrawDeactivationMask(REDRAW_NONE);
591 audio.sound_deactivated = FALSE;
594 static void TapeStartGameRecording()
596 TapeStartRecording(level.random_seed);
598 #if defined(NETWORK_AVALIABLE)
601 SendToServer_StartPlaying();
610 static void TapeAppendRecording()
612 if (!tape.playing || !tape.pausing)
616 tape.playing = FALSE;
617 tape.fast_forward = FALSE;
618 tape.warp_forward = FALSE;
619 tape.pause_before_end = FALSE;
620 tape.deactivate_display = FALSE;
623 tape.recording = TRUE;
626 // set current delay (for last played move)
627 tape.pos[tape.counter].delay = tape.delay_played;
630 TapeSetDateFromNow();
632 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
633 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
635 UpdateAndDisplayGameControlValues();
638 void TapeHaltRecording()
644 tape.pos[tape.counter].delay = 0;
646 tape.length = tape.counter;
647 tape.length_frames = GetTapeLengthFrames();
648 tape.length_seconds = GetTapeLengthSeconds();
651 void TapeStopRecording()
655 tape.recording = FALSE;
656 tape.pausing = FALSE;
658 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
659 MapTapeEjectButton();
662 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
664 byte action[MAX_PLAYERS];
667 if (!tape.recording) /* (record action even when tape is paused) */
670 if (tape.counter >= MAX_TAPE_LEN - 1)
676 for (i = 0; i < MAX_PLAYERS; i++)
677 action[i] = action_raw[i];
679 if (tape.set_centered_player)
681 for (i = 0; i < MAX_PLAYERS; i++)
682 if (tape.centered_player_nr_next == i ||
683 tape.centered_player_nr_next == -1)
684 action[i] |= KEY_SET_FOCUS;
686 tape.set_centered_player = FALSE;
689 if (tape.pos[tape.counter].delay > 0) /* already stored action */
691 boolean changed_events = FALSE;
693 for (i = 0; i < MAX_PLAYERS; 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)
700 tape.pos[tape.counter].delay = 0;
703 tape.pos[tape.counter].delay++;
706 if (tape.pos[tape.counter].delay == 0) /* store new action */
708 for (i = 0; i < MAX_PLAYERS; i++)
709 tape.pos[tape.counter].action[i] = action[i];
711 tape.pos[tape.counter].delay++;
715 void TapeTogglePause(boolean toggle_mode)
717 if (tape.playing && tape.pausing && (toggle_mode & TAPE_TOGGLE_PLAY_PAUSE))
719 // continue playing in normal mode
720 tape.fast_forward = FALSE;
721 tape.warp_forward = FALSE;
722 tape.deactivate_display = FALSE;
724 tape.pause_before_end = FALSE;
727 tape.pausing = !tape.pausing;
729 if (tape.single_step && (toggle_mode & TAPE_TOGGLE_MANUAL))
730 tape.single_step = FALSE;
732 DrawVideoDisplayCurrentState();
734 if (tape.deactivate_display)
737 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
739 TapeDeactivateDisplayOn();
742 if (tape.quick_resume)
744 tape.quick_resume = FALSE;
746 TapeStopWarpForward();
747 TapeAppendRecording();
749 if (!CheckEngineSnapshotSingle())
750 SaveEngineSnapshotSingle();
752 // restart step/move snapshots after quick loading tape
753 SaveEngineSnapshotToListInitial();
755 // do not map undo/redo buttons after quick loading tape
759 if (setup.show_snapshot_buttons &&
760 game_status == GAME_MODE_PLAYING &&
761 CheckEngineSnapshotList())
764 MapUndoRedoButtons();
765 else if (!tape.single_step)
766 UnmapUndoRedoButtons();
770 void TapeStartPlaying()
772 if (TAPE_IS_EMPTY(tape))
775 if (!TAPE_IS_STOPPED(tape))
782 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
783 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
784 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
785 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
789 SetDrawDeactivationMask(REDRAW_NONE);
790 audio.sound_deactivated = FALSE;
793 static void TapeStartGamePlaying()
800 void TapeStopPlaying()
802 tape.playing = FALSE;
803 tape.pausing = FALSE;
805 if (tape.warp_forward)
806 TapeStopWarpForward();
808 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
809 MapTapeEjectButton();
812 byte *TapePlayAction()
814 int update_delay = FRAMES_PER_SECOND / 2;
815 boolean update_video_display = (FrameCounter % update_delay == 0);
816 boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
817 static byte action[MAX_PLAYERS];
820 if (!tape.playing || tape.pausing)
823 if (tape.pause_before_end) // stop some seconds before end of tape
825 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
827 TapeStopWarpForward();
828 TapeTogglePause(TAPE_TOGGLE_MANUAL);
834 if (tape.counter >= tape.length) /* end of tape reached */
836 if (tape.warp_forward && !tape.auto_play)
838 TapeStopWarpForward();
839 TapeTogglePause(TAPE_TOGGLE_MANUAL);
849 if (update_video_display && !tape.deactivate_display)
853 if (tape.warp_forward)
854 state |= VIDEO_STATE_WARP(update_draw_label_on);
855 else if (tape.fast_forward)
856 state |= VIDEO_STATE_FFWD(update_draw_label_on);
858 if (tape.pause_before_end)
859 state |= VIDEO_STATE_PBEND(update_draw_label_on);
861 // draw labels and symbols separately to prevent labels overlapping symbols
862 DrawVideoDisplayLabel(state);
863 DrawVideoDisplaySymbol(state);
866 for (i = 0; i < MAX_PLAYERS; i++)
867 action[i] = tape.pos[tape.counter].action[i];
869 #if DEBUG_TAPE_WHEN_PLAYING
870 printf("%05d", FrameCounter);
871 for (i = 0; i < MAX_PLAYERS; i++)
872 printf(" %08x", action[i]);
876 tape.set_centered_player = FALSE;
877 tape.centered_player_nr_next = -999;
879 for (i = 0; i < MAX_PLAYERS; i++)
881 if (action[i] & KEY_SET_FOCUS)
883 tape.set_centered_player = TRUE;
884 tape.centered_player_nr_next =
885 (tape.centered_player_nr_next == -999 ? i : -1);
888 action[i] &= ~KEY_SET_FOCUS;
892 if (tape.delay_played >= tape.pos[tape.counter].delay)
895 tape.delay_played = 0;
899 PrintTapeReplayProgress(FALSE);
909 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
911 if (tape.date && tape.length)
913 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
914 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
915 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
919 unsigned int GetTapeLengthFrames()
921 unsigned int tape_length_frames = 0;
924 if (TAPE_IS_EMPTY(tape))
927 for (i = 0; i < tape.length; i++)
928 tape_length_frames += tape.pos[i].delay;
930 return tape_length_frames;
933 unsigned int GetTapeLengthSeconds()
935 return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
938 static void TapeStartWarpForward(int mode)
940 tape.fast_forward = (mode & AUTOPLAY_FFWD);
941 tape.warp_forward = (mode & AUTOPLAY_WARP);
942 tape.deactivate_display = (mode & AUTOPLAY_WARP_NO_DISPLAY);
944 tape.pausing = FALSE;
946 if (tape.deactivate_display)
947 TapeDeactivateDisplayOn();
949 DrawVideoDisplayCurrentState();
952 static void TapeStopWarpForward()
954 tape.fast_forward = FALSE;
955 tape.warp_forward = FALSE;
956 tape.deactivate_display = FALSE;
958 tape.pause_before_end = FALSE;
960 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
962 DrawVideoDisplayCurrentState();
965 static void TapeSingleStep()
971 TapeTogglePause(TAPE_TOGGLE_MANUAL);
973 tape.single_step = !tape.single_step;
975 DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
980 if (game_status == GAME_MODE_MAIN)
982 Request("No game that can be saved!", REQ_CONFIRM);
987 if (game_status != GAME_MODE_PLAYING)
991 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
993 if (TAPE_IS_EMPTY(tape))
995 Request("No tape that can be saved!", REQ_CONFIRM);
1000 if (SaveTapeChecked(tape.level_nr))
1001 SaveEngineSnapshotSingle();
1004 void TapeQuickLoad()
1006 char *filename = getTapeFilename(level_nr);
1008 if (!fileExists(filename))
1010 Request("No tape for this level!", REQ_CONFIRM);
1015 if (tape.recording && !Request("Stop recording and load tape?",
1016 REQ_ASK | REQ_STAY_CLOSED))
1018 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1023 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
1026 if (CheckEngineSnapshotSingle())
1028 TapeStartGamePlaying();
1030 LoadEngineSnapshotSingle();
1032 DrawCompleteVideoDisplay();
1034 tape.playing = TRUE;
1035 tape.pausing = TRUE;
1037 TapeStopWarpForward();
1038 TapeAppendRecording();
1040 // restart step/move snapshots after quick loading tape
1041 SaveEngineSnapshotToListInitial();
1043 if (FrameCounter > 0)
1052 if (!TAPE_IS_EMPTY(tape))
1054 TapeStartGamePlaying();
1055 TapeStartWarpForward(AUTOPLAY_MODE_WARP_NO_DISPLAY);
1057 tape.quick_resume = TRUE;
1059 else /* this should not happen (basically checked above) */
1061 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1063 Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1067 void InsertSolutionTape()
1069 if (!TAPE_IS_EMPTY(tape))
1072 LoadSolutionTape(level_nr);
1074 if (TAPE_IS_EMPTY(tape))
1075 Request("No solution tape for this level!", REQ_CONFIRM);
1077 DrawCompleteVideoDisplay();
1081 /* ------------------------------------------------------------------------- *
1082 * tape autoplay functions
1083 * ------------------------------------------------------------------------- */
1087 static LevelDirTree *autoplay_leveldir = NULL;
1088 static boolean autoplay_initialized = FALSE;
1089 static int autoplay_level_nr = -1;
1090 static int num_levels_played = 0;
1091 static int num_levels_solved = 0;
1092 static int num_tape_missing = 0;
1093 static boolean level_failed[MAX_TAPES_PER_SET];
1096 if (autoplay_initialized)
1098 /* just finished auto-playing tape */
1099 PrintTapeReplayProgress(TRUE);
1101 num_levels_played++;
1103 if (tape.auto_play_level_solved)
1104 num_levels_solved++;
1105 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1106 level_failed[level_nr] = TRUE;
1110 DrawCompleteVideoDisplay();
1112 audio.sound_enabled = FALSE;
1113 setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1115 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1116 global.autoplay_leveldir);
1118 if (autoplay_leveldir == NULL)
1119 Error(ERR_EXIT, "no such level identifier: '%s'",
1120 global.autoplay_leveldir);
1122 leveldir_current = autoplay_leveldir;
1124 if (autoplay_leveldir->first_level < 0)
1125 autoplay_leveldir->first_level = 0;
1126 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1127 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1129 autoplay_level_nr = autoplay_leveldir->first_level;
1132 Print("Automatically playing level tapes\n");
1134 Print("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1135 Print("Level series name: '%s'\n", autoplay_leveldir->name);
1136 Print("Level series author: '%s'\n", autoplay_leveldir->author);
1137 Print("Number of levels: %d\n", autoplay_leveldir->levels);
1141 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1142 level_failed[i] = FALSE;
1144 autoplay_initialized = TRUE;
1147 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1149 level_nr = autoplay_level_nr++;
1151 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1156 LoadLevel(level_nr);
1158 if (level.no_level_file || level.no_valid_file)
1160 Print("Level %03d: (no level)\n", level_nr);
1166 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1167 Print("Level %03d: (only testing level)\n", level_nr);
1171 if (options.mytapes)
1174 LoadSolutionTape(level_nr);
1176 if (tape.no_valid_file)
1180 Print("Level %03d: (no tape)\n", level_nr);
1187 TapeStartGamePlaying();
1188 TapeStartWarpForward(global.autoplay_mode);
1195 Print("Number of levels played: %d\n", num_levels_played);
1196 Print("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1197 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1199 Print("Summary (for automatic parsing by scripts):\n");
1200 Print("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1201 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1202 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1204 if (num_levels_played != num_levels_solved)
1207 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1208 if (level_failed[i])
1219 /* ---------- new tape button stuff ---------------------------------------- */
1227 } tapebutton_info[NUM_TAPE_BUTTONS] =
1230 IMG_GFX_TAPE_BUTTON_EJECT, &tape.button.eject,
1231 TAPE_CTRL_ID_EJECT, "eject tape"
1234 /* (same position as "eject" button) */
1235 IMG_GFX_TAPE_BUTTON_EXTRA, &tape.button.eject,
1236 TAPE_CTRL_ID_EXTRA, "extra functions"
1239 IMG_GFX_TAPE_BUTTON_STOP, &tape.button.stop,
1240 TAPE_CTRL_ID_STOP, "stop tape"
1243 IMG_GFX_TAPE_BUTTON_PAUSE, &tape.button.pause,
1244 TAPE_CTRL_ID_PAUSE, "pause tape"
1247 IMG_GFX_TAPE_BUTTON_RECORD, &tape.button.record,
1248 TAPE_CTRL_ID_RECORD, "record tape"
1251 IMG_GFX_TAPE_BUTTON_PLAY, &tape.button.play,
1252 TAPE_CTRL_ID_PLAY, "play tape"
1256 void CreateTapeButtons()
1260 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1262 struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1263 struct XY *pos = tapebutton_info[i].pos;
1264 struct GadgetInfo *gi;
1265 int gd_x = gfx->src_x;
1266 int gd_y = gfx->src_y;
1267 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1268 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1271 gi = CreateGadget(GDI_CUSTOM_ID, id,
1272 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1275 GDI_WIDTH, gfx->width,
1276 GDI_HEIGHT, gfx->height,
1277 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1278 GDI_STATE, GD_BUTTON_UNPRESSED,
1279 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1280 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1281 GDI_DIRECT_DRAW, FALSE,
1282 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1283 GDI_CALLBACK_ACTION, HandleTapeButtons,
1287 Error(ERR_EXIT, "cannot create gadget");
1289 tape_gadget[id] = gi;
1293 void FreeTapeButtons()
1297 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1298 FreeGadget(tape_gadget[i]);
1301 void MapTapeEjectButton()
1303 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1304 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1307 void MapTapeWarpButton()
1309 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1310 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1313 void MapTapeButtons()
1317 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1318 if (i != TAPE_CTRL_ID_EXTRA)
1319 MapGadget(tape_gadget[i]);
1321 if (tape.recording || tape.playing)
1322 MapTapeWarpButton();
1324 if (tape.show_game_buttons)
1328 void UnmapTapeButtons()
1332 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1333 UnmapGadget(tape_gadget[i]);
1335 if (tape.show_game_buttons)
1339 void RedrawTapeButtons()
1343 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1344 RedrawGadget(tape_gadget[i]);
1346 if (tape.show_game_buttons)
1347 RedrawGameButtons();
1349 // RedrawGadget() may have set REDRAW_ALL if buttons are defined off-area
1350 redraw_mask &= ~REDRAW_ALL;
1353 void RedrawOrRemapTapeButtons()
1355 if (tape_gadget[TAPE_CTRL_ID_PLAY]->mapped)
1357 // tape buttons already mapped
1358 RedrawTapeButtons();
1367 static void HandleTapeButtonsExt(int id)
1369 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1374 case TAPE_CTRL_ID_EJECT:
1377 if (TAPE_IS_EMPTY(tape))
1381 if (TAPE_IS_EMPTY(tape))
1382 Request("No tape for this level!", REQ_CONFIRM);
1387 SaveTapeChecked(tape.level_nr);
1392 DrawCompleteVideoDisplay();
1395 case TAPE_CTRL_ID_EXTRA:
1398 tape.pause_before_end = !tape.pause_before_end;
1400 DrawVideoDisplayCurrentState();
1402 else if (tape.recording)
1409 case TAPE_CTRL_ID_STOP:
1414 case TAPE_CTRL_ID_PAUSE:
1415 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1419 case TAPE_CTRL_ID_RECORD:
1420 if (TAPE_IS_STOPPED(tape))
1422 TapeStartGameRecording();
1424 else if (tape.pausing)
1426 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1427 TapeAppendRecording();
1429 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1434 case TAPE_CTRL_ID_PLAY:
1435 if (tape.recording && tape.pausing) /* PAUSE -> RECORD */
1437 // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1439 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1442 if (TAPE_IS_EMPTY(tape))
1445 if (TAPE_IS_STOPPED(tape))
1447 TapeStartGamePlaying();
1449 else if (tape.playing)
1451 if (tape.pausing) /* PAUSE -> PLAY */
1453 TapeTogglePause(TAPE_TOGGLE_MANUAL | TAPE_TOGGLE_PLAY_PAUSE);
1455 else if (!tape.fast_forward) /* PLAY -> FFWD */
1457 tape.fast_forward = TRUE;
1459 else if (!tape.warp_forward) /* FFWD -> WARP */
1461 tape.warp_forward = TRUE;
1463 else if (!tape.deactivate_display) /* WARP -> WARP BLIND */
1465 tape.deactivate_display = TRUE;
1467 TapeDeactivateDisplayOn();
1469 else /* WARP BLIND -> PLAY */
1471 tape.fast_forward = FALSE;
1472 tape.warp_forward = FALSE;
1473 tape.deactivate_display = FALSE;
1475 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
1478 DrawVideoDisplayCurrentState();
1488 static void HandleTapeButtons(struct GadgetInfo *gi)
1490 HandleTapeButtonsExt(gi->custom_id);
1493 void HandleTapeButtonKeys(Key key)
1495 boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1496 boolean extra_button_is_active = !eject_button_is_active;
1498 if (key == setup.shortcut.tape_eject && eject_button_is_active)
1499 HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1500 else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1501 HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1502 else if (key == setup.shortcut.tape_stop)
1503 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1504 else if (key == setup.shortcut.tape_pause)
1505 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1506 else if (key == setup.shortcut.tape_record)
1507 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1508 else if (key == setup.shortcut.tape_play)
1509 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);