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