1 /* $Id: credits.c,v 1.11 2004-10-23 17:42:13 schaffner Exp $ */
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.
17 * Routines to display the credits.
26 static char rcsid[] = "$Id: credits.c,v 1.11 2004-10-23 17:42:13 schaffner Exp $";
39 #include "pa_enabl.h" //$$POLY_ACC
66 #include "menu.h" // for MenuHires
72 #define ROW_SPACING (MenuHires?26:11)
73 #define NUM_LINES_HIRES 21
74 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
76 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,
77 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
78 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
79 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
80 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
81 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
82 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
83 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,
86 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,
87 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,
88 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,
89 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,
90 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,
91 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,
92 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,
93 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,
94 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,
95 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,
96 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,
97 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,
98 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,
99 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,
100 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,
101 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
103 extern ubyte *gr_bitblt_fade_table;
105 grs_font * header_font;
106 grs_font * title_font;
107 grs_font * names_font;
110 #define ALLOWED_CHAR 'S'
112 #define ALLOWED_CHAR 'R'
116 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx") //only read from hog file
118 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
122 int left, top, width, height;
125 #define CREDITS_FILE (cfexist("mcredits.tex")?"mcredits.tex":cfexist("ocredits.tex")?"ocredits.tex":"credits.tex")
127 //if filename passed is NULL, show normal credits
128 void credits_show(char *credits_filename)
132 char buffer[NUM_LINES_HIRES][80];
134 ubyte backdrop_palette[768];
138 // fix time_delay = 4180; // ~ F1_0 / 12.9
139 // fix time_delay = 1784;
140 fix time_delay = 2800;
141 int first_line_offset,extra_inc=0;
142 int have_bin_file = 0;
146 WIN(int credinit = 0;)
148 box dirty_box[NUM_LINES_HIRES];
149 grs_canvas *CreditsOffscreenBuf=NULL;
152 dd_grs_canvas *save_canv,
153 grs_canvas *save_canv
157 save_canv = dd_grd_curcanv,
158 save_canv = grd_curcanv
161 // Clear out all tex buffer lines.
162 for (i=0; i<NUM_LINES; i++ )
165 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
169 sprintf(filename, "%s", CREDITS_FILE);
171 if (credits_filename) {
172 strcpy(filename,credits_filename);
175 file = cfopen( filename, "rb" );
179 if (credits_filename)
180 return; //ok to not find special filename
182 tempp = strchr(filename, '.');
184 sprintf(nfile, "%s.txb", filename);
185 file = cfopen(nfile, "rb");
187 Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
191 set_screen_mode(SCREEN_MENU);
193 WIN(DEFINE_SCREEN(NULL));
198 gr_use_palette_table( "credits.256" );
200 gr_palette_load(gr_palette);
202 #if defined(POLY_ACC)
203 pa_update_clut(gr_palette, 0, 256, 0);
205 header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
206 title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
207 names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
208 backdrop.bm_data=NULL;
210 //MWA Made backdrop bitmap linear since it should always be. the current canvas may not
211 //MWA be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
213 pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
214 if (pcx_error != PCX_ERROR_NONE) {
219 songs_play_song( SONG_CREDITS, 1 );
221 gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
224 dd_gr_set_current_canvas(NULL),
225 gr_set_current_canvas(NULL)
227 WIN(DDGRLOCK(dd_grd_curcanv));
228 gr_bitmap(0,0,&backdrop);
229 WIN(DDGRUNLOCK(dd_grd_curcanv));
231 gr_palette_fade_in( gr_palette, 32, 0 );
233 // Create a new offscreen buffer for the credits screen
234 //MWA Let's be a little smarter about this and check the VR_offscreen buffer
235 //MWA for size to determine if we can use that buffer. If the game size
236 //MWA matches what we need, then lets save memory.
238 #ifndef PA_3DFX_VOODOO
240 if (MenuHires && VR_offscreen_buffer->cv_w == 640) {
241 CreditsOffscreenBuf = VR_offscreen_buffer;
243 else if (MenuHires) {
244 CreditsOffscreenBuf = gr_create_canvas(640,480);
247 CreditsOffscreenBuf = gr_create_canvas(320,200);
250 CreditsOffscreenBuf = gr_create_canvas(640,480);
253 CreditsOffscreenBuf = gr_create_canvas(640,480);
256 if (!CreditsOffscreenBuf)
257 Error("Not enough memory to allocate Credits Buffer.");
259 //gr_clear_canvas(BM_XRGB(0,0,0));
266 last_time = timer_get_fixed_seconds();
268 first_line_offset = 0;
277 buffer_line = (buffer_line+1) % NUM_LINES;
279 if (cfgets( buffer[buffer_line], 80, file )) {
281 if (have_bin_file) // is this a binary tbl file
282 decode_text_line (buffer[buffer_line]);
283 p = buffer[buffer_line];
289 if (p[1] == ALLOWED_CHAR)
296 //fseek( file, 0, SEEK_SET);
297 buffer[buffer_line][0] = 0;
300 } while (extra_inc--);
303 NO_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
304 PA_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
307 y = first_line_offset - i;
309 gr_set_current_canvas(CreditsOffscreenBuf);
311 gr_bitmap(0,0,&backdrop);
313 for (j=0; j<NUM_LINES; j++ ) {
316 l = (buffer_line + j + 1 ) % NUM_LINES;
321 } else if ( s[0] == '$' ) {
322 grd_curcanv->cv_font = header_font;
324 } else if ( s[0] == '*' ) {
325 grd_curcanv->cv_font = title_font;
328 grd_curcanv->cv_font = names_font;
330 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
332 tempp = strchr( s, '\t' );
334 // Wacky Credits thing
335 int w, h, aw, w2, x1, x2;
338 gr_get_string_size( s, &w, &h, &aw );
339 x1 = ((MenuHires?320:160)-w)/2;
340 gr_printf( x1 , y, s );
341 gr_get_string_size( &tempp[1], &w2, &h, &aw );
342 x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
343 gr_printf( x2, y, &tempp[1] );
345 dirty_box[j].left = ((MenuHires?320:160)-w)/2;
346 dirty_box[j].top = y;
347 dirty_box[j].width =(x2+w2)-x1;
348 dirty_box[j].height = h;
353 // Wacky Fast Credits thing
356 gr_get_string_size( s, &w, &h, &aw);
357 dirty_box[j].width = w;
358 dirty_box[j].height = h;
359 dirty_box[j].top = y;
360 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
362 gr_printf( 0x8000, y, s );
364 gr_bitblt_fade_table = NULL;
365 if (buffer[l][0] == '!')
371 { // Wacky Fast Credits Thing
375 for (j=0; j<NUM_LINES; j++ )
377 new_box = &dirty_box[j];
379 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
382 #if defined(POLY_ACC)
383 if(new_box->width != 0)
385 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
386 new_box->left, new_box->top, new_box->left, new_box->top,
387 tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
388 WIN(DDGRSCREENUNLOCK);
391 #if defined(POLY_ACC)
395 #if !defined(POLY_ACC) || defined(MACINTOSH)
396 MAC( if(!PAEnabled) ) // POLY_ACC always on for the macintosh
397 for (j=0; j<NUM_LINES; j++ )
399 new_box = &dirty_box[j];
401 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
403 gr_bm_bitblt( new_box->width
418 // Wacky Fast Credits thing doesn't need this (it's done above)
420 //@@ dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
421 //@@ 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 // mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
425 while( timer_get_fixed_seconds() < last_time+time_delay );
426 last_time = timer_get_fixed_seconds();
432 DoMessageStuff(&msg);
435 _RedrawScreen = FALSE;
437 gr_close_font(header_font);
438 gr_close_font(title_font);
439 gr_close_font(names_font);
441 d_free(backdrop.bm_data);
442 gr_free_canvas(CreditsOffscreenBuf);
451 //see if redbook song needs to be restarted
452 songs_check_redbook_repeat();
457 if (k == KEY_BACKSP) {
464 // fix ot = time_delay;
465 // time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
466 // if (ot!=time_delay) {
467 // mprintf( (0, "[%x] ", time_delay ));
471 if (k == KEY_PRINT_SCREEN) {
476 if ((k>0)||(done>NUM_LINES)) {
477 gr_close_font(header_font);
478 gr_close_font(title_font);
479 gr_close_font(names_font);
480 gr_palette_fade_out( gr_palette, 32, 0 );
481 gr_use_palette_table( DEFAULT_PALETTE );
482 d_free(backdrop.bm_data);
485 dd_gr_set_current_canvas(save_canv),
486 gr_set_current_canvas(save_canv)
488 songs_play_song( SONG_TITLE, 1 );
491 gr_free_canvas(CreditsOffscreenBuf);
493 if (CreditsOffscreenBuf != VR_offscreen_buffer)
494 gr_free_canvas(CreditsOffscreenBuf);
497 WIN(DEFINE_SCREEN(Menu_pcx_name));
503 if (buffer[(buffer_line + 1 ) % NUM_LINES][0] == '!') {
504 first_line_offset -= ROW_SPACING-ROW_SPACING/2;
505 if (first_line_offset <= -ROW_SPACING) {
506 first_line_offset += ROW_SPACING;