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