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