]> icculus.org git repositories - btb/d2x.git/blob - main/credits.c
move old per-file change logs into new file ChangeLog-old
[btb/d2x.git] / main / credits.c
1 /* $Id: credits.c,v 1.9 2004-08-28 23:17:45 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.9 2004-08-28 23:17:45 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]) - 1; 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                                 p = strchr(&buffer[buffer_line][0],'\n');
301                                 if (p) *p = '\0';
302                         } else  {
303                                 //fseek( file, 0, SEEK_SET);
304                                 buffer[buffer_line][0] = 0;
305                                 done++;
306                         }
307                 } while (extra_inc--);
308                 extra_inc = 0;
309
310 NO_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
311 PA_DFX (for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {)
312                         int y;
313
314                         y = first_line_offset - i;
315
316                         gr_set_current_canvas(CreditsOffscreenBuf);
317                 
318                         gr_bitmap(0,0,&backdrop);
319
320                         for (j=0; j<NUM_LINES; j++ )    {
321                                 char *s;
322
323                                 l = (buffer_line + j + 1 ) %  NUM_LINES;
324                                 s = buffer[l];
325
326                                 if ( s[0] == '!' ) {
327                                         s++;
328                                 } else if ( s[0] == '$' )       {
329                                         grd_curcanv->cv_font = header_font;
330                                         s++;
331                                 } else if ( s[0] == '*' )       {
332                                         grd_curcanv->cv_font = title_font;
333                                         s++;
334                                 } else
335                                         grd_curcanv->cv_font = names_font;
336
337                                 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
338
339                                 tempp = strchr( s, '\t' );
340                                 if ( tempp )    {
341                                 //      Wacky Credits thing
342                                         int w, h, aw, w2, x1, x2;
343
344                                         *tempp = 0;
345                                         gr_get_string_size( s, &w, &h, &aw );
346                                         x1 = ((MenuHires?320:160)-w)/2;
347                                         gr_printf( x1 , y, s );
348                                         gr_get_string_size( &tempp[1], &w2, &h, &aw );
349                                         x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
350                                         gr_printf( x2, y, &tempp[1] );
351
352                                         dirty_box[j].left = ((MenuHires?320:160)-w)/2;
353                                         dirty_box[j].top = y;
354                                         dirty_box[j].width =(x2+w2)-x1;
355                                         dirty_box[j].height = h;
356
357                                         *tempp = '\t';
358                 
359                                 } else {
360                                 // Wacky Fast Credits thing
361                                         int w, h, aw;
362
363                                         gr_get_string_size( s, &w, &h, &aw);
364                                         dirty_box[j].width = w;
365                                 dirty_box[j].height = h;
366                                 dirty_box[j].top = y;
367                                 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
368
369                                         gr_printf( 0x8000, y, s );
370                                 }
371                                 gr_bitblt_fade_table = NULL;
372                                 if (buffer[l][0] == '!')
373                                         y += ROW_SPACING/2;
374                                 else
375                                         y += ROW_SPACING;
376                         }
377
378                         {       // Wacky Fast Credits Thing
379                                 box     *new_box;
380                                 grs_bitmap *tempbmp;
381
382                                 for (j=0; j<NUM_LINES; j++ )
383                                 {
384                                         new_box = &dirty_box[j];
385
386                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
387
388                                 WIN(DDGRSCREENLOCK);
389 #if defined(POLY_ACC)
390                                         if(new_box->width != 0)
391 #endif
392                                                 gr_bm_bitblt( new_box->width + 1, new_box->height +4,
393                                                                         new_box->left, new_box->top, new_box->left, new_box->top,
394                                                                         tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
395                                 WIN(DDGRSCREENUNLOCK);
396                                 }
397
398 #if defined(POLY_ACC)
399                 pa_flush();
400 #endif
401
402 #if !defined(POLY_ACC) || defined(MACINTOSH)
403                                 MAC( if(!PAEnabled) )                   // POLY_ACC always on for the macintosh
404                                 for (j=0; j<NUM_LINES; j++ )
405                                 {
406                                         new_box = &dirty_box[j];
407
408                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
409
410                                         gr_bm_bitblt(   new_box->width
411                                                                         ,new_box->height+2
412                                                                         ,new_box->left
413                                                                         ,new_box->top
414                                                                         ,new_box->left
415                                                                         ,new_box->top
416                                                                         ,&backdrop
417                                                                         ,tempbmp );
418                                 }
419                                 
420 #endif
421                         gr_update();
422                                 
423                         }
424
425 //              Wacky Fast Credits thing doesn't need this (it's done above)
426 //@@            WINDOS(
427 //@@                    dd_gr_blt_notrans(CreditsOffscreenBuf, 0,0,0,0, dd_grd_screencanv, 0,0,0,0),
428 //@@                    gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
429 //@@            );
430
431 //                      mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
432                         while( timer_get_fixed_seconds() < last_time+time_delay );
433                         last_time = timer_get_fixed_seconds();
434                 
435                 #ifdef WINDOWS
436                         {
437                                 MSG msg;
438
439                                 DoMessageStuff(&msg);
440
441                                 if (_RedrawScreen) {
442                                         _RedrawScreen = FALSE;
443
444                                         gr_close_font(header_font);
445                                         gr_close_font(title_font);
446                                         gr_close_font(names_font);
447
448                                         d_free(backdrop.bm_data);
449                                         gr_free_canvas(CreditsOffscreenBuf);
450                 
451                                         goto CreditsPaint;
452                                 }
453
454                                 DDGRRESTORE;
455                         }
456                 #endif
457
458                         //see if redbook song needs to be restarted
459                         songs_check_redbook_repeat();
460
461                         k = key_inkey();
462
463                         #ifndef NDEBUG
464                         if (k == KEY_BACKSP) {
465                                 Int3();
466                                 k=0;
467                         }
468                         #endif
469
470 //                      {
471 //                              fix ot = time_delay;
472 //                              time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
473 //                              if (ot!=time_delay)     {
474 //                                      mprintf( (0, "[%x] ", time_delay ));
475 //                              }
476 //                      }
477
478                         if (k == KEY_PRINT_SCREEN) {
479                                 save_screen_shot(0);
480                                 k = 0;
481                         }
482
483                         if ((k>0)||(done>NUM_LINES))    {
484                                         gr_close_font(header_font);
485                                         gr_close_font(title_font);
486                                         gr_close_font(names_font);
487                                         gr_palette_fade_out( gr_palette, 32, 0 );
488                                         gr_use_palette_table( DEFAULT_PALETTE );
489                                         d_free(backdrop.bm_data);
490                                         cfclose(file);
491                                 WINDOS(
492                                         dd_gr_set_current_canvas(save_canv),
493                                         gr_set_current_canvas(save_canv)
494                                 );
495                                         songs_play_song( SONG_TITLE, 1 );
496
497                                 #ifdef WINDOWS
498                                         gr_free_canvas(CreditsOffscreenBuf);
499                                 #else                                   
500                                         if (CreditsOffscreenBuf != VR_offscreen_buffer)
501                                                 gr_free_canvas(CreditsOffscreenBuf);
502                                 #endif
503
504                                 WIN(DEFINE_SCREEN(Menu_pcx_name));
505                         
506                                 return;
507                         }
508                 }
509
510                 if (buffer[(buffer_line + 1 ) %  NUM_LINES][0] == '!') {
511                         first_line_offset -= ROW_SPACING-ROW_SPACING/2;
512                         if (first_line_offset <= -ROW_SPACING) {
513                                 first_line_offset += ROW_SPACING;
514                                 extra_inc++;
515                         }
516                 }
517         }
518
519 }