1 /* $Id: inferno.c,v 1.62 2003/05/12 22:46:01 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  * Old Log:
26  * Revision 1.1  1995/12/05  15:57:49  allender
27  * Initial revision
28  *
29  * Revision 1.19  1995/11/07  17:03:12  allender
30  * added splash screen for descent contest
31  *
32  * Revision 1.18  1995/10/31  10:22:22  allender
33  * shareware stuff
34  *
35  * Revision 1.17  1995/10/18  01:53:07  allender
36  * mouse click to leave do not distribute screen
37  *
38  * Revision 1.16  1995/10/17  12:00:12  allender
39  * mouse click gets past endgame screen
40  *
41  * Revision 1.15  1995/10/12  17:40:12  allender
42  * read config file after digi initialized
43  *
44  * Revision 1.14  1995/10/05  10:38:22  allender
45  * changed key_getch at exit to be key_inkey and moved
46  * mouse init until after macintosh windowing init call
47  *
48  * Revision 1.13  1995/09/18  17:01:04  allender
49  * put gr_init call before render buffer stuff
50  *
51  * Revision 1.12  1995/08/31  15:50:53  allender
52  * call init for appletalk, and change name of intro screens
53  *
54  * Revision 1.11  1995/08/26  16:26:19  allender
55  * whole bunch 'o stuff!!
56  *
57  * Revision 1.10  1995/07/12  21:48:18  allender
58  * removed Int3 from beginning of program
59  *
60  * Revision 1.9  1995/07/05  16:45:48  allender
61  * removed hide_cursor call
62  *
63  * Revision 1.8  1995/06/20  16:44:57  allender
64  * game now renders in 640x480 at all times.  Changed code
65  * to call game_init_render_buffers with right params
66  *
67  * Revision 1.7  1995/06/13  13:07:55  allender
68  * change macintosh initialzation.  Mac windows now init'ed through gr_init.
69  *
70  * Revision 1.6  1995/06/08  16:36:53  allender
71  * "ifdef" profile include
72  *
73  * Revision 1.5  1995/06/07  08:08:18  allender
74  * dont' make memory info show at end of program
75  *
76  * Revision 1.4  1995/06/02  07:47:40  allender
77  * removed network initialzation for now
78  *
79  * Revision 1.3  1995/05/26  06:54:52  allender
80  * put digi_init after timer and key stuff since I was testing stuff
81  * that needed the keyboard handler installed
82  *
83  * Revision 1.2  1995/05/19  11:28:09  allender
84  * removed printf
85  *
86  * Revision 1.1  1995/05/16  15:26:39  allender
87  * Initial revision
88  *
89  * Revision 2.36  1996/01/05  16:52:16  john
90  * Improved 3d stuff.
91  *
92  * Revision 2.35  1995/10/07  13:20:06  john
93  * Added new modes for LCDBIOS, also added support for -JoyNice,
94  * and added Shift+F1-F4 to controls various stereoscopic params.
95  *
96  * Revision 2.34  1995/06/26  11:30:57  john
97  * Made registration/copyright screen go away after 5 minutes.
98  *
99  * Revision 2.33  1995/05/31  14:26:55  unknown
100  * Fixed ugly spacing.
101  *
102  * Revision 2.32  1995/05/26  16:15:28  john
103  * Split SATURN into define's for requiring cd, using cd, etc.
104  * Also started adding all the Rockwell stuff.
105  *
106  * Revision 2.31  1995/05/11  13:30:01  john
107  * Changed 3dbios detection to work like Didde Kim wanted it to.
108  *
109  * Revision 2.30  1995/05/08  13:53:50  john
110  * Added code to read vipport environemnt variable.
111  *
112  * Revision 2.29  1995/05/08  11:26:18  john
113  * Reversed eyes in 3dmax mode.
114  *
115  * Revision 2.28  1995/05/08  11:24:06  john
116  * Made 3dmax work like Kasan wants it to.
117  *
118  * Revision 2.27  1995/04/23  16:06:25  john
119  * Moved rinvul into modem/null modem menu.
120  *
121  * Revision 2.26  1995/04/12  13:39:26  john
122  * Fixed bug with -lowmem not working.
123  *
124  * Revision 2.25  1995/04/09  14:43:00  john
125  * Made Dynamic sockets not print Msockets for help.
126  *
127  * Revision 2.24  1995/04/07  16:11:33  john
128  * Fixed problem with VFX display when using setup.
129  *
130  * Revision 2.23  1995/04/06  15:40:51  john
131  * Synced VFX with setup #'s.
132  *
133  * Revision 2.22  1995/04/06  12:12:53  john
134  * Fixed some bugs with 3dmax.
135  *
136  * Revision 2.21  1995/03/30  16:36:51  mike
137  * text localization.
138  *
139  * Revision 2.20  1995/03/29  15:33:52  john
140  * Added code to parse descent.net file.
141  *
142  * Revision 2.19  1995/03/28  20:08:21  john
143  * Took away alternate server thing.
144  *
145  * Revision 2.18  1995/03/27  09:43:08  john
146  * Added VR Settings in config file.
147  *
148  * Revision 2.17  1995/03/23  19:02:21  john
149  * Added descent.net file use.
150  *
151  * Revision 2.16  1995/03/23  12:25:11  john
152  * Moved IPX stuff into BIOS lib.
153  *
154  * Revision 2.15  1995/03/21  16:52:34  john
155  * Added 320x100.
156  *
157  * Revision 2.14  1995/03/21  14:40:33  john
158  * Ifdef'd out the NETWORK code.
159  *
160  * Revision 2.13  1995/03/16  23:13:35  john
161  * Fixed bug with piggy paging in bitmap not checking for disk
162  * error, hence bogifying textures if you pull the CD out.
163  *
164  * Revision 2.12  1995/03/16  21:45:22  john
165  * Made all paged modes have incompatible menus!
166  *
167  * Revision 2.11  1995/03/15  15:19:34  john
168  * Took out code that changes to exe dir.
169  *
170  * Revision 2.10  1995/03/15  14:33:37  john
171  * Added code to force the Descent CD-rom in the drive.
172  *
173  * Revision 2.9  1995/03/15  11:41:27  john
174  * Better Saturn CD-ROM support.
175  *
176  * Revision 2.8  1995/03/14  18:24:46  john
177  * Force Destination Saturn to use CD-ROM drive.
178  *
179  * Revision 2.7  1995/03/14  16:22:35  john
180  * Added cdrom alternate directory stuff.
181  *
182  * Revision 2.6  1995/03/13  15:17:19  john
183  * Added alternate hogfile directory.
184  *
185  * Revision 2.5  1995/03/10  13:05:35  john
186  * Added code so that palette is correct for VFX1 helmets.
187  *
188  * Revision 2.4  1995/03/07  15:12:43  john
189  * Fixed VFX,3dmax support.
190  *
191  * Revision 2.3  1995/03/07  14:19:35  mike
192  * More destination saturn stuff.
193  *
194  * Revision 2.2  1995/03/06  16:47:34  mike
195  * destination saturn
196  *
197  * Revision 2.1  1995/03/06  15:24:06  john
198  * New screen techniques.
199  *
200  * Revision 2.0  1995/02/27  11:31:29  john
201  * New version 2.0, which has no anonymous unions, builds with
202  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
203  *
204  * Revision 1.295  1995/02/23  12:02:14  john
205  * Made mono  windows smaller.
206  *
207  * Revision 1.294  1995/02/16  17:35:00  john
208  * Added code to allow dynamic socket changing.
209  *
210  * Revision 1.293  1995/02/14  19:29:29  john
211  * Locked down critical error handler.
212  *
213  * Revision 1.292  1995/02/14  15:29:20  john
214  * Added CR-LF to last line of menu help text.
215  *
216  * Revision 1.291  1995/02/14  11:39:01  john
217  * Added polled/bios joystick readers.
218  *
219  * Revision 1.290  1995/02/13  20:35:03  john
220  * Lintized
221  *
222  * Revision 1.289  1995/02/11  16:20:02  john
223  * Added code to make the default mission be the one last played.
224  *
225  * Revision 1.288  1995/02/11  15:54:13  rob
226  * changed cinvul to rinvul.
227  *
228  * Revision 1.287  1995/02/11  14:48:43  rob
229  * Added max of 314 seconds to control invul. times
230  *
231  * Revision 1.286  1995/02/11  12:42:01  john
232  * Added new song method, with FM bank switching..
233  *
234  * Revision 1.285  1995/02/11  11:36:11  rob
235  * Added cinvul option.
236  *
237  * Revision 1.284  1995/02/10  16:07:45  matt
238  * Took 'registered' out of printed info at startup
239  *
240  * Revision 1.283  1995/02/09  22:00:59  john
241  * Added i-glasses tracking.
242  *
243  * Revision 1.282  1995/02/02  11:11:27  john
244  * Added -nocyberman switch.
245  *
246  * Revision 1.281  1995/02/01  16:35:14  john
247  * Linted.
248  *
249  * Revision 1.280  1995/01/31  02:04:25  matt
250  * Fixed up cmdline help
251  *
252  * Revision 1.279  1995/01/30  16:25:55  john
253  * Put back in graphical screen at program end.
254  *
255  * Revision 1.278  1995/01/28  17:05:50  matt
256  * Changed imbedded copyright to use comma instead of hyphen
257  *
258  * Revision 1.277  1995/01/28  15:57:26  john
259  * Made joystick calibration be only when wrong detected in
260  * menu or joystick axis changed.
261  *
262  * Revision 1.276  1995/01/25  14:37:49  john
263  * Made joystick only prompt for calibration once...
264  *
265  * Revision 1.275  1995/01/24  18:21:00  john
266  * Added Adam's text warning.
267  *
268  * Revision 1.274  1995/01/22  15:57:20  john
269  * Took out code that printed warning out as game exited.
270  *
271  * Revision 1.273  1995/01/22  13:31:35  matt
272  * Added load of mission 0, so there's always a default mission
273  *
274  * Revision 1.272  1995/01/19  17:00:41  john
275  * Made save game work between levels.
276  *
277  * Revision 1.271  1995/01/18  11:47:57  adam
278  * changed copyright notice
279  *
280  * Revision 1.270  1995/01/15  13:42:42  john
281  * Moved low_mem cutoff higher.
282  *
283  * Revision 1.269  1995/01/12  18:53:50  john
284  * Put ifdef EDITOR around the code that checked for
285  * a 800x600 mode, because this trashed some people's
286  * computers (maybe) causing the mem allocation error in
287  * mouse.c that many users reported.
288  *
289  * Revision 1.268  1995/01/12  11:41:42  john
290  * Added external control reading.
291  *
292  * Revision 1.267  1995/01/06  10:26:55  john
293  * Added -nodoscheck command line switch.
294  *
295  * Revision 1.266  1995/01/05  16:59:30  yuan
296  * Don't show orderform in editor version.
297  *
298  * Revision 1.265  1994/12/28  15:33:51  john
299  * Added -slowjoy option.
300  *
301  * Revision 1.264  1994/12/15  16:44:15  matt
302  * Added trademark notice
303  *
304  * Revision 1.263  1994/12/14  20:13:59  john
305  * Reduced physical mem requments to 2 MB.
306  *
307  * Revision 1.262  1994/12/14  19:06:17  john
308  * Lowered physical memory requments to 2 MB.
309  *
310  * Revision 1.261  1994/12/14  09:41:29  allender
311  * change to drive and directory (if needed) of command line invocation
312  * so descent can be started from anywhere
313  *
314  * Revision 1.260  1994/12/13  19:08:59  john
315  * Updated memory requirements.
316  *
317  * Revision 1.259  1994/12/13  17:30:33  john
318  * Made the timer rate be changed right after initializing it.
319  *
320  * Revision 1.258  1994/12/13  02:46:25  matt
321  * Added imbedded copyright
322  *
323  * Revision 1.257  1994/12/13  02:06:46  john
324  * Added code to check stack used by descent... initial
325  * check showed stack used 35k/50k, so we decided it wasn't
326  * worth pursuing any more.
327  *
328  * Revision 1.256  1994/12/11  23:17:54  john
329  * Added -nomusic.
330  * Added RealFrameTime.
331  * Put in a pause when sound initialization error.
332  * Made controlcen countdown and framerate use RealFrameTime.
333  *
334  * Revision 1.255  1994/12/10  00:56:51  matt
335  * Added -nomusic to command-line help
336  *
337  * Revision 1.254  1994/12/08  11:55:11  john
338  * Took out low memory print.
339  *
340  * Revision 1.253  1994/12/08  11:51:00  john
341  * Made strcpy only copy corect number of chars,.
342  *
343  * Revision 1.252  1994/12/08  00:38:29  matt
344  * Cleaned up banner messages
345  *
346  * Revision 1.251  1994/12/07  19:14:52  matt
347  * Cleaned up command-line options and command-line help message
348  *
349  * Revision 1.250  1994/12/06  19:33:28  john
350  * Fixed text of message to make more sense.
351  *
352  * Revision 1.249  1994/12/06  16:30:55  john
353  * Neatend mem message,..
354  *
355  * Revision 1.248  1994/12/06  16:17:35  john
356  * Added better mem checking/printing.
357  *
358  * Revision 1.247  1994/12/06  14:14:37  john
359  * Added code to set low mem based on memory.
360  *
361  * Revision 1.246  1994/12/05  12:29:09  allender
362  * removed ifdefs around -norun option
363  *
364  * Revision 1.245  1994/12/05  00:03:30  matt
365  * Added -norun option to exit after writing pig
366  *
367  * Revision 1.244  1994/12/04  14:47:01  john
368  * MAde the intro and menu be the same song.
369  *
370  * Revision 1.243  1994/12/04  14:36:42  john
371  * Added menu music.
372  *
373  * Revision 1.242  1994/12/02  13:50:17  yuan
374  * Localization.
375  *
376  * Revision 1.241  1994/12/01  17:28:30  adam
377  * added end-shareware stuff
378  *
379  * Revision 1.240  1994/11/30  12:10:57  adam
380  * added support for PCX titles/brief screens
381  *
382  * Revision 1.239  1994/11/29  15:47:33  matt
383  * Moved error_init to start of game, so error message prints last
384  *
385  * Revision 1.238  1994/11/29  14:19:22  jasen
386  * reduced dos mem requirments.
387  *
388  * Revision 1.237  1994/11/29  03:46:35  john
389  * Added joystick sensitivity; Added sound channels to detail menu.  Removed -maxchannels
390  * command line arg.
391  *
392  * Revision 1.236  1994/11/29  02:50:18  john
393  * Increased the amount a joystick has to be off before
394  * asking if they want to recalibrate their joystick.
395  *
396  * Revision 1.235  1994/11/29  02:01:29  john
397  * Corrected some of the Descent command line help items.
398  *
399  * Revision 1.234  1994/11/29  01:39:56  john
400  * Fixed minor bug with vfx_light help not wrapping correctly.
401  *
402  * Revision 1.233  1994/11/28  21:34:17  john
403  * Reduced dos mem rqment to 70k.
404  *
405  * Revision 1.232  1994/11/28  21:20:38  john
406  * First version with memory checking.
407  *
408  * Revision 1.231  1994/11/28  20:06:21  rob
409  * Removed old serial param command line options.
410  * Added -noserial and -nonetwork to help listing.
411  *
412  * Revision 1.230  1994/11/27  23:15:24  matt
413  * Made changes for new mprintf calling convention
414  *
415  * Revision 1.229  1994/11/27  20:50:51  matt
416  * Don't set mem stuff if no debug
417  *
418  * Revision 1.228  1994/11/27  18:46:21  matt
419  * Cleaned up command-line switches a little
420  *
421  * Revision 1.227  1994/11/21  17:48:00  matt
422  * Added text to specifiy whether shareware or registered version
423  *
424  * Revision 1.226  1994/11/21  14:44:20  john
425  * Fixed some bugs with setting volumes even when -nosound was used. Duh!
426  *
427  * Revision 1.225  1994/11/21  13:53:42  matt
428  * Took out dos extender copyright
429  *
430  * Revision 1.224  1994/11/21  09:46:54  john
431  * Added -showmeminfo parameter.
432  *
433  * Revision 1.223  1994/11/20  22:12:05  mike
434  * Make some stuff dependent on SHAREWARE.
435  *
436  * Revision 1.222  1994/11/20  21:14:09  john
437  * Changed -serial to -noserial.  MAde a 1 sec delay
438  * before leaving title screen.  Clear keyboard buffer
439  * before asking for player name.
440  *
441  * Revision 1.221  1994/11/19  15:20:20  mike
442  * rip out unused code and data
443  *
444  * Revision 1.220  1994/11/17  19:14:29  adam
445  * prevented order screen from coming up when -notitles is used
446  *
447  * Revision 1.219  1994/11/16  11:34:39  john
448  * Added -nottitle switch.
449  *
450  * Revision 1.218  1994/11/16  10:05:53  john
451  * Added verbose messages.
452  *
453  * Revision 1.217  1994/11/15  20:12:34  john
454  * Added back in inferno and parallax screens.
455  *
456  * Revision 1.216  1994/11/15  18:35:30  john
457  * Added verbose setting.
458  *
459  * Revision 1.215  1994/11/15  17:47:44  john
460  * Added ordering info screen.
461  *
462  * Revision 1.214  1994/11/15  08:57:44  john
463  * Added MS-DOS version checking and -nonetwork option.
464  *
465  * Revision 1.213  1994/11/15  08:34:32  john
466  * Added better error messages for IPX init.
467  *
468  * Revision 1.212  1994/11/14  20:14:18  john
469  * Fixed some warnings.
470  *
471  * Revision 1.211  1994/11/14  19:50:49  john
472  * Added joystick cal values to descent.cfg.
473  *
474  * Revision 1.210  1994/11/14  17:56:44  allender
475  * make call to ReadConfigFile at startup
476  *
477  * Revision 1.209  1994/11/14  11:41:55  john
478  * Fixed bug with editor/game sequencing.
479  *
480  * Revision 1.208  1994/11/13  17:05:11  john
481  * Made the callsign entry be a list box and gave the ability
482  * to delete players.
483  *
484  * Revision 1.207  1994/11/13  15:39:22  john
485  * Added critical error handler to game.  Took out -editor command line
486  * option because it didn't work anymore and wasn't worth fixing.  Made scores
487  * not use MINER enviroment variable on release version, and made scores
488  * not print an error if there is no descent.hi.
489  *
490  * Revision 1.206  1994/11/10  20:53:29  john
491  * Used new sound install parameters.
492  *
493  * Revision 1.205  1994/11/10  11:07:52  mike
494  * Set default detail level.
495  *
496  * Revision 1.204  1994/11/09  13:45:43  matt
497  * Made -? work again for help
498  *
499  * Revision 1.203  1994/11/09  10:55:58  matt
500  * Cleaned up initialization for editor -> game transitions
501  *
502  * Revision 1.202  1994/11/07  21:35:47  matt
503  * Use new function iff_read_into_bitmap()
504  *
505  * Revision 1.201  1994/11/05  17:22:16  john
506  * Fixed lots of sequencing problems with newdemo stuff.
507  *
508  * Revision 1.200  1994/11/05  14:05:44  john
509  * Fixed fade transitions between all screens by making
510  * gr_palette_fade_in and out keep track of whether the palette is
511  * faded in or not.  Then, wherever the code needs to fade out, it
512  * just calls gr_palette_fade_out and it will fade out if it isn't
513  * already.  The same with fade_in.
514  * This eliminates the need for all the flags like Menu_fade_out,
515  * game_fade_in palette, etc.
516  *
517  * Revision 1.199  1994/11/04  14:36:30  allender
518  * change Auto_demo meaning to mean autostart from menu only.  Use
519  * FindArgs when searching for AutoDemo from command line.  also,
520  * set N_Players to 1 when starting in editor mode.
521  *
522  * Revision 1.198  1994/11/02  11:59:49  john
523  * Moved menu out of game into inferno main loop.
524  *
525  * Revision 1.197  1994/11/01  17:57:39  mike
526  * -noscreens option to bypass all screens.
527  *
528  * Revision 1.196  1994/10/28  15:42:34  allender
529  * don't register player if Autodemo is on
530  *
531  * Revision 1.195  1994/10/28  10:58:01  matt
532  * Added copyright notice for DOS4GW
533  *
534  * Revision 1.194  1994/10/20  21:26:48  matt
535  * Took out old serial name/number code, and put up message if this
536  * is a marked version.
537  *
538  * Revision 1.193  1994/10/19  09:52:14  allender
539  * Print out who descent.exe belongs to if descent.exe is stamped.
540  *
541  * Revision 1.192  1994/10/18  16:43:05  allender
542  * Added check for identifier stamp and time after which descent will
543  * no longer run.
544  *
545  * Revision 1.191  1994/10/17  13:07:17  john
546  * Moved the descent.cfg info into the player config file.
547  *
548  * Revision 1.190  1994/10/04  10:26:31  matt
549  * Support new menu fade in
550  *
551  * Revision 1.189  1994/10/03  22:58:46  matt
552  * Changed some values of game_mode
553  *
554  * Revision 1.188  1994/10/03  18:55:39  rob
555  * Changed defaults for com port settings.
556  *
557  * Revision 1.187  1994/10/03  13:34:47  matt
558  * Added new (and hopefully better) game sequencing functions
559  *
560  * Revision 1.186  1994/09/30  12:37:28  john
561  * Added midi,digi volume to configuration.
562  *
563  * Revision 1.185  1994/09/30  10:08:48  john
564  * Changed sound stuff... made it so the reseting card doesn't hang,
565  * made volume change only if sound is installed.
566  *
567  * Revision 1.184  1994/09/28  17:25:00  matt
568  * Added first draft of game save/load system
569  *
570  * Revision 1.183  1994/09/28  16:18:23  john
571  * Added capability to play midi song.
572  *
573  * Revision 1.182  1994/09/28  11:31:18  john
574  * Made text output unbuffered.
575  *
576  * Revision 1.181  1994/09/27  19:23:44  john
577  * Added -nojoystick and -nomouse
578  *
579  * Revision 1.180  1994/09/24  16:55:29  rob
580  * No longer open COM port immediately upon program start.
581  * No longer set Network_active is serial_active is set.
582  *
583  * Revision 1.179  1994/09/24  14:16:30  mike
584  * Support new game mode constants.
585  *
586  * Revision 1.178  1994/09/22  17:52:31  rob
587  * Added Findargs hooks for -serial, -speed, and -com.
588  *
589  * Revision 1.177  1994/09/22  16:14:11  john
590  * Redid intro sequecing.
591  *
592  * Revision 1.176  1994/09/21  16:32:58  john
593  * Made mouse and keyboard init after bm_init. Why?
594  * Because it seems to work better under virtual
595  * memory.
596  *
597  * Revision 1.175  1994/09/21  16:27:52  john
598  * Added mouse_init
599  *
600  * Revision 1.174  1994/09/20  15:14:10  matt
601  * New message for new VFX switches
602  *
603  * Revision 1.173  1994/09/16  16:14:27  john
604  * Added acrade sequencing.
605  *
606  * Revision 1.172  1994/09/16  11:49:52  john
607  * Added first version of arcade joystick support;
608  * Also fixed some bugs in kconfig.c, such as reading non-present
609  * joysticks, which killed frame rate, and not reading key_down_time
610  * when in slide mode or bank mode.
611  *
612  * Revision 1.171  1994/09/15  16:11:35  john
613  * Added support for VFX1 head tracking. Fixed bug with memory over-
614  * write when using stereo mode.
615  *
616  * Revision 1.170  1994/09/12  19:38:23  john
617  * Made some stuff that prints to the DOS screen go to the
618  * mono instead, since it really is debugging info.
619  *
620  * Revision 1.169  1994/08/29  21:18:28  john
621  * First version of new keyboard/oystick remapping stuff.
622  *
623  * Revision 1.168  1994/08/26  13:02:00  john
624  * Put high score system in.
625  *
626  * Revision 1.167  1994/08/24  19:00:23  john
627  * Changed key_down_time to return fixed seconds instead of
628  * milliseconds.
629  *
630  * Revision 1.166  1994/08/18  16:24:20  john
631  * changed socket to channel in text.
632  *
633  * Revision 1.165  1994/08/18  16:16:51  john
634  * Added support for different sockets.
635  *
636  * Revision 1.164  1994/08/18  10:47:53  john
637  * *** empty log message ***
638  *
639  * Revision 1.163  1994/08/12  09:15:54  john
640  * *** empty log message ***
641  *
642  * Revision 1.162  1994/08/12  03:11:19  john
643  * Made network be default off; Moved network options into
644  * main menu.  Made starting net game check that mines are the
645  * same.
646  *
647  * Revision 1.161  1994/08/10  19:57:05  john
648  * Changed font stuff; Took out old menu; messed up lots of
649  * other stuff like game sequencing messages, etc.
650  *
651  * Revision 1.160  1994/08/05  16:30:23  john
652  * Added capability to turn off network.
653  *
654  * Revision 1.159  1994/08/04  19:42:51  matt
655  * Moved serial number & name (and version name) from inferno.c to inferno.ini
656  *
657  * Revision 1.158  1994/08/03  10:30:23  matt
658  * Change cybermaxx switches, updated command-line help, and added serial number system
659  *
660  * Revision 1.157  1994/07/29  18:30:10  matt
661  * New parms (lack of parms, actually) for g3_init()
662  *
663  * Revision 1.156  1994/07/24  00:39:25  matt
664  * Added more text to TEX file; make NewGame() take a start level; made game
665  * load/save menus use open/close window funcs.
666  *
667  * Revision 1.155  1994/07/21  21:31:27  john
668  * First cheapo version of VictorMaxx tracking.
669  *
670  * Revision 1.154  1994/07/21  18:15:34  matt
671  * Ripped out a bunch of unused stuff
672  *
673  * Revision 1.153  1994/07/21  17:59:10  matt
674  * Cleaned up initial mode game/editor code
675  *
676  * Revision 1.152  1994/07/21  13:11:19  matt
677  * Ripped out remants of old demo system, and added demo only system that
678  * disables object movement and game options from menu.
679  *
680  * Revision 1.151  1994/07/20  15:58:27  john
681  * First installment of ipx stuff.
682  *
683  * Revision 1.150  1994/07/15  16:04:24  matt
684  * Changed comment for milestone 3 version
685  *
686  * Revision 1.149  1994/07/15  13:59:24  matt
687  * Fixed stupid mistake I make in the last revision
688  *
689  * Revision 1.148  1994/07/15  13:20:15  matt
690  * Updated comand-line help
691  *
692  * Revision 1.147  1994/07/14  23:29:43  matt
693  * Open two mono debug messages, one for errors & one for spew
694  *
695  * Revision 1.146  1994/07/09  22:48:05  matt
696  * Added localizable text
697  *
698  * Revision 1.145  1994/07/02  13:49:47  matt
699  * Cleaned up includes
700  *
701  * Revision 1.144  1994/06/30  20:04:43  john
702  * Added -joydef support.
703  *
704  * Revision 1.143  1994/06/24  17:01:44  john
705  * Add VFX support; Took Game Sequencing, like EndGame and stuff and
706  * took it out of game.c and into gameseq.c
707  *
708  */
709 
710 #ifdef HAVE_CONFIG_H
711 #include <conf.h>
712 #endif
713 
714 char copyright[] = "DESCENT II  COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
715 
716 #include <stdio.h>
717 #include <stdlib.h>
718 #include <string.h>
719 #include <limits.h>
720 
721 #ifdef __unix__
722 #include <unistd.h>
723 #include <sys/stat.h>
724 #include <sys/types.h>
725 #endif
726 
727 #include "pstypes.h"
728 #include "strutil.h"
729 #include "console.h"
730 #include "pa_enabl.h"       //$$POLY_ACC
731 #include "gr.h"
732 #include "fix.h"
733 #include "vecmat.h"
734 #include "mono.h"
735 #include "key.h"
736 #include "timer.h"
737 #include "3d.h"
738 #include "bm.h"
739 #include "inferno.h"
740 #include "error.h"
741 #include "game.h"
742 #include "segment.h"		//for Side_to_verts
743 #include "u_mem.h"
744 #include "segpoint.h"
745 #include "screens.h"
746 #include "texmap.h"
747 #include "texmerge.h"
748 #include "menu.h"
749 #include "wall.h"
750 #include "polyobj.h"
751 #include "effects.h"
752 #include "digi.h"
753 #include "iff.h"
754 #include "pcx.h"
755 #include "palette.h"
756 #include "args.h"
757 #include "sounds.h"
758 #include "titles.h"
759 #include "player.h"
760 #include "text.h"
761 #include "ipx.h"
762 #include "newdemo.h"
763 #ifdef NETWORK
764 #include "network.h"
765 #endif
766 #include "modem.h"
767 #include "gamefont.h"
768 #include "kconfig.h"
769 #include "mouse.h"
770 #include "joy.h"
771 #include "newmenu.h"
772 #include "desc_id.h"
773 #include "config.h"
774 #include "joydefs.h"
775 #include "multi.h"
776 #include "songs.h"
777 #include "cfile.h"
778 #include "gameseq.h"
779 #include "gamepal.h"
780 #include "mission.h"
781 #include "movie.h"
782 #include "compbit.h"
783 #include "d_io.h"
784 
785 // #  include "3dfx_des.h"
786 
787 //added on 9/30/98 by Matt Mueller for selectable automap modes
788 #include "automap.h"
789 //end addition -MM
790 
791 #include "../texmap/scanline.h" //for select_tmap -MM
792 
793 #if defined(POLY_ACC)
794 #include "poly_acc.h"
795 extern int Current_display_mode;        //$$ there's got to be a better way than hacking this.
796 #endif
797 
798 #ifdef EDITOR
799 #include "editor/editor.h"
800 #include "editor/kdefs.h"
801 #include "ui.h"
802 #endif
803 
804 #ifndef __MSDOS__
805 #include <SDL.h>
806 #endif
807 
808 #include "vers_id.h"
809 
810 void mem_init(void);
811 void arch_init(void);
812 void arch_init_start(void);
813 
814 //Current version number
815 
816 ubyte Version_major = 1;		//FULL VERSION
817 ubyte Version_minor = 2;
818 
819 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000";	//4-byte checksum
820 char desc_id_exit_num = 0;
821 
822 int Function_mode=FMODE_MENU;		//game or editor?
823 int Screen_mode=-1;					//game screen or editor screen?
824 
825 //--unused-- grs_bitmap Inferno_bitmap_title;
826 
827 int WVIDEO_running=0;		//debugger can set to 1 if running
828 
829 #ifdef EDITOR
830 int Inferno_is_800x600_available = 0;
831 #endif
832 
833 //--unused-- int Cyberman_installed=0;			// SWIFT device present
834 ubyte CybermouseActive=0;
835 
836 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
837 
838 void check_joystick_calibration(void);
839 
840 
841 //--------------------------------------------------------------------------
842 
843 extern int piggy_low_memory;
844 
845 
846 int descent_critical_error = 0;
847 unsigned descent_critical_deverror = 0;
848 unsigned descent_critical_errcode = 0;
849 
850 extern int Network_allow_socket_changes;
851 
852 extern void vfx_set_palette_sub(ubyte *);
853 
854 extern int VR_low_res;
855 
856 extern int Config_vr_type;
857 extern int Config_vr_resolution;
858 extern int Config_vr_tracking;
859 
860 #define LINE_LEN	100
861 
862 //read help from a file & print to screen
print_commandline_help()863 void print_commandline_help()
864 {
865 	CFILE *ifile;
866 	int have_binary=0;
867 	char line[LINE_LEN];
868 
869 	ifile = cfopen("help.tex","rb");
870 	if (!ifile) {
871 		ifile = cfopen("help.txb","rb");
872 		if (!ifile)
873 			Warning("Cannot load help text file.");
874 		have_binary = 1;
875 	}
876 
877 	if (ifile)
878 	{
879 
880 		while (cfgets(line,LINE_LEN,ifile)) {
881 
882 			if (have_binary) {
883 				int i;
884 				for (i = 0; i < strlen(line) - 1; i++) {
885 					encode_rotate_left(&(line[i]));
886 					line[i] = line[i] ^ BITMAP_TBL_XOR;
887 					encode_rotate_left(&(line[i]));
888 				}
889 			}
890 
891 			if (line[0] == ';')
892 				continue;		//don't show comments
893 
894 			printf("%s",line);
895 
896 		}
897 
898 		cfclose(ifile);
899 
900 	}
901 
902 //	printf( " Diagnostic:\n\n");
903 //	printf( "  -emul           %s\n", "Certain video cards need this option in order to run game");
904 //	printf(	"  -ddemul         %s\n", "If -emul doesn't work, use this option");
905 //	printf( "\n");
906 #ifdef EDITOR
907 	printf( " Editor Options:\n\n");
908 	printf( "  -autoload <file>%s\n", "Autoload a level in the editor");
909 	printf( "  -hoarddata      %s\n","FIXME: Undocumented");
910 //	printf( "  -nobm           %s\n","FIXME: Undocumented");
911 	printf( "\n");
912 #endif
913 	printf( " D2X Options:\n\n");
914 	printf( "  -noredundancy   %s\n", "Do not send messages when picking up redundant items in multi");
915 	printf( "  -shortpackets   %s\n", "Set shortpackets to default as on");
916 	printf( "  -maxfps <n>     %s\n", "Set maximum framerate (1-100)");
917 	printf( "  -notitles       %s\n", "Do not show titlescreens on startup");
918 	printf( "  -hogdir <dir>   %s\n", "set shared data directory to <dir>");
919 #ifdef __unix__
920 	printf( "  -nohogdir       %s\n", "don't try to use shared data directory");
921 	printf( "  -userdir <dir>  %s\n", "set user dir to <dir> instead of $HOME/.d2x");
922 #endif
923 	printf( "  -ini <file>     %s\n", "option file (alternate to command line), defaults to d2x.ini");
924 	printf( "  -autodemo       %s\n", "Start in demo mode");
925 	printf( "  -bigpig         %s\n","FIXME: Undocumented");
926 	printf( "  -bspgen         %s\n","FIXME: Undocumented");
927 //	printf( "  -cdproxy        %s\n","FIXME: Undocumented");
928 #ifndef NDEBUG
929 	printf( "  -checktime      %s\n","FIXME: Undocumented");
930 	printf( "  -showmeminfo    %s\n","FIXME: Undocumented");
931 #endif
932 //	printf( "  -codereadonly   %s\n","FIXME: Undocumented");
933 //	printf( "  -cyberimpact    %s\n","FIXME: Undocumented");
934 	printf( "  -debug          %s\n","Enable very verbose output");
935 //	printf( "  -debugmode      %s\n","FIXME: Undocumented");
936 //	printf( "  -disallowgfx    %s\n","FIXME: Undocumented");
937 //	printf( "  -disallowreboot %s\n","FIXME: Undocumented");
938 //	printf( "  -dynamicsockets %s\n","FIXME: Undocumented");
939 //	printf( "  -forcegfx       %s\n","FIXME: Undocumented");
940 #ifdef SDL_INPUT
941 	printf( "  -grabmouse      %s\n","Keeps the mouse from wandering out of the window");
942 #endif
943 //	printf( "  -hw_3dacc       %s\n","FIXME: Undocumented");
944 #ifndef RELEASE
945 	printf( "  -invulnerability %s\n","Make yourself invulnerable");
946 #endif
947 	printf( "  -ipxnetwork <num> %s\n","Use IPX network number <num>");
948 	printf( "  -jasen          %s\n","FIXME: Undocumented");
949 	printf( "  -joyslow        %s\n","FIXME: Undocumented");
950 #ifdef NETWORK
951 	printf( "  -kali           %s\n","use Kali for networking");
952 #endif
953 //	printf( "  -logfile        %s\n","FIXME: Undocumented");
954 	printf( "  -lowresmovies   %s\n","Play low resolution movies if available (for slow machines)");
955 #if defined(EDITOR) || !defined(MACDATA)
956 	printf( "  -macdata        %s\n","Read (and, for editor, write) mac data files (swap colors)");
957 #endif
958 //	printf( "  -memdbg         %s\n","FIXME: Undocumented");
959 //	printf( "  -monodebug      %s\n","FIXME: Undocumented");
960 	printf( "  -nocdrom        %s\n","FIXME: Undocumented");
961 #ifdef __DJGPP__
962 	printf( "  -nocyberman     %s\n","FIXME: Undocumented");
963 #endif
964 #ifndef NDEBUG
965 	printf( "  -nofade         %s\n","Disable fades");
966 #endif
967 #ifdef NETWORK
968 	printf( "  -nomatrixcheat  %s\n","FIXME: Undocumented");
969 	printf( "  -norankings     %s\n","Disable multiplayer ranking system");
970 	printf( "  -packets <num>  %s\n","Specifies the number of packets per second\n");
971 //	printf( "  -showaddress    %s\n","FIXME: Undocumented");
972 	printf( "  -socket         %s\n","FIXME: Undocumented");
973 #endif
974 #if !defined(MACINTOSH) && !defined(WINDOWS)
975 	printf( "  -nomixer        %s\n","Don't crank music volume");
976 //	printf( "  -superhires     %s\n","Allow higher-resolution modes");
977 #endif
978 //	printf( "  -nomodex        %s\n","FIXME: Undocumented");
979 #ifndef RELEASE
980 	printf( "  -nomovies       %s\n","Don't play movies");
981 	printf( "  -noscreens      %s\n","Skip briefing screens");
982 #endif
983 #if !defined(SHAREWARE) || ( defined(SHAREWARE) && defined(APPLE_DEMO) )
984 	printf( "  -noredbook      %s\n","Disable redbook audio");
985 #endif
986 	printf( "  -norun          %s\n","Bail out after initialization");
987 //	printf( "  -ordinaljoy     %s\n","FIXME: Undocumented");
988 //	printf( "  -rtscts         %s\n","Same as -ctsrts");
989 //	printf( "  -semiwin        %s\n","Use non-fullscreen mode");
990 //	printf( "  -specialdevice  %s\n","FIXME: Undocumented");
991 #ifdef TACTILE
992 	printf( "  -stickmag       %s\n","FIXME: Undocumented");
993 #endif
994 //	printf( "  -stopwatch      %s\n","FIXME: Undocumented");
995 	printf( "  -subtitles      %s\n","Turn on movie subtitles (English-only)");
996 //	printf( "  -sysram         %s\n","FIXME: Undocumented");
997 	printf( "  -text <file>    %s\n","Specify alternate .tex file");
998 //	printf( "  -tsengdebug1    %s\n","FIXME: Undocumented");
999 //	printf( "  -tsengdebug2    %s\n","FIXME: Undocumented");
1000 //	printf( "  -tsengdebug3    %s\n","FIXME: Undocumented");
1001 #ifdef NETWORK
1002 	printf( "  -udp            %s\n","Use TCP/UDP for networking");
1003 #endif
1004 //	printf( "  -vidram         %s\n","FIXME: Undocumented");
1005 	printf( "  -xcontrol       %s\n","FIXME: Undocumented");
1006 	printf( "  -xname          %s\n","FIXME: Undocumented");
1007 	printf( "  -xver           %s\n","FIXME: Undocumented");
1008 	printf( "  -tmap <t>       %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
1009 	printf( "  -automap<X>x<Y> %s\n","Set automap resolution to <X> by <Y>");
1010 	printf( "  -automap_gameres %s\n","Set automap to use the same resolution as in game");
1011 //	printf( "  -menu<X>x<Y>    %s\n","Set menu resolution to <X> by <Y>");
1012 //	printf( "  -menu_gameres   %s\n","Set menus to use the same resolution as in game");
1013 	printf( "\n");
1014 
1015 	printf( "D2X System Options:\n\n");
1016 #ifdef __MSDOS__
1017 	printf( "  -joy209         %s\n", "Use alternate port 209 for joystick");
1018 #endif
1019 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1020 	printf( "  -fullscreen     %s\n", "Use fullscreen mode if available");
1021 #endif
1022 #ifdef OGL
1023 	printf( "  -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
1024 	printf( "  -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
1025 	printf( "  -gl_mipmap      %s\n","set gl texture filters to \"standard\" options for mipmapping");
1026 	printf( "  -gl_simple      %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
1027 	printf( "  -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
1028 	printf( "  -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
1029 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
1030 	printf( "  -gl_voodoo      %s\n","force fullscreen mode only");
1031 #endif
1032 	printf( "  -gl_16bittextures %s\n","attempt to use 16bit textures");
1033 	printf( "  -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
1034 	printf( "  -gl_intensity4_ok %s\n","FIXME: Undocumented");
1035 	printf( "  -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
1036 	printf( "  -gl_readpixels_ok %s\n","FIXME: Undocumented");
1037 	printf( "  -gl_rgba2_ok    %s\n","FIXME: Undocumented");
1038 //	printf( "  -gl_test1       %s\n","FIXME: Undocumented");
1039 	printf( "  -gl_test2       %s\n","FIXME: Undocumented");
1040 	printf( "  -gl_vidmem      %s\n","FIXME: Undocumented");
1041 #ifdef OGL_RUNTIME_LOAD
1042 	printf( "  -gl_library <l> %s\n","use alternate opengl library");
1043 #endif
1044 #endif
1045 #ifdef SDL_VIDEO
1046 	printf( "  -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
1047 	printf( "  -hwsurface      %s\n","FIXME: Undocumented");
1048 #endif
1049 #ifdef __unix__
1050 	printf( "  -serialdevice <s> %s\n", "Set serial/modem device to <s>");
1051 	printf( "  -serialread <r> %s\n", "Set serial/modem to read from <r>");
1052 #endif
1053 	printf( "\n Help:\n\n");
1054 	printf( "  -help, -h, -?, ? %s\n", "View this help screen");
1055 	printf( "\n");
1056 }
1057 
do_joystick_init()1058 void do_joystick_init()
1059 {
1060 
1061 	if (!FindArg( "-nojoystick" ))	{
1062 		con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
1063 		joy_init();
1064 		if ( FindArg( "-joyslow" ))	{
1065 			con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
1066 			joy_set_slow_reading(JOY_SLOW_READINGS);
1067 		}
1068 		if ( FindArg( "-joypolled" ))	{
1069 			con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
1070 			joy_set_slow_reading(JOY_POLLED_READINGS);
1071 		}
1072 		if ( FindArg( "-joybios" ))	{
1073 			con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
1074 			joy_set_slow_reading(JOY_BIOS_READINGS);
1075 		}
1076 
1077 	//	Added from Descent v1.5 by John.  Adapted by Samir.
1078 	} else {
1079 		con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
1080 	}
1081 }
1082 
1083 //set this to force game to run in low res
1084 int disable_high_res=0;
1085 
do_register_player(ubyte * title_pal)1086 void do_register_player(ubyte *title_pal)
1087 {
1088 	Players[Player_num].callsign[0] = '\0';
1089 
1090 	if (!Auto_demo) 	{
1091 
1092 		key_flush();
1093 
1094 		//now, before we bring up the register player menu, we need to
1095 		//do some stuff to make sure the palette is ok.  First, we need to
1096 		//get our current palette into the 2d's array, so the remapping will
1097 		//work.  Second, we need to remap the fonts.  Third, we need to fill
1098 		//in part of the fade tables so the darkening of the menu edges works
1099 
1100 		memcpy(gr_palette,title_pal,sizeof(gr_palette));
1101 		remap_fonts_and_menus(1);
1102 		RegisterPlayer();		//get player's name
1103 	}
1104 
1105 }
1106 
1107 #ifdef NETWORK
do_network_init()1108 void do_network_init()
1109 {
1110 	if (!FindArg( "-nonetwork" ))	{
1111 		int socket = 0, showaddress = 0, t;
1112 		int ipx_error;
1113 
1114 		con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
1115 		if ((t=FindArg("-socket")))
1116 			socket = atoi( Args[t+1] );
1117 		//@@if ( FindArg("-showaddress") ) showaddress=1;
1118 		if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket, showaddress))==0)	{
1119   			con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
1120 			Network_active = 1;
1121 		} else {
1122 			switch( ipx_error )	{
1123 			case 3: 	con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
1124 			case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
1125 			case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
1126 			default:
1127 				con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
1128 			}
1129 			con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
1130 			Network_active = 0;		// Assume no network
1131 		}
1132 		ipx_read_user_file( "descent.usr" );
1133 		ipx_read_network_file( "descent.net" );
1134 		//@@if ( FindArg( "-dynamicsockets" ))
1135 		//@@	Network_allow_socket_changes = 1;
1136 		//@@else
1137 		//@@	Network_allow_socket_changes = 0;
1138 	} else {
1139 		con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
1140 		Network_active = 0;		// Assume no network
1141 	}
1142 }
1143 #endif
1144 
1145 #define PROGNAME argv[0]
1146 
1147 extern char Language[];
1148 
1149 //can we do highres menus?
1150 extern int MenuHiresAvailable;
1151 
1152 int intro_played = 0;
1153 
1154 int Inferno_verbose = 0;
1155 
1156 //added on 11/18/98 by Victor Rachels to add -mission and -startgame
1157 int start_net_immediately = 0;
1158 //int start_with_mission = 0;
1159 //char *start_with_mission_name;
1160 //end this section addition
1161 
1162 int open_movie_file(char *filename,int must_have);
1163 
1164 #if defined(POLY_ACC)
1165 #define MENU_HIRES_MODE SM_640x480x15xPA
1166 #else
1167 #define MENU_HIRES_MODE SM(640,480)
1168 #endif
1169 
1170 //	DESCENT II by Parallax Software
1171 //		Descent Main
1172 
1173 //extern ubyte gr_current_pal[];
1174 
1175 #ifdef	EDITOR
1176 int	Auto_exit = 0;
1177 char	Auto_file[128] = "";
1178 #endif
1179 
main(int argc,char * argv[])1180 int main(int argc, char *argv[])
1181 {
1182 	int i, t;
1183 	ubyte title_pal[768];
1184 	int screen_width = 640;
1185 	int screen_height = 480;
1186 	u_int32_t screen_mode = SM(screen_width,screen_height);
1187 
1188 	con_init();  // Initialise the console
1189 	mem_init();
1190 
1191 	error_init(NULL, NULL);
1192 
1193 	InitArgs( argc,argv );
1194 
1195 #ifdef __unix__
1196 	{
1197 		char *home = getenv("HOME");
1198 
1199 		if ((t = FindArg("-userdir")))
1200 			chdir(Args[t+1]);
1201 
1202 		else if (home) {
1203 			char buf[PATH_MAX + 5];
1204 
1205 			strcpy(buf, home);
1206 			strcat(buf, "/.d2x");
1207 			if (chdir(buf)) {
1208 				d_mkdir(buf);
1209 				if (chdir(buf))
1210 					fprintf(stderr, "Cannot change to $HOME/.d2x\n");
1211 			}
1212 		}
1213 	}
1214 #endif
1215 
1216 	if (FindArg("-debug"))
1217 		con_threshold.value = (float)2;
1218 	else if (FindArg("-verbose"))
1219 		con_threshold.value = (float)1;
1220 
1221 	//tell cfile where hogdir is
1222 	if ((t=FindArg("-hogdir")))
1223 		cfile_use_alternate_hogdir(Args[t+1]);
1224 #ifdef __unix__
1225 	else if (!FindArg("-nohogdir"))
1226 		cfile_use_alternate_hogdir(SHAREPATH);
1227 #endif
1228 
1229 	//tell cfile about our counter
1230 	cfile_set_critical_error_counter_ptr(&descent_critical_error);
1231 
1232 	if (! cfile_init("descent2.hog"))
1233 		if (! cfile_init("d2demo.hog"))
1234 			Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
1235 #ifdef __unix__
1236 			      "\t$HOME/.d2x\n"
1237 			      "\t" SHAREPATH "\n"
1238 #else
1239 				  "\tCurrent directory\n"
1240 #endif
1241 				  "Or use the -hogdir option to specify an alternate location.");
1242 	load_text();
1243 
1244 	//print out the banner title
1245 	con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
1246 	#ifdef VERSION_NAME
1247 	con_printf(CON_NORMAL, "  %s", VERSION_NAME);
1248 	#endif
1249 	if (cfexist(MISSION_DIR "d2x.hog"))
1250 		con_printf(CON_NORMAL, "  Vertigo Enhanced");
1251 
1252 	con_printf(CON_NORMAL, "  %s %s\n", __DATE__,__TIME__);
1253 	con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
1254 	con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
1255 	con_printf(CON_NORMAL, "                                         Copyright (c) 2002 Bradley Bell\n");
1256 
1257 
1258 	if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) || FindArg( "-h" ) ) {
1259 		print_commandline_help();
1260 		set_exit_message("");
1261 #ifdef __MINGW32__
1262 		exit(0);  /* mingw hangs on this return.  dunno why */
1263 #endif
1264 		return(0);
1265 	}
1266 
1267 	con_printf(CON_NORMAL, "\n");
1268 	con_printf(CON_NORMAL, TXT_HELP, PROGNAME);		//help message has %s for program name
1269 	con_printf(CON_NORMAL, "\n");
1270 
1271 	//(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
1272 	if(FindArg("-sound22k"))
1273 	{
1274 		digi_sample_rate = SAMPLE_RATE_22K;
1275 	}
1276 
1277 	if(FindArg("-sound11k"))
1278 	{
1279 		digi_sample_rate = SAMPLE_RATE_11K;
1280 	}
1281 
1282 	arch_init_start();
1283 
1284 	arch_init();
1285 
1286 	//con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
1287 
1288 	//added/edited 8/18/98 by Victor Rachels to set maximum fps <= 100
1289 	if ((t = FindArg( "-maxfps" ))) {
1290 		t=atoi(Args[t+1]);
1291 		if (t>0&&t<=80)
1292 			maxfps=t;
1293 	}
1294 	//end addition - Victor Rachels
1295 
1296 	if ( FindArg( "-autodemo" ))
1297 		Auto_demo = 1;
1298 
1299 #ifndef RELEASE
1300 	if ( FindArg( "-noscreens" ) )
1301 		Skip_briefing_screens = 1;
1302 #endif
1303 
1304 	if ((t=FindArg("-tmap"))){
1305 		select_tmap(Args[t+1]);
1306 	}else
1307 		select_tmap(NULL);
1308 
1309 	Lighting_on = 1;
1310 
1311 //	if (init_graphics()) return 1;
1312 
1313 	#ifdef EDITOR
1314 	if (!Inferno_is_800x600_available)	{
1315 		con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
1316 		Function_mode = FMODE_MENU;
1317 	}
1318 	#endif
1319 
1320 	if (!WVIDEO_running)
1321 		con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
1322 
1323 	con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
1324 	ReadConfigFile();
1325 
1326 	do_joystick_init();
1327 
1328 #ifdef NETWORK
1329 	do_network_init();
1330 #endif
1331 
1332 #if defined(POLY_ACC)
1333     Current_display_mode = -1;
1334     game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
1335 #else
1336 
1337 	if (!VR_offscreen_buffer)	//if hasn't been initialied (by headset init)
1338 		set_display_mode(0);		//..then set default display mode
1339 #endif
1340 
1341 	{
1342 //added on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
1343 		int i, argnum=INT_MAX;
1344 //end addition -MM
1345 		int vr_mode = VR_NONE;
1346 		int screen_compatible = 1;
1347 		int use_double_buffer = 0;
1348 
1349 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
1350 //added on 9/30/98 by Matt Mueller clean up screen mode code, and add higher resolutions
1351 #define SCREENMODE(X,Y,C) if ( (i=FindArg( "-" #X "x" #Y ))&&(i<argnum))  {argnum=i; screen_mode = SM( X , Y ); con_printf(CON_VERBOSE, "Using " #X "x" #Y " ...\n" );screen_width = X;screen_height = Y;use_double_buffer = 1;screen_compatible = C;}
1352 //aren't #defines great? :)
1353 
1354 		SCREENMODE(320,100,0);
1355 		SCREENMODE(320,200,1);
1356 //end addition/edit -MM
1357 		SCREENMODE(320,240,0);
1358 		SCREENMODE(320,400,0);
1359 		SCREENMODE(640,400,0);
1360 		SCREENMODE(640,480,0);
1361 		SCREENMODE(800,600,0);
1362 		SCREENMODE(1024,768,0);
1363 		SCREENMODE(1152,864,0);
1364 		SCREENMODE(1280,960,0);
1365 		SCREENMODE(1280,1024,0);
1366 		SCREENMODE(1600,1200,0);
1367 //end addition -MM
1368 
1369 //added ifdefs on 9/30/98 by Matt Mueller to fix high res in linux
1370 #ifdef __MSDOS__
1371 		if ( FindArg( "-nodoublebuffer" ) )	{
1372 			con_printf(CON_VERBOSE, "Double-buffering disabled...\n" );
1373 #endif
1374 			use_double_buffer = 0;
1375 #ifdef __MSDOS__
1376 		}
1377 #endif
1378 //end addition -MM
1379 
1380 		//added 3/24/99 by Owen Evans for screen res changing
1381 //		Game_Screen_mode = screen_mode;
1382 		//end added -OE
1383 		game_init_render_buffers(screen_mode, screen_width, screen_height, vr_mode, screen_compatible);
1384 
1385 	}
1386 	{
1387 //added/edited on 12/14/98 by Matt Mueller - override res in d1x.ini with command line args
1388 		int i, argnum=INT_MAX;
1389 //added on 9/30/98 by Matt Mueller for selectable automap modes - edited 11/21/99 whee, more fun with defines.
1390 #define SMODE(V,VV,VG,X,Y) if ( (i=FindArg( "-" #V #X "x" #Y )) && (i<argnum))  {argnum=i; VV = SM( X , Y );VG=0;}
1391 #define SMODE_GR(V,VG) if ((i=FindArg("-" #V "_gameres"))){if (i<argnum) VG=1;}
1392 #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) );
1393 //aren't #defines great? :)
1394 //end addition/edit -MM
1395 #define S_MODE(V,VV,VG) argnum=INT_MAX;SMODE(V,VV,VG,320,200);SMODE(V,VV,VG,320,240);SMODE(V,VV,VG,320,400);SMODE(V,VV,VG,640,400);SMODE(V,VV,VG,640,480);SMODE(V,VV,VG,800,600);SMODE(V,VV,VG,1024,768);SMODE(V,VV,VG,1280,1024);SMODE(V,VV,VG,1600,1200);SMODE_GR(V,VG);SMODE_PRINT(V,VV,VG);
1396 
1397 		S_MODE(automap,automap_mode,automap_use_game_res);
1398 //		S_MODE(menu,menu_screen_mode,menu_use_game_res);
1399 	 }
1400 //end addition -MM
1401 
1402 	i = FindArg( "-xcontrol" );
1403 	if ( i > 0 )	{
1404 		kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
1405 	}
1406 
1407 	con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
1408 	if (FindArg("-nofade"))
1409 		grd_fades_disabled=1;
1410 
1411 	//determine whether we're using high-res menus & movies
1412 #if !defined(POLY_ACC)
1413 	if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
1414 		MovieHires = MenuHires = MenuHiresAvailable = 0;
1415 	else
1416 #endif
1417 		//NOTE LINK TO ABOVE!
1418 		MenuHires = MenuHiresAvailable = 1;
1419 
1420 	if (FindArg( "-lowresmovies" ))
1421 		MovieHires = 0;
1422 
1423 	if ((t=gr_init())!=0)				//doesn't do much
1424 		Error(TXT_CANT_INIT_GFX,t);
1425 
1426    #ifdef _3DFX
1427    _3dfx_Init();
1428    #endif
1429 
1430 	// Load the palette stuff. Returns non-zero if error.
1431 	con_printf(CON_DEBUG, "Initializing palette system...\n" );
1432 	gr_use_palette_table(DEFAULT_PALETTE );
1433 
1434 	con_printf(CON_DEBUG, "Initializing font system...\n" );
1435 	gamefont_init();	// must load after palette data loaded.
1436 
1437 	con_printf( CON_DEBUG, "Initializing movie libraries...\n" );
1438 	init_movies();		//init movie libraries
1439 
1440 #if 0
1441 	con_printf(CON_VERBOSE, "Going into graphics mode...\n");
1442 #if defined(POLY_ACC)
1443 	gr_set_mode(SM_640x480x15xPA);
1444 #else
1445 	gr_set_mode(MovieHires?SM(640,480):SM(320,200));
1446 #endif
1447 #endif
1448 
1449 	#ifndef RELEASE
1450 	if ( FindArg( "-notitles" ) )
1451 		songs_play_song( SONG_TITLE, 1);
1452 	else
1453 	#endif
1454 	{	//NOTE LINK TO ABOVE!
1455 #ifndef SHAREWARE
1456 		int played=MOVIE_NOT_PLAYED;	//default is not played
1457 #endif
1458 		int song_playing = 0;
1459 
1460 		#ifdef D2_OEM
1461 		#define MOVIE_REQUIRED 0
1462 		#else
1463 		#define MOVIE_REQUIRED 1
1464 		#endif
1465 
1466 #ifdef D2_OEM   //$$POLY_ACC, jay.
1467 		{	//show bundler screens
1468 			FILE *tfile;
1469 			char filename[FILENAME_LEN];
1470 
1471 			played=MOVIE_NOT_PLAYED;	//default is not played
1472 
1473             played = PlayMovie("pre_i.mve",0);
1474 
1475 			if (!played) {
1476                 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
1477 
1478 				while ((tfile=fopen(filename,"rb")) != NULL) {
1479 					fclose(tfile);
1480 					show_title_screen( filename, 1, 0 );
1481                     filename[5]++;
1482 				}
1483 			}
1484 		}
1485 #endif
1486 
1487 		#ifndef SHAREWARE
1488 			init_subtitles("intro.tex");
1489 			played = PlayMovie("intro.mve",MOVIE_REQUIRED);
1490 			close_subtitles();
1491 		#endif
1492 
1493 		#ifdef D2_OEM
1494 		if (played != MOVIE_NOT_PLAYED)
1495 			intro_played = 1;
1496 		else {						//didn't get intro movie, try titles
1497 
1498 			played = PlayMovie("titles.mve",MOVIE_REQUIRED);
1499 
1500 			if (played == MOVIE_NOT_PLAYED) {
1501 #if defined(POLY_ACC)
1502 				gr_set_mode(SM_640x480x15xPA);
1503 #else
1504 				gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
1505 #endif
1506 				con_printf( CON_DEBUG, "\nPlaying title song..." );
1507 				songs_play_song( SONG_TITLE, 1);
1508 				song_playing = 1;
1509 				con_printf( CON_DEBUG, "\nShowing logo screens..." );
1510 				show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
1511 				show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
1512 			}
1513 		}
1514 
1515 		{	//show bundler movie or screens
1516 
1517 			FILE *tfile;
1518 			char filename[FILENAME_LEN];
1519 			int movie_handle;
1520 
1521 			played=MOVIE_NOT_PLAYED;	//default is not played
1522 
1523 			//check if OEM movie exists, so we don't stop the music if it doesn't
1524 			movie_handle = open_movie_file("oem.mve",0);
1525 			if (movie_handle != -1) {
1526 				close(movie_handle);
1527 				played = PlayMovie("oem.mve",0);
1528 				song_playing = 0;		//movie will kill sound
1529 			}
1530 
1531 			if (!played) {
1532 				strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
1533 
1534 				while ((tfile=fopen(filename,"rb")) != NULL) {
1535 					fclose(tfile);
1536 					show_title_screen( filename, 1, 0 );
1537 					filename[3]++;
1538 				}
1539 			}
1540 		}
1541 		#endif
1542 
1543 		if (!song_playing)
1544 			songs_play_song( SONG_TITLE, 1);
1545 
1546 	}
1547 
1548 	PA_DFX (pa_splash());
1549 
1550 	con_printf( CON_DEBUG, "\nShowing loading screen..." );
1551 	{
1552 		//grs_bitmap title_bm;
1553 		int pcx_error;
1554 		char filename[14];
1555 
1556 		strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
1557 		if (! cfexist(filename))
1558 			strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx"); // OEM
1559 		if (! cfexist(filename))
1560 			strcpy(filename, "descentd.pcx"); // SHAREWARE
1561 		if (! cfexist(filename))
1562 			strcpy(filename, "descentb.pcx"); // MAC SHAREWARE
1563 
1564 #if defined(POLY_ACC)
1565 		gr_set_mode(SM_640x480x15xPA);
1566 #else
1567 		gr_set_mode(MenuHires?SM(640,480):SM(320,200));
1568 #endif
1569 #ifdef OGL
1570 		set_screen_mode(SCREEN_MENU);
1571 #endif
1572 
1573 		FontHires = FontHiresAvailable && MenuHires;
1574 
1575 		if ((pcx_error=pcx_read_fullscr( filename, title_pal ))==PCX_ERROR_NONE)	{
1576 			//vfx_set_palette_sub( title_pal );
1577 			gr_palette_clear();
1578 			gr_palette_fade_in( title_pal, 32, 0 );
1579 		} else
1580 			Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
1581 	}
1582 
1583 	con_printf( CON_DEBUG , "\nDoing bm_init..." );
1584 	#ifdef EDITOR
1585 		bm_init_use_tbl();
1586 	#else
1587 		bm_init();
1588 	#endif
1589 
1590 	#ifdef EDITOR
1591 	if (FindArg("-hoarddata") != 0) {
1592 		#define MAX_BITMAPS_PER_BRUSH 30
1593 		grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
1594 		grs_bitmap icon;
1595 		int nframes;
1596 		short nframes_short;
1597 		ubyte palette[256*3];
1598 		FILE *ofile;
1599 		int iff_error,i;
1600 		char *sounds[] = {"selforb.raw","selforb.r22",		//SOUND_YOU_GOT_ORB
1601 								"teamorb.raw","teamorb.r22",		//SOUND_FRIEND_GOT_ORB
1602 								"enemyorb.raw","enemyorb.r22",	//SOUND_OPPONENT_GOT_ORB
1603 								"OPSCORE1.raw","OPSCORE1.r22"};	//SOUND_OPPONENT_HAS_SCORED
1604 
1605 		ofile = fopen("hoard.ham","wb");
1606 
1607 	   iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
1608 		Assert(iff_error == IFF_NO_ERROR);
1609 		nframes_short = nframes;
1610 		fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
1611 		fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
1612 		fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
1613 		fwrite(palette,3,256,ofile);
1614 		for (i=0;i<nframes;i++)
1615 			fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
1616 
1617 		iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
1618 		Assert(iff_error == IFF_NO_ERROR);
1619 		Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
1620 		nframes_short = nframes;
1621 		fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
1622 		fwrite(palette,3,256,ofile);
1623 		for (i=0;i<nframes;i++)
1624 			fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
1625 
1626 		for (i=0;i<2;i++) {
1627 			iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
1628 			Assert(iff_error == IFF_NO_ERROR);
1629 			fwrite(&icon.bm_w,sizeof(short),1,ofile);
1630 			fwrite(&icon.bm_h,sizeof(short),1,ofile);
1631 			fwrite(palette,3,256,ofile);
1632 			fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
1633 		}
1634 
1635 		for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
1636 			FILE *ifile;
1637 			int size;
1638 			ubyte *buf;
1639 			ifile = fopen(sounds[i],"rb");
1640 			Assert(ifile != NULL);
1641 			size = ffilelength(ifile);
1642 			buf = d_malloc(size);
1643 			fread(buf,1,size,ifile);
1644 			fwrite(&size,sizeof(size),1,ofile);
1645 			fwrite(buf,1,size,ofile);
1646 			d_free(buf);
1647 			fclose(ifile);
1648 		}
1649 
1650 		fclose(ofile);
1651 
1652 		exit(1);
1653 	}
1654 	#endif
1655 
1656 	//the bitmap loading code changes gr_palette, so restore it
1657 	memcpy(gr_palette,title_pal,sizeof(gr_palette));
1658 
1659 	if ( FindArg( "-norun" ) )
1660 		return(0);
1661 
1662 	con_printf( CON_DEBUG, "\nInitializing 3d system..." );
1663 	g3_init();
1664 
1665 	con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
1666 	texmerge_init( 10 );		// 10 cache bitmaps
1667 
1668 	con_printf( CON_DEBUG, "\nRunning game...\n" );
1669 	set_screen_mode(SCREEN_MENU);
1670 
1671 	init_game();
1672 
1673 	//	If built with editor, option to auto-load a level and quit game
1674 	//	to write certain data.
1675 	#ifdef	EDITOR
1676 	{	int t;
1677 	if ( (t = FindArg( "-autoload" )) ) {
1678 		Auto_exit = 1;
1679 		strcpy(Auto_file, Args[t+1]);
1680 	}
1681 
1682 	}
1683 
1684 	if (Auto_exit) {
1685 		strcpy(Players[0].callsign, "dummy");
1686 	} else
1687 	#endif
1688 		do_register_player(title_pal);
1689 
1690 	gr_palette_fade_out( title_pal, 32, 0 );
1691 
1692 	Game_mode = GM_GAME_OVER;
1693 
1694 	if (Auto_demo)	{
1695 		newdemo_start_playback("descent.dem");
1696 		if (Newdemo_state == ND_STATE_PLAYBACK )
1697 			Function_mode = FMODE_GAME;
1698 	}
1699 
1700 	//do this here because the demo code can do a longjmp when trying to
1701 	//autostart a demo from the main menu, never having gone into the game
1702 	setjmp(LeaveGame);
1703 
1704 	while (Function_mode != FMODE_EXIT)
1705 	{
1706 		switch( Function_mode )	{
1707 		case FMODE_MENU:
1708 			set_screen_mode(SCREEN_MENU);
1709 			if ( Auto_demo )	{
1710 				newdemo_start_playback(NULL);		// Randomly pick a file
1711 				if (Newdemo_state != ND_STATE_PLAYBACK)
1712 					Error("No demo files were found for autodemo mode!");
1713 			} else {
1714 				#ifdef EDITOR
1715 				if (Auto_exit) {
1716 					strcpy((char *)&Level_names[0], Auto_file);
1717 					LoadLevel(1, 1);
1718 					Function_mode = FMODE_EXIT;
1719 					break;
1720 				}
1721 				#endif
1722 
1723 				check_joystick_calibration();
1724 				gr_palette_clear();		//I'm not sure why we need this, but we do
1725 				DoMenu();
1726 				#ifdef EDITOR
1727 				if ( Function_mode == FMODE_EDITOR )	{
1728 					create_new_mine();
1729 					SetPlayerFromCurseg();
1730 					load_palette(NULL,1,0);
1731 				}
1732 				#endif
1733 			}
1734 			break;
1735 		case FMODE_GAME:
1736 			#ifdef EDITOR
1737 				keyd_editor_mode = 0;
1738 			#endif
1739 
1740 #ifdef SDL_INPUT
1741 			/* keep the mouse from wandering in SDL */
1742 			if (FindArg("-grabmouse"))
1743 			    SDL_WM_GrabInput(SDL_GRAB_ON);
1744 #endif
1745 
1746 			game();
1747 
1748 #ifdef SDL_INPUT
1749 			/* give control back to the WM */
1750 			if (FindArg("-grabmouse"))
1751 			    SDL_WM_GrabInput(SDL_GRAB_OFF);
1752 #endif
1753 
1754 			if ( Function_mode == FMODE_MENU )
1755 				songs_play_song( SONG_TITLE, 1 );
1756 			break;
1757 		#ifdef EDITOR
1758 		case FMODE_EDITOR:
1759 			keyd_editor_mode = 1;
1760 			editor();
1761 #ifdef __WATCOMC__
1762 			_harderr( (void*)descent_critical_error_handler );		// Reinstall game error handler
1763 #endif
1764 			if ( Function_mode == FMODE_GAME ) {
1765 				Game_mode = GM_EDITOR;
1766 				editor_reset_stuff_on_level();
1767 				N_players = 1;
1768 			}
1769 			break;
1770 		#endif
1771 		default:
1772 			Error("Invalid function mode %d",Function_mode);
1773 		}
1774 	}
1775 
1776 	WriteConfigFile();
1777 
1778 #if 0
1779 	#ifndef RELEASE
1780 	if (!FindArg( "-notitles" ))
1781 	#endif
1782 		show_order_form();
1783 #endif
1784 
1785 	#ifndef NDEBUG
1786 	if ( FindArg( "-showmeminfo" ) )
1787 		show_mem_info = 1;		// Make memory statistics show
1788 	#endif
1789 
1790 	return(0);		//presumably successful exit
1791 }
1792 
1793 
check_joystick_calibration()1794 void check_joystick_calibration()	{
1795 	int x1, y1, x2, y2, c;
1796 	fix t1;
1797 
1798 	if ( (Config_control_type!=CONTROL_JOYSTICK) &&
1799 		  (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
1800 		  (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
1801 		  (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
1802 		) return;
1803 
1804 	joy_get_pos( &x1, &y1 );
1805 
1806 	t1 = timer_get_fixed_seconds();
1807 	while( timer_get_fixed_seconds() < t1 + F1_0/100 )
1808 		;
1809 
1810 	joy_get_pos( &x2, &y2 );
1811 
1812 	// If joystick hasn't moved...
1813 	if ( (abs(x2-x1)<30) &&  (abs(y2-y1)<30) )	{
1814 		if ( (abs(x1)>30) || (abs(x2)>30) ||  (abs(y1)>30) || (abs(y2)>30) )	{
1815 			c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
1816 			if ( c==0 )	{
1817 				joydefs_calibrate();
1818 			}
1819 		}
1820 	}
1821 
1822 }
1823 
show_order_form()1824 void show_order_form()
1825 {
1826 #if !defined(EDITOR) && (defined(SHAREWARE) || defined(D2_OEM))
1827 
1828 	int pcx_error;
1829 	char title_pal[768];
1830 	char	exit_screen[16];
1831 
1832 	gr_set_current_canvas( NULL );
1833 	gr_palette_clear();
1834 
1835 	key_flush();
1836 
1837 	#ifdef D2_OEM
1838 		strcpy(exit_screen, MenuHires?"ordrd2ob.pcx":"ordrd2o.pcx");
1839 	#else
1840 	#if defined(SHAREWARE)
1841 		strcpy(exit_screen, "orderd2.pcx");
1842 	#else
1843 		strcpy(exit_screen, MenuHires?"warningb.pcx":"warning.pcx");
1844 	#endif
1845 	#endif
1846 
1847 	if ((pcx_error=pcx_read_fullscr( exit_screen, title_pal ))==PCX_ERROR_NONE) {
1848 		//vfx_set_palette_sub( title_pal );
1849 		gr_palette_fade_in( title_pal, 32, 0 );
1850 		key_getch();
1851 		gr_palette_fade_out( title_pal, 32, 0 );
1852 	}
1853 	else
1854 		Int3();		//can't load order screen
1855 
1856 	key_flush();
1857 
1858 #endif
1859 }
1860 
quit_request()1861 void quit_request()
1862 {
1863 #ifdef NETWORK
1864 //	void network_abort_game();
1865 //	if(Network_status)
1866 //		network_abort_game();
1867 #endif
1868 	exit(0);
1869 }
1870