dxx-rebirth/main/credits.c

272 lines
6.1 KiB
C
Raw Normal View History

2006-03-20 17:12:09 +00:00
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Routines to display the credits.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include "error.h"
#include "pstypes.h"
#include "gr.h"
2010-03-22 03:31:02 +00:00
#include "window.h"
2006-03-20 17:12:09 +00:00
#include "key.h"
#include "mouse.h"
2006-03-20 17:12:09 +00:00
#include "palette.h"
#include "game.h"
#include "gamepal.h"
#include "timer.h"
#include "gamefont.h"
#include "pcx.h"
2010-03-22 03:31:02 +00:00
#include "u_mem.h"
2006-03-20 17:12:09 +00:00
#include "screens.h"
#include "digi.h"
#include "rbaudio.h"
2006-03-20 17:12:09 +00:00
#include "text.h"
#include "songs.h"
#include "menu.h"
#include "mission.h"
#include "config.h"
2006-03-20 17:12:09 +00:00
#define ROW_SPACING (SHEIGHT / 17)
#define NUM_LINES 20 //14
#define CREDITS_FILE (PHYSFSX_exists("mcredits.tex",1)?"mcredits.tex":PHYSFSX_exists("ocredits.tex",1)?"ocredits.tex":"credits.tex")
2010-03-22 03:31:02 +00:00
#define ALLOWED_CHAR (is_SHAREWARE ? 'S' : 'R')
typedef struct credits
{
PHYSFS_file * file;
2010-03-22 03:31:02 +00:00
int have_bin_file;
char buffer[NUM_LINES][80];
int buffer_line;
int first_line_offset;
int extra_inc;
int done;
int row;
grs_bitmap backdrop;
} credits;
int credits_handler(window *wind, d_event *event, credits *cr)
{
int j, l, y;
2010-03-22 03:31:02 +00:00
char * tempp;
switch (event->type)
{
case EVENT_KEY_COMMAND:
if (!call_default_handler(event)) // if not print screen, debug etc
window_close(wind);
return 1;
2010-03-22 03:31:02 +00:00
case EVENT_MOUSE_BUTTON_DOWN:
case EVENT_MOUSE_BUTTON_UP:
if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT)
{
window_close(wind);
return 1;
}
break;
2010-03-22 03:31:02 +00:00
case EVENT_IDLE:
if (cr->done>NUM_LINES)
{
window_close(wind);
return 0;
}
break;
case EVENT_WINDOW_DRAW:
timer_delay(F1_0/28);
2010-03-22 03:31:02 +00:00
if (cr->row == 0)
{
do {
cr->buffer_line = (cr->buffer_line+1) % NUM_LINES;
get_line:;
if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], 80, cr->file )) {
2010-03-22 03:31:02 +00:00
char *p;
if (cr->have_bin_file) // is this a binary tbl file
decode_text_line (cr->buffer[cr->buffer_line]);
p = cr->buffer[cr->buffer_line];
if (p[0] == ';')
goto get_line;
if (p[0] == '%')
{
if (p[1] == ALLOWED_CHAR)
strcpy(p,p+2);
else
goto get_line;
}
} else {
//fseek( file, 0, SEEK_SET);
cr->buffer[cr->buffer_line][0] = 0;
cr->done++;
}
} while (cr->extra_inc--);
cr->extra_inc = 0;
}
// cheap but effective: towards end of credits sequence, fade out the music volume
if (cr->done >= NUM_LINES-16)
{
static int curvol = 8;
if (curvol != (NUM_LINES-cr->done)/2)
{
curvol = (NUM_LINES-cr->done)/2;
songs_set_volume(curvol);
}
}
2010-03-22 03:31:02 +00:00
y = cr->first_line_offset - cr->row;
show_fullscr(&cr->backdrop);
for (j=0; j<NUM_LINES; j++ ) {
char *s;
l = (cr->buffer_line + j + 1 ) % NUM_LINES;
s = cr->buffer[l];
if ( s[0] == '!' ) {
s++;
} else if ( s[0] == '$' ) {
gr_set_curfont( HUGE_FONT );
s++;
} else if ( s[0] == '*' ) {
gr_set_curfont( MEDIUM3_FONT );
s++;
} else
gr_set_curfont( MEDIUM2_FONT );
tempp = strchr( s, '\t' );
if ( !tempp ) {
// Wacky Fast Credits thing
int w, h, aw;
gr_get_string_size( s, &w, &h, &aw);
gr_printf( 0x8000, y, s );
}
y += ROW_SPACING;
}
cr->row += SHEIGHT/200;
if (cr->row >= ROW_SPACING)
cr->row = 0;
break;
case EVENT_WINDOW_CLOSE:
gr_free_bitmap_data (&cr->backdrop);
PHYSFS_close(cr->file);
songs_set_volume(GameCfg.MusicVolume);
2010-03-22 03:31:02 +00:00
songs_play_song( SONG_TITLE, 1 );
d_free(cr);
break;
default:
break;
}
return 0;
}
2006-03-20 17:12:09 +00:00
//if filename passed is NULL, show normal credits
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
void credits_show(char *credits_filename)
2006-03-20 17:12:09 +00:00
{
2010-03-22 03:31:02 +00:00
credits *cr;
window *wind;
int i;
2006-03-20 17:12:09 +00:00
int pcx_error;
char * tempp;
char filename[32];
ubyte backdrop_palette[768];
2010-03-22 03:31:02 +00:00
MALLOC(cr, credits, 1);
if (!cr)
return;
cr->have_bin_file = 0;
cr->buffer_line = 0;
cr->first_line_offset = 0;
cr->extra_inc = 0;
cr->done = 0;
cr->row = 0;
2006-03-20 17:12:09 +00:00
// Clear out all tex buffer lines.
for (i=0; i<NUM_LINES; i++ )
2010-03-22 03:31:02 +00:00
cr->buffer[i][0] = 0;
2006-03-20 17:12:09 +00:00
sprintf(filename, "%s", CREDITS_FILE);
2010-03-22 03:31:02 +00:00
cr->have_bin_file = 0;
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
if (credits_filename) {
strcpy(filename,credits_filename);
2010-03-22 03:31:02 +00:00
cr->have_bin_file = 1;
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
}
cr->file = PHYSFSX_openReadBuffered( filename );
2010-03-22 03:31:02 +00:00
if (cr->file == NULL) {
2006-03-20 17:12:09 +00:00
char nfile[32];
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
if (credits_filename)
{
d_free(cr);
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
return; //ok to not find special filename
}
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
2006-03-20 17:12:09 +00:00
tempp = strchr(filename, '.');
*tempp = '\0';
sprintf(nfile, "%s.txb", filename);
cr->file = PHYSFSX_openReadBuffered(nfile);
2010-03-22 03:31:02 +00:00
if (cr->file == NULL)
2006-03-20 17:12:09 +00:00
Error("Missing CREDITS.TEX and CREDITS.TXB file\n");
2010-03-22 03:31:02 +00:00
cr->have_bin_file = 1;
2006-03-20 17:12:09 +00:00
}
set_screen_mode(SCREEN_MENU);
gr_use_palette_table( "credits.256" );
2010-03-22 03:31:02 +00:00
cr->backdrop.bm_data=NULL;
2006-03-20 17:12:09 +00:00
2010-03-22 03:31:02 +00:00
pcx_error = pcx_read_bitmap(STARS_BACKGROUND,&cr->backdrop, BM_LINEAR,backdrop_palette);
2006-03-20 17:12:09 +00:00
if (pcx_error != PCX_ERROR_NONE) {
PHYSFS_close(cr->file);
d_free(cr);
2006-03-20 17:12:09 +00:00
return;
}
songs_play_song( SONG_CREDITS, 1 );
2010-03-22 03:31:02 +00:00
gr_remap_bitmap_good( &cr->backdrop,backdrop_palette, -1, -1 );
2006-03-20 17:12:09 +00:00
gr_set_current_canvas(NULL);
2010-03-22 03:31:02 +00:00
show_fullscr(&cr->backdrop);
gr_palette_load( gr_palette );
2006-03-20 17:12:09 +00:00
key_flush();
2010-03-22 03:31:02 +00:00
wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *))credits_handler, cr);
if (!wind)
{
d_event event = { EVENT_WINDOW_CLOSE };
credits_handler(NULL, &event, cr);
return;
2006-03-20 17:12:09 +00:00
}
2010-03-22 03:31:02 +00:00
while (window_exists(wind))
event_process();
2006-03-20 17:12:09 +00:00
}