]> icculus.org git repositories - btb/d2x.git/blob - main/titles.c
for Descent 1 briefings, look for briefings no further than NUM_D1_BRIEFING_SCREENS...
[btb/d2x.git] / main / titles.c
1 /* $Id: titles.c,v 1.39 2005-11-29 09:44:24 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 #define NUM_D1_BRIEFING_SCREENS (sizeof(D1_Briefing_screens)/sizeof(briefing_screen))
305
306 int     Briefing_text_x, Briefing_text_y;
307
308 void init_char_pos(int x, int y)
309 {
310         Briefing_text_x = x;
311         Briefing_text_y = y;
312         mprintf ((0,"Setting init x=%d y=%d\n",x,y));
313 }
314
315 grs_canvas      *Robot_canv = NULL;
316 vms_angvec      Robot_angles;
317
318 char    Bitmap_name[32] = "";
319 #define EXIT_DOOR_MAX   14
320 #define OTHER_THING_MAX 10      //  Adam: This is the number of frames in your new animating thing.
321 #define DOOR_DIV_INIT   6
322 sbyte   Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
323
324 //-----------------------------------------------------------------------------
325 void show_bitmap_frame(void)
326 {
327         grs_canvas *curcanv_save, *bitmap_canv=0;
328
329         grs_bitmap *bitmap_ptr;
330
331         //      Only plot every nth frame.
332         if (Door_div_count) {
333                 Door_div_count--;
334                 return;
335         }
336
337         Door_div_count = DOOR_DIV_INIT;
338
339         if (Bitmap_name[0] != 0) {
340                 char            *pound_signp;
341                 int             num, dig1, dig2;
342
343                 //      Set supertransparency color to black
344                 if (!New_pal_254_bash) {
345                         New_pal_254_bash = 1;
346                         New_pal[254*3] = 0;
347                         New_pal[254*3+1] = 0;
348                         New_pal[254*3+2] = 0;
349                         gr_palette_load( New_pal );
350                 }
351
352                 switch (Animating_bitmap_type) {
353                 case 0:
354                         bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 64, 64);
355                         break;
356                 case 1:
357                         bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 94, 94);
358                         break;
359
360                         // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
361                         default:
362                                 Int3(); // Impossible, illegal value for Animating_bitmap_type
363                 }
364
365                 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv;
366
367                 pound_signp = strchr(Bitmap_name, '#');
368                 Assert(pound_signp != NULL);
369
370                 dig1 = *(pound_signp+1);
371                 dig2 = *(pound_signp+2);
372                 if (dig2 == 0)
373                         num = dig1-'0';
374                 else
375                         num = (dig1-'0')*10 + (dig2-'0');
376
377                 switch (Animating_bitmap_type) {
378                 case 0:
379                         num += Door_dir;
380                         if (num > EXIT_DOOR_MAX) {
381                                 num = EXIT_DOOR_MAX;
382                                 Door_dir = -1;
383                         } else if (num < 0) {
384                                 num = 0;
385                                 Door_dir = 1;
386                         }
387                         break;
388                 case 1:
389                         num++;
390                         if (num > OTHER_THING_MAX)
391                                 num = 0;
392                         break;
393                 }
394
395                 Assert(num < 100);
396                 if (num >= 10) {
397                         *(pound_signp+1) = (num / 10) + '0';
398                         *(pound_signp+2) = (num % 10) + '0';
399                         *(pound_signp+3) = 0;
400                 } else {
401                         *(pound_signp+1) = (num % 10) + '0';
402                         *(pound_signp+2) = 0;
403                 }
404
405                 {
406                         bitmap_index bi;
407                         bi = piggy_find_bitmap(Bitmap_name);
408                         bitmap_ptr = &GameBitmaps[bi.index];
409                         PIGGY_PAGE_IN( bi );
410                 }
411
412                 gr_bitmapm(0, 0, bitmap_ptr);
413
414                 grd_curcanv = curcanv_save;
415                 d_free(bitmap_canv);
416
417                 switch (Animating_bitmap_type) {
418                 case 0:
419                         if (num == EXIT_DOOR_MAX) {
420                                 Door_dir = -1;
421                                 Door_div_count = 64;
422                         } else if (num == 0) {
423                                 Door_dir = 1;
424                                 Door_div_count = 64;
425                         }
426                         break;
427                 case 1:
428                         break;
429                 }
430         }
431
432 }
433
434 //-----------------------------------------------------------------------------
435 void show_briefing_bitmap(grs_bitmap *bmp)
436 {
437         grs_canvas      *curcanv_save, *bitmap_canv;
438
439         bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
440         curcanv_save = grd_curcanv;
441         gr_set_current_canvas(bitmap_canv);
442         gr_bitmapm(0, 0, bmp);
443         gr_set_current_canvas(curcanv_save);
444
445         d_free(bitmap_canv);
446 }
447
448 //-----------------------------------------------------------------------------
449 void show_spinning_robot_frame(int robot_num)
450 {
451         grs_canvas      *curcanv_save;
452
453         if (robot_num != -1) {
454                 Robot_angles.h += 150;
455
456                 curcanv_save = grd_curcanv;
457                 grd_curcanv = Robot_canv;
458                 Assert(Robot_info[robot_num].model_num != -1);
459                 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
460                 grd_curcanv = curcanv_save;
461         }
462
463 }
464
465 //-----------------------------------------------------------------------------
466 void init_spinning_robot(void) //(int x,int y,int w,int h)
467 {
468         //Robot_angles.p += 0;
469         //Robot_angles.b += 0;
470         //Robot_angles.h += 0;
471
472         int x = rescale_x(138);
473         int y = rescale_y(55);
474         int w = rescale_x(166);
475         int h = rescale_y(138);
476
477         Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
478         // 138, 55, 166, 138
479 }
480
481 //---------------------------------------------------------------------------
482 // Returns char width.
483 // If show_robot_flag set, then show a frame of the spinning robot.
484 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
485 {
486         int w, h, aw;
487         char message[2];
488         static fix      start_time=0;
489
490         message[0] = the_char;
491         message[1] = 0;
492
493         if (start_time==0 && timer_get_fixed_seconds()<0)
494                 start_time=timer_get_fixed_seconds();
495
496         gr_get_string_size(message, &w, &h, &aw );
497
498         Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
499
500         //      Draw cursor if there is some delay and caller says to draw cursor
501         if (cursor_flag && delay) {
502                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
503                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
504                 gr_update();
505         }
506
507         if (delay)
508                 delay=fixdiv (F1_0,i2f(15));
509
510         if ((Bitmap_name[0] != 0) && (delay != 0))
511                 show_bitmap_frame();
512
513         if (RobotPlaying && (delay != 0))
514                 RotateRobot();
515
516         while (timer_get_fixed_seconds() < (start_time + delay)) {
517                 if (RobotPlaying && delay != 0)
518                         RotateRobot();
519         }
520         if (robot_num != -1)
521                 show_spinning_robot_frame(robot_num);
522
523         start_time = timer_get_fixed_seconds();
524
525         //      Erase cursor
526         if (cursor_flag && delay) {
527                 gr_set_fontcolor(Erase_color, -1);
528                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
529         }
530
531         //      Draw the character
532         gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
533         gr_printf(Briefing_text_x, Briefing_text_y, message );
534
535         gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
536         gr_printf(Briefing_text_x+1, Briefing_text_y, message );
537
538         if (delay) gr_update();
539
540 //      if (the_char != ' ')
541 //              if (!digi_is_sound_playing(SOUND_MARKER_HIT))
542 //                      digi_play_sample( SOUND_MARKER_HIT, F1_0 );
543
544         return w;
545 }
546
547 //-----------------------------------------------------------------------------
548 int load_briefing_screen( int screen_num )
549 {
550         int     pcx_error;
551         char *fname;
552
553         if (EMULATING_D1)
554                 fname = Briefing_screens[screen_num].bs_name;
555         else
556                 fname = CurBriefScreenName;
557
558         if ((pcx_error = pcx_read_fullscr(fname, New_pal)) != PCX_ERROR_NONE) {
559                 printf( "File '%s', PCX load error: %s\n  (It's a briefing screen.  Does this cause you pain?)\n", fname, pcx_errormsg(pcx_error));
560                 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);
561                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n", fname, pcx_errormsg(pcx_error), pcx_error);
562         }
563
564         return 0;
565 }
566
567 int load_new_briefing_screen( char *fname )
568 {
569         int pcx_error;
570
571         mprintf ((0,"Loading new briefing <%s>\n",fname));
572         strcpy (CurBriefScreenName,fname);
573
574         if (gr_palette_fade_out( New_pal, 32, 0 ))
575                 return 0;
576
577         if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE)     {
578         //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE)     {
579                 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);
580                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
581         }
582
583         gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
584
585         if (gr_palette_fade_in( New_pal, 32, 0 ))
586                 return 0;
587         DoBriefingColorStuff();
588
589         return 1;
590 }
591
592
593
594 #define KEY_DELAY_DEFAULT       ((F1_0*20)/1000)
595
596 //-----------------------------------------------------------------------------
597 int get_message_num(char **message)
598 {
599         int     num=0;
600
601         while (**message == ' ')
602                 (*message)++;
603
604         while ((**message >= '0') && (**message <= '9')) {
605                 num = 10*num + **message-'0';
606                 (*message)++;
607         }
608
609         while (*(*message)++ != 10)             //      Get and drop eoln
610                 ;
611
612         return num;
613 }
614
615 //-----------------------------------------------------------------------------
616 void get_message_name(char **message, char *result)
617 {
618         while (**message == ' ')
619                 (*message)++;
620
621         while ((**message != ' ') && (**message != 10)) {
622                 if (**message != '\n')
623                         *result++ = **message;
624                 (*message)++;
625         }
626
627         if (**message != 10)
628                 while (*(*message)++ != 10)             //      Get and drop eoln
629                         ;
630
631         *result = 0;
632 }
633
634 //-----------------------------------------------------------------------------
635 void flash_cursor(int cursor_flag)
636 {
637         if (cursor_flag == 0)
638                 return;
639
640         if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
641                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
642         else
643                 gr_set_fontcolor(Erase_color, -1);
644
645         gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
646         gr_update();
647 }
648
649 extern int InitMovieBriefing();
650
651
652 //-----------------------------------------------------------------------------
653 // Return true if message got aborted by user (pressed ESC), else return false.
654 int show_briefing_message(int screen_num, char *message)
655 {
656         int     prev_ch=-1;
657         int     ch, done=0,i;
658         briefing_screen *bsp;
659         int     delay_count = KEY_DELAY_DEFAULT;
660         int     key_check;
661         int     robot_num=-1;
662         int     rval=0;
663         static int tab_stop=0;
664         int     flashing_cursor=0;
665         int     new_page=0,GotZ=0;
666         char spinRobotName[]="rba.mve",kludge;  // matt don't change this!
667         char fname[15];
668         char DumbAdjust=0;
669         char chattering=0;
670         int hum_channel=-1,printing_channel=-1;
671         int LineAdjustment=1;
672
673         Bitmap_name[0] = 0;
674         Current_color = 0;
675         RobotPlaying=0;
676
677         InitMovieBriefing();
678
679         #ifndef SHAREWARE
680         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
681         #endif
682
683         // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
684         gr_set_curfont( GAME_FONT );
685
686         if (EMULATING_D1) {
687                 GotZ = 1;
688                 MALLOC(bsp, briefing_screen, 1);
689                 memcpy(bsp, &Briefing_screens[screen_num], sizeof(briefing_screen));
690                 bsp->text_ulx = rescale_x(bsp->text_ulx);
691                 bsp->text_uly = rescale_y(bsp->text_uly);
692                 bsp->text_width = rescale_x(bsp->text_width);
693                 bsp->text_height = rescale_y(bsp->text_height);
694                 init_char_pos(bsp->text_ulx, bsp->text_uly);
695         } else {
696                 bsp=&Briefing_screens[0];
697                 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
698         }
699
700         while (!done) {
701                 ch = *message++;
702                 if (ch == '$') {
703                         ch = *message++;
704                         if (ch=='D') {
705                                 screen_num=DefineBriefingBox (&message);
706                         //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
707
708                                 bsp = &Briefing_screens[screen_num];
709                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
710                                 LineAdjustment=0;
711                                 prev_ch = 10;                                   // read to eoln
712                         } else if (ch=='U') {
713                                 screen_num=get_message_num(&message);
714                                 bsp = &Briefing_screens[screen_num];
715                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
716                                 prev_ch = 10;                                   // read to eoln
717                         } else if (ch == 'C') {
718                                 Current_color = get_message_num(&message)-1;
719                                 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
720                                 prev_ch = 10;
721                         } else if (ch == 'F') {     // toggle flashing cursor
722                                 flashing_cursor = !flashing_cursor;
723                                 prev_ch = 10;
724                                 while (*message++ != 10)
725                                         ;
726                         } else if (ch == 'T') {
727                                 tab_stop = get_message_num(&message);
728                                 tab_stop*=(1+MenuHires);
729                                 prev_ch = 10;                                                   //      read to eoln
730                         } else if (ch == 'R') {
731                                 if (Robot_canv != NULL) {
732                                         d_free(Robot_canv);
733                                         Robot_canv=NULL;
734                                 }
735                                 if (RobotPlaying) {
736                                         DeInitRobotMovie();
737                                         RobotPlaying=0;
738                                 }
739
740                                 if (EMULATING_D1) {
741                                         init_spinning_robot();
742                                         robot_num = get_message_num(&message);
743                                         while (*message++ != 10)
744                                                 ;
745                                 } else {
746                                         kludge=*message++;
747                                         spinRobotName[2]=kludge; // ugly but proud
748
749                                         RobotPlaying=InitRobotMovie(spinRobotName);
750
751                                         // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
752
753                                         if (RobotPlaying) {
754                                                 RotateRobot();
755                                                 DoBriefingColorStuff ();
756                                                 mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
757                                         }
758                                 }
759                                 prev_ch = 10;                           // read to eoln
760                         } else if (ch == 'N') {
761                                 //--grs_bitmap *bitmap_ptr;
762                                 if (Robot_canv != NULL) {
763                                         d_free(Robot_canv);
764                                         Robot_canv=NULL;
765                                 }
766
767                                 get_message_name(&message, Bitmap_name);
768                                 strcat(Bitmap_name, "#0");
769                                 Animating_bitmap_type = 0;
770                                 prev_ch = 10;
771                         } else if (ch == 'O') {
772                                 if (Robot_canv != NULL) {
773                                                 d_free(Robot_canv);
774                                                 Robot_canv=NULL;
775                                 }
776
777                                 get_message_name(&message, Bitmap_name);
778                                 strcat(Bitmap_name, "#0");
779                                 Animating_bitmap_type = 1;
780                                 prev_ch = 10;
781                         } else if (ch=='A') {
782                                 LineAdjustment=1-LineAdjustment;
783                         } else if (ch=='Z') {
784                                 //mprintf ((0,"Got a Z!\n"));
785                                 GotZ=1;
786 #if 1 //defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
787                                 DumbAdjust=1;
788 #else
789                                 if (LineAdjustment==1)
790                                         DumbAdjust=1;
791                                 else
792                                         DumbAdjust=2;
793 #endif
794
795                                 i=0;
796                                 while ((fname[i]=*message) != '\n') {
797                                         i++;
798                                         message++;
799                                 }
800                                 fname[i]=0;
801                                 if (*message != 10)
802                                         while (*message++ != 10)    //  Get and drop eoln
803                                                 ;
804
805                                 {
806                                         char fname2[15];
807
808                                         i=0;
809                                         while (fname[i]!='.') {
810                                                 fname2[i] = fname[i];
811                                                 i++;
812                                         }
813                                         fname2[i++]='b';
814                                         fname2[i++]='.';
815                                         fname2[i++]='p';
816                                         fname2[i++]='c';
817                                         fname2[i++]='x';
818                                         fname2[i++]=0;
819
820                                         if ((MenuHires && cfexist(fname2)) || !cfexist(fname))
821                                                 load_new_briefing_screen (fname2);
822                                         else
823                                                 load_new_briefing_screen (fname);
824                                 }
825
826                                 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
827
828                         } else if (ch == 'B') {
829                                 char        bitmap_name[32];
830                                 grs_bitmap  guy_bitmap;
831                                 ubyte       temp_palette[768];
832                                 int         iff_error;
833
834                                 if (Robot_canv != NULL) {
835                                         d_free(Robot_canv);
836                                         Robot_canv=NULL;
837                                 }
838
839                                 get_message_name(&message, bitmap_name);
840                                 strcat(bitmap_name, ".bbm");
841                                 guy_bitmap.bm_data = NULL;
842                                 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
843                                 Assert(iff_error == IFF_NO_ERROR);
844                                 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
845
846                                 show_briefing_bitmap(&guy_bitmap);
847                                 d_free(guy_bitmap.bm_data);
848                                 prev_ch = 10;
849 //                      } else if (ch==EOF) {
850 //                              done=1;
851 //                      } else if (ch == 'B') {
852 //                              if (Robot_canv != NULL) {
853 //                                      d_free(Robot_canv);
854 //                                      Robot_canv=NULL;
855 //                              }
856 //
857 //                              bitmap_num = get_message_num(&message);
858 //                              if (bitmap_num != -1)
859 //                                      show_briefing_bitmap(Textures[bitmap_num]);
860 //                              prev_ch = 10;                           // read to eoln
861                         } else if (ch == 'S') {
862                                 int keypress;
863                                 fix start_time;
864
865                                 chattering=0;
866                                 if (printing_channel>-1)
867                                         digi_stop_sound( printing_channel );
868                                 printing_channel=-1;
869
870                                 gr_update();
871
872                                 start_time = timer_get_fixed_seconds();
873                                 while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
874
875                                         while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
876                                                 ;
877                                         flash_cursor(flashing_cursor);
878
879                                         if (RobotPlaying)
880                                                 RotateRobot ();
881                                         if (robot_num != -1)
882                                                 show_spinning_robot_frame(robot_num);
883
884                                         if (Bitmap_name[0] != 0)
885                                                 show_bitmap_frame();
886                                         start_time += KEY_DELAY_DEFAULT/2;
887                                 }
888
889 #ifndef NDEBUG
890                                 if (keypress == KEY_BACKSP)
891                                         Int3();
892 #endif
893                                 if (keypress == KEY_ESC)
894                                         rval = 1;
895
896                                 flashing_cursor = 0;
897                                 done = 1;
898                         } else if (ch == 'P') {         //      New page.
899                                 if (!GotZ) {
900                                         Int3(); // Hey ryan!!!! You gotta load a screen before you start
901                                                 // printing to it! You know, $Z !!!
902                                     load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
903                                 }
904
905                                 new_page = 1;
906                                 while (*message != 10) {
907                                         message++;      //      drop carriage return after special escape sequence
908                                 }
909                                 message++;
910                                 prev_ch = 10;
911                                 gr_update();
912                         }
913                 } else if (ch == '\t') {                //      Tab
914                         if (Briefing_text_x - bsp->text_ulx < tab_stop)
915                                 Briefing_text_x = bsp->text_ulx + tab_stop;
916                 } else if ((ch == ';') && (prev_ch == 10)) {
917                         while (*message++ != 10)
918                                 ;
919                         prev_ch = 10;
920                 } else if (ch == '\\') {
921                         prev_ch = ch;
922                 } else if (ch == 10) {
923                         if (prev_ch != '\\') {
924                                 prev_ch = ch;
925                                 if (DumbAdjust==0)
926                                         Briefing_text_y += (8*(MenuHires+1));
927                                 else
928                                         DumbAdjust--;
929                                 Briefing_text_x = bsp->text_ulx;
930                                 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
931                                         load_briefing_screen(screen_num);
932                                         Briefing_text_x = bsp->text_ulx;
933                                         Briefing_text_y = bsp->text_uly;
934                                 }
935                         } else {
936                                 if (ch == 13)           //Can this happen? Above says ch==10
937                                         Int3();
938                                 prev_ch = ch;
939                         }
940
941                 } else {
942                         if (!GotZ) {
943                                 Int3(); // Hey ryan!!!! You gotta load a screen before you start
944                                         // printing to it! You know, $Z !!!
945                                 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
946                         }
947
948                         prev_ch = ch;
949
950                         if (!chattering) {
951                                 printing_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
952                                 chattering=1;
953                         }
954
955                         Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
956
957                 }
958
959                 //      Check for Esc -> abort.
960                 if(delay_count)
961                         key_check=local_key_inkey();
962                 else
963                         key_check=0;
964
965 #ifdef WINDOWS
966                 if (_RedrawScreen) {
967                         _RedrawScreen = FALSE;
968                         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
969                         key_check = KEY_ESC;
970                 }
971 #endif
972                 if ( key_check == KEY_ESC ) {
973                         rval = 1;
974                         done = 1;
975                 }
976
977                 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
978                         delay_count = 0;
979
980 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
981                 if ((key_check == KEY_ALTED+KEY_ENTER) ||
982                         (key_check == KEY_ALTED+KEY_PADENTER))
983                         gr_toggle_fullscreen();
984 #endif
985
986                 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
987                         Briefing_text_x = bsp->text_ulx;
988                         Briefing_text_y += bsp->text_uly;
989                 }
990
991                 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
992                         fix     start_time = 0;
993                         int     keypress;
994
995                         new_page = 0;
996
997                         if (printing_channel>-1)
998                                 digi_stop_sound( printing_channel );
999                         printing_channel=-1;
1000
1001                         chattering=0;
1002
1003                         start_time = timer_get_fixed_seconds();
1004                         while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
1005                                 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1006                                         ;
1007                                 flash_cursor(flashing_cursor);
1008                                 if (RobotPlaying)
1009                                         RotateRobot();
1010                                 if (robot_num != -1)
1011                                         show_spinning_robot_frame(robot_num);
1012                                 if (Bitmap_name[0] != 0)
1013                                         show_bitmap_frame();
1014                                 start_time += KEY_DELAY_DEFAULT/2;
1015                         }
1016
1017                         if (RobotPlaying)
1018                                 DeInitRobotMovie();
1019                         RobotPlaying=0;
1020                         robot_num = -1;
1021
1022 #ifndef NDEBUG
1023                         if (keypress == KEY_BACKSP)
1024                                 Int3();
1025 #endif
1026                         if (keypress == KEY_ESC) {
1027                                 rval = 1;
1028                                 done = 1;
1029                         }
1030
1031                         load_briefing_screen(screen_num);
1032                         Briefing_text_x = bsp->text_ulx;
1033                         Briefing_text_y = bsp->text_uly;
1034                         delay_count = KEY_DELAY_DEFAULT;
1035                 }
1036         }
1037
1038         if (RobotPlaying) {
1039                 DeInitRobotMovie();
1040                 RobotPlaying=0;
1041         }
1042
1043         if (Robot_canv != NULL)
1044                 {d_free(Robot_canv); Robot_canv=NULL;}
1045
1046         if (hum_channel>-1)
1047                 digi_stop_sound( hum_channel );
1048         if (printing_channel>-1)
1049                 digi_stop_sound( printing_channel );
1050
1051         if (EMULATING_D1)
1052                 d_free(bsp);
1053
1054         return rval;
1055 }
1056
1057 //-----------------------------------------------------------------------------
1058 // Return a pointer to the start of text for screen #screen_num.
1059 char * get_briefing_message(int screen_num)
1060 {
1061         char *tptr = Briefing_text;
1062         int     cur_screen=0;
1063         int     ch;
1064
1065         Assert(screen_num >= 0);
1066
1067         while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1068                 ch = *tptr++;
1069                 if (ch == '$') {
1070                         ch = *tptr++;
1071                         if (ch == 'S')
1072                                 cur_screen = get_message_num(&tptr);
1073                 }
1074         }
1075
1076         if (screen_num!=cur_screen)
1077                 return (NULL);
1078
1079         return tptr;
1080 }
1081
1082 //-----------------------------------------------------------------------------
1083 //      Load Descent briefing text.
1084 int load_screen_text(char *filename, char **buf)
1085 {
1086         CFILE *tfile;
1087         CFILE *ifile;
1088         int     len, i,x;
1089         int     have_binary = 0;
1090
1091         if ((tfile = cfopen(filename,"rb")) == NULL) {
1092                 char nfilename[30], *ptr;
1093
1094                 strcpy(nfilename, filename);
1095                 if ((ptr = strrchr(nfilename, '.')))
1096                         *ptr = '\0';
1097                 strcat(nfilename, ".txb");
1098                 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1099                         mprintf ((0,"can't open %s!\n",nfilename));
1100                         return (0);
1101                                 //Error("Cannot open file %s or %s", filename, nfilename);
1102                 }
1103
1104                 mprintf ((0,"reading...\n"));
1105                 have_binary = 1;
1106
1107                 len = cfilelength(ifile);
1108                 MALLOC(*buf, char, len+500);
1109                 mprintf ((0,"len=%d\n",len));
1110                 for (x=0, i=0; i < len; i++, x++) {
1111                         cfread (*buf+x,1,1,ifile);
1112                         //  mprintf ((0,"%c",*(*buf+x)));
1113                         if (*(*buf+x)==13)
1114                                 x--;
1115                 }
1116
1117                 cfclose(ifile);
1118         } else {
1119                 len = cfilelength(tfile);
1120                 MALLOC(*buf, char, len+500);
1121                 for (x=0, i=0; i < len; i++, x++) {
1122                         cfread (*buf+x,1,1,tfile);
1123                         // mprintf ((0,"%c",*(*buf+x)));
1124                         if (*(*buf+x)==13)
1125                                 x--;
1126                 }
1127
1128
1129                 //cfread(*buf, 1, len, tfile);
1130                 cfclose(tfile);
1131         }
1132
1133         if (have_binary)
1134                 decode_text(*buf, len);
1135
1136         return (1);
1137 }
1138
1139 //-----------------------------------------------------------------------------
1140 // Return true if message got aborted, else return false.
1141 int show_briefing_text(int screen_num)
1142 {
1143         char    *message_ptr;
1144
1145         message_ptr = get_briefing_message
1146                 (EMULATING_D1 ? Briefing_screens[screen_num].message_num : screen_num);
1147
1148         if (message_ptr==NULL)
1149                 return (0);
1150
1151         DoBriefingColorStuff();
1152
1153         return show_briefing_message(screen_num, message_ptr);
1154 }
1155
1156 void DoBriefingColorStuff ()
1157 {
1158         Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1159         Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1160
1161         Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1162         Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1163
1164         Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1165         Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1166
1167         if (EMULATING_D1) {
1168                 //green
1169                 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 54, 0);
1170                 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 19, 0);
1171                 //white
1172                 Briefing_foreground_colors[1] = gr_find_closest_color_current( 42, 38, 32);
1173                 Briefing_background_colors[1] = gr_find_closest_color_current( 14, 14, 14);
1174
1175                 //Begin D1X addition
1176                 //red
1177                 Briefing_foreground_colors[2] = gr_find_closest_color_current( 63, 0, 0);
1178                 Briefing_background_colors[2] = gr_find_closest_color_current( 31, 0, 0);
1179         }
1180         //blue
1181         Briefing_foreground_colors[3] = gr_find_closest_color_current( 0, 0, 54);
1182         Briefing_background_colors[3] = gr_find_closest_color_current( 0, 0, 19);
1183         //gray
1184         Briefing_foreground_colors[4] = gr_find_closest_color_current( 14, 14, 14);
1185         Briefing_background_colors[4] = gr_find_closest_color_current( 0, 0, 0);
1186         //yellow
1187         Briefing_foreground_colors[5] = gr_find_closest_color_current( 54, 54, 0);
1188         Briefing_background_colors[5] = gr_find_closest_color_current( 19, 19, 0);
1189         //purple
1190         Briefing_foreground_colors[6] = gr_find_closest_color_current( 0, 54, 54);
1191         Briefing_background_colors[6] = gr_find_closest_color_current( 0, 19, 19);
1192         //End D1X addition
1193
1194         Erase_color = gr_find_closest_color_current(0, 0, 0);
1195 }
1196
1197 //-----------------------------------------------------------------------------
1198 // Return true if screen got aborted by user, else return false.
1199 int show_briefing_screen( int screen_num, int allow_keys)
1200 {
1201         int     rval=0;
1202         //ubyte   palette_save[768];
1203
1204         New_pal_254_bash = 0;
1205
1206         if (Skip_briefing_screens) {
1207                 mprintf((0, "Skipping briefing screen [%s]\n", &Briefing_screens[screen_num].bs_name));
1208                 return 0;
1209         }
1210
1211         if (EMULATING_D1) {
1212                 int pcx_error;
1213 #if 1
1214                 grs_bitmap briefing_bm;
1215
1216                 gr_init_bitmap_data(&briefing_bm);
1217                 if ((pcx_error=pcx_read_bitmap(Briefing_screens[screen_num].bs_name, &briefing_bm, BM_LINEAR, New_pal))!=PCX_ERROR_NONE) {
1218 #else
1219                 if ((pcx_error=pcx_read_fullscr(Briefing_screens[screen_num].bs_name, New_pal))!=PCX_ERROR_NONE) {
1220 #endif
1221                         printf("PCX load error: %s.  File '%s'\n\n", pcx_errormsg(pcx_error), Briefing_screens[screen_num].bs_name);
1222                         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));
1223                         Int3();
1224                         return 0;
1225                 }
1226
1227 #if 1
1228                 //memcpy(palette_save, gr_palette, sizeof(palette_save));
1229                 //memcpy(New_pal, gr_palette, sizeof(gr_palette));
1230
1231                 //vfx_set_palette_sub( New_pal );
1232 #ifdef OGL
1233                 gr_palette_load(New_pal);
1234 #else
1235                 gr_palette_clear();
1236 #endif
1237                 gr_set_current_canvas( NULL );
1238                 show_fullscr(&briefing_bm);
1239 #endif
1240
1241                 //added on 9/13/98 by adb to make arch's requiring updates work
1242                 gr_update();
1243                 //end changes by adb
1244
1245 #if 1
1246                 gr_free_bitmap_data (&briefing_bm);
1247 #endif
1248
1249                 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1250                         return 1;
1251
1252                 //memcpy(gr_palette,New_pal,sizeof(gr_palette));
1253
1254         }
1255
1256         #ifdef MACINTOSH
1257         key_close();            // kill the keyboard handler during briefing screens for movies
1258         #endif
1259         rval = show_briefing_text(screen_num);
1260         #ifdef MACINTOSH
1261         key_init();
1262         #endif
1263
1264         #if defined (MACINTOSH) || defined(WINDOWS)
1265         memcpy(New_pal,gr_palette,sizeof(gr_palette));          // attempt to get fades after briefing screens done correctly.
1266         #endif
1267
1268
1269         if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1270                 return 1;
1271
1272         //gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1273
1274         //d_free(briefing_bm.bm_data);
1275
1276         return rval;
1277 }
1278
1279
1280 //-----------------------------------------------------------------------------
1281 void do_briefing_screens(char *filename,int level_num)
1282 {
1283         int     abort_briefing_screens = 0;
1284         int     cur_briefing_screen = 0;
1285
1286         if (Skip_briefing_screens) {
1287                 mprintf((0, "Skipping all briefing screens.\n"));
1288                 return;
1289         }
1290
1291         #ifdef APPLE_DEMO
1292         return;                 // no briefing screens at all for demo
1293
1294         #endif
1295
1296         mprintf ((0,"Trying briefing screen <%s>\n",filename));
1297
1298         if (!filename || !*filename)
1299                 return;
1300
1301         if (!load_screen_text(filename, &Briefing_text))
1302                 return;
1303
1304         #ifdef SHAREWARE
1305         songs_play_song( SONG_BRIEFING, 1 );
1306         #else
1307         songs_stop_all();
1308         #endif
1309
1310         set_screen_mode( SCREEN_MENU );
1311
1312         gr_set_current_canvas(NULL);
1313
1314         mprintf ((0,"Playing briefing screen <%s>, level %d\n",filename,level_num));
1315
1316         key_flush();
1317
1318         if (EMULATING_D1) {
1319                 int i;
1320
1321                 for (i = 0; i < NUM_D1_BRIEFING_SCREENS; i++)
1322                         memcpy(&Briefing_screens[i], &D1_Briefing_screens[i], sizeof(briefing_screen));
1323
1324                 if (level_num == 1) {
1325                         while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1326                                 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1327                                 cur_briefing_screen++;
1328                         }
1329                 }
1330
1331                 if (!abort_briefing_screens) {
1332                         for (cur_briefing_screen = 0; cur_briefing_screen < NUM_D1_BRIEFING_SCREENS; cur_briefing_screen++)
1333                                 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1334                                         if (show_briefing_screen(cur_briefing_screen, 0))
1335                                                 break;
1336                 }
1337
1338         } else
1339                 show_briefing_screen(level_num,0);
1340
1341         d_free (Briefing_text);
1342         key_flush();
1343
1344         return;
1345
1346 }
1347
1348 int DefineBriefingBox (char **buf)
1349 {
1350         int n,i=0;
1351         char name[20];
1352
1353         n=get_new_message_num (buf);
1354
1355         Assert(n < MAX_BRIEFING_SCREENS);
1356
1357         while (**buf!=' ') {
1358                 name[i++]=**buf;
1359                 (*buf)++;
1360         }
1361
1362         name[i]='\0';   // slap a delimiter on this guy
1363
1364         strcpy (Briefing_screens[n].bs_name,name);
1365         Briefing_screens[n].level_num=get_new_message_num (buf);
1366         Briefing_screens[n].message_num=get_new_message_num (buf);
1367         Briefing_screens[n].text_ulx=get_new_message_num (buf);
1368         Briefing_screens[n].text_uly=get_new_message_num (buf);
1369         Briefing_screens[n].text_width=get_new_message_num (buf);
1370         Briefing_screens[n].text_height=get_message_num (buf);  // NOTICE!!!
1371
1372         Briefing_screens[n].text_ulx = rescale_x(Briefing_screens[n].text_ulx);
1373         Briefing_screens[n].text_uly = rescale_y(Briefing_screens[n].text_uly);
1374         Briefing_screens[n].text_width = rescale_x(Briefing_screens[n].text_width);
1375         Briefing_screens[n].text_height = rescale_y(Briefing_screens[n].text_height);
1376
1377         return (n);
1378 }
1379
1380 int get_new_message_num(char **message)
1381 {
1382         int     num=0;
1383
1384         while (**message == ' ')
1385                 (*message)++;
1386
1387         while ((**message >= '0') && (**message <= '9')) {
1388                 num = 10*num + **message-'0';
1389                 (*message)++;
1390         }
1391
1392        (*message)++;
1393
1394         return num;
1395 }
1396