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