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.
14 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
24 #include "pa_enabl.h" //$$POLY_ACC
36 #include "segment.h" //for Side_to_verts
76 // # include "3dfx_des.h"
80 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
84 #include "editor\editor.h"
85 #include "editor\kdefs.h"
97 void arch_init_start(void);
99 //Current version number
101 ubyte Version_major = 1; //FULL VERSION
102 ubyte Version_minor = 2;
104 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
105 char desc_id_exit_num = 0;
107 int Function_mode=FMODE_MENU; //game or editor?
108 int Screen_mode=-1; //game screen or editor screen?
110 //--unused-- grs_bitmap Inferno_bitmap_title;
112 int WVIDEO_running=0; //debugger can set to 1 if running
115 int Inferno_is_800x600_available = 0;
118 //--unused-- int Cyberman_installed=0; // SWIFT device present
119 ubyte CybermouseActive=0;
121 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
123 void check_joystick_calibration(void);
126 //--------------------------------------------------------------------------
128 extern int piggy_low_memory;
131 int descent_critical_error = 0;
132 unsigned descent_critical_deverror = 0;
133 unsigned descent_critical_errcode = 0;
135 extern int Network_allow_socket_changes;
137 extern void vfx_set_palette_sub(ubyte *);
139 extern int VR_low_res;
141 extern int Config_vr_type;
142 extern int Config_vr_resolution;
143 extern int Config_vr_tracking;
144 int grd_fades_disabled=1;
148 //read help from a file & print to screen
149 void print_commandline_help()
155 ifile = cfopen("help.tex","rb");
157 ifile = cfopen("help.txb","rb");
159 Error("Cannot load help text file.");
163 while (cfgets(line,LINE_LEN,ifile)) {
167 for (i = 0; i < strlen(line) - 1; i++) {
168 encode_rotate_left(&(line[i]));
169 line[i] = line[i] ^ BITMAP_TBL_XOR;
170 encode_rotate_left(&(line[i]));
174 // if (line[0] == ';')
175 // continue; //don't show comments
183 // D2X-specific options:
184 printf( " D2X Options:\n\n");
185 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
186 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
187 printf( " -notitles %s\n", "Do not show titlescreens on startup");
188 printf( " -ini <file> %s\n", "option file (alternate to command line)");
189 printf( " -autodemo %s\n","FIXME: Undocumented");
190 printf( " -autoload %s\n","FIXME: Undocumented");
191 printf( " -bigpig %s\n","FIXME: Undocumented");
192 printf( " -bspgen %s\n","FIXME: Undocumented");
193 printf( " -cdproxy %s\n","FIXME: Undocumented");
194 printf( " -checktime %s\n","FIXME: Undocumented");
195 printf( " -codereadonly %s\n","FIXME: Undocumented");
196 printf( " -cyberimpact %s\n","FIXME: Undocumented");
197 printf( " -ddemul %s\n","FIXME: Undocumented");
198 printf( " -debug %s\n","FIXME: Undocumented");
199 printf( " -debugmode %s\n","FIXME: Undocumented");
200 printf( " -disallowgfx %s\n","FIXME: Undocumented");
201 printf( " -disallowreboot %s\n","FIXME: Undocumented");
202 printf( " -dynamicsockets %s\n","FIXME: Undocumented");
203 printf( " -emul %s\n","FIXME: Undocumented");
204 printf( " -forcegfx %s\n","FIXME: Undocumented");
205 printf( " -grabmouse %s\n","FIXME: Undocumented");
206 printf( " -hoarddata %s\n","FIXME: Undocumented");
207 printf( " -hw_3dacc %s\n","FIXME: Undocumented");
208 printf( " -hwsurface %s\n","FIXME: Undocumented");
209 printf( " -invulnerability %s\n","FIXME: Undocumented");
210 printf( " -ipxnetwork %s\n","FIXME: Undocumented");
211 printf( " -jasen %s\n","FIXME: Undocumented");
212 printf( " -joyslow %s\n","FIXME: Undocumented");
213 printf( " -kali %s\n","FIXME: Undocumented");
214 printf( " -logfile %s\n","FIXME: Undocumented");
215 printf( " -lowresmovies %s\n","FIXME: Undocumented");
216 printf( " -macdata %s\n","FIXME: Undocumented");
217 printf( " -memdbg %s\n","FIXME: Undocumented");
218 printf( " -monodebug %s\n","FIXME: Undocumented");
219 printf( " -nobm %s\n","FIXME: Undocumented");
220 printf( " -nocdrom %s\n","FIXME: Undocumented");
221 printf( " -nocyberman %s\n","FIXME: Undocumented");
222 printf( " -nofade %s\n","FIXME: Undocumented");
223 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
224 printf( " -nomixer %s\n","FIXME: Undocumented");
225 printf( " -nomodex %s\n","FIXME: Undocumented");
226 printf( " -nomovies %s\n","FIXME: Undocumented");
227 printf( " -norankings %s\n","FIXME: Undocumented");
228 printf( " -noredbook %s\n","FIXME: Undocumented");
229 printf( " -norun %s\n","FIXME: Undocumented");
230 printf( " -noscreens %s\n","FIXME: Undocumented");
231 printf( " -ordinaljoy %s\n","FIXME: Undocumented");
232 printf( " -packets %s\n","FIXME: Undocumented");
233 printf( " -rtscts %s\n","FIXME: Undocumented");
234 printf( " -semiwin %s\n","FIXME: Undocumented");
235 printf( " -showaddress %s\n","FIXME: Undocumented");
236 printf( " -showmeminfo %s\n","FIXME: Undocumented");
237 printf( " -socket %s\n","FIXME: Undocumented");
238 printf( " -specialdevice %s\n","FIXME: Undocumented");
239 printf( " -stickmag %s\n","FIXME: Undocumented");
240 printf( " -stopwatch %s\n","FIXME: Undocumented");
241 printf( " -superhires %s\n","FIXME: Undocumented");
242 printf( " -sysram %s\n","FIXME: Undocumented");
243 printf( " -text %s\n","FIXME: Undocumented");
244 printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
245 printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
246 printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
247 printf( " -udp %s\n","FIXME: Undocumented");
248 printf( " -vidram %s\n","FIXME: Undocumented");
249 printf( " -xcontrol %s\n","FIXME: Undocumented");
250 printf( " -xname %s\n","FIXME: Undocumented");
251 printf( " -xver %s\n","FIXME: Undocumented");
253 printf( "\n D2X System Options:\n\n");
256 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
258 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
259 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
262 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
263 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
264 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
265 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
266 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
267 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
268 printf( " -gl_voodoo %s\n","force fullscreen mode only");
269 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
270 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
271 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
272 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
273 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
274 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
275 printf( " -gl_test1 %s\n","FIXME: Undocumented");
276 printf( " -gl_test2 %s\n","FIXME: Undocumented");
277 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
278 #ifdef OGL_RUNTIME_LOAD
279 printf( " -gl_library <l> %s\n","use alternate opengl library");
283 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
286 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
287 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
290 printf( " -help, -?, ? %s\n", "View this help screen");
294 void do_joystick_init()
298 if (!FindArg( "-nojoystick" )) {
299 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
301 if ( FindArg( "-joyslow" )) {
302 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
303 joy_set_slow_reading(JOY_SLOW_READINGS);
305 if ( FindArg( "-joypolled" )) {
306 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
307 joy_set_slow_reading(JOY_POLLED_READINGS);
309 if ( FindArg( "-joybios" )) {
310 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
311 joy_set_slow_reading(JOY_BIOS_READINGS);
314 // Added from Descent v1.5 by John. Adapted by Samir.
316 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
320 //set this to force game to run in low res
321 int disable_high_res=0;
323 void do_register_player(ubyte *title_pal)
325 Players[Player_num].callsign[0] = '\0';
331 //now, before we bring up the register player menu, we need to
332 //do some stuff to make sure the palette is ok. First, we need to
333 //get our current palette into the 2d's array, so the remapping will
334 //work. Second, we need to remap the fonts. Third, we need to fill
335 //in part of the fade tables so the darkening of the menu edges works
337 memcpy(gr_palette,title_pal,sizeof(gr_palette));
338 remap_fonts_and_menus(1);
339 RegisterPlayer(); //get player's name
345 void do_network_init()
347 if (!FindArg( "-nonetwork" )) {
348 int socket=0, showaddress=0, t;
351 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
352 if ((t=FindArg("-socket")))
353 socket = atoi( Args[t+1] );
354 //@@if ( FindArg("-showaddress") ) showaddress=1;
355 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
356 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
359 switch( ipx_error ) {
360 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
361 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
362 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
364 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
366 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
367 Network_active = 0; // Assume no network
369 ipx_read_user_file( "descent.usr" );
370 ipx_read_network_file( "descent.net" );
371 //@@if ( FindArg( "-dynamicsockets" ))
372 //@@ Network_allow_socket_changes = 1;
374 //@@ Network_allow_socket_changes = 0;
376 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
377 Network_active = 0; // Assume no network
383 #define PROGNAME "d2demo"
385 #define PROGNAME "d2"
388 extern char Language[];
390 //can we do highres menus?
391 extern int MenuHiresAvailable;
394 int intro_played = 0;
397 int open_movie_file(char *filename,int must_have);
399 #if defined(POLY_ACC)
400 #define MENU_HIRES_MODE SM_640x480x15xPA
402 #define MENU_HIRES_MODE SM(640,480)
405 // DESCENT II by Parallax Software
408 //extern ubyte gr_current_pal[];
412 char Auto_file[128] = "";
415 int main(int argc,char **argv)
418 ubyte title_pal[768];
420 con_init(); // Initialise the console
423 error_init(NULL, NULL);
425 args_init( argc,argv );
427 if ( FindArg( "-debug") )
429 con_threshold.value = (float)2;
432 if ( FindArg( "-verbose" ) )
434 con_threshold.value = (float)1;
441 //tell cfile about our counter
442 cfile_set_critical_error_counter_ptr(&descent_critical_error);
445 cfile_init("d2demo.hog"); //specify name of hogfile
447 #define HOGNAME "descent2.hog"
448 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
450 Error("Could not find required file <%s>",HOGNAME);
457 //print out the banner title
458 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
459 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
460 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
461 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
464 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
465 print_commandline_help();
466 set_exit_message("");
470 con_printf(CON_NORMAL, "\n");
471 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
472 con_printf(CON_NORMAL, "\n");
474 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
476 if ( FindArg( "-autodemo" ))
479 if ( FindArg( "-noscreens" ) )
480 Skip_briefing_screens = 1;
484 // if (init_graphics()) return 1;
487 if (!Inferno_is_800x600_available) {
488 con_printf(CON_NORMAL "The editor will not be available, press any key to start game...\n" );
489 Function_mode = FMODE_MENU;
494 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
496 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
503 #if defined(POLY_ACC)
504 Current_display_mode = -1;
505 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
508 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
509 set_display_mode(0); //..then set default display mode
512 i = FindArg( "-xcontrol" );
514 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
517 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
518 if (FindArg("-nofade"))
519 grd_fades_disabled=1;
521 if ((t=gr_init())!=0) //doesn't do much
522 Error(TXT_CANT_INIT_GFX,t);
528 // Load the palette stuff. Returns non-zero if error.
529 con_printf(CON_DEBUG, "\nInitializing palette system..." );
530 gr_use_palette_table(DEFAULT_PALETTE );
532 con_printf(CON_DEBUG, "\nInitializing font system..." );
533 gamefont_init(); // must load after palette data loaded.
535 //determine whether we're using high-res menus & movies
536 #if !defined(POLY_ACC)
537 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
538 MovieHires = MenuHires = MenuHiresAvailable = 0;
541 //NOTE LINK TO ABOVE!
542 MenuHires = MenuHiresAvailable = 1;
544 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
545 init_movies(); //init movie libraries
547 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
548 #if defined(POLY_ACC)
549 gr_set_mode(SM_640x480x15xPA);
551 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
555 if ( FindArg( "-notitles" ) )
556 songs_play_song( SONG_TITLE, 1);
559 { //NOTE LINK TO ABOVE!
560 int played=MOVIE_NOT_PLAYED; //default is not played
561 int song_playing = 0;
564 #define MOVIE_REQUIRED 0
566 #define MOVIE_REQUIRED 1
569 #ifdef D2_OEM //$$POLY_ACC, jay.
570 { //show bundler screens
572 char filename[FILENAME_LEN];
574 played=MOVIE_NOT_PLAYED; //default is not played
576 played = PlayMovie("pre_i.mve",0);
579 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
581 while ((tfile=fopen(filename,"rb")) != NULL) {
583 show_title_screen( filename, 1, 0 );
591 init_subtitles("intro.tex");
592 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
597 if (played != MOVIE_NOT_PLAYED)
599 else { //didn't get intro movie, try titles
601 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
603 if (played == MOVIE_NOT_PLAYED) {
604 #if defined(POLY_ACC)
605 gr_set_mode(SM_640x480x15xPA);
607 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
609 con_printf( CON_DEBUG, "\nPlaying title song..." );
610 songs_play_song( SONG_TITLE, 1);
612 con_printf( CON_DEBUG, "\nShowing logo screens..." );
613 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
614 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
618 { //show bundler movie or screens
621 char filename[FILENAME_LEN];
624 played=MOVIE_NOT_PLAYED; //default is not played
626 //check if OEM movie exists, so we don't stop the music if it doesn't
627 movie_handle = open_movie_file("oem.mve",0);
628 if (movie_handle != -1) {
630 played = PlayMovie("oem.mve",0);
631 song_playing = 0; //movie will kill sound
635 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
637 while ((tfile=fopen(filename,"rb")) != NULL) {
639 show_title_screen( filename, 1, 0 );
647 songs_play_song( SONG_TITLE, 1);
651 PA_DFX (pa_splash());
653 con_printf( CON_DEBUG, "\nShowing loading screen..." );
655 //grs_bitmap title_bm;
660 strcpy(filename, "descentd.pcx");
663 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
665 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
669 #if defined(POLY_ACC)
670 gr_set_mode(SM_640x480x15xPA);
672 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
675 FontHires = MenuHires;
677 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
678 //vfx_set_palette_sub( title_pal );
680 gr_palette_fade_in( title_pal, 32, 0 );
682 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
685 con_printf( CON_DEBUG , "\nDoing bm_init..." );
693 if (FindArg("-hoarddata") != 0) {
694 #define MAX_BITMAPS_PER_BRUSH 30
695 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
699 ubyte palette[256*3];
702 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
703 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
704 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
705 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
707 ofile = fopen("hoard.ham","wb");
709 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
710 Assert(iff_error == IFF_NO_ERROR);
711 nframes_short = nframes;
712 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
713 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
714 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
715 fwrite(palette,3,256,ofile);
716 for (i=0;i<nframes;i++)
717 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
719 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
720 Assert(iff_error == IFF_NO_ERROR);
721 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
722 nframes_short = nframes;
723 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
724 fwrite(palette,3,256,ofile);
725 for (i=0;i<nframes;i++)
726 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
729 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
730 Assert(iff_error == IFF_NO_ERROR);
731 fwrite(&icon.bm_w,sizeof(short),1,ofile);
732 fwrite(&icon.bm_h,sizeof(short),1,ofile);
733 fwrite(palette,3,256,ofile);
734 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
737 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
741 ifile = fopen(sounds[i],"rb");
742 Assert(ifile != NULL);
743 size = filelength(ifile->_handle);
744 buf = d_malloc(size);
745 fread(buf,1,size,ifile);
746 fwrite(&size,sizeof(size),1,ofile);
747 fwrite(buf,1,size,ofile);
758 //the bitmap loading code changes gr_palette, so restore it
759 memcpy(gr_palette,title_pal,sizeof(gr_palette));
761 if ( FindArg( "-norun" ) )
764 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
767 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
768 texmerge_init( 10 ); // 10 cache bitmaps
770 con_printf( CON_DEBUG, "\nRunning game...\n" );
771 set_screen_mode(SCREEN_MENU);
775 // If built with editor, option to auto-load a level and quit game
776 // to write certain data.
779 if ( t = FindArg( "-autoload" ) ) {
781 strcpy(Auto_file, Args[t+1]);
787 strcpy(Players[0].callsign, "dummy");
790 do_register_player(title_pal);
792 gr_palette_fade_out( title_pal, 32, 0 );
794 Game_mode = GM_GAME_OVER;
797 newdemo_start_playback("descent.dem");
798 if (Newdemo_state == ND_STATE_PLAYBACK )
799 Function_mode = FMODE_GAME;
802 //do this here because the demo code can do a longjmp when trying to
803 //autostart a demo from the main menu, never having gone into the game
806 while (Function_mode != FMODE_EXIT)
808 switch( Function_mode ) {
810 set_screen_mode(SCREEN_MENU);
812 newdemo_start_playback(NULL); // Randomly pick a file
813 if (Newdemo_state != ND_STATE_PLAYBACK)
814 Error("No demo files were found for autodemo mode!");
818 strcpy(&Level_names[0], Auto_file);
820 Function_mode = FMODE_EXIT;
825 check_joystick_calibration();
826 gr_palette_clear(); //I'm not sure why we need this, but we do
829 if ( Function_mode == FMODE_EDITOR ) {
831 SetPlayerFromCurseg();
832 load_palette(NULL,1,0);
839 keyd_editor_mode = 0;
843 /* keep the mouse from wandering in SDL/X11 */
844 if (FindArg("-grabmouse"))
845 SDL_WM_GrabInput(SDL_GRAB_ON);
852 /* give control back to the WM */
853 if (FindArg("-grabmouse"))
854 SDL_WM_GrabInput(SDL_GRAB_OFF);
857 if ( Function_mode == FMODE_MENU )
858 songs_play_song( SONG_TITLE, 1 );
862 keyd_editor_mode = 1;
864 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
865 if ( Function_mode == FMODE_GAME ) {
866 Game_mode = GM_EDITOR;
867 editor_reset_stuff_on_level();
873 Error("Invalid function mode %d",Function_mode);
881 if (!FindArg( "-notitles" ))
886 if ( FindArg( "-showmeminfo" ) )
887 show_mem_info = 1; // Make memory statistics show
890 return(0); //presumably successful exit
894 void check_joystick_calibration() {
895 int x1, y1, x2, y2, c;
898 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
899 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
900 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
901 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
904 joy_get_pos( &x1, &y1 );
906 t1 = timer_get_fixed_seconds();
907 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
910 joy_get_pos( &x2, &y2 );
912 // If joystick hasn't moved...
913 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
914 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
915 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );