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 /* some positions in the video tape control window */
49 #define VIDEO_DATE_LABEL_XPOS (VIDEO_DISPLAY1_XPOS)
50 #define VIDEO_DATE_LABEL_YPOS (VIDEO_DISPLAY1_YPOS)
51 #define VIDEO_DATE_LABEL_XSIZE (VIDEO_DISPLAY_XSIZE)
52 #define VIDEO_DATE_LABEL_YSIZE (VIDEO_DISPLAY_YSIZE)
53 #define VIDEO_DATE_XPOS (VIDEO_DISPLAY1_XPOS + 2)
54 #define VIDEO_DATE_YPOS (VIDEO_DISPLAY1_YPOS + 14)
55 #define VIDEO_DATE_XSIZE (VIDEO_DISPLAY_XSIZE)
56 #define VIDEO_DATE_YSIZE 16
57 #define VIDEO_REC_LABEL_XPOS (VIDEO_DISPLAY2_XPOS)
58 #define VIDEO_REC_LABEL_YPOS (VIDEO_DISPLAY2_YPOS)
59 #define VIDEO_REC_LABEL_XSIZE 20
60 #define VIDEO_REC_LABEL_YSIZE 12
61 #define VIDEO_REC_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS + 20)
62 #define VIDEO_REC_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
63 #define VIDEO_REC_SYMBOL_XSIZE 16
64 #define VIDEO_REC_SYMBOL_YSIZE 16
65 #define VIDEO_PLAY_LABEL_XPOS (VIDEO_DISPLAY2_XPOS + 65)
66 #define VIDEO_PLAY_LABEL_YPOS (VIDEO_DISPLAY2_YPOS)
67 #define VIDEO_PLAY_LABEL_XSIZE 22
68 #define VIDEO_PLAY_LABEL_YSIZE 12
69 #define VIDEO_PLAY_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS + 52)
70 #define VIDEO_PLAY_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
71 #define VIDEO_PLAY_SYMBOL_XSIZE 11
72 #define VIDEO_PLAY_SYMBOL_YSIZE 13
73 #define VIDEO_PAUSE_LABEL_XPOS (VIDEO_DISPLAY2_XPOS)
74 #define VIDEO_PAUSE_LABEL_YPOS (VIDEO_DISPLAY2_YPOS + 20)
75 #define VIDEO_PAUSE_LABEL_XSIZE 35
76 #define VIDEO_PAUSE_LABEL_YSIZE 8
77 #define VIDEO_PAUSE_SYMBOL_XPOS (VIDEO_DISPLAY2_XPOS + 35)
78 #define VIDEO_PAUSE_SYMBOL_YPOS (VIDEO_DISPLAY2_YPOS)
79 #define VIDEO_PAUSE_SYMBOL_XSIZE 17
80 #define VIDEO_PAUSE_SYMBOL_YSIZE 13
81 #define VIDEO_TIME_XPOS (VIDEO_DISPLAY2_XPOS + 39)
82 #define VIDEO_TIME_YPOS (VIDEO_DISPLAY2_YPOS + 14)
83 #define VIDEO_TIME_XSIZE 50
84 #define VIDEO_TIME_YSIZE 16
86 /* some default values for tape labels and symbols */
87 #define VIDEO_LABEL_XPOS 5
88 #define VIDEO_LABEL_YPOS 42
89 #define VIDEO_LABEL_XSIZE 40
90 #define VIDEO_LABEL_YSIZE 28
91 #define VIDEO_SYMBOL_XPOS 39
92 #define VIDEO_SYMBOL_YPOS 42
93 #define VIDEO_SYMBOL_XSIZE 56
94 #define VIDEO_SYMBOL_YSIZE 13
96 /* values for certain tape labels and symbols */
97 #define VIDEO_FFWD_LABEL_XPOS VIDEO_LABEL_XPOS
98 #define VIDEO_FFWD_LABEL_YPOS 193
99 #define VIDEO_FFWD_LABEL_XSIZE VIDEO_LABEL_XSIZE
100 #define VIDEO_FFWD_LABEL_YSIZE VIDEO_LABEL_YSIZE
101 #define VIDEO_FFWD_SYMBOL_XPOS VIDEO_SYMBOL_XPOS
102 #define VIDEO_FFWD_SYMBOL_YPOS 193
103 #define VIDEO_FFWD_SYMBOL_XSIZE 27
104 #define VIDEO_FFWD_SYMBOL_YSIZE VIDEO_SYMBOL_YSIZE
106 #define VIDEO_PBEND_LABEL_XPOS VIDEO_LABEL_XPOS
107 #define VIDEO_PBEND_LABEL_YPOS 221
108 #define VIDEO_PBEND_LABEL_XSIZE VIDEO_LABEL_XSIZE
109 #define VIDEO_PBEND_LABEL_YSIZE VIDEO_LABEL_YSIZE
110 #define VIDEO_PBEND_SYMBOL_XPOS VIDEO_SYMBOL_XPOS
111 #define VIDEO_PBEND_SYMBOL_YPOS 221
112 #define VIDEO_PBEND_SYMBOL_XSIZE 27
113 #define VIDEO_PBEND_SYMBOL_YSIZE VIDEO_SYMBOL_YSIZE
115 #define VIDEO_WARP_LABEL_XPOS VIDEO_LABEL_XPOS
116 #define VIDEO_WARP_LABEL_YPOS 165
117 #define VIDEO_WARP_LABEL_XSIZE VIDEO_LABEL_XSIZE
118 #define VIDEO_WARP_LABEL_YSIZE VIDEO_LABEL_YSIZE
119 #define VIDEO_WARP_SYMBOL_XPOS VIDEO_SYMBOL_XPOS
120 #define VIDEO_WARP_SYMBOL_YPOS 165
121 #define VIDEO_WARP_SYMBOL_XSIZE 27
122 #define VIDEO_WARP_SYMBOL_YSIZE VIDEO_SYMBOL_YSIZE
123 #define VIDEO_WARP2_SYMBOL_XPOS VIDEO_SYMBOL_XPOS
124 #define VIDEO_WARP2_SYMBOL_YPOS 152
125 #define VIDEO_WARP2_SYMBOL_XSIZE 27
126 #define VIDEO_WARP2_SYMBOL_YSIZE VIDEO_SYMBOL_YSIZE
128 #define VIDEO_1STEP_SYMBOL_XPOS (VIDEO_SYMBOL_XPOS + 18)
129 #define VIDEO_1STEP_SYMBOL_YPOS 139
130 #define VIDEO_1STEP_SYMBOL_XSIZE (VIDEO_SYMBOL_XSIZE - 18)
131 #define VIDEO_1STEP_SYMBOL_YSIZE VIDEO_SYMBOL_YSIZE
133 #define PG_X3(x) (DOOR_GFX_PAGEX3 + (x))
134 #define PG_X4(x) (DOOR_GFX_PAGEX4 + (x))
135 #define PG_X5(x) (DOOR_GFX_PAGEX5 + (x))
136 #define PG_X6(x) (DOOR_GFX_PAGEX6 + (x))
138 #define PG_Y1(y) (DOOR_GFX_PAGEY1 + (y))
139 #define PG_Y2(y) (DOOR_GFX_PAGEY2 + (y))
141 #define VIDEO_INFO_OFF (VIDEO_STATE_DATE_OFF | \
142 VIDEO_STATE_TIME_OFF | \
143 VIDEO_STATE_FRAME_OFF)
144 #define VIDEO_STATE_OFF (VIDEO_STATE_PLAY_OFF | \
145 VIDEO_STATE_REC_OFF | \
146 VIDEO_STATE_PAUSE_OFF | \
147 VIDEO_STATE_FFWD_OFF | \
148 VIDEO_STATE_PBEND_OFF | \
149 VIDEO_STATE_1STEP_OFF)
150 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
151 VIDEO_PRESS_REC_OFF | \
152 VIDEO_PRESS_PAUSE_OFF | \
153 VIDEO_PRESS_STOP_OFF | \
154 VIDEO_PRESS_EJECT_OFF)
155 #define VIDEO_ALL_OFF (VIDEO_INFO_OFF | \
159 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
160 VIDEO_STATE_TIME_ON | \
161 VIDEO_STATE_FRAME_ON)
162 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
163 VIDEO_STATE_REC_ON | \
164 VIDEO_STATE_PAUSE_ON | \
165 VIDEO_STATE_FFWD_ON | \
166 VIDEO_STATE_PBEND_ON | \
167 VIDEO_STATE_1STEP_ON)
168 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
169 VIDEO_PRESS_REC_ON | \
170 VIDEO_PRESS_PAUSE_ON | \
171 VIDEO_PRESS_STOP_ON | \
172 VIDEO_PRESS_EJECT_ON)
173 #define VIDEO_ALL_ON (VIDEO_INFO_ON | \
177 #define VIDEO_INFO (VIDEO_INFO_ON | VIDEO_INFO_OFF)
178 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
179 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
180 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
182 #define NUM_TAPE_FUNCTIONS 11
183 #define NUM_TAPE_FUNCTION_PARTS 2
184 #define NUM_TAPE_FUNCTION_STATES 2
187 /* ========================================================================= */
188 /* video display functions */
189 /* ========================================================================= */
191 static void DrawVideoDisplay_Graphics(unsigned int state, unsigned int value)
200 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
203 { IMG_TAPE_LABEL_GFX_PLAY, &tape.label.play },
204 { IMG_TAPE_SYMBOL_GFX_PLAY, &tape.symbol.play },
207 { IMG_TAPE_LABEL_GFX_RECORD, &tape.label.record },
208 { IMG_TAPE_SYMBOL_GFX_RECORD, &tape.symbol.record },
211 { IMG_TAPE_LABEL_GFX_PAUSE, &tape.label.pause },
212 { IMG_TAPE_SYMBOL_GFX_PAUSE, &tape.symbol.pause },
215 { IMG_TAPE_LABEL_GFX_DATE, &tape.label.date },
219 { IMG_TAPE_LABEL_GFX_TIME, &tape.label.time },
223 /* (no label for displaying optional frame) */
228 { IMG_TAPE_LABEL_GFX_FAST_FORWARD, &tape.label.fast_forward },
229 { IMG_TAPE_SYMBOL_GFX_FAST_FORWARD, &tape.symbol.fast_forward },
232 { IMG_TAPE_LABEL_GFX_PAUSE_BEFORE_END, &tape.label.pause_before_end },
233 { IMG_TAPE_SYMBOL_GFX_PAUSE_BEFORE_END, &tape.symbol.pause_before_end },
236 { IMG_TAPE_LABEL_GFX_WARP_FORWARD_BLIND, &tape.label.warp_forward_blind},
237 { IMG_TAPE_SYMBOL_GFX_WARP_FORWARD_BLIND, &tape.symbol.warp_forward_blind},
240 { IMG_TAPE_LABEL_GFX_WARP_FORWARD, &tape.label.warp_forward },
241 { IMG_TAPE_SYMBOL_GFX_WARP_FORWARD, &tape.symbol.warp_forward },
244 { IMG_TAPE_LABEL_GFX_SINGLE_STEP, &tape.label.single_step },
245 { IMG_TAPE_SYMBOL_GFX_SINGLE_STEP, &tape.symbol.single_step },
249 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */
251 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */
253 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */
255 int graphic = video_pos[i][j].graphic;
256 struct XY *pos = video_pos[i][j].pos;
263 if (state & (1 << (i * 2 + k)))
265 struct GraphicInfo *gfx_bg = &graphic_info[IMG_BACKGROUND_TAPE];
266 struct GraphicInfo *gfx = &graphic_info[graphic];
270 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
272 if (value == skip_value)
277 gd_bitmap = gfx->bitmap;
283 gd_bitmap = gfx_bg->bitmap;
284 gd_x = gfx_bg->src_x + pos->x;
285 gd_y = gfx_bg->src_y + pos->y;
288 /* some tape graphics may be undefined -- only draw if defined */
289 if (gd_bitmap != NULL)
290 BlitBitmap(gd_bitmap, drawto, gd_x, gd_y, gfx->width, gfx->height,
291 VX + pos->x, VY + pos->y);
293 redraw_mask |= REDRAW_DOOR_2;
301 #define DATETIME_NONE (0)
303 #define DATETIME_DATE_YYYY (1 << 0)
304 #define DATETIME_DATE_YY (1 << 1)
305 #define DATETIME_DATE_MON (1 << 2)
306 #define DATETIME_DATE_MM (1 << 3)
307 #define DATETIME_DATE_DD (1 << 4)
309 #define DATETIME_TIME_HH (1 << 5)
310 #define DATETIME_TIME_MIN (1 << 6)
311 #define DATETIME_TIME_MM (1 << 7)
312 #define DATETIME_TIME_SS (1 << 8)
314 #define DATETIME_FRAME (1 << 9)
316 #define DATETIME_XOFFSET_1 (1 << 10)
317 #define DATETIME_XOFFSET_2 (1 << 11)
319 #define DATETIME_DATE (DATETIME_DATE_YYYY | \
321 DATETIME_DATE_MON | \
325 #define DATETIME_TIME (DATETIME_TIME_HH | \
326 DATETIME_TIME_MIN | \
330 #define MAX_DATETIME_STRING_SIZE 32
332 static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value)
336 static char *month_shortnames[] =
354 struct TextPosInfo *pos;
359 { &tape.text.date, DATETIME_DATE_DD },
360 { &tape.text.date, DATETIME_DATE_MON | DATETIME_XOFFSET_1 },
361 { &tape.text.date, DATETIME_DATE_YY | DATETIME_XOFFSET_2 },
362 { &tape.text.date_yyyy, DATETIME_DATE_YYYY },
363 { &tape.text.date_yy, DATETIME_DATE_YY },
364 { &tape.text.date_mon, DATETIME_DATE_MON },
365 { &tape.text.date_mm, DATETIME_DATE_MM },
366 { &tape.text.date_dd, DATETIME_DATE_DD },
368 { &tape.text.time, DATETIME_TIME_MIN },
369 { &tape.text.time, DATETIME_TIME_SS | DATETIME_XOFFSET_1 },
370 { &tape.text.time_hh, DATETIME_TIME_HH },
371 { &tape.text.time_mm, DATETIME_TIME_MM },
372 { &tape.text.time_ss, DATETIME_TIME_SS },
374 { &tape.text.frame, DATETIME_FRAME },
376 { NULL, DATETIME_NONE },
379 for (i = 0; datetime_info[i].pos != NULL; i++)
381 struct TextPosInfo *pos = datetime_info[i].pos;
382 int type = datetime_info[i].type;
389 xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset :
390 type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0);
393 if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON))
395 char s[MAX_DATETIME_STRING_SIZE];
396 int year2 = value / 10000;
397 int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
398 int month_index = (value / 100) % 100;
399 int month = month_index + 1;
400 int day = value % 100;
402 strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) :
403 type & DATETIME_DATE_YY ? int2str(year2, 2) :
404 type & DATETIME_DATE_MON ? month_shortnames[month_index] :
405 type & DATETIME_DATE_MM ? int2str(month, 2) :
406 type & DATETIME_DATE_DD ? int2str(day, 2) : ""));
408 DrawText(xpos, ypos, s, pos->font);
410 else if ((type & DATETIME_TIME) && (state & VIDEO_STATE_TIME_ON))
412 char s[MAX_DATETIME_STRING_SIZE];
413 int hh = (value / 3600) % 100;
414 int min = value / 60;
415 int mm = (value / 60) % 60;
418 strcpy(s, (type & DATETIME_TIME_HH ? int2str(hh, 2) :
419 type & DATETIME_TIME_MIN ? int2str(min, 2) :
420 type & DATETIME_TIME_MM ? int2str(mm, 2) :
421 type & DATETIME_TIME_SS ? int2str(ss, 2) : ""));
423 DrawText(xpos, ypos, s, pos->font);
425 else if ((type & DATETIME_FRAME) && (state & VIDEO_STATE_FRAME_ON))
427 DrawText(xpos, ypos, int2str(value, pos->size), pos->font);
432 void DrawVideoDisplay(unsigned int state, unsigned int value)
434 DrawVideoDisplay_Graphics(state, value);
435 DrawVideoDisplay_DateTime(state, value);
438 void DrawCompleteVideoDisplay()
440 struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
442 /* draw tape background */
443 BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
444 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
446 /* draw tape buttons (forced) */
450 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
454 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
455 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
456 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
457 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
460 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
462 else if (tape.playing)
464 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
465 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
466 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
467 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
470 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
472 else if (tape.date && tape.length)
474 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
475 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
476 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
479 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
483 void TapeDeactivateDisplayOn()
485 SetDrawDeactivationMask(REDRAW_FIELD);
486 audio.sound_deactivated = TRUE;
489 void TapeDeactivateDisplayOff(boolean redraw_display)
491 SetDrawDeactivationMask(REDRAW_NONE);
492 audio.sound_deactivated = FALSE;
497 DrawGameDoorValues();
502 /* ========================================================================= */
503 /* tape control functions */
504 /* ========================================================================= */
506 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
508 struct tm *lt = localtime(&epoch_seconds);
510 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
513 void TapeSetDateFromNow()
515 TapeSetDateFromEpochSeconds(time(NULL));
524 tape.length_frames = 0;
525 tape.length_seconds = 0;
527 if (leveldir_current)
528 setString(&tape.level_identifier, leveldir_current->identifier);
530 tape.level_nr = level_nr;
531 tape.pos[tape.counter].delay = 0;
534 tape.random_seed = InitRND(level.random_seed);
536 tape.file_version = FILE_VERSION_ACTUAL;
537 tape.game_version = GAME_VERSION_ACTUAL;
538 tape.engine_version = level.game_version;
540 TapeSetDateFromNow();
542 for (i = 0; i < MAX_PLAYERS; i++)
543 tape.player_participates[i] = FALSE;
545 tape.centered_player_nr_next = -1;
546 tape.set_centered_player = FALSE;
549 static void TapeRewind()
552 tape.delay_played = 0;
553 tape.pause_before_death = FALSE;
554 tape.recording = FALSE;
555 tape.playing = FALSE;
556 tape.fast_forward = FALSE;
557 tape.warp_forward = FALSE;
558 tape.deactivate_display = FALSE;
559 tape.auto_play = (global.autoplay_leveldir != NULL);
560 tape.auto_play_level_solved = FALSE;
561 tape.quick_resume = FALSE;
562 tape.single_step = FALSE;
564 tape.centered_player_nr_next = -1;
565 tape.set_centered_player = FALSE;
567 InitRND(tape.random_seed);
570 static void TapeSetRandomSeed(int random_seed)
572 tape.random_seed = InitRND(random_seed);
575 void TapeStartRecording(int random_seed)
577 if (!TAPE_IS_STOPPED(tape))
582 TapeSetRandomSeed(random_seed);
584 tape.recording = TRUE;
586 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
587 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
588 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
589 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
593 SetDrawDeactivationMask(REDRAW_NONE);
594 audio.sound_deactivated = FALSE;
597 static void TapeStartGameRecording()
599 TapeStartRecording(level.random_seed);
601 #if defined(NETWORK_AVALIABLE)
604 SendToServer_StartPlaying();
613 static void TapeAppendRecording()
615 if (!tape.playing || !tape.pausing)
618 tape.pos[tape.counter].delay = tape.delay_played;
619 tape.playing = FALSE;
620 tape.recording = TRUE;
623 TapeSetDateFromNow();
625 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
626 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
628 UpdateAndDisplayGameControlValues();
631 void TapeHaltRecording()
637 tape.pos[tape.counter].delay = 0;
639 tape.length = tape.counter;
640 tape.length_frames = GetTapeLengthFrames();
641 tape.length_seconds = GetTapeLengthSeconds();
644 void TapeStopRecording()
648 tape.recording = FALSE;
649 tape.pausing = FALSE;
651 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
652 MapTapeEjectButton();
655 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
657 byte action[MAX_PLAYERS];
660 if (!tape.recording) /* (record action even when tape is paused) */
663 if (tape.counter >= MAX_TAPE_LEN - 1)
669 for (i = 0; i < MAX_PLAYERS; i++)
670 action[i] = action_raw[i];
672 if (tape.set_centered_player)
674 for (i = 0; i < MAX_PLAYERS; i++)
675 if (tape.centered_player_nr_next == i ||
676 tape.centered_player_nr_next == -1)
677 action[i] |= KEY_SET_FOCUS;
679 tape.set_centered_player = FALSE;
682 if (tape.pos[tape.counter].delay > 0) /* already stored action */
684 boolean changed_events = FALSE;
686 for (i = 0; i < MAX_PLAYERS; i++)
687 if (tape.pos[tape.counter].action[i] != action[i])
688 changed_events = TRUE;
690 if (changed_events || tape.pos[tape.counter].delay >= 255)
693 tape.pos[tape.counter].delay = 0;
696 tape.pos[tape.counter].delay++;
699 if (tape.pos[tape.counter].delay == 0) /* store new action */
701 for (i = 0; i < MAX_PLAYERS; i++)
702 tape.pos[tape.counter].action[i] = action[i];
704 tape.pos[tape.counter].delay++;
708 void TapeTogglePause(boolean toggle_manual)
712 if (tape.pause_before_death)
713 state |= VIDEO_STATE_PBEND_OFF;
714 else if (tape.fast_forward)
715 state |= VIDEO_STATE_FFWD_OFF;
717 tape.pausing = !tape.pausing;
718 tape.fast_forward = FALSE;
719 tape.pause_before_death = FALSE;
721 if (tape.single_step && toggle_manual)
722 tape.single_step = FALSE;
724 state |= (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
726 state |= VIDEO_STATE_PLAY_ON;
728 state |= (tape.single_step ? VIDEO_STATE_1STEP_ON : VIDEO_STATE_1STEP_OFF);
730 DrawVideoDisplay(state, 0);
732 if (tape.warp_forward)
734 TapeStopWarpForward();
736 if (tape.quick_resume)
738 tape.quick_resume = FALSE;
740 TapeAppendRecording();
742 if (!CheckEngineSnapshotSingle())
743 SaveEngineSnapshotSingle();
745 // restart step/move snapshots after quick loading tape
746 SaveEngineSnapshotToListInitial();
750 if (setup.show_snapshot_buttons &&
751 game_status == GAME_MODE_PLAYING &&
752 CheckEngineSnapshotList())
755 MapUndoRedoButtons();
756 else if (!tape.single_step)
757 UnmapUndoRedoButtons();
761 void TapeStartPlaying()
763 if (TAPE_IS_EMPTY(tape))
766 if (!TAPE_IS_STOPPED(tape))
773 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
774 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
775 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
776 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
780 SetDrawDeactivationMask(REDRAW_NONE);
781 audio.sound_deactivated = FALSE;
784 static void TapeStartGamePlaying()
791 void TapeStopPlaying()
793 tape.playing = FALSE;
794 tape.pausing = FALSE;
796 if (tape.warp_forward)
797 TapeStopWarpForward();
799 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
800 MapTapeEjectButton();
803 byte *TapePlayAction()
805 static byte action[MAX_PLAYERS];
808 if (!tape.playing || tape.pausing)
811 if (tape.pause_before_death) /* stop 10 seconds before player gets killed */
813 if (!(FrameCounter % 20))
815 if ((FrameCounter / 20) % 2)
816 DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY);
818 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF, VIDEO_DISPLAY_LABEL_ONLY);
821 if (tape.warp_forward)
823 if (tape.deactivate_display)
824 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
826 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
829 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
831 TapeTogglePause(TAPE_TOGGLE_MANUAL);
836 else if (tape.fast_forward)
838 if ((FrameCounter / 20) % 2)
839 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, VIDEO_DISPLAY_LABEL_ONLY);
841 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF, VIDEO_DISPLAY_LABEL_ONLY);
843 if (tape.warp_forward)
845 if (tape.deactivate_display)
846 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
848 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
853 /* !!! this makes things much slower !!! */
854 else if (tape.warp_forward)
856 if ((FrameCounter / 20) % 2)
857 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_LABEL_ONLY);
859 DrawVideoDisplay(VIDEO_STATE_WARP_OFF, VIDEO_DISPLAY_LABEL_ONLY);
861 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
865 if (tape.counter >= tape.length) /* end of tape reached */
867 if (tape.warp_forward && !tape.auto_play)
868 TapeTogglePause(TAPE_TOGGLE_MANUAL);
875 for (i = 0; i < MAX_PLAYERS; i++)
876 action[i] = tape.pos[tape.counter].action[i];
878 #if DEBUG_TAPE_WHEN_PLAYING
879 printf("%05d", FrameCounter);
880 for (i = 0; i < MAX_PLAYERS; i++)
881 printf(" %08x", action[i]);
885 tape.set_centered_player = FALSE;
886 tape.centered_player_nr_next = -999;
888 for (i = 0; i < MAX_PLAYERS; i++)
890 if (action[i] & KEY_SET_FOCUS)
892 tape.set_centered_player = TRUE;
893 tape.centered_player_nr_next =
894 (tape.centered_player_nr_next == -999 ? i : -1);
897 action[i] &= ~KEY_SET_FOCUS;
901 if (tape.delay_played >= tape.pos[tape.counter].delay)
904 tape.delay_played = 0;
915 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
917 if (tape.date && tape.length)
919 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
920 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
921 DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
925 unsigned int GetTapeLengthFrames()
927 unsigned int tape_length_frames = 0;
930 if (TAPE_IS_EMPTY(tape))
933 for (i = 0; i < tape.length; i++)
934 tape_length_frames += tape.pos[i].delay;
936 return tape_length_frames;
939 unsigned int GetTapeLengthSeconds()
941 return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
944 static void TapeStartWarpForward()
946 tape.warp_forward = TRUE;
948 if (!tape.fast_forward && !tape.pause_before_death)
950 tape.pausing = FALSE;
951 tape.deactivate_display = TRUE;
953 TapeDeactivateDisplayOn();
956 if (tape.fast_forward || tape.pause_before_death)
957 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
959 DrawVideoDisplay(VIDEO_STATE_WARP_ON, 0);
962 static void TapeStopWarpForward()
964 int state = (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
966 tape.warp_forward = FALSE;
967 tape.deactivate_display = FALSE;
969 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
971 if (tape.pause_before_death)
972 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PBEND_ON;
973 else if (tape.fast_forward)
974 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_FFWD_ON;
976 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PLAY_ON;
978 DrawVideoDisplay(state, 0);
981 static void TapeSingleStep()
987 TapeTogglePause(TAPE_TOGGLE_MANUAL);
989 tape.single_step = !tape.single_step;
991 DrawVideoDisplay((tape.single_step ? VIDEO_STATE_1STEP_ON :
992 VIDEO_STATE_1STEP_OFF), 0);
997 if (game_status == GAME_MODE_MAIN)
999 Request("No game that can be saved!", REQ_CONFIRM);
1004 if (game_status != GAME_MODE_PLAYING)
1008 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
1010 if (TAPE_IS_EMPTY(tape))
1012 Request("No tape that can be saved!", REQ_CONFIRM);
1017 if (SaveTapeChecked(tape.level_nr))
1018 SaveEngineSnapshotSingle();
1021 void TapeQuickLoad()
1023 char *filename = getTapeFilename(level_nr);
1025 if (!fileExists(filename))
1027 Request("No tape for this level!", REQ_CONFIRM);
1032 if (tape.recording && !Request("Stop recording and load tape?",
1033 REQ_ASK | REQ_STAY_CLOSED))
1035 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1040 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
1043 if (CheckEngineSnapshotSingle())
1045 TapeStartGamePlaying();
1047 LoadEngineSnapshotSingle();
1049 DrawCompleteVideoDisplay();
1051 tape.playing = TRUE;
1052 tape.pausing = TRUE;
1054 TapeStopWarpForward();
1055 TapeAppendRecording();
1057 // restart step/move snapshots after quick loading tape
1058 SaveEngineSnapshotToListInitial();
1060 if (FrameCounter > 0)
1069 if (!TAPE_IS_EMPTY(tape))
1071 TapeStartGamePlaying();
1072 TapeStartWarpForward();
1074 tape.quick_resume = TRUE;
1076 else /* this should not happen (basically checked above) */
1078 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1080 Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1084 void InsertSolutionTape()
1086 if (!TAPE_IS_EMPTY(tape))
1089 LoadSolutionTape(level_nr);
1091 if (TAPE_IS_EMPTY(tape))
1092 Request("No solution tape for this level!", REQ_CONFIRM);
1094 DrawCompleteVideoDisplay();
1098 /* ------------------------------------------------------------------------- *
1099 * tape autoplay functions
1100 * ------------------------------------------------------------------------- */
1104 static LevelDirTree *autoplay_leveldir = NULL;
1105 static boolean autoplay_initialized = FALSE;
1106 static int autoplay_level_nr = -1;
1107 static int num_levels_played = 0;
1108 static int num_levels_solved = 0;
1109 static int num_tape_missing = 0;
1110 static boolean level_failed[MAX_TAPES_PER_SET];
1113 if (autoplay_initialized)
1115 /* just finished auto-playing tape */
1116 printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1118 num_levels_played++;
1120 if (tape.auto_play_level_solved)
1121 num_levels_solved++;
1122 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1123 level_failed[level_nr] = TRUE;
1127 DrawCompleteVideoDisplay();
1128 audio.sound_enabled = FALSE;
1130 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1131 global.autoplay_leveldir);
1133 if (autoplay_leveldir == NULL)
1134 Error(ERR_EXIT, "no such level identifier: '%s'",
1135 global.autoplay_leveldir);
1137 leveldir_current = autoplay_leveldir;
1139 if (autoplay_leveldir->first_level < 0)
1140 autoplay_leveldir->first_level = 0;
1141 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1142 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1144 autoplay_level_nr = autoplay_leveldir->first_level;
1146 printf_line("=", 79);
1147 printf("Automatically playing level tapes\n");
1148 printf_line("-", 79);
1149 printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1150 printf("Level series name: '%s'\n", autoplay_leveldir->name);
1151 printf("Level series author: '%s'\n", autoplay_leveldir->author);
1152 printf("Number of levels: %d\n", autoplay_leveldir->levels);
1153 printf_line("=", 79);
1156 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1157 level_failed[i] = FALSE;
1159 autoplay_initialized = TRUE;
1162 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1164 level_nr = autoplay_level_nr++;
1166 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1171 printf("Level %03d: ", level_nr);
1173 LoadLevel(level_nr);
1174 if (level.no_valid_file)
1176 printf("(no level)\n");
1181 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1182 printf("(only testing level)\n");
1186 LoadSolutionTape(level_nr);
1188 if (tape.no_valid_file)
1192 printf("(no tape)\n");
1197 printf("playing tape ... ");
1199 TapeStartGamePlaying();
1201 if (global.autoplay_mode == AUTOPLAY_FFWD)
1202 tape.fast_forward = TRUE;
1204 if (global.autoplay_mode != AUTOPLAY_PLAY)
1205 TapeStartWarpForward();
1211 printf_line("=", 79);
1212 printf("Number of levels played: %d\n", num_levels_played);
1213 printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1214 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1215 printf_line("-", 79);
1216 printf("Summary (for automatic parsing by scripts):\n");
1217 printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1218 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1219 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1221 if (num_levels_played != num_levels_solved)
1223 printf(", FAILED:");
1224 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1225 if (level_failed[i])
1230 printf_line("=", 79);
1236 /* ---------- new tape button stuff ---------------------------------------- */
1244 } tapebutton_info[NUM_TAPE_BUTTONS] =
1247 IMG_TAPE_BUTTON_GFX_EJECT, &tape.button.eject,
1248 TAPE_CTRL_ID_EJECT, "eject tape"
1251 /* (same position as "eject" button) */
1252 IMG_TAPE_BUTTON_GFX_EXTRA, &tape.button.eject,
1253 TAPE_CTRL_ID_EXTRA, "extra functions"
1256 IMG_TAPE_BUTTON_GFX_STOP, &tape.button.stop,
1257 TAPE_CTRL_ID_STOP, "stop tape"
1260 IMG_TAPE_BUTTON_GFX_PAUSE, &tape.button.pause,
1261 TAPE_CTRL_ID_PAUSE, "pause tape"
1264 IMG_TAPE_BUTTON_GFX_RECORD, &tape.button.record,
1265 TAPE_CTRL_ID_RECORD, "record tape"
1268 IMG_TAPE_BUTTON_GFX_PLAY, &tape.button.play,
1269 TAPE_CTRL_ID_PLAY, "play tape"
1273 void CreateTapeButtons()
1277 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1279 struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1280 struct XY *pos = tapebutton_info[i].pos;
1281 struct GadgetInfo *gi;
1282 int gd_x = gfx->src_x;
1283 int gd_y = gfx->src_y;
1284 int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1285 int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1288 gi = CreateGadget(GDI_CUSTOM_ID, id,
1289 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1292 GDI_WIDTH, gfx->width,
1293 GDI_HEIGHT, gfx->height,
1294 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1295 GDI_STATE, GD_BUTTON_UNPRESSED,
1296 GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1297 GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1298 GDI_DIRECT_DRAW, FALSE,
1299 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1300 GDI_CALLBACK_ACTION, HandleTapeButtons,
1304 Error(ERR_EXIT, "cannot create gadget");
1306 tape_gadget[id] = gi;
1310 void FreeTapeButtons()
1314 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1315 FreeGadget(tape_gadget[i]);
1318 void MapTapeEjectButton()
1320 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1321 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1324 void MapTapeWarpButton()
1326 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1327 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1330 void MapTapeButtons()
1334 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1335 if (i != TAPE_CTRL_ID_EXTRA)
1336 MapGadget(tape_gadget[i]);
1338 if (tape.recording || tape.playing)
1339 MapTapeWarpButton();
1341 if (tape.show_game_buttons)
1345 void UnmapTapeButtons()
1349 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1350 UnmapGadget(tape_gadget[i]);
1352 if (tape.show_game_buttons)
1356 static void HandleTapeButtonsExt(int id)
1358 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1363 case TAPE_CTRL_ID_EJECT:
1366 if (TAPE_IS_EMPTY(tape))
1370 if (TAPE_IS_EMPTY(tape))
1371 Request("No tape for this level!", REQ_CONFIRM);
1376 SaveTapeChecked(tape.level_nr);
1381 DrawCompleteVideoDisplay();
1384 case TAPE_CTRL_ID_EXTRA:
1387 if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
1389 TapeStartWarpForward();
1391 else /* WARP FORWARD PLAY -> PLAY */
1393 TapeStopWarpForward();
1396 else if (tape.recording)
1401 case TAPE_CTRL_ID_STOP:
1405 case TAPE_CTRL_ID_PAUSE:
1406 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1409 case TAPE_CTRL_ID_RECORD:
1410 if (TAPE_IS_STOPPED(tape))
1411 TapeStartGameRecording();
1412 else if (tape.pausing)
1414 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1415 TapeAppendRecording();
1417 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1421 case TAPE_CTRL_ID_PLAY:
1422 if (tape.recording && tape.pausing) /* PAUSE -> RECORD */
1424 // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1426 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1429 if (TAPE_IS_EMPTY(tape))
1432 if (TAPE_IS_STOPPED(tape))
1434 TapeStartGamePlaying();
1436 else if (tape.playing)
1438 if (tape.pausing) /* PAUSE -> PLAY */
1440 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1442 else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
1444 tape.fast_forward = TRUE;
1445 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1447 else if (!tape.pause_before_death) /* FFWD PLAY -> AUTO PAUSE */
1449 tape.pause_before_death = TRUE;
1450 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1452 else /* AUTO PAUSE -> NORMAL PLAY */
1454 if (tape.warp_forward)
1455 TapeStopWarpForward();
1457 tape.fast_forward = FALSE;
1458 tape.pause_before_death = FALSE;
1460 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
1470 static void HandleTapeButtons(struct GadgetInfo *gi)
1472 HandleTapeButtonsExt(gi->custom_id);
1475 void HandleTapeButtonKeys(Key key)
1477 boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1478 boolean extra_button_is_active = !eject_button_is_active;
1480 if (key == setup.shortcut.tape_eject && eject_button_is_active)
1481 HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1482 else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1483 HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1484 else if (key == setup.shortcut.tape_stop)
1485 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1486 else if (key == setup.shortcut.tape_pause)
1487 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1488 else if (key == setup.shortcut.tape_record)
1489 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1490 else if (key == setup.shortcut.tape_play)
1491 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);