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