1 /* $Id: inferno.c,v 1.88 2004-08-28 23:37:35 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.");
197 while (cfgets(line,LINE_LEN,ifile)) {
201 for (i = 0; i < strlen(line) - 1; i++) {
202 encode_rotate_left(&(line[i]));
203 line[i] = line[i] ^ BITMAP_TBL_XOR;
204 encode_rotate_left(&(line[i]));
209 continue; //don't show comments
219 // printf( " Diagnostic:\n\n");
220 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
221 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
224 printf( " Editor Options:\n\n");
225 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
226 printf( " -hoarddata %s\n","FIXME: Undocumented");
227 // printf( " -nobm %s\n","FIXME: Undocumented");
230 printf( " D2X Options:\n\n");
231 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
232 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
233 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
234 printf(" -renderstats %s\n", "Enable renderstats info by default");
236 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
237 printf( " -notitles %s\n", "Do not show titlescreens on startup");
238 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
240 printf( " -nohogdir %s\n", "don't try to use shared data directory");
241 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
243 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
244 printf( " -autodemo %s\n", "Start in demo mode");
245 printf( " -bigpig %s\n","FIXME: Undocumented");
246 printf( " -bspgen %s\n","FIXME: Undocumented");
247 // printf( " -cdproxy %s\n","FIXME: Undocumented");
249 printf( " -checktime %s\n","FIXME: Undocumented");
250 printf( " -showmeminfo %s\n","FIXME: Undocumented");
252 // printf( " -codereadonly %s\n","FIXME: Undocumented");
253 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
254 printf( " -debug %s\n","Enable very verbose output");
255 // printf( " -debugmode %s\n","FIXME: Undocumented");
256 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
257 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
258 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
259 // printf( " -forcegfx %s\n","FIXME: Undocumented");
261 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
263 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
265 printf( " -invulnerability %s\n","Make yourself invulnerable");
267 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
268 printf( " -jasen %s\n","FIXME: Undocumented");
269 printf( " -joyslow %s\n","FIXME: Undocumented");
271 printf( " -kali %s\n","use Kali for networking");
273 // printf( " -logfile %s\n","FIXME: Undocumented");
274 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
275 #if defined(EDITOR) || !defined(MACDATA)
276 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
278 // printf( " -memdbg %s\n","FIXME: Undocumented");
279 // printf( " -monodebug %s\n","FIXME: Undocumented");
280 printf( " -nocdrom %s\n","FIXME: Undocumented");
282 printf( " -nocyberman %s\n","FIXME: Undocumented");
285 printf( " -nofade %s\n","Disable fades");
288 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
289 printf( " -norankings %s\n","Disable multiplayer ranking system");
290 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
291 // printf( " -showaddress %s\n","FIXME: Undocumented");
292 printf( " -socket %s\n","FIXME: Undocumented");
294 #if !defined(MACINTOSH) && !defined(WINDOWS)
295 printf( " -nomixer %s\n","Don't crank music volume");
296 // printf( " -superhires %s\n","Allow higher-resolution modes");
298 // printf( " -nomodex %s\n","FIXME: Undocumented");
300 printf( " -nomovies %s\n","Don't play movies");
301 printf( " -noscreens %s\n","Skip briefing screens");
303 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
304 printf( " -noredbook %s\n","Disable redbook audio");
306 printf( " -norun %s\n","Bail out after initialization");
307 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
308 // printf( " -rtscts %s\n","Same as -ctsrts");
309 // printf( " -semiwin %s\n","Use non-fullscreen mode");
310 // printf( " -specialdevice %s\n","FIXME: Undocumented");
312 printf( " -stickmag %s\n","FIXME: Undocumented");
314 // printf( " -stopwatch %s\n","FIXME: Undocumented");
315 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
316 // printf( " -sysram %s\n","FIXME: Undocumented");
317 printf( " -text <file> %s\n","Specify alternate .tex file");
318 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
319 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
320 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
321 // printf( " -vidram %s\n","FIXME: Undocumented");
322 printf( " -xcontrol %s\n","FIXME: Undocumented");
323 printf( " -xname %s\n","FIXME: Undocumented");
324 printf( " -xver %s\n","FIXME: Undocumented");
325 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
327 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
328 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
330 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
332 printf(" -niceautomap %s\n", "Free cpu while doing automap");
333 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
334 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
335 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
336 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
337 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
340 printf( "D2X System Options:\n\n");
342 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
343 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
345 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
346 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
349 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
350 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
351 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
352 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
353 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
354 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
355 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
356 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
357 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
358 printf( " -gl_voodoo %s\n","force fullscreen mode only");
360 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
361 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
362 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
363 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
364 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
365 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
366 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
367 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
368 printf( " -gl_test2 %s\n","FIXME: Undocumented");
369 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
370 #ifdef OGL_RUNTIME_LOAD
371 printf( " -gl_library <l> %s\n","use alternate opengl library");
374 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
378 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
379 printf( " -hwsurface %s\n","FIXME: Undocumented");
382 printf(" -udp %s\n", "Specify options for udp/ip:");
383 printf(" @<shift> %s\n", " shift udp port base offset");
384 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
385 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
386 printf(" %s\n", " HOSTS can be any IP or hostname")
388 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
389 printf(" %s\n", " separate multiple HOSTS with a ,");
392 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
393 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
395 printf( "\n Help:\n\n");
396 printf( " -help, -h, -?, ? %s\n", "View this help screen");
400 void do_joystick_init()
403 if (!FindArg( "-nojoystick" )) {
404 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
406 if ( FindArg( "-joyslow" )) {
407 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
408 joy_set_slow_reading(JOY_SLOW_READINGS);
410 if ( FindArg( "-joypolled" )) {
411 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
412 joy_set_slow_reading(JOY_POLLED_READINGS);
414 if ( FindArg( "-joybios" )) {
415 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
416 joy_set_slow_reading(JOY_BIOS_READINGS);
419 // Added from Descent v1.5 by John. Adapted by Samir.
421 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
425 //set this to force game to run in low res
426 int disable_high_res=0;
428 void do_register_player(ubyte *title_pal)
430 Players[Player_num].callsign[0] = '\0';
436 //now, before we bring up the register player menu, we need to
437 //do some stuff to make sure the palette is ok. First, we need to
438 //get our current palette into the 2d's array, so the remapping will
439 //work. Second, we need to remap the fonts. Third, we need to fill
440 //in part of the fade tables so the darkening of the menu edges works
442 memcpy(gr_palette,title_pal,sizeof(gr_palette));
443 remap_fonts_and_menus(1);
444 RegisterPlayer(); //get player's name
449 #define PROGNAME argv[0]
451 extern char Language[];
453 //can we do highres menus?
454 extern int MenuHiresAvailable;
456 int intro_played = 0;
458 int Inferno_verbose = 0;
460 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
461 int start_net_immediately = 0;
462 //int start_with_mission = 0;
463 //char *start_with_mission_name;
464 //end this section addition
466 int open_movie_file(char *filename,int must_have);
468 #if defined(POLY_ACC)
469 #define MENU_HIRES_MODE SM_640x480x15xPA
471 #define MENU_HIRES_MODE SM(640,480)
474 // DESCENT II by Parallax Software
477 //extern ubyte gr_current_pal[];
481 char Auto_file[128] = "";
484 int main(int argc, char *argv[])
487 ubyte title_pal[768];
489 con_init(); // Initialise the console
492 error_init(NULL, NULL);
494 InitArgs( argc,argv );
498 char *home = getenv("HOME");
500 if ((t = FindArg("-userdir")))
504 char buf[PATH_MAX + 5];
507 strcat(buf, "/.d2x");
511 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
517 if (FindArg("-debug"))
518 con_threshold.value = (float)2;
519 else if (FindArg("-verbose"))
520 con_threshold.value = (float)1;
522 //tell cfile where hogdir is
523 if ((t=FindArg("-hogdir")))
524 cfile_use_alternate_hogdir(Args[t+1]);
526 else if (!FindArg("-nohogdir"))
527 cfile_use_alternate_hogdir(SHAREPATH);
530 //tell cfile about our counter
531 cfile_set_critical_error_counter_ptr(&descent_critical_error);
533 if (! cfile_init("descent2.hog"))
534 if (! cfile_init("d2demo.hog"))
535 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
540 "\tCurrent directory\n"
542 "Or use the -hogdir option to specify an alternate location.");
545 //print out the banner title
546 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
548 con_printf(CON_NORMAL, " %s", VERSION_NAME);
550 if (cfexist(MISSION_DIR "d2x.hog"))
551 con_printf(CON_NORMAL, " Vertigo Enhanced");
553 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
554 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
555 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
556 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
559 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
560 print_commandline_help();
561 set_exit_message("");
563 exit(0); /* mingw hangs on this return. dunno why */
568 con_printf(CON_NORMAL, "\n");
569 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
570 con_printf(CON_NORMAL, "\n");
572 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
573 if(FindArg("-sound22k"))
575 digi_sample_rate = SAMPLE_RATE_22K;
578 if(FindArg("-sound11k"))
580 digi_sample_rate = SAMPLE_RATE_11K;
587 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
589 if ((t = FindArg("-rearviewtime")))
591 float f = atof(Args[t + 1]);
592 Rear_view_leave_time = f * f1_0;
594 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
596 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
597 if ((t = FindArg( "-maxfps" ))) {
602 //end addition - Victor Rachels
604 #ifdef SUPPORTS_NICEFPS
605 if (FindArg("-nicefps"))
607 if (FindArg("-niceautomap"))
611 if (FindArg("-renderstats"))
614 if ( FindArg( "-autodemo" ))
618 if ( FindArg( "-noscreens" ) )
619 Skip_briefing_screens = 1;
622 if ((t=FindArg("-tmap"))){
623 select_tmap(Args[t+1]);
629 // if (init_graphics()) return 1;
632 if (!Inferno_is_800x600_available) {
633 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
634 Function_mode = FMODE_MENU;
639 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
641 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
646 #if defined(POLY_ACC)
647 Current_display_mode = -1;
648 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
651 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
652 set_display_mode(0); //..then set default display mode
656 int screen_width = 640;
657 int screen_height = 480;
658 int vr_mode = VR_NONE;
659 int screen_flags = VRF_USE_PAGING;
661 if (FindResArg("", &screen_width, &screen_height))
663 /* stuff below mirrors values from display_mode_info in
664 * menu.c which is used by set_display_mode. In fact,
665 * set_display_mode should probably be rewritten to allow
666 * arbitrary resolutions, and then we get rid of this
669 switch (SM(screen_width, screen_height))
673 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
676 screen_flags = VRF_USE_PAGING;
682 screen_flags = VRF_COMPATIBLE_MENUS;
686 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
689 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
691 if (FindArg("-nodoublebuffer"))
695 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
696 screen_flags &= ~VRF_USE_PAGING;
699 // added 3/24/99 by Owen Evans for screen res changing
700 Game_screen_mode = SM(screen_width, screen_height);
702 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
706 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
707 int i, argnum = INT_MAX, w, h;
708 // 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.
709 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
710 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
711 #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) );
712 // aren't #defines great? :)
713 // end addition/edit -MM
714 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
716 S_MODE(automap,automap_mode,automap_use_game_res);
717 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
721 i = FindArg( "-xcontrol" );
723 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
726 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
727 if (FindArg("-nofade"))
728 grd_fades_disabled=1;
730 //determine whether we're using high-res menus & movies
731 #if !defined(POLY_ACC)
732 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
733 MovieHires = MenuHires = MenuHiresAvailable = 0;
736 //NOTE LINK TO ABOVE!
737 MenuHires = MenuHiresAvailable = 1;
739 if (FindArg( "-lowresmovies" ))
742 if ((t=gr_init())!=0) //doesn't do much
743 Error(TXT_CANT_INIT_GFX,t);
749 // Load the palette stuff. Returns non-zero if error.
750 con_printf(CON_DEBUG, "Initializing palette system...\n" );
751 gr_use_palette_table(DEFAULT_PALETTE );
753 con_printf(CON_DEBUG, "Initializing font system...\n" );
754 gamefont_init(); // must load after palette data loaded.
756 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
757 init_movies(); //init movie libraries
760 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
761 #if defined(POLY_ACC)
762 gr_set_mode(SM_640x480x15xPA);
764 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
769 if ( FindArg( "-notitles" ) )
770 songs_play_song( SONG_TITLE, 1);
773 { //NOTE LINK TO ABOVE!
775 int played=MOVIE_NOT_PLAYED; //default is not played
777 int song_playing = 0;
780 #define MOVIE_REQUIRED 0
782 #define MOVIE_REQUIRED 1
785 #ifdef D2_OEM //$$POLY_ACC, jay.
786 { //show bundler screens
787 char filename[FILENAME_LEN];
789 played=MOVIE_NOT_PLAYED; //default is not played
791 played = PlayMovie("pre_i.mve",0);
794 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
796 while (cfexist(filename))
798 show_title_screen( filename, 1, 0 );
806 init_subtitles("intro.tex");
807 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
812 if (played != MOVIE_NOT_PLAYED)
814 else { //didn't get intro movie, try titles
816 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
818 if (played == MOVIE_NOT_PLAYED) {
819 #if defined(POLY_ACC)
820 gr_set_mode(SM_640x480x15xPA);
822 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
824 con_printf( CON_DEBUG, "\nPlaying title song..." );
825 songs_play_song( SONG_TITLE, 1);
827 con_printf( CON_DEBUG, "\nShowing logo screens..." );
828 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
829 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
833 { //show bundler movie or screens
835 char filename[FILENAME_LEN];
838 played=MOVIE_NOT_PLAYED; //default is not played
840 //check if OEM movie exists, so we don't stop the music if it doesn't
841 movie_handle = open_movie_file("oem.mve",0);
842 if (movie_handle != -1) {
844 played = PlayMovie("oem.mve",0);
845 song_playing = 0; //movie will kill sound
849 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
851 while (cfexist(filename))
853 show_title_screen( filename, 1, 0 );
861 songs_play_song( SONG_TITLE, 1);
865 PA_DFX (pa_splash());
867 con_printf( CON_DEBUG, "\nShowing loading screen..." );
869 //grs_bitmap title_bm;
873 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
874 if (! cfexist(filename))
875 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
876 if (! cfexist(filename))
877 strcpy(filename, "descentd.pcx"); // SHAREWARE
878 if (! cfexist(filename))
879 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
881 #if defined(POLY_ACC)
882 gr_set_mode(SM_640x480x15xPA);
884 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
887 set_screen_mode(SCREEN_MENU);
890 FontHires = FontHiresAvailable && MenuHires;
892 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
893 //vfx_set_palette_sub( title_pal );
895 gr_palette_fade_in( title_pal, 32, 0 );
897 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
900 con_printf( CON_DEBUG , "\nDoing bm_init..." );
908 if (FindArg("-hoarddata") != 0) {
909 #define MAX_BITMAPS_PER_BRUSH 30
910 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
914 ubyte palette[256*3];
917 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
918 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
919 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
920 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
922 ofile = fopen("hoard.ham","wb");
924 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
925 Assert(iff_error == IFF_NO_ERROR);
926 nframes_short = nframes;
927 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
928 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
929 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
930 fwrite(palette,3,256,ofile);
931 for (i=0;i<nframes;i++)
932 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
934 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
935 Assert(iff_error == IFF_NO_ERROR);
936 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
937 nframes_short = nframes;
938 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
939 fwrite(palette,3,256,ofile);
940 for (i=0;i<nframes;i++)
941 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
944 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
945 Assert(iff_error == IFF_NO_ERROR);
946 fwrite(&icon.bm_w,sizeof(short),1,ofile);
947 fwrite(&icon.bm_h,sizeof(short),1,ofile);
948 fwrite(palette,3,256,ofile);
949 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
952 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
956 ifile = fopen(sounds[i],"rb");
957 Assert(ifile != NULL);
958 size = ffilelength(ifile);
959 buf = d_malloc(size);
960 fread(buf,1,size,ifile);
961 fwrite(&size,sizeof(size),1,ofile);
962 fwrite(buf,1,size,ofile);
973 //the bitmap loading code changes gr_palette, so restore it
974 memcpy(gr_palette,title_pal,sizeof(gr_palette));
976 if ( FindArg( "-norun" ) )
979 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
982 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
983 texmerge_init( 10 ); // 10 cache bitmaps
985 con_printf( CON_DEBUG, "\nRunning game...\n" );
986 set_screen_mode(SCREEN_MENU);
990 // If built with editor, option to auto-load a level and quit game
991 // to write certain data.
994 if ( (t = FindArg( "-autoload" )) ) {
996 strcpy(Auto_file, Args[t+1]);
1002 strcpy(Players[0].callsign, "dummy");
1005 do_register_player(title_pal);
1007 gr_palette_fade_out( title_pal, 32, 0 );
1009 Game_mode = GM_GAME_OVER;
1012 newdemo_start_playback("descent.dem");
1013 if (Newdemo_state == ND_STATE_PLAYBACK )
1014 Function_mode = FMODE_GAME;
1017 //do this here because the demo code can do a longjmp when trying to
1018 //autostart a demo from the main menu, never having gone into the game
1021 while (Function_mode != FMODE_EXIT)
1023 switch( Function_mode ) {
1025 set_screen_mode(SCREEN_MENU);
1027 newdemo_start_playback(NULL); // Randomly pick a file
1028 if (Newdemo_state != ND_STATE_PLAYBACK)
1029 Error("No demo files were found for autodemo mode!");
1033 strcpy((char *)&Level_names[0], Auto_file);
1035 Function_mode = FMODE_EXIT;
1040 check_joystick_calibration();
1041 gr_palette_clear(); //I'm not sure why we need this, but we do
1044 if ( Function_mode == FMODE_EDITOR ) {
1046 SetPlayerFromCurseg();
1047 load_palette(NULL,1,0);
1054 keyd_editor_mode = 0;
1058 /* keep the mouse from wandering in SDL */
1059 if (FindArg("-grabmouse"))
1060 SDL_WM_GrabInput(SDL_GRAB_ON);
1066 /* give control back to the WM */
1067 if (FindArg("-grabmouse"))
1068 SDL_WM_GrabInput(SDL_GRAB_OFF);
1071 if ( Function_mode == FMODE_MENU )
1072 songs_play_song( SONG_TITLE, 1 );
1076 keyd_editor_mode = 1;
1079 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1081 if ( Function_mode == FMODE_GAME ) {
1082 Game_mode = GM_EDITOR;
1083 editor_reset_stuff_on_level();
1089 Error("Invalid function mode %d",Function_mode);
1096 if (!FindArg( "-notitles" ))
1101 if ( FindArg( "-showmeminfo" ) )
1102 show_mem_info = 1; // Make memory statistics show
1105 return(0); //presumably successful exit
1109 void check_joystick_calibration() {
1110 int x1, y1, x2, y2, c;
1113 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1114 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1115 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1116 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1119 joy_get_pos( &x1, &y1 );
1121 t1 = timer_get_fixed_seconds();
1122 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1125 joy_get_pos( &x2, &y2 );
1127 // If joystick hasn't moved...
1128 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1129 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1130 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1132 joydefs_calibrate();
1139 void show_order_form()
1144 unsigned char title_pal[768];
1145 char exit_screen[16];
1147 gr_set_current_canvas( NULL );
1152 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1153 if (! cfexist(exit_screen))
1154 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1155 if (! cfexist(exit_screen))
1156 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1157 if (! cfexist(exit_screen))
1158 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1159 if (! cfexist(exit_screen))
1160 return; // D2 registered
1162 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1163 //vfx_set_palette_sub( title_pal );
1164 gr_palette_fade_in( title_pal, 32, 0 );
1166 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1167 gr_palette_fade_out( title_pal, 32, 0 );
1170 Int3(); //can't load order screen
1180 // void network_abort_game();
1181 // if(Network_status)
1182 // network_abort_game();