1 /* $Id: titles.c,v 1.18 2003-02-18 07:05:14 btb 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.
33 #include "pa_enabl.h" //$$POLY_ACC
70 extern void RotateRobot();
73 void DoBriefingColorStuff ();
74 int get_new_message_num(char **message);
75 int DefineBriefingBox (char **buf);
77 extern unsigned RobSX,RobSY,RobDX,RobDY; // Robot movie coords
82 char CurBriefScreenName[15]="brief03.pcx";
88 #define MAX_BRIEFING_COLORS 3
90 // Descent 1 briefings
91 char Ending_text_filename[13] = "\0";
92 char Briefing_text_filename[13] = "\0";
94 #define SHAREWARE_ENDING_FILENAME "ending.tex"
96 // Can be set by -noscreens command line option. Causes bypassing of all briefing screens.
97 int Skip_briefing_screens=0;
98 int Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
99 int Current_color = 0;
102 extern int check_button_press();
105 extern void macintosh_quit(void);
108 static int rescale_x(int x)
110 return x * GWIDTH / 320;
113 static int rescale_y(int y)
115 return y * GHEIGHT / 200;
119 int local_key_inkey(void)
126 DoMessageStuff(&msg);
131 if (rval == KEY_PRINT_SCREEN) {
135 gr_palette_read(gr_palette);
136 gr_copy_palette(gr_palette,gr_palette,0); //reset color lookup cache
141 return 0; //say no key pressed
144 if (check_button_press()) //joystick or mouse button pressed?
148 if ( rval == KEY_Q+KEY_COMMAND )
155 int local_key_inkey(void)
160 if (!GetOSEvent(everyEvent, &event))
163 if (event.what != keyDown)
166 rval = (int)((event.message & keyCodeMask) >> 8);
168 if (rval == KEY_PRINT_SCREEN) {
170 return 0; //say no key pressed
173 if (check_button_press()) //joystick or mouse button pressed?
177 if ( rval == KEY_Q+KEY_COMMAND )
185 int show_title_screen( char * filename, int allow_keys, int from_hog_only )
190 ubyte palette_save[768];
191 char new_filename[FILENAME_LEN+1] = "";
195 strcpy(new_filename,"\x01"); //only read from hog file
198 strcat(new_filename,filename);
199 filename = new_filename;
201 title_bm.bm_data=NULL;
202 if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
203 printf( "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
204 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));
205 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error);
208 memcpy(palette_save,gr_palette,sizeof(palette_save));
210 #if defined(POLY_ACC)
212 pa_update_clut(New_pal, 0, 256, 0);
215 //vfx_set_palette_sub( New_pal );
217 gr_palette_load( New_pal );
223 dd_gr_set_current_canvas(NULL),
224 gr_set_current_canvas( NULL )
226 WIN(DDGRLOCK(dd_grd_curcanv));
227 show_fullscr(&title_bm);
228 WIN(DDGRUNLOCK(dd_grd_curcanv));
232 #if defined(POLY_ACC)
236 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
238 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
240 gr_palette_load( New_pal );
241 timer = timer_get_fixed_seconds() + i2f(3);
243 if ( local_key_inkey() && allow_keys ) break;
244 if ( timer_get_fixed_seconds() > timer ) break;
246 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
248 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
249 d_free(title_bm.bm_data);
254 char bs_name[14]; // filename, eg merc01. Assumes .lbm suffix.
257 short text_ulx, text_uly; // upper left x,y of text window
258 short text_width, text_height; // width and height of text window
261 #define BRIEFING_SECRET_NUM 31 // This must correspond to the first secret level which must come at the end of the list.
262 #define BRIEFING_OFFSET_NUM 4 // This must correspond to the first level screen (ie, past the bald guy briefing screens)
264 #define SHAREWARE_ENDING_LEVEL_NUM 0x7f
265 #define REGISTERED_ENDING_LEVEL_NUM 0x7e
268 #define ENDING_LEVEL_NUM SHAREWARE_ENDING_LEVEL_NUM
270 #define ENDING_LEVEL_NUM REGISTERED_ENDING_LEVEL_NUM
273 #define MAX_BRIEFING_SCREENS 60
275 briefing_screen Briefing_screens[MAX_BRIEFING_SCREENS]=
276 {{"brief03.pcx",0,3,8,8,257,177}}; // default=0!!!
278 int Briefing_text_x, Briefing_text_y;
280 void init_char_pos(int x, int y)
284 mprintf ((0,"Setting init x=%d y=%d\n",x,y));
287 grs_canvas *Robot_canv = NULL;
288 vms_angvec Robot_angles;
290 char Bitmap_name[32] = "";
291 #define EXIT_DOOR_MAX 14
292 #define OTHER_THING_MAX 10 // Adam: This is the number of frames in your new animating thing.
293 #define DOOR_DIV_INIT 6
294 byte Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
296 //-----------------------------------------------------------------------------
297 void show_bitmap_frame(void)
300 dd_grs_canvas *curcanv_save, *bitmap_canv=0;
302 grs_canvas *curcanv_save, *bitmap_canv=0;
305 grs_bitmap *bitmap_ptr;
307 // Only plot every nth frame.
308 if (Door_div_count) {
313 Door_div_count = DOOR_DIV_INIT;
315 if (Bitmap_name[0] != 0) {
319 // Set supertransparency color to black
320 if (!New_pal_254_bash) {
321 New_pal_254_bash = 1;
323 New_pal[254*3+1] = 0;
324 New_pal[254*3+2] = 0;
325 gr_palette_load( New_pal );
328 switch (Animating_bitmap_type) {
331 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 64, 64); break,
332 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 64, 64); break
336 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 94, 94); break,
337 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 94, 94); break
340 // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
342 Int3(); // Impossible, illegal value for Animating_bitmap_type
346 curcanv_save = dd_grd_curcanv; dd_grd_curcanv = bitmap_canv,
347 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv
350 pound_signp = strchr(Bitmap_name, '#');
351 Assert(pound_signp != NULL);
353 dig1 = *(pound_signp+1);
354 dig2 = *(pound_signp+2);
358 num = (dig1-'0')*10 + (dig2-'0');
360 switch (Animating_bitmap_type) {
363 if (num > EXIT_DOOR_MAX) {
366 } else if (num < 0) {
373 if (num > OTHER_THING_MAX)
380 *(pound_signp+1) = (num / 10) + '0';
381 *(pound_signp+2) = (num % 10) + '0';
382 *(pound_signp+3) = 0;
384 *(pound_signp+1) = (num % 10) + '0';
385 *(pound_signp+2) = 0;
390 bi = piggy_find_bitmap(Bitmap_name);
391 bitmap_ptr = &GameBitmaps[bi.index];
395 WIN(DDGRLOCK(dd_grd_curcanv));
396 gr_bitmapm(0, 0, bitmap_ptr);
397 WIN(DDGRUNLOCK(dd_grd_curcanv));
400 dd_grd_curcanv = curcanv_save,
401 grd_curcanv = curcanv_save
405 switch (Animating_bitmap_type) {
407 if (num == EXIT_DOOR_MAX) {
410 } else if (num == 0) {
422 //-----------------------------------------------------------------------------
423 void show_briefing_bitmap(grs_bitmap *bmp)
426 dd_grs_canvas *bitmap_canv, *curcanv_save;
428 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
429 curcanv_save = dd_grd_curcanv;
430 dd_gr_set_current_canvas(bitmap_canv);
431 DDGRLOCK(dd_grd_curcanv);
433 DDGRUNLOCK(dd_grd_curcanv);
434 dd_gr_set_current_canvas(curcanv_save);
436 grs_canvas *curcanv_save, *bitmap_canv;
438 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
439 curcanv_save = grd_curcanv;
440 gr_set_current_canvas(bitmap_canv);
441 gr_bitmapm(0, 0, bmp);
442 gr_set_current_canvas(curcanv_save);
449 //-----------------------------------------------------------------------------
450 void show_spinning_robot_frame(int robot_num)
452 grs_canvas *curcanv_save;
454 if (robot_num != -1) {
455 Robot_angles.h += 150;
457 curcanv_save = grd_curcanv;
458 grd_curcanv = Robot_canv;
459 Assert(Robot_info[robot_num].model_num != -1);
460 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
461 grd_curcanv = curcanv_save;
466 //-----------------------------------------------------------------------------
467 void init_spinning_robot(void) //(int x,int y,int w,int h)
475 int x = rescale_x(138);
476 int y = rescale_y(55);
477 int w = rescale_x(166);
478 int h = rescale_y(138);
481 Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
486 //---------------------------------------------------------------------------
487 // Returns char width.
488 // If show_robot_flag set, then show a frame of the spinning robot.
489 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
493 static fix start_time=0;
496 message[0] = the_char;
499 if (start_time==0 && timer_get_fixed_seconds()<0)
500 start_time=timer_get_fixed_seconds();
502 gr_get_string_size(message, &w, &h, &aw );
504 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
506 // Draw cursor if there is some delay and caller says to draw cursor
507 if (cursor_flag && delay) {
508 WIN(DDGRLOCK(dd_grd_curcanv));
509 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
510 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
511 WIN(DDGRUNLOCK(dd_grd_curcanv));
515 delay=fixdiv (F1_0,i2f(15));
521 if (RobotPlaying && (delay != 0))
524 while (timer_get_fixed_seconds() < (start_time + delay)) {
525 if (RobotPlaying && delay != 0)
530 show_spinning_robot_frame(robot_num);
533 start_time = timer_get_fixed_seconds();
535 WIN(DDGRLOCK(dd_grd_curcanv));
537 if (cursor_flag && delay) {
538 gr_set_fontcolor(Erase_color, -1);
539 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
542 // Draw the character
543 gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
544 gr_printf(Briefing_text_x, Briefing_text_y, message );
546 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
547 gr_printf(Briefing_text_x+1, Briefing_text_y, message );
548 WIN(DDGRUNLOCK(dd_grd_curcanv));
550 if (delay) gr_update();
552 // if (the_char != ' ')
553 // if (!digi_is_sound_playing(SOUND_MARKER_HIT))
554 // digi_play_sample( SOUND_MARKER_HIT, F1_0 );
559 //-----------------------------------------------------------------------------
560 int load_briefing_screen( int screen_num )
564 WIN(DDGRLOCK(dd_grd_curcanv));
565 if ((pcx_error=pcx_read_fullscr( CurBriefScreenName, New_pal ))!=PCX_ERROR_NONE) {
566 printf( "File '%s', PCX load error: %s\n (It's a briefing screen. Does this cause you pain?)\n",Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error));
567 printf( "File '%s', PCX load error: %s (%i)\n (It's a briefing screen. Does this cause you pain?)\n",Briefing_screens[screen_num].bs_name, pcx_errormsg(pcx_error), pcx_error);
568 WIN(DDGRUNLOCK(dd_grd_curcanv));
569 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",CurBriefScreenName, pcx_errormsg(pcx_error), pcx_error);
571 WIN(DDGRUNLOCK(dd_grd_curcanv));
578 int load_new_briefing_screen( char *fname )
582 mprintf ((0,"Loading new briefing <%s>\n",fname));
583 strcpy (CurBriefScreenName,fname);
585 //WIN(DEFINE_SCREEN(CurBriefScreenName));
587 if (gr_palette_fade_out( New_pal, 32, 0 ))
590 WIN(DDGRLOCK(dd_grd_curcanv));
591 if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE) {
592 //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE) {
593 printf( "File '%s', PCX load error: %s (%i)\n (It's a briefing screen. Does this cause you pain?)\n",fname, pcx_errormsg(pcx_error), pcx_error);
594 WIN(DDGRUNLOCK(dd_grd_curcanv));
595 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
597 WIN(DDGRUNLOCK(dd_grd_curcanv));
601 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
603 if (gr_palette_fade_in( New_pal, 32, 0 ))
605 DoBriefingColorStuff();
612 #define KEY_DELAY_DEFAULT ((F1_0*20)/1000)
614 //-----------------------------------------------------------------------------
615 int get_message_num(char **message)
619 while (**message == ' ')
622 while ((**message >= '0') && (**message <= '9')) {
623 num = 10*num + **message-'0';
627 while (*(*message)++ != 10) // Get and drop eoln
633 //-----------------------------------------------------------------------------
634 void get_message_name(char **message, char *result)
636 while (**message == ' ')
639 while ((**message != ' ') && (**message != 10)) {
640 if (**message != '\n')
641 *result++ = **message;
646 while (*(*message)++ != 10) // Get and drop eoln
652 //-----------------------------------------------------------------------------
653 void flash_cursor(int cursor_flag)
655 if (cursor_flag == 0)
658 WIN(DDGRLOCK(dd_grd_curcanv));
659 if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
660 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
662 gr_set_fontcolor(Erase_color, -1);
664 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
665 WIN(DDGRUNLOCK(dd_grd_curcanv));
668 extern int InitMovieBriefing();
670 //-----------------------------------------------------------------------------
671 // Return true if message got aborted by user (pressed ESC), else return false.
672 int show_d1_briefing_message(int screen_num, char *message)
676 briefing_screen *bsp = &Briefing_screens[screen_num];
677 int delay_count = KEY_DELAY_DEFAULT;
682 int flashing_cursor=0;
684 int text_ulx = rescale_x(bsp->text_ulx);
685 int text_uly = rescale_y(bsp->text_uly);
691 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
692 gr_set_curfont( GAME_FONT );
694 init_char_pos(text_ulx, text_uly);
701 Current_color = get_message_num(&message)-1;
702 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
704 } else if (ch == 'F') { // toggle flashing cursor
705 flashing_cursor = !flashing_cursor;
707 while (*message++ != 10)
709 } else if (ch == 'T') {
710 tab_stop = get_message_num(&message);
711 prev_ch = 10; // read to eoln
712 } else if (ch == 'R') {
713 if (Robot_canv != NULL)
714 {free(Robot_canv); Robot_canv=NULL;}
716 init_spinning_robot();
717 robot_num = get_message_num(&message);
718 prev_ch = 10; // read to eoln
719 } else if (ch == 'N') {
720 //--grs_bitmap *bitmap_ptr;
721 if (Robot_canv != NULL)
722 {free(Robot_canv); Robot_canv=NULL;}
724 get_message_name(&message, Bitmap_name);
725 strcat(Bitmap_name, "#0");
726 Animating_bitmap_type = 0;
728 } else if (ch == 'O') {
729 if (Robot_canv != NULL)
730 {free(Robot_canv); Robot_canv=NULL;}
732 get_message_name(&message, Bitmap_name);
733 strcat(Bitmap_name, "#0");
734 Animating_bitmap_type = 1;
736 } else if (ch == 'B') {
737 char bitmap_name[32];
738 grs_bitmap guy_bitmap;
739 ubyte temp_palette[768];
742 if (Robot_canv != NULL)
743 {free(Robot_canv); Robot_canv=NULL;}
745 get_message_name(&message, bitmap_name);
746 strcat(bitmap_name, ".bbm");
747 gr_init_bitmap_data (&guy_bitmap);
748 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
749 Assert(iff_error == IFF_NO_ERROR);
751 show_briefing_bitmap(&guy_bitmap);
752 gr_free_bitmap_data (&guy_bitmap);
754 // } else if (ch == 'B') {
755 // if (Robot_canv != NULL)
756 // {free(Robot_canv); Robot_canv=NULL;}
758 // bitmap_num = get_message_num(&message);
759 // if (bitmap_num != -1)
760 // show_briefing_bitmap(Textures[bitmap_num]);
761 // prev_ch = 10; // read to eoln
762 } else if (ch == 'S') {
767 start_time = timer_get_fixed_seconds();
768 start_time = timer_get_approx_seconds();
769 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
771 //added on 9/13/98 by adb to make arch's requiring updates work
775 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
776 if ( timer_get_approx_seconds() > time_out_value ) {
778 break; // Time out after 1 minute..
780 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
782 flash_cursor(flashing_cursor);
783 show_spinning_robot_frame(robot_num);
786 //added on 9/13/98 by adb to make arch's requiring updates work
790 start_time += KEY_DELAY_DEFAULT/2;
794 if (keypress == KEY_BACKSP)
797 if (keypress == KEY_ESC)
802 } else if (ch == 'P') { // New page.
804 while (*message != 10) {
805 message++; // drop carriage return after special escape sequence
810 } else if (ch == '$' || ch == ';') { // Print a $/;
812 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
816 } else if (ch == '\t') { // Tab
817 if (Briefing_text_x - text_ulx < tab_stop)
818 Briefing_text_x = text_ulx + tab_stop;
819 } else if ((ch == ';') && (prev_ch == 10)) {
820 while (*message++ != 10)
823 } else if (ch == '\\') {
825 } else if (ch == 10) {
826 if (prev_ch != '\\') {
828 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
829 Briefing_text_x = text_ulx;
830 if (Briefing_text_y > text_uly + rescale_y(bsp->text_height)) {
831 load_briefing_screen(screen_num);
832 Briefing_text_x = text_ulx;
833 Briefing_text_y = text_uly;
842 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
845 //added/changed on 9/13/98 by adb to speed up briefings after pressing a key with SDL
846 // Check for Esc -> abort.
848 key_check=local_key_inkey();
852 if ( key_check == KEY_ESC ) {
858 if ( key_check == KEY_ALTED+KEY_F2 )
862 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
865 if (Briefing_text_x > text_ulx + rescale_x(bsp->text_width)) {
866 Briefing_text_x = text_ulx;
867 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
870 if ((new_page) || (Briefing_text_y > text_uly + rescale_y(bsp->text_height))) {
872 fix time_out_value = 0;
876 start_time = timer_get_approx_seconds();
877 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
879 //added on 9/13/98 by adb to make arch's requiring updates work
883 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
884 if ( timer_get_approx_seconds() > time_out_value ) {
886 break; // Time out after 1 minute..
888 while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
890 flash_cursor(flashing_cursor);
891 show_spinning_robot_frame(robot_num);
894 //added on 9/13/98 by adb to make arch's requiring updates work
898 start_time += KEY_DELAY_DEFAULT/2;
904 if (keypress == KEY_BACKSP)
907 if (keypress == KEY_ESC) {
912 load_briefing_screen(screen_num);
913 Briefing_text_x = text_ulx;
914 Briefing_text_y = text_uly;
915 delay_count = KEY_DELAY_DEFAULT;
919 if (Robot_canv != NULL)
920 {free(Robot_canv); Robot_canv=NULL;}
925 //-----------------------------------------------------------------------------
926 // Return true if message got aborted by user (pressed ESC), else return false.
927 int show_briefing_message(int screen_num, char *message)
931 briefing_screen *bsp = &Briefing_screens[screen_num];
932 int delay_count = KEY_DELAY_DEFAULT;
936 static int tab_stop=0;
937 int flashing_cursor=0;
938 int new_page=0,GotZ=0;
940 char spinRobotName[]="rba.mve",kludge; // matt don't change this!
945 int hum_channel=-1,printing_channel=-1;
946 int LineAdjustment=1;
947 WIN(int wpage_done=0);
958 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
961 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
962 gr_set_curfont( GAME_FONT );
964 bsp=&Briefing_screens[0];
965 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
972 screen_num=DefineBriefingBox (&message);
973 //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
975 bsp = &Briefing_screens[screen_num];
976 init_char_pos(bsp->text_ulx, bsp->text_uly);
978 prev_ch = 10; // read to eoln
979 } else if (ch=='U') {
980 screen_num=get_message_num(&message);
981 bsp = &Briefing_screens[screen_num];
982 init_char_pos(bsp->text_ulx, bsp->text_uly);
983 prev_ch = 10; // read to eoln
984 } else if (ch == 'C') {
985 Current_color = get_message_num(&message)-1;
986 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
988 } else if (ch == 'F') { // toggle flashing cursor
989 flashing_cursor = !flashing_cursor;
991 while (*message++ != 10)
993 } else if (ch == 'T') {
994 tab_stop = get_message_num(&message);
995 tab_stop*=(1+MenuHires);
996 prev_ch = 10; // read to eoln
997 } else if (ch == 'R') {
998 if (Robot_canv != NULL) {
1009 spinRobotName[2]=kludge; // ugly but proud
1011 RobotPlaying=InitRobotMovie(spinRobotName);
1013 // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
1016 DoBriefingColorStuff ();
1017 mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
1020 init_spinning_robot();
1021 robot_num = get_message_num(&message);
1023 prev_ch = 10; // read to eoln
1024 } else if (ch == 'N') {
1025 //--grs_bitmap *bitmap_ptr;
1026 if (Robot_canv != NULL) {
1031 get_message_name(&message, Bitmap_name);
1032 strcat(Bitmap_name, "#0");
1033 Animating_bitmap_type = 0;
1035 } else if (ch == 'O') {
1036 if (Robot_canv != NULL) {
1041 get_message_name(&message, Bitmap_name);
1042 strcat(Bitmap_name, "#0");
1043 Animating_bitmap_type = 1;
1045 } else if (ch=='A') {
1046 LineAdjustment=1-LineAdjustment;
1047 } else if (ch=='Z') {
1048 //mprintf ((0,"Got a Z!\n"));
1050 #if defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
1053 if (LineAdjustment==1)
1060 while ((fname[i]=*message) != '\n') {
1070 while (fname[i]!='.') {
1071 fname2[i] = fname[i];
1083 if ((MenuHires && cfexist(fname2)) || !cfexist(fname))
1084 load_new_briefing_screen (fname2);
1086 load_new_briefing_screen (fname);
1089 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1091 } else if (ch == 'B') {
1092 char bitmap_name[32];
1093 grs_bitmap guy_bitmap;
1094 ubyte temp_palette[768];
1097 if (Robot_canv != NULL) {
1102 get_message_name(&message, bitmap_name);
1103 strcat(bitmap_name, ".bbm");
1104 guy_bitmap.bm_data = NULL;
1105 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
1106 Assert(iff_error == IFF_NO_ERROR);
1107 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
1109 show_briefing_bitmap(&guy_bitmap);
1110 d_free(guy_bitmap.bm_data);
1112 // } else if (ch==EOF) {
1114 // } else if (ch == 'B') {
1115 // if (Robot_canv != NULL) {
1116 // d_free(Robot_canv);
1120 // bitmap_num = get_message_num(&message);
1121 // if (bitmap_num != -1)
1122 // show_briefing_bitmap(Textures[bitmap_num]);
1123 // prev_ch = 10; // read to eoln
1124 } else if (ch == 'S') {
1129 if (printing_channel>-1)
1130 digi_stop_sound( printing_channel );
1131 printing_channel=-1;
1140 start_time = timer_get_fixed_seconds();
1141 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1143 if (_RedrawScreen) {
1144 _RedrawScreen = FALSE;
1145 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1151 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1153 flash_cursor(flashing_cursor);
1159 show_spinning_robot_frame(robot_num);
1162 show_bitmap_frame();
1163 start_time += KEY_DELAY_DEFAULT/2;
1167 if (keypress == KEY_BACKSP)
1170 if (keypress == KEY_ESC)
1173 flashing_cursor = 0;
1175 WIN(wpage_done = 0);
1176 } else if (ch == 'P') { // New page.
1178 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1179 // printing to it! You know, $Z !!!
1180 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1184 while (*message != 10) {
1185 message++; // drop carriage return after special escape sequence
1191 } else if (ch == '\t') { // Tab
1192 if (Briefing_text_x - bsp->text_ulx < tab_stop)
1193 Briefing_text_x = bsp->text_ulx + tab_stop;
1194 } else if ((ch == ';') && (prev_ch == 10)) {
1195 while (*message++ != 10)
1198 } else if (ch == '\\') {
1200 } else if (ch == 10) {
1201 if (prev_ch != '\\') {
1203 if (1) //DumbAdjust==0)
1204 Briefing_text_y += (8*(MenuHires+1));
1207 Briefing_text_x = bsp->text_ulx;
1208 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
1209 load_briefing_screen(screen_num);
1210 Briefing_text_x = bsp->text_ulx;
1211 Briefing_text_y = bsp->text_uly;
1214 if (ch == 13) //Can this happen? Above says ch==10
1221 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1222 // printing to it! You know, $Z !!!
1223 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1229 printing_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
1233 WIN(if (GRMODEINFO(emul)) delay_count = 0);
1235 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
1239 // Check for Esc -> abort.
1241 key_check=local_key_inkey();
1246 if (_RedrawScreen) {
1247 _RedrawScreen = FALSE;
1248 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1249 key_check = KEY_ESC;
1252 if ( key_check == KEY_ESC ) {
1257 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
1260 #ifdef GR_SUPPORTS_FULLSCREEN
1261 if ((key_check == KEY_CTRLED+KEY_SHIFTED+KEY_PADENTER) ||
1262 (key_check == KEY_ALTED+KEY_CTRLED+KEY_PADENTER) ||
1263 (key_check == KEY_ALTED+KEY_SHIFTED+KEY_PADENTER))
1264 gr_toggle_fullscreen();
1267 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
1268 Briefing_text_x = bsp->text_ulx;
1269 Briefing_text_y += bsp->text_uly;
1272 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
1278 if (printing_channel>-1)
1279 digi_stop_sound( printing_channel );
1280 printing_channel=-1;
1291 start_time = timer_get_fixed_seconds();
1292 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1294 if (_RedrawScreen) {
1295 _RedrawScreen = FALSE;
1296 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1302 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1304 flash_cursor(flashing_cursor);
1309 show_spinning_robot_frame(robot_num);
1311 show_bitmap_frame();
1312 start_time += KEY_DELAY_DEFAULT/2;
1323 if (keypress == KEY_BACKSP)
1326 if (keypress == KEY_ESC) {
1331 load_briefing_screen(screen_num);
1332 Briefing_text_x = bsp->text_ulx;
1333 Briefing_text_y = bsp->text_uly;
1334 delay_count = KEY_DELAY_DEFAULT;
1336 WIN(wpage_done = 0);
1347 if (Robot_canv != NULL)
1348 {d_free(Robot_canv); Robot_canv=NULL;}
1351 digi_stop_sound( hum_channel );
1352 if (printing_channel>-1)
1353 digi_stop_sound( printing_channel );
1358 //-----------------------------------------------------------------------------
1359 // Return a pointer to the start of text for screen #screen_num.
1360 char * get_briefing_message(int screen_num)
1362 char *tptr = Briefing_text;
1366 Assert(screen_num >= 0);
1368 while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1373 cur_screen = get_message_num(&tptr);
1377 if (screen_num!=cur_screen)
1383 //-----------------------------------------------------------------------------
1384 // Load Descent briefing text.
1385 int load_screen_text(char *filename, char **buf)
1390 int have_binary = 0;
1392 if ((tfile = cfopen(filename,"rb")) == NULL) {
1393 char nfilename[30], *ptr;
1395 strcpy(nfilename, filename);
1396 ptr = strrchr(nfilename, '.');
1398 strcat(nfilename, ".txb");
1399 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1400 mprintf ((0,"can't open %s!\n",nfilename));
1402 //Error("Cannot open file %s or %s", filename, nfilename);
1405 mprintf ((0,"reading...\n"));
1408 len = cfilelength(ifile);
1409 MALLOC(*buf, char, len+500);
1410 mprintf ((0,"len=%d\n",len));
1411 for (x=0, i=0; i < len; i++, x++) {
1412 cfread (*buf+x,1,1,ifile);
1413 // mprintf ((0,"%c",*(*buf+x)));
1420 len = cfilelength(tfile);
1421 MALLOC(*buf, char, len+500);
1422 for (x=0, i=0; i < len; i++, x++) {
1423 cfread (*buf+x,1,1,tfile);
1424 // mprintf ((0,"%c",*(*buf+x)));
1430 //cfread(*buf, 1, len, tfile);
1437 for (i = 0, ptr = *buf; i < len; i++, ptr++) {
1439 encode_rotate_left(ptr);
1440 *ptr = *ptr ^ BITMAP_TBL_XOR;
1441 encode_rotate_left(ptr);
1449 //-----------------------------------------------------------------------------
1450 // Return true if message got aborted, else return false.
1451 int show_briefing_text(int screen_num)
1455 message_ptr = get_briefing_message(screen_num);
1456 if (message_ptr==NULL)
1459 DoBriefingColorStuff();
1461 if (Mission_list[Current_mission_num].descent_version == 1)
1462 return show_d1_briefing_message(screen_num, message_ptr);
1464 return show_briefing_message(screen_num, message_ptr);
1467 void DoBriefingColorStuff ()
1469 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1470 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1472 Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1473 Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1475 Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1476 Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1478 Erase_color = gr_find_closest_color_current(0, 0, 0);
1481 //-----------------------------------------------------------------------------
1482 // Return true if screen got aborted by user, else return false.
1483 int show_briefing_screen( int screen_num, int allow_keys)
1486 ubyte palette_save[768];
1488 New_pal_254_bash = 0;
1490 if (Skip_briefing_screens) {
1491 mprintf((0, "Skipping briefing screen [brief03.pcx]\n"));
1495 // briefing_bm.bm_data=NULL;
1496 // if ((pcx_error=pcx_read_bitmap( "brief03.pcx", &briefing_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
1497 // mprintf((0, "File '%s', PCX load error: %s (%i)\n (It's a briefing screen. Does this cause you pain?)\n","Brief03.pcx", pcx_errormsg(pcx_error), pcx_error));
1502 memcpy(palette_save,gr_palette,sizeof(palette_save));
1503 memcpy(New_pal,gr_palette,sizeof(gr_palette));
1506 // vfx_set_palette_sub( New_pal );
1507 // gr_palette_clear();
1508 // gr_bitmap( 0, 0, &briefing_bm );
1510 gr_palette_load(New_pal);
1513 // if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1515 // memcpy(gr_palette,New_pal,sizeof(gr_palette));
1518 key_close(); // kill the keyboard handler during briefing screens for movies
1520 rval = show_briefing_text(screen_num);
1525 #if defined (MACINTOSH) || defined(WINDOWS)
1526 memcpy(New_pal,gr_palette,sizeof(gr_palette)); // attempt to get fades after briefing screens done correctly.
1531 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1534 DEFINE_SCREEN(NULL);
1535 WIN(DDGRLOCK(dd_grd_curcanv));
1536 gr_clear_canvas (0);
1537 WIN(DDGRUNLOCK(dd_grd_curcanv));
1538 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1542 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1544 // d_free(briefing_bm.bm_data);
1550 //-----------------------------------------------------------------------------
1551 void do_briefing_screens(char *filename,int level_num)
1553 int abort_briefing_screens = 0;
1554 int cur_briefing_screen = 0;
1556 if (Skip_briefing_screens) {
1557 mprintf((0, "Skipping all briefing screens.\n"));
1562 return; // no briefing screens at all for demo
1566 mprintf ((0,"Trying briefing screen <%s>\n",filename));
1571 if (!load_screen_text(filename, &Briefing_text))
1575 songs_play_song( SONG_BRIEFING, 1 );
1580 set_screen_mode( SCREEN_MENU );
1583 dd_gr_set_current_canvas(NULL),
1584 gr_set_current_canvas(NULL)
1587 mprintf ((0,"Playing briefing screen <%s>, level %d\n",filename,level_num));
1591 if (Mission_list[Current_mission_num].descent_version == 1) {
1592 if (level_num == 1) {
1593 while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1594 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1595 cur_briefing_screen++;
1599 if (!abort_briefing_screens) {
1600 for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREENS; cur_briefing_screen++)
1601 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1602 if (show_briefing_screen(cur_briefing_screen, 0))
1607 show_briefing_screen(level_num,0);
1609 d_free (Briefing_text);
1616 int DefineBriefingBox (char **buf)
1621 n=get_new_message_num (buf);
1623 Assert(n < MAX_BRIEFING_SCREENS);
1625 while (**buf!=' ') {
1630 name[i]='\0'; // slap a delimiter on this guy
1632 strcpy (Briefing_screens[n].bs_name,name);
1633 Briefing_screens[n].level_num=get_new_message_num (buf);
1634 Briefing_screens[n].message_num=get_new_message_num (buf);
1635 Briefing_screens[n].text_ulx=get_new_message_num (buf);
1636 Briefing_screens[n].text_uly=get_new_message_num (buf);
1637 Briefing_screens[n].text_width=get_new_message_num (buf);
1638 Briefing_screens[n].text_height=get_message_num (buf); // NOTICE!!!
1641 Briefing_screens[n].text_ulx*=2;
1642 Briefing_screens[n].text_uly*=2.4;
1643 Briefing_screens[n].text_width*=2;
1644 Briefing_screens[n].text_height*=2.4;
1650 int get_new_message_num(char **message)
1654 while (**message == ' ')
1657 while ((**message >= '0') && (**message <= '9')) {
1658 num = 10*num + **message-'0';