1 /* $Id: inferno.c,v 1.98 2005-02-25 07:19:33 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.
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
146 int Inferno_is_800x600_available = 0;
149 //--unused-- int Cyberman_installed=0; // SWIFT device present
150 ubyte CybermouseActive=0;
153 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
156 void check_joystick_calibration(void);
158 void show_order_form(void);
160 //--------------------------------------------------------------------------
162 extern int piggy_low_memory;
165 int descent_critical_error = 0;
166 unsigned descent_critical_deverror = 0;
167 unsigned descent_critical_errcode = 0;
169 extern int Network_allow_socket_changes;
171 extern void vfx_set_palette_sub(ubyte *);
173 extern int VR_low_res;
175 extern int Config_vr_type;
176 extern int Config_vr_resolution;
177 extern int Config_vr_tracking;
181 //read help from a file & print to screen
182 void print_commandline_help()
188 ifile = cfopen("help.tex","rb");
190 ifile = cfopen("help.txb","rb");
192 Warning("Cannot load help text file.");
200 while ((end = cfgets(line,LINE_LEN,ifile))) {
202 // This is the only use of cfgets that needs the CR
205 decode_text_line (line);
208 continue; //don't show comments
218 // printf( " Diagnostic:\n\n");
219 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
220 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
223 printf( " Editor Options:\n\n");
224 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
225 printf( " -hoarddata %s\n","Make the hoard ham file from some files, then exit");
226 // printf( " -nobm %s\n","FIXME: Undocumented");
229 printf( " D2X Options:\n\n");
230 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
231 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
232 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
233 printf(" -renderstats %s\n", "Enable renderstats info by default");
235 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
236 printf( " -notitles %s\n", "Do not show titlescreens on startup");
237 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
239 printf( " -nohogdir %s\n", "don't try to use shared data directory");
240 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
242 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
243 printf( " -autodemo %s\n", "Start in demo mode");
244 printf( " -bigpig %s\n","FIXME: Undocumented");
245 printf( " -bspgen %s\n","FIXME: Undocumented");
246 // printf( " -cdproxy %s\n","FIXME: Undocumented");
248 printf( " -checktime %s\n","FIXME: Undocumented");
249 printf( " -showmeminfo %s\n","FIXME: Undocumented");
251 // printf( " -codereadonly %s\n","FIXME: Undocumented");
252 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
253 printf( " -debug %s\n","Enable very verbose output");
254 // printf( " -debugmode %s\n","FIXME: Undocumented");
255 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
256 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
257 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
258 // printf( " -forcegfx %s\n","FIXME: Undocumented");
260 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
262 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
264 printf( " -invulnerability %s\n","Make yourself invulnerable");
266 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
267 printf( " -jasen %s\n","FIXME: Undocumented");
268 printf( " -joyslow %s\n","FIXME: Undocumented");
270 printf( " -kali %s\n","use Kali for networking");
272 // printf( " -logfile %s\n","FIXME: Undocumented");
273 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
274 #if defined(EDITOR) || !defined(MACDATA)
275 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
277 // printf( " -memdbg %s\n","FIXME: Undocumented");
278 // printf( " -monodebug %s\n","FIXME: Undocumented");
279 printf( " -nocdrom %s\n","FIXME: Undocumented");
281 printf( " -nocyberman %s\n","FIXME: Undocumented");
284 printf( " -nofade %s\n","Disable fades");
287 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
288 printf( " -norankings %s\n","Disable multiplayer ranking system");
289 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
290 // printf( " -showaddress %s\n","FIXME: Undocumented");
291 printf( " -socket %s\n","FIXME: Undocumented");
293 #if !defined(MACINTOSH) && !defined(WINDOWS)
294 printf( " -nomixer %s\n","Don't crank music volume");
295 // printf( " -superhires %s\n","Allow higher-resolution modes");
297 // printf( " -nomodex %s\n","FIXME: Undocumented");
299 printf( " -nomovies %s\n","Don't play movies");
300 printf( " -noscreens %s\n","Skip briefing screens");
302 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
303 printf( " -noredbook %s\n","Disable redbook audio");
305 printf( " -norun %s\n","Bail out after initialization");
306 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
307 // printf( " -rtscts %s\n","Same as -ctsrts");
308 // printf( " -semiwin %s\n","Use non-fullscreen mode");
309 // printf( " -specialdevice %s\n","FIXME: Undocumented");
311 printf( " -stickmag %s\n","FIXME: Undocumented");
313 // printf( " -stopwatch %s\n","FIXME: Undocumented");
314 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
315 // printf( " -sysram %s\n","FIXME: Undocumented");
316 printf( " -text <file> %s\n","Specify alternate .tex file");
317 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
318 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
319 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
320 // printf( " -vidram %s\n","FIXME: Undocumented");
321 printf( " -xcontrol %s\n","FIXME: Undocumented");
322 printf( " -xname %s\n","FIXME: Undocumented");
323 printf( " -xver %s\n","FIXME: Undocumented");
324 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
326 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
327 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
329 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
331 printf(" -niceautomap %s\n", "Free cpu while doing automap");
332 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
333 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
334 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
335 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
336 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
339 printf( "D2X System Options:\n\n");
341 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
342 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
344 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
345 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
348 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
349 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
350 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
351 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
352 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
353 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
354 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
355 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
356 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
357 printf( " -gl_voodoo %s\n","force fullscreen mode only");
359 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
360 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
361 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
362 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
363 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
364 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
365 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
366 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
367 printf( " -gl_test2 %s\n","FIXME: Undocumented");
368 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
369 #ifdef OGL_RUNTIME_LOAD
370 printf( " -gl_library <l> %s\n","use alternate opengl library");
373 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
377 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
378 printf( " -hwsurface %s\n","FIXME: Undocumented");
381 printf(" -udp %s\n", "Specify options for udp/ip:");
382 printf(" @<shift> %s\n", " shift udp port base offset");
383 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
384 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
385 printf(" %s\n", " HOSTS can be any IP or hostname")
387 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
388 printf(" %s\n", " separate multiple HOSTS with a ,");
391 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
392 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
394 printf( "\n Help:\n\n");
395 printf( " -help, -h, -?, ? %s\n", "View this help screen");
399 void do_joystick_init()
402 if (!FindArg( "-nojoystick" )) {
403 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
405 if ( FindArg( "-joyslow" )) {
406 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
407 joy_set_slow_reading(JOY_SLOW_READINGS);
409 if ( FindArg( "-joypolled" )) {
410 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
411 joy_set_slow_reading(JOY_POLLED_READINGS);
413 if ( FindArg( "-joybios" )) {
414 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
415 joy_set_slow_reading(JOY_BIOS_READINGS);
418 // Added from Descent v1.5 by John. Adapted by Samir.
420 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
424 //set this to force game to run in low res
425 int disable_high_res=0;
427 void do_register_player(ubyte *title_pal)
429 Players[Player_num].callsign[0] = '\0';
435 //now, before we bring up the register player menu, we need to
436 //do some stuff to make sure the palette is ok. First, we need to
437 //get our current palette into the 2d's array, so the remapping will
438 //work. Second, we need to remap the fonts. Third, we need to fill
439 //in part of the fade tables so the darkening of the menu edges works
441 memcpy(gr_palette,title_pal,sizeof(gr_palette));
442 remap_fonts_and_menus(1);
443 RegisterPlayer(); //get player's name
448 #define PROGNAME argv[0]
450 extern char Language[];
452 //can we do highres menus?
453 extern int MenuHiresAvailable;
455 int intro_played = 0;
457 int Inferno_verbose = 0;
459 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
460 int start_net_immediately = 0;
461 //int start_with_mission = 0;
462 //char *start_with_mission_name;
463 //end this section addition
465 #if defined(POLY_ACC)
466 #define MENU_HIRES_MODE SM_640x480x15xPA
468 #define MENU_HIRES_MODE SM(640,480)
471 // DESCENT II by Parallax Software
474 //extern ubyte gr_current_pal[];
478 char Auto_file[128] = "";
481 int main(int argc, char *argv[])
484 ubyte title_pal[768];
486 PHYSFS_init(argv[0]);
487 PHYSFS_permitSymbolicLinks(1);
489 con_init(); // Initialise the console
492 error_init(NULL, NULL);
494 PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
495 InitArgs( argc,argv );
497 if ((t = FindArg("-userdir"))
499 || 1 // or if it's a unix platform
503 // This stuff below seems overly complicated - brad
505 char *path = Args[t+1];
506 char fullPath[PATH_MAX + 5];
512 PHYSFS_removeFromSearchPath(PHYSFS_getBaseDir());
514 if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
516 const char *home = PHYSFS_getUserDir();
518 strcpy(fullPath, home); // prepend home to the path
520 if (*path == *PHYSFS_getDirSeparator())
522 strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
525 strncpy(fullPath, path, PATH_MAX + 5);
527 PHYSFS_setWriteDir(fullPath);
528 if (!PHYSFS_getWriteDir()) // need to make it
530 PHYSFS_mkdir(fullPath);
531 PHYSFS_setWriteDir(fullPath);
534 PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1);
538 if (!PHYSFS_getWriteDir())
540 PHYSFS_setWriteDir(PHYSFS_getBaseDir());
541 if (!PHYSFS_getWriteDir())
542 Error("can't set write dir\n");
544 PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 0);
547 if (FindArg("-debug"))
548 con_threshold.value = (float)2;
549 else if (FindArg("-verbose"))
550 con_threshold.value = (float)1;
552 //tell cfile where hogdir is
553 if ((t=FindArg("-hogdir")))
554 PHYSFS_addToSearchPath(Args[t + 1], 1);
556 else if (!FindArg("-nohogdir"))
557 PHYSFS_addToSearchPath(SHAREPATH, 1);
560 if (! cfile_init("descent2.hog"))
561 if (! cfile_init("d2demo.hog"))
562 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
567 "\tCurrent directory\n"
569 "Or use the -hogdir option to specify an alternate location.");
572 //print out the banner title
573 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
575 con_printf(CON_NORMAL, " %s", VERSION_NAME);
577 if (cfexist(MISSION_DIR "d2x.hog"))
578 con_printf(CON_NORMAL, " Vertigo Enhanced");
580 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
581 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
582 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
583 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
586 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
587 print_commandline_help();
588 set_exit_message("");
590 exit(0); /* mingw hangs on this return. dunno why */
595 con_printf(CON_NORMAL, "\n");
596 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
597 con_printf(CON_NORMAL, "\n");
602 for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
603 con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
605 list = PHYSFS_getCdRomDirs();
606 for (i = list; *i != NULL; i++)
607 con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
608 PHYSFS_freeList(list);
610 list = PHYSFS_enumerateFiles("");
611 for (i = list; *i != NULL; i++)
612 con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
613 PHYSFS_freeList(list);
616 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
617 if(FindArg("-sound22k"))
619 digi_sample_rate = SAMPLE_RATE_22K;
622 if(FindArg("-sound11k"))
624 digi_sample_rate = SAMPLE_RATE_11K;
631 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
633 if ((t = FindArg("-rearviewtime")))
635 float f = atof(Args[t + 1]);
636 Rear_view_leave_time = f * f1_0;
638 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
640 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
641 if ((t = FindArg( "-maxfps" ))) {
646 //end addition - Victor Rachels
648 #ifdef SUPPORTS_NICEFPS
649 if (FindArg("-nicefps"))
651 if (FindArg("-niceautomap"))
655 if (FindArg("-renderstats"))
658 if ( FindArg( "-autodemo" ))
662 if ( FindArg( "-noscreens" ) )
663 Skip_briefing_screens = 1;
666 if ((t=FindArg("-tmap"))){
667 select_tmap(Args[t+1]);
673 // if (init_graphics()) return 1;
676 if (!Inferno_is_800x600_available) {
677 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
678 Function_mode = FMODE_MENU;
683 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
685 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
690 #if defined(POLY_ACC)
691 Current_display_mode = -1;
692 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
695 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
696 set_display_mode(0); //..then set default display mode
700 int screen_width = 640;
701 int screen_height = 480;
702 int vr_mode = VR_NONE;
703 int screen_flags = VRF_USE_PAGING;
705 if (FindResArg("", &screen_width, &screen_height))
707 /* stuff below mirrors values from display_mode_info in
708 * menu.c which is used by set_display_mode. In fact,
709 * set_display_mode should probably be rewritten to allow
710 * arbitrary resolutions, and then we get rid of this
713 switch (SM(screen_width, screen_height))
717 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
720 screen_flags = VRF_USE_PAGING;
726 screen_flags = VRF_COMPATIBLE_MENUS;
730 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
733 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
735 if (FindArg("-nodoublebuffer"))
739 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
740 screen_flags &= ~VRF_USE_PAGING;
743 // added 3/24/99 by Owen Evans for screen res changing
744 Game_screen_mode = SM(screen_width, screen_height);
746 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
750 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
751 int i, argnum = INT_MAX, w, h;
752 // 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.
753 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
754 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
755 #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) );
756 // aren't #defines great? :)
757 // end addition/edit -MM
758 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
760 S_MODE(automap,automap_mode,automap_use_game_res);
761 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
765 i = FindArg( "-xcontrol" );
767 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
770 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
771 if (FindArg("-nofade"))
772 grd_fades_disabled=1;
774 //determine whether we're using high-res menus & movies
775 #if !defined(POLY_ACC)
776 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
777 MovieHires = MenuHires = MenuHiresAvailable = 0;
780 //NOTE LINK TO ABOVE!
781 MenuHires = MenuHiresAvailable = 1;
783 if (FindArg( "-lowresmovies" ))
786 if ((t=gr_init())!=0) //doesn't do much
787 Error(TXT_CANT_INIT_GFX,t);
793 // Load the palette stuff. Returns non-zero if error.
794 con_printf(CON_DEBUG, "Initializing palette system...\n" );
795 gr_use_palette_table(DEFAULT_PALETTE );
797 con_printf(CON_DEBUG, "Initializing font system...\n" );
798 gamefont_init(); // must load after palette data loaded.
800 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
801 init_movies(); //init movie libraries
804 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
805 #if defined(POLY_ACC)
806 gr_set_mode(SM_640x480x15xPA);
808 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
812 if ( FindArg( "-notitles" ) )
813 songs_play_song( SONG_TITLE, 1);
817 int played=MOVIE_NOT_PLAYED; //default is not played
819 int song_playing = 0;
822 #define MOVIE_REQUIRED 0
824 #define MOVIE_REQUIRED 1
827 { //show bundler screens
828 char filename[FILENAME_LEN];
830 played=MOVIE_NOT_PLAYED; //default is not played
832 played = PlayMovie("pre_i.mve",0);
835 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
837 while (PHYSFS_exists(filename))
839 show_title_screen( filename, 1, 0 );
846 init_subtitles("intro.tex");
847 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
851 if (played != MOVIE_NOT_PLAYED)
853 else { //didn't get intro movie, try titles
855 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
857 if (played == MOVIE_NOT_PLAYED)
859 char filename[FILENAME_LEN];
861 #if defined(POLY_ACC)
862 gr_set_mode(SM_640x480x15xPA);
864 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
867 set_screen_mode(SCREEN_MENU);
869 con_printf( CON_DEBUG, "\nPlaying title song..." );
870 songs_play_song( SONG_TITLE, 1);
872 con_printf( CON_DEBUG, "\nShowing logo screens..." );
874 strcpy(filename, MenuHires?"iplogo1b.pcx":"iplogo1.pcx"); // OEM
875 if (! cfexist(filename))
876 strcpy(filename, "iplogo1.pcx"); // SHAREWARE
877 if (! cfexist(filename))
878 strcpy(filename, "mplogo.pcx"); // MAC SHAREWARE
879 if (cfexist(filename))
880 show_title_screen(filename, 1, 1);
882 strcpy(filename, MenuHires?"logob.pcx":"logo.pcx"); // OEM
883 if (! cfexist(filename))
884 strcpy(filename, "logo.pcx"); // SHAREWARE
885 if (! cfexist(filename))
886 strcpy(filename, "plogo.pcx"); // MAC SHAREWARE
887 if (cfexist(filename))
888 show_title_screen(filename, 1, 1);
892 { //show bundler movie or screens
894 char filename[FILENAME_LEN];
895 PHYSFS_file *movie_handle;
897 played=MOVIE_NOT_PLAYED; //default is not played
899 //check if OEM movie exists, so we don't stop the music if it doesn't
900 movie_handle = PHYSFS_openRead("oem.mve");
903 PHYSFS_close(movie_handle);
904 played = PlayMovie("oem.mve",0);
905 song_playing = 0; //movie will kill sound
909 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
911 while (PHYSFS_exists(filename))
913 show_title_screen( filename, 1, 0 );
920 songs_play_song( SONG_TITLE, 1);
924 PA_DFX (pa_splash());
926 con_printf( CON_DEBUG, "\nShowing loading screen..." );
928 //grs_bitmap title_bm;
932 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
933 if (! cfexist(filename))
934 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
935 if (! cfexist(filename))
936 strcpy(filename, "descentd.pcx"); // SHAREWARE
937 if (! cfexist(filename))
938 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
940 #if defined(POLY_ACC)
941 gr_set_mode(SM_640x480x15xPA);
943 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
946 set_screen_mode(SCREEN_MENU);
949 FontHires = FontHiresAvailable && MenuHires;
951 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
952 //vfx_set_palette_sub( title_pal );
954 gr_palette_fade_in( title_pal, 32, 0 );
957 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
960 con_printf( CON_DEBUG , "\nDoing bm_init..." );
968 if (FindArg("-hoarddata") != 0) {
969 #define MAX_BITMAPS_PER_BRUSH 30
970 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
973 ubyte palette[256*3];
976 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
977 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
978 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
979 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
981 ofile = PHYSFSX_openWriteBuffered("hoard.ham");
983 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
984 Assert(iff_error == IFF_NO_ERROR);
985 PHYSFS_writeULE16(ofile, nframes);
986 PHYSFS_writeULE16(ofile, bm[0]->bm_w);
987 PHYSFS_writeULE16(ofile, bm[0]->bm_h);
988 PHYSFS_write(ofile, palette, 3, 256);
989 for (i=0;i<nframes;i++)
990 PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
992 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
993 Assert(iff_error == IFF_NO_ERROR);
994 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
995 PHYSFS_writeULE16(ofile, nframes);
996 PHYSFS_write(ofile, palette, 3, 256);
997 for (i=0;i<nframes;i++)
998 PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
1001 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
1002 Assert(iff_error == IFF_NO_ERROR);
1003 PHYSFS_writeULE16(ofile, icon.bm_w);
1004 PHYSFS_writeULE16(ofile, icon.bm_h);
1005 PHYSFS_write(ofile, palette, 3, 256);
1006 PHYSFS_write(ofile, icon.bm_data, icon.bm_w*icon.bm_h, 1);
1009 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
1014 ifile = PHYSFS_openRead(sounds[i]);
1015 Assert(ifile != NULL);
1016 size = PHYSFS_fileLength(ifile);
1017 buf = d_malloc(size);
1018 PHYSFS_read(ifile, buf, size, 1);
1019 PHYSFS_writeULE32(ofile, size);
1020 PHYSFS_write(ofile, buf, size, 1);
1022 PHYSFS_close(ifile);
1025 PHYSFS_close(ofile);
1031 //the bitmap loading code changes gr_palette, so restore it
1032 memcpy(gr_palette,title_pal,sizeof(gr_palette));
1034 if ( FindArg( "-norun" ) )
1037 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
1040 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
1041 texmerge_init( 10 ); // 10 cache bitmaps
1043 con_printf( CON_DEBUG, "\nRunning game...\n" );
1044 set_screen_mode(SCREEN_MENU);
1048 // If built with editor, option to auto-load a level and quit game
1049 // to write certain data.
1052 if ( (t = FindArg( "-autoload" )) ) {
1054 strcpy(Auto_file, Args[t+1]);
1060 strcpy(Players[0].callsign, "dummy");
1063 do_register_player(title_pal);
1065 gr_palette_fade_out( title_pal, 32, 0 );
1067 Game_mode = GM_GAME_OVER;
1070 newdemo_start_playback("descent.dem");
1071 if (Newdemo_state == ND_STATE_PLAYBACK )
1072 Function_mode = FMODE_GAME;
1075 //do this here because the demo code can do a longjmp when trying to
1076 //autostart a demo from the main menu, never having gone into the game
1079 while (Function_mode != FMODE_EXIT)
1081 switch( Function_mode ) {
1083 set_screen_mode(SCREEN_MENU);
1085 newdemo_start_playback(NULL); // Randomly pick a file
1086 if (Newdemo_state != ND_STATE_PLAYBACK)
1087 Error("No demo files were found for autodemo mode!");
1091 strcpy((char *)&Level_names[0], Auto_file);
1093 Function_mode = FMODE_EXIT;
1098 check_joystick_calibration();
1099 gr_palette_clear(); //I'm not sure why we need this, but we do
1102 if ( Function_mode == FMODE_EDITOR ) {
1104 SetPlayerFromCurseg();
1105 load_palette(NULL,1,0);
1112 keyd_editor_mode = 0;
1116 /* keep the mouse from wandering in SDL */
1117 if (FindArg("-grabmouse"))
1118 SDL_WM_GrabInput(SDL_GRAB_ON);
1124 /* give control back to the WM */
1125 if (FindArg("-grabmouse"))
1126 SDL_WM_GrabInput(SDL_GRAB_OFF);
1129 if ( Function_mode == FMODE_MENU )
1130 songs_play_song( SONG_TITLE, 1 );
1134 keyd_editor_mode = 1;
1137 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1139 if ( Function_mode == FMODE_GAME ) {
1140 Game_mode = GM_EDITOR;
1141 editor_reset_stuff_on_level();
1147 Error("Invalid function mode %d",Function_mode);
1153 if (!FindArg( "-notitles" ))
1157 if ( FindArg( "-showmeminfo" ) )
1158 show_mem_info = 1; // Make memory statistics show
1161 return(0); //presumably successful exit
1165 void check_joystick_calibration() {
1166 int x1, y1, x2, y2, c;
1169 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1170 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1171 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1172 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1175 joy_get_pos( &x1, &y1 );
1177 t1 = timer_get_fixed_seconds();
1178 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1181 joy_get_pos( &x2, &y2 );
1183 // If joystick hasn't moved...
1184 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1185 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1186 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1188 joydefs_calibrate();
1195 void show_order_form()
1200 unsigned char title_pal[768];
1201 char exit_screen[16];
1203 gr_set_current_canvas( NULL );
1208 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1209 if (! cfexist(exit_screen))
1210 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1211 if (! cfexist(exit_screen))
1212 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1213 if (! cfexist(exit_screen))
1214 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1215 if (! cfexist(exit_screen))
1216 return; // D2 registered
1218 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1219 //vfx_set_palette_sub( title_pal );
1220 gr_palette_fade_in( title_pal, 32, 0 );
1222 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1223 gr_palette_fade_out( title_pal, 32, 0 );
1226 Int3(); //can't load order screen
1236 // void network_abort_game();
1237 // if(Network_status)
1238 // network_abort_game();