1 /* $Id: inferno.c,v 1.87 2004-08-28 23:17:45 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)
25 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
35 #include <sys/types.h>
41 #include "pa_enabl.h" //$$POLY_ACC
53 #include "segment.h" //for Side_to_verts
95 // # include "3dfx_des.h"
97 //added on 9/30/98 by Matt Mueller for selectable automap modes
101 #include "../texmap/scanline.h" //for select_tmap -MM
103 #if defined(POLY_ACC)
104 #include "poly_acc.h"
105 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
109 #include "editor/editor.h"
110 #include "editor/kdefs.h"
121 void arch_init(void);
122 void arch_init_start(void);
124 //Current version number
126 ubyte Version_major = 1; //FULL VERSION
127 ubyte Version_minor = 2;
129 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
130 char desc_id_exit_num = 0;
132 int Function_mode=FMODE_MENU; //game or editor?
133 int Screen_mode=-1; //game screen or editor screen?
135 //--unused-- grs_bitmap Inferno_bitmap_title;
137 int WVIDEO_running=0; //debugger can set to 1 if running
140 int Inferno_is_800x600_available = 0;
143 //--unused-- int Cyberman_installed=0; // SWIFT device present
144 ubyte CybermouseActive=0;
146 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
148 void check_joystick_calibration(void);
150 void show_order_form(void);
152 //--------------------------------------------------------------------------
154 extern int piggy_low_memory;
157 int descent_critical_error = 0;
158 unsigned descent_critical_deverror = 0;
159 unsigned descent_critical_errcode = 0;
161 extern int Network_allow_socket_changes;
163 extern void vfx_set_palette_sub(ubyte *);
165 extern int VR_low_res;
167 extern int Config_vr_type;
168 extern int Config_vr_resolution;
169 extern int Config_vr_tracking;
173 //read help from a file & print to screen
174 void print_commandline_help()
180 ifile = cfopen("help.tex","rb");
182 ifile = cfopen("help.txb","rb");
184 Warning("Cannot load help text file.");
191 while (cfgets(line,LINE_LEN,ifile)) {
195 for (i = 0; i < strlen(line) - 1; i++) {
196 encode_rotate_left(&(line[i]));
197 line[i] = line[i] ^ BITMAP_TBL_XOR;
198 encode_rotate_left(&(line[i]));
203 continue; //don't show comments
213 // printf( " Diagnostic:\n\n");
214 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
215 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
218 printf( " Editor Options:\n\n");
219 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
220 printf( " -hoarddata %s\n","FIXME: Undocumented");
221 // printf( " -nobm %s\n","FIXME: Undocumented");
224 printf( " D2X Options:\n\n");
225 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
226 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
227 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
228 printf(" -renderstats %s\n", "Enable renderstats info by default");
230 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
231 printf( " -notitles %s\n", "Do not show titlescreens on startup");
232 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
234 printf( " -nohogdir %s\n", "don't try to use shared data directory");
235 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
237 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
238 printf( " -autodemo %s\n", "Start in demo mode");
239 printf( " -bigpig %s\n","FIXME: Undocumented");
240 printf( " -bspgen %s\n","FIXME: Undocumented");
241 // printf( " -cdproxy %s\n","FIXME: Undocumented");
243 printf( " -checktime %s\n","FIXME: Undocumented");
244 printf( " -showmeminfo %s\n","FIXME: Undocumented");
246 // printf( " -codereadonly %s\n","FIXME: Undocumented");
247 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
248 printf( " -debug %s\n","Enable very verbose output");
249 // printf( " -debugmode %s\n","FIXME: Undocumented");
250 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
251 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
252 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
253 // printf( " -forcegfx %s\n","FIXME: Undocumented");
255 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
257 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
259 printf( " -invulnerability %s\n","Make yourself invulnerable");
261 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
262 printf( " -jasen %s\n","FIXME: Undocumented");
263 printf( " -joyslow %s\n","FIXME: Undocumented");
265 printf( " -kali %s\n","use Kali for networking");
267 // printf( " -logfile %s\n","FIXME: Undocumented");
268 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
269 #if defined(EDITOR) || !defined(MACDATA)
270 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
272 // printf( " -memdbg %s\n","FIXME: Undocumented");
273 // printf( " -monodebug %s\n","FIXME: Undocumented");
274 printf( " -nocdrom %s\n","FIXME: Undocumented");
276 printf( " -nocyberman %s\n","FIXME: Undocumented");
279 printf( " -nofade %s\n","Disable fades");
282 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
283 printf( " -norankings %s\n","Disable multiplayer ranking system");
284 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
285 // printf( " -showaddress %s\n","FIXME: Undocumented");
286 printf( " -socket %s\n","FIXME: Undocumented");
288 #if !defined(MACINTOSH) && !defined(WINDOWS)
289 printf( " -nomixer %s\n","Don't crank music volume");
290 // printf( " -superhires %s\n","Allow higher-resolution modes");
292 // printf( " -nomodex %s\n","FIXME: Undocumented");
294 printf( " -nomovies %s\n","Don't play movies");
295 printf( " -noscreens %s\n","Skip briefing screens");
297 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
298 printf( " -noredbook %s\n","Disable redbook audio");
300 printf( " -norun %s\n","Bail out after initialization");
301 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
302 // printf( " -rtscts %s\n","Same as -ctsrts");
303 // printf( " -semiwin %s\n","Use non-fullscreen mode");
304 // printf( " -specialdevice %s\n","FIXME: Undocumented");
306 printf( " -stickmag %s\n","FIXME: Undocumented");
308 // printf( " -stopwatch %s\n","FIXME: Undocumented");
309 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
310 // printf( " -sysram %s\n","FIXME: Undocumented");
311 printf( " -text <file> %s\n","Specify alternate .tex file");
312 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
313 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
314 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
315 // printf( " -vidram %s\n","FIXME: Undocumented");
316 printf( " -xcontrol %s\n","FIXME: Undocumented");
317 printf( " -xname %s\n","FIXME: Undocumented");
318 printf( " -xver %s\n","FIXME: Undocumented");
319 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
321 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
322 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
324 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
326 printf(" -niceautomap %s\n", "Free cpu while doing automap");
327 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
328 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
329 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
330 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
331 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
334 printf( "D2X System Options:\n\n");
336 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
337 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
339 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
340 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
343 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
344 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
345 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
346 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
347 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
348 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
349 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
350 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
351 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
352 printf( " -gl_voodoo %s\n","force fullscreen mode only");
354 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
355 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
356 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
357 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
358 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
359 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
360 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
361 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
362 printf( " -gl_test2 %s\n","FIXME: Undocumented");
363 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
364 #ifdef OGL_RUNTIME_LOAD
365 printf( " -gl_library <l> %s\n","use alternate opengl library");
368 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
372 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
373 printf( " -hwsurface %s\n","FIXME: Undocumented");
376 printf(" -udp %s\n", "Specify options for udp/ip:");
377 printf(" @<shift> %s\n", " shift udp port base offset");
378 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
379 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
380 printf(" %s\n", " HOSTS can be any IP or hostname")
382 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
383 printf(" %s\n", " separate multiple HOSTS with a ,");
386 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
387 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
389 printf( "\n Help:\n\n");
390 printf( " -help, -h, -?, ? %s\n", "View this help screen");
394 void do_joystick_init()
397 if (!FindArg( "-nojoystick" )) {
398 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
400 if ( FindArg( "-joyslow" )) {
401 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
402 joy_set_slow_reading(JOY_SLOW_READINGS);
404 if ( FindArg( "-joypolled" )) {
405 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
406 joy_set_slow_reading(JOY_POLLED_READINGS);
408 if ( FindArg( "-joybios" )) {
409 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
410 joy_set_slow_reading(JOY_BIOS_READINGS);
413 // Added from Descent v1.5 by John. Adapted by Samir.
415 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
419 //set this to force game to run in low res
420 int disable_high_res=0;
422 void do_register_player(ubyte *title_pal)
424 Players[Player_num].callsign[0] = '\0';
430 //now, before we bring up the register player menu, we need to
431 //do some stuff to make sure the palette is ok. First, we need to
432 //get our current palette into the 2d's array, so the remapping will
433 //work. Second, we need to remap the fonts. Third, we need to fill
434 //in part of the fade tables so the darkening of the menu edges works
436 memcpy(gr_palette,title_pal,sizeof(gr_palette));
437 remap_fonts_and_menus(1);
438 RegisterPlayer(); //get player's name
443 #define PROGNAME argv[0]
445 extern char Language[];
447 //can we do highres menus?
448 extern int MenuHiresAvailable;
450 int intro_played = 0;
452 int Inferno_verbose = 0;
454 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
455 int start_net_immediately = 0;
456 //int start_with_mission = 0;
457 //char *start_with_mission_name;
458 //end this section addition
460 int open_movie_file(char *filename,int must_have);
462 #if defined(POLY_ACC)
463 #define MENU_HIRES_MODE SM_640x480x15xPA
465 #define MENU_HIRES_MODE SM(640,480)
468 // DESCENT II by Parallax Software
471 //extern ubyte gr_current_pal[];
475 char Auto_file[128] = "";
478 int main(int argc, char *argv[])
481 ubyte title_pal[768];
483 con_init(); // Initialise the console
486 error_init(NULL, NULL);
488 InitArgs( argc,argv );
492 char *home = getenv("HOME");
494 if ((t = FindArg("-userdir")))
498 char buf[PATH_MAX + 5];
501 strcat(buf, "/.d2x");
505 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
511 if (FindArg("-debug"))
512 con_threshold.value = (float)2;
513 else if (FindArg("-verbose"))
514 con_threshold.value = (float)1;
516 //tell cfile where hogdir is
517 if ((t=FindArg("-hogdir")))
518 cfile_use_alternate_hogdir(Args[t+1]);
520 else if (!FindArg("-nohogdir"))
521 cfile_use_alternate_hogdir(SHAREPATH);
524 //tell cfile about our counter
525 cfile_set_critical_error_counter_ptr(&descent_critical_error);
527 if (! cfile_init("descent2.hog"))
528 if (! cfile_init("d2demo.hog"))
529 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
534 "\tCurrent directory\n"
536 "Or use the -hogdir option to specify an alternate location.");
539 //print out the banner title
540 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
542 con_printf(CON_NORMAL, " %s", VERSION_NAME);
544 if (cfexist(MISSION_DIR "d2x.hog"))
545 con_printf(CON_NORMAL, " Vertigo Enhanced");
547 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
548 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
549 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
550 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
553 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
554 print_commandline_help();
555 set_exit_message("");
557 exit(0); /* mingw hangs on this return. dunno why */
562 con_printf(CON_NORMAL, "\n");
563 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
564 con_printf(CON_NORMAL, "\n");
566 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
567 if(FindArg("-sound22k"))
569 digi_sample_rate = SAMPLE_RATE_22K;
572 if(FindArg("-sound11k"))
574 digi_sample_rate = SAMPLE_RATE_11K;
581 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
583 if ((t = FindArg("-rearviewtime")))
585 float f = atof(Args[t + 1]);
586 Rear_view_leave_time = f * f1_0;
588 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
590 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
591 if ((t = FindArg( "-maxfps" ))) {
596 //end addition - Victor Rachels
598 #ifdef SUPPORTS_NICEFPS
599 if (FindArg("-nicefps"))
601 if (FindArg("-niceautomap"))
605 if (FindArg("-renderstats"))
608 if ( FindArg( "-autodemo" ))
612 if ( FindArg( "-noscreens" ) )
613 Skip_briefing_screens = 1;
616 if ((t=FindArg("-tmap"))){
617 select_tmap(Args[t+1]);
623 // if (init_graphics()) return 1;
626 if (!Inferno_is_800x600_available) {
627 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
628 Function_mode = FMODE_MENU;
633 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
635 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
640 #if defined(POLY_ACC)
641 Current_display_mode = -1;
642 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
645 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
646 set_display_mode(0); //..then set default display mode
650 int screen_width = 640;
651 int screen_height = 480;
652 int vr_mode = VR_NONE;
653 int screen_flags = VRF_USE_PAGING;
655 if (FindResArg("", &screen_width, &screen_height))
657 /* stuff below mirrors values from display_mode_info in
658 * menu.c which is used by set_display_mode. In fact,
659 * set_display_mode should probably be rewritten to allow
660 * arbitrary resolutions, and then we get rid of this
663 switch (SM(screen_width, screen_height))
667 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
670 screen_flags = VRF_USE_PAGING;
676 screen_flags = VRF_COMPATIBLE_MENUS;
680 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
683 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
685 if (FindArg("-nodoublebuffer"))
689 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
690 screen_flags &= ~VRF_USE_PAGING;
693 // added 3/24/99 by Owen Evans for screen res changing
694 Game_screen_mode = SM(screen_width, screen_height);
696 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
700 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
701 int i, argnum = INT_MAX, w, h;
702 // 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.
703 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
704 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
705 #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) );
706 // aren't #defines great? :)
707 // end addition/edit -MM
708 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
710 S_MODE(automap,automap_mode,automap_use_game_res);
711 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
715 i = FindArg( "-xcontrol" );
717 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
720 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
721 if (FindArg("-nofade"))
722 grd_fades_disabled=1;
724 //determine whether we're using high-res menus & movies
725 #if !defined(POLY_ACC)
726 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
727 MovieHires = MenuHires = MenuHiresAvailable = 0;
730 //NOTE LINK TO ABOVE!
731 MenuHires = MenuHiresAvailable = 1;
733 if (FindArg( "-lowresmovies" ))
736 if ((t=gr_init())!=0) //doesn't do much
737 Error(TXT_CANT_INIT_GFX,t);
743 // Load the palette stuff. Returns non-zero if error.
744 con_printf(CON_DEBUG, "Initializing palette system...\n" );
745 gr_use_palette_table(DEFAULT_PALETTE );
747 con_printf(CON_DEBUG, "Initializing font system...\n" );
748 gamefont_init(); // must load after palette data loaded.
750 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
751 init_movies(); //init movie libraries
754 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
755 #if defined(POLY_ACC)
756 gr_set_mode(SM_640x480x15xPA);
758 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
763 if ( FindArg( "-notitles" ) )
764 songs_play_song( SONG_TITLE, 1);
767 { //NOTE LINK TO ABOVE!
769 int played=MOVIE_NOT_PLAYED; //default is not played
771 int song_playing = 0;
774 #define MOVIE_REQUIRED 0
776 #define MOVIE_REQUIRED 1
779 #ifdef D2_OEM //$$POLY_ACC, jay.
780 { //show bundler screens
781 char filename[FILENAME_LEN];
783 played=MOVIE_NOT_PLAYED; //default is not played
785 played = PlayMovie("pre_i.mve",0);
788 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
790 while (cfexist(filename))
792 show_title_screen( filename, 1, 0 );
800 init_subtitles("intro.tex");
801 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
806 if (played != MOVIE_NOT_PLAYED)
808 else { //didn't get intro movie, try titles
810 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
812 if (played == MOVIE_NOT_PLAYED) {
813 #if defined(POLY_ACC)
814 gr_set_mode(SM_640x480x15xPA);
816 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
818 con_printf( CON_DEBUG, "\nPlaying title song..." );
819 songs_play_song( SONG_TITLE, 1);
821 con_printf( CON_DEBUG, "\nShowing logo screens..." );
822 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
823 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
827 { //show bundler movie or screens
829 char filename[FILENAME_LEN];
832 played=MOVIE_NOT_PLAYED; //default is not played
834 //check if OEM movie exists, so we don't stop the music if it doesn't
835 movie_handle = open_movie_file("oem.mve",0);
836 if (movie_handle != -1) {
838 played = PlayMovie("oem.mve",0);
839 song_playing = 0; //movie will kill sound
843 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
845 while (cfexist(filename))
847 show_title_screen( filename, 1, 0 );
855 songs_play_song( SONG_TITLE, 1);
859 PA_DFX (pa_splash());
861 con_printf( CON_DEBUG, "\nShowing loading screen..." );
863 //grs_bitmap title_bm;
867 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
868 if (! cfexist(filename))
869 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
870 if (! cfexist(filename))
871 strcpy(filename, "descentd.pcx"); // SHAREWARE
872 if (! cfexist(filename))
873 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
875 #if defined(POLY_ACC)
876 gr_set_mode(SM_640x480x15xPA);
878 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
881 set_screen_mode(SCREEN_MENU);
884 FontHires = FontHiresAvailable && MenuHires;
886 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
887 //vfx_set_palette_sub( title_pal );
889 gr_palette_fade_in( title_pal, 32, 0 );
891 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
894 con_printf( CON_DEBUG , "\nDoing bm_init..." );
902 if (FindArg("-hoarddata") != 0) {
903 #define MAX_BITMAPS_PER_BRUSH 30
904 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
908 ubyte palette[256*3];
911 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
912 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
913 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
914 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
916 ofile = fopen("hoard.ham","wb");
918 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
919 Assert(iff_error == IFF_NO_ERROR);
920 nframes_short = nframes;
921 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
922 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
923 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
924 fwrite(palette,3,256,ofile);
925 for (i=0;i<nframes;i++)
926 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
928 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
929 Assert(iff_error == IFF_NO_ERROR);
930 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
931 nframes_short = nframes;
932 fwrite(&nframes_short,sizeof(nframes_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);
938 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
939 Assert(iff_error == IFF_NO_ERROR);
940 fwrite(&icon.bm_w,sizeof(short),1,ofile);
941 fwrite(&icon.bm_h,sizeof(short),1,ofile);
942 fwrite(palette,3,256,ofile);
943 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
946 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
950 ifile = fopen(sounds[i],"rb");
951 Assert(ifile != NULL);
952 size = ffilelength(ifile);
953 buf = d_malloc(size);
954 fread(buf,1,size,ifile);
955 fwrite(&size,sizeof(size),1,ofile);
956 fwrite(buf,1,size,ofile);
967 //the bitmap loading code changes gr_palette, so restore it
968 memcpy(gr_palette,title_pal,sizeof(gr_palette));
970 if ( FindArg( "-norun" ) )
973 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
976 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
977 texmerge_init( 10 ); // 10 cache bitmaps
979 con_printf( CON_DEBUG, "\nRunning game...\n" );
980 set_screen_mode(SCREEN_MENU);
984 // If built with editor, option to auto-load a level and quit game
985 // to write certain data.
988 if ( (t = FindArg( "-autoload" )) ) {
990 strcpy(Auto_file, Args[t+1]);
996 strcpy(Players[0].callsign, "dummy");
999 do_register_player(title_pal);
1001 gr_palette_fade_out( title_pal, 32, 0 );
1003 Game_mode = GM_GAME_OVER;
1006 newdemo_start_playback("descent.dem");
1007 if (Newdemo_state == ND_STATE_PLAYBACK )
1008 Function_mode = FMODE_GAME;
1011 //do this here because the demo code can do a longjmp when trying to
1012 //autostart a demo from the main menu, never having gone into the game
1015 while (Function_mode != FMODE_EXIT)
1017 switch( Function_mode ) {
1019 set_screen_mode(SCREEN_MENU);
1021 newdemo_start_playback(NULL); // Randomly pick a file
1022 if (Newdemo_state != ND_STATE_PLAYBACK)
1023 Error("No demo files were found for autodemo mode!");
1027 strcpy((char *)&Level_names[0], Auto_file);
1029 Function_mode = FMODE_EXIT;
1034 check_joystick_calibration();
1035 gr_palette_clear(); //I'm not sure why we need this, but we do
1038 if ( Function_mode == FMODE_EDITOR ) {
1040 SetPlayerFromCurseg();
1041 load_palette(NULL,1,0);
1048 keyd_editor_mode = 0;
1052 /* keep the mouse from wandering in SDL */
1053 if (FindArg("-grabmouse"))
1054 SDL_WM_GrabInput(SDL_GRAB_ON);
1060 /* give control back to the WM */
1061 if (FindArg("-grabmouse"))
1062 SDL_WM_GrabInput(SDL_GRAB_OFF);
1065 if ( Function_mode == FMODE_MENU )
1066 songs_play_song( SONG_TITLE, 1 );
1070 keyd_editor_mode = 1;
1073 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1075 if ( Function_mode == FMODE_GAME ) {
1076 Game_mode = GM_EDITOR;
1077 editor_reset_stuff_on_level();
1083 Error("Invalid function mode %d",Function_mode);
1090 if (!FindArg( "-notitles" ))
1095 if ( FindArg( "-showmeminfo" ) )
1096 show_mem_info = 1; // Make memory statistics show
1099 return(0); //presumably successful exit
1103 void check_joystick_calibration() {
1104 int x1, y1, x2, y2, c;
1107 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1108 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1109 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1110 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1113 joy_get_pos( &x1, &y1 );
1115 t1 = timer_get_fixed_seconds();
1116 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1119 joy_get_pos( &x2, &y2 );
1121 // If joystick hasn't moved...
1122 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1123 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1124 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1126 joydefs_calibrate();
1133 void show_order_form()
1138 unsigned char title_pal[768];
1139 char exit_screen[16];
1141 gr_set_current_canvas( NULL );
1146 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1147 if (! cfexist(exit_screen))
1148 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1149 if (! cfexist(exit_screen))
1150 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1151 if (! cfexist(exit_screen))
1152 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1153 if (! cfexist(exit_screen))
1154 return; // D2 registered
1156 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1157 //vfx_set_palette_sub( title_pal );
1158 gr_palette_fade_in( title_pal, 32, 0 );
1160 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1161 gr_palette_fade_out( title_pal, 32, 0 );
1164 Int3(); //can't load order screen
1174 // void network_abort_game();
1175 // if(Network_status)
1176 // network_abort_game();