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