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