1 /* $Id: inferno.c,v 1.91 2004-10-23 20:53:08 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
100 // # include "3dfx_des.h"
102 //added on 9/30/98 by Matt Mueller for selectable automap modes
106 #include "../texmap/scanline.h" //for select_tmap -MM
108 #if defined(POLY_ACC)
109 #include "poly_acc.h"
110 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
114 #include "editor/editor.h"
115 #include "editor/kdefs.h"
126 void arch_init(void);
127 void arch_init_start(void);
129 //Current version number
131 ubyte Version_major = 1; //FULL VERSION
132 ubyte Version_minor = 2;
134 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
135 char desc_id_exit_num = 0;
137 int Function_mode=FMODE_MENU; //game or editor?
138 int Screen_mode=-1; //game screen or editor screen?
140 //--unused-- grs_bitmap Inferno_bitmap_title;
142 int WVIDEO_running=0; //debugger can set to 1 if running
145 int Inferno_is_800x600_available = 0;
148 //--unused-- int Cyberman_installed=0; // SWIFT device present
149 ubyte CybermouseActive=0;
151 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
153 void check_joystick_calibration(void);
155 void show_order_form(void);
157 //--------------------------------------------------------------------------
159 extern int piggy_low_memory;
162 int descent_critical_error = 0;
163 unsigned descent_critical_deverror = 0;
164 unsigned descent_critical_errcode = 0;
166 extern int Network_allow_socket_changes;
168 extern void vfx_set_palette_sub(ubyte *);
170 extern int VR_low_res;
172 extern int Config_vr_type;
173 extern int Config_vr_resolution;
174 extern int Config_vr_tracking;
178 //read help from a file & print to screen
179 void print_commandline_help()
185 ifile = cfopen("help.tex","rb");
187 ifile = cfopen("help.txb","rb");
189 Warning("Cannot load help text file.");
197 while ((end = cfgets(line,LINE_LEN,ifile))) {
199 // This is the only use of cfgets that needs the CR
202 decode_text_line (line);
205 continue; //don't show comments
215 // printf( " Diagnostic:\n\n");
216 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
217 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
220 printf( " Editor Options:\n\n");
221 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
222 printf( " -hoarddata %s\n","FIXME: Undocumented");
223 // printf( " -nobm %s\n","FIXME: Undocumented");
226 printf( " D2X Options:\n\n");
227 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
228 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
229 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
230 printf(" -renderstats %s\n", "Enable renderstats info by default");
232 printf( " -maxfps <n> %s\n", "Set maximum framerate (1-100)");
233 printf( " -notitles %s\n", "Do not show titlescreens on startup");
234 printf( " -hogdir <dir> %s\n", "set shared data directory to <dir>");
236 printf( " -nohogdir %s\n", "don't try to use shared data directory");
237 printf( " -userdir <dir> %s\n", "set user dir to <dir> instead of $HOME/.d2x");
239 printf( " -ini <file> %s\n", "option file (alternate to command line), defaults to d2x.ini");
240 printf( " -autodemo %s\n", "Start in demo mode");
241 printf( " -bigpig %s\n","FIXME: Undocumented");
242 printf( " -bspgen %s\n","FIXME: Undocumented");
243 // printf( " -cdproxy %s\n","FIXME: Undocumented");
245 printf( " -checktime %s\n","FIXME: Undocumented");
246 printf( " -showmeminfo %s\n","FIXME: Undocumented");
248 // printf( " -codereadonly %s\n","FIXME: Undocumented");
249 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
250 printf( " -debug %s\n","Enable very verbose output");
251 // printf( " -debugmode %s\n","FIXME: Undocumented");
252 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
253 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
254 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
255 // printf( " -forcegfx %s\n","FIXME: Undocumented");
257 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
259 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
261 printf( " -invulnerability %s\n","Make yourself invulnerable");
263 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
264 printf( " -jasen %s\n","FIXME: Undocumented");
265 printf( " -joyslow %s\n","FIXME: Undocumented");
267 printf( " -kali %s\n","use Kali for networking");
269 // printf( " -logfile %s\n","FIXME: Undocumented");
270 printf( " -lowresmovies %s\n","Play low resolution movies if available (for slow machines)");
271 #if defined(EDITOR) || !defined(MACDATA)
272 printf( " -macdata %s\n","Read (and, for editor, write) mac data files (swap colors)");
274 // printf( " -memdbg %s\n","FIXME: Undocumented");
275 // printf( " -monodebug %s\n","FIXME: Undocumented");
276 printf( " -nocdrom %s\n","FIXME: Undocumented");
278 printf( " -nocyberman %s\n","FIXME: Undocumented");
281 printf( " -nofade %s\n","Disable fades");
284 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
285 printf( " -norankings %s\n","Disable multiplayer ranking system");
286 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
287 // printf( " -showaddress %s\n","FIXME: Undocumented");
288 printf( " -socket %s\n","FIXME: Undocumented");
290 #if !defined(MACINTOSH) && !defined(WINDOWS)
291 printf( " -nomixer %s\n","Don't crank music volume");
292 // printf( " -superhires %s\n","Allow higher-resolution modes");
294 // printf( " -nomodex %s\n","FIXME: Undocumented");
296 printf( " -nomovies %s\n","Don't play movies");
297 printf( " -noscreens %s\n","Skip briefing screens");
299 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
300 printf( " -noredbook %s\n","Disable redbook audio");
302 printf( " -norun %s\n","Bail out after initialization");
303 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
304 // printf( " -rtscts %s\n","Same as -ctsrts");
305 // printf( " -semiwin %s\n","Use non-fullscreen mode");
306 // printf( " -specialdevice %s\n","FIXME: Undocumented");
308 printf( " -stickmag %s\n","FIXME: Undocumented");
310 // printf( " -stopwatch %s\n","FIXME: Undocumented");
311 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
312 // printf( " -sysram %s\n","FIXME: Undocumented");
313 printf( " -text <file> %s\n","Specify alternate .tex file");
314 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
315 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
316 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
317 // printf( " -vidram %s\n","FIXME: Undocumented");
318 printf( " -xcontrol %s\n","FIXME: Undocumented");
319 printf( " -xname %s\n","FIXME: Undocumented");
320 printf( " -xver %s\n","FIXME: Undocumented");
321 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
323 printf( " -<X>x<Y> %s\n", "Change screen resolution. Options:");
324 printf( " 320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
326 printf( " -<X>x<Y> %s\n", "Change screen resolution to <X> by <Y>");
328 printf(" -niceautomap %s\n", "Free cpu while doing automap");
329 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
330 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
331 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
332 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
333 printf(" -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
336 printf( "D2X System Options:\n\n");
338 printf(" -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
339 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
341 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
342 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
345 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
346 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
347 printf(" -gl_mipmap %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
348 printf(" -gl_trilinear %s\n", "set gl texture filters to trilinear mipmapping");
349 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
350 printf(" -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
351 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
352 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
353 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
354 printf( " -gl_voodoo %s\n","force fullscreen mode only");
356 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
357 printf(" -gl_16bpp %s\n", "attempt to use 16bit screen mode");
358 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
359 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
360 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
361 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
362 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
363 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
364 printf( " -gl_test2 %s\n","FIXME: Undocumented");
365 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
366 #ifdef OGL_RUNTIME_LOAD
367 printf( " -gl_library <l> %s\n","use alternate opengl library");
370 printf(" -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
374 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
375 printf( " -hwsurface %s\n","FIXME: Undocumented");
378 printf(" -udp %s\n", "Specify options for udp/ip:");
379 printf(" @<shift> %s\n", " shift udp port base offset");
380 printf(" =<HOST_LIST> %s\n", " broadcast both local and to HOST_LIST");
381 printf(" +<HOST_LIST> %s\n", " broadcast only to HOST_LIST");
382 printf(" %s\n", " HOSTS can be any IP or hostname")
384 printf(" %s\n", " HOSTS can also be in the form of <address>:<shift>");
385 printf(" %s\n", " separate multiple HOSTS with a ,");
388 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
389 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
391 printf( "\n Help:\n\n");
392 printf( " -help, -h, -?, ? %s\n", "View this help screen");
396 void do_joystick_init()
399 if (!FindArg( "-nojoystick" )) {
400 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
402 if ( FindArg( "-joyslow" )) {
403 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
404 joy_set_slow_reading(JOY_SLOW_READINGS);
406 if ( FindArg( "-joypolled" )) {
407 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
408 joy_set_slow_reading(JOY_POLLED_READINGS);
410 if ( FindArg( "-joybios" )) {
411 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
412 joy_set_slow_reading(JOY_BIOS_READINGS);
415 // Added from Descent v1.5 by John. Adapted by Samir.
417 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
421 //set this to force game to run in low res
422 int disable_high_res=0;
424 void do_register_player(ubyte *title_pal)
426 Players[Player_num].callsign[0] = '\0';
432 //now, before we bring up the register player menu, we need to
433 //do some stuff to make sure the palette is ok. First, we need to
434 //get our current palette into the 2d's array, so the remapping will
435 //work. Second, we need to remap the fonts. Third, we need to fill
436 //in part of the fade tables so the darkening of the menu edges works
438 memcpy(gr_palette,title_pal,sizeof(gr_palette));
439 remap_fonts_and_menus(1);
440 RegisterPlayer(); //get player's name
445 #define PROGNAME argv[0]
447 extern char Language[];
449 //can we do highres menus?
450 extern int MenuHiresAvailable;
452 int intro_played = 0;
454 int Inferno_verbose = 0;
456 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
457 int start_net_immediately = 0;
458 //int start_with_mission = 0;
459 //char *start_with_mission_name;
460 //end this section addition
462 int open_movie_file(char *filename,int must_have);
464 #if defined(POLY_ACC)
465 #define MENU_HIRES_MODE SM_640x480x15xPA
467 #define MENU_HIRES_MODE SM(640,480)
470 // DESCENT II by Parallax Software
473 //extern ubyte gr_current_pal[];
477 char Auto_file[128] = "";
480 int main(int argc, char *argv[])
483 ubyte title_pal[768];
485 con_init(); // Initialise the console
488 error_init(NULL, NULL);
490 InitArgs( argc,argv );
494 char *home = getenv("HOME");
496 if ((t = FindArg("-userdir")))
500 char buf[PATH_MAX + 5];
503 strcat(buf, "/.d2x");
507 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
513 if (FindArg("-debug"))
514 con_threshold.value = (float)2;
515 else if (FindArg("-verbose"))
516 con_threshold.value = (float)1;
518 //tell cfile where hogdir is
519 if ((t=FindArg("-hogdir")))
520 cfile_use_alternate_hogdir(Args[t+1]);
522 else if (!FindArg("-nohogdir"))
523 cfile_use_alternate_hogdir(SHAREPATH);
526 //tell cfile about our counter
527 cfile_set_critical_error_counter_ptr(&descent_critical_error);
529 if (! cfile_init("descent2.hog"))
530 if (! cfile_init("d2demo.hog"))
531 Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
536 "\tCurrent directory\n"
538 "Or use the -hogdir option to specify an alternate location.");
541 //print out the banner title
542 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
544 con_printf(CON_NORMAL, " %s", VERSION_NAME);
546 if (cfexist(MISSION_DIR "d2x.hog"))
547 con_printf(CON_NORMAL, " Vertigo Enhanced");
549 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
550 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
551 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
552 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
555 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
556 print_commandline_help();
557 set_exit_message("");
559 exit(0); /* mingw hangs on this return. dunno why */
564 con_printf(CON_NORMAL, "\n");
565 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
566 con_printf(CON_NORMAL, "\n");
568 //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
569 if(FindArg("-sound22k"))
571 digi_sample_rate = SAMPLE_RATE_22K;
574 if(FindArg("-sound11k"))
576 digi_sample_rate = SAMPLE_RATE_11K;
583 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
585 if ((t = FindArg("-rearviewtime")))
587 float f = atof(Args[t + 1]);
588 Rear_view_leave_time = f * f1_0;
590 con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
592 //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
593 if ((t = FindArg( "-maxfps" ))) {
598 //end addition - Victor Rachels
600 #ifdef SUPPORTS_NICEFPS
601 if (FindArg("-nicefps"))
603 if (FindArg("-niceautomap"))
607 if (FindArg("-renderstats"))
610 if ( FindArg( "-autodemo" ))
614 if ( FindArg( "-noscreens" ) )
615 Skip_briefing_screens = 1;
618 if ((t=FindArg("-tmap"))){
619 select_tmap(Args[t+1]);
625 // if (init_graphics()) return 1;
628 if (!Inferno_is_800x600_available) {
629 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
630 Function_mode = FMODE_MENU;
635 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
637 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
642 #if defined(POLY_ACC)
643 Current_display_mode = -1;
644 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
647 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
648 set_display_mode(0); //..then set default display mode
652 int screen_width = 640;
653 int screen_height = 480;
654 int vr_mode = VR_NONE;
655 int screen_flags = VRF_USE_PAGING;
657 if (FindResArg("", &screen_width, &screen_height))
659 /* stuff below mirrors values from display_mode_info in
660 * menu.c which is used by set_display_mode. In fact,
661 * set_display_mode should probably be rewritten to allow
662 * arbitrary resolutions, and then we get rid of this
665 switch (SM(screen_width, screen_height))
669 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
672 screen_flags = VRF_USE_PAGING;
678 screen_flags = VRF_COMPATIBLE_MENUS;
682 con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
685 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
687 if (FindArg("-nodoublebuffer"))
691 con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
692 screen_flags &= ~VRF_USE_PAGING;
695 // added 3/24/99 by Owen Evans for screen res changing
696 Game_screen_mode = SM(screen_width, screen_height);
698 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
702 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
703 int i, argnum = INT_MAX, w, h;
704 // 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.
705 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
706 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
707 #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) );
708 // aren't #defines great? :)
709 // end addition/edit -MM
710 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
712 S_MODE(automap,automap_mode,automap_use_game_res);
713 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
717 i = FindArg( "-xcontrol" );
719 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
722 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
723 if (FindArg("-nofade"))
724 grd_fades_disabled=1;
726 //determine whether we're using high-res menus & movies
727 #if !defined(POLY_ACC)
728 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
729 MovieHires = MenuHires = MenuHiresAvailable = 0;
732 //NOTE LINK TO ABOVE!
733 MenuHires = MenuHiresAvailable = 1;
735 if (FindArg( "-lowresmovies" ))
738 if ((t=gr_init())!=0) //doesn't do much
739 Error(TXT_CANT_INIT_GFX,t);
745 // Load the palette stuff. Returns non-zero if error.
746 con_printf(CON_DEBUG, "Initializing palette system...\n" );
747 gr_use_palette_table(DEFAULT_PALETTE );
749 con_printf(CON_DEBUG, "Initializing font system...\n" );
750 gamefont_init(); // must load after palette data loaded.
752 con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
753 init_movies(); //init movie libraries
756 con_printf(CON_VERBOSE, "Going into graphics mode...\n");
757 #if defined(POLY_ACC)
758 gr_set_mode(SM_640x480x15xPA);
760 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
765 if ( FindArg( "-notitles" ) )
766 songs_play_song( SONG_TITLE, 1);
769 { //NOTE LINK TO ABOVE!
771 int played=MOVIE_NOT_PLAYED; //default is not played
773 int song_playing = 0;
776 #define MOVIE_REQUIRED 0
778 #define MOVIE_REQUIRED 1
781 #ifdef D2_OEM //$$POLY_ACC, jay.
782 { //show bundler screens
783 char filename[FILENAME_LEN];
785 played=MOVIE_NOT_PLAYED; //default is not played
787 played = PlayMovie("pre_i.mve",0);
790 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
792 while (cfexist(filename))
794 show_title_screen( filename, 1, 0 );
802 init_subtitles("intro.tex");
803 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
808 if (played != MOVIE_NOT_PLAYED)
810 else { //didn't get intro movie, try titles
812 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
814 if (played == MOVIE_NOT_PLAYED) {
815 #if defined(POLY_ACC)
816 gr_set_mode(SM_640x480x15xPA);
818 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
820 con_printf( CON_DEBUG, "\nPlaying title song..." );
821 songs_play_song( SONG_TITLE, 1);
823 con_printf( CON_DEBUG, "\nShowing logo screens..." );
824 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
825 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
829 { //show bundler movie or screens
831 char filename[FILENAME_LEN];
834 played=MOVIE_NOT_PLAYED; //default is not played
836 //check if OEM movie exists, so we don't stop the music if it doesn't
837 movie_handle = open_movie_file("oem.mve",0);
838 if (movie_handle != -1) {
840 played = PlayMovie("oem.mve",0);
841 song_playing = 0; //movie will kill sound
845 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
847 while (cfexist(filename))
849 show_title_screen( filename, 1, 0 );
857 songs_play_song( SONG_TITLE, 1);
861 PA_DFX (pa_splash());
863 con_printf( CON_DEBUG, "\nShowing loading screen..." );
865 //grs_bitmap title_bm;
869 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
870 if (! cfexist(filename))
871 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
872 if (! cfexist(filename))
873 strcpy(filename, "descentd.pcx"); // SHAREWARE
874 if (! cfexist(filename))
875 strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
877 #if defined(POLY_ACC)
878 gr_set_mode(SM_640x480x15xPA);
880 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
883 set_screen_mode(SCREEN_MENU);
886 FontHires = FontHiresAvailable && MenuHires;
888 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
889 //vfx_set_palette_sub( title_pal );
891 gr_palette_fade_in( title_pal, 32, 0 );
893 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
896 con_printf( CON_DEBUG , "\nDoing bm_init..." );
904 if (FindArg("-hoarddata") != 0) {
905 #define MAX_BITMAPS_PER_BRUSH 30
906 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
910 ubyte palette[256*3];
913 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
914 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
915 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
916 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
918 ofile = fopen("hoard.ham","wb");
920 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
921 Assert(iff_error == IFF_NO_ERROR);
922 nframes_short = nframes;
923 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
924 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
925 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
926 fwrite(palette,3,256,ofile);
927 for (i=0;i<nframes;i++)
928 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
930 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
931 Assert(iff_error == IFF_NO_ERROR);
932 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
933 nframes_short = nframes;
934 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
935 fwrite(palette,3,256,ofile);
936 for (i=0;i<nframes;i++)
937 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
940 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
941 Assert(iff_error == IFF_NO_ERROR);
942 fwrite(&icon.bm_w,sizeof(short),1,ofile);
943 fwrite(&icon.bm_h,sizeof(short),1,ofile);
944 fwrite(palette,3,256,ofile);
945 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
948 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
952 ifile = fopen(sounds[i],"rb");
953 Assert(ifile != NULL);
954 size = ffilelength(ifile);
955 buf = d_malloc(size);
956 fread(buf,1,size,ifile);
957 fwrite(&size,sizeof(size),1,ofile);
958 fwrite(buf,1,size,ofile);
969 //the bitmap loading code changes gr_palette, so restore it
970 memcpy(gr_palette,title_pal,sizeof(gr_palette));
972 if ( FindArg( "-norun" ) )
975 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
978 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
979 texmerge_init( 10 ); // 10 cache bitmaps
981 con_printf( CON_DEBUG, "\nRunning game...\n" );
982 set_screen_mode(SCREEN_MENU);
986 // If built with editor, option to auto-load a level and quit game
987 // to write certain data.
990 if ( (t = FindArg( "-autoload" )) ) {
992 strcpy(Auto_file, Args[t+1]);
998 strcpy(Players[0].callsign, "dummy");
1001 do_register_player(title_pal);
1003 gr_palette_fade_out( title_pal, 32, 0 );
1005 Game_mode = GM_GAME_OVER;
1008 newdemo_start_playback("descent.dem");
1009 if (Newdemo_state == ND_STATE_PLAYBACK )
1010 Function_mode = FMODE_GAME;
1013 //do this here because the demo code can do a longjmp when trying to
1014 //autostart a demo from the main menu, never having gone into the game
1017 while (Function_mode != FMODE_EXIT)
1019 switch( Function_mode ) {
1021 set_screen_mode(SCREEN_MENU);
1023 newdemo_start_playback(NULL); // Randomly pick a file
1024 if (Newdemo_state != ND_STATE_PLAYBACK)
1025 Error("No demo files were found for autodemo mode!");
1029 strcpy((char *)&Level_names[0], Auto_file);
1031 Function_mode = FMODE_EXIT;
1036 check_joystick_calibration();
1037 gr_palette_clear(); //I'm not sure why we need this, but we do
1040 if ( Function_mode == FMODE_EDITOR ) {
1042 SetPlayerFromCurseg();
1043 load_palette(NULL,1,0);
1050 keyd_editor_mode = 0;
1054 /* keep the mouse from wandering in SDL */
1055 if (FindArg("-grabmouse"))
1056 SDL_WM_GrabInput(SDL_GRAB_ON);
1062 /* give control back to the WM */
1063 if (FindArg("-grabmouse"))
1064 SDL_WM_GrabInput(SDL_GRAB_OFF);
1067 if ( Function_mode == FMODE_MENU )
1068 songs_play_song( SONG_TITLE, 1 );
1072 keyd_editor_mode = 1;
1075 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1077 if ( Function_mode == FMODE_GAME ) {
1078 Game_mode = GM_EDITOR;
1079 editor_reset_stuff_on_level();
1085 Error("Invalid function mode %d",Function_mode);
1092 if (!FindArg( "-notitles" ))
1097 if ( FindArg( "-showmeminfo" ) )
1098 show_mem_info = 1; // Make memory statistics show
1101 return(0); //presumably successful exit
1105 void check_joystick_calibration() {
1106 int x1, y1, x2, y2, c;
1109 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1110 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1111 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1112 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1115 joy_get_pos( &x1, &y1 );
1117 t1 = timer_get_fixed_seconds();
1118 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1121 joy_get_pos( &x2, &y2 );
1123 // If joystick hasn't moved...
1124 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1125 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1126 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1128 joydefs_calibrate();
1135 void show_order_form()
1140 unsigned char title_pal[768];
1141 char exit_screen[16];
1143 gr_set_current_canvas( NULL );
1148 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1149 if (! cfexist(exit_screen))
1150 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1151 if (! cfexist(exit_screen))
1152 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1153 if (! cfexist(exit_screen))
1154 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1155 if (! cfexist(exit_screen))
1156 return; // D2 registered
1158 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1159 //vfx_set_palette_sub( title_pal );
1160 gr_palette_fade_in( title_pal, 32, 0 );
1162 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1163 gr_palette_fade_out( title_pal, 32, 0 );
1166 Int3(); //can't load order screen
1176 // void network_abort_game();
1177 // if(Network_status)
1178 // network_abort_game();