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