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