1 /* $Id: titles.c,v 1.40 2006-07-29 03:49:00 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines to display title screens...
67 void DoBriefingColorStuff ();
68 int get_new_message_num(char **message);
69 int DefineBriefingBox (char **buf);
71 extern unsigned RobSX,RobSY,RobDX,RobDY; // Robot movie coords
76 char CurBriefScreenName[15]="brief03.pcx";
80 //Begin D1X modification
81 #define MAX_BRIEFING_COLORS 7
82 //End D1X modification
84 #define SHAREWARE_ENDING_FILENAME "ending.tex"
86 // Can be set by -noscreens command line option. Causes bypassing of all briefing screens.
87 int Skip_briefing_screens=0;
88 int Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
89 int Current_color = 0;
92 extern int check_button_press();
95 // added by Jan Bobrowski for variable-size menu screen
96 static int rescale_x(int x)
98 return x * GWIDTH / 320;
101 static int rescale_y(int y)
103 return y * GHEIGHT / 200;
107 int local_key_inkey(void)
113 if (rval == KEY_PRINT_SCREEN) {
115 return 0; //say no key pressed
118 if (check_button_press()) //joystick or mouse button pressed?
120 else if (mouse_button_state(0))
123 if ( rval == KEY_Q+KEY_COMMAND )
129 int local_key_inkey(void)
134 if (!GetOSEvent(everyEvent, &event))
137 if (event.what != keyDown)
140 rval = (int)((event.message & keyCodeMask) >> 8);
142 if (rval == KEY_PRINT_SCREEN) {
144 return 0; //say no key pressed
147 if (check_button_press()) //joystick or mouse button pressed?
150 if ( rval == KEY_Q+KEY_COMMAND )
158 void delay_until(fix time)
160 fix t = timer_get_fixed_seconds();
162 timer_delay(time - t);
166 int show_title_screen( char * filename, int allow_keys, int from_hog_only )
171 ubyte palette_save[768];
172 char new_filename[FILENAME_LEN+1] = "";
176 strcpy(new_filename,"\x01"); //only read from hog file
179 strcat(new_filename,filename);
180 filename = new_filename;
182 title_bm.bm_data=NULL;
183 if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
184 printf( "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
185 mprintf((0, "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error));
186 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error);
189 memcpy(palette_save,gr_palette,sizeof(palette_save));
191 //vfx_set_palette_sub( New_pal );
194 gr_set_current_canvas( NULL );
195 show_fullscr(&title_bm);
197 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
199 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
201 gr_palette_load( New_pal );
202 timer = timer_get_fixed_seconds() + i2f(3);
204 if ( local_key_inkey() && allow_keys ) break;
205 if ( timer_get_fixed_seconds() > timer ) break;
207 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
209 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
210 d_free(title_bm.bm_data);
214 int intro_played = 0;
216 void show_titles(void)
219 int played=MOVIE_NOT_PLAYED; //default is not played
221 int song_playing = 0;
224 #define MOVIE_REQUIRED 0
226 #define MOVIE_REQUIRED 1
229 { //show bundler screens
230 char filename[FILENAME_LEN];
232 played=MOVIE_NOT_PLAYED; //default is not played
234 played = PlayMovie("pre_i.mve",0);
237 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
239 while (PHYSFS_exists(filename))
241 show_title_screen( filename, 1, 0 );
248 init_subtitles("intro.tex");
249 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
253 if (played != MOVIE_NOT_PLAYED)
256 { //didn't get intro movie, try titles
258 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
260 if (played == MOVIE_NOT_PLAYED)
262 char filename[FILENAME_LEN];
264 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
266 set_screen_mode(SCREEN_MENU);
268 con_printf( CON_DEBUG, "\nPlaying title song..." );
269 songs_play_song( SONG_TITLE, 1);
271 con_printf( CON_DEBUG, "\nShowing logo screens..." );
273 strcpy(filename, MenuHires?"iplogo1b.pcx":"iplogo1.pcx"); // OEM
274 if (! cfexist(filename))
275 strcpy(filename, "iplogo1.pcx"); // SHAREWARE
276 if (! cfexist(filename))
277 strcpy(filename, "mplogo.pcx"); // MAC SHAREWARE
278 if (cfexist(filename))
279 show_title_screen(filename, 1, 1);
281 strcpy(filename, MenuHires?"logob.pcx":"logo.pcx"); // OEM
282 if (! cfexist(filename))
283 strcpy(filename, "logo.pcx"); // SHAREWARE
284 if (! cfexist(filename))
285 strcpy(filename, "plogo.pcx"); // MAC SHAREWARE
286 if (cfexist(filename))
287 show_title_screen(filename, 1, 1);
291 { //show bundler movie or screens
293 char filename[FILENAME_LEN];
294 PHYSFS_file *movie_handle;
296 played=MOVIE_NOT_PLAYED; //default is not played
298 //check if OEM movie exists, so we don't stop the music if it doesn't
299 movie_handle = PHYSFS_openRead("oem.mve");
302 PHYSFS_close(movie_handle);
303 played = PlayMovie("oem.mve",0);
304 song_playing = 0; //movie will kill sound
309 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
311 while (PHYSFS_exists(filename))
313 show_title_screen( filename, 1, 0 );
320 songs_play_song( SONG_TITLE, 1);
323 void show_loading_screen(ubyte *title_pal)
325 //grs_bitmap title_bm;
329 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
330 if (! cfexist(filename))
331 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
332 if (! cfexist(filename))
333 strcpy(filename, "descentd.pcx"); // SHAREWARE
334 if (! cfexist(filename))
335 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
337 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
339 set_screen_mode(SCREEN_MENU);
342 FontHires = FontHiresAvailable && MenuHires;
344 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
345 //vfx_set_palette_sub( title_pal );
347 gr_palette_fade_in( title_pal, 32, 0 );
350 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
354 char bs_name[14]; // filename, eg merc01. Assumes .lbm suffix.
357 short text_ulx, text_uly; // upper left x,y of text window
358 short text_width, text_height; // width and height of text window
361 #define BRIEFING_SECRET_NUM 31 // This must correspond to the first secret level which must come at the end of the list.
362 #define BRIEFING_OFFSET_NUM 4 // This must correspond to the first level screen (ie, past the bald guy briefing screens)
364 #define SHAREWARE_ENDING_LEVEL_NUM 0x7f
365 #define REGISTERED_ENDING_LEVEL_NUM 0x7e
368 #define ENDING_LEVEL_NUM SHAREWARE_ENDING_LEVEL_NUM
370 #define ENDING_LEVEL_NUM REGISTERED_ENDING_LEVEL_NUM
373 #define MAX_BRIEFING_SCREENS 60
375 briefing_screen Briefing_screens[MAX_BRIEFING_SCREENS]=
376 {{"brief03.pcx",0,3,8,8,257,177}}; // default=0!!!
378 briefing_screen D1_Briefing_screens[] = {
379 { "brief01.pcx", 0, 1, 13, 140, 290, 59 },
380 { "brief02.pcx", 0, 2, 27, 34, 257, 177 },
381 { "brief03.pcx", 0, 3, 20, 22, 257, 177 },
382 { "brief02.pcx", 0, 4, 27, 34, 257, 177 },
384 { "moon01.pcx", 1, 5, 10, 10, 300, 170 }, // level 1
385 { "moon01.pcx", 2, 6, 10, 10, 300, 170 }, // level 2
386 { "moon01.pcx", 3, 7, 10, 10, 300, 170 }, // level 3
388 { "venus01.pcx", 4, 8, 15, 15, 300, 200 }, // level 4
389 { "venus01.pcx", 5, 9, 15, 15, 300, 200 }, // level 5
391 { "brief03.pcx", 6, 10, 20, 22, 257, 177 },
392 { "merc01.pcx", 6, 11, 10, 15, 300, 200 }, // level 6
393 { "merc01.pcx", 7, 12, 10, 15, 300, 200 }, // level 7
396 { "brief03.pcx", 8, 13, 20, 22, 257, 177 },
397 { "mars01.pcx", 8, 14, 10, 100, 300, 200 }, // level 8
398 { "mars01.pcx", 9, 15, 10, 100, 300, 200 }, // level 9
399 { "brief03.pcx", 10, 16, 20, 22, 257, 177 },
400 { "mars01.pcx", 10, 17, 10, 100, 300, 200 }, // level 10
402 { "jup01.pcx", 11, 18, 10, 40, 300, 200 }, // level 11
403 { "jup01.pcx", 12, 19, 10, 40, 300, 200 }, // level 12
404 { "brief03.pcx", 13, 20, 20, 22, 257, 177 },
405 { "jup01.pcx", 13, 21, 10, 40, 300, 200 }, // level 13
406 { "jup01.pcx", 14, 22, 10, 40, 300, 200 }, // level 14
408 { "saturn01.pcx", 15, 23, 10, 40, 300, 200 }, // level 15
409 { "brief03.pcx", 16, 24, 20, 22, 257, 177 },
410 { "saturn01.pcx", 16, 25, 10, 40, 300, 200 }, // level 16
411 { "brief03.pcx", 17, 26, 20, 22, 257, 177 },
412 { "saturn01.pcx", 17, 27, 10, 40, 300, 200 }, // level 17
414 { "uranus01.pcx", 18, 28, 100, 100, 300, 200 }, // level 18
415 { "uranus01.pcx", 19, 29, 100, 100, 300, 200 }, // level 19
416 { "uranus01.pcx", 20, 30, 100, 100, 300, 200 }, // level 20
417 { "uranus01.pcx", 21, 31, 100, 100, 300, 200 }, // level 21
419 { "neptun01.pcx", 22, 32, 10, 20, 300, 200 }, // level 22
420 { "neptun01.pcx", 23, 33, 10, 20, 300, 200 }, // level 23
421 { "neptun01.pcx", 24, 34, 10, 20, 300, 200 }, // level 24
423 { "pluto01.pcx", 25, 35, 10, 20, 300, 200 }, // level 25
424 { "pluto01.pcx", 26, 36, 10, 20, 300, 200 }, // level 26
425 { "pluto01.pcx", 27, 37, 10, 20, 300, 200 }, // level 27
427 { "aster01.pcx", -1, 38, 10, 90, 300, 200 }, // secret level -1
428 { "aster01.pcx", -2, 39, 10, 90, 300, 200 }, // secret level -2
429 { "aster01.pcx", -3, 40, 10, 90, 300, 200 }, // secret level -3
432 { "end01.pcx", SHAREWARE_ENDING_LEVEL_NUM, 1, 23, 40, 320, 200 }, // shareware end
434 { "end02.pcx", REGISTERED_ENDING_LEVEL_NUM, 1, 5, 5, 300, 200 }, // registered end
435 { "end01.pcx", REGISTERED_ENDING_LEVEL_NUM, 2, 23, 40, 320, 200 }, // registered end
436 { "end03.pcx", REGISTERED_ENDING_LEVEL_NUM, 3, 5, 5, 300, 200 }, // registered end
441 #define NUM_D1_BRIEFING_SCREENS (sizeof(D1_Briefing_screens)/sizeof(briefing_screen))
443 int Briefing_text_x, Briefing_text_y;
445 void init_char_pos(int x, int y)
449 mprintf ((0,"Setting init x=%d y=%d\n",x,y));
452 grs_canvas *Robot_canv = NULL;
453 vms_angvec Robot_angles;
455 ubyte Bitmap_palette[768];
457 char Bitmap_name[32] = "";
458 #define EXIT_DOOR_MAX 14
459 #define OTHER_THING_MAX 10 // Adam: This is the number of frames in your new animating thing.
460 #define DOOR_DIV_INIT 6
461 sbyte Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
463 //-----------------------------------------------------------------------------
464 void show_bitmap_frame(void)
466 grs_canvas *curcanv_save, *bitmap_canv=0;
468 grs_bitmap *bitmap_ptr;
470 // Only plot every nth frame.
471 if (Door_div_count) {
476 Door_div_count = DOOR_DIV_INIT;
478 if (Bitmap_name[0] != 0) {
482 // Set supertransparency color to black
483 if (!New_pal_254_bash) {
484 New_pal_254_bash = 1;
486 New_pal[254*3+1] = 0;
487 New_pal[254*3+2] = 0;
488 gr_palette_load( New_pal );
491 switch (Animating_bitmap_type) {
493 bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 64, 64);
496 bitmap_canv = gr_create_sub_canvas(grd_curcanv, rescale_x(220), rescale_x(45), 94, 94);
499 // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
501 Int3(); // Impossible, illegal value for Animating_bitmap_type
504 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv;
506 pound_signp = strchr(Bitmap_name, '#');
507 Assert(pound_signp != NULL);
509 dig1 = *(pound_signp+1);
510 dig2 = *(pound_signp+2);
514 num = (dig1-'0')*10 + (dig2-'0');
516 switch (Animating_bitmap_type) {
519 if (num > EXIT_DOOR_MAX) {
522 } else if (num < 0) {
529 if (num > OTHER_THING_MAX)
536 *(pound_signp+1) = (num / 10) + '0';
537 *(pound_signp+2) = (num % 10) + '0';
538 *(pound_signp+3) = 0;
540 *(pound_signp+1) = (num % 10) + '0';
541 *(pound_signp+2) = 0;
546 bi = piggy_find_bitmap(Bitmap_name);
547 bitmap_ptr = &GameBitmaps[bi.index];
551 gr_bitmapm(0, 0, bitmap_ptr);
553 grd_curcanv = curcanv_save;
554 gr_copy_palette(gr_palette, New_pal, sizeof(New_pal));
555 gr_remap_bitmap_good(&bitmap_canv->cv_bitmap, Bitmap_palette, 255, 254);
558 switch (Animating_bitmap_type) {
560 if (num == EXIT_DOOR_MAX) {
563 } else if (num == 0) {
575 //-----------------------------------------------------------------------------
576 void show_briefing_bitmap(grs_bitmap *bmp)
578 grs_canvas *curcanv_save, *bitmap_canv;
580 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
581 curcanv_save = grd_curcanv;
582 gr_set_current_canvas(bitmap_canv);
583 gr_bitmapm(0, 0, bmp);
584 gr_set_current_canvas(curcanv_save);
589 //-----------------------------------------------------------------------------
590 void show_spinning_robot_frame(int robot_num)
592 grs_canvas *curcanv_save;
594 if (robot_num != -1) {
595 Robot_angles.h += 150;
597 curcanv_save = grd_curcanv;
598 grd_curcanv = Robot_canv;
599 Assert(Robot_info[robot_num].model_num != -1);
600 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
601 grd_curcanv = curcanv_save;
602 gr_copy_palette(gr_palette, New_pal, sizeof(New_pal));
603 gr_remap_bitmap_good(&Robot_canv->cv_bitmap, Bitmap_palette, 255, 254);
608 //-----------------------------------------------------------------------------
609 void init_spinning_robot(void) //(int x,int y,int w,int h)
611 //Robot_angles.p += 0;
612 //Robot_angles.b += 0;
613 //Robot_angles.h += 0;
615 int x = rescale_x(138);
616 int y = rescale_y(55);
617 int w = rescale_x(166);
618 int h = rescale_y(138);
620 gr_use_palette_table(DEFAULT_LEVEL_PALETTE);
621 memcpy(Bitmap_palette, gr_palette, sizeof(Bitmap_palette));
623 Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
627 //---------------------------------------------------------------------------
628 // Returns char width.
629 // If show_robot_flag set, then show a frame of the spinning robot.
630 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
634 static fix start_time=0;
636 message[0] = the_char;
639 if (start_time==0 && timer_get_fixed_seconds()<0)
640 start_time=timer_get_fixed_seconds();
642 gr_get_string_size(message, &w, &h, &aw );
644 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
646 // Draw cursor if there is some delay and caller says to draw cursor
647 if (cursor_flag && delay) {
648 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
649 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
654 delay=fixdiv (F1_0,i2f(15));
656 if ((Bitmap_name[0] != 0) && (delay != 0))
659 if (RobotPlaying && (delay != 0))
662 if ((robot_num != -1) && (delay != 0))
663 show_spinning_robot_frame(robot_num);
665 while (timer_get_fixed_seconds() < (start_time + delay)) {
668 if (RobotPlaying && delay != 0)
671 if ((robot_num != -1) && (delay != 0)) {
672 show_spinning_robot_frame(robot_num);
673 delay_until(start_time + delay);
677 start_time = timer_get_fixed_seconds();
680 if (cursor_flag && delay) {
681 gr_set_fontcolor(Erase_color, -1);
682 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
685 // Draw the character
686 gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
687 gr_printf(Briefing_text_x, Briefing_text_y, message );
689 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
690 gr_printf(Briefing_text_x+1, Briefing_text_y, message );
692 if (delay) gr_update();
694 // if (the_char != ' ')
695 // if (!digi_is_sound_playing(SOUND_MARKER_HIT))
696 // digi_play_sample( SOUND_MARKER_HIT, F1_0 );
701 //-----------------------------------------------------------------------------
702 int load_briefing_screen( int screen_num )
707 strcpy (CurBriefScreenName, Briefing_screens[screen_num].bs_name);
709 if ((pcx_error = pcx_read_fullscr(CurBriefScreenName, New_pal)) != PCX_ERROR_NONE)
710 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n", CurBriefScreenName, pcx_errormsg(pcx_error), pcx_error);
715 int load_new_briefing_screen( char *fname )
717 mprintf ((0,"Loading new briefing <%s>\n",fname));
718 strcpy (CurBriefScreenName,fname);
720 if (gr_palette_fade_out( New_pal, 32, 0 ))
723 load_briefing_screen(-1);
725 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
727 if (gr_palette_fade_in( New_pal, 32, 0 ))
729 DoBriefingColorStuff();
736 #define KEY_DELAY_DEFAULT ((F1_0*20)/1000)
738 //-----------------------------------------------------------------------------
739 int get_message_num(char **message)
743 while (**message == ' ')
746 while ((**message >= '0') && (**message <= '9')) {
747 num = 10*num + **message-'0';
751 while (*(*message)++ != 10) // Get and drop eoln
757 //-----------------------------------------------------------------------------
758 void get_message_name(char **message, char *result)
760 while (**message == ' ')
763 while ((**message != ' ') && (**message != 10)) {
764 if (**message != '\n')
765 *result++ = **message;
770 while (*(*message)++ != 10) // Get and drop eoln
776 //-----------------------------------------------------------------------------
777 void flash_cursor(int cursor_flag)
779 if (cursor_flag == 0)
782 if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
783 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
785 gr_set_fontcolor(Erase_color, -1);
787 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
791 extern int InitMovieBriefing();
794 //-----------------------------------------------------------------------------
795 // Return true if message got aborted by user (pressed ESC), else return false.
796 int show_briefing_message(int screen_num, char *message)
800 briefing_screen *bsp;
801 int delay_count = KEY_DELAY_DEFAULT;
805 static int tab_stop=0;
806 int flashing_cursor=0;
807 int new_page=0,GotZ=0;
808 char spinRobotName[]="rba.mve",kludge; // matt don't change this!
812 int hum_channel=-1,printing_channel=-1;
813 int LineAdjustment=1;
822 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
825 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
826 gr_set_curfont( GAME_FONT );
830 MALLOC(bsp, briefing_screen, 1);
831 memcpy(bsp, &Briefing_screens[screen_num], sizeof(briefing_screen));
832 bsp->text_ulx = rescale_x(bsp->text_ulx);
833 bsp->text_uly = rescale_y(bsp->text_uly);
834 bsp->text_width = rescale_x(bsp->text_width);
835 bsp->text_height = rescale_y(bsp->text_height);
836 init_char_pos(bsp->text_ulx, bsp->text_uly);
838 bsp=&Briefing_screens[0];
839 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
847 screen_num=DefineBriefingBox (&message);
848 //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
850 bsp = &Briefing_screens[screen_num];
851 init_char_pos(bsp->text_ulx, bsp->text_uly);
853 prev_ch = 10; // read to eoln
854 } else if (ch=='U') {
855 screen_num=get_message_num(&message);
856 bsp = &Briefing_screens[screen_num];
857 init_char_pos(bsp->text_ulx, bsp->text_uly);
858 prev_ch = 10; // read to eoln
859 } else if (ch == 'C') {
860 Current_color = get_message_num(&message)-1;
861 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
863 } else if (ch == 'F') { // toggle flashing cursor
864 flashing_cursor = !flashing_cursor;
866 while (*message++ != 10)
868 } else if (ch == 'T') {
869 tab_stop = get_message_num(&message);
870 tab_stop*=(1+MenuHires);
871 prev_ch = 10; // read to eoln
872 } else if (ch == 'R') {
873 if (Robot_canv != NULL) {
883 init_spinning_robot();
884 robot_num = get_message_num(&message);
885 while (*message++ != 10)
889 spinRobotName[2]=kludge; // ugly but proud
891 RobotPlaying=InitRobotMovie(spinRobotName);
893 // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
897 DoBriefingColorStuff ();
898 mprintf ((0,"Robot playing is %d!!!\n",RobotPlaying));
901 prev_ch = 10; // read to eoln
902 } else if (ch == 'N') {
903 //--grs_bitmap *bitmap_ptr;
904 if (Robot_canv != NULL) {
909 get_message_name(&message, Bitmap_name);
910 strcat(Bitmap_name, "#0");
911 Animating_bitmap_type = 0;
913 } else if (ch == 'O') {
914 if (Robot_canv != NULL) {
919 get_message_name(&message, Bitmap_name);
920 strcat(Bitmap_name, "#0");
921 Animating_bitmap_type = 1;
923 } else if (ch=='A') {
924 LineAdjustment=1-LineAdjustment;
925 } else if (ch=='Z') {
926 //mprintf ((0,"Got a Z!\n"));
928 #if 1 //defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
931 if (LineAdjustment==1)
938 while ((fname[i]=*message) != '\n') {
944 while (*message++ != 10) // Get and drop eoln
951 while (fname[i]!='.') {
952 fname2[i] = fname[i];
962 if ((MenuHires && cfexist(fname2)) || !cfexist(fname))
963 load_new_briefing_screen (fname2);
965 load_new_briefing_screen (fname);
968 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
970 } else if (ch == 'B') {
971 char bitmap_name[32];
972 grs_bitmap guy_bitmap;
973 ubyte temp_palette[768];
976 if (Robot_canv != NULL) {
981 get_message_name(&message, bitmap_name);
982 strcat(bitmap_name, ".bbm");
983 guy_bitmap.bm_data = NULL;
984 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
985 Assert(iff_error == IFF_NO_ERROR);
986 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
988 show_briefing_bitmap(&guy_bitmap);
989 d_free(guy_bitmap.bm_data);
991 // } else if (ch==EOF) {
993 // } else if (ch == 'B') {
994 // if (Robot_canv != NULL) {
995 // d_free(Robot_canv);
999 // bitmap_num = get_message_num(&message);
1000 // if (bitmap_num != -1)
1001 // show_briefing_bitmap(Textures[bitmap_num]);
1002 // prev_ch = 10; // read to eoln
1003 } else if (ch == 'S') {
1008 if (printing_channel>-1)
1009 digi_stop_sound( printing_channel );
1010 printing_channel=-1;
1014 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1015 start_time = timer_get_fixed_seconds();
1017 flash_cursor(flashing_cursor);
1021 if (robot_num != -1)
1022 show_spinning_robot_frame(robot_num);
1024 if (Bitmap_name[0] != 0)
1025 show_bitmap_frame();
1027 delay_until(start_time + KEY_DELAY_DEFAULT/2);
1031 if (keypress == KEY_BACKSP)
1034 if (keypress == KEY_ESC)
1037 flashing_cursor = 0;
1039 } else if (ch == 'P') { // New page.
1041 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1042 // printing to it! You know, $Z !!!
1043 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1047 while (*message != 10) {
1048 message++; // drop carriage return after special escape sequence
1054 } else if (ch == '\t') { // Tab
1055 if (Briefing_text_x - bsp->text_ulx < tab_stop)
1056 Briefing_text_x = bsp->text_ulx + tab_stop;
1057 } else if ((ch == ';') && (prev_ch == 10)) {
1058 while (*message++ != 10)
1061 } else if (ch == '\\') {
1063 } else if (ch == 10) {
1064 if (prev_ch != '\\') {
1067 Briefing_text_y += (8*(MenuHires+1));
1070 Briefing_text_x = bsp->text_ulx;
1071 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
1072 load_briefing_screen(screen_num);
1073 Briefing_text_x = bsp->text_ulx;
1074 Briefing_text_y = bsp->text_uly;
1077 if (ch == 13) //Can this happen? Above says ch==10
1084 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1085 // printing to it! You know, $Z !!!
1086 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1092 printing_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
1096 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
1100 // Check for Esc -> abort.
1102 key_check=local_key_inkey();
1107 if (_RedrawScreen) {
1108 _RedrawScreen = FALSE;
1109 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1110 key_check = KEY_ESC;
1113 if ( key_check == KEY_ESC ) {
1118 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
1121 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1122 if ((key_check == KEY_ALTED+KEY_ENTER) ||
1123 (key_check == KEY_ALTED+KEY_PADENTER))
1124 gr_toggle_fullscreen();
1127 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
1128 Briefing_text_x = bsp->text_ulx;
1129 Briefing_text_y += bsp->text_uly;
1132 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
1138 if (printing_channel>-1)
1139 digi_stop_sound( printing_channel );
1140 printing_channel=-1;
1144 start_time = timer_get_fixed_seconds();
1145 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1147 flash_cursor(flashing_cursor);
1150 if (robot_num != -1)
1151 show_spinning_robot_frame(robot_num);
1152 if (Bitmap_name[0] != 0)
1153 show_bitmap_frame();
1154 start_time += KEY_DELAY_DEFAULT/2;
1155 delay_until(start_time + KEY_DELAY_DEFAULT/2);
1164 if (keypress == KEY_BACKSP)
1167 if (keypress == KEY_ESC) {
1172 load_briefing_screen(screen_num);
1173 Briefing_text_x = bsp->text_ulx;
1174 Briefing_text_y = bsp->text_uly;
1175 delay_count = KEY_DELAY_DEFAULT;
1184 if (Robot_canv != NULL)
1185 {d_free(Robot_canv); Robot_canv=NULL;}
1188 digi_stop_sound( hum_channel );
1189 if (printing_channel>-1)
1190 digi_stop_sound( printing_channel );
1198 //-----------------------------------------------------------------------------
1199 // Return a pointer to the start of text for screen #screen_num.
1200 char * get_briefing_message(int screen_num)
1202 char *tptr = Briefing_text;
1206 Assert(screen_num >= 0);
1208 while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1213 cur_screen = get_message_num(&tptr);
1217 if (screen_num!=cur_screen)
1223 //-----------------------------------------------------------------------------
1224 // Load Descent briefing text.
1225 int load_screen_text(char *filename, char **buf)
1230 int have_binary = 0;
1232 if ((tfile = cfopen(filename,"rb")) == NULL) {
1233 char nfilename[30], *ptr;
1235 strcpy(nfilename, filename);
1236 if ((ptr = strrchr(nfilename, '.')))
1238 strcat(nfilename, ".txb");
1239 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1240 mprintf ((0,"can't open %s!\n",nfilename));
1242 //Error("Cannot open file %s or %s", filename, nfilename);
1245 mprintf ((0,"reading...\n"));
1248 len = cfilelength(ifile);
1249 MALLOC(*buf, char, len+500);
1250 mprintf ((0,"len=%d\n",len));
1251 for (x=0, i=0; i < len; i++, x++) {
1252 cfread (*buf+x,1,1,ifile);
1253 // mprintf ((0,"%c",*(*buf+x)));
1260 len = cfilelength(tfile);
1261 MALLOC(*buf, char, len+500);
1262 for (x=0, i=0; i < len; i++, x++) {
1263 cfread (*buf+x,1,1,tfile);
1264 // mprintf ((0,"%c",*(*buf+x)));
1270 //cfread(*buf, 1, len, tfile);
1275 decode_text(*buf, len);
1280 //-----------------------------------------------------------------------------
1281 // Return true if message got aborted, else return false.
1282 int show_briefing_text(int screen_num)
1286 message_ptr = get_briefing_message
1287 (EMULATING_D1 ? Briefing_screens[screen_num].message_num : screen_num);
1289 if (message_ptr==NULL)
1292 DoBriefingColorStuff();
1294 return show_briefing_message(screen_num, message_ptr);
1297 void DoBriefingColorStuff ()
1299 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1300 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1302 Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1303 Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1305 Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1306 Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1310 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 54, 0);
1311 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 19, 0);
1313 Briefing_foreground_colors[1] = gr_find_closest_color_current( 42, 38, 32);
1314 Briefing_background_colors[1] = gr_find_closest_color_current( 14, 14, 14);
1316 //Begin D1X addition
1318 Briefing_foreground_colors[2] = gr_find_closest_color_current( 63, 0, 0);
1319 Briefing_background_colors[2] = gr_find_closest_color_current( 31, 0, 0);
1322 Briefing_foreground_colors[3] = gr_find_closest_color_current( 0, 0, 54);
1323 Briefing_background_colors[3] = gr_find_closest_color_current( 0, 0, 19);
1325 Briefing_foreground_colors[4] = gr_find_closest_color_current( 14, 14, 14);
1326 Briefing_background_colors[4] = gr_find_closest_color_current( 0, 0, 0);
1328 Briefing_foreground_colors[5] = gr_find_closest_color_current( 54, 54, 0);
1329 Briefing_background_colors[5] = gr_find_closest_color_current( 19, 19, 0);
1331 Briefing_foreground_colors[6] = gr_find_closest_color_current( 0, 54, 54);
1332 Briefing_background_colors[6] = gr_find_closest_color_current( 0, 19, 19);
1335 Erase_color = gr_find_closest_color_current(0, 0, 0);
1338 //-----------------------------------------------------------------------------
1339 // Return true if screen got aborted by user, else return false.
1340 int show_briefing_screen( int screen_num, int allow_keys)
1343 //ubyte palette_save[768];
1345 New_pal_254_bash = 0;
1347 if (Skip_briefing_screens) {
1348 mprintf((0, "Skipping briefing screen [%s]\n", &Briefing_screens[screen_num].bs_name));
1353 load_briefing_screen(screen_num);
1357 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1362 key_close(); // kill the keyboard handler during briefing screens for movies
1364 rval = show_briefing_text(screen_num);
1369 #if defined (MACINTOSH) || defined(WINDOWS)
1370 memcpy(New_pal,gr_palette,sizeof(gr_palette)); // attempt to get fades after briefing screens done correctly.
1374 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1377 //gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1379 //d_free(briefing_bm.bm_data);
1385 //-----------------------------------------------------------------------------
1386 void do_briefing_screens(char *filename,int level_num)
1388 int abort_briefing_screens = 0;
1389 int cur_briefing_screen = 0;
1391 if (Skip_briefing_screens) {
1392 mprintf((0, "Skipping all briefing screens.\n"));
1397 return; // no briefing screens at all for demo
1401 mprintf ((0,"Trying briefing screen <%s>\n",filename));
1403 if (!filename || !*filename)
1406 if (!load_screen_text(filename, &Briefing_text))
1410 songs_play_song( SONG_BRIEFING, 1 );
1415 set_screen_mode( SCREEN_MENU );
1417 gr_set_current_canvas(NULL);
1419 mprintf ((0,"Playing briefing screen <%s>, level %d\n",filename,level_num));
1426 for (i = 0; i < NUM_D1_BRIEFING_SCREENS; i++)
1427 memcpy(&Briefing_screens[i], &D1_Briefing_screens[i], sizeof(briefing_screen));
1429 if (level_num == 1) {
1430 while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1431 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1432 cur_briefing_screen++;
1436 if (!abort_briefing_screens) {
1437 for (cur_briefing_screen = 0; cur_briefing_screen < NUM_D1_BRIEFING_SCREENS; cur_briefing_screen++)
1438 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1439 if (show_briefing_screen(cur_briefing_screen, 0))
1444 show_briefing_screen(level_num,0);
1446 d_free (Briefing_text);
1453 int DefineBriefingBox (char **buf)
1458 n=get_new_message_num (buf);
1460 Assert(n < MAX_BRIEFING_SCREENS);
1462 while (**buf!=' ') {
1467 name[i]='\0'; // slap a delimiter on this guy
1469 strcpy (Briefing_screens[n].bs_name,name);
1470 Briefing_screens[n].level_num=get_new_message_num (buf);
1471 Briefing_screens[n].message_num=get_new_message_num (buf);
1472 Briefing_screens[n].text_ulx=get_new_message_num (buf);
1473 Briefing_screens[n].text_uly=get_new_message_num (buf);
1474 Briefing_screens[n].text_width=get_new_message_num (buf);
1475 Briefing_screens[n].text_height=get_message_num (buf); // NOTICE!!!
1477 Briefing_screens[n].text_ulx = rescale_x(Briefing_screens[n].text_ulx);
1478 Briefing_screens[n].text_uly = rescale_y(Briefing_screens[n].text_uly);
1479 Briefing_screens[n].text_width = rescale_x(Briefing_screens[n].text_width);
1480 Briefing_screens[n].text_height = rescale_y(Briefing_screens[n].text_height);
1485 int get_new_message_num(char **message)
1489 while (**message == ' ')
1492 while ((**message >= '0') && (**message <= '9')) {
1493 num = 10*num + **message-'0';
1502 void show_order_form()
1507 unsigned char title_pal[768];
1508 char exit_screen[16];
1510 gr_set_current_canvas( NULL );
1515 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1516 if (! cfexist(exit_screen))
1517 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1518 if (! cfexist(exit_screen))
1519 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1520 if (! cfexist(exit_screen))
1521 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1522 if (! cfexist(exit_screen))
1523 return; // D2 registered
1525 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1526 //vfx_set_palette_sub( title_pal );
1527 gr_palette_fade_in( title_pal, 32, 0 );
1529 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1530 gr_palette_fade_out( title_pal, 32, 0 );
1533 Int3(); //can't load order screen