2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/main/inferno.c,v $
18 * $Date: 2002-02-13 10:39:21 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.23 2002/02/02 23:30:26 bradleyb
24 * Enabled RELEASE option
26 * Revision 1.22 2002/01/29 10:11:56 bradleyb
27 * update copyright date
29 * Revision 1.21 2002/01/29 00:08:13 bradleyb
32 * Revision 1.20 2002/01/28 00:03:47 bradleyb
33 * Data files now go in DATADIR/games/d2x, user files now go in ~/.d2x
35 * Revision 1.19 2002/01/18 07:01:37 bradleyb
38 * Revision 1.18 2001/12/28 09:26:41 bradleyb
39 * document -nomovies option
41 * Revision 1.17 2001/11/09 06:55:08 bradleyb
44 * Revision 1.16 2001/11/08 10:30:28 bradleyb
45 * Enabled shareware build, endlevel flythrough sequence
47 * Revision 1.15 2001/11/05 07:39:08 bradleyb
48 * Change args_init back to InitArgs
50 * Revision 1.14 2001/11/04 09:01:41 bradleyb
51 * SDL applies to more than X11...
53 * Revision 1.13 2001/10/31 07:41:54 bradleyb
56 * Revision 1.12 2001/10/27 01:39:23 bradleyb
57 * added some documentation
59 * Revision 1.11 2001/10/25 09:12:16 bradleyb
60 * Completed tmap selection code.
62 * Revision 1.10 2001/10/25 02:19:31 bradleyb
63 * conditionalize including multi.h and network.h, fix backslashes, fix compiler errors with EDITOR
65 * Revision 1.9 2001/10/19 08:08:50 bradleyb
66 * conditionalize conf.h
68 * Revision 1.8 2001/10/19 00:31:51 bradleyb
69 * Trying to get network working on win32
71 * Revision 1.7 2001/10/18 00:01:01 bradleyb
72 * RCS headers added/changed
81 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
91 #include <sys/types.h>
97 #include "pa_enabl.h" //$$POLY_ACC
109 #include "segment.h" //for Side_to_verts
111 #include "segpoint.h"
114 #include "texmerge.h"
134 #include "gamefont.h"
152 // # include "3dfx_des.h"
154 #include "../texmap/scanline.h" //for select_tmap -MM
156 #if defined(POLY_ACC)
157 #include "poly_acc.h"
158 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
162 #include "editor/editor.h"
163 #include "editor/kdefs.h"
174 void arch_init(void);
175 void arch_init_start(void);
177 //Current version number
179 ubyte Version_major = 1; //FULL VERSION
180 ubyte Version_minor = 2;
182 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
183 char desc_id_exit_num = 0;
185 int Function_mode=FMODE_MENU; //game or editor?
186 int Screen_mode=-1; //game screen or editor screen?
188 //--unused-- grs_bitmap Inferno_bitmap_title;
190 int WVIDEO_running=0; //debugger can set to 1 if running
193 int Inferno_is_800x600_available = 0;
196 //--unused-- int Cyberman_installed=0; // SWIFT device present
197 ubyte CybermouseActive=0;
199 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
201 void check_joystick_calibration(void);
204 //--------------------------------------------------------------------------
206 extern int piggy_low_memory;
209 int descent_critical_error = 0;
210 unsigned descent_critical_deverror = 0;
211 unsigned descent_critical_errcode = 0;
213 extern int Network_allow_socket_changes;
215 extern void vfx_set_palette_sub(ubyte *);
217 extern int VR_low_res;
219 extern int Config_vr_type;
220 extern int Config_vr_resolution;
221 extern int Config_vr_tracking;
222 int grd_fades_disabled=1;
226 //read help from a file & print to screen
227 void print_commandline_help()
233 ifile = cfopen("help.tex","rb");
235 ifile = cfopen("help.txb","rb");
237 Error("Cannot load help text file.");
241 while (cfgets(line,LINE_LEN,ifile)) {
245 for (i = 0; i < strlen(line) - 1; i++) {
246 encode_rotate_left(&(line[i]));
247 line[i] = line[i] ^ BITMAP_TBL_XOR;
248 encode_rotate_left(&(line[i]));
253 continue; //don't show comments
261 // printf( " Diagnostic:\n\n");
262 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
263 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
266 printf( " Editor Options:\n\n");
267 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
268 printf( " -hoarddata %s\n","FIXME: Undocumented");
269 printf( " -macdata %s\n","FIXME: Undocumented");
270 // printf( " -nobm %s\n","FIXME: Undocumented");
273 printf( " D2X Options:\n\n");
274 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
275 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
276 printf( " -notitles %s\n", "Do not show titlescreens on startup");
277 printf( " -ini <file> %s\n", "option file (alternate to command line) defaults to d2x.ini, or d1x.ini");
278 printf( " -autodemo %s\n", "Start in demo mode");
279 printf( " -bigpig %s\n","FIXME: Undocumented");
280 printf( " -bspgen %s\n","FIXME: Undocumented");
281 // printf( " -cdproxy %s\n","FIXME: Undocumented");
283 printf( " -checktime %s\n","FIXME: Undocumented");
284 printf( " -showmeminfo %s\n","FIXME: Undocumented");
286 // printf( " -codereadonly %s\n","FIXME: Undocumented");
287 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
288 printf( " -debug %s\n","Enable very verbose output");
289 // printf( " -debugmode %s\n","FIXME: Undocumented");
290 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
291 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
292 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
293 // printf( " -forcegfx %s\n","FIXME: Undocumented");
295 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
297 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
299 printf( " -invulnerability %s\n","Make yourself invulnerable");
301 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
302 printf( " -jasen %s\n","FIXME: Undocumented");
303 printf( " -joyslow %s\n","FIXME: Undocumented");
304 // printf( " -logfile %s\n","FIXME: Undocumented");
305 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
306 // printf( " -memdbg %s\n","FIXME: Undocumented");
307 // printf( " -monodebug %s\n","FIXME: Undocumented");
308 #if defined(__DJGPP__) || defined(__SDL__)
309 printf( " -nocdrom %s\n","FIXME: Undocumented");
312 printf( " -nocyberman %s\n","FIXME: Undocumented");
314 printf( " -nofade %s\n","Disable fades");
316 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
317 printf( " -norankings %s\n","Disable multiplayer ranking system");
318 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
319 // printf( " -showaddress %s\n","FIXME: Undocumented");
320 printf( " -socket %s\n","FIXME: Undocumented");
322 #if !defined(MACINTOSH) && !defined(WINDOWS)
323 printf( " -nomixer %s\n","Don't crank music volume");
324 printf( " -superhires %s\n","Allow higher-resolution modes");
326 // printf( " -nomodex %s\n","FIXME: Undocumented");
328 printf( " -nomovies %s\n","Don't play movies");
329 printf( " -noscreens %s\n","Skip briefing screens");
331 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
332 printf( " -noredbook %s\n","Disable redbook audio");
334 printf( " -norun %s\n","Bail out after initialization");
335 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
336 // printf( " -rtscts %s\n","Same as -ctsrts");
337 // printf( " -semiwin %s\n","Use non-fullscreen mode");
338 // printf( " -specialdevice %s\n","FIXME: Undocumented");
340 printf( " -stickmag %s\n","FIXME: Undocumented");
342 // printf( " -stopwatch %s\n","FIXME: Undocumented");
343 // printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
344 // printf( " -sysram %s\n","FIXME: Undocumented");
345 printf( " -text <file> %s\n","Specify alternate .tex file");
346 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
347 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
348 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
349 // printf( " -udp %s\n","FIXME: Undocumented");
350 // printf( " -vidram %s\n","FIXME: Undocumented");
351 printf( " -xcontrol %s\n","FIXME: Undocumented");
352 printf( " -xname %s\n","FIXME: Undocumented");
353 printf( " -xver %s\n","FIXME: Undocumented");
354 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
357 printf( "D2X System Options:\n\n");
359 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
361 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
362 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
365 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
366 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
367 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
368 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
369 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
370 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
371 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
372 printf( " -gl_voodoo %s\n","force fullscreen mode only");
374 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
375 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
376 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
377 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
378 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
379 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
380 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
381 printf( " -gl_test2 %s\n","FIXME: Undocumented");
382 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
383 #ifdef OGL_RUNTIME_LOAD
384 printf( " -gl_library <l> %s\n","use alternate opengl library");
388 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
389 printf( " -hwsurface %s\n","FIXME: Undocumented");
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()
404 if (!FindArg( "-nojoystick" )) {
405 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
407 if ( FindArg( "-joyslow" )) {
408 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
409 joy_set_slow_reading(JOY_SLOW_READINGS);
411 if ( FindArg( "-joypolled" )) {
412 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
413 joy_set_slow_reading(JOY_POLLED_READINGS);
415 if ( FindArg( "-joybios" )) {
416 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
417 joy_set_slow_reading(JOY_BIOS_READINGS);
420 // Added from Descent v1.5 by John. Adapted by Samir.
422 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
426 //set this to force game to run in low res
427 int disable_high_res=0;
429 void do_register_player(ubyte *title_pal)
431 Players[Player_num].callsign[0] = '\0';
437 //now, before we bring up the register player menu, we need to
438 //do some stuff to make sure the palette is ok. First, we need to
439 //get our current palette into the 2d's array, so the remapping will
440 //work. Second, we need to remap the fonts. Third, we need to fill
441 //in part of the fade tables so the darkening of the menu edges works
443 memcpy(gr_palette,title_pal,sizeof(gr_palette));
444 remap_fonts_and_menus(1);
445 RegisterPlayer(); //get player's name
451 void do_network_init()
453 if (!FindArg( "-nonetwork" )) {
457 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
458 if ((t=FindArg("-socket")))
459 socket = atoi( Args[t+1] );
460 //@@if ( FindArg("-showaddress") ) showaddress=1;
461 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
462 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
465 switch( ipx_error ) {
466 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
467 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
468 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
470 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
472 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
473 Network_active = 0; // Assume no network
475 ipx_read_user_file( "descent.usr" );
476 ipx_read_network_file( "descent.net" );
477 //@@if ( FindArg( "-dynamicsockets" ))
478 //@@ Network_allow_socket_changes = 1;
480 //@@ Network_allow_socket_changes = 0;
482 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
483 Network_active = 0; // Assume no network
488 #define PROGNAME argv[0]
490 extern char Language[];
492 //can we do highres menus?
493 extern int MenuHiresAvailable;
496 int intro_played = 0;
499 int Inferno_verbose = 0;
501 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
502 int start_net_immediately = 0;
503 //int start_with_mission = 0;
504 //char *start_with_mission_name;
505 //end this section addition
507 int open_movie_file(char *filename,int must_have);
509 #if defined(POLY_ACC)
510 #define MENU_HIRES_MODE SM_640x480x15xPA
512 #define MENU_HIRES_MODE SM(640,480)
515 // DESCENT II by Parallax Software
518 //extern ubyte gr_current_pal[];
522 char Auto_file[128] = "";
525 int main(int argc,char **argv)
528 ubyte title_pal[768];
530 con_init(); // Initialise the console
533 error_init(NULL, NULL);
537 char *home = getenv("HOME");
540 char buf[PATH_MAX + 5];
543 strcat(buf, "/.d2x");
547 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
553 InitArgs( argc,argv );
555 if ( FindArg( "-debug") )
557 con_threshold.value = (float)2;
560 if ( FindArg( "-verbose" ) )
562 con_threshold.value = (float)1;
569 //tell cfile where hogdir is
570 cfile_use_alternate_hogdir(SHAREPATH);
572 //tell cfile about our counter
573 cfile_set_critical_error_counter_ptr(&descent_critical_error);
576 cfile_init("d2demo.hog"); //specify name of hogfile
578 #define HOGNAME "descent2.hog"
579 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
581 Error("Could not find required file <%s>",HOGNAME);
588 //print out the banner title
589 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
590 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
591 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
592 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
593 con_printf(CON_NORMAL, " Copyright (c) 2002 Bradley Bell\n");
596 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
597 print_commandline_help();
598 set_exit_message("");
600 exit(0); /* mingw hangs on this return. dunno why */
605 con_printf(CON_NORMAL, "\n");
606 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
607 con_printf(CON_NORMAL, "\n");
609 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
611 if ( FindArg( "-autodemo" ))
615 if ( FindArg( "-noscreens" ) )
616 Skip_briefing_screens = 1;
619 if ((t=FindArg("-tmap"))){
620 select_tmap(Args[t+1]);
626 // if (init_graphics()) return 1;
629 if (!Inferno_is_800x600_available) {
630 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
631 Function_mode = FMODE_MENU;
636 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
638 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
645 #if defined(POLY_ACC)
646 Current_display_mode = -1;
647 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
650 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
651 set_display_mode(0); //..then set default display mode
654 i = FindArg( "-xcontrol" );
656 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
659 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
660 if (FindArg("-nofade"))
661 grd_fades_disabled=1;
663 if ((t=gr_init())!=0) //doesn't do much
664 Error(TXT_CANT_INIT_GFX,t);
670 // Load the palette stuff. Returns non-zero if error.
671 con_printf(CON_DEBUG, "\nInitializing palette system..." );
672 gr_use_palette_table(DEFAULT_PALETTE );
674 con_printf(CON_DEBUG, "\nInitializing font system..." );
675 gamefont_init(); // must load after palette data loaded.
677 //determine whether we're using high-res menus & movies
678 #if !defined(POLY_ACC)
679 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
680 MovieHires = MenuHires = MenuHiresAvailable = 0;
683 //NOTE LINK TO ABOVE!
684 MenuHires = MenuHiresAvailable = 1;
686 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
687 init_movies(); //init movie libraries
689 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
690 #if defined(POLY_ACC)
691 gr_set_mode(SM_640x480x15xPA);
693 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
697 if ( FindArg( "-notitles" ) )
698 songs_play_song( SONG_TITLE, 1);
701 { //NOTE LINK TO ABOVE!
703 int played=MOVIE_NOT_PLAYED; //default is not played
705 int song_playing = 0;
708 #define MOVIE_REQUIRED 0
710 #define MOVIE_REQUIRED 1
713 #ifdef D2_OEM //$$POLY_ACC, jay.
714 { //show bundler screens
716 char filename[FILENAME_LEN];
718 played=MOVIE_NOT_PLAYED; //default is not played
720 played = PlayMovie("pre_i.mve",0);
723 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
725 while ((tfile=fopen(filename,"rb")) != NULL) {
727 show_title_screen( filename, 1, 0 );
735 init_subtitles("intro.tex");
736 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
741 if (played != MOVIE_NOT_PLAYED)
743 else { //didn't get intro movie, try titles
745 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
747 if (played == MOVIE_NOT_PLAYED) {
748 #if defined(POLY_ACC)
749 gr_set_mode(SM_640x480x15xPA);
751 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
753 con_printf( CON_DEBUG, "\nPlaying title song..." );
754 songs_play_song( SONG_TITLE, 1);
756 con_printf( CON_DEBUG, "\nShowing logo screens..." );
757 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
758 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
762 { //show bundler movie or screens
765 char filename[FILENAME_LEN];
768 played=MOVIE_NOT_PLAYED; //default is not played
770 //check if OEM movie exists, so we don't stop the music if it doesn't
771 movie_handle = open_movie_file("oem.mve",0);
772 if (movie_handle != -1) {
774 played = PlayMovie("oem.mve",0);
775 song_playing = 0; //movie will kill sound
779 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
781 while ((tfile=fopen(filename,"rb")) != NULL) {
783 show_title_screen( filename, 1, 0 );
791 songs_play_song( SONG_TITLE, 1);
795 PA_DFX (pa_splash());
797 con_printf( CON_DEBUG, "\nShowing loading screen..." );
799 //grs_bitmap title_bm;
804 strcpy(filename, "descentd.pcx");
807 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
809 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
813 #if defined(POLY_ACC)
814 gr_set_mode(SM_640x480x15xPA);
816 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
819 FontHires = MenuHires;
821 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
822 //vfx_set_palette_sub( title_pal );
824 gr_palette_fade_in( title_pal, 32, 0 );
826 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
829 con_printf( CON_DEBUG , "\nDoing bm_init..." );
837 if (FindArg("-hoarddata") != 0) {
838 #define MAX_BITMAPS_PER_BRUSH 30
839 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
843 ubyte palette[256*3];
846 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
847 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
848 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
849 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
851 ofile = fopen("hoard.ham","wb");
853 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
854 Assert(iff_error == IFF_NO_ERROR);
855 nframes_short = nframes;
856 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
857 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
858 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
859 fwrite(palette,3,256,ofile);
860 for (i=0;i<nframes;i++)
861 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
863 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
864 Assert(iff_error == IFF_NO_ERROR);
865 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
866 nframes_short = nframes;
867 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
868 fwrite(palette,3,256,ofile);
869 for (i=0;i<nframes;i++)
870 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
873 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
874 Assert(iff_error == IFF_NO_ERROR);
875 fwrite(&icon.bm_w,sizeof(short),1,ofile);
876 fwrite(&icon.bm_h,sizeof(short),1,ofile);
877 fwrite(palette,3,256,ofile);
878 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
881 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
885 ifile = fopen(sounds[i],"rb");
886 Assert(ifile != NULL);
887 size = ffilelength(ifile);
888 buf = d_malloc(size);
889 fread(buf,1,size,ifile);
890 fwrite(&size,sizeof(size),1,ofile);
891 fwrite(buf,1,size,ofile);
902 //the bitmap loading code changes gr_palette, so restore it
903 memcpy(gr_palette,title_pal,sizeof(gr_palette));
905 if ( FindArg( "-norun" ) )
908 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
911 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
912 texmerge_init( 10 ); // 10 cache bitmaps
914 con_printf( CON_DEBUG, "\nRunning game...\n" );
915 set_screen_mode(SCREEN_MENU);
919 // If built with editor, option to auto-load a level and quit game
920 // to write certain data.
923 if ( (t = FindArg( "-autoload" )) ) {
925 strcpy(Auto_file, Args[t+1]);
931 strcpy(Players[0].callsign, "dummy");
934 do_register_player(title_pal);
936 gr_palette_fade_out( title_pal, 32, 0 );
938 Game_mode = GM_GAME_OVER;
941 newdemo_start_playback("descent.dem");
942 if (Newdemo_state == ND_STATE_PLAYBACK )
943 Function_mode = FMODE_GAME;
946 //do this here because the demo code can do a longjmp when trying to
947 //autostart a demo from the main menu, never having gone into the game
950 while (Function_mode != FMODE_EXIT)
952 switch( Function_mode ) {
954 set_screen_mode(SCREEN_MENU);
956 newdemo_start_playback(NULL); // Randomly pick a file
957 if (Newdemo_state != ND_STATE_PLAYBACK)
958 Error("No demo files were found for autodemo mode!");
962 strcpy((char *)&Level_names[0], Auto_file);
964 Function_mode = FMODE_EXIT;
969 check_joystick_calibration();
970 gr_palette_clear(); //I'm not sure why we need this, but we do
973 if ( Function_mode == FMODE_EDITOR ) {
975 SetPlayerFromCurseg();
976 load_palette(NULL,1,0);
983 keyd_editor_mode = 0;
987 /* keep the mouse from wandering in SDL */
988 if (FindArg("-grabmouse"))
989 SDL_WM_GrabInput(SDL_GRAB_ON);
996 /* give control back to the WM */
997 if (FindArg("-grabmouse"))
998 SDL_WM_GrabInput(SDL_GRAB_OFF);
1001 if ( Function_mode == FMODE_MENU )
1002 songs_play_song( SONG_TITLE, 1 );
1006 keyd_editor_mode = 1;
1009 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
1011 if ( Function_mode == FMODE_GAME ) {
1012 Game_mode = GM_EDITOR;
1013 editor_reset_stuff_on_level();
1019 Error("Invalid function mode %d",Function_mode);
1027 if (!FindArg( "-notitles" ))
1032 if ( FindArg( "-showmeminfo" ) )
1033 show_mem_info = 1; // Make memory statistics show
1036 return(0); //presumably successful exit
1040 void check_joystick_calibration() {
1041 int x1, y1, x2, y2, c;
1044 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1045 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1046 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1047 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1050 joy_get_pos( &x1, &y1 );
1052 t1 = timer_get_fixed_seconds();
1053 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1056 joy_get_pos( &x2, &y2 );
1058 // If joystick hasn't moved...
1059 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1060 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1061 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1063 joydefs_calibrate();
1070 void show_order_form()
1072 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1075 char title_pal[768];
1076 char exit_screen[16];
1078 gr_set_current_canvas( NULL );
1084 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1086 #if defined(SHAREWARE)
1087 strcpy(exit_screen, "orderd2.pcx");
1089 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1093 if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
1094 //vfx_set_palette_sub( title_pal );
1095 gr_palette_fade_in( title_pal, 32, 0 );
1097 gr_palette_fade_out( title_pal, 32, 0 );
1100 Int3(); //can't load order screen
1110 // void network_abort_game();
1111 // if(Network_status)
1112 // network_abort_game();