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