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