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