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