]> icculus.org git repositories - btb/d2x.git/blob - main/titles.c
remove DirectDraw use and Windows mouse stuff made redundant by SDL (lots of WINDOWS...
[btb/d2x.git] / main / titles.c
1 /* $Id: titles.c,v 1.38 2005-08-02 06:13:56 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Routines to display title screens...
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef WINDOWS
26 #include "desw.h"
27 #endif
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32
33 #ifdef MACINTOSH
34 #include <Events.h>
35 #endif
36
37 #include "pstypes.h"
38 #include "timer.h"
39 #include "key.h"
40 #include "gr.h"
41 #include "palette.h"
42 #include "iff.h"
43 #include "pcx.h"
44 #include "u_mem.h"
45 #include "joy.h"
46 #include "mono.h"
47 #include "gamefont.h"
48 #include "cfile.h"
49 #include "error.h"
50 #include "polyobj.h"
51 #include "textures.h"
52 #include "screens.h"
53 #include "multi.h"
54 #include "player.h"
55 #include "digi.h"
56 #include "text.h"
57 #include "kmatrix.h"
58 #include "piggy.h"
59 #include "songs.h"
60 #include "newmenu.h"
61 #include "state.h"
62 #include "movie.h"
63 #include "menu.h"
64 #include "mouse.h"
65
66
67 void DoBriefingColorStuff ();
68 int get_new_message_num(char **message);
69 int DefineBriefingBox (char **buf);
70
71 extern unsigned RobSX,RobSY,RobDX,RobDY; // Robot movie coords
72
73 ubyte New_pal[768];
74 int     New_pal_254_bash;
75
76 char CurBriefScreenName[15]="brief03.pcx";
77 char    * Briefing_text;
78 char RobotPlaying=0;
79
80 //Begin D1X modification
81 #define MAX_BRIEFING_COLORS     7
82 //End D1X modification
83
84 #define SHAREWARE_ENDING_FILENAME       "ending.tex"
85
86 //      Can be set by -noscreens command line option.  Causes bypassing of all briefing screens.
87 int     Skip_briefing_screens=0;
88 int     Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
89 int     Current_color = 0;
90 int     Erase_color;
91
92 extern int check_button_press();
93
94 #ifdef MACINTOSH
95 extern void macintosh_quit(void);
96 #endif
97
98 // added by Jan Bobrowski for variable-size menu screen
99 static int rescale_x(int x)
100 {
101         return x * GWIDTH / 320;
102 }
103
104 static int rescale_y(int y)
105 {
106         return y * GHEIGHT / 200;
107 }
108
109 #ifndef MACINTOSH
110 int local_key_inkey(void)
111 {
112         int     rval;
113
114         rval = key_inkey();
115
116         if (rval == KEY_PRINT_SCREEN) {
117                 save_screen_shot(0);
118                 return 0;                               //say no key pressed
119         }
120
121         if (check_button_press())               //joystick or mouse button pressed?
122                 rval = KEY_SPACEBAR;
123         else if (mouse_button_state(0))
124                 rval = KEY_SPACEBAR;
125
126         #ifdef MACINTOSH
127         if ( rval == KEY_Q+KEY_COMMAND )
128                 macintosh_quit();
129         #endif
130
131         return rval;
132 }
133 #else
134 int local_key_inkey(void)
135 {
136         EventRecord event;
137         int     rval;
138
139         if (!GetOSEvent(everyEvent, &event))
140                 return 0;
141
142         if (event.what != keyDown)
143                 return 0;
144
145         rval = (int)((event.message & keyCodeMask) >> 8);
146
147         if (rval == KEY_PRINT_SCREEN) {
148                 save_screen_shot(0);
149                 return 0;                               //say no key pressed
150         }
151
152         if (check_button_press())               //joystick or mouse button pressed?
153                 rval = KEY_SPACEBAR;
154
155         #ifdef MACINTOSH
156         if ( rval == KEY_Q+KEY_COMMAND )
157                 macintosh_quit();
158         #endif
159
160         return rval;
161 }
162 #endif
163
164 int show_title_screen( char * filename, int allow_keys, int from_hog_only )
165 {
166         fix timer;
167         int pcx_error;
168         grs_bitmap title_bm;
169         ubyte   palette_save[768];
170         char new_filename[FILENAME_LEN+1] = "";
171
172         #ifdef RELEASE
173         if (from_hog_only)
174                 strcpy(new_filename,"\x01");    //only read from hog file
175         #endif
176
177         strcat(new_filename,filename);
178         filename = new_filename;
179
180         title_bm.bm_data=NULL;
181         if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE)     {
182                 printf( "File '%s', PCX load error: %s (%i)\n  (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
183                 mprintf((0, "File '%s', PCX load error: %s (%i)\n  (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error));
184                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error);
185         }
186
187         memcpy(palette_save,gr_palette,sizeof(palette_save));
188
189         //vfx_set_palette_sub( New_pal );
190 #ifdef OGL
191         gr_palette_load( New_pal );
192 #else
193         gr_palette_clear();
194 #endif
195
196         gr_set_current_canvas( NULL );
197         show_fullscr(&title_bm);
198
199         if (gr_palette_fade_in( New_pal, 32, allow_keys ))
200                 return 1;
201         gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
202
203         gr_palette_load( New_pal );
204         timer   = timer_get_fixed_seconds() + i2f(3);
205         while (1) {
206                 if ( local_key_inkey() && allow_keys ) break;
207                 if ( timer_get_fixed_seconds() > timer ) break;
208         }
209         if (gr_palette_fade_out( New_pal, 32, allow_keys ))
210                 return 1;
211         gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
212         d_free(title_bm.bm_data);
213         return 0;
214 }
215
216 typedef struct {
217         char    bs_name[14];                //  filename, eg merc01.  Assumes .lbm suffix.
218         sbyte   level_num;
219         sbyte   message_num;
220         short   text_ulx, text_uly;         //  upper left x,y of text window
221         short   text_width, text_height;    //  width and height of text window
222 } briefing_screen;
223
224 #define BRIEFING_SECRET_NUM 31          //  This must correspond to the first secret level which must come at the end of the list.
225 #define BRIEFING_OFFSET_NUM 4           // This must correspond to the first level screen (ie, past the bald guy briefing screens)
226
227 #define SHAREWARE_ENDING_LEVEL_NUM  0x7f
228 #define REGISTERED_ENDING_LEVEL_NUM 0x7e
229
230 #ifdef SHAREWARE
231 #define ENDING_LEVEL_NUM        SHAREWARE_ENDING_LEVEL_NUM
232 #else
233 #define ENDING_LEVEL_NUM        REGISTERED_ENDING_LEVEL_NUM
234 #endif
235
236 #define MAX_BRIEFING_SCREENS 60
237
238 briefing_screen Briefing_screens[MAX_BRIEFING_SCREENS]=
239  {{"brief03.pcx",0,3,8,8,257,177}}; // default=0!!!
240
241 briefing_screen D1_Briefing_screens[] = {
242         { "brief01.pcx",   0,  1,  13, 140, 290,  59 },
243         { "brief02.pcx",   0,  2,  27,  34, 257, 177 },
244         { "brief03.pcx",   0,  3,  20,  22, 257, 177 },
245         { "brief02.pcx",   0,  4,  27,  34, 257, 177 },
246
247         { "moon01.pcx",    1,  5,  10,  10, 300, 170 }, // level 1
248         { "moon01.pcx",    2,  6,  10,  10, 300, 170 }, // level 2
249         { "moon01.pcx",    3,  7,  10,  10, 300, 170 }, // level 3
250
251         { "venus01.pcx",   4,  8,  15, 15, 300,  200 }, // level 4
252         { "venus01.pcx",   5,  9,  15, 15, 300,  200 }, // level 5
253
254         { "brief03.pcx",   6, 10,  20,  22, 257, 177 },
255         { "merc01.pcx",    6, 11,  10, 15, 300, 200 },  // level 6
256         { "merc01.pcx",    7, 12,  10, 15, 300, 200 },  // level 7
257
258 #ifndef SHAREWARE
259         { "brief03.pcx",   8, 13,  20,  22, 257, 177 },
260         { "mars01.pcx",    8, 14,  10, 100, 300,  200 }, // level 8
261         { "mars01.pcx",    9, 15,  10, 100, 300,  200 }, // level 9
262         { "brief03.pcx",  10, 16,  20,  22, 257, 177 },
263         { "mars01.pcx",   10, 17,  10, 100, 300,  200 }, // level 10
264
265         { "jup01.pcx",    11, 18,  10, 40, 300,  200 }, // level 11
266         { "jup01.pcx",    12, 19,  10, 40, 300,  200 }, // level 12
267         { "brief03.pcx",  13, 20,  20,  22, 257, 177 },
268         { "jup01.pcx",    13, 21,  10, 40, 300,  200 }, // level 13
269         { "jup01.pcx",    14, 22,  10, 40, 300,  200 }, // level 14
270
271         { "saturn01.pcx", 15, 23,  10, 40, 300,  200 }, // level 15
272         { "brief03.pcx",  16, 24,  20,  22, 257, 177 },
273         { "saturn01.pcx", 16, 25,  10, 40, 300,  200 }, // level 16
274         { "brief03.pcx",  17, 26,  20,  22, 257, 177 },
275         { "saturn01.pcx", 17, 27,  10, 40, 300,  200 }, // level 17
276
277         { "uranus01.pcx", 18, 28,  100, 100, 300,  200 }, // level 18
278         { "uranus01.pcx", 19, 29,  100, 100, 300,  200 }, // level 19
279         { "uranus01.pcx", 20, 30,  100, 100, 300,  200 }, // level 20
280         { "uranus01.pcx", 21, 31,  100, 100, 300,  200 }, // level 21
281
282         { "neptun01.pcx", 22, 32,  10, 20, 300,  200 }, // level 22
283         { "neptun01.pcx", 23, 33,  10, 20, 300,  200 }, // level 23
284         { "neptun01.pcx", 24, 34,  10, 20, 300,  200 }, // level 24
285
286         { "pluto01.pcx",  25, 35,  10, 20, 300,  200 }, // level 25
287         { "pluto01.pcx",  26, 36,  10, 20, 300,  200 }, // level 26
288         { "pluto01.pcx",  27, 37,  10, 20, 300,  200 }, // level 27
289
290         { "aster01.pcx",  -1, 38,  10, 90, 300,  200 }, // secret level -1
291         { "aster01.pcx",  -2, 39,  10, 90, 300,  200 }, // secret level -2
292         { "aster01.pcx",  -3, 40,  10, 90, 300,  200 }, // secret level -3
293 #endif
294
295         { "end01.pcx",   SHAREWARE_ENDING_LEVEL_NUM,  1,  23, 40, 320, 200 },   // shareware end
296 #ifndef SHAREWARE
297         { "end02.pcx",   REGISTERED_ENDING_LEVEL_NUM,  1,  5, 5, 300, 200 },    // registered end
298         { "end01.pcx",   REGISTERED_ENDING_LEVEL_NUM,  2,  23, 40, 320, 200 },  // registered end
299         { "end03.pcx",   REGISTERED_ENDING_LEVEL_NUM,  3,  5, 5, 300, 200 },    // registered end
300 #endif
301
302 };
303
304
305 int     Briefing_text_x, Briefing_text_y;
306
307 void init_char_pos(int x, int y)
308 {
309         Briefing_text_x = x;
310         Briefing_text_y = y;
311         mprintf ((0,"Setting init x=%d y=%d\n",x,y));
312 }
313
314 grs_canvas      *Robot_canv = NULL;
315 vms_angvec      Robot_angles;
316
317 char    Bitmap_name[32] = "";
318 #define EXIT_DOOR_MAX   14
319 #define OTHER_THING_MAX 10      //  Adam: This is the number of frames in your new animating thing.
320 #define DOOR_DIV_INIT   6
321 sbyte   Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
322
323 //-----------------------------------------------------------------------------
324 void show_bitmap_frame(void)
325 {
326         grs_canvas *curcanv_save, *bitmap_canv=0;
327
328         grs_bitmap *bitmap_ptr;
329
330         //      Only plot every nth frame.
331         if (Door_div_count) {
332                 Door_div_count--;
333                 return;
334         }
335
336         Door_div_count = DOOR_DIV_INIT;
337
338         if (Bitmap_name[0] != 0) {
339                 char            *pound_signp;
340                 int             num, dig1, dig2;
341
342                 //      Set supertransparency color to black
343                 if (!New_pal_254_bash) {
344                         New_pal_254_bash = 1;
345                         New_pal[254*3] = 0;
346                         New_pal[254*3+1] = 0;
347                         New_pal[254*3+2] = 0;
348                         gr_palette_load( New_pal );
349                 }
350
351                 switch (Animating_bitmap_type) {
352                 case 0:
353                         bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 64, 64);
354                         break;
355                 case 1:
356                         bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 94, 94);
357                         break;
358
359                         // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
360                         default:
361                                 Int3(); // Impossible, illegal value for Animating_bitmap_type
362                 }
363
364                 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv;
365
366                 pound_signp = strchr(Bitmap_name, '#');
367                 Assert(pound_signp != NULL);
368
369                 dig1 = *(pound_signp+1);
370                 dig2 = *(pound_signp+2);
371                 if (dig2 == 0)
372                         num = dig1-'0';
373                 else
374                         num = (dig1-'0')*10 + (dig2-'0');
375
376                 switch (Animating_bitmap_type) {
377                 case 0:
378                         num += Door_dir;
379                         if (num > EXIT_DOOR_MAX) {
380                                 num = EXIT_DOOR_MAX;
381                                 Door_dir = -1;
382                         } else if (num < 0) {
383                                 num = 0;
384                                 Door_dir = 1;
385                         }
386                         break;
387                 case 1:
388                         num++;
389                         if (num > OTHER_THING_MAX)
390                                 num = 0;
391                         break;
392                 }
393
394                 Assert(num < 100);
395                 if (num >= 10) {
396                         *(pound_signp+1) = (num / 10) + '0';
397                         *(pound_signp+2) = (num % 10) + '0';
398                         *(pound_signp+3) = 0;
399                 } else {
400                         *(pound_signp+1) = (num % 10) + '0';
401                         *(pound_signp+2) = 0;
402                 }
403
404                 {
405                         bitmap_index bi;
406                         bi = piggy_find_bitmap(Bitmap_name);
407                         bitmap_ptr = &GameBitmaps[bi.index];
408                         PIGGY_PAGE_IN( bi );
409                 }
410
411                 gr_bitmapm(0, 0, bitmap_ptr);
412
413                 grd_curcanv = curcanv_save;
414                 d_free(bitmap_canv);
415
416                 switch (Animating_bitmap_type) {
417                 case 0:
418                         if (num == EXIT_DOOR_MAX) {
419                                 Door_dir = -1;
420                                 Door_div_count = 64;
421                         } else if (num == 0) {
422                                 Door_dir = 1;
423                                 Door_div_count = 64;
424                         }
425                         break;
426                 case 1:
427                         break;
428                 }
429         }
430
431 }
432
433 //-----------------------------------------------------------------------------
434 void show_briefing_bitmap(grs_bitmap *bmp)
435 {
436         grs_canvas      *curcanv_save, *bitmap_canv;
437
438         bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
439         curcanv_save = grd_curcanv;
440         gr_set_current_canvas(bitmap_canv);
441         gr_bitmapm(0, 0, bmp);
442         gr_set_current_canvas(curcanv_save);
443
444         d_free(bitmap_canv);
445 }
446
447 //-----------------------------------------------------------------------------
448 void show_spinning_robot_frame(int robot_num)
449 {
450         grs_canvas      *curcanv_save;
451
452         if (robot_num != -1) {
453                 Robot_angles.h += 150;
454
455                 curcanv_save = grd_curcanv;
456                 grd_curcanv = Robot_canv;
457                 Assert(Robot_info[robot_num].model_num != -1);
458                 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
459                 grd_curcanv = curcanv_save;
460         }
461
462 }
463
464 //-----------------------------------------------------------------------------
465 void init_spinning_robot(void) //(int x,int y,int w,int h)
466 {
467         //Robot_angles.p += 0;
468         //Robot_angles.b += 0;
469         //Robot_angles.h += 0;
470
471         int x = rescale_x(138);
472         int y = rescale_y(55);
473         int w = rescale_x(166);
474         int h = rescale_y(138);
475
476         Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
477         // 138, 55, 166, 138
478 }
479
480 //---------------------------------------------------------------------------
481 // Returns char width.
482 // If show_robot_flag set, then show a frame of the spinning robot.
483 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
484 {
485         int w, h, aw;
486         char message[2];
487         static fix      start_time=0;
488
489         message[0] = the_char;
490         message[1] = 0;
491
492         if (start_time==0 && timer_get_fixed_seconds()<0)
493                 start_time=timer_get_fixed_seconds();
494
495         gr_get_string_size(message, &w, &h, &aw );
496
497         Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
498
499         //      Draw cursor if there is some delay and caller says to draw cursor
500         if (cursor_flag && delay) {
501                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
502                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
503                 gr_update();
504         }
505
506         if (delay)
507                 delay=fixdiv (F1_0,i2f(15));
508
509         if ((Bitmap_name[0] != 0) && (delay != 0))
510                 show_bitmap_frame();
511
512         if (RobotPlaying && (delay != 0))
513                 RotateRobot();
514
515         while (timer_get_fixed_seconds() < (start_time + delay)) {
516                 if (RobotPlaying && delay != 0)
517                         RotateRobot();
518         }
519         if (robot_num != -1)
520                 show_spinning_robot_frame(robot_num);
521
522         start_time = timer_get_fixed_seconds();
523
524         //      Erase cursor
525         if (cursor_flag && delay) {
526                 gr_set_fontcolor(Erase_color, -1);
527                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
528         }
529
530         //      Draw the character
531         gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
532         gr_printf(Briefing_text_x, Briefing_text_y, message );
533
534         gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
535         gr_printf(Briefing_text_x+1, Briefing_text_y, message );
536
537         if (delay) gr_update();
538
539 //      if (the_char != ' ')
540 //              if (!digi_is_sound_playing(SOUND_MARKER_HIT))
541 //                      digi_play_sample( SOUND_MARKER_HIT, F1_0 );
542
543         return w;
544 }
545
546 //-----------------------------------------------------------------------------
547 int load_briefing_screen( int screen_num )
548 {
549         int     pcx_error;
550         char *fname;
551
552         if (EMULATING_D1)
553                 fname = Briefing_screens[screen_num].bs_name;
554         else
555                 fname = CurBriefScreenName;
556
557         if ((pcx_error = pcx_read_fullscr(fname, New_pal)) != PCX_ERROR_NONE) {
558                 printf( "File '%s', PCX load error: %s\n  (It's a briefing screen.  Does this cause you pain?)\n", fname, pcx_errormsg(pcx_error));
559                 printf( "File '%s', PCX load error: %s (%i)\n  (It's a briefing screen.  Does this cause you pain?)\n", fname, pcx_errormsg(pcx_error), pcx_error);
560                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n", fname, pcx_errormsg(pcx_error), pcx_error);
561         }
562
563         return 0;
564 }
565
566 int load_new_briefing_screen( char *fname )
567 {
568         int pcx_error;
569
570         mprintf ((0,"Loading new briefing <%s>\n",fname));
571         strcpy (CurBriefScreenName,fname);
572
573         if (gr_palette_fade_out( New_pal, 32, 0 ))
574                 return 0;
575
576         if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE)     {
577         //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE)     {
578                 printf( "File '%s', PCX load error: %s (%i)\n  (It's a briefing screen.  Does this cause you pain?)\n",fname, pcx_errormsg(pcx_error), pcx_error);
579                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
580         }
581
582         gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
583
584         if (gr_palette_fade_in( New_pal, 32, 0 ))
585                 return 0;
586         DoBriefingColorStuff();
587
588         return 1;
589 }
590
591
592
593 #define KEY_DELAY_DEFAULT       ((F1_0*20)/1000)
594
595 //-----------------------------------------------------------------------------
596 int get_message_num(char **message)
597 {
598         int     num=0;
599
600         while (**message == ' ')
601                 (*message)++;
602
603         while ((**message >= '0') && (**message <= '9')) {
604                 num = 10*num + **message-'0';
605                 (*message)++;
606         }
607
608         while (*(*message)++ != 10)             //      Get and drop eoln
609                 ;
610
611         return num;
612 }
613
614 //-----------------------------------------------------------------------------
615 void get_message_name(char **message, char *result)
616 {
617         while (**message == ' ')
618                 (*message)++;
619
620         while ((**message != ' ') && (**message != 10)) {
621                 if (**message != '\n')
622                         *result++ = **message;
623                 (*message)++;
624         }
625
626         if (**message != 10)
627                 while (*(*message)++ != 10)             //      Get and drop eoln
628                         ;
629
630         *result = 0;
631 }
632
633 //-----------------------------------------------------------------------------
634 void flash_cursor(int cursor_flag)
635 {
636         if (cursor_flag == 0)
637                 return;
638
639         if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
640                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
641         else
642                 gr_set_fontcolor(Erase_color, -1);
643
644         gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
645         gr_update();
646 }
647
648 extern int InitMovieBriefing();
649
650
651 //-----------------------------------------------------------------------------
652 // Return true if message got aborted by user (pressed ESC), else return false.
653 int show_briefing_message(int screen_num, char *message)
654 {
655         int     prev_ch=-1;
656         int     ch, done=0,i;
657         briefing_screen *bsp;
658         int     delay_count = KEY_DELAY_DEFAULT;
659         int     key_check;
660         int     robot_num=-1;
661         int     rval=0;
662         static int tab_stop=0;
663         int     flashing_cursor=0;
664         int     new_page=0,GotZ=0;
665         char spinRobotName[]="rba.mve",kludge;  // matt don't change this!
666         char fname[15];
667         char DumbAdjust=0;
668         char chattering=0;
669         int hum_channel=-1,printing_channel=-1;
670         int LineAdjustment=1;
671
672         Bitmap_name[0] = 0;
673         Current_color = 0;
674         RobotPlaying=0;
675
676         InitMovieBriefing();
677
678         #ifndef SHAREWARE
679         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
680         #endif
681
682         // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
683         gr_set_curfont( GAME_FONT );
684
685         if (EMULATING_D1) {
686                 GotZ = 1;
687                 MALLOC(bsp, briefing_screen, 1);
688                 memcpy(bsp, &Briefing_screens[screen_num], sizeof(briefing_screen));
689                 bsp->text_ulx = rescale_x(bsp->text_ulx);
690                 bsp->text_uly = rescale_y(bsp->text_uly);
691                 bsp->text_width = rescale_x(bsp->text_width);
692                 bsp->text_height = rescale_y(bsp->text_height);
693                 init_char_pos(bsp->text_ulx, bsp->text_uly);
694         } else {
695                 bsp=&Briefing_screens[0];
696                 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
697         }
698
699         while (!done) {
700                 ch = *message++;
701                 if (ch == '$') {
702                         ch = *message++;
703                         if (ch=='D') {
704                                 screen_num=DefineBriefingBox (&message);
705                         //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
706
707                                 bsp = &Briefing_screens[screen_num];
708                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
709                                 LineAdjustment=0;
710                                 prev_ch = 10;                                   // read to eoln
711                         } else if (ch=='U') {
712                                 screen_num=get_message_num(&message);
713                                 bsp = &Briefing_screens[screen_num];
714                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
715                                 prev_ch = 10;                                   // read to eoln
716                         } else if (ch == 'C') {
717                                 Current_color = get_message_num(&message)-1;
718                                 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
719                                 prev_ch = 10;
720                         } else if (ch == 'F') {     // toggle flashing cursor
721                                 flashing_cursor = !flashing_cursor;
722                                 prev_ch = 10;
723                                 while (*message++ != 10)
724                                         ;
725                         } else if (ch == 'T') {
726                                 tab_stop = get_message_num(&message);
727                                 tab_stop*=(1+MenuHires);
728                                 prev_ch = 10;                                                   //      read to eoln
729                         } else if (ch == 'R') {
730                                 if (Robot_canv != NULL) {
731                                         d_free(Robot_canv);
732                                         Robot_canv=NULL;
733                                 }
734                                 if (RobotPlaying) {
735                                         DeInitRobotMovie();
736                                         RobotPlaying=0;
737                                 }
738
739                                 if (EMULATING_D1) {
740                                         init_spinning_robot();
741                                         robot_num = get_message_num(&message);
742                                         while (*message++ != 10)
743                                                 ;
744                                 } else {
745                                         kludge=*message++;
746                                         spinRobotName[2]=kludge; // ugly but proud
747
748                                         RobotPlaying=InitRobotMovie(spinRobotName);
749
750                                         // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
751
752                                         if (RobotPlaying) {
753                                                 RotateRobot();
754                                                 DoBriefingColorStuff ();
755                                                 mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
756                                         }
757                                 }
758                                 prev_ch = 10;                           // read to eoln
759                         } else if (ch == 'N') {
760                                 //--grs_bitmap *bitmap_ptr;
761                                 if (Robot_canv != NULL) {
762                                         d_free(Robot_canv);
763                                         Robot_canv=NULL;
764                                 }
765
766                                 get_message_name(&message, Bitmap_name);
767                                 strcat(Bitmap_name, "#0");
768                                 Animating_bitmap_type = 0;
769                                 prev_ch = 10;
770                         } else if (ch == 'O') {
771                                 if (Robot_canv != NULL) {
772                                                 d_free(Robot_canv);
773                                                 Robot_canv=NULL;
774                                 }
775
776                                 get_message_name(&message, Bitmap_name);
777                                 strcat(Bitmap_name, "#0");
778                                 Animating_bitmap_type = 1;
779                                 prev_ch = 10;
780                         } else if (ch=='A') {
781                                 LineAdjustment=1-LineAdjustment;
782                         } else if (ch=='Z') {
783                                 //mprintf ((0,"Got a Z!\n"));
784                                 GotZ=1;
785 #if 1 //defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
786                                 DumbAdjust=1;
787 #else
788                                 if (LineAdjustment==1)
789                                         DumbAdjust=1;
790                                 else
791                                         DumbAdjust=2;
792 #endif
793
794                                 i=0;
795                                 while ((fname[i]=*message) != '\n') {
796                                         i++;
797                                         message++;
798                                 }
799                                 fname[i]=0;
800                                 if (*message != 10)
801                                         while (*message++ != 10)    //  Get and drop eoln
802                                                 ;
803
804                                 {
805                                         char fname2[15];
806
807                                         i=0;
808                                         while (fname[i]!='.') {
809                                                 fname2[i] = fname[i];
810                                                 i++;
811                                         }
812                                         fname2[i++]='b';
813                                         fname2[i++]='.';
814                                         fname2[i++]='p';
815                                         fname2[i++]='c';
816                                         fname2[i++]='x';
817                                         fname2[i++]=0;
818
819                                         if ((MenuHires && cfexist(fname2)) || !cfexist(fname))
820                                                 load_new_briefing_screen (fname2);
821                                         else
822                                                 load_new_briefing_screen (fname);
823                                 }
824
825                                 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
826
827                         } else if (ch == 'B') {
828                                 char        bitmap_name[32];
829                                 grs_bitmap  guy_bitmap;
830                                 ubyte       temp_palette[768];
831                                 int         iff_error;
832
833                                 if (Robot_canv != NULL) {
834                                         d_free(Robot_canv);
835                                         Robot_canv=NULL;
836                                 }
837
838                                 get_message_name(&message, bitmap_name);
839                                 strcat(bitmap_name, ".bbm");
840                                 guy_bitmap.bm_data = NULL;
841                                 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
842                                 Assert(iff_error == IFF_NO_ERROR);
843                                 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
844
845                                 show_briefing_bitmap(&guy_bitmap);
846                                 d_free(guy_bitmap.bm_data);
847                                 prev_ch = 10;
848 //                      } else if (ch==EOF) {
849 //                              done=1;
850 //                      } else if (ch == 'B') {
851 //                              if (Robot_canv != NULL) {
852 //                                      d_free(Robot_canv);
853 //                                      Robot_canv=NULL;
854 //                              }
855 //
856 //                              bitmap_num = get_message_num(&message);
857 //                              if (bitmap_num != -1)
858 //                                      show_briefing_bitmap(Textures[bitmap_num]);
859 //                              prev_ch = 10;                           // read to eoln
860                         } else if (ch == 'S') {
861                                 int keypress;
862                                 fix start_time;
863
864                                 chattering=0;
865                                 if (printing_channel>-1)
866                                         digi_stop_sound( printing_channel );
867                                 printing_channel=-1;
868
869                                 gr_update();
870
871                                 start_time = timer_get_fixed_seconds();
872                                 while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
873
874                                         while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
875                                                 ;
876                                         flash_cursor(flashing_cursor);
877
878                                         if (RobotPlaying)
879                                                 RotateRobot ();
880                                         if (robot_num != -1)
881                                                 show_spinning_robot_frame(robot_num);
882
883                                         if (Bitmap_name[0] != 0)
884                                                 show_bitmap_frame();
885                                         start_time += KEY_DELAY_DEFAULT/2;
886                                 }
887
888 #ifndef NDEBUG
889                                 if (keypress == KEY_BACKSP)
890                                         Int3();
891 #endif
892                                 if (keypress == KEY_ESC)
893                                         rval = 1;
894
895                                 flashing_cursor = 0;
896                                 done = 1;
897                         } else if (ch == 'P') {         //      New page.
898                                 if (!GotZ) {
899                                         Int3(); // Hey ryan!!!! You gotta load a screen before you start
900                                                 // printing to it! You know, $Z !!!
901                                     load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
902                                 }
903
904                                 new_page = 1;
905                                 while (*message != 10) {
906                                         message++;      //      drop carriage return after special escape sequence
907                                 }
908                                 message++;
909                                 prev_ch = 10;
910                                 gr_update();
911                         }
912                 } else if (ch == '\t') {                //      Tab
913                         if (Briefing_text_x - bsp->text_ulx < tab_stop)
914                                 Briefing_text_x = bsp->text_ulx + tab_stop;
915                 } else if ((ch == ';') && (prev_ch == 10)) {
916                         while (*message++ != 10)
917                                 ;
918                         prev_ch = 10;
919                 } else if (ch == '\\') {
920                         prev_ch = ch;
921                 } else if (ch == 10) {
922                         if (prev_ch != '\\') {
923                                 prev_ch = ch;
924                                 if (DumbAdjust==0)
925                                         Briefing_text_y += (8*(MenuHires+1));
926                                 else
927                                         DumbAdjust--;
928                                 Briefing_text_x = bsp->text_ulx;
929                                 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
930                                         load_briefing_screen(screen_num);
931                                         Briefing_text_x = bsp->text_ulx;
932                                         Briefing_text_y = bsp->text_uly;
933                                 }
934                         } else {
935                                 if (ch == 13)           //Can this happen? Above says ch==10
936                                         Int3();
937                                 prev_ch = ch;
938                         }
939
940                 } else {
941                         if (!GotZ) {
942                                 Int3(); // Hey ryan!!!! You gotta load a screen before you start
943                                         // printing to it! You know, $Z !!!
944                                 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
945                         }
946
947                         prev_ch = ch;
948
949                         if (!chattering) {
950                                 printing_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
951                                 chattering=1;
952                         }
953
954                         Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
955
956                 }
957
958                 //      Check for Esc -> abort.
959                 if(delay_count)
960                         key_check=local_key_inkey();
961                 else
962                         key_check=0;
963
964 #ifdef WINDOWS
965                 if (_RedrawScreen) {
966                         _RedrawScreen = FALSE;
967                         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
968                         key_check = KEY_ESC;
969                 }
970 #endif
971                 if ( key_check == KEY_ESC ) {
972                         rval = 1;
973                         done = 1;
974                 }
975
976                 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
977                         delay_count = 0;
978
979 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
980                 if ((key_check == KEY_ALTED+KEY_ENTER) ||
981                         (key_check == KEY_ALTED+KEY_PADENTER))
982                         gr_toggle_fullscreen();
983 #endif
984
985                 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
986                         Briefing_text_x = bsp->text_ulx;
987                         Briefing_text_y += bsp->text_uly;
988                 }
989
990                 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
991                         fix     start_time = 0;
992                         int     keypress;
993
994                         new_page = 0;
995
996                         if (printing_channel>-1)
997                                 digi_stop_sound( printing_channel );
998                         printing_channel=-1;
999
1000                         chattering=0;
1001
1002                         start_time = timer_get_fixed_seconds();
1003                         while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
1004                                 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1005                                         ;
1006                                 flash_cursor(flashing_cursor);
1007                                 if (RobotPlaying)
1008                                         RotateRobot();
1009                                 if (robot_num != -1)
1010                                         show_spinning_robot_frame(robot_num);
1011                                 if (Bitmap_name[0] != 0)
1012                                         show_bitmap_frame();
1013                                 start_time += KEY_DELAY_DEFAULT/2;
1014                         }
1015
1016                         if (RobotPlaying)
1017                                 DeInitRobotMovie();
1018                         RobotPlaying=0;
1019                         robot_num = -1;
1020
1021 #ifndef NDEBUG
1022                         if (keypress == KEY_BACKSP)
1023                                 Int3();
1024 #endif
1025                         if (keypress == KEY_ESC) {
1026                                 rval = 1;
1027                                 done = 1;
1028                         }
1029
1030                         load_briefing_screen(screen_num);
1031                         Briefing_text_x = bsp->text_ulx;
1032                         Briefing_text_y = bsp->text_uly;
1033                         delay_count = KEY_DELAY_DEFAULT;
1034                 }
1035         }
1036
1037         if (RobotPlaying) {
1038                 DeInitRobotMovie();
1039                 RobotPlaying=0;
1040         }
1041
1042         if (Robot_canv != NULL)
1043                 {d_free(Robot_canv); Robot_canv=NULL;}
1044
1045         if (hum_channel>-1)
1046                 digi_stop_sound( hum_channel );
1047         if (printing_channel>-1)
1048                 digi_stop_sound( printing_channel );
1049
1050         if (EMULATING_D1)
1051                 d_free(bsp);
1052
1053         return rval;
1054 }
1055
1056 //-----------------------------------------------------------------------------
1057 // Return a pointer to the start of text for screen #screen_num.
1058 char * get_briefing_message(int screen_num)
1059 {
1060         char *tptr = Briefing_text;
1061         int     cur_screen=0;
1062         int     ch;
1063
1064         Assert(screen_num >= 0);
1065
1066         while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1067                 ch = *tptr++;
1068                 if (ch == '$') {
1069                         ch = *tptr++;
1070                         if (ch == 'S')
1071                                 cur_screen = get_message_num(&tptr);
1072                 }
1073         }
1074
1075         if (screen_num!=cur_screen)
1076                 return (NULL);
1077
1078         return tptr;
1079 }
1080
1081 //-----------------------------------------------------------------------------
1082 //      Load Descent briefing text.
1083 int load_screen_text(char *filename, char **buf)
1084 {
1085         CFILE *tfile;
1086         CFILE *ifile;
1087         int     len, i,x;
1088         int     have_binary = 0;
1089
1090         if ((tfile = cfopen(filename,"rb")) == NULL) {
1091                 char nfilename[30], *ptr;
1092
1093                 strcpy(nfilename, filename);
1094                 if ((ptr = strrchr(nfilename, '.')))
1095                         *ptr = '\0';
1096                 strcat(nfilename, ".txb");
1097                 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1098                         mprintf ((0,"can't open %s!\n",nfilename));
1099                         return (0);
1100                                 //Error("Cannot open file %s or %s", filename, nfilename);
1101                 }
1102
1103                 mprintf ((0,"reading...\n"));
1104                 have_binary = 1;
1105
1106                 len = cfilelength(ifile);
1107                 MALLOC(*buf, char, len+500);
1108                 mprintf ((0,"len=%d\n",len));
1109                 for (x=0, i=0; i < len; i++, x++) {
1110                         cfread (*buf+x,1,1,ifile);
1111                         //  mprintf ((0,"%c",*(*buf+x)));
1112                         if (*(*buf+x)==13)
1113                                 x--;
1114                 }
1115
1116                 cfclose(ifile);
1117         } else {
1118                 len = cfilelength(tfile);
1119                 MALLOC(*buf, char, len+500);
1120                 for (x=0, i=0; i < len; i++, x++) {
1121                         cfread (*buf+x,1,1,tfile);
1122                         // mprintf ((0,"%c",*(*buf+x)));
1123                         if (*(*buf+x)==13)
1124                                 x--;
1125                 }
1126
1127
1128                 //cfread(*buf, 1, len, tfile);
1129                 cfclose(tfile);
1130         }
1131
1132         if (have_binary)
1133                 decode_text(*buf, len);
1134
1135         return (1);
1136 }
1137
1138 //-----------------------------------------------------------------------------
1139 // Return true if message got aborted, else return false.
1140 int show_briefing_text(int screen_num)
1141 {
1142         char    *message_ptr;
1143
1144         message_ptr = get_briefing_message
1145                 (EMULATING_D1 ? Briefing_screens[screen_num].message_num : screen_num);
1146
1147         if (message_ptr==NULL)
1148                 return (0);
1149
1150         DoBriefingColorStuff();
1151
1152         return show_briefing_message(screen_num, message_ptr);
1153 }
1154
1155 void DoBriefingColorStuff ()
1156 {
1157         Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1158         Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1159
1160         Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1161         Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1162
1163         Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1164         Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1165
1166         if (EMULATING_D1) {
1167                 //green
1168                 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 54, 0);
1169                 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 19, 0);
1170                 //white
1171                 Briefing_foreground_colors[1] = gr_find_closest_color_current( 42, 38, 32);
1172                 Briefing_background_colors[1] = gr_find_closest_color_current( 14, 14, 14);
1173
1174                 //Begin D1X addition
1175                 //red
1176                 Briefing_foreground_colors[2] = gr_find_closest_color_current( 63, 0, 0);
1177                 Briefing_background_colors[2] = gr_find_closest_color_current( 31, 0, 0);
1178         }
1179         //blue
1180         Briefing_foreground_colors[3] = gr_find_closest_color_current( 0, 0, 54);
1181         Briefing_background_colors[3] = gr_find_closest_color_current( 0, 0, 19);
1182         //gray
1183         Briefing_foreground_colors[4] = gr_find_closest_color_current( 14, 14, 14);
1184         Briefing_background_colors[4] = gr_find_closest_color_current( 0, 0, 0);
1185         //yellow
1186         Briefing_foreground_colors[5] = gr_find_closest_color_current( 54, 54, 0);
1187         Briefing_background_colors[5] = gr_find_closest_color_current( 19, 19, 0);
1188         //purple
1189         Briefing_foreground_colors[6] = gr_find_closest_color_current( 0, 54, 54);
1190         Briefing_background_colors[6] = gr_find_closest_color_current( 0, 19, 19);
1191         //End D1X addition
1192
1193         Erase_color = gr_find_closest_color_current(0, 0, 0);
1194 }
1195
1196 //-----------------------------------------------------------------------------
1197 // Return true if screen got aborted by user, else return false.
1198 int show_briefing_screen( int screen_num, int allow_keys)
1199 {
1200         int     rval=0;
1201         //ubyte   palette_save[768];
1202
1203         New_pal_254_bash = 0;
1204
1205         if (Skip_briefing_screens) {
1206                 mprintf((0, "Skipping briefing screen [%s]\n", &Briefing_screens[screen_num].bs_name));
1207                 return 0;
1208         }
1209
1210         if (EMULATING_D1) {
1211                 int pcx_error;
1212 #if 1
1213                 grs_bitmap briefing_bm;
1214
1215                 gr_init_bitmap_data(&briefing_bm);
1216                 if ((pcx_error=pcx_read_bitmap(Briefing_screens[screen_num].bs_name, &briefing_bm, BM_LINEAR, New_pal))!=PCX_ERROR_NONE) {
1217 #else
1218                 if ((pcx_error=pcx_read_fullscr(Briefing_screens[screen_num].bs_name, New_pal))!=PCX_ERROR_NONE) {
1219 #endif
1220                         printf("PCX load error: %s.  File '%s'\n\n", pcx_errormsg(pcx_error), Briefing_screens[screen_num].bs_name);
1221                         mprintf((0, "File '%s', PCX load error: %s (%i)\n  (It's a briefing screen.  Does this cause you pain?)\n", Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error), pcx_error));
1222                         Int3();
1223                         return 0;
1224                 }
1225
1226 #if 1
1227                 //memcpy(palette_save, gr_palette, sizeof(palette_save));
1228                 //memcpy(New_pal, gr_palette, sizeof(gr_palette));
1229
1230                 //vfx_set_palette_sub( New_pal );
1231 #ifdef OGL
1232                 gr_palette_load(New_pal);
1233 #else
1234                 gr_palette_clear();
1235 #endif
1236                 gr_set_current_canvas( NULL );
1237                 show_fullscr(&briefing_bm);
1238 #endif
1239
1240                 //added on 9/13/98 by adb to make arch's requiring updates work
1241                 gr_update();
1242                 //end changes by adb
1243
1244 #if 1
1245                 gr_free_bitmap_data (&briefing_bm);
1246 #endif
1247
1248                 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1249                         return 1;
1250
1251                 //memcpy(gr_palette,New_pal,sizeof(gr_palette));
1252
1253         }
1254
1255         #ifdef MACINTOSH
1256         key_close();            // kill the keyboard handler during briefing screens for movies
1257         #endif
1258         rval = show_briefing_text(screen_num);
1259         #ifdef MACINTOSH
1260         key_init();
1261         #endif
1262
1263         #if defined (MACINTOSH) || defined(WINDOWS)
1264         memcpy(New_pal,gr_palette,sizeof(gr_palette));          // attempt to get fades after briefing screens done correctly.
1265         #endif
1266
1267
1268         if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1269                 return 1;
1270
1271         //gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1272
1273         //d_free(briefing_bm.bm_data);
1274
1275         return rval;
1276 }
1277
1278
1279 //-----------------------------------------------------------------------------
1280 void do_briefing_screens(char *filename,int level_num)
1281 {
1282         int     abort_briefing_screens = 0;
1283         int     cur_briefing_screen = 0;
1284
1285         if (Skip_briefing_screens) {
1286                 mprintf((0, "Skipping all briefing screens.\n"));
1287                 return;
1288         }
1289
1290         #ifdef APPLE_DEMO
1291         return;                 // no briefing screens at all for demo
1292
1293         #endif
1294
1295         mprintf ((0,"Trying briefing screen <%s>\n",filename));
1296
1297         if (!filename || !*filename)
1298                 return;
1299
1300         if (!load_screen_text(filename, &Briefing_text))
1301                 return;
1302
1303         #ifdef SHAREWARE
1304         songs_play_song( SONG_BRIEFING, 1 );
1305         #else
1306         songs_stop_all();
1307         #endif
1308
1309         set_screen_mode( SCREEN_MENU );
1310
1311         gr_set_current_canvas(NULL);
1312
1313         mprintf ((0,"Playing briefing screen <%s>, level %d\n",filename,level_num));
1314
1315         key_flush();
1316
1317         if (EMULATING_D1) {
1318                 int i;
1319
1320                 for (i = 0; i < MAX_BRIEFING_SCREENS; i++)
1321                         memcpy(&Briefing_screens[i], &D1_Briefing_screens[i], sizeof(briefing_screen));
1322
1323                 if (level_num == 1) {
1324                         while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1325                                 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1326                                 cur_briefing_screen++;
1327                         }
1328                 }
1329
1330                 if (!abort_briefing_screens) {
1331                         for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREENS; cur_briefing_screen++)
1332                                 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1333                                         if (show_briefing_screen(cur_briefing_screen, 0))
1334                                                 break;
1335                 }
1336
1337         } else
1338                 show_briefing_screen(level_num,0);
1339
1340         d_free (Briefing_text);
1341         key_flush();
1342
1343         return;
1344
1345 }
1346
1347 int DefineBriefingBox (char **buf)
1348 {
1349         int n,i=0;
1350         char name[20];
1351
1352         n=get_new_message_num (buf);
1353
1354         Assert(n < MAX_BRIEFING_SCREENS);
1355
1356         while (**buf!=' ') {
1357                 name[i++]=**buf;
1358                 (*buf)++;
1359         }
1360
1361         name[i]='\0';   // slap a delimiter on this guy
1362
1363         strcpy (Briefing_screens[n].bs_name,name);
1364         Briefing_screens[n].level_num=get_new_message_num (buf);
1365         Briefing_screens[n].message_num=get_new_message_num (buf);
1366         Briefing_screens[n].text_ulx=get_new_message_num (buf);
1367         Briefing_screens[n].text_uly=get_new_message_num (buf);
1368         Briefing_screens[n].text_width=get_new_message_num (buf);
1369         Briefing_screens[n].text_height=get_message_num (buf);  // NOTICE!!!
1370
1371         Briefing_screens[n].text_ulx = rescale_x(Briefing_screens[n].text_ulx);
1372         Briefing_screens[n].text_uly = rescale_y(Briefing_screens[n].text_uly);
1373         Briefing_screens[n].text_width = rescale_x(Briefing_screens[n].text_width);
1374         Briefing_screens[n].text_height = rescale_y(Briefing_screens[n].text_height);
1375
1376         return (n);
1377 }
1378
1379 int get_new_message_num(char **message)
1380 {
1381         int     num=0;
1382
1383         while (**message == ' ')
1384                 (*message)++;
1385
1386         while ((**message >= '0') && (**message <= '9')) {
1387                 num = 10*num + **message-'0';
1388                 (*message)++;
1389         }
1390
1391        (*message)++;
1392
1393         return num;
1394 }
1395