]> icculus.org git repositories - btb/d2x.git/blob - main/titles.c
fixed crash when using shareware data files without -nohires
[btb/d2x.git] / main / titles.c
1 /* $Id: titles.c,v 1.20 2003-02-23 06:10:59 btb Exp $ */
2 /*
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.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include <conf.h>
17 #endif
18
19 #define ROBOT_MOVIES
20
21 #ifdef WINDOWS
22 #include "desw.h"
23 #endif
24
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #ifdef MACINTOSH
30 #include <Events.h>
31 #endif
32
33 #include "pa_enabl.h"                   //$$POLY_ACC
34 #include "pstypes.h"
35 #include "timer.h"
36 #include "key.h"
37 #include "gr.h"
38 #include "palette.h"
39 #include "iff.h"
40 #include "pcx.h"
41 #include "u_mem.h"
42 #include "joy.h"
43 #include "mono.h"
44 #include "gamefont.h"
45 #include "cfile.h"
46 #include "error.h"
47 #include "polyobj.h"
48 #include "textures.h"
49 #include "screens.h"
50 #include "multi.h"
51 #include "player.h"
52 #include "digi.h"
53 #include "compbit.h"
54 #include "text.h"
55 #include "kmatrix.h"
56 #include "piggy.h"
57 #include "songs.h"
58 #include "newmenu.h"
59 #include "state.h"
60 #ifdef ROBOT_MOVIES
61 #include "movie.h"
62 #endif
63 #include "menu.h"
64
65 #if defined(POLY_ACC)
66 #include "poly_acc.h"
67 #endif
68
69
70 void DoBriefingColorStuff ();
71 int get_new_message_num(char **message);
72 int DefineBriefingBox (char **buf);
73
74 extern unsigned RobSX,RobSY,RobDX,RobDY; // Robot movie coords
75
76 ubyte New_pal[768];
77 int     New_pal_254_bash;
78
79 char CurBriefScreenName[15]="brief03.pcx";
80 char    * Briefing_text;
81 #ifdef ROBOT_MOVIES
82 char RobotPlaying=0;
83 #endif
84
85 #define MAX_BRIEFING_COLORS     3
86
87 // Descent 1 briefings
88 char Ending_text_filename[13] = "\0";
89 char Briefing_text_filename[13] = "\0";
90
91 #define SHAREWARE_ENDING_FILENAME       "ending.tex"
92
93 //      Can be set by -noscreens command line option.  Causes bypassing of all briefing screens.
94 int     Skip_briefing_screens=0;
95 int     Briefing_foreground_colors[MAX_BRIEFING_COLORS], Briefing_background_colors[MAX_BRIEFING_COLORS];
96 int     Current_color = 0;
97 int     Erase_color;
98
99 extern int check_button_press();
100
101 #ifdef MACINTOSH
102 extern void macintosh_quit(void);
103 #endif
104
105 static int rescale_x(int x)
106 {
107         return x * GWIDTH / 320;
108 }
109
110 static int rescale_y(int y)
111 {
112         return y * GHEIGHT / 200;
113 }
114
115 #ifndef MACINTOSH
116 int local_key_inkey(void)
117 {
118         int     rval;
119
120 #ifdef WINDOWS
121         MSG msg;
122
123         DoMessageStuff(&msg);
124 #endif
125
126         rval = key_inkey();
127
128         if (rval == KEY_PRINT_SCREEN) {
129                 #ifdef POLY_ACC
130 #ifdef ROBOT_MOVIES
131                 if (RobotPlaying) {
132                         gr_palette_read(gr_palette);
133                         gr_copy_palette(gr_palette,gr_palette,0);       //reset color lookup cache
134                 }
135 #endif
136                 #endif
137                 save_screen_shot(0);
138                 return 0;                               //say no key pressed
139         }
140
141         if (check_button_press())               //joystick or mouse button pressed?
142                 rval = KEY_SPACEBAR;
143
144         #ifdef MACINTOSH
145         if ( rval == KEY_Q+KEY_COMMAND )
146                 macintosh_quit();
147         #endif
148
149         return rval;
150 }
151 #else
152 int local_key_inkey(void)
153 {
154         EventRecord event;
155         int     rval;
156
157         if (!GetOSEvent(everyEvent, &event))
158                 return 0;
159
160         if (event.what != keyDown)
161                 return 0;
162
163         rval = (int)((event.message & keyCodeMask) >> 8);
164
165         if (rval == KEY_PRINT_SCREEN) {
166                 save_screen_shot(0);
167                 return 0;                               //say no key pressed
168         }
169
170         if (check_button_press())               //joystick or mouse button pressed?
171                 rval = KEY_SPACEBAR;
172
173         #ifdef MACINTOSH
174         if ( rval == KEY_Q+KEY_COMMAND )
175                 macintosh_quit();
176         #endif
177
178         return rval;
179 }
180 #endif
181
182 int show_title_screen( char * filename, int allow_keys, int from_hog_only )
183 {
184         fix timer;
185         int pcx_error;
186         grs_bitmap title_bm;
187         ubyte   palette_save[768];
188         char new_filename[FILENAME_LEN+1] = "";
189
190         #ifdef RELEASE
191         if (from_hog_only)
192                 strcpy(new_filename,"\x01");    //only read from hog file
193         #endif
194
195         strcat(new_filename,filename);
196         filename = new_filename;
197
198         title_bm.bm_data=NULL;
199         if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE)     {
200                 printf( "File '%s', PCX load error: %s (%i)\n  (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error);
201                 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));
202                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error);
203         }
204
205         memcpy(palette_save,gr_palette,sizeof(palette_save));
206
207 #if defined(POLY_ACC)
208     pa_save_clut();
209     pa_update_clut(New_pal, 0, 256, 0);
210 #endif
211
212         //vfx_set_palette_sub( New_pal );
213 #ifdef OGL
214         gr_palette_load( New_pal );
215 #else
216         gr_palette_clear();
217 #endif
218
219         WINDOS(
220                 dd_gr_set_current_canvas(NULL),
221                 gr_set_current_canvas( NULL )
222         );
223         WIN(DDGRLOCK(dd_grd_curcanv));
224         show_fullscr(&title_bm);
225         WIN(DDGRUNLOCK(dd_grd_curcanv));
226
227         WIN(DDGRRESTORE);
228
229 #if defined(POLY_ACC)
230     pa_restore_clut();
231 #endif
232
233         if (gr_palette_fade_in( New_pal, 32, allow_keys ))
234                 return 1;
235         gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
236
237         gr_palette_load( New_pal );
238         timer   = timer_get_fixed_seconds() + i2f(3);
239         while (1) {
240                 if ( local_key_inkey() && allow_keys ) break;
241                 if ( timer_get_fixed_seconds() > timer ) break;
242         }
243         if (gr_palette_fade_out( New_pal, 32, allow_keys ))
244                 return 1;
245         gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
246         d_free(title_bm.bm_data);
247         return 0;
248 }
249
250 typedef struct {
251         char    bs_name[14];                //  filename, eg merc01.  Assumes .lbm suffix.
252         byte    level_num;
253         byte    message_num;
254         short   text_ulx, text_uly;         //  upper left x,y of text window
255         short   text_width, text_height;    //  width and height of text window
256 } briefing_screen;
257
258 #define BRIEFING_SECRET_NUM 31          //  This must correspond to the first secret level which must come at the end of the list.
259 #define BRIEFING_OFFSET_NUM 4           // This must correspond to the first level screen (ie, past the bald guy briefing screens)
260
261 #define SHAREWARE_ENDING_LEVEL_NUM  0x7f
262 #define REGISTERED_ENDING_LEVEL_NUM 0x7e
263
264 #ifdef SHAREWARE
265 #define ENDING_LEVEL_NUM        SHAREWARE_ENDING_LEVEL_NUM
266 #else
267 #define ENDING_LEVEL_NUM        REGISTERED_ENDING_LEVEL_NUM
268 #endif
269
270 #define MAX_BRIEFING_SCREENS 60
271
272 briefing_screen Briefing_screens[MAX_BRIEFING_SCREENS]=
273  {{"brief03.pcx",0,3,8,8,257,177}}; // default=0!!!
274
275 int     Briefing_text_x, Briefing_text_y;
276
277 void init_char_pos(int x, int y)
278 {
279         Briefing_text_x = x;
280         Briefing_text_y = y;
281         mprintf ((0,"Setting init x=%d y=%d\n",x,y));
282 }
283
284 grs_canvas      *Robot_canv = NULL;
285 vms_angvec      Robot_angles;
286
287 char    Bitmap_name[32] = "";
288 #define EXIT_DOOR_MAX   14
289 #define OTHER_THING_MAX 10      //  Adam: This is the number of frames in your new animating thing.
290 #define DOOR_DIV_INIT   6
291 byte    Door_dir=1, Door_div_count=0, Animating_bitmap_type=0;
292
293 //-----------------------------------------------------------------------------
294 void show_bitmap_frame(void)
295 {
296 #ifdef WINDOWS
297         dd_grs_canvas *curcanv_save, *bitmap_canv=0;
298 #else
299         grs_canvas *curcanv_save, *bitmap_canv=0;
300 #endif
301
302         grs_bitmap *bitmap_ptr;
303
304         //      Only plot every nth frame.
305         if (Door_div_count) {
306                 Door_div_count--;
307                 return;
308         }
309
310         Door_div_count = DOOR_DIV_INIT;
311
312         if (Bitmap_name[0] != 0) {
313                 char            *pound_signp;
314                 int             num, dig1, dig2;
315
316                 //      Set supertransparency color to black
317                 if (!New_pal_254_bash) {
318                         New_pal_254_bash = 1;
319                         New_pal[254*3] = 0;
320                         New_pal[254*3+1] = 0;
321                         New_pal[254*3+2] = 0;
322                         gr_palette_load( New_pal );
323                 }
324
325                 switch (Animating_bitmap_type) {
326                 case 0:
327                         WINDOS(
328                                 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 64, 64); break,
329                                 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 64, 64);       break
330                         );
331                 case 1:
332                         WINDOS(
333                                 bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, 94, 94); break,
334                                 bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, 94, 94);       break
335                         );
336
337                         // Adam: Change here for your new animating bitmap thing. 94, 94 are bitmap size.
338                         default:
339                                 Int3(); // Impossible, illegal value for Animating_bitmap_type
340                 }
341
342                 WINDOS(
343                         curcanv_save = dd_grd_curcanv; dd_grd_curcanv = bitmap_canv,
344                         curcanv_save = grd_curcanv; grd_curcanv = bitmap_canv
345                 );
346
347                 pound_signp = strchr(Bitmap_name, '#');
348                 Assert(pound_signp != NULL);
349
350                 dig1 = *(pound_signp+1);
351                 dig2 = *(pound_signp+2);
352                 if (dig2 == 0)
353                         num = dig1-'0';
354                 else
355                         num = (dig1-'0')*10 + (dig2-'0');
356
357                 switch (Animating_bitmap_type) {
358                 case 0:
359                         num += Door_dir;
360                         if (num > EXIT_DOOR_MAX) {
361                                 num = EXIT_DOOR_MAX;
362                                 Door_dir = -1;
363                         } else if (num < 0) {
364                                 num = 0;
365                                 Door_dir = 1;
366                         }
367                         break;
368                 case 1:
369                         num++;
370                         if (num > OTHER_THING_MAX)
371                                 num = 0;
372                         break;
373                 }
374
375                 Assert(num < 100);
376                 if (num >= 10) {
377                         *(pound_signp+1) = (num / 10) + '0';
378                         *(pound_signp+2) = (num % 10) + '0';
379                         *(pound_signp+3) = 0;
380                 } else {
381                         *(pound_signp+1) = (num % 10) + '0';
382                         *(pound_signp+2) = 0;
383                 }
384
385                 {
386                         bitmap_index bi;
387                         bi = piggy_find_bitmap(Bitmap_name);
388                         bitmap_ptr = &GameBitmaps[bi.index];
389                         PIGGY_PAGE_IN( bi );
390                 }
391
392                 WIN(DDGRLOCK(dd_grd_curcanv));
393                 gr_bitmapm(0, 0, bitmap_ptr);
394                 WIN(DDGRUNLOCK(dd_grd_curcanv));
395
396                 WINDOS(
397                         dd_grd_curcanv = curcanv_save,
398                         grd_curcanv = curcanv_save
399                 );
400                 d_free(bitmap_canv);
401
402                 switch (Animating_bitmap_type) {
403                 case 0:
404                         if (num == EXIT_DOOR_MAX) {
405                                 Door_dir = -1;
406                                 Door_div_count = 64;
407                         } else if (num == 0) {
408                                 Door_dir = 1;
409                                 Door_div_count = 64;
410                         }
411                         break;
412                 case 1:
413                         break;
414                 }
415         }
416
417 }
418
419 //-----------------------------------------------------------------------------
420 void show_briefing_bitmap(grs_bitmap *bmp)
421 {
422 #ifdef WINDOWS
423         dd_grs_canvas *bitmap_canv, *curcanv_save;
424
425         bitmap_canv = dd_gr_create_sub_canvas(dd_grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
426         curcanv_save = dd_grd_curcanv;
427         dd_gr_set_current_canvas(bitmap_canv);
428         DDGRLOCK(dd_grd_curcanv);
429         gr_bitmapm(0,0,bmp);
430         DDGRUNLOCK(dd_grd_curcanv);
431         dd_gr_set_current_canvas(curcanv_save);
432 #else
433         grs_canvas      *curcanv_save, *bitmap_canv;
434
435         bitmap_canv = gr_create_sub_canvas(grd_curcanv, 220, 45, bmp->bm_w, bmp->bm_h);
436         curcanv_save = grd_curcanv;
437         gr_set_current_canvas(bitmap_canv);
438         gr_bitmapm(0, 0, bmp);
439         gr_set_current_canvas(curcanv_save);
440 #endif
441
442         d_free(bitmap_canv);
443 }
444
445 #ifndef WINDOWS
446 //-----------------------------------------------------------------------------
447 void show_spinning_robot_frame(int robot_num)
448 {
449         grs_canvas      *curcanv_save;
450
451         if (robot_num != -1) {
452                 Robot_angles.h += 150;
453
454                 curcanv_save = grd_curcanv;
455                 grd_curcanv = Robot_canv;
456                 Assert(Robot_info[robot_num].model_num != -1);
457                 draw_model_picture(Robot_info[robot_num].model_num, &Robot_angles);
458                 grd_curcanv = curcanv_save;
459         }
460
461 }
462
463 //-----------------------------------------------------------------------------
464 void init_spinning_robot(void) //(int x,int y,int w,int h)
465 {
466 #if 0
467         Robot_angles.p += 0;
468         Robot_angles.b += 0;
469         Robot_angles.h += 0;
470
471 #else
472         int x = rescale_x(138);
473         int y = rescale_y(55);
474         int w = rescale_x(166);
475         int h = rescale_y(138);
476 #endif
477
478         Robot_canv = gr_create_sub_canvas(grd_curcanv, x, y, w, h);
479         // 138, 55, 166, 138
480 }
481 #endif
482
483 //---------------------------------------------------------------------------
484 // Returns char width.
485 // If show_robot_flag set, then show a frame of the spinning robot.
486 int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag)
487 {
488         int w, h, aw;
489         char message[2];
490         static fix      start_time=0;
491
492         robot_num=0;
493         message[0] = the_char;
494         message[1] = 0;
495
496         if (start_time==0 && timer_get_fixed_seconds()<0)
497                 start_time=timer_get_fixed_seconds();
498
499         gr_get_string_size(message, &w, &h, &aw );
500
501         Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
502
503         //      Draw cursor if there is some delay and caller says to draw cursor
504         if (cursor_flag && delay) {
505                 WIN(DDGRLOCK(dd_grd_curcanv));
506                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
507                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
508                 WIN(DDGRUNLOCK(dd_grd_curcanv));
509         }
510
511         if (delay)
512                 delay=fixdiv (F1_0,i2f(15));
513
514         if (delay != 0)
515                 show_bitmap_frame();
516
517 #ifdef ROBOT_MOVIES
518         if (RobotPlaying && (delay != 0))
519                 RotateRobot();
520
521         while (timer_get_fixed_seconds() < (start_time + delay)) {
522                 if (RobotPlaying && delay != 0)
523                         RotateRobot();
524         }
525 #else
526         if (robot_num != -1)
527                 show_spinning_robot_frame(robot_num);
528 #endif
529
530         start_time = timer_get_fixed_seconds();
531
532         WIN(DDGRLOCK(dd_grd_curcanv));
533         //      Erase cursor
534         if (cursor_flag && delay) {
535                 gr_set_fontcolor(Erase_color, -1);
536                 gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
537         }
538
539         //      Draw the character
540         gr_set_fontcolor(Briefing_background_colors[Current_color], -1);
541         gr_printf(Briefing_text_x, Briefing_text_y, message );
542
543         gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
544         gr_printf(Briefing_text_x+1, Briefing_text_y, message );
545         WIN(DDGRUNLOCK(dd_grd_curcanv));
546
547         if (delay) gr_update();
548
549 //      if (the_char != ' ')
550 //              if (!digi_is_sound_playing(SOUND_MARKER_HIT))
551 //                      digi_play_sample( SOUND_MARKER_HIT, F1_0 );
552
553         return w;
554 }
555
556 //-----------------------------------------------------------------------------
557 int load_briefing_screen( int screen_num )
558 {
559         int     pcx_error;
560
561         WIN(DDGRLOCK(dd_grd_curcanv));
562         if ((pcx_error=pcx_read_fullscr( CurBriefScreenName, New_pal ))!=PCX_ERROR_NONE) {
563                 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));
564                 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);
565                 WIN(DDGRUNLOCK(dd_grd_curcanv));
566                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",CurBriefScreenName, pcx_errormsg(pcx_error), pcx_error);
567         }
568         WIN(DDGRUNLOCK(dd_grd_curcanv));
569
570         WIN(DDGRRESTORE);
571
572         return 0;
573 }
574
575 int load_new_briefing_screen( char *fname )
576 {
577         int pcx_error;
578
579         mprintf ((0,"Loading new briefing <%s>\n",fname));
580         strcpy (CurBriefScreenName,fname);
581
582         //WIN(DEFINE_SCREEN(CurBriefScreenName));
583
584         if (gr_palette_fade_out( New_pal, 32, 0 ))
585                 return 0;
586
587         WIN(DDGRLOCK(dd_grd_curcanv));
588         if ((pcx_error=pcx_read_fullscr( fname, New_pal ))!=PCX_ERROR_NONE)     {
589         //if ((pcx_error=pcx_read_bitmap( fname, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, New_pal ))!=PCX_ERROR_NONE)     {
590                 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);
591                 WIN(DDGRUNLOCK(dd_grd_curcanv));
592                 Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",fname, pcx_errormsg(pcx_error), pcx_error);
593         }
594         WIN(DDGRUNLOCK(dd_grd_curcanv));
595
596         WIN(DDGRRESTORE);
597
598         gr_copy_palette(gr_palette, New_pal, sizeof(gr_palette));
599
600         if (gr_palette_fade_in( New_pal, 32, 0 ))
601                 return 0;
602         DoBriefingColorStuff();
603
604         return 1;
605 }
606
607
608
609 #define KEY_DELAY_DEFAULT       ((F1_0*20)/1000)
610
611 //-----------------------------------------------------------------------------
612 int get_message_num(char **message)
613 {
614         int     num=0;
615
616         while (**message == ' ')
617                 (*message)++;
618
619         while ((**message >= '0') && (**message <= '9')) {
620                 num = 10*num + **message-'0';
621                 (*message)++;
622         }
623
624         while (*(*message)++ != 10)             //      Get and drop eoln
625                 ;
626
627         return num;
628 }
629
630 //-----------------------------------------------------------------------------
631 void get_message_name(char **message, char *result)
632 {
633         while (**message == ' ')
634                 (*message)++;
635
636         while ((**message != ' ') && (**message != 10)) {
637                 if (**message != '\n')
638                         *result++ = **message;
639                 (*message)++;
640         }
641
642         if (**message != 10)
643                 while (*(*message)++ != 10)             //      Get and drop eoln
644                         ;
645
646         *result = 0;
647 }
648
649 //-----------------------------------------------------------------------------
650 void flash_cursor(int cursor_flag)
651 {
652         if (cursor_flag == 0)
653                 return;
654
655 WIN(DDGRLOCK(dd_grd_curcanv));
656         if ((timer_get_fixed_seconds() % (F1_0/2) ) > (F1_0/4))
657                 gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1);
658         else
659                 gr_set_fontcolor(Erase_color, -1);
660
661         gr_printf(Briefing_text_x+1, Briefing_text_y, "_" );
662 WIN(DDGRUNLOCK(dd_grd_curcanv));
663 }
664
665 extern int InitMovieBriefing();
666
667 //-----------------------------------------------------------------------------
668 // Return true if message got aborted by user (pressed ESC), else return false.
669 int show_d1_briefing_message(int screen_num, char *message)
670 {
671         int     prev_ch=-1;
672         int     ch, done=0;
673         briefing_screen *bsp = &Briefing_screens[screen_num];
674         int     delay_count = KEY_DELAY_DEFAULT;
675         int     key_check;
676         int     robot_num=-1;
677         int     rval=0;
678         int     tab_stop=0;
679         int     flashing_cursor=0;
680         int     new_page=0;
681         int text_ulx = rescale_x(bsp->text_ulx);
682         int text_uly = rescale_y(bsp->text_uly);
683
684         Bitmap_name[0] = 0;
685
686         Current_color = 0;
687
688         // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
689         gr_set_curfont( GAME_FONT );
690
691         init_char_pos(text_ulx, text_uly);
692
693         while (!done) {
694                 ch = *message++;
695                 if (ch == '$') {
696                         ch = *message++;
697                         if (ch == 'C') {
698                                 Current_color = get_message_num(&message)-1;
699                                 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
700                                 prev_ch = 10;
701                         } else if (ch == 'F') {         //      toggle flashing cursor
702                                 flashing_cursor = !flashing_cursor;
703                                 prev_ch = 10;
704                                 while (*message++ != 10)
705                                         ;
706                         } else if (ch == 'T') {
707                                 tab_stop = get_message_num(&message);
708                                 prev_ch = 10;                                                   //      read to eoln
709                         } else if (ch == 'R') {
710                                 if (Robot_canv != NULL)
711                                         {free(Robot_canv); Robot_canv=NULL;}
712
713                                 init_spinning_robot();
714                                 robot_num = get_message_num(&message);
715                                 prev_ch = 10;                                                   //      read to eoln
716                         } else if (ch == 'N') {
717                                 //--grs_bitmap  *bitmap_ptr;
718                                 if (Robot_canv != NULL)
719                                         {free(Robot_canv); Robot_canv=NULL;}
720
721                                 get_message_name(&message, Bitmap_name);
722                                 strcat(Bitmap_name, "#0");
723                                 Animating_bitmap_type = 0;
724                                 prev_ch = 10;
725                         } else if (ch == 'O') {
726                                 if (Robot_canv != NULL)
727                                         {free(Robot_canv); Robot_canv=NULL;}
728
729                                 get_message_name(&message, Bitmap_name);
730                                 strcat(Bitmap_name, "#0");
731                                 Animating_bitmap_type = 1;
732                                 prev_ch = 10;
733                         } else if (ch == 'B') {
734                                 char                    bitmap_name[32];
735                                 grs_bitmap      guy_bitmap;
736                                 ubyte                   temp_palette[768];
737                                 int                     iff_error;
738
739                                 if (Robot_canv != NULL)
740                                         {free(Robot_canv); Robot_canv=NULL;}
741
742                                 get_message_name(&message, bitmap_name);
743                                 strcat(bitmap_name, ".bbm");
744                                 gr_init_bitmap_data (&guy_bitmap);
745                                 iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette);
746                                 Assert(iff_error == IFF_NO_ERROR);
747
748                                 show_briefing_bitmap(&guy_bitmap);
749                                 gr_free_bitmap_data (&guy_bitmap);
750                                 prev_ch = 10;
751 //                      } else if (ch == 'B') {
752 //                              if (Robot_canv != NULL)
753 //                                      {free(Robot_canv); Robot_canv=NULL;}
754 //
755 //                              bitmap_num = get_message_num(&message);
756 //                              if (bitmap_num != -1)
757 //                                      show_briefing_bitmap(Textures[bitmap_num]);
758 //                              prev_ch = 10;                                                   //      read to eoln
759                         } else if (ch == 'S') {
760                                 int     keypress;
761                                 fix     start_time;
762                                 fix time_out_value;
763
764                                 start_time = timer_get_fixed_seconds();
765                                 start_time = timer_get_approx_seconds();
766                                 time_out_value = start_time + i2f(60*5);        // Wait 1 minute...
767
768                                 //added on 9/13/98 by adb to make arch's requiring updates work
769                                 gr_update();
770                                 //end changes by adb
771
772                                 while ( (keypress = local_key_inkey()) == 0 ) { //      Wait for a key
773                                         if ( timer_get_approx_seconds() > time_out_value ) {
774                                                 keypress = 0;
775                                                 break;                                  // Time out after 1 minute..
776                                         }
777                                         while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
778                                                 ;
779                                         flash_cursor(flashing_cursor);
780                                         show_spinning_robot_frame(robot_num);
781                                         show_bitmap_frame();
782
783                                         //added on 9/13/98 by adb to make arch's requiring updates work
784                                         gr_update();
785                                         //end changes by adb
786
787                                         start_time += KEY_DELAY_DEFAULT/2;
788                                 }
789
790 #ifndef NDEBUG
791                                 if (keypress == KEY_BACKSP)
792                                         Int3();
793 #endif
794                                 if (keypress == KEY_ESC)
795                                         rval = 1;
796
797                                 flashing_cursor = 0;
798                                 done = 1;
799                         } else if (ch == 'P') {         //      New page.
800                                 new_page = 1;
801                                 while (*message != 10) {
802                                         message++;      //      drop carriage return after special escape sequence
803                                 }
804                                 message++;
805                                 prev_ch = 10;
806 //Begin D1X addition
807                         } else if (ch == '$' || ch == ';') {         // Print a $/;
808                                 prev_ch = ch;
809                                 Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
810
811 //End D1X addition
812                         }
813                 } else if (ch == '\t') {                //      Tab
814                         if (Briefing_text_x - text_ulx < tab_stop)
815                                 Briefing_text_x = text_ulx + tab_stop;
816                 } else if ((ch == ';') && (prev_ch == 10)) {
817                         while (*message++ != 10)
818                                 ;
819                         prev_ch = 10;
820                 } else if (ch == '\\') {
821                         prev_ch = ch;
822                 } else if (ch == 10) {
823                         if (prev_ch != '\\') {
824                                 prev_ch = ch;
825                                 Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
826                                 Briefing_text_x = text_ulx;
827                                 if (Briefing_text_y > text_uly + rescale_y(bsp->text_height)) {
828                                         load_briefing_screen(screen_num);
829                                         Briefing_text_x = text_ulx;
830                                         Briefing_text_y = text_uly;
831                                 }
832                         } else {
833                                 if (ch == 13)
834                                         Int3();
835                                 prev_ch = ch;
836                         }
837                 } else {
838                         prev_ch = ch;
839                         Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
840                 }
841
842                 //added/changed on 9/13/98 by adb to speed up briefings after pressing a key with SDL
843                 //      Check for Esc -> abort.
844                 if(delay_count)
845                         key_check=local_key_inkey();
846                 else
847                         key_check=0;
848                 //end change - adb
849                 if ( key_check == KEY_ESC ) {
850                         rval = 1;
851                         done = 1;
852                 }
853
854 #if 0
855                 if ( key_check == KEY_ALTED+KEY_F2 )
856                         title_save_game();
857 #endif
858
859                 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
860                         delay_count = 0;
861
862                 if (Briefing_text_x > text_ulx + rescale_x(bsp->text_width)) {
863                         Briefing_text_x = text_ulx;
864                         Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5;
865                 }
866
867                 if ((new_page) || (Briefing_text_y > text_uly + rescale_y(bsp->text_height))) {
868                         fix     start_time = 0;
869                         fix     time_out_value = 0;
870                         int     keypress;
871
872                         new_page = 0;
873                         start_time = timer_get_approx_seconds();
874                         time_out_value = start_time + i2f(60*5);                // Wait 1 minute...
875
876                         //added on 9/13/98 by adb to make arch's requiring updates work
877                         gr_update();
878                         //end changes by adb
879
880                         while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
881                                 if ( timer_get_approx_seconds() > time_out_value ) {
882                                         keypress = 0;
883                                         break;                                  // Time out after 1 minute..
884                                 }
885                                 while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2)
886                                         ;
887                                 flash_cursor(flashing_cursor);
888                                 show_spinning_robot_frame(robot_num);
889                                 show_bitmap_frame();
890
891                                 //added on 9/13/98 by adb to make arch's requiring updates work
892                                 gr_update();
893                                 //end changes by adb
894
895                                 start_time += KEY_DELAY_DEFAULT/2;
896                         }
897
898                         robot_num = -1;
899
900 #ifndef NDEBUG
901                         if (keypress == KEY_BACKSP)
902                                 Int3();
903 #endif
904                         if (keypress == KEY_ESC) {
905                                 rval = 1;
906                                 done = 1;
907                         }
908
909                         load_briefing_screen(screen_num);
910                         Briefing_text_x = text_ulx;
911                         Briefing_text_y = text_uly;
912                         delay_count = KEY_DELAY_DEFAULT;
913                 }
914         }
915
916         if (Robot_canv != NULL)
917                 {free(Robot_canv); Robot_canv=NULL;}
918
919         return rval;
920 }
921
922 //-----------------------------------------------------------------------------
923 // Return true if message got aborted by user (pressed ESC), else return false.
924 int show_briefing_message(int screen_num, char *message)
925 {
926         int     prev_ch=-1;
927         int     ch, done=0,i;
928         briefing_screen *bsp = &Briefing_screens[screen_num];
929         int     delay_count = KEY_DELAY_DEFAULT;
930         int     key_check;
931         int     robot_num=-1;
932         int     rval=0;
933         static int tab_stop=0;
934         int     flashing_cursor=0;
935         int     new_page=0,GotZ=0;
936 #ifdef ROBOT_MOVIES
937         char spinRobotName[]="rba.mve",kludge;  // matt don't change this!
938 #endif
939         char fname[15];
940         char DumbAdjust=0;
941         char chattering=0;
942         int hum_channel=-1,printing_channel=-1;
943         int LineAdjustment=1;
944         WIN(int wpage_done=0);
945
946         Bitmap_name[0] = 0;
947         Current_color = 0;
948 #ifdef ROBOT_MOVIES
949         RobotPlaying=0;
950
951         InitMovieBriefing();
952 #endif
953
954         #ifndef SHAREWARE
955         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
956         #endif
957
958         // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y));
959         gr_set_curfont( GAME_FONT );
960
961         bsp=&Briefing_screens[0];
962         init_char_pos(bsp->text_ulx, bsp->text_uly-(8*(1+MenuHires)));
963
964         while (!done) {
965                 ch = *message++;
966                 if (ch == '$') {
967                         ch = *message++;
968                         if (ch=='D') {
969                                 screen_num=DefineBriefingBox (&message);
970                         //load_new_briefing_screen (Briefing_screens[screen_num].bs_name);
971
972                                 bsp = &Briefing_screens[screen_num];
973                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
974                                 //LineAdjustment=0;
975                                 prev_ch = 10;                                   // read to eoln
976                         } else if (ch=='U') {
977                                 screen_num=get_message_num(&message);
978                                 bsp = &Briefing_screens[screen_num];
979                                 init_char_pos(bsp->text_ulx, bsp->text_uly);
980                                 prev_ch = 10;                                   // read to eoln
981                         } else if (ch == 'C') {
982                                 Current_color = get_message_num(&message)-1;
983                                 Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS));
984                                 prev_ch = 10;
985                         } else if (ch == 'F') {     // toggle flashing cursor
986                                 flashing_cursor = !flashing_cursor;
987                                 prev_ch = 10;
988                                 while (*message++ != 10)
989                                         ;
990                         } else if (ch == 'T') {
991                                 tab_stop = get_message_num(&message);
992                                 tab_stop*=(1+MenuHires);
993                                 prev_ch = 10;                                                   //      read to eoln
994                         } else if (ch == 'R') {
995                                 if (Robot_canv != NULL) {
996                                         d_free(Robot_canv);
997                                         Robot_canv=NULL;
998                                 }
999 #ifdef ROBOT_MOVIES
1000                                 if (RobotPlaying) {
1001                                         DeInitRobotMovie();
1002                                         RobotPlaying=0;
1003                                 }
1004
1005                                 kludge=*message++;
1006                                 spinRobotName[2]=kludge; // ugly but proud
1007
1008                                 RobotPlaying=InitRobotMovie(spinRobotName);
1009
1010                                 // gr_remap_bitmap_good( &grd_curcanv->cv_bitmap, pal, -1, -1 );
1011
1012                                 if (RobotPlaying) {
1013                                         RotateRobot();
1014                                         DoBriefingColorStuff ();
1015                                         mprintf ((0,"Robot playing is %d!!!",RobotPlaying));
1016                                 }
1017 #else
1018                                 init_spinning_robot();
1019                                 robot_num = get_message_num(&message);
1020 #endif
1021                                 prev_ch = 10;                           // read to eoln
1022                         } else if (ch == 'N') {
1023                                 //--grs_bitmap *bitmap_ptr;
1024                                 if (Robot_canv != NULL) {
1025                                         d_free(Robot_canv);
1026                                         Robot_canv=NULL;
1027                                 }
1028
1029                                 get_message_name(&message, Bitmap_name);
1030                                 strcat(Bitmap_name, "#0");
1031                                 Animating_bitmap_type = 0;
1032                                 prev_ch = 10;
1033                         } else if (ch == 'O') {
1034                                 if (Robot_canv != NULL) {
1035                                                 d_free(Robot_canv);
1036                                                 Robot_canv=NULL;
1037                                 }
1038
1039                                 get_message_name(&message, Bitmap_name);
1040                                 strcat(Bitmap_name, "#0");
1041                                 Animating_bitmap_type = 1;
1042                                 prev_ch = 10;
1043                         } else if (ch=='A') {
1044                                 LineAdjustment=1-LineAdjustment;
1045                         } else if (ch=='Z') {
1046                                 //mprintf ((0,"Got a Z!\n"));
1047                                 GotZ=1;
1048 #if defined (D2_OEM) || defined(COMPILATION) || (defined(MACINTOSH) && defined(SHAREWARE))
1049                                 DumbAdjust=1;
1050 #else
1051                                 if (LineAdjustment==1)
1052                                         DumbAdjust=1;
1053                                 else
1054                                         DumbAdjust=2;
1055 #endif
1056
1057                                 i=0;
1058                                 while ((fname[i]=*message) != '\n') {
1059                                         i++;
1060                                         message++;
1061                                 }
1062                                 fname[i]=0;
1063
1064                                 {
1065                                         char fname2[15];
1066
1067                                         i=0;
1068                                         while (fname[i]!='.') {
1069                                                 fname2[i] = fname[i];
1070                                                 i++;
1071                                         }
1072 #ifndef SHAREWARE
1073                                         fname2[i++]='b';
1074 #endif
1075                                         fname2[i++]='.';
1076                                         fname2[i++]='p';
1077                                         fname2[i++]='c';
1078                                         fname2[i++]='x';
1079                                         fname2[i++]=0;
1080
1081                                         if ((MenuHires && cfexist(fname2)) || !cfexist(fname))
1082                                                 load_new_briefing_screen (fname2);
1083                                         else
1084                                                 load_new_briefing_screen (fname);
1085                                 }
1086
1087                                 //load_new_briefing_screen (MenuHires?"end01b.pcx":"end01.pcx");
1088
1089                         } else if (ch == 'B') {
1090                                 char        bitmap_name[32];
1091                                 grs_bitmap  guy_bitmap;
1092                                 ubyte       temp_palette[768];
1093                                 int         iff_error;
1094
1095                                 if (Robot_canv != NULL) {
1096                                         d_free(Robot_canv);
1097                                         Robot_canv=NULL;
1098                                 }
1099
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 );
1106
1107                                 show_briefing_bitmap(&guy_bitmap);
1108                                 d_free(guy_bitmap.bm_data);
1109                                 prev_ch = 10;
1110 //                      } else if (ch==EOF) {
1111 //                              done=1;
1112 //                      } else if (ch == 'B') {
1113 //                              if (Robot_canv != NULL) {
1114 //                                      d_free(Robot_canv);
1115 //                                      Robot_canv=NULL;
1116 //                              }
1117 //
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') {
1123                                 int keypress;
1124                                 fix start_time;
1125
1126                                 chattering=0;
1127                                 if (printing_channel>-1)
1128                                         digi_stop_sound( printing_channel );
1129                                 printing_channel=-1;
1130
1131 #ifdef WINDOWS
1132                                 if (!wpage_done) {
1133                                         DDGRRESTORE;
1134                                         wpage_done =1;
1135                                 }
1136 #endif
1137
1138                                 start_time = timer_get_fixed_seconds();
1139                                 while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
1140 #ifdef WINDOWS
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 );
1144                                                 keypress = KEY_ESC;
1145                                                 break;
1146                                         }
1147 #endif
1148
1149                                         while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1150                                                 ;
1151                                         flash_cursor(flashing_cursor);
1152
1153 #ifdef ROBOT_MOVIES
1154                                         if (RobotPlaying)
1155                                                 RotateRobot ();
1156 #else
1157                                         show_spinning_robot_frame(robot_num);
1158 #endif
1159
1160                                         show_bitmap_frame();
1161                                         start_time += KEY_DELAY_DEFAULT/2;
1162                                 }
1163
1164 #ifndef NDEBUG
1165                                 if (keypress == KEY_BACKSP)
1166                                         Int3();
1167 #endif
1168                                 if (keypress == KEY_ESC)
1169                                         rval = 1;
1170
1171                                 flashing_cursor = 0;
1172                                 done = 1;
1173                                 WIN(wpage_done = 0);
1174                         } else if (ch == 'P') {         //      New page.
1175                                 if (!GotZ) {
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");
1179                                 }
1180
1181                                 new_page = 1;
1182                                 while (*message != 10) {
1183                                         message++;      //      drop carriage return after special escape sequence
1184                                 }
1185                                 message++;
1186                                 prev_ch = 10;
1187                                 gr_update();
1188                         }
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)
1194                                 ;
1195                         prev_ch = 10;
1196                 } else if (ch == '\\') {
1197                         prev_ch = ch;
1198                 } else if (ch == 10) {
1199                         if (prev_ch != '\\') {
1200                                 prev_ch = ch;
1201                                 if (1) //DumbAdjust==0)
1202                                         Briefing_text_y += (8*(MenuHires+1));
1203                                 else
1204                                         DumbAdjust--;
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;
1210                                 }
1211                         } else {
1212                                 if (ch == 13)           //Can this happen? Above says ch==10
1213                                         Int3();
1214                                 prev_ch = ch;
1215                         }
1216
1217                 } else {
1218                         if (!GotZ) {
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");
1222                         }
1223
1224                         prev_ch = ch;
1225
1226                         if (!chattering) {
1227                                 printing_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, -1 );
1228                                 chattering=1;
1229                         }
1230
1231                         WIN(if (GRMODEINFO(emul)) delay_count = 0);
1232
1233                         Briefing_text_x += show_char_delay(ch, delay_count, robot_num, flashing_cursor);
1234
1235                 }
1236
1237                 //      Check for Esc -> abort.
1238                 if(delay_count)
1239                         key_check=local_key_inkey();
1240                 else
1241                         key_check=0;
1242
1243 #ifdef WINDOWS
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;
1248                 }
1249 #endif
1250                 if ( key_check == KEY_ESC ) {
1251                         rval = 1;
1252                         done = 1;
1253                 }
1254
1255                 if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER))
1256                         delay_count = 0;
1257
1258 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1259                 if ((key_check == KEY_CTRLED+KEY_SHIFTED+KEY_PADENTER) ||
1260                         (key_check == KEY_ALTED+KEY_CTRLED+KEY_PADENTER) ||
1261                         (key_check == KEY_ALTED+KEY_SHIFTED+KEY_PADENTER))
1262                         gr_toggle_fullscreen();
1263 #endif
1264
1265                 if (Briefing_text_x > bsp->text_ulx + bsp->text_width) {
1266                         Briefing_text_x = bsp->text_ulx;
1267                         Briefing_text_y += bsp->text_uly;
1268                 }
1269
1270                 if ((new_page) || (Briefing_text_y > bsp->text_uly + bsp->text_height)) {
1271                         fix     start_time = 0;
1272                         int     keypress;
1273
1274                         new_page = 0;
1275
1276                         if (printing_channel>-1)
1277                                 digi_stop_sound( printing_channel );
1278                         printing_channel=-1;
1279
1280                         chattering=0;
1281
1282 #ifdef WINDOWS
1283                         if (!wpage_done) {
1284                                 DDGRRESTORE;
1285                                 wpage_done =1;
1286                         }
1287 #endif
1288
1289                         start_time = timer_get_fixed_seconds();
1290                         while ( (keypress = local_key_inkey()) == 0 ) {         //      Wait for a key
1291 #ifdef WINDOWS
1292                                 if (_RedrawScreen) {
1293                                         _RedrawScreen = FALSE;
1294                                         hum_channel  = digi_start_sound( digi_xlat_sound(SOUND_BRIEFING_HUM), F1_0/2, 0xFFFF/2, 1, -1, -1, -1 );
1295                                         keypress = KEY_ESC;
1296                                         break;
1297                                 }
1298 #endif
1299
1300                                 while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2)
1301                                         ;
1302                                 flash_cursor(flashing_cursor);
1303 #ifdef ROBOT_MOVIES
1304                                 if (RobotPlaying)
1305                                         RotateRobot();
1306 #else
1307                                 show_spinning_robot_frame(robot_num);
1308 #endif
1309                                 show_bitmap_frame();
1310                                 start_time += KEY_DELAY_DEFAULT/2;
1311                         }
1312
1313 #ifdef ROBOT_MOVIES
1314                         if (RobotPlaying)
1315                                 DeInitRobotMovie();
1316                         RobotPlaying=0;
1317 #endif
1318                         robot_num = -1;
1319
1320 #ifndef NDEBUG
1321                         if (keypress == KEY_BACKSP)
1322                                 Int3();
1323 #endif
1324                         if (keypress == KEY_ESC) {
1325                                 rval = 1;
1326                                 done = 1;
1327                         }
1328
1329                         load_briefing_screen(screen_num);
1330                         Briefing_text_x = bsp->text_ulx;
1331                         Briefing_text_y = bsp->text_uly;
1332                         delay_count = KEY_DELAY_DEFAULT;
1333
1334                         WIN(wpage_done = 0);
1335                 }
1336         }
1337
1338 #ifdef ROBOT_MOVIES
1339         if (RobotPlaying) {
1340                 DeInitRobotMovie();
1341                 RobotPlaying=0;
1342         }
1343 #endif
1344
1345         if (Robot_canv != NULL)
1346                 {d_free(Robot_canv); Robot_canv=NULL;}
1347
1348         if (hum_channel>-1)
1349                 digi_stop_sound( hum_channel );
1350         if (printing_channel>-1)
1351                 digi_stop_sound( printing_channel );
1352
1353         return rval;
1354 }
1355
1356 //-----------------------------------------------------------------------------
1357 // Return a pointer to the start of text for screen #screen_num.
1358 char * get_briefing_message(int screen_num)
1359 {
1360         char *tptr = Briefing_text;
1361         int     cur_screen=0;
1362         int     ch;
1363
1364         Assert(screen_num >= 0);
1365
1366         while ( (*tptr != 0 ) && (screen_num != cur_screen)) {
1367                 ch = *tptr++;
1368                 if (ch == '$') {
1369                         ch = *tptr++;
1370                         if (ch == 'S')
1371                                 cur_screen = get_message_num(&tptr);
1372                 }
1373         }
1374
1375         if (screen_num!=cur_screen)
1376                 return (NULL);
1377
1378         return tptr;
1379 }
1380
1381 //-----------------------------------------------------------------------------
1382 //      Load Descent briefing text.
1383 int load_screen_text(char *filename, char **buf)
1384 {
1385         CFILE *tfile;
1386         CFILE *ifile;
1387         int     len, i,x;
1388         int     have_binary = 0;
1389
1390         if ((tfile = cfopen(filename,"rb")) == NULL) {
1391                 char nfilename[30], *ptr;
1392
1393                 strcpy(nfilename, filename);
1394                 ptr = strrchr(nfilename, '.');
1395                 *ptr = '\0';
1396                 strcat(nfilename, ".txb");
1397                 if ((ifile = cfopen(nfilename, "rb")) == NULL) {
1398                         mprintf ((0,"can't open %s!\n",nfilename));
1399                         return (0);
1400                                 //Error("Cannot open file %s or %s", filename, nfilename);
1401                 }
1402
1403                 mprintf ((0,"reading...\n"));
1404                 have_binary = 1;
1405
1406                 len = cfilelength(ifile);
1407                 MALLOC(*buf, char, len+500);
1408                 mprintf ((0,"len=%d\n",len));
1409                 for (x=0, i=0; i < len; i++, x++) {
1410                         cfread (*buf+x,1,1,ifile);
1411                         //  mprintf ((0,"%c",*(*buf+x)));
1412                         if (*(*buf+x)==13)
1413                                 x--;
1414                 }
1415
1416                 cfclose(ifile);
1417         } else {
1418                 len = cfilelength(tfile);
1419                 MALLOC(*buf, char, len+500);
1420                 for (x=0, i=0; i < len; i++, x++) {
1421                         cfread (*buf+x,1,1,tfile);
1422                         // mprintf ((0,"%c",*(*buf+x)));
1423                         if (*(*buf+x)==13)
1424                                 x--;
1425                 }
1426
1427
1428                 //cfread(*buf, 1, len, tfile);
1429                 cfclose(tfile);
1430         }
1431
1432         if (have_binary) {
1433                 char *ptr;
1434
1435                 for (i = 0, ptr = *buf; i < len; i++, ptr++) {
1436                         if (*ptr != '\n') {
1437                                 encode_rotate_left(ptr);
1438                                 *ptr = *ptr ^ BITMAP_TBL_XOR;
1439                                 encode_rotate_left(ptr);
1440                         }
1441                 }
1442         }
1443
1444         return (1);
1445 }
1446
1447 //-----------------------------------------------------------------------------
1448 // Return true if message got aborted, else return false.
1449 int show_briefing_text(int screen_num)
1450 {
1451         char    *message_ptr;
1452
1453         message_ptr = get_briefing_message(screen_num);
1454         if (message_ptr==NULL)
1455                 return (0);
1456
1457         DoBriefingColorStuff();
1458
1459         if (Mission_list[Current_mission_num].descent_version == 1)
1460                 return show_d1_briefing_message(screen_num, message_ptr);
1461         else
1462                 return show_briefing_message(screen_num, message_ptr);
1463 }
1464
1465 void DoBriefingColorStuff ()
1466 {
1467         Briefing_foreground_colors[0] = gr_find_closest_color_current( 0, 40, 0);
1468         Briefing_background_colors[0] = gr_find_closest_color_current( 0, 6, 0);
1469
1470         Briefing_foreground_colors[1] = gr_find_closest_color_current( 40, 33, 35);
1471         Briefing_background_colors[1] = gr_find_closest_color_current( 5, 5, 5);
1472
1473         Briefing_foreground_colors[2] = gr_find_closest_color_current( 8, 31, 54);
1474         Briefing_background_colors[2] = gr_find_closest_color_current( 1, 4, 7);
1475
1476         Erase_color = gr_find_closest_color_current(0, 0, 0);
1477 }
1478
1479 //-----------------------------------------------------------------------------
1480 // Return true if screen got aborted by user, else return false.
1481 int show_briefing_screen( int screen_num, int allow_keys)
1482 {
1483         int     rval=0;
1484         ubyte   palette_save[768];
1485
1486         New_pal_254_bash = 0;
1487
1488         if (Skip_briefing_screens) {
1489                 mprintf((0, "Skipping briefing screen [brief03.pcx]\n"));
1490                 return 0;
1491         }
1492
1493 //      briefing_bm.bm_data=NULL;
1494 //   if ((pcx_error=pcx_read_bitmap( "brief03.pcx", &briefing_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE)     {
1495 //        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));
1496 //              Int3();
1497 //              return 0;
1498 //      }
1499
1500         memcpy(palette_save,gr_palette,sizeof(palette_save));
1501         memcpy(New_pal,gr_palette,sizeof(gr_palette));
1502
1503
1504 //      vfx_set_palette_sub( New_pal );
1505 //      gr_palette_clear();
1506 //      gr_bitmap( 0, 0, &briefing_bm );
1507 #ifdef OGL
1508         gr_palette_load(New_pal);
1509 #endif
1510
1511 //      if (gr_palette_fade_in( New_pal, 32, allow_keys ))
1512 //              return 1;
1513 //      memcpy(gr_palette,New_pal,sizeof(gr_palette));
1514
1515         #ifdef MACINTOSH
1516         key_close();            // kill the keyboard handler during briefing screens for movies
1517         #endif
1518         rval = show_briefing_text(screen_num);
1519         #ifdef MACINTOSH
1520         key_init();
1521         #endif
1522
1523         #if defined (MACINTOSH) || defined(WINDOWS)
1524         memcpy(New_pal,gr_palette,sizeof(gr_palette));          // attempt to get fades after briefing screens done correctly.
1525         #endif
1526
1527
1528 #ifndef WINDOWS
1529         if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1530                 return 1;
1531 #else
1532                 DEFINE_SCREEN(NULL);
1533                 WIN(DDGRLOCK(dd_grd_curcanv));
1534                 gr_clear_canvas (0);
1535                 WIN(DDGRUNLOCK(dd_grd_curcanv));
1536                 if (gr_palette_fade_out( New_pal, 32, allow_keys ))
1537                         return 1;
1538 #endif
1539
1540         gr_copy_palette(gr_palette, palette_save, sizeof(palette_save));
1541
1542 //      d_free(briefing_bm.bm_data);
1543
1544         return rval;
1545 }
1546
1547
1548 //-----------------------------------------------------------------------------
1549 void do_briefing_screens(char *filename,int level_num)
1550 {
1551         int     abort_briefing_screens = 0;
1552         int     cur_briefing_screen = 0;
1553
1554         if (Skip_briefing_screens) {
1555                 mprintf((0, "Skipping all briefing screens.\n"));
1556                 return;
1557         }
1558
1559         #ifdef APPLE_DEMO
1560         return;                 // no briefing screens at all for demo
1561
1562         #endif
1563
1564         mprintf ((0,"Trying briefing screen <%s>\n",filename));
1565
1566         if (!filename)
1567                 return;
1568
1569         if (!load_screen_text(filename, &Briefing_text))
1570                 return;
1571
1572         #ifdef SHAREWARE
1573         songs_play_song( SONG_BRIEFING, 1 );
1574         #else
1575         songs_stop_all();
1576         #endif
1577
1578         set_screen_mode( SCREEN_MENU );
1579
1580         WINDOS(
1581                 dd_gr_set_current_canvas(NULL),
1582                 gr_set_current_canvas(NULL)
1583         );
1584
1585         mprintf ((0,"Playing briefing screen <%s>, level %d\n",filename,level_num));
1586
1587         key_flush();
1588
1589         if (Mission_list[Current_mission_num].descent_version == 1) {
1590                 if (level_num == 1) {
1591                         while ((!abort_briefing_screens) && (Briefing_screens[cur_briefing_screen].level_num == 0)) {
1592                                 abort_briefing_screens = show_briefing_screen(cur_briefing_screen, 0);
1593                                 cur_briefing_screen++;
1594                         }
1595                 }
1596
1597                 if (!abort_briefing_screens) {
1598                         for (cur_briefing_screen = 0; cur_briefing_screen < MAX_BRIEFING_SCREENS; cur_briefing_screen++)
1599                                 if (Briefing_screens[cur_briefing_screen].level_num == level_num)
1600                                         if (show_briefing_screen(cur_briefing_screen, 0))
1601                                                 break;
1602                 }
1603
1604         } else
1605                 show_briefing_screen(level_num,0);
1606
1607         d_free (Briefing_text);
1608         key_flush();
1609
1610         return;
1611
1612 }
1613
1614 int DefineBriefingBox (char **buf)
1615 {
1616         int n,i=0;
1617         char name[20];
1618
1619         n=get_new_message_num (buf);
1620
1621         Assert(n < MAX_BRIEFING_SCREENS);
1622
1623         while (**buf!=' ') {
1624                 name[i++]=**buf;
1625                 (*buf)++;
1626         }
1627
1628         name[i]='\0';   // slap a delimiter on this guy
1629
1630         strcpy (Briefing_screens[n].bs_name,name);
1631         Briefing_screens[n].level_num=get_new_message_num (buf);
1632         Briefing_screens[n].message_num=get_new_message_num (buf);
1633         Briefing_screens[n].text_ulx=get_new_message_num (buf);
1634         Briefing_screens[n].text_uly=get_new_message_num (buf);
1635         Briefing_screens[n].text_width=get_new_message_num (buf);
1636         Briefing_screens[n].text_height=get_message_num (buf);  // NOTICE!!!
1637
1638         if (MenuHires) {
1639                 Briefing_screens[n].text_ulx*=2;
1640                 Briefing_screens[n].text_uly*=2.4;
1641                 Briefing_screens[n].text_width*=2;
1642                 Briefing_screens[n].text_height*=2.4;
1643         }
1644
1645         return (n);
1646 }
1647
1648 int get_new_message_num(char **message)
1649 {
1650         int     num=0;
1651
1652         while (**message == ' ')
1653                 (*message)++;
1654
1655         while ((**message >= '0') && (**message <= '9')) {
1656                 num = 10*num + **message-'0';
1657                 (*message)++;
1658         }
1659
1660        (*message)++;
1661
1662         return num;
1663 }
1664