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