1 /* $Id: credits.c,v 1.13 2005-07-30 01:50:17 chris 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.13 2005-07-30 01:50:17 chris Exp $";
65 #include "menu.h" // for MenuHires
67 #define ROW_SPACING (MenuHires?26:11)
68 #define NUM_LINES_HIRES 21
69 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
71 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,
72 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
73 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
74 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
75 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
76 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
77 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
78 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,
81 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,
82 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,
83 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,
84 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,
85 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,
86 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,
87 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,
88 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,
89 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,
90 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,
91 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,
92 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,
93 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,
94 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,
95 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,
96 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
98 extern ubyte *gr_bitblt_fade_table;
100 grs_font * header_font;
101 grs_font * title_font;
102 grs_font * names_font;
105 #define ALLOWED_CHAR 'S'
107 #define ALLOWED_CHAR 'R'
111 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx") //only read from hog file
113 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
117 int left, top, width, height;
120 #define CREDITS_FILE (cfexist("mcredits.tex")?"mcredits.tex":cfexist("ocredits.tex")?"ocredits.tex":"credits.tex")
122 //if filename passed is NULL, show normal credits
123 void credits_show(char *credits_filename)
127 char buffer[NUM_LINES_HIRES][80];
129 ubyte backdrop_palette[768];
133 // fix time_delay = 4180; // ~ F1_0 / 12.9
134 // fix time_delay = 1784;
135 fix time_delay = 2800;
136 int first_line_offset,extra_inc=0;
137 int have_bin_file = 0;
141 WIN(int credinit = 0;)
143 box dirty_box[NUM_LINES_HIRES];
144 grs_canvas *CreditsOffscreenBuf=NULL;
147 dd_grs_canvas *save_canv,
148 grs_canvas *save_canv
152 save_canv = dd_grd_curcanv,
153 save_canv = grd_curcanv
156 // Clear out all tex buffer lines.
157 for (i=0; i<NUM_LINES; i++ )
160 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
164 sprintf(filename, "%s", CREDITS_FILE);
166 if (credits_filename) {
167 strcpy(filename,credits_filename);
170 file = cfopen( filename, "rb" );
174 if (credits_filename)
175 return; //ok to not find special filename
177 tempp = strchr(filename, '.');
179 sprintf(nfile, "%s.txb", filename);
180 file = cfopen(nfile, "rb");
182 Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
186 set_screen_mode(SCREEN_MENU);
188 WIN(DEFINE_SCREEN(NULL));
193 gr_use_palette_table( "credits.256" );
195 gr_palette_load(gr_palette);
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;
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.
205 pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
206 if (pcx_error != PCX_ERROR_NONE) {
211 songs_play_song( SONG_CREDITS, 1 );
213 gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
216 dd_gr_set_current_canvas(NULL),
217 gr_set_current_canvas(NULL)
219 WIN(DDGRLOCK(dd_grd_curcanv));
220 gr_bitmap(0,0,&backdrop);
221 WIN(DDGRUNLOCK(dd_grd_curcanv));
223 gr_palette_fade_in( gr_palette, 32, 0 );
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.
231 if (MenuHires && VR_offscreen_buffer->cv_w == 640) {
232 CreditsOffscreenBuf = VR_offscreen_buffer;
234 else if (MenuHires) {
235 CreditsOffscreenBuf = gr_create_canvas(640,480);
238 CreditsOffscreenBuf = gr_create_canvas(320,200);
241 CreditsOffscreenBuf = gr_create_canvas(640,480);
244 if (!CreditsOffscreenBuf)
245 Error("Not enough memory to allocate Credits Buffer.");
247 //gr_clear_canvas(BM_XRGB(0,0,0));
254 last_time = timer_get_fixed_seconds();
256 first_line_offset = 0;
265 buffer_line = (buffer_line+1) % NUM_LINES;
267 if (cfgets( buffer[buffer_line], 80, file )) {
269 if (have_bin_file) // is this a binary tbl file
270 decode_text_line (buffer[buffer_line]);
271 p = buffer[buffer_line];
277 if (p[1] == ALLOWED_CHAR)
284 //fseek( file, 0, SEEK_SET);
285 buffer[buffer_line][0] = 0;
288 } while (extra_inc--);
291 for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {
294 y = first_line_offset - i;
296 gr_set_current_canvas(CreditsOffscreenBuf);
298 gr_bitmap(0,0,&backdrop);
300 for (j=0; j<NUM_LINES; j++ ) {
303 l = (buffer_line + j + 1 ) % NUM_LINES;
308 } else if ( s[0] == '$' ) {
309 grd_curcanv->cv_font = header_font;
311 } else if ( s[0] == '*' ) {
312 grd_curcanv->cv_font = title_font;
315 grd_curcanv->cv_font = names_font;
317 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
319 tempp = strchr( s, '\t' );
321 // Wacky Credits thing
322 int w, h, aw, w2, x1, x2;
325 gr_get_string_size( s, &w, &h, &aw );
326 x1 = ((MenuHires?320:160)-w)/2;
327 gr_printf( x1 , y, s );
328 gr_get_string_size( &tempp[1], &w2, &h, &aw );
329 x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
330 gr_printf( x2, y, &tempp[1] );
332 dirty_box[j].left = ((MenuHires?320:160)-w)/2;
333 dirty_box[j].top = y;
334 dirty_box[j].width =(x2+w2)-x1;
335 dirty_box[j].height = h;
340 // Wacky Fast Credits thing
343 gr_get_string_size( s, &w, &h, &aw);
344 dirty_box[j].width = w;
345 dirty_box[j].height = h;
346 dirty_box[j].top = y;
347 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
349 gr_printf( 0x8000, y, s );
351 gr_bitblt_fade_table = NULL;
352 if (buffer[l][0] == '!')
358 { // Wacky Fast Credits Thing
362 for (j=0; j<NUM_LINES; j++ )
364 new_box = &dirty_box[j];
366 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
369 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
370 new_box->left, new_box->top, new_box->left, new_box->top,
371 tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
372 WIN(DDGRSCREENUNLOCK);
376 for (j=0; j<NUM_LINES; j++ )
378 new_box = &dirty_box[j];
380 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
382 gr_bm_bitblt( new_box->width
397 // Wacky Fast Credits thing doesn't need this (it's done above)
399 //@@ dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
400 //@@ gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
403 // mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
404 while( timer_get_fixed_seconds() < last_time+time_delay );
405 last_time = timer_get_fixed_seconds();
411 DoMessageStuff(&msg);
414 _RedrawScreen = FALSE;
416 gr_close_font(header_font);
417 gr_close_font(title_font);
418 gr_close_font(names_font);
420 d_free(backdrop.bm_data);
421 gr_free_canvas(CreditsOffscreenBuf);
430 //see if redbook song needs to be restarted
431 songs_check_redbook_repeat();
436 if (k == KEY_BACKSP) {
443 // fix ot = time_delay;
444 // time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
445 // if (ot!=time_delay) {
446 // mprintf( (0, "[%x] ", time_delay ));
450 if (k == KEY_PRINT_SCREEN) {
455 if ((k>0)||(done>NUM_LINES)) {
456 gr_close_font(header_font);
457 gr_close_font(title_font);
458 gr_close_font(names_font);
459 gr_palette_fade_out( gr_palette, 32, 0 );
460 gr_use_palette_table( DEFAULT_PALETTE );
461 d_free(backdrop.bm_data);
464 dd_gr_set_current_canvas(save_canv),
465 gr_set_current_canvas(save_canv)
467 songs_play_song( SONG_TITLE, 1 );
470 gr_free_canvas(CreditsOffscreenBuf);
472 if (CreditsOffscreenBuf != VR_offscreen_buffer)
473 gr_free_canvas(CreditsOffscreenBuf);
476 WIN(DEFINE_SCREEN(Menu_pcx_name));
482 if (buffer[(buffer_line + 1 ) % NUM_LINES][0] == '!') {
483 first_line_offset -= ROW_SPACING-ROW_SPACING/2;
484 if (first_line_offset <= -ROW_SPACING) {
485 first_line_offset += ROW_SPACING;