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