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