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