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