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.
15 * $Source: /cvs/cvsroot/d2x/main/inferno.c,v $
18 * $Date: 2001-10-25 02:19:31 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.9 2001/10/19 08:08:50 bradleyb
24 * conditionalize conf.h
26 * Revision 1.8 2001/10/19 00:31:51 bradleyb
27 * Trying to get network working on win32
29 * Revision 1.7 2001/10/18 00:01:01 bradleyb
30 * RCS headers added/changed
39 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
48 #include "pa_enabl.h" //$$POLY_ACC
60 #include "segment.h" //for Side_to_verts
102 // # include "3dfx_des.h"
104 #if defined(POLY_ACC)
105 #include "poly_acc.h"
106 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
110 #include "editor/editor.h"
111 #include "editor/kdefs.h"
123 void arch_init(void);
124 void arch_init_start(void);
126 //Current version number
128 ubyte Version_major = 1; //FULL VERSION
129 ubyte Version_minor = 2;
131 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
132 char desc_id_exit_num = 0;
134 int Function_mode=FMODE_MENU; //game or editor?
135 int Screen_mode=-1; //game screen or editor screen?
137 //--unused-- grs_bitmap Inferno_bitmap_title;
139 int WVIDEO_running=0; //debugger can set to 1 if running
142 int Inferno_is_800x600_available = 0;
145 //--unused-- int Cyberman_installed=0; // SWIFT device present
146 ubyte CybermouseActive=0;
148 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
150 void check_joystick_calibration(void);
153 //--------------------------------------------------------------------------
155 extern int piggy_low_memory;
158 int descent_critical_error = 0;
159 unsigned descent_critical_deverror = 0;
160 unsigned descent_critical_errcode = 0;
162 extern int Network_allow_socket_changes;
164 extern void vfx_set_palette_sub(ubyte *);
166 extern int VR_low_res;
168 extern int Config_vr_type;
169 extern int Config_vr_resolution;
170 extern int Config_vr_tracking;
171 int grd_fades_disabled=1;
175 //read help from a file & print to screen
176 void print_commandline_help()
182 ifile = cfopen("help.tex","rb");
184 ifile = cfopen("help.txb","rb");
186 Error("Cannot load help text file.");
190 while (cfgets(line,LINE_LEN,ifile)) {
194 for (i = 0; i < strlen(line) - 1; i++) {
195 encode_rotate_left(&(line[i]));
196 line[i] = line[i] ^ BITMAP_TBL_XOR;
197 encode_rotate_left(&(line[i]));
202 continue; //don't show comments
210 // D2X-specific options:
211 printf( " D2X Options:\n\n");
212 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
213 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
214 printf( " -notitles %s\n", "Do not show titlescreens on startup");
215 printf( " -ini <file> %s\n", "option file (alternate to command line)");
216 printf( " -autodemo %s\n","FIXME: Undocumented");
217 printf( " -autoload %s\n","FIXME: Undocumented");
218 printf( " -bigpig %s\n","FIXME: Undocumented");
219 printf( " -bspgen %s\n","FIXME: Undocumented");
220 printf( " -cdproxy %s\n","FIXME: Undocumented");
221 printf( " -checktime %s\n","FIXME: Undocumented");
222 printf( " -codereadonly %s\n","FIXME: Undocumented");
223 printf( " -cyberimpact %s\n","FIXME: Undocumented");
224 printf( " -ddemul %s\n","FIXME: Undocumented");
225 printf( " -debug %s\n","FIXME: Undocumented");
226 printf( " -debugmode %s\n","FIXME: Undocumented");
227 printf( " -disallowgfx %s\n","FIXME: Undocumented");
228 printf( " -disallowreboot %s\n","FIXME: Undocumented");
229 printf( " -dynamicsockets %s\n","FIXME: Undocumented");
230 printf( " -emul %s\n","FIXME: Undocumented");
231 printf( " -forcegfx %s\n","FIXME: Undocumented");
232 printf( " -grabmouse %s\n","FIXME: Undocumented");
233 printf( " -hoarddata %s\n","FIXME: Undocumented");
234 printf( " -hw_3dacc %s\n","FIXME: Undocumented");
235 printf( " -hwsurface %s\n","FIXME: Undocumented");
236 printf( " -invulnerability %s\n","FIXME: Undocumented");
237 printf( " -ipxnetwork %s\n","FIXME: Undocumented");
238 printf( " -jasen %s\n","FIXME: Undocumented");
239 printf( " -joyslow %s\n","FIXME: Undocumented");
240 printf( " -kali %s\n","FIXME: Undocumented");
241 printf( " -logfile %s\n","FIXME: Undocumented");
242 printf( " -lowresmovies %s\n","FIXME: Undocumented");
243 printf( " -macdata %s\n","FIXME: Undocumented");
244 printf( " -memdbg %s\n","FIXME: Undocumented");
245 printf( " -monodebug %s\n","FIXME: Undocumented");
246 printf( " -nobm %s\n","FIXME: Undocumented");
247 printf( " -nocdrom %s\n","FIXME: Undocumented");
248 printf( " -nocyberman %s\n","FIXME: Undocumented");
249 printf( " -nofade %s\n","FIXME: Undocumented");
250 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
251 printf( " -nomixer %s\n","FIXME: Undocumented");
252 printf( " -nomodex %s\n","FIXME: Undocumented");
253 printf( " -nomovies %s\n","FIXME: Undocumented");
254 printf( " -norankings %s\n","FIXME: Undocumented");
255 printf( " -noredbook %s\n","FIXME: Undocumented");
256 printf( " -norun %s\n","FIXME: Undocumented");
257 printf( " -noscreens %s\n","FIXME: Undocumented");
258 printf( " -ordinaljoy %s\n","FIXME: Undocumented");
259 printf( " -packets %s\n","FIXME: Undocumented");
260 printf( " -rtscts %s\n","FIXME: Undocumented");
261 printf( " -semiwin %s\n","FIXME: Undocumented");
262 printf( " -showaddress %s\n","FIXME: Undocumented");
263 printf( " -showmeminfo %s\n","FIXME: Undocumented");
264 printf( " -socket %s\n","FIXME: Undocumented");
265 printf( " -specialdevice %s\n","FIXME: Undocumented");
266 printf( " -stickmag %s\n","FIXME: Undocumented");
267 printf( " -stopwatch %s\n","FIXME: Undocumented");
268 printf( " -superhires %s\n","FIXME: Undocumented");
269 printf( " -sysram %s\n","FIXME: Undocumented");
270 printf( " -text %s\n","FIXME: Undocumented");
271 printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
272 printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
273 printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
274 printf( " -udp %s\n","FIXME: Undocumented");
275 printf( " -vidram %s\n","FIXME: Undocumented");
276 printf( " -xcontrol %s\n","FIXME: Undocumented");
277 printf( " -xname %s\n","FIXME: Undocumented");
278 printf( " -xver %s\n","FIXME: Undocumented");
280 printf( "\n D2X System Options:\n\n");
283 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
285 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
286 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
289 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
290 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
291 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
292 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
293 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
294 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
295 printf( " -gl_voodoo %s\n","force fullscreen mode only");
296 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
297 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
298 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
299 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
300 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
301 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
302 printf( " -gl_test1 %s\n","FIXME: Undocumented");
303 printf( " -gl_test2 %s\n","FIXME: Undocumented");
304 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
305 #ifdef OGL_RUNTIME_LOAD
306 printf( " -gl_library <l> %s\n","use alternate opengl library");
310 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
313 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
314 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
317 printf( " -help, -?, ? %s\n", "View this help screen");
321 void do_joystick_init()
325 if (!FindArg( "-nojoystick" )) {
326 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
328 if ( FindArg( "-joyslow" )) {
329 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
330 joy_set_slow_reading(JOY_SLOW_READINGS);
332 if ( FindArg( "-joypolled" )) {
333 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
334 joy_set_slow_reading(JOY_POLLED_READINGS);
336 if ( FindArg( "-joybios" )) {
337 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
338 joy_set_slow_reading(JOY_BIOS_READINGS);
341 // Added from Descent v1.5 by John. Adapted by Samir.
343 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
347 //set this to force game to run in low res
348 int disable_high_res=0;
350 void do_register_player(ubyte *title_pal)
352 Players[Player_num].callsign[0] = '\0';
358 //now, before we bring up the register player menu, we need to
359 //do some stuff to make sure the palette is ok. First, we need to
360 //get our current palette into the 2d's array, so the remapping will
361 //work. Second, we need to remap the fonts. Third, we need to fill
362 //in part of the fade tables so the darkening of the menu edges works
364 memcpy(gr_palette,title_pal,sizeof(gr_palette));
365 remap_fonts_and_menus(1);
366 RegisterPlayer(); //get player's name
372 void do_network_init()
374 if (!FindArg( "-nonetwork" )) {
378 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
379 if ((t=FindArg("-socket")))
380 socket = atoi( Args[t+1] );
381 //@@if ( FindArg("-showaddress") ) showaddress=1;
382 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
383 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
386 switch( ipx_error ) {
387 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
388 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
389 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
391 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
393 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
394 Network_active = 0; // Assume no network
396 ipx_read_user_file( "descent.usr" );
397 ipx_read_network_file( "descent.net" );
398 //@@if ( FindArg( "-dynamicsockets" ))
399 //@@ Network_allow_socket_changes = 1;
401 //@@ Network_allow_socket_changes = 0;
403 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
404 Network_active = 0; // Assume no network
410 #define PROGNAME "d2demo"
412 #define PROGNAME "d2"
415 extern char Language[];
417 //can we do highres menus?
418 extern int MenuHiresAvailable;
421 int intro_played = 0;
424 int Inferno_verbose = 0;
426 int open_movie_file(char *filename,int must_have);
428 #if defined(POLY_ACC)
429 #define MENU_HIRES_MODE SM_640x480x15xPA
431 #define MENU_HIRES_MODE SM(640,480)
434 // DESCENT II by Parallax Software
437 //extern ubyte gr_current_pal[];
441 char Auto_file[128] = "";
444 int main(int argc,char **argv)
447 ubyte title_pal[768];
449 con_init(); // Initialise the console
452 error_init(NULL, NULL);
454 args_init( argc,argv );
456 if ( FindArg( "-debug") )
458 con_threshold.value = (float)2;
461 if ( FindArg( "-verbose" ) )
463 con_threshold.value = (float)1;
470 //tell cfile about our counter
471 cfile_set_critical_error_counter_ptr(&descent_critical_error);
474 cfile_init("d2demo.hog"); //specify name of hogfile
476 #define HOGNAME "descent2.hog"
477 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
479 Error("Could not find required file <%s>",HOGNAME);
486 //print out the banner title
487 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
488 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
489 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
490 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
493 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
494 print_commandline_help();
495 set_exit_message("");
499 con_printf(CON_NORMAL, "\n");
500 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
501 con_printf(CON_NORMAL, "\n");
503 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
505 if ( FindArg( "-autodemo" ))
508 if ( FindArg( "-noscreens" ) )
509 Skip_briefing_screens = 1;
513 // if (init_graphics()) return 1;
516 if (!Inferno_is_800x600_available) {
517 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
518 Function_mode = FMODE_MENU;
523 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
525 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
532 #if defined(POLY_ACC)
533 Current_display_mode = -1;
534 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
537 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
538 set_display_mode(0); //..then set default display mode
541 i = FindArg( "-xcontrol" );
543 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
546 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
547 if (FindArg("-nofade"))
548 grd_fades_disabled=1;
550 if ((t=gr_init())!=0) //doesn't do much
551 Error(TXT_CANT_INIT_GFX,t);
557 // Load the palette stuff. Returns non-zero if error.
558 con_printf(CON_DEBUG, "\nInitializing palette system..." );
559 gr_use_palette_table(DEFAULT_PALETTE );
561 con_printf(CON_DEBUG, "\nInitializing font system..." );
562 gamefont_init(); // must load after palette data loaded.
564 //determine whether we're using high-res menus & movies
565 #if !defined(POLY_ACC)
566 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
567 MovieHires = MenuHires = MenuHiresAvailable = 0;
570 //NOTE LINK TO ABOVE!
571 MenuHires = MenuHiresAvailable = 1;
573 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
574 init_movies(); //init movie libraries
576 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
577 #if defined(POLY_ACC)
578 gr_set_mode(SM_640x480x15xPA);
580 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
584 if ( FindArg( "-notitles" ) )
585 songs_play_song( SONG_TITLE, 1);
588 { //NOTE LINK TO ABOVE!
589 int played=MOVIE_NOT_PLAYED; //default is not played
590 int song_playing = 0;
593 #define MOVIE_REQUIRED 0
595 #define MOVIE_REQUIRED 1
598 #ifdef D2_OEM //$$POLY_ACC, jay.
599 { //show bundler screens
601 char filename[FILENAME_LEN];
603 played=MOVIE_NOT_PLAYED; //default is not played
605 played = PlayMovie("pre_i.mve",0);
608 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
610 while ((tfile=fopen(filename,"rb")) != NULL) {
612 show_title_screen( filename, 1, 0 );
620 init_subtitles("intro.tex");
621 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
626 if (played != MOVIE_NOT_PLAYED)
628 else { //didn't get intro movie, try titles
630 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
632 if (played == MOVIE_NOT_PLAYED) {
633 #if defined(POLY_ACC)
634 gr_set_mode(SM_640x480x15xPA);
636 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
638 con_printf( CON_DEBUG, "\nPlaying title song..." );
639 songs_play_song( SONG_TITLE, 1);
641 con_printf( CON_DEBUG, "\nShowing logo screens..." );
642 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
643 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
647 { //show bundler movie or screens
650 char filename[FILENAME_LEN];
653 played=MOVIE_NOT_PLAYED; //default is not played
655 //check if OEM movie exists, so we don't stop the music if it doesn't
656 movie_handle = open_movie_file("oem.mve",0);
657 if (movie_handle != -1) {
659 played = PlayMovie("oem.mve",0);
660 song_playing = 0; //movie will kill sound
664 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
666 while ((tfile=fopen(filename,"rb")) != NULL) {
668 show_title_screen( filename, 1, 0 );
676 songs_play_song( SONG_TITLE, 1);
680 PA_DFX (pa_splash());
682 con_printf( CON_DEBUG, "\nShowing loading screen..." );
684 //grs_bitmap title_bm;
689 strcpy(filename, "descentd.pcx");
692 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
694 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
698 #if defined(POLY_ACC)
699 gr_set_mode(SM_640x480x15xPA);
701 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
704 FontHires = MenuHires;
706 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
707 //vfx_set_palette_sub( title_pal );
709 gr_palette_fade_in( title_pal, 32, 0 );
711 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
714 con_printf( CON_DEBUG , "\nDoing bm_init..." );
722 if (FindArg("-hoarddata") != 0) {
723 #define MAX_BITMAPS_PER_BRUSH 30
724 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
728 ubyte palette[256*3];
731 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
732 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
733 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
734 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
736 ofile = fopen("hoard.ham","wb");
738 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
739 Assert(iff_error == IFF_NO_ERROR);
740 nframes_short = nframes;
741 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
742 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
743 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
744 fwrite(palette,3,256,ofile);
745 for (i=0;i<nframes;i++)
746 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
748 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
749 Assert(iff_error == IFF_NO_ERROR);
750 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
751 nframes_short = nframes;
752 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
753 fwrite(palette,3,256,ofile);
754 for (i=0;i<nframes;i++)
755 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
758 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
759 Assert(iff_error == IFF_NO_ERROR);
760 fwrite(&icon.bm_w,sizeof(short),1,ofile);
761 fwrite(&icon.bm_h,sizeof(short),1,ofile);
762 fwrite(palette,3,256,ofile);
763 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
766 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
770 ifile = fopen(sounds[i],"rb");
771 Assert(ifile != NULL);
772 size = ffilelength(ifile);
773 buf = d_malloc(size);
774 fread(buf,1,size,ifile);
775 fwrite(&size,sizeof(size),1,ofile);
776 fwrite(buf,1,size,ofile);
787 //the bitmap loading code changes gr_palette, so restore it
788 memcpy(gr_palette,title_pal,sizeof(gr_palette));
790 if ( FindArg( "-norun" ) )
793 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
796 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
797 texmerge_init( 10 ); // 10 cache bitmaps
799 con_printf( CON_DEBUG, "\nRunning game...\n" );
800 set_screen_mode(SCREEN_MENU);
804 // If built with editor, option to auto-load a level and quit game
805 // to write certain data.
808 if ( (t = FindArg( "-autoload" )) ) {
810 strcpy(Auto_file, Args[t+1]);
816 strcpy(Players[0].callsign, "dummy");
819 do_register_player(title_pal);
821 gr_palette_fade_out( title_pal, 32, 0 );
823 Game_mode = GM_GAME_OVER;
826 newdemo_start_playback("descent.dem");
827 if (Newdemo_state == ND_STATE_PLAYBACK )
828 Function_mode = FMODE_GAME;
831 //do this here because the demo code can do a longjmp when trying to
832 //autostart a demo from the main menu, never having gone into the game
835 while (Function_mode != FMODE_EXIT)
837 switch( Function_mode ) {
839 set_screen_mode(SCREEN_MENU);
841 newdemo_start_playback(NULL); // Randomly pick a file
842 if (Newdemo_state != ND_STATE_PLAYBACK)
843 Error("No demo files were found for autodemo mode!");
847 strcpy((char *)&Level_names[0], Auto_file);
849 Function_mode = FMODE_EXIT;
854 check_joystick_calibration();
855 gr_palette_clear(); //I'm not sure why we need this, but we do
858 if ( Function_mode == FMODE_EDITOR ) {
860 SetPlayerFromCurseg();
861 load_palette(NULL,1,0);
868 keyd_editor_mode = 0;
872 /* keep the mouse from wandering in SDL/X11 */
873 if (FindArg("-grabmouse"))
874 SDL_WM_GrabInput(SDL_GRAB_ON);
881 /* give control back to the WM */
882 if (FindArg("-grabmouse"))
883 SDL_WM_GrabInput(SDL_GRAB_OFF);
886 if ( Function_mode == FMODE_MENU )
887 songs_play_song( SONG_TITLE, 1 );
891 keyd_editor_mode = 1;
894 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
896 if ( Function_mode == FMODE_GAME ) {
897 Game_mode = GM_EDITOR;
898 editor_reset_stuff_on_level();
904 Error("Invalid function mode %d",Function_mode);
912 if (!FindArg( "-notitles" ))
917 if ( FindArg( "-showmeminfo" ) )
918 show_mem_info = 1; // Make memory statistics show
921 return(0); //presumably successful exit
925 void check_joystick_calibration() {
926 int x1, y1, x2, y2, c;
929 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
930 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
931 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
932 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
935 joy_get_pos( &x1, &y1 );
937 t1 = timer_get_fixed_seconds();
938 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
941 joy_get_pos( &x2, &y2 );
943 // If joystick hasn't moved...
944 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
945 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
946 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );