1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
5 * Holger Schemel *
6 * Detmolder Strasse 189 *
7 * 33604 Bielefeld *
8 * Germany *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
11 * tape.c *
12 ***********************************************************/
13
14 #include "libgame/libgame.h"
15
16 #include "tape.h"
17 #include "init.h"
18 #include "game.h"
19 #include "tools.h"
20 #include "files.h"
21 #include "network.h"
22 #include "cartoons.h"
23
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
31
32 #define NUM_TAPE_BUTTONS 6
33
34 /* values for tape handling */
35 #define TAPE_PAUSE_SECONDS_BEFORE_DEATH 5
36
37 /* forward declaration for internal use */
38 static void HandleTapeButtons(struct GadgetInfo *);
39 static void TapeStopWarpForward();
40
41 static struct GadgetInfo *tape_gadget[NUM_TAPE_BUTTONS];
42
43
44 /* ========================================================================= */
45 /* video tape definitions */
46 /* ========================================================================= */
47
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
85
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
95
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
105
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
114
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
127
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
132
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))
137
138 #define PG_Y1(y) (DOOR_GFX_PAGEY1 + (y))
139 #define PG_Y2(y) (DOOR_GFX_PAGEY2 + (y))
140
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 | \
155 VIDEO_STATE_OFF | \
156 VIDEO_PRESS_OFF)
157
158 #define VIDEO_INFO_ON (VIDEO_STATE_DATE_ON | \
159 VIDEO_STATE_TIME_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 | \
172 VIDEO_STATE_ON | \
173 VIDEO_PRESS_ON)
174
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)
179
180 #define NUM_TAPE_FUNCTIONS 10
181 #define NUM_TAPE_FUNCTION_PARTS 2
182 #define NUM_TAPE_FUNCTION_STATES 2
183
184
185 /* ========================================================================= */
186 /* video display functions */
187 /* ========================================================================= */
188
DrawVideoDisplay(unsigned long state,unsigned long value)189 void DrawVideoDisplay(unsigned long state, unsigned long value)
190 {
191 int i, j, k;
192 static char *monatsname[12] =
193 {
194 "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
195 "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
196 };
197 static struct
198 {
199 int gd_x1, gd_y1;
200 int gd_x2, gd_y2;
201 int x, y;
202 int width, height;
203 }
204 video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
205 {
206 {
207 {
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
212 },
213 {
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
218 }
219 },
220 {
221 {
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
226 },
227 {
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
232 }
233 },
234 {
235 {
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
240 },
241 {
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
246 }
247 },
248 {
249 {
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
254 },
255 {
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
260 }
261 },
262 {
263 {
264 -1, -1,
265 -1, -1,
266 -1, -1,
267 -1, -1
268 },
269 {
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
274 }
275 },
276 {
277 {
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
282 },
283 {
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
288 }
289 },
290 {
291 {
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
296 },
297 {
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
302 }
303 },
304 {
305 {
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
310 },
311 {
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
316 }
317 },
318 {
319 {
320 -1, -1,
321 -1, -1,
322 -1, -1,
323 -1, -1
324 },
325 {
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
330 }
331 },
332 {
333 {
334 -1, -1,
335 -1, -1,
336 -1, -1,
337 -1, -1
338 },
339 {
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
344 }
345 },
346 };
347
348 for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */
349 {
350 for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */
351 {
352 for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */
353 {
354 if (state & (1 << (i * 2 + k)))
355 {
356 int gd_x, gd_y;
357 int skip_value =
358 (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
359
360 if (k == 1) /* on */
361 {
362 gd_x = video_pos[i][j].gd_x1;
363 gd_y = video_pos[i][j].gd_y1;
364 }
365 else /* off */
366 {
367 gd_x = video_pos[i][j].gd_x2;
368 gd_y = video_pos[i][j].gd_y2;
369 }
370
371 if (video_pos[i][j].x != -1 && value != skip_value)
372 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
373 gd_x, gd_y,
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);
378 }
379 }
380 }
381 }
382
383 if (state & VIDEO_STATE_DATE_ON)
384 {
385 int tag = value % 100;
386 int monat = (value/100) % 100;
387 int jahr = (value/10000);
388
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);
395 }
396
397 if (state & VIDEO_STATE_TIME_ON)
398 {
399 int min = value / 60;
400 int sec = value % 60;
401
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);
406 }
407
408 redraw_mask |= REDRAW_DOOR_2;
409 }
410
DrawCompleteVideoDisplay()411 void DrawCompleteVideoDisplay()
412 {
413 #if 0
414 printf("::: %d, %d / %d, %d [%d] [%d, %d] [%d/%d]\n",
415 VX, VY, EX, EY, game_status, gfx.vx, gfx.vy,
416 tape.date, tape.length);
417 #endif
418
419 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
420 DOOR_GFX_PAGEX3, DOOR_GFX_PAGEY2,
421 gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
422 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
423 DOOR_GFX_PAGEX4 + VIDEO_CONTROL_XPOS,
424 DOOR_GFX_PAGEY2 + VIDEO_CONTROL_YPOS,
425 VIDEO_CONTROL_XSIZE, VIDEO_CONTROL_YSIZE,
426 gfx.vx + VIDEO_CONTROL_XPOS, gfx.vy + VIDEO_CONTROL_YPOS);
427
428 DrawVideoDisplay(VIDEO_ALL_OFF, 0);
429
430 #if 1
431 if (tape.recording)
432 {
433 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
434 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
435 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
436
437 if (tape.pausing)
438 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
439 }
440 else if (tape.playing)
441 {
442 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
443 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
444 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
445
446 if (tape.pausing)
447 DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
448 }
449 else if (tape.date && tape.length)
450 {
451 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
452 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
453 }
454 #else
455 if (tape.date && tape.length)
456 {
457 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
458 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
459 }
460 #endif
461
462 BlitBitmap(drawto, bitmap_db_door, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
463 DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2);
464 }
465
TapeDeactivateDisplayOn()466 void TapeDeactivateDisplayOn()
467 {
468 SetDrawDeactivationMask(REDRAW_FIELD);
469 audio.sound_deactivated = TRUE;
470 }
471
TapeDeactivateDisplayOff(boolean redraw_display)472 void TapeDeactivateDisplayOff(boolean redraw_display)
473 {
474 SetDrawDeactivationMask(REDRAW_NONE);
475 audio.sound_deactivated = FALSE;
476
477 if (redraw_display)
478 {
479 RedrawPlayfield(TRUE, 0,0,0,0);
480 DrawGameDoorValues();
481 }
482 }
483
484
485 /* ========================================================================= */
486 /* tape control functions */
487 /* ========================================================================= */
488
TapeSetDateFromEpochSeconds(time_t epoch_seconds)489 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
490 {
491 struct tm *lt = localtime(&epoch_seconds);
492
493 tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
494 }
495
TapeSetDateFromNow()496 void TapeSetDateFromNow()
497 {
498 TapeSetDateFromEpochSeconds(time(NULL));
499 }
500
TapeErase()501 void TapeErase()
502 {
503 int i;
504
505 tape.counter = 0;
506 tape.length = 0;
507 tape.length_seconds = 0;
508
509 if (leveldir_current)
510 setString(&tape.level_identifier, leveldir_current->identifier);
511
512 tape.level_nr = level_nr;
513 tape.pos[tape.counter].delay = 0;
514 tape.changed = TRUE;
515
516 tape.random_seed = InitRND(level.random_seed);
517
518 tape.file_version = FILE_VERSION_ACTUAL;
519 tape.game_version = GAME_VERSION_ACTUAL;
520 tape.engine_version = level.game_version;
521
522 TapeSetDateFromNow();
523
524 for (i = 0; i < MAX_PLAYERS; i++)
525 tape.player_participates[i] = FALSE;
526
527 tape.centered_player_nr_next = -1;
528 tape.set_centered_player = FALSE;
529 }
530
TapeRewind()531 static void TapeRewind()
532 {
533 tape.counter = 0;
534 tape.delay_played = 0;
535 tape.pause_before_death = FALSE;
536 tape.recording = FALSE;
537 tape.playing = FALSE;
538 tape.fast_forward = FALSE;
539 tape.warp_forward = FALSE;
540 tape.deactivate_display = FALSE;
541 tape.auto_play = (global.autoplay_leveldir != NULL);
542 tape.auto_play_level_solved = FALSE;
543 tape.quick_resume = FALSE;
544 tape.single_step = FALSE;
545
546 tape.centered_player_nr_next = -1;
547 tape.set_centered_player = FALSE;
548
549 InitRND(tape.random_seed);
550 }
551
TapeSetRandomSeed(long random_seed)552 static void TapeSetRandomSeed(long random_seed)
553 {
554 tape.random_seed = InitRND(random_seed);
555 }
556
TapeStartRecording(long random_seed)557 void TapeStartRecording(long random_seed)
558 {
559 if (!TAPE_IS_STOPPED(tape))
560 TapeStop();
561
562 TapeErase();
563 TapeRewind();
564 TapeSetRandomSeed(random_seed);
565
566 tape.recording = TRUE;
567
568 DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
569 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
570 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
571
572 MapTapeWarpButton();
573
574 SetDrawDeactivationMask(REDRAW_NONE);
575 audio.sound_deactivated = FALSE;
576 }
577
TapeStartGameRecording()578 static void TapeStartGameRecording()
579 {
580 TapeStartRecording(level.random_seed);
581
582 #if defined(NETWORK_AVALIABLE)
583 if (options.network)
584 {
585 SendToServer_StartPlaying();
586
587 return;
588 }
589 #endif
590
591 InitGame();
592 }
593
TapeAppendRecording()594 static void TapeAppendRecording()
595 {
596 if (!tape.playing || !tape.pausing)
597 return;
598
599 tape.pos[tape.counter].delay = tape.delay_played;
600 tape.playing = FALSE;
601 tape.recording = TRUE;
602 tape.changed = TRUE;
603
604 TapeSetDateFromNow();
605
606 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
607 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
608
609 #if 1
610 UpdateAndDisplayGameControlValues();
611 #endif
612 }
613
TapeHaltRecording()614 void TapeHaltRecording()
615 {
616 if (!tape.recording)
617 return;
618
619 tape.counter++;
620 tape.pos[tape.counter].delay = 0;
621
622 tape.length = tape.counter;
623 tape.length_seconds = GetTapeLength();
624 }
625
TapeStopRecording()626 void TapeStopRecording()
627 {
628 TapeHaltRecording();
629
630 tape.recording = FALSE;
631 tape.pausing = FALSE;
632
633 DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
634 MapTapeEjectButton();
635 }
636
TapeRecordAction(byte action_raw[MAX_PLAYERS])637 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
638 {
639 byte action[MAX_PLAYERS];
640 int i;
641
642 if (!tape.recording) /* (record action even when tape is paused) */
643 return;
644
645 if (tape.counter >= MAX_TAPE_LEN - 1)
646 {
647 TapeStopRecording();
648 return;
649 }
650
651 for (i = 0; i < MAX_PLAYERS; i++)
652 action[i] = action_raw[i];
653
654 if (tape.set_centered_player)
655 {
656 for (i = 0; i < MAX_PLAYERS; i++)
657 if (tape.centered_player_nr_next == i ||
658 tape.centered_player_nr_next == -1)
659 action[i] |= KEY_SET_FOCUS;
660
661 tape.set_centered_player = FALSE;
662 }
663
664 if (tape.pos[tape.counter].delay > 0) /* already stored action */
665 {
666 boolean changed_events = FALSE;
667
668 for (i = 0; i < MAX_PLAYERS; i++)
669 if (tape.pos[tape.counter].action[i] != action[i])
670 changed_events = TRUE;
671
672 if (changed_events || tape.pos[tape.counter].delay >= 255)
673 {
674 tape.counter++;
675 tape.pos[tape.counter].delay = 0;
676 }
677 else
678 tape.pos[tape.counter].delay++;
679 }
680
681 if (tape.pos[tape.counter].delay == 0) /* store new action */
682 {
683 for (i = 0; i < MAX_PLAYERS; i++)
684 tape.pos[tape.counter].action[i] = action[i];
685
686 tape.pos[tape.counter].delay++;
687 }
688 }
689
TapeTogglePause(boolean toggle_manual)690 void TapeTogglePause(boolean toggle_manual)
691 {
692 int state = 0;
693
694 if (tape.pause_before_death)
695 state |= VIDEO_STATE_PBEND_OFF;
696 else if (tape.fast_forward)
697 state |= VIDEO_STATE_FFWD_OFF;
698
699 tape.pausing = !tape.pausing;
700 tape.fast_forward = FALSE;
701 tape.pause_before_death = FALSE;
702
703 if (tape.single_step && toggle_manual)
704 tape.single_step = FALSE;
705
706 state |= (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
707 if (tape.playing)
708 state |= VIDEO_STATE_PLAY_ON;
709 else
710 state |= (tape.single_step ? VIDEO_STATE_1STEP_ON : VIDEO_STATE_1STEP_OFF);
711
712 DrawVideoDisplay(state, 0);
713
714 if (tape.warp_forward)
715 {
716 TapeStopWarpForward();
717
718 if (tape.quick_resume)
719 {
720 tape.quick_resume = FALSE;
721
722 TapeAppendRecording();
723
724 if (!CheckEngineSnapshot())
725 SaveEngineSnapshot();
726 }
727 }
728 }
729
TapeStartPlaying()730 void TapeStartPlaying()
731 {
732 if (TAPE_IS_EMPTY(tape))
733 return;
734
735 if (!TAPE_IS_STOPPED(tape))
736 TapeStop();
737
738 TapeRewind();
739
740 tape.playing = TRUE;
741
742 DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
743 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
744 DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
745
746 MapTapeWarpButton();
747
748 SetDrawDeactivationMask(REDRAW_NONE);
749 audio.sound_deactivated = FALSE;
750 }
751
TapeStartGamePlaying()752 static void TapeStartGamePlaying()
753 {
754 TapeStartPlaying();
755
756 InitGame();
757 }
758
TapeStopPlaying()759 void TapeStopPlaying()
760 {
761 tape.playing = FALSE;
762 tape.pausing = FALSE;
763
764 if (tape.warp_forward)
765 TapeStopWarpForward();
766
767 DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
768 MapTapeEjectButton();
769 }
770
TapePlayAction()771 byte *TapePlayAction()
772 {
773 static byte action[MAX_PLAYERS];
774 int i;
775
776 if (!tape.playing || tape.pausing)
777 return NULL;
778
779 if (tape.pause_before_death) /* stop 10 seconds before player gets killed */
780 {
781 if (!(FrameCounter % 20))
782 {
783 if ((FrameCounter / 20) % 2)
784 DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY);
785 else
786 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF, VIDEO_DISPLAY_LABEL_ONLY);
787 }
788
789 if (tape.warp_forward)
790 {
791 if (tape.deactivate_display)
792 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
793 else
794 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
795 }
796
797 if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
798 {
799 TapeTogglePause(TAPE_TOGGLE_MANUAL);
800
801 return NULL;
802 }
803 }
804 else if (tape.fast_forward)
805 {
806 if ((FrameCounter / 20) % 2)
807 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, VIDEO_DISPLAY_LABEL_ONLY);
808 else
809 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF, VIDEO_DISPLAY_LABEL_ONLY);
810
811 if (tape.warp_forward)
812 {
813 if (tape.deactivate_display)
814 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
815 else
816 DrawVideoDisplay(VIDEO_STATE_WARP2_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
817 }
818 }
819
820 #if 0
821 /* !!! this makes things much slower !!! */
822 else if (tape.warp_forward)
823 {
824 if ((FrameCounter / 20) % 2)
825 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_LABEL_ONLY);
826 else
827 DrawVideoDisplay(VIDEO_STATE_WARP_OFF, VIDEO_DISPLAY_LABEL_ONLY);
828
829 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
830 }
831 #endif
832
833 if (tape.counter >= tape.length) /* end of tape reached */
834 {
835 if (tape.warp_forward && !tape.auto_play)
836 TapeTogglePause(TAPE_TOGGLE_MANUAL);
837 else
838 TapeStop();
839
840 return NULL;
841 }
842
843 for (i = 0; i < MAX_PLAYERS; i++)
844 action[i] = tape.pos[tape.counter].action[i];
845
846 tape.set_centered_player = FALSE;
847 tape.centered_player_nr_next = -999;
848
849 for (i = 0; i < MAX_PLAYERS; i++)
850 {
851 if (action[i] & KEY_SET_FOCUS)
852 {
853 tape.set_centered_player = TRUE;
854 tape.centered_player_nr_next =
855 (tape.centered_player_nr_next == -999 ? i : -1);
856 }
857
858 action[i] &= ~KEY_SET_FOCUS;
859 }
860
861 tape.delay_played++;
862 if (tape.delay_played >= tape.pos[tape.counter].delay)
863 {
864 tape.counter++;
865 tape.delay_played = 0;
866 }
867
868 return action;
869 }
870
TapeStop()871 void TapeStop()
872 {
873 TapeStopRecording();
874 TapeStopPlaying();
875
876 DrawVideoDisplay(VIDEO_STATE_OFF, 0);
877
878 if (tape.date && tape.length)
879 {
880 DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
881 DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
882 }
883 }
884
GetTapeLength()885 unsigned int GetTapeLength()
886 {
887 unsigned int tape_length = 0;
888 int i;
889
890 if (TAPE_IS_EMPTY(tape))
891 return(0);
892
893 for (i = 0; i < tape.length; i++)
894 tape_length += tape.pos[i].delay;
895
896 return(tape_length * GAME_FRAME_DELAY / 1000);
897 }
898
TapeStartWarpForward()899 static void TapeStartWarpForward()
900 {
901 tape.warp_forward = TRUE;
902
903 if (!tape.fast_forward && !tape.pause_before_death)
904 {
905 tape.pausing = FALSE;
906 tape.deactivate_display = TRUE;
907
908 TapeDeactivateDisplayOn();
909 }
910
911 if (tape.fast_forward || tape.pause_before_death)
912 DrawVideoDisplay(VIDEO_STATE_WARP_ON, VIDEO_DISPLAY_SYMBOL_ONLY);
913 else
914 DrawVideoDisplay(VIDEO_STATE_WARP_ON, 0);
915 }
916
TapeStopWarpForward()917 static void TapeStopWarpForward()
918 {
919 int state = (tape.pausing ? VIDEO_STATE_PAUSE_ON : VIDEO_STATE_PAUSE_OFF);
920
921 tape.warp_forward = FALSE;
922 tape.deactivate_display = FALSE;
923
924 TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
925
926 if (tape.pause_before_death)
927 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PBEND_ON;
928 else if (tape.fast_forward)
929 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_FFWD_ON;
930 else
931 state |= VIDEO_STATE_WARP_OFF | VIDEO_STATE_PLAY_ON;
932
933 DrawVideoDisplay(state, 0);
934 }
935
TapeSingleStep()936 static void TapeSingleStep()
937 {
938 if (options.network)
939 return;
940
941 if (!tape.pausing)
942 TapeTogglePause(TAPE_TOGGLE_MANUAL);
943
944 tape.single_step = !tape.single_step;
945
946 DrawVideoDisplay((tape.single_step ? VIDEO_STATE_1STEP_ON :
947 VIDEO_STATE_1STEP_OFF), 0);
948 }
949
TapeQuickSave()950 void TapeQuickSave()
951 {
952 if (game_status == GAME_MODE_MAIN)
953 {
954 Request("No game that can be saved !", REQ_CONFIRM);
955
956 return;
957 }
958
959 if (game_status != GAME_MODE_PLAYING)
960 return;
961
962 if (tape.recording)
963 TapeHaltRecording(); /* prepare tape for saving on-the-fly */
964
965 if (TAPE_IS_EMPTY(tape))
966 {
967 Request("No tape that can be saved !", REQ_CONFIRM);
968
969 return;
970 }
971
972 if (SaveTapeChecked(tape.level_nr))
973 SaveEngineSnapshot();
974 }
975
TapeQuickLoad()976 void TapeQuickLoad()
977 {
978 char *filename = getTapeFilename(level_nr);
979
980 if (!fileExists(filename))
981 {
982 Request("No tape for this level !", REQ_CONFIRM);
983
984 return;
985 }
986
987 if (tape.recording && !Request("Stop recording and load tape ?",
988 REQ_ASK | REQ_STAY_CLOSED))
989 {
990 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
991
992 return;
993 }
994
995 if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
996 return;
997
998 if (CheckEngineSnapshot())
999 {
1000 TapeStartGamePlaying();
1001
1002 LoadEngineSnapshot();
1003
1004 DrawCompleteVideoDisplay();
1005
1006 tape.playing = TRUE;
1007 tape.pausing = TRUE;
1008
1009 TapeStopWarpForward();
1010 TapeAppendRecording();
1011
1012 if (FrameCounter > 0)
1013 return;
1014 }
1015
1016 TapeStop();
1017 TapeErase();
1018
1019 LoadTape(level_nr);
1020
1021 if (!TAPE_IS_EMPTY(tape))
1022 {
1023 TapeStartGamePlaying();
1024 TapeStartWarpForward();
1025
1026 tape.quick_resume = TRUE;
1027 }
1028 else /* this should not happen (basically checked above) */
1029 {
1030 int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1031
1032 Request("No tape for this level !", REQ_CONFIRM | reopen_door);
1033 }
1034 }
1035
InsertSolutionTape()1036 void InsertSolutionTape()
1037 {
1038 if (!TAPE_IS_EMPTY(tape))
1039 return;
1040
1041 LoadSolutionTape(level_nr);
1042
1043 if (TAPE_IS_EMPTY(tape))
1044 Request("No solution tape for this level !", REQ_CONFIRM);
1045
1046 DrawCompleteVideoDisplay();
1047 }
1048
1049
1050 /* ------------------------------------------------------------------------- *
1051 * tape autoplay functions
1052 * ------------------------------------------------------------------------- */
1053
AutoPlayTape()1054 void AutoPlayTape()
1055 {
1056 static LevelDirTree *autoplay_leveldir = NULL;
1057 static boolean autoplay_initialized = FALSE;
1058 static int autoplay_level_nr = -1;
1059 static int num_levels_played = 0;
1060 static int num_levels_solved = 0;
1061 static int num_tape_missing = 0;
1062 static boolean level_failed[MAX_TAPES_PER_SET];
1063 static boolean tape_missing[MAX_TAPES_PER_SET];
1064 int i;
1065
1066 if (autoplay_initialized)
1067 {
1068 /* just finished auto-playing tape */
1069 printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1070
1071 num_levels_played++;
1072
1073 if (tape.auto_play_level_solved)
1074 num_levels_solved++;
1075 else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1076 level_failed[level_nr] = TRUE;
1077 }
1078 else
1079 {
1080 DrawCompleteVideoDisplay();
1081 audio.sound_enabled = FALSE;
1082
1083 autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1084 global.autoplay_leveldir);
1085
1086 if (autoplay_leveldir == NULL)
1087 Error(ERR_EXIT, "no such level identifier: '%s'",
1088 global.autoplay_leveldir);
1089
1090 leveldir_current = autoplay_leveldir;
1091
1092 if (autoplay_leveldir->first_level < 0)
1093 autoplay_leveldir->first_level = 0;
1094 if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1095 autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1096
1097 autoplay_level_nr = autoplay_leveldir->first_level;
1098
1099 printf_line("=", 79);
1100 printf("Automatically playing level tapes\n");
1101 printf_line("-", 79);
1102 printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1103 printf("Level series name: '%s'\n", autoplay_leveldir->name);
1104 printf("Level series author: '%s'\n", autoplay_leveldir->author);
1105 printf("Number of levels: %d\n", autoplay_leveldir->levels);
1106 printf_line("=", 79);
1107 printf("\n");
1108
1109 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1110 {
1111 level_failed[i] = FALSE;
1112 tape_missing[i] = FALSE;
1113 }
1114
1115 autoplay_initialized = TRUE;
1116 }
1117
1118 while (autoplay_level_nr <= autoplay_leveldir->last_level)
1119 {
1120 level_nr = autoplay_level_nr++;
1121
1122 if (!global.autoplay_all && !global.autoplay_level[level_nr])
1123 continue;
1124
1125 TapeErase();
1126
1127 printf("Level %03d: ", level_nr);
1128
1129 LoadLevel(level_nr);
1130 if (level.no_valid_file)
1131 {
1132 printf("(no level)\n");
1133 continue;
1134 }
1135
1136 #if 0
1137 /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1138 printf("(only testing level)\n");
1139 continue;
1140 #endif
1141
1142 LoadSolutionTape(level_nr);
1143
1144 if (tape.no_valid_file)
1145 {
1146 num_tape_missing++;
1147 if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1148 tape_missing[level_nr] = TRUE;
1149
1150 printf("(no tape)\n");
1151 continue;
1152 }
1153
1154 printf("playing tape ... ");
1155
1156 TapeStartGamePlaying();
1157 TapeStartWarpForward();
1158
1159 return;
1160 }
1161
1162 printf("\n");
1163 printf_line("=", 79);
1164 printf("Number of levels played: %d\n", num_levels_played);
1165 printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1166 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1167 printf_line("-", 79);
1168 printf("Summary (for automatic parsing by scripts):\n");
1169 printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1170 autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1171 (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1172
1173 if (num_levels_played != num_levels_solved)
1174 {
1175 printf(", FAILED:");
1176 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1177 if (level_failed[i])
1178 printf(" %03d", i);
1179 }
1180
1181 #if 0
1182 if (num_tape_missing > 0)
1183 {
1184 printf(", NO TAPE:");
1185 for (i = 0; i < MAX_TAPES_PER_SET; i++)
1186 if (tape_missing[i])
1187 printf(" %03d", i);
1188 }
1189 #endif
1190
1191 printf("\n");
1192 printf_line("=", 79);
1193
1194 CloseAllAndExit(0);
1195 }
1196
1197
1198 /* ---------- new tape button stuff ---------------------------------------- */
1199
1200 /* graphic position values for tape buttons */
1201 #define TAPE_BUTTON_XSIZE 18
1202 #define TAPE_BUTTON_YSIZE 18
1203 #define TAPE_BUTTON_XPOS 5
1204 #define TAPE_BUTTON_YPOS 77
1205
1206 #define TAPE_BUTTON_EJECT_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
1207 #define TAPE_BUTTON_EXTRA_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
1208 #define TAPE_BUTTON_STOP_XPOS (TAPE_BUTTON_XPOS + 1 * TAPE_BUTTON_XSIZE)
1209 #define TAPE_BUTTON_PAUSE_XPOS (TAPE_BUTTON_XPOS + 2 * TAPE_BUTTON_XSIZE)
1210 #define TAPE_BUTTON_RECORD_XPOS (TAPE_BUTTON_XPOS + 3 * TAPE_BUTTON_XSIZE)
1211 #define TAPE_BUTTON_PLAY_XPOS (TAPE_BUTTON_XPOS + 4 * TAPE_BUTTON_XSIZE)
1212
1213 static struct
1214 {
1215 int x, y;
1216 int gadget_id;
1217 char *infotext;
1218 } tapebutton_info[NUM_TAPE_BUTTONS] =
1219 {
1220 {
1221 TAPE_BUTTON_EJECT_XPOS, TAPE_BUTTON_YPOS,
1222 TAPE_CTRL_ID_EJECT,
1223 "eject tape"
1224 },
1225 {
1226 TAPE_BUTTON_EXTRA_XPOS, TAPE_BUTTON_YPOS,
1227 TAPE_CTRL_ID_EXTRA,
1228 "extra functions"
1229 },
1230 {
1231 TAPE_BUTTON_STOP_XPOS, TAPE_BUTTON_YPOS,
1232 TAPE_CTRL_ID_STOP,
1233 "stop tape"
1234 },
1235 {
1236 TAPE_BUTTON_PAUSE_XPOS, TAPE_BUTTON_YPOS,
1237 TAPE_CTRL_ID_PAUSE,
1238 "pause tape"
1239 },
1240 {
1241 TAPE_BUTTON_RECORD_XPOS, TAPE_BUTTON_YPOS,
1242 TAPE_CTRL_ID_RECORD,
1243 "record tape"
1244 },
1245 {
1246 TAPE_BUTTON_PLAY_XPOS, TAPE_BUTTON_YPOS,
1247 TAPE_CTRL_ID_PLAY,
1248 "play tape"
1249 }
1250 };
1251
CreateTapeButtons()1252 void CreateTapeButtons()
1253 {
1254 int i;
1255
1256 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1257 {
1258 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
1259 struct GadgetInfo *gi;
1260 int gd_xoffset, gd_yoffset;
1261 int gd_x1, gd_x2, gd_y;
1262 int id = i;
1263
1264 gd_xoffset = tapebutton_info[i].x;
1265 gd_yoffset = tapebutton_info[i].y;
1266 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
1267 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
1268 gd_y = DOOR_GFX_PAGEY2 + gd_yoffset;
1269
1270 if (i == TAPE_CTRL_ID_EXTRA)
1271 {
1272 gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
1273 gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
1274 }
1275
1276 gi = CreateGadget(GDI_CUSTOM_ID, id,
1277 GDI_INFO_TEXT, tapebutton_info[i].infotext,
1278 GDI_X, VX + gd_xoffset,
1279 GDI_Y, VY + gd_yoffset,
1280 GDI_WIDTH, TAPE_BUTTON_XSIZE,
1281 GDI_HEIGHT, TAPE_BUTTON_YSIZE,
1282 GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1283 GDI_STATE, GD_BUTTON_UNPRESSED,
1284 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
1285 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
1286 GDI_DIRECT_DRAW, FALSE,
1287 GDI_EVENT_MASK, GD_EVENT_RELEASED,
1288 GDI_CALLBACK_ACTION, HandleTapeButtons,
1289 GDI_END);
1290
1291 if (gi == NULL)
1292 Error(ERR_EXIT, "cannot create gadget");
1293
1294 tape_gadget[id] = gi;
1295 }
1296 }
1297
FreeTapeButtons()1298 void FreeTapeButtons()
1299 {
1300 int i;
1301
1302 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1303 FreeGadget(tape_gadget[i]);
1304 }
1305
MapTapeEjectButton()1306 void MapTapeEjectButton()
1307 {
1308 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1309 MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1310 }
1311
MapTapeWarpButton()1312 void MapTapeWarpButton()
1313 {
1314 UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1315 MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1316 }
1317
MapTapeButtons()1318 void MapTapeButtons()
1319 {
1320 int i;
1321
1322 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1323 if (i != TAPE_CTRL_ID_EXTRA)
1324 MapGadget(tape_gadget[i]);
1325
1326 if (tape.recording || tape.playing)
1327 MapTapeWarpButton();
1328 }
1329
UnmapTapeButtons()1330 void UnmapTapeButtons()
1331 {
1332 int i;
1333
1334 for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1335 UnmapGadget(tape_gadget[i]);
1336 }
1337
HandleTapeButtonsExt(int id)1338 static void HandleTapeButtonsExt(int id)
1339 {
1340 if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1341 return;
1342
1343 switch (id)
1344 {
1345 case TAPE_CTRL_ID_EJECT:
1346 TapeStop();
1347
1348 if (TAPE_IS_EMPTY(tape))
1349 {
1350 LoadTape(level_nr);
1351
1352 if (TAPE_IS_EMPTY(tape))
1353 Request("No tape for this level !", REQ_CONFIRM);
1354 }
1355 else
1356 {
1357 if (tape.changed)
1358 SaveTapeChecked(tape.level_nr);
1359
1360 TapeErase();
1361 }
1362
1363 DrawCompleteVideoDisplay();
1364 break;
1365
1366 case TAPE_CTRL_ID_EXTRA:
1367 if (tape.playing)
1368 {
1369 if (!tape.warp_forward) /* PLAY -> WARP FORWARD PLAY */
1370 {
1371 TapeStartWarpForward();
1372 }
1373 else /* WARP FORWARD PLAY -> PLAY */
1374 {
1375 TapeStopWarpForward();
1376 }
1377 }
1378 else if (tape.recording)
1379 TapeSingleStep();
1380
1381 break;
1382
1383 case TAPE_CTRL_ID_STOP:
1384 TapeStop();
1385 break;
1386
1387 case TAPE_CTRL_ID_PAUSE:
1388 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1389 break;
1390
1391 case TAPE_CTRL_ID_RECORD:
1392 if (TAPE_IS_STOPPED(tape))
1393 TapeStartGameRecording();
1394 else if (tape.pausing)
1395 {
1396 if (tape.playing) /* PLAY -> PAUSE -> RECORD */
1397 TapeAppendRecording();
1398 else
1399 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1400 }
1401 break;
1402
1403 case TAPE_CTRL_ID_PLAY:
1404 if (TAPE_IS_EMPTY(tape))
1405 break;
1406
1407 if (TAPE_IS_STOPPED(tape))
1408 {
1409 TapeStartGamePlaying();
1410 }
1411 else if (tape.playing)
1412 {
1413 if (tape.pausing) /* PAUSE -> PLAY */
1414 {
1415 TapeTogglePause(TAPE_TOGGLE_MANUAL);
1416 }
1417 else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
1418 {
1419 tape.fast_forward = TRUE;
1420 DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1421 }
1422 else if (!tape.pause_before_death) /* FFWD PLAY -> AUTO PAUSE */
1423 {
1424 tape.pause_before_death = TRUE;
1425 DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1426 }
1427 else /* AUTO PAUSE -> NORMAL PLAY */
1428 {
1429 if (tape.warp_forward)
1430 TapeStopWarpForward();
1431
1432 tape.fast_forward = FALSE;
1433 tape.pause_before_death = FALSE;
1434
1435 DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
1436 }
1437 }
1438 break;
1439
1440 default:
1441 break;
1442 }
1443 }
1444
HandleTapeButtons(struct GadgetInfo * gi)1445 static void HandleTapeButtons(struct GadgetInfo *gi)
1446 {
1447 HandleTapeButtonsExt(gi->custom_id);
1448 }
1449
HandleTapeButtonKeys(Key key)1450 void HandleTapeButtonKeys(Key key)
1451 {
1452 boolean use_extra = (tape.recording || tape.playing);
1453
1454 if (key == setup.shortcut.tape_eject)
1455 HandleTapeButtonsExt(use_extra ? TAPE_CTRL_ID_EXTRA : TAPE_CTRL_ID_EJECT);
1456 else if (key == setup.shortcut.tape_stop)
1457 HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1458 else if (key == setup.shortcut.tape_pause)
1459 HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1460 else if (key == setup.shortcut.tape_record)
1461 HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1462 else if (key == setup.shortcut.tape_play)
1463 HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);
1464 }
1465