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