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