1 /* $Id: inferno.c,v 1.109 2006-07-29 04:02:49 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * inferno.c: Entry point of program (main procedure)
19 * After main initializes everything, most of the time is spent in the loop
20 * while (Function_mode != FMODE_EXIT)
21 * In this loop, the main menu is brought up first.
31 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
41 #include <sys/types.h>
60 #include "segment.h" //for Side_to_verts
98 // # include "3dfx_des.h"
100 //added on 9/30/98 by Matt Mueller for selectable automap modes
104 #include "../texmap/scanline.h" //for select_tmap -MM
107 #include "editor/editor.h"
108 #include "editor/kdefs.h"
119 void arch_init(void);
120 void arch_init_start(void);
122 //Current version number
124 ubyte Version_major = 1; //FULL VERSION
125 ubyte Version_minor = 2;
127 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
128 char desc_id_exit_num = 0;
130 int Function_mode=FMODE_MENU; //game or editor?
131 int Screen_mode=-1; //game screen or editor screen?
133 //--unused-- grs_bitmap Inferno_bitmap_title;
135 int WVIDEO_running=0; //debugger can set to 1 if running
137 //--unused-- int Cyberman_installed=0; // SWIFT device present
138 ubyte CybermouseActive=0;
141 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
144 void check_joystick_calibration(void);
146 void show_order_form(void);
148 //--------------------------------------------------------------------------
150 extern int piggy_low_memory;
153 int descent_critical_error = 0;
154 unsigned descent_critical_deverror = 0;
155 unsigned descent_critical_errcode = 0;
157 extern int Network_allow_socket_changes;
159 extern void vfx_set_palette_sub(ubyte *);
161 extern int VR_low_res;
163 extern int Config_vr_type;
164 extern int Config_vr_resolution;
165 extern int Config_vr_tracking;
169 //read help from a file & print to screen
170 void print_commandline_help()
176 ifile = cfopen("help.tex","rb");
178 ifile = cfopen("help.txb","rb");
180 Warning("Cannot load help text file.");
188 while ((end = cfgets(line,LINE_LEN,ifile))) {
191 decode_text_line (line);
193 // This is the only use of cfgets that needs the CR
197 continue; //don't show comments
207 // printf( " Diagnostic:\n\n");
208 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
209 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
212 printf( " Editor Options:\n\n");
213 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
214 printf( " -hoarddata %s\n","Make the hoard ham file from some files, then exit");
215 // printf( " -nobm %s\n","FIXME: Undocumented");
218 printf( " D2X Options:\n\n");
219 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
220 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
221 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
222 printf(" -renderstats %s\n", "Enable renderstats info by default");
224 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
225 printf( " -notitles %s\n", "Do not show titlescreens on startup");
226 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
228 printf( " -nohogdir %s\n", "don't try to use shared data directory");
229 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
231 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
232 printf( " -autodemo %s\n", "Start in demo mode");
233 printf( " -bigpig %s\n","FIXME: Undocumented");
234 printf( " -bspgen %s\n","FIXME: Undocumented");
235 // printf( " -cdproxy %s\n","FIXME: Undocumented");
237 printf( " -checktime %s\n","FIXME: Undocumented");
238 printf( " -showmeminfo %s\n","FIXME: Undocumented");
240 // printf( " -codereadonly %s\n","FIXME: Undocumented");
241 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
242 printf( " -debug %s\n","Enable very verbose output");
243 // printf( " -debugmode %s\n","FIXME: Undocumented");
244 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
245 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
246 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
247 // printf( " -forcegfx %s\n","FIXME: Undocumented");
249 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
251 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
253 printf( " -invulnerability %s\n","Make yourself invulnerable");
255 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
256 printf( " -jasen %s\n","FIXME: Undocumented");
257 printf( " -joyslow %s\n","FIXME: Undocumented");
259 printf( " -kali %s\n","use Kali for networking");
261 // printf( " -logfile %s\n","FIXME: Undocumented");
262 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
263 #if defined(EDITOR) || !defined(MACDATA)
264 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
266 // printf( " -memdbg %s\n","FIXME: Undocumented");
267 // printf( " -monodebug %s\n","FIXME: Undocumented");
268 printf( " -nocdrom %s\n","FIXME: Undocumented");
270 printf( " -nocyberman %s\n","FIXME: Undocumented");
273 printf( " -nofade %s\n","Disable fades");
276 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
277 printf( " -norankings %s\n","Disable multiplayer ranking system");
278 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
279 // printf( " -showaddress %s\n","FIXME: Undocumented");
280 printf( " -socket %s\n","FIXME: Undocumented");
282 #if !defined(MACINTOSH) && !defined(WINDOWS)
283 printf( " -nomixer %s\n","Don't crank music volume");
284 // printf( " -superhires %s\n","Allow higher-resolution modes");
286 // printf( " -nomodex %s\n","FIXME: Undocumented");
288 printf( " -nomovies %s\n","Don't play movies");
289 printf( " -noscreens %s\n","Skip briefing screens");
291 printf( " -noredbook %s\n","Disable redbook audio");
292 printf( " -norun %s\n","Bail out after initialization");
293 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
294 // printf( " -rtscts %s\n","Same as -ctsrts");
295 // printf( " -semiwin %s\n","Use non-fullscreen mode");
296 // printf( " -specialdevice %s\n","FIXME: Undocumented");
298 printf( " -stickmag %s\n","FIXME: Undocumented");
300 // printf( " -stopwatch %s\n","FIXME: Undocumented");
301 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
302 // printf( " -sysram %s\n","FIXME: Undocumented");
303 printf( " -text <file> %s\n","Specify alternate .tex file");
304 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
305 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
306 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
307 // printf( " -vidram %s\n","FIXME: Undocumented");
308 printf( " -xcontrol %s\n","FIXME: Undocumented");
309 printf( " -xname %s\n","FIXME: Undocumented");
310 printf( " -xver %s\n","FIXME: Undocumented");
311 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
313 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
314 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
316 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
318 printf(" -niceautomap %s\n", "Free cpu while doing automap");
319 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
320 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
321 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
322 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
323 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
326 printf( "D2X System Options:\n\n");
328 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
329 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
331 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
332 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
335 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
336 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
337 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
338 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
339 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
340 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
341 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
342 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
343 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
344 printf( " -gl_voodoo %s\n","force fullscreen mode only");
346 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
347 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
348 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
349 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
350 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
351 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
352 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
353 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
354 printf( " -gl_test2 %s\n","FIXME: Undocumented");
355 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
356 #ifdef OGL_RUNTIME_LOAD
357 printf( " -gl_library <l> %s\n","use alternate opengl library");
360 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
364 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
365 printf( " -hwsurface %s\n","FIXME: Undocumented");
368 printf(" -udp %s\n", "Specify options for udp/ip:");
369 printf(" @<shift> %s\n", " shift udp port base offset");
370 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
371 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
372 printf(" %s\n", " HOSTS can be any IP or hostname")
374 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
375 printf(" %s\n", " separate multiple HOSTS with a ,");
378 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
379 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
381 printf( "\n Help:\n\n");
382 printf( " -help, -h, -?, ? %s\n", "View this help screen");
386 void do_joystick_init()
389 if (!FindArg( "-nojoystick" )) {
390 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
392 if ( FindArg( "-joyslow" )) {
393 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
394 joy_set_slow_reading(JOY_SLOW_READINGS);
396 if ( FindArg( "-joypolled" )) {
397 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
398 joy_set_slow_reading(JOY_POLLED_READINGS);
400 if ( FindArg( "-joybios" )) {
401 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
402 joy_set_slow_reading(JOY_BIOS_READINGS);
405 // Added from Descent v1.5 by John. Adapted by Samir.
407 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
411 //set this to force game to run in low res
412 int disable_high_res=0;
414 void do_register_player(ubyte *title_pal)
416 Players[Player_num].callsign[0] = '\0';
422 //now, before we bring up the register player menu, we need to
423 //do some stuff to make sure the palette is ok. First, we need to
424 //get our current palette into the 2d's array, so the remapping will
425 //work. Second, we need to remap the fonts. Third, we need to fill
426 //in part of the fade tables so the darkening of the menu edges works
428 memcpy(gr_palette,title_pal,sizeof(gr_palette));
429 remap_fonts_and_menus(1);
430 RegisterPlayer(); //get player's name
435 #define PROGNAME argv[0]
437 extern char Language[];
439 //can we do highres menus?
440 extern int MenuHiresAvailable;
442 int Inferno_verbose = 0;
444 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
445 int start_net_immediately = 0;
446 //int start_with_mission = 0;
447 //char *start_with_mission_name;
448 //end this section addition
450 #define MENU_HIRES_MODE SM(640,480)
452 // DESCENT II by Parallax Software
455 //extern ubyte gr_current_pal[];
459 char Auto_file[128] = "";
462 int main(int argc, char *argv[])
465 ubyte title_pal[768];
468 CON_Init(); // Initialise the console
470 error_init(NULL, NULL);
471 PHYSFSX_init(argc, argv);
473 if ((t = FindArg("-autoexec")))
474 cmd_appendf("exec %s", Args[t+1]);
476 if (cfexist("autoexec.cfg"))
477 cmd_append("exec autoexec.cfg");
480 if (FindArg("-debug"))
481 cvar_setint( &con_threshold, CON_DEBUG );
482 else if (FindArg("-verbose"))
483 cvar_setint( &con_threshold, CON_VERBOSE );
485 if (! cfile_init("descent2.hog"))
486 if (! cfile_init("d2demo.hog"))
487 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
492 "\tCurrent directory\n"
494 "Or use the -hogdir option to specify an alternate location.");
497 //print out the banner title
498 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
500 con_printf(CON_NORMAL, " %s", VERSION_NAME);
502 if (cfexist(MISSION_DIR "d2x.hog"))
503 con_printf(CON_NORMAL, " Vertigo Enhanced");
505 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
506 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
507 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
508 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
511 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
512 print_commandline_help();
513 set_exit_message("");
515 exit(0); /* mingw hangs on this return. dunno why */
520 con_printf(CON_NORMAL, "\n");
521 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
522 con_printf(CON_NORMAL, "\n");
527 for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
528 con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
530 list = PHYSFS_getCdRomDirs();
531 for (i = list; *i != NULL; i++)
532 con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
533 PHYSFS_freeList(list);
535 list = PHYSFS_enumerateFiles("");
536 for (i = list; *i != NULL; i++)
537 con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
538 PHYSFS_freeList(list);
541 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
542 if(FindArg("-sound22k"))
544 digi_sample_rate = SAMPLE_RATE_22K;
547 if(FindArg("-sound11k"))
549 digi_sample_rate = SAMPLE_RATE_11K;
556 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
558 if ((t = FindArg("-rearviewtime")))
560 float f = atof(Args[t + 1]);
561 Rear_view_leave_time = f * f1_0;
563 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
565 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
566 if ((t = FindArg( "-maxfps" ))) {
568 if (t > 0 && t <= MAX_FPS)
571 //end addition - Victor Rachels
573 #ifdef SUPPORTS_NICEFPS
574 if (FindArg("-nicefps"))
576 if (FindArg("-niceautomap"))
580 if (FindArg("-renderstats"))
583 if ( FindArg( "-autodemo" ))
587 if ( FindArg( "-noscreens" ) )
588 Skip_briefing_screens = 1;
591 if ((t=FindArg("-tmap"))){
592 select_tmap(Args[t+1]);
598 // if (init_graphics()) return 1;
601 if (gr_check_mode(SM(800, 600)) != 0)
603 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
604 Function_mode = FMODE_MENU;
609 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
611 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
616 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
617 set_display_mode(Default_display_mode); //..then set default display mode
620 int screen_width = 640;
621 int screen_height = 480;
623 FindResArg("", &screen_width, &screen_height);
625 // added 3/24/99 by Owen Evans for screen res changing
626 Game_screen_mode = SM(screen_width, screen_height);
628 set_display_mode(Game_screen_mode);
632 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
633 int i, argnum = INT_MAX, w, h;
634 // added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines. - edited 03/31/02 to use new FindResArg.
635 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
636 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
637 #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) );
638 // aren't #defines great? :)
639 // end addition/edit -MM
640 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
642 S_MODE(automap,automap_mode,automap_use_game_res);
643 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
647 i = FindArg( "-xcontrol" );
649 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
652 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
653 if (FindArg("-nofade"))
654 grd_fades_disabled=1;
656 //determine whether we're using high-res menus & movies
657 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
658 cvar_setint( &MovieHires, MenuHires = MenuHiresAvailable = 0 );
660 //NOTE LINK TO ABOVE!
661 MenuHires = MenuHiresAvailable = 1;
663 if (FindArg( "-lowresmovies" ))
664 cvar_setint( &MovieHires, 0 );
666 if ((t=gr_init())!=0) //doesn't do much
667 Error(TXT_CANT_INIT_GFX,t);
669 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
670 gr_set_mode(MovieHires.intval?SM(640,480):SM(320,200));
672 // Load the palette stuff. Returns non-zero if error.
673 con_printf(CON_DEBUG, "Initializing palette system...\n" );
674 gr_use_palette_table(DEFAULT_PALETTE );
676 con_printf(CON_DEBUG, "Initializing font system...\n" );
677 gamefont_init(); // must load after palette data loaded.
679 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
680 init_movies(); //init movie libraries
682 if ( FindArg( "-notitles" ) )
683 songs_play_song( SONG_TITLE, 1);
687 con_printf( CON_DEBUG, "\nShowing loading screen..." );
688 show_loading_screen(title_pal); // title_pal is needed (see below)
690 CON_InitGFX(SWIDTH, SHEIGHT / 2);
692 con_printf( CON_DEBUG , "\nDoing bm_init..." );
694 if (!bm_init_use_tbl())
699 if (FindArg("-hoarddata") != 0)
706 //the bitmap loading code changes gr_palette, so restore it
707 memcpy(gr_palette,title_pal,sizeof(gr_palette));
709 if ( FindArg( "-norun" ) )
712 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
715 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
716 texmerge_init( 10 ); // 10 cache bitmaps
718 con_printf( CON_DEBUG, "\nRunning game...\n" );
719 set_screen_mode(SCREEN_MENU);
723 // If built with editor, option to auto-load a level and quit game
724 // to write certain data.
727 if ( (t = FindArg( "-autoload" )) ) {
729 strcpy(Auto_file, Args[t+1]);
735 strcpy(Players[0].callsign, "dummy");
738 do_register_player(title_pal);
740 gr_palette_fade_out( title_pal, 32, 0 );
742 Game_mode = GM_GAME_OVER;
745 newdemo_start_playback("foo.dem");
746 if (Newdemo_state == ND_STATE_PLAYBACK )
747 Function_mode = FMODE_GAME;
750 //do this here because the demo code can do a longjmp when trying to
751 //autostart a demo from the main menu, never having gone into the game
754 while (Function_mode != FMODE_EXIT)
756 switch( Function_mode ) {
758 set_screen_mode(SCREEN_MENU);
760 newdemo_start_playback(NULL); // Randomly pick a file
761 if (Newdemo_state != ND_STATE_PLAYBACK)
762 Error("No demo files were found for autodemo mode!");
766 strcpy((char *)&Level_names[0], Auto_file);
768 Function_mode = FMODE_EXIT;
773 check_joystick_calibration();
774 gr_palette_clear(); //I'm not sure why we need this, but we do
777 if ( Function_mode == FMODE_EDITOR ) {
779 SetPlayerFromCurseg();
780 load_palette(NULL,1,0);
787 keyd_editor_mode = 0;
791 /* keep the mouse from wandering in SDL */
792 if (FindArg("-grabmouse"))
793 SDL_WM_GrabInput(SDL_GRAB_ON);
799 /* give control back to the WM */
800 if (FindArg("-grabmouse"))
801 SDL_WM_GrabInput(SDL_GRAB_OFF);
804 if ( Function_mode == FMODE_MENU )
805 songs_play_song( SONG_TITLE, 1 );
809 keyd_editor_mode = 1;
812 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
814 if ( Function_mode == FMODE_GAME ) {
815 Game_mode = GM_EDITOR;
816 editor_reset_stuff_on_level();
822 Error("Invalid function mode %d",Function_mode);
828 if (!FindArg( "-notitles" ))
832 if ( FindArg( "-showmeminfo" ) )
833 show_mem_info = 1; // Make memory statistics show
836 return(0); //presumably successful exit
840 void check_joystick_calibration() {
841 int x1, y1, x2, y2, c;
844 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
845 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
846 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
847 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
850 joy_get_pos( &x1, &y1 );
852 t1 = timer_get_fixed_seconds();
853 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
856 joy_get_pos( &x2, &y2 );
858 // If joystick hasn't moved...
859 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
860 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
861 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
873 // void network_abort_game();
874 // if(Network_status)
875 // network_abort_game();