1 /* $Id: inferno.c,v 1.100 2005-02-26 09:30:04 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>
49 #include "pa_enabl.h" //$$POLY_ACC
61 #include "segment.h" //for Side_to_verts
101 // # include "3dfx_des.h"
103 //added on 9/30/98 by Matt Mueller for selectable automap modes
107 #include "../texmap/scanline.h" //for select_tmap -MM
109 #if defined(POLY_ACC)
110 #include "poly_acc.h"
111 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
115 #include "editor/editor.h"
116 #include "editor/kdefs.h"
127 void arch_init(void);
128 void arch_init_start(void);
130 //Current version number
132 ubyte Version_major = 1; //FULL VERSION
133 ubyte Version_minor = 2;
135 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
136 char desc_id_exit_num = 0;
138 int Function_mode=FMODE_MENU; //game or editor?
139 int Screen_mode=-1; //game screen or editor screen?
141 //--unused-- grs_bitmap Inferno_bitmap_title;
143 int WVIDEO_running=0; //debugger can set to 1 if running
145 //--unused-- int Cyberman_installed=0; // SWIFT device present
146 ubyte CybermouseActive=0;
149 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
152 void check_joystick_calibration(void);
154 void show_order_form(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;
177 //read help from a file & print to screen
178 void print_commandline_help()
184 ifile = cfopen("help.tex","rb");
186 ifile = cfopen("help.txb","rb");
188 Warning("Cannot load help text file.");
196 while ((end = cfgets(line,LINE_LEN,ifile))) {
198 // This is the only use of cfgets that needs the CR
201 decode_text_line (line);
204 continue; //don't show comments
214 // printf( " Diagnostic:\n\n");
215 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
216 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
219 printf( " Editor Options:\n\n");
220 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
221 printf( " -hoarddata %s\n","Make the hoard ham file from some files, then exit");
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 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
229 printf(" -renderstats %s\n", "Enable renderstats info by default");
231 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
232 printf( " -notitles %s\n", "Do not show titlescreens on startup");
233 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
235 printf( " -nohogdir %s\n", "don't try to use shared data directory");
236 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
238 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
239 printf( " -autodemo %s\n", "Start in demo mode");
240 printf( " -bigpig %s\n","FIXME: Undocumented");
241 printf( " -bspgen %s\n","FIXME: Undocumented");
242 // printf( " -cdproxy %s\n","FIXME: Undocumented");
244 printf( " -checktime %s\n","FIXME: Undocumented");
245 printf( " -showmeminfo %s\n","FIXME: Undocumented");
247 // printf( " -codereadonly %s\n","FIXME: Undocumented");
248 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
249 printf( " -debug %s\n","Enable very verbose output");
250 // printf( " -debugmode %s\n","FIXME: Undocumented");
251 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
252 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
253 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
254 // printf( " -forcegfx %s\n","FIXME: Undocumented");
256 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
258 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
260 printf( " -invulnerability %s\n","Make yourself invulnerable");
262 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
263 printf( " -jasen %s\n","FIXME: Undocumented");
264 printf( " -joyslow %s\n","FIXME: Undocumented");
266 printf( " -kali %s\n","use Kali for networking");
268 // printf( " -logfile %s\n","FIXME: Undocumented");
269 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
270 #if defined(EDITOR) || !defined(MACDATA)
271 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
273 // printf( " -memdbg %s\n","FIXME: Undocumented");
274 // printf( " -monodebug %s\n","FIXME: Undocumented");
275 printf( " -nocdrom %s\n","FIXME: Undocumented");
277 printf( " -nocyberman %s\n","FIXME: Undocumented");
280 printf( " -nofade %s\n","Disable fades");
283 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
284 printf( " -norankings %s\n","Disable multiplayer ranking system");
285 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
286 // printf( " -showaddress %s\n","FIXME: Undocumented");
287 printf( " -socket %s\n","FIXME: Undocumented");
289 #if !defined(MACINTOSH) && !defined(WINDOWS)
290 printf( " -nomixer %s\n","Don't crank music volume");
291 // printf( " -superhires %s\n","Allow higher-resolution modes");
293 // printf( " -nomodex %s\n","FIXME: Undocumented");
295 printf( " -nomovies %s\n","Don't play movies");
296 printf( " -noscreens %s\n","Skip briefing screens");
298 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
299 printf( " -noredbook %s\n","Disable redbook audio");
301 printf( " -norun %s\n","Bail out after initialization");
302 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
303 // printf( " -rtscts %s\n","Same as -ctsrts");
304 // printf( " -semiwin %s\n","Use non-fullscreen mode");
305 // printf( " -specialdevice %s\n","FIXME: Undocumented");
307 printf( " -stickmag %s\n","FIXME: Undocumented");
309 // printf( " -stopwatch %s\n","FIXME: Undocumented");
310 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
311 // printf( " -sysram %s\n","FIXME: Undocumented");
312 printf( " -text <file> %s\n","Specify alternate .tex file");
313 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
314 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
315 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
316 // printf( " -vidram %s\n","FIXME: Undocumented");
317 printf( " -xcontrol %s\n","FIXME: Undocumented");
318 printf( " -xname %s\n","FIXME: Undocumented");
319 printf( " -xver %s\n","FIXME: Undocumented");
320 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
322 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
323 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
325 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
327 printf(" -niceautomap %s\n", "Free cpu while doing automap");
328 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
329 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
330 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
331 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
332 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
335 printf( "D2X System Options:\n\n");
337 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
338 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
340 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
341 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
344 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
345 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
346 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
347 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
348 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
349 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
350 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
351 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
352 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
353 printf( " -gl_voodoo %s\n","force fullscreen mode only");
355 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
356 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
357 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
358 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
359 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
360 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
361 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
362 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
363 printf( " -gl_test2 %s\n","FIXME: Undocumented");
364 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
365 #ifdef OGL_RUNTIME_LOAD
366 printf( " -gl_library <l> %s\n","use alternate opengl library");
369 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
373 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
374 printf( " -hwsurface %s\n","FIXME: Undocumented");
377 printf(" -udp %s\n", "Specify options for udp/ip:");
378 printf(" @<shift> %s\n", " shift udp port base offset");
379 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
380 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
381 printf(" %s\n", " HOSTS can be any IP or hostname")
383 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
384 printf(" %s\n", " separate multiple HOSTS with a ,");
387 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
388 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
390 printf( "\n Help:\n\n");
391 printf( " -help, -h, -?, ? %s\n", "View this help screen");
395 void do_joystick_init()
398 if (!FindArg( "-nojoystick" )) {
399 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
401 if ( FindArg( "-joyslow" )) {
402 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
403 joy_set_slow_reading(JOY_SLOW_READINGS);
405 if ( FindArg( "-joypolled" )) {
406 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
407 joy_set_slow_reading(JOY_POLLED_READINGS);
409 if ( FindArg( "-joybios" )) {
410 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
411 joy_set_slow_reading(JOY_BIOS_READINGS);
414 // Added from Descent v1.5 by John. Adapted by Samir.
416 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
420 //set this to force game to run in low res
421 int disable_high_res=0;
423 void do_register_player(ubyte *title_pal)
425 Players[Player_num].callsign[0] = '\0';
431 //now, before we bring up the register player menu, we need to
432 //do some stuff to make sure the palette is ok. First, we need to
433 //get our current palette into the 2d's array, so the remapping will
434 //work. Second, we need to remap the fonts. Third, we need to fill
435 //in part of the fade tables so the darkening of the menu edges works
437 memcpy(gr_palette,title_pal,sizeof(gr_palette));
438 remap_fonts_and_menus(1);
439 RegisterPlayer(); //get player's name
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 #if defined(POLY_ACC)
462 #define MENU_HIRES_MODE SM_640x480x15xPA
464 #define MENU_HIRES_MODE SM(640,480)
467 // DESCENT II by Parallax Software
470 //extern ubyte gr_current_pal[];
474 char Auto_file[128] = "";
477 int main(int argc, char *argv[])
480 ubyte title_pal[768];
482 PHYSFS_init(argv[0]);
483 PHYSFS_permitSymbolicLinks(1);
485 con_init(); // Initialise the console
488 error_init(NULL, NULL);
490 PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
491 InitArgs( argc,argv );
493 if ((t = FindArg("-userdir"))
495 || 1 // or if it's a unix platform
499 // This stuff below seems overly complicated - brad
501 char *path = Args[t+1];
502 char fullPath[PATH_MAX + 5];
508 PHYSFS_removeFromSearchPath(PHYSFS_getBaseDir());
510 if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
512 const char *home = PHYSFS_getUserDir();
514 strcpy(fullPath, home); // prepend home to the path
516 if (*path == *PHYSFS_getDirSeparator())
518 strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
521 strncpy(fullPath, path, PATH_MAX + 5);
523 PHYSFS_setWriteDir(fullPath);
524 if (!PHYSFS_getWriteDir()) // need to make it
526 PHYSFS_mkdir(fullPath);
527 PHYSFS_setWriteDir(fullPath);
530 PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1);
534 if (!PHYSFS_getWriteDir())
536 PHYSFS_setWriteDir(PHYSFS_getBaseDir());
537 if (!PHYSFS_getWriteDir())
538 Error("can't set write dir\n");
540 PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 0);
543 if (FindArg("-debug"))
544 con_threshold.value = (float)2;
545 else if (FindArg("-verbose"))
546 con_threshold.value = (float)1;
548 //tell cfile where hogdir is
549 if ((t=FindArg("-hogdir")))
550 PHYSFS_addToSearchPath(Args[t + 1], 1);
552 else if (!FindArg("-nohogdir"))
553 PHYSFS_addToSearchPath(SHAREPATH, 1);
556 if (! cfile_init("descent2.hog"))
557 if (! cfile_init("d2demo.hog"))
558 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
563 "\tCurrent directory\n"
565 "Or use the -hogdir option to specify an alternate location.");
568 //print out the banner title
569 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
571 con_printf(CON_NORMAL, " %s", VERSION_NAME);
573 if (cfexist(MISSION_DIR "d2x.hog"))
574 con_printf(CON_NORMAL, " Vertigo Enhanced");
576 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
577 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
578 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
579 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
582 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
583 print_commandline_help();
584 set_exit_message("");
586 exit(0); /* mingw hangs on this return. dunno why */
591 con_printf(CON_NORMAL, "\n");
592 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
593 con_printf(CON_NORMAL, "\n");
598 for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
599 con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
601 list = PHYSFS_getCdRomDirs();
602 for (i = list; *i != NULL; i++)
603 con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
604 PHYSFS_freeList(list);
606 list = PHYSFS_enumerateFiles("");
607 for (i = list; *i != NULL; i++)
608 con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
609 PHYSFS_freeList(list);
612 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
613 if(FindArg("-sound22k"))
615 digi_sample_rate = SAMPLE_RATE_22K;
618 if(FindArg("-sound11k"))
620 digi_sample_rate = SAMPLE_RATE_11K;
627 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
629 if ((t = FindArg("-rearviewtime")))
631 float f = atof(Args[t + 1]);
632 Rear_view_leave_time = f * f1_0;
634 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
636 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
637 if ((t = FindArg( "-maxfps" ))) {
642 //end addition - Victor Rachels
644 #ifdef SUPPORTS_NICEFPS
645 if (FindArg("-nicefps"))
647 if (FindArg("-niceautomap"))
651 if (FindArg("-renderstats"))
654 if ( FindArg( "-autodemo" ))
658 if ( FindArg( "-noscreens" ) )
659 Skip_briefing_screens = 1;
662 if ((t=FindArg("-tmap"))){
663 select_tmap(Args[t+1]);
669 // if (init_graphics()) return 1;
672 if (gr_check_mode(SM(800, 600)) != 0)
674 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
675 Function_mode = FMODE_MENU;
680 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
682 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
687 #if defined(POLY_ACC)
688 Current_display_mode = -1;
689 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
692 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
693 set_display_mode(0); //..then set default display mode
697 int screen_width = 640;
698 int screen_height = 480;
699 int vr_mode = VR_NONE;
700 int screen_flags = VRF_USE_PAGING;
702 if (FindResArg("", &screen_width, &screen_height))
704 /* stuff below mirrors values from display_mode_info in
705 * menu.c which is used by set_display_mode. In fact,
706 * set_display_mode should probably be rewritten to allow
707 * arbitrary resolutions, and then we get rid of this
710 switch (SM(screen_width, screen_height))
714 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
717 screen_flags = VRF_USE_PAGING;
723 screen_flags = VRF_COMPATIBLE_MENUS;
727 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
730 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
732 if (FindArg("-nodoublebuffer"))
736 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
737 screen_flags &= ~VRF_USE_PAGING;
740 // added 3/24/99 by Owen Evans for screen res changing
741 Game_screen_mode = SM(screen_width, screen_height);
743 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
747 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
748 int i, argnum = INT_MAX, w, h;
749 // 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.
750 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
751 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
752 #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) );
753 // aren't #defines great? :)
754 // end addition/edit -MM
755 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
757 S_MODE(automap,automap_mode,automap_use_game_res);
758 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
762 i = FindArg( "-xcontrol" );
764 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
767 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
768 if (FindArg("-nofade"))
769 grd_fades_disabled=1;
771 //determine whether we're using high-res menus & movies
772 #if !defined(POLY_ACC)
773 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
774 MovieHires = MenuHires = MenuHiresAvailable = 0;
777 //NOTE LINK TO ABOVE!
778 MenuHires = MenuHiresAvailable = 1;
780 if (FindArg( "-lowresmovies" ))
783 if ((t=gr_init())!=0) //doesn't do much
784 Error(TXT_CANT_INIT_GFX,t);
790 // Load the palette stuff. Returns non-zero if error.
791 con_printf(CON_DEBUG, "Initializing palette system...\n" );
792 gr_use_palette_table(DEFAULT_PALETTE );
794 con_printf(CON_DEBUG, "Initializing font system...\n" );
795 gamefont_init(); // must load after palette data loaded.
797 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
798 init_movies(); //init movie libraries
801 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
802 #if defined(POLY_ACC)
803 gr_set_mode(SM_640x480x15xPA);
805 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
809 if ( FindArg( "-notitles" ) )
810 songs_play_song( SONG_TITLE, 1);
814 int played=MOVIE_NOT_PLAYED; //default is not played
816 int song_playing = 0;
819 #define MOVIE_REQUIRED 0
821 #define MOVIE_REQUIRED 1
824 { //show bundler screens
825 char filename[FILENAME_LEN];
827 played=MOVIE_NOT_PLAYED; //default is not played
829 played = PlayMovie("pre_i.mve",0);
832 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
834 while (PHYSFS_exists(filename))
836 show_title_screen( filename, 1, 0 );
843 init_subtitles("intro.tex");
844 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
848 if (played != MOVIE_NOT_PLAYED)
850 else { //didn't get intro movie, try titles
852 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
854 if (played == MOVIE_NOT_PLAYED)
856 char filename[FILENAME_LEN];
858 #if defined(POLY_ACC)
859 gr_set_mode(SM_640x480x15xPA);
861 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
864 set_screen_mode(SCREEN_MENU);
866 con_printf( CON_DEBUG, "\nPlaying title song..." );
867 songs_play_song( SONG_TITLE, 1);
869 con_printf( CON_DEBUG, "\nShowing logo screens..." );
871 strcpy(filename, MenuHires?"iplogo1b.pcx":"iplogo1.pcx"); // OEM
872 if (! cfexist(filename))
873 strcpy(filename, "iplogo1.pcx"); // SHAREWARE
874 if (! cfexist(filename))
875 strcpy(filename, "mplogo.pcx"); // MAC SHAREWARE
876 if (cfexist(filename))
877 show_title_screen(filename, 1, 1);
879 strcpy(filename, MenuHires?"logob.pcx":"logo.pcx"); // OEM
880 if (! cfexist(filename))
881 strcpy(filename, "logo.pcx"); // SHAREWARE
882 if (! cfexist(filename))
883 strcpy(filename, "plogo.pcx"); // MAC SHAREWARE
884 if (cfexist(filename))
885 show_title_screen(filename, 1, 1);
889 { //show bundler movie or screens
891 char filename[FILENAME_LEN];
892 PHYSFS_file *movie_handle;
894 played=MOVIE_NOT_PLAYED; //default is not played
896 //check if OEM movie exists, so we don't stop the music if it doesn't
897 movie_handle = PHYSFS_openRead("oem.mve");
900 PHYSFS_close(movie_handle);
901 played = PlayMovie("oem.mve",0);
902 song_playing = 0; //movie will kill sound
906 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
908 while (PHYSFS_exists(filename))
910 show_title_screen( filename, 1, 0 );
917 songs_play_song( SONG_TITLE, 1);
921 PA_DFX (pa_splash());
923 con_printf( CON_DEBUG, "\nShowing loading screen..." );
925 //grs_bitmap title_bm;
929 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
930 if (! cfexist(filename))
931 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
932 if (! cfexist(filename))
933 strcpy(filename, "descentd.pcx"); // SHAREWARE
934 if (! cfexist(filename))
935 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
937 #if defined(POLY_ACC)
938 gr_set_mode(SM_640x480x15xPA);
940 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
943 set_screen_mode(SCREEN_MENU);
946 FontHires = FontHiresAvailable && MenuHires;
948 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
949 //vfx_set_palette_sub( title_pal );
951 gr_palette_fade_in( title_pal, 32, 0 );
954 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
957 con_printf( CON_DEBUG , "\nDoing bm_init..." );
959 if (!bm_init_use_tbl())
964 if (FindArg("-hoarddata") != 0) {
965 #define MAX_BITMAPS_PER_BRUSH 30
966 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
969 ubyte palette[256*3];
972 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
973 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
974 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
975 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
977 ofile = PHYSFSX_openWriteBuffered("hoard.ham");
979 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
980 Assert(iff_error == IFF_NO_ERROR);
981 PHYSFS_writeULE16(ofile, nframes);
982 PHYSFS_writeULE16(ofile, bm[0]->bm_w);
983 PHYSFS_writeULE16(ofile, bm[0]->bm_h);
984 PHYSFS_write(ofile, palette, 3, 256);
985 for (i=0;i<nframes;i++)
986 PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
988 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
989 Assert(iff_error == IFF_NO_ERROR);
990 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
991 PHYSFS_writeULE16(ofile, nframes);
992 PHYSFS_write(ofile, palette, 3, 256);
993 for (i=0;i<nframes;i++)
994 PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
997 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
998 Assert(iff_error == IFF_NO_ERROR);
999 PHYSFS_writeULE16(ofile, icon.bm_w);
1000 PHYSFS_writeULE16(ofile, icon.bm_h);
1001 PHYSFS_write(ofile, palette, 3, 256);
1002 PHYSFS_write(ofile, icon.bm_data, icon.bm_w*icon.bm_h, 1);
1005 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
1010 ifile = PHYSFS_openRead(sounds[i]);
1011 Assert(ifile != NULL);
1012 size = PHYSFS_fileLength(ifile);
1013 buf = d_malloc(size);
1014 PHYSFS_read(ifile, buf, size, 1);
1015 PHYSFS_writeULE32(ofile, size);
1016 PHYSFS_write(ofile, buf, size, 1);
1018 PHYSFS_close(ifile);
1021 PHYSFS_close(ofile);
1027 //the bitmap loading code changes gr_palette, so restore it
1028 memcpy(gr_palette,title_pal,sizeof(gr_palette));
1030 if ( FindArg( "-norun" ) )
1033 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
1036 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
1037 texmerge_init( 10 ); // 10 cache bitmaps
1039 con_printf( CON_DEBUG, "\nRunning game...\n" );
1040 set_screen_mode(SCREEN_MENU);
1044 // If built with editor, option to auto-load a level and quit game
1045 // to write certain data.
1048 if ( (t = FindArg( "-autoload" )) ) {
1050 strcpy(Auto_file, Args[t+1]);
1056 strcpy(Players[0].callsign, "dummy");
1059 do_register_player(title_pal);
1061 gr_palette_fade_out( title_pal, 32, 0 );
1063 Game_mode = GM_GAME_OVER;
1066 newdemo_start_playback("descent.dem");
1067 if (Newdemo_state == ND_STATE_PLAYBACK )
1068 Function_mode = FMODE_GAME;
1071 //do this here because the demo code can do a longjmp when trying to
1072 //autostart a demo from the main menu, never having gone into the game
1075 while (Function_mode != FMODE_EXIT)
1077 switch( Function_mode ) {
1079 set_screen_mode(SCREEN_MENU);
1081 newdemo_start_playback(NULL); // Randomly pick a file
1082 if (Newdemo_state != ND_STATE_PLAYBACK)
1083 Error("No demo files were found for autodemo mode!");
1087 strcpy((char *)&Level_names[0], Auto_file);
1089 Function_mode = FMODE_EXIT;
1094 check_joystick_calibration();
1095 gr_palette_clear(); //I'm not sure why we need this, but we do
1098 if ( Function_mode == FMODE_EDITOR ) {
1100 SetPlayerFromCurseg();
1101 load_palette(NULL,1,0);
1108 keyd_editor_mode = 0;
1112 /* keep the mouse from wandering in SDL */
1113 if (FindArg("-grabmouse"))
1114 SDL_WM_GrabInput(SDL_GRAB_ON);
1120 /* give control back to the WM */
1121 if (FindArg("-grabmouse"))
1122 SDL_WM_GrabInput(SDL_GRAB_OFF);
1125 if ( Function_mode == FMODE_MENU )
1126 songs_play_song( SONG_TITLE, 1 );
1130 keyd_editor_mode = 1;
1133 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1135 if ( Function_mode == FMODE_GAME ) {
1136 Game_mode = GM_EDITOR;
1137 editor_reset_stuff_on_level();
1143 Error("Invalid function mode %d",Function_mode);
1149 if (!FindArg( "-notitles" ))
1153 if ( FindArg( "-showmeminfo" ) )
1154 show_mem_info = 1; // Make memory statistics show
1157 return(0); //presumably successful exit
1161 void check_joystick_calibration() {
1162 int x1, y1, x2, y2, c;
1165 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1166 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1167 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1168 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1171 joy_get_pos( &x1, &y1 );
1173 t1 = timer_get_fixed_seconds();
1174 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1177 joy_get_pos( &x2, &y2 );
1179 // If joystick hasn't moved...
1180 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1181 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1182 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1184 joydefs_calibrate();
1191 void show_order_form()
1196 unsigned char title_pal[768];
1197 char exit_screen[16];
1199 gr_set_current_canvas( NULL );
1204 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1205 if (! cfexist(exit_screen))
1206 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1207 if (! cfexist(exit_screen))
1208 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1209 if (! cfexist(exit_screen))
1210 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1211 if (! cfexist(exit_screen))
1212 return; // D2 registered
1214 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1215 //vfx_set_palette_sub( title_pal );
1216 gr_palette_fade_in( title_pal, 32, 0 );
1218 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1219 gr_palette_fade_out( title_pal, 32, 0 );
1222 Int3(); //can't load order screen
1232 // void network_abort_game();
1233 // if(Network_status)
1234 // network_abort_game();