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