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.
14 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
24 #include "pa_enabl.h" //$$POLY_ACC
36 #include "segment.h" //for Side_to_verts
76 // # include "3dfx_des.h"
80 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
84 #include "editor\editor.h"
85 #include "editor\kdefs.h"
97 void arch_init_start(void);
99 //Current version number
101 ubyte Version_major = 1; //FULL VERSION
102 ubyte Version_minor = 2;
104 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
105 char desc_id_exit_num = 0;
107 int Function_mode=FMODE_MENU; //game or editor?
108 int Screen_mode=-1; //game screen or editor screen?
110 //--unused-- grs_bitmap Inferno_bitmap_title;
112 int WVIDEO_running=0; //debugger can set to 1 if running
115 int Inferno_is_800x600_available = 0;
118 //--unused-- int Cyberman_installed=0; // SWIFT device present
119 ubyte CybermouseActive=0;
121 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
123 void check_joystick_calibration(void);
126 //--------------------------------------------------------------------------
128 extern int piggy_low_memory;
131 int descent_critical_error = 0;
132 unsigned descent_critical_deverror = 0;
133 unsigned descent_critical_errcode = 0;
135 extern int Network_allow_socket_changes;
137 extern void vfx_set_palette_sub(ubyte *);
139 extern int VR_low_res;
141 extern int Config_vr_type;
142 extern int Config_vr_resolution;
143 extern int Config_vr_tracking;
144 int grd_fades_disabled=1;
148 void do_joystick_init()
152 if (!FindArg( "-nojoystick" )) {
153 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
155 if ( FindArg( "-joyslow" )) {
156 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
157 joy_set_slow_reading(JOY_SLOW_READINGS);
159 if ( FindArg( "-joypolled" )) {
160 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
161 joy_set_slow_reading(JOY_POLLED_READINGS);
163 if ( FindArg( "-joybios" )) {
164 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
165 joy_set_slow_reading(JOY_BIOS_READINGS);
168 // Added from Descent v1.5 by John. Adapted by Samir.
170 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
174 //set this to force game to run in low res
175 int disable_high_res=0;
177 void do_register_player(ubyte *title_pal)
179 Players[Player_num].callsign[0] = '\0';
185 //now, before we bring up the register player menu, we need to
186 //do some stuff to make sure the palette is ok. First, we need to
187 //get our current palette into the 2d's array, so the remapping will
188 //work. Second, we need to remap the fonts. Third, we need to fill
189 //in part of the fade tables so the darkening of the menu edges works
191 memcpy(gr_palette,title_pal,sizeof(gr_palette));
192 remap_fonts_and_menus(1);
193 RegisterPlayer(); //get player's name
199 void do_network_init()
201 if (!FindArg( "-nonetwork" )) {
202 int socket=0, showaddress=0, t;
205 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
206 if ((t=FindArg("-socket")))
207 socket = atoi( Args[t+1] );
208 //@@if ( FindArg("-showaddress") ) showaddress=1;
209 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
210 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
213 switch( ipx_error ) {
214 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
215 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
216 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
218 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
220 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
221 Network_active = 0; // Assume no network
223 ipx_read_user_file( "descent.usr" );
224 ipx_read_network_file( "descent.net" );
225 //@@if ( FindArg( "-dynamicsockets" ))
226 //@@ Network_allow_socket_changes = 1;
228 //@@ Network_allow_socket_changes = 0;
230 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
231 Network_active = 0; // Assume no network
237 #define PROGNAME "d2demo"
239 #define PROGNAME "d2"
242 extern char Language[];
244 //can we do highres menus?
245 extern int MenuHiresAvailable;
248 int intro_played = 0;
251 int open_movie_file(char *filename,int must_have);
253 #if defined(POLY_ACC)
254 #define MENU_HIRES_MODE SM_640x480x15xPA
256 #define MENU_HIRES_MODE SM(640,480)
259 // DESCENT II by Parallax Software
262 //extern ubyte gr_current_pal[];
266 char Auto_file[128] = "";
269 int main(int argc,char **argv)
272 ubyte title_pal[768];
275 con_init(); // Initialise the console
278 error_init(NULL, NULL);
280 args_init( argc,argv );
282 if ( FindArg( "-debug") )
284 con_threshold.value = (float)2;
287 if ( FindArg( "-verbose" ) )
289 con_threshold.value = (float)1;
296 //tell cfile about our counter
297 cfile_set_critical_error_counter_ptr(&descent_critical_error);
300 cfile_init("d2demo.hog"); //specify name of hogfile
302 #define HOGNAME "descent2.hog"
303 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
305 Error("Could not find required file <%s>",HOGNAME);
312 //print out the banner title
313 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
314 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
315 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
316 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
319 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
320 //print_commandline_help();
321 set_exit_message("");
325 con_printf(CON_NORMAL, "\n");
326 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
327 con_printf(CON_NORMAL, "\n");
329 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
331 if ( FindArg( "-autodemo" ))
334 if ( FindArg( "-noscreens" ) )
335 Skip_briefing_screens = 1;
339 // if (init_graphics()) return 1;
342 if (!Inferno_is_800x600_available) {
343 con_printf(CON_NORMAL "The editor will not be available, press any key to start game...\n" );
344 Function_mode = FMODE_MENU;
349 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
351 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
358 #if defined(POLY_ACC)
359 Current_display_mode = -1;
360 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
363 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
364 set_display_mode(0); //..then set default display mode
367 i = FindArg( "-xcontrol" );
369 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
372 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
373 if (FindArg("-nofade"))
374 grd_fades_disabled=1;
376 if ((t=gr_init())!=0) //doesn't do much
377 Error(TXT_CANT_INIT_GFX,t);
383 // Load the palette stuff. Returns non-zero if error.
384 con_printf(CON_DEBUG, "\nInitializing palette system..." );
385 gr_use_palette_table(DEFAULT_PALETTE );
387 con_printf(CON_DEBUG, "\nInitializing font system..." );
388 gamefont_init(); // must load after palette data loaded.
390 //determine whether we're using high-res menus & movies
391 #if !defined(POLY_ACC)
392 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
393 MovieHires = MenuHires = MenuHiresAvailable = 0;
396 //NOTE LINK TO ABOVE!
397 MenuHires = MenuHiresAvailable = 1;
399 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
400 init_movies(); //init movie libraries
402 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
403 #if defined(POLY_ACC)
404 gr_set_mode(SM_640x480x15xPA);
406 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
410 if ( FindArg( "-notitles" ) )
411 songs_play_song( SONG_TITLE, 1);
414 { //NOTE LINK TO ABOVE!
415 int played=MOVIE_NOT_PLAYED; //default is not played
416 int song_playing = 0;
419 #define MOVIE_REQUIRED 0
421 #define MOVIE_REQUIRED 1
424 #ifdef D2_OEM //$$POLY_ACC, jay.
425 { //show bundler screens
427 char filename[FILENAME_LEN];
429 played=MOVIE_NOT_PLAYED; //default is not played
431 played = PlayMovie("pre_i.mve",0);
434 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
436 while ((tfile=fopen(filename,"rb")) != NULL) {
438 show_title_screen( filename, 1, 0 );
446 init_subtitles("intro.tex");
447 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
452 if (played != MOVIE_NOT_PLAYED)
454 else { //didn't get intro movie, try titles
456 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
458 if (played == MOVIE_NOT_PLAYED) {
459 #if defined(POLY_ACC)
460 gr_set_mode(SM_640x480x15xPA);
462 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
464 con_printf( CON_DEBUG, "\nPlaying title song..." );
465 songs_play_song( SONG_TITLE, 1);
467 con_printf( CON_DEBUG, "\nShowing logo screens..." );
468 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
469 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
473 { //show bundler movie or screens
476 char filename[FILENAME_LEN];
479 played=MOVIE_NOT_PLAYED; //default is not played
481 //check if OEM movie exists, so we don't stop the music if it doesn't
482 movie_handle = open_movie_file("oem.mve",0);
483 if (movie_handle != -1) {
485 played = PlayMovie("oem.mve",0);
486 song_playing = 0; //movie will kill sound
490 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
492 while ((tfile=fopen(filename,"rb")) != NULL) {
494 show_title_screen( filename, 1, 0 );
502 songs_play_song( SONG_TITLE, 1);
506 PA_DFX (pa_splash());
508 con_printf( CON_DEBUG, "\nShowing loading screen..." );
510 //grs_bitmap title_bm;
515 strcpy(filename, "descentd.pcx");
518 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
520 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
524 #if defined(POLY_ACC)
525 gr_set_mode(SM_640x480x15xPA);
527 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
530 FontHires = MenuHires;
532 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
533 //vfx_set_palette_sub( title_pal );
535 gr_palette_fade_in( title_pal, 32, 0 );
537 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
540 con_printf( CON_DEBUG , "\nDoing bm_init..." );
548 if (FindArg("-hoarddata") != 0) {
549 #define MAX_BITMAPS_PER_BRUSH 30
550 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
554 ubyte palette[256*3];
557 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
558 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
559 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
560 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
562 ofile = fopen("hoard.ham","wb");
564 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
565 Assert(iff_error == IFF_NO_ERROR);
566 nframes_short = nframes;
567 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
568 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
569 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
570 fwrite(palette,3,256,ofile);
571 for (i=0;i<nframes;i++)
572 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
574 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
575 Assert(iff_error == IFF_NO_ERROR);
576 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
577 nframes_short = nframes;
578 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
579 fwrite(palette,3,256,ofile);
580 for (i=0;i<nframes;i++)
581 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
584 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
585 Assert(iff_error == IFF_NO_ERROR);
586 fwrite(&icon.bm_w,sizeof(short),1,ofile);
587 fwrite(&icon.bm_h,sizeof(short),1,ofile);
588 fwrite(palette,3,256,ofile);
589 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
592 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
596 ifile = fopen(sounds[i],"rb");
597 Assert(ifile != NULL);
598 size = filelength(ifile->_handle);
599 buf = d_malloc(size);
600 fread(buf,1,size,ifile);
601 fwrite(&size,sizeof(size),1,ofile);
602 fwrite(buf,1,size,ofile);
613 //the bitmap loading code changes gr_palette, so restore it
614 memcpy(gr_palette,title_pal,sizeof(gr_palette));
616 if ( FindArg( "-norun" ) )
619 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
622 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
623 texmerge_init( 10 ); // 10 cache bitmaps
625 con_printf( CON_DEBUG, "\nRunning game...\n" );
626 set_screen_mode(SCREEN_MENU);
630 // If built with editor, option to auto-load a level and quit game
631 // to write certain data.
634 if ( t = FindArg( "-autoload" ) ) {
636 strcpy(Auto_file, Args[t+1]);
642 strcpy(Players[0].callsign, "dummy");
645 do_register_player(title_pal);
647 gr_palette_fade_out( title_pal, 32, 0 );
649 Game_mode = GM_GAME_OVER;
652 newdemo_start_playback("descent.dem");
653 if (Newdemo_state == ND_STATE_PLAYBACK )
654 Function_mode = FMODE_GAME;
657 //do this here because the demo code can do a longjmp when trying to
658 //autostart a demo from the main menu, never having gone into the game
661 while (Function_mode != FMODE_EXIT)
663 switch( Function_mode ) {
665 set_screen_mode(SCREEN_MENU);
667 newdemo_start_playback(NULL); // Randomly pick a file
668 if (Newdemo_state != ND_STATE_PLAYBACK)
669 Error("No demo files were found for autodemo mode!");
673 strcpy(&Level_names[0], Auto_file);
675 Function_mode = FMODE_EXIT;
680 check_joystick_calibration();
681 gr_palette_clear(); //I'm not sure why we need this, but we do
684 if ( Function_mode == FMODE_EDITOR ) {
686 SetPlayerFromCurseg();
687 load_palette(NULL,1,0);
694 keyd_editor_mode = 0;
698 /* keep the mouse from wandering in SDL/X11 */
699 if (FindArg("-grabmouse"))
700 SDL_WM_GrabInput(SDL_GRAB_ON);
707 /* give control back to the WM */
708 if (FindArg("-grabmouse"))
709 SDL_WM_GrabInput(SDL_GRAB_OFF);
712 if ( Function_mode == FMODE_MENU )
713 songs_play_song( SONG_TITLE, 1 );
717 keyd_editor_mode = 1;
719 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
720 if ( Function_mode == FMODE_GAME ) {
721 Game_mode = GM_EDITOR;
722 editor_reset_stuff_on_level();
728 Error("Invalid function mode %d",Function_mode);
736 if (!FindArg( "-notitles" ))
741 if ( FindArg( "-showmeminfo" ) )
742 show_mem_info = 1; // Make memory statistics show
745 return(0); //presumably successful exit
749 void check_joystick_calibration() {
750 int x1, y1, x2, y2, c;
753 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
754 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
755 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
756 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
759 joy_get_pos( &x1, &y1 );
761 t1 = timer_get_fixed_seconds();
762 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
765 joy_get_pos( &x2, &y2 );
767 // If joystick hasn't moved...
768 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
769 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
770 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );