]> icculus.org git repositories - btb/d2x.git/blob - main/inferno.c
remove ObjType, ObjId, ObjStrength and OL_ constants; use "object" instead of "robot...
[btb/d2x.git] / main / inferno.c
1 /* $Id: inferno.c,v 1.101 2005-03-20 12:53:33 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * inferno.c: Entry point of program (main procedure)
18  *
19  * After main initializes everything, most of the time is spent in the loop
20  * while (Function_mode != FMODE_EXIT)
21  * In this loop, the main menu is brought up first.
22  *
23  * main() for Inferno
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include <conf.h>
29 #endif
30
31 char copyright[] = "DESCENT II  COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <limits.h>
37
38 #ifdef __unix__
39 #include <unistd.h>
40 #include <sys/stat.h>
41 #include <sys/types.h>
42 #endif
43
44 #include <physfs.h>
45
46 #include "pstypes.h"
47 #include "strutil.h"
48 #include "console.h"
49 #include "pa_enabl.h"       //$$POLY_ACC
50 #include "gr.h"
51 #include "fix.h"
52 #include "vecmat.h"
53 #include "mono.h"
54 #include "key.h"
55 #include "timer.h"
56 #include "3d.h"
57 #include "bm.h"
58 #include "inferno.h"
59 #include "error.h"
60 #include "game.h"
61 #include "segment.h"            //for Side_to_verts
62 #include "u_mem.h"
63 #include "segpoint.h"
64 #include "screens.h"
65 #include "texmap.h"
66 #include "texmerge.h"
67 #include "menu.h"
68 #include "wall.h"
69 #include "polyobj.h"
70 #include "effects.h"
71 #include "digi.h"
72 #include "iff.h"
73 #include "pcx.h"
74 #include "palette.h"
75 #include "args.h"
76 #include "sounds.h"
77 #include "titles.h"
78 #include "player.h"
79 #include "text.h"
80 #include "newdemo.h"
81 #ifdef NETWORK
82 #include "network.h"
83 #include "modem.h"
84 #endif
85 #include "gamefont.h"
86 #include "kconfig.h"
87 #include "mouse.h"
88 #include "joy.h"
89 #include "newmenu.h"
90 #include "desc_id.h"
91 #include "config.h"
92 #include "joydefs.h"
93 #include "multi.h"
94 #include "songs.h"
95 #include "cfile.h"
96 #include "gameseq.h"
97 #include "gamepal.h"
98 #include "mission.h"
99 #include "movie.h"
100
101 // #  include "3dfx_des.h"
102
103 //added on 9/30/98 by Matt Mueller for selectable automap modes
104 #include "automap.h"
105 //end addition -MM
106
107 #include "../texmap/scanline.h" //for select_tmap -MM
108
109 #if defined(POLY_ACC)
110 #include "poly_acc.h"
111 extern int Current_display_mode;        //$$ there's got to be a better way than hacking this.
112 #endif
113
114 #ifdef EDITOR
115 #include "editor/editor.h"
116 #include "editor/kdefs.h"
117 #include "ui.h"
118 #endif
119
120 #ifndef __MSDOS__
121 #include <SDL.h>
122 #endif
123
124 #include "vers_id.h"
125
126 void mem_init(void);
127 void arch_init(void);
128 void arch_init_start(void);
129
130 //Current version number
131
132 ubyte Version_major = 1;                //FULL VERSION
133 ubyte Version_minor = 2;
134
135 //static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; // 4-byte checksum
136 char desc_id_exit_num = 0;
137
138 int Function_mode=FMODE_MENU;           //game or editor?
139 int Screen_mode=-1;                                     //game screen or editor screen?
140
141 //--unused-- grs_bitmap Inferno_bitmap_title;
142
143 int WVIDEO_running=0;           //debugger can set to 1 if running
144
145 //--unused-- int Cyberman_installed=0;                  // SWIFT device present
146 ubyte CybermouseActive=0;
147
148 #ifdef __WATCOMC__
149 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
150 #endif
151
152 void check_joystick_calibration(void);
153
154 void show_order_form(void);
155
156 //--------------------------------------------------------------------------
157
158 extern int piggy_low_memory;
159
160
161 int descent_critical_error = 0;
162 unsigned descent_critical_deverror = 0;
163 unsigned descent_critical_errcode = 0;
164
165 extern int Network_allow_socket_changes;
166
167 extern void vfx_set_palette_sub(ubyte *);
168
169 extern int VR_low_res;
170
171 extern int Config_vr_type;
172 extern int Config_vr_resolution;
173 extern int Config_vr_tracking;
174
175 #define LINE_LEN        100
176
177 //read help from a file & print to screen
178 void print_commandline_help()
179 {
180         CFILE *ifile;
181         int have_binary=0;
182         char line[LINE_LEN];
183
184         ifile = cfopen("help.tex","rb");
185         if (!ifile) {
186                 ifile = cfopen("help.txb","rb");
187                 if (!ifile)
188                         Warning("Cannot load help text file.");
189                 have_binary = 1;
190         }
191
192         if (ifile)
193         {
194         char *end;
195         
196                 while ((end = cfgets(line,LINE_LEN,ifile))) {
197
198             // This is the only use of cfgets that needs the CR
199             *end++ = '\n';
200                         if (have_binary)
201                                 decode_text_line (line);
202
203                         if (line[0] == ';')
204                                 continue;               //don't show comments
205
206                         printf("%s",line);
207
208                 }
209
210                 cfclose(ifile);
211
212         }
213
214 //      printf( " Diagnostic:\n\n");
215 //      printf( "  -emul           %s\n", "Certain video cards need this option in order to run game");
216 //      printf( "  -ddemul         %s\n", "If -emul doesn't work, use this option");
217 //      printf( "\n");
218 #ifdef EDITOR
219         printf( " Editor Options:\n\n");
220         printf( "  -autoload <file>%s\n", "Autoload a level in the editor");
221         printf( "  -hoarddata      %s\n","Make the hoard ham file from some files, then exit");
222 //      printf( "  -nobm           %s\n","FIXME: Undocumented");
223         printf( "\n");
224 #endif
225         printf( " D2X Options:\n\n");
226         printf( "  -noredundancy   %s\n", "Do not send messages when picking up redundant items in multi");
227         printf( "  -shortpackets   %s\n", "Set shortpackets to default as on");
228 #ifdef OGL // currently only does anything on ogl build, so don't advertise othewise.
229         printf("  -renderstats    %s\n", "Enable renderstats info by default");
230 #endif
231         printf( "  -maxfps <n>     %s\n", "Set maximum framerate (1-100)");
232         printf( "  -notitles       %s\n", "Do not show titlescreens on startup");
233         printf( "  -hogdir <dir>   %s\n", "set shared data directory to <dir>");
234 #ifdef __unix__
235         printf( "  -nohogdir       %s\n", "don't try to use shared data directory");
236         printf( "  -userdir <dir>  %s\n", "set user dir to <dir> instead of $HOME/.d2x");
237 #endif
238         printf( "  -ini <file>     %s\n", "option file (alternate to command line), defaults to d2x.ini");
239         printf( "  -autodemo       %s\n", "Start in demo mode");
240         printf( "  -bigpig         %s\n","FIXME: Undocumented");
241         printf( "  -bspgen         %s\n","FIXME: Undocumented");
242 //      printf( "  -cdproxy        %s\n","FIXME: Undocumented");
243 #ifndef NDEBUG
244         printf( "  -checktime      %s\n","FIXME: Undocumented");
245         printf( "  -showmeminfo    %s\n","FIXME: Undocumented");
246 #endif
247 //      printf( "  -codereadonly   %s\n","FIXME: Undocumented");
248 //      printf( "  -cyberimpact    %s\n","FIXME: Undocumented");
249         printf( "  -debug          %s\n","Enable very verbose output");
250 //      printf( "  -debugmode      %s\n","FIXME: Undocumented");
251 //      printf( "  -disallowgfx    %s\n","FIXME: Undocumented");
252 //      printf( "  -disallowreboot %s\n","FIXME: Undocumented");
253 //      printf( "  -dynamicsockets %s\n","FIXME: Undocumented");
254 //      printf( "  -forcegfx       %s\n","FIXME: Undocumented");
255 #ifdef SDL_INPUT
256         printf( "  -grabmouse      %s\n","Keeps the mouse from wandering out of the window");
257 #endif
258 //      printf( "  -hw_3dacc       %s\n","FIXME: Undocumented");
259 #ifndef RELEASE
260         printf( "  -invulnerability %s\n","Make yourself invulnerable");
261 #endif
262         printf( "  -ipxnetwork <num> %s\n","Use IPX network number <num>");
263         printf( "  -jasen          %s\n","FIXME: Undocumented");
264         printf( "  -joyslow        %s\n","FIXME: Undocumented");
265 #ifdef NETWORK
266         printf( "  -kali           %s\n","use Kali for networking");
267 #endif
268 //      printf( "  -logfile        %s\n","FIXME: Undocumented");
269         printf( "  -lowresmovies   %s\n","Play low resolution movies if available (for slow machines)");
270 #if defined(EDITOR) || !defined(MACDATA)
271         printf( "  -macdata        %s\n","Read (and, for editor, write) mac data files (swap colors)");
272 #endif
273 //      printf( "  -memdbg         %s\n","FIXME: Undocumented");
274 //      printf( "  -monodebug      %s\n","FIXME: Undocumented");
275         printf( "  -nocdrom        %s\n","FIXME: Undocumented");
276 #ifdef __DJGPP__
277         printf( "  -nocyberman     %s\n","FIXME: Undocumented");
278 #endif
279 #ifndef NDEBUG
280         printf( "  -nofade         %s\n","Disable fades");
281 #endif
282 #ifdef NETWORK
283         printf( "  -nomatrixcheat  %s\n","FIXME: Undocumented");
284         printf( "  -norankings     %s\n","Disable multiplayer ranking system");
285         printf( "  -packets <num>  %s\n","Specifies the number of packets per second\n");
286 //      printf( "  -showaddress    %s\n","FIXME: Undocumented");
287         printf( "  -socket         %s\n","FIXME: Undocumented");
288 #endif
289 #if !defined(MACINTOSH) && !defined(WINDOWS)
290         printf( "  -nomixer        %s\n","Don't crank music volume");
291 //      printf( "  -superhires     %s\n","Allow higher-resolution modes");
292 #endif
293 //      printf( "  -nomodex        %s\n","FIXME: Undocumented");
294 #ifndef RELEASE
295         printf( "  -nomovies       %s\n","Don't play movies");
296         printf( "  -noscreens      %s\n","Skip briefing screens");
297 #endif
298 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
299         printf( "  -noredbook      %s\n","Disable redbook audio");
300 #endif
301         printf( "  -norun          %s\n","Bail out after initialization");
302 //      printf( "  -ordinaljoy     %s\n","FIXME: Undocumented");
303 //      printf( "  -rtscts         %s\n","Same as -ctsrts");
304 //      printf( "  -semiwin        %s\n","Use non-fullscreen mode");
305 //      printf( "  -specialdevice  %s\n","FIXME: Undocumented");
306 #ifdef TACTILE
307         printf( "  -stickmag       %s\n","FIXME: Undocumented");
308 #endif
309 //      printf( "  -stopwatch      %s\n","FIXME: Undocumented");
310         printf( "  -subtitles      %s\n","Turn on movie subtitles (English-only)");
311 //      printf( "  -sysram         %s\n","FIXME: Undocumented");
312         printf( "  -text <file>    %s\n","Specify alternate .tex file");
313 //      printf( "  -tsengdebug1    %s\n","FIXME: Undocumented");
314 //      printf( "  -tsengdebug2    %s\n","FIXME: Undocumented");
315 //      printf( "  -tsengdebug3    %s\n","FIXME: Undocumented");
316 //      printf( "  -vidram         %s\n","FIXME: Undocumented");
317         printf( "  -xcontrol       %s\n","FIXME: Undocumented");
318         printf( "  -xname          %s\n","FIXME: Undocumented");
319         printf( "  -xver           %s\n","FIXME: Undocumented");
320         printf( "  -tmap <t>       %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
321 #ifdef __MSDOS__
322         printf( "  -<X>x<Y>        %s\n", "Change screen resolution. Options:");
323         printf( "                     320x100;320x200;320x240;320x400;640x400;640x480;800x600;1024x768\n");
324 #else
325         printf( "  -<X>x<Y>        %s\n", "Change screen resolution to <X> by <Y>");
326 #endif
327         printf("  -niceautomap    %s\n", "Free cpu while doing automap");
328         printf( "  -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
329         printf( "  -automap_gameres %s\n","Set automap to use the same resolution as in game");
330 //      printf( "  -menu<X>x<Y>    %s\n","Set menu resolution to <X> by <Y>");
331 //      printf( "  -menu_gameres   %s\n","Set menus to use the same resolution as in game");
332         printf("  -rearviewtime t %s\n", "time holding rearview key to use toggle mode (default 0.0625 seconds)");
333         printf( "\n");
334
335         printf( "D2X System Options:\n\n");
336 #ifdef __MSDOS__
337         printf("  -ihaveabrokenmouse %s\n", "try to make mouse work if it is not currently");
338         printf( "  -joy209         %s\n", "Use alternate port 209 for joystick");
339 #endif
340 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
341         printf( "  -fullscreen     %s\n", "Use fullscreen mode if available");
342 #endif
343 #ifdef OGL
344         printf( "  -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
345         printf( "  -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
346         printf("  -gl_mipmap      %s\n", "set gl texture filters to \"standard\" (bilinear) mipmapping");
347         printf("  -gl_trilinear   %s\n", "set gl texture filters to trilinear mipmapping");
348         printf( "  -gl_simple      %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
349         printf("  -gl_anisotropy <f> %s\n", "set maximum degree of anisotropy to <f>");
350         printf( "  -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
351         printf( "  -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
352 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
353         printf( "  -gl_voodoo      %s\n","force fullscreen mode only");
354 #endif
355         printf( "  -gl_16bittextures %s\n","attempt to use 16bit textures");
356         printf("  -gl_16bpp       %s\n", "attempt to use 16bit screen mode");
357         printf( "  -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
358         printf( "  -gl_intensity4_ok %s\n","FIXME: Undocumented");
359         printf( "  -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
360         printf( "  -gl_readpixels_ok %s\n","FIXME: Undocumented");
361         printf( "  -gl_rgba2_ok    %s\n","FIXME: Undocumented");
362 //      printf( "  -gl_test1       %s\n","FIXME: Undocumented");
363         printf( "  -gl_test2       %s\n","FIXME: Undocumented");
364         printf( "  -gl_vidmem      %s\n","FIXME: Undocumented");
365 #ifdef OGL_RUNTIME_LOAD
366         printf( "  -gl_library <l> %s\n","use alternate opengl library");
367 #endif
368 #ifdef WGL_VIDEO
369         printf("  -gl_refresh <r> %s\n", "set refresh rate (in fullscreen mode)");
370 #endif
371 #endif
372 #ifdef SDL_VIDEO
373         printf( "  -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
374         printf( "  -hwsurface      %s\n","FIXME: Undocumented");
375 #endif
376 #ifdef NETWORK
377         printf("  -udp            %s\n", "Specify options for udp/ip:");
378         printf("    @<shift>      %s\n", "  shift udp port base offset");
379         printf("    =<HOST_LIST>  %s\n", "  broadcast both local and to HOST_LIST");
380         printf("    +<HOST_LIST>  %s\n", "  broadcast only to HOST_LIST");
381         printf("                  %s\n", "   HOSTS can be any IP or hostname")
382                 ;
383         printf("                  %s\n", "   HOSTS can also be in the form of <address>:<shift>");
384         printf("                  %s\n", "   separate multiple HOSTS with a ,");
385 #endif
386 #ifdef __unix__
387         printf( "  -serialdevice <s> %s\n", "Set serial/modem device to <s>");
388         printf( "  -serialread <r> %s\n", "Set serial/modem to read from <r>");
389 #endif
390         printf( "\n Help:\n\n");
391         printf( "  -help, -h, -?, ? %s\n", "View this help screen");
392         printf( "\n");
393 }
394
395 void do_joystick_init()
396 {
397
398         if (!FindArg( "-nojoystick" ))  {
399                 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
400                 joy_init();
401                 if ( FindArg( "-joyslow" ))     {
402                         con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
403                         joy_set_slow_reading(JOY_SLOW_READINGS);
404                 }
405                 if ( FindArg( "-joypolled" ))   {
406                         con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
407                         joy_set_slow_reading(JOY_POLLED_READINGS);
408                 }
409                 if ( FindArg( "-joybios" ))     {
410                         con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
411                         joy_set_slow_reading(JOY_BIOS_READINGS);
412                 }
413
414         //      Added from Descent v1.5 by John.  Adapted by Samir.
415         } else {
416                 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
417         }
418 }
419
420 //set this to force game to run in low res
421 int disable_high_res=0;
422
423 void do_register_player(ubyte *title_pal)
424 {
425         Players[Player_num].callsign[0] = '\0';
426
427         if (!Auto_demo)         {
428
429                 key_flush();
430
431                 //now, before we bring up the register player menu, we need to
432                 //do some stuff to make sure the palette is ok.  First, we need to
433                 //get our current palette into the 2d's array, so the remapping will
434                 //work.  Second, we need to remap the fonts.  Third, we need to fill
435                 //in part of the fade tables so the darkening of the menu edges works
436
437                 memcpy(gr_palette,title_pal,sizeof(gr_palette));
438                 remap_fonts_and_menus(1);
439                 RegisterPlayer();               //get player's name
440         }
441
442 }
443
444 #define PROGNAME argv[0]
445
446 extern char Language[];
447
448 //can we do highres menus?
449 extern int MenuHiresAvailable;
450
451 int intro_played = 0;
452
453 int Inferno_verbose = 0;
454
455 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
456 int start_net_immediately = 0;
457 //int start_with_mission = 0;
458 //char *start_with_mission_name;
459 //end this section addition
460
461 #if defined(POLY_ACC)
462 #define MENU_HIRES_MODE SM_640x480x15xPA
463 #else
464 #define MENU_HIRES_MODE SM(640,480)
465 #endif
466
467 //      DESCENT II by Parallax Software
468 //              Descent Main
469
470 //extern ubyte gr_current_pal[];
471
472 #ifdef  EDITOR
473 int     Auto_exit = 0;
474 char    Auto_file[128] = "";
475 #endif
476
477 int main(int argc, char *argv[])
478 {
479         int i, t;
480         ubyte title_pal[768];
481
482         PHYSFS_init(argv[0]);
483         PHYSFS_permitSymbolicLinks(1);
484
485         con_init();  // Initialise the console
486         mem_init();
487
488         error_init(NULL, NULL);
489
490         PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
491         InitArgs( argc,argv );
492
493         if ((t = FindArg("-userdir"))
494 #ifdef __unix__
495          || 1   // or if it's a unix platform
496 #endif
497          )
498         {
499                 // This stuff below seems overly complicated - brad
500
501                 char *path = Args[t+1];
502                 char fullPath[PATH_MAX + 5];
503
504 #ifdef __unix__
505                 if (!t)
506                         path = "~/.d2x";
507 #endif
508                 PHYSFS_removeFromSearchPath(PHYSFS_getBaseDir());
509                 
510                 if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
511                 {
512                         const char *home = PHYSFS_getUserDir();
513                         
514                         strcpy(fullPath, home); // prepend home to the path
515                         path++;
516                         if (*path == *PHYSFS_getDirSeparator())
517                                 path++;
518                         strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
519                 }
520                 else
521                         strncpy(fullPath, path, PATH_MAX + 5);
522                 
523                 PHYSFS_setWriteDir(fullPath);
524                 if (!PHYSFS_getWriteDir())  // need to make it
525                 {
526                         PHYSFS_mkdir(fullPath);
527                         PHYSFS_setWriteDir(fullPath);
528                 }
529                         
530                 PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1);
531                 AppendArgs();
532         }
533
534         if (!PHYSFS_getWriteDir())
535         {
536                 PHYSFS_setWriteDir(PHYSFS_getBaseDir());
537                 if (!PHYSFS_getWriteDir())
538                         Error("can't set write dir\n");
539                 else
540                         PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 0);
541         }
542         
543         if (FindArg("-debug"))
544                 con_threshold.value = (float)2;
545         else if (FindArg("-verbose"))
546                 con_threshold.value = (float)1;
547
548         //tell cfile where hogdir is
549         if ((t=FindArg("-hogdir")))
550                 PHYSFS_addToSearchPath(Args[t + 1], 1);
551 #ifdef __unix__
552         else if (!FindArg("-nohogdir"))
553                 PHYSFS_addToSearchPath(SHAREPATH, 1);
554 #endif
555
556         if (! cfile_init("descent2.hog"))
557                 if (! cfile_init("d2demo.hog"))
558                         Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
559 #ifdef __unix__
560                               "\t$HOME/.d2x\n"
561                               "\t" SHAREPATH "\n"
562 #else
563                                   "\tCurrent directory\n"
564 #endif
565                                   "Or use the -hogdir option to specify an alternate location.");
566         load_text();
567
568         //print out the banner title
569         con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
570         #ifdef VERSION_NAME
571         con_printf(CON_NORMAL, "  %s", VERSION_NAME);
572         #endif
573         if (cfexist(MISSION_DIR "d2x.hog"))
574                 con_printf(CON_NORMAL, "  Vertigo Enhanced");
575
576         con_printf(CON_NORMAL, "  %s %s\n", __DATE__,__TIME__);
577         con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
578         con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
579         con_printf(CON_NORMAL, "                                         Copyright (c) 2002 Bradley Bell\n");
580
581
582         if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
583                 print_commandline_help();
584                 set_exit_message("");
585 #ifdef __MINGW32__
586                 exit(0);  /* mingw hangs on this return.  dunno why */
587 #endif
588                 return(0);
589         }
590
591         con_printf(CON_NORMAL, "\n");
592         con_printf(CON_NORMAL, TXT_HELP, PROGNAME);             //help message has %s for program name
593         con_printf(CON_NORMAL, "\n");
594
595         {
596                 char **i, **list;
597
598                 for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
599                         con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
600
601                 list = PHYSFS_getCdRomDirs();
602                 for (i = list; *i != NULL; i++)
603                         con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
604                 PHYSFS_freeList(list);
605
606                 list = PHYSFS_enumerateFiles("");
607                 for (i = list; *i != NULL; i++)
608                         con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
609                 PHYSFS_freeList(list);
610         }
611
612         //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
613         if(FindArg("-sound22k"))
614         {
615                 digi_sample_rate = SAMPLE_RATE_22K;
616         }
617
618         if(FindArg("-sound11k"))
619         {
620                 digi_sample_rate = SAMPLE_RATE_11K;
621         }
622
623         arch_init_start();
624
625         arch_init();
626
627         //con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
628
629         if ((t = FindArg("-rearviewtime")))
630         {
631                 float f = atof(Args[t + 1]);
632                 Rear_view_leave_time = f * f1_0;
633         }
634         con_printf(CON_VERBOSE, "Rear_view_leave_time=0x%x (%f sec)\n", Rear_view_leave_time, Rear_view_leave_time / (float)f1_0);
635
636         //added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
637         if ((t = FindArg( "-maxfps" ))) {
638                 t=atoi(Args[t+1]);
639                 if (t > 0 && t <= MAX_FPS)
640                         maxfps=t;
641         }
642         //end addition - Victor Rachels
643
644 #ifdef SUPPORTS_NICEFPS
645         if (FindArg("-nicefps"))
646                 use_nice_fps = 1;
647         if (FindArg("-niceautomap"))
648                 nice_automap = 1;
649 #endif
650
651         if (FindArg("-renderstats"))
652                 gr_renderstats = 1;
653
654         if ( FindArg( "-autodemo" ))
655                 Auto_demo = 1;
656
657 #ifndef RELEASE
658         if ( FindArg( "-noscreens" ) )
659                 Skip_briefing_screens = 1;
660 #endif
661
662         if ((t=FindArg("-tmap"))){
663                 select_tmap(Args[t+1]);
664         }else
665                 select_tmap(NULL);
666
667         Lighting_on = 1;
668
669 //      if (init_graphics()) return 1;
670
671         #ifdef EDITOR
672         if (gr_check_mode(SM(800, 600)) != 0)
673         {
674                 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
675                 Function_mode = FMODE_MENU;
676         }
677         #endif
678
679         if (!WVIDEO_running)
680                 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
681
682         con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
683         ReadConfigFile();
684
685         do_joystick_init();
686
687 #if defined(POLY_ACC)
688     Current_display_mode = -1;
689     game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
690 #else
691
692         if (!VR_offscreen_buffer)       //if hasn't been initialied (by headset init)
693                 set_display_mode(0);            //..then set default display mode
694 #endif
695
696         {
697                 int screen_width = 640;
698                 int screen_height = 480;
699                 int vr_mode = VR_NONE;
700                 int screen_flags = VRF_USE_PAGING;
701
702                 if (FindResArg("", &screen_width, &screen_height))
703                 {
704                         /* stuff below mirrors values from display_mode_info in
705                          * menu.c which is used by set_display_mode. In fact,
706                          * set_display_mode should probably be rewritten to allow
707                          * arbitrary resolutions, and then we get rid of this
708                          * stuff here.
709                          */
710                         switch (SM(screen_width, screen_height))
711                         {
712                         case SM(320, 200):
713                         case SM(640, 480):
714                                 screen_flags = VRF_ALLOW_COCKPIT + VRF_COMPATIBLE_MENUS;
715                                 break;
716                         case SM(320, 400):
717                                 screen_flags = VRF_USE_PAGING;
718                                 break;
719                         case SM(640, 400):
720                         case SM(800, 600):
721                         case SM(1024, 768):
722                         case SM(1280, 1024):
723                                 screen_flags = VRF_COMPATIBLE_MENUS;
724                                 break;
725                         }
726
727                         con_printf(CON_VERBOSE, "Using %ix%i ...\n", screen_width, screen_height);
728                 }
729
730 // added ifdef on 9/30/98 by Matt Mueller to fix high res in linux
731 #ifdef __MSDOS__
732                 if (FindArg("-nodoublebuffer"))
733 #endif
734 // end addition -MM
735                 {
736                         con_printf(CON_VERBOSE, "Double-buffering disabled...\n");
737                         screen_flags &= ~VRF_USE_PAGING;
738                 }
739
740                 // added 3/24/99 by Owen Evans for screen res changing
741                 Game_screen_mode = SM(screen_width, screen_height);
742                 // end added -OE
743                 game_init_render_buffers(Game_screen_mode, screen_width, screen_height, vr_mode, screen_flags);
744
745         }
746         {
747 // added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
748                 int i, argnum = INT_MAX, w, h;
749 // added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines. - edited 03/31/02 to use new FindResArg.
750 #define SMODE(V,VV,VG) if ((i=FindResArg(#V, &w, &h)) && (i < argnum)) { argnum = i; VV = SM(w, h); VG = 0; }
751 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
752 #define SMODE_PRINT(V,VV,VG) if (VG) con_printf(CON_VERBOSE, #V " using game resolution ...\n"); else con_printf(CON_VERBOSE, #V " using %ix%i ...\n",SM_W(VV),SM_H(VV) );
753 // aren't #defines great? :)
754 // end addition/edit -MM
755 #define S_MODE(V,VV,VG) argnum = INT_MAX; SMODE(V, VV, VG); SMODE_GR(V, VG); SMODE_PRINT(V, VV, VG);
756
757                 S_MODE(automap,automap_mode,automap_use_game_res);
758 //              S_MODE(menu,menu_screen_mode,menu_use_game_res);
759          }
760 //end addition -MM
761
762         i = FindArg( "-xcontrol" );
763         if ( i > 0 )    {
764                 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
765         }
766
767         con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
768         if (FindArg("-nofade"))
769                 grd_fades_disabled=1;
770
771         //determine whether we're using high-res menus & movies
772 #if !defined(POLY_ACC)
773         if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
774                 MovieHires = MenuHires = MenuHiresAvailable = 0;
775         else
776 #endif
777                 //NOTE LINK TO ABOVE!
778                 MenuHires = MenuHiresAvailable = 1;
779
780         if (FindArg( "-lowresmovies" ))
781                 MovieHires = 0;
782
783         if ((t=gr_init())!=0)                           //doesn't do much
784                 Error(TXT_CANT_INIT_GFX,t);
785
786    #ifdef _3DFX
787    _3dfx_Init();
788    #endif
789
790         // Load the palette stuff. Returns non-zero if error.
791         con_printf(CON_DEBUG, "Initializing palette system...\n" );
792         gr_use_palette_table(DEFAULT_PALETTE );
793
794         con_printf(CON_DEBUG, "Initializing font system...\n" );
795         gamefont_init();        // must load after palette data loaded.
796
797         con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
798         init_movies();          //init movie libraries
799
800 #if 0
801         con_printf(CON_VERBOSE, "Going into graphics mode...\n");
802 #if defined(POLY_ACC)
803         gr_set_mode(SM_640x480x15xPA);
804 #else
805         gr_set_mode(MovieHires?SM(640,480):SM(320,200));
806 #endif
807 #endif
808
809         if ( FindArg( "-notitles" ) )
810                 songs_play_song( SONG_TITLE, 1);
811         else
812         {
813 #ifndef SHAREWARE
814                 int played=MOVIE_NOT_PLAYED;    //default is not played
815 #endif
816                 int song_playing = 0;
817
818                 #ifdef D2_OEM
819                 #define MOVIE_REQUIRED 0
820                 #else
821                 #define MOVIE_REQUIRED 1
822                 #endif
823
824                 {       //show bundler screens
825                         char filename[FILENAME_LEN];
826
827                         played=MOVIE_NOT_PLAYED;        //default is not played
828
829             played = PlayMovie("pre_i.mve",0);
830
831                         if (!played) {
832                 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
833
834                                 while (PHYSFS_exists(filename))
835                                 {
836                                         show_title_screen( filename, 1, 0 );
837                     filename[5]++;
838                                 }
839                         }
840                 }
841
842                 #ifndef SHAREWARE
843                         init_subtitles("intro.tex");
844                         played = PlayMovie("intro.mve",MOVIE_REQUIRED);
845                         close_subtitles();
846                 #endif
847
848                 if (played != MOVIE_NOT_PLAYED)
849                         intro_played = 1;
850                 else {                                          //didn't get intro movie, try titles
851
852                         played = PlayMovie("titles.mve",MOVIE_REQUIRED);
853
854                         if (played == MOVIE_NOT_PLAYED)
855                         {
856                                 char filename[FILENAME_LEN];
857
858 #if defined(POLY_ACC)
859                                 gr_set_mode(SM_640x480x15xPA);
860 #else
861                                 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
862 #endif
863 #ifdef OGL
864                                 set_screen_mode(SCREEN_MENU);
865 #endif
866                                 con_printf( CON_DEBUG, "\nPlaying title song..." );
867                                 songs_play_song( SONG_TITLE, 1);
868                                 song_playing = 1;
869                                 con_printf( CON_DEBUG, "\nShowing logo screens..." );
870
871                                 strcpy(filename, MenuHires?"iplogo1b.pcx":"iplogo1.pcx"); // OEM
872                                 if (! cfexist(filename))
873                                         strcpy(filename, "iplogo1.pcx"); // SHAREWARE
874                                 if (! cfexist(filename))
875                                         strcpy(filename, "mplogo.pcx"); // MAC SHAREWARE
876                                 if (cfexist(filename))
877                                         show_title_screen(filename, 1, 1);
878
879                                 strcpy(filename, MenuHires?"logob.pcx":"logo.pcx"); // OEM
880                                 if (! cfexist(filename))
881                                         strcpy(filename, "logo.pcx"); // SHAREWARE
882                                 if (! cfexist(filename))
883                                         strcpy(filename, "plogo.pcx"); // MAC SHAREWARE
884                                 if (cfexist(filename))
885                                         show_title_screen(filename, 1, 1);
886                         }
887                 }
888
889                 {       //show bundler movie or screens
890
891                         char filename[FILENAME_LEN];
892                         PHYSFS_file *movie_handle;
893
894                         played=MOVIE_NOT_PLAYED;        //default is not played
895
896                         //check if OEM movie exists, so we don't stop the music if it doesn't
897                         movie_handle = PHYSFS_openRead("oem.mve");
898                         if (movie_handle)
899                         {
900                                 PHYSFS_close(movie_handle);
901                                 played = PlayMovie("oem.mve",0);
902                                 song_playing = 0;               //movie will kill sound
903                         }
904
905                         if (!played) {
906                                 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
907
908                                 while (PHYSFS_exists(filename))
909                                 {
910                                         show_title_screen( filename, 1, 0 );
911                                         filename[3]++;
912                                 }
913                         }
914                 }
915
916                 if (!song_playing)
917                         songs_play_song( SONG_TITLE, 1);
918                         
919         }
920
921         PA_DFX (pa_splash());
922
923         con_printf( CON_DEBUG, "\nShowing loading screen..." );
924         {
925                 //grs_bitmap title_bm;
926                 int pcx_error;
927                 char filename[14];
928
929                 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
930                 if (! cfexist(filename))
931                         strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
932                 if (! cfexist(filename))
933                         strcpy(filename, "descentd.pcx"); // SHAREWARE
934                 if (! cfexist(filename))
935                         strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
936
937 #if defined(POLY_ACC)
938                 gr_set_mode(SM_640x480x15xPA);
939 #else
940                 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
941 #endif
942 #ifdef OGL
943                 set_screen_mode(SCREEN_MENU);
944 #endif
945
946                 FontHires = FontHiresAvailable && MenuHires;
947
948                 if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE)        {
949                         //vfx_set_palette_sub( title_pal );
950                         gr_palette_clear();
951                         gr_palette_fade_in( title_pal, 32, 0 );
952                         gr_update();
953                 } else
954                         Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
955         }
956
957         con_printf( CON_DEBUG , "\nDoing bm_init..." );
958         #ifdef EDITOR
959         if (!bm_init_use_tbl())
960         #endif
961                 bm_init();
962
963         #ifdef EDITOR
964         if (FindArg("-hoarddata") != 0) {
965                 #define MAX_BITMAPS_PER_BRUSH 30
966                 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
967                 grs_bitmap icon;
968                 int nframes;
969                 ubyte palette[256*3];
970                 PHYSFS_file *ofile;
971                 int iff_error,i;
972                 char *sounds[] = {"selforb.raw","selforb.r22",          //SOUND_YOU_GOT_ORB                     
973                                                                 "teamorb.raw","teamorb.r22",            //SOUND_FRIEND_GOT_ORB                  
974                                                                 "enemyorb.raw","enemyorb.r22",  //SOUND_OPPONENT_GOT_ORB        
975                                                                 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
976
977                 ofile = PHYSFSX_openWriteBuffered("hoard.ham");
978
979            iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
980                 Assert(iff_error == IFF_NO_ERROR);
981                 PHYSFS_writeULE16(ofile, nframes);
982                 PHYSFS_writeULE16(ofile, bm[0]->bm_w);
983                 PHYSFS_writeULE16(ofile, bm[0]->bm_h);
984                 PHYSFS_write(ofile, palette, 3, 256);
985                 for (i=0;i<nframes;i++)
986                         PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
987
988                 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
989                 Assert(iff_error == IFF_NO_ERROR);
990                 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
991                 PHYSFS_writeULE16(ofile, nframes);
992                 PHYSFS_write(ofile, palette, 3, 256);
993                 for (i=0;i<nframes;i++)
994                         PHYSFS_write(ofile, bm[i]->bm_data, bm[i]->bm_w*bm[i]->bm_h, 1);
995
996                 for (i=0;i<2;i++) {
997                         iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
998                         Assert(iff_error == IFF_NO_ERROR);
999                         PHYSFS_writeULE16(ofile, icon.bm_w);
1000                         PHYSFS_writeULE16(ofile, icon.bm_h);
1001                         PHYSFS_write(ofile, palette, 3, 256);
1002                         PHYSFS_write(ofile, icon.bm_data, icon.bm_w*icon.bm_h, 1);
1003                 }
1004
1005                 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
1006                         PHYSFS_file *ifile;
1007                         int size;
1008                         ubyte *buf;
1009
1010                         ifile = PHYSFS_openRead(sounds[i]);
1011                         Assert(ifile != NULL);
1012                         size = PHYSFS_fileLength(ifile);
1013                         buf = d_malloc(size);
1014                         PHYSFS_read(ifile, buf, size, 1);
1015                         PHYSFS_writeULE32(ofile, size);
1016                         PHYSFS_write(ofile, buf, size, 1);
1017                         d_free(buf);
1018                         PHYSFS_close(ifile);
1019                 }
1020
1021                 PHYSFS_close(ofile);
1022
1023                 exit(1);
1024         }
1025         #endif
1026
1027         //the bitmap loading code changes gr_palette, so restore it
1028         memcpy(gr_palette,title_pal,sizeof(gr_palette));
1029
1030         if ( FindArg( "-norun" ) )
1031                 return(0);
1032
1033         con_printf( CON_DEBUG, "\nInitializing 3d system..." );
1034         g3_init();
1035
1036         con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
1037         texmerge_init( 10 );            // 10 cache bitmaps
1038
1039         con_printf( CON_DEBUG, "\nRunning game...\n" );
1040         set_screen_mode(SCREEN_MENU);
1041
1042         init_game();
1043
1044         //      If built with editor, option to auto-load a level and quit game
1045         //      to write certain data.
1046         #ifdef  EDITOR
1047         {       int t;
1048         if ( (t = FindArg( "-autoload" )) ) {
1049                 Auto_exit = 1;
1050                 strcpy(Auto_file, Args[t+1]);
1051         }
1052                 
1053         }
1054
1055         if (Auto_exit) {
1056                 strcpy(Players[0].callsign, "dummy");
1057         } else
1058         #endif
1059                 do_register_player(title_pal);
1060
1061         gr_palette_fade_out( title_pal, 32, 0 );
1062
1063         Game_mode = GM_GAME_OVER;
1064
1065         if (Auto_demo)  {
1066                 newdemo_start_playback("descent.dem");          
1067                 if (Newdemo_state == ND_STATE_PLAYBACK )
1068                         Function_mode = FMODE_GAME;
1069         }
1070
1071         //do this here because the demo code can do a longjmp when trying to
1072         //autostart a demo from the main menu, never having gone into the game
1073         setjmp(LeaveGame);
1074
1075         while (Function_mode != FMODE_EXIT)
1076         {
1077                 switch( Function_mode ) {
1078                 case FMODE_MENU:
1079                         set_screen_mode(SCREEN_MENU);
1080                         if ( Auto_demo )        {
1081                                 newdemo_start_playback(NULL);           // Randomly pick a file
1082                                 if (Newdemo_state != ND_STATE_PLAYBACK) 
1083                                         Error("No demo files were found for autodemo mode!");
1084                         } else {
1085                                 #ifdef EDITOR
1086                                 if (Auto_exit) {
1087                                         strcpy((char *)&Level_names[0], Auto_file);
1088                                         LoadLevel(1, 1);
1089                                         Function_mode = FMODE_EXIT;
1090                                         break;
1091                                 }
1092                                 #endif
1093
1094                                 check_joystick_calibration();
1095                                 gr_palette_clear();             //I'm not sure why we need this, but we do
1096                                 DoMenu();                                                                               
1097                                 #ifdef EDITOR
1098                                 if ( Function_mode == FMODE_EDITOR )    {
1099                                         create_new_mine();
1100                                         SetPlayerFromCurseg();
1101                                         load_palette(NULL,1,0);
1102                                 }
1103                                 #endif
1104                         }
1105                         break;
1106                 case FMODE_GAME:
1107                         #ifdef EDITOR
1108                                 keyd_editor_mode = 0;
1109                         #endif
1110
1111 #ifdef SDL_INPUT
1112                         /* keep the mouse from wandering in SDL */
1113                         if (FindArg("-grabmouse"))
1114                             SDL_WM_GrabInput(SDL_GRAB_ON);
1115 #endif
1116
1117                         game();
1118
1119 #ifdef SDL_INPUT
1120                         /* give control back to the WM */
1121                         if (FindArg("-grabmouse"))
1122                             SDL_WM_GrabInput(SDL_GRAB_OFF);
1123 #endif
1124
1125                         if ( Function_mode == FMODE_MENU )
1126                                 songs_play_song( SONG_TITLE, 1 );
1127                         break;
1128                 #ifdef EDITOR
1129                 case FMODE_EDITOR:
1130                         keyd_editor_mode = 1;
1131                         editor();
1132 #ifdef __WATCOMC__
1133                         _harderr( (void*)descent_critical_error_handler );              // Reinstall game error handler
1134 #endif
1135                         if ( Function_mode == FMODE_GAME ) {
1136                                 Game_mode = GM_EDITOR;
1137                                 editor_reset_stuff_on_level();
1138                                 N_players = 1;
1139                         }
1140                         break;
1141                 #endif
1142                 default:
1143                         Error("Invalid function mode %d",Function_mode);
1144                 }
1145         }
1146
1147         WriteConfigFile();
1148
1149         if (!FindArg( "-notitles" ))
1150                 show_order_form();
1151
1152         #ifndef NDEBUG
1153         if ( FindArg( "-showmeminfo" ) )
1154                 show_mem_info = 1;              // Make memory statistics show
1155         #endif
1156
1157         return(0);              //presumably successful exit
1158 }
1159
1160
1161 void check_joystick_calibration()       {
1162         int x1, y1, x2, y2, c;
1163         fix t1;
1164
1165         if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1166                   (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1167                   (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1168                   (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1169                 ) return;
1170
1171         joy_get_pos( &x1, &y1 );
1172
1173         t1 = timer_get_fixed_seconds();
1174         while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1175                 ;
1176
1177         joy_get_pos( &x2, &y2 );
1178
1179         // If joystick hasn't moved...
1180         if ( (abs(x2-x1)<30) &&  (abs(y2-y1)<30) )      {
1181                 if ( (abs(x1)>30) || (abs(x2)>30) ||  (abs(y1)>30) || (abs(y2)>30) )    {
1182                         c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1183                         if ( c==0 )     {
1184                                 joydefs_calibrate();
1185                         }
1186                 }
1187         }
1188
1189 }
1190
1191 void show_order_form()
1192 {
1193 #ifndef EDITOR
1194
1195         int pcx_error;
1196         unsigned char title_pal[768];
1197         char    exit_screen[16];
1198
1199         gr_set_current_canvas( NULL );
1200         gr_palette_clear();
1201
1202         key_flush();
1203
1204         strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx"); // OEM
1205         if (! cfexist(exit_screen))
1206                 strcpy(exit_screen, MenuHires?"orderd2b.pcx":"orderd2.pcx"); // SHAREWARE, prefer mac if hires
1207         if (! cfexist(exit_screen))
1208                 strcpy(exit_screen, MenuHires?"orderd2.pcx":"orderd2b.pcx"); // SHAREWARE, have to rescale
1209         if (! cfexist(exit_screen))
1210                 strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx"); // D1
1211         if (! cfexist(exit_screen))
1212                 return; // D2 registered
1213
1214         if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1215                 //vfx_set_palette_sub( title_pal );
1216                 gr_palette_fade_in( title_pal, 32, 0 );
1217                 gr_update();
1218                 while (!key_inkey() && !mouse_button_state(0)) {} //key_getch();
1219                 gr_palette_fade_out( title_pal, 32, 0 );
1220         }
1221         else
1222                 Int3();         //can't load order screen
1223
1224         key_flush();
1225
1226 #endif
1227 }
1228
1229 void quit_request()
1230 {
1231 #ifdef NETWORK
1232 //      void network_abort_game();
1233 //      if(Network_status)
1234 //              network_abort_game();
1235 #endif
1236         exit(0);
1237 }