1 /* $Id: credits.c,v 1.14 2005-08-02 06:13:56 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.14 2005-08-02 06:13:56 chris Exp $";
61 #include "menu.h" // for MenuHires
63 #define ROW_SPACING (MenuHires?26:11)
64 #define NUM_LINES_HIRES 21
65 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
67 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,
68 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
69 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
70 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
71 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
72 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
73 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
74 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,
77 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,
78 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,
79 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,
80 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,
81 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,
82 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,
83 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,
84 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,
85 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,
86 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,
87 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,
88 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,
89 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,
90 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,
91 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,
92 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
94 extern ubyte *gr_bitblt_fade_table;
96 grs_font * header_font;
97 grs_font * title_font;
98 grs_font * names_font;
101 #define ALLOWED_CHAR 'S'
103 #define ALLOWED_CHAR 'R'
107 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx") //only read from hog file
109 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
113 int left, top, width, height;
116 #define CREDITS_FILE (cfexist("mcredits.tex")?"mcredits.tex":cfexist("ocredits.tex")?"ocredits.tex":"credits.tex")
118 //if filename passed is NULL, show normal credits
119 void credits_show(char *credits_filename)
123 char buffer[NUM_LINES_HIRES][80];
125 ubyte backdrop_palette[768];
129 // fix time_delay = 4180; // ~ F1_0 / 12.9
130 // fix time_delay = 1784;
131 fix time_delay = 2800;
132 int first_line_offset,extra_inc=0;
133 int have_bin_file = 0;
137 box dirty_box[NUM_LINES_HIRES];
138 grs_canvas *CreditsOffscreenBuf=NULL;
139 grs_canvas *save_canv;
141 save_canv = grd_curcanv;
143 // Clear out all tex buffer lines.
144 for (i=0; i<NUM_LINES; i++ )
147 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
151 sprintf(filename, "%s", CREDITS_FILE);
153 if (credits_filename) {
154 strcpy(filename,credits_filename);
157 file = cfopen( filename, "rb" );
161 if (credits_filename)
162 return; //ok to not find special filename
164 tempp = strchr(filename, '.');
166 sprintf(nfile, "%s.txb", filename);
167 file = cfopen(nfile, "rb");
169 Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
173 set_screen_mode(SCREEN_MENU);
175 gr_use_palette_table( "credits.256" );
177 gr_palette_load(gr_palette);
179 header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
180 title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
181 names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
182 backdrop.bm_data=NULL;
184 //MWA Made backdrop bitmap linear since it should always be. the current canvas may not
185 //MWA be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
187 pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
188 if (pcx_error != PCX_ERROR_NONE) {
193 songs_play_song( SONG_CREDITS, 1 );
195 gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
197 gr_set_current_canvas(NULL);
198 gr_bitmap(0,0,&backdrop);
200 gr_palette_fade_in( gr_palette, 32, 0 );
202 // Create a new offscreen buffer for the credits screen
203 //MWA Let's be a little smarter about this and check the VR_offscreen buffer
204 //MWA for size to determine if we can use that buffer. If the game size
205 //MWA matches what we need, then lets save memory.
207 if (MenuHires && VR_offscreen_buffer->cv_w == 640) {
208 CreditsOffscreenBuf = VR_offscreen_buffer;
210 else if (MenuHires) {
211 CreditsOffscreenBuf = gr_create_canvas(640,480);
214 CreditsOffscreenBuf = gr_create_canvas(320,200);
217 if (!CreditsOffscreenBuf)
218 Error("Not enough memory to allocate Credits Buffer.");
220 //gr_clear_canvas(BM_XRGB(0,0,0));
224 last_time = timer_get_fixed_seconds();
226 first_line_offset = 0;
233 buffer_line = (buffer_line+1) % NUM_LINES;
235 if (cfgets( buffer[buffer_line], 80, file )) {
237 if (have_bin_file) // is this a binary tbl file
238 decode_text_line (buffer[buffer_line]);
239 p = buffer[buffer_line];
245 if (p[1] == ALLOWED_CHAR)
252 //fseek( file, 0, SEEK_SET);
253 buffer[buffer_line][0] = 0;
256 } while (extra_inc--);
259 for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {
262 y = first_line_offset - i;
264 gr_set_current_canvas(CreditsOffscreenBuf);
266 gr_bitmap(0,0,&backdrop);
268 for (j=0; j<NUM_LINES; j++ ) {
271 l = (buffer_line + j + 1 ) % NUM_LINES;
276 } else if ( s[0] == '$' ) {
277 grd_curcanv->cv_font = header_font;
279 } else if ( s[0] == '*' ) {
280 grd_curcanv->cv_font = title_font;
283 grd_curcanv->cv_font = names_font;
285 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
287 tempp = strchr( s, '\t' );
289 // Wacky Credits thing
290 int w, h, aw, w2, x1, x2;
293 gr_get_string_size( s, &w, &h, &aw );
294 x1 = ((MenuHires?320:160)-w)/2;
295 gr_printf( x1 , y, s );
296 gr_get_string_size( &tempp[1], &w2, &h, &aw );
297 x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
298 gr_printf( x2, y, &tempp[1] );
300 dirty_box[j].left = ((MenuHires?320:160)-w)/2;
301 dirty_box[j].top = y;
302 dirty_box[j].width =(x2+w2)-x1;
303 dirty_box[j].height = h;
308 // Wacky Fast Credits thing
311 gr_get_string_size( s, &w, &h, &aw);
312 dirty_box[j].width = w;
313 dirty_box[j].height = h;
314 dirty_box[j].top = y;
315 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
317 gr_printf( 0x8000, y, s );
319 gr_bitblt_fade_table = NULL;
320 if (buffer[l][0] == '!')
326 { // Wacky Fast Credits Thing
330 for (j=0; j<NUM_LINES; j++ )
332 new_box = &dirty_box[j];
334 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
336 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
337 new_box->left, new_box->top, new_box->left, new_box->top,
338 tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
342 for (j=0; j<NUM_LINES; j++ )
344 new_box = &dirty_box[j];
346 tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
348 gr_bm_bitblt( new_box->width
363 // Wacky Fast Credits thing doesn't need this (it's done above)
364 //@@ gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
366 // mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
367 while( timer_get_fixed_seconds() < last_time+time_delay );
368 last_time = timer_get_fixed_seconds();
370 //see if redbook song needs to be restarted
371 songs_check_redbook_repeat();
376 if (k == KEY_BACKSP) {
383 // fix ot = time_delay;
384 // time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
385 // if (ot!=time_delay) {
386 // mprintf( (0, "[%x] ", time_delay ));
390 if (k == KEY_PRINT_SCREEN) {
395 if ((k>0)||(done>NUM_LINES)) {
396 gr_close_font(header_font);
397 gr_close_font(title_font);
398 gr_close_font(names_font);
399 gr_palette_fade_out( gr_palette, 32, 0 );
400 gr_use_palette_table( DEFAULT_PALETTE );
401 d_free(backdrop.bm_data);
403 gr_set_current_canvas(save_canv);
404 songs_play_song( SONG_TITLE, 1 );
406 if (CreditsOffscreenBuf != VR_offscreen_buffer)
407 gr_free_canvas(CreditsOffscreenBuf);
413 if (buffer[(buffer_line + 1 ) % NUM_LINES][0] == '!') {
414 first_line_offset -= ROW_SPACING-ROW_SPACING/2;
415 if (first_line_offset <= -ROW_SPACING) {
416 first_line_offset += ROW_SPACING;