1 /* $Id: inferno.c,v 1.89 2004-08-29 17:57:23 schaffner 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>
47 #include "pa_enabl.h" //$$POLY_ACC
59 #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;
152 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
154 void check_joystick_calibration(void);
156 void show_order_form(void);
158 //--------------------------------------------------------------------------
160 extern int piggy_low_memory;
163 int descent_critical_error = 0;
164 unsigned descent_critical_deverror = 0;
165 unsigned descent_critical_errcode = 0;
167 extern int Network_allow_socket_changes;
169 extern void vfx_set_palette_sub(ubyte *);
171 extern int VR_low_res;
173 extern int Config_vr_type;
174 extern int Config_vr_resolution;
175 extern int Config_vr_tracking;
179 //read help from a file & print to screen
180 void print_commandline_help()
186 ifile = cfopen("help.tex","rb");
188 ifile = cfopen("help.txb","rb");
190 Warning("Cannot load help text file.");
198 while (end = cfgets(line,LINE_LEN,ifile)) {
200 // This is the only use of cfgets that needs the CR
204 for (i = 0; i < strlen(line) - 1; i++) {
205 encode_rotate_left(&(line[i]));
206 line[i] = line[i] ^ BITMAP_TBL_XOR;
207 encode_rotate_left(&(line[i]));
212 continue; //don't show comments
222 // printf( " Diagnostic:\n\n");
223 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
224 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
227 printf( " Editor Options:\n\n");
228 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
229 printf( " -hoarddata %s\n","FIXME: Undocumented");
230 // printf( " -nobm %s\n","FIXME: Undocumented");
233 printf( " D2X Options:\n\n");
234 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
235 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
236 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
237 printf(" -renderstats %s\n", "Enable renderstats info by default");
239 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
240 printf( " -notitles %s\n", "Do not show titlescreens on startup");
241 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
243 printf( " -nohogdir %s\n", "don't try to use shared data directory");
244 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
246 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
247 printf( " -autodemo %s\n", "Start in demo mode");
248 printf( " -bigpig %s\n","FIXME: Undocumented");
249 printf( " -bspgen %s\n","FIXME: Undocumented");
250 // printf( " -cdproxy %s\n","FIXME: Undocumented");
252 printf( " -checktime %s\n","FIXME: Undocumented");
253 printf( " -showmeminfo %s\n","FIXME: Undocumented");
255 // printf( " -codereadonly %s\n","FIXME: Undocumented");
256 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
257 printf( " -debug %s\n","Enable very verbose output");
258 // printf( " -debugmode %s\n","FIXME: Undocumented");
259 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
260 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
261 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
262 // printf( " -forcegfx %s\n","FIXME: Undocumented");
264 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
266 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
268 printf( " -invulnerability %s\n","Make yourself invulnerable");
270 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
271 printf( " -jasen %s\n","FIXME: Undocumented");
272 printf( " -joyslow %s\n","FIXME: Undocumented");
274 printf( " -kali %s\n","use Kali for networking");
276 // printf( " -logfile %s\n","FIXME: Undocumented");
277 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
278 #if defined(EDITOR) || !defined(MACDATA)
279 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
281 // printf( " -memdbg %s\n","FIXME: Undocumented");
282 // printf( " -monodebug %s\n","FIXME: Undocumented");
283 printf( " -nocdrom %s\n","FIXME: Undocumented");
285 printf( " -nocyberman %s\n","FIXME: Undocumented");
288 printf( " -nofade %s\n","Disable fades");
291 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
292 printf( " -norankings %s\n","Disable multiplayer ranking system");
293 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
294 // printf( " -showaddress %s\n","FIXME: Undocumented");
295 printf( " -socket %s\n","FIXME: Undocumented");
297 #if !defined(MACINTOSH) && !defined(WINDOWS)
298 printf( " -nomixer %s\n","Don't crank music volume");
299 // printf( " -superhires %s\n","Allow higher-resolution modes");
301 // printf( " -nomodex %s\n","FIXME: Undocumented");
303 printf( " -nomovies %s\n","Don't play movies");
304 printf( " -noscreens %s\n","Skip briefing screens");
306 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
307 printf( " -noredbook %s\n","Disable redbook audio");
309 printf( " -norun %s\n","Bail out after initialization");
310 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
311 // printf( " -rtscts %s\n","Same as -ctsrts");
312 // printf( " -semiwin %s\n","Use non-fullscreen mode");
313 // printf( " -specialdevice %s\n","FIXME: Undocumented");
315 printf( " -stickmag %s\n","FIXME: Undocumented");
317 // printf( " -stopwatch %s\n","FIXME: Undocumented");
318 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
319 // printf( " -sysram %s\n","FIXME: Undocumented");
320 printf( " -text <file> %s\n","Specify alternate .tex file");
321 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
322 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
323 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
324 // printf( " -vidram %s\n","FIXME: Undocumented");
325 printf( " -xcontrol %s\n","FIXME: Undocumented");
326 printf( " -xname %s\n","FIXME: Undocumented");
327 printf( " -xver %s\n","FIXME: Undocumented");
328 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
330 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
331 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
333 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
335 printf(" -niceautomap %s\n", "Free cpu while doing automap");
336 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
337 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
338 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
339 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
340 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
343 printf( "D2X System Options:\n\n");
345 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
346 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
348 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
349 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
352 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
353 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
354 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
355 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
356 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
357 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
358 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
359 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
360 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
361 printf( " -gl_voodoo %s\n","force fullscreen mode only");
363 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
364 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
365 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
366 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
367 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
368 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
369 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
370 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
371 printf( " -gl_test2 %s\n","FIXME: Undocumented");
372 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
373 #ifdef OGL_RUNTIME_LOAD
374 printf( " -gl_library <l> %s\n","use alternate opengl library");
377 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
381 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
382 printf( " -hwsurface %s\n","FIXME: Undocumented");
385 printf(" -udp %s\n", "Specify options for udp/ip:");
386 printf(" @<shift> %s\n", " shift udp port base offset");
387 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
388 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
389 printf(" %s\n", " HOSTS can be any IP or hostname")
391 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
392 printf(" %s\n", " separate multiple HOSTS with a ,");
395 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
396 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
398 printf( "\n Help:\n\n");
399 printf( " -help, -h, -?, ? %s\n", "View this help screen");
403 void do_joystick_init()
406 if (!FindArg( "-nojoystick" )) {
407 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
409 if ( FindArg( "-joyslow" )) {
410 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
411 joy_set_slow_reading(JOY_SLOW_READINGS);
413 if ( FindArg( "-joypolled" )) {
414 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
415 joy_set_slow_reading(JOY_POLLED_READINGS);
417 if ( FindArg( "-joybios" )) {
418 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
419 joy_set_slow_reading(JOY_BIOS_READINGS);
422 // Added from Descent v1.5 by John. Adapted by Samir.
424 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
428 //set this to force game to run in low res
429 int disable_high_res=0;
431 void do_register_player(ubyte *title_pal)
433 Players[Player_num].callsign[0] = '\0';
439 //now, before we bring up the register player menu, we need to
440 //do some stuff to make sure the palette is ok. First, we need to
441 //get our current palette into the 2d's array, so the remapping will
442 //work. Second, we need to remap the fonts. Third, we need to fill
443 //in part of the fade tables so the darkening of the menu edges works
445 memcpy(gr_palette,title_pal,sizeof(gr_palette));
446 remap_fonts_and_menus(1);
447 RegisterPlayer(); //get player's name
452 #define PROGNAME argv[0]
454 extern char Language[];
456 //can we do highres menus?
457 extern int MenuHiresAvailable;
459 int intro_played = 0;
461 int Inferno_verbose = 0;
463 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
464 int start_net_immediately = 0;
465 //int start_with_mission = 0;
466 //char *start_with_mission_name;
467 //end this section addition
469 int open_movie_file(char *filename,int must_have);
471 #if defined(POLY_ACC)
472 #define MENU_HIRES_MODE SM_640x480x15xPA
474 #define MENU_HIRES_MODE SM(640,480)
477 // DESCENT II by Parallax Software
480 //extern ubyte gr_current_pal[];
484 char Auto_file[128] = "";
487 int main(int argc, char *argv[])
490 ubyte title_pal[768];
492 con_init(); // Initialise the console
495 error_init(NULL, NULL);
497 InitArgs( argc,argv );
501 char *home = getenv("HOME");
503 if ((t = FindArg("-userdir")))
507 char buf[PATH_MAX + 5];
510 strcat(buf, "/.d2x");
514 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
520 if (FindArg("-debug"))
521 con_threshold.value = (float)2;
522 else if (FindArg("-verbose"))
523 con_threshold.value = (float)1;
525 //tell cfile where hogdir is
526 if ((t=FindArg("-hogdir")))
527 cfile_use_alternate_hogdir(Args[t+1]);
529 else if (!FindArg("-nohogdir"))
530 cfile_use_alternate_hogdir(SHAREPATH);
533 //tell cfile about our counter
534 cfile_set_critical_error_counter_ptr(&descent_critical_error);
536 if (! cfile_init("descent2.hog"))
537 if (! cfile_init("d2demo.hog"))
538 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
543 "\tCurrent directory\n"
545 "Or use the -hogdir option to specify an alternate location.");
548 //print out the banner title
549 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
551 con_printf(CON_NORMAL, " %s", VERSION_NAME);
553 if (cfexist(MISSION_DIR "d2x.hog"))
554 con_printf(CON_NORMAL, " Vertigo Enhanced");
556 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
557 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
558 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
559 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
562 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
563 print_commandline_help();
564 set_exit_message("");
566 exit(0); /* mingw hangs on this return. dunno why */
571 con_printf(CON_NORMAL, "\n");
572 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
573 con_printf(CON_NORMAL, "\n");
575 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
576 if(FindArg("-sound22k"))
578 digi_sample_rate = SAMPLE_RATE_22K;
581 if(FindArg("-sound11k"))
583 digi_sample_rate = SAMPLE_RATE_11K;
590 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
592 if ((t = FindArg("-rearviewtime")))
594 float f = atof(Args[t + 1]);
595 Rear_view_leave_time = f * f1_0;
597 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
599 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
600 if ((t = FindArg( "-maxfps" ))) {
605 //end addition - Victor Rachels
607 #ifdef SUPPORTS_NICEFPS
608 if (FindArg("-nicefps"))
610 if (FindArg("-niceautomap"))
614 if (FindArg("-renderstats"))
617 if ( FindArg( "-autodemo" ))
621 if ( FindArg( "-noscreens" ) )
622 Skip_briefing_screens = 1;
625 if ((t=FindArg("-tmap"))){
626 select_tmap(Args[t+1]);
632 // if (init_graphics()) return 1;
635 if (!Inferno_is_800x600_available) {
636 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
637 Function_mode = FMODE_MENU;
642 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
644 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
649 #if defined(POLY_ACC)
650 Current_display_mode = -1;
651 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
654 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
655 set_display_mode(0); //..then set default display mode
659 int screen_width = 640;
660 int screen_height = 480;
661 int vr_mode = VR_NONE;
662 int screen_flags = VRF_USE_PAGING;
664 if (FindResArg("", &screen_width, &screen_height))
666 /* stuff below mirrors values from display_mode_info in
667 * menu.c which is used by set_display_mode. In fact,
668 * set_display_mode should probably be rewritten to allow
669 * arbitrary resolutions, and then we get rid of this
672 switch (SM(screen_width, screen_height))
676 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
679 screen_flags = VRF_USE_PAGING;
685 screen_flags = VRF_COMPATIBLE_MENUS;
689 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
692 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
694 if (FindArg("-nodoublebuffer"))
698 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
699 screen_flags &= ~VRF_USE_PAGING;
702 // added 3/24/99 by Owen Evans for screen res changing
703 Game_screen_mode = SM(screen_width, screen_height);
705 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
709 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
710 int i, argnum = INT_MAX, w, h;
711 // 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.
712 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
713 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
714 #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) );
715 // aren't #defines great? :)
716 // end addition/edit -MM
717 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
719 S_MODE(automap,automap_mode,automap_use_game_res);
720 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
724 i = FindArg( "-xcontrol" );
726 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
729 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
730 if (FindArg("-nofade"))
731 grd_fades_disabled=1;
733 //determine whether we're using high-res menus & movies
734 #if !defined(POLY_ACC)
735 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
736 MovieHires = MenuHires = MenuHiresAvailable = 0;
739 //NOTE LINK TO ABOVE!
740 MenuHires = MenuHiresAvailable = 1;
742 if (FindArg( "-lowresmovies" ))
745 if ((t=gr_init())!=0) //doesn't do much
746 Error(TXT_CANT_INIT_GFX,t);
752 // Load the palette stuff. Returns non-zero if error.
753 con_printf(CON_DEBUG, "Initializing palette system...\n" );
754 gr_use_palette_table(DEFAULT_PALETTE );
756 con_printf(CON_DEBUG, "Initializing font system...\n" );
757 gamefont_init(); // must load after palette data loaded.
759 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
760 init_movies(); //init movie libraries
763 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
764 #if defined(POLY_ACC)
765 gr_set_mode(SM_640x480x15xPA);
767 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
772 if ( FindArg( "-notitles" ) )
773 songs_play_song( SONG_TITLE, 1);
776 { //NOTE LINK TO ABOVE!
778 int played=MOVIE_NOT_PLAYED; //default is not played
780 int song_playing = 0;
783 #define MOVIE_REQUIRED 0
785 #define MOVIE_REQUIRED 1
788 #ifdef D2_OEM //$$POLY_ACC, jay.
789 { //show bundler screens
790 char filename[FILENAME_LEN];
792 played=MOVIE_NOT_PLAYED; //default is not played
794 played = PlayMovie("pre_i.mve",0);
797 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
799 while (cfexist(filename))
801 show_title_screen( filename, 1, 0 );
809 init_subtitles("intro.tex");
810 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
815 if (played != MOVIE_NOT_PLAYED)
817 else { //didn't get intro movie, try titles
819 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
821 if (played == MOVIE_NOT_PLAYED) {
822 #if defined(POLY_ACC)
823 gr_set_mode(SM_640x480x15xPA);
825 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
827 con_printf( CON_DEBUG, "\nPlaying title song..." );
828 songs_play_song( SONG_TITLE, 1);
830 con_printf( CON_DEBUG, "\nShowing logo screens..." );
831 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
832 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
836 { //show bundler movie or screens
838 char filename[FILENAME_LEN];
841 played=MOVIE_NOT_PLAYED; //default is not played
843 //check if OEM movie exists, so we don't stop the music if it doesn't
844 movie_handle = open_movie_file("oem.mve",0);
845 if (movie_handle != -1) {
847 played = PlayMovie("oem.mve",0);
848 song_playing = 0; //movie will kill sound
852 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
854 while (cfexist(filename))
856 show_title_screen( filename, 1, 0 );
864 songs_play_song( SONG_TITLE, 1);
868 PA_DFX (pa_splash());
870 con_printf( CON_DEBUG, "\nShowing loading screen..." );
872 //grs_bitmap title_bm;
876 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
877 if (! cfexist(filename))
878 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
879 if (! cfexist(filename))
880 strcpy(filename, "descentd.pcx"); // SHAREWARE
881 if (! cfexist(filename))
882 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
884 #if defined(POLY_ACC)
885 gr_set_mode(SM_640x480x15xPA);
887 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
890 set_screen_mode(SCREEN_MENU);
893 FontHires = FontHiresAvailable && MenuHires;
895 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
896 //vfx_set_palette_sub( title_pal );
898 gr_palette_fade_in( title_pal, 32, 0 );
900 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
903 con_printf( CON_DEBUG , "\nDoing bm_init..." );
911 if (FindArg("-hoarddata") != 0) {
912 #define MAX_BITMAPS_PER_BRUSH 30
913 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
917 ubyte palette[256*3];
920 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
921 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
922 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
923 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
925 ofile = fopen("hoard.ham","wb");
927 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
928 Assert(iff_error == IFF_NO_ERROR);
929 nframes_short = nframes;
930 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
931 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
932 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
933 fwrite(palette,3,256,ofile);
934 for (i=0;i<nframes;i++)
935 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
937 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
938 Assert(iff_error == IFF_NO_ERROR);
939 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
940 nframes_short = nframes;
941 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
942 fwrite(palette,3,256,ofile);
943 for (i=0;i<nframes;i++)
944 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
947 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
948 Assert(iff_error == IFF_NO_ERROR);
949 fwrite(&icon.bm_w,sizeof(short),1,ofile);
950 fwrite(&icon.bm_h,sizeof(short),1,ofile);
951 fwrite(palette,3,256,ofile);
952 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
955 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
959 ifile = fopen(sounds[i],"rb");
960 Assert(ifile != NULL);
961 size = ffilelength(ifile);
962 buf = d_malloc(size);
963 fread(buf,1,size,ifile);
964 fwrite(&size,sizeof(size),1,ofile);
965 fwrite(buf,1,size,ofile);
976 //the bitmap loading code changes gr_palette, so restore it
977 memcpy(gr_palette,title_pal,sizeof(gr_palette));
979 if ( FindArg( "-norun" ) )
982 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
985 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
986 texmerge_init( 10 ); // 10 cache bitmaps
988 con_printf( CON_DEBUG, "\nRunning game...\n" );
989 set_screen_mode(SCREEN_MENU);
993 // If built with editor, option to auto-load a level and quit game
994 // to write certain data.
997 if ( (t = FindArg( "-autoload" )) ) {
999 strcpy(Auto_file, Args[t+1]);
1005 strcpy(Players[0].callsign, "dummy");
1008 do_register_player(title_pal);
1010 gr_palette_fade_out( title_pal, 32, 0 );
1012 Game_mode = GM_GAME_OVER;
1015 newdemo_start_playback("descent.dem");
1016 if (Newdemo_state == ND_STATE_PLAYBACK )
1017 Function_mode = FMODE_GAME;
1020 //do this here because the demo code can do a longjmp when trying to
1021 //autostart a demo from the main menu, never having gone into the game
1024 while (Function_mode != FMODE_EXIT)
1026 switch( Function_mode ) {
1028 set_screen_mode(SCREEN_MENU);
1030 newdemo_start_playback(NULL); // Randomly pick a file
1031 if (Newdemo_state != ND_STATE_PLAYBACK)
1032 Error("No demo files were found for autodemo mode!");
1036 strcpy((char *)&Level_names[0], Auto_file);
1038 Function_mode = FMODE_EXIT;
1043 check_joystick_calibration();
1044 gr_palette_clear(); //I'm not sure why we need this, but we do
1047 if ( Function_mode == FMODE_EDITOR ) {
1049 SetPlayerFromCurseg();
1050 load_palette(NULL,1,0);
1057 keyd_editor_mode = 0;
1061 /* keep the mouse from wandering in SDL */
1062 if (FindArg("-grabmouse"))
1063 SDL_WM_GrabInput(SDL_GRAB_ON);
1069 /* give control back to the WM */
1070 if (FindArg("-grabmouse"))
1071 SDL_WM_GrabInput(SDL_GRAB_OFF);
1074 if ( Function_mode == FMODE_MENU )
1075 songs_play_song( SONG_TITLE, 1 );
1079 keyd_editor_mode = 1;
1082 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1084 if ( Function_mode == FMODE_GAME ) {
1085 Game_mode = GM_EDITOR;
1086 editor_reset_stuff_on_level();
1092 Error("Invalid function mode %d",Function_mode);
1099 if (!FindArg( "-notitles" ))
1104 if ( FindArg( "-showmeminfo" ) )
1105 show_mem_info = 1; // Make memory statistics show
1108 return(0); //presumably successful exit
1112 void check_joystick_calibration() {
1113 int x1, y1, x2, y2, c;
1116 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1117 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1118 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1119 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1122 joy_get_pos( &x1, &y1 );
1124 t1 = timer_get_fixed_seconds();
1125 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1128 joy_get_pos( &x2, &y2 );
1130 // If joystick hasn't moved...
1131 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1132 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1133 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1135 joydefs_calibrate();
1142 void show_order_form()
1147 unsigned char title_pal[768];
1148 char exit_screen[16];
1150 gr_set_current_canvas( NULL );
1155 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1156 if (! cfexist(exit_screen))
1157 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1158 if (! cfexist(exit_screen))
1159 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1160 if (! cfexist(exit_screen))
1161 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1162 if (! cfexist(exit_screen))
1163 return; // D2 registered
1165 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1166 //vfx_set_palette_sub( title_pal );
1167 gr_palette_fade_in( title_pal, 32, 0 );
1169 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1170 gr_palette_fade_out( title_pal, 32, 0 );
1173 Int3(); //can't load order screen
1183 // void network_abort_game();
1184 // if(Network_status)
1185 // network_abort_game();