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