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: 2002-02-16 02:08:31 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.26 2002/02/15 12:24:53 bradleyb
24 * automap resolution now selectable
26 * Revision 1.25 2002/02/14 11:29:31 bradleyb
27 * allow gr_init lowres
29 * Revision 1.24 2002/02/13 10:39:21 bradleyb
30 * Lotsa networking stuff from d1x
32 * Revision 1.23 2002/02/02 23:30:26 bradleyb
33 * Enabled RELEASE option
35 * Revision 1.22 2002/01/29 10:11:56 bradleyb
36 * update copyright date
38 * Revision 1.21 2002/01/29 00:08:13 bradleyb
41 * Revision 1.20 2002/01/28 00:03:47 bradleyb
42 * Data files now go in DATADIR/games/d2x, user files now go in ~/.d2x
44 * Revision 1.19 2002/01/18 07:01:37 bradleyb
47 * Revision 1.18 2001/12/28 09:26:41 bradleyb
48 * document -nomovies option
50 * Revision 1.17 2001/11/09 06:55:08 bradleyb
53 * Revision 1.16 2001/11/08 10:30:28 bradleyb
54 * Enabled shareware build, endlevel flythrough sequence
56 * Revision 1.15 2001/11/05 07:39:08 bradleyb
57 * Change args_init back to InitArgs
59 * Revision 1.14 2001/11/04 09:01:41 bradleyb
60 * SDL applies to more than X11...
62 * Revision 1.13 2001/10/31 07:41:54 bradleyb
65 * Revision 1.12 2001/10/27 01:39:23 bradleyb
66 * added some documentation
68 * Revision 1.11 2001/10/25 09:12:16 bradleyb
69 * Completed tmap selection code.
71 * Revision 1.10 2001/10/25 02:19:31 bradleyb
72 * conditionalize including multi.h and network.h, fix backslashes, fix compiler errors with EDITOR
74 * Revision 1.9 2001/10/19 08:08:50 bradleyb
75 * conditionalize conf.h
77 * Revision 1.8 2001/10/19 00:31:51 bradleyb
78 * Trying to get network working on win32
80 * Revision 1.7 2001/10/18 00:01:01 bradleyb
81 * RCS headers added/changed
90 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
100 #include <sys/types.h>
106 #include "pa_enabl.h" //$$POLY_ACC
118 #include "segment.h" //for Side_to_verts
120 #include "segpoint.h"
123 #include "texmerge.h"
143 #include "gamefont.h"
161 // # include "3dfx_des.h"
163 //added on 9/30/98 by Matt Mueller for selectable automap modes
167 #include "../texmap/scanline.h" //for select_tmap -MM
169 #if defined(POLY_ACC)
170 #include "poly_acc.h"
171 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
175 #include "editor/editor.h"
176 #include "editor/kdefs.h"
184 #ifndef SDL_VERSION_ATLEAST
191 void arch_init(void);
192 void arch_init_start(void);
194 //Current version number
196 ubyte Version_major = 1; //FULL VERSION
197 ubyte Version_minor = 2;
199 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
200 char desc_id_exit_num = 0;
202 int Function_mode=FMODE_MENU; //game or editor?
203 int Screen_mode=-1; //game screen or editor screen?
205 //--unused-- grs_bitmap Inferno_bitmap_title;
207 int WVIDEO_running=0; //debugger can set to 1 if running
210 int Inferno_is_800x600_available = 0;
213 //--unused-- int Cyberman_installed=0; // SWIFT device present
214 ubyte CybermouseActive=0;
216 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
218 void check_joystick_calibration(void);
221 //--------------------------------------------------------------------------
223 extern int piggy_low_memory;
226 int descent_critical_error = 0;
227 unsigned descent_critical_deverror = 0;
228 unsigned descent_critical_errcode = 0;
230 extern int Network_allow_socket_changes;
232 extern void vfx_set_palette_sub(ubyte *);
234 extern int VR_low_res;
236 extern int Config_vr_type;
237 extern int Config_vr_resolution;
238 extern int Config_vr_tracking;
239 int grd_fades_disabled=1;
243 //read help from a file & print to screen
244 void print_commandline_help()
250 ifile = cfopen("help.tex","rb");
252 ifile = cfopen("help.txb","rb");
254 Error("Cannot load help text file.");
258 while (cfgets(line,LINE_LEN,ifile)) {
262 for (i = 0; i < strlen(line) - 1; i++) {
263 encode_rotate_left(&(line[i]));
264 line[i] = line[i] ^ BITMAP_TBL_XOR;
265 encode_rotate_left(&(line[i]));
270 continue; //don't show comments
278 // printf( " Diagnostic:\n\n");
279 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
280 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
283 printf( " Editor Options:\n\n");
284 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
285 printf( " -hoarddata %s\n","FIXME: Undocumented");
286 printf( " -macdata %s\n","FIXME: Undocumented");
287 // printf( " -nobm %s\n","FIXME: Undocumented");
290 printf( " D2X Options:\n\n");
291 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
292 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
293 printf( " -notitles %s\n", "Do not show titlescreens on startup");
294 printf( " -ini <file> %s\n", "option file (alternate to command line) defaults to d2x.ini, or d1x.ini");
295 printf( " -autodemo %s\n", "Start in demo mode");
296 printf( " -bigpig %s\n","FIXME: Undocumented");
297 printf( " -bspgen %s\n","FIXME: Undocumented");
298 // printf( " -cdproxy %s\n","FIXME: Undocumented");
300 printf( " -checktime %s\n","FIXME: Undocumented");
301 printf( " -showmeminfo %s\n","FIXME: Undocumented");
303 // printf( " -codereadonly %s\n","FIXME: Undocumented");
304 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
305 printf( " -debug %s\n","Enable very verbose output");
306 // printf( " -debugmode %s\n","FIXME: Undocumented");
307 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
308 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
309 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
310 // printf( " -forcegfx %s\n","FIXME: Undocumented");
312 #if SDL_VERSION_ATLEAST(1,0,2)
313 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
316 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
318 printf( " -invulnerability %s\n","Make yourself invulnerable");
320 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
321 printf( " -jasen %s\n","FIXME: Undocumented");
322 printf( " -joyslow %s\n","FIXME: Undocumented");
323 // printf( " -logfile %s\n","FIXME: Undocumented");
324 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
325 // printf( " -memdbg %s\n","FIXME: Undocumented");
326 // printf( " -monodebug %s\n","FIXME: Undocumented");
327 #if defined(__DJGPP__) || defined(__SDL__)
328 printf( " -nocdrom %s\n","FIXME: Undocumented");
331 printf( " -nocyberman %s\n","FIXME: Undocumented");
333 printf( " -nofade %s\n","Disable fades");
335 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
336 printf( " -norankings %s\n","Disable multiplayer ranking system");
337 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
338 // printf( " -showaddress %s\n","FIXME: Undocumented");
339 printf( " -socket %s\n","FIXME: Undocumented");
341 #if !defined(MACINTOSH) && !defined(WINDOWS)
342 printf( " -nomixer %s\n","Don't crank music volume");
343 printf( " -superhires %s\n","Allow higher-resolution modes");
345 // printf( " -nomodex %s\n","FIXME: Undocumented");
347 printf( " -nomovies %s\n","Don't play movies");
348 printf( " -noscreens %s\n","Skip briefing screens");
350 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
351 printf( " -noredbook %s\n","Disable redbook audio");
353 printf( " -norun %s\n","Bail out after initialization");
354 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
355 // printf( " -rtscts %s\n","Same as -ctsrts");
356 // printf( " -semiwin %s\n","Use non-fullscreen mode");
357 // printf( " -specialdevice %s\n","FIXME: Undocumented");
359 printf( " -stickmag %s\n","FIXME: Undocumented");
361 // printf( " -stopwatch %s\n","FIXME: Undocumented");
362 // printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
363 // printf( " -sysram %s\n","FIXME: Undocumented");
364 printf( " -text <file> %s\n","Specify alternate .tex file");
365 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
366 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
367 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
368 // printf( " -udp %s\n","FIXME: Undocumented");
369 // printf( " -vidram %s\n","FIXME: Undocumented");
370 printf( " -xcontrol %s\n","FIXME: Undocumented");
371 printf( " -xname %s\n","FIXME: Undocumented");
372 printf( " -xver %s\n","FIXME: Undocumented");
373 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
374 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
375 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
376 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
377 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
380 printf( "D2X System Options:\n\n");
382 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
384 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
385 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
388 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
389 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
390 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
391 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
392 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
393 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
394 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
395 printf( " -gl_voodoo %s\n","force fullscreen mode only");
397 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
398 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
399 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
400 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
401 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
402 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
403 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
404 printf( " -gl_test2 %s\n","FIXME: Undocumented");
405 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
406 #ifdef OGL_RUNTIME_LOAD
407 printf( " -gl_library <l> %s\n","use alternate opengl library");
411 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
412 printf( " -hwsurface %s\n","FIXME: Undocumented");
415 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
416 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
418 printf( "\n Help:\n\n");
419 printf( " -help, -h, -?, ? %s\n", "View this help screen");
423 void do_joystick_init()
427 if (!FindArg( "-nojoystick" )) {
428 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
430 if ( FindArg( "-joyslow" )) {
431 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
432 joy_set_slow_reading(JOY_SLOW_READINGS);
434 if ( FindArg( "-joypolled" )) {
435 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
436 joy_set_slow_reading(JOY_POLLED_READINGS);
438 if ( FindArg( "-joybios" )) {
439 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
440 joy_set_slow_reading(JOY_BIOS_READINGS);
443 // Added from Descent v1.5 by John. Adapted by Samir.
445 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
449 //set this to force game to run in low res
450 int disable_high_res=0;
452 void do_register_player(ubyte *title_pal)
454 Players[Player_num].callsign[0] = '\0';
460 //now, before we bring up the register player menu, we need to
461 //do some stuff to make sure the palette is ok. First, we need to
462 //get our current palette into the 2d's array, so the remapping will
463 //work. Second, we need to remap the fonts. Third, we need to fill
464 //in part of the fade tables so the darkening of the menu edges works
466 memcpy(gr_palette,title_pal,sizeof(gr_palette));
467 remap_fonts_and_menus(1);
468 RegisterPlayer(); //get player's name
474 void do_network_init()
476 if (!FindArg( "-nonetwork" )) {
480 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
481 if ((t=FindArg("-socket")))
482 socket = atoi( Args[t+1] );
483 //@@if ( FindArg("-showaddress") ) showaddress=1;
484 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
485 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
488 switch( ipx_error ) {
489 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
490 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
491 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
493 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
495 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
496 Network_active = 0; // Assume no network
498 ipx_read_user_file( "descent.usr" );
499 ipx_read_network_file( "descent.net" );
500 //@@if ( FindArg( "-dynamicsockets" ))
501 //@@ Network_allow_socket_changes = 1;
503 //@@ Network_allow_socket_changes = 0;
505 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
506 Network_active = 0; // Assume no network
511 #define PROGNAME argv[0]
513 extern char Language[];
515 //can we do highres menus?
516 extern int MenuHiresAvailable;
519 int intro_played = 0;
522 int Inferno_verbose = 0;
524 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
525 int start_net_immediately = 0;
526 //int start_with_mission = 0;
527 //char *start_with_mission_name;
528 //end this section addition
530 int open_movie_file(char *filename,int must_have);
532 #if defined(POLY_ACC)
533 #define MENU_HIRES_MODE SM_640x480x15xPA
535 #define MENU_HIRES_MODE SM(640,480)
538 // DESCENT II by Parallax Software
541 //extern ubyte gr_current_pal[];
545 char Auto_file[128] = "";
548 int main(int argc,char **argv)
551 ubyte title_pal[768];
552 int screen_width = 640;
553 int screen_height = 480;
554 u_int32_t screen_mode = SM(640,480);
556 con_init(); // Initialise the console
559 error_init(NULL, NULL);
563 char *home = getenv("HOME");
566 char buf[PATH_MAX + 5];
569 strcat(buf, "/.d2x");
573 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
579 InitArgs( argc,argv );
581 if ( FindArg( "-debug") )
583 con_threshold.value = (float)2;
586 if ( FindArg( "-verbose" ) )
588 con_threshold.value = (float)1;
595 //tell cfile where hogdir is
596 cfile_use_alternate_hogdir(SHAREPATH);
598 //tell cfile about our counter
599 cfile_set_critical_error_counter_ptr(&descent_critical_error);
602 cfile_init("d2demo.hog"); //specify name of hogfile
604 #define HOGNAME "descent2.hog"
605 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
607 Error("Could not find required file <%s>",HOGNAME);
614 //print out the banner title
615 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
616 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
617 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
618 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
619 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
622 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
623 print_commandline_help();
624 set_exit_message("");
626 exit(0); /* mingw hangs on this return. dunno why */
631 con_printf(CON_NORMAL, "\n");
632 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
633 con_printf(CON_NORMAL, "\n");
635 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
637 if ( FindArg( "-autodemo" ))
641 if ( FindArg( "-noscreens" ) )
642 Skip_briefing_screens = 1;
645 if ((t=FindArg("-tmap"))){
646 select_tmap(Args[t+1]);
652 // if (init_graphics()) return 1;
655 if (!Inferno_is_800x600_available) {
656 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
657 Function_mode = FMODE_MENU;
662 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
664 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
671 #if defined(POLY_ACC)
672 Current_display_mode = -1;
673 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
676 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
677 set_display_mode(0); //..then set default display mode
681 //added on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
682 int i, argnum=INT_MAX;
684 int vr_mode = VR_NONE;
685 int screen_compatible = 1;
686 int use_double_buffer = 0;
688 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
689 //added on 9/30/98 by Matt Mueller clean up screen mode code, and add higher resolutions
690 #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;}
691 //aren't #defines great? :)
693 SCREENMODE(320,100,0);
694 SCREENMODE(320,200,1);
695 //end addition/edit -MM
696 SCREENMODE(320,240,0);
697 SCREENMODE(320,400,0);
698 SCREENMODE(640,400,0);
699 SCREENMODE(640,480,0);
700 SCREENMODE(800,600,0);
701 SCREENMODE(1024,768,0);
702 SCREENMODE(1152,864,0);
703 SCREENMODE(1280,960,0);
704 SCREENMODE(1280,1024,0);
705 SCREENMODE(1600,1200,0);
708 //added ifdefs on 9/30/98 by Matt Mueller to fix high res in linux
710 if ( FindArg( "-nodoublebuffer" ) ) {
711 con_printf(CON_VERBOSE, "Double-buffering disabled...\n" );
713 use_double_buffer = 0;
719 //added 3/24/99 by Owen Evans for screen res changing
720 // Game_Screen_mode = screen_mode;
722 game_init_render_buffers(screen_mode, screen_width, screen_height, vr_mode, screen_compatible);
726 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
727 int i, argnum=INT_MAX;
728 //added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines.
729 #define SMODE(V,VV,VG,X,Y) if ( (i=FindArg( "-" #V #X "x" #Y )) && (i<argnum)) {argnum=i; VV = SM( X , Y );VG=0;}
730 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
731 #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) );
732 //aren't #defines great? :)
733 //end addition/edit -MM
734 #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);
736 S_MODE(automap,automap_mode,automap_use_game_res);
737 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
741 i = FindArg( "-xcontrol" );
743 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
746 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
747 if (FindArg("-nofade"))
748 grd_fades_disabled=1;
750 //determine whether we're using high-res menus & movies
751 #if !defined(POLY_ACC)
752 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
753 MovieHires = MenuHires = MenuHiresAvailable = 0;
756 //NOTE LINK TO ABOVE!
757 MenuHires = MenuHiresAvailable = 1;
759 if ((t=gr_init())!=0) //doesn't do much
760 Error(TXT_CANT_INIT_GFX,t);
766 // Load the palette stuff. Returns non-zero if error.
767 con_printf(CON_DEBUG, "\nInitializing palette system..." );
768 gr_use_palette_table(DEFAULT_PALETTE );
770 con_printf(CON_DEBUG, "\nInitializing font system..." );
771 gamefont_init(); // must load after palette data loaded.
773 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
774 init_movies(); //init movie libraries
776 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
777 #if defined(POLY_ACC)
778 gr_set_mode(SM_640x480x15xPA);
780 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
784 if ( FindArg( "-notitles" ) )
785 songs_play_song( SONG_TITLE, 1);
788 { //NOTE LINK TO ABOVE!
790 int played=MOVIE_NOT_PLAYED; //default is not played
792 int song_playing = 0;
795 #define MOVIE_REQUIRED 0
797 #define MOVIE_REQUIRED 1
800 #ifdef D2_OEM //$$POLY_ACC, jay.
801 { //show bundler screens
803 char filename[FILENAME_LEN];
805 played=MOVIE_NOT_PLAYED; //default is not played
807 played = PlayMovie("pre_i.mve",0);
810 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
812 while ((tfile=fopen(filename,"rb")) != NULL) {
814 show_title_screen( filename, 1, 0 );
822 init_subtitles("intro.tex");
823 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
828 if (played != MOVIE_NOT_PLAYED)
830 else { //didn't get intro movie, try titles
832 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
834 if (played == MOVIE_NOT_PLAYED) {
835 #if defined(POLY_ACC)
836 gr_set_mode(SM_640x480x15xPA);
838 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
840 con_printf( CON_DEBUG, "\nPlaying title song..." );
841 songs_play_song( SONG_TITLE, 1);
843 con_printf( CON_DEBUG, "\nShowing logo screens..." );
844 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
845 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
849 { //show bundler movie or screens
852 char filename[FILENAME_LEN];
855 played=MOVIE_NOT_PLAYED; //default is not played
857 //check if OEM movie exists, so we don't stop the music if it doesn't
858 movie_handle = open_movie_file("oem.mve",0);
859 if (movie_handle != -1) {
861 played = PlayMovie("oem.mve",0);
862 song_playing = 0; //movie will kill sound
866 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
868 while ((tfile=fopen(filename,"rb")) != NULL) {
870 show_title_screen( filename, 1, 0 );
878 songs_play_song( SONG_TITLE, 1);
882 PA_DFX (pa_splash());
884 con_printf( CON_DEBUG, "\nShowing loading screen..." );
886 //grs_bitmap title_bm;
891 strcpy(filename, "descentd.pcx");
894 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
896 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
900 #if defined(POLY_ACC)
901 gr_set_mode(SM_640x480x15xPA);
903 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
906 FontHires = MenuHires;
908 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
909 //vfx_set_palette_sub( title_pal );
911 gr_palette_fade_in( title_pal, 32, 0 );
913 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
916 con_printf( CON_DEBUG , "\nDoing bm_init..." );
924 if (FindArg("-hoarddata") != 0) {
925 #define MAX_BITMAPS_PER_BRUSH 30
926 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
930 ubyte palette[256*3];
933 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
934 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
935 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
936 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
938 ofile = fopen("hoard.ham","wb");
940 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
941 Assert(iff_error == IFF_NO_ERROR);
942 nframes_short = nframes;
943 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
944 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
945 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
946 fwrite(palette,3,256,ofile);
947 for (i=0;i<nframes;i++)
948 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
950 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
951 Assert(iff_error == IFF_NO_ERROR);
952 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
953 nframes_short = nframes;
954 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
955 fwrite(palette,3,256,ofile);
956 for (i=0;i<nframes;i++)
957 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
960 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
961 Assert(iff_error == IFF_NO_ERROR);
962 fwrite(&icon.bm_w,sizeof(short),1,ofile);
963 fwrite(&icon.bm_h,sizeof(short),1,ofile);
964 fwrite(palette,3,256,ofile);
965 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
968 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
972 ifile = fopen(sounds[i],"rb");
973 Assert(ifile != NULL);
974 size = ffilelength(ifile);
975 buf = d_malloc(size);
976 fread(buf,1,size,ifile);
977 fwrite(&size,sizeof(size),1,ofile);
978 fwrite(buf,1,size,ofile);
989 //the bitmap loading code changes gr_palette, so restore it
990 memcpy(gr_palette,title_pal,sizeof(gr_palette));
992 if ( FindArg( "-norun" ) )
995 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
998 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
999 texmerge_init( 10 ); // 10 cache bitmaps
1001 con_printf( CON_DEBUG, "\nRunning game...\n" );
1002 set_screen_mode(SCREEN_MENU);
1006 // If built with editor, option to auto-load a level and quit game
1007 // to write certain data.
1010 if ( (t = FindArg( "-autoload" )) ) {
1012 strcpy(Auto_file, Args[t+1]);
1018 strcpy(Players[0].callsign, "dummy");
1021 do_register_player(title_pal);
1023 gr_palette_fade_out( title_pal, 32, 0 );
1025 Game_mode = GM_GAME_OVER;
1028 newdemo_start_playback("descent.dem");
1029 if (Newdemo_state == ND_STATE_PLAYBACK )
1030 Function_mode = FMODE_GAME;
1033 //do this here because the demo code can do a longjmp when trying to
1034 //autostart a demo from the main menu, never having gone into the game
1037 while (Function_mode != FMODE_EXIT)
1039 switch( Function_mode ) {
1041 set_screen_mode(SCREEN_MENU);
1043 newdemo_start_playback(NULL); // Randomly pick a file
1044 if (Newdemo_state != ND_STATE_PLAYBACK)
1045 Error("No demo files were found for autodemo mode!");
1049 strcpy((char *)&Level_names[0], Auto_file);
1051 Function_mode = FMODE_EXIT;
1056 check_joystick_calibration();
1057 gr_palette_clear(); //I'm not sure why we need this, but we do
1060 if ( Function_mode == FMODE_EDITOR ) {
1062 SetPlayerFromCurseg();
1063 load_palette(NULL,1,0);
1070 keyd_editor_mode = 0;
1074 #if SDL_VERSION_ATLEAST(1,0,2)
1075 /* keep the mouse from wandering in SDL */
1076 if (FindArg("-grabmouse"))
1077 SDL_WM_GrabInput(SDL_GRAB_ON);
1084 #if SDL_VERSION_ATLEAST(1,0,2)
1085 /* give control back to the WM */
1086 if (FindArg("-grabmouse"))
1087 SDL_WM_GrabInput(SDL_GRAB_OFF);
1091 if ( Function_mode == FMODE_MENU )
1092 songs_play_song( SONG_TITLE, 1 );
1096 keyd_editor_mode = 1;
1099 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1101 if ( Function_mode == FMODE_GAME ) {
1102 Game_mode = GM_EDITOR;
1103 editor_reset_stuff_on_level();
1109 Error("Invalid function mode %d",Function_mode);
1117 if (!FindArg( "-notitles" ))
1122 if ( FindArg( "-showmeminfo" ) )
1123 show_mem_info = 1; // Make memory statistics show
1126 return(0); //presumably successful exit
1130 void check_joystick_calibration() {
1131 int x1, y1, x2, y2, c;
1134 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1135 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1136 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1137 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1140 joy_get_pos( &x1, &y1 );
1142 t1 = timer_get_fixed_seconds();
1143 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1146 joy_get_pos( &x2, &y2 );
1148 // If joystick hasn't moved...
1149 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1150 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1151 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1153 joydefs_calibrate();
1160 void show_order_form()
1162 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1165 char title_pal[768];
1166 char exit_screen[16];
1168 gr_set_current_canvas( NULL );
1174 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1176 #if defined(SHAREWARE)
1177 strcpy(exit_screen, "orderd2.pcx");
1179 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1183 if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
1184 //vfx_set_palette_sub( title_pal );
1185 gr_palette_fade_in( title_pal, 32, 0 );
1187 gr_palette_fade_out( title_pal, 32, 0 );
1190 Int3(); //can't load order screen
1200 // void network_abort_game();
1201 // if(Network_status)
1202 // network_abort_game();