]> icculus.org git repositories - taylor/freespace2.git/blob - src/controlconfig/controlsconfigcommon.cpp
added copyright header
[taylor/freespace2.git] / src / controlconfig / controlsconfigcommon.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/ControlConfig/ControlsConfigCommon.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * C module for keyboard, joystick and mouse configuration common stuff (between Fred and FreeSpace)
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:15  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:43  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:08  root
25  * Initial import.
26  *
27  * 
28  * 14    11/01/99 3:36p Jefff
29  * had scan code texts for y and z in german swapped
30  * 
31  * 13    11/01/99 2:16p Jefff
32  * minor key name change in german
33  * 
34  * 12    10/29/99 6:10p Jefff
35  * squashed the damned y/z german issues once and for all
36  * 
37  * 11    10/28/99 11:16p Jefff
38  * Changed some german key names.  Made key translations always use the
39  * english table.
40  * 
41  * 10    10/28/99 2:05a Jefff
42  * revised some german key names.  changed some y/z switch stuff.
43  * 
44  * 9     10/25/99 5:39p Jefff
45  * swap init binding for y and z keys in German builds
46  * 
47  * 8     9/01/99 2:56p Jefff
48  * a few control key description changes
49  * 
50  * 7     8/22/99 5:53p Dave
51  * Scoring fixes. Added self destruct key. Put callsigns in the logfile
52  * instead of ship designations for multiplayer players.
53  * 
54  * 6     8/19/99 10:59a Dave
55  * Packet loss detection.
56  * 
57  * 5     8/01/99 12:39p Dave
58  * Added HUD contrast control key (for nebula).
59  * 
60  * 4     7/23/99 2:57p Andsager
61  * fix translate_key_to_index to work with localization
62  * 
63  * 3     11/05/98 4:18p Dave
64  * First run nebula support. Beefed up localization a bit. Removed all
65  * conditional compiles for foreign versions. Modified mission file
66  * format.
67  * 
68  * 2     10/07/98 10:52a Dave
69  * Initial checkin.
70  * 
71  * 1     10/07/98 10:48a Dave
72  * 
73  * 41    6/19/98 3:51p Lawrance
74  * localize control text
75  * 
76  * 40    6/17/98 11:05a Lawrance
77  * localize the control config strings
78  * 
79  * 39    5/24/98 2:28p Hoffoss
80  * Because we never really care about if the left or the right shift or
81  * alt key was used, but rather than either shift or alt was used, made
82  * both map to the left one.  Solves some problems, causes none.
83  * 
84  * 38    5/22/98 11:21a Hoffoss
85  * Added bank when pressed back in.
86  * 
87  * 37    5/15/98 8:37p Lawrance
88  * Add 'equalize recharge rates' and 'target ship that sent last
89  * transmission' key bindings
90  * 
91  * 36    5/13/98 7:15p Hoffoss
92  * Fixed remaining bugs with axis binding.
93  * 
94  * 35    5/13/98 1:17a Hoffoss
95  * Added joystick axes configurability.
96  * 
97  * 34    5/12/98 11:25a Hoffoss
98  * Disabled bank when pressed action.
99  * 
100  * 33    5/09/98 10:48p Lawrance
101  * change text for view bindings
102  * 
103  * 32    5/09/98 4:52p Lawrance
104  * Implement padlock view (up/rear/left/right)
105  * 
106  * 31    4/30/98 9:43p Hoffoss
107  * Added new actions for free look movement which are default bounded to
108  * the hat.
109  * 
110  * 30    4/25/98 1:25p Lawrance
111  * Add time compression keys to key config
112  * 
113  * 29    4/25/98 12:43p Allender
114  * added new shortcut key for attack my subsystem
115  * 
116  * 28    4/18/98 5:00p Dave
117  * Put in observer zoom key. Made mission sync screen more informative.
118  * 
119  * 27    4/17/98 1:24a Lawrance
120  * fix spelling error
121  * 
122  * 26    4/15/98 11:06a Lawrance
123  * fix bug with a multi key showing up in demo, remove obsolete bindings
124  * from demo and full version
125  * 
126  * 25    4/10/98 12:47p Allender
127  * changed working on replay popup.  Don't reference repair in comm menu.
128  * Added Shift-R for repair me
129  * 
130  * 24    4/08/98 11:11a Hoffoss
131  * Fixed some bugs that showed up due to fixing other bugs the other day
132  * with controls.
133  * 
134  * 23    4/07/98 4:06p Lawrance
135  * Change binding next for bomb targeting
136  * 
137  * 22    4/07/98 1:52p Lawrance
138  * fix error in binding text for energy keys 
139  * 
140  * 21    4/06/98 11:17a Hoffoss
141  * Fixed num lock/pause interplay bug.
142  * 
143  * 20    4/01/98 6:46p Lawrance
144  * change text for Alt+J
145  * 
146  * 19    3/31/98 4:15p Hoffoss
147  * Disabled the show objectives action.
148  * 
149  * 18    3/25/98 2:16p Dave
150  * Select random default image for newly created pilots. Fixed several
151  * multi-pause messaging bugs. Begin work on online help for multiplayer
152  * keys.
153  * 
154  * 17    3/19/98 5:04p Dave
155  * Put in support for targeted multiplayer text and voice messaging (all,
156  * friendly, hostile, individual).
157  * 
158  * 16    3/17/98 11:25a Hoffoss
159  * Fixed some of the action's names.
160  * 
161  * 15    3/17/98 10:48a Hoffoss
162  * Allowed a special hack for "bank while pressed" action to use alt and
163  * shift keys standalone.
164  * 
165  * 14    2/28/98 9:47p Lawrance
166  * change some binding text
167  * 
168  * 13    2/28/98 7:02p Lawrance
169  * overhaul on-line help
170  * 
171  * 12    2/26/98 12:33a Lawrance
172  * Added back slew mode,  lots of changes to external and chase views.
173  * 
174  * 11    2/23/98 11:25a Sandeep
175  * added default keys
176  * 
177  * 10    2/22/98 6:27p Lawrance
178  * External mode takes precedence over chase mode.  Fix bug with repair
179  * ships docking in chase mode.
180  * 
181  * 9     2/22/98 12:19p John
182  * Externalized some strings
183  * 
184  * 8     2/02/98 6:59p Lawrance
185  * Adding new targeting keys (bomb, uninspected cargo, new ship, live
186  * turrets).
187  * 
188  * 7     1/27/98 4:24p Allender
189  * moved hotkey selection to F3 instead of X.  Made palette flash
190  * disappear in multiplayer pause menu
191  * 
192  * 6     1/22/98 4:53p Hoffoss
193  * Made training messages/directives display a joystick button in place of
194  * a keypress if there is no keypress bound to the action.
195  * 
196  * 5     1/22/98 4:15p Hoffoss
197  * Added code to allow popup to tell player he needs to bind a key for the
198  * training mission.
199  * 
200  * 4     1/02/98 4:42p Allender
201  * removed unused key bindings from control config list
202  * 
203  * 3     12/30/97 4:47p Allender
204  * work with ignore my target command.  Added new keyboard hotkey.  Made
205  * it work globally
206  * 
207  * 2     12/24/97 3:37p Hoffoss
208  * Moved control config stuff to seperate library to Fred can access it as
209  * well.
210  * 
211  * 1     12/24/97 3:27p Hoffoss
212  * 
213  * 1     12/24/97 11:58a Hoffoss
214  * 
215  * 98    12/22/97 2:15p Hoffoss
216  * Fixed bug where joystick axis lines weren't being displayed.
217  * 
218  * 97    12/16/97 2:44p Hoffoss
219  * Added clear button to control config screen.
220  * 
221  * 96    12/12/97 3:07p Hoffoss
222  * Changed how deleting bindings work.  Each control of an action can be
223  * deleted independently or both at once.
224  * 
225  * 95    12/07/97 2:36p John
226  * Made warp out be Alt+J instead of J
227  * 
228  * 94    12/03/97 4:59p Hoffoss
229  * Added reset sound and change control config sounds around.
230  * 
231  * 93    12/03/97 4:16p Hoffoss
232  * Changed sound stuff used in interface screens for interface purposes.
233  * 
234  * 92    12/01/97 5:25p Hoffoss
235  * Routed interface sound playing through a special function that will
236  * only allow one instance of the sound to play at a time, avoiding
237  * over-mixing problems.
238  * 
239  * 91    12/01/97 3:38p Hoffoss
240  * Changed placement of 'More' indicator.
241  * 
242  * 90    11/25/97 3:49p Hoffoss
243  * Changed subhilighting to happen when mouse is over line, rather than
244  * mouse button down but not up again yet.
245  * 
246  * 89    11/24/97 10:20p Lawrance
247  * Add key 'KEY_N' to target next ship on monitoring view
248  * 
249  * 88    11/24/97 6:15p Lawrance
250  * fix button scroll problem
251  * 
252  * 87    11/23/97 6:15p Hoffoss
253  * Make exiting the controls config screen save the pilot, so changes keep
254  * even if programs crashes or something.
255  * 
256  * 86    11/21/97 5:57p Hoffoss
257  * Fixed bug where timef type controls weren't checking joystick buttons.
258  * 
259  * 85    11/21/97 4:06p Hoffoss
260  * Fixed bug with enabling of axis are reversed.
261  * 
262  * 84    11/20/97 4:47p Hoffoss
263  * Swapped throttle and rudder, which apparently were backwards.
264  * 
265  * 83    11/20/97 4:00p Lawrance
266  * set z to a valid value
267  * 
268  * 82    11/20/97 3:52p Hoffoss
269  * Made "None" appear if no control is bound to function.
270  * 
271  * 81    11/20/97 2:10p Hoffoss
272  * Added defaults for  joystick buttons 2 and 3.
273  * 
274  * 80    11/20/97 1:08a Lawrance
275  * add support for 'R' key - target closest friendly repair ship
276  * 
277  * 79    11/19/97 8:33p Hoffoss
278  * New controls config screen baby!
279  * 
280  * 78    11/17/97 7:09p Hoffoss
281  * Made chase view control a trigger type.
282  * 
283  * 77    11/17/97 6:40p Lawrance
284  * Changed 'I' key to toggle of extended target info, moved target closest
285  * locked missile to 'L'
286  * 
287  * 76    11/17/97 3:26p Jasen
288  * Adjusted coordinates for the help button .ani location
289  * 
290  * 75    11/16/97 3:51p Hoffoss
291  * Added more button to config screen when scrolling allowed.
292  * 
293  * 74    11/16/97 3:20p Hoffoss
294  * Added various suggestions from the Todolist.
295  * 
296  * 73    11/14/97 4:33p Mike
297  * Change Debug key to backquote (from F11).
298  * Balance a ton of subsystems in ships.tbl.
299  * Change "Heavy Laser" to "Disruptor".
300  * 
301  * 72    11/12/97 2:54p Hoffoss
302  * Made modifiers non-stand alone, added support for red tabs on
303  * conflicts.
304  * 
305  * 71    10/30/97 6:01p Hoffoss
306  * Changed screen to utilize the new text color standards.
307  * 
308  * 70    10/29/97 7:25p Hoffoss
309  * Added crude support for UI button double click checking.
310  * 
311  * 69    10/29/97 6:32p Hoffoss
312  * Changed some interface apperances.
313  * 
314  * 68    10/29/97 4:54p Hoffoss
315  * Changed scan_code_text element for Enter to 'Enter' instead of 'a' with
316  * a caret over it (what's that all about?)
317  * 
318  * 67    10/28/97 10:42a Hoffoss
319  * Fixed handling of continuous controls that have modifiers to the key.
320  * 
321  * 66    10/28/97 10:03a Hoffoss
322  * Fixed bug with continuous type controls not registering if pressed and
323  * released too quickly.  Also some other little changes.
324  * 
325  * 65    10/28/97 12:12a Lawrance
326  * remove unused keys (Alt-H and Alt-F)
327  * 
328  * 64    10/27/97 12:23p Hoffoss
329  * Improved warning system and fixed coloring bug.
330  * 
331  * 63    10/27/97 11:39a Hoffoss
332  * Added control conflicts checking.
333  * 
334  * 62    10/26/97 3:20p Hoffoss
335  * Added many missing features to control config screen.
336  * 
337  * 61    10/25/97 5:41p Hoffoss
338  * More functionality added to the controls config screen.
339  * 
340  * 60    10/24/97 11:00p Hoffoss
341  * Controls config screen much improved.
342  * 
343  * 59    10/22/97 4:50p Hoffoss
344  * Disabled throttle by default.
345  * 
346  * 58    10/22/97 11:00a Hoffoss
347  * Changed VIEW_SLEW and VIEW_EXTERNAL to be continuous rather than
348  * trigger actions.
349  * 
350  * 57    10/21/97 7:05p Hoffoss
351  * Overhauled the key/joystick control structure and usage throughout the
352  * entire FreeSpace code.  The whole system is very different now.
353  * 
354  * 56    10/18/97 7:19p Hoffoss
355  * Added timestamp recording when a key is pressed.
356  * 
357  * 55    10/13/97 4:33p Hoffoss
358  * Made training messages go away after time.
359  * 
360  * 54    10/13/97 3:24p Hoffoss
361  * Made it so training message text can be arbitrarily bolded.
362  * 
363  * 53    9/24/97 4:52p Hoffoss
364  * Changed training message key token handling, and implemented a new
365  * training message system method to test out for a while.
366  * 
367  * 52    9/14/97 10:24p Lawrance
368  * add damage screen popup window
369  * 
370  * 51    9/10/97 6:02p Hoffoss
371  * Added code to check for key-pressed sexp operator in FreeSpace as part
372  * of training mission stuff.
373  * 
374  * 50    9/09/97 3:39p Sandeep
375  * warning level 4 bugs
376  * $NoKeywords: $
377  *
378 */
379
380 #include "controlsconfig.h"
381 #include "key.h"
382 #include "joy.h"
383 #include "localize.h"
384
385 #define TARGET_TAB                      0
386 #define SHIP_TAB                                1
387 #define WEAPON_TAB                      2
388 #define COMPUTER_TAB                    3
389
390 int Failed_key_index;
391
392 // assume control keys are used as modifiers until we find out 
393 int Shift_is_modifier;
394 int Ctrl_is_modifier;
395 int Alt_is_modifier;
396
397 int Axis_enabled[JOY_NUM_AXES] = { 1, 1, 1, 0, 0, 0 };
398 int Axis_enabled_defaults[JOY_NUM_AXES] = { 1, 1, 1, 0, 0, 0 };
399 int Invert_axis[JOY_NUM_AXES] = { 0, 0, 0, 0, 0, 0 };
400 int Invert_axis_defaults[JOY_NUM_AXES] = { 0, 0, 0, 0, 0, 0 };
401
402 // arrays which hold the key mappings.  The array index represents a key-independent action.
403 //
404 //XSTR:OFF
405 config_item Control_config[CCFG_MAX + 1] = {
406         // targeting a ship
407         {                           KEY_T,                              -1, TARGET_TAB, "Target Next Ship" },
408         {             KEY_SHIFTED | KEY_T,                              -1, TARGET_TAB, "Target Previous Ship" },
409         {                           KEY_H,                              2,  TARGET_TAB, "Target Next Closest Hostile Ship" },
410         {                  KEY_SHIFTED | KEY_H,                         -1, TARGET_TAB, "Target Previous Closest Hostile Ship" },
411         { KEY_ALTED |               KEY_H,                              -1, TARGET_TAB, "Toggle Auto Targeting" },
412         {                           KEY_F,                              -1, TARGET_TAB, "Target Next Closest Friendly Ship" },
413         {             KEY_SHIFTED | KEY_F,                              -1, TARGET_TAB, "Target Previous Closest Friendly Ship" },
414         {                           KEY_Y,                              4,  TARGET_TAB, "Target Ship in Reticle" },
415         {                           KEY_G,                              -1, TARGET_TAB, "Target Target's Nearest Attacker" },
416         { KEY_ALTED     |                                        KEY_Y,                         -1, TARGET_TAB, "Target Last Ship to Send Transmission" },
417         { KEY_ALTED |               KEY_T,                              -1, TARGET_TAB, "Turn Off Auto-Targeting" },
418
419         // targeting a ship's subsystem
420         {                           KEY_V,                              -1, TARGET_TAB, "Target Subsystem in Reticle" },
421         {                           KEY_S,                              -1, TARGET_TAB, "Target Next Subsystem" },
422         {             KEY_SHIFTED | KEY_S,                              -1, TARGET_TAB, "Target Previous Subsystem" },
423         { KEY_ALTED |               KEY_S,                              -1, TARGET_TAB, "Turn Off Auto-Targeting of Subsystems" },
424
425         // matching speed
426         {                           KEY_M,                              -1, COMPUTER_TAB,       "Match Target Speed" },
427         { KEY_ALTED |               KEY_M,                              -1, COMPUTER_TAB,       "Toggle Auto Speed Matching" },
428
429         // weapons
430         {                           KEY_LCTRL,                  0,       WEAPON_TAB,    "Fire Primary Weapon", CC_TYPE_CONTINUOUS },
431         {                           KEY_SPACEBAR,               1,  WEAPON_TAB, "Fire Secondary Weapon", CC_TYPE_CONTINUOUS },
432         {                           KEY_PERIOD,         -1, WEAPON_TAB, "Cycle Forward Primary Weapon" },
433         {                           KEY_COMMA,                  -1, WEAPON_TAB, "Cycle Backward Primary Weapon" },
434         {                           KEY_DIVIDE,         -1, WEAPON_TAB, "Cycle Secondary Weapon Bank" },
435         {             KEY_SHIFTED | KEY_DIVIDE,         -1, WEAPON_TAB, "Cycle Secondary Weapon Firing Rate" },
436         {                           KEY_X,                              3,       WEAPON_TAB,    "Launch Countermeasure" },
437
438         // controls
439         {                           KEY_A,                              -1, SHIP_TAB,           "Forward Thrust", CC_TYPE_CONTINUOUS },
440         {                           KEY_Z,                              -1, SHIP_TAB,           "Reverse Thrust", CC_TYPE_CONTINUOUS },
441         {                           KEY_PAD7,                   -1, SHIP_TAB,           "Bank Left", CC_TYPE_CONTINUOUS },
442         {                           KEY_PAD9,                   -1, SHIP_TAB,           "Bank Right", CC_TYPE_CONTINUOUS },
443         {                           KEY_PAD8,                   -1, SHIP_TAB,           "Pitch Forward", CC_TYPE_CONTINUOUS },
444         {                           KEY_PAD2,                   -1, SHIP_TAB,           "Pitch Backward", CC_TYPE_CONTINUOUS },
445         {                           KEY_PAD4,                   -1, SHIP_TAB,           "Turn Left", CC_TYPE_CONTINUOUS },
446         {                           KEY_PAD6,                   -1, SHIP_TAB,           "Turn Right", CC_TYPE_CONTINUOUS },
447
448         // throttle controls
449         {                           KEY_BACKSP,         -1, SHIP_TAB,           "Set Throttle to Zero" },
450         {                           KEY_SLASH,                  -1, SHIP_TAB,           "Set Throttle to Max" },
451         {                           KEY_LBRACKET,               -1, SHIP_TAB,           "Set Throttle to One-Third" },
452         {                           KEY_RBRACKET,               -1, SHIP_TAB,           "Set Throttle to Two-Thirds" },
453         {                           KEY_EQUAL,                  -1, SHIP_TAB,           "Increase Throttle 5 Percent" },
454         {                           KEY_MINUS,                  -1, SHIP_TAB,           "Decrease Throttle 5 Percent" },
455
456         // squadmate messaging
457         {             KEY_SHIFTED | KEY_A,                              -1, COMPUTER_TAB,       "Attack My Target" },
458         {             KEY_SHIFTED | KEY_Z,                              -1, COMPUTER_TAB,       "Disarm My Target" },
459         {             KEY_SHIFTED | KEY_D,                              -1, COMPUTER_TAB,       "Disable My Target" },
460         {             KEY_SHIFTED | KEY_V,                              -1, COMPUTER_TAB,       "Attack my Subsystem" },
461         {             KEY_SHIFTED | KEY_X,                              -1, COMPUTER_TAB,       "Capture My Target" },
462         {             KEY_SHIFTED | KEY_E,                              -1, COMPUTER_TAB,       "Engage Enemy" },
463         {             KEY_SHIFTED | KEY_W,                              -1, COMPUTER_TAB,       "Form on my Wing" },
464         {             KEY_SHIFTED | KEY_I,                              -1, COMPUTER_TAB,       "Ignore my Target" },
465         {             KEY_SHIFTED | KEY_P,                              -1, COMPUTER_TAB,       "Protect my Target" },
466         {             KEY_SHIFTED | KEY_C,                              -1, COMPUTER_TAB,       "Cover me" },
467         {             KEY_SHIFTED | KEY_J,                              -1, COMPUTER_TAB,       "Return to base" },
468         {                                 KEY_SHIFTED | KEY_R,                          -1, COMPUTER_TAB, "Rearm me" },
469
470         {                                                                        KEY_R,                         6,  TARGET_TAB, "Target Closest Attacking Ship" },
471
472         // Views
473         {                           KEY_PADMULTIPLY,    -1, COMPUTER_TAB,       "Chase View" },
474         {                           KEY_PADPERIOD,      -1, COMPUTER_TAB,       "External View"},
475         {                           KEY_PADENTER,               -1, COMPUTER_TAB,       "Toggle External Camera Lock"},
476         {                           KEY_PAD0,                   -1, COMPUTER_TAB,       "Free Look View", CC_TYPE_CONTINUOUS },
477         {                           KEY_PADDIVIDE,      -1, COMPUTER_TAB,       "Current Target View" },
478         {                           KEY_PADPLUS,                -1, COMPUTER_TAB,       "Increase View Distance", CC_TYPE_CONTINUOUS },
479         {                           KEY_PADMINUS,               -1, COMPUTER_TAB,       "Decrease View Distance", CC_TYPE_CONTINUOUS },
480         {                           KEY_PAD5,                   -1, COMPUTER_TAB,       "Center View", CC_TYPE_CONTINUOUS },
481         {                                                                        -1,                                    33, COMPUTER_TAB, "View Up", CC_TYPE_CONTINUOUS },
482         {                                                                        -1,                                    32, COMPUTER_TAB, "View Rear", CC_TYPE_CONTINUOUS },
483         {                                                                        -1,                                    34, COMPUTER_TAB, "View Left", CC_TYPE_CONTINUOUS },
484         {                                                                        -1,                                    35, COMPUTER_TAB, "View Right", CC_TYPE_CONTINUOUS },
485
486         {                           KEY_RAPOSTRO,               -1, COMPUTER_TAB,       "Cycle Radar Range" },
487         {                           KEY_C,                              -1, COMPUTER_TAB, "Communications Menu" },
488         {                           -1,                                 -1, -1,                         "Show Objectives" },
489         { KEY_ALTED |               KEY_J,                              -1, COMPUTER_TAB,       "Enter Subspace (End Mission)" },
490         {                           KEY_J,                              -1, TARGET_TAB, "Target Target's Target" },
491         {                           KEY_TAB,                    5,  SHIP_TAB,           "Afterburner", CC_TYPE_CONTINUOUS },
492         
493         {                           KEY_INSERT,         -1, COMPUTER_TAB,       "Increase Weapon Energy" },
494         {                           KEY_DELETE,         -1, COMPUTER_TAB,       "Decrease Weapon Energy" },
495         {                           KEY_HOME,                   -1, COMPUTER_TAB,       "Increase Shield Energy" },
496         {                           KEY_END,                    -1, COMPUTER_TAB,       "Decrease Shield Energy" },
497         {                           KEY_PAGEUP,         -1, COMPUTER_TAB,       "Increase Engine Energy" },
498         {                           KEY_PAGEDOWN,               -1, COMPUTER_TAB,       "Decrease Engine Energy" },
499         { KEY_ALTED |               KEY_D,                              -1, COMPUTER_TAB, "Equalize Energy Settings" },
500
501         {                           KEY_Q,                              7,  COMPUTER_TAB,       "Equalize Shield" },
502         {                           KEY_UP,                             -1, COMPUTER_TAB,       "Augment Forward Shield" },
503         {                           KEY_DOWN,                   -1, COMPUTER_TAB,       "Augment Rear Shield" },
504         {                           KEY_LEFT,                   -1, COMPUTER_TAB,       "Augment Left Shield" },
505         {                           KEY_RIGHT,                  -1, COMPUTER_TAB,       "Augment Right Shield" },
506         {                           KEY_SCROLLOCK,      -1, COMPUTER_TAB,       "Transfer Energy Laser->Shield" },
507         {             KEY_SHIFTED | KEY_SCROLLOCK,      -1, COMPUTER_TAB,       "Transfer Energy Shield->Laser" },
508         {                           -1,                                 -1, -1,                         "Show Damage Popup Window" },   
509
510         {                           -1,                                 -1, SHIP_TAB,           "Bank When Pressed", CC_TYPE_CONTINUOUS },
511         {                                                                        -1,                                    -1, -1,                         "Show NavMap" },
512         { KEY_ALTED |                KEY_E,                             -1, COMPUTER_TAB,       "Add or Remove Escort" },
513         { KEY_ALTED | KEY_SHIFTED | KEY_E,                              -1, COMPUTER_TAB,       "Clear Escort List" },
514         {                                                    KEY_E,                             -1, TARGET_TAB, "Target Next Escort Ship" },
515         { KEY_ALTED     |                                        KEY_R,                         -1, TARGET_TAB, "Target Closest Repair Ship" },
516
517         {                           KEY_U,                              -1, TARGET_TAB, "Target Next Uninspected Cargo" },
518         {             KEY_SHIFTED | KEY_U,                              -1, TARGET_TAB, "Target Previous Uninspected Cargo" },
519         {                                                                        KEY_N,                         -1, TARGET_TAB, "Target Newest Ship In Area" },
520         {                           KEY_K,                              -1, TARGET_TAB, "Target Next Live Turret" },
521         {             KEY_SHIFTED | KEY_K,                              -1, TARGET_TAB, "Target Previous Live Turret" },
522
523         {                                                                        KEY_B,                         -1, TARGET_TAB, "Target Next Hostile Bomb or Bomber" },
524         {             KEY_SHIFTED | KEY_B,                              -1, TARGET_TAB, "Target Previous Hostile Bomb or Bomber" },
525
526         // multiplayer messaging keys
527         {                                                                        KEY_1,                         -1, COMPUTER_TAB,       "(Multiplayer) Message All", CC_TYPE_CONTINUOUS },
528         {                                                                        KEY_2,                         -1, COMPUTER_TAB, "(Multiplayer) Message Friendly", CC_TYPE_CONTINUOUS },
529         {                                                                        KEY_3,                         -1, COMPUTER_TAB, "(Multiplayer) Message Hostile", CC_TYPE_CONTINUOUS },
530         {                                                                        KEY_4,                         -1, COMPUTER_TAB, "(Multiplayer) Message Target", CC_TYPE_CONTINUOUS },
531         { KEY_ALTED     |                                        KEY_X,                         -1, COMPUTER_TAB, "(Multiplayer) Observer zoom to target"},     
532
533         {             KEY_SHIFTED | KEY_PERIOD,         -1, COMPUTER_TAB,       "Increase time compression" },
534         {             KEY_SHIFTED | KEY_COMMA,                  -1, COMPUTER_TAB,       "Decrease time compression" },
535
536         {                                                                        KEY_L,                         -1, COMPUTER_TAB, "Toggle high HUD contrast" }, 
537
538         {                                 KEY_SHIFTED | KEY_N,                          -1, COMPUTER_TAB, "(Multiplayer) Toggle network info"},
539         {                                 KEY_SHIFTED | KEY_END,                        -1, COMPUTER_TAB, "(Multiplayer) Self destruct"},
540
541         {                           -1,                                 -1, -1,                         "" }
542 };
543
544 char *Scan_code_text_german[] = {
545         "",                             "Esc",                          "1",                            "2",                            "3",                            "4",                            "5",                            "6",
546         "7",                            "8",                            "9",                            "0",                            "Akzent '",                             "\xE1",                         "R\x81""cktaste",               "Tab",
547         "Q",                            "W",                            "E",                            "R",                            "T",                            "Z",                            "U",                            "I",
548         "O",                            "P",                            "\x9A",                         "+",                            "Eingabe",                      "Strg Links",                   "A",                            "S",
549
550         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            "\x99",
551         "\xAE",                         "`",                            "Shift",                        "#",                            "Y",                            "X",                            "C",                            "V",
552         "B",                            "N",                            "M",                            ",",                            ".",                            "-",                            "Shift",                        "Num *",
553         "Alt",                          "Leertaste",                    "Hochstell",                    "F1",                           "F2",                           "F3",                           "F4",                           "F5",
554
555         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                          "Pause",                        "Rollen",                       "Num 7",
556         "Num 8",                        "Num 9",                        "Num -",                        "Num 4",                        "Num 5",                        "Num 6",                        "Num +",                        "Num 1",
557         "Num 2",                        "Num 3",                        "Num 0",                        "Num ,",                        "",                             "",                             "",                             "F11",
558         "F12",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
559
560         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
561         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
562         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
563         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
564
565         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
566         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
567         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
568         "",                             "",                             "",                             "",                             "Num Eingabe",                  "Strg Rechts",                  "",                             "",
569
570         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
571         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
572         "",                             "",                             "",                             "",                             "",                             "Num /",                        "",                             "Druck",
573         "Alt",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
574
575         "",                             "",                             "",                             "",                             "",                             "Num Lock",                     "",                             "Pos 1",
576         "Pfeil Hoch",                   "Bild Hoch",                    "",                             "Pfeil Links",                  "",                             "Pfeil Rechts",                 "",                             "Ende",
577         "Pfeil Runter",                         "Bild Runter",                  "Einfg",                        "Entf",                         "",                             "",                             "",                             "",
578         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
579
580         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
581         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
582         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
583         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
584 };
585
586 char *Joy_button_text_german[] = {
587         "Knopf 1",              "Knopf 2",              "Knopf 3",              "Knopf 4",              "Knopf 5",              "Knopf 6",
588         "Knopf 7",              "Knopf 8",              "Knopf 9",              "Knopf 10",             "Knopf 11",             "Knopf 12",
589         "Knopf 13",             "Knopf 14",             "Knopf 15",             "Knopf 16",             "Knopf 17",             "Knopf 18",
590         "Knopf 19",             "Knopf 20",             "Knopf 21",             "Knopf 22",             "Knopf 23",             "Knopf 24",
591         "Knopf 25",             "Knopf 26",             "Knopf 27",             "Knopf 28",             "Knopf 29",             "Knopf 30",
592         "Knopf 31",             "Knopf 32",             "Hut Hinten",   "Hut Vorne",    "Hut Links",    "Hut Rechts"
593 };
594
595 char *Scan_code_text_french[] = {
596         "",                             "\x90""chap",                   "1",                            "2",                            "3",                            "4",                            "5",                            "6",
597         "7",                            "8",                            "9",                            "0",                            "-",                            "=",                            "Fl\x82""che Ret.",                     "Tab",
598         "Q",                            "W",                            "E",                            "R",                            "T",                            "Y",                            "U",                            "I",
599         "O",                            "P",                            "[",                            "]",                            "Entr\x82""e",                  "Ctrl Gauche",                  "A",                            "S",
600
601         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            ";",
602         "'",                            "`",                            "Maj.",                 "\\",                           "Z",                            "X",                            "C",                            "V",
603         "B",                            "N",                            "M",                            ",",                            ".",                            "/",                            "Maj.",                 "Pav\x82 *",
604         "Alt",                          "Espace",                       "Verr. Maj.",                   "F1",                           "F2",                           "F3",                           "F4",                           "F5",
605
606         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                          "Pause",                        "Arret defil",          "Pav\x82 7",
607         "Pav\x82 8",                    "Pav\x82 9",                    "Pav\x82 -",                    "Pav\x82 4",                    "Pav\x82 5",                    "Pav\x82 6",                    "Pav\x82 +",                    "Pav\x82 1",
608         "Pav\x82 2",                    "Pav\x82 3",                    "Pav\x82 0",                    "Pav\x82 .",                    "",                             "",                             "",                             "F11",
609         "F12",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
610
611         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
612         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
613         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
614         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
615
616         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
617         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
618         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
619         "",                             "",                             "",                             "",                             "Pav\x82 Entr",                 "Ctrl Droite",          "",                             "",
620
621         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
622         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
623         "",                             "",                             "",                             "",                             "",                             "Pav\x82 /",                    "",                             "Impr \x82""cran",
624         "Alt",                          "",                             "",                             "",                             "",                             "",                             "",                             "",
625
626         "",                             "",                             "",                             "",                             "",                             "Verr num",                     "",                             "Orig.",
627         "Fl\x82""che Haut",                     "Page Haut",                    "",                             "Fl\x82""che Gauche",                   "",                             "Fl\x82""che Droite",                   "",                     "Fin",
628         "Fl\x82""che Bas",                      "Page Bas",                     "Inser",                        "Suppr",                        "",                             "",                             "",                             "",
629         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
630
631         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
632         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
633         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
634         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
635 };
636
637 char *Joy_button_text_french[] = {
638         "Bouton 1",             "Bouton 2",             "Bouton 3",             "Bouton 4",             "Bouton 5",             "Bouton 6",
639         "Bouton 7",             "Bouton 8",             "Bouton 9",             "Bouton 10",            "Bouton 11",            "Bouton 12",
640         "Bouton 13",            "Bouton 14",            "Bouton 15",            "Bouton 16",            "Bouton 17",            "Bouton 18",
641         "Bouton 19",            "Bouton 20",            "Bouton 21",            "Bouton 22",            "Bouton 23",            "Bouton 24",
642         "Bouton 25",            "Bouton 26",            "Bouton 27",            "Bouton 28",            "Bouton 29",            "Bouton 30",
643         "Bouton 31",            "Bouton 32",            "Chapeau Arrière",              "Chapeau Avant",                "Chapeau Gauche",               "Chapeau Droite"
644 };
645
646 //      This is the text that is displayed on the screen for the keys a player selects
647 char *Scan_code_text_english[] = {
648         "",                             "Esc",                  "1",                            "2",                            "3",                            "4",                            "5",                            "6",
649         "7",                            "8",                            "9",                            "0",                            "-",                            "=",                            "Backspace",    "Tab",
650         "Q",                            "W",                            "E",                            "R",                            "T",                            "Y",                            "U",                            "I",
651         "O",                            "P",                            "[",                            "]",                            "Enter",                        "Left Ctrl",    "A",                            "S",
652
653         "D",                            "F",                            "G",                            "H",                            "J",                            "K",                            "L",                            ";",
654         "'",                            "`",                            "Shift",                        "\\",                           "Z",                            "X",                            "C",                            "V",
655         "B",                            "N",                            "M",                            ",",                            ".",                            "/",                            "Shift",                        "Pad *",
656         "Alt",                  "Spacebar",             "Caps Lock",    "F1",                           "F2",                           "F3",                           "F4",                           "F5",
657
658         "F6",                           "F7",                           "F8",                           "F9",                           "F10",                  "Pause",                        "Scroll Lock",  "Pad 7",
659         "Pad 8",                        "Pad 9",                        "Pad -",                        "Pad 4",                        "Pad 5",                        "Pad 6",                        "Pad +",                        "Pad 1",
660         "Pad 2",                        "Pad 3",                        "Pad 0",                        "Pad .",                        "",                             "",                             "",                             "F11",
661         "F12",                  "",                             "",                             "",                             "",                             "",                             "",                             "",
662
663         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
664         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
665         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
666         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
667
668         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
669         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
670         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
671         "",                             "",                             "",                             "",                             "Pad Enter",    "Right Ctrl",   "",                             "",
672
673         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
674         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
675         "",                             "",                             "",                             "",                             "",                             "Pad /",                        "",                             "Print Scrn",
676         "Alt",                  "",                             "",                             "",                             "",                             "",                             "",                             "",
677
678         "",                             "",                             "",                             "",                             "",                             "Num Lock",             "",                             "Home",
679         "Up Arrow",             "Page Up",              "",                             "Left Arrow",   "",                             "Right Arrow",  "",                             "End",
680         "Down Arrow",  "Page Down",     "Insert",               "Delete",               "",                             "",                             "",                             "",
681         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
682
683         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
684         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
685         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
686         "",                             "",                             "",                             "",                             "",                             "",                             "",                             "",
687 };
688
689 char *Joy_button_text_english[] = {
690         "Button 1",             "Button 2",             "Button 3",             "Button 4",             "Button 5",             "Button 6",
691         "Button 7",             "Button 8",             "Button 9",             "Button 10",    "Button 11",    "Button 12",
692         "Button 13",    "Button 14",    "Button 15",    "Button 16",    "Button 17",    "Button 18",
693         "Button 19",    "Button 20",    "Button 21",    "Button 22",    "Button 23",    "Button 24",
694         "Button 25",    "Button 26",    "Button 27",    "Button 28",    "Button 29",    "Button 30",
695         "Button 31",    "Button 32",    "Hat Back",             "Hat Forward",  "Hat Left",             "Hat Right"
696 };
697
698 char **Scan_code_text = Scan_code_text_english;
699 char **Joy_button_text = Joy_button_text_english;
700
701 void set_modifier_status()
702 {
703         int i;
704
705         Alt_is_modifier = 0;
706         Shift_is_modifier = 0;
707         Ctrl_is_modifier = 0;
708
709         for (i=0; i<CCFG_MAX; i++) {
710                 if (Control_config[i].key_id < 0)
711                         continue;
712
713                 if (Control_config[i].key_id & KEY_ALTED)
714                         Alt_is_modifier = 1;
715
716                 if (Control_config[i].key_id & KEY_SHIFTED)
717                         Shift_is_modifier = 1;
718
719                 if (Control_config[i].key_id & KEY_CTRLED) {
720                         Assert(0);  // get Alan
721                         Ctrl_is_modifier = 1;
722                 }
723         }
724 }
725
726 int translate_key_to_index(char *key)
727 {
728         int i, index = -1, alt = 0, shift = 0, max_scan_codes;
729
730         if (Lcl_gr) {
731                 max_scan_codes = sizeof(Scan_code_text_german) / sizeof(char *);
732         } else if (Lcl_fr) {
733                 max_scan_codes = sizeof(Scan_code_text_french) / sizeof(char *);
734         } else {
735                 max_scan_codes = sizeof(Scan_code_text_english) / sizeof(char *);
736         }
737
738         // look for modifiers
739         Assert(key);
740         if (!strnicmp(key, "Alt", 3)) {
741                 alt = 1;
742                 key += 3;
743                 if (*key)
744                         key++;
745         }
746
747         char *translated_shift;
748         
749         if(Lcl_gr){
750                 translated_shift = "Shift";
751         } else if(Lcl_fr){      
752                 translated_shift = "Maj.";
753         } else {        
754                 translated_shift = "Shift";
755         }
756
757         if (!strnicmp(key, translated_shift, 5)) {
758                 shift = 1;
759                 key += 5;
760                 if (*key)
761                         key++;
762         }
763
764         // look up index for default key
765         if (*key) {
766                 for (i=0; i<max_scan_codes; i++)
767                         if (!stricmp(key, Scan_code_text_english[i])) {
768                                 index = i;
769                                 break;
770                         }
771
772                 if (i == max_scan_codes)
773                         return -1;
774
775                 if (shift)
776                         index |= KEY_SHIFTED;
777                 if (alt)
778                         index |= KEY_ALTED;
779
780                 // convert scancode to Control_config index
781                 for (i=0; i<CCFG_MAX; i++) {
782                         if (Control_config[i].key_default == index) {
783                                 index = i;
784                                 break;
785                         }
786                 }
787
788                 if (i == CCFG_MAX)
789                         return -1;
790
791                 return index;
792         }
793
794         return -1;
795 }
796
797 // Given the system default key 'key', return the current key that is bound to the function
798 // Both are 'key' and the return value are descriptive strings that can be displayed
799 // directly to the user.  If 'key' isn't a real key or not normally bound to anything,
800 // or there is no key current bound to the function, NULL is returned.
801 char *translate_key(char *key)
802 {
803         int index = -1, code = -1;
804
805         index = translate_key_to_index(key);
806         if (index < 0)
807                 return NULL;
808
809         code = Control_config[index].key_id;
810         Failed_key_index = index;
811         if (code < 0) {
812                 code = Control_config[index].joy_id;
813                 if (code >= 0)
814                         return Joy_button_text[code];
815         }
816
817         return textify_scancode(code);
818 }
819
820 char *textify_scancode(int code)
821 {
822         static char text[40];
823
824         if (code < 0)
825                 return "None";
826
827         *text = 0;
828         if (code & KEY_ALTED) {
829                 if(Lcl_gr){             
830                         strcat(text, "Alt-");
831                 } else if(Lcl_fr){              
832                         strcat(text, "Alt-");
833                 } else {                
834                         strcat(text, "Alt-");
835                 }               
836         }
837
838         if (code & KEY_SHIFTED) {               
839                 if(Lcl_gr){
840                         strcat(text, "Shift-");
841                 } else if(Lcl_fr){              
842                         strcat(text, "Maj.-");
843                 } else {                
844                         strcat(text, "Shift-");
845                 }
846         }
847
848         strcat(text, Scan_code_text[code & KEY_MASK]);
849         return text;
850 }
851 //XSTR:ON
852
853 // initialize common control config stuff - call at game startup after localization has been initialized
854 void control_config_common_init()
855 {
856         if(Lcl_gr){
857                 Scan_code_text = Scan_code_text_german;
858                 Joy_button_text = Joy_button_text_german;
859                 
860                 // swap init bindings for y and z keys
861                 Control_config[TARGET_SHIP_IN_RETICLE].key_default = KEY_Z;
862                 Control_config[TARGET_LAST_TRANMISSION_SENDER].key_default = KEY_ALTED | KEY_Z;
863                 Control_config[REVERSE_THRUST].key_default = KEY_Y;
864                 Control_config[DISARM_MESSAGE].key_default = KEY_SHIFTED | KEY_Y;               
865         } else if(Lcl_fr){
866                 Scan_code_text = Scan_code_text_french;
867                 Joy_button_text = Joy_button_text_french;
868         } else {
869                 Scan_code_text = Scan_code_text_english;
870                 Joy_button_text = Joy_button_text_english;
871         }
872 }