2006-03-20 17:12:09 +00:00
/* $Id: inferno.c,v 1.1.1.1 2006/03/17 19:57:28 zicodxx Exp $ */
/*
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 .
*/
/*
*
* inferno . c : Entry point of program ( main procedure )
*
* After main initializes everything , most of the time is spent in the loop
* while ( Function_mode ! = FMODE_EXIT )
* In this loop , the main menu is brought up first .
*
* main ( ) for Inferno
*
*/
# ifdef HAVE_CONFIG_H
# include <conf.h>
# endif
char copyright [ ] = " DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION " ;
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <limits.h>
# ifdef __unix__
# include <unistd.h>
# include <sys/stat.h>
# include <sys/types.h>
# endif
2007-04-09 02:41:45 +00:00
# if !(defined(__APPLE__) && defined(__MACH__))
2006-03-20 17:12:09 +00:00
# include <physfs.h>
2007-04-09 02:41:45 +00:00
# else
# include <physfs/physfs.h>
# endif
2006-03-20 17:12:09 +00:00
# include "pstypes.h"
# include "strutil.h"
# include "console.h"
# include "gr.h"
# include "fix.h"
# include "vecmat.h"
# include "mono.h"
# include "key.h"
# include "timer.h"
# include "3d.h"
# include "bm.h"
# include "inferno.h"
# include "error.h"
# include "game.h"
# include "segment.h" //for Side_to_verts
# include "u_mem.h"
# include "segpoint.h"
# include "screens.h"
# include "texmap.h"
# include "texmerge.h"
# include "menu.h"
# include "wall.h"
# include "polyobj.h"
# include "effects.h"
# include "digi.h"
# include "palette.h"
# include "args.h"
# include "sounds.h"
# include "titles.h"
# include "player.h"
# include "text.h"
# include "gauges.h" // ZICO - new HUD modes
# ifdef NETWORK
# include "network.h"
# include "modem.h"
# endif
# include "gamefont.h"
# include "kconfig.h"
# include "mouse.h"
# include "newmenu.h"
# include "desc_id.h"
# include "config.h"
# include "joydefs.h"
# include "multi.h"
# include "songs.h"
# include "cfile.h"
# include "gameseq.h"
# include "gamepal.h"
# include "mission.h"
# include "movie.h"
2006-10-21 09:23:52 +00:00
# include "playsave.h"
2007-02-10 23:19:21 +00:00
# include "collide.h"
2007-04-04 10:24:03 +00:00
# include "newdemo.h"
2007-07-14 22:36:04 +00:00
# include "joy.h"
2006-03-20 17:12:09 +00:00
# include "../texmap/scanline.h" //for select_tmap -MM
# ifdef EDITOR
# include "editor/editor.h"
# include "editor/kdefs.h"
# include "ui.h"
# endif
2007-04-09 02:41:45 +00:00
# include <SDL/SDL.h>
2006-03-20 17:12:09 +00:00
# include "vers_id.h"
void mem_init ( void ) ;
//Current version number
ubyte Version_major = 1 ; //FULL VERSION
ubyte Version_minor = 2 ;
//static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
char desc_id_exit_num = 0 ;
int Function_mode = FMODE_MENU ; //game or editor?
int Screen_mode = - 1 ; //game screen or editor screen?
//--unused-- grs_bitmap Inferno_bitmap_title;
int WVIDEO_running = 0 ; //debugger can set to 1 if running
//--unused-- int Cyberman_installed=0; // SWIFT device present
ubyte CybermouseActive = 0 ;
# ifdef __WATCOMC__
int __far descent_critical_error_handler ( unsigned deverr , unsigned errcode , unsigned __far * devhdr ) ;
# endif
void show_order_form ( void ) ;
//--------------------------------------------------------------------------
int descent_critical_error = 0 ;
unsigned descent_critical_deverror = 0 ;
unsigned descent_critical_errcode = 0 ;
extern int Network_allow_socket_changes ;
extern void vfx_set_palette_sub ( ubyte * ) ;
extern int VR_low_res ;
extern int Config_vr_type ;
extern int Config_vr_resolution ;
extern int Config_vr_tracking ;
2007-03-22 11:32:22 +00:00
extern int vertigo_present ;
2006-10-31 21:15:47 +00:00
# ifndef NDEBUG
extern int checktime ;
# endif
2007-07-14 22:36:04 +00:00
extern void d_mouse_init ( void ) ;
2006-03-20 17:12:09 +00:00
# define LINE_LEN 100
//read help from a file & print to screen
void print_commandline_help ( )
{
2006-10-18 12:53:34 +00:00
printf ( " \n System Options: \n \n " ) ;
2007-07-14 20:33:42 +00:00
printf ( " -fps %s \n " , " Enable FPS indicator by default " ) ;
2007-03-31 21:00:47 +00:00
printf ( " -nonicefps %s \n " , " Disable CPU cycle freeing. Higher CPU load, but game may be smoother " ) ;
2007-01-20 12:42:49 +00:00
printf ( " -maxfps <n> %s \n " , " Set maximum framerate (1-80) " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -hogdir <s> %s \n " , " set shared data directory to <dir> " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -nohogdir %s \n " , " don't try to use shared data directory " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -userdir <s> %s \n " , " set user dir to <dir> instead of $HOME/.d2x-rebirth " ) ;
2007-05-21 11:24:27 +00:00
printf ( " -use_players_dir %s \n " , " put player files and saved games in Players subdirectory " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -lowmem %s \n " , " Lowers animation detail for better performance with low memory " ) ;
2007-03-31 21:00:47 +00:00
printf ( " -legacyhomers %s \n " , " Activate original homing missiles (FPS and physics dependent) " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -pilot <s> %s \n " , " Select this pilot automatically " ) ;
2007-07-14 20:33:42 +00:00
printf ( " -autodemo %s \n " , " Start in demo mode " ) ;
2006-10-18 12:53:34 +00:00
printf ( " \n Controls: \n \n " ) ;
2007-07-14 22:36:04 +00:00
printf ( " -nomouse %s \n " , " Deactivate mouse " ) ;
printf ( " -nojoystick %s \n " , " Deactivate joystick " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -mouselook %s \n " , " Activate mouselook. Works in singleplayer only " ) ;
printf ( " -grabmouse %s \n " , " Keeps the mouse from wandering out of the window " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -window %s \n " , " Run the game in a window " ) ;
2006-10-18 12:53:34 +00:00
printf ( " \n Sound: \n \n " ) ;
2007-07-14 22:36:04 +00:00
printf ( " -nosound %s \n " , " Disables sound output " ) ;
printf ( " -nomusic %s \n " , " Disables music output " ) ;
printf ( " -sound11k %s \n " , " Use 11KHz sounds " ) ;
2006-10-18 12:53:34 +00:00
# if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
2007-07-14 22:36:04 +00:00
printf ( " -redbook %s \n " , " Enable redbook audio support " ) ;
2006-10-18 12:53:34 +00:00
# endif // !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
printf ( " \n Graphics: \n \n " ) ;
printf ( " -menu<X>x<Y> %s \n " , " Set menu-resolution to <X> by <Y> instead of game-resolution " ) ;
printf ( " -aspect<Y>x<X> %s \n " , " use specified aspect " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -hud <n> %s \n " , " Set hud mode. 0=normal 1-3=new " ) ;
2007-02-10 23:19:21 +00:00
printf ( " -persistentdebris %s \n " , " Enable persistent debris " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -lowresmovies %s \n " , " Play low resolution movies if available (for slow machines) " ) ;
printf ( " -subtitles %s \n " , " Turn on movie subtitles (English-only) " ) ;
# ifdef OGL
printf ( " \n OpenGL: \n \n " ) ;
printf ( " -gl_mipmap %s \n " , " Set gl texture filters to \" standard \" options for mipmapping " ) ;
printf ( " -gl_trilinear %s \n " , " Set gl texture filters to trilinear mipmapping " ) ;
2007-01-29 23:31:20 +00:00
printf ( " -gl_transparency %s \n " , " Enable transparency effects " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -gl_reticle <n> %s \n " , " Use OGL reticle 0=never 1=above 320x* 2=always " ) ;
printf ( " -gl_scissor_ok <n> %s \n " , " Set glScissor. 0=off 1=on (default) " ) ;
2007-02-09 15:34:10 +00:00
printf ( " -gl_voodoo %s \n " , " Force fullscreen mode only " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -fixedfont %s \n " , " Do not scale fonts to current resolution " ) ;
# endif // OGL
# ifdef NETWORK
printf ( " \n Multiplayer: \n \n " ) ;
printf ( " -norankings %s \n " , " Disable multiplayer ranking system " ) ;
printf ( " -noredundancy %s \n " , " Do not send messages when picking up redundant items in multi " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -packets <n> %s \n " , " Specifies the number of packets per second \n " ) ;
printf ( " -ipxnetwork <n> %s \n " , " Use IPX network number <num> " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -kali %s \n " , " Use Kali for networking " ) ;
2007-05-30 14:16:49 +00:00
printf ( " -ip_nogetmyaddr %s \n " , " Prevent autodetection of local ip address " ) ;
2007-07-15 21:22:07 +00:00
printf ( " -ip_myaddr <n> %s \n " , " Use <a> as local ip address " ) ;
printf ( " -ip_bind_addr <n> %s \n " , " Bind to <a> instead of INADDR_ANY " ) ;
printf ( " -ip_baseport <n> %s \n " , " Use <p> as offset from normal port (allows multiple instances of d1x to be run on a single computer) " ) ;
2006-10-18 12:53:34 +00:00
# endif // NETWORK
# ifndef NDEBUG
printf ( " \n Debug: \n \n " ) ;
printf ( " -debug %s \n " , " Enable very verbose output " ) ;
printf ( " -Verbose %s \n " , " Shows initialization steps for tech support " ) ;
printf ( " -renderstats %s \n " , " Enable renderstats info by default " ) ;
printf ( " -norun %s \n " , " Bail out after initialization " ) ;
printf ( " -nofade %s \n " , " Disable fades " ) ;
printf ( " -norun %s \n " , " Bail out after initialization " ) ;
printf ( " -text <file> %s \n " , " Specify alternate .tex file " ) ;
# ifndef RELEASE
printf ( " -nomovies %s \n " , " Don't play movies " ) ;
# endif // RELEASE
# ifdef SDL_VIDEO
2006-03-20 17:12:09 +00:00
printf ( " -nosdlvidmodecheck %s \n " , " Some X servers don't like checking vidmode first, so just switch " ) ;
2006-10-18 12:53:34 +00:00
# endif // SDL_VIDEO
# ifdef EDITOR
printf ( " \n Editor: \n \n " ) ;
printf ( " -autoload <file> %s \n " , " Autoload a level in the editor " ) ;
2007-07-14 22:36:04 +00:00
printf ( " -macdata %s \n " , " Read and write mac data files in editor (swap colors) " ) ;
printf ( " -hoarddata %s \n " , " Make the hoard ham file from some files, then exit " ) ;
2006-10-18 12:53:34 +00:00
# endif // EDITOR
/* KEPT FOR FURTHER REFERENCE
printf ( " \n Unused / Obsolete: \n \n " ) ;
printf ( " -nobm %s \n " , " FIXME: Undocumented " ) ;
printf ( " -bigpig %s \n " , " FIXME: Undocumented " ) ;
printf ( " -bspgen %s \n " , " FIXME: Undocumented " ) ;
printf ( " -cdproxy %s \n " , " FIXME: Undocumented " ) ;
printf ( " -checktime %s \n " , " FIXME: Undocumented " ) ;
printf ( " -showmeminfo %s \n " , " FIXME: Undocumented " ) ;
printf ( " -codereadonly %s \n " , " FIXME: Undocumented " ) ;
printf ( " -cyberimpact %s \n " , " FIXME: Undocumented " ) ;
printf ( " -debugmode %s \n " , " FIXME: Undocumented " ) ;
printf ( " -disallowgfx %s \n " , " FIXME: Undocumented " ) ;
printf ( " -disallowreboot %s \n " , " FIXME: Undocumented " ) ;
printf ( " -dynamicsockets %s \n " , " FIXME: Undocumented " ) ;
printf ( " -forcegfx %s \n " , " FIXME: Undocumented " ) ;
printf ( " -hw_3dacc %s \n " , " FIXME: Undocumented " ) ;
printf ( " -jasen %s \n " , " FIXME: Undocumented " ) ;
printf ( " -joyslow %s \n " , " FIXME: Undocumented " ) ;
printf ( " -logfile %s \n " , " FIXME: Undocumented " ) ;
printf ( " -memdbg %s \n " , " FIXME: Undocumented " ) ;
printf ( " -monodebug %s \n " , " FIXME: Undocumented " ) ;
printf ( " -nocyberman %s \n " , " FIXME: Undocumented " ) ;
printf ( " -nomatrixcheat %s \n " , " FIXME: Undocumented " ) ;
printf ( " -showaddress %s \n " , " FIXME: Undocumented " ) ;
printf ( " -socket %s \n " , " FIXME: Undocumented " ) ;
printf ( " -nomodex %s \n " , " FIXME: Undocumented " ) ;
printf ( " -ordinaljoy %s \n " , " FIXME: Undocumented " ) ;
printf ( " -specialdevice %s \n " , " FIXME: Undocumented " ) ;
printf ( " -stickmag %s \n " , " FIXME: Undocumented " ) ;
printf ( " -stopwatch %s \n " , " FIXME: Undocumented " ) ;
printf ( " -sysram %s \n " , " FIXME: Undocumented " ) ;
printf ( " -tsengdebug1 %s \n " , " FIXME: Undocumented " ) ;
printf ( " -tsengdebug2 %s \n " , " FIXME: Undocumented " ) ;
printf ( " -tsengdebug3 %s \n " , " FIXME: Undocumented " ) ;
printf ( " -vidram %s \n " , " FIXME: Undocumented " ) ;
printf ( " -xname %s \n " , " FIXME: Undocumented " ) ;
printf ( " -xver %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_intensity4_ok %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_luminance4_alpha4_ok %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_readpixels_ok %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_rgba2_ok %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_test1 %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_test2 %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_vidmem %s \n " , " FIXME: Undocumented " ) ;
printf ( " -hwsurface %s \n " , " FIXME: Undocumented " ) ;
printf ( " -gl_library <l> %s \n " , " use alternate opengl library " ) ;
printf ( " -emul %s \n " , " Certain video cards need this option in order to run game " ) ;
printf ( " -ddemul %s \n " , " If -emul doesn't work, use this option " ) ;
printf ( " -rtscts %s \n " , " Same as -ctsrts " ) ;
printf ( " -semiwin %s \n " , " Use non-fullscreen mode " ) ;
printf ( " -ihaveabrokenmouse %s \n " , " try to make mouse work if it is not currently " ) ;
printf ( " -joy209 %s \n " , " Use alternate port 209 for joystick " ) ;
printf ( " -serialdevice <s> %s \n " , " Set serial/modem device to <s> " ) ;
printf ( " -serialread <r> %s \n " , " Set serial/modem to read from <r> " ) ;
*/
# endif // NDEBUG
2006-03-20 17:12:09 +00:00
printf ( " \n Help: \n \n " ) ;
2006-10-18 12:53:34 +00:00
printf ( " -help, -h, -?, ? %s \n " , " View this help screen " ) ;
printf ( " \n \n " ) ;
2006-03-20 17:12:09 +00:00
}
2007-07-14 22:36:04 +00:00
void sdl_close ( )
{
SDL_Quit ( ) ;
}
2006-03-20 17:12:09 +00:00
//set this to force game to run in low res
int disable_high_res = 0 ;
void do_register_player ( ubyte * title_pal )
{
Players [ Player_num ] . callsign [ 0 ] = ' \0 ' ;
2007-04-04 10:24:03 +00:00
key_flush ( ) ;
2006-03-20 17:12:09 +00:00
2007-04-04 10:24:03 +00:00
//now, before we bring up the register player menu, we need to
//do some stuff to make sure the palette is ok. First, we need to
//get our current palette into the 2d's array, so the remapping will
//work. Second, we need to remap the fonts. Third, we need to fill
//in part of the fade tables so the darkening of the menu edges works
2006-03-20 17:12:09 +00:00
2007-04-04 10:24:03 +00:00
memcpy ( gr_palette , title_pal , sizeof ( gr_palette ) ) ;
remap_fonts_and_menus ( 1 ) ;
RegisterPlayer ( ) ; //get player's name
read_player_file ( ) ; // read out now so we are able to use game resolution in menu
2006-03-20 17:12:09 +00:00
}
# define PROGNAME argv[0]
extern char Language [ ] ;
//can we do highres menus?
extern int MenuHiresAvailable ;
int Inferno_verbose = 0 ;
//added on 11/18/98 by Victor Rachels to add -mission and -startgame
int start_net_immediately = 0 ;
//int start_with_mission = 0;
//char *start_with_mission_name;
//end this section addition
2006-08-30 18:12:04 +00:00
u_int32_t MENU_HIRES_MODE = SM ( 640 , 480 ) ; //#define MENU_HIRES_MODE SM(640,480)
int menu_use_game_res = 1 ;
2006-03-20 17:12:09 +00:00
// DESCENT II by Parallax Software
// Descent Main
//extern ubyte gr_current_pal[];
# ifdef EDITOR
int Auto_exit = 0 ;
char Auto_file [ 128 ] = " " ;
# endif
int main ( int argc , char * argv [ ] )
{
2007-07-14 20:33:42 +00:00
int t ;
2006-03-20 17:12:09 +00:00
ubyte title_pal [ 768 ] ;
con_init ( ) ; // Initialise the console
mem_init ( ) ;
error_init ( NULL , NULL ) ;
2006-10-02 13:55:58 +00:00
PHYSFSX_init ( argc , argv ) ;
2006-03-20 17:12:09 +00:00
if ( FindArg ( " -debug " ) )
con_threshold . value = ( float ) 2 ;
else if ( FindArg ( " -verbose " ) )
con_threshold . value = ( float ) 1 ;
2007-05-27 02:24:00 +00:00
if ( ! cfile_init ( " descent2.hog " , 1 ) )
if ( ! cfile_init ( " d2demo.hog " , 1 ) )
2006-12-31 00:09:49 +00:00
Error ( " Could not find a valid hog file (descent2.hog or d2demo.hog) \n Possible locations are: \n "
2006-03-20 17:12:09 +00:00
# ifdef __unix__
2006-10-02 12:53:08 +00:00
" \t $HOME/.d2x-rebirth \n "
2006-03-20 17:12:09 +00:00
" \t " SHAREPATH " \n "
# else
" \t Current directory \n "
# endif
" Or use the -hogdir option to specify an alternate location. " ) ;
load_text ( ) ;
//print out the banner title
con_printf ( CON_NORMAL , " \n DESCENT 2 %s v%d.%d " , VERSION_TYPE , Version_major , Version_minor ) ;
2006-12-26 03:42:13 +00:00
# if 1 //def VERSION_NAME
con_printf ( CON_NORMAL , " %s " , DESCENT_VERSION ) ; // D2X version
2006-03-20 17:12:09 +00:00
# endif
2007-03-22 11:32:22 +00:00
if ( cfexist ( MISSION_DIR " d2x.hog " ) ) {
2006-03-20 17:12:09 +00:00
con_printf ( CON_NORMAL , " Vertigo Enhanced " ) ;
2007-03-22 11:32:22 +00:00
vertigo_present = 1 ;
}
2006-03-20 17:12:09 +00:00
con_printf ( CON_NORMAL , " %s %s \n " , __DATE__ , __TIME__ ) ;
con_printf ( CON_NORMAL , " %s \n %s \n " , TXT_COPYRIGHT , TXT_TRADEMARK ) ;
con_printf ( CON_NORMAL , " This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins \n " ) ;
con_printf ( CON_NORMAL , " Copyright (c) 2002 Bradley Bell \n " ) ;
2006-12-26 03:42:13 +00:00
con_printf ( CON_NORMAL , " Copyright (c) 2005 Christian Beckhaeuser \n " ) ;
2006-03-20 17:12:09 +00:00
2006-10-18 12:53:34 +00:00
if ( FindArg ( " -help " ) | | FindArg ( " -h " ) | | FindArg ( " -? " ) | | FindArg ( " ? " ) ) {
2006-03-20 17:12:09 +00:00
print_commandline_help ( ) ;
set_exit_message ( " " ) ;
# ifdef __MINGW32__
exit ( 0 ) ; /* mingw hangs on this return. dunno why */
# endif
return ( 0 ) ;
}
con_printf ( CON_NORMAL , " \n " ) ;
con_printf ( CON_NORMAL , TXT_HELP , PROGNAME ) ; //help message has %s for program name
con_printf ( CON_NORMAL , " \n " ) ;
{
char * * i , * * list ;
2006-12-31 00:00:44 +00:00
list = PHYSFS_getSearchPath ( ) ;
for ( i = list ; * i ! = NULL ; i + + )
2006-03-20 17:12:09 +00:00
con_printf ( CON_VERBOSE , " PHYSFS: [%s] is in the search path. \n " , * i ) ;
2006-12-31 00:00:44 +00:00
PHYSFS_freeList ( list ) ;
2006-03-20 17:12:09 +00:00
list = PHYSFS_getCdRomDirs ( ) ;
for ( i = list ; * i ! = NULL ; i + + )
con_printf ( CON_VERBOSE , " PHYSFS: cdrom dir [%s] is available. \n " , * i ) ;
PHYSFS_freeList ( list ) ;
list = PHYSFS_enumerateFiles ( " " ) ;
for ( i = list ; * i ! = NULL ; i + + )
con_printf ( CON_DEBUG , " PHYSFS: * We've got [%s]. \n " , * i ) ;
PHYSFS_freeList ( list ) ;
}
2007-07-14 22:36:04 +00:00
if ( SDL_Init ( SDL_INIT_VIDEO ) < 0 )
Error ( " SDL library initialisation failed: %s. " , SDL_GetError ( ) ) ;
2006-03-20 17:12:09 +00:00
2007-07-14 22:36:04 +00:00
key_init ( ) ;
if ( ! GameArg . SndNoSound )
digi_init ( ) ;
if ( ! GameArg . CtlNoMouse )
d_mouse_init ( ) ;
if ( ! GameArg . CtlNoJoystick )
joy_init ( ) ;
atexit ( sdl_close ) ;
2006-03-20 17:12:09 +00:00
//con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
if ( FindArg ( " -renderstats " ) )
gr_renderstats = 1 ;
2006-10-31 21:15:47 +00:00
# ifndef NDEBUG
if ( FindArg ( " -checktime " ) )
checktime = 1 ;
# endif
2006-03-20 17:12:09 +00:00
if ( ( t = FindArg ( " -tmap " ) ) ) {
select_tmap ( Args [ t + 1 ] ) ;
} else
select_tmap ( NULL ) ;
Lighting_on = 1 ;
# ifdef EDITOR
if ( gr_check_mode ( SM ( 800 , 600 ) ) ! = 0 )
{
con_printf ( CON_NORMAL , " The editor will not be available, press any key to start game... \n " ) ;
Function_mode = FMODE_MENU ;
}
# endif
if ( ! WVIDEO_running )
con_printf ( CON_DEBUG , " WVIDEO_running = %d \n " , WVIDEO_running ) ;
con_printf ( CON_VERBOSE , " %s " , TXT_VERBOSE_1 ) ;
ReadConfigFile ( ) ;
if ( ! VR_offscreen_buffer ) //if hasn't been initialied (by headset init)
set_display_mode ( 0 ) ; //..then set default display mode
{
int screen_width = 640 ;
int screen_height = 480 ;
2007-03-24 04:37:33 +00:00
// int screen_flags = 0;
2006-03-20 17:12:09 +00:00
// added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
2007-03-22 14:25:27 +00:00
# if !defined (NDEBUG) && !defined (OGL)
2006-03-20 17:12:09 +00:00
if ( FindArg ( " -nodoublebuffer " ) )
// end addition -MM
2007-03-21 12:35:35 +00:00
// later modified by kreatordxx to allow double buffering to be disabled for any supported platform
2006-03-20 17:12:09 +00:00
{
con_printf ( CON_VERBOSE , " Double-buffering disabled... \n " ) ;
2007-03-21 12:35:35 +00:00
Game_double_buffer = 0 ;
2006-03-20 17:12:09 +00:00
}
2007-03-21 12:35:35 +00:00
# endif
2006-03-20 17:12:09 +00:00
// added 3/24/99 by Owen Evans for screen res changing
Game_screen_mode = SM ( screen_width , screen_height ) ;
// end added -OE
2007-04-05 13:23:44 +00:00
// game_init_render_buffers(screen_width, screen_height, VR_NONE, screen_flags);
2006-03-20 17:12:09 +00:00
}
2006-08-30 18:12:04 +00:00
2006-03-20 17:12:09 +00:00
{
int i , argnum = INT_MAX , w , h ;
2007-01-25 13:01:39 +00:00
# define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; if(w<640||h<480) disable_high_res=1; }
2006-03-20 17:12:09 +00:00
# define SMODE_PRINT(V,VV,VG) if (VG) con_printf(CON_VERBOSE, #V " using game resolution ...\n"); else con_printf(CON_VERBOSE, #V " using %ix%i ...\n",SM_W(VV),SM_H(VV) );
2007-07-15 15:23:45 +00:00
# define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_PRINT(V, VV, VG);
2006-03-20 17:12:09 +00:00
2006-08-30 18:12:04 +00:00
S_MODE ( menu , MENU_HIRES_MODE , menu_use_game_res ) ;
2006-03-20 17:12:09 +00:00
}
con_printf ( CON_VERBOSE , " \n %s \n \n " , TXT_INITIALIZING_GRAPHICS ) ;
if ( FindArg ( " -nofade " ) )
grd_fades_disabled = 1 ;
//determine whether we're using high-res menus & movies
if ( FindArg ( " -nohires " ) | | FindArg ( " -nohighres " ) | | ( gr_check_mode ( MENU_HIRES_MODE ) ! = 0 ) | | disable_high_res )
2007-07-15 15:23:45 +00:00
GameArg . GfxMovieHires = MenuHires = MenuHiresAvailable = 0 ;
2006-03-20 17:12:09 +00:00
else
//NOTE LINK TO ABOVE!
2007-07-15 15:23:45 +00:00
GameArg . GfxMovieHires = MenuHires = MenuHiresAvailable = 1 ;
2006-03-20 17:12:09 +00:00
2007-02-09 12:38:21 +00:00
if ( ( t = gr_init ( 0 ) ) ! = 0 ) //doesn't do much
2006-03-20 17:12:09 +00:00
Error ( TXT_CANT_INIT_GFX , t ) ;
2007-02-09 12:38:21 +00:00
gr_set_mode ( MENU_SCREEN_MODE ) ;
2006-03-20 17:12:09 +00:00
// Load the palette stuff. Returns non-zero if error.
con_printf ( CON_DEBUG , " Initializing palette system... \n " ) ;
2007-06-11 15:54:09 +00:00
gr_use_palette_table ( D2_DEFAULT_PALETTE ) ;
2006-03-20 17:12:09 +00:00
con_printf ( CON_DEBUG , " Initializing font system... \n " ) ;
gamefont_init ( ) ; // must load after palette data loaded.
con_printf ( CON_DEBUG , " Initializing movie libraries... \n " ) ;
init_movies ( ) ; //init movie libraries
#if 0
con_printf ( CON_VERBOSE , " Going into graphics mode... \n " ) ;
gr_set_mode ( MovieHires ? SM ( 640 , 480 ) : SM ( 320 , 200 ) ) ;
# endif
2007-03-03 18:27:55 +00:00
show_titles ( ) ;
2006-03-20 17:12:09 +00:00
con_printf ( CON_DEBUG , " \n Showing loading screen... " ) ;
2006-10-02 13:51:05 +00:00
show_loading_screen ( title_pal ) ; // title_pal is needed (see below)
2006-03-20 17:12:09 +00:00
con_printf ( CON_DEBUG , " \n Doing bm_init... " ) ;
# ifdef EDITOR
if ( ! bm_init_use_tbl ( ) )
# endif
bm_init ( ) ;
# ifdef EDITOR
if ( FindArg ( " -hoarddata " ) ! = 0 ) {
2006-10-02 13:29:04 +00:00
save_hoard_data ( ) ;
2006-03-20 17:12:09 +00:00
exit ( 1 ) ;
}
# endif
//the bitmap loading code changes gr_palette, so restore it
memcpy ( gr_palette , title_pal , sizeof ( gr_palette ) ) ;
if ( FindArg ( " -norun " ) )
return ( 0 ) ;
con_printf ( CON_DEBUG , " \n Initializing 3d system... " ) ;
g3_init ( ) ;
con_printf ( CON_DEBUG , " \n Initializing texture caching system... " ) ;
texmerge_init ( 10 ) ; // 10 cache bitmaps
con_printf ( CON_DEBUG , " \n Running game... \n " ) ;
set_screen_mode ( SCREEN_MENU ) ;
init_game ( ) ;
// If built with editor, option to auto-load a level and quit game
// to write certain data.
# ifdef EDITOR
{ int t ;
if ( ( t = FindArg ( " -autoload " ) ) ) {
Auto_exit = 1 ;
strcpy ( Auto_file , Args [ t + 1 ] ) ;
}
}
if ( Auto_exit ) {
strcpy ( Players [ 0 ] . callsign , " dummy " ) ;
} else
# endif
2006-10-10 09:53:58 +00:00
{
// do_register_player(title_pal);
2007-07-14 20:33:42 +00:00
if ( GameArg . SysPilot )
2006-10-10 09:53:58 +00:00
{
2007-05-21 11:24:27 +00:00
char filename [ 32 ] = " " ;
2006-10-18 12:53:34 +00:00
int j ;
2007-05-21 11:24:27 +00:00
2007-07-14 20:33:42 +00:00
if ( GameArg . SysUsePlayersDir )
2007-05-21 11:24:27 +00:00
strcpy ( filename , " Players/ " ) ;
2007-07-14 20:33:42 +00:00
strncat ( filename , GameArg . SysPilot , 12 ) ;
2007-05-21 11:24:27 +00:00
filename [ 8 + 12 ] = ' \0 ' ; // unfortunately strncat doesn't put the terminating 0 on the end if it reaches 'n'
2007-07-14 20:33:42 +00:00
for ( j = GameArg . SysUsePlayersDir ? 8 : 0 ; filename [ j ] ! = ' \0 ' ; j + + ) {
2006-10-18 12:53:34 +00:00
switch ( filename [ j ] ) {
case ' ' :
filename [ j ] = ' \0 ' ;
}
}
strlwr ( filename ) ;
2007-05-10 09:34:27 +00:00
if ( ! strstr ( filename , " .plr " ) ) // if player hasn't specified .plr extension in argument, add it
strcat ( filename , " .plr " ) ;
2006-10-10 09:53:58 +00:00
if ( cfexist ( filename ) )
{
2006-10-18 12:53:34 +00:00
strcpy ( strstr ( filename , " .plr " ) , " \0 " ) ;
2007-07-14 20:33:42 +00:00
strcpy ( Players [ Player_num ] . callsign , GameArg . SysUsePlayersDir ? & filename [ 8 ] : filename ) ;
2006-10-10 09:53:58 +00:00
read_player_file ( ) ;
WriteConfigFile ( ) ;
remap_fonts_and_menus ( 1 ) ;
}
2006-10-18 12:53:34 +00:00
else //pilot doesn't exist. get pilot.
2006-10-10 09:53:58 +00:00
do_register_player ( title_pal ) ;
}
else
do_register_player ( title_pal ) ;
}
2006-03-20 17:12:09 +00:00
gr_palette_fade_out ( title_pal , 32 , 0 ) ;
Game_mode = GM_GAME_OVER ;
while ( Function_mode ! = FMODE_EXIT )
{
switch ( Function_mode ) {
case FMODE_MENU :
set_screen_mode ( SCREEN_MENU ) ;
2007-04-04 10:24:03 +00:00
# ifdef EDITOR
if ( Auto_exit ) {
strcpy ( ( char * ) & Level_names [ 0 ] , Auto_file ) ;
LoadLevel ( 1 , 1 ) ;
Function_mode = FMODE_EXIT ;
break ;
}
# endif
gr_palette_clear ( ) ; //I'm not sure why we need this, but we do
DoMenu ( ) ;
# ifdef EDITOR
if ( Function_mode = = FMODE_EDITOR ) {
create_new_mine ( ) ;
SetPlayerFromCurseg ( ) ;
load_palette ( NULL , 1 , 0 ) ;
2006-03-20 17:12:09 +00:00
}
2007-04-04 10:24:03 +00:00
# endif
2006-03-20 17:12:09 +00:00
break ;
case FMODE_GAME :
# ifdef EDITOR
keyd_editor_mode = 0 ;
# endif
game ( ) ;
if ( Function_mode = = FMODE_MENU )
songs_play_song ( SONG_TITLE , 1 ) ;
break ;
# ifdef EDITOR
case FMODE_EDITOR :
keyd_editor_mode = 1 ;
editor ( ) ;
# ifdef __WATCOMC__
_harderr ( ( void * ) descent_critical_error_handler ) ; // Reinstall game error handler
# endif
if ( Function_mode = = FMODE_GAME ) {
Game_mode = GM_EDITOR ;
editor_reset_stuff_on_level ( ) ;
N_players = 1 ;
}
break ;
# endif
default :
Error ( " Invalid function mode %d " , Function_mode ) ;
}
}
WriteConfigFile ( ) ;
2007-03-03 18:27:55 +00:00
show_order_form ( ) ;
2006-03-20 17:12:09 +00:00
# ifndef NDEBUG
if ( FindArg ( " -showmeminfo " ) )
show_mem_info = 1 ; // Make memory statistics show
# endif
# ifdef _WIN32
digi_stop_current_song ( ) ; // ZICO - stop all midis // hack for some onboard soundcards
digi_close ( ) ; // ZICO - stop all sounds // hack for some onboard soundcards
# endif
return ( 0 ) ; //presumably successful exit
}
void quit_request ( )
{
# ifdef NETWORK
// void network_abort_game();
// if(Network_status)
// network_abort_game();
# endif
exit ( 0 ) ;
}