1 /* $Id: titles.c,v 1.13 2002-08-27 08:03:25 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.
343 default: Int3(); // Impossible, illegal value for Animating_bitmap_type
347 curcanv_save = dd_grd_curcanv; dd_grd_curcanv = bitmap_canv,
348 curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv
351 pound_signp = strchr(Bitmap_name, '#');
352 Assert(pound_signp != NULL);
354 dig1 = *(pound_signp+1);
355 dig2 = *(pound_signp+2);
359 num = (dig1-'0')*10 + (dig2-'0');
361 switch (Animating_bitmap_type) {
364 if (num > EXIT_DOOR_MAX) {
367 } else if (num < 0) {
374 if (num > OTHER_THING_MAX)
381 *(pound_signp+1) = (num / 10) + '0';
382 *(pound_signp+2) = (num % 10) + '0';
383 *(pound_signp+3) = 0;
385 *(pound_signp+1) = (num % 10) + '0';
386 *(pound_signp+2) = 0;
391 bi = piggy_find_bitmap(Bitmap_name);
392 bitmap_ptr = &GameBitmaps[bi.index];
396 WIN(DDGRLOCK(dd_grd_curcanv));
397 gr_bitmapm(0, 0, bitmap_ptr);
398 WIN(DDGRUNLOCK(dd_grd_curcanv));
401 dd_grd_curcanv = curcanv_save,
402 grd_curcanv = curcanv_save
406 switch (Animating_bitmap_type) {
408 if (num == EXIT_DOOR_MAX) {
411 } else if (num == 0) {
423 // -----------------------------------------------------------------------------
424 void show_briefing_bitmap(grs_bitmap *bmp)
427 dd_grs_canvas *bitmap_canv, *curcanv_save;
429 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
430 curcanv_save = dd_grd_curcanv;
431 dd_gr_set_current_canvas(bitmap_canv);
432 DDGRLOCK(dd_grd_curcanv);
434 DDGRUNLOCK(dd_grd_curcanv);
435 dd_gr_set_current_canvas(curcanv_save);
437 grs_canvas *curcanv_save, *bitmap_canv;
439 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
440 curcanv_save = grd_curcanv;
441 gr_set_current_canvas(bitmap_canv);
442 gr_bitmapm(0, 0, bmp);
443 gr_set_current_canvas(curcanv_save);
450 // -----------------------------------------------------------------------------
451 void show_spinning_robot_frame(int robot_num)
453 grs_canvas *curcanv_save;
455 if (robot_num != -1) {
456 Robot_angles.h += 150;
458 curcanv_save = grd_curcanv;
459 grd_curcanv = Robot_canv;
460 Assert(Robot_info[robot_num].model_num != -1);
461 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
462 grd_curcanv = curcanv_save;
467 // -----------------------------------------------------------------------------
468 void init_spinning_robot(void) //(int x,int y,int w,int h)
476 int x = rescale_x(138);
477 int y = rescale_y(55);
478 int w = rescale_x(166);
479 int h = rescale_y(138);
482 Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
487 // ---------------------------------------------------------------------------
488 // Returns char width.
489 // If show_robot_flag set, then show a frame of the spinning robot.
490 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
494 static fix start_time=0;
497 message[0] = the_char;
500 if (start_time==0 && timer_get_fixed_seconds()<0)
501 start_time=timer_get_fixed_seconds();
503 gr_get_string_size(message, &w, &h, &aw );
505 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
507 // Draw cursor if there is some delay and caller says to draw cursor
508 if (cursor_flag && delay) {
509 WIN(DDGRLOCK(dd_grd_curcanv));
510 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
511 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
512 WIN(DDGRUNLOCK(dd_grd_curcanv));
516 delay=fixdiv (F1_0,i2f(15));
522 if (RobotPlaying && (delay != 0))
525 while (timer_get_fixed_seconds() < (start_time + delay)) {
526 if (RobotPlaying && delay != 0)
531 show_spinning_robot_frame(robot_num);
534 start_time = timer_get_fixed_seconds();
536 WIN(DDGRLOCK(dd_grd_curcanv));
538 if (cursor_flag && delay) {
539 gr_set_fontcolor(Erase_color, -1);
540 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
543 // Draw the character
544 gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
545 gr_printf(Briefing_text_x, Briefing_text_y, message );
547 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
548 gr_printf(Briefing_text_x+1, Briefing_text_y, message );
549 WIN(DDGRUNLOCK(dd_grd_curcanv));
551 if (delay) gr_update();
553 // if (the_char != ' ')
554 // if (!digi_is_sound_playing(SOUND_MARKER_HIT))
555 // digi_play_sample( SOUND_MARKER_HIT, F1_0 );
560 // -----------------------------------------------------------------------------
561 int load_briefing_screen( int screen_num )
565 WIN(DDGRLOCK(dd_grd_curcanv));
566 if ((pcx_error=pcx_read_fullscr( CurBriefScreenName, New_pal ))!=PCX_ERROR_NONE) {
567 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));
568 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);
569 WIN(DDGRUNLOCK(dd_grd_curcanv));
570 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",CurBriefScreenName, pcx_errormsg(pcx_error), pcx_error);
572 WIN(DDGRUNLOCK(dd_grd_curcanv));
579 int load_new_briefing_screen( char *fname )
583 mprintf ((0,"Loading new briefing %s!\n",fname));
584 strcpy (CurBriefScreenName,fname);
586 //WIN(DEFINE_SCREEN(CurBriefScreenName));
588 if (gr_palette_fade_out( New_pal, 32, 0 ))
591 WIN(DDGRLOCK(dd_grd_curcanv));
592 if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE) {
593 //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE) {
594 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);
595 WIN(DDGRUNLOCK(dd_grd_curcanv));
596 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
598 WIN(DDGRUNLOCK(dd_grd_curcanv));
602 gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
604 if (gr_palette_fade_in( New_pal, 32, 0 ))
606 DoBriefingColorStuff();
613 #define KEY_DELAY_DEFAULT ((F1_0*20)/1000)
615 // -----------------------------------------------------------------------------
616 int get_message_num(char **message)
620 while (**message == ' ')
623 while ((**message >= '0') && (**message <= '9')) {
624 num = 10*num + **message-'0';
628 while (*(*message)++ != 10) // Get and drop eoln
634 // -----------------------------------------------------------------------------
635 void get_message_name(char **message, char *result)
637 while (**message == ' ')
640 while ((**message != ' ') && (**message != 10)) {
641 if (**message != '\n')
642 *result++ = **message;
647 while (*(*message)++ != 10) // Get and drop eoln
653 // -----------------------------------------------------------------------------
654 void flash_cursor(int cursor_flag)
656 if (cursor_flag == 0)
659 WIN(DDGRLOCK(dd_grd_curcanv));
660 if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
661 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
663 gr_set_fontcolor(Erase_color, -1);
665 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
666 WIN(DDGRUNLOCK(dd_grd_curcanv));
669 extern int InitMovieBriefing();
671 // -----------------------------------------------------------------------------
672 // Return true if message got aborted by user (pressed ESC), else return false.
673 int show_d1_briefing_message(int screen_num, char *message)
677 briefing_screen *bsp = &Briefing_screens[screen_num];
678 int delay_count = KEY_DELAY_DEFAULT;
683 int flashing_cursor=0;
685 int text_ulx = rescale_x(bsp->text_ulx);
686 int text_uly = rescale_y(bsp->text_uly);
692 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
693 gr_set_curfont( GAME_FONT );
695 init_char_pos(text_ulx, text_uly);
702 Current_color = get_message_num(&message)-1;
703 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
705 } else if (ch == 'F') { // toggle flashing cursor
706 flashing_cursor = !flashing_cursor;
708 while (*message++ != 10)
710 } else if (ch == 'T') {
711 tab_stop = get_message_num(&message);
712 prev_ch = 10; // read to eoln
713 } else if (ch == 'R') {
714 if (Robot_canv != NULL)
715 {free(Robot_canv); Robot_canv=NULL;}
717 init_spinning_robot();
718 robot_num = get_message_num(&message);
719 prev_ch = 10; // read to eoln
720 } else if (ch == 'N') {
721 //--grs_bitmap *bitmap_ptr;
722 if (Robot_canv != NULL)
723 {free(Robot_canv); Robot_canv=NULL;}
725 get_message_name(&message, Bitmap_name);
726 strcat(Bitmap_name, "#0");
727 Animating_bitmap_type = 0;
729 } else if (ch == 'O') {
730 if (Robot_canv != NULL)
731 {free(Robot_canv); Robot_canv=NULL;}
733 get_message_name(&message, Bitmap_name);
734 strcat(Bitmap_name, "#0");
735 Animating_bitmap_type = 1;
737 } else if (ch == 'B') {
738 char bitmap_name[32];
739 grs_bitmap guy_bitmap;
740 ubyte temp_palette[768];
743 if (Robot_canv != NULL)
744 {free(Robot_canv); Robot_canv=NULL;}
746 get_message_name(&message, bitmap_name);
747 strcat(bitmap_name, ".bbm");
748 gr_init_bitmap_data (&guy_bitmap);
749 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
750 Assert(iff_error == IFF_NO_ERROR);
752 show_briefing_bitmap(&guy_bitmap);
753 gr_free_bitmap_data (&guy_bitmap);
755 // } else if (ch == 'B') {
756 // if (Robot_canv != NULL)
757 // {free(Robot_canv); Robot_canv=NULL;}
759 // bitmap_num = get_message_num(&message);
760 // if (bitmap_num != -1)
761 // show_briefing_bitmap(Textures[bitmap_num]);
762 // prev_ch = 10; // read to eoln
763 } else if (ch == 'S') {
768 start_time = timer_get_fixed_seconds();
769 start_time = timer_get_approx_seconds();
770 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
772 //added on 9/13/98 by adb to make arch's requiring updates work
776 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
777 if ( timer_get_approx_seconds() > time_out_value ) {
779 break; // Time out after 1 minute..
781 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
783 flash_cursor(flashing_cursor);
784 show_spinning_robot_frame(robot_num);
787 //added on 9/13/98 by adb to make arch's requiring updates work
791 start_time += KEY_DELAY_DEFAULT/2;
795 if (keypress == KEY_BACKSP)
798 if (keypress == KEY_ESC)
803 } else if (ch == 'P') { // New page.
805 while (*message != 10) {
806 message++; // drop carriage return after special escape sequence
811 } else if (ch == '$' || ch == ';') { // Print a $/;
813 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
817 } else if (ch == '\t') { // Tab
818 if (Briefing_text_x - text_ulx < tab_stop)
819 Briefing_text_x = text_ulx + tab_stop;
820 } else if ((ch == ';') && (prev_ch == 10)) {
821 while (*message++ != 10)
824 } else if (ch == '\\') {
826 } else if (ch == 10) {
827 if (prev_ch != '\\') {
829 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
830 Briefing_text_x = text_ulx;
831 if (Briefing_text_y > text_uly + rescale_y(bsp->text_height)) {
832 load_briefing_screen(screen_num);
833 Briefing_text_x = text_ulx;
834 Briefing_text_y = text_uly;
843 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
846 //added/changed on 9/13/98 by adb to speed up briefings after pressing a key with SDL
847 // Check for Esc -> abort.
849 key_check=local_key_inkey();
853 if ( key_check == KEY_ESC ) {
859 if ( key_check == KEY_ALTED+KEY_F2 )
863 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
866 if (Briefing_text_x > text_ulx + rescale_x(bsp->text_width)) {
867 Briefing_text_x = text_ulx;
868 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
871 if ((new_page) || (Briefing_text_y > text_uly + rescale_y(bsp->text_height))) {
873 fix time_out_value = 0;
877 start_time = timer_get_approx_seconds();
878 time_out_value = start_time + i2f(60*5); // Wait 1 minute...
880 //added on 9/13/98 by adb to make arch's requiring updates work
884 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
885 if ( timer_get_approx_seconds() > time_out_value ) {
887 break; // Time out after 1 minute..
889 while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
891 flash_cursor(flashing_cursor);
892 show_spinning_robot_frame(robot_num);
895 //added on 9/13/98 by adb to make arch's requiring updates work
899 start_time += KEY_DELAY_DEFAULT/2;
905 if (keypress == KEY_BACKSP)
908 if (keypress == KEY_ESC) {
913 load_briefing_screen(screen_num);
914 Briefing_text_x = text_ulx;
915 Briefing_text_y = text_uly;
916 delay_count = KEY_DELAY_DEFAULT;
920 if (Robot_canv != NULL)
921 {free(Robot_canv); Robot_canv=NULL;}
926 // -----------------------------------------------------------------------------
927 // Return true if message got aborted by user (pressed ESC), else return false.
928 int show_briefing_message(int screen_num, char *message)
932 briefing_screen *bsp = &Briefing_screens[screen_num];
933 int delay_count = KEY_DELAY_DEFAULT;
937 static int tab_stop=0;
938 int flashing_cursor=0;
939 int new_page=0,GotZ=0;
941 char spinRobotName[]="rba.mve",kludge; // matt don't change this!
946 int hum_channel=-1,printing_channel=-1;
947 int LineAdjustment=1;
948 WIN(int wpage_done=0);
959 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
962 // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
963 gr_set_curfont( GAME_FONT );
965 bsp=&Briefing_screens[0];
966 init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
973 screen_num=DefineBriefingBox (&message);
974 //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
976 bsp = &Briefing_screens[screen_num];
977 init_char_pos(bsp->text_ulx, bsp->text_uly);
979 prev_ch = 10; // read to eoln
980 } else if (ch=='U') {
981 screen_num=get_message_num(&message);
982 bsp = &Briefing_screens[screen_num];
983 init_char_pos(bsp->text_ulx, bsp->text_uly);
984 prev_ch = 10; // read to eoln
985 } else if (ch == 'C') {
986 Current_color = get_message_num(&message)-1;
987 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
989 } else if (ch == 'F') { // toggle flashing cursor
990 flashing_cursor = !flashing_cursor;
992 while (*message++ != 10)
994 } else if (ch == 'T') {
995 tab_stop = get_message_num(&message);
996 tab_stop*=(1+MenuHires);
997 prev_ch = 10; // read to eoln
998 } else if (ch == 'R') {
999 if (Robot_canv != NULL) {
1010 spinRobotName[2]=kludge; // ugly but proud
1012 RobotPlaying=InitRobotMovie(spinRobotName);
1014 // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
1017 DoBriefingColorStuff ();
1018 mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
1021 init_spinning_robot();
1022 robot_num = get_message_num(&message);
1024 prev_ch = 10; // read to eoln
1025 } else if (ch == 'N') {
1026 //--grs_bitmap *bitmap_ptr;
1027 if (Robot_canv != NULL) {
1032 get_message_name(&message, Bitmap_name);
1033 strcat(Bitmap_name, "#0");
1034 Animating_bitmap_type = 0;
1036 } else if (ch == 'O') {
1037 if (Robot_canv != NULL) {
1042 get_message_name(&message, Bitmap_name);
1043 strcat(Bitmap_name, "#0");
1044 Animating_bitmap_type = 1;
1046 } else if (ch=='A') {
1047 LineAdjustment=1-LineAdjustment;
1048 } else if (ch=='Z') {
1049 //mprintf ((0,"Got a Z!\n"));
1051 #if defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
1054 if (LineAdjustment==1)
1061 while ((fname[i]=*message) != '\n') {
1071 while (fname[i]!='.')
1072 fname2[i] = fname[i++];
1082 load_new_briefing_screen (cfexist(fname2)?fname2:fname);
1084 load_new_briefing_screen (fname);
1086 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1088 } else if (ch == 'B') {
1089 char bitmap_name[32];
1090 grs_bitmap guy_bitmap;
1091 ubyte temp_palette[768];
1094 if (Robot_canv != NULL) {
1099 get_message_name(&message, bitmap_name);
1100 strcat(bitmap_name, ".bbm");
1101 guy_bitmap.bm_data = NULL;
1102 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
1103 Assert(iff_error == IFF_NO_ERROR);
1104 gr_remap_bitmap_good( &guy_bitmap, temp_palette, -1, -1 );
1106 show_briefing_bitmap(&guy_bitmap);
1107 d_free(guy_bitmap.bm_data);
1109 // } else if (ch==EOF) {
1111 // } else if (ch == 'B') {
1112 // if (Robot_canv != NULL) {
1113 // d_free(Robot_canv);
1117 // bitmap_num = get_message_num(&message);
1118 // if (bitmap_num != -1)
1119 // show_briefing_bitmap(Textures[bitmap_num]);
1120 // prev_ch = 10; // read to eoln
1121 } else if (ch == 'S') {
1126 if (printing_channel>-1)
1127 digi_stop_sound( printing_channel );
1128 printing_channel=-1;
1137 start_time = timer_get_fixed_seconds();
1138 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1140 if (_RedrawScreen) {
1141 _RedrawScreen = FALSE;
1142 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1148 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1150 flash_cursor(flashing_cursor);
1156 show_spinning_robot_frame(robot_num);
1159 show_bitmap_frame();
1160 start_time += KEY_DELAY_DEFAULT/2;
1164 if (keypress == KEY_BACKSP)
1167 if (keypress == KEY_ESC)
1170 flashing_cursor = 0;
1172 WIN(wpage_done = 0);
1173 } else if (ch == 'P') { // New page.
1175 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1176 // printing to it! You know, $Z !!!
1177 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1181 while (*message != 10) {
1182 message++; // drop carriage return after special escape sequence
1188 } else if (ch == '\t') { // Tab
1189 if (Briefing_text_x - bsp->text_ulx < tab_stop)
1190 Briefing_text_x = bsp->text_ulx + tab_stop;
1191 } else if ((ch == ';') && (prev_ch == 10)) {
1192 while (*message++ != 10)
1195 } else if (ch == '\\') {
1197 } else if (ch == 10) {
1198 if (prev_ch != '\\') {
1200 if (1) //DumbAdjust==0)
1201 Briefing_text_y += (8*(MenuHires+1));
1204 Briefing_text_x = bsp->text_ulx;
1205 if (Briefing_text_y > bsp->text_uly + bsp->text_height) {
1206 load_briefing_screen(screen_num);
1207 Briefing_text_x = bsp->text_ulx;
1208 Briefing_text_y = bsp->text_uly;
1211 if (ch == 13) //Can this happen? Above says ch==10
1218 Int3(); // Hey ryan!!!! You gotta load a screen before you start
1219 // printing to it! You know, $Z !!!
1220 load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1226 printing_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
1230 WIN(if (GRMODEINFO(emul)) delay_count = 0);
1232 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
1236 // Check for Esc -> abort.
1238 key_check=local_key_inkey();
1243 if (_RedrawScreen) {
1244 _RedrawScreen = FALSE;
1245 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1246 key_check = KEY_ESC;
1249 if ( key_check == KEY_ESC ) {
1254 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
1257 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
1258 Briefing_text_x = bsp->text_ulx;
1259 Briefing_text_y += bsp->text_uly;
1262 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
1268 if (printing_channel>-1)
1269 digi_stop_sound( printing_channel );
1270 printing_channel=-1;
1281 start_time = timer_get_fixed_seconds();
1282 while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key
1284 if (_RedrawScreen) {
1285 _RedrawScreen = FALSE;
1286 hum_channel = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1292 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1294 flash_cursor(flashing_cursor);
1299 show_spinning_robot_frame(robot_num);
1301 show_bitmap_frame();
1302 start_time += KEY_DELAY_DEFAULT/2;
1313 if (keypress == KEY_BACKSP)
1316 if (keypress == KEY_ESC) {
1321 load_briefing_screen(screen_num);
1322 Briefing_text_x = bsp->text_ulx;
1323 Briefing_text_y = bsp->text_uly;
1324 delay_count = KEY_DELAY_DEFAULT;
1326 WIN(wpage_done = 0);
1337 if (Robot_canv != NULL)
1338 {d_free(Robot_canv); Robot_canv=NULL;}
1341 digi_stop_sound( hum_channel );
1342 if (printing_channel>-1)
1343 digi_stop_sound( printing_channel );
1348 //-----------------------------------------------------------------------------
1349 // Return a pointer to the start of text for screen #screen_num.
1350 char * get_briefing_message(int screen_num)
1352 char *tptr = Briefing_text;
1356 Assert(screen_num >= 0);
1358 while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1363 cur_screen = get_message_num(&tptr);
1367 if (screen_num!=cur_screen)
1373 //-----------------------------------------------------------------------------
1374 // Load Descent briefing text.
1375 int load_screen_text(char *filename, char **buf)
1380 int have_binary = 0;
1382 if ((tfile = cfopen(filename,"rb")) == NULL) {
1383 char nfilename[30], *ptr;
1385 strcpy(nfilename, filename);
1386 ptr = strrchr(nfilename, '.');
1388 strcat(nfilename, ".txb");
1389 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1390 mprintf ((0,"can't open %s!\n",nfilename));
1392 //Error("Cannot open file %s or %s", filename, nfilename);
1395 mprintf ((0,"reading...\n"));
1398 len = cfilelength(ifile);
1399 MALLOC(*buf, char, len+500);
1400 mprintf ((0,"len=%d\n",len));
1401 for (x=0, i=0; i < len; i++, x++) {
1402 cfread (*buf+x,1,1,ifile);
1403 // mprintf ((0,"%c",*(*buf+x)));
1410 len = cfilelength(tfile);
1411 MALLOC(*buf, char, len+500);
1412 for (x=0, i=0; i < len; i++, x++) {
1413 cfread (*buf+x,1,1,tfile);
1414 // mprintf ((0,"%c",*(*buf+x)));
1420 //cfread(*buf, 1, len, tfile);
1427 for (i = 0, ptr = *buf; i < len; i++, ptr++) {
1429 encode_rotate_left(ptr);
1430 *ptr = *ptr ^ BITMAP_TBL_XOR;
1431 encode_rotate_left(ptr);
1439 //-----------------------------------------------------------------------------
1440 // Return true if message got aborted, else return false.
1441 int show_briefing_text(int screen_num)
1445 message_ptr = get_briefing_message(screen_num);
1446 if (message_ptr==NULL)
1449 DoBriefingColorStuff();
1451 if (Mission_list[Current_mission_num].descent_version == 1)
1452 return show_d1_briefing_message(screen_num, message_ptr);
1454 return show_briefing_message(screen_num, message_ptr);
1457 void DoBriefingColorStuff ()
1459 Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1460 Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1462 Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1463 Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1465 Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1466 Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1468 Erase_color = gr_find_closest_color_current(0, 0, 0);
1471 //-----------------------------------------------------------------------------
1472 // Return true if screen got aborted by user, else return false.
1473 int show_briefing_screen( int screen_num, int allow_keys)
1476 ubyte palette_save[768];
1478 New_pal_254_bash = 0;
1480 if (Skip_briefing_screens) {
1481 mprintf((0, "Skipping briefing screen [brief03.pcx]\n"));
1485 // briefing_bm.bm_data=NULL;
1486 // if ((pcx_error=pcx_read_bitmap( "brief03.pcx", &briefing_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) {
1487 // 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));
1492 memcpy(palette_save,gr_palette,sizeof(palette_save));
1493 memcpy(New_pal,gr_palette,sizeof(gr_palette));
1496 // vfx_set_palette_sub( New_pal );
1497 // gr_palette_clear();
1498 // gr_bitmap( 0, 0, &briefing_bm );
1500 gr_palette_load(New_pal);
1503 // if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1505 // memcpy(gr_palette,New_pal,sizeof(gr_palette));
1508 key_close(); // kill the keyboard handler during briefing screens for movies
1510 rval = show_briefing_text(screen_num);
1515 #if defined (MACINTOSH) || defined(WINDOWS)
1516 memcpy(New_pal,gr_palette,sizeof(gr_palette)); // attempt to get fades after briefing screens done correctly.
1521 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1524 DEFINE_SCREEN(NULL);
1525 WIN(DDGRLOCK(dd_grd_curcanv));
1526 gr_clear_canvas (0);
1527 WIN(DDGRUNLOCK(dd_grd_curcanv));
1528 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1532 gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1534 // d_free(briefing_bm.bm_data);
1540 // -----------------------------------------------------------------------------
1541 void do_briefing_screens(char *filename,int level_num)
1543 int abort_briefing_screens = 0;
1544 int cur_briefing_screen = 0;
1548 if (Skip_briefing_screens) {
1549 mprintf((0, "Skipping all briefing screens.\n"));
1554 return; // no briefing screens at all for demo
1558 mprintf ((0,"Trying briefing screen! %s\n",filename));
1563 if (!load_screen_text(filename, &Briefing_text))
1567 songs_play_song( SONG_BRIEFING, 1 );
1572 set_screen_mode( SCREEN_MENU );
1575 dd_gr_set_current_canvas(NULL),
1576 gr_set_current_canvas(NULL)
1579 mprintf ((0,"Playing briefing screen! %s %d\n",filename,level_num));
1583 if (Mission_list[Current_mission_num].descent_version == 1) {
1584 if (level_num == 1) {
1585 while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1586 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1587 cur_briefing_screen++;
1591 if (!abort_briefing_screens) {
1592 for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREENS; cur_briefing_screen++)
1593 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1594 if (show_briefing_screen(cur_briefing_screen, 0))
1599 show_briefing_screen(level_num,0);
1601 d_free (Briefing_text);
1608 int DefineBriefingBox (char **buf)
1613 n=get_new_message_num (buf);
1615 Assert(n < MAX_BRIEFING_SCREENS);
1617 while (**buf!=' ') {
1622 name[i]='\0'; // slap a delimiter on this guy
1624 strcpy (Briefing_screens[n].bs_name,name);
1625 Briefing_screens[n].level_num=get_new_message_num (buf);
1626 Briefing_screens[n].message_num=get_new_message_num (buf);
1627 Briefing_screens[n].text_ulx=get_new_message_num (buf);
1628 Briefing_screens[n].text_uly=get_new_message_num (buf);
1629 Briefing_screens[n].text_width=get_new_message_num (buf);
1630 Briefing_screens[n].text_height=get_message_num (buf); // NOTICE!!!
1633 Briefing_screens[n].text_ulx*=2;
1634 Briefing_screens[n].text_uly*=2.4;
1635 Briefing_screens[n].text_width*=2;
1636 Briefing_screens[n].text_height*=2.4;
1642 int get_new_message_num(char **message)
1646 while (**message == ' ')
1649 while ((**message >= '0') && (**message <= '9')) {
1650 num = 10*num + **message-'0';