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-01-29 00:08:13 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.20 2002/01/28 00:03:47 bradleyb
24 * Data files now go in DATADIR/games/d2x, user files now go in ~/.d2x
26 * Revision 1.19 2002/01/18 07:01:37 bradleyb
29 * Revision 1.18 2001/12/28 09:26:41 bradleyb
30 * document -nomovies option
32 * Revision 1.17 2001/11/09 06:55:08 bradleyb
35 * Revision 1.16 2001/11/08 10:30:28 bradleyb
36 * Enabled shareware build, endlevel flythrough sequence
38 * Revision 1.15 2001/11/05 07:39:08 bradleyb
39 * Change args_init back to InitArgs
41 * Revision 1.14 2001/11/04 09:01:41 bradleyb
42 * SDL applies to more than X11...
44 * Revision 1.13 2001/10/31 07:41:54 bradleyb
47 * Revision 1.12 2001/10/27 01:39:23 bradleyb
48 * added some documentation
50 * Revision 1.11 2001/10/25 09:12:16 bradleyb
51 * Completed tmap selection code.
53 * Revision 1.10 2001/10/25 02:19:31 bradleyb
54 * conditionalize including multi.h and network.h, fix backslashes, fix compiler errors with EDITOR
56 * Revision 1.9 2001/10/19 08:08:50 bradleyb
57 * conditionalize conf.h
59 * Revision 1.8 2001/10/19 00:31:51 bradleyb
60 * Trying to get network working on win32
62 * Revision 1.7 2001/10/18 00:01:01 bradleyb
63 * RCS headers added/changed
72 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
82 #include <sys/types.h>
88 #include "pa_enabl.h" //$$POLY_ACC
100 #include "segment.h" //for Side_to_verts
102 #include "segpoint.h"
105 #include "texmerge.h"
125 #include "gamefont.h"
143 // # include "3dfx_des.h"
145 #include "../texmap/scanline.h" //for select_tmap -MM
147 #if defined(POLY_ACC)
148 #include "poly_acc.h"
149 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
153 #include "editor/editor.h"
154 #include "editor/kdefs.h"
165 void arch_init(void);
166 void arch_init_start(void);
168 //Current version number
170 ubyte Version_major = 1; //FULL VERSION
171 ubyte Version_minor = 2;
173 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
174 char desc_id_exit_num = 0;
176 int Function_mode=FMODE_MENU; //game or editor?
177 int Screen_mode=-1; //game screen or editor screen?
179 //--unused-- grs_bitmap Inferno_bitmap_title;
181 int WVIDEO_running=0; //debugger can set to 1 if running
184 int Inferno_is_800x600_available = 0;
187 //--unused-- int Cyberman_installed=0; // SWIFT device present
188 ubyte CybermouseActive=0;
190 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
192 void check_joystick_calibration(void);
195 //--------------------------------------------------------------------------
197 extern int piggy_low_memory;
200 int descent_critical_error = 0;
201 unsigned descent_critical_deverror = 0;
202 unsigned descent_critical_errcode = 0;
204 extern int Network_allow_socket_changes;
206 extern void vfx_set_palette_sub(ubyte *);
208 extern int VR_low_res;
210 extern int Config_vr_type;
211 extern int Config_vr_resolution;
212 extern int Config_vr_tracking;
213 int grd_fades_disabled=1;
217 //read help from a file & print to screen
218 void print_commandline_help()
224 ifile = cfopen("help.tex","rb");
226 ifile = cfopen("help.txb","rb");
228 Error("Cannot load help text file.");
232 while (cfgets(line,LINE_LEN,ifile)) {
236 for (i = 0; i < strlen(line) - 1; i++) {
237 encode_rotate_left(&(line[i]));
238 line[i] = line[i] ^ BITMAP_TBL_XOR;
239 encode_rotate_left(&(line[i]));
244 continue; //don't show comments
252 // printf( " Diagnostic:\n\n");
253 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
254 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
257 printf( " Editor Options:\n\n");
258 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
259 printf( " -hoarddata %s\n","FIXME: Undocumented");
260 printf( " -macdata %s\n","FIXME: Undocumented");
261 // printf( " -nobm %s\n","FIXME: Undocumented");
264 printf( " D2X Options:\n\n");
265 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
266 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
267 printf( " -notitles %s\n", "Do not show titlescreens on startup");
268 printf( " -ini <file> %s\n", "option file (alternate to command line) defaults to d2x.ini, or d1x.ini");
269 printf( " -autodemo %s\n", "Start in demo mode");
270 printf( " -bigpig %s\n","FIXME: Undocumented");
271 printf( " -bspgen %s\n","FIXME: Undocumented");
272 // printf( " -cdproxy %s\n","FIXME: Undocumented");
274 printf( " -checktime %s\n","FIXME: Undocumented");
275 printf( " -showmeminfo %s\n","FIXME: Undocumented");
277 // printf( " -codereadonly %s\n","FIXME: Undocumented");
278 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
279 printf( " -debug %s\n","Enable very verbose output");
280 // printf( " -debugmode %s\n","FIXME: Undocumented");
281 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
282 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
283 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
284 // printf( " -forcegfx %s\n","FIXME: Undocumented");
286 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
288 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
290 printf( " -invulnerability %s\n","Make yourself invulnerable");
292 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
293 printf( " -jasen %s\n","FIXME: Undocumented");
294 printf( " -joyslow %s\n","FIXME: Undocumented");
295 // printf( " -logfile %s\n","FIXME: Undocumented");
296 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
297 // printf( " -memdbg %s\n","FIXME: Undocumented");
298 // printf( " -monodebug %s\n","FIXME: Undocumented");
299 #if defined(__DJGPP__) || defined(__SDL__)
300 printf( " -nocdrom %s\n","FIXME: Undocumented");
303 printf( " -nocyberman %s\n","FIXME: Undocumented");
305 printf( " -nofade %s\n","Disable fades");
307 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
308 printf( " -norankings %s\n","Disable multiplayer ranking system");
309 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
310 // printf( " -showaddress %s\n","FIXME: Undocumented");
311 printf( " -socket %s\n","FIXME: Undocumented");
313 #if !defined(MACINTOSH) && !defined(WINDOWS)
314 printf( " -nomixer %s\n","Don't crank music volume");
315 printf( " -superhires %s\n","Allow higher-resolution modes");
317 // printf( " -nomodex %s\n","FIXME: Undocumented");
319 printf( " -nomovies %s\n","Don't play movies");
321 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
322 printf( " -noredbook %s\n","Disable redbook audio");
324 printf( " -norun %s\n","Bail out after initialization");
325 printf( " -noscreens %s\n","Skip briefing screens");
326 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
327 // printf( " -rtscts %s\n","Same as -ctsrts");
328 // printf( " -semiwin %s\n","Use non-fullscreen mode");
329 // printf( " -specialdevice %s\n","FIXME: Undocumented");
331 printf( " -stickmag %s\n","FIXME: Undocumented");
333 // printf( " -stopwatch %s\n","FIXME: Undocumented");
334 // printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
335 // printf( " -sysram %s\n","FIXME: Undocumented");
336 printf( " -text <file> %s\n","Specify alternate .tex file");
337 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
338 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
339 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
340 // printf( " -udp %s\n","FIXME: Undocumented");
341 // printf( " -vidram %s\n","FIXME: Undocumented");
342 printf( " -xcontrol %s\n","FIXME: Undocumented");
343 printf( " -xname %s\n","FIXME: Undocumented");
344 printf( " -xver %s\n","FIXME: Undocumented");
345 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
348 printf( "D2X System Options:\n\n");
350 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
352 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
353 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
356 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
357 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
358 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
359 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
360 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
361 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
362 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
363 printf( " -gl_voodoo %s\n","force fullscreen mode only");
365 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
366 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
367 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
368 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
369 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
370 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
371 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
372 printf( " -gl_test2 %s\n","FIXME: Undocumented");
373 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
374 #ifdef OGL_RUNTIME_LOAD
375 printf( " -gl_library <l> %s\n","use alternate opengl library");
379 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
380 printf( " -hwsurface %s\n","FIXME: Undocumented");
383 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
384 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
386 printf( "\n Help:\n\n");
387 printf( " -help, -h, -?, ? %s\n", "View this help screen");
391 void do_joystick_init()
395 if (!FindArg( "-nojoystick" )) {
396 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
398 if ( FindArg( "-joyslow" )) {
399 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
400 joy_set_slow_reading(JOY_SLOW_READINGS);
402 if ( FindArg( "-joypolled" )) {
403 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
404 joy_set_slow_reading(JOY_POLLED_READINGS);
406 if ( FindArg( "-joybios" )) {
407 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
408 joy_set_slow_reading(JOY_BIOS_READINGS);
411 // Added from Descent v1.5 by John. Adapted by Samir.
413 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
417 //set this to force game to run in low res
418 int disable_high_res=0;
420 void do_register_player(ubyte *title_pal)
422 Players[Player_num].callsign[0] = '\0';
428 //now, before we bring up the register player menu, we need to
429 //do some stuff to make sure the palette is ok. First, we need to
430 //get our current palette into the 2d's array, so the remapping will
431 //work. Second, we need to remap the fonts. Third, we need to fill
432 //in part of the fade tables so the darkening of the menu edges works
434 memcpy(gr_palette,title_pal,sizeof(gr_palette));
435 remap_fonts_and_menus(1);
436 RegisterPlayer(); //get player's name
442 void do_network_init()
444 if (!FindArg( "-nonetwork" )) {
448 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
449 if ((t=FindArg("-socket")))
450 socket = atoi( Args[t+1] );
451 //@@if ( FindArg("-showaddress") ) showaddress=1;
452 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
453 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
456 switch( ipx_error ) {
457 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
458 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
459 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
461 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
463 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
464 Network_active = 0; // Assume no network
466 ipx_read_user_file( "descent.usr" );
467 ipx_read_network_file( "descent.net" );
468 //@@if ( FindArg( "-dynamicsockets" ))
469 //@@ Network_allow_socket_changes = 1;
471 //@@ Network_allow_socket_changes = 0;
473 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
474 Network_active = 0; // Assume no network
479 #define PROGNAME argv[0]
481 extern char Language[];
483 //can we do highres menus?
484 extern int MenuHiresAvailable;
487 int intro_played = 0;
490 int Inferno_verbose = 0;
492 int open_movie_file(char *filename,int must_have);
494 #if defined(POLY_ACC)
495 #define MENU_HIRES_MODE SM_640x480x15xPA
497 #define MENU_HIRES_MODE SM(640,480)
500 // DESCENT II by Parallax Software
503 //extern ubyte gr_current_pal[];
507 char Auto_file[128] = "";
510 int main(int argc,char **argv)
513 ubyte title_pal[768];
515 con_init(); // Initialise the console
518 error_init(NULL, NULL);
522 char *home = getenv("HOME");
525 char buf[PATH_MAX + 5];
528 strcat(buf, "/.d2x");
532 fprintf(stderr, "Cannot change to $HOME/.d2x\n");
538 InitArgs( argc,argv );
540 if ( FindArg( "-debug") )
542 con_threshold.value = (float)2;
545 if ( FindArg( "-verbose" ) )
547 con_threshold.value = (float)1;
554 //tell cfile where hogdir is
555 cfile_use_alternate_hogdir(SHAREPATH);
557 //tell cfile about our counter
558 cfile_set_critical_error_counter_ptr(&descent_critical_error);
561 cfile_init("d2demo.hog"); //specify name of hogfile
563 #define HOGNAME "descent2.hog"
564 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
566 Error("Could not find required file <%s>",HOGNAME);
573 //print out the banner title
574 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
575 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
576 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
577 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
578 con_printf(CON_NORMAL, " Copyright (c) 2001 Bradley Bell\n");
581 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
582 print_commandline_help();
583 set_exit_message("");
585 exit(0); /* mingw hangs on this return. dunno why */
590 con_printf(CON_NORMAL, "\n");
591 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
592 con_printf(CON_NORMAL, "\n");
594 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
596 if ( FindArg( "-autodemo" ))
599 if ( FindArg( "-noscreens" ) )
600 Skip_briefing_screens = 1;
602 if ((t=FindArg("-tmap"))){
603 select_tmap(Args[t+1]);
609 // if (init_graphics()) return 1;
612 if (!Inferno_is_800x600_available) {
613 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
614 Function_mode = FMODE_MENU;
619 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
621 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
628 #if defined(POLY_ACC)
629 Current_display_mode = -1;
630 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
633 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
634 set_display_mode(0); //..then set default display mode
637 i = FindArg( "-xcontrol" );
639 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
642 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
643 if (FindArg("-nofade"))
644 grd_fades_disabled=1;
646 if ((t=gr_init())!=0) //doesn't do much
647 Error(TXT_CANT_INIT_GFX,t);
653 // Load the palette stuff. Returns non-zero if error.
654 con_printf(CON_DEBUG, "\nInitializing palette system..." );
655 gr_use_palette_table(DEFAULT_PALETTE );
657 con_printf(CON_DEBUG, "\nInitializing font system..." );
658 gamefont_init(); // must load after palette data loaded.
660 //determine whether we're using high-res menus & movies
661 #if !defined(POLY_ACC)
662 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
663 MovieHires = MenuHires = MenuHiresAvailable = 0;
666 //NOTE LINK TO ABOVE!
667 MenuHires = MenuHiresAvailable = 1;
669 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
670 init_movies(); //init movie libraries
672 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
673 #if defined(POLY_ACC)
674 gr_set_mode(SM_640x480x15xPA);
676 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
680 if ( FindArg( "-notitles" ) )
681 songs_play_song( SONG_TITLE, 1);
684 { //NOTE LINK TO ABOVE!
686 int played=MOVIE_NOT_PLAYED; //default is not played
688 int song_playing = 0;
691 #define MOVIE_REQUIRED 0
693 #define MOVIE_REQUIRED 1
696 #ifdef D2_OEM //$$POLY_ACC, jay.
697 { //show bundler screens
699 char filename[FILENAME_LEN];
701 played=MOVIE_NOT_PLAYED; //default is not played
703 played = PlayMovie("pre_i.mve",0);
706 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
708 while ((tfile=fopen(filename,"rb")) != NULL) {
710 show_title_screen( filename, 1, 0 );
718 init_subtitles("intro.tex");
719 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
724 if (played != MOVIE_NOT_PLAYED)
726 else { //didn't get intro movie, try titles
728 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
730 if (played == MOVIE_NOT_PLAYED) {
731 #if defined(POLY_ACC)
732 gr_set_mode(SM_640x480x15xPA);
734 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
736 con_printf( CON_DEBUG, "\nPlaying title song..." );
737 songs_play_song( SONG_TITLE, 1);
739 con_printf( CON_DEBUG, "\nShowing logo screens..." );
740 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
741 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
745 { //show bundler movie or screens
748 char filename[FILENAME_LEN];
751 played=MOVIE_NOT_PLAYED; //default is not played
753 //check if OEM movie exists, so we don't stop the music if it doesn't
754 movie_handle = open_movie_file("oem.mve",0);
755 if (movie_handle != -1) {
757 played = PlayMovie("oem.mve",0);
758 song_playing = 0; //movie will kill sound
762 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
764 while ((tfile=fopen(filename,"rb")) != NULL) {
766 show_title_screen( filename, 1, 0 );
774 songs_play_song( SONG_TITLE, 1);
778 PA_DFX (pa_splash());
780 con_printf( CON_DEBUG, "\nShowing loading screen..." );
782 //grs_bitmap title_bm;
787 strcpy(filename, "descentd.pcx");
790 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
792 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
796 #if defined(POLY_ACC)
797 gr_set_mode(SM_640x480x15xPA);
799 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
802 FontHires = MenuHires;
804 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
805 //vfx_set_palette_sub( title_pal );
807 gr_palette_fade_in( title_pal, 32, 0 );
809 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
812 con_printf( CON_DEBUG , "\nDoing bm_init..." );
820 if (FindArg("-hoarddata") != 0) {
821 #define MAX_BITMAPS_PER_BRUSH 30
822 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
826 ubyte palette[256*3];
829 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
830 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
831 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
832 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
834 ofile = fopen("hoard.ham","wb");
836 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
837 Assert(iff_error == IFF_NO_ERROR);
838 nframes_short = nframes;
839 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
840 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
841 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
842 fwrite(palette,3,256,ofile);
843 for (i=0;i<nframes;i++)
844 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
846 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
847 Assert(iff_error == IFF_NO_ERROR);
848 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
849 nframes_short = nframes;
850 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
851 fwrite(palette,3,256,ofile);
852 for (i=0;i<nframes;i++)
853 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
856 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
857 Assert(iff_error == IFF_NO_ERROR);
858 fwrite(&icon.bm_w,sizeof(short),1,ofile);
859 fwrite(&icon.bm_h,sizeof(short),1,ofile);
860 fwrite(palette,3,256,ofile);
861 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
864 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
868 ifile = fopen(sounds[i],"rb");
869 Assert(ifile != NULL);
870 size = ffilelength(ifile);
871 buf = d_malloc(size);
872 fread(buf,1,size,ifile);
873 fwrite(&size,sizeof(size),1,ofile);
874 fwrite(buf,1,size,ofile);
885 //the bitmap loading code changes gr_palette, so restore it
886 memcpy(gr_palette,title_pal,sizeof(gr_palette));
888 if ( FindArg( "-norun" ) )
891 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
894 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
895 texmerge_init( 10 ); // 10 cache bitmaps
897 con_printf( CON_DEBUG, "\nRunning game...\n" );
898 set_screen_mode(SCREEN_MENU);
902 // If built with editor, option to auto-load a level and quit game
903 // to write certain data.
906 if ( (t = FindArg( "-autoload" )) ) {
908 strcpy(Auto_file, Args[t+1]);
914 strcpy(Players[0].callsign, "dummy");
917 do_register_player(title_pal);
919 gr_palette_fade_out( title_pal, 32, 0 );
921 Game_mode = GM_GAME_OVER;
924 newdemo_start_playback("descent.dem");
925 if (Newdemo_state == ND_STATE_PLAYBACK )
926 Function_mode = FMODE_GAME;
929 //do this here because the demo code can do a longjmp when trying to
930 //autostart a demo from the main menu, never having gone into the game
933 while (Function_mode != FMODE_EXIT)
935 switch( Function_mode ) {
937 set_screen_mode(SCREEN_MENU);
939 newdemo_start_playback(NULL); // Randomly pick a file
940 if (Newdemo_state != ND_STATE_PLAYBACK)
941 Error("No demo files were found for autodemo mode!");
945 strcpy((char *)&Level_names[0], Auto_file);
947 Function_mode = FMODE_EXIT;
952 check_joystick_calibration();
953 gr_palette_clear(); //I'm not sure why we need this, but we do
956 if ( Function_mode == FMODE_EDITOR ) {
958 SetPlayerFromCurseg();
959 load_palette(NULL,1,0);
966 keyd_editor_mode = 0;
970 /* keep the mouse from wandering in SDL */
971 if (FindArg("-grabmouse"))
972 SDL_WM_GrabInput(SDL_GRAB_ON);
979 /* give control back to the WM */
980 if (FindArg("-grabmouse"))
981 SDL_WM_GrabInput(SDL_GRAB_OFF);
984 if ( Function_mode == FMODE_MENU )
985 songs_play_song( SONG_TITLE, 1 );
989 keyd_editor_mode = 1;
992 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
994 if ( Function_mode == FMODE_GAME ) {
995 Game_mode = GM_EDITOR;
996 editor_reset_stuff_on_level();
1002 Error("Invalid function mode %d",Function_mode);
1010 if (!FindArg( "-notitles" ))
1015 if ( FindArg( "-showmeminfo" ) )
1016 show_mem_info = 1; // Make memory statistics show
1019 return(0); //presumably successful exit
1023 void check_joystick_calibration() {
1024 int x1, y1, x2, y2, c;
1027 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1028 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1029 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1030 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1033 joy_get_pos( &x1, &y1 );
1035 t1 = timer_get_fixed_seconds();
1036 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1039 joy_get_pos( &x2, &y2 );
1041 // If joystick hasn't moved...
1042 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1043 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1044 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1046 joydefs_calibrate();
1053 void show_order_form()
1055 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1058 char title_pal[768];
1059 char exit_screen[16];
1061 gr_set_current_canvas( NULL );
1067 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1069 #if defined(SHAREWARE)
1070 strcpy(exit_screen, "orderd2.pcx");
1072 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1076 if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
1077 //vfx_set_palette_sub( title_pal );
1078 gr_palette_fade_in( title_pal, 32, 0 );
1080 gr_palette_fade_out( title_pal, 32, 0 );
1083 Int3(); //can't load order screen
1093 // void network_abort_game();
1094 // if(Network_status)
1095 // network_abort_game();