]> icculus.org git repositories - btb/d2x.git/blob - main/credits.c
This commit was generated by cvs2svn to compensate for changes in r2,
[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.1.1.1 2001-01-19 03:30:04 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
94 grs_font * header_font;
95 grs_font * title_font;
96 grs_font * names_font;
97
98 #ifdef SHAREWARE
99 #define ALLOWED_CHAR 'S'
100 #else
101 #define ALLOWED_CHAR 'R'
102 #endif
103
104 #ifdef RELEASE
105 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx")        //only read from hog file
106 #else
107 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
108 #endif
109
110 typedef struct box {
111         int left, top, width, height;
112 } box;
113
114 #ifdef MACINTOSH
115 #define CREDITS_FILE    "mcredits.tex"
116 #else
117 #ifdef D2_OEM
118 #define CREDITS_FILE    "ocredits.tex"
119 #else
120 #define CREDITS_FILE    "credits.tex"
121 #endif
122 #endif
123
124 //if filename passed is NULL, show normal credits
125 void credits_show(char *credits_filename)
126 {
127         int i, j, l, done;
128         CFILE * file;
129         char buffer[NUM_LINES_HIRES][80];
130         grs_bitmap backdrop;
131         ubyte backdrop_palette[768];
132         int pcx_error;
133         int buffer_line = 0;
134         fix last_time;
135 //      fix time_delay = 4180;                  // ~ F1_0 / 12.9
136 //      fix time_delay = 1784;
137         fix time_delay = 2800;
138         int first_line_offset,extra_inc=0;
139         int have_bin_file = 0;
140         char * tempp;
141         char filename[32];
142
143 WIN(int credinit = 0;)
144
145         box dirty_box[NUM_LINES_HIRES];
146         grs_canvas *CreditsOffscreenBuf=NULL;
147
148         WINDOS(
149                 dd_grs_canvas *save_canv,
150                 grs_canvas *save_canv
151         );
152
153         WINDOS(
154                 save_canv = dd_grd_curcanv,
155                 save_canv = grd_curcanv
156         );
157
158         // Clear out all tex buffer lines.
159         for (i=0; i<NUM_LINES; i++ ) 
160         {
161                 buffer[i][0] = 0;
162                 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
163         }
164
165
166         sprintf(filename, "%s", CREDITS_FILE);
167         have_bin_file = 0;
168         if (credits_filename) {
169                 strcpy(filename,credits_filename);
170                 have_bin_file = 1;
171         }
172         file = cfopen( filename, "rb" );
173         if (file == NULL) {
174                 char nfile[32];
175                 
176                 if (credits_filename)
177                         return;         //ok to not find special filename
178
179                 tempp = strchr(filename, '.');
180                 *tempp = '\0';
181                 sprintf(nfile, "%s.txb", filename);
182                 file = cfopen(nfile, "rb");
183                 if (file == NULL)
184                         Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
185                 have_bin_file = 1;
186         }
187
188         set_screen_mode(SCREEN_MENU);
189
190         WIN(DEFINE_SCREEN(NULL));
191
192 CreditsPaint:
193         gr_use_palette_table( "credits.256" );
194 #if defined(POLY_ACC)
195         pa_update_clut(gr_palette, 0, 256, 0);
196 #endif
197         header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
198         title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
199         names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
200         backdrop.bm_data=NULL;
201
202 //MWA  Made backdrop bitmap linear since it should always be.  the current canvas may not
203 //MWA  be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
204
205         pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
206         if (pcx_error != PCX_ERROR_NONE)                {
207                 cfclose(file);
208                 return;
209         }
210
211         songs_play_song( SONG_CREDITS, 1 );
212
213         gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
214
215 WINDOS(
216         dd_gr_set_current_canvas(NULL), 
217         gr_set_current_canvas(NULL)
218 );
219 WIN(DDGRLOCK(dd_grd_curcanv));
220         gr_bitmap(0,0,&backdrop);
221 WIN(DDGRUNLOCK(dd_grd_curcanv));
222         gr_update();
223         gr_palette_fade_in( gr_palette, 32, 0 );
224
225 //      Create a new offscreen buffer for the credits screen
226 //MWA  Let's be a little smarter about this and check the VR_offscreen buffer
227 //MWA  for size to determine if we can use that buffer.  If the game size
228 //MWA  matches what we need, then lets save memory.
229
230 #ifndef PA_3DFX_VOODOO
231 #ifndef WINDOWS
232         if (MenuHires && VR_offscreen_buffer->cv_w == 640)      {
233                 CreditsOffscreenBuf = VR_offscreen_buffer;
234         }
235         else if (MenuHires)     {
236                 CreditsOffscreenBuf = gr_create_canvas(640,480);
237         }
238         else {
239                 CreditsOffscreenBuf = gr_create_canvas(320,200);
240         }
241 #else
242         CreditsOffscreenBuf = gr_create_canvas(640,480);
243 #endif                           
244 #else
245         CreditsOffscreenBuf = gr_create_canvas(640,480);
246 #endif
247
248         if (!CreditsOffscreenBuf) 
249                 Error("Not enough memory to allocate Credits Buffer.");
250
251         //gr_clear_canvas(BM_XRGB(0,0,0));
252         key_flush();
253
254 #ifdef WINDOWS
255         if (!credinit)  
256 #endif
257         {
258                 last_time = timer_get_fixed_seconds();
259                 done = 0;
260                 first_line_offset = 0;
261         }
262
263         WIN(credinit = 1);
264
265         while( 1 )      {
266                 int k;
267
268                 do {
269                         buffer_line = (buffer_line+1) % NUM_LINES;
270 get_line:;
271                         if (cfgets( buffer[buffer_line], 80, file ))    {
272                                 char *p;
273                                 if (have_bin_file) {                            // is this a binary tbl file
274                                         for (i = 0; i < strlen(buffer[buffer_line]) - 1; i++) {
275                                                 encode_rotate_left(&(buffer[buffer_line][i]));
276                                                 buffer[buffer_line][i] ^= BITMAP_TBL_XOR;
277                                                 encode_rotate_left(&(buffer[buffer_line][i]));
278                                         }
279                                 }
280                                 p = buffer[buffer_line];
281                                 if (p[0] == ';')
282                                         goto get_line;
283
284                                 if (p[0] == '%')
285                                 {
286                                         if (p[1] == ALLOWED_CHAR)
287                                                 strcpy(p,p+2);
288                                         else
289                                                 goto get_line;
290                                 }
291
292                                 p = strchr(&buffer[buffer_line][0],'\n');
293                                 if (p) *p = '\0';
294                         } else  {
295                                 //fseek( file, 0, SEEK_SET);
296                                 buffer[buffer_line][0] = 0;
297                                 done++;
298                         }
299                 } while (extra_inc--);
300                 extra_inc = 0;
301
302 NO_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
303 PA_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
304                         int y;
305
306                         y = first_line_offset - i;
307
308                         gr_set_current_canvas(CreditsOffscreenBuf);
309                 
310                         gr_bitmap(0,0,&backdrop);
311
312                         for (j=0; j<NUM_LINES; j++ )    {
313                                 char *s;
314
315                                 l = (buffer_line + j + 1 ) %  NUM_LINES;
316                                 s = buffer[l];
317
318                                 if ( s[0] == '!' ) {
319                                         s++;
320                                 } else if ( s[0] == '$' )       {
321                                         grd_curcanv->cv_font = header_font;
322                                         s++;
323                                 } else if ( s[0] == '*' )       {
324                                         grd_curcanv->cv_font = title_font;
325                                         s++;
326                                 } else
327                                         grd_curcanv->cv_font = names_font;
328
329                                 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
330
331                                 tempp = strchr( s, '\t' );
332                                 if ( tempp )    {
333                                 //      Wacky Credits thing
334                                         int w, h, aw, w2, x1, x2;
335
336                                         *tempp = 0;
337                                         gr_get_string_size( s, &w, &h, &aw );
338                                         x1 = ((MenuHires?320:160)-w)/2;
339                                         gr_printf( x1 , y, s );
340                                         gr_get_string_size( &tempp[1], &w2, &h, &aw );
341                                         x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
342                                         gr_printf( x2, y, &tempp[1] );
343
344                                         dirty_box[j].left = ((MenuHires?320:160)-w)/2;
345                                         dirty_box[j].top = y;
346                                         dirty_box[j].width =(x2+w2)-x1;
347                                         dirty_box[j].height = h;
348
349                                         *tempp = '\t';
350                 
351                                 } else {
352                                 // Wacky Fast Credits thing
353                                         int w, h, aw;
354
355                                         gr_get_string_size( s, &w, &h, &aw);
356                                         dirty_box[j].width = w;
357                                 dirty_box[j].height = h;
358                                 dirty_box[j].top = y;
359                                 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
360
361                                         gr_printf( 0x8000, y, s );
362                                 }
363                                 gr_bitblt_fade_table = NULL;
364                                 if (buffer[l][0] == '!')
365                                         y += ROW_SPACING/2;
366                                 else
367                                         y += ROW_SPACING;
368                         }
369
370                         {       // Wacky Fast Credits Thing
371                                 box     *new_box;
372                                 grs_bitmap *tempbmp;
373                                 
374                                 for (j=0; j<NUM_LINES; j++ )
375                                 {
376                                         new_box = &dirty_box[j];
377
378                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
379                           
380                                 WIN(DDGRSCREENLOCK);
381 #if defined(POLY_ACC)
382                                         if(new_box->width != 0)
383 #endif
384                                                 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
385                                                                         new_box->left, new_box->top, new_box->left, new_box->top,
386                                                                         tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
387                                 WIN(DDGRSCREENUNLOCK);
388                                 }
389
390 #if defined(POLY_ACC)
391                 pa_flush();
392 #endif
393
394 #if !defined(POLY_ACC) || defined(MACINTOSH)
395                                 MAC( if(!PAEnabled) )                   // POLY_ACC always on for the macintosh
396                                 for (j=0; j<NUM_LINES; j++ )
397                                 {
398                                         new_box = &dirty_box[j];
399
400                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
401
402                                         gr_bm_bitblt(   new_box->width 
403                                                                         ,new_box->height+2
404                                                                         ,new_box->left
405                                                                         ,new_box->top
406                                                                         ,new_box->left
407                                                                         ,new_box->top
408                                                                         ,&backdrop
409                                                                         ,tempbmp );
410                                 }
411                                 
412 #endif
413                         gr_update();
414                                 
415                         }
416
417 //              Wacky Fast Credits thing doesn't need this (it's done above)
418 //@@            WINDOS(
419 //@@                    dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
420 //@@                    gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
421 //@@            );
422
423 //                      mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
424                         while( timer_get_fixed_seconds() < last_time+time_delay );
425                         last_time = timer_get_fixed_seconds();
426                 
427                 #ifdef WINDOWS
428                         {
429                                 MSG msg;
430
431                                 DoMessageStuff(&msg);
432
433                                 if (_RedrawScreen) {
434                                         _RedrawScreen = FALSE;
435
436                                         gr_close_font(header_font);
437                                         gr_close_font(title_font);
438                                         gr_close_font(names_font);
439
440                                         d_free(backdrop.bm_data);
441                                         gr_free_canvas(CreditsOffscreenBuf);
442                 
443                                         goto CreditsPaint;
444                                 }
445
446                                 DDGRRESTORE;
447                         }
448                 #endif
449
450                         //see if redbook song needs to be restarted
451                         songs_check_redbook_repeat();
452
453                         k = key_inkey();
454
455                         #ifndef NDEBUG
456                         if (k == KEY_BACKSP) {
457                                 Int3();
458                                 k=0;
459                         }
460                         #endif
461
462 //                      {
463 //                              fix ot = time_delay;
464 //                              time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
465 //                              if (ot!=time_delay)     {
466 //                                      mprintf( (0, "[%x] ", time_delay ));
467 //                              }
468 //                      }
469
470                         if (k == KEY_PRINT_SCREEN) {
471                                 save_screen_shot(0);
472                                 k = 0;
473                         }
474
475                         if ((k>0)||(done>NUM_LINES))    {
476                                         gr_close_font(header_font);
477                                         gr_close_font(title_font);
478                                         gr_close_font(names_font);
479                                         gr_palette_fade_out( gr_palette, 32, 0 );
480                                         gr_use_palette_table( DEFAULT_PALETTE );
481                                         d_free(backdrop.bm_data);
482                                         cfclose(file);
483                                 WINDOS(
484                                         dd_gr_set_current_canvas(save_canv),
485                                         gr_set_current_canvas(save_canv)
486                                 );
487                                         songs_play_song( SONG_TITLE, 1 );
488
489                                 #ifdef WINDOWS
490                                         gr_free_canvas(CreditsOffscreenBuf);
491                                 #else                                   
492                                         if (CreditsOffscreenBuf != VR_offscreen_buffer)
493                                                 gr_free_canvas(CreditsOffscreenBuf);
494                                 #endif
495
496                                 WIN(DEFINE_SCREEN(Menu_pcx_name));
497                         
498                                 return;
499                         }
500                 }
501
502                 if (buffer[(buffer_line + 1 ) %  NUM_LINES][0] == '!') {
503                         first_line_offset -= ROW_SPACING-ROW_SPACING/2;
504                         if (first_line_offset <= -ROW_SPACING) {
505                                 first_line_offset += ROW_SPACING;
506                                 extra_inc++;
507                         }
508                 }
509         }
510
511 }