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