1 /* $Id: titles.c,v 1.14 2002-08-30 08:04:44 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
79 extern int MVEPaletteCalls;
84 char CurBriefScreenName[15]="brief03.pcx";
90 #define MAX_BRIEFING_COLORS 3
92 // Descent 1 briefings
93 char Ending_text_filename[13] = "\0";
94 char Briefing_text_filename[13] = "\0";
96 #define SHAREWARE_ENDING_FILENAME "ending.tex"
98 // Can be set by -noscreens command line option. Causes bypassing of all briefing screens.
99 int Skip_briefing_screens=0;
100 int Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
101 int Current_color = 0;
104 extern int check_button_press();
107 extern void macintosh_quit(void);
110 static int rescale_x(int x)
112 return x * GWIDTH / 320;
115 static int rescale_y(int y)
117 return y * GHEIGHT / 200;
121 int local_key_inkey(void)
128 DoMessageStuff(&msg);
133 if (rval == KEY_PRINT_SCREEN) {
137 gr_palette_read(gr_palette);
138 gr_copy_palette(gr_palette,gr_palette,0); //reset color lookup cache
143 return 0; //say no key pressed
146 if (check_button_press()) //joystick or mouse button pressed?
150 if ( rval == KEY_Q+KEY_COMMAND )
157 int local_key_inkey(void)
162 if (!GetOSEvent(everyEvent, &event))
165 if (event.what != keyDown)
168 rval = (int)((event.message & keyCodeMask) >> 8);
170 if (rval == KEY_PRINT_SCREEN) {
172 return 0; //say no key pressed
175 if (check_button_press()) //joystick or mouse button pressed?
179 if ( rval == KEY_Q+KEY_COMMAND )
187 int show_title_screen( char * filename, int allow_keys, int from_hog_only )
192 ubyte palette_save[768];
193 char new_filename[FILENAME_LEN+1] = "";
197 strcpy(new_filename,"\x01"); //only read from hog file
200 strcat(new_filename,filename);
201 filename = new_filename;
203 title_bm.bm_data=NULL;
204 if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
205 printf( "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
206 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));
207 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error);
210 memcpy(palette_save,gr_palette,sizeof(palette_save));
212 #if defined(POLY_ACC)
214 pa_update_clut(New_pal, 0, 256, 0);
217 //vfx_set_palette_sub( New_pal );
219 gr_palette_load( New_pal );
225 dd_gr_set_current_canvas(NULL),
226 gr_set_current_canvas( NULL )
228 WIN(DDGRLOCK(dd_grd_curcanv));
229 show_fullscr(&title_bm);
230 WIN(DDGRUNLOCK(dd_grd_curcanv));
234 #if defined(POLY_ACC)
238 if (gr_palette_fade_in( New_pal, 32, allow_keys ))
240 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
242 gr_palette_load( New_pal );
243 timer = timer_get_fixed_seconds() + i2f(3);
245 if ( local_key_inkey() && allow_keys ) break;
246 if ( timer_get_fixed_seconds() > timer ) break;
248 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
250 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
251 d_free(title_bm.bm_data);
256 char bs_name[14]; // filename, eg merc01. Assumes .lbm suffix.
259 short text_ulx, text_uly; // upper left x,y of text window
260 short text_width, text_height; // width and height of text window
263 #define BRIEFING_SECRET_NUM 31 // This must correspond to the first secret level which must come at the end of the list.
264 #define BRIEFING_OFFSET_NUM 4 // This must correspond to the first level screen (ie, past the bald guy briefing screens)
266 #define SHAREWARE_ENDING_LEVEL_NUM 0x7f
267 #define REGISTERED_ENDING_LEVEL_NUM 0x7e
270 #define ENDING_LEVEL_NUM SHAREWARE_ENDING_LEVEL_NUM
272 #define ENDING_LEVEL_NUM REGISTERED_ENDING_LEVEL_NUM
275 #define MAX_BRIEFING_SCREENS 60
277 briefing_screen Briefing_screens[MAX_BRIEFING_SCREENS]=
278 {{"brief03.pcx",0,3,8,8,257,177}}; // default=0!!!
280 int Briefing_text_x, Briefing_text_y;
282 void init_char_pos(int x, int y)
286 mprintf ((0,"Setting init x=%d y=%d\n",x,y));
289 grs_canvas *Robot_canv = NULL;
290 vms_angvec Robot_angles;
292 char Bitmap_name[32] = "";
293 #define EXIT_DOOR_MAX 14
294 #define OTHER_THING_MAX 10 // Adam: This is the number of frames in your new animating thing.
295 #define DOOR_DIV_INIT 6
296 byte Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
298 //-----------------------------------------------------------------------------
299 void show_bitmap_frame(void)
302 dd_grs_canvas *curcanv_save, *bitmap_canv=0;
304 grs_canvas *curcanv_save, *bitmap_canv=0;
307 grs_bitmap *bitmap_ptr;
309 // Only plot every nth frame.
310 if (Door_div_count) {
315 Door_div_count = DOOR_DIV_INIT;
317 if (Bitmap_name[0] != 0) {
321 // Set supertransparency color to black
322 if (!New_pal_254_bash) {
323 New_pal_254_bash = 1;
325 New_pal[254*3+1] = 0;
326 New_pal[254*3+2] = 0;
327 gr_palette_load( New_pal );
330 switch (Animating_bitmap_type) {
333 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 64, 64); break,
334 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 64, 64); break
338 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 94, 94); break,
339 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 94, 94); break
342 // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
344 Int3(); // Impossible, illegal value for Animating_bitmap_type
348 curcanv_save = dd_grd_curcanv; dd_grd_curcanv = bitmap_canv,
349 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv
352 pound_signp = strchr(Bitmap_name, '#');
353 Assert(pound_signp != NULL);
355 dig1 = *(pound_signp+1);
356 dig2 = *(pound_signp+2);
360 num = (dig1-'0')*10 + (dig2-'0');
362 switch (Animating_bitmap_type) {
365 if (num > EXIT_DOOR_MAX) {
368 } else if (num < 0) {
375 if (num > OTHER_THING_MAX)
382 *(pound_signp+1) = (num / 10) + '0';
383 *(pound_signp+2) = (num % 10) + '0';
384 *(pound_signp+3) = 0;
386 *(pound_signp+1) = (num % 10) + '0';
387 *(pound_signp+2) = 0;
392 bi = piggy_find_bitmap(Bitmap_name);
393 bitmap_ptr = &GameBitmaps[bi.index];
397 WIN(DDGRLOCK(dd_grd_curcanv));
398 gr_bitmapm(0, 0, bitmap_ptr);
399 WIN(DDGRUNLOCK(dd_grd_curcanv));
402 dd_grd_curcanv = curcanv_save,
403 grd_curcanv = curcanv_save
407 switch (Animating_bitmap_type) {
409 if (num == EXIT_DOOR_MAX) {
412 } else if (num == 0) {
424 //-----------------------------------------------------------------------------
425 void show_briefing_bitmap(grs_bitmap *bmp)
428 dd_grs_canvas *bitmap_canv, *curcanv_save;
430 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
431 curcanv_save = dd_grd_curcanv;
432 dd_gr_set_current_canvas(bitmap_canv);
433 DDGRLOCK(dd_grd_curcanv);
435 DDGRUNLOCK(dd_grd_curcanv);
436 dd_gr_set_current_canvas(curcanv_save);
438 grs_canvas *curcanv_save, *bitmap_canv;
440 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
441 curcanv_save = grd_curcanv;
442 gr_set_current_canvas(bitmap_canv);
443 gr_bitmapm(0, 0, bmp);
444 gr_set_current_canvas(curcanv_save);
451 //-----------------------------------------------------------------------------
452 void show_spinning_robot_frame(int robot_num)
454 grs_canvas *curcanv_save;
456 if (robot_num != -1) {
457 Robot_angles.h += 150;
459 curcanv_save = grd_curcanv;
460 grd_curcanv = Robot_canv;
461 Assert(Robot_info[robot_num].model_num != -1);
462 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
463 grd_curcanv = curcanv_save;
468 //-----------------------------------------------------------------------------
469 void init_spinning_robot(void) //(int x,int y,int w,int h)
477 int x = rescale_x(138);
478 int y = rescale_y(55);
479 int w = rescale_x(166);
480 int h = rescale_y(138);
483 Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
488 //---------------------------------------------------------------------------
489 // Returns char width.
490 // If show_robot_flag set, then show a frame of the spinning robot.
491 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
495 static fix start_time=0;
498 message[0] = the_char;
501 if (start_time==0 && timer_get_fixed_seconds()<0)
502 start_time=timer_get_fixed_seconds();
504 gr_get_string_size(message, &w, &h, &aw );
506 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
508 // Draw cursor if there is some delay and caller says to draw cursor
509 if (cursor_flag && delay) {
510 WIN(DDGRLOCK(dd_grd_curcanv));
511 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
512 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
513 WIN(DDGRUNLOCK(dd_grd_curcanv));
517 delay=fixdiv (F1_0,i2f(15));
523 if (RobotPlaying && (delay != 0))
526 while (timer_get_fixed_seconds() < (start_time + delay)) {
527 if (RobotPlaying && delay != 0)
532 show_spinning_robot_frame(robot_num);
535 start_time = timer_get_fixed_seconds();
537 WIN(DDGRLOCK(dd_grd_curcanv));
539 if (cursor_flag && delay) {
540 gr_set_fontcolor(Erase_color, -1);
541 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
544 // Draw the character
545 gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
546 gr_printf(Briefing_text_x, Briefing_text_y, message );
548 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
549 gr_printf(Briefing_text_x+1, Briefing_text_y, message );
550 WIN(DDGRUNLOCK(dd_grd_curcanv));
552 if (delay) gr_update();
554 // if (the_char != ' ')
555 // if (!digi_is_sound_playing(SOUND_MARKER_HIT))
556 // digi_play_sample( SOUND_MARKER_HIT, F1_0 );
561 //-----------------------------------------------------------------------------
562 int load_briefing_screen( int screen_num )
566 WIN(DDGRLOCK(dd_grd_curcanv));
567 if ((pcx_error=pcx_read_fullscr( CurBriefScreenName, New_pal ))!=PCX_ERROR_NONE) {
568 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));
569 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);
570 WIN(DDGRUNLOCK(dd_grd_curcanv));
571 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",CurBriefScreenName, pcx_errormsg(pcx_error), pcx_error);
573 WIN(DDGRUNLOCK(dd_grd_curcanv));
580 int load_new_briefing_screen( char *fname )
584 mprintf ((0,"Loading new briefing %s!\n",fname));
585 strcpy (CurBriefScreenName,fname);
587 //WIN(DEFINE_SCREEN(CurBriefScreenName));
589 if (gr_palette_fade_out( New_pal, 32, 0 ))
592 WIN(DDGRLOCK(dd_grd_curcanv));
593 if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE) {
594 //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE) {
595 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);
596 WIN(DDGRUNLOCK(dd_grd_curcanv));
597 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
599 WIN(DDGRUNLOCK(dd_grd_curcanv));
603 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
605 if (gr_palette_fade_in( New_pal, 32, 0 ))
607 DoBriefingColorStuff();
614 #define KEY_DELAY_DEFAULT ((F1_0*20)/1000)
616 //-----------------------------------------------------------------------------
617 int get_message_num(char **message)
621 while (**message == ' ')
624 while ((**message >= '0') && (**message <= '9')) {
625 num = 10*num + **message-'0';
629 while (*(*message)++ != 10) // Get and drop eoln
635 //-----------------------------------------------------------------------------
636 void get_message_name(char **message, char *result)
638 while (**message == ' ')
641 while ((**message != ' ') && (**message != 10)) {
642 if (**message != '\n')
643 *result++ = **message;
648 while (*(*message)++ != 10) // Get and drop eoln
654 //-----------------------------------------------------------------------------
655 void flash_cursor(int cursor_flag)
657 if (cursor_flag == 0)
660 WIN(DDGRLOCK(dd_grd_curcanv));
661 if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
662 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
664 gr_set_fontcolor(Erase_color, -1);
666 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
667 WIN(DDGRUNLOCK(dd_grd_curcanv));
670 extern int InitMovieBriefing();
672 //-----------------------------------------------------------------------------
673 // Return true if message got aborted by user (pressed ESC), else return false.
674 int show_d1_briefing_message(int screen_num, char *message)
678 briefing_screen *bsp = &Briefing_screens[screen_num];
679 int delay_count = KEY_DELAY_DEFAULT;
684 int flashing_cursor=0;
686 int text_ulx = rescale_x(bsp->text_ulx);
687 int text_uly = rescale_y(bsp->text_uly);
693 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
694 gr_set_curfont( GAME_FONT );
696 init_char_pos(text_ulx, text_uly);
703 Current_color = get_message_num(&message)-1;
704 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
706 } else if (ch == 'F') { // toggle flashing cursor
707 flashing_cursor = !flashing_cursor;
709 while (*message++ != 10)
711 } else if (ch == 'T') {
712 tab_stop = get_message_num(&message);
713 prev_ch = 10; // read to eoln
714 } else if (ch == 'R') {
715 if (Robot_canv != NULL)
716 {free(Robot_canv); Robot_canv=NULL;}
718 init_spinning_robot();
719 robot_num = get_message_num(&message);
720 prev_ch = 10; // read to eoln
721 } else if (ch == 'N') {
722 //--grs_bitmap *bitmap_ptr;
723 if (Robot_canv != NULL)
724 {free(Robot_canv); Robot_canv=NULL;}
726 get_message_name(&message, Bitmap_name);
727 strcat(Bitmap_name, "#0");
728 Animating_bitmap_type = 0;
730 } else if (ch == 'O') {
731 if (Robot_canv != NULL)
732 {free(Robot_canv); Robot_canv=NULL;}
734 get_message_name(&message, Bitmap_name);
735 strcat(Bitmap_name, "#0");
736 Animating_bitmap_type = 1;
738 } else if (ch == 'B') {
739 char bitmap_name[32];
740 grs_bitmap guy_bitmap;
741 ubyte temp_palette[768];
744 if (Robot_canv != NULL)
745 {free(Robot_canv); Robot_canv=NULL;}
747 get_message_name(&message, bitmap_name);
748 strcat(bitmap_name, ".bbm");
749 gr_init_bitmap_data (&guy_bitmap);
750 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
751 Assert(iff_error == IFF_NO_ERROR);
753 show_briefing_bitmap(&guy_bitmap);
754 gr_free_bitmap_data (&guy_bitmap);
756 // } else if (ch == 'B') {
757 // if (Robot_canv != NULL)
758 // {free(Robot_canv); Robot_canv=NULL;}
760 // bitmap_num = get_message_num(&message);
761 // if (bitmap_num != -1)
762 // show_briefing_bitmap(Textures[bitmap_num]);
763 // prev_ch = 10; // read to eoln
764 } else if (ch == 'S') {
769 start_time = timer_get_fixed_seconds();
770 start_time = timer_get_approx_seconds();
771 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
773 //added on 9/13/98 by adb to make arch's requiring updates work
777 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
778 if ( timer_get_approx_seconds() > time_out_value ) {
780 break; // Time out after 1 minute..
782 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
784 flash_cursor(flashing_cursor);
785 show_spinning_robot_frame(robot_num);
788 //added on 9/13/98 by adb to make arch's requiring updates work
792 start_time += KEY_DELAY_DEFAULT/2;
796 if (keypress == KEY_BACKSP)
799 if (keypress == KEY_ESC)
804 } else if (ch == 'P') { // New page.
806 while (*message != 10) {
807 message++; // drop carriage return after special escape sequence
812 } else if (ch == '$' || ch == ';') { // Print a $/;
814 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
818 } else if (ch == '\t') { // Tab
819 if (Briefing_text_x - text_ulx < tab_stop)
820 Briefing_text_x = text_ulx + tab_stop;
821 } else if ((ch == ';') && (prev_ch == 10)) {
822 while (*message++ != 10)
825 } else if (ch == '\\') {
827 } else if (ch == 10) {
828 if (prev_ch != '\\') {
830 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
831 Briefing_text_x = text_ulx;
832 if (Briefing_text_y > text_uly + rescale_y(bsp->text_height)) {
833 load_briefing_screen(screen_num);
834 Briefing_text_x = text_ulx;
835 Briefing_text_y = text_uly;
844 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
847 //added/changed on 9/13/98 by adb to speed up briefings after pressing a key with SDL
848 // Check for Esc -> abort.
850 key_check=local_key_inkey();
854 if ( key_check == KEY_ESC ) {
860 if ( key_check == KEY_ALTED+KEY_F2 )
864 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
867 if (Briefing_text_x > text_ulx + rescale_x(bsp->text_width)) {
868 Briefing_text_x = text_ulx;
869 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
872 if ((new_page) || (Briefing_text_y > text_uly + rescale_y(bsp->text_height))) {
874 fix time_out_value = 0;
878 start_time = timer_get_approx_seconds();
879 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
881 //added on 9/13/98 by adb to make arch's requiring updates work
885 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
886 if ( timer_get_approx_seconds() > time_out_value ) {
888 break; // Time out after 1 minute..
890 while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
892 flash_cursor(flashing_cursor);
893 show_spinning_robot_frame(robot_num);
896 //added on 9/13/98 by adb to make arch's requiring updates work
900 start_time += KEY_DELAY_DEFAULT/2;
906 if (keypress == KEY_BACKSP)
909 if (keypress == KEY_ESC) {
914 load_briefing_screen(screen_num);
915 Briefing_text_x = text_ulx;
916 Briefing_text_y = text_uly;
917 delay_count = KEY_DELAY_DEFAULT;
921 if (Robot_canv != NULL)
922 {free(Robot_canv); Robot_canv=NULL;}
927 //-----------------------------------------------------------------------------
928 // Return true if message got aborted by user (pressed ESC), else return false.
929 int show_briefing_message(int screen_num, char *message)
933 briefing_screen *bsp = &Briefing_screens[screen_num];
934 int delay_count = KEY_DELAY_DEFAULT;
938 static int tab_stop=0;
939 int flashing_cursor=0;
940 int new_page=0,GotZ=0;
942 char spinRobotName[]="rba.mve",kludge; // matt don't change this!
947 int hum_channel=-1,printing_channel=-1;
948 int LineAdjustment=1;
949 WIN(int wpage_done=0);
960 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
963 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
964 gr_set_curfont( GAME_FONT );
966 bsp=&Briefing_screens[0];
967 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
974 screen_num=DefineBriefingBox (&message);
975 //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
977 bsp = &Briefing_screens[screen_num];
978 init_char_pos(bsp->text_ulx, bsp->text_uly);
980 prev_ch = 10; // read to eoln
981 } else if (ch=='U') {
982 screen_num=get_message_num(&message);
983 bsp = &Briefing_screens[screen_num];
984 init_char_pos(bsp->text_ulx, bsp->text_uly);
985 prev_ch = 10; // read to eoln
986 } else if (ch == 'C') {
987 Current_color = get_message_num(&message)-1;
988 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
990 } else if (ch == 'F') { // toggle flashing cursor
991 flashing_cursor = !flashing_cursor;
993 while (*message++ != 10)
995 } else if (ch == 'T') {
996 tab_stop = get_message_num(&message);
997 tab_stop*=(1+MenuHires);
998 prev_ch = 10; // read to eoln
999 } else if (ch == 'R') {
1000 if (Robot_canv != NULL) {
1011 spinRobotName[2]=kludge; // ugly but proud
1013 RobotPlaying=InitRobotMovie(spinRobotName);
1015 // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
1018 DoBriefingColorStuff ();
1019 mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
1022 init_spinning_robot();
1023 robot_num = get_message_num(&message);
1025 prev_ch = 10; // read to eoln
1026 } else if (ch == 'N') {
1027 //--grs_bitmap *bitmap_ptr;
1028 if (Robot_canv != NULL) {
1033 get_message_name(&message, Bitmap_name);
1034 strcat(Bitmap_name, "#0");
1035 Animating_bitmap_type = 0;
1037 } else if (ch == 'O') {
1038 if (Robot_canv != NULL) {
1043 get_message_name(&message, Bitmap_name);
1044 strcat(Bitmap_name, "#0");
1045 Animating_bitmap_type = 1;
1047 } else if (ch=='A') {
1048 LineAdjustment=1-LineAdjustment;
1049 } else if (ch=='Z') {
1050 //mprintf ((0,"Got a Z!\n"));
1052 #if defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
1055 if (LineAdjustment==1)
1062 while ((fname[i]=*message) != '\n') {
1072 while (fname[i]!='.')
1073 fname2[i] = fname[i++];
1083 load_new_briefing_screen (cfexist(fname2)?fname2:fname);
1085 load_new_briefing_screen (fname);
1087 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1089 } else if (ch == 'B') {
1090 char bitmap_name[32];
1091 grs_bitmap guy_bitmap;
1092 ubyte temp_palette[768];
1095 if (Robot_canv != NULL) {
1100 get_message_name(&message, bitmap_name);
1101 strcat(bitmap_name, ".bbm");
1102 guy_bitmap.bm_data = NULL;
1103 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
1104 Assert(iff_error == IFF_NO_ERROR);
1105 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
1107 show_briefing_bitmap(&guy_bitmap);
1108 d_free(guy_bitmap.bm_data);
1110 // } else if (ch==EOF) {
1112 // } else if (ch == 'B') {
1113 // if (Robot_canv != NULL) {
1114 // d_free(Robot_canv);
1118 // bitmap_num = get_message_num(&message);
1119 // if (bitmap_num != -1)
1120 // show_briefing_bitmap(Textures[bitmap_num]);
1121 // prev_ch = 10; // read to eoln
1122 } else if (ch == 'S') {
1127 if (printing_channel>-1)
1128 digi_stop_sound( printing_channel );
1129 printing_channel=-1;
1138 start_time = timer_get_fixed_seconds();
1139 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1141 if (_RedrawScreen) {
1142 _RedrawScreen = FALSE;
1143 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1149 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1151 flash_cursor(flashing_cursor);
1157 show_spinning_robot_frame(robot_num);
1160 show_bitmap_frame();
1161 start_time += KEY_DELAY_DEFAULT/2;
1165 if (keypress == KEY_BACKSP)
1168 if (keypress == KEY_ESC)
1171 flashing_cursor = 0;
1173 WIN(wpage_done = 0);
1174 } else if (ch == 'P') { // New page.
1176 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1177 // printing to it! You know, $Z !!!
1178 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1182 while (*message != 10) {
1183 message++; // drop carriage return after special escape sequence
1189 } else if (ch == '\t') { // Tab
1190 if (Briefing_text_x - bsp->text_ulx < tab_stop)
1191 Briefing_text_x = bsp->text_ulx + tab_stop;
1192 } else if ((ch == ';') && (prev_ch == 10)) {
1193 while (*message++ != 10)
1196 } else if (ch == '\\') {
1198 } else if (ch == 10) {
1199 if (prev_ch != '\\') {
1201 if (1) //DumbAdjust==0)
1202 Briefing_text_y += (8*(MenuHires+1));
1205 Briefing_text_x = bsp->text_ulx;
1206 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
1207 load_briefing_screen(screen_num);
1208 Briefing_text_x = bsp->text_ulx;
1209 Briefing_text_y = bsp->text_uly;
1212 if (ch == 13) //Can this happen? Above says ch==10
1219 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1220 // printing to it! You know, $Z !!!
1221 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1227 printing_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
1231 WIN(if (GRMODEINFO(emul)) delay_count = 0);
1233 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
1237 // Check for Esc -> abort.
1239 key_check=local_key_inkey();
1244 if (_RedrawScreen) {
1245 _RedrawScreen = FALSE;
1246 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1247 key_check = KEY_ESC;
1250 if ( key_check == KEY_ESC ) {
1255 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
1258 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
1259 Briefing_text_x = bsp->text_ulx;
1260 Briefing_text_y += bsp->text_uly;
1263 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
1269 if (printing_channel>-1)
1270 digi_stop_sound( printing_channel );
1271 printing_channel=-1;
1282 start_time = timer_get_fixed_seconds();
1283 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1285 if (_RedrawScreen) {
1286 _RedrawScreen = FALSE;
1287 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1293 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1295 flash_cursor(flashing_cursor);
1300 show_spinning_robot_frame(robot_num);
1302 show_bitmap_frame();
1303 start_time += KEY_DELAY_DEFAULT/2;
1314 if (keypress == KEY_BACKSP)
1317 if (keypress == KEY_ESC) {
1322 load_briefing_screen(screen_num);
1323 Briefing_text_x = bsp->text_ulx;
1324 Briefing_text_y = bsp->text_uly;
1325 delay_count = KEY_DELAY_DEFAULT;
1327 WIN(wpage_done = 0);
1338 if (Robot_canv != NULL)
1339 {d_free(Robot_canv); Robot_canv=NULL;}
1342 digi_stop_sound( hum_channel );
1343 if (printing_channel>-1)
1344 digi_stop_sound( printing_channel );
1349 //-----------------------------------------------------------------------------
1350 // Return a pointer to the start of text for screen #screen_num.
1351 char * get_briefing_message(int screen_num)
1353 char *tptr = Briefing_text;
1357 Assert(screen_num >= 0);
1359 while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1364 cur_screen = get_message_num(&tptr);
1368 if (screen_num!=cur_screen)
1374 //-----------------------------------------------------------------------------
1375 // Load Descent briefing text.
1376 int load_screen_text(char *filename, char **buf)
1381 int have_binary = 0;
1383 if ((tfile = cfopen(filename,"rb")) == NULL) {
1384 char nfilename[30], *ptr;
1386 strcpy(nfilename, filename);
1387 ptr = strrchr(nfilename, '.');
1389 strcat(nfilename, ".txb");
1390 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1391 mprintf ((0,"can't open %s!\n",nfilename));
1393 //Error("Cannot open file %s or %s", filename, nfilename);
1396 mprintf ((0,"reading...\n"));
1399 len = cfilelength(ifile);
1400 MALLOC(*buf, char, len+500);
1401 mprintf ((0,"len=%d\n",len));
1402 for (x=0, i=0; i < len; i++, x++) {
1403 cfread (*buf+x,1,1,ifile);
1404 // mprintf ((0,"%c",*(*buf+x)));
1411 len = cfilelength(tfile);
1412 MALLOC(*buf, char, len+500);
1413 for (x=0, i=0; i < len; i++, x++) {
1414 cfread (*buf+x,1,1,tfile);
1415 // mprintf ((0,"%c",*(*buf+x)));
1421 //cfread(*buf, 1, len, tfile);
1428 for (i = 0, ptr = *buf; i < len; i++, ptr++) {
1430 encode_rotate_left(ptr);
1431 *ptr = *ptr ^ BITMAP_TBL_XOR;
1432 encode_rotate_left(ptr);
1440 //-----------------------------------------------------------------------------
1441 // Return true if message got aborted, else return false.
1442 int show_briefing_text(int screen_num)
1446 message_ptr = get_briefing_message(screen_num);
1447 if (message_ptr==NULL)
1450 DoBriefingColorStuff();
1452 if (Mission_list[Current_mission_num].descent_version == 1)
1453 return show_d1_briefing_message(screen_num, message_ptr);
1455 return show_briefing_message(screen_num, message_ptr);
1458 void DoBriefingColorStuff ()
1460 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1461 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1463 Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1464 Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1466 Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1467 Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1469 Erase_color = gr_find_closest_color_current(0, 0, 0);
1472 //-----------------------------------------------------------------------------
1473 // Return true if screen got aborted by user, else return false.
1474 int show_briefing_screen( int screen_num, int allow_keys)
1477 ubyte palette_save[768];
1479 New_pal_254_bash = 0;
1481 if (Skip_briefing_screens) {
1482 mprintf((0, "Skipping briefing screen [brief03.pcx]\n"));
1486 // briefing_bm.bm_data=NULL;
1487 // if ((pcx_error=pcx_read_bitmap( "brief03.pcx", &briefing_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
1488 // 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));
1493 memcpy(palette_save,gr_palette,sizeof(palette_save));
1494 memcpy(New_pal,gr_palette,sizeof(gr_palette));
1497 // vfx_set_palette_sub( New_pal );
1498 // gr_palette_clear();
1499 // gr_bitmap( 0, 0, &briefing_bm );
1501 gr_palette_load(New_pal);
1504 // if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1506 // memcpy(gr_palette,New_pal,sizeof(gr_palette));
1509 key_close(); // kill the keyboard handler during briefing screens for movies
1511 rval = show_briefing_text(screen_num);
1516 #if defined (MACINTOSH) || defined(WINDOWS)
1517 memcpy(New_pal,gr_palette,sizeof(gr_palette)); // attempt to get fades after briefing screens done correctly.
1522 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1525 DEFINE_SCREEN(NULL);
1526 WIN(DDGRLOCK(dd_grd_curcanv));
1527 gr_clear_canvas (0);
1528 WIN(DDGRUNLOCK(dd_grd_curcanv));
1529 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1533 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1535 // d_free(briefing_bm.bm_data);
1541 //-----------------------------------------------------------------------------
1542 void do_briefing_screens(char *filename,int level_num)
1544 int abort_briefing_screens = 0;
1545 int cur_briefing_screen = 0;
1549 if (Skip_briefing_screens) {
1550 mprintf((0, "Skipping all briefing screens.\n"));
1555 return; // no briefing screens at all for demo
1559 mprintf ((0,"Trying briefing screen! %s\n",filename));
1564 if (!load_screen_text(filename, &Briefing_text))
1568 songs_play_song( SONG_BRIEFING, 1 );
1573 set_screen_mode( SCREEN_MENU );
1576 dd_gr_set_current_canvas(NULL),
1577 gr_set_current_canvas(NULL)
1580 mprintf ((0,"Playing briefing screen! %s %d\n",filename,level_num));
1584 if (Mission_list[Current_mission_num].descent_version == 1) {
1585 if (level_num == 1) {
1586 while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1587 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1588 cur_briefing_screen++;
1592 if (!abort_briefing_screens) {
1593 for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREENS; cur_briefing_screen++)
1594 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1595 if (show_briefing_screen(cur_briefing_screen, 0))
1600 show_briefing_screen(level_num,0);
1602 d_free (Briefing_text);
1609 int DefineBriefingBox (char **buf)
1614 n=get_new_message_num (buf);
1616 Assert(n < MAX_BRIEFING_SCREENS);
1618 while (**buf!=' ') {
1623 name[i]='\0'; // slap a delimiter on this guy
1625 strcpy (Briefing_screens[n].bs_name,name);
1626 Briefing_screens[n].level_num=get_new_message_num (buf);
1627 Briefing_screens[n].message_num=get_new_message_num (buf);
1628 Briefing_screens[n].text_ulx=get_new_message_num (buf);
1629 Briefing_screens[n].text_uly=get_new_message_num (buf);
1630 Briefing_screens[n].text_width=get_new_message_num (buf);
1631 Briefing_screens[n].text_height=get_message_num (buf); // NOTICE!!!
1634 Briefing_screens[n].text_ulx*=2;
1635 Briefing_screens[n].text_uly*=2.4;
1636 Briefing_screens[n].text_width*=2;
1637 Briefing_screens[n].text_height*=2.4;
1643 int get_new_message_num(char **message)
1647 while (**message == ' ')
1650 while ((**message >= '0') && (**message <= '9')) {
1651 num = 10*num + **message-'0';