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"
93 void arch_init_start(void);
95 //Current version number
97 ubyte Version_major = 1; //FULL VERSION
98 ubyte Version_minor = 2;
100 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
101 char desc_id_exit_num = 0;
103 int Function_mode=FMODE_MENU; //game or editor?
104 int Screen_mode=-1; //game screen or editor screen?
106 //--unused-- grs_bitmap Inferno_bitmap_title;
108 int WVIDEO_running=0; //debugger can set to 1 if running
111 int Inferno_is_800x600_available = 0;
114 //--unused-- int Cyberman_installed=0; // SWIFT device present
115 ubyte CybermouseActive=0;
117 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
119 void check_joystick_calibration(void);
122 //--------------------------------------------------------------------------
124 extern int piggy_low_memory;
126 void mem_int_to_string( int number, char *dest )
131 sprintf( buffer, "%d", number );
135 // Don't bother with less than 3 digits
136 sprintf( dest, "%d", number );
142 for (i=l-1; i>=0; i-- ) {
155 int descent_critical_error = 0;
156 unsigned descent_critical_deverror = 0;
157 unsigned descent_critical_errcode = 0;
159 extern int Network_allow_socket_changes;
161 extern void vfx_set_palette_sub(ubyte *);
163 extern int VR_low_res;
165 extern int Config_vr_type;
166 extern int Config_vr_resolution;
167 extern int Config_vr_tracking;
168 int grd_fades_disabled=1;
172 void do_joystick_init()
176 if (!args_find( "-nojoystick" )) {
177 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
179 if ( args_find( "-joyslow" )) {
180 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
181 joy_set_slow_reading(JOY_SLOW_READINGS);
183 if ( args_find( "-joypolled" )) {
184 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
185 joy_set_slow_reading(JOY_POLLED_READINGS);
187 if ( args_find( "-joybios" )) {
188 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
189 joy_set_slow_reading(JOY_BIOS_READINGS);
192 // Added from Descent v1.5 by John. Adapted by Samir.
194 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
198 //set this to force game to run in low res
199 int disable_high_res=0;
201 void do_register_player(ubyte *title_pal)
203 Players[Player_num].callsign[0] = '\0';
209 //now, before we bring up the register player menu, we need to
210 //do some stuff to make sure the palette is ok. First, we need to
211 //get our current palette into the 2d's array, so the remapping will
212 //work. Second, we need to remap the fonts. Third, we need to fill
213 //in part of the fade tables so the darkening of the menu edges works
215 memcpy(gr_palette,title_pal,sizeof(gr_palette));
216 remap_fonts_and_menus(1);
217 RegisterPlayer(); //get player's name
223 void do_network_init()
225 if (!args_find( "-nonetwork" )) {
226 int socket=0, showaddress=0, t;
229 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
230 if ((t=args_find("-socket")))
231 socket = atoi( Args[t+1] );
232 //@@if ( args_find("-showaddress") ) showaddress=1;
233 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
234 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
237 switch( ipx_error ) {
238 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
239 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
240 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
242 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
244 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
245 Network_active = 0; // Assume no network
247 ipx_read_user_file( "descent.usr" );
248 ipx_read_network_file( "descent.net" );
249 //@@if ( args_find( "-dynamicsockets" ))
250 //@@ Network_allow_socket_changes = 1;
252 //@@ Network_allow_socket_changes = 0;
254 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
255 Network_active = 0; // Assume no network
261 #define PROGNAME "d2demo"
263 #define PROGNAME "d2"
266 extern char Language[];
268 //can we do highres menus?
269 extern int MenuHiresAvailable;
272 int intro_played = 0;
275 int open_movie_file(char *filename,int must_have);
277 #if defined(POLY_ACC)
278 #define MENU_HIRES_MODE SM_640x480x15xPA
280 #define MENU_HIRES_MODE SM(640,480)
283 // DESCENT II by Parallax Software
286 //extern ubyte gr_current_pal[];
290 char Auto_file[128] = "";
293 int main(int argc,char **argv)
296 ubyte title_pal[768];
299 con_init(); // Initialise the console
302 error_init(NULL, NULL);
304 args_init( argc,argv );
306 if ( args_find( "-debug") )
308 con_threshold.value = (float)2;
311 if ( args_find( "-verbose" ) )
313 con_threshold.value = (float)1;
320 //tell cfile about our counter
321 cfile_set_critical_error_counter_ptr(&descent_critical_error);
324 cfile_init("d2demo.hog"); //specify name of hogfile
326 #define HOGNAME "descent2.hog"
327 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
329 Error("Could not find required file <%s>",HOGNAME);
336 //print out the banner title
337 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
338 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
339 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
340 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
343 if (args_find( "-?" ) || args_find( "-help" ) || args_find( "?" ) ) {
344 //print_commandline_help();
345 set_exit_message("");
349 con_printf(CON_NORMAL, "\n");
350 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
351 con_printf(CON_NORMAL, "\n");
353 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
355 if ( args_find( "-autodemo" ))
358 if ( args_find( "-noscreens" ) )
359 Skip_briefing_screens = 1;
363 // if (init_graphics()) return 1;
366 if (!Inferno_is_800x600_available) {
367 con_printf(CON_NORMAL "The editor will not be available, press any key to start game...\n" );
368 Function_mode = FMODE_MENU;
373 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
375 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
382 #if defined(POLY_ACC)
383 Current_display_mode = -1;
384 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
387 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
388 set_display_mode(0); //..then set default display mode
391 i = args_find( "-xcontrol" );
393 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
396 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
397 if (args_find("-nofade"))
398 grd_fades_disabled=1;
400 if ((t=gr_init())!=0) //doesn't do much
401 Error(TXT_CANT_INIT_GFX,t);
407 // Load the palette stuff. Returns non-zero if error.
408 con_printf(CON_DEBUG, "\nInitializing palette system..." );
409 gr_use_palette_table(DEFAULT_PALETTE );
411 con_printf(CON_DEBUG, "\nInitializing font system..." );
412 gamefont_init(); // must load after palette data loaded.
414 //determine whether we're using high-res menus & movies
415 #if !defined(POLY_ACC)
416 if (args_find("-nohires") || args_find("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
417 MovieHires = MenuHires = MenuHiresAvailable = 0;
420 //NOTE LINK TO ABOVE!
421 MenuHires = MenuHiresAvailable = 1;
423 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
424 init_movies(); //init movie libraries
426 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
427 #if defined(POLY_ACC)
428 gr_set_mode(SM_640x480x15xPA);
430 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
434 if ( args_find( "-notitles" ) )
435 songs_play_song( SONG_TITLE, 1);
438 { //NOTE LINK TO ABOVE!
439 int played=MOVIE_NOT_PLAYED; //default is not played
440 int song_playing = 0;
443 #define MOVIE_REQUIRED 0
445 #define MOVIE_REQUIRED 1
448 #ifdef D2_OEM //$$POLY_ACC, jay.
449 { //show bundler screens
451 char filename[FILENAME_LEN];
453 played=MOVIE_NOT_PLAYED; //default is not played
455 played = PlayMovie("pre_i.mve",0);
458 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
460 while ((tfile=fopen(filename,"rb")) != NULL) {
462 show_title_screen( filename, 1, 0 );
470 init_subtitles("intro.tex");
471 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
476 if (played != MOVIE_NOT_PLAYED)
478 else { //didn't get intro movie, try titles
480 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
482 if (played == MOVIE_NOT_PLAYED) {
483 #if defined(POLY_ACC)
484 gr_set_mode(SM_640x480x15xPA);
486 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
488 con_printf( CON_DEBUG, "\nPlaying title song..." );
489 songs_play_song( SONG_TITLE, 1);
491 con_printf( CON_DEBUG, "\nShowing logo screens..." );
492 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
493 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
497 { //show bundler movie or screens
500 char filename[FILENAME_LEN];
503 played=MOVIE_NOT_PLAYED; //default is not played
505 //check if OEM movie exists, so we don't stop the music if it doesn't
506 movie_handle = open_movie_file("oem.mve",0);
507 if (movie_handle != -1) {
509 played = PlayMovie("oem.mve",0);
510 song_playing = 0; //movie will kill sound
514 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
516 while ((tfile=fopen(filename,"rb")) != NULL) {
518 show_title_screen( filename, 1, 0 );
526 songs_play_song( SONG_TITLE, 1);
530 PA_DFX (pa_splash());
532 con_printf( CON_DEBUG, "\nShowing loading screen..." );
534 //grs_bitmap title_bm;
539 strcpy(filename, "descentd.pcx");
542 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
544 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
548 #if defined(POLY_ACC)
549 gr_set_mode(SM_640x480x15xPA);
551 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
554 FontHires = MenuHires;
556 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
557 //vfx_set_palette_sub( title_pal );
559 gr_palette_fade_in( title_pal, 32, 0 );
561 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
564 con_printf( CON_DEBUG , "\nDoing bm_init..." );
572 if (args_find("-hoarddata") != 0) {
573 #define MAX_BITMAPS_PER_BRUSH 30
574 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
578 ubyte palette[256*3];
581 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
582 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
583 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
584 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
586 ofile = fopen("hoard.ham","wb");
588 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
589 Assert(iff_error == IFF_NO_ERROR);
590 nframes_short = nframes;
591 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
592 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
593 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
594 fwrite(palette,3,256,ofile);
595 for (i=0;i<nframes;i++)
596 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
598 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
599 Assert(iff_error == IFF_NO_ERROR);
600 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
601 nframes_short = nframes;
602 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
603 fwrite(palette,3,256,ofile);
604 for (i=0;i<nframes;i++)
605 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
608 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
609 Assert(iff_error == IFF_NO_ERROR);
610 fwrite(&icon.bm_w,sizeof(short),1,ofile);
611 fwrite(&icon.bm_h,sizeof(short),1,ofile);
612 fwrite(palette,3,256,ofile);
613 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
616 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
620 ifile = fopen(sounds[i],"rb");
621 Assert(ifile != NULL);
622 size = filelength(ifile->_handle);
623 buf = d_malloc(size);
624 fread(buf,1,size,ifile);
625 fwrite(&size,sizeof(size),1,ofile);
626 fwrite(buf,1,size,ofile);
637 //the bitmap loading code changes gr_palette, so restore it
638 memcpy(gr_palette,title_pal,sizeof(gr_palette));
640 if ( args_find( "-norun" ) )
643 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
646 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
647 texmerge_init( 10 ); // 10 cache bitmaps
649 con_printf( CON_DEBUG, "\nRunning game...\n" );
650 set_screen_mode(SCREEN_MENU);
654 // If built with editor, option to auto-load a level and quit game
655 // to write certain data.
658 if ( t = args_find( "-autoload" ) ) {
660 strcpy(Auto_file, Args[t+1]);
666 strcpy(Players[0].callsign, "dummy");
669 do_register_player(title_pal);
671 gr_palette_fade_out( title_pal, 32, 0 );
673 Game_mode = GM_GAME_OVER;
676 newdemo_start_playback("descent.dem");
677 if (Newdemo_state == ND_STATE_PLAYBACK )
678 Function_mode = FMODE_GAME;
681 //do this here because the demo code can do a longjmp when trying to
682 //autostart a demo from the main menu, never having gone into the game
685 while (Function_mode != FMODE_EXIT)
687 switch( Function_mode ) {
689 set_screen_mode(SCREEN_MENU);
691 newdemo_start_playback(NULL); // Randomly pick a file
692 if (Newdemo_state != ND_STATE_PLAYBACK)
693 Error("No demo files were found for autodemo mode!");
697 strcpy(&Level_names[0], Auto_file);
699 Function_mode = FMODE_EXIT;
704 check_joystick_calibration();
705 gr_palette_clear(); //I'm not sure why we need this, but we do
708 if ( Function_mode == FMODE_EDITOR ) {
710 SetPlayerFromCurseg();
711 load_palette(NULL,1,0);
718 keyd_editor_mode = 0;
721 if ( Function_mode == FMODE_MENU )
722 songs_play_song( SONG_TITLE, 1 );
726 keyd_editor_mode = 1;
728 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
729 if ( Function_mode == FMODE_GAME ) {
730 Game_mode = GM_EDITOR;
731 editor_reset_stuff_on_level();
737 Error("Invalid function mode %d",Function_mode);
744 if (!args_find( "-notitles" ))
748 if ( args_find( "-showmeminfo" ) )
749 show_mem_info = 1; // Make memory statistics show
752 return(0); //presumably successful exit
756 void check_joystick_calibration() {
757 int x1, y1, x2, y2, c;
760 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
761 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
762 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
763 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
766 joy_get_pos( &x1, &y1 );
768 t1 = timer_get_fixed_seconds();
769 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
772 joy_get_pos( &x2, &y2 );
774 // If joystick hasn't moved...
775 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
776 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
777 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );