]> icculus.org git repositories - btb/d2x.git/blob - main/credits.c
remove rcs tags
[btb/d2x.git] / main / credits.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Routines to display the credits.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <ctype.h>
29
30 #include "error.h"
31 #include "pstypes.h"
32 #include "gr.h"
33 #include "mono.h"
34 #include "key.h"
35 #include "palette.h"
36 #include "game.h"
37 #include "gamepal.h"
38 #include "timer.h"
39
40 #include "newmenu.h"
41 #include "gamefont.h"
42 #ifdef NETWORK
43 #include "network.h"
44 #endif
45 #include "iff.h"
46 #include "pcx.h"
47 #include "u_mem.h"
48 #include "mouse.h"
49 #include "joy.h"
50 #include "screens.h"
51 #include "digi.h"
52
53 #include "cfile.h"
54 #include "text.h"
55 #include "songs.h"
56 #include "menu.h"  // for MenuHires
57
58 #define ROW_SPACING (MenuHires?26:11)
59 #define NUM_LINES_HIRES 21
60 #define NUM_LINES (MenuHires?NUM_LINES_HIRES:20)
61
62 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,
63 11,11,12,12,12,13,13,14,14,15,15,15,16,16,17,17,17,18,18,19,19,19,20,20,
64 20,21,21,22,22,22,23,23,23,24,24,24,24,25,25,25,26,26,26,26,27,27,27,27,
65 28,28,28,28,28,29,29,29,29,29,29,30,30,30,30,30,30,30,30,30,31,31,31,31,
66 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,30,30,30,30,30,
67 30,30,30,30,29,29,29,29,29,29,28,28,28,28,28,27,27,27,27,26,26,26,26,25,
68 25,25,24,24,24,24,23,23,23,22,22,22,21,21,20,20,20,19,19,19,18,18,17,17,
69 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,
70 5,4,4,3,3,2,2,1 };
71
72 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,
73 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,
74 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,
75 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,
76 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,
77 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,
78 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,
79 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,
80 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,
81 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,
82 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,
83 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,
84 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,
85 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,
86 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,
87 5,5,4,4,4,4,4,3,3,3,3,3,2,2,2,2,2,1,1};
88
89 extern ubyte *gr_bitblt_fade_table;
90
91 grs_font * header_font;
92 grs_font * title_font;
93 grs_font * names_font;
94
95 #ifdef SHAREWARE
96 #define ALLOWED_CHAR 'S'
97 #else
98 #define ALLOWED_CHAR 'R'
99 #endif
100
101 #ifdef RELEASE
102 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"\x01starsb.pcx":"\x01stars.pcx")        //only read from hog file
103 #else
104 #define CREDITS_BACKGROUND_FILENAME (MenuHires?"starsb.pcx":"stars.pcx")
105 #endif
106
107 typedef struct box {
108         int left, top, width, height;
109 } box_t;
110
111 #define CREDITS_FILE    (cfexist("mcredits.tex")?"mcredits.tex":cfexist("ocredits.tex")?"ocredits.tex":"credits.tex")
112
113 //if filename passed is NULL, show normal credits
114 void credits_show(char *credits_filename)
115 {
116         int i, j, l, done;
117         CFILE * file;
118         char buffer[NUM_LINES_HIRES][80];
119         grs_bitmap backdrop;
120         ubyte backdrop_palette[768];
121         int pcx_error;
122         int buffer_line = 0;
123         fix last_time;
124 //      fix time_delay = 4180;                  // ~ F1_0 / 12.9
125 //      fix time_delay = 1784;
126         fix time_delay = 2800;
127         int first_line_offset,extra_inc=0;
128         int have_bin_file = 0;
129         char * tempp;
130         char filename[32];
131
132         box_t dirty_box[NUM_LINES_HIRES];
133         grs_canvas *CreditsOffscreenBuf=NULL;
134         grs_canvas *save_canv;
135
136         save_canv = grd_curcanv;
137
138         // Clear out all tex buffer lines.
139         for (i=0; i<NUM_LINES; i++ )
140         {
141                 buffer[i][0] = 0;
142                 dirty_box[i].left = dirty_box[i].top = dirty_box[i].width = dirty_box[i].height = 0;
143         }
144
145
146         sprintf(filename, "%s", CREDITS_FILE);
147         have_bin_file = 0;
148         if (credits_filename) {
149                 strcpy(filename,credits_filename);
150                 have_bin_file = 1;
151         }
152         file = cfopen( filename, "rb" );
153         if (file == NULL) {
154                 char nfile[32];
155                 
156                 if (credits_filename)
157                         return;         //ok to not find special filename
158
159                 tempp = strchr(filename, '.');
160                 *tempp = '\0';
161                 sprintf(nfile, "%s.txb", filename);
162                 file = cfopen(nfile, "rb");
163                 if (file == NULL)
164                         Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
165                 have_bin_file = 1;
166         }
167
168         set_screen_mode(SCREEN_MENU);
169
170         gr_use_palette_table( "credits.256" );
171 #ifdef OGL
172         gr_palette_load(gr_palette);
173 #endif
174         header_font = gr_init_font( MenuHires?"font1-1h.fnt":"font1-1.fnt" );
175         title_font = gr_init_font( MenuHires?"font2-3h.fnt":"font2-3.fnt" );
176         names_font = gr_init_font( MenuHires?"font2-2h.fnt":"font2-2.fnt" );
177         backdrop.bm_data=NULL;
178
179 //MWA  Made backdrop bitmap linear since it should always be.  the current canvas may not
180 //MWA  be linear, so we can't rely on grd_curcanv->cv_bitmap->bm_type.
181
182         pcx_error = pcx_read_bitmap(CREDITS_BACKGROUND_FILENAME,&backdrop, BM_LINEAR,backdrop_palette);
183         if (pcx_error != PCX_ERROR_NONE)                {
184                 cfclose(file);
185                 return;
186         }
187
188         songs_play_song( SONG_CREDITS, 1 );
189
190         gr_remap_bitmap_good( &backdrop,backdrop_palette, -1, -1 );
191
192         gr_set_current_canvas(NULL);
193         gr_bitmap(0,0,&backdrop);
194         gr_update();
195         gr_palette_fade_in( gr_palette, 32, 0 );
196
197 //      Create a new offscreen buffer for the credits screen
198 //MWA  Let's be a little smarter about this and check the VR_offscreen buffer
199 //MWA  for size to determine if we can use that buffer.  If the game size
200 //MWA  matches what we need, then lets save memory.
201
202         if (MenuHires && VR_offscreen_buffer->cv_w == 640)      {
203                 CreditsOffscreenBuf = VR_offscreen_buffer;
204         }
205         else if (MenuHires)     {
206                 CreditsOffscreenBuf = gr_create_canvas(640,480);
207         }
208         else {
209                 CreditsOffscreenBuf = gr_create_canvas(320,200);
210         }
211
212         if (!CreditsOffscreenBuf)
213                 Error("Not enough memory to allocate Credits Buffer.");
214
215         //gr_clear_canvas(BM_XRGB(0,0,0));
216         key_flush();
217
218         {
219                 last_time = timer_get_fixed_seconds();
220                 done = 0;
221                 first_line_offset = 0;
222         }
223
224         while( 1 )      {
225                 int k;
226
227                 do {
228                         buffer_line = (buffer_line+1) % NUM_LINES;
229 get_line:;
230                         if (cfgets( buffer[buffer_line], 80, file ))    {
231                                 char *p;
232                                 if (have_bin_file) // is this a binary tbl file
233                                         decode_text_line (buffer[buffer_line]);
234                                 p = buffer[buffer_line];
235                                 if (p[0] == ';')
236                                         goto get_line;
237
238                                 if (p[0] == '%')
239                                 {
240                                         if (p[1] == ALLOWED_CHAR)
241                                                 strcpy(p,p+2);
242                                         else
243                                                 goto get_line;
244                                 }
245
246                         } else  {
247                                 //fseek( file, 0, SEEK_SET);
248                                 buffer[buffer_line][0] = 0;
249                                 done++;
250                         }
251                 } while (extra_inc--);
252                 extra_inc = 0;
253
254                 for (i=0; i<ROW_SPACING; i += (MenuHires?2:1) ) {
255                         int y;
256
257                         y = first_line_offset - i;
258
259                         gr_set_current_canvas(CreditsOffscreenBuf);
260                 
261                         gr_bitmap(0,0,&backdrop);
262
263                         for (j=0; j<NUM_LINES; j++ )    {
264                                 char *s;
265
266                                 l = (buffer_line + j + 1 ) %  NUM_LINES;
267                                 s = buffer[l];
268
269                                 if ( s[0] == '!' ) {
270                                         s++;
271                                 } else if ( s[0] == '$' )       {
272                                         grd_curcanv->cv_font = header_font;
273                                         s++;
274                                 } else if ( s[0] == '*' )       {
275                                         grd_curcanv->cv_font = title_font;
276                                         s++;
277                                 } else
278                                         grd_curcanv->cv_font = names_font;
279
280                                 gr_bitblt_fade_table = (MenuHires?fade_values_hires:fade_values);
281
282                                 tempp = strchr( s, '\t' );
283                                 if ( tempp )    {
284                                 //      Wacky Credits thing
285                                         int w, h, aw, w2, x1, x2;
286
287                                         *tempp = 0;
288                                         gr_get_string_size( s, &w, &h, &aw );
289                                         x1 = ((MenuHires?320:160)-w)/2;
290                                         gr_printf( x1 , y, s );
291                                         gr_get_string_size( &tempp[1], &w2, &h, &aw );
292                                         x2 = (MenuHires?320:160)+(((MenuHires?320:160)-w2)/2);
293                                         gr_printf( x2, y, &tempp[1] );
294
295                                         dirty_box[j].left = ((MenuHires?320:160)-w)/2;
296                                         dirty_box[j].top = y;
297                                         dirty_box[j].width =(x2+w2)-x1;
298                                         dirty_box[j].height = h;
299
300                                         *tempp = '\t';
301                 
302                                 } else {
303                                 // Wacky Fast Credits thing
304                                         int w, h, aw;
305
306                                         gr_get_string_size( s, &w, &h, &aw);
307                                         dirty_box[j].width = w;
308                                 dirty_box[j].height = h;
309                                 dirty_box[j].top = y;
310                                 dirty_box[j].left = ((MenuHires?640:320) - w) / 2;
311
312                                         gr_printf( 0x8000, y, s );
313                                 }
314                                 gr_bitblt_fade_table = NULL;
315                                 if (buffer[l][0] == '!')
316                                         y += ROW_SPACING/2;
317                                 else
318                                         y += ROW_SPACING;
319                         }
320
321                         {       // Wacky Fast Credits Thing
322                                 box_t *new_box;
323                                 grs_bitmap *tempbmp;
324
325                                 for (j=0; j<NUM_LINES; j++ )
326                                 {
327                                         new_box = &dirty_box[j];
328
329                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
330
331                                         gr_bm_bitblt( new_box->width + 1, new_box->height +4,
332                                                                 new_box->left, new_box->top, new_box->left, new_box->top,
333                                                                 tempbmp, &(grd_curscreen->sc_canvas.cv_bitmap) );
334                                 }
335
336 #ifndef OGL
337                                 for (j=0; j<NUM_LINES; j++ )
338                                 {
339                                         new_box = &dirty_box[j];
340
341                                         tempbmp = &(CreditsOffscreenBuf->cv_bitmap);
342
343                                         gr_bm_bitblt(   new_box->width
344                                                                         ,new_box->height+2
345                                                                         ,new_box->left
346                                                                         ,new_box->top
347                                                                         ,new_box->left
348                                                                         ,new_box->top
349                                                                         ,&backdrop
350                                                                         ,tempbmp );
351                                 }
352                                 
353 #endif
354                         gr_update();
355                                 
356                         }
357
358 //              Wacky Fast Credits thing doesn't need this (it's done above)
359 //@@            gr_bm_ubitblt(grd_curcanv->cv_w, grd_curcanv->cv_h, 0, 0, 0, 0, &(CreditsOffscreenBuf->cv_bitmap), &(grd_curscreen->sc_canvas.cv_bitmap) );
360
361 //                      mprintf( ( 0, "Fr = %d", (timer_get_fixed_seconds() - last_time) ));
362                         while( timer_get_fixed_seconds() < last_time+time_delay );
363                         last_time = timer_get_fixed_seconds();
364                 
365                         //see if redbook song needs to be restarted
366                         songs_check_redbook_repeat();
367
368                         k = key_inkey();
369
370                         #ifndef NDEBUG
371                         if (k == KEY_BACKSP) {
372                                 Int3();
373                                 k=0;
374                         }
375                         #endif
376
377 //                      {
378 //                              fix ot = time_delay;
379 //                              time_delay += (keyd_pressed[KEY_X] - keyd_pressed[KEY_Z])*100;
380 //                              if (ot!=time_delay)     {
381 //                                      mprintf( (0, "[%x] ", time_delay ));
382 //                              }
383 //                      }
384
385                         if (k == KEY_PRINT_SCREEN) {
386                                 save_screen_shot(0);
387                                 k = 0;
388                         }
389
390                         if ((k>0)||(done>NUM_LINES))    {
391                                         gr_close_font(header_font);
392                                         gr_close_font(title_font);
393                                         gr_close_font(names_font);
394                                         gr_palette_fade_out( gr_palette, 32, 0 );
395                                         gr_use_palette_table( DEFAULT_PALETTE );
396                                         d_free(backdrop.bm_data);
397                                         cfclose(file);
398                                         gr_set_current_canvas(save_canv);
399                                         songs_play_song( SONG_TITLE, 1 );
400
401                                         if (CreditsOffscreenBuf != VR_offscreen_buffer)
402                                                 gr_free_canvas(CreditsOffscreenBuf);
403
404                                 return;
405                         }
406                 }
407
408                 if (buffer[(buffer_line + 1 ) %  NUM_LINES][0] == '!') {
409                         first_line_offset -= ROW_SPACING-ROW_SPACING/2;
410                         if (first_line_offset <= -ROW_SPACING) {
411                                 first_line_offset += ROW_SPACING;
412                                 extra_inc++;
413                         }
414                 }
415         }
416
417 }