1 /* $Id: inferno.c,v 1.42 2002-08-30 00:57:32 btb 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.
29 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
39 #include <sys/types.h>
45 #include "pa_enabl.h" //$$POLY_ACC
57 #include "segment.h" //for Side_to_verts
100 // # include "3dfx_des.h"
102 //added on 9/30/98 by Matt Mueller for selectable automap modes
106 #include "../texmap/scanline.h" //for select_tmap -MM
108 #if defined(POLY_ACC)
109 #include "poly_acc.h"
110 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
114 #include "editor/editor.h"
115 #include "editor/kdefs.h"
126 void arch_init(void);
127 void arch_init_start(void);
129 //Current version number
131 ubyte Version_major = 1; //FULL VERSION
132 ubyte Version_minor = 2;
134 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
135 char desc_id_exit_num = 0;
137 int Function_mode=FMODE_MENU; //game or editor?
138 int Screen_mode=-1; //game screen or editor screen?
140 //--unused-- grs_bitmap Inferno_bitmap_title;
142 int WVIDEO_running=0; //debugger can set to 1 if running
145 int Inferno_is_800x600_available = 0;
148 //--unused-- int Cyberman_installed=0; // SWIFT device present
149 ubyte CybermouseActive=0;
151 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
153 void check_joystick_calibration(void);
156 //--------------------------------------------------------------------------
158 extern int piggy_low_memory;
161 int descent_critical_error = 0;
162 unsigned descent_critical_deverror = 0;
163 unsigned descent_critical_errcode = 0;
165 extern int Network_allow_socket_changes;
167 extern void vfx_set_palette_sub(ubyte *);
169 extern int VR_low_res;
171 extern int Config_vr_type;
172 extern int Config_vr_resolution;
173 extern int Config_vr_tracking;
174 int grd_fades_disabled=1;
178 //read help from a file & print to screen
179 void print_commandline_help()
185 ifile = cfopen("help.tex","rb");
187 ifile = cfopen("help.txb","rb");
189 Error("Cannot load help text file.");
193 while (cfgets(line,LINE_LEN,ifile)) {
197 for (i = 0; i < strlen(line) - 1; i++) {
198 encode_rotate_left(&(line[i]));
199 line[i] = line[i] ^ BITMAP_TBL_XOR;
200 encode_rotate_left(&(line[i]));
205 continue; //don't show comments
213 // printf( " Diagnostic:\n\n");
214 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
215 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
218 printf( " Editor Options:\n\n");
219 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
220 printf( " -hoarddata %s\n","FIXME: Undocumented");
221 printf( " -macdata %s\n","FIXME: Undocumented");
222 // printf( " -nobm %s\n","FIXME: Undocumented");
225 printf( " D2X Options:\n\n");
226 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
227 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
228 printf( " -notitles %s\n", "Do not show titlescreens on startup");
229 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
230 printf( " -autodemo %s\n", "Start in demo mode");
231 printf( " -bigpig %s\n","FIXME: Undocumented");
232 printf( " -bspgen %s\n","FIXME: Undocumented");
233 // printf( " -cdproxy %s\n","FIXME: Undocumented");
235 printf( " -checktime %s\n","FIXME: Undocumented");
236 printf( " -showmeminfo %s\n","FIXME: Undocumented");
238 // printf( " -codereadonly %s\n","FIXME: Undocumented");
239 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
240 printf( " -debug %s\n","Enable very verbose output");
241 // printf( " -debugmode %s\n","FIXME: Undocumented");
242 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
243 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
244 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
245 // printf( " -forcegfx %s\n","FIXME: Undocumented");
247 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
249 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
251 printf( " -invulnerability %s\n","Make yourself invulnerable");
253 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
254 printf( " -jasen %s\n","FIXME: Undocumented");
255 printf( " -joyslow %s\n","FIXME: Undocumented");
256 // printf( " -logfile %s\n","FIXME: Undocumented");
257 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
258 // printf( " -memdbg %s\n","FIXME: Undocumented");
259 // printf( " -monodebug %s\n","FIXME: Undocumented");
260 printf( " -nocdrom %s\n","FIXME: Undocumented");
262 printf( " -nocyberman %s\n","FIXME: Undocumented");
264 printf( " -nofade %s\n","Disable fades");
266 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
267 printf( " -norankings %s\n","Disable multiplayer ranking system");
268 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
269 // printf( " -showaddress %s\n","FIXME: Undocumented");
270 printf( " -socket %s\n","FIXME: Undocumented");
272 #if !defined(MACINTOSH) && !defined(WINDOWS)
273 printf( " -nomixer %s\n","Don't crank music volume");
274 printf( " -superhires %s\n","Allow higher-resolution modes");
276 // printf( " -nomodex %s\n","FIXME: Undocumented");
278 printf( " -nomovies %s\n","Don't play movies");
279 printf( " -noscreens %s\n","Skip briefing screens");
281 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
282 printf( " -noredbook %s\n","Disable redbook audio");
284 printf( " -norun %s\n","Bail out after initialization");
285 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
286 // printf( " -rtscts %s\n","Same as -ctsrts");
287 // printf( " -semiwin %s\n","Use non-fullscreen mode");
288 // printf( " -specialdevice %s\n","FIXME: Undocumented");
290 printf( " -stickmag %s\n","FIXME: Undocumented");
292 // printf( " -stopwatch %s\n","FIXME: Undocumented");
293 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
294 // printf( " -sysram %s\n","FIXME: Undocumented");
295 printf( " -text <file> %s\n","Specify alternate .tex file");
296 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
297 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
298 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
300 printf( " -udp %s\n","Use TCP/UDP for networking");
302 // printf( " -vidram %s\n","FIXME: Undocumented");
303 printf( " -xcontrol %s\n","FIXME: Undocumented");
304 printf( " -xname %s\n","FIXME: Undocumented");
305 printf( " -xver %s\n","FIXME: Undocumented");
306 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
307 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
308 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
309 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
310 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
313 printf( "D2X System Options:\n\n");
315 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
317 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
318 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
321 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
322 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
323 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
324 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
325 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
326 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
327 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
328 printf( " -gl_voodoo %s\n","force fullscreen mode only");
330 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
331 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
332 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
333 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
334 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
335 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
336 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
337 printf( " -gl_test2 %s\n","FIXME: Undocumented");
338 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
339 #ifdef OGL_RUNTIME_LOAD
340 printf( " -gl_library <l> %s\n","use alternate opengl library");
344 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
345 printf( " -hwsurface %s\n","FIXME: Undocumented");
348 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
349 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
351 printf( "\n Help:\n\n");
352 printf( " -help, -h, -?, ? %s\n", "View this help screen");
356 void do_joystick_init()
360 if (!FindArg( "-nojoystick" )) {
361 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
363 if ( FindArg( "-joyslow" )) {
364 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
365 joy_set_slow_reading(JOY_SLOW_READINGS);
367 if ( FindArg( "-joypolled" )) {
368 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
369 joy_set_slow_reading(JOY_POLLED_READINGS);
371 if ( FindArg( "-joybios" )) {
372 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
373 joy_set_slow_reading(JOY_BIOS_READINGS);
376 // Added from Descent v1.5 by John. Adapted by Samir.
378 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
382 //set this to force game to run in low res
383 int disable_high_res=0;
385 void do_register_player(ubyte *title_pal)
387 Players[Player_num].callsign[0] = '\0';
393 //now, before we bring up the register player menu, we need to
394 //do some stuff to make sure the palette is ok. First, we need to
395 //get our current palette into the 2d's array, so the remapping will
396 //work. Second, we need to remap the fonts. Third, we need to fill
397 //in part of the fade tables so the darkening of the menu edges works
399 memcpy(gr_palette,title_pal,sizeof(gr_palette));
400 remap_fonts_and_menus(1);
401 RegisterPlayer(); //get player's name
407 void do_network_init()
409 if (!FindArg( "-nonetwork" )) {
410 int socket = 0, showaddress = 0, t;
413 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
414 if ((t=FindArg("-socket")))
415 socket = atoi( Args[t+1] );
416 //@@if ( FindArg("-showaddress") ) showaddress=1;
417 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket, showaddress))==0) {
418 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
421 switch( ipx_error ) {
422 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
423 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
424 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
426 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
428 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
429 Network_active = 0; // Assume no network
431 ipx_read_user_file( "descent.usr" );
432 ipx_read_network_file( "descent.net" );
433 //@@if ( FindArg( "-dynamicsockets" ))
434 //@@ Network_allow_socket_changes = 1;
436 //@@ Network_allow_socket_changes = 0;
438 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
439 Network_active = 0; // Assume no network
444 #define PROGNAME argv[0]
446 extern char Language[];
448 //can we do highres menus?
449 extern int MenuHiresAvailable;
451 int intro_played = 0;
453 int Inferno_verbose = 0;
455 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
456 int start_net_immediately = 0;
457 //int start_with_mission = 0;
458 //char *start_with_mission_name;
459 //end this section addition
461 int open_movie_file(char *filename,int must_have);
463 #if defined(POLY_ACC)
464 #define MENU_HIRES_MODE SM_640x480x15xPA
466 #define MENU_HIRES_MODE SM(640,480)
469 // DESCENT II by Parallax Software
472 //extern ubyte gr_current_pal[];
476 char Auto_file[128] = "";
479 int main(int argc,char **argv)
482 ubyte title_pal[768];
483 int screen_width = 640;
484 int screen_height = 480;
485 u_int32_t screen_mode = SM(screen_width,screen_height);
487 con_init(); // Initialise the console
490 error_init(NULL, NULL);
494 char *home = getenv("HOME");
497 char buf[PATH_MAX + 5];
500 strcat(buf, "/.d2x");
504 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
510 InitArgs( argc,argv );
512 if (FindArg("-debug"))
513 con_threshold.value = (float)2;
514 else if (FindArg("-verbose"))
515 con_threshold.value = (float)1;
522 //tell cfile where hogdir is
523 cfile_use_alternate_hogdir(SHAREPATH);
526 //tell cfile about our counter
527 cfile_set_critical_error_counter_ptr(&descent_critical_error);
529 if (! cfile_init("descent2.hog"))
530 if (! cfile_init("d2demo.hog"))
531 Error("Could not find a valid hog file (descent2.hog or d2demo.hog)");
534 //print out the banner title
535 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
536 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
537 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
538 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
539 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
542 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
543 print_commandline_help();
544 set_exit_message("");
546 exit(0); /* mingw hangs on this return. dunno why */
551 con_printf(CON_NORMAL, "\n");
552 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
553 con_printf(CON_NORMAL, "\n");
555 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
557 if ( FindArg( "-autodemo" ))
561 if ( FindArg( "-noscreens" ) )
562 Skip_briefing_screens = 1;
565 if ((t=FindArg("-tmap"))){
566 select_tmap(Args[t+1]);
572 // if (init_graphics()) return 1;
575 if (!Inferno_is_800x600_available) {
576 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
577 Function_mode = FMODE_MENU;
582 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
584 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
591 #if defined(POLY_ACC)
592 Current_display_mode = -1;
593 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
596 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
597 set_display_mode(0); //..then set default display mode
601 //added on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
602 int i, argnum=INT_MAX;
604 int vr_mode = VR_NONE;
605 int screen_compatible = 1;
606 int use_double_buffer = 0;
608 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
609 //added on 9/30/98 by Matt Mueller clean up screen mode code, and add higher resolutions
610 #define SCREENMODE(X,Y,C) if ( (i=FindArg( "-" #X "x" #Y ))&&(i<argnum)) {argnum=i; screen_mode = SM( X , Y ); con_printf(CON_VERBOSE, "Using " #X "x" #Y " ...\n" );screen_width = X;screen_height = Y;use_double_buffer = 1;screen_compatible = C;}
611 //aren't #defines great? :)
613 SCREENMODE(320,100,0);
614 SCREENMODE(320,200,1);
615 //end addition/edit -MM
616 SCREENMODE(320,240,0);
617 SCREENMODE(320,400,0);
618 SCREENMODE(640,400,0);
619 SCREENMODE(640,480,0);
620 SCREENMODE(800,600,0);
621 SCREENMODE(1024,768,0);
622 SCREENMODE(1152,864,0);
623 SCREENMODE(1280,960,0);
624 SCREENMODE(1280,1024,0);
625 SCREENMODE(1600,1200,0);
628 //added ifdefs on 9/30/98 by Matt Mueller to fix high res in linux
630 if ( FindArg( "-nodoublebuffer" ) ) {
631 con_printf(CON_VERBOSE, "Double-buffering disabled...\n" );
633 use_double_buffer = 0;
639 //added 3/24/99 by Owen Evans for screen res changing
640 // Game_Screen_mode = screen_mode;
642 game_init_render_buffers(screen_mode, screen_width, screen_height, vr_mode, screen_compatible);
646 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
647 int i, argnum=INT_MAX;
648 //added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines.
649 #define SMODE(V,VV,VG,X,Y) if ( (i=FindArg( "-" #V #X "x" #Y )) && (i<argnum)) {argnum=i; VV = SM( X , Y );VG=0;}
650 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
651 #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) );
652 //aren't #defines great? :)
653 //end addition/edit -MM
654 #define S_MODE(V,VV,VG) argnum=INT_MAX;SMODE(V,VV,VG,320,200);SMODE(V,VV,VG,320,240);SMODE(V,VV,VG,320,400);SMODE(V,VV,VG,640,400);SMODE(V,VV,VG,640,480);SMODE(V,VV,VG,800,600);SMODE(V,VV,VG,1024,768);SMODE(V,VV,VG,1280,1024);SMODE(V,VV,VG,1600,1200);SMODE_GR(V,VG);SMODE_PRINT(V,VV,VG);
656 S_MODE(automap,automap_mode,automap_use_game_res);
657 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
661 i = FindArg( "-xcontrol" );
663 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
666 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
667 if (FindArg("-nofade"))
668 grd_fades_disabled=1;
670 //determine whether we're using high-res menus & movies
671 #if !defined(POLY_ACC)
672 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
673 MovieHires = MenuHires = MenuHiresAvailable = 0;
676 //NOTE LINK TO ABOVE!
677 MenuHires = MenuHiresAvailable = 1;
679 if ((t=gr_init())!=0) //doesn't do much
680 Error(TXT_CANT_INIT_GFX,t);
686 // Load the palette stuff. Returns non-zero if error.
687 con_printf(CON_DEBUG, "Initializing palette system...\n" );
688 gr_use_palette_table(DEFAULT_PALETTE );
690 con_printf(CON_DEBUG, "Initializing font system...\n" );
691 gamefont_init(); // must load after palette data loaded.
693 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
694 init_movies(); //init movie libraries
697 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
698 #if defined(POLY_ACC)
699 gr_set_mode(SM_640x480x15xPA);
701 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
706 if ( FindArg( "-notitles" ) )
707 songs_play_song( SONG_TITLE, 1);
710 { //NOTE LINK TO ABOVE!
712 int played=MOVIE_NOT_PLAYED; //default is not played
714 int song_playing = 0;
717 #define MOVIE_REQUIRED 0
719 #define MOVIE_REQUIRED 1
722 #ifdef D2_OEM //$$POLY_ACC, jay.
723 { //show bundler screens
725 char filename[FILENAME_LEN];
727 played=MOVIE_NOT_PLAYED; //default is not played
729 played = PlayMovie("pre_i.mve",0);
732 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
734 while ((tfile=fopen(filename,"rb")) != NULL) {
736 show_title_screen( filename, 1, 0 );
744 init_subtitles("intro.tex");
745 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
750 if (played != MOVIE_NOT_PLAYED)
752 else { //didn't get intro movie, try titles
754 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
756 if (played == MOVIE_NOT_PLAYED) {
757 #if defined(POLY_ACC)
758 gr_set_mode(SM_640x480x15xPA);
760 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
762 con_printf( CON_DEBUG, "\nPlaying title song..." );
763 songs_play_song( SONG_TITLE, 1);
765 con_printf( CON_DEBUG, "\nShowing logo screens..." );
766 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
767 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
771 { //show bundler movie or screens
774 char filename[FILENAME_LEN];
777 played=MOVIE_NOT_PLAYED; //default is not played
779 //check if OEM movie exists, so we don't stop the music if it doesn't
780 movie_handle = open_movie_file("oem.mve",0);
781 if (movie_handle != -1) {
783 played = PlayMovie("oem.mve",0);
784 song_playing = 0; //movie will kill sound
788 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
790 while ((tfile=fopen(filename,"rb")) != NULL) {
792 show_title_screen( filename, 1, 0 );
800 songs_play_song( SONG_TITLE, 1);
804 PA_DFX (pa_splash());
806 con_printf( CON_DEBUG, "\nShowing loading screen..." );
808 //grs_bitmap title_bm;
812 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
813 if (! cfexist(filename))
814 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
815 if (! cfexist(filename))
816 strcpy(filename, "descentd.pcx"); // SHAREWARE
818 #if defined(POLY_ACC)
819 gr_set_mode(SM_640x480x15xPA);
821 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
824 FontHires = FontHiresAvailable && MenuHires;
826 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
827 //vfx_set_palette_sub( title_pal );
829 gr_palette_fade_in( title_pal, 32, 0 );
831 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
834 con_printf( CON_DEBUG , "\nDoing bm_init..." );
842 if (FindArg("-hoarddata") != 0) {
843 #define MAX_BITMAPS_PER_BRUSH 30
844 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
848 ubyte palette[256*3];
851 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
852 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
853 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
854 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
856 ofile = fopen("hoard.ham","wb");
858 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
859 Assert(iff_error == IFF_NO_ERROR);
860 nframes_short = nframes;
861 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
862 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
863 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
864 fwrite(palette,3,256,ofile);
865 for (i=0;i<nframes;i++)
866 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
868 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
869 Assert(iff_error == IFF_NO_ERROR);
870 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
871 nframes_short = nframes;
872 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
873 fwrite(palette,3,256,ofile);
874 for (i=0;i<nframes;i++)
875 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
878 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
879 Assert(iff_error == IFF_NO_ERROR);
880 fwrite(&icon.bm_w,sizeof(short),1,ofile);
881 fwrite(&icon.bm_h,sizeof(short),1,ofile);
882 fwrite(palette,3,256,ofile);
883 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
886 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
890 ifile = fopen(sounds[i],"rb");
891 Assert(ifile != NULL);
892 size = ffilelength(ifile);
893 buf = d_malloc(size);
894 fread(buf,1,size,ifile);
895 fwrite(&size,sizeof(size),1,ofile);
896 fwrite(buf,1,size,ofile);
907 //the bitmap loading code changes gr_palette, so restore it
908 memcpy(gr_palette,title_pal,sizeof(gr_palette));
910 if ( FindArg( "-norun" ) )
913 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
916 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
917 texmerge_init( 10 ); // 10 cache bitmaps
919 con_printf( CON_DEBUG, "\nRunning game...\n" );
920 set_screen_mode(SCREEN_MENU);
924 // If built with editor, option to auto-load a level and quit game
925 // to write certain data.
928 if ( (t = FindArg( "-autoload" )) ) {
930 strcpy(Auto_file, Args[t+1]);
936 strcpy(Players[0].callsign, "dummy");
939 do_register_player(title_pal);
941 gr_palette_fade_out( title_pal, 32, 0 );
943 Game_mode = GM_GAME_OVER;
946 newdemo_start_playback("descent.dem");
947 if (Newdemo_state == ND_STATE_PLAYBACK )
948 Function_mode = FMODE_GAME;
951 //do this here because the demo code can do a longjmp when trying to
952 //autostart a demo from the main menu, never having gone into the game
955 while (Function_mode != FMODE_EXIT)
957 switch( Function_mode ) {
959 set_screen_mode(SCREEN_MENU);
961 newdemo_start_playback(NULL); // Randomly pick a file
962 if (Newdemo_state != ND_STATE_PLAYBACK)
963 Error("No demo files were found for autodemo mode!");
967 strcpy((char *)&Level_names[0], Auto_file);
969 Function_mode = FMODE_EXIT;
974 check_joystick_calibration();
975 gr_palette_clear(); //I'm not sure why we need this, but we do
978 if ( Function_mode == FMODE_EDITOR ) {
980 SetPlayerFromCurseg();
981 load_palette(NULL,1,0);
988 keyd_editor_mode = 0;
992 /* keep the mouse from wandering in SDL */
993 if (FindArg("-grabmouse"))
994 SDL_WM_GrabInput(SDL_GRAB_ON);
1000 /* give control back to the WM */
1001 if (FindArg("-grabmouse"))
1002 SDL_WM_GrabInput(SDL_GRAB_OFF);
1005 if ( Function_mode == FMODE_MENU )
1006 songs_play_song( SONG_TITLE, 1 );
1010 keyd_editor_mode = 1;
1013 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1015 if ( Function_mode == FMODE_GAME ) {
1016 Game_mode = GM_EDITOR;
1017 editor_reset_stuff_on_level();
1023 Error("Invalid function mode %d",Function_mode);
1031 if (!FindArg( "-notitles" ))
1036 if ( FindArg( "-showmeminfo" ) )
1037 show_mem_info = 1; // Make memory statistics show
1040 return(0); //presumably successful exit
1044 void check_joystick_calibration() {
1045 int x1, y1, x2, y2, c;
1048 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1049 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1050 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1051 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1054 joy_get_pos( &x1, &y1 );
1056 t1 = timer_get_fixed_seconds();
1057 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1060 joy_get_pos( &x2, &y2 );
1062 // If joystick hasn't moved...
1063 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1064 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1065 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1067 joydefs_calibrate();
1074 void show_order_form()
1076 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1079 char title_pal[768];
1080 char exit_screen[16];
1082 gr_set_current_canvas( NULL );
1088 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1090 #if defined(SHAREWARE)
1091 strcpy(exit_screen, "orderd2.pcx");
1093 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1097 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1098 //vfx_set_palette_sub( title_pal );
1099 gr_palette_fade_in( title_pal, 32, 0 );
1101 gr_palette_fade_out( title_pal, 32, 0 );
1104 Int3(); //can't load order screen
1114 // void network_abort_game();
1115 // if(Network_status)
1116 // network_abort_game();