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