configuration fixes
[btb/d2x.git] / main / credits.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #ifdef RCS
16 static char rcsid[] = "$Id: credits.c,v 1.2 2001-01-20 13:49:14 bradleyb Exp $";
17 #endif
18
19 #ifdef WINDOWS
20 #include "desw.h"
21 #endif
22
23 #include <conf.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <ctype.h>
29
30 #include "pa_enabl.h"                   //$$POLY_ACC
31 #include "error.h"
32 #include "pstypes.h"
33 #include "gr.h"
34 #include "mono.h"
35 #include "key.h"
36 #include "palette.h"
37 #include "game.h"
38 #include "gamepal.h"
39 #include "timer.h"
40
41 #include "newmenu.h"
42 #include "gamefont.h"
43 #include "network.h"
44 #include "iff.h"
45 #include "pcx.h"
46 #include "u_mem.h"
47 #include "mouse.h"
48 #include "joy.h"
49 #include "screens.h"
50 #include "digi.h"
51
52 #include "cfile.h"
53 #include "compbit.h"
54 #include "songs.h"
55 #include "menu.h"                       // for MenuHires
56
57 #if defined(POLY_ACC)
58 #include "poly_acc.h"
59 #endif
60
61 #define ROW_SPACING (MenuHires?26:11)
62 #define NUM_LINES_HIRES 21
63 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
64
65 ubyte fade_values[200] = { 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,8,9,9,10,10,
66 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
67 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
68 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
69 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
70 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
71 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
72 17,16,16,15,15,15,14,14,13,13,12,12,12,11,11,10,10,9,9,8,8,8,7,7,6,6,5,
73 5,4,4,3,3,2,2,1 };
74
75 ubyte fade_values_hires[480] = { 1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,
76 5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,8,8,9,9,9,9,9,10,10,10,10,10,10,11,11,11,11,11,12,12,12,12,12,12,
77 13,13,13,13,13,14,14,14,14,14,14,15,15,15,15,15,15,16,16,16,16,16,17,17,17,17,17,17,18,18,
78 18,18,18,18,18,19,19,19,19,19,19,20,20,20,20,20,20,20,21,21,21,21,21,21,22,22,22,22,22,22,
79 22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,26,26,26,26,
80 26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,29,29,29,
81 29,29,29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
82 30,30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
83 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,
84 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,29,29,29,29,29,29,29,29,29,29,29,29,
85 29,29,28,28,28,28,28,28,28,28,28,28,28,28,27,27,27,27,27,27,27,27,27,27,26,26,26,26,26,26,
86 26,26,26,25,25,25,25,25,25,25,25,25,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,
87 22,22,22,22,22,21,21,21,21,21,21,20,20,20,20,20,20,20,19,19,19,19,19,19,18,18,18,18,18,18,
88 18,17,17,17,17,17,17,16,16,16,16,16,15,15,15,15,15,15,14,14,14,14,14,14,13,13,13,13,13,12,
89 12,12,12,12,12,11,11,11,11,11,10,10,10,10,10,10,9,9,9,9,9,8,8,8,8,8,7,7,7,7,7,6,6,6,6,6,5,5,5,5,
90 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
91
92 extern ubyte *gr_bitblt_fade_table;
93 extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
94
95 grs_font * header_font;
96 grs_font * title_font;
97 grs_font * names_font;
98
99 #ifdef SHAREWARE
100 #define ALLOWED_CHAR 'S'
101 #else
102 #define ALLOWED_CHAR 'R'
103 #endif
104
105 #ifdef RELEASE
106 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx")        //only read from hog file
107 #else
108 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
109 #endif
110
111 typedef struct box {
112         int left, top, width, height;
113 } box;
114
115 #ifdef MACINTOSH
116 #define CREDITS_FILE    "mcredits.tex"
117 #else
118 #ifdef D2_OEM
119 #define CREDITS_FILE    "ocredits.tex"
120 #else
121 #define CREDITS_FILE    "credits.tex"
122 #endif
123 #endif
124
125 //if filename passed is NULL, show normal credits
126 void credits_show(char *credits_filename)
127 {
128         int i, j, l, done;
129         CFILE * file;
130         char buffer[NUM_LINES_HIRES][80];
131         grs_bitmap backdrop;
132         ubyte backdrop_palette[768];
133         int pcx_error;
134         int buffer_line = 0;
135         fix last_time;
136 //      fix time_delay = 4180;                  // ~ F1_0 / 12.9
137 //      fix time_delay = 1784;
138         fix time_delay = 2800;
139         int first_line_offset,extra_inc=0;
140         int have_bin_file = 0;
141         char * tempp;
142         char filename[32];
143
144 WIN(int credinit = 0;)
145
146         box dirty_box[NUM_LINES_HIRES];
147         grs_canvas *CreditsOffscreenBuf=NULL;
148
149         WINDOS(
150                 dd_grs_canvas *save_canv,
151                 grs_canvas *save_canv
152         );
153
154         WINDOS(
155                 save_canv = dd_grd_curcanv,
156                 save_canv = grd_curcanv
157         );
158
159         // Clear out all tex buffer lines.
160         for (i=0; i<NUM_LINES; i++ ) 
161         {
162                 buffer[i][0] = 0;
163                 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
164         }
165
166
167         sprintf(filename, "%s", CREDITS_FILE);
168         have_bin_file = 0;
169         if (credits_filename) {
170                 strcpy(filename,credits_filename);
171                 have_bin_file = 1;
172         }
173         file = cfopen( filename, "rb" );
174         if (file == NULL) {
175                 char nfile[32];
176                 
177                 if (credits_filename)
178                         return;         //ok to not find special filename
179
180                 tempp = strchr(filename, '.');
181                 *tempp = '\0';
182                 sprintf(nfile, "%s.txb", filename);
183                 file = cfopen(nfile, "rb");
184                 if (file == NULL)
185                         Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
186                 have_bin_file = 1;
187         }
188
189         set_screen_mode(SCREEN_MENU);
190
191         WIN(DEFINE_SCREEN(NULL));
192
193 #ifdef WINDOWS
194 CreditsPaint:
195 #endif
196         gr_use_palette_table( "credits.256" );
197 #if defined(POLY_ACC)
198         pa_update_clut(gr_palette, 0, 256, 0);
199 #endif
200         header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
201         title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
202         names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
203         backdrop.bm_data=NULL;
204
205 //MWA  Made backdrop bitmap linear since it should always be.  the current canvas may not
206 //MWA  be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
207
208         pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
209         if (pcx_error != PCX_ERROR_NONE)                {
210                 cfclose(file);
211                 return;
212         }
213
214         songs_play_song( SONG_CREDITS, 1 );
215
216         gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
217
218 WINDOS(
219         dd_gr_set_current_canvas(NULL), 
220         gr_set_current_canvas(NULL)
221 );
222 WIN(DDGRLOCK(dd_grd_curcanv));
223         gr_bitmap(0,0,&backdrop);
224 WIN(DDGRUNLOCK(dd_grd_curcanv));
225         gr_update();
226         gr_palette_fade_in( gr_palette, 32, 0 );
227
228 //      Create a new offscreen buffer for the credits screen
229 //MWA  Let's be a little smarter about this and check the VR_offscreen buffer
230 //MWA  for size to determine if we can use that buffer.  If the game size
231 //MWA  matches what we need, then lets save memory.
232
233 #ifndef PA_3DFX_VOODOO
234 #ifndef WINDOWS
235         if (MenuHires && VR_offscreen_buffer->cv_w == 640)      {
236                 CreditsOffscreenBuf = VR_offscreen_buffer;
237         }
238         else if (MenuHires)     {
239                 CreditsOffscreenBuf = gr_create_canvas(640,480);
240         }
241         else {
242                 CreditsOffscreenBuf = gr_create_canvas(320,200);
243         }
244 #else
245         CreditsOffscreenBuf = gr_create_canvas(640,480);
246 #endif                           
247 #else
248         CreditsOffscreenBuf = gr_create_canvas(640,480);
249 #endif
250
251         if (!CreditsOffscreenBuf) 
252                 Error("Not enough memory to allocate Credits Buffer.");
253
254         //gr_clear_canvas(BM_XRGB(0,0,0));
255         key_flush();
256
257 #ifdef WINDOWS
258         if (!credinit)  
259 #endif
260         {
261                 last_time = timer_get_fixed_seconds();
262                 done = 0;
263                 first_line_offset = 0;
264         }
265
266         WIN(credinit = 1);
267
268         while( 1 )      {
269                 int k;
270
271                 do {
272                         buffer_line = (buffer_line+1) % NUM_LINES;
273 get_line:;
274                         if (cfgets( buffer[buffer_line], 80, file ))    {
275                                 char *p;
276                                 if (have_bin_file) {                            // is this a binary tbl file
277                                         for (i = 0; i < strlen(buffer[buffer_line]) - 1; i++) {
278                                                 encode_rotate_left(&(buffer[buffer_line][i]));
279                                                 buffer[buffer_line][i] ^= BITMAP_TBL_XOR;
280                                                 encode_rotate_left(&(buffer[buffer_line][i]));
281                                         }
282                                 }
283                                 p = buffer[buffer_line];
284                                 if (p[0] == ';')
285                                         goto get_line;
286
287                                 if (p[0] == '%')
288                                 {
289                                         if (p[1] == ALLOWED_CHAR)
290                                                 strcpy(p,p+2);
291                                         else
292                                                 goto get_line;
293                                 }
294
295                                 p = strchr(&buffer[buffer_line][0],'\n');
296                                 if (p) *p = '\0';
297                         } else  {
298                                 //fseek( file, 0, SEEK_SET);
299                                 buffer[buffer_line][0] = 0;
300                                 done++;
301                         }
302                 } while (extra_inc--);
303                 extra_inc = 0;
304
305 NO_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
306 PA_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
307                         int y;
308
309                         y = first_line_offset - i;
310
311                         gr_set_current_canvas(CreditsOffscreenBuf);
312                 
313                         gr_bitmap(0,0,&backdrop);
314
315                         for (j=0; j<NUM_LINES; j++ )    {
316                                 char *s;
317
318                                 l = (buffer_line + j + 1 ) %  NUM_LINES;
319                                 s = buffer[l];
320
321                                 if ( s[0] == '!' ) {
322                                         s++;
323                                 } else if ( s[0] == '$' )       {
324                                         grd_curcanv->cv_font = header_font;
325                                         s++;
326                                 } else if ( s[0] == '*' )       {
327                                         grd_curcanv->cv_font = title_font;
328                                         s++;
329                                 } else
330                                         grd_curcanv->cv_font = names_font;
331
332                                 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
333
334                                 tempp = strchr( s, '\t' );
335                                 if ( tempp )    {
336                                 //      Wacky Credits thing
337                                         int w, h, aw, w2, x1, x2;
338
339                                         *tempp = 0;
340                                         gr_get_string_size( s, &w, &h, &aw );
341                                         x1 = ((MenuHires?320:160)-w)/2;
342                                         gr_printf( x1 , y, s );
343                                         gr_get_string_size( &tempp[1], &w2, &h, &aw );
344                                         x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
345                                         gr_printf( x2, y, &tempp[1] );
346
347                                         dirty_box[j].left = ((MenuHires?320:160)-w)/2;
348                                         dirty_box[j].top = y;
349                                         dirty_box[j].width =(x2+w2)-x1;
350                                         dirty_box[j].height = h;
351
352                                         *tempp = '\t';
353                 
354                                 } else {
355                                 // Wacky Fast Credits thing
356                                         int w, h, aw;
357
358                                         gr_get_string_size( s, &w, &h, &aw);
359                                         dirty_box[j].width = w;
360                                 dirty_box[j].height = h;
361                                 dirty_box[j].top = y;
362                                 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
363
364                                         gr_printf( 0x8000, y, s );
365                                 }
366                                 gr_bitblt_fade_table = NULL;
367                                 if (buffer[l][0] == '!')
368                                         y += ROW_SPACING/2;
369                                 else
370                                         y += ROW_SPACING;
371                         }
372
373                         {       // Wacky Fast Credits Thing
374                                 box     *new_box;
375                                 grs_bitmap *tempbmp;
376                                 
377                                 for (j=0; j<NUM_LINES; j++ )
378                                 {
379                                         new_box = &dirty_box[j];
380
381                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
382                           
383                                 WIN(DDGRSCREENLOCK);
384 #if defined(POLY_ACC)
385                                         if(new_box->width != 0)
386 #endif
387                                                 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
388                                                                         new_box->left, new_box->top, new_box->left, new_box->top,
389                                                                         tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
390                                 WIN(DDGRSCREENUNLOCK);
391                                 }
392
393 #if defined(POLY_ACC)
394                 pa_flush();
395 #endif
396
397 #if !defined(POLY_ACC) || defined(MACINTOSH)
398                                 MAC( if(!PAEnabled) )                   // POLY_ACC always on for the macintosh
399                                 for (j=0; j<NUM_LINES; j++ )
400                                 {
401                                         new_box = &dirty_box[j];
402
403                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
404
405                                         gr_bm_bitblt(   new_box->width 
406                                                                         ,new_box->height+2
407                                                                         ,new_box->left
408                                                                         ,new_box->top
409                                                                         ,new_box->left
410                                                                         ,new_box->top
411                                                                         ,&backdrop
412                                                                         ,tempbmp );
413                                 }
414                                 
415 #endif
416                         gr_update();
417                                 
418                         }
419
420 //              Wacky Fast Credits thing doesn't need this (it's done above)
421 //@@            WINDOS(
422 //@@                    dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
423 //@@                    gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
424 //@@            );
425
426 //                      mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
427                         while( timer_get_fixed_seconds() < last_time+time_delay );
428                         last_time = timer_get_fixed_seconds();
429                 
430                 #ifdef WINDOWS
431                         {
432                                 MSG msg;
433
434                                 DoMessageStuff(&msg);
435
436                                 if (_RedrawScreen) {
437                                         _RedrawScreen = FALSE;
438
439                                         gr_close_font(header_font);
440                                         gr_close_font(title_font);
441                                         gr_close_font(names_font);
442
443                                         d_free(backdrop.bm_data);
444                                         gr_free_canvas(CreditsOffscreenBuf);
445                 
446                                         goto CreditsPaint;
447                                 }
448
449                                 DDGRRESTORE;
450                         }
451                 #endif
452
453                         //see if redbook song needs to be restarted
454                         songs_check_redbook_repeat();
455
456                         k = key_inkey();
457
458                         #ifndef NDEBUG
459                         if (k == KEY_BACKSP) {
460                                 Int3();
461                                 k=0;
462                         }
463                         #endif
464
465 //                      {
466 //                              fix ot = time_delay;
467 //                              time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
468 //                              if (ot!=time_delay)     {
469 //                                      mprintf( (0, "[%x] ", time_delay ));
470 //                              }
471 //                      }
472
473                         if (k == KEY_PRINT_SCREEN) {
474                                 save_screen_shot(0);
475                                 k = 0;
476                         }
477
478                         if ((k>0)||(done>NUM_LINES))    {
479                                         gr_close_font(header_font);
480                                         gr_close_font(title_font);
481                                         gr_close_font(names_font);
482                                         gr_palette_fade_out( gr_palette, 32, 0 );
483                                         gr_use_palette_table( DEFAULT_PALETTE );
484                                         d_free(backdrop.bm_data);
485                                         cfclose(file);
486                                 WINDOS(
487                                         dd_gr_set_current_canvas(save_canv),
488                                         gr_set_current_canvas(save_canv)
489                                 );
490                                         songs_play_song( SONG_TITLE, 1 );
491
492                                 #ifdef WINDOWS
493                                         gr_free_canvas(CreditsOffscreenBuf);
494                                 #else                                   
495                                         if (CreditsOffscreenBuf != VR_offscreen_buffer)
496                                                 gr_free_canvas(CreditsOffscreenBuf);
497                                 #endif
498
499                                 WIN(DEFINE_SCREEN(Menu_pcx_name));
500                         
501                                 return;
502                         }
503                 }
504
505                 if (buffer[(buffer_line + 1 ) %  NUM_LINES][0] == '!') {
506                         first_line_offset -= ROW_SPACING-ROW_SPACING/2;
507                         if (first_line_offset <= -ROW_SPACING) {
508                                 first_line_offset += ROW_SPACING;
509                                 extra_inc++;
510                         }
511                 }
512         }
513
514 }