]> icculus.org git repositories - btb/d2x.git/blob - main/kconfig.c
separate control type into separate cvars for joy and mouse
[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 "inferno.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 * joyaxis_text[4] = { "X1", "Y1", "X2", "Y2" };
93 //char * mouseaxis_text[2] = { "L/R", "F/B" };
94
95 int invert_text[2] = { TNUM_N, TNUM_Y };
96
97 #ifndef USE_LINUX_JOY
98 #if defined(SDL_INPUT)
99 char *joyaxis_text[JOY_MAX_AXES];
100 #else
101         int joyaxis_text[7] = { TNUM_X1, TNUM_Y1, TNUM_Z1, TNUM_UN, TNUM_P1,TNUM_R1,TNUM_YA1 };
102 //      int joyaxis_text[4] = { TNUM_X1, TNUM_Y1, TNUM_X2, TNUM_Y2 };
103 #endif
104 #endif
105
106 int mouseaxis_text[3] = { TNUM_L_R, TNUM_F_B, TNUM_Z1 };
107
108 #if !defined OGL && !defined SDL_INPUT
109 char * key_text[256] = {         \
110 "","ESC","1","2","3","4","5","6","7","8","9","0","-",                   \
111 "=","BSPC","TAB","Q","W","E","R","T","Y","U","I","O",                           \
112 "P","[","]","\x83","LCTRL","A","S","D","F",        \
113 "G","H","J","K","L",";","'","`",        \
114 "LSHFT","\\","Z","X","C","V","B","N","M",",",      \
115 ".","/","RSHFT","PAD*","LALT","SPC",      \
116 "CPSLK","F1","F2","F3","F4","F5","F6","F7","F8","F9",        \
117 "F10","NMLCK","SCLK","PAD7","PAD8","PAD9","PAD-",   \
118 "PAD4","PAD5","PAD6","PAD+","PAD1","PAD2","PAD3","PAD0", \
119 "PAD.","","","","F11","F12","","","","","","","","","",         \
120 "","","","","","","","","","","","","","","","","","","","",     \
121 "","","","","","","","","","","","","","","","","","","","",     \
122 "","","","","","","","","","","","","","","","","","",           \
123 "PAD\x83","RCTRL","","","","","","","","","","","","","", \
124 "","","","","","","","","","","PAD/","","","RALT","",      \
125 "","","","","","","","","","","","","","HOME","\x82","PGUP",     \
126 "","\x81","","\x7f","","END","\x80","PGDN","INS",       \
127 "DEL","","","","","","","","","","","","","","","","","",     \
128 "","","","","","","","","","","","","","","","","","","","",     \
129 "","","","","","","" };
130 #endif /* OGL */
131
132 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 };
133
134 //extern void GameLoop(int, int );
135
136 extern void transfer_energy_to_shield(fix);
137 extern void CyclePrimary(),CycleSecondary(),InitMarkerInput();
138 extern ubyte DefiningMarkerMessage;
139 extern char CybermouseActive;
140
141 control_info Controls;
142
143 fix Cruise_speed=0;
144
145 // macros for drawing lo/hi res kconfig screens (see scores.c as well)
146
147 #define LHX(x)          ((x)*(MenuHires?2:1))
148 #define LHY(y)          ((y)*(MenuHires?2.4:1))
149
150
151 #define BT_KEY                          0
152 //#define BT_MOUSE_BUTTON       1
153 #define BT_MOUSE_AXIS           2
154 //#define BT_JOY_BUTTON                 3
155 #define BT_JOY_AXIS                     4
156 #define BT_INVERT                               5
157
158 char *btype_text[] = { "BT_KEY", "BT_MOUSE_BUTTON", "BT_MOUSE_AXIS", "BT_JOY_BUTTON", "BT_JOY_AXIS", "BT_INVERT" };
159
160 #define INFO_Y 28
161
162 typedef struct kc_item {
163         short id;                               // The id of this item
164         short x, y;                             
165         short w1;
166         short w2;
167         short u,d,l,r;
168         //short text_num1;
169         char *text;
170         ubyte type;
171         ubyte value;            // what key,button,etc
172 } kc_item;
173
174 int Num_items=28;
175 kc_item *All_items;
176
177
178 //----------- WARNING!!!!!!! -------------------------------------------
179 // THESE NEXT FOUR BLOCKS OF DATA ARE GENERATED BY PRESSING DEL+F12 WHEN
180 // IN THE KEYBOARD CONFIG SCREEN.  BASICALLY, THAT PROCEDURE MODIFIES THE
181 // U,D,L,R FIELDS OF THE ARRAYS AND DUMPS THE NEW ARRAYS INTO KCONFIG.COD
182 //-------------------------------------------------------------------------
183
184 kc_item kc_keyboard[NUM_KEY_CONTROLS] = {
185         {  0, 15, 49, 71, 26, 55,  2, 55,  1,"Pitch forward", BT_KEY, 255 },
186         {  1, 15, 49,100, 26, 50,  3,  0, 24,"Pitch forward", BT_KEY, 255 },
187         {  2, 15, 57, 71, 26,  0,  4, 25,  3,"Pitch backward", BT_KEY, 255 },
188         {  3, 15, 57,100, 26,  1,  5,  2, 26,"Pitch backward", BT_KEY, 255 },
189         {  4, 15, 65, 71, 26,  2,  6, 27,  5,"Turn left", BT_KEY, 255 },
190         {  5, 15, 65,100, 26,  3,  7,  4, 28,"Turn left", BT_KEY, 255 },
191         {  6, 15, 73, 71, 26,  4,  8, 29,  7,"Turn right", BT_KEY, 255 },
192         {  7, 15, 73,100, 26,  5,  9,  6, 34,"Turn right", BT_KEY, 255 },
193         {  8, 15, 85, 71, 26,  6, 10, 35,  9,"Slide on", BT_KEY, 255 },
194         {  9, 15, 85,100, 26,  7, 11,  8, 36,"Slide on", BT_KEY, 255 },
195         { 10, 15, 93, 71, 26,  8, 12, 37, 11,"Slide left", BT_KEY, 255 },
196         { 11, 15, 93,100, 26,  9, 13, 10, 44,"Slide left", BT_KEY, 255 },
197         { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 },
198         { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 },
199         { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 },
200         { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 },
201         { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 },
202         { 17, 15,117,100, 26, 15, 19, 16, 46,"Slide down", BT_KEY, 255 },
203         { 18, 15,129, 71, 26, 16, 20, 47, 19,"Bank on", BT_KEY, 255 },
204         { 19, 15,129,100, 26, 17, 21, 18, 38,"Bank on", BT_KEY, 255 },
205         { 20, 15,137, 71, 26, 18, 22, 39, 21,"Bank left", BT_KEY, 255 },
206         { 21, 15,137,100, 26, 19, 23, 20, 40,"Bank left", BT_KEY, 255 },
207         { 22, 15,145, 71, 26, 20, 48, 41, 23,"Bank right", BT_KEY, 255 },
208         { 23, 15,145,100, 26, 21, 49, 22, 42,"Bank right", BT_KEY, 255 },
209         { 24,158, 49, 83, 26, 51, 26,  1, 25,"Fire primary", BT_KEY, 255 },
210         { 25,158, 49,112, 26, 54, 27, 24,  2,"Fire primary", BT_KEY, 255 },
211         { 26,158, 57, 83, 26, 24, 28,  3, 27,"Fire secondary", BT_KEY, 255 },
212         { 27,158, 57,112, 26, 25, 29, 26,  4,"Fire secondary", BT_KEY, 255 },
213         { 28,158, 65, 83, 26, 26, 34,  5, 29,"Fire flare", BT_KEY, 255 },
214         { 29,158, 65,112, 26, 27, 35, 28,  6,"Fire flare", BT_KEY, 255 },
215         { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 },
216         { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 },
217         { 32,158,113, 83, 26, 30, 46, 15, 33,"reverse", BT_KEY, 255 },
218         { 33,158,113,112, 26, 31, 47, 32, 16,"reverse", BT_KEY, 255 },
219         { 34,158, 73, 83, 26, 28, 36,  7, 35,"Drop Bomb", BT_KEY, 255 },
220         { 35,158, 73,112, 26, 29, 37, 34,  8,"Drop Bomb", BT_KEY, 255 },
221         { 36,158, 85, 83, 26, 34, 44,  9, 37,"REAR VIEW", BT_KEY, 255 },
222         { 37,158, 85,112, 26, 35, 45, 36, 10,"REAR VIEW", BT_KEY, 255 },
223         { 38,158,133, 83, 26, 46, 40, 19, 39,"Cruise Faster", BT_KEY, 255 },
224         { 39,158,133,112, 26, 47, 41, 38, 20,"Cruise Faster", BT_KEY, 255 },
225         { 40,158,141, 83, 26, 38, 42, 21, 41,"Cruise Slower", BT_KEY, 255 },
226         { 41,158,141,112, 26, 39, 43, 40, 22,"Cruise Slower", BT_KEY, 255 },
227         { 42,158,149, 83, 26, 40, 52, 23, 43,"Cruise Off", BT_KEY, 255 },
228         { 43,158,149,112, 26, 41, 53, 42, 48,"Cruise Off", BT_KEY, 255 },
229         { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 },
230         { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 },
231         { 46,158,121, 83, 26, 32, 38, 17, 47,"Afterburner", BT_KEY, 255 },
232         { 47,158,121,112, 26, 33, 39, 46, 18,"Afterburner", BT_KEY, 255 },
233         { 48, 15,161, 71, 26, 22, 50, 43, 49,"Cycle Primary", BT_KEY, 255 },
234         { 49, 15,161,100, 26, 23, 51, 48, 52,"Cycle Primary", BT_KEY, 255 },
235         { 50, 15,169, 71, 26, 48,  1, 53, 51,"Cycle Second", BT_KEY, 255 },
236         { 51, 15,169,100, 26, 49, 24, 50, 54,"Cycle Second", BT_KEY, 255 },
237         { 52,158,163, 83, 26, 42, 54, 49, 53,"Headlight", BT_KEY, 255 },
238         { 53,158,163,112, 26, 43, 55, 52, 50,"Headlight", BT_KEY, 255 },
239         { 54,158,171, 83, 26, 52, 56, 51, 55,"Energy->Shield", BT_KEY, 255 },
240         { 55,158,171,112, 26, 53,  0, 54,  0,"Energy->Shield", BT_KEY, 255 },
241         { 56,158,179, 83, 26, 54,  0,  0,  0,"Toggle Bomb", BT_KEY, 255 },
242 };
243
244 char *kc_key_bind_text[NUM_KEY_CONTROLS] = {
245         "+lookdown",    "+lookdown",
246         "+lookup",      "+lookup",
247         "+left",        "+left",
248         "+right",       "+right",
249         "+strafe",      "+strafe",
250         "+moveleft",    "+moveleft",
251         "+moveright",   "+moveright",
252         "+moveup",      "+moveup",
253         "+movedown",    "+movedown",
254         "+bank",        "+bank",
255         "+bankleft",    "+bankleft",
256         "+bankright",   "+bankright",
257         "+attack",      "+attack",
258         "+attack2",     "+attack2",
259         "+flare",       "+flare",
260         "+forward",     "+forward",
261         "+back",        "+back",
262         "+bomb",        "+bomb",
263         "+rearview",    "+rearview",
264         "+cruiseup",    "+cruiseup",
265         "+cruisedown",  "+cruisedown",
266         "+cruiseoff",   "+cruiseoff",
267         "+automap",     "+automap",
268         "+afterburner", "+afterburner",
269         "+cycle",       "+cycle",
270         "+cycle2",      "+cycle2",
271         "+headlight",   "+headlight",
272         "+nrgshield",   "+nrgshield",
273         "+togglebomb",
274 };
275
276 ubyte default_kc_keyboard_settings[MAX_CONTROLS] = {0x48,0xc8,0x50,0xd0,0x4b,0xcb,0x4d,0xcd,0x38,0xff,0x4f,0xff,0x51,0xff,0x4a,0xff,0x4e,0xff,0x2a,0xff,0x10,0x47,0x12,0x49,0x1d,0x80,0x39,0x81,0x21,0x24,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,0x80,0x0,0x0};
277
278 kc_item kc_other[NUM_OTHER_CONTROLS] = {
279         {  0, 22,138, 51, 40, 23,  2, 23,  1,"Pitch U/D", BT_JOY_AXIS, 255 },
280         {  1, 22,138, 99,  8, 10,  3,  0, 12,"Pitch U/D", BT_INVERT, 255 },
281         {  2, 22,146, 51, 40,  0,  4, 13,  3,"Turn L/R", BT_JOY_AXIS, 255 },
282         {  3, 22,146, 99,  8,  1,  5,  2, 14,"Turn L/R", BT_INVERT, 255 },
283         {  4, 22,154, 51, 40,  2,  6, 15,  5,"Slide L/R", BT_JOY_AXIS, 255 },
284         {  5, 22,154, 99,  8,  3,  7,  4, 16,"Slide L/R", BT_INVERT, 255 },
285         {  6, 22,162, 51, 40,  4,  8, 17,  7,"Slide U/D", BT_JOY_AXIS, 255 },
286         {  7, 22,162, 99,  8,  5,  9,  6, 18,"Slide U/D", BT_INVERT, 255 },
287         {  8, 22,170, 51, 40,  6, 10, 19,  9,"Bank L/R", BT_JOY_AXIS, 255 },
288         {  9, 22,170, 99,  8,  7, 11,  8, 20,"Bank L/R", BT_INVERT, 255 },
289         { 10, 22,182, 51, 40,  8,  1, 21, 11,"throttle", BT_JOY_AXIS, 255 },
290         { 11, 22,182, 99,  8,  9, 12, 10, 22,"throttle", BT_INVERT, 255 },
291         { 12,182,138, 51, 40, 11, 14,  1, 13,"Pitch U/D", BT_MOUSE_AXIS, 255 },
292         { 13,182,138, 99,  8, 22, 15, 12,  2,"Pitch U/D", BT_INVERT, 255 },
293         { 14,182,146, 51, 40, 12, 16,  3, 15,"Turn L/R", BT_MOUSE_AXIS, 255 },
294         { 15,182,146, 99,  8, 13, 17, 14,  4,"Turn L/R", BT_INVERT, 255 },
295         { 16,182,154, 51, 40, 14, 18,  5, 17,"Slide L/R", BT_MOUSE_AXIS, 255 },
296         { 17,182,154, 99,  8, 15, 19, 16,  6,"Slide L/R", BT_INVERT, 255 },
297         { 18,182,162, 51, 40, 16, 20,  7, 19,"Slide U/D", BT_MOUSE_AXIS, 255 },
298         { 19,182,162, 99,  8, 17, 21, 18,  8,"Slide U/D", BT_INVERT, 255 },
299         { 20,182,170, 51, 40, 18, 22,  9, 21,"Bank L/R", BT_MOUSE_AXIS, 255 },
300         { 21,182,170, 99,  8, 19, 23, 20, 10,"Bank L/R", BT_INVERT, 255 },
301         { 22,182,182, 51, 40, 20, 13, 11, 23,"throttle", BT_MOUSE_AXIS, 255 },
302         { 23,182,182, 99,  8, 21,  0, 22,  0,"throttle", BT_INVERT, 255 },
303 };
304
305 kc_axis_map kc_other_axismap[NUM_OTHER_CONTROLS] = {
306         AXIS_PITCH,     AXIS_NONE,
307         AXIS_TURN,      AXIS_NONE,
308         AXIS_LEFTRIGHT, AXIS_NONE,
309         AXIS_UPDOWN,    AXIS_NONE,
310         AXIS_BANK,      AXIS_NONE,
311         AXIS_THROTTLE,  AXIS_NONE,
312         AXIS_PITCH,     AXIS_NONE,
313         AXIS_TURN,      AXIS_NONE,
314         AXIS_LEFTRIGHT, AXIS_NONE,
315         AXIS_UPDOWN,    AXIS_NONE,
316         AXIS_BANK,      AXIS_NONE,
317         AXIS_THROTTLE,  AXIS_NONE,
318 };
319
320 ubyte default_kc_other_settings[MAX_CONTROLS] = {0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x1,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x2,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x3f};
321
322 kc_item kc_d2x[NUM_D2X_CONTROLS] = {
323 //        id,x,y,w1,w2,u,d,l,r,text_num1,type,value
324         {  0, 15, 49, 71, 26, 19,  2, 27,  1,"WEAPON 1", BT_KEY, 255 },
325         {  1, 15, 49,100, 26, 18,  3,  0,  2,"WEAPON 1", BT_KEY, 255 },
326         {  2, 15, 57, 71, 26,  0,  4,  1,  3,"WEAPON 2", BT_KEY, 255 },
327         {  3, 15, 57,100, 26,  1,  5,  2,  4,"WEAPON 2", BT_KEY, 255 },
328         {  4, 15, 65, 71, 26,  2,  6,  3,  5,"WEAPON 3", BT_KEY, 255 },
329         {  5, 15, 65,100, 26,  3,  7,  4,  6,"WEAPON 3", BT_KEY, 255 },
330         {  6, 15, 73, 71, 26,  4,  8,  5,  7,"WEAPON 4", BT_KEY, 255 },
331         {  7, 15, 73,100, 26,  5,  9,  6,  8,"WEAPON 4", BT_KEY, 255 },
332         {  8, 15, 81, 71, 26,  6, 10,  7,  9,"WEAPON 5", BT_KEY, 255 },
333         {  9, 15, 81,100, 26,  7, 11,  8, 10,"WEAPON 5", BT_KEY, 255 },
334         { 10, 15, 89, 71, 26,  8, 12,  9, 11,"WEAPON 6", BT_KEY, 255 },
335         { 11, 15, 89,100, 26,  9, 13, 10, 12,"WEAPON 6", BT_KEY, 255 },
336         { 12, 15, 97, 71, 26, 10, 14, 11, 13,"WEAPON 7", BT_KEY, 255 },
337         { 13, 15, 97,100, 26, 11, 15, 12, 14,"WEAPON 7", BT_KEY, 255 },
338         { 14, 15,105, 71, 26, 12, 16, 13, 15,"WEAPON 8", BT_KEY, 255 },
339         { 15, 15,105,100, 26, 13, 17, 14, 16,"WEAPON 8", BT_KEY, 255 },
340         { 16, 15,113, 71, 26, 14, 18, 15, 17,"WEAPON 9", BT_KEY, 255 },
341         { 17, 15,113,100, 26, 15, 19, 16, 18,"WEAPON 9", BT_KEY, 255 },
342         { 18, 15,121, 71, 26, 16,  1, 17, 19,"WEAPON 0", BT_KEY, 255 },
343         { 19, 15,121,100, 26, 17,  0, 18,  0,"WEAPON 0", BT_KEY, 255 },
344         //{ 20, 15,131, 71, 26, 18, 22, 19, 21, "CYC PRIMARY", BT_KEY, 255},
345         //{ 21, 15,131,100, 26, 19, 23, 20, 22, "CYC PRIMARY", BT_KEY, 255},
346         //{ 22, 15,139, 71, 26, 20, 24, 21, 23, "CYC SECONDARY", BT_KEY, 255},
347         //{ 23, 15,139,100, 26, 21, 25, 22, 24, "CYC SECONDARY", BT_KEY, 255},
348         //{ 24,  8,147, 78, 26, 22, 26, 23, 25, "TOGGLE_PRIM AUTO", BT_KEY, 255},
349         //{ 25,  8,147,107, 26, 23, 27, 24, 26, "TOGGLE_PRIM_AUTO", BT_KEY, 255},
350         //{ 26,  8,155, 78, 26, 24,  1, 25, 27, "TOGGLE SEC AUTO", BT_KEY, 255},
351         //{ 27,  8,155,107, 26, 25,  0, 26,  0, "TOGGLE SEC AUTO", BT_KEY, 255},
352 };
353
354 ubyte default_kc_d2x_settings[MAX_CONTROLS] = {0x2,0xff,0x3,0xff,0x4,0xff,0x5,0xff,0x6,0xff,0x7,0xff,0x8,0xff,0x9,0xff,0xa,0xff,0xb,0xff,0xff,0x0,0xff,0xff,0x12,0xf,0x80,0x80,0x80,0x0,0x4,0x4,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x20,0x57,0x52,0x0,0x12,0xa2,0xa2,0xa4,0xa4,0xa4,0xa4,0xa4,0x0,0x0,0x0,0x0,0x0,0x0,0xff,0xff,0xff};
355
356
357 void kc_drawitem( kc_item *item, int is_current );
358 void kc_change_key( kc_item * item );
359 void kc_next_joyaxis(kc_item *item);  //added by WraithX on 11/22/00
360 void kc_change_joyaxis( kc_item * item );
361 void kc_change_mouseaxis( kc_item * item );
362 void kc_change_invert( kc_item * item );
363 void kconfig_read_external_controls( void );
364
365 int kconfig_is_axes_used(int axis)
366 {
367         int i;
368         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
369                 if (( kc_other[i].type == BT_JOY_AXIS ) && (kc_other[i].value == axis ))
370                         return 1;
371         }
372         return 0;
373 }
374
375 #ifdef TABLE_CREATION
376 int find_item_at( kc_item * items, int nitems, int x, int y )
377 {
378         int i;
379         
380         for (i=0; i<nitems; i++ )       {
381                 if ( ((items[i].x+items[i].w1)==x) && (items[i].y==y))
382                         return i;
383         }
384         return -1;
385 }
386
387 int find_next_item_up( kc_item * items, int nitems, int citem )
388 {
389         int x, y, i;
390
391         y = items[citem].y;
392         x = items[citem].x+items[citem].w1;
393         
394         do {    
395                 y--;
396                 if ( y < 0 ) {
397                         y = grd_curcanv->cv_bitmap.bm_h-1;
398                         x--;
399                         if ( x < 0 ) {
400                                 x = grd_curcanv->cv_bitmap.bm_w-1;
401                         }
402                 }
403                 i = find_item_at( items, nitems, x, y );
404         } while ( i < 0 );
405         
406         return i;
407 }
408
409 int find_next_item_down( kc_item * items, int nitems, int citem )
410 {
411         int x, y, i;
412
413         y = items[citem].y;
414         x = items[citem].x+items[citem].w1;
415         
416         do {    
417                 y++;
418                 if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
419                         y = 0;
420                         x++;
421                         if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
422                                 x = 0;
423                         }
424                 }
425                 i = find_item_at( items, nitems, x, y );
426         } while ( i < 0 );
427         
428         return i;
429 }
430
431 int find_next_item_right( kc_item * items, int nitems, int citem )
432 {
433         int x, y, i;
434
435         y = items[citem].y;
436         x = items[citem].x+items[citem].w1;
437         
438         do {    
439                 x++;
440                 if ( x > grd_curcanv->cv_bitmap.bm_w-1 ) {
441                         x = 0;
442                         y++;
443                         if ( y > grd_curcanv->cv_bitmap.bm_h-1 ) {
444                                 y = 0;
445                         }
446                 }
447                 i = find_item_at( items, nitems, x, y );
448         } while ( i < 0 );
449         
450         return i;
451 }
452
453 int find_next_item_left( kc_item * items, int nitems, int citem )
454 {
455         int x, y, i;
456
457         y = items[citem].y;
458         x = items[citem].x+items[citem].w1;
459         
460         do {    
461                 x--;
462                 if ( x < 0 ) {
463                         x = grd_curcanv->cv_bitmap.bm_w-1;
464                         y--;
465                         if ( y < 0 ) {
466                                 y = grd_curcanv->cv_bitmap.bm_h-1;
467                         }
468                 }
469                 i = find_item_at( items, nitems, x, y );
470         } while ( i < 0 );
471         
472         return i;
473 }
474 #endif
475
476 #ifdef NEWMENU_MOUSE
477 int get_item_height(kc_item *item)
478 {
479         int w, h, aw;
480         char btext[10];
481
482         if (item->value==255) {
483                 strcpy(btext, "");
484         } else {
485                 switch( item->type )    {
486                         case BT_KEY:
487                                 strncpy( btext, key_text[item->value], 10 ); break;
488                         case BT_MOUSE_AXIS:
489                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
490                         case BT_JOY_AXIS:
491 #ifdef USE_LINUX_JOY
492                                 sprintf( btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number (item->value) );
493 #elif defined(SDL_INPUT)
494                                 if (joyaxis_text[item->value])
495                                         strncpy(btext, joyaxis_text[item->value], 10);
496                                 else
497                                         sprintf(btext, "AXIS%2d", item->value + 1);
498 #else
499                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
500 #endif
501                                 break;
502                         case BT_INVERT:
503                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
504                 }
505         }
506         gr_get_string_size(btext, &w, &h, &aw  );
507
508         return h;
509 }
510 #endif
511
512 void kconfig_sub(kc_item * items,int nitems, char * title)
513 {
514         grs_canvas * save_canvas;
515         grs_font * save_font;
516         int old_keyd_repeat;
517 #ifdef NEWMENU_MOUSE
518         int mouse_state, omouse_state, mx, my, x1, x2, y1, y2;
519         int close_x, close_y, close_size;
520 #endif
521
522         int i,k,ocitem,citem;
523         int time_stopped = 0;
524
525         All_items = items;
526         Num_items = nitems;
527
528         if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence)) )
529         {
530                 time_stopped = 1;
531                 stop_time();
532         }
533
534         save_canvas = grd_curcanv;
535
536
537         gr_set_current_canvas(NULL);
538         save_font = grd_curcanv->cv_font;
539
540         game_flush_inputs();
541         old_keyd_repeat = keyd_repeat;
542         keyd_repeat = 1;
543
544         //gr_clear_canvas( BM_XRGB(0,0,0) );
545
546         nm_draw_background(0, 0, grd_curcanv->cv_bitmap.bm_w - 1, grd_curcanv->cv_bitmap.bm_h - 1);
547    gr_palette_load (gr_palette);
548
549         grd_curcanv->cv_font = MEDIUM3_FONT;
550
551         {
552                 char * p;
553                 p = strchr( title, '\n' );
554                 if ( p ) *p = 32;
555                 gr_string( 0x8000, LHY(8), title );
556                 if ( p ) *p = '\n';
557         }
558
559
560 //      if ( items == kc_keyboard )     {
561 //              gr_string( 0x8000, 8, "Keyboard" );
562 //      } else if ( items == kc_other ) {
563 //              gr_string( 0x8000, 8, "Others" );
564 //      }
565
566 #ifdef NEWMENU_MOUSE
567         close_x = close_y = MenuHires?15:7;
568         close_size = MenuHires?10:5;
569         /*
570         gr_setcolor( BM_XRGB(0, 0, 0) );
571         gr_rect(close_x, close_y, close_x + close_size, close_y + close_size);
572         gr_setcolor( BM_XRGB(21, 21, 21) );
573         gr_rect(close_x + LHX(1), close_y + LHX(1), close_x + close_size - LHX(1), close_y + close_size - LHX(1));
574         */
575 #endif
576
577         grd_curcanv->cv_font = GAME_FONT;
578         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
579
580         gr_string( 0x8000, LHY(20), TXT_KCONFIG_STRING_1 );
581         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
582         if ( items == kc_keyboard )     {
583                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
584                 gr_setcolor( BM_XRGB(31,27,6) );
585                 
586                 gr_scanline( LHX(98), LHX(106), LHY(42) );
587                 gr_scanline( LHX(120), LHX(128), LHY(42) );
588                 gr_pixel( LHX(98), LHY(43) );                                           
589                 gr_pixel( LHX(98), LHY(44) );                                           
590                 gr_pixel( LHX(128), LHY(43) );                                          
591                 gr_pixel( LHX(128), LHY(44) );                                          
592                 
593                 gr_string( LHX(109), LHY(40), "OR" );
594
595                 gr_scanline( LHX(253), LHX(261), LHY(42) );
596                 gr_scanline( LHX(274), LHX(283), LHY(42) );
597                 gr_pixel( LHX(253), LHY(43) );                                          
598                 gr_pixel( LHX(253), LHY(44) );                                          
599                 gr_pixel( LHX(283), LHY(43) );                                          
600                 gr_pixel( LHX(283), LHY(44) );                                          
601
602                 gr_string( LHX(264), LHY(40), "OR" );
603
604         } if ( items == kc_other )      {
605                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
606                 gr_setcolor( BM_XRGB(31,27,6) );
607                 gr_scanline( LHX(18), LHX(60), LHY(119+5) );
608                 gr_scanline( LHX(102), LHX(144), LHY(119+5) );
609                 gr_string( LHX(63), LHY(117+5), TXT_CONTROL_JOYSTICK );
610                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
611                 gr_string( LHX(84), LHY(129), TXT_AXIS );
612                 gr_string( LHX(110), LHY(129), TXT_INVERT );
613
614                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
615                 gr_setcolor( BM_XRGB(31,27,6) );
616                 gr_scanline( LHX(178), LHX(226), LHY(119+5) );
617                 gr_scanline( LHX(256), LHX(304), LHY(119+5) );
618                 gr_string( LHX(229), LHY(117+5), TXT_CONTROL_MOUSE );
619                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
620                 gr_string( LHX(244), LHY(129), TXT_AXIS );
621                 gr_string( LHX(270), LHY(129), TXT_INVERT );
622         }
623         else if ( items == kc_d2x )
624         {
625                 gr_set_fontcolor( BM_XRGB(31,27,6), -1 );
626                 gr_setcolor( BM_XRGB(31,27,6) );
627
628                 gr_scanline( LHX(98), LHX(106), LHY(42) );
629                 gr_scanline( LHX(120), LHX(128), LHY(42) );
630                 gr_pixel( LHX(98), LHY(43) );
631                 gr_pixel( LHX(98), LHY(44) );
632                 gr_pixel( LHX(128), LHY(43) );
633                 gr_pixel( LHX(128), LHY(44) );
634
635                 gr_string(LHX(109), LHY(40), "OR");
636         }
637
638         for (i=0; i<nitems; i++ )       {
639                 kc_drawitem( &items[i], 0 );
640         }
641
642         citem = 0;
643         while(items[citem].id == -1)
644                 citem++;
645         kc_drawitem( &items[citem], 1 );
646
647         newmenu_show_cursor();
648
649 #ifdef NEWMENU_MOUSE
650         mouse_state = omouse_state = 0;
651 #endif
652
653         while(1)                {
654         //      Windows addendum to allow for kconfig input.
655                 gr_update();
656
657                 //see if redbook song needs to be restarted
658                 songs_check_redbook_repeat();
659
660                 k = key_inkey();
661
662 #ifdef NEWMENU_MOUSE
663                 omouse_state = mouse_state;
664                 mouse_state = mouse_button_state(0);
665 #endif
666
667                 if ( !time_stopped ) {
668                         #ifdef NETWORK
669                         if (multi_menu_poll() == -1)
670                                 k = -2;
671                         #endif
672                 }
673                 ocitem = citem;
674                 switch( k )     {
675                 case KEY_BACKSP:
676                         Int3();
677                         break;
678                 case KEY_COMMAND+KEY_SHIFTED+KEY_3:
679                 case KEY_PRINT_SCREEN:
680                         save_screen_shot(0);
681                         break;                                                  
682                 case KEY_CTRLED+KEY_D:
683                         items[citem].value = 255;
684                         kc_drawitem( &items[citem], 1 );
685                         break;
686                 case KEY_CTRLED+KEY_R:  
687                         if ( items == kc_keyboard )
688                                 for (i = 0; i < NUM_KEY_CONTROLS; i++) {
689                                         items[i].value = default_kc_keyboard_settings[i];
690                                         kc_drawitem( &items[i], 0 );
691                                 }
692                         else if ( items == kc_other )
693                                 for (i = 0; i < NUM_OTHER_CONTROLS; i++) {
694                                         items[i].value = default_kc_other_settings[i];
695                                         kc_drawitem( &items[i], 0 );
696                                 }
697                         else if ( items == kc_d2x )
698                                 for (i = 0; i < NUM_D2X_CONTROLS; i++)
699                                 {
700                                         items[i].value = default_kc_d2x_settings[i];
701                                         kc_drawitem( &items[i], 0 );
702                                 }
703                         kc_drawitem( &items[citem], 1 );
704                         break;
705                 case KEY_DELETE:
706                         items[citem].value=255;
707                         kc_drawitem( &items[citem], 1 );
708                         break;
709                 case KEY_UP:            
710                 case KEY_PAD8:
711 #ifdef TABLE_CREATION
712                         if (items[citem].u==-1) items[citem].u=find_next_item_up( items,nitems, citem);
713 #endif
714                         citem = items[citem].u; 
715                         break;
716                 
717                 case KEY_DOWN:  
718                 case KEY_PAD2:
719 #ifdef TABLE_CREATION
720                         if (items[citem].d==-1) items[citem].d=find_next_item_down( items,nitems, citem);
721 #endif
722                         citem = items[citem].d; 
723                         break;
724                 case KEY_LEFT:  
725                 case KEY_PAD4:
726 #ifdef TABLE_CREATION
727                         if (items[citem].l==-1) items[citem].l=find_next_item_left( items,nitems, citem);
728 #endif
729                         citem = items[citem].l; 
730                         break;
731                 case KEY_RIGHT:         
732                 case KEY_PAD6:
733 #ifdef TABLE_CREATION
734                         if (items[citem].r==-1) items[citem].r=find_next_item_right( items,nitems, citem);
735 #endif
736                         citem = items[citem].r; 
737                         break;
738                 case KEY_ENTER: 
739                 case KEY_PADENTER:      
740                         switch( items[citem].type )     {
741                         case BT_KEY:            kc_change_key( &items[citem] ); break;
742                         case BT_MOUSE_AXIS:     kc_change_mouseaxis( &items[citem] ); break;
743                         case BT_JOY_AXIS:       kc_change_joyaxis( &items[citem] ); break;
744                         case BT_INVERT:         kc_change_invert( &items[citem] ); break;
745                         }
746                         break;
747                 //the following case added by WraithX on 11/22/00 to work around the weird joystick bug...
748                 case KEY_SPACEBAR:
749                         switch(items[citem].type)
750                         {
751                         case BT_JOY_AXIS:
752                                 kc_next_joyaxis(&items[citem]);
753                                 break;
754                         }
755                         break;
756                 //end addition by WraithX
757                 case -2:        
758                 case KEY_ESC:
759                         grd_curcanv->cv_font    = save_font;
760
761                         gr_set_current_canvas( save_canvas );
762                         keyd_repeat = old_keyd_repeat;
763                         game_flush_inputs();
764                         newmenu_hide_cursor();
765                         if (time_stopped)
766                                 start_time();
767                         return;
768 #ifdef TABLE_CREATION
769                 case KEY_DEBUGGED+KEY_SHIFTED+KEY_2:
770                 case KEY_DEBUGGED+KEY_F12:      {
771                         FILE * fp;
772                         int j;
773
774                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
775                                 kc_keyboard[i].u = find_next_item_up( kc_keyboard,NUM_KEY_CONTROLS, i);
776                                 kc_keyboard[i].d = find_next_item_down( kc_keyboard,NUM_KEY_CONTROLS, i);
777                                 kc_keyboard[i].l = find_next_item_left( kc_keyboard,NUM_KEY_CONTROLS, i);
778                                 kc_keyboard[i].r = find_next_item_right( kc_keyboard,NUM_KEY_CONTROLS, i);
779                         }
780                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
781                                 kc_other[i].u = find_next_item_up( kc_other,NUM_OTHER_CONTROLS, i);
782                                 kc_other[i].d = find_next_item_down( kc_other,NUM_OTHER_CONTROLS, i);
783                                 kc_other[i].l = find_next_item_left( kc_other,NUM_OTHER_CONTROLS, i);
784                                 kc_other[i].r = find_next_item_right( kc_other,NUM_OTHER_CONTROLS, i);
785                         }
786                         fp = stderr; //fopen( "kconfig.cod", "wt" );
787
788                         fprintf( fp, "kc_item kc_keyboard[NUM_KEY_CONTROLS] = {\n" );
789                         for (i=0; i<NUM_KEY_CONTROLS; i++ )     {
790                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n", 
791                                         kc_keyboard[i].id, kc_keyboard[i].x, kc_keyboard[i].y, kc_keyboard[i].w1, kc_keyboard[i].w2,
792                                         kc_keyboard[i].u, kc_keyboard[i].d, kc_keyboard[i].l, kc_keyboard[i].r,
793                                         34, kc_keyboard[i].text, 34, btype_text[kc_keyboard[i].type] );
794                         }
795                         fprintf( fp, "};\n\n" );
796                         fprintf( fp, "ubyte default_kc_keyboard_settings[MAX_CONTROLS] = " );
797                         fprintf( fp, "{0x%x", kc_keyboard[0].value );
798                         for (j = 1; j < MAX_CONTROLS; j++)
799                                 fprintf( fp, ",0x%x", kc_keyboard[j].value );
800                         fprintf( fp, "};\n\n" );
801
802                         fprintf( fp, "kc_item kc_other[NUM_OTHER_CONTROLS] = {\n" );
803                         for (i=0; i<NUM_OTHER_CONTROLS; i++ )   {
804                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n",
805                                         kc_other[i].id, kc_other[i].x, kc_other[i].y, kc_other[i].w1, kc_other[i].w2,
806                                         kc_other[i].u, kc_other[i].d, kc_other[i].l, kc_other[i].r,
807                                         34, kc_other[i].text, 34, btype_text[kc_other[i].type] );
808                         }
809                         fprintf( fp, "};\n\n" );
810                         fprintf( fp, "ubyte default_kc_other_settings[MAX_CONTROLS] = " );
811                         fprintf( fp, "{0x%x", kc_other[0].value );
812                         for (j = 1; j < MAX_CONTROLS; j++)
813                                 fprintf( fp, ",0x%x", kc_other[j].value );
814                         fprintf( fp, "};\n" );
815
816                         fprintf( fp, "kc_item kc_d2x[NUM_D2X_CONTROLS] = {\n" );
817                         for (i=0; i<NUM_D2X_CONTROLS; i++ )     {
818                                 fprintf( fp, "\t{ %2d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%c%s%c, %s, 255 },\n",
819                                                 kc_d2x[i].id, kc_d2x[i].x, kc_d2x[i].y, kc_d2x[i].w1, kc_d2x[i].w2,
820                                                 kc_d2x[i].u, kc_d2x[i].d, kc_d2x[i].l, kc_d2x[i].r,
821                                                 34, kc_d2x[i].text, 34, btype_text[kc_d2x[i].type] );
822                         }
823                         fprintf( fp, "};\n\n" );
824                         fprintf( fp, "ubyte default_kc_d2x_settings[MAX_CONTROLS] = " );
825                         fprintf( fp, "{0x%x", kc_d2x[0].value );
826                         for (j = 1; j < MAX_CONTROLS; j++)
827                                 fprintf( fp, ",0x%x", kc_d2x[j].value );
828                         fprintf( fp, "};\n" );
829
830                         fclose(fp);
831
832                         }
833                         break;
834 #endif
835                 }
836
837 #ifdef NEWMENU_MOUSE
838                 if ( (mouse_state && !omouse_state) || (mouse_state && omouse_state) ) {
839                         int item_height;
840                         
841                         mouse_get_pos(&mx, &my);
842                         for (i=0; i<nitems; i++ )       {
843                                 item_height = get_item_height( &items[i] );
844                                 x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[i].x) + LHX(items[i].w1);
845                                 x2 = x1 + LHX(items[i].w2);
846                                 y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[i].y);
847                                 y2 = y1 + LHX(item_height);
848                                 if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
849                                         citem = i;
850                                         break;
851                                 }
852                         }
853                 }
854                 else if ( !mouse_state && omouse_state ) {
855                         int item_height;
856                         
857                         mouse_get_pos(&mx, &my);
858                         item_height = get_item_height( &items[citem] );
859                         x1 = grd_curcanv->cv_bitmap.bm_x + LHX(items[citem].x) + LHX(items[citem].w1);
860                         x2 = x1 + LHX(items[citem].w2);
861                         y1 = grd_curcanv->cv_bitmap.bm_y + LHY(items[citem].y);
862                         y2 = y1 + LHY(item_height);
863                         if (((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2))) {
864                                 newmenu_hide_cursor();
865                                 switch( items[citem].type )     {
866                                 case BT_KEY:                            kc_change_key( &items[citem] ); break;
867                                 case BT_MOUSE_AXIS:             kc_change_mouseaxis( &items[citem] ); break;
868                                 case BT_JOY_AXIS:               kc_change_joyaxis( &items[citem] ); break;
869                                 case BT_INVERT:                         kc_change_invert( &items[citem] ); break;
870                                 }
871                                 newmenu_show_cursor();
872                         } else {
873                                 x1 = grd_curcanv->cv_bitmap.bm_x + close_x + LHX(1);
874                                 x2 = x1 + close_size - LHX(1);
875                                 y1 = grd_curcanv->cv_bitmap.bm_y + close_y + LHX(1);
876                                 y2 = y1 + close_size - LHX(1);
877                                 if ( ((mx > x1) && (mx < x2)) && ((my > y1) && (my < y2)) ) {
878                                         grd_curcanv->cv_font    = save_font;
879                                         gr_set_current_canvas( save_canvas );
880                                         keyd_repeat = old_keyd_repeat;
881                                         game_flush_inputs();
882                                         newmenu_hide_cursor();
883                                         if (time_stopped)
884                                                 start_time();
885                                         return;
886                                 }
887                         }
888
889                 }
890 #endif // NEWMENU_MOUSE
891
892                 if (ocitem!=citem)      {
893                         newmenu_hide_cursor();
894                         kc_drawitem( &items[ocitem], 0 );
895                         kc_drawitem( &items[citem], 1 );
896                         newmenu_show_cursor();
897                 }
898         }
899 }
900
901
902 void kc_drawitem( kc_item *item, int is_current )
903 {
904         int x, w, h, aw;
905         char btext[16];
906
907         if (is_current)
908                 gr_set_fontcolor( BM_XRGB(20,20,29), -1 );
909         else
910                 gr_set_fontcolor( BM_XRGB(15,15,24), -1 );
911    gr_string( LHX(item->x), LHY(item->y), item->text );
912
913         if (item->value==255) {
914                 strcpy( btext, "" );
915         } else {
916                 switch( item->type )    {
917                         case BT_KEY:
918                                 strncpy( btext, key_text[item->value], 10 ); break;
919                         case BT_MOUSE_AXIS:
920                                 strncpy( btext, Text_string[mouseaxis_text[item->value]], 10 ); break;
921                         case BT_JOY_AXIS:
922 #ifdef USE_LINUX_JOY
923                                 sprintf(btext, "J%d A%d", j_axis[item->value].joydev, j_Get_joydev_axis_number(item->value));
924 #elif defined(SDL_INPUT)
925                                 if (joyaxis_text[item->value])
926                                         strncpy(btext, joyaxis_text[item->value], 10);
927                                 else
928                                         sprintf(btext, "AXIS%2d", item->value + 1);
929 #else
930                                 strncpy(btext, Text_string[joyaxis_text[item->value]], 10);
931 #endif
932                                 break;
933                         case BT_INVERT:
934                                 strncpy( btext, Text_string[invert_text[item->value]], 10 ); break;
935                 }
936         }
937         if (item->w1) {
938                 gr_get_string_size(btext, &w, &h, &aw  );
939
940                 if (is_current)
941                         gr_setcolor( BM_XRGB(21,0,24) );
942                 else
943                         gr_setcolor( BM_XRGB(16,0,19) );
944                 gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
945                 
946                 gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
947
948                 x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
949         
950                 gr_string( x, LHY(item->y), btext );
951         }
952 }
953
954
955 static int looper=0;
956
957 void kc_drawquestion( kc_item *item )
958 {
959         int c, x, w, h, aw;
960
961         gr_get_string_size("?", &w, &h, &aw  );
962
963         c = BM_XRGB(21,0,24);
964
965         //@@gr_setcolor( gr_fade_table[fades[looper]*256+c] );
966         gr_setcolor(BM_XRGB(21*fades[looper]/31,0,24*fades[looper]/31));
967         looper++;
968         if (looper>63) looper=0;
969
970         gr_urect( LHX(item->w1+item->x), LHY(item->y-1), LHX(item->w1+item->x+item->w2), LHY(item->y)+h );
971         
972         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
973
974         x = LHX(item->w1+item->x)+((LHX(item->w2)-w)/2);
975    
976         gr_string( x, LHY(item->y), "?" );
977 gr_update();
978 }
979
980 void kc_change_key( kc_item * item )
981 {
982         int i,n,f,k;
983         ubyte keycode;
984
985         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
986         
987         gr_string( 0x8000, LHY(INFO_Y), TXT_PRESS_NEW_KEY );
988
989         game_flush_inputs();
990         keycode=255;
991         k=255;
992         
993         while( (k!=KEY_ESC) && (keycode==255) ) 
994         {                               
995                 #ifdef NETWORK
996                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
997                         multi_menu_poll();
998                 #endif
999 //              if ( Game_mode & GM_MULTI )
1000 //                      GameLoop( 0, 0 );                               // Continue
1001                 k = key_inkey();
1002                 timer_delay(f0_1/10);
1003                 kc_drawquestion( item );
1004         
1005                 for (i=0; i<256; i++ )  {
1006                         if (keyd_pressed[i] && (strlen(key_text[i])>0)) {
1007                                 f = 0;
1008                                 for (n=0; n<sizeof(system_keys); n++ )
1009                                         if ( system_keys[n] == i )
1010                                                 f=1;
1011                                 if (!f) 
1012                                         keycode=i;
1013                         }
1014                 }
1015         }
1016
1017         if (k!=KEY_ESC) {
1018                 for (i=0; i<Num_items; i++ )    {
1019                         n = item - All_items;
1020                         if ( (i!=n) && (All_items[i].type==BT_KEY) && (All_items[i].value==keycode) )           {
1021                                 All_items[i].value = 255;
1022                                 kc_drawitem( &All_items[i], 0 );
1023                         }
1024                 }
1025                 item->value = keycode;
1026         }
1027         kc_drawitem( item, 1 );
1028
1029         gr_set_fontcolor( BM_XRGB(28,28,28), BM_XRGB(0,0,0) );
1030
1031         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1032
1033         game_flush_inputs();
1034
1035 }
1036
1037
1038 // 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
1039 void kc_next_joyaxis(kc_item *item)
1040 {
1041         int n, i, k, max, tries;
1042         ubyte code = 0;
1043
1044         k = 255;
1045         n = 0;
1046         i = 0;
1047
1048         // I modelled this ifdef after the code in the kc_change_joyaxis method.
1049         // So, if somethin's not workin here, it might not be workin there either.
1050         max = JOY_MAX_AXES;
1051         tries = 1;
1052         code = (item->value + 1) % max;
1053
1054         if (code != 255)
1055         {
1056                 for (i = 0; i < Num_items; i++)
1057                 {
1058                         n = item - All_items;
1059                         if ((i != n) && (All_items[i].type == BT_JOY_AXIS) && (All_items[i].value == code))
1060                         {
1061                                 if (tries > max)
1062                                         return; // all axes allocated already
1063                                 i = -1; // -1 so the i++ will push back to 0
1064                                 code = (item->value + ++tries) % max; // try next axis
1065                         }//end if
1066                 }//end for
1067
1068                 item->value = code;
1069         }//end if
1070
1071         kc_drawitem(item, 1);
1072         nm_restore_background(0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h);
1073         game_flush_inputs();
1074
1075 }//method kc_next_joyaxis
1076 //end addition by WraithX
1077
1078
1079 void kc_change_joyaxis( kc_item * item )
1080 {
1081         int axis[JOY_MAX_AXES];
1082         int old_axis[JOY_MAX_AXES];
1083         int numaxis = joy_num_axes;
1084         int n,i,k;
1085         ubyte code;
1086
1087         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1088         
1089         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_JOY_AXIS );
1090
1091         game_flush_inputs();
1092         code=255;
1093         k=255;
1094
1095         joystick_read_raw_axis( JOY_ALL_AXIS, old_axis );
1096
1097         while( (k!=KEY_ESC) && (code==255))     
1098         {                               
1099                 #ifdef NETWORK
1100                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1101                         multi_menu_poll();
1102                 #endif
1103 //              if ( Game_mode & GM_MULTI )
1104 //                      GameLoop( 0, 0 );                               // Continue
1105                 k = key_inkey();
1106                 timer_delay(f0_1/10);
1107
1108                 if (k == KEY_PRINT_SCREEN)
1109                         save_screen_shot(0);
1110
1111                 kc_drawquestion( item );
1112
1113                 joystick_read_raw_axis( JOY_ALL_AXIS, axis );
1114
1115                 for (i=0; i<numaxis; i++ )      {
1116                         if ( abs(axis[i]-old_axis[i])>100 )
1117                         {
1118                                 code = i;
1119                                 con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", i);
1120                         }
1121                         //old_axis[i] = axis[i];
1122                 }
1123                 for (i=0; i<Num_items; i++ )    
1124                  {
1125                         n = item - All_items;
1126                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) 
1127                                 code = 255;
1128                  }
1129         
1130         }
1131         if (code!=255)  {
1132                 for (i=0; i<Num_items; i++ )    {
1133                         n = item - All_items;
1134                         if ( (i!=n) && (All_items[i].type==BT_JOY_AXIS) && (All_items[i].value==code) ) {
1135                                 All_items[i].value = 255;
1136                                 kc_drawitem( &All_items[i], 0 );
1137                         }
1138                 }
1139
1140                 item->value = code;                                      
1141         }
1142         kc_drawitem( item, 1 );
1143         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1144         game_flush_inputs();
1145
1146 }
1147
1148 void kc_change_mouseaxis( kc_item * item )
1149 {
1150         int i,n,k;
1151         ubyte code;
1152         int dx, dy, dz;
1153
1154         gr_set_fontcolor( BM_XRGB(28,28,28), -1 );
1155         
1156         gr_string( 0x8000, LHY(INFO_Y), TXT_MOVE_NEW_MSE_AXIS );
1157
1158         game_flush_inputs();
1159         code=255;
1160         k=255;
1161
1162         mouse_get_delta( &dx, &dy, &dz );
1163
1164         while( (k!=KEY_ESC) && (code==255))     
1165         {                               
1166                 #ifdef NETWORK
1167                 if ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME) && (!Endlevel_sequence))
1168                         multi_menu_poll();
1169                 #endif
1170 //              if ( Game_mode & GM_MULTI )
1171 //                      GameLoop( 0, 0 );                               // Continue
1172                 k = key_inkey();
1173                 timer_delay(f0_1/10);
1174
1175                 if (k == KEY_PRINT_SCREEN)
1176                         save_screen_shot(0);
1177
1178                 kc_drawquestion( item );
1179
1180                 mouse_get_delta( &dx, &dy, &dz );
1181                 if ( abs(dx)>20 ) code = 0;
1182                 if ( abs(dy)>20 ) code = 1;
1183                 if ( abs(dz)>20 ) code = 2;
1184         }
1185         if (code!=255)  {
1186                 for (i=0; i<Num_items; i++ )    {
1187                         n = item - All_items;
1188                         if ( (i!=n) && (All_items[i].type==BT_MOUSE_AXIS) && (All_items[i].value==code) )               {
1189                                 All_items[i].value = 255;
1190                                 kc_drawitem( &All_items[i], 0 );
1191                         }
1192                 }
1193                 item->value = code;
1194         }
1195         kc_drawitem( item, 1 );
1196         nm_restore_background( 0, LHY(INFO_Y), LHX(310), grd_curcanv->cv_font->ft_h );
1197         game_flush_inputs();
1198
1199 }
1200
1201
1202 void kc_change_invert( kc_item * item )
1203 {
1204         game_flush_inputs();
1205
1206         if (item->value)
1207                 item->value = 0;
1208         else 
1209                 item->value = 1;
1210
1211         kc_drawitem( item, 1 );
1212
1213 }
1214
1215 #include "screens.h"
1216
1217 void kconfig(int n, char * title)
1218 {
1219         int i, j;
1220         grs_bitmap *save_bm;
1221
1222         set_screen_mode( SCREEN_MENU );
1223
1224         kc_set_controls();
1225
1226         //save screen
1227         save_bm = gr_create_bitmap( grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_h );
1228         Assert( save_bm != NULL );
1229         
1230         gr_bm_bitblt(grd_curcanv->cv_bitmap.bm_w, grd_curcanv->cv_bitmap.bm_w, 
1231                                         0, 0, 0, 0, &grd_curcanv->cv_bitmap, save_bm );
1232
1233         switch(n)       {
1234         case 0:kconfig_sub( kc_keyboard, NUM_KEY_CONTROLS, title );break;
1235         case 1:kconfig_sub( kc_other, NUM_OTHER_CONTROLS, title );break;
1236         case 2:kconfig_sub( kc_d2x, NUM_D2X_CONTROLS, title ); break;
1237         default:
1238                 Int3();
1239                 return;
1240         }
1241
1242         //restore screen
1243         gr_bitmap(0, 0, save_bm);
1244         gr_free_bitmap(save_bm);
1245
1246 #if 0 // set_screen_mode always calls this later... right?
1247         reset_cockpit();                //force cockpit redraw next time
1248 #endif
1249
1250         // Update save values...
1251         
1252         for (j=0; j<256; j++)
1253                 if (key_binding(j)) {
1254                         for (i = 0; i < NUM_KEY_CONTROLS; i++)
1255                                 if (!stricmp(key_binding(j), kc_key_bind_text[i])) {
1256                                         cmd_appendf("unbind %s", key_text[j]);
1257                                         break;
1258                                 }
1259                         for (i = 0; i < NUM_D2X_CONTROLS; i++)
1260                                 if (kc_d2x[i].type == BT_KEY && !stricmp(key_binding(j), kc_d2x[i].text)) {
1261                                         cmd_appendf("unbind %s", key_text[j]);
1262                                         break;
1263                                 }
1264                 }
1265
1266         for (i=0; i<NUM_KEY_CONTROLS; i++ )
1267                 if (kc_keyboard[i].value != 255)
1268                         cmd_appendf("bind %s \"%s\"", key_text[kc_keyboard[i].value], kc_key_bind_text[i]);
1269
1270         for (i = 0; i < NUM_D2X_CONTROLS; i++)
1271                 if (kc_d2x[i].value != 255)
1272                         cmd_appendf("bind %s \"%s\"", key_text[kc_d2x[i].value], kc_d2x[i].text);
1273
1274         for (i = 0; i < 6; i++) {
1275                 cvar_setint(&joy_advaxes[i], AXIS_NONE);
1276                 cvar_setint(&joy_invert[i], 0);
1277         }
1278         for (i = 0; i < 3; i++) {
1279                 cvar_setint(&mouse_axes[i], AXIS_NONE);
1280                 cvar_setint(&mouse_invert[i], 0);
1281         }
1282         for (i = 0; i < NUM_OTHER_CONTROLS; i++) {
1283                 if (kc_other[i].type == BT_JOY_AXIS && kc_other[i].value != 255) {
1284                         cvar_setint(&joy_advaxes[kc_other[i].value], kc_other_axismap[i]);
1285                         cvar_setint(&joy_invert[kc_other[i].value], kc_other[i+1].value);
1286                 }
1287                 if (kc_other[i].type == BT_MOUSE_AXIS && kc_other[i].value != 255) {
1288                         cvar_setint(&mouse_axes[kc_other[i].value], kc_other_axismap[i]);
1289                         cvar_setint(&mouse_invert[kc_other[i].value], kc_other[i+1].value);
1290                 }
1291         }
1292
1293         cmd_queue_process();
1294 }
1295
1296
1297 fix Last_angles_p = 0;
1298 fix Last_angles_b = 0;
1299 fix Last_angles_h = 0;
1300 ubyte Last_angles_read = 0;
1301
1302 extern int                      VR_sensitivity;
1303                                                 
1304 int VR_sense_range[3] = { 25, 50, 75 };
1305
1306 #if 0 // unused
1307 read_head_tracker()
1308 {
1309         fix yaw, pitch, roll;
1310         int buttons;
1311
1312 //------ read vfx1 helmet --------
1313         if (vfx1_installed) {
1314                 vfx_get_data(&yaw,&pitch,&roll,&buttons);
1315         } else if (iglasses_headset_installed)  {
1316                 iglasses_read_headset( &yaw, &pitch, &roll );
1317         } else if (Victor_headset_installed)   {
1318                 victor_read_headset_filtered( &yaw, &pitch, &roll );
1319         } else {
1320                 return;
1321         }
1322
1323         Use_player_head_angles = 0;
1324         if ( Last_angles_read ) {
1325                 fix yaw1 = yaw;
1326                 
1327                 yaw1 = yaw;
1328                 if ( (Last_angles_h < (F1_0/4) ) && (yaw > ((F1_0*3)/4) ) )     
1329                         yaw1 -= F1_0;
1330                 else if ( (yaw < (F1_0/4) ) && (Last_angles_h > ((F1_0*3)/4) ) )        
1331                         yaw1 += F1_0;
1332         
1333                 Controls.pitch_time     += fixmul((pitch- Last_angles_p)*VR_sense_range[VR_sensitivity],FrameTime);
1334                 Controls.heading_time+= fixmul((yaw1 -  Last_angles_h)*VR_sense_range[VR_sensitivity],FrameTime);
1335                 Controls.bank_time      += fixmul((roll - Last_angles_b)*VR_sense_range[VR_sensitivity],FrameTime);
1336         }
1337         Last_angles_read = 1;
1338         Last_angles_p = pitch;
1339         Last_angles_h = yaw;
1340         Last_angles_b = roll;
1341 }
1342 #endif
1343
1344 #define PH_SCALE        8
1345
1346 #ifndef __MSDOS__
1347 #define JOYSTICK_READ_TIME      (F1_0/40)               //      Read joystick at 40 Hz.
1348 #else
1349 #define JOYSTICK_READ_TIME      (F1_0/10)               //      Read joystick at 10 Hz.
1350 #endif
1351
1352 fix     LastReadTime = 0;
1353
1354 fix     joy_axis[JOY_MAX_AXES];
1355
1356 ubyte                   kc_use_external_control = 0;
1357 ubyte                   kc_enable_external_control = 0;
1358 ubyte                   kc_external_intno = 0;
1359 ext_control_info        *kc_external_control = NULL;
1360 char                    *kc_external_name = NULL;
1361 ubyte                   kc_external_version = 0;
1362 extern int Automap_active;
1363
1364 void kconfig_init_external_controls(int intno, int address)
1365 {
1366         int i;
1367         kc_external_intno = intno;
1368         kc_external_control     = (ext_control_info *)address;
1369         kc_use_external_control = 1;
1370         kc_enable_external_control  = 1;
1371
1372         i = FindArg ( "-xname" );
1373         if ( i )        
1374                 kc_external_name = Args[i+1];
1375         else
1376                 kc_external_name = "External Controller";
1377
1378    for (i=0;i<strlen (kc_external_name);i++)
1379     if (kc_external_name[i]=='_')
1380           kc_external_name[i]=' '; 
1381
1382         i = FindArg ( "-xver" );
1383         if ( i )
1384                 kc_external_version = atoi(Args[i+1]);
1385         
1386         printf( "%s int: 0x%x, data: 0x%p, ver:%d\n", kc_external_name, kc_external_intno, kc_external_control, kc_external_version );
1387
1388 }
1389
1390
1391 fix Next_toggle_time[3]={0,0,0};
1392
1393 int allowed_to_toggle(int i)
1394 {
1395   //used for keeping tabs of when its ok to toggle headlight,primary,and secondary
1396  
1397         if (Next_toggle_time[i] > GameTime)
1398                 if (Next_toggle_time[i] < GameTime + (F1_0/8))  //      In case time is bogus, never wait > 1 second.
1399                         return 0;
1400
1401         Next_toggle_time[i] = GameTime + (F1_0/8);
1402
1403         return 1;
1404 }
1405
1406
1407 void controls_read_all()
1408 {
1409         int i;
1410         int slide_on, bank_on;
1411         int dx, dy, dz;
1412         fix ctime;
1413         int raw_joy_axis[JOY_MAX_AXES];
1414         fix kp, kh;
1415         ubyte channel_masks;
1416         fix analog_control[7]; // indexed on kc_axis_map
1417
1418         memset(analog_control, 0, sizeof(analog_control));
1419
1420         {
1421                 fix temp = Controls.heading_time;
1422                 fix temp1 = Controls.pitch_time;
1423                 memset( &Controls, 0, sizeof(control_info) );
1424                 Controls.heading_time = temp;
1425                 Controls.pitch_time = temp1;
1426         }
1427         slide_on = 0;
1428         bank_on = 0;
1429
1430         ctime = timer_get_fixed_seconds();
1431
1432         //---------  Read Joystick -----------
1433         if ( (LastReadTime + JOYSTICK_READ_TIME > ctime) ) {
1434 # ifndef __MSDOS__
1435                 if ((ctime < 0) && (LastReadTime >= 0))
1436 # else
1437                 if ((ctime < 0) && (LastReadTime > 0))
1438 # endif
1439                         LastReadTime = ctime;
1440         } else if (Config_control_joystick.intval) {
1441                 LastReadTime = ctime;
1442                 channel_masks = joystick_read_raw_axis( JOY_ALL_AXIS, raw_joy_axis );
1443
1444                 Assert(joy_num_axes <= 6); // don't have cvar mapping above 6 yet
1445                 for (i = 0; i < joy_num_axes; i++)
1446                 {
1447 #ifndef SDL_INPUT
1448                         if (channel_masks&(1<<i))       {
1449 #endif
1450                                 int joy_null_value = 10;
1451
1452                                         raw_joy_axis[i] = joy_get_scaled_reading( raw_joy_axis[i], i );
1453
1454                                         if (joy_advaxes[i].intval == AXIS_THROTTLE) // If this is the throttle
1455                                                 joy_null_value = 20;            // Then use a larger dead-zone
1456         
1457                                         if (raw_joy_axis[i] > joy_null_value) 
1458                                           raw_joy_axis[i] = ((raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value);
1459                                         else if (raw_joy_axis[i] < -joy_null_value)
1460                                           raw_joy_axis[i] = ((raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value);
1461                                         else
1462                                           raw_joy_axis[i] = 0;
1463                                         joy_axis[i]     = (raw_joy_axis[i]*FrameTime)/128;      
1464 #ifndef SDL_INPUT
1465                         } else {
1466                                 joy_axis[i] = 0;
1467                         }
1468 #endif
1469                 }       
1470         } else {
1471                 for (i = 0; i < joy_num_axes; i++)
1472                         joy_axis[i] = 0;
1473         }
1474
1475         if (Config_control_joystick.intval)
1476                 for (i = 0; i < 6; i++)
1477                         analog_control[joy_advaxes[i].intval] += joy_axis[i] * (joy_invert[i].intval ? -1 : 1);
1478
1479         if (Config_control_mouse.intval) {
1480                 //---------  Read Mouse -----------
1481                 mouse_get_delta( &dx, &dy, &dz );
1482
1483                 analog_control[mouse_axes[0].intval] += dx * FrameTime / 35 * (mouse_invert[0].intval ? -1 : 1);
1484                 analog_control[mouse_axes[1].intval] += dy * FrameTime / 25 * (mouse_invert[1].intval ? -1 : 1);
1485                 analog_control[mouse_axes[2].intval] += dz * FrameTime      * (mouse_invert[2].intval ? -1 : 1);
1486
1487         }
1488
1489 //------------- Read slide_on -------------
1490         
1491         slide_on |= console_control_state(CONCNTL_STRAFE);
1492
1493 //------------- Read bank_on ---------------
1494
1495         bank_on |= console_control_state(CONCNTL_BANK);
1496
1497 //------------ Read pitch_time -----------
1498         if ( !slide_on )        {
1499                 // mprintf((0, "pitch: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
1500                 kp = 0;
1501
1502                 kp += console_control_down_time(CONCNTL_LOOKDOWN) / (PH_SCALE * 2);
1503                 kp -= console_control_down_time(CONCNTL_LOOKUP) / (PH_SCALE * 2);
1504
1505                 if (kp == 0)
1506                         Controls.pitch_time = 0;
1507                 else if (kp > 0) {
1508                         if (Controls.pitch_time < 0)
1509                                 Controls.pitch_time = 0;
1510                 } else // kp < 0
1511                         if (Controls.pitch_time > 0)
1512                                 Controls.pitch_time = 0;
1513                 Controls.pitch_time += kp;
1514
1515                 Controls.pitch_time -= analog_control[AXIS_PITCH] * Config_joystick_sensitivity.intval / 8;
1516
1517         } else
1518                 Controls.pitch_time = 0;
1519
1520 // the following "if" added by WraithX, 4/14/00
1521 // done so that dead players can't move
1522 if (!Player_is_dead)
1523 {
1524 //----------- Read vertical_thrust_time -----------------
1525
1526         if ( slide_on ) {
1527                 Controls.vertical_thrust_time += console_control_down_time(CONCNTL_LOOKDOWN);
1528                 Controls.vertical_thrust_time -= console_control_down_time(CONCNTL_LOOKUP);
1529                 Controls.vertical_thrust_time += analog_control[AXIS_PITCH];
1530         }
1531
1532         Controls.vertical_thrust_time += console_control_down_time(CONCNTL_MOVEUP);
1533         Controls.vertical_thrust_time -= console_control_down_time(CONCNTL_MOVEDOWN);
1534         Controls.vertical_thrust_time += analog_control[AXIS_UPDOWN];
1535
1536 }// end "if" added by WraithX
1537
1538 //---------- Read heading_time -----------
1539
1540         if (!slide_on && !bank_on)      {
1541                 //mprintf((0, "heading: %7.3f %7.3f: %7.3f\n", f2fl(k4), f2fl(k6), f2fl(Controls.heading_time)));
1542                 kh = 0;
1543
1544                 kh -= console_control_down_time(CONCNTL_LEFT) / PH_SCALE;
1545                 kh += console_control_down_time(CONCNTL_RIGHT) / PH_SCALE;
1546
1547                 if (kh == 0)
1548                         Controls.heading_time = 0;
1549                 else if (kh > 0) {
1550                         if (Controls.heading_time < 0)
1551                                 Controls.heading_time = 0;
1552                 } else // kh < 0
1553                         if (Controls.heading_time > 0)
1554                                 Controls.heading_time = 0;
1555                 Controls.heading_time += kh;
1556
1557                 Controls.heading_time += analog_control[AXIS_TURN] * Config_joystick_sensitivity.intval / 8;
1558
1559         } else
1560                 Controls.heading_time = 0;
1561
1562 // the following "if" added by WraithX, 4/14/00
1563 // done so that dead players can't move
1564 if (!Player_is_dead)
1565 {
1566 //----------- Read sideways_thrust_time -----------------
1567
1568         if ( slide_on ) {
1569                 Controls.sideways_thrust_time -= console_control_down_time(CONCNTL_LEFT);
1570                 Controls.sideways_thrust_time += console_control_down_time(CONCNTL_RIGHT);
1571                 Controls.sideways_thrust_time += analog_control[AXIS_TURN];
1572         }
1573
1574         Controls.sideways_thrust_time -= console_control_down_time(CONCNTL_MOVELEFT);
1575         Controls.sideways_thrust_time += console_control_down_time(CONCNTL_MOVERIGHT);
1576         Controls.sideways_thrust_time += analog_control[AXIS_LEFTRIGHT];
1577
1578 }// end "if" added by WraithX
1579
1580 //----------- Read bank_time -----------------
1581
1582         if ( bank_on )  {
1583                 Controls.bank_time += console_control_down_time(CONCNTL_LEFT);
1584                 Controls.bank_time -= console_control_down_time(CONCNTL_RIGHT);
1585                 Controls.bank_time -= analog_control[AXIS_TURN] * Config_joystick_sensitivity.intval / 8;
1586         }
1587
1588         Controls.bank_time += console_control_down_time(CONCNTL_BANKLEFT);
1589         Controls.bank_time -= console_control_down_time(CONCNTL_BANKRIGHT);
1590         Controls.bank_time += analog_control[AXIS_BANK];
1591
1592 // the following "if" added by WraithX, 4/14/00
1593 // done so that dead players can't move
1594 if (!Player_is_dead)
1595 {
1596 //----------- Read forward_thrust_time -------------
1597
1598         Controls.forward_thrust_time += console_control_down_time(CONCNTL_FORWARD);
1599         Controls.forward_thrust_time -= console_control_down_time(CONCNTL_BACK);
1600         Controls.forward_thrust_time -= analog_control[AXIS_THROTTLE];
1601
1602 //----------- Read afterburner_state -------------
1603
1604         Controls.afterburner_state |= console_control_state(CONCNTL_AFTERBURN);
1605
1606 //-------Read headlight key--------------------------
1607
1608         Controls.headlight_count += console_control_down_count(CONCNTL_HEADLIGHT);
1609
1610 //--------Read Cycle Primary Key------------------
1611
1612         Controls.cycle_primary_count += console_control_down_count(CONCNTL_CYCLE);
1613
1614 //--------Read Cycle Secondary Key------------------
1615
1616         Controls.cycle_secondary_count += console_control_down_count(CONCNTL_CYCLE2);
1617
1618 //--------Read Toggle Bomb key----------------------
1619
1620         if (console_control_down_count(CONCNTL_TOGGLEBOMB)) {
1621                 int bomb = Secondary_last_was_super[PROXIMITY_INDEX]?PROXIMITY_INDEX:SMART_MINE_INDEX;
1622
1623                 if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX] &&
1624                         !Players[Player_num].secondary_ammo[SMART_MINE_INDEX])
1625                 {
1626                         digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
1627                         HUD_init_message ("No bombs available!");
1628                 } else {
1629                         if (Players[Player_num].secondary_ammo[bomb] == 0) {
1630                                 digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 );
1631                                 HUD_init_message("No %s available!", (bomb == SMART_MINE_INDEX)?"Smart mines":"Proximity bombs");
1632                         } else {
1633                                 Secondary_last_was_super[PROXIMITY_INDEX]=!Secondary_last_was_super[PROXIMITY_INDEX];
1634                                 digi_play_sample_once( SOUND_GOOD_SELECTION_SECONDARY, F1_0 );
1635                         }
1636                 }
1637         }
1638
1639 //---------Read Energy->Shield key----------
1640
1641         if ((Players[Player_num].flags & PLAYER_FLAGS_CONVERTER) && console_control_state(CONCNTL_NRGSHIELD))
1642                 transfer_energy_to_shield(console_control_down_time(CONCNTL_NRGSHIELD));
1643
1644 //----------- Read fire_primary_down_count
1645
1646         Controls.fire_primary_down_count += console_control_down_count(CONCNTL_ATTACK);
1647
1648 //----------- Read fire_primary_state
1649
1650         Controls.fire_primary_state |= console_control_state(CONCNTL_ATTACK);
1651
1652 //----------- Read fire_secondary_down_count
1653
1654         Controls.fire_secondary_down_count += console_control_down_count(CONCNTL_ATTACK2);
1655
1656 //----------- Read fire_secondary_state
1657
1658         Controls.fire_secondary_state |= console_control_state(CONCNTL_ATTACK2);
1659
1660 //----------- Read fire_flare_down_count
1661
1662         Controls.fire_flare_down_count += console_control_down_count(CONCNTL_FLARE);
1663
1664 //----------- Read drop_bomb_down_count
1665
1666         Controls.drop_bomb_down_count += console_control_down_count(CONCNTL_BOMB);
1667
1668 //----------- Read rear_view_down_count
1669
1670         Controls.rear_view_down_count += console_control_down_count(CONCNTL_REARVIEW);
1671
1672 //----------- Read rear_view_down_state
1673
1674         Controls.rear_view_down_state |= console_control_state(CONCNTL_REARVIEW);
1675
1676 }//end "if" added by WraithX
1677
1678 //----------- Read automap_down_count
1679
1680         Controls.automap_down_count += console_control_down_count(CONCNTL_AUTOMAP);
1681
1682 //----------- Read automap_state
1683
1684         Controls.automap_state |= console_control_state(CONCNTL_AUTOMAP);
1685
1686 //----------- Read stupid-cruise-control-type of throttle.
1687
1688         Cruise_speed += console_control_down_time(CONCNTL_CRUISEUP);
1689         Cruise_speed -= console_control_down_time(CONCNTL_CRUISEDOWN);
1690
1691         if (console_control_down_count(CONCNTL_CRUISEOFF))
1692                 Cruise_speed = 0;
1693
1694         if (Cruise_speed > i2f(100))
1695                 Cruise_speed = i2f(100);
1696         if (Cruise_speed < 0 )
1697                 Cruise_speed = 0;
1698
1699         if (Controls.forward_thrust_time==0)
1700                 Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100;
1701
1702 #if 0
1703         read_head_tracker();
1704
1705         // Read external controls
1706         if (kc_use_external_control || CybermouseActive)
1707                 kconfig_read_external_controls();
1708 #endif
1709
1710 //----------- Clamp values between -FrameTime and FrameTime
1711         if (FrameTime > F1_0 )
1712                 mprintf( (1, "Bogus frame time of %.2f seconds\n", f2fl(FrameTime) ));
1713
1714         if (Controls.pitch_time         > FrameTime/2 ) Controls.pitch_time         = FrameTime/2;
1715         if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime;
1716         if (Controls.heading_time         > FrameTime ) Controls.heading_time         = FrameTime;
1717         if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime;
1718         if (Controls.bank_time            > FrameTime ) Controls.bank_time            = FrameTime;
1719         if (Controls.forward_thrust_time  > FrameTime ) Controls.forward_thrust_time  = FrameTime;
1720 //      if (Controls.afterburner_time     > FrameTime ) Controls.afterburner_time     = FrameTime;
1721
1722         if (Controls.pitch_time         < -FrameTime/2 ) Controls.pitch_time         = -FrameTime/2;
1723         if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime;
1724         if (Controls.heading_time         < -FrameTime ) Controls.heading_time         = -FrameTime;
1725         if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime;
1726         if (Controls.bank_time            < -FrameTime ) Controls.bank_time            = -FrameTime;
1727         if (Controls.forward_thrust_time  < -FrameTime ) Controls.forward_thrust_time  = -FrameTime;
1728 //      if (Controls.afterburner_time     < -FrameTime ) Controls.afterburner_time     = -FrameTime;
1729
1730
1731 //--------- Don't do anything if in debug mode
1732 #ifndef RELEASE
1733         if ( keyd_pressed[KEY_DELETE] ) {
1734                 memset( &Controls, 0, sizeof(control_info) );
1735         }
1736 #endif
1737 }
1738
1739
1740 void reset_cruise(void)
1741 {
1742         Cruise_speed=0;
1743 }
1744
1745
1746 void kc_set_controls()
1747 {
1748         int i, j;
1749
1750         for (i=0; i<NUM_KEY_CONTROLS; i++ )
1751                 kc_keyboard[i].value = 255;
1752
1753         for (i=0; i<NUM_OTHER_CONTROLS; i++ ) {
1754                 if (kc_other[i].type == BT_INVERT)
1755                         kc_other[i].value = 0;
1756                 else
1757                         kc_other[i].value = 255;
1758         }
1759
1760         for (i=0; i<NUM_D2X_CONTROLS; i++ )
1761                 kc_d2x[i].value = 255;
1762
1763         for (j = 0; j < 256; j++)
1764                 if (key_binding(j)) {
1765                         for (i = 0; i < NUM_KEY_CONTROLS; i++)
1766                                 if (kc_keyboard[i].value == 255
1767                                         && !stricmp(key_binding(j), kc_key_bind_text[i])) {
1768                                         kc_keyboard[i].value = j;
1769                                         break;
1770                                 }
1771                 }
1772
1773         for(j = 0; j < 256; j++)
1774                 if (key_binding(j)) {
1775                         for (i = 0; i < NUM_D2X_CONTROLS; i++)
1776                                 if (kc_d2x[i].value == 255
1777                                         && !stricmp(key_binding(j), kc_d2x[i].text)) {
1778                                         kc_d2x[i].value = j;
1779                                         break;
1780                                 }
1781                 }
1782
1783         for (i = 0; i < 6; i++) {
1784                 int inv = joy_invert[i].intval;
1785                 switch (joy_advaxes[i].intval) {
1786                         case AXIS_PITCH:     kc_other[ 0].value = i; kc_other[ 1].value = inv; break;
1787                         case AXIS_TURN:      kc_other[ 2].value = i; kc_other[ 3].value = inv; break;
1788                         case AXIS_LEFTRIGHT: kc_other[ 4].value = i; kc_other[ 5].value = inv; break;
1789                         case AXIS_UPDOWN:    kc_other[ 6].value = i; kc_other[ 7].value = inv; break;
1790                         case AXIS_BANK:      kc_other[ 8].value = i; kc_other[ 9].value = inv; break;
1791                         case AXIS_THROTTLE:  kc_other[10].value = i; kc_other[11].value = inv; break;
1792                         case AXIS_NONE:      break;
1793                         default:
1794                                 Int3();
1795                                 break;
1796                 }
1797         }
1798
1799         for (i = 0; i < 3; i++) {
1800                 int inv = mouse_invert[i].intval;
1801                 switch (mouse_axes[i].intval) {
1802                         case AXIS_PITCH:     kc_other[12].value = i; kc_other[13].value = inv; break;
1803                         case AXIS_TURN:      kc_other[14].value = i; kc_other[15].value = inv; break;
1804                         case AXIS_LEFTRIGHT: kc_other[16].value = i; kc_other[17].value = inv; break;
1805                         case AXIS_UPDOWN:    kc_other[18].value = i; kc_other[19].value = inv; break;
1806                         case AXIS_BANK:      kc_other[20].value = i; kc_other[21].value = inv; break;
1807                         case AXIS_THROTTLE:  kc_other[22].value = i; kc_other[23].value = inv; break;
1808                         case AXIS_NONE:      break;
1809                         default:
1810                                 Int3();
1811                                 break;
1812                 }
1813         }
1814 }
1815
1816 #if 0 // no mac support for vr headset
1817
1818 void kconfig_center_headset()
1819 {
1820         if (vfx1_installed)
1821                 vfx_center_headset();
1822 //      } else if (iglasses_headset_installed)  {
1823 //      } else if (Victor_headset_installed)   {
1824 //      } else {
1825 //      }
1826
1827 }
1828
1829 #endif // end of #if for kconfig_center_headset
1830
1831 void CybermouseAdjust ()
1832  {
1833 /*      if ( Player_num > -1 )  {
1834                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
1835                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
1836                 cvar_setint(&Auto_leveling_on, 0);
1837
1838                 if ( kc_external_version > 0 ) {                
1839                         vms_matrix tempm, ViewMatrix;
1840                         vms_angvec * Kconfig_abs_movement;
1841                         char * oem_message;
1842         
1843                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(control_info));
1844         
1845                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
1846                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
1847                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1848                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
1849                         }
1850                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
1851                         if (oem_message[0] != '\0' )
1852                                 HUD_init_message( oem_message );
1853                 }
1854         }*/
1855
1856         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
1857         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
1858         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
1859         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
1860         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
1861         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
1862 //      Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
1863 //      Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
1864         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
1865         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
1866         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
1867         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
1868         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
1869         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
1870 //      Controls.automap_down_count += kc_external_control->automap_down_count;
1871 //      Controls.automap_state |= kc_external_control->automap_state;
1872   } 
1873
1874 char GetKeyValue (char key)
1875   {
1876         mprintf ((0,"Returning %c!\n",kc_keyboard[(int)key].value));
1877         return (kc_keyboard[(int)key].value);
1878   }
1879
1880
1881 #if 0 // unused
1882 extern object *obj_find_first_of_type (int);
1883 void kconfig_read_external_controls()
1884 {
1885         //union REGS r;
1886    int i;
1887
1888         if ( !kc_enable_external_control ) return;
1889
1890         if ( kc_external_version == 0 ) 
1891                 memset( kc_external_control, 0, sizeof(ext_control_info));
1892         else if ( kc_external_version > 0 )     {
1893         
1894                 if (kc_external_version>=4)
1895                         memset( kc_external_control, 0, sizeof(advanced_ext_control_info));
1896       else if (kc_external_version>0)     
1897                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 );
1898                 else if (kc_external_version>2)
1899                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof(vms_matrix) +4 );
1900
1901                 if ( kc_external_version > 1 ) {
1902                         // Write ship pos and angles to external controls...
1903                         ubyte *temp_ptr = (ubyte *)kc_external_control;
1904                         vms_vector *ship_pos;
1905                         vms_matrix *ship_orient;
1906                         memset( kc_external_control, 0, sizeof(ext_control_info)+sizeof(vms_angvec) + 64 + sizeof(vms_vector)+sizeof(vms_matrix) );
1907                         temp_ptr += sizeof(ext_control_info) + sizeof(vms_angvec) + 64;
1908                         ship_pos = (vms_vector *)temp_ptr;
1909                         temp_ptr += sizeof(vms_vector);
1910                         ship_orient = (vms_matrix *)temp_ptr;
1911                         // Fill in ship postion...
1912                         *ship_pos = Objects[Players[Player_num].objnum].pos;
1913                         // Fill in ship orientation...
1914                         *ship_orient = Objects[Players[Player_num].objnum].orient;
1915                 }
1916     if (kc_external_version>=4)
1917           {
1918            advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
1919  
1920       temp_ptr->headlight_state=(Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT_ON);
1921                 temp_ptr->primary_weapon_flags=Players[Player_num].primary_weapon_flags;
1922                 temp_ptr->secondary_weapon_flags=Players[Player_num].secondary_weapon_flags;
1923       temp_ptr->current_primary_weapon=Primary_weapon;
1924       temp_ptr->current_secondary_weapon=Secondary_weapon;
1925
1926       temp_ptr->current_guidebot_command=Escort_goal_object;
1927
1928            temp_ptr->force_vector=ExtForceVec;
1929                 temp_ptr->force_matrix=ExtApplyForceMatrix;
1930            for (i=0;i<3;i++)
1931        temp_ptr->joltinfo[i]=ExtJoltInfo[i];  
1932       for (i=0;i<2;i++)
1933                    temp_ptr->x_vibrate_info[i]=ExtXVibrateInfo[i];
1934                 temp_ptr->x_vibrate_clear=ExtXVibrateClear;
1935            temp_ptr->game_status=ExtGameStatus;
1936    
1937       memset ((void *)&ExtForceVec,0,sizeof(vms_vector));
1938       memset ((void *)&ExtApplyForceMatrix,0,sizeof(vms_matrix));
1939       
1940       for (i=0;i<3;i++)
1941                  ExtJoltInfo[i]=0;
1942       for (i=0;i<2;i++)
1943                  ExtXVibrateInfo[i]=0;
1944       ExtXVibrateClear=0;
1945      }
1946         }
1947
1948         if ( Automap_active )                   // (If in automap...)
1949                 kc_external_control->automap_state = 1;
1950         //memset(&r,0,sizeof(r));
1951
1952   #if 0
1953  
1954         int386 ( kc_external_intno, &r, &r);            // Read external info...
1955
1956   #endif 
1957
1958         if ( Player_num > -1 )  {
1959                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_TURNROLL);    // Turn off roll when turning
1960                 Objects[Players[Player_num].objnum].mtype.phys_info.flags &= (~PF_LEVELLING);   // Turn off leveling to nearest side.
1961                 cvar_setint(&Auto_leveling_on, 0);
1962
1963                 if ( kc_external_version > 0 ) {                
1964                         vms_matrix tempm, ViewMatrix;
1965                         vms_angvec * Kconfig_abs_movement;
1966                         char * oem_message;
1967         
1968                         Kconfig_abs_movement = (vms_angvec *)((uint)kc_external_control + sizeof(ext_control_info));
1969         
1970                         if ( Kconfig_abs_movement->p || Kconfig_abs_movement->b || Kconfig_abs_movement->h )    {
1971                                 vm_angles_2_matrix(&tempm,Kconfig_abs_movement);
1972                                 vm_matrix_x_matrix(&ViewMatrix,&Objects[Players[Player_num].objnum].orient,&tempm);
1973                                 Objects[Players[Player_num].objnum].orient = ViewMatrix;                
1974                         }
1975                         oem_message = (char *)((uint)Kconfig_abs_movement + sizeof(vms_angvec));
1976                         if (oem_message[0] != '\0' )
1977                                 HUD_init_message( oem_message );
1978                 }
1979         }
1980
1981         Controls.pitch_time += fixmul(kc_external_control->pitch_time,FrameTime);                                               
1982         Controls.vertical_thrust_time += fixmul(kc_external_control->vertical_thrust_time,FrameTime);
1983         Controls.heading_time += fixmul(kc_external_control->heading_time,FrameTime);
1984         Controls.sideways_thrust_time += fixmul(kc_external_control->sideways_thrust_time ,FrameTime);
1985         Controls.bank_time += fixmul(kc_external_control->bank_time ,FrameTime);
1986         Controls.forward_thrust_time += fixmul(kc_external_control->forward_thrust_time ,FrameTime);
1987         Controls.rear_view_down_count += kc_external_control->rear_view_down_count;     
1988         Controls.rear_view_down_state |= kc_external_control->rear_view_down_state;     
1989         Controls.fire_primary_down_count += kc_external_control->fire_primary_down_count;
1990         Controls.fire_primary_state |= kc_external_control->fire_primary_state;
1991         Controls.fire_secondary_state |= kc_external_control->fire_secondary_state;
1992         Controls.fire_secondary_down_count += kc_external_control->fire_secondary_down_count;
1993         Controls.fire_flare_down_count += kc_external_control->fire_flare_down_count;
1994         Controls.drop_bomb_down_count += kc_external_control->drop_bomb_down_count;     
1995         Controls.automap_down_count += kc_external_control->automap_down_count;
1996         Controls.automap_state |= kc_external_control->automap_state;
1997         
1998    if (kc_external_version>=3)
1999          {
2000                 ubyte *temp_ptr = (ubyte *)kc_external_control;
2001                 temp_ptr += (sizeof(ext_control_info) + sizeof(vms_angvec) + 64 + sizeof(vms_vector) + sizeof (vms_matrix));
2002   
2003            if (*(temp_ptr))
2004                  Controls.cycle_primary_count=(*(temp_ptr));
2005            if (*(temp_ptr+1))
2006                  Controls.cycle_secondary_count=(*(temp_ptr+1));
2007
2008                 if (*(temp_ptr+2))
2009                  Controls.afterburner_state=(*(temp_ptr+2));
2010                 if (*(temp_ptr+3))
2011                  Controls.headlight_count=(*(temp_ptr+3));
2012          }
2013    if (kc_external_version>=4)
2014          {
2015      int i;
2016           advanced_ext_control_info *temp_ptr=(advanced_ext_control_info *)kc_external_control;
2017      
2018      for (i=0;i<128;i++)
2019            if (temp_ptr->keyboard[i])
2020                         key_putkey (i);
2021
2022      if (temp_ptr->Reactor_blown)
2023       {
2024        if (Game_mode & GM_MULTI)
2025                     net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
2026                  else
2027                          do_controlcen_destroyed_stuff(obj_find_first_of_type (OBJ_CNTRLCEN));
2028            }
2029     }
2030   
2031 }
2032 #endif
2033