1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
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 #define VIDEO_STATE_OFF (VIDEO_STATE_PLAY_OFF | \
144 VIDEO_STATE_REC_OFF | \
145 VIDEO_STATE_PAUSE_OFF | \
146 VIDEO_STATE_FFWD_OFF | \
147 VIDEO_STATE_PBEND_OFF | \
148 VIDEO_STATE_1STEP_OFF)
149 #define VIDEO_PRESS_OFF (VIDEO_PRESS_PLAY_OFF | \
150 VIDEO_PRESS_REC_OFF | \
151 VIDEO_PRESS_PAUSE_OFF | \
152 VIDEO_PRESS_STOP_OFF | \
153 VIDEO_PRESS_EJECT_OFF)
154 #define VIDEO_ALL_OFF (VIDEO_INFO_OFF | \
158 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
160 #define VIDEO_STATE_ON (VIDEO_STATE_PLAY_ON | \
161 VIDEO_STATE_REC_ON | \
162 VIDEO_STATE_PAUSE_ON | \
163 VIDEO_STATE_FFWD_ON | \
164 VIDEO_STATE_PBEND_ON | \
165 VIDEO_STATE_1STEP_ON)
166 #define VIDEO_PRESS_ON (VIDEO_PRESS_PLAY_ON | \
167 VIDEO_PRESS_REC_ON | \
168 VIDEO_PRESS_PAUSE_ON | \
169 VIDEO_PRESS_STOP_ON | \
170 VIDEO_PRESS_EJECT_ON)
171 #define VIDEO_ALL_ON (VIDEO_INFO_ON | \
175 #define VIDEO_INFO (VIDEO_INFO_ON | VIDEO_INFO_OFF)
176 #define VIDEO_STATE (VIDEO_STATE_ON | VIDEO_STATE_OFF)
177 #define VIDEO_PRESS (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
178 #define VIDEO_ALL (VIDEO_ALL_ON | VIDEO_ALL_OFF)
180 #define NUM_TAPE_FUNCTIONS 10
181 #define NUM_TAPE_FUNCTION_PARTS 2
182 #define NUM_TAPE_FUNCTION_STATES 2
185 /* ========================================================================= */
186 /* video display functions */
187 /* ========================================================================= */
189 void DrawVideoDisplay(unsigned long state, unsigned long value)
192 static char *monatsname[12] =
194 "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
195 "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
204 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
208 PG_X4(VIDEO_PLAY_LABEL_XPOS), PG_Y2(VIDEO_PLAY_LABEL_YPOS),
209 PG_X3(VIDEO_PLAY_LABEL_XPOS), PG_Y2(VIDEO_PLAY_LABEL_YPOS),
210 VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS,
211 VIDEO_PLAY_LABEL_XSIZE, VIDEO_PLAY_LABEL_YSIZE
214 PG_X4(VIDEO_PLAY_SYMBOL_XPOS), PG_Y2(VIDEO_PLAY_SYMBOL_YPOS),
215 PG_X3(VIDEO_PLAY_SYMBOL_XPOS), PG_Y2(VIDEO_PLAY_SYMBOL_YPOS),
216 VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS,
217 VIDEO_PLAY_SYMBOL_XSIZE, VIDEO_PLAY_SYMBOL_YSIZE
222 PG_X4(VIDEO_REC_LABEL_XPOS), PG_Y2(VIDEO_REC_LABEL_YPOS),
223 PG_X3(VIDEO_REC_LABEL_XPOS), PG_Y2(VIDEO_REC_LABEL_YPOS),
224 VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS,
225 VIDEO_REC_LABEL_XSIZE, VIDEO_REC_LABEL_YSIZE
228 PG_X4(VIDEO_REC_SYMBOL_XPOS), PG_Y2(VIDEO_REC_SYMBOL_YPOS),
229 PG_X3(VIDEO_REC_SYMBOL_XPOS), PG_Y2(VIDEO_REC_SYMBOL_YPOS),
230 VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS,
231 VIDEO_REC_SYMBOL_XSIZE, VIDEO_REC_SYMBOL_YSIZE
236 PG_X4(VIDEO_PAUSE_LABEL_XPOS), PG_Y2(VIDEO_PAUSE_LABEL_YPOS),
237 PG_X3(VIDEO_PAUSE_LABEL_XPOS), PG_Y2(VIDEO_PAUSE_LABEL_YPOS),
238 VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS,
239 VIDEO_PAUSE_LABEL_XSIZE, VIDEO_PAUSE_LABEL_YSIZE
242 PG_X4(VIDEO_PAUSE_SYMBOL_XPOS), PG_Y2(VIDEO_PAUSE_SYMBOL_YPOS),
243 PG_X3(VIDEO_PAUSE_SYMBOL_XPOS), PG_Y2(VIDEO_PAUSE_SYMBOL_YPOS),
244 VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS,
245 VIDEO_PAUSE_SYMBOL_XSIZE, VIDEO_PAUSE_SYMBOL_YSIZE
250 PG_X4(VIDEO_DATE_LABEL_XPOS), PG_Y2(VIDEO_DATE_LABEL_YPOS),
251 PG_X3(VIDEO_DATE_LABEL_XPOS), PG_Y2(VIDEO_DATE_LABEL_YPOS),
252 VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS,
253 VIDEO_DATE_LABEL_XSIZE, VIDEO_DATE_LABEL_YSIZE
256 PG_X4(VIDEO_DATE_XPOS), PG_Y2(VIDEO_DATE_YPOS),
257 PG_X3(VIDEO_DATE_XPOS), PG_Y2(VIDEO_DATE_YPOS),
258 VIDEO_DATE_XPOS, VIDEO_DATE_YPOS,
259 VIDEO_DATE_XSIZE, VIDEO_DATE_YSIZE
270 PG_X4(VIDEO_TIME_XPOS), PG_Y2(VIDEO_TIME_YPOS),
271 PG_X3(VIDEO_TIME_XPOS), PG_Y2(VIDEO_TIME_YPOS),
272 VIDEO_TIME_XPOS, VIDEO_TIME_YPOS,
273 VIDEO_TIME_XSIZE, VIDEO_TIME_YSIZE
278 PG_X6(VIDEO_FFWD_LABEL_XPOS), PG_Y1(VIDEO_FFWD_LABEL_YPOS),
279 PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS),
280 VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS,
281 VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE
284 PG_X6(VIDEO_FFWD_SYMBOL_XPOS), PG_Y1(VIDEO_FFWD_SYMBOL_YPOS),
285 PG_X3(VIDEO_FFWD_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS),
286 VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS,
287 VIDEO_FFWD_SYMBOL_XSIZE, VIDEO_FFWD_SYMBOL_YSIZE
292 PG_X6(VIDEO_PBEND_LABEL_XPOS), PG_Y1(VIDEO_PBEND_LABEL_YPOS),
293 PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS),
294 VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS,
295 VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE
298 PG_X6(VIDEO_PBEND_SYMBOL_XPOS), PG_Y1(VIDEO_PBEND_SYMBOL_YPOS),
299 PG_X3(VIDEO_PBEND_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS),
300 VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS,
301 VIDEO_PBEND_SYMBOL_XSIZE, VIDEO_PBEND_SYMBOL_YSIZE
306 PG_X6(VIDEO_WARP_LABEL_XPOS), PG_Y1(VIDEO_WARP_LABEL_YPOS),
307 PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS),
308 VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS,
309 VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE
312 PG_X6(VIDEO_WARP_SYMBOL_XPOS), PG_Y1(VIDEO_WARP_SYMBOL_YPOS),
313 PG_X3(VIDEO_WARP_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS),
314 VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS,
315 VIDEO_WARP_SYMBOL_XSIZE, VIDEO_WARP_SYMBOL_YSIZE
326 PG_X6(VIDEO_WARP2_SYMBOL_XPOS), PG_Y1(VIDEO_WARP2_SYMBOL_YPOS),
327 PG_X3(VIDEO_WARP2_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS),
328 VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS,
329 VIDEO_WARP2_SYMBOL_XSIZE, VIDEO_WARP2_SYMBOL_YSIZE
340 PG_X6(VIDEO_1STEP_SYMBOL_XPOS), PG_Y1(VIDEO_1STEP_SYMBOL_YPOS),
341 PG_X3(VIDEO_1STEP_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS),
342 VIDEO_1STEP_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS,
343 VIDEO_1STEP_SYMBOL_XSIZE, VIDEO_1STEP_SYMBOL_YSIZE
348 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */
350 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */
352 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */
354 if (state & (1 << (i * 2 + k)))
358 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
362 gd_x = video_pos[i][j].gd_x1;
363 gd_y = video_pos[i][j].gd_y1;
367 gd_x = video_pos[i][j].gd_x2;
368 gd_y = video_pos[i][j].gd_y2;
371 if (video_pos[i][j].x != -1 && value != skip_value)
372 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
374 video_pos[i][j].width,
375 video_pos[i][j].height,
376 VX + video_pos[i][j].x,
377 VY + video_pos[i][j].y);
383 if (state & VIDEO_STATE_DATE_ON)
385 int tag = value % 100;
386 int monat = (value/100) % 100;
387 int jahr = (value/10000);
389 DrawText(VX + VIDEO_DATE_XPOS, VY + VIDEO_DATE_YPOS,
390 int2str(tag, 2), FONT_TAPE_RECORDER);
391 DrawText(VX + VIDEO_DATE_XPOS + 27, VY + VIDEO_DATE_YPOS,
392 monatsname[monat], FONT_TAPE_RECORDER);
393 DrawText(VX + VIDEO_DATE_XPOS + 64, VY + VIDEO_DATE_YPOS,
394 int2str(jahr, 2), FONT_TAPE_RECORDER);
397 if (state & VIDEO_STATE_TIME_ON)
399 int min = value / 60;
400 int sec = value % 60;
402 DrawText(VX + VIDEO_TIME_XPOS, VY + VIDEO_TIME_YPOS,
403 int2str(min, 2), FONT_TAPE_RECORDER);
404 DrawText(VX + VIDEO_TIME_XPOS + 27, VY + VIDEO_TIME_YPOS,
405 int2str(sec, 2), FONT_TAPE_RECORDER);
408 redraw_mask |= REDRAW_DOOR_2;
411 void DrawCompleteVideoDisplay()
413 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
414 DOOR_GFX_PAGEX3, DOOR_GFX_PAGEY2,
415 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
416 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
417 DOOR_GFX_PAGEX4 + VIDEO_CONTROL_XPOS,
418 DOOR_GFX_PAGEY2 + VIDEO_CONTROL_YPOS,
419 VIDEO_CONTROL_XSIZE, VIDEO_CONTROL_YSIZE,
420 gfx.vx + VIDEO_CONTROL_XPOS, gfx.vy + VIDEO_CONTROL_YPOS);
422 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
423 if (tape.date && tape.length)
425 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
426 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
429 BlitBitmap(drawto, bitmap_db_door, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
430 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2);
433 void TapeDeactivateDisplayOn()
435 SetDrawDeactivationMask(REDRAW_FIELD);
436 audio.sound_deactivated = TRUE;
439 void TapeDeactivateDisplayOff(boolean redraw_display)
441 SetDrawDeactivationMask(REDRAW_NONE);
442 audio.sound_deactivated = FALSE;
446 RedrawPlayfield(TRUE, 0,0,0,0);
447 DrawGameDoorValues();
452 /* ========================================================================= */
453 /* tape control functions */
454 /* ========================================================================= */
456 static void TapeSetDate()
458 time_t epoch_seconds = time(NULL);
459 struct tm *now = localtime(&epoch_seconds);
461 tape.date = 10000 * (now->tm_year % 100) + 100 * now->tm_mon + now->tm_mday;
471 if (leveldir_current)
472 setString(&tape.level_identifier, leveldir_current->identifier);
474 tape.level_nr = level_nr;
475 tape.pos[tape.counter].delay = 0;
478 tape.random_seed = InitRND(level.random_seed);
480 tape.file_version = FILE_VERSION_ACTUAL;
481 tape.game_version = GAME_VERSION_ACTUAL;
482 tape.engine_version = level.game_version;
486 for (i = 0; i < MAX_PLAYERS; i++)
487 tape.player_participates[i] = FALSE;
489 tape.centered_player_nr_next = -1;
490 tape.set_centered_player = FALSE;
493 static void TapeRewind()
496 tape.delay_played = 0;
497 tape.pause_before_death = FALSE;
498 tape.recording = FALSE;
499 tape.playing = FALSE;
500 tape.fast_forward = FALSE;
501 tape.warp_forward = FALSE;
502 tape.deactivate_display = FALSE;
503 tape.auto_play = (global.autoplay_leveldir != NULL);
504 tape.auto_play_level_solved = FALSE;
505 tape.quick_resume = FALSE;
506 tape.single_step = FALSE;
508 tape.centered_player_nr_next = -1;
509 tape.set_centered_player = FALSE;
511 InitRND(tape.random_seed);
514 static void TapeSetRandomSeed(long random_seed)
516 tape.random_seed = InitRND(random_seed);
519 void TapeStartRecording(long random_seed)
521 if (!TAPE_IS_STOPPED(tape))
526 TapeSetRandomSeed(random_seed);
528 tape.recording = TRUE;
530 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
531 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
532 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
535 SetDrawDeactivationMask(REDRAW_NONE);
536 audio.sound_deactivated = FALSE;
539 static void TapeStartGameRecording()
541 TapeStartRecording(level.random_seed);
543 #if defined(NETWORK_AVALIABLE)
546 SendToServer_StartPlaying();
555 static void TapeAppendRecording()
557 if (!tape.playing || !tape.pausing)
560 tape.pos[tape.counter].delay = tape.delay_played;
561 tape.playing = FALSE;
562 tape.recording = TRUE;
567 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
568 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
571 UpdateAndDisplayGameControlValues();
575 void TapeHaltRecording()
581 tape.pos[tape.counter].delay = 0;
583 tape.length = tape.counter;
584 tape.length_seconds = GetTapeLength();
587 void TapeStopRecording()
591 tape.recording = FALSE;
592 tape.pausing = FALSE;
594 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
595 MapTapeEjectButton();
598 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
600 byte action[MAX_PLAYERS];
603 if (!tape.recording) /* (record action even when tape is paused) */
606 if (tape.counter >= MAX_TAPE_LEN - 1)
612 for (i = 0; i < MAX_PLAYERS; i++)
613 action[i] = action_raw[i];
615 if (tape.set_centered_player)
617 for (i = 0; i < MAX_PLAYERS; i++)
618 if (tape.centered_player_nr_next == i ||
619 tape.centered_player_nr_next == -1)
620 action[i] |= KEY_SET_FOCUS;
622 tape.set_centered_player = FALSE;
625 if (tape.pos[tape.counter].delay > 0) /* already stored action */
627 boolean changed_events = FALSE;
629 for (i = 0; i < MAX_PLAYERS; i++)
630 if (tape.pos[tape.counter].action[i] != action[i])
631 changed_events = TRUE;
633 if (changed_events || tape.pos[tape.counter].delay >= 255)
636 tape.pos[tape.counter].delay = 0;
639 tape.pos[tape.counter].delay++;
642 if (tape.pos[tape.counter].delay == 0) /* store new action */
644 for (i = 0; i < MAX_PLAYERS; i++)
645 tape.pos[tape.counter].action[i] = action[i];
647 tape.pos[tape.counter].delay++;
651 void TapeTogglePause(boolean toggle_manual)
655 if (tape.pause_before_death)
656 state |= VIDEO_STATE_PBEND_OFF;
657 else if (tape.fast_forward)
658 state |= VIDEO_STATE_FFWD_OFF;
660 tape.pausing = !tape.pausing;
661 tape.fast_forward = FALSE;
662 tape.pause_before_death = FALSE;
664 if (tape.single_step && toggle_manual)
665 tape.single_step = FALSE;
667 state |= (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
669 state |= VIDEO_STATE_PLAY_ON;
671 state |= (tape.single_step ? VIDEO_STATE_1STEP_ON : VIDEO_STATE_1STEP_OFF);
673 DrawVideoDisplay(state, 0);
675 if (tape.warp_forward)
677 TapeStopWarpForward();
679 if (tape.quick_resume)
681 tape.quick_resume = FALSE;
683 TapeAppendRecording();
685 if (!CheckEngineSnapshot())
686 SaveEngineSnapshot();
691 void TapeStartPlaying()
693 if (TAPE_IS_EMPTY(tape))
696 if (!TAPE_IS_STOPPED(tape))
703 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
704 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
705 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
708 SetDrawDeactivationMask(REDRAW_NONE);
709 audio.sound_deactivated = FALSE;
712 static void TapeStartGamePlaying()
719 void TapeStopPlaying()
721 tape.playing = FALSE;
722 tape.pausing = FALSE;
724 if (tape.warp_forward)
725 TapeStopWarpForward();
727 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
728 MapTapeEjectButton();
731 byte *TapePlayAction()
733 static byte action[MAX_PLAYERS];
736 if (!tape.playing || tape.pausing)
739 if (tape.pause_before_death) /* stop 10 seconds before player gets killed */
741 if (!(FrameCounter % 20))
743 if ((FrameCounter / 20) % 2)
744 DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY);
746 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF, VIDEO_DISPLAY_LABEL_ONLY);
749 if (tape.warp_forward)
751 if (tape.deactivate_display)
752 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
754 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
757 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
759 TapeTogglePause(TAPE_TOGGLE_MANUAL);
764 else if (tape.fast_forward)
766 if ((FrameCounter / 20) % 2)
767 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, VIDEO_DISPLAY_LABEL_ONLY);
769 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF, VIDEO_DISPLAY_LABEL_ONLY);
771 if (tape.warp_forward)
773 if (tape.deactivate_display)
774 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
776 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
781 /* !!! this makes things much slower !!! */
782 else if (tape.warp_forward)
784 if ((FrameCounter / 20) % 2)
785 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_LABEL_ONLY);
787 DrawVideoDisplay(VIDEO_STATE_WARP_OFF, VIDEO_DISPLAY_LABEL_ONLY);
789 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
793 if (tape.counter >= tape.length) /* end of tape reached */
795 if (tape.warp_forward && !tape.auto_play)
796 TapeTogglePause(TAPE_TOGGLE_MANUAL);
803 for (i = 0; i < MAX_PLAYERS; i++)
804 action[i] = tape.pos[tape.counter].action[i];
806 tape.set_centered_player = FALSE;
807 tape.centered_player_nr_next = -999;
809 for (i = 0; i < MAX_PLAYERS; i++)
811 if (action[i] & KEY_SET_FOCUS)
813 tape.set_centered_player = TRUE;
814 tape.centered_player_nr_next =
815 (tape.centered_player_nr_next == -999 ? i : -1);
818 action[i] &= ~KEY_SET_FOCUS;
822 if (tape.delay_played >= tape.pos[tape.counter].delay)
825 tape.delay_played = 0;
836 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
838 if (tape.date && tape.length)
840 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
841 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
845 unsigned int GetTapeLength()
847 unsigned int tape_length = 0;
850 if (TAPE_IS_EMPTY(tape))
853 for (i = 0; i < tape.length; i++)
854 tape_length += tape.pos[i].delay;
856 return(tape_length * GAME_FRAME_DELAY / 1000);
859 static void TapeStartWarpForward()
861 tape.warp_forward = TRUE;
863 if (!tape.fast_forward && !tape.pause_before_death)
865 tape.pausing = FALSE;
866 tape.deactivate_display = TRUE;
868 TapeDeactivateDisplayOn();
871 if (tape.fast_forward || tape.pause_before_death)
872 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
874 DrawVideoDisplay(VIDEO_STATE_WARP_ON, 0);
877 static void TapeStopWarpForward()
879 int state = (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
881 tape.warp_forward = FALSE;
882 tape.deactivate_display = FALSE;
884 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
886 if (tape.pause_before_death)
887 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PBEND_ON;
888 else if (tape.fast_forward)
889 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_FFWD_ON;
891 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PLAY_ON;
893 DrawVideoDisplay(state, 0);
896 static void TapeSingleStep()
902 TapeTogglePause(TAPE_TOGGLE_MANUAL);
904 tape.single_step = !tape.single_step;
906 DrawVideoDisplay((tape.single_step ? VIDEO_STATE_1STEP_ON :
907 VIDEO_STATE_1STEP_OFF), 0);
912 if (game_status == GAME_MODE_MAIN)
914 Request("No game that can be saved !", REQ_CONFIRM);
919 if (game_status != GAME_MODE_PLAYING)
923 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
925 if (TAPE_IS_EMPTY(tape))
927 Request("No tape that can be saved !", REQ_CONFIRM);
932 if (SaveTapeChecked(tape.level_nr))
933 SaveEngineSnapshot();
938 char *filename = getTapeFilename(level_nr);
940 if (!fileExists(filename))
942 Request("No tape for this level !", REQ_CONFIRM);
947 if (tape.recording && !Request("Stop recording and load tape ?",
948 REQ_ASK | REQ_STAY_CLOSED))
950 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
955 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
958 if (CheckEngineSnapshot())
960 TapeStartGamePlaying();
962 LoadEngineSnapshot();
964 DrawCompleteVideoDisplay();
969 TapeStopWarpForward();
970 TapeAppendRecording();
972 if (FrameCounter > 0)
981 if (!TAPE_IS_EMPTY(tape))
983 TapeStartGamePlaying();
984 TapeStartWarpForward();
986 tape.quick_resume = TRUE;
988 else /* this should not happen (basically checked above) */
990 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
992 Request("No tape for this level !", REQ_CONFIRM | reopen_door);
996 void InsertSolutionTape()
998 if (!TAPE_IS_EMPTY(tape))
1001 LoadSolutionTape(level_nr);
1003 if (TAPE_IS_EMPTY(tape))
1004 Request("No solution tape for this level !", REQ_CONFIRM);
1006 DrawCompleteVideoDisplay();
1010 /* ------------------------------------------------------------------------- *
1011 * tape autoplay functions
1012 * ------------------------------------------------------------------------- */
1016 static LevelDirTree *autoplay_leveldir = NULL;
1017 static boolean autoplay_initialized = FALSE;
1018 static int autoplay_level_nr = -1;
1019 static int num_levels_played = 0;
1020 static int num_levels_solved = 0;
1021 static int num_tape_missing = 0;
1022 static boolean level_failed[MAX_TAPES_PER_SET];
1023 static boolean tape_missing[MAX_TAPES_PER_SET];
1026 if (autoplay_initialized)
1028 /* just finished auto-playing tape */
1029 printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1031 num_levels_played++;
1033 if (tape.auto_play_level_solved)
1034 num_levels_solved++;
1035 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1036 level_failed[level_nr] = TRUE;
1040 DrawCompleteVideoDisplay();
1041 audio.sound_enabled = FALSE;
1043 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1044 global.autoplay_leveldir);
1046 if (autoplay_leveldir == NULL)
1047 Error(ERR_EXIT, "no such level identifier: '%s'",
1048 global.autoplay_leveldir);
1050 leveldir_current = autoplay_leveldir;
1052 if (autoplay_leveldir->first_level < 0)
1053 autoplay_leveldir->first_level = 0;
1054 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1055 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1057 autoplay_level_nr = autoplay_leveldir->first_level;
1059 printf_line("=", 79);
1060 printf("Automatically playing level tapes\n");
1061 printf_line("-", 79);
1062 printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1063 printf("Level series name: '%s'\n", autoplay_leveldir->name);
1064 printf("Level series author: '%s'\n", autoplay_leveldir->author);
1065 printf("Number of levels: %d\n", autoplay_leveldir->levels);
1066 printf_line("=", 79);
1069 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1071 level_failed[i] = FALSE;
1072 tape_missing[i] = FALSE;
1075 autoplay_initialized = TRUE;
1078 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1080 level_nr = autoplay_level_nr++;
1082 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1087 printf("Level %03d: ", level_nr);
1089 LoadLevel(level_nr);
1090 if (level.no_valid_file)
1092 printf("(no level)\n");
1097 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1098 printf("(only testing level)\n");
1102 LoadSolutionTape(level_nr);
1104 if (tape.no_valid_file)
1107 if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1108 tape_missing[level_nr] = TRUE;
1110 printf("(no tape)\n");
1114 printf("playing tape ... ");
1116 TapeStartGamePlaying();
1117 TapeStartWarpForward();
1123 printf_line("=", 79);
1124 printf("Number of levels played: %d\n", num_levels_played);
1125 printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1126 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1127 printf_line("-", 79);
1128 printf("Summary (for automatic parsing by scripts):\n");
1129 printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1130 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1131 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1133 if (num_levels_played != num_levels_solved)
1135 printf(", FAILED:");
1136 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1137 if (level_failed[i])
1142 if (num_tape_missing > 0)
1144 printf(", NO TAPE:");
1145 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1146 if (tape_missing[i])
1152 printf_line("=", 79);
1158 /* ---------- new tape button stuff ---------------------------------------- */
1160 /* graphic position values for tape buttons */
1161 #define TAPE_BUTTON_XSIZE 18
1162 #define TAPE_BUTTON_YSIZE 18
1163 #define TAPE_BUTTON_XPOS 5
1164 #define TAPE_BUTTON_YPOS 77
1166 #define TAPE_BUTTON_EJECT_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
1167 #define TAPE_BUTTON_EXTRA_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
1168 #define TAPE_BUTTON_STOP_XPOS (TAPE_BUTTON_XPOS + 1 * TAPE_BUTTON_XSIZE)
1169 #define TAPE_BUTTON_PAUSE_XPOS (TAPE_BUTTON_XPOS + 2 * TAPE_BUTTON_XSIZE)
1170 #define TAPE_BUTTON_RECORD_XPOS (TAPE_BUTTON_XPOS + 3 * TAPE_BUTTON_XSIZE)
1171 #define TAPE_BUTTON_PLAY_XPOS (TAPE_BUTTON_XPOS + 4 * TAPE_BUTTON_XSIZE)
1178 } tapebutton_info[NUM_TAPE_BUTTONS] =
1181 TAPE_BUTTON_EJECT_XPOS, TAPE_BUTTON_YPOS,
1186 TAPE_BUTTON_EXTRA_XPOS, TAPE_BUTTON_YPOS,
1191 TAPE_BUTTON_STOP_XPOS, TAPE_BUTTON_YPOS,
1196 TAPE_BUTTON_PAUSE_XPOS, TAPE_BUTTON_YPOS,
1201 TAPE_BUTTON_RECORD_XPOS, TAPE_BUTTON_YPOS,
1202 TAPE_CTRL_ID_RECORD,
1206 TAPE_BUTTON_PLAY_XPOS, TAPE_BUTTON_YPOS,
1212 void CreateTapeButtons()
1216 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1218 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
1219 struct GadgetInfo *gi;
1220 int gd_xoffset, gd_yoffset;
1221 int gd_x1, gd_x2, gd_y;
1224 gd_xoffset = tapebutton_info[i].x;
1225 gd_yoffset = tapebutton_info[i].y;
1226 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
1227 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
1228 gd_y = DOOR_GFX_PAGEY2 + gd_yoffset;
1230 if (i == TAPE_CTRL_ID_EXTRA)
1232 gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
1233 gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
1236 gi = CreateGadget(GDI_CUSTOM_ID, id,
1237 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1238 GDI_X, VX + gd_xoffset,
1239 GDI_Y, VY + gd_yoffset,
1240 GDI_WIDTH, TAPE_BUTTON_XSIZE,
1241 GDI_HEIGHT, TAPE_BUTTON_YSIZE,
1242 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1243 GDI_STATE, GD_BUTTON_UNPRESSED,
1244 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1245 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1246 GDI_DIRECT_DRAW, FALSE,
1247 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1248 GDI_CALLBACK_ACTION, HandleTapeButtons,
1252 Error(ERR_EXIT, "cannot create gadget");
1254 tape_gadget[id] = gi;
1258 void FreeTapeButtons()
1262 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1263 FreeGadget(tape_gadget[i]);
1266 void MapTapeEjectButton()
1268 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1269 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1272 void MapTapeWarpButton()
1274 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1275 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1278 void MapTapeButtons()
1282 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1283 if (i != TAPE_CTRL_ID_EXTRA)
1284 MapGadget(tape_gadget[i]);
1286 if (tape.recording || tape.playing)
1287 MapTapeWarpButton();
1290 void UnmapTapeButtons()
1294 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1295 UnmapGadget(tape_gadget[i]);
1298 static void HandleTapeButtons(struct GadgetInfo *gi)
1300 int id = gi->custom_id;
1302 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1307 case TAPE_CTRL_ID_EJECT:
1310 if (TAPE_IS_EMPTY(tape))
1314 if (TAPE_IS_EMPTY(tape))
1315 Request("No tape for this level !", REQ_CONFIRM);
1320 SaveTapeChecked(tape.level_nr);
1325 DrawCompleteVideoDisplay();
1328 case TAPE_CTRL_ID_EXTRA:
1331 if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
1333 TapeStartWarpForward();
1335 else /* WARP FORWARD PLAY -> PLAY */
1337 TapeStopWarpForward();
1340 else if (tape.recording)
1345 case TAPE_CTRL_ID_STOP:
1349 case TAPE_CTRL_ID_PAUSE:
1350 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1353 case TAPE_CTRL_ID_RECORD:
1354 if (TAPE_IS_STOPPED(tape))
1355 TapeStartGameRecording();
1356 else if (tape.pausing)
1358 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1359 TapeAppendRecording();
1361 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1365 case TAPE_CTRL_ID_PLAY:
1366 if (TAPE_IS_EMPTY(tape))
1369 if (TAPE_IS_STOPPED(tape))
1371 TapeStartGamePlaying();
1373 else if (tape.playing)
1375 if (tape.pausing) /* PAUSE -> PLAY */
1377 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1379 else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
1381 tape.fast_forward = TRUE;
1382 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1384 else if (!tape.pause_before_death) /* FFWD PLAY -> AUTO PAUSE */
1386 tape.pause_before_death = TRUE;
1387 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1389 else /* AUTO PAUSE -> NORMAL PLAY */
1391 if (tape.warp_forward)
1392 TapeStopWarpForward();
1394 tape.fast_forward = FALSE;
1395 tape.pause_before_death = FALSE;
1397 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);