]> icculus.org git repositories - btb/d2x.git/blob - main/kconfig.c
bunch of fixes (esp. for non linux-native joystick)
[btb/d2x.git] / main / kconfig.c
1 /* $Id: kconfig.c,v 1.26 2003-12-18 10:32:57 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  * Routines to configure keyboard, joystick, etc..
18  *
19  * Old Log:
20  * Revision 1.18  1995/10/29  20:14:10  allender
21  * don't read mouse 30x/sec.  Still causes problems -- left with
22  * exposure at > 60 frame/s
23  *
24  * Revision 1.17  1995/10/27  14:16:35  allender
25  * don't set lastreadtime when doing mouse stuff if we didn't
26  * read mouse this frame
27  *
28  * Revision 1.16  1995/10/24  18:10:22  allender
29  * get mouse stuff working right this time?
30  *
31  * Revision 1.15  1995/10/23  14:50:50  allender
32  * corrected values for control type in kc_set_controls
33  *
34  * Revision 1.14  1995/10/21  16:36:54  allender
35  * fix up mouse read time
36  *
37  * Revision 1.13  1995/10/20  00:46:53  allender
38  * fix up mouse reading problem
39  *
40  * Revision 1.12  1995/10/19  13:36:38  allender
41  * mouse support in kconfig screens
42  *
43  * Revision 1.11  1995/10/18  21:06:06  allender
44  * removed Int3 in cruise stuff -- was in there for debugging and
45  * now not needed
46  *
47  * Revision 1.10  1995/10/17  13:12:47  allender
48  * fixed config menus so buttons don't get configured
49  *
50  * Revision 1.9  1995/10/15  23:07:55  allender
51  * added return key as second button for primary fire
52  *
53  * Revision 1.8  1995/09/05  08:49:47  allender
54  * change 'PADRTN' label to 'ENTER'
55  *
56  * Revision 1.7  1995/09/01  15:38:22  allender
57  * took out cap of reading controls max 25 times/sec
58  *
59  * Revision 1.6  1995/09/01  13:33:59  allender
60  * erase all old text
61  *
62  * Revision 1.5  1995/08/18  10:20:55  allender
63  * keep controls reading to 25 times/s max so fast
64  * frame rates don't mess up control reading
65  *
66  * Revision 1.4  1995/07/28  15:43:13  allender
67  * make mousebutton control primary fire
68  *
69  * Revision 1.3  1995/07/26  17:04:32  allender
70  * new defaults and make joystick main button work correctly
71  *
72  * Revision 1.2  1995/07/17  08:51:03  allender
73  * fixed up configuration menus to look right
74  *
75  * Revision 1.1  1995/05/16  15:26:56  allender
76  * Initial revision
77  *
78  * Revision 2.11  1995/08/23  16:08:04  john
79  * Added version 2 of external controls that passes the ship
80  * position and orientation the drivers.
81  *
82  * Revision 2.10  1995/07/07  16:48:01  john
83  * Fixed bug with new interface.
84  *
85  * Revision 2.9  1995/07/03  15:02:32  john
86  * Added new version of external controls for Cybermouse absolute position.
87  *
88  * Revision 2.8  1995/06/30  12:30:28  john
89  * Added -Xname command line.
90  *
91  * Revision 2.7  1995/03/30  16:36:56  mike
92  * text localization.
93  *
94  * Revision 2.6  1995/03/21  14:39:31  john
95  * Ifdef'd out the NETWORK code.
96  *
97  * Revision 2.5  1995/03/16  10:53:07  john
98  * Move VFX center to Shift+Z instead of Enter because
99  * it conflicted with toggling HUD on/off.
100  *
101  * Revision 2.4  1995/03/10  13:47:24  john
102  * Added head tracking sensitivity.
103  *
104  * Revision 2.3  1995/03/09  18:07:06  john
105  * Fixed bug with iglasses tracking not "centering" right.
106  * Made VFX have bright headlight lighting.
107  *
108  * Revision 2.2  1995/03/08  15:32:39  john
109  * Made VictorMaxx head tracking use Greenleaf code.
110  *
111  * Revision 2.1  1995/03/06  15:23:31  john
112  * New screen techniques.
113  *
114  * Revision 2.0  1995/02/27  11:29:26  john
115  * New version 2.0, which has no anonymous unions, builds with
116  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
117  *
118  * Revision 1.105  1995/02/22  14:11:58  allender
119  * remove anonymous unions from object structure
120  *
121  * Revision 1.104  1995/02/13  12:01:56  john
122  * Fixed bug with buggin not mmaking player faster.
123  *
124  * Revision 1.103  1995/02/09  22:00:46  john
125  * Added i-glasses tracking.
126  *
127  * Revision 1.102  1995/01/24  21:25:47  john
128  * Fixed bug with slide/bank on not working with
129  * Cyberman heading.,
130  *
131  * Revision 1.101  1995/01/24  16:09:56  john
132  * Fixed bug with Wingman extreme customize text overwriting title.
133  *
134  * Revision 1.100  1995/01/24  12:37:46  john
135  * Made Esc exit key define menu.
136  *
137  * Revision 1.99  1995/01/23  23:54:43  matt
138  * Made keypad enter work
139  *
140  * Revision 1.98  1995/01/23  16:42:00  john
141  * Made the external controls always turn banking off, leveling off
142  * and passed automap state thru to the tsr.
143  *
144  * Revision 1.97  1995/01/12  11:41:33  john
145  * Added external control reading.
146  *
147  * Revision 1.96  1995/01/05  10:43:58  mike
148  * Handle case when timer_get_fixed_seconds() goes negative.  Happens at 9.1
149  * hours.  Previously, joystick would stop functioning.  Now will work.
150  *
151  * Revision 1.95  1994/12/29  11:17:38  john
152  * Took out some warnings and mprintf.
153  *
154  * Revision 1.94  1994/12/29  11:07:41  john
155  * Fixed Thrustmaster and Logitech Wingman extreme
156  * Hat by reading the y2 axis during the center stage
157  * of the calibration, and using 75, 50, 27, and 3 %
158  * as values for the 4 positions.
159  *
160  * Revision 1.93  1994/12/27  12:16:20  john
161  * Fixed bug with slide on not working with joystick or mouse buttons.
162  *
163  * Revision 1.92  1994/12/20  10:34:15  john
164  * Made sensitivity work for mouse & joystick and made
165  * it only affect, pitch, heading, and roll.
166  *
167  * Revision 1.91  1994/12/16  00:11:23  matt
168  * Made delete key act normally when debug out
169  *
170  * Revision 1.90  1994/12/14  17:41:15  john
171  * Added more buttons so that  Yoke would work.
172  *
173  * Revision 1.89  1994/12/13  17:25:35  allender
174  * Added Assert for bogus time for joystick reading.
175  *
176  * Revision 1.88  1994/12/13  14:48:01  john
177  * Took out some debugging mprintf's
178  *
179  *
180  * Revision 1.87  1994/12/13  14:43:02  john
181  * Took out the code in kconfig to build direction array.
182  * Called kc_set_controls after selecting a new control type.
183  *
184  * Revision 1.86  1994/12/13  01:11:32  john
185  * Fixed bug with message clearing overwriting
186  * right border.
187  *
188  * Revision 1.85  1994/12/12  00:35:58  john
189  * Added or thing for keys.
190  *
191  * Revision 1.84  1994/12/09  17:08:06  john
192  * Made mouse a bit less sensitive.
193  *
194  * Revision 1.83  1994/12/09  16:04:00  john
195  * Increased mouse sensitivity.
196  *
197  * Revision 1.82  1994/12/09  00:41:26  mike
198  * fix hang in automap print screen
199  *
200  * Revision 1.81  1994/12/08  11:50:37  john
201  * Made strcpy only copy corect number of chars,.
202  *
203  * Revision 1.80  1994/12/07  16:16:06  john
204  * Added command to check to see if a joystick axes has been used.
205  *
206  * Revision 1.79  1994/12/07  14:52:28  yuan
207  * Localization 492
208  *
209  * Revision 1.78  1994/12/07  13:37:40  john
210  * Made the joystick thrust work in reverse.
211  *
212  * Revision 1.77  1994/12/07  11:28:24  matt
213  * Did a little localization support
214  *
215  * Revision 1.76  1994/12/04  12:30:03  john
216  * Made the Thrustmaster stick read every frame, not every 10 frames,
217  * because it uses analog axis as buttons.
218  *
219  * Revision 1.75  1994/12/03  22:35:25  yuan
220  * Localization 412
221  *
222  * Revision 1.74  1994/12/03  15:39:24  john
223  * Made numeric keypad move in conifg.
224  *
225  * Revision 1.73  1994/12/01  16:23:39  john
226  * Fixed include mistake.
227  *
228  * Revision 1.72  1994/12/01  16:07:57  john
229  * Fixed bug that disabled joystick in automap because it used gametime, which is
230  * paused during automap. Fixed be used timer_Get_fixed_seconds instead of GameTime.
231  *
232  * Revision 1.71  1994/12/01  12:30:49  john
233  * Made Ctrl+D delete, not Ctrl+E
234  *
235  * Revision 1.70  1994/12/01  11:52:52  john
236  * Added default values for GamePad.
237  *
238  * Revision 1.69  1994/11/30  00:59:12  mike
239  * optimizations.
240  *
241  * Revision 1.68  1994/11/29  03:45:50  john
242  * Added joystick sensitivity; Added sound channels to detail menu.  Removed -maxchannels
243  * command line arg.
244  *
245  * Revision 1.67  1994/11/27  23:13:44  matt
246  * Made changes for new mprintf calling convention
247  *
248  * Revision 1.66  1994/11/27  19:52:12  matt
249  * Made screen shots work in a few more places
250  *
251  * Revision 1.65  1994/11/22  16:54:50  mike
252  * autorepeat on missiles.
253  *
254  * Revision 1.64  1994/11/21  11:16:17  rob
255  * Changed calls to GameLoop to calls to multi_menu_poll and changed
256  * conditions under which they are called.
257  *
258  * Revision 1.63  1994/11/19  15:14:48  mike
259  * remove unused code and data
260  *
261  * Revision 1.62  1994/11/18  23:37:56  john
262  * Changed some shorts to ints.
263  *
264  * Revision 1.61  1994/11/17  13:36:35  rob
265  * Added better network hook in kconfig menu.
266  *
267  * Revision 1.60  1994/11/14  20:09:13  john
268  * Made Tab be default for automap.
269  *
270  * Revision 1.59  1994/11/13  16:34:07  matt
271  * Fixed victormaxx angle conversions
272  *
273  * Revision 1.58  1994/11/12  14:47:05  john
274  * Added support for victor head tracking.
275  *
276  * Revision 1.57  1994/11/08  15:14:55  john
277  * Added more calls so net doesn't die in net game.
278  *
279  * Revision 1.56  1994/11/07  14:01:07  john
280  * Changed the gamma correction sequencing.
281  *
282  * Revision 1.55  1994/11/01  16:40:08  john
283  * Added Gamma correction.
284  *
285  * Revision 1.54  1994/10/25  23:09:26  john
286  * Made the automap key configurable.
287  *
288  * Revision 1.53  1994/10/25  13:11:59  john
289  * Made keys the way Adam speced 'em for final game.
290  *
291  * Revision 1.52  1994/10/24  17:44:22  john
292  * Added stereo channel reversing.
293  *
294  * Revision 1.51  1994/10/22  13:23:18  john
295  * Made default rear view key be R.
296  *
297  * Revision 1.50  1994/10/22  13:20:09  john
298  * Took out toggle primary/secondary weapons.  Fixed black
299  * background for 'axes' and 'buttons' text.
300  *
301  * Revision 1.49  1994/10/21  15:20:15  john
302  * Made PrtScr do screen dump, not F2.
303  *
304  * Revision 1.48  1994/10/21  13:41:36  john
305  * Allowed F2 to screen dump.
306  *
307  * Revision 1.47  1994/10/17  13:07:05  john
308  * Moved the descent.cfg info into the player config file.
309  *
310  * Revision 1.46  1994/10/14  15:30:22  john
311  * Added Cyberman default positions.
312  *
313  * Revision 1.45  1994/10/14  15:24:54  john
314  * Made Cyberman work with config.
315  *
316  * Revision 1.44  1994/10/14  12:46:04  john
317  * Added the ability to reset all to default.
318  *
319  * Revision 1.43  1994/10/14  12:18:31  john
320  * Made mouse invert axis always be 0 or 1.
321  *
322  * Revision 1.42  1994/10/14  12:16:03  john
323  * Changed code so that by doing DEL+F12 saves the current kconfig
324  * values as default. Added support for drop_bomb key.  Took out
325  * unused slots for keyboard.  Made keyboard use control_type of 0
326  * save slots.
327  *
328  * Revision 1.41  1994/10/13  21:27:02  john
329  * Made axis invert value always be 0 or 1.
330  *
331  * Revision 1.40  1994/10/13  20:18:15  john
332  * Added some more system keys, such as F? and CAPSLOCK.
333  *
334  * Revision 1.39  1994/10/13  19:22:29  john
335  * Added separate config saves for different devices.
336  * Made all the devices work together better, such as mice won't
337  * get read when you're playing with the joystick.
338  *
339  * Revision 1.38  1994/10/13  15:41:57  mike
340  * Remove afterburner.
341  *
342  */
343
344 #ifdef HAVE_CONFIG_H
345 #include <conf.h>
346 #endif
347
348 #ifdef RCS
349 static char rcsid[] = "$Id: kconfig.c,v 1.26 2003-12-18 10:32:57 btb Exp $";
350 #endif
351
352 #ifdef WINDOWS
353 #include "desw.h"
354 #endif
355
356 #include <stdio.h>
357 #include <stdlib.h>
358 #include <string.h>
359 #include <stdarg.h>
360 #include <ctype.h>
361
362 #include "pa_enabl.h"                   //$$POLY_ACC
363 #include "error.h"
364 #include "pstypes.h"
365 #include "gr.h"
366 #include "mono.h"
367 #include "key.h"
368 #include "palette.h"
369 #include "game.h"
370 #include "gamefont.h"
371 #include "iff.h"
372 #include "u_mem.h"
373 #include "joy.h"
374 #include "mouse.h"
375 #include "kconfig.h"
376 #include "gauges.h"
377 #include "joydefs.h"
378 #include "songs.h"
379 #include "render.h"
380 #include "digi.h"
381 #include "newmenu.h"
382 #include "endlevel.h"
383 #include "multi.h"
384 #include "timer.h"
385 #include "text.h"
386 #include "player.h"
387 #include "menu.h"
388 #include "automap.h"
389 #include "args.h"
390 #include "lighting.h"
391 #include "ai.h"
392 #include "cntrlcen.h"
393 #if defined (TACTILE)
394  #include "tactile.h"
395 #endif
396
397 #if defined(POLY_ACC)
398 #include "poly_acc.h"
399 #endif
400
401 #include "collide.h"
402
403 #ifdef USE_LINUX_JOY
404 #include "joystick.h"
405 #endif
406
407 ubyte ExtGameStatus=1;
408
409 vms_vector ExtForceVec;
410 vms_matrix ExtApplyForceMatrix;
411
412 int ExtJoltInfo[3]={0,0,0};
413 int ExtXVibrateInfo[2]={0,0};
414 int ExtYVibrateInfo[2]={0,0};
415 ubyte ExtXVibrateClear=0;
416 ubyte ExtYVibrateClear=0;
417
418 #define TABLE_CREATION 1
419
420 // Array used to 'blink' the cursor while waiting for a keypress.
421 sbyte fades[64] = { 1,1,1,2,2,3,4,4,5,6,8,9,10,12,13,15,16,17,19,20,22,23,24,26,27,28,28,29,30,30,31,31,31,31,31,30,30,29,28,28,27,26,24,23,22,20,19,17,16,15,13,12,10,9,8,6,5,4,4,3,2,2,1,1 };
422
423 //char * invert_text[2] = { "N", "Y" };
424 //char * joybutton_text[28] = { "BTN 1", "BTN 2", "BTN 3", "BTN 4", "", "TRIG", "LEFT", "HAT \81", "RIGHT", "", "", "HAT \80", "MID", "", "", "HAT \7f", "", "", "", "HAT \82", "TRIG", "LEFT", "RIGHT", "", "UP","DOWN","LEFT", "RIGHT" };
425 //char * joyaxis_text[4] = { "X1", "Y1", "X2", "Y2" };
426 //char * mouseaxis_text[2] = { "L/R", "F/B" };
427 //char * mousebutton_text[3] = { "Left", "Right", "Mid" };
428
429 int invert_text[2] = { TNUM_N, TNUM_Y };
430
431 #ifdef WINDOWS
432         int joybutton_text[28] = 
433         { TNUM_BTN_1, TNUM_BTN_2, TNUM_BTN_3, TNUM_BTN_4,
434           -1, -1, -1, -1,
435           -1, -1, -1, -1,
436           -1, -1, -1, -1,
437           TNUM_HAT_L, TNUM_HAT_R, TNUM_HAT_U, TNUM_HAT_D,
438           -1, -1, -1, -1,
439           -1, -1, -1, -1
440         };
441         int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 };
442 #else
443         int joybutton_text[28] = 
444         { TNUM_BTN_1, TNUM_BTN_2, TNUM_BTN_3, TNUM_BTN_4,
445           -1, TNUM_TRIG, TNUM_LEFT, TNUM_HAT_L,
446          TNUM_RIGHT, -1, TNUM_HAT2_D, TNUM_HAT_R,
447          TNUM_MID, -1, TNUM_HAT2_R, TNUM_HAT_U,
448          TNUM_HAT2_L, -1, TNUM_HAT2_U, TNUM_HAT_D,
449          TNUM_TRIG, TNUM_LEFT, TNUM_RIGHT, -1, 
450          TNUM_UP, TNUM_DOWN, TNUM_LEFT, TNUM_RIGHT };
451
452         int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 };
453 //      int joyaxis_text[4] = { TNUM_X1, TNUM_Y1, TNUM_X2, TNUM_Y2 };
454 #endif
455         
456 int mouseaxis_text[3] = { TNUM_L_R, TNUM_F_B, TNUM_Z1 };
457 #ifndef MACINTOSH
458 int mousebutton_text[3] = { TNUM_LEFT, TNUM_RIGHT, TNUM_MID };
459 char * mousebutton_textra[13] = { "M4", "M5", "M6", "M7", "M8", "M9", "M10","M11","M12","M13","M14","M15","M16" };//text for buttons above 3. -MPM
460 #else
461 char *mousebutton_text[3] = { "Btn", "", "" };          // only one silly mouse button on the mac
462 #endif
463
464 #ifdef MACINTOSH
465 char * key_text[256] = {         
466 "","S","D","F","H","G","Z","X","C","V","","B","Q", "W", "E", "R",
467 "Y","T","1","2","3","4","6","5","=","9","7","-", "8", "0", "]", "O",
468 "U","[","I","P","RET","L","J","'","K", ";", "\\", ",", "/", "N", "M", ".",
469 "TAB","SPC","`","DEL","","ESC","","APL","SHIFT","CAPSL","OPTN","CTRL","","","","A",
470 "","PAD.","","PAD*","","PAD+","","NMLCK","","","","PAD/","ENTER","","PAD-","",
471 "","PAD=","PAD0","PAD1","PAD2","PAD3","PAD4","PAD5","PAD6","PAD7","","PAD8","PAD9","","","",
472 "F5","F6","F7","","F8","F9","","F11","","F13","","F14","","F10","","F12",
473 "","PAUSE","HELP","HOME","PGUP","DEL","","END","F2","","F1","LARW","RARW","DARW","UARW","",
474 "","","","","","","","","","","","","","","","",
475 "","","","","","","","","","","","","","","","",
476 "","","","","","","","","","","","","","","","",
477 "","","","","","","","","","","","","","","","",
478 "","","","","","","","","","","","","","","","",
479 "","","","","","","","","","","","","","","","",
480 "","","","","","","","","","","","","","","","",
481 "","","","","","","","","","","","","","","",""};
482 #else
483 #if !defined OGL && !defined SDL_INPUT
484 char * key_text[256] = {         \
485 "","ESC","1","2","3","4","5","6","7","8","9","0","-",                   \
486 "=","BSPC","TAB","Q","W","E","R","T","Y","U","I","O",                           \
487 "P","[","]","\83","LCTRL","A","S","D","F",        \
488 "G","H","J","K","L",";","'","`",        \
489 "LSHFT","\\","Z","X","C","V","B","N","M",",",      \
490 ".","/","RSHFT","PAD*","LALT","SPC",      \
491 "CPSLK","F1","F2","F3","F4","F5","F6","F7","F8","F9",        \
492 "F10","NMLCK","SCLK","PAD7","PAD8","PAD9","PAD-",   \
493 "PAD4","PAD5","PAD6","PAD+","PAD1","PAD2","PAD3","PAD0", \
494 "PAD.","","","","F11","F12","","","","","","","","","",         \
495 "","","","","","","","","","","","","","","","","","","","",     \
496 "","","","","","","","","","","","","","","","","","","","",     \
497 "","","","","","","","","","","","","","","","","","",           \
498 "PAD\83","RCTRL","","","","","","","","","","","","","", \
499 "","","","","","","","","","","PAD/","","","RALT","",      \
500 "","","","","","","","","","","","","","HOME","\82","PGUP",     \
501 "","\81","","\7f","","END","\80","PGDN","INS",       \
502 "DEL","","","","","","","","","","","","","","","","","",     \
503 "","","","","","","","","","","","","","","","","","","","",     \
504 "","","","","","","" };
505 #endif /* OGL */
506 #endif
507
508 #ifdef D2X_KEYS
509 //added/removed by Victor Rachels for adding rebindable keys for these
510 // KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0
511 ubyte system_keys[] = { KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_MINUS, KEY_EQUAL, KEY_PRINT_SCREEN };
512 #else
513 ubyte system_keys[] = { KEY_ESC, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11, KEY_F12, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_PRINT_SCREEN };
514 #endif
515
516 //extern void GameLoop(int, int );
517
518 extern void transfer_energy_to_shield(fix);
519 extern void CyclePrimary(),CycleSecondary(),InitMarkerInput();
520 extern ubyte DefiningMarkerMessage;
521 extern char CybermouseActive;
522
523 #ifdef WINDOWS
524 extern int joydefsw_do_button();
525 extern int joydefsw_do_winjoybutton(int *axis);
526 extern joydefsw_win_joyselect(char *title);
527 #endif
528
529 control_info Controls;
530
531 fix Cruise_speed=0;
532
533 // macros for drawing lo/hi res kconfig screens (see scores.c as well)
534
535 #define LHX(x)          ((x)*(MenuHires?2:1))
536 #define LHY(y)          ((y)*(MenuHires?2.4:1))
537
538
539 #define BT_KEY                          0
540 #define BT_MOUSE_BUTTON         1
541 #define BT_MOUSE_AXIS           2
542 #define BT_JOY_BUTTON           3
543 #define BT_JOY_AXIS                     4
544 #define BT_INVERT                               5
545
546 char *btype_text[] = { "BT_KEY", "BT_MOUSE_BUTTON", "BT_MOUSE_AXIS", "BT_JOY_BUTTON", "BT_JOY_AXIS", "BT_INVERT" };
547
548 #define INFO_Y 28
549
550 typedef struct kc_item {
551         short id;                               // The id of this item
552         short x, y;                             
553         short w1;
554         short w2;
555         short u,d,l,r;
556         //short text_num1;
557         char *text;
558         ubyte type;
559         ubyte value;            // what key,button,etc
560 } kc_item;
561
562 int Num_items=28;
563 kc_item *All_items;
564
565 ubyte kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS];
566
567 //added on 2/4/99 by Victor Rachels to add d1x new keys
568 ubyte kconfig_d2x_settings[MAX_D2X_CONTROLS];
569 //end this section addition - VR
570
571 //----------- WARNING!!!!!!! -------------------------------------------
572 // THESE NEXT FOUR BLOCKS OF DATA ARE GENERATED BY PRESSING DEL+F12 WHEN
573 // IN THE KEYBOARD CONFIG SCREEN.  BASICALLY, THAT PROCEDURE MODIFIES THE
574 // U,D,L,R FIELDS OF THE ARRAYS AND DUMPS THE NEW ARRAYS INTO KCONFIG.COD
575 //-------------------------------------------------------------------------
576 /*ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
577 {0xc8,0x48,0xd0,0x50,0xcb,0x4b,0xcd,0x4d,0x38,0xff,0xff,0x4f,0xff,0x51,0xff,0x4a,0xff,0x4e,0xff,0xff,0x10,0x47,0x12,0x49,0x1d,0x9d,0x39,0xff,0x21,0xff,0x1e,0xff,0x2c,0xff,0x30,0xff,0x13,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xff,0x1f,0xff,0x33,0xff,0x34,0xff,0x23,0xff,0x14,0xff,0xff,0xff,0x0,0x0},
578 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
579 {0x5,0xc,0xff,0xff,0xff,0xff,0x7,0xf,0x13,0xb,0xff,0x6,0x8,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
580 {0x0,0x1,0xff,0xff,0x2,0xff,0x7,0xf,0x13,0xb,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
581 {0x3,0x0,0x1,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
582 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
583 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
584 };*/                                                                              
585
586 #ifndef MACINTOSH
587 ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
588 {0xc8,0x48,0xd0,0x50,0xcb,0x4b,0xcd,0x4d,0x38,0xff,0xff,0x4f,0xff,0x51,0xff,0x4a,0xff,0x4e,0xff,0xff,0x10,0x47,0x12,0x49,0x1d,0x9d,0x39,0xff,0x21,0xff,0x1e,0xff,0x2c,0xff,0x30,0xff,0x13,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xff,0x1f,0xff,0x33,0xff,0x34,0xff,0x23,0xff,0x14,0xff,0xff,0xff,0x0,0x0},
589 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
590 {0x5,0xc,0xff,0xff,0xff,0xff,0x7,0xf,0x13,0xb,0xff,0x6,0x8,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0},
591 {0x0,0x1,0xff,0xff,0x2,0xff,0x7,0xf,0x13,0xb,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
592 {0x3,0x0,0x1,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
593 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
594 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
595 #ifdef WINDOWS
596 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
597 #endif
598 };
599
600
601
602 kc_item kc_keyboard[NUM_KEY_CONTROLS] = {
603         {  0, 15, 49, 71, 26, 55,  2, 55,  1,"Pitch forward", BT_KEY, 255 },
604         {  1, 15, 49,100, 26, 50,  3,  0, 24,"Pitch forward", BT_KEY, 255 },
605         {  2, 15, 57, 71, 26,  0,  4, 25,  3,"Pitch backward", BT_KEY, 255 },
606         {  3, 15, 57,100, 26,  1,  5,  2, 26,"Pitch backward", BT_KEY, 255 },
607         {  4, 15, 65, 71, 26,  2,  6, 27,  5,"Turn left", BT_KEY, 255 },
608         {  5, 15, 65,100, 26,  3,  7,  4, 28,"Turn left", BT_KEY, 255 },
609         {  6, 15, 73, 71, 26,  4,  8, 29,  7,"Turn right", BT_KEY, 255 },
610         {  7, 15, 73,100, 26,  5,  9,  6, 34,"Turn right", BT_KEY, 255 },
611         {  8, 15, 85, 71, 26,  6, 10, 35,  9,"Slide on", BT_KEY, 255 },
612         {  9, 15, 85,100, 26,  7, 11,  8, 36,"Slide on", BT_KEY, 255 },
613         { 10, 15, 93, 71, 26,  8, 12, 37, 11,"Slide left", BT_KEY, 255 },
614         { 11, 15, 93,100, 26,  9, 13, 10, 44,"Slide left", BT_KEY, 255 },
615         { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 },
616         { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 },
617         { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 },
618         { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 },
619         { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 },
620         { 17, 15,117,100, 26, 15, 19, 16, 46,"Slide down", BT_KEY, 255 },
621         { 18, 15,129, 71, 26, 16, 20, 47, 19,"Bank on", BT_KEY, 255 },
622         { 19, 15,129,100, 26, 17, 21, 18, 38,"Bank on", BT_KEY, 255 },
623         { 20, 15,137, 71, 26, 18, 22, 39, 21,"Bank left", BT_KEY, 255 },
624         { 21, 15,137,100, 26, 19, 23, 20, 40,"Bank left", BT_KEY, 255 },
625         { 22, 15,145, 71, 26, 20, 48, 41, 23,"Bank right", BT_KEY, 255 },
626         { 23, 15,145,100, 26, 21, 49, 22, 42,"Bank right", BT_KEY, 255 },
627         { 24,158, 49, 83, 26, 51, 26,  1, 25,"Fire primary", BT_KEY, 255 },
628         { 25,158, 49,112, 26, 54, 27, 24,  2,"Fire primary", BT_KEY, 255 },
629         { 26,158, 57, 83, 26, 24, 28,  3, 27,"Fire secondary", BT_KEY, 255 },
630         { 27,158, 57,112, 26, 25, 29, 26,  4,"Fire secondary", BT_KEY, 255 },
631         { 28,158, 65, 83, 26, 26, 34,  5, 29,"Fire flare", BT_KEY, 255 },
632         { 29,158, 65,112, 26, 27, 35, 28,  6,"Fire flare", BT_KEY, 255 },
633         { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 },
634         { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 },
635         { 32,158,113, 83, 26, 30, 46, 15, 33,"reverse", BT_KEY, 255 },
636         { 33,158,113,112, 26, 31, 47, 32, 16,"reverse", BT_KEY, 255 },
637         { 34,158, 73, 83, 26, 28, 36,  7, 35,"Drop Bomb", BT_KEY, 255 },
638         { 35,158, 73,112, 26, 29, 37, 34,  8,"Drop Bomb", BT_KEY, 255 },
639         { 36,158, 85, 83, 26, 34, 44,  9, 37,"REAR VIEW", BT_KEY, 255 },
640         { 37,158, 85,112, 26, 35, 45, 36, 10,"REAR VIEW", BT_KEY, 255 },
641         { 38,158,133, 83, 26, 46, 40, 19, 39,"Cruise Faster", BT_KEY, 255 },
642         { 39,158,133,112, 26, 47, 41, 38, 20,"Cruise Faster", BT_KEY, 255 },
643         { 40,158,141, 83, 26, 38, 42, 21, 41,"Cruise Slower", BT_KEY, 255 },
644         { 41,158,141,112, 26, 39, 43, 40, 22,"Cruise Slower", BT_KEY, 255 },
645         { 42,158,149, 83, 26, 40, 52, 23, 43,"Cruise Off", BT_KEY, 255 },
646         { 43,158,149,112, 26, 41, 53, 42, 48,"Cruise Off", BT_KEY, 255 },
647         { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 },
648         { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 },
649         { 46,158,121, 83, 26, 32, 38, 17, 47,"Afterburner", BT_KEY, 255 },
650         { 47,158,121,112, 26, 33, 39, 46, 18,"Afterburner", BT_KEY, 255 },
651         { 48, 15,161, 71, 26, 22, 50, 43, 49,"Cycle Primary", BT_KEY, 255 },
652         { 49, 15,161,100, 26, 23, 51, 48, 52,"Cycle Primary", BT_KEY, 255 },
653         { 50, 15,169, 71, 26, 48,  1, 53, 51,"Cycle Second", BT_KEY, 255 },
654         { 51, 15,169,100, 26, 49, 24, 50, 54,"Cycle Second", BT_KEY, 255 },
655         { 52,158,163, 83, 26, 42, 54, 49, 53,"Headlight", BT_KEY, 255 },
656         { 53,158,163,112, 26, 43, 55, 52, 50,"Headlight", BT_KEY, 255 },
657         { 54,158,171, 83, 26, 52, 56, 51, 55,"Energy->Shield", BT_KEY, 255 },
658         { 55,158,171,112, 26, 53,  0, 54,  0,"Energy->Shield", BT_KEY, 255 },
659    { 56,158,179,83,  26, 54,  0, 0,  0, "Toggle Bomb",  BT_KEY,255},
660 };
661 kc_item kc_joystick[NUM_OTHER_CONTROLS] = {
662         {  0, 25, 46, 85, 26, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
663         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
664         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
665         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
666         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
667         {  5,180, 46, 79, 26, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
668         {  6,180, 54, 79, 26,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
669         {  7,180, 62, 79, 26,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
670         {  8,180, 70, 79, 26,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
671         {  9,180, 78, 79, 26,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
672         { 10,180, 90, 79, 26,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
673         { 11,180, 98, 79, 26, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
674         { 12,180,106, 79, 26, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
675         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
676         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
677         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
678         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
679         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
680         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
681         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
682         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
683         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
684         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
685         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
686         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
687         { 25, 25,109, 85, 26,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
688         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
689         { 27, 25,117, 85, 26, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
690         { 28,180,114, 79, 26, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
691         { 29,180,122, 79, 26, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
692         { 30, 25,125, 85, 26, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
693 };
694 kc_item kc_superjoy[NUM_OTHER_CONTROLS] = {
695         {  0, 25, 46, 85, 26, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
696         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
697         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
698         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
699         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
700         {  5,180, 46, 79, 26, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
701         {  6,180, 54, 79, 26,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
702         {  7,180, 62, 79, 26,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
703         {  8,180, 70, 79, 26,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
704         {  9,180, 78, 79, 26,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
705         { 10,180, 90, 79, 26,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
706         { 11,180, 98, 79, 26, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
707         { 12,180,106, 79, 26, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
708         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
709         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
710         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
711         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
712         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
713         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
714         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
715         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
716         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
717         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
718         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
719         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
720         { 25, 25,109, 85, 26,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
721         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
722         { 27, 25,117, 85, 26, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
723         { 28,180,114, 79, 26, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
724         { 29,180,122, 79, 26, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
725         { 30, 25,125, 85, 26, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
726 };
727
728 kc_item kc_mouse[NUM_OTHER_CONTROLS] = {
729         {  0, 25, 46, 85, 26, 12,  1, 24,  5,"Fire primary", BT_MOUSE_BUTTON, 255 },
730         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_MOUSE_BUTTON, 255 },
731         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_MOUSE_BUTTON, 255 },
732         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_MOUSE_BUTTON, 255 },
733         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_MOUSE_BUTTON, 255 },
734         {  5,180, 46, 59, 26, 24,  6,  0,  1,"Slide on", BT_MOUSE_BUTTON, 255 },
735         {  6,180, 54, 59, 26,  5,  7,  1,  4,"Slide left", BT_MOUSE_BUTTON, 255 },
736         {  7,180, 62, 59, 26,  6,  8,  4, 26,"Slide right", BT_MOUSE_BUTTON, 255 },
737         {  8,180, 70, 59, 26,  7,  9, 26,  9,"Slide up", BT_MOUSE_BUTTON, 255 },
738         {  9,180, 78, 59, 26,  8, 10,  8,  2,"Slide down", BT_MOUSE_BUTTON, 255 },
739         { 10,180, 90, 59, 26,  9, 11,  2,  3,"Bank on", BT_MOUSE_BUTTON, 255 },
740         { 11,180, 98, 59, 26, 10, 12,  3, 12,"Bank left", BT_MOUSE_BUTTON, 255 },
741         { 12,180,106, 59, 26, 11,  0, 11, 25,"Bank right", BT_MOUSE_BUTTON, 255 },
742         { 13,103,138, 58, 26, 27, 15, 25, 14,"Pitch U/D", BT_MOUSE_AXIS, 255 },
743         { 14,103,138,106,  8, 23, 16, 13, 15,"Pitch U/D", BT_INVERT, 255 },
744         { 15,103,146, 58, 26, 13, 17, 14, 16,"Turn L/R", BT_MOUSE_AXIS, 255 },
745         { 16,103,146,106,  8, 14, 18, 15, 17,"Turn L/R", BT_INVERT, 255 },
746         { 17,103,154, 58, 26, 15, 19, 16, 18,"Slide L/R", BT_MOUSE_AXIS, 255 },
747         { 18,103,154,106,  8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255 },
748         { 19,103,162, 58, 26, 17, 21, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255 },
749         { 20,103,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
750         { 21,103,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_MOUSE_AXIS, 255 },
751         { 22,103,170,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
752         { 23,103,182, 58, 26, 21, 14, 22, 24,"throttle", BT_MOUSE_AXIS, 255 },
753         { 24,103,182,106,  8, 22,  5, 23,  0,"throttle", BT_INVERT, 255 },
754         { 25, 25,109, 85, 26,  3, 27, 12, 13,"REAR VIEW", BT_MOUSE_BUTTON, 255 },
755         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_MOUSE_BUTTON, 255 },
756         { 27, 25,117, 85, 26, 25, 13, 25, 13,"Afterburner", BT_MOUSE_BUTTON, 255 },
757 };
758
759 #ifdef D2X_KEYS
760 //added on 2/4/99 by Victor Rachels to add d1x new keys
761 kc_item kc_d2x[NUM_D2X_CONTROLS] = {
762 //        id,x,y,w1,w2,u,d,l,r,text_num1,type,value
763         {  0, 15, 49, 71, 26, 27,  2, 27,  1, "WEAPON 1", BT_KEY, 255},
764         {  1, 15, 49,100, 26, 26,  3,  0,  2, "WEAPON 1", BT_JOY_BUTTON, 255},
765         {  2, 15, 57, 71, 26,  0,  4,  1,  3, "WEAPON 2", BT_KEY, 255},
766         {  3, 15, 57,100, 26,  1,  5,  2,  4, "WEAPON 2", BT_JOY_BUTTON, 255},
767         {  4, 15, 65, 71, 26,  2,  6,  3,  5, "WEAPON 3", BT_KEY, 255},
768         {  5, 15, 65,100, 26,  3,  7,  4,  6, "WEAPON 3", BT_JOY_BUTTON, 255},
769         {  6, 15, 73, 71, 26,  4,  8,  5,  7, "WEAPON 4", BT_KEY, 255},
770         {  7, 15, 73,100, 26,  5,  9,  6,  8, "WEAPON 4", BT_JOY_BUTTON, 255},
771         {  8, 15, 81, 71, 26,  6, 10,  7,  9, "WEAPON 5", BT_KEY, 255},
772         {  9, 15, 81,100, 26,  7, 11,  8, 10, "WEAPON 5", BT_JOY_BUTTON, 255},
773
774         { 10, 15, 89, 71, 26,  8, 12,  9, 11, "WEAPON 6", BT_KEY, 255},
775         { 11, 15, 89,100, 26,  9, 13, 10, 12, "WEAPON 6", BT_JOY_BUTTON, 255},
776         { 12, 15, 97, 71, 26, 10, 14, 11, 13, "WEAPON 7", BT_KEY, 255},
777         { 13, 15, 97,100, 26, 11, 15, 12, 14, "WEAPON 7", BT_JOY_BUTTON, 255},
778         { 14, 15,105, 71, 26, 12, 16, 13, 15, "WEAPON 8", BT_KEY, 255},
779         { 15, 15,105,100, 26, 13, 17, 14, 16, "WEAPON 8", BT_JOY_BUTTON, 255},
780         { 16, 15,113, 71, 26, 14, 18, 15, 17, "WEAPON 9", BT_KEY, 255},
781         { 17, 15,113,100, 26, 15, 19, 16, 18, "WEAPON 9", BT_JOY_BUTTON, 255},
782         { 18, 15,121, 71, 26, 16, 20, 17, 19, "WEAPON 0", BT_KEY, 255},
783         { 19, 15,121,100, 26, 17, 21, 18, 20, "WEAPON 0", BT_JOY_BUTTON, 255},
784
785         //{ 20, 15,131, 71, 26, 18, 22, 19, 21, "CYC PRIMARY", BT_KEY, 255},
786         //{ 21, 15,131,100, 26, 19, 23, 20, 22, "CYC PRIMARY", BT_JOY_BUTTON, 255},
787         //{ 22, 15,139, 71, 26, 20, 24, 21, 23, "CYC SECONDARY", BT_KEY, 255},
788         //{ 23, 15,139,100, 26, 21, 25, 22, 24, "CYC SECONDARY", BT_JOY_BUTTON, 255},
789         //{ 24,  8,147, 78, 26, 22, 26, 23, 25, "TOGGLE_PRIM AUTO", BT_KEY, 255},
790         //{ 25,  8,147,107, 26, 23, 27, 24, 26, "TOGGLE_PRIM_AUTO", BT_JOY_BUTTON, 255},
791         //{ 26,  8,155, 78, 26, 24,  1, 25, 27, "TOGGLE SEC AUTO", BT_KEY, 255},
792         //{ 27,  8,155,107, 26, 25,  0, 26,  0, "TOGGLE SEC AUTO", BT_JOY_BUTTON, 255},
793 };
794 //end this section addition - VR
795 #endif
796
797 #else           // ifndef MACINTOSH (following are macintosh controls)
798
799 ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {
800 {0x5b,0x7e,0x54,0x7d,0x56,0x7b,0x58,0x7c,0x3a,0xff,0xff,0x53,0xff,0x55,0xff,0x4e,0xff,0x45,0xff,0xff,0xc,0x59,0xe,0x5c,0x3b,0x24,0x31,0xff,0x3,0xff,0x3f,0xff,0x6,0xff,0xb,0xff,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x30,0xff,0x1,0xff,0x2b,0xff,0x2f,0xff,0x4,0xff,0x11,0xff,0xff,0xff,0x0,0x0},
801 {0x0,0x1,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
802 {0x0,0x3,0xff,0xff,0xff,0xff,0xb,0xc,0x9,0xa,0xff,0x1,0x2,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0},
803 {0x5,0x4,0xff,0xff,0x6,0xff,0x3,0x2,0x0,0x1,0xff,0x8,0xa,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x3,0x1,0xb,0x7,0xd,0xe,0xf,0xc,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
804 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
805 {0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0},
806 {0x0,0x1,0xff,0xff,0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0},
807 };
808
809 ubyte default_firebird_settings[MAX_CONTROLS] =
810 {0x0,0x1,0xff,0xff,0x2,0xff,0x4,0x6,0x5,0x7,0xff,0xb,0xc,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x03,0x0,0xff,0x3,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0};
811
812 ubyte default_mousestick_settings[MAX_CONTROLS] =
813 {0x2,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3,0x4,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0};
814
815 kc_item kc_keyboard[NUM_KEY_CONTROLS] = {
816         {  0, 15, 49, 71, 26, 55,  2, 55,  1,"Pitch forward", BT_KEY, 255 },
817         {  1, 15, 49,100, 26, 50,  3,  0, 24,"Pitch forward", BT_KEY, 255 },
818         {  2, 15, 57, 71, 26,  0,  4, 25,  3,"Pitch backward", BT_KEY, 255 },
819         {  3, 15, 57,100, 26,  1,  5,  2, 26,"Pitch backward", BT_KEY, 255 },
820         {  4, 15, 65, 71, 26,  2,  6, 27,  5,"Turn left", BT_KEY, 255 },
821         {  5, 15, 65,100, 26,  3,  7,  4, 28,"Turn left", BT_KEY, 255 },
822         {  6, 15, 73, 71, 26,  4,  8, 29,  7,"Turn right", BT_KEY, 255 },
823         {  7, 15, 73,100, 26,  5,  9,  6, 34,"Turn right", BT_KEY, 255 },
824         {  8, 15, 85, 71, 26,  6, 10, 35,  9,"Slide on", BT_KEY, 255 },
825         {  9, 15, 85,100, 26,  7, 11,  8, 36,"Slide on", BT_KEY, 255 },
826         { 10, 15, 93, 71, 26,  8, 12, 37, 11,"Slide left", BT_KEY, 255 },
827         { 11, 15, 93,100, 26,  9, 13, 10, 44,"Slide left", BT_KEY, 255 },
828         { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 },
829         { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 },
830         { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 },
831         { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 },
832         { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 },
833         { 17, 15,117,100, 26, 15, 19, 16, 46,"Slide down", BT_KEY, 255 },
834         { 18, 15,129, 71, 26, 16, 20, 47, 19,"Bank on", BT_KEY, 255 },
835         { 19, 15,129,100, 26, 17, 21, 18, 38,"Bank on", BT_KEY, 255 },
836         { 20, 15,137, 71, 26, 18, 22, 39, 21,"Bank left", BT_KEY, 255 },
837         { 21, 15,137,100, 26, 19, 23, 20, 40,"Bank left", BT_KEY, 255 },
838         { 22, 15,145, 71, 26, 20, 48, 41, 23,"Bank right", BT_KEY, 255 },
839         { 23, 15,145,100, 26, 21, 49, 22, 42,"Bank right", BT_KEY, 255 },
840         { 24,158, 49, 83, 26, 51, 26,  1, 25,"Fire primary", BT_KEY, 255 },
841         { 25,158, 49,112, 26, 54, 27, 24,  2,"Fire primary", BT_KEY, 255 },
842         { 26,158, 57, 83, 26, 24, 28,  3, 27,"Fire secondary", BT_KEY, 255 },
843         { 27,158, 57,112, 26, 25, 29, 26,  4,"Fire secondary", BT_KEY, 255 },
844         { 28,158, 65, 83, 26, 26, 34,  5, 29,"Fire flare", BT_KEY, 255 },
845         { 29,158, 65,112, 26, 27, 35, 28,  6,"Fire flare", BT_KEY, 255 },
846         { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 },
847         { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 },
848         { 32,158,113, 83, 26, 30, 46, 15, 33,"reverse", BT_KEY, 255 },
849         { 33,158,113,112, 26, 31, 47, 32, 16,"reverse", BT_KEY, 255 },
850         { 34,158, 73, 83, 26, 28, 36,  7, 35,"Drop Bomb", BT_KEY, 255 },
851         { 35,158, 73,112, 26, 29, 37, 34,  8,"Drop Bomb", BT_KEY, 255 },
852         { 36,158, 85, 83, 26, 34, 44,  9, 37,"REAR VIEW", BT_KEY, 255 },
853         { 37,158, 85,112, 26, 35, 45, 36, 10,"REAR VIEW", BT_KEY, 255 },
854         { 38,158,133, 83, 26, 46, 40, 19, 39,"Cruise Faster", BT_KEY, 255 },
855         { 39,158,133,112, 26, 47, 41, 38, 20,"Cruise Faster", BT_KEY, 255 },
856         { 40,158,141, 83, 26, 38, 42, 21, 41,"Cruise Slower", BT_KEY, 255 },
857         { 41,158,141,112, 26, 39, 43, 40, 22,"Cruise Slower", BT_KEY, 255 },
858         { 42,158,149, 83, 26, 40, 52, 23, 43,"Cruise Off", BT_KEY, 255 },
859         { 43,158,149,112, 26, 41, 53, 42, 48,"Cruise Off", BT_KEY, 255 },
860         { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 },
861         { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 },
862         { 46,158,121, 83, 26, 32, 38, 17, 47,"Afterburner", BT_KEY, 255 },
863         { 47,158,121,112, 26, 33, 39, 46, 18,"Afterburner", BT_KEY, 255 },
864         { 48, 15,161, 71, 26, 22, 50, 43, 49,"Cycle Primary", BT_KEY, 255 },
865         { 49, 15,161,100, 26, 23, 51, 48, 52,"Cycle Primary", BT_KEY, 255 },
866         { 50, 15,169, 71, 26, 48,  1, 53, 51,"Cycle Second", BT_KEY, 255 },
867         { 51, 15,169,100, 26, 49, 24, 50, 54,"Cycle Second", BT_KEY, 255 },
868         { 52,158,163, 83, 26, 42, 54, 49, 53,"Headlight", BT_KEY, 255 },
869         { 53,158,163,112, 26, 43, 55, 52, 50,"Headlight", BT_KEY, 255 },
870         { 54,158,171, 83, 26, 52, 25, 51, 55,"Energy->Shield", BT_KEY, 255 },
871         { 55,158,171,112, 26, 53,  0, 54,  0,"Energy->Shield", BT_KEY, 255 },
872 };
873 kc_item kc_joystick[NUM_OTHER_CONTROLS] = {
874         {  0, 25, 46, 85, 28, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
875         {  1, 25, 54, 85, 28,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
876         {  2, 25, 85, 85, 28, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
877         {  3, 25, 93, 85, 28,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
878         {  4, 25, 62, 85, 28,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
879         {  5,180, 46, 79, 28, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
880         {  6,180, 54, 79, 28,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
881         {  7,180, 62, 79, 28,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
882         {  8,180, 70, 79, 28,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
883         {  9,180, 78, 79, 28,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
884         { 10,180, 90, 79, 28,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
885         { 11,180, 98, 79, 28, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
886         { 12,180,106, 79, 28, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
887         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
888         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
889         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
890         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
891         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
892         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
893         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
894         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
895         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
896         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
897         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
898         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
899         { 25, 25,109, 85, 28,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
900         { 26, 25, 70, 85, 28,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
901         { 27, 25,117, 85, 28, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
902         { 28,180,114, 79, 28, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
903         { 29,180,122, 79, 28, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
904         { 30, 25,125, 85, 28, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
905 };
906 kc_item kc_superjoy[NUM_OTHER_CONTROLS] = {
907         {  0, 25, 46, 85, 26, 15,  1, 24,  5,"Fire primary", BT_JOY_BUTTON, 255 },
908         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_JOY_BUTTON, 255 },
909         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_JOY_BUTTON, 255 },
910         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_JOY_BUTTON, 255 },
911         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_JOY_BUTTON, 255 },
912         {  5,180, 46, 79, 26, 23,  6,  0,  1,"Slide on", BT_JOY_BUTTON, 255 },
913         {  6,180, 54, 79, 26,  5,  7,  1,  4,"Slide left", BT_JOY_BUTTON, 255 },
914         {  7,180, 62, 79, 26,  6,  8,  4, 26,"Slide right", BT_JOY_BUTTON, 255 },
915         {  8,180, 70, 79, 26,  7,  9, 26,  9,"Slide up", BT_JOY_BUTTON, 255 },
916         {  9,180, 78, 79, 26,  8, 10,  8,  2,"Slide down", BT_JOY_BUTTON, 255 },
917         { 10,180, 90, 79, 26,  9, 11,  2,  3,"Bank on", BT_JOY_BUTTON, 255 },
918         { 11,180, 98, 79, 26, 10, 12,  3, 12,"Bank left", BT_JOY_BUTTON, 255 },
919         { 12,180,106, 79, 26, 11, 28, 11, 25,"Bank right", BT_JOY_BUTTON, 255 },
920         { 13, 22,154, 51, 26, 24, 15, 30, 14,"Pitch U/D", BT_JOY_AXIS, 255 },
921         { 14, 22,154, 99,  8, 30, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 },
922         { 15, 22,162, 51, 26, 13,  0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 },
923         { 16, 22,162, 99,  8, 14, 17, 15, 19,"Turn L/R", BT_INVERT, 255 },
924         { 17,164,154, 58, 26, 16, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 },
925         { 18,164,154,106,  8, 29, 20, 17, 15,"Slide L/R", BT_INVERT, 255 },
926         { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 },
927         { 20,164,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
928         { 21,164,172, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 },
929         { 22,164,172,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
930         { 23,164,180, 58, 26, 21,  5, 22, 24,"throttle", BT_JOY_AXIS, 255 },
931         { 24,164,180,106,  8, 22, 13, 23,  0,"throttle", BT_INVERT, 255 },
932         { 25, 25,109, 85, 26,  3, 27, 12, 28,"REAR VIEW", BT_JOY_BUTTON, 255 },
933         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_JOY_BUTTON, 255 },
934         { 27, 25,117, 85, 26, 25, 30, 28, 29,"Afterburner", BT_JOY_BUTTON, 255 },
935         { 28,180,114, 79, 26, 12, 29, 25, 27,"Cycle Primary", BT_JOY_BUTTON, 255 },
936         { 29,180,122, 79, 26, 28, 18, 27, 30,"Cycle Secondary", BT_JOY_BUTTON, 255 },
937         { 30, 25,125, 85, 26, 27, 14, 29, 13,"Headlight", BT_JOY_BUTTON, 255 },
938 };
939
940 kc_item kc_mouse[NUM_OTHER_CONTROLS] = {
941         {  0, 25, 46, 85, 26, 28,  1, 28,  5,"Fire primary", BT_MOUSE_BUTTON, 255 },
942         {  1, 25, 54, 85, 26,  0,  4,  5,  6,"Fire secondary", BT_MOUSE_BUTTON, 255 },
943         {  2, 25, 85, 85, 26, 26,  3,  9, 10,"Accelerate", BT_MOUSE_BUTTON, 255 },
944         {  3, 25, 93, 85, 26,  2, 25, 10, 11,"reverse", BT_MOUSE_BUTTON, 255 },
945         {  4, 25, 62, 85, 26,  1, 26,  6,  7,"Fire flare", BT_MOUSE_BUTTON, 255 },
946         {  5,180, 46, 59, 26, 24,  6,  0,  1,"Slide on", BT_MOUSE_BUTTON, 255 },
947         {  6,180, 54, 59, 26,  5,  7,  1,  4,"Slide left", BT_MOUSE_BUTTON, 255 },
948         {  7,180, 62, 59, 26,  6,  8,  4, 26,"Slide right", BT_MOUSE_BUTTON, 255 },
949         {  8,180, 70, 59, 26,  7,  9, 26,  9,"Slide up", BT_MOUSE_BUTTON, 255 },
950         {  9,180, 78, 59, 26,  8, 10,  8,  2,"Slide down", BT_MOUSE_BUTTON, 255 },
951         { 10,180, 90, 59, 26,  9, 11,  2,  3,"Bank on", BT_MOUSE_BUTTON, 255 },
952         { 11,180, 98, 59, 26, 10, 12,  3, 12,"Bank left", BT_MOUSE_BUTTON, 255 },
953         { 12,180,106, 59, 26, 11, 28, 11, 25,"Bank right", BT_MOUSE_BUTTON, 255 },
954         { 13,103,138, 58, 26, 27, 15, 27, 14,"Pitch U/D", BT_MOUSE_AXIS, 255 },
955         { 14,103,138,106,  8, 23, 16, 13, 15,"Pitch U/D", BT_INVERT, 255 },
956         { 15,103,146, 58, 26, 13, 17, 14, 16,"Turn L/R", BT_MOUSE_AXIS, 255 },
957         { 16,103,146,106,  8, 14, 18, 15, 17,"Turn L/R", BT_INVERT, 255 },
958         { 17,103,154, 58, 26, 15, 19, 16, 18,"Slide L/R", BT_MOUSE_AXIS, 255 },
959         { 18,103,154,106,  8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255 },
960         { 19,103,162, 58, 26, 17, 21, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255 },
961         { 20,103,162,106,  8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 },
962         { 21,103,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_MOUSE_AXIS, 255 },
963         { 22,103,170,106,  8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 },
964         { 23,103,182, 58, 26, 21, 14, 22, 24,"throttle", BT_MOUSE_AXIS, 255 },
965         { 24,103,182,106,  8, 22,  5, 23, 28,"throttle", BT_INVERT, 255 },
966         { 25, 25,109, 85, 26,  3, 27, 12, 27,"REAR VIEW", BT_MOUSE_BUTTON, 255 },
967         { 26, 25, 70, 85, 26,  4,  2,  7,  8,"Drop Bomb", BT_MOUSE_BUTTON, 255 },
968         { 27, 25,117, 85, 26, 25, 13, 25, 13,"Afterburner", BT_MOUSE_BUTTON, 255 },
969 };
970
971 #endif
972
973 //added on 2/4/99 by Victor Rachels to add new keys system
974 ubyte default_kconfig_d2x_settings[MAX_D2X_CONTROLS] = {
975  0x2 ,0xff,0x3 ,0xff,0x4 ,0xff,0x5 ,0xff,0x6 ,0xff,0x7 ,0xff,0x8 ,0xff,0x9 ,
976  0xff,0xa ,0xff,0xb ,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
977  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff };
978 //end this section addition - VR
979
980 void kc_drawitem( kc_item *item, int is_current );
981 void kc_change_key( kc_item * item );
982 void kc_change_joybutton( kc_item * item );
983 void kc_change_mousebutton( kc_item * item );
984 void kc_change_joyaxis( kc_item * item );
985 void kc_change_mouseaxis( kc_item * item );
986 void kc_change_invert( kc_item * item );
987 void kconfig_read_fcs( int raw_axis );
988 void kconfig_set_fcs_button( int btn, int button );
989 void kconfig_read_external_controls( void );
990
991 int kconfig_is_axes_used(int axis)
992 {
993         int i;
994         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
995                 if (( kc_joystick[i].type == BT_JOY_AXIS ) && (kc_joystick[i].value == axis ))
996                         return 1;
997         }
998         return 0;
999 }
1000
1001 #ifdef TABLE_CREATION
1002 int find_item_at( kc_item * items, int nitems, int x, int y )
1003 {
1004         int i;
1005         
1006         for (i=0; i<nitems; i++ )       {
1007                 if ( ((items[i].x+items[i].w1)==x) && (items[i].y==y))
1008                         return i;
1009         }
1010         return -1;
1011 }
1012
1013 int find_next_item_up( kc_item * items, int nitems, int citem )
1014 {
1015         int x, y, i;
1016
1017         y = items[citem].y;
1018         x = items[citem].x+items[citem].w1;
1019         
1020         do {    
1021                 y--;
1022                 if ( y < 0 ) {
1023                         y = grd_curcanv->cv_bitmap.bm_h-1;
1024                         x--;
1025                         if ( x < 0 ) {
1026                                 x = grd_curcanv->cv_bitmap.bm_w-1;
1027                         }
1028                 }
1029                 i = find_item_at( items, nitems, x, y );
1030         } while ( i < 0 );
1031         
1032         return i;
1033 }
1034
1035 int find_next_item_down( kc_item * items, int nitems, int citem )
1036 {
1037         int x, y, i;
1038
1039         y = items[citem].y;
1040         x = items[citem].x+items[citem].w1;
1041         
1042         do {    
1043                 y++;
1044                 if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
1045                         y = 0;
1046                         x++;
1047                         if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
1048                                 x = 0;
1049                         }
1050                 }
1051                 i = find_item_at( items, nitems, x, y );
1052         } while ( i < 0 );
1053         
1054         return i;
1055 }
1056
1057 int find_next_item_right( kc_item * items, int nitems, int citem )
1058 {
1059         int x, y, i;
1060
1061         y = items[citem].y;
1062         x = items[citem].x+items[citem].w1;
1063         
1064         do {    
1065                 x++;
1066                 if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
1067                         x = 0;
1068                         y++;
1069                         if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
1070                                 y = 0;
1071                         }
1072                 }
1073                 i = find_item_at( items, nitems, x, y );
1074         } while ( i < 0 );
1075         
1076         return i;
1077 }
1078
1079 int find_next_item_left( kc_item * items, int nitems, int citem )
1080 {
1081         int x, y, i;
1082
1083         y = items[citem].y;
1084         x = items[citem].x+items[citem].w1;
1085         
1086         do {    
1087                 x--;
1088                 if ( x < 0 ) {
1089                         x = grd_curcanv->cv_bitmap.bm_w-1;
1090                         y--;
1091                         if ( y < 0 ) {
1092                                 y = grd_curcanv->cv_bitmap.bm_h-1;
1093                         }
1094                 }
1095                 i = find_item_at( items, nitems, x, y );
1096         } while ( i < 0 );
1097         
1098         return i;
1099 }
1100 #endif
1101
1102 #ifdef NEWMENU_MOUSE
1103 int get_item_height(kc_item *item)
1104 {
1105         int w, h, aw;
1106         char btext[10];
1107
1108         if (item->value==255) {
1109                 strcpy(btext, "");
1110         } else {
1111                 switch( item->type )    {
1112                         case BT_KEY:
1113                                 strncpy( btext, key_text[item->value], 10 ); break;
1114                         case BT_MOUSE_BUTTON:
1115 #ifndef MACINTOSH
1116                                 strncpy( btext, Text_string[mousebutton_text[item->value]], 10); break;
1117 #else
1118                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
1119 #endif
1120                         case BT_MOUSE_AXIS:
1121                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
1122                         case BT_JOY_BUTTON:
1123                                 if ( joybutton_text[item->value] !=-1 )
1124                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1125                                 else
1126                                         sprintf( btext, "BTN%d", item->value );
1127                                 break;
1128                         case BT_JOY_AXIS:
1129                                 strncpy( btext, Text_string[joyaxis_text[item->value]], 10 ); break;
1130                         case BT_INVERT:
1131                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
1132                 }
1133         }
1134         gr_get_string_size(btext, &w, &h, &aw  );
1135
1136         return h;
1137 }
1138 #endif
1139
1140 void kconfig_sub(kc_item * items,int nitems, char * title)
1141 {
1142 WINDOS(
1143         dd_grs_canvas * save_canvas,
1144         grs_canvas * save_canvas
1145 );
1146         grs_font * save_font;
1147         int old_keyd_repeat;
1148 #ifdef NEWMENU_MOUSE
1149         int mouse_state, omouse_state, mx, my, x1, x2, y1, y2;
1150         int close_x, close_y, close_size;
1151 #endif
1152
1153         int i,k,ocitem,citem;
1154         int time_stopped = 0;
1155 WIN(char *old_bg_pcx);
1156
1157 WIN(old_bg_pcx = _SCRContext.bkg_filename);
1158 WIN(DEFINE_SCREEN(NULL));
1159
1160         All_items = items;
1161         Num_items = nitems;
1162
1163         if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
1164         {
1165                 time_stopped = 1;
1166                 stop_time();
1167         }
1168
1169 //      if (Config_control_type == CONTROL_WINJOYSTICK) {
1170 //              WINDOS(
1171 //                      joydefsw_win_joyselect(title2); title = title2,
1172 //                      Int3()
1173 //              );                                                                                              // Get Samir...
1174 //      }
1175
1176 WINDOS(
1177         save_canvas = dd_grd_curcanv,
1178         save_canvas = grd_curcanv
1179 );
1180
1181
1182 WINDOS(
1183         dd_gr_set_current_canvas(NULL),
1184         gr_set_current_canvas(NULL)
1185 );              
1186         save_font = grd_curcanv->cv_font;
1187
1188 #ifdef WINDOWS
1189 KConfigPaint:
1190 #endif
1191         game_flush_inputs();
1192         old_keyd_repeat = keyd_repeat;
1193         keyd_repeat = 1;
1194
1195         //gr_clear_canvas( BM_XRGB(0,0,0) );
1196
1197         nm_draw_background(0, 0, grd_curcanv->cv_bitmap.bm_w - 1, grd_curcanv->cv_bitmap.bm_h - 1);
1198    gr_palette_load (gr_palette);
1199
1200         grd_curcanv->cv_font = MEDIUM3_FONT;
1201
1202 WIN(DDGRLOCK(dd_grd_curcanv));  
1203         {
1204                 char * p;
1205                 p = strchr( title, '\n' );
1206                 if ( p ) *p = 32;
1207                 gr_string( 0x8000, LHY(8), title );
1208                 if ( p ) *p = '\n';
1209         }
1210
1211
1212 //      if ( items == kc_keyboard )     {
1213 //              gr_string( 0x8000, 8, "Keyboard" );
1214 //      } else if ( items == kc_joystick )      {
1215 //              gr_string( 0x8000, 8, "Joysticks" );
1216 //      } else if ( items == kc_mouse ) {
1217 //              gr_string( 0x8000, 8, "Mouse" );
1218 //      }
1219
1220 #ifdef NEWMENU_MOUSE
1221         close_x = close_y = MenuHires?15:7;
1222         close_size = MenuHires?10:5;
1223         gr_setcolor( BM_XRGB(0, 0, 0) );
1224         gr_rect(close_x, close_y, close_x + close_size, close_y + close_size);
1225         gr_setcolor( BM_XRGB(21, 21, 21) );
1226         gr_rect(close_x + LHX(1), close_y + LHX(1), close_x + close_size - LHX(1), close_y + close_size - LHX(1));
1227 #endif
1228
1229         grd_curcanv->cv_font = GAME_FONT;
1230         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1231
1232         #ifndef MACINTOSH
1233         gr_string( 0x8000, LHY(20), TXT_KCONFIG_STRING_1 );
1234         #else
1235         gr_string( 0x8000, LHY(20), "Enter changes, ctrl-d deletes, ctrl-r resets defaults, ESC exits");
1236         #endif
1237         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1238         if ( items == kc_keyboard )     {
1239                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1240                 gr_setcolor( BM_XRGB(31,27,6) );
1241                 
1242                 gr_scanline( LHX(98), LHX(106), LHY(42) );
1243                 gr_scanline( LHX(120), LHX(128), LHY(42) );
1244                 gr_pixel( LHX(98), LHY(43) );                                           
1245                 gr_pixel( LHX(98), LHY(44) );                                           
1246                 gr_pixel( LHX(128), LHY(43) );                                          
1247                 gr_pixel( LHX(128), LHY(44) );                                          
1248                 
1249                 gr_string( LHX(109), LHY(40), "OR" );
1250
1251                 gr_scanline( LHX(253), LHX(261), LHY(42) );
1252                 gr_scanline( LHX(274), LHX(283), LHY(42) );
1253                 gr_pixel( LHX(253), LHY(43) );                                          
1254                 gr_pixel( LHX(253), LHY(44) );                                          
1255                 gr_pixel( LHX(283), LHY(43) );                                          
1256                 gr_pixel( LHX(283), LHY(44) );                                          
1257
1258                 gr_string( LHX(264), LHY(40), "OR" );
1259
1260         } if ( items == kc_joystick )   {
1261                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1262                 gr_setcolor( BM_XRGB(31,27,6) );
1263                 gr_scanline( LHX(18), LHX(135), LHY(37) );
1264                 gr_scanline( LHX(181), LHX(294), LHY(37) );
1265                 gr_scanline( LHX(18), LHX(144), LHY(119+18) );
1266                 gr_scanline( LHX(174), LHX(294), LHY(119+18) );
1267                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1268                 gr_string( 0x8000,LHY(117+18), TXT_AXES );
1269                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1270                 gr_string( LHX(81), LHY(137+8), TXT_AXIS );
1271                 gr_string( LHX(111), LHY(137+8), TXT_INVERT );
1272                 gr_string( LHX(222), LHY(137+8), TXT_AXIS );
1273                 gr_string( LHX(252), LHY(137+8), TXT_INVERT );
1274         } else if ( items == kc_mouse ) {
1275                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1276                 gr_setcolor( BM_XRGB(31,27,6) );
1277                 gr_scanline( LHX(18), LHX(135), LHY(37) );
1278                 gr_scanline( LHX(181), LHX(294), LHY(37) );
1279                 gr_scanline( LHX(18), LHX(144), LHY(119+5) );
1280                 gr_scanline( LHX(174), LHX(294), LHY(119+5) );
1281                 gr_string( 0x8000, LHY(35), TXT_BUTTONS );
1282                 gr_string( 0x8000,LHY(117+5), TXT_AXES );
1283                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1284                 gr_string( LHX(169), LHY(129), TXT_AXIS );
1285                 gr_string( LHX(199), LHY(129), TXT_INVERT );
1286         }
1287 #ifdef D2X_KEYS
1288         else if ( items == kc_d2x )
1289         {
1290                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
1291                 gr_setcolor( BM_XRGB(31,27,6) );
1292
1293                 gr_string(LHX( 94), LHY(40), "KB");
1294                 gr_string(LHX(121), LHY(40), "JOY");
1295         }
1296 #endif
1297
1298 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1299
1300         for (i=0; i<nitems; i++ )       {
1301                 kc_drawitem( &items[i], 0 );
1302         }
1303
1304         citem = 0;
1305         kc_drawitem( &items[citem], 1 );
1306
1307         newmenu_show_cursor();
1308
1309 #ifdef NEWMENU_MOUSE
1310         mouse_state = omouse_state = 0;
1311 #endif
1312
1313         while(1)                {
1314         //      Windows addendum to allow for kconfig input.
1315         #ifdef WINDOWS
1316                 {
1317                         MSG msg;
1318
1319                         DoMessageStuff(&msg);
1320
1321                         if (_RedrawScreen) {
1322                                 _RedrawScreen = FALSE;
1323
1324                                 dd_gr_set_current_canvas(NULL); 
1325
1326                                 goto KConfigPaint;
1327                         }
1328
1329                         DDGRRESTORE;
1330                 }
1331         #endif
1332                 gr_update();
1333
1334                 //see if redbook song needs to be restarted
1335                 songs_check_redbook_repeat();
1336
1337                 k = key_inkey();
1338
1339 #ifdef NEWMENU_MOUSE
1340                 omouse_state = mouse_state;
1341                 mouse_state = mouse_button_state(0);
1342 #endif
1343
1344                 if ( !time_stopped ) {
1345                         #ifdef NETWORK
1346                         if (multi_menu_poll() == -1)
1347                                 k = -2;
1348                         #endif
1349                 }
1350                 ocitem = citem;
1351                 switch( k )     {
1352                 case KEY_BACKSP:
1353                         Int3();
1354                         break;
1355                 MAC(case KEY_COMMAND+KEY_SHIFTED+KEY_3:)
1356                 case KEY_PRINT_SCREEN:
1357                         save_screen_shot(0);
1358                         break;                                                  
1359                 case KEY_CTRLED+KEY_D:
1360                         items[citem].value = 255;
1361                         kc_drawitem( &items[citem], 1 );
1362                         break;
1363                 case KEY_CTRLED+KEY_R:  
1364                         if ( items==kc_keyboard )       {
1365                                 for (i=0; i<NUM_KEY_CONTROLS; i++ )             {
1366                                         items[i].value=default_kconfig_settings[0][i];
1367                                         kc_drawitem( &items[i], 0 );
1368                                 }
1369 #ifdef D2X_KEYS
1370                         } else if ( items==kc_d2x ) {
1371                                 for(i=0;i<NUM_D2X_CONTROLS;i++)
1372                                 {
1373                                         items[i].value=default_kconfig_d2x_settings[i];
1374                                         kc_drawitem( &items[i], 0 );
1375                                 }
1376 #endif
1377                         } else {
1378                                 #ifdef MACINTOSH
1379                           // hack for firebire and mousestick default controls since I made
1380                           // them the same control type -- dumb dumb dumb
1381                                 if (joy_have_firebird())
1382                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1383                                                 items[i].value = default_firebird_settings[i];
1384                                                 kc_drawitem( &items[i], 0 );
1385                                         }
1386                                 else if (joy_have_mousestick())
1387                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1388                                                 items[i].value = default_mousestick_settings[i];
1389                                                 kc_drawitem( &items[i], 0 );
1390                                         }
1391                                 else
1392                                 #endif  // note link to above else
1393                                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1394                                                 items[i].value = default_kconfig_settings[Config_control_type][i];
1395                                                 kc_drawitem( &items[i], 0 );
1396                                         }
1397                         }
1398                         kc_drawitem( &items[citem], 1 );
1399                         break;
1400                 case KEY_DELETE:
1401                         items[citem].value=255;
1402                         kc_drawitem( &items[citem], 1 );
1403                         break;
1404                 case KEY_UP:            
1405                 case KEY_PAD8:
1406 #ifdef TABLE_CREATION
1407                         if (items[citem].u==-1) items[citem].u=find_next_item_up( items,nitems, citem);
1408 #endif
1409                         citem = items[citem].u; 
1410                         break;
1411                 
1412                 case KEY_DOWN:  
1413                 case KEY_PAD2:
1414 #ifdef TABLE_CREATION
1415                         if (items[citem].d==-1) items[citem].d=find_next_item_down( items,nitems, citem);
1416 #endif
1417                         citem = items[citem].d; 
1418                         break;
1419                 case KEY_LEFT:  
1420                 case KEY_PAD4:
1421 #ifdef TABLE_CREATION
1422                         if (items[citem].l==-1) items[citem].l=find_next_item_left( items,nitems, citem);
1423 #endif
1424                         citem = items[citem].l; 
1425                         break;
1426                 case KEY_RIGHT:         
1427                 case KEY_PAD6:
1428 #ifdef TABLE_CREATION
1429                         if (items[citem].r==-1) items[citem].r=find_next_item_right( items,nitems, citem);
1430 #endif
1431                         citem = items[citem].r; 
1432                         break;
1433                 case KEY_ENTER: 
1434                 case KEY_PADENTER:      
1435                         switch( items[citem].type )     {
1436                         case BT_KEY:            kc_change_key( &items[citem] ); break;
1437                         case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1438                         case BT_MOUSE_AXIS:     kc_change_mouseaxis( &items[citem] ); break;
1439                         case BT_JOY_BUTTON:     kc_change_joybutton( &items[citem] ); break;
1440                         case BT_JOY_AXIS:       kc_change_joyaxis( &items[citem] ); break;
1441                         case BT_INVERT:         kc_change_invert( &items[citem] ); break;
1442                         }
1443                         break;
1444                 case -2:        
1445                 case KEY_ESC:
1446                         grd_curcanv->cv_font    = save_font;
1447
1448                 WIN(DEFINE_SCREEN(old_bg_pcx));
1449
1450                 WINDOS(
1451                         dd_gr_set_current_canvas(save_canvas),
1452                         gr_set_current_canvas( save_canvas )
1453                 );                      
1454                         keyd_repeat = old_keyd_repeat;
1455                         game_flush_inputs();
1456                         newmenu_hide_cursor();
1457                         if (time_stopped)
1458                                 start_time();
1459                         return;
1460 #ifdef TABLE_CREATION
1461                 case KEY_DEBUGGED+KEY_F12:      {
1462                         FILE * fp;
1463                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1464                                 kc_keyboard[i].u = find_next_item_up( kc_keyboard,NUM_KEY_CONTROLS, i);
1465                                 kc_keyboard[i].d = find_next_item_down( kc_keyboard,NUM_KEY_CONTROLS, i);
1466                                 kc_keyboard[i].l = find_next_item_left( kc_keyboard,NUM_KEY_CONTROLS, i);
1467                                 kc_keyboard[i].r = find_next_item_right( kc_keyboard,NUM_KEY_CONTROLS, i);
1468                         }
1469                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1470                                 kc_joystick[i].u = find_next_item_up( kc_joystick,NUM_OTHER_CONTROLS, i);
1471                                 kc_joystick[i].d = find_next_item_down( kc_joystick,NUM_OTHER_CONTROLS, i);
1472                                 kc_joystick[i].l = find_next_item_left( kc_joystick,NUM_OTHER_CONTROLS, i);
1473                                 kc_joystick[i].r = find_next_item_right( kc_joystick,NUM_OTHER_CONTROLS, i);
1474                         }
1475                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1476                                 kc_mouse[i].u = find_next_item_up( kc_mouse,NUM_OTHER_CONTROLS, i);
1477                                 kc_mouse[i].d = find_next_item_down( kc_mouse,NUM_OTHER_CONTROLS, i);
1478                                 kc_mouse[i].l = find_next_item_left( kc_mouse,NUM_OTHER_CONTROLS, i);
1479                                 kc_mouse[i].r = find_next_item_right( kc_mouse,NUM_OTHER_CONTROLS, i);
1480                         }
1481                         fp = fopen( "kconfig.cod", "wt" );
1482
1483                         fprintf( fp, "ubyte default_kconfig_settings[CONTROL_MAX_TYPES][MAX_CONTROLS] = {\n" );
1484                         for (i=0; i<CONTROL_MAX_TYPES; i++ )    {
1485                                 int j;
1486                                 fprintf( fp, "{0x%x", kconfig_settings[i][0] );
1487                                 for (j=1; j<MAX_CONTROLS; j++ )
1488                                         fprintf( fp, ",0x%x", kconfig_settings[i][j] );
1489                                 fprintf( fp, "},\n" );
1490                         }
1491                         fprintf( fp, "};\n" );
1492                 
1493                         fprintf( fp, "\nkc_item kc_keyboard[NUM_KEY_CONTROLS] = {\n" );
1494                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
1495                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1496                                         kc_keyboard[i].id, kc_keyboard[i].x, kc_keyboard[i].y, kc_keyboard[i].w1, kc_keyboard[i].w2,
1497                                         kc_keyboard[i].u, kc_keyboard[i].d, kc_keyboard[i].l, kc_keyboard[i].r,
1498                                         34, kc_keyboard[i].text, 34, btype_text[kc_keyboard[i].type] );
1499                         }
1500                         fprintf( fp, "};" );
1501
1502                         fprintf( fp, "\nkc_item kc_joystick[NUM_OTHER_CONTROLS] = {\n" );
1503                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1504                                 if (kc_joystick[i].type == BT_JOY_BUTTON)
1505                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1506                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1507                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1508                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1509                 else
1510                                         fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1511                                                 kc_joystick[i].id, kc_joystick[i].x, kc_joystick[i].y, kc_joystick[i].w1, kc_joystick[i].w2,
1512                                                 kc_joystick[i].u, kc_joystick[i].d, kc_joystick[i].l, kc_joystick[i].r,
1513                                                 34, kc_joystick[i].text, 34, btype_text[kc_joystick[i].type] );
1514                         }
1515                         fprintf( fp, "};" );
1516
1517                         fprintf( fp, "\nkc_item kc_mouse[NUM_OTHER_CONTROLS] = {\n" );
1518                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
1519                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
1520                                         kc_mouse[i].id, kc_mouse[i].x, kc_mouse[i].y, kc_mouse[i].w1, kc_mouse[i].w2,
1521                                         kc_mouse[i].u, kc_mouse[i].d, kc_mouse[i].l, kc_mouse[i].r,
1522                                         34, kc_mouse[i].text, 34, btype_text[kc_mouse[i].type] );
1523                         }
1524                         fprintf( fp, "};" );
1525
1526                         fclose(fp);
1527
1528                         }
1529                         break;
1530 #endif
1531                 }
1532
1533 #ifdef NEWMENU_MOUSE
1534                 if ( (mouse_state && !omouse_state) || (mouse_state && omouse_state) ) {
1535                         int item_height;
1536                         
1537                         mouse_get_pos(&mx, &my);
1538                         for (i=0; i<nitems; i++ )       {
1539                                 item_height = get_item_height( &items[i] );
1540                                 x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[i].x) + LHX(items[i].w1);
1541                                 x2 = x1 + LHX(items[i].w2);
1542                                 y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[i].y);
1543                                 y2 = y1 + LHX(item_height);
1544                                 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1545                                         citem = i;
1546                                         break;
1547                                 }
1548                         }
1549                 }
1550                 else if ( !mouse_state && omouse_state ) {
1551                         int item_height;
1552                         
1553                         mouse_get_pos(&mx, &my);
1554                         item_height = get_item_height( &items[citem] );
1555                         x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[citem].x) + LHX(items[citem].w1);
1556                         x2 = x1 + LHX(items[citem].w2);
1557                         y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[citem].y);
1558                         y2 = y1 + LHY(item_height);
1559                         if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
1560                                 newmenu_hide_cursor();
1561                                 switch( items[citem].type )     {
1562                                 case BT_KEY:                            kc_change_key( &items[citem] ); break;
1563                                 case BT_MOUSE_BUTTON:   kc_change_mousebutton( &items[citem] ); break;
1564                                 case BT_MOUSE_AXIS:             kc_change_mouseaxis( &items[citem] ); break;
1565                                 case BT_JOY_BUTTON:             kc_change_joybutton( &items[citem] ); break;
1566                                 case BT_JOY_AXIS:               kc_change_joyaxis( &items[citem] ); break;
1567                                 case BT_INVERT:                         kc_change_invert( &items[citem] ); break;
1568                                 }
1569                                 newmenu_show_cursor();
1570                         } else {
1571                                 x1 = grd_curcanv->cv_bitmap.bm_x + close_x + LHX(1);
1572                                 x2 = x1 + close_size - LHX(1);
1573                                 y1 = grd_curcanv->cv_bitmap.bm_y + close_y + LHX(1);
1574                                 y2 = y1 + close_size - LHX(1);
1575                                 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
1576                                         grd_curcanv->cv_font    = save_font;
1577                                         WINDOS(dd_gr_set_current_canvas( save_canvas ),
1578                                                         gr_set_current_canvas( save_canvas ));
1579                                         keyd_repeat = old_keyd_repeat;
1580                                         game_flush_inputs();
1581                                         newmenu_hide_cursor();
1582                                         if (time_stopped)
1583                                                 start_time();
1584                                         return;
1585                                 }
1586                         }
1587
1588                 }
1589 #endif // NEWMENU_MOUSE
1590
1591                 if (ocitem!=citem)      {
1592                         newmenu_hide_cursor();
1593                         kc_drawitem( &items[ocitem], 0 );
1594                         kc_drawitem( &items[citem], 1 );
1595                         newmenu_show_cursor();
1596                 }
1597         }
1598 }
1599
1600
1601 void kc_drawitem( kc_item *item, int is_current )
1602 {
1603         int x, w, h, aw;
1604         char btext[16];
1605 //      PA_DFX (pa_set_frontbuffer_current());
1606 WIN(DDGRLOCK(dd_grd_curcanv));
1607
1608         if (is_current)
1609                 gr_set_fontcolor( BM_XRGB(20,20,29), -1 );
1610         else
1611                 gr_set_fontcolor( BM_XRGB(15,15,24), -1 );
1612    gr_string( LHX(item->x), LHY(item->y), item->text );
1613 WIN(DDGRUNLOCK(dd_grd_curcanv));
1614
1615         if (item->value==255) {
1616                 strcpy( btext, "" );
1617         } else {
1618                 switch( item->type )    {
1619                         case BT_KEY:
1620                                 strncpy( btext, key_text[item->value], 10 ); break;
1621                         case BT_MOUSE_BUTTON:
1622                                 #ifndef MACINTOSH
1623                                 //strncpy( btext, Text_string[mousebutton_text[item->value]], 10 ); break;
1624                                 strncpy( btext, (item->value <= 3)?Text_string[mousebutton_text[item->value]]:mousebutton_textra[item->value-3], 10 ); break;
1625                                 #else
1626                                 strncpy( btext, mousebutton_text[item->value], 10 ); break;
1627                                 #endif
1628                         case BT_MOUSE_AXIS:
1629                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
1630                         case BT_JOY_BUTTON:
1631 #ifndef MACINTOSH
1632         #ifdef WINDOWS
1633                                 if (joybutton_text[item->value] != -1) 
1634                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1635                                 else 
1636                                         sprintf( btext, "BTN%2d", item->value+1 );
1637         #else   
1638                                 if ( joybutton_text[item->value] !=-1 )
1639                                         strncpy( btext, Text_string[ joybutton_text[item->value]  ], 10 );
1640                                 else
1641                                         sprintf( btext, "BTN%d", item->value );
1642         #endif
1643 #else
1644                                 strncpy( btext, joy_btn_name( item->value ), 10);
1645                                 if (btext == NULL)
1646                                         sprintf( btext, "BTN%d", item->value );
1647 #endif
1648                                 break;
1649                         case BT_JOY_AXIS:
1650                                 strncpy( btext, Text_string[joyaxis_text[item->value]], 10 ); break;
1651                         case BT_INVERT:
1652                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
1653                 }
1654         }
1655         if (item->w1) {
1656         WIN(DDGRLOCK(dd_grd_curcanv));
1657                 gr_get_string_size(btext, &w, &h, &aw  );
1658
1659                 if (is_current)
1660                         gr_setcolor( BM_XRGB(21,0,24) );
1661                 else
1662                         gr_setcolor( BM_XRGB(16,0,19) );
1663                 gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1664                 
1665                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1666
1667                 x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1668         
1669                 gr_string( x, LHY(item->y), btext );
1670 //              PA_DFX (pa_set_backbuffer_current());
1671
1672         WIN(DDGRUNLOCK(dd_grd_curcanv));
1673         }
1674 }
1675
1676
1677 static int looper=0;
1678
1679 void kc_drawquestion( kc_item *item )
1680 {
1681         int c, x, w, h, aw;
1682
1683 WIN(DDGRLOCK(dd_grd_curcanv));  
1684   // PA_DFX (pa_set_frontbuffer_current());
1685
1686         gr_get_string_size("?", &w, &h, &aw  );
1687
1688         c = BM_XRGB(21,0,24);
1689
1690         //@@gr_setcolor( gr_fade_table[fades[looper]*256+c] );
1691         gr_setcolor(BM_XRGB(21*fades[looper]/31,0,24*fades[looper]/31));
1692         looper++;
1693         if (looper>63) looper=0;
1694
1695         gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
1696         
1697         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1698
1699         x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
1700    
1701         gr_string( x, LHY(item->y), "?" );
1702 //      PA_DFX (pa_set_backbuffer_current());
1703 WIN(DDGRUNLOCK(dd_grd_curcanv));
1704 gr_update();
1705 }
1706
1707 void kc_change_key( kc_item * item )
1708 {
1709         int i,n,f,k;
1710         ubyte keycode;
1711
1712 WIN(DDGRLOCK(dd_grd_curcanv));
1713         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1714         
1715         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_KEY );
1716 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1717
1718         game_flush_inputs();
1719         keycode=255;
1720         k=255;
1721         
1722         while( (k!=KEY_ESC) && (keycode==255) ) 
1723         {                               
1724         #ifdef WINDOWS
1725                 {
1726                         MSG msg;
1727
1728                         DoMessageStuff(&msg);
1729                         DDGRRESTORE;
1730                 
1731                 }
1732         #endif
1733
1734                 #ifdef NETWORK
1735                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1736                         multi_menu_poll();
1737                 #endif
1738 //              if ( Game_mode & GM_MULTI )
1739 //                      GameLoop( 0, 0 );                               // Continue
1740                 k = key_inkey();
1741                 timer_delay(f0_1/10);
1742                 kc_drawquestion( item );
1743         
1744                 for (i=0; i<256; i++ )  {
1745                         if (keyd_pressed[i] && (strlen(key_text[i])>0)) {
1746                                 f = 0;
1747                                 for (n=0; n<sizeof(system_keys); n++ )
1748                                         if ( system_keys[n] == i )
1749                                                 f=1;
1750                                 if (!f) 
1751                                         keycode=i;
1752                         }
1753                 }
1754         }
1755
1756         if (k!=KEY_ESC) {
1757                 for (i=0; i<Num_items; i++ )    {
1758                         n = item - All_items;
1759                         if ( (i!=n) && (All_items[i].type==BT_KEY) && (All_items[i].value==keycode) )           {
1760                                 All_items[i].value = 255;
1761                                 kc_drawitem( &All_items[i], 0 );
1762                         }
1763                 }
1764                 item->value = keycode;
1765         }
1766         kc_drawitem( item, 1 );
1767
1768 WIN(DDGRLOCK(dd_grd_curcanv));
1769         gr_set_fontcolor( BM_XRGB(28,28,28), BM_XRGB(0,0,0) );
1770 WIN(DDGRUNLOCK(dd_grd_curcanv));
1771
1772         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1773
1774         game_flush_inputs();
1775
1776 }
1777
1778 void kc_change_joybutton( kc_item * item )
1779 {
1780         int n,i,k;
1781         ubyte code;
1782
1783 WIN(DDGRLOCK(dd_grd_curcanv));
1784         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1785         
1786         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_JBUTTON );
1787 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1788
1789         game_flush_inputs();
1790         code=255;
1791         k=255;
1792         
1793         while( (k!=KEY_ESC) && (code==255))     
1794         {                               
1795         #ifdef WINDOWS
1796                 {
1797                         MSG msg;
1798                         DoMessageStuff(&msg);
1799                         DDGRRESTORE;
1800                 }
1801         #endif
1802
1803                 #ifdef NETWORK
1804                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1805                         multi_menu_poll();
1806                 #endif
1807 //              if ( Game_mode & GM_MULTI )
1808 //                      GameLoop( 0, 0 );                               // Continue
1809                 k = key_inkey();
1810                 timer_delay(f0_1/10);
1811
1812                 if (k == KEY_PRINT_SCREEN)
1813                         save_screen_shot(0);
1814
1815                 kc_drawquestion( item );
1816
1817                 WIN(code = joydefsw_do_button());
1818                 
1819 #ifdef MACINTOSH
1820                 code = joy_do_buttons();
1821 #endif
1822                 
1823 #if !defined(WINDOWS) && !defined(MACINTOSH)
1824                 if (Config_control_type==CONTROL_THRUSTMASTER_FCS)      {
1825                         int axis[4];
1826                         joystick_read_raw_axis( JOY_ALL_AXIS, axis );
1827                         kconfig_read_fcs( axis[3] );
1828                         if ( joy_get_button_state(7) ) code = 7;
1829                         if ( joy_get_button_state(11) ) code = 11;
1830                         if ( joy_get_button_state(15) ) code = 15;
1831                         if ( joy_get_button_state(19) ) code = 19;
1832                         for (i=0; i<4; i++ )    {
1833                                 if ( joy_get_button_state(i) )
1834                                         code = i;
1835                         }
1836                 } else if (Config_control_type==CONTROL_FLIGHTSTICK_PRO) {
1837                         for (i=4; i<20; i++ )   {
1838                                 if ( joy_get_button_state(i)  ) {
1839                                         code = i;
1840                                         mprintf(( 0, "JB: %d\n", code ));
1841                                 }
1842                         }
1843                 } else {
1844                         for (i=0; i<MAX_BUTTONS; i++ )  {
1845                                 if ( joy_get_button_state(i) )
1846                                         code = i;
1847                         }
1848                 }
1849 #endif
1850         }
1851         if (code!=255)  {
1852                 for (i=0; i<Num_items; i++ )    {
1853                         n = item - All_items;
1854                         if ( (i!=n) && (All_items[i].type==BT_JOY_BUTTON) && (All_items[i].value==code) ) {
1855                                 All_items[i].value = 255;
1856                                 kc_drawitem( &All_items[i], 0 );
1857                         }
1858                 }
1859                 item->value = code;
1860         }
1861         kc_drawitem( item, 1 );
1862         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1863         game_flush_inputs();
1864 }
1865
1866 void kc_change_mousebutton( kc_item * item )
1867 {
1868         int n,i,b,k;
1869         ubyte code;
1870
1871 WIN(DDGRLOCK(dd_grd_curcanv));
1872         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1873         
1874         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_MBUTTON );
1875 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1876
1877
1878         game_flush_inputs();
1879         code=255;
1880         k=255;
1881         
1882         while( (k!=KEY_ESC) && (code==255))     
1883         {                               
1884         #ifdef WINDOWS
1885                 {
1886                         MSG msg;
1887                         DoMessageStuff(&msg);
1888                         DDGRRESTORE;
1889                 }
1890         #endif
1891
1892                 #ifdef NETWORK
1893                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1894                         multi_menu_poll();
1895                 #endif
1896 //              if ( Game_mode & GM_MULTI )
1897 //                      GameLoop( 0, 0 );                               // Continue
1898                 k = key_inkey();
1899                 timer_delay(f0_1/10);
1900
1901                 if (k == KEY_PRINT_SCREEN)
1902                         save_screen_shot(0);
1903
1904                 kc_drawquestion( item );
1905
1906                 b = mouse_get_btns();
1907                 for (i = 0; i < 16; i++ ) {
1908                         if ( b & (1<<i) )       
1909                                 code = i;
1910                 }
1911         }
1912         if (code!=255)  {
1913                 for (i=0; i<Num_items; i++ )    {
1914                         n = item - All_items;
1915                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_BUTTON) && (All_items[i].value==code) )             {
1916                                 All_items[i].value = 255;
1917                                 kc_drawitem( &All_items[i], 0 );
1918                         }
1919                 }
1920                 item->value = code;
1921         }
1922         kc_drawitem( item, 1 );
1923         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1924         game_flush_inputs();
1925
1926 }
1927
1928 void kc_change_joyaxis( kc_item * item )
1929 {
1930 #ifdef USE_LINUX_JOY
1931         int axis[MAX_AXES];
1932         int old_axis[MAX_AXES];
1933         int numaxis = MAX_AXES;
1934 #else
1935         int axis[JOY_NUM_AXES];
1936         int old_axis[JOY_NUM_AXES];
1937         int numaxis = JOY_NUM_AXES;
1938 #endif
1939         int n,i,k;
1940         ubyte code;
1941
1942 WIN(DDGRLOCK(dd_grd_curcanv));
1943         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1944         
1945         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_JOY_AXIS );
1946 WIN(DDGRUNLOCK(dd_grd_curcanv));        
1947
1948         game_flush_inputs();
1949         code=255;
1950         k=255;
1951
1952         WINDOS(
1953                 joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, old_axis ),
1954                 joystick_read_raw_axis( JOY_ALL_AXIS, old_axis )
1955         );
1956
1957         while( (k!=KEY_ESC) && (code==255))     
1958         {                               
1959         #ifdef WINDOWS
1960                 {
1961                         MSG msg;
1962                         DoMessageStuff(&msg);
1963                         DDGRRESTORE;
1964                 }
1965         #endif
1966
1967                 #ifdef NETWORK
1968                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1969                         multi_menu_poll();
1970                 #endif
1971 //              if ( Game_mode & GM_MULTI )
1972 //                      GameLoop( 0, 0 );                               // Continue
1973                 k = key_inkey();
1974                 timer_delay(f0_1/10);
1975
1976                 if (k == KEY_PRINT_SCREEN)
1977                         save_screen_shot(0);
1978
1979                 kc_drawquestion( item );
1980
1981                 WINDOS(
1982                         joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, axis ),
1983                         joystick_read_raw_axis( JOY_ALL_AXIS, axis )
1984                 );
1985                 
1986                 for (i=0; i<numaxis; i++ )      {
1987 #if defined (MACINTOSH)
1988                         if ( abs(axis[i]-old_axis[i])>100 )     {
1989 #elif defined(WINDOWS)
1990                         if ( abs(axis[i]-old_axis[i])>1024 )    {
1991 #else 
1992                         if ( abs(axis[i]-old_axis[i])>200 )     {
1993 #endif
1994                                 code = i;
1995                                 con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", i);
1996                         }
1997                         //old_axis[i] = axis[i];
1998                 }
1999                 for (i=0; i<Num_items; i++ )    
2000                  {
2001                         n = item - All_items;
2002                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) 
2003                                 code = 255;
2004                  }
2005         
2006         }
2007         if (code!=255)  {
2008                 for (i=0; i<Num_items; i++ )    {
2009                         n = item - All_items;
2010                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) {
2011                                 All_items[i].value = 255;
2012                                 kc_drawitem( &All_items[i], 0 );
2013                         }
2014                 }
2015
2016                 item->value = code;                                      
2017         }
2018         kc_drawitem( item, 1 );
2019         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
2020         game_flush_inputs();
2021
2022 }
2023
2024 void kc_change_mouseaxis( kc_item * item )
2025 {
2026         int i,n,k;
2027         ubyte code;
2028         int dx,dy;
2029 #ifdef SDL_INPUT
2030         int dz;
2031 #endif
2032
2033 WIN(DDGRLOCK(dd_grd_curcanv));
2034         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
2035         
2036         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_MSE_AXIS );
2037 WIN(DDGRUNLOCK(dd_grd_curcanv));        
2038
2039         game_flush_inputs();
2040         code=255;
2041         k=255;
2042
2043         mouse_get_delta( &dx, &dy );
2044
2045         while( (k!=KEY_ESC) && (code==255))     
2046         {                               
2047         #ifdef WINDOWS
2048                 {
2049                         MSG msg;
2050                         DoMessageStuff(&msg);
2051                         DDGRRESTORE;
2052                 }
2053         #endif
2054
2055                 #ifdef NETWORK
2056                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
2057                         multi_menu_poll();
2058                 #endif
2059 //              if ( Game_mode & GM_MULTI )
2060 //                      GameLoop( 0, 0 );                               // Continue
2061                 k = key_inkey();
2062                 timer_delay(f0_1/10);
2063
2064                 if (k == KEY_PRINT_SCREEN)
2065                         save_screen_shot(0);
2066
2067                 kc_drawquestion( item );
2068
2069 #ifdef SDL_INPUT
2070                 mouse_get_delta_z( &dx, &dy, &dz );
2071 #else
2072                 mouse_get_delta( &dx, &dy );
2073 #endif
2074                 if ( abs(dx)>20 ) code = 0;
2075                 if ( abs(dy)>20 ) code = 1;
2076 #ifdef SDL_INPUT
2077                 if ( abs(dz)>20 ) code = 2;
2078 #endif
2079         }
2080         if (code!=255)  {
2081                 for (i=0; i<Num_items; i++ )    {
2082                         n = item - All_items;
2083                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_AXIS) && (All_items[i].value==code) )               {
2084                                 All_items[i].value = 255;
2085                                 kc_drawitem( &All_items[i], 0 );
2086                         }
2087                 }
2088                 item->value = code;
2089         }
2090         kc_drawitem( item, 1 );
2091         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
2092         game_flush_inputs();
2093
2094 }
2095
2096
2097 void kc_change_invert( kc_item * item )
2098 {
2099         game_flush_inputs();
2100
2101         if (item->value)
2102                 item->value = 0;
2103         else 
2104                 item->value = 1;
2105
2106         kc_drawitem( item, 1 );
2107
2108 }
2109
2110 #include "screens.h"
2111
2112 void kconfig(int n, char * title)
2113 {
2114         int i;
2115         grs_bitmap *save_bm;
2116
2117         set_screen_mode( SCREEN_MENU );
2118
2119         kc_set_controls();
2120
2121         //save screen
2122         WIN(mouse_set_mode(0));
2123         WIN(dd_gr_set_current_canvas(NULL));
2124         
2125 #if defined(POLY_ACC)
2126         save_bm = gr_create_bitmap2( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h, grd_curcanv->cv_bitmap.bm_type, NULL );
2127 #else
2128         save_bm = gr_create_bitmap( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
2129 #endif
2130         Assert( save_bm != NULL );
2131         
2132         WIN(DDGRLOCK(dd_grd_curcanv));
2133                 gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_w, 
2134                                                  0, 0, 0, 0, &grd_curcanv->cv_bitmap, save_bm );
2135         WIN(DDGRUNLOCK(dd_grd_curcanv));
2136
2137         switch(n)       {
2138         case 0:kconfig_sub( kc_keyboard, NUM_KEY_CONTROLS, title );break;
2139         case 1:kconfig_sub( kc_joystick, NUM_OTHER_CONTROLS, title );break;
2140         case 2:kconfig_sub( kc_mouse, NUM_OTHER_CONTROLS, title ); break;
2141         case 3:kconfig_sub( kc_superjoy, NUM_OTHER_CONTROLS, title); break;
2142 #ifdef D2X_KEYS
2143         //added on 2/4/99 by Victor Rachels for new keys menu
2144         case 4:kconfig_sub( kc_d2x, NUM_D2X_CONTROLS, title ); break;
2145         //end this section addition - VR
2146 #endif
2147         default:
2148                 Int3();
2149                 return;
2150         }
2151
2152         //restore screen
2153         WIN(mouse_set_mode(1));
2154         WIN(dd_gr_set_current_canvas(NULL));
2155         WIN(DDGRLOCK(dd_grd_curcanv));
2156                 gr_bitmap(0, 0, save_bm);
2157         WIN(DDGRUNLOCK(dd_grd_curcanv));
2158         gr_free_bitmap(save_bm);
2159
2160         reset_cockpit();                //force cockpit redraw next time
2161
2162         // Update save values...
2163         
2164         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
2165                 kconfig_settings[0][i] = kc_keyboard[i].value;
2166
2167         if ( (Config_control_type>0) && (Config_control_type<5)) { 
2168                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2169                         kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
2170         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
2171                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2172                         kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
2173         }
2174         else if (Config_control_type == CONTROL_WINJOYSTICK) {
2175                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   
2176                         kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
2177         }
2178
2179 #ifdef D2X_KEYS
2180         for (i=0; i<NUM_D2X_CONTROLS; i++)
2181                 kconfig_d2x_settings[i] = kc_d2x[i].value;
2182 #endif
2183 }
2184
2185
2186 void kconfig_read_fcs( int raw_axis )
2187 {
2188         int raw_button, button, axis_min[4], axis_center[4], axis_max[4];
2189
2190         if (Config_control_type!=CONTROL_THRUSTMASTER_FCS) return;
2191
2192         joy_get_cal_vals(axis_min, axis_center, axis_max);
2193
2194         if ( axis_max[3] > 1 )
2195                 raw_button = (raw_axis*100)/axis_max[3];
2196         else
2197                 raw_button = 0;
2198
2199         if ( raw_button > 88 )
2200                 button = 0;
2201         else if ( raw_button > 63 )
2202                 button = 7;
2203         else if ( raw_button > 39 )
2204                 button = 11;
2205         else if ( raw_button > 15 )
2206                 button = 15;
2207         else    
2208                 button = 19;
2209
2210         kconfig_set_fcs_button( 19, button );
2211         kconfig_set_fcs_button( 15, button );
2212         kconfig_set_fcs_button( 11, button );
2213         kconfig_set_fcs_button( 7, button );
2214 }
2215                 
2216
2217 void kconfig_set_fcs_button( int btn, int button )
2218 {
2219         int state,time_down,upcount,downcount;
2220         state = time_down = upcount = downcount = 0;
2221
2222         if ( joy_get_button_state(btn) ) {
2223                 if ( btn==button )      {
2224                         state = 1;
2225                         time_down = FrameTime;
2226                 } else {
2227                         upcount=1;
2228                 }
2229         } else {
2230                 if ( btn==button )      {
2231                         state = 1;
2232                         time_down = FrameTime;
2233                         downcount=1;
2234                 } else {
2235                         upcount=1;
2236                 }
2237         }                               
2238                         
2239         joy_set_btn_values( btn, state, time_down, downcount, upcount );
2240                                         
2241 }
2242
2243
2244
2245 fix Last_angles_p = 0;
2246 fix Last_angles_b = 0;
2247 fix Last_angles_h = 0;
2248 ubyte Last_angles_read = 0;
2249
2250 extern int                      VR_sensitivity;
2251                                                 
2252 int VR_sense_range[3] = { 25, 50, 75 };
2253
2254 #if 0 //ndef MACINTOSH
2255 read_head_tracker()
2256 {
2257 #ifndef WINDOWS
2258
2259         fix yaw, pitch, roll;
2260         int buttons;
2261
2262 //------ read vfx1 helmet --------
2263         if (vfx1_installed) {
2264                 vfx_get_data(&yaw,&pitch,&roll,&buttons);
2265         } else if (iglasses_headset_installed)  {
2266                 iglasses_read_headset( &yaw, &pitch, &roll );
2267         } else if (Victor_headset_installed)   {
2268                 victor_read_headset_filtered( &yaw, &pitch, &roll );
2269         } else {
2270                 return;
2271         }
2272
2273         Use_player_head_angles = 0;
2274         if ( Last_angles_read ) {
2275                 fix yaw1 = yaw;
2276                 
2277                 yaw1 = yaw;
2278                 if ( (Last_angles_h < (F1_0/4) ) && (yaw > ((F1_0*3)/4) ) )     
2279                         yaw1 -= F1_0;
2280                 else if ( (yaw < (F1_0/4) ) && (Last_angles_h > ((F1_0*3)/4) ) )        
2281                         yaw1 += F1_0;
2282         
2283                 Controls.pitch_time     += fixmul((pitch- Last_angles_p)*VR_sense_range[VR_sensitivity],FrameTime);
2284                 Controls.heading_time+= fixmul((yaw1 -  Last_angles_h)*VR_sense_range[VR_sensitivity],FrameTime);
2285                 Controls.bank_time      += fixmul((roll - Last_angles_b)*VR_sense_range[VR_sensitivity],FrameTime);
2286         }
2287         Last_angles_read = 1;
2288         Last_angles_p = pitch;
2289         Last_angles_h = yaw;
2290         Last_angles_b = roll;
2291 #endif
2292 }
2293 #endif
2294
2295 #define PH_SCALE        8
2296
2297 #ifndef __MSDOS__ // WINDOWS
2298 #define JOYSTICK_READ_TIME      (F1_0/40)               //      Read joystick at 40 Hz.
2299 #else
2300 #define JOYSTICK_READ_TIME      (F1_0/10)               //      Read joystick at 10 Hz.
2301 #endif
2302
2303 fix     LastReadTime = 0;
2304
2305 #ifdef USE_LINUX_JOY
2306 fix     joy_axis[MAX_AXES];
2307 #else
2308 fix     joy_axis[JOY_NUM_AXES];
2309 #endif
2310
2311 ubyte                   kc_use_external_control = 0;
2312 ubyte                           kc_enable_external_control = 0;
2313 ubyte                   kc_external_intno = 0;
2314 ext_control_info        *kc_external_control = NULL;
2315 ubyte                           *kc_external_name = NULL;
2316 ubyte                           kc_external_version = 0;
2317 extern int Automap_active;
2318
2319 void kconfig_init_external_controls(int intno, int address)
2320 {
2321         int i;
2322         kc_external_intno = intno;
2323         kc_external_control     = (ext_control_info *)address;
2324         kc_use_external_control = 1;
2325         kc_enable_external_control  = 1;
2326
2327         i = FindArg ( "-xname" );
2328         if ( i )        
2329                 kc_external_name = Args[i+1];
2330         else
2331                 kc_external_name = "External Controller";
2332
2333    for (i=0;i<strlen (kc_external_name);i++)
2334     if (kc_external_name[i]=='_')
2335           kc_external_name[i]=' '; 
2336
2337         i = FindArg ( "-xver" );
2338         if ( i )
2339                 kc_external_version = atoi(Args[i+1]);
2340         
2341         printf( "%s int: 0x%x, data: 0x%p, ver:%d\n", kc_external_name, kc_external_intno, kc_external_control, kc_external_version );
2342
2343 }
2344
2345 #if !defined(MACINTOSH)
2346 /*void kconfig_read_external_controls()
2347 {
2348         union REGS r;
2349
2350         if ( !kc_enable_external_control && !CybermouseActive) 
2351                 return;
2352
2353         if ( kc_external_version == 0 ) 
2354                 memset( kc_external_control, 0, sizeof(control_info) );
2355         else if ( kc_external_version > 0 )     {
2356                 memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 );
2357                 if ( kc_external_version > 1 ) {
2358                         // Write ship pos and angles to external controls...
2359                         ubyte *temp_ptr = (ubyte *)kc_external_control;
2360                         vms_vector *ship_pos;
2361                         vms_matrix *ship_orient;
2362                         memset( kc_external_control, 0, sizeof(control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
2363                         temp_ptr += sizeof(control_info)+sizeof(vms_angvec) + 64;
2364                         ship_pos = (vms_vector *)temp_ptr;
2365                         temp_ptr += sizeof(vms_vector);
2366                         ship_orient = (vms_matrix *)temp_ptr;
2367                         // Fill in ship postion...
2368                         *ship_pos = Objects[Players[Player_num].objnum].pos;
2369                         // Fill in ship orientation...
2370                         *ship_orient = Objects[Players[Player_num].objnum].orient;
2371                 }
2372         }
2373
2374         if ( Automap_active )                    // (If in automap...)
2375                 kc_external_control->automap_state = 1;
2376         memset(&r,0,sizeof(r));
2377
2378 #ifndef WINDOWS
2379   
2380    if (!CybermouseActive)
2381         int386 ( kc_external_intno, &r, &r);            // Read external info...
2382 //      else
2383   //            ReadOWL (kc_external_control);
2384
2385 #endif
2386
2387         if ( Player_num > -1 )  {
2388                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
2389                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
2390                 Auto_leveling_on = 0;
2391
2392                 if ( kc_external_version > 0 ) {                
2393                         vms_matrix tempm, ViewMatrix;
2394                         vms_angvec * Kconfig_abs_movement;
2395                         char * oem_message;
2396         
2397                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
2398         
2399                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
2400                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
2401                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
2402                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
2403                         }
2404                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
2405                         if (oem_message[0] != '\0' )
2406                                 HUD_init_message( oem_message );
2407                 }
2408         }
2409
2410         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
2411         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
2412         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
2413         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
2414         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
2415         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
2416         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
2417         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
2418         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
2419         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
2420         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
2421         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
2422         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
2423         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
2424         Controls.automap_down_count += kc_external_control->automap_down_count;
2425         Controls.automap_state |= kc_external_control->automap_state;
2426 } */
2427 #endif
2428
2429 #ifdef WINDOWS
2430 void controls_read_all_win()
2431 {
2432         int i;
2433         int slide_on, bank_on;
2434         int dx, dy;
2435         fix ctime;
2436         fix mouse_axis[2];
2437         int raw_joy_axis[7];
2438         int mouse_buttons;
2439         fix k0, k1, k2, k3, kp;
2440         fix k4, k5, k6, k7, kh;
2441         ubyte channel_masks;
2442         int use_mouse, use_joystick;
2443         int speed_factor=1;
2444
2445         if (Game_turbo_mode)
2446                 speed_factor = 2;
2447         
2448         {
2449                 fix temp = Controls.heading_time;
2450                 fix temp1 = Controls.pitch_time;
2451                 memset( &Controls, 0, sizeof(control_info) );
2452                 Controls.heading_time = temp;
2453                 Controls.pitch_time = temp1;
2454         }
2455         slide_on = 0;
2456         bank_on = 0;
2457
2458         ctime = timer_get_fixed_seconds();
2459
2460 //      DO JOYSTICK (X,Y,Z  R,U,V)
2461 //      ----------------------------------------------------------------------------
2462         if ( (LastReadTime + JOYSTICK_READ_TIME) > ctime ) {
2463                 if ((ctime < 0) && (LastReadTime > 0))
2464                         LastReadTime = ctime;
2465                 use_joystick=1;
2466         } else if ((Config_control_type==CONTROL_WINJOYSTICK)) {
2467                 LastReadTime = ctime;
2468                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS+JOY_EXT_AXIS, raw_joy_axis );
2469
2470                 for (i=0; i<7; i++ )    {
2471                         if (channel_masks&(1<<i))       {
2472                                 int joy_null_value = 28;
2473
2474                         // DO POV if joystick has a hat.
2475                         //      --------------------------------------------------------------------
2476                                 if (i == 3) {
2477                                         joydefsw_do_winjoybutton(raw_joy_axis);
2478                                 }
2479                                 else {
2480                                 // DO AXIS
2481                                 //      --------------------------------------------------------------------    
2482                                 //      mprintf((0, "(%d)=%d,", i, raw_joy_axis[i]));
2483                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
2484                                 //      mprintf((0, "%d  ",raw_joy_axis[i]));
2485                                 //      if (i%2) mprintf((0,"\n"));
2486
2487         
2488                                         if (kc_superjoy[23].value==i)           // If this is the throttle
2489                                                 joy_null_value = 32;                            // Then use a larger dead-zone
2490         
2491                                         if (raw_joy_axis[i] > (joy_null_value-2)) 
2492                                                 raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
2493                                         else if (raw_joy_axis[i] < -(joy_null_value+2))
2494                                                 raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
2495                                         else
2496                                                 raw_joy_axis[i] = 0;
2497                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
2498                                 }
2499                         } else {
2500                                 joy_axis[i] = 0;
2501                         }
2502                 }       
2503                 use_joystick=1;
2504
2505         } else {
2506                 for (i=0; i<6; i++ )
2507                         joy_axis[i] = 0;
2508                 use_joystick=0;
2509         }
2510
2511 //      DO MOUSE 
2512 //      ----------------------------------------------------------------------------
2513         if (Config_control_type==5) {
2514                 mouse_get_delta( &dx, &dy );
2515                 mouse_axis[0] = (dx*FrameTime)/35;
2516                 mouse_axis[1] = (dy*FrameTime)/25;
2517                 mouse_buttons = mouse_get_btns();
2518                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
2519                 use_mouse=1;
2520    } else {
2521                 mouse_axis[0] = 0;
2522                 mouse_axis[1] = 0;
2523                 mouse_buttons = 0;
2524                 use_mouse=0;
2525         }
2526
2527 //------------- Read slide_on -------------
2528         
2529         // From keyboard...
2530         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
2531         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
2532         // From joystick...
2533         if ((use_joystick)&&(kc_superjoy[5].value<255)) slide_on |= joy_get_button_state( kc_superjoy[5].value );
2534         // From mouse...
2535         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
2536
2537 //------------- Read bank_on ---------------
2538
2539         // From keyboard...
2540         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
2541         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
2542         // From joystick...
2543         if ( (use_joystick)&&(kc_superjoy[10].value < 255 )) bank_on |= joy_get_button_state( kc_superjoy[10].value );
2544         // From mouse...
2545         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
2546
2547 //------------ Read pitch_time -----------
2548         if ( !slide_on )        {
2549                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2550                 kp = 0;
2551                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
2552                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
2553                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
2554                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
2555
2556                 // From keyboard...
2557                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
2558                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
2559                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
2560                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
2561
2562                 // From Cyberman...
2563                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2564                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
2565                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
2566                 }
2567         
2568                 if (kp == 0)
2569                         Controls.pitch_time = 0;
2570                 else if (kp > 0) {
2571                         if (Controls.pitch_time < 0)
2572                                 Controls.pitch_time = 0;
2573                 } else // kp < 0
2574                         if (Controls.pitch_time > 0)
2575                                 Controls.pitch_time = 0;
2576                 Controls.pitch_time += kp;
2577         
2578                 // From joystick...
2579                 if ( (use_joystick)&&(kc_superjoy[13].value < 255 ))    {
2580                         if ( !kc_superjoy[14].value )           // If not inverted...
2581                                 Controls.pitch_time -= (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2582                         else
2583                                 Controls.pitch_time += (joy_axis[kc_superjoy[13].value]*Config_joystick_sensitivity)/8;
2584                 }
2585         
2586                 // From mouse...
2587                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
2588                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
2589                         if ( !kc_mouse[14].value )              // If not inverted...
2590                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2591                         else
2592                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
2593                 }
2594         } else {
2595                 Controls.pitch_time = 0;
2596         }
2597
2598
2599 //----------- Read vertical_thrust_time -----------------
2600
2601         if ( slide_on ) {
2602                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
2603                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
2604                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
2605                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
2606
2607                 // From keyboard...
2608                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
2609                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
2610                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
2611                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
2612
2613                 // From Cyberman...
2614                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2615                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
2616                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
2617                 }
2618         
2619                 // From joystick...
2620                 if ((use_joystick)&&( kc_superjoy[13].value < 255 ))    {
2621                         if ( !kc_superjoy[14].value )           // If not inverted...
2622                                 Controls.vertical_thrust_time += joy_axis[kc_superjoy[13].value];
2623                         else
2624                                 Controls.vertical_thrust_time -= joy_axis[kc_superjoy[13].value];
2625                 }
2626         
2627                 // From mouse...
2628                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
2629                         if ( !kc_mouse[14].value )              // If not inverted...
2630                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
2631                         else
2632                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
2633                 }
2634         }
2635
2636         // From keyboard...
2637         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
2638         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
2639         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
2640         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
2641         
2642         // From joystick...
2643         if ((use_joystick)&&( kc_superjoy[19].value < 255 ))    {
2644                 if ( !kc_superjoy[20].value )           // If not inverted...
2645                         Controls.vertical_thrust_time += joy_axis[kc_superjoy[19].value];
2646                 else
2647                         Controls.vertical_thrust_time -= joy_axis[kc_superjoy[19].value];
2648         }
2649
2650         // From joystick buttons
2651         if ( (use_joystick)&&(kc_superjoy[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_superjoy[8].value );
2652         if ( (use_joystick)&&(kc_superjoy[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_superjoy[9].value );
2653
2654         // From mouse buttons
2655         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
2656         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
2657
2658         // From mouse...
2659         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
2660                 if ( !kc_mouse[20].value )              // If not inverted...
2661                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
2662                 else
2663                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
2664         }
2665
2666         // From Cyberman...
2667         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2668                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
2669                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
2670         }
2671
2672 //---------- Read heading_time -----------
2673
2674         if (!slide_on && !bank_on)      {
2675                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
2676                 kh = 0;
2677                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
2678                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
2679                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
2680                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
2681
2682                 // From keyboard...
2683                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
2684                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
2685                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
2686                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
2687
2688                 // From Cyberman...
2689                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2690                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
2691                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
2692                 }
2693         
2694                 if (kh == 0)
2695                         Controls.heading_time = 0;
2696                 else if (kh > 0) {
2697                         if (Controls.heading_time < 0)
2698                                 Controls.heading_time = 0;
2699                 } else // kh < 0
2700                         if (Controls.heading_time > 0)
2701                                 Controls.heading_time = 0;
2702                 Controls.heading_time += kh;
2703
2704                 // From joystick...
2705                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2706                         if ( !kc_superjoy[16].value )           // If not inverted...
2707                                 Controls.heading_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2708                         else
2709                                 Controls.heading_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2710                 }
2711         
2712                 // From mouse...
2713                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2714                         if ( !kc_mouse[16].value )              // If not inverted...
2715                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2716                         else
2717                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2718                 }
2719         } else {
2720                 Controls.heading_time = 0;
2721         }
2722
2723 //----------- Read sideways_thrust_time -----------------
2724
2725         if ( slide_on ) {
2726                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2727                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2728                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2729                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2730
2731                 // From keyboard...
2732                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
2733                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
2734                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
2735                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
2736         
2737                 // From joystick...
2738                 if ( (use_joystick)&&(kc_superjoy[15].value < 255 ))    {
2739                         if ( !kc_superjoy[16].value )           // If not inverted...
2740                                 Controls.sideways_thrust_time += joy_axis[kc_superjoy[15].value];
2741                         else
2742                                 Controls.sideways_thrust_time -= joy_axis[kc_superjoy[15].value];
2743                 }
2744                 
2745                 // From cyberman
2746                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2747                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
2748                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
2749                 }
2750         
2751                 // From mouse...
2752                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2753                         if ( !kc_mouse[16].value )              // If not inverted...
2754                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
2755                         else
2756                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
2757                 }
2758         }
2759
2760         // From keyboard...
2761         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
2762         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
2763         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
2764         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
2765         
2766         // From joystick...
2767         if ( (use_joystick)&&(kc_superjoy[17].value < 255 ))    {
2768                 if ( !kc_superjoy[18].value )           // If not inverted...
2769                         Controls.sideways_thrust_time -= joy_axis[kc_superjoy[17].value];
2770                 else
2771                         Controls.sideways_thrust_time += joy_axis[kc_superjoy[17].value];
2772         }
2773
2774         // From joystick buttons
2775         if ( (use_joystick)&&(kc_superjoy[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_superjoy[6].value );
2776         if ( (use_joystick)&&(kc_superjoy[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_superjoy[7].value );
2777
2778         // From mouse buttons
2779         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
2780         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
2781
2782         // From mouse...
2783         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
2784                 if ( !kc_mouse[18].value )              // If not inverted...
2785                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
2786                 else
2787                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
2788         }
2789
2790 //----------- Read bank_time -----------------
2791
2792         if ( bank_on )  {
2793                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
2794                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
2795                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
2796                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
2797
2798                 // From keyboard...
2799                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
2800                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
2801                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
2802                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
2803
2804                 // From Cyberman...
2805                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2806                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
2807                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
2808                 }
2809
2810                 // From joystick...
2811                 if ( (use_joystick)&&(kc_superjoy[15].value < 255) )    {
2812                         if ( !kc_superjoy[16].value )           // If not inverted...
2813                                 Controls.bank_time -= (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2814                         else
2815                                 Controls.bank_time += (joy_axis[kc_superjoy[15].value]*Config_joystick_sensitivity)/8;
2816                 }
2817         
2818                 // From mouse...
2819                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
2820                         if ( !kc_mouse[16].value )              // If not inverted...
2821                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2822                         else
2823                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
2824                 }
2825         }
2826
2827         // From keyboard...
2828         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
2829         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
2830         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
2831         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
2832
2833         // From joystick...
2834         if ( (use_joystick)&&(kc_superjoy[21].value < 255) )    {
2835                 if ( !kc_superjoy[22].value )           // If not inverted...
2836                         Controls.bank_time -= joy_axis[kc_superjoy[21].value];
2837                 else
2838                         Controls.bank_time += joy_axis[kc_superjoy[21].value];
2839         }
2840
2841         // From joystick buttons
2842         if ( (use_joystick)&&(kc_superjoy[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_superjoy[11].value );
2843         if ( (use_joystick)&&(kc_superjoy[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_superjoy[12].value );
2844
2845         // From mouse buttons
2846         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
2847         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
2848
2849         // From mouse...
2850         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
2851                 if ( !kc_mouse[22].value )              // If not inverted...
2852                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
2853                 else
2854                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
2855         }
2856
2857         // From Cyberman
2858         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
2859                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
2860                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
2861         }
2862
2863 //----------- Read forward_thrust_time -------------
2864
2865         // From keyboard...
2866         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
2867         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
2868         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
2869         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
2870
2871         // From joystick...
2872         if ( (use_joystick)&&(kc_superjoy[23].value < 255 ))    {
2873                 if ( !kc_superjoy[24].value )           // If not inverted...
2874                         Controls.forward_thrust_time -= joy_axis[kc_superjoy[23].value];
2875                 else
2876                         Controls.forward_thrust_time += joy_axis[kc_superjoy[23].value];
2877         }
2878
2879         // From joystick buttons
2880         if ( (use_joystick)&&(kc_superjoy[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_superjoy[2].value );
2881         if ( (use_joystick)&&(kc_superjoy[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_superjoy[3].value );
2882
2883         // From mouse...
2884         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
2885                 if ( !kc_mouse[24].value )              // If not inverted...
2886                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
2887                 else
2888                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
2889         }
2890
2891         // From mouse buttons
2892         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
2893         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
2894
2895 //----------- Read afterburner_state -------------
2896
2897         // From keyboard...
2898         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
2899         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
2900
2901         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
2902
2903         if ( (use_joystick)&&(kc_superjoy[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_superjoy[27].value);
2904
2905 //-------Read headlight key--------------------------
2906         if (kc_keyboard[52].value < 255 )
2907                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
2908         if (kc_keyboard[53].value < 255 )
2909                    Controls.headlight_count=key_down_count(kc_keyboard[53].value);
2910                   if ((use_joystick)&&(kc_superjoy[30].value < 255 )) 
2911          Controls.headlight_count=joy_get_button_down_cnt(kc_superjoy[30].value);
2912                  
2913 //--------Read Cycle Primary Key------------------
2914
2915                   if (kc_keyboard[48].value<255)
2916                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
2917                   if (kc_keyboard[49].value<255)
2918                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
2919              if ((use_joystick)&&(kc_superjoy[28].value < 255 )) 
2920          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_superjoy[28].value);
2921
2922 //--------Read Cycle Secondary Key------------------
2923
2924                   if (kc_keyboard[50].value<255)
2925                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
2926                   if (kc_keyboard[51].value<255)
2927                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
2928              if ((use_joystick)&&(kc_superjoy[29].value < 255 )) 
2929                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_superjoy[29].value);
2930
2931 //--------Read Toggle Bomb key----------------------
2932
2933                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
2934          {
2935           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
2936
2937                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
2938                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
2939                            {
2940                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
2941                                  HUD_init_message ("No bombs available!");
2942                                 }
2943                          else
2944                                 {       
2945                                  if (Players[Player_num].secondary_ammo[bomb]==0)
2946                                         {
2947                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
2948                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
2949                                         }
2950                                   else
2951                                         {
2952                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
2953                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
2954                                         }
2955                                 }
2956                         }
2957           
2958 //---------Read Energy->Shield key----------
2959
2960         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
2961                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
2962         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
2963                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
2964
2965 //----------- Read fire_primary_down_count
2966         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
2967         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
2968         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_superjoy[0].value);
2969         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
2970
2971 //----------- Read fire_primary_state
2972         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
2973         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
2974         if ((use_joystick)&&(kc_superjoy[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_superjoy[0].value);
2975         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
2976
2977 //----------- Read fire_secondary_down_count
2978         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
2979         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
2980         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_superjoy[1].value);
2981         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
2982
2983 //----------- Read fire_secondary_state
2984         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
2985         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
2986         if ((use_joystick)&&(kc_superjoy[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_superjoy[1].value);
2987         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
2988
2989 //----------- Read fire_flare_down_count
2990         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
2991         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
2992         if ((use_joystick)&&(kc_superjoy[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_superjoy[4].value);
2993         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
2994
2995 //----------- Read drop_bomb_down_count
2996         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
2997         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
2998         if ((use_joystick)&&(kc_superjoy[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_superjoy[26].value);
2999         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
3000
3001 //----------- Read rear_view_down_count
3002         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
3003         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
3004         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_superjoy[25].value);
3005         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
3006
3007 //----------- Read rear_view_down_state
3008         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
3009         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
3010         if ((use_joystick)&&(kc_superjoy[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_superjoy[25].value);
3011         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
3012
3013 //----------- Read automap_down_count
3014         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
3015         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
3016
3017 //----------- Read automap_state
3018         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
3019         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
3020
3021 //----------- Read stupid-cruise-control-type of throttle.
3022         {
3023                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
3024                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
3025                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
3026                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
3027                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
3028                         Cruise_speed = 0;
3029                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
3030                         Cruise_speed = 0;
3031         
3032                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
3033                 if (Cruise_speed < 0 ) Cruise_speed = 0;
3034         
3035                 if (Controls.forward_thrust_time==0)
3036                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
3037         }
3038
3039         //read_head_tracker();
3040
3041         // Read external controls
3042         if (kc_use_external_control || CybermouseActive)
3043                 kconfig_read_external_controls();
3044
3045 //----------- Clamp values between -FrameTime and FrameTime
3046         if (FrameTime > F1_0 )
3047                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
3048
3049         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
3050         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
3051         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
3052         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
3053         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
3054         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
3055 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
3056
3057         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
3058         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
3059         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
3060         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
3061         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
3062         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
3063 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
3064
3065
3066 //--------- Don't do anything if in debug mode
3067         #ifndef RELEASE
3068         if ( keyd_pressed[KEY_DELETE] ) {
3069                 memset( &Controls, 0, sizeof(control_info) );
3070         }
3071         #endif
3072 }
3073 #else
3074
3075
3076 fix Next_toggle_time[3]={0,0,0};
3077
3078 int allowed_to_toggle(int i)
3079 {
3080   //used for keeping tabs of when its ok to toggle headlight,primary,and secondary
3081  
3082         if (Next_toggle_time[i] > GameTime)
3083                 if (Next_toggle_time[i] < GameTime + (F1_0/8))  //      In case time is bogus, never wait > 1 second.
3084                         return 0;
3085
3086         Next_toggle_time[i] = GameTime + (F1_0/8);
3087
3088         return 1;
3089 }
3090
3091
3092 #ifdef D2X_KEYS
3093 //added on 2/7/99 by Victor Rachels for jostick state setting
3094 int d2x_joystick_ostate[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
3095 //end this section adition - VR
3096 #endif
3097
3098
3099 void controls_read_all()
3100 {
3101         int i;
3102         int slide_on, bank_on;
3103         int dx, dy;
3104 #ifdef SDL_INPUT
3105         int dz;
3106 #endif
3107         int idx, idy;
3108         fix ctime;
3109         fix mouse_axis[3] = {0,0,0};
3110 #ifdef USE_LINUX_JOY
3111         int raw_joy_axis[MAX_AXES];
3112 #else
3113         int raw_joy_axis[JOY_NUM_AXES];
3114 #endif
3115         int mouse_buttons;
3116         fix k0, k1, k2, k3, kp;
3117         fix k4, k5, k6, k7, kh;
3118         ubyte channel_masks;
3119         int use_mouse, use_joystick;
3120         int speed_factor=1;
3121
3122         mouse_buttons=0;
3123         use_mouse=0;
3124
3125         if (Game_turbo_mode)
3126                 speed_factor = 2;
3127         
3128         {
3129                 fix temp = Controls.heading_time;
3130                 fix temp1 = Controls.pitch_time;
3131                 memset( &Controls, 0, sizeof(control_info) );
3132                 Controls.heading_time = temp;
3133                 Controls.pitch_time = temp1;
3134         }
3135         slide_on = 0;
3136         bank_on = 0;
3137
3138         ctime = timer_get_fixed_seconds();
3139
3140         //---------  Read Joystick -----------
3141 #ifndef MACINTOSH
3142         if ( (LastReadTime + JOYSTICK_READ_TIME > ctime) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) ) {
3143 # ifndef __MSDOS__
3144                 if ((ctime < 0) && (LastReadTime >= 0))
3145 # else
3146                 if ((ctime < 0) && (LastReadTime > 0))
3147 # endif
3148                         LastReadTime = ctime;
3149                 use_joystick=1;
3150         } else if ((Config_control_type>0) && (Config_control_type<5) ) {
3151                 LastReadTime = ctime;
3152                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
3153                 
3154 # ifdef USE_LINUX_JOY
3155                 for (i = 0; i < j_num_axes; i++)
3156 # else
3157                 for (i = 0; i < JOY_NUM_AXES; i++)
3158 # endif
3159                 {
3160 #ifndef SDL_INPUT
3161                         if (channel_masks&(1<<i))       {
3162 #endif
3163                                 int joy_null_value = 10;
3164
3165                                 if ( (i==3) && (Config_control_type==CONTROL_THRUSTMASTER_FCS) )        {
3166                                         kconfig_read_fcs( raw_joy_axis[i] );
3167                                 } else {
3168                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
3169         
3170                                         if (kc_joystick[23].value==i)           // If this is the throttle
3171                                                 joy_null_value = 20;            // Then use a larger dead-zone
3172         
3173                                         if (raw_joy_axis[i] > joy_null_value) 
3174                                           raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
3175                                         else if (raw_joy_axis[i] < -joy_null_value)
3176                                           raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
3177                                         else
3178                                           raw_joy_axis[i] = 0;
3179                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
3180                                 }
3181 #ifndef SDL_INPUT
3182                         } else {
3183                                 joy_axis[i] = 0;
3184                         }
3185 #endif
3186                 }       
3187                 use_joystick=1;
3188         } else {
3189 #ifdef USE_LINUX_JOY
3190                 for (i = 0; i < j_num_axes; i++)
3191 #else
3192                 for (i = 0; i < JOY_NUM_AXES; i++)
3193 #endif
3194                         joy_axis[i] = 0;
3195                 use_joystick=0;
3196         }
3197 #else   // MACINTOSH
3198         //---------  Read Joystick -----------
3199         if ((Config_control_type>0) && (Config_control_type<5) ) {
3200                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
3201                 for (i=0; i<4; i++ )    {
3202                         if (channel_masks&(1<<i))       {
3203                                 int joy_null_value = 10;
3204
3205                                 raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
3206
3207                                 if (kc_joystick[23].value==i)           // If this is the throttle
3208                                         joy_null_value = 20;                            // Then use a larger dead-zone
3209
3210                                 if (raw_joy_axis[i] > joy_null_value) 
3211                                         raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
3212                                 else if (raw_joy_axis[i] < -joy_null_value)
3213                                         raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
3214                                 else
3215                                         raw_joy_axis[i] = 0;
3216                                 joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
3217                         } else {
3218                                 joy_axis[i] = 0;
3219                         }
3220                 }       
3221                 use_joystick=1;
3222         } else {
3223                 for (i=0; i<4; i++ )
3224                         joy_axis[i] = 0;
3225                 use_joystick=0;
3226         }
3227 #endif          // ifndef MACINTOSH
3228
3229         if (Config_control_type==5 && !CybermouseActive) {
3230                 //---------  Read Mouse -----------
3231 #ifdef SDL_INPUT
3232                 mouse_get_delta_z( &dx, &dy, &dz );
3233 #else
3234                 mouse_get_delta( &dx, &dy );
3235 #endif
3236                 mouse_axis[0] = (dx*FrameTime)/35;
3237                 mouse_axis[1] = (dy*FrameTime)/25;
3238 #ifdef SDL_INPUT
3239                 mouse_axis[2] = (dz*FrameTime);
3240 #endif
3241                 mouse_buttons = mouse_get_btns();
3242                 //mprintf(( 0, "Mouse %d,%d b:%d, 0x%x\n", mouse_axis[0], mouse_axis[1], mouse_buttons, FrameTime ));
3243                 use_mouse=1;
3244         } else if (Config_control_type==6 && !CybermouseActive) {
3245                 //---------  Read Cyberman -----------
3246                 mouse_get_cyberman_pos(&idx,&idy );
3247                 mouse_axis[0] = (idx*FrameTime)/128;
3248                 mouse_axis[1] = (idy*FrameTime)/128;
3249                 mouse_buttons = mouse_get_btns();
3250                 use_mouse=1;
3251         } else if (CybermouseActive) {
3252 //              ReadOWL (kc_external_control);
3253 //              CybermouseAdjust();
3254         } else {
3255                 mouse_axis[0] = 0;
3256                 mouse_axis[1] = 0;
3257                 mouse_buttons = 0;
3258                 use_mouse=0;
3259         }
3260
3261 #ifdef D2X_KEYS
3262         //added on 2/4/99 by Victor Rachels for d1x keys
3263         //--------- Read primary weapon select -------------
3264         //the following "if" added by WraithX to stop deadies from switchin weapons, 4/14/00
3265         if (!Player_is_dead)
3266         {
3267                 {
3268                         int d2x_joystick_state[10];
3269
3270                         for(i=0;i<10;i++)
3271                                 d2x_joystick_state[i] = joy_get_button_state(kc_d2x[i*2+1].value);
3272
3273
3274                         //----------------Weapon 1----------------
3275                         if(key_down_count(kc_d2x[0].value) ||
3276                            (joy_get_button_state(kc_d2x[1].value) &&
3277                                 (d2x_joystick_state[0]!=d2x_joystick_ostate[0]) ) )
3278                         {
3279                                 //int i, valu=0;
3280                                 do_weapon_select(0,0);
3281                                 /*
3282                                 for(i=MAX_PRIMARY_WEAPONS;i<MAX_PRIMARY_WEAPONS+NEWPRIMS;i++)
3283                                         if(primary_order[i]>primary_order[valu]&&player_has_weapon(i,0))
3284                                                 valu = i;
3285                                 LaserPowSelected = valu;
3286                                 */
3287                         }
3288                         //----------------Weapon 2----------------
3289                         if(key_down_count(kc_d2x[2].value) ||
3290                            (joy_get_button_state(kc_d2x[3].value) &&
3291                                 (d2x_joystick_state[1]!=d2x_joystick_ostate[1]) ) )
3292                                 do_weapon_select(1,0);
3293                         //----------------Weapon 3----------------
3294                         if(key_down_count(kc_d2x[4].value) ||
3295                            (joy_get_button_state(kc_d2x[5].value) &&
3296                                 (d2x_joystick_state[2]!=d2x_joystick_ostate[2]) ) )
3297                                 do_weapon_select(2,0);
3298                         //----------------Weapon 4----------------
3299                         if(key_down_count(kc_d2x[6].value) ||
3300                            (joy_get_button_state(kc_d2x[7].value) &&
3301                                 (d2x_joystick_state[3]!=d2x_joystick_ostate[3]) ) )
3302                                 do_weapon_select(3,0);
3303                         //----------------Weapon 5----------------
3304                         if(key_down_count(kc_d2x[8].value) ||
3305                            (joy_get_button_state(kc_d2x[9].value) &&
3306                                 (d2x_joystick_state[4]!=d2x_joystick_ostate[4]) ) )
3307                                 do_weapon_select(4,0);
3308  
3309                         //--------- Read secondary weapon select ----------
3310                         //----------------Weapon 6----------------
3311                         if(key_down_count(kc_d2x[10].value) ||
3312                            (joy_get_button_state(kc_d2x[11].value) &&
3313                                 (d2x_joystick_state[5]!=d2x_joystick_ostate[5]) ) )
3314                                 do_weapon_select(0,1);
3315                         //----------------Weapon 7----------------
3316                         if(key_down_count(kc_d2x[12].value) ||
3317                            (joy_get_button_state(kc_d2x[13].value) &&
3318                                 (d2x_joystick_state[6]!=d2x_joystick_ostate[6]) ) )
3319                                 do_weapon_select(1,1);
3320                         //----------------Weapon 8----------------
3321                         if(key_down_count(kc_d2x[14].value) ||
3322                            (joy_get_button_state(kc_d2x[15].value) &&
3323                                 (d2x_joystick_state[7]!=d2x_joystick_ostate[7]) ) )
3324                                 do_weapon_select(2,1);
3325                         //----------------Weapon 9----------------
3326                         if(key_down_count(kc_d2x[16].value) ||
3327                            (joy_get_button_state(kc_d2x[17].value) &&
3328                                 (d2x_joystick_state[8]!=d2x_joystick_ostate[8]) ) )
3329                                 do_weapon_select(3,1);
3330                         //----------------Weapon 0----------------
3331                         if(key_down_count(kc_d2x[18].value) ||
3332                            (joy_get_button_state(kc_d2x[19].value) &&
3333                                 (d2x_joystick_state[9]!=d2x_joystick_ostate[9]) ) )
3334                                 do_weapon_select(4,1);
3335                         memcpy(d2x_joystick_ostate,d2x_joystick_state,10*sizeof(int));
3336                 }
3337                 //end this section addition - VR
3338
3339
3340         }//end "if (!Player_is_dead)" - WraithX
3341 #endif
3342
3343
3344 //------------- Read slide_on -------------
3345         
3346         // From keyboard...
3347         if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ];
3348         if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ];
3349         // From joystick...
3350         if ((use_joystick)&&(kc_joystick[5].value<255)) slide_on |= joy_get_button_state( kc_joystick[5].value );
3351         // From mouse...
3352         if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1<<kc_mouse[5].value);
3353
3354 //------------- Read bank_on ---------------
3355
3356         // From keyboard...
3357         if ( kc_keyboard[18].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[18].value ];
3358         if ( kc_keyboard[19].value < 255 ) bank_on |= keyd_pressed[ kc_keyboard[19].value ];
3359         // From joystick...
3360         if ( (use_joystick)&&(kc_joystick[10].value < 255 )) bank_on |= joy_get_button_state( kc_joystick[10].value );
3361         // From mouse...
3362         if ( (use_mouse)&&(kc_mouse[10].value < 255 )) bank_on |= mouse_buttons & (1<<kc_mouse[10].value);
3363
3364 //------------ Read pitch_time -----------
3365         if ( !slide_on )        {
3366                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3367                 kp = 0;
3368                 k0 = speed_factor*key_down_time( kc_keyboard[0].value )/2;      // Divide by two since we want pitch to go slower
3369                 k1 = speed_factor*key_down_time( kc_keyboard[1].value )/2;
3370                 k2 = speed_factor*key_down_time( kc_keyboard[2].value )/2;
3371                 k3 = speed_factor*key_down_time( kc_keyboard[3].value )/2;
3372
3373                 // From keyboard...
3374                 if ( kc_keyboard[0].value < 255 ) kp += k0/PH_SCALE;
3375                 if ( kc_keyboard[1].value < 255 ) kp += k1/PH_SCALE;
3376                 if ( kc_keyboard[2].value < 255 ) kp -= k2/PH_SCALE;
3377                 if ( kc_keyboard[3].value < 255 ) kp -= k3/PH_SCALE;
3378
3379                 // From Cyberman...
3380                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3381                         kp += mouse_button_down_time(MB_PITCH_FORWARD)/(PH_SCALE*2);
3382                         kp -= mouse_button_down_time(MB_PITCH_BACKWARD)/(PH_SCALE*2);
3383                 }
3384         
3385                 if (kp == 0)
3386                         Controls.pitch_time = 0;
3387                 else if (kp > 0) {
3388                         if (Controls.pitch_time < 0)
3389                                 Controls.pitch_time = 0;
3390                 } else // kp < 0
3391                         if (Controls.pitch_time > 0)
3392                                 Controls.pitch_time = 0;
3393                 Controls.pitch_time += kp;
3394         
3395                 // From joystick...
3396                 if ( (use_joystick)&&(kc_joystick[13].value < 255 ))    {
3397                         if ( !kc_joystick[14].value )           // If not inverted...
3398                                 Controls.pitch_time -= (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3399                         else
3400                                 Controls.pitch_time += (joy_axis[kc_joystick[13].value]*Config_joystick_sensitivity)/8;
3401                 }
3402         
3403                 // From mouse...
3404                 //mprintf(( 0, "UM: %d, PV: %d\n", use_mouse, kc_mouse[13].value ));
3405                 if ( (use_mouse)&&(kc_mouse[13].value < 255) )  {
3406                         if ( !kc_mouse[14].value )              // If not inverted...
3407                                 Controls.pitch_time -= (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3408                         else
3409                                 Controls.pitch_time += (mouse_axis[kc_mouse[13].value]*Config_joystick_sensitivity)/8;
3410                 }
3411         } else {
3412                 Controls.pitch_time = 0;
3413         }
3414
3415
3416 //----------- Read vertical_thrust_time -----------------
3417
3418         if ( slide_on ) {
3419                 k0 = speed_factor*key_down_time( kc_keyboard[0].value );
3420                 k1 = speed_factor*key_down_time( kc_keyboard[1].value );
3421                 k2 = speed_factor*key_down_time( kc_keyboard[2].value );
3422                 k3 = speed_factor*key_down_time( kc_keyboard[3].value );
3423
3424                 // From keyboard...
3425                 if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0;
3426                 if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1;
3427                 if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2;
3428                 if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3;
3429
3430                 // From Cyberman...
3431                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3432                         Controls.vertical_thrust_time -= mouse_button_down_time(MB_PITCH_FORWARD);
3433                         Controls.vertical_thrust_time += mouse_button_down_time(MB_PITCH_BACKWARD);
3434                 }
3435         
3436                 // From joystick...
3437                 if ((use_joystick)&&( kc_joystick[13].value < 255 ))    {
3438                         if ( !kc_joystick[14].value )           // If not inverted...
3439                                 Controls.vertical_thrust_time += joy_axis[kc_joystick[13].value];
3440                         else
3441                                 Controls.vertical_thrust_time -= joy_axis[kc_joystick[13].value];
3442                 }
3443         
3444                 // From mouse...
3445                 if ( (use_mouse)&&(kc_mouse[13].value < 255 ))  {
3446                         if ( !kc_mouse[14].value )              // If not inverted...
3447                                 Controls.vertical_thrust_time -= mouse_axis[kc_mouse[13].value];
3448                         else
3449                                 Controls.vertical_thrust_time += mouse_axis[kc_mouse[13].value];
3450                 }
3451         }
3452
3453         // From keyboard...
3454         if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value );
3455         if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value );
3456         if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value );
3457         if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value );
3458         
3459         // From joystick...
3460         if ((use_joystick)&&( kc_joystick[19].value < 255 ))    {
3461                 if ( !kc_joystick[20].value )           // If not inverted...
3462                         Controls.vertical_thrust_time += joy_axis[kc_joystick[19].value];
3463                 else
3464                         Controls.vertical_thrust_time -= joy_axis[kc_joystick[19].value];
3465         }
3466
3467         // From joystick buttons
3468         if ( (use_joystick)&&(kc_joystick[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_joystick[8].value );
3469         if ( (use_joystick)&&(kc_joystick[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_joystick[9].value );
3470
3471         // From mouse buttons
3472         if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value );
3473         if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value );
3474
3475         // From mouse...
3476         if ( (use_mouse)&&(kc_mouse[19].value < 255 ))  {
3477                 if ( !kc_mouse[20].value )              // If not inverted...
3478                         Controls.vertical_thrust_time += mouse_axis[kc_mouse[19].value];
3479                 else
3480                         Controls.vertical_thrust_time -= mouse_axis[kc_mouse[19].value];
3481         }
3482
3483         // From Cyberman...
3484         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3485                 Controls.vertical_thrust_time += mouse_button_down_time(MB_Z_UP)/2;
3486                 Controls.vertical_thrust_time -= mouse_button_down_time(MB_Z_DOWN)/2;
3487         }
3488
3489 //---------- Read heading_time -----------
3490
3491         if (!slide_on && !bank_on)      {
3492                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
3493                 kh = 0;
3494                 k4 = speed_factor*key_down_time( kc_keyboard[4].value );
3495                 k5 = speed_factor*key_down_time( kc_keyboard[5].value );
3496                 k6 = speed_factor*key_down_time( kc_keyboard[6].value );
3497                 k7 = speed_factor*key_down_time( kc_keyboard[7].value );
3498
3499                 // From keyboard...
3500                 if ( kc_keyboard[4].value < 255 ) kh -= k4/PH_SCALE;
3501                 if ( kc_keyboard[5].value < 255 ) kh -= k5/PH_SCALE;
3502                 if ( kc_keyboard[6].value < 255 ) kh += k6/PH_SCALE;
3503                 if ( kc_keyboard[7].value < 255 ) kh += k7/PH_SCALE;
3504
3505                 // From Cyberman...
3506                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3507                         kh -= mouse_button_down_time(MB_HEAD_LEFT)/PH_SCALE;
3508                         kh += mouse_button_down_time(MB_HEAD_RIGHT)/PH_SCALE;
3509                 }
3510         
3511                 if (kh == 0)
3512                         Controls.heading_time = 0;
3513                 else if (kh > 0) {
3514                         if (Controls.heading_time < 0)
3515                                 Controls.heading_time = 0;
3516                 } else // kh < 0
3517                         if (Controls.heading_time > 0)
3518                                 Controls.heading_time = 0;
3519                 Controls.heading_time += kh;
3520
3521                 // From joystick...
3522                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3523                         if ( !kc_joystick[16].value )           // If not inverted...
3524                                 Controls.heading_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3525                         else
3526                                 Controls.heading_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3527                 }
3528         
3529                 // From mouse...
3530                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3531                         if ( !kc_mouse[16].value )              // If not inverted...
3532                                 Controls.heading_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3533                         else
3534                                 Controls.heading_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3535                 }
3536         } else {
3537                 Controls.heading_time = 0;
3538         }
3539
3540 //----------- Read sideways_thrust_time -----------------
3541
3542         if ( slide_on ) {
3543                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3544                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3545                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3546                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3547
3548                 // From keyboard...
3549                 if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0;
3550                 if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1;
3551                 if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2;
3552                 if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3;
3553         
3554                 // From joystick...
3555                 if ( (use_joystick)&&(kc_joystick[15].value < 255 ))    {
3556                         if ( !kc_joystick[16].value )           // If not inverted...
3557                                 Controls.sideways_thrust_time += joy_axis[kc_joystick[15].value];
3558                         else
3559                                 Controls.sideways_thrust_time -= joy_axis[kc_joystick[15].value];
3560                 }
3561                 
3562                 // From cyberman
3563                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3564                         Controls.sideways_thrust_time -= mouse_button_down_time(MB_HEAD_LEFT);
3565                         Controls.sideways_thrust_time += mouse_button_down_time(MB_HEAD_RIGHT);
3566                 }
3567         
3568                 // From mouse...
3569                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3570                         if ( !kc_mouse[16].value )              // If not inverted...
3571                                 Controls.sideways_thrust_time += mouse_axis[kc_mouse[15].value];
3572                         else
3573                                 Controls.sideways_thrust_time -= mouse_axis[kc_mouse[15].value];
3574                 }
3575         }
3576
3577         // From keyboard...
3578         if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value );
3579         if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value );
3580         if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value );
3581         if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value );
3582         
3583         // From joystick...
3584         if ( (use_joystick)&&(kc_joystick[17].value < 255 ))    {
3585                 if ( !kc_joystick[18].value )           // If not inverted...
3586                         Controls.sideways_thrust_time -= joy_axis[kc_joystick[17].value];
3587                 else
3588                         Controls.sideways_thrust_time += joy_axis[kc_joystick[17].value];
3589         }
3590
3591         // From joystick buttons
3592         if ( (use_joystick)&&(kc_joystick[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_joystick[6].value );
3593         if ( (use_joystick)&&(kc_joystick[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_joystick[7].value );
3594
3595         // From mouse buttons
3596         if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value );
3597         if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value );
3598
3599         // From mouse...
3600         if ( (use_mouse)&&(kc_mouse[17].value < 255 ))  {
3601                 if ( !kc_mouse[18].value )              // If not inverted...
3602                         Controls.sideways_thrust_time += mouse_axis[kc_mouse[17].value];
3603                 else
3604                         Controls.sideways_thrust_time -= mouse_axis[kc_mouse[17].value];
3605         }
3606
3607 //----------- Read bank_time -----------------
3608
3609         if ( bank_on )  {
3610                 k0 = speed_factor*key_down_time( kc_keyboard[4].value );
3611                 k1 = speed_factor*key_down_time( kc_keyboard[5].value );
3612                 k2 = speed_factor*key_down_time( kc_keyboard[6].value );
3613                 k3 = speed_factor*key_down_time( kc_keyboard[7].value );
3614
3615                 // From keyboard...
3616                 if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0;
3617                 if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1;
3618                 if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2;
3619                 if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3;
3620
3621                 // From Cyberman...
3622                 if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3623                         Controls.bank_time -= mouse_button_down_time(MB_HEAD_LEFT);
3624                         Controls.bank_time += mouse_button_down_time(MB_HEAD_RIGHT);
3625                 }
3626
3627                 // From joystick...
3628                 if ( (use_joystick)&&(kc_joystick[15].value < 255) )    {
3629                         if ( !kc_joystick[16].value )           // If not inverted...
3630                                 Controls.bank_time -= (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3631                         else
3632                                 Controls.bank_time += (joy_axis[kc_joystick[15].value]*Config_joystick_sensitivity)/8;
3633                 }
3634         
3635                 // From mouse...
3636                 if ( (use_mouse)&&(kc_mouse[15].value < 255 ))  {
3637                         if ( !kc_mouse[16].value )              // If not inverted...
3638                                 Controls.bank_time += (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3639                         else
3640                                 Controls.bank_time -= (mouse_axis[kc_mouse[15].value]*Config_joystick_sensitivity)/8;
3641                 }
3642         }
3643
3644         // From keyboard...
3645         if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value );
3646         if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value );
3647         if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value );
3648         if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value );
3649
3650         // From joystick...
3651         if ( (use_joystick)&&(kc_joystick[21].value < 255) )    {
3652                 if ( !kc_joystick[22].value )           // If not inverted...
3653                         Controls.bank_time -= joy_axis[kc_joystick[21].value];
3654                 else
3655                         Controls.bank_time += joy_axis[kc_joystick[21].value];
3656         }
3657
3658         // From joystick buttons
3659         if ( (use_joystick)&&(kc_joystick[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_joystick[11].value );
3660         if ( (use_joystick)&&(kc_joystick[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_joystick[12].value );
3661
3662         // From mouse buttons
3663         if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value );
3664         if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value );
3665
3666         // From mouse...
3667         if ( (use_mouse)&&(kc_mouse[21].value < 255 ))  {
3668                 if ( !kc_mouse[22].value )              // If not inverted...
3669                         Controls.bank_time += mouse_axis[kc_mouse[21].value];
3670                 else
3671                         Controls.bank_time -= mouse_axis[kc_mouse[21].value];
3672         }
3673
3674         // From Cyberman
3675         if ((use_mouse)&&(Config_control_type==CONTROL_CYBERMAN))       {
3676                 Controls.bank_time += mouse_button_down_time(MB_BANK_LEFT);
3677                 Controls.bank_time -= mouse_button_down_time(MB_BANK_RIGHT);
3678         }
3679
3680 //----------- Read forward_thrust_time -------------
3681
3682         // From keyboard...
3683         if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value );
3684         if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value );
3685         if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value );
3686         if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value );
3687
3688         // From joystick...
3689         if ( (use_joystick)&&(kc_joystick[23].value < 255 ))    {
3690                 if ( !kc_joystick[24].value )           // If not inverted...
3691                         Controls.forward_thrust_time -= joy_axis[kc_joystick[23].value];
3692                 else
3693                         Controls.forward_thrust_time += joy_axis[kc_joystick[23].value];
3694         }
3695
3696         // From joystick buttons
3697         if ( (use_joystick)&&(kc_joystick[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_joystick[2].value );
3698         if ( (use_joystick)&&(kc_joystick[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_joystick[3].value );
3699
3700         // From mouse...
3701         if ( (use_mouse)&&(kc_mouse[23].value < 255 ))  {
3702                 if ( !kc_mouse[24].value )              // If not inverted...
3703                         Controls.forward_thrust_time -= mouse_axis[kc_mouse[23].value];
3704                 else
3705                         Controls.forward_thrust_time += mouse_axis[kc_mouse[23].value];
3706         }
3707
3708         // From mouse buttons
3709         if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value );
3710         if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value );
3711
3712 //----------- Read afterburner_state -------------
3713
3714         // From keyboard...
3715         if ( kc_keyboard[46].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[46].value];
3716         if ( kc_keyboard[47].value < 255 ) Controls.afterburner_state |= keyd_pressed[kc_keyboard[47].value];
3717
3718         if ( (use_mouse)&&(kc_mouse[27].value < 255 )) Controls.afterburner_state |= mouse_button_state(kc_mouse[27].value);
3719
3720         if ( (use_joystick)&&(kc_joystick[27].value < 255 )) Controls.afterburner_state |= joy_get_button_state(kc_joystick[27].value);
3721
3722 //-------Read headlight key--------------------------
3723
3724         if (kc_keyboard[52].value < 255 )
3725                    Controls.headlight_count=key_down_count(kc_keyboard[52].value);
3726         if (kc_keyboard[53].value < 255 )
3727                    Controls.headlight_count+=key_down_count(kc_keyboard[53].value);
3728                   if ((use_joystick)&&(kc_joystick[30].value < 255 )) 
3729                Controls.headlight_count+=joy_get_button_down_cnt(kc_joystick[30].value);
3730
3731 //--------Read Cycle Primary Key------------------
3732
3733                   if (kc_keyboard[48].value<255)
3734                          Controls.cycle_primary_count=key_down_count(kc_keyboard[48].value);
3735                   if (kc_keyboard[49].value<255)
3736                         Controls.cycle_primary_count+=key_down_count(kc_keyboard[49].value);
3737              if ((use_joystick)&&(kc_joystick[28].value < 255 )) 
3738          Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_joystick[28].value);
3739
3740
3741 //--------Read Cycle Secondary Key------------------
3742
3743                   if (kc_keyboard[50].value<255)
3744                          Controls.cycle_secondary_count=key_down_count(kc_keyboard[50].value);
3745                   if (kc_keyboard[51].value<255)
3746                         Controls.cycle_secondary_count+=key_down_count(kc_keyboard[51].value);
3747              if ((use_joystick)&&(kc_joystick[29].value < 255 )) 
3748                         Controls.cycle_secondary_count=joy_get_button_down_cnt(kc_joystick[29].value);
3749
3750 //--------Read Toggle Bomb key----------------------
3751
3752                   if (kc_keyboard[56].value<255 && key_down_count(kc_keyboard[56].value))
3753          {
3754           int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
3755
3756                          if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
3757                                   !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
3758                            {
3759                                  digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3760                                  HUD_init_message ("No bombs available!");
3761                                 }
3762                          else
3763                                 {       
3764                                  if (Players[Player_num].secondary_ammo[bomb]==0)
3765                                         {
3766                                          digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
3767                                          HUD_init_message ("No %s available!",(bomb==SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
3768                                         }
3769                                   else
3770                                         {
3771                                Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
3772                                          digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
3773                                         }
3774                                 }
3775                         }
3776           
3777 //---------Read Energy->Shield key----------
3778
3779         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[54].value])
3780                 transfer_energy_to_shield(key_down_time(kc_keyboard[54].value));
3781         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && keyd_pressed[kc_keyboard[55].value])
3782                 transfer_energy_to_shield(key_down_time(kc_keyboard[55].value));
3783
3784 //----------- Read fire_primary_down_count
3785         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value);
3786         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value);
3787         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_joystick[0].value);
3788         if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value);
3789
3790 //----------- Read fire_primary_state
3791         if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value];
3792         if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value];
3793         if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_joystick[0].value);
3794         if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value);
3795
3796 //----------- Read fire_secondary_down_count
3797         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value);
3798         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value);
3799         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_joystick[1].value);
3800         if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value);
3801
3802 //----------- Read fire_secondary_state
3803         if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value];
3804         if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value];
3805         if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_joystick[1].value);
3806         if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value);
3807
3808 //----------- Read fire_flare_down_count
3809         if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value);
3810         if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value);
3811         if ((use_joystick)&&(kc_joystick[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_joystick[4].value);
3812         if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value);
3813
3814 //----------- Read drop_bomb_down_count
3815         if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value);
3816         if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value);
3817         if ((use_joystick)&&(kc_joystick[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_joystick[26].value);
3818         if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value);
3819
3820 //----------- Read rear_view_down_count
3821         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value);
3822         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value);
3823         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_joystick[25].value);
3824         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value);
3825
3826 //----------- Read rear_view_down_state
3827         if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value];
3828         if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value];
3829         if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_joystick[25].value);
3830         if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value);
3831
3832 //----------- Read automap_down_count
3833         if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value);
3834         if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value);
3835
3836 //----------- Read automap_state
3837         if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value];
3838         if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value];
3839
3840 //----------- Read stupid-cruise-control-type of throttle.
3841         {
3842                 if ( kc_keyboard[38].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[38].value)*5,FrameTime);
3843                 if ( kc_keyboard[39].value < 255 ) Cruise_speed += fixdiv(speed_factor*key_down_time(kc_keyboard[39].value)*5,FrameTime);
3844                 if ( kc_keyboard[40].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[40].value)*5,FrameTime);
3845                 if ( kc_keyboard[41].value < 255 ) Cruise_speed -= fixdiv(speed_factor*key_down_time(kc_keyboard[41].value)*5,FrameTime);
3846                 if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) )
3847                         Cruise_speed = 0;
3848                 if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) )
3849                         Cruise_speed = 0;
3850         
3851                 if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100);
3852                 if (Cruise_speed < 0 ) Cruise_speed = 0;
3853         
3854                 if (Controls.forward_thrust_time==0)
3855                         Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
3856         }
3857
3858 #if !defined(MACINTOSH)
3859         //read_head_tracker();
3860
3861         // Read external controls
3862         // if (kc_use_external_control || CybermouseActive)
3863         //      kconfig_read_external_controls();
3864 #endif
3865
3866 //----------- Clamp values between -FrameTime and FrameTime
3867         if (FrameTime > F1_0 )
3868                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
3869
3870         if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2;
3871         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
3872         if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime;
3873         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
3874         if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime;
3875         if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime;
3876 //      if (Controls.afterburner_time > FrameTime ) Controls.afterburner_time = FrameTime;
3877
3878         if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2;
3879         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
3880         if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime;
3881         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
3882         if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime;
3883         if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime;
3884 //      if (Controls.afterburner_time < -FrameTime ) Controls.afterburner_time = -FrameTime;
3885
3886
3887 //--------- Don't do anything if in debug mode
3888         #ifndef RELEASE
3889         if ( keyd_pressed[KEY_DELETE] ) {
3890                 memset( &Controls, 0, sizeof(control_info) );
3891         }
3892         #endif
3893 }
3894 #endif
3895
3896 void reset_cruise(void)
3897 {
3898         Cruise_speed=0;
3899 }
3900
3901
3902 void kc_set_controls()
3903 {
3904         int i;
3905
3906         for (i=0; i<NUM_KEY_CONTROLS; i++ )     
3907                 kc_keyboard[i].value = kconfig_settings[0][i];
3908
3909         if ( (Config_control_type>0) && (Config_control_type<5)) {
3910                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
3911                         kc_joystick[i].value = kconfig_settings[Config_control_type][i];
3912                         if (kc_joystick[i].type == BT_INVERT )  {
3913                                 if (kc_joystick[i].value!=1)
3914                                         kc_joystick[i].value    = 0;
3915                                 kconfig_settings[Config_control_type][i] = kc_joystick[i].value;
3916                         }
3917                 }
3918         } else if (Config_control_type>4 && Config_control_type<CONTROL_WINJOYSTICK) {
3919                 for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
3920                         kc_mouse[i].value = kconfig_settings[Config_control_type][i];
3921                         if (kc_mouse[i].type == BT_INVERT )     {
3922                                 if (kc_mouse[i].value!=1)
3923                                         kc_mouse[i].value       = 0;
3924                                 kconfig_settings[Config_control_type][i] = kc_mouse[i].value;
3925                         }
3926                 }
3927         } else if (Config_control_type == CONTROL_WINJOYSTICK) {
3928                 for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
3929                         kc_superjoy[i].value = kconfig_settings[Config_control_type][i];
3930                         if (kc_superjoy[i].type == BT_INVERT )  {
3931                                 if (kc_superjoy[i].value!=1)
3932                                         kc_superjoy[i].value    = 0;
3933                                 kconfig_settings[Config_control_type][i] = kc_superjoy[i].value;
3934                         }
3935                 }
3936         }
3937
3938 #ifdef D2X_KEYS
3939         for (i=0; i<NUM_D2X_CONTROLS; i++ )
3940                 kc_d2x[i].value = kconfig_d2x_settings[i];
3941 #endif
3942 }
3943
3944 #if 0 //ndef MACINTOSH  // no mac support for vr headset
3945
3946 void kconfig_center_headset()
3947 {
3948 #ifndef WINDOWS
3949         if (vfx1_installed)
3950                 vfx_center_headset();
3951 #endif
3952 //      } else if (iglasses_headset_installed)  {
3953 //      } else if (Victor_headset_installed)   {
3954 //      } else {
3955 //      }
3956
3957 }
3958
3959 #endif  // end of #ifndef MACINTOSH for kconfig_center_headset
3960
3961 void CybermouseAdjust ()
3962  {
3963 /*      if ( Player_num > -1 )  {
3964                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
3965                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
3966                 Auto_leveling_on = 0;
3967
3968                 if ( kc_external_version > 0 ) {                
3969                         vms_matrix tempm, ViewMatrix;
3970                         vms_angvec * Kconfig_abs_movement;
3971                         char * oem_message;
3972         
3973                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
3974         
3975                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
3976                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
3977                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
3978                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
3979                         }
3980                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
3981                         if (oem_message[0] != '\0' )
3982                                 HUD_init_message( oem_message );
3983                 }
3984         }*/
3985
3986         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
3987         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
3988         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
3989         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
3990         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
3991         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
3992 //      Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
3993 //      Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
3994         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
3995         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
3996         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
3997         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
3998         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
3999         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
4000 //      Controls.automap_down_count += kc_external_control->automap_down_count;
4001 //      Controls.automap_state |= kc_external_control->automap_state;
4002   } 
4003
4004 char GetKeyValue (char key)
4005   {
4006         mprintf ((0,"Returning %c!\n",kc_keyboard[(int)key].value));
4007         return (kc_keyboard[(int)key].value);
4008   }
4009
4010 #if !defined(MACINTOSH)
4011
4012
4013 extern object *obj_find_first_of_type (int);
4014 void kconfig_read_external_controls()
4015 {
4016         //union REGS r;
4017    int i;
4018
4019         if ( !kc_enable_external_control ) return;
4020
4021         if ( kc_external_version == 0 ) 
4022                 memset( kc_external_control, 0, sizeof(ext_control_info));
4023         else if ( kc_external_version > 0 )     {
4024         
4025                 if (kc_external_version>=4)
4026                         memset( kc_external_control, 0, sizeof(advanced_ext_control_info));
4027       else if (kc_external_version>0)     
4028                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 );
4029                 else if (kc_external_version>2)
4030                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof(vms_matrix) +4 );
4031
4032                 if ( kc_external_version > 1 ) {
4033                         // Write ship pos and angles to external controls...
4034                         ubyte *temp_ptr = (ubyte *)kc_external_control;
4035                         vms_vector *ship_pos;
4036                         vms_matrix *ship_orient;
4037                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
4038                         temp_ptr += sizeof(ext_control_info) + sizeof(vms_angvec) + 64;
4039                         ship_pos = (vms_vector *)temp_ptr;
4040                         temp_ptr += sizeof(vms_vector);
4041                         ship_orient = (vms_matrix *)temp_ptr;
4042                         // Fill in ship postion...
4043                         *ship_pos = Objects[Players[Player_num].objnum].pos;
4044                         // Fill in ship orientation...
4045                         *ship_orient = Objects[Players[Player_num].objnum].orient;
4046                 }
4047     if (kc_external_version>=4)
4048           {
4049            advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
4050  
4051       temp_ptr->headlight_state=(Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON);
4052                 temp_ptr->primary_weapon_flags=Players[Player_num].primary_weapon_flags;
4053                 temp_ptr->secondary_weapon_flags=Players[Player_num].secondary_weapon_flags;
4054       temp_ptr->current_primary_weapon=Primary_weapon;
4055       temp_ptr->current_secondary_weapon=Secondary_weapon;
4056
4057       temp_ptr->current_guidebot_command=Escort_goal_object;
4058
4059            temp_ptr->force_vector=ExtForceVec;
4060                 temp_ptr->force_matrix=ExtApplyForceMatrix;
4061            for (i=0;i<3;i++)
4062        temp_ptr->joltinfo[i]=ExtJoltInfo[i];  
4063       for (i=0;i<2;i++)
4064                    temp_ptr->x_vibrate_info[i]=ExtXVibrateInfo[i];
4065                 temp_ptr->x_vibrate_clear=ExtXVibrateClear;
4066            temp_ptr->game_status=ExtGameStatus;
4067    
4068       memset ((void *)&ExtForceVec,0,sizeof(vms_vector));
4069       memset ((void *)&ExtApplyForceMatrix,0,sizeof(vms_matrix));
4070       
4071       for (i=0;i<3;i++)
4072                  ExtJoltInfo[i]=0;
4073       for (i=0;i<2;i++)
4074                  ExtXVibrateInfo[i]=0;
4075       ExtXVibrateClear=0;
4076      }
4077         }
4078
4079         if ( Automap_active )                   // (If in automap...)
4080                 kc_external_control->automap_state = 1;
4081         //memset(&r,0,sizeof(r));
4082
4083   #if 0
4084  
4085         int386 ( kc_external_intno, &r, &r);            // Read external info...
4086
4087   #endif 
4088
4089         if ( Player_num > -1 )  {
4090                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
4091                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
4092                 Auto_leveling_on = 0;
4093
4094                 if ( kc_external_version > 0 ) {                
4095                         vms_matrix tempm, ViewMatrix;
4096                         vms_angvec * Kconfig_abs_movement;
4097                         char * oem_message;
4098         
4099                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(ext_control_info));
4100         
4101                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
4102                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
4103                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
4104                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
4105                         }
4106                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
4107                         if (oem_message[0] != '\0' )
4108                                 HUD_init_message( oem_message );
4109                 }
4110         }
4111
4112         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
4113         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
4114         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
4115         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
4116         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
4117         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
4118         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
4119         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
4120         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
4121         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
4122         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
4123         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
4124         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
4125         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
4126         Controls.automap_down_count += kc_external_control->automap_down_count;
4127         Controls.automap_state |= kc_external_control->automap_state;
4128         
4129    if (kc_external_version>=3)
4130          {
4131                 ubyte *temp_ptr = (ubyte *)kc_external_control;
4132                 temp_ptr += (sizeof(ext_control_info) + sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof (vms_matrix));
4133   
4134            if (*(temp_ptr))
4135                  Controls.cycle_primary_count=(*(temp_ptr));
4136            if (*(temp_ptr+1))
4137                  Controls.cycle_secondary_count=(*(temp_ptr+1));
4138
4139                 if (*(temp_ptr+2))
4140                  Controls.afterburner_state=(*(temp_ptr+2));
4141                 if (*(temp_ptr+3))
4142                  Controls.headlight_count=(*(temp_ptr+3));
4143          }
4144    if (kc_external_version>=4)
4145          {
4146      int i;
4147           advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
4148      
4149      for (i=0;i<128;i++)
4150            if (temp_ptr->keyboard[i])
4151                         key_putkey (i);
4152
4153      if (temp_ptr->Reactor_blown)
4154       {
4155        if (Game_mode & GM_MULTI)
4156                     net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
4157                  else
4158                          do_controlcen_destroyed_stuff(obj_find_first_of_type (OBJ_CNTRLCEN));
4159            }
4160     }
4161   
4162 }
4163 #endif
4164