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