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-28 00:03:47 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.19 2002/01/18 07:01:37 bradleyb
26 * Revision 1.18 2001/12/28 09:26:41 bradleyb
27 * document -nomovies option
29 * Revision 1.17 2001/11/09 06:55:08 bradleyb
32 * Revision 1.16 2001/11/08 10:30:28 bradleyb
33 * Enabled shareware build, endlevel flythrough sequence
35 * Revision 1.15 2001/11/05 07:39:08 bradleyb
36 * Change args_init back to InitArgs
38 * Revision 1.14 2001/11/04 09:01:41 bradleyb
39 * SDL applies to more than X11...
41 * Revision 1.13 2001/10/31 07:41:54 bradleyb
44 * Revision 1.12 2001/10/27 01:39:23 bradleyb
45 * added some documentation
47 * Revision 1.11 2001/10/25 09:12:16 bradleyb
48 * Completed tmap selection code.
50 * Revision 1.10 2001/10/25 02:19:31 bradleyb
51 * conditionalize including multi.h and network.h, fix backslashes, fix compiler errors with EDITOR
53 * Revision 1.9 2001/10/19 08:08:50 bradleyb
54 * conditionalize conf.h
56 * Revision 1.8 2001/10/19 00:31:51 bradleyb
57 * Trying to get network working on win32
59 * Revision 1.7 2001/10/18 00:01:01 bradleyb
60 * RCS headers added/changed
69 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
79 #include <sys/types.h>
85 #include "pa_enabl.h" //$$POLY_ACC
97 #include "segment.h" //for Side_to_verts
102 #include "texmerge.h"
122 #include "gamefont.h"
139 // # include "3dfx_des.h"
141 #include "../texmap/scanline.h" //for select_tmap -MM
143 #if defined(POLY_ACC)
144 #include "poly_acc.h"
145 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
149 #include "editor/editor.h"
150 #include "editor/kdefs.h"
162 void arch_init(void);
163 void arch_init_start(void);
165 //Current version number
167 ubyte Version_major = 1; //FULL VERSION
168 ubyte Version_minor = 2;
170 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
171 char desc_id_exit_num = 0;
173 int Function_mode=FMODE_MENU; //game or editor?
174 int Screen_mode=-1; //game screen or editor screen?
176 //--unused-- grs_bitmap Inferno_bitmap_title;
178 int WVIDEO_running=0; //debugger can set to 1 if running
181 int Inferno_is_800x600_available = 0;
184 //--unused-- int Cyberman_installed=0; // SWIFT device present
185 ubyte CybermouseActive=0;
187 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
189 void check_joystick_calibration(void);
192 //--------------------------------------------------------------------------
194 extern int piggy_low_memory;
197 int descent_critical_error = 0;
198 unsigned descent_critical_deverror = 0;
199 unsigned descent_critical_errcode = 0;
201 extern int Network_allow_socket_changes;
203 extern void vfx_set_palette_sub(ubyte *);
205 extern int VR_low_res;
207 extern int Config_vr_type;
208 extern int Config_vr_resolution;
209 extern int Config_vr_tracking;
210 int grd_fades_disabled=1;
214 //read help from a file & print to screen
215 void print_commandline_help()
221 ifile = cfopen("help.tex","rb");
223 ifile = cfopen("help.txb","rb");
225 Error("Cannot load help text file.");
229 while (cfgets(line,LINE_LEN,ifile)) {
233 for (i = 0; i < strlen(line) - 1; i++) {
234 encode_rotate_left(&(line[i]));
235 line[i] = line[i] ^ BITMAP_TBL_XOR;
236 encode_rotate_left(&(line[i]));
241 continue; //don't show comments
249 // printf( " Diagnostic:\n\n");
250 // printf( " -emul %s\n", "Certain video cards need this option in order to run game");
251 // printf( " -ddemul %s\n", "If -emul doesn't work, use this option");
254 printf( " Editor Options:\n\n");
255 printf( " -autoload <file>%s\n", "Autoload a level in the editor");
256 printf( " -hoarddata %s\n","FIXME: Undocumented");
257 printf( " -macdata %s\n","FIXME: Undocumented");
258 // printf( " -nobm %s\n","FIXME: Undocumented");
261 printf( " D2X Options:\n\n");
262 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
263 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
264 printf( " -notitles %s\n", "Do not show titlescreens on startup");
265 printf( " -ini <file> %s\n", "option file (alternate to command line) defaults to d2x.ini, or d1x.ini");
266 printf( " -autodemo %s\n", "Start in demo mode");
267 printf( " -bigpig %s\n","FIXME: Undocumented");
268 printf( " -bspgen %s\n","FIXME: Undocumented");
269 // printf( " -cdproxy %s\n","FIXME: Undocumented");
271 printf( " -checktime %s\n","FIXME: Undocumented");
272 printf( " -showmeminfo %s\n","FIXME: Undocumented");
274 // printf( " -codereadonly %s\n","FIXME: Undocumented");
275 // printf( " -cyberimpact %s\n","FIXME: Undocumented");
276 printf( " -debug %s\n","Enable very verbose output");
277 // printf( " -debugmode %s\n","FIXME: Undocumented");
278 // printf( " -disallowgfx %s\n","FIXME: Undocumented");
279 // printf( " -disallowreboot %s\n","FIXME: Undocumented");
280 // printf( " -dynamicsockets %s\n","FIXME: Undocumented");
281 // printf( " -forcegfx %s\n","FIXME: Undocumented");
283 printf( " -grabmouse %s\n","Keeps the mouse from wandering out of the window");
285 // printf( " -hw_3dacc %s\n","FIXME: Undocumented");
287 printf( " -invulnerability %s\n","Make yourself invulnerable");
289 printf( " -ipxnetwork <num> %s\n","Use IPX network number <num>");
290 printf( " -jasen %s\n","FIXME: Undocumented");
291 printf( " -joyslow %s\n","FIXME: Undocumented");
292 // printf( " -logfile %s\n","FIXME: Undocumented");
293 // printf( " -lowresmovies %s\n","FIXME: Undocumented");
294 // printf( " -memdbg %s\n","FIXME: Undocumented");
295 // printf( " -monodebug %s\n","FIXME: Undocumented");
296 #if defined(__DJGPP__) || defined(__SDL__)
297 printf( " -nocdrom %s\n","FIXME: Undocumented");
300 printf( " -nocyberman %s\n","FIXME: Undocumented");
302 printf( " -nofade %s\n","Disable fades");
304 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
305 printf( " -norankings %s\n","Disable multiplayer ranking system");
306 printf( " -packets <num> %s\n","Specifies the number of packets per second\n");
307 // printf( " -showaddress %s\n","FIXME: Undocumented");
308 printf( " -socket %s\n","FIXME: Undocumented");
310 #if !defined(MACINTOSH) && !defined(WINDOWS)
311 printf( " -nomixer %s\n","Don't crank music volume");
312 printf( " -superhires %s\n","Allow higher-resolution modes");
314 // printf( " -nomodex %s\n","FIXME: Undocumented");
316 printf( " -nomovies %s\n","Don't play movies");
318 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
319 printf( " -noredbook %s\n","Disable redbook audio");
321 printf( " -norun %s\n","Bail out after initialization");
322 printf( " -noscreens %s\n","Skip briefing screens");
323 // printf( " -ordinaljoy %s\n","FIXME: Undocumented");
324 // printf( " -rtscts %s\n","Same as -ctsrts");
325 // printf( " -semiwin %s\n","Use non-fullscreen mode");
326 // printf( " -specialdevice %s\n","FIXME: Undocumented");
328 printf( " -stickmag %s\n","FIXME: Undocumented");
330 // printf( " -stopwatch %s\n","FIXME: Undocumented");
331 // printf( " -subtitles %s\n","Turn on movie subtitles (English-only)");
332 // printf( " -sysram %s\n","FIXME: Undocumented");
333 printf( " -text <file> %s\n","Specify alternate .tex file");
334 // printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
335 // printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
336 // printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
337 // printf( " -udp %s\n","FIXME: Undocumented");
338 // printf( " -vidram %s\n","FIXME: Undocumented");
339 printf( " -xcontrol %s\n","FIXME: Undocumented");
340 printf( " -xname %s\n","FIXME: Undocumented");
341 printf( " -xver %s\n","FIXME: Undocumented");
342 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
345 printf( "D2X System Options:\n\n");
347 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
349 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
350 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
353 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
354 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
355 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
356 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
357 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
358 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
359 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
360 printf( " -gl_voodoo %s\n","force fullscreen mode only");
362 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
363 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
364 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
365 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
366 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
367 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
368 // printf( " -gl_test1 %s\n","FIXME: Undocumented");
369 printf( " -gl_test2 %s\n","FIXME: Undocumented");
370 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
371 #ifdef OGL_RUNTIME_LOAD
372 printf( " -gl_library <l> %s\n","use alternate opengl library");
376 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
377 printf( " -hwsurface %s\n","FIXME: Undocumented");
380 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
381 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
383 printf( "\n Help:\n\n");
384 printf( " -help, -h, -?, ? %s\n", "View this help screen");
388 void do_joystick_init()
392 if (!FindArg( "-nojoystick" )) {
393 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
395 if ( FindArg( "-joyslow" )) {
396 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
397 joy_set_slow_reading(JOY_SLOW_READINGS);
399 if ( FindArg( "-joypolled" )) {
400 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
401 joy_set_slow_reading(JOY_POLLED_READINGS);
403 if ( FindArg( "-joybios" )) {
404 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
405 joy_set_slow_reading(JOY_BIOS_READINGS);
408 // Added from Descent v1.5 by John. Adapted by Samir.
410 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
414 //set this to force game to run in low res
415 int disable_high_res=0;
417 void do_register_player(ubyte *title_pal)
419 Players[Player_num].callsign[0] = '\0';
425 //now, before we bring up the register player menu, we need to
426 //do some stuff to make sure the palette is ok. First, we need to
427 //get our current palette into the 2d's array, so the remapping will
428 //work. Second, we need to remap the fonts. Third, we need to fill
429 //in part of the fade tables so the darkening of the menu edges works
431 memcpy(gr_palette,title_pal,sizeof(gr_palette));
432 remap_fonts_and_menus(1);
433 RegisterPlayer(); //get player's name
439 void do_network_init()
441 if (!FindArg( "-nonetwork" )) {
445 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
446 if ((t=FindArg("-socket")))
447 socket = atoi( Args[t+1] );
448 //@@if ( FindArg("-showaddress") ) showaddress=1;
449 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
450 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
453 switch( ipx_error ) {
454 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
455 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
456 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
458 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
460 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
461 Network_active = 0; // Assume no network
463 ipx_read_user_file( "descent.usr" );
464 ipx_read_network_file( "descent.net" );
465 //@@if ( FindArg( "-dynamicsockets" ))
466 //@@ Network_allow_socket_changes = 1;
468 //@@ Network_allow_socket_changes = 0;
470 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
471 Network_active = 0; // Assume no network
476 #define PROGNAME argv[0]
478 extern char Language[];
480 //can we do highres menus?
481 extern int MenuHiresAvailable;
484 int intro_played = 0;
487 int Inferno_verbose = 0;
489 int open_movie_file(char *filename,int must_have);
491 #if defined(POLY_ACC)
492 #define MENU_HIRES_MODE SM_640x480x15xPA
494 #define MENU_HIRES_MODE SM(640,480)
497 // DESCENT II by Parallax Software
500 //extern ubyte gr_current_pal[];
504 char Auto_file[128] = "";
507 int main(int argc,char **argv)
510 ubyte title_pal[768];
512 con_init(); // Initialise the console
515 error_init(NULL, NULL);
519 char *home = getenv("HOME");
522 char buf[PATH_MAX + 5];
525 strcat(buf, "/.d2x");
529 fprintf(stderr, "Cannot change to ~/.d2x\n");
535 InitArgs( argc,argv );
537 if ( FindArg( "-debug") )
539 con_threshold.value = (float)2;
542 if ( FindArg( "-verbose" ) )
544 con_threshold.value = (float)1;
551 //tell cfile where hogdir is
552 cfile_use_alternate_hogdir(SHAREPATH);
554 //tell cfile about our counter
555 cfile_set_critical_error_counter_ptr(&descent_critical_error);
558 cfile_init("d2demo.hog"); //specify name of hogfile
560 #define HOGNAME "descent2.hog"
561 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
563 Error("Could not find required file <%s>",HOGNAME);
570 //print out the banner title
571 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
572 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
573 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
574 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
575 con_printf(CON_NORMAL, " Copyright (c) 2001 Bradley Bell\n");
578 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
579 print_commandline_help();
580 set_exit_message("");
582 exit(0); /* mingw hangs on this return. dunno why */
587 con_printf(CON_NORMAL, "\n");
588 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
589 con_printf(CON_NORMAL, "\n");
591 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
593 if ( FindArg( "-autodemo" ))
596 if ( FindArg( "-noscreens" ) )
597 Skip_briefing_screens = 1;
599 if ((t=FindArg("-tmap"))){
600 select_tmap(Args[t+1]);
606 // if (init_graphics()) return 1;
609 if (!Inferno_is_800x600_available) {
610 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
611 Function_mode = FMODE_MENU;
616 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
618 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
625 #if defined(POLY_ACC)
626 Current_display_mode = -1;
627 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
630 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
631 set_display_mode(0); //..then set default display mode
634 i = FindArg( "-xcontrol" );
636 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
639 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
640 if (FindArg("-nofade"))
641 grd_fades_disabled=1;
643 if ((t=gr_init())!=0) //doesn't do much
644 Error(TXT_CANT_INIT_GFX,t);
650 // Load the palette stuff. Returns non-zero if error.
651 con_printf(CON_DEBUG, "\nInitializing palette system..." );
652 gr_use_palette_table(DEFAULT_PALETTE );
654 con_printf(CON_DEBUG, "\nInitializing font system..." );
655 gamefont_init(); // must load after palette data loaded.
657 //determine whether we're using high-res menus & movies
658 #if !defined(POLY_ACC)
659 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
660 MovieHires = MenuHires = MenuHiresAvailable = 0;
663 //NOTE LINK TO ABOVE!
664 MenuHires = MenuHiresAvailable = 1;
666 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
667 init_movies(); //init movie libraries
669 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
670 #if defined(POLY_ACC)
671 gr_set_mode(SM_640x480x15xPA);
673 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
677 if ( FindArg( "-notitles" ) )
678 songs_play_song( SONG_TITLE, 1);
681 { //NOTE LINK TO ABOVE!
683 int played=MOVIE_NOT_PLAYED; //default is not played
685 int song_playing = 0;
688 #define MOVIE_REQUIRED 0
690 #define MOVIE_REQUIRED 1
693 #ifdef D2_OEM //$$POLY_ACC, jay.
694 { //show bundler screens
696 char filename[FILENAME_LEN];
698 played=MOVIE_NOT_PLAYED; //default is not played
700 played = PlayMovie("pre_i.mve",0);
703 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
705 while ((tfile=fopen(filename,"rb")) != NULL) {
707 show_title_screen( filename, 1, 0 );
715 init_subtitles("intro.tex");
716 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
721 if (played != MOVIE_NOT_PLAYED)
723 else { //didn't get intro movie, try titles
725 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
727 if (played == MOVIE_NOT_PLAYED) {
728 #if defined(POLY_ACC)
729 gr_set_mode(SM_640x480x15xPA);
731 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
733 con_printf( CON_DEBUG, "\nPlaying title song..." );
734 songs_play_song( SONG_TITLE, 1);
736 con_printf( CON_DEBUG, "\nShowing logo screens..." );
737 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
738 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
742 { //show bundler movie or screens
745 char filename[FILENAME_LEN];
748 played=MOVIE_NOT_PLAYED; //default is not played
750 //check if OEM movie exists, so we don't stop the music if it doesn't
751 movie_handle = open_movie_file("oem.mve",0);
752 if (movie_handle != -1) {
754 played = PlayMovie("oem.mve",0);
755 song_playing = 0; //movie will kill sound
759 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
761 while ((tfile=fopen(filename,"rb")) != NULL) {
763 show_title_screen( filename, 1, 0 );
771 songs_play_song( SONG_TITLE, 1);
775 PA_DFX (pa_splash());
777 con_printf( CON_DEBUG, "\nShowing loading screen..." );
779 //grs_bitmap title_bm;
784 strcpy(filename, "descentd.pcx");
787 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
789 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
793 #if defined(POLY_ACC)
794 gr_set_mode(SM_640x480x15xPA);
796 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
799 FontHires = MenuHires;
801 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
802 //vfx_set_palette_sub( title_pal );
804 gr_palette_fade_in( title_pal, 32, 0 );
806 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
809 con_printf( CON_DEBUG , "\nDoing bm_init..." );
817 if (FindArg("-hoarddata") != 0) {
818 #define MAX_BITMAPS_PER_BRUSH 30
819 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
823 ubyte palette[256*3];
826 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
827 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
828 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
829 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
831 ofile = fopen("hoard.ham","wb");
833 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
834 Assert(iff_error == IFF_NO_ERROR);
835 nframes_short = nframes;
836 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
837 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
838 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
839 fwrite(palette,3,256,ofile);
840 for (i=0;i<nframes;i++)
841 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
843 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
844 Assert(iff_error == IFF_NO_ERROR);
845 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
846 nframes_short = nframes;
847 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
848 fwrite(palette,3,256,ofile);
849 for (i=0;i<nframes;i++)
850 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
853 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
854 Assert(iff_error == IFF_NO_ERROR);
855 fwrite(&icon.bm_w,sizeof(short),1,ofile);
856 fwrite(&icon.bm_h,sizeof(short),1,ofile);
857 fwrite(palette,3,256,ofile);
858 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
861 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
865 ifile = fopen(sounds[i],"rb");
866 Assert(ifile != NULL);
867 size = ffilelength(ifile);
868 buf = d_malloc(size);
869 fread(buf,1,size,ifile);
870 fwrite(&size,sizeof(size),1,ofile);
871 fwrite(buf,1,size,ofile);
882 //the bitmap loading code changes gr_palette, so restore it
883 memcpy(gr_palette,title_pal,sizeof(gr_palette));
885 if ( FindArg( "-norun" ) )
888 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
891 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
892 texmerge_init( 10 ); // 10 cache bitmaps
894 con_printf( CON_DEBUG, "\nRunning game...\n" );
895 set_screen_mode(SCREEN_MENU);
899 // If built with editor, option to auto-load a level and quit game
900 // to write certain data.
903 if ( (t = FindArg( "-autoload" )) ) {
905 strcpy(Auto_file, Args[t+1]);
911 strcpy(Players[0].callsign, "dummy");
914 do_register_player(title_pal);
916 gr_palette_fade_out( title_pal, 32, 0 );
918 Game_mode = GM_GAME_OVER;
921 newdemo_start_playback("descent.dem");
922 if (Newdemo_state == ND_STATE_PLAYBACK )
923 Function_mode = FMODE_GAME;
926 //do this here because the demo code can do a longjmp when trying to
927 //autostart a demo from the main menu, never having gone into the game
930 while (Function_mode != FMODE_EXIT)
932 switch( Function_mode ) {
934 set_screen_mode(SCREEN_MENU);
936 newdemo_start_playback(NULL); // Randomly pick a file
937 if (Newdemo_state != ND_STATE_PLAYBACK)
938 Error("No demo files were found for autodemo mode!");
942 strcpy((char *)&Level_names[0], Auto_file);
944 Function_mode = FMODE_EXIT;
949 check_joystick_calibration();
950 gr_palette_clear(); //I'm not sure why we need this, but we do
953 if ( Function_mode == FMODE_EDITOR ) {
955 SetPlayerFromCurseg();
956 load_palette(NULL,1,0);
963 keyd_editor_mode = 0;
967 /* keep the mouse from wandering in SDL */
968 if (FindArg("-grabmouse"))
969 SDL_WM_GrabInput(SDL_GRAB_ON);
976 /* give control back to the WM */
977 if (FindArg("-grabmouse"))
978 SDL_WM_GrabInput(SDL_GRAB_OFF);
981 if ( Function_mode == FMODE_MENU )
982 songs_play_song( SONG_TITLE, 1 );
986 keyd_editor_mode = 1;
989 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
991 if ( Function_mode == FMODE_GAME ) {
992 Game_mode = GM_EDITOR;
993 editor_reset_stuff_on_level();
999 Error("Invalid function mode %d",Function_mode);
1007 if (!FindArg( "-notitles" ))
1012 if ( FindArg( "-showmeminfo" ) )
1013 show_mem_info = 1; // Make memory statistics show
1016 return(0); //presumably successful exit
1020 void check_joystick_calibration() {
1021 int x1, y1, x2, y2, c;
1024 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1025 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1026 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1027 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1030 joy_get_pos( &x1, &y1 );
1032 t1 = timer_get_fixed_seconds();
1033 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1036 joy_get_pos( &x2, &y2 );
1038 // If joystick hasn't moved...
1039 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
1040 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
1041 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1043 joydefs_calibrate();
1050 void show_order_form()
1052 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1055 char title_pal[768];
1056 char exit_screen[16];
1058 gr_set_current_canvas( NULL );
1064 strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1066 #if defined(SHAREWARE)
1067 strcpy(exit_screen, "orderd2.pcx");
1069 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1073 if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
1074 //vfx_set_palette_sub( title_pal );
1075 gr_palette_fade_in( title_pal, 32, 0 );
1077 gr_palette_fade_out( title_pal, 32, 0 );
1080 Int3(); //can't load order screen
1090 // void network_abort_game();
1091 // if(Network_status)
1092 // network_abort_game();