1 /* $Id: inferno.c,v 1.38 2002-08-06 05:21:33 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * FIXME: put description here
26 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
36 #include <sys/types.h>
42 #include "pa_enabl.h" //$$POLY_ACC
54 #include "segment.h" //for Side_to_verts
97 // # include "3dfx_des.h"
99 //added on 9/30/98 by Matt Mueller for selectable automap modes
103 #include "../texmap/scanline.h" //for select_tmap -MM
105 #if defined(POLY_ACC)
106 #include "poly_acc.h"
107 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
111 #include "editor/editor.h"
112 #include "editor/kdefs.h"
123 void arch_init(void);
124 void arch_init_start(void);
126 //Current version number
128 ubyte Version_major = 1; //FULL VERSION
129 ubyte Version_minor = 2;
131 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
132 char desc_id_exit_num = 0;
134 int Function_mode=FMODE_MENU; //game or editor?
135 int Screen_mode=-1; //game screen or editor screen?
137 //--unused-- grs_bitmap Inferno_bitmap_title;
139 int WVIDEO_running=0; //debugger can set to 1 if running
142 int Inferno_is_800x600_available = 0;
145 //--unused-- int Cyberman_installed=0; // SWIFT device present
146 ubyte CybermouseActive=0;
148 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
150 void check_joystick_calibration(void);
153 //--------------------------------------------------------------------------
155 extern int piggy_low_memory;
158 int descent_critical_error = 0;
159 unsigned descent_critical_deverror = 0;
160 unsigned descent_critical_errcode = 0;
162 extern int Network_allow_socket_changes;
164 extern void vfx_set_palette_sub(ubyte *);
166 extern int VR_low_res;
168 extern int Config_vr_type;
169 extern int Config_vr_resolution;
170 extern int Config_vr_tracking;
171 int grd_fades_disabled=1;
175 //read help from a file & print to screen
176 void print_commandline_help()
182 ifile = cfopen("help.tex","rb");
184 ifile = cfopen("help.txb","rb");
186 Error("Cannot load help text file.");
190 while (cfgets(line,LINE_LEN,ifile)) {
194 for (i = 0; i < strlen(line) - 1; i++) {
195 encode_rotate_left(&(line[i]));
196 line[i] = line[i] ^ BITMAP_TBL_XOR;
197 encode_rotate_left(&(line[i]));
202 continue; //don't show comments
210 // printf( " Diagnostic:\n\n");
211 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
212 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
215 printf( " Editor Options:\n\n");
216 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
217 printf( " -hoarddata %s\n","FIXME: Undocumented");
218 printf( " -macdata %s\n","FIXME: Undocumented");
219 // printf( " -nobm %s\n","FIXME: Undocumented");
222 printf( " D2X Options:\n\n");
223 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
224 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
225 printf( " -notitles %s\n", "Do not show titlescreens on startup");
226 printf( " -ini <file> %s\n", "option file (alternate to command line) defaults to d2x.ini, or d1x.ini");
227 printf( " -autodemo %s\n", "Start in demo mode");
228 printf( " -bigpig %s\n","FIXME: Undocumented");
229 printf( " -bspgen %s\n","FIXME: Undocumented");
230 // printf( " -cdproxy %s\n","FIXME: Undocumented");
232 printf( " -checktime %s\n","FIXME: Undocumented");
233 printf( " -showmeminfo %s\n","FIXME: Undocumented");
235 // printf( " -codereadonly %s\n","FIXME: Undocumented");
236 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
237 printf( " -debug %s\n","Enable very verbose output");
238 // printf( " -debugmode %s\n","FIXME: Undocumented");
239 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
240 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
241 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
242 // printf( " -forcegfx %s\n","FIXME: Undocumented");
244 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
246 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
248 printf( " -invulnerability %s\n","Make yourself invulnerable");
250 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
251 printf( " -jasen %s\n","FIXME: Undocumented");
252 printf( " -joyslow %s\n","FIXME: Undocumented");
253 // printf( " -logfile %s\n","FIXME: Undocumented");
254 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
255 // printf( " -memdbg %s\n","FIXME: Undocumented");
256 // printf( " -monodebug %s\n","FIXME: Undocumented");
257 printf( " -nocdrom %s\n","FIXME: Undocumented");
259 printf( " -nocyberman %s\n","FIXME: Undocumented");
261 printf( " -nofade %s\n","Disable fades");
263 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
264 printf( " -norankings %s\n","Disable multiplayer ranking system");
265 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
266 // printf( " -showaddress %s\n","FIXME: Undocumented");
267 printf( " -socket %s\n","FIXME: Undocumented");
269 #if !defined(MACINTOSH) && !defined(WINDOWS)
270 printf( " -nomixer %s\n","Don't crank music volume");
271 printf( " -superhires %s\n","Allow higher-resolution modes");
273 // printf( " -nomodex %s\n","FIXME: Undocumented");
275 printf( " -nomovies %s\n","Don't play movies");
276 printf( " -noscreens %s\n","Skip briefing screens");
278 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
279 printf( " -noredbook %s\n","Disable redbook audio");
281 printf( " -norun %s\n","Bail out after initialization");
282 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
283 // printf( " -rtscts %s\n","Same as -ctsrts");
284 // printf( " -semiwin %s\n","Use non-fullscreen mode");
285 // printf( " -specialdevice %s\n","FIXME: Undocumented");
287 printf( " -stickmag %s\n","FIXME: Undocumented");
289 // printf( " -stopwatch %s\n","FIXME: Undocumented");
290 printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
291 // printf( " -sysram %s\n","FIXME: Undocumented");
292 printf( " -text <file> %s\n","Specify alternate .tex file");
293 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
294 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
295 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
296 // printf( " -udp %s\n","FIXME: Undocumented");
297 // printf( " -vidram %s\n","FIXME: Undocumented");
298 printf( " -xcontrol %s\n","FIXME: Undocumented");
299 printf( " -xname %s\n","FIXME: Undocumented");
300 printf( " -xver %s\n","FIXME: Undocumented");
301 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
302 printf( " -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
303 printf( " -automap_gameres %s\n","Set automap to use the same resolution as in game");
304 // printf( " -menu<X>x<Y> %s\n","Set menu resolution to <X> by <Y>");
305 // printf( " -menu_gameres %s\n","Set menus to use the same resolution as in game");
308 printf( "D2X System Options:\n\n");
310 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
312 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
313 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
316 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
317 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
318 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
319 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
320 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
321 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
322 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
323 printf( " -gl_voodoo %s\n","force fullscreen mode only");
325 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
326 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
327 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
328 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
329 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
330 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
331 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
332 printf( " -gl_test2 %s\n","FIXME: Undocumented");
333 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
334 #ifdef OGL_RUNTIME_LOAD
335 printf( " -gl_library <l> %s\n","use alternate opengl library");
339 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
340 printf( " -hwsurface %s\n","FIXME: Undocumented");
343 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
344 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
346 printf( "\n Help:\n\n");
347 printf( " -help, -h, -?, ? %s\n", "View this help screen");
351 void do_joystick_init()
355 if (!FindArg( "-nojoystick" )) {
356 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
358 if ( FindArg( "-joyslow" )) {
359 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
360 joy_set_slow_reading(JOY_SLOW_READINGS);
362 if ( FindArg( "-joypolled" )) {
363 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
364 joy_set_slow_reading(JOY_POLLED_READINGS);
366 if ( FindArg( "-joybios" )) {
367 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
368 joy_set_slow_reading(JOY_BIOS_READINGS);
371 // Added from Descent v1.5 by John. Adapted by Samir.
373 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
377 //set this to force game to run in low res
378 int disable_high_res=0;
380 void do_register_player(ubyte *title_pal)
382 Players[Player_num].callsign[0] = '\0';
388 //now, before we bring up the register player menu, we need to
389 //do some stuff to make sure the palette is ok. First, we need to
390 //get our current palette into the 2d's array, so the remapping will
391 //work. Second, we need to remap the fonts. Third, we need to fill
392 //in part of the fade tables so the darkening of the menu edges works
394 memcpy(gr_palette,title_pal,sizeof(gr_palette));
395 remap_fonts_and_menus(1);
396 RegisterPlayer(); //get player's name
402 void do_network_init()
404 if (!FindArg( "-nonetwork" )) {
408 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
409 if ((t=FindArg("-socket")))
410 socket = atoi( Args[t+1] );
411 //@@if ( FindArg("-showaddress") ) showaddress=1;
412 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
413 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
416 switch( ipx_error ) {
417 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
418 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
419 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
421 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
423 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
424 Network_active = 0; // Assume no network
426 ipx_read_user_file( "descent.usr" );
427 ipx_read_network_file( "descent.net" );
428 //@@if ( FindArg( "-dynamicsockets" ))
429 //@@ Network_allow_socket_changes = 1;
431 //@@ Network_allow_socket_changes = 0;
433 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
434 Network_active = 0; // Assume no network
439 #define PROGNAME argv[0]
441 extern char Language[];
443 //can we do highres menus?
444 extern int MenuHiresAvailable;
447 int intro_played = 0;
450 int Inferno_verbose = 0;
452 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
453 int start_net_immediately = 0;
454 //int start_with_mission = 0;
455 //char *start_with_mission_name;
456 //end this section addition
458 int open_movie_file(char *filename,int must_have);
460 #if defined(POLY_ACC)
461 #define MENU_HIRES_MODE SM_640x480x15xPA
463 #define MENU_HIRES_MODE SM(640,480)
466 // DESCENT II by Parallax Software
469 //extern ubyte gr_current_pal[];
473 char Auto_file[128] = "";
476 int main(int argc,char **argv)
479 ubyte title_pal[768];
480 int screen_width = 640;
481 int screen_height = 480;
482 u_int32_t screen_mode = SM(screen_width,screen_height);
484 con_init(); // Initialise the console
487 error_init(NULL, NULL);
491 char *home = getenv("HOME");
494 char buf[PATH_MAX + 5];
497 strcat(buf, "/.d2x");
501 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
507 InitArgs( argc,argv );
509 if (FindArg("-debug"))
510 con_threshold.value = (float)2;
511 else if (FindArg("-verbose"))
512 con_threshold.value = (float)1;
519 //tell cfile where hogdir is
520 cfile_use_alternate_hogdir(SHAREPATH);
523 //tell cfile about our counter
524 cfile_set_critical_error_counter_ptr(&descent_critical_error);
526 if (! cfile_init("descent2.hog"))
527 if (! cfile_init("d2demo.hog"))
528 Error("Could not find a valid hog file (descent2.hog or d2demo.hog)");
531 //print out the banner title
532 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
533 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
534 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
535 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
536 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
539 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
540 print_commandline_help();
541 set_exit_message("");
543 exit(0); /* mingw hangs on this return. dunno why */
548 con_printf(CON_NORMAL, "\n");
549 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
550 con_printf(CON_NORMAL, "\n");
552 //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
554 if ( FindArg( "-autodemo" ))
558 if ( FindArg( "-noscreens" ) )
559 Skip_briefing_screens = 1;
562 if ((t=FindArg("-tmap"))){
563 select_tmap(Args[t+1]);
569 // if (init_graphics()) return 1;
572 if (!Inferno_is_800x600_available) {
573 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
574 Function_mode = FMODE_MENU;
579 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
581 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
588 #if defined(POLY_ACC)
589 Current_display_mode = -1;
590 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
593 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
594 set_display_mode(0); //..then set default display mode
598 //added on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
599 int i, argnum=INT_MAX;
601 int vr_mode = VR_NONE;
602 int screen_compatible = 1;
603 int use_double_buffer = 0;
605 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
606 //added on 9/30/98 by Matt Mueller clean up screen mode code, and add higher resolutions
607 #define SCREENMODE(X,Y,C) if ( (i=FindArg( "-" #X "x" #Y ))&&(i<argnum)) {argnum=i; screen_mode = SM( X , Y ); con_printf(CON_VERBOSE, "Using " #X "x" #Y " ...\n" );screen_width = X;screen_height = Y;use_double_buffer = 1;screen_compatible = C;}
608 //aren't #defines great? :)
610 SCREENMODE(320,100,0);
611 SCREENMODE(320,200,1);
612 //end addition/edit -MM
613 SCREENMODE(320,240,0);
614 SCREENMODE(320,400,0);
615 SCREENMODE(640,400,0);
616 SCREENMODE(640,480,0);
617 SCREENMODE(800,600,0);
618 SCREENMODE(1024,768,0);
619 SCREENMODE(1152,864,0);
620 SCREENMODE(1280,960,0);
621 SCREENMODE(1280,1024,0);
622 SCREENMODE(1600,1200,0);
625 //added ifdefs on 9/30/98 by Matt Mueller to fix high res in linux
627 if ( FindArg( "-nodoublebuffer" ) ) {
628 con_printf(CON_VERBOSE, "Double-buffering disabled...\n" );
630 use_double_buffer = 0;
636 //added 3/24/99 by Owen Evans for screen res changing
637 // Game_Screen_mode = screen_mode;
639 game_init_render_buffers(screen_mode, screen_width, screen_height, vr_mode, screen_compatible);
643 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
644 int i, argnum=INT_MAX;
645 //added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines.
646 #define SMODE(V,VV,VG,X,Y) if ( (i=FindArg( "-" #V #X "x" #Y )) && (i<argnum)) {argnum=i; VV = SM( X , Y );VG=0;}
647 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
648 #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) );
649 //aren't #defines great? :)
650 //end addition/edit -MM
651 #define S_MODE(V,VV,VG) argnum=INT_MAX;SMODE(V,VV,VG,320,200);SMODE(V,VV,VG,320,240);SMODE(V,VV,VG,320,400);SMODE(V,VV,VG,640,400);SMODE(V,VV,VG,640,480);SMODE(V,VV,VG,800,600);SMODE(V,VV,VG,1024,768);SMODE(V,VV,VG,1280,1024);SMODE(V,VV,VG,1600,1200);SMODE_GR(V,VG);SMODE_PRINT(V,VV,VG);
653 S_MODE(automap,automap_mode,automap_use_game_res);
654 // S_MODE(menu,menu_screen_mode,menu_use_game_res);
658 i = FindArg( "-xcontrol" );
660 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
663 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
664 if (FindArg("-nofade"))
665 grd_fades_disabled=1;
667 //determine whether we're using high-res menus & movies
668 #if !defined(POLY_ACC)
669 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
670 MovieHires = MenuHires = MenuHiresAvailable = 0;
673 //NOTE LINK TO ABOVE!
674 MenuHires = MenuHiresAvailable = 1;
676 if ((t=gr_init())!=0) //doesn't do much
677 Error(TXT_CANT_INIT_GFX,t);
683 // Load the palette stuff. Returns non-zero if error.
684 con_printf(CON_DEBUG, "\nInitializing palette system..." );
685 gr_use_palette_table(DEFAULT_PALETTE );
687 con_printf(CON_DEBUG, "\nInitializing font system..." );
688 gamefont_init(); // must load after palette data loaded.
690 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
691 init_movies(); //init movie libraries
694 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
695 #if defined(POLY_ACC)
696 gr_set_mode(SM_640x480x15xPA);
698 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
703 if ( FindArg( "-notitles" ) )
704 songs_play_song( SONG_TITLE, 1);
707 { //NOTE LINK TO ABOVE!
709 int played=MOVIE_NOT_PLAYED; //default is not played
711 int song_playing = 0;
714 #define MOVIE_REQUIRED 0
716 #define MOVIE_REQUIRED 1
719 #ifdef D2_OEM //$$POLY_ACC, jay.
720 { //show bundler screens
722 char filename[FILENAME_LEN];
724 played=MOVIE_NOT_PLAYED; //default is not played
726 played = PlayMovie("pre_i.mve",0);
729 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
731 while ((tfile=fopen(filename,"rb")) != NULL) {
733 show_title_screen( filename, 1, 0 );
741 init_subtitles("intro.tex");
742 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
747 if (played != MOVIE_NOT_PLAYED)
749 else { //didn't get intro movie, try titles
751 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
753 if (played == MOVIE_NOT_PLAYED) {
754 #if defined(POLY_ACC)
755 gr_set_mode(SM_640x480x15xPA);
757 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
759 con_printf( CON_DEBUG, "\nPlaying title song..." );
760 songs_play_song( SONG_TITLE, 1);
762 con_printf( CON_DEBUG, "\nShowing logo screens..." );
763 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
764 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
768 { //show bundler movie or screens
771 char filename[FILENAME_LEN];
774 played=MOVIE_NOT_PLAYED; //default is not played
776 //check if OEM movie exists, so we don't stop the music if it doesn't
777 movie_handle = open_movie_file("oem.mve",0);
778 if (movie_handle != -1) {
780 played = PlayMovie("oem.mve",0);
781 song_playing = 0; //movie will kill sound
785 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
787 while ((tfile=fopen(filename,"rb")) != NULL) {
789 show_title_screen( filename, 1, 0 );
797 songs_play_song( SONG_TITLE, 1);
801 PA_DFX (pa_splash());
803 con_printf( CON_DEBUG, "\nShowing loading screen..." );
805 //grs_bitmap title_bm;
809 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
810 if (! cfexist(filename))
811 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
812 if (! cfexist(filename))
813 strcpy(filename, "descentd.pcx"); // SHAREWARE
815 #if defined(POLY_ACC)
816 gr_set_mode(SM_640x480x15xPA);
818 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
821 FontHires = FontHiresAvailable && MenuHires;
823 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE) {
824 //vfx_set_palette_sub( title_pal );
826 gr_palette_fade_in( title_pal, 32, 0 );
828 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
831 con_printf( CON_DEBUG , "\nDoing bm_init..." );
839 if (FindArg("-hoarddata") != 0) {
840 #define MAX_BITMAPS_PER_BRUSH 30
841 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
845 ubyte palette[256*3];
848 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
849 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
850 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
851 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
853 ofile = fopen("hoard.ham","wb");
855 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
856 Assert(iff_error == IFF_NO_ERROR);
857 nframes_short = nframes;
858 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
859 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
860 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
861 fwrite(palette,3,256,ofile);
862 for (i=0;i<nframes;i++)
863 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
865 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
866 Assert(iff_error == IFF_NO_ERROR);
867 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
868 nframes_short = nframes;
869 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
870 fwrite(palette,3,256,ofile);
871 for (i=0;i<nframes;i++)
872 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
875 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
876 Assert(iff_error == IFF_NO_ERROR);
877 fwrite(&icon.bm_w,sizeof(short),1,ofile);
878 fwrite(&icon.bm_h,sizeof(short),1,ofile);
879 fwrite(palette,3,256,ofile);
880 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
883 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
887 ifile = fopen(sounds[i],"rb");
888 Assert(ifile != NULL);
889 size = ffilelength(ifile);
890 buf = d_malloc(size);
891 fread(buf,1,size,ifile);
892 fwrite(&size,sizeof(size),1,ofile);
893 fwrite(buf,1,size,ofile);
904 //the bitmap loading code changes gr_palette, so restore it
905 memcpy(gr_palette,title_pal,sizeof(gr_palette));
907 if ( FindArg( "-norun" ) )
910 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
913 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
914 texmerge_init( 10 ); // 10 cache bitmaps
916 con_printf( CON_DEBUG, "\nRunning game...\n" );
917 set_screen_mode(SCREEN_MENU);
921 // If built with editor, option to auto-load a level and quit game
922 // to write certain data.
925 if ( (t = FindArg( "-autoload" )) ) {
927 strcpy(Auto_file, Args[t+1]);
933 strcpy(Players[0].callsign, "dummy");
936 do_register_player(title_pal);
938 gr_palette_fade_out( title_pal, 32, 0 );
940 Game_mode = GM_GAME_OVER;
943 newdemo_start_playback("descent.dem");
944 if (Newdemo_state == ND_STATE_PLAYBACK )
945 Function_mode = FMODE_GAME;
948 //do this here because the demo code can do a longjmp when trying to
949 //autostart a demo from the main menu, never having gone into the game
952 while (Function_mode != FMODE_EXIT)
954 switch( Function_mode ) {
956 set_screen_mode(SCREEN_MENU);
958 newdemo_start_playback(NULL); // Randomly pick a file
959 if (Newdemo_state != ND_STATE_PLAYBACK)
960 Error("No demo files were found for autodemo mode!");
964 strcpy((char *)&Level_names[0], Auto_file);
966 Function_mode = FMODE_EXIT;
971 check_joystick_calibration();
972 gr_palette_clear(); //I'm not sure why we need this, but we do
975 if ( Function_mode == FMODE_EDITOR ) {
977 SetPlayerFromCurseg();
978 load_palette(NULL,1,0);
985 keyd_editor_mode = 0;
989 /* keep the mouse from wandering in SDL */
990 if (FindArg("-grabmouse"))
991 SDL_WM_GrabInput(SDL_GRAB_ON);
997 /* give control back to the WM */
998 if (FindArg("-grabmouse"))
999 SDL_WM_GrabInput(SDL_GRAB_OFF);
1002 if ( Function_mode == FMODE_MENU )
1003 songs_play_song( SONG_TITLE, 1 );
1007 keyd_editor_mode = 1;
1010 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1012 if ( Function_mode == FMODE_GAME ) {
1013 Game_mode = GM_EDITOR;
1014 editor_reset_stuff_on_level();
1020 Error("Invalid function mode %d",Function_mode);
1028 if (!FindArg( "-notitles" ))
1033 if ( FindArg( "-showmeminfo" ) )
1034 show_mem_info = 1; // Make memory statistics show
1037 return(0); //presumably successful exit
1041 void check_joystick_calibration() {
1042 int x1, y1, x2, y2, c;
1045 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1046 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1047 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1048 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1051 joy_get_pos( &x1, &y1 );
1053 t1 = timer_get_fixed_seconds();
1054 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1057 joy_get_pos( &x2, &y2 );
1059 // If joystick hasn't moved...
1060 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1061 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1062 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1064 joydefs_calibrate();
1071 void show_order_form()
1073 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1076 char title_pal[768];
1077 char exit_screen[16];
1079 gr_set_current_canvas( NULL );
1085 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1087 #if defined(SHAREWARE)
1088 strcpy(exit_screen, "orderd2.pcx");
1090 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1094 if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1095 //vfx_set_palette_sub( title_pal );
1096 gr_palette_fade_in( title_pal, 32, 0 );
1098 gr_palette_fade_out( title_pal, 32, 0 );
1101 Int3(); //can't load order screen
1111 // void network_abort_game();
1112 // if(Network_status)
1113 // network_abort_game();