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