]> git.mxchange.org Git - flightgear.git/blob - src/Controls/controls.cxx
You bastards! Writing property names to char arrays that are too short for
[flightgear.git] / src / Controls / controls.cxx
1 // controls.cxx -- defines a standard interface to all flight sim controls
2 //
3 // Written by Curtis Olson, started May 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include "controls.hxx"
25
26 #include <simgear/debug/logstream.hxx>
27 #include <Main/fg_props.hxx>
28
29
30 static const int MAX_NAME_LEN = 128;
31
32 \f
33 ////////////////////////////////////////////////////////////////////////
34 // Inline utility methods.
35 ////////////////////////////////////////////////////////////////////////
36
37 static inline void
38 CLAMP(double *x, double min, double max )
39 {
40   if ( *x < min ) { *x = min; }
41   if ( *x > max ) { *x = max; }
42 }
43
44 static inline void
45 CLAMP(int *i, int min, int max )
46 {
47   if ( *i < min ) { *i = min; }
48   if ( *i > max ) { *i = max; }
49 }
50
51 \f
52 ////////////////////////////////////////////////////////////////////////
53 // Implementation of FGControls.
54 ////////////////////////////////////////////////////////////////////////
55
56 // Constructor
57 FGControls::FGControls() :
58     aileron( 0.0 ),
59     aileron_trim( 0.0 ),
60     elevator( 0.0 ),
61     elevator_trim( 0.0 ),
62     rudder( 0.0 ),
63     rudder_trim( 0.0 ),
64     flaps( 0.0 ),
65     slats( 0.0 ),
66     BLC( false ),
67     spoilers( 0.0 ),
68     speedbrake( 0.0 ),
69     wing_sweep( 0.0 ),
70     wing_fold( false ),
71     drag_chute( false ),
72     throttle_idle( true ),
73     dump_valve( false ),
74     parking_brake( 0.0 ),
75     steering( 0.0 ),
76     gear_down( true ),
77     antiskid( true ),
78     tailhook( false ),
79     tailwheel_lock( false ),
80     wing_heat( false ),
81     pitot_heat( true ),
82     wiper( 0 ),
83     window_heat( false ),
84     battery_switch( true ),
85     external_power( false ),
86     APU_generator( false ),
87     APU_bleed( false ),
88     mode( 0 ),
89     dump( false ),
90     taxi_light( false ),
91     logo_lights( false ),
92     nav_lights( false ),
93     beacon( false ),
94     strobe( false ),
95     panel_norm( 0.0 ),
96     instruments_norm( 0.0 ),
97     dome_norm( 0.0 ),
98     master_arm( false ),
99     station_select( 1 ),
100     release_ALL( false ),
101     vertical_adjust( 0.0 ),
102     fore_aft_adjust( 0.0 ),
103     eject( false ),
104     off_start_run( 0 ),
105     APU_fire_switch( false ),
106     autothrottle_arm( false ),
107     autothrottle_engage( false ),
108     heading_select( 0.0 ),
109     altitude_select( 50000.0 ),
110     bank_angle_select( 30.0 ),
111     vertical_speed_select( 0.0 ),
112     speed_select( 0.0 ),
113     mach_select( 0.0 ),
114     vertical_mode( 0 ),
115     lateral_mode( 0 )
116 {
117 }
118
119
120 void FGControls::reset_all()
121 {
122     set_aileron( 0.0 );
123     set_aileron_trim( 0.0 );
124     set_elevator( 0.0 );
125     set_elevator_trim( 0.0 );
126     set_rudder( 0.0 );
127     set_rudder_trim( 0.0 );
128     BLC = false;
129     set_spoilers( 0.0 );
130     set_speedbrake( 0.0 );
131     set_wing_sweep( 0.0 );
132     wing_fold = false;
133     drag_chute = false;
134     set_throttle( ALL_ENGINES, 0.0 );
135     set_starter( ALL_ENGINES, false );
136     set_magnetos( ALL_ENGINES, 0 );
137     set_fuel_pump( ALL_ENGINES, false );
138     set_fire_switch( ALL_ENGINES, false );
139     set_fire_bottle_discharge( ALL_ENGINES, false );
140     set_cutoff( ALL_ENGINES, true );
141     set_nitrous_injection( ALL_ENGINES, false );
142     set_cowl_flaps_norm( ALL_ENGINES, 1.0 );
143     set_feather( ALL_ENGINES, false );
144     set_ignition( ALL_ENGINES, false );
145     set_augmentation( ALL_ENGINES, false );
146     set_reverser( ALL_ENGINES, false );
147     set_water_injection( ALL_ENGINES, false );
148     set_condition( ALL_ENGINES, 0 );
149     throttle_idle = true;
150     set_fuel_selector( ALL_TANKS, true );
151     dump_valve = false;
152     steering =  0.0;
153     gear_down = true;
154     tailhook = false;
155     tailwheel_lock = false;
156     set_carb_heat( ALL_ENGINES, false );
157     set_inlet_heat( ALL_ENGINES, false );
158     wing_heat = false;
159     pitot_heat = true;
160     wiper = 0;
161     window_heat = false;
162     set_engine_pump( ALL_HYD_SYSTEMS, true );
163     set_electric_pump( ALL_HYD_SYSTEMS, true );
164     landing_lights = false;
165     turn_off_lights = false;
166     master_arm = false;
167     eject = false;
168     APU_fire_switch = false;
169     autothrottle_arm = false;
170     autothrottle_engage = false;
171     set_autopilot_engage( ALL_AUTOPILOTS, false );
172 }
173
174
175 // Destructor
176 FGControls::~FGControls() {
177 }
178
179
180 void
181 FGControls::init ()
182 {
183     throttle_idle = true;
184     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
185         throttle[engine] = 0.0;
186         mixture[engine] = 1.0;
187         fuel_pump[engine] = false;
188         prop_advance[engine] = 1.0;
189         magnetos[engine] = 0;
190         starter[engine] = false;
191         ignition[engine] = false;
192         fire_switch[engine] = false;
193         cutoff[engine] = true;
194         augmentation[engine] = false;
195         reverser[engine] = false;
196         water_injection[engine] = false;
197         nitrous_injection[engine] = false;
198         condition[engine] = 0;
199     }
200
201     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
202         brake[wheel] = 0.0;
203         alternate_extension[wheel] = false;
204     }
205
206     auto_coordination = fgGetNode("/sim/auto-coordination", true);
207 }
208
209
210 void
211 FGControls::bind ()
212 {
213   int index, i;
214
215   // flight controls
216   fgTie("/controls/flight/aileron", this,
217         &FGControls::get_aileron, &FGControls::set_aileron);
218   fgSetArchivable("/controls/flight/aileron");
219
220   fgTie("/controls/flight/aileron-trim", this,
221        &FGControls::get_aileron_trim, &FGControls::set_aileron_trim);
222   fgSetArchivable("/controls/flight/aileron-trim");
223
224   fgTie("/controls/flight/elevator", this,
225        &FGControls::get_elevator, &FGControls::set_elevator);
226   fgSetArchivable("/controls/flight/elevator");
227
228   fgTie("/controls/flight/elevator-trim", this,
229        &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
230   fgSetArchivable("/controls/flight/elevator-trim");
231
232   fgTie("/controls/flight/rudder", this,
233        &FGControls::get_rudder, &FGControls::set_rudder);
234   fgSetArchivable("/controls/flight/rudder");
235
236   fgTie("/controls/flight/rudder-trim", this,
237        &FGControls::get_rudder_trim, &FGControls::set_rudder_trim);
238   fgSetArchivable("/controls/flight/rudder-trim");
239
240   fgTie("/controls/flight/flaps", this,
241        &FGControls::get_flaps, &FGControls::set_flaps);
242   fgSetArchivable("/controls/flight/flaps");
243
244   fgTie("/controls/flight/slats", this,
245        &FGControls::get_slats, &FGControls::set_slats);
246   fgSetArchivable("/controls/flight/slats");
247
248   fgTie("/controls/flight/BLC", this,
249        &FGControls::get_BLC, &FGControls::set_BLC);
250   fgSetArchivable("/controls/flight/BLC");
251
252   fgTie("/controls/flight/spoilers", this,
253        &FGControls::get_spoilers, &FGControls::set_spoilers);
254   fgSetArchivable("/controls/flight/spoilers");
255
256   fgTie("/controls/flight/speedbrake", this,
257        &FGControls::get_speedbrake, &FGControls::set_speedbrake);
258   fgSetArchivable("/controls/flight/speedbrake");
259
260   fgTie("/controls/flight/wing-sweep", this,
261        &FGControls::get_wing_sweep, &FGControls::set_wing_sweep);
262   fgSetArchivable("/controls/flight/wing-sweep");
263
264   fgTie("/controls/flight/wing-fold", this,
265        &FGControls::get_wing_fold, &FGControls::set_wing_fold);
266   fgSetArchivable("/controls/flight/wing-fold");
267
268   fgTie("/controls/flight/drag-chute", this,
269        &FGControls::get_drag_chute, &FGControls::set_drag_chute);
270   fgSetArchivable("/controls/flight/drag-chute");
271
272   // engines
273   fgTie("/controls/engines/throttle_idle", this,
274        &FGControls::get_throttle_idle, &FGControls::set_throttle_idle);
275   fgSetArchivable("/controls/engines/throttle_idle");
276
277   for (index = 0; index < MAX_ENGINES; index++) {
278     char name[MAX_NAME_LEN];
279     sprintf(name, "/controls/engines/engine[%d]/throttle", index);
280     fgTie(name, this, index,
281           &FGControls::get_throttle, &FGControls::set_throttle);
282     fgSetArchivable(name);
283
284     sprintf(name, "/controls/engines/engine[%d]/starter", index);
285     fgTie(name, this, index,
286          &FGControls::get_starter, &FGControls::set_starter);
287     fgSetArchivable(name);
288
289     sprintf(name, "/controls/engines/engine[%d]/fuel-pump", index);
290     fgTie(name, this, index,
291          &FGControls::get_fuel_pump, &FGControls::set_fuel_pump);
292     fgSetArchivable(name);
293
294     sprintf(name, "/controls/engines/engine[%d]/fire-switch", index);
295     fgTie(name, this, index,
296          &FGControls::get_fire_switch, &FGControls::set_fire_switch);
297     fgSetArchivable(name);
298
299     sprintf(name, 
300        "/controls/engines/engine[%d]/fire-bottle-discharge", index);
301     fgTie(name, this, index,
302          &FGControls::get_fire_bottle_discharge,
303          &FGControls::set_fire_bottle_discharge);
304     fgSetArchivable(name);
305
306     sprintf(name, "/controls/engines/engine[%d]/cutoff", index);
307     fgTie(name, this, index,
308          &FGControls::get_cutoff, &FGControls::set_cutoff);
309     fgSetArchivable(name);
310
311     sprintf(name, "/controls/engines/engine[%d]/mixture", index);
312     fgTie(name, this, index,
313          &FGControls::get_mixture, &FGControls::set_mixture);
314     fgSetArchivable(name);
315
316     sprintf(name, 
317        "/controls/engines/engine[%d]/propeller-pitch", index);
318     fgTie(name, this, index,
319          &FGControls::get_prop_advance, 
320          &FGControls::set_prop_advance);
321     fgSetArchivable(name);
322
323     sprintf(name, "/controls/engines/engine[%d]/magnetos", index);
324     fgTie(name, this, index,
325          &FGControls::get_magnetos, &FGControls::set_magnetos);
326     fgSetArchivable(name);
327
328     sprintf(name, "/controls/engines/engine[%d]/WEP", index);
329     fgTie(name, this, index,
330          &FGControls::get_nitrous_injection,
331          &FGControls::set_nitrous_injection);
332     fgSetArchivable(name);
333
334     sprintf(name, 
335        "/controls/engines/engine[%d]/cowl-flaps-norm", index);
336     fgTie(name, this, index,
337          &FGControls::get_cowl_flaps_norm, 
338          &FGControls::set_cowl_flaps_norm);
339     fgSetArchivable(name);
340
341     sprintf(name, "/controls/engines/engine[%d]/feather", index);
342     fgTie(name, this, index,
343          &FGControls::get_feather, &FGControls::set_feather);
344     fgSetArchivable(name);
345
346     sprintf(name, "/controls/engines/engine[%d]/ignition", index);
347     fgTie(name, this, index,
348          &FGControls::get_ignition, &FGControls::set_ignition);
349     fgSetArchivable(name);
350
351     sprintf(name, "/controls/engines/engine[%d]/augmentation", index);
352     fgTie(name, this, index,
353          &FGControls::get_augmentation, 
354          &FGControls::set_augmentation);
355     fgSetArchivable(name);
356
357     sprintf(name, "/controls/engines/engine[%d]/reverser", index);
358     fgTie(name, this, index,
359          &FGControls::get_reverser, &FGControls::set_reverser);
360     fgSetArchivable(name);
361
362     sprintf(name, 
363        "/controls/engines/engine[%d]/water-injection", index);
364     fgTie(name, this, index,
365          &FGControls::get_water_injection,
366          &FGControls::set_water_injection);
367     fgSetArchivable(name);
368
369     sprintf(name, "/controls/engines/engine[%d]/condition", index);
370     fgTie(name, this, index,
371          &FGControls::get_condition, &FGControls::set_condition);
372     fgSetArchivable(name);
373   }
374
375   // fuel
376   fgTie("/controls/fuel/dump-valve", this,
377        &FGControls::get_dump_valve, &FGControls::set_dump_valve);
378   fgSetArchivable("/controls/fuel/dump-valve");
379
380   for (index = 0; index < MAX_TANKS; index++) {
381     char name[MAX_NAME_LEN];
382     sprintf(name, "/controls/fuel/tank[%d]/fuel_selector", index);
383     fgTie(name, this, index,
384           &FGControls::get_fuel_selector, 
385           &FGControls::set_fuel_selector);
386     fgSetArchivable(name);  
387
388     sprintf(name, "/controls/fuel/tank[%d]/to_engine", index);
389     fgTie(name, this, index,
390           &FGControls::get_to_engine, &FGControls::set_to_engine);
391     fgSetArchivable(name);  
392
393     sprintf(name, "/controls/fuel/tank[%d]/to_tank", index);
394     fgTie(name, this, index,
395           &FGControls::get_to_tank, &FGControls::set_to_tank);
396     fgSetArchivable(name);  
397
398     for (i = 0; i < MAX_BOOSTPUMPS; i++) {
399       char name[MAX_NAME_LEN];
400       sprintf(name, 
401          "/controls/fuel/tank[%d]/boost-pump[%d]", index, i);
402       fgTie(name, this, index * 2 + i,
403             &FGControls::get_boost_pump, 
404             &FGControls::set_boost_pump);
405       fgSetArchivable(name);  
406     }
407   }
408
409   // gear
410   fgTie("/controls/gear/parking-brake", this,
411         &FGControls::get_parking_brake, 
412         &FGControls::set_parking_brake);
413   fgSetArchivable("/controls/gear/parking-brake");
414
415   fgTie("/controls/gear/steering", this,
416         &FGControls::get_steering, &FGControls::set_steering);
417   fgSetArchivable("/controls/gear/steering");
418
419   fgTie("/controls/gear/gear-down", this,
420         &FGControls::get_gear_down, &FGControls::set_gear_down);
421   fgSetArchivable("/controls/gear/gear-down");
422
423   fgTie("/controls/gear/antiskid", this,
424         &FGControls::get_antiskid, &FGControls::set_antiskid);
425   fgSetArchivable("/controls/gear/antiskid");
426
427   fgTie("/controls/gear/tailhook", this,
428         &FGControls::get_tailhook, &FGControls::set_tailhook);
429   fgSetArchivable("/controls/gear/tailhook");
430
431   fgTie("/controls/gear/tailwheel-lock", this,
432         &FGControls::get_tailwheel_lock, 
433         &FGControls::set_tailwheel_lock);
434   fgSetArchivable("/controls/gear/tailwheel-lock");
435
436   for (index = 0; index < MAX_WHEELS; index++) {
437       char name[MAX_NAME_LEN];
438       sprintf(name, "/controls/gear/wheel[%d]/brake", index);
439       fgTie(name, this, index,
440             &FGControls::get_brake, &FGControls::set_brake);
441       fgSetArchivable(name);
442
443       sprintf(name, "/controls/gear/wheel[%d]/alternate-extension", index);
444       fgTie(name, this, index,
445             &FGControls::get_alternate_extension, 
446             &FGControls::set_alternate_extension);
447       fgSetArchivable(name);
448   }
449
450   // anti-ice
451   fgTie("/controls/anti-ice/wing-heat", this,
452         &FGControls::get_wing_heat, &FGControls::set_wing_heat);
453   fgSetArchivable("/controls/anti-ice/wing-heat");
454
455   fgTie("/controls/anti-ice/pitot-heat", this,
456         &FGControls::get_pitot_heat, &FGControls::set_pitot_heat);
457   fgSetArchivable("/controls/anti-ice/pitot-heat");
458
459   fgTie("/controls/anti-ice/wiper", this,
460         &FGControls::get_wiper, &FGControls::set_wiper);
461   fgSetArchivable("/controls/anti-ice/wiper");
462
463   fgTie("/controls/anti-ice/window-heat", this,
464         &FGControls::get_window_heat, &FGControls::set_window_heat);
465   fgSetArchivable("/controls/anti-ice/window-heat");
466
467   for (index = 0; index < MAX_ENGINES; index++) {
468       char name[MAX_NAME_LEN];
469       sprintf(name, "/controls/anti-ice/engine[%d]/carb-heat", index);  
470       fgTie(name, this, index,
471         &FGControls::get_carb_heat, &FGControls::set_carb_heat);
472       fgSetArchivable(name);
473
474       sprintf(name, "/controls/anti-ice/engine[%d]/inlet-heat", index);  
475       fgTie(name, this, index,
476         &FGControls::get_inlet_heat, &FGControls::set_inlet_heat);
477       fgSetArchivable(name);
478   }
479
480   // hydraulics
481   for (index = 0; index < MAX_HYD_SYSTEMS; index++) {
482       char name[MAX_NAME_LEN];
483       sprintf(name, 
484          "/controls/hydraulic/system[%d]/engine-pump", index);  
485       fgTie(name, this, index,
486         &FGControls::get_engine_pump, &FGControls::set_engine_pump);
487       fgSetArchivable(name);
488
489       sprintf(name, 
490          "/controls/hydraulic/system[%d]/electric-pump", index);  
491       fgTie(name, this, index,
492         &FGControls::get_electric_pump, 
493         &FGControls::set_electric_pump);
494       fgSetArchivable(name);
495   }  
496
497   // electric
498   fgTie("/controls/electric/battery-switch", this,
499         &FGControls::get_battery_switch, 
500         &FGControls::set_battery_switch);
501   fgSetArchivable("/controls/electric/battery-switch");
502   
503   fgTie("/controls/electric/external-power", this,
504         &FGControls::get_external_power, 
505         &FGControls::set_external_power);
506   fgSetArchivable("/controls/electric/external-power");
507
508   fgTie("/controls/electric/APU-generator", this,
509         &FGControls::get_APU_generator, 
510         &FGControls::set_APU_generator);
511   fgSetArchivable("/controls/electric/APU-generator");
512
513   for (index = 0; index < MAX_ENGINES; index++) {
514       char name[MAX_NAME_LEN];
515       sprintf(name, 
516          "/controls/electric/engine[%d]/generator", index);  
517       fgTie(name, this, index,
518         &FGControls::get_generator_breaker, 
519         &FGControls::set_generator_breaker);
520       fgSetArchivable(name);
521
522       sprintf(name, "/controls/electric/engine[%d]/bus-tie", index);  
523       fgTie(name, this, index,
524         &FGControls::get_bus_tie, 
525         &FGControls::set_bus_tie);
526       fgSetArchivable(name);
527   }  
528
529   // pneumatic
530   fgTie("/controls/pneumatic/APU-bleed", this,
531         &FGControls::get_APU_bleed, 
532         &FGControls::set_APU_bleed);
533   fgSetArchivable("/controls/pneumatic/APU-bleed");
534
535   for (index = 0; index < MAX_ENGINES; index++) {
536       char name[MAX_NAME_LEN];
537       sprintf(name, 
538          "/controls/pneumatic/engine[%d]/bleed", index);  
539       fgTie(name, this, index,
540         &FGControls::get_engine_bleed, 
541         &FGControls::set_engine_bleed);
542       fgSetArchivable(name);
543   }
544
545   // pressurization
546   fgTie("/controls/pressurization/mode", this,
547         &FGControls::get_mode, &FGControls::set_mode);
548   fgSetArchivable("/controls/pressurization/mode");
549
550   fgTie("/controls/pressurization/dump", this,
551         &FGControls::get_dump, &FGControls::set_dump);
552   fgSetArchivable("/controls/pressurization/dump");
553
554   fgTie("/controls/pressurization/outflow-valve", this,
555         &FGControls::get_outflow_valve, 
556         &FGControls::set_outflow_valve);
557   fgSetArchivable("/controls/pressurization/outflow-valve");
558
559   for (index = 0; index < MAX_PACKS; index++) {
560       char name[MAX_NAME_LEN];
561       sprintf(name, "/controls/pressurization/pack[%d]/pack-on", index);  
562       fgTie(name, this, index,
563         &FGControls::get_pack_on, &FGControls::set_pack_on);
564       fgSetArchivable(name);
565   }
566  
567   // lights
568   fgTie("/controls/lighting/landing-lights", this,
569         &FGControls::get_landing_lights, 
570         &FGControls::set_landing_lights);
571   fgSetArchivable("/controls/lighting/landing-lights");  
572
573   fgTie("/controls/lighting/turn-off-lights", this,
574         &FGControls::get_turn_off_lights,
575         &FGControls::set_turn_off_lights);
576   fgSetArchivable("/controls/lighting/turn-off-lights");
577   
578   fgTie("/controls/lighting/taxi-light", this,
579         &FGControls::get_taxi_light, &FGControls::set_taxi_light);
580   fgSetArchivable("/controls/lighting/taxi-light");
581   
582   fgTie("/controls/lighting/logo-lights", this,
583         &FGControls::get_logo_lights, &FGControls::set_logo_lights);
584   fgSetArchivable("/controls/lighting/logo-lights");
585   
586   fgTie("/controls/lighting/nav-lights", this,
587         &FGControls::get_nav_lights, &FGControls::set_nav_lights);
588   fgSetArchivable("/controls/lighting/nav-lights");  
589
590   fgTie("/controls/lighting/beacon", this,
591         &FGControls::get_beacon, &FGControls::set_beacon);
592   fgSetArchivable("/controls/lighting/beacon");
593   
594   fgTie("/controls/lighting/strobe", this,
595         &FGControls::get_strobe, &FGControls::set_strobe);
596   fgSetArchivable("/controls/lighting/strobe");  
597
598   fgTie("/controls/lighting/panel-norm", this,
599         &FGControls::get_panel_norm, &FGControls::set_panel_norm);
600   fgSetArchivable("/controls/lighting/panel-norm");
601   
602   fgTie("/controls/lighting/instruments-norm", this,
603         &FGControls::get_instruments_norm, 
604         &FGControls::set_instruments_norm);
605   fgSetArchivable("/controls/lighting/instruments-norm");  
606
607   fgTie("/controls/lighting/dome-norm", this,
608         &FGControls::get_dome_norm, &FGControls::set_dome_norm);
609   fgSetArchivable("/controls/lighting/dome-norm"); 
610  
611 #ifdef FG_HAVE_ARMAMENT
612   // armament
613   fgTie("/controls/armament/master-arm", this,
614         &FGControls::get_master_arm, &FGControls::set_master_arm);
615   fgSetArchivable("/controls/armament/master-arm");  
616
617   fgTie("/controls/armament/station-select", this,
618         &FGControls::get_station_select, 
619         &FGControls::set_station_select);
620   fgSetArchivable("/controls/armament/station-select");  
621
622   fgTie("/controls/armament/release-all", this,
623         &FGControls::get_release_ALL, 
624         &FGControls::set_release_ALL);
625   fgSetArchivable("/controls/armament/release-all");  
626
627   for (index = 0; index < MAX_STATIONS; index++) {
628       char name[MAX_NAME_LEN];
629       sprintf(name, "/controls/armament/station[%d]/stick-size", index);  
630       fgTie(name, this, index,
631         &FGControls::get_stick_size, &FGControls::set_stick_size);
632       fgSetArchivable(name);
633
634       sprintf(name, 
635           "/controls/armament/station[%d]/release-stick", index);  
636       fgTie(name, this, index,
637         &FGControls::get_release_stick, &FGControls::set_release_stick);
638       fgSetArchivable(name);
639
640       sprintf(name, "/controls/armament/station[%d]/release-all", index);  
641       fgTie(name, this, index,
642         &FGControls::get_release_all, &FGControls::set_release_all);
643       fgSetArchivable(name);
644
645       sprintf(name, "/controls/armament/station[%d]/jettison-all", index);  
646       fgTie(name, this, index,
647         &FGControls::get_jettison_all, &FGControls::set_jettison_all);
648       fgSetArchivable(name);
649   }
650
651 #endif
652
653   // seat
654   fgTie("/controls/seat/vertical-adjust", this,
655         &FGControls::get_vertical_adjust, 
656         &FGControls::set_vertical_adjust);
657   fgSetArchivable("/controls/seat/vertical-adjust");
658
659   fgTie("/controls/seat/fore-aft-adjust", this,
660         &FGControls::get_fore_aft_adjust, 
661         &FGControls::set_fore_aft_adjust);
662   fgSetArchivable("/controls/seat/fore-aft-adjust");
663   
664   fgTie("/controls/seat/eject", this,
665         &FGControls::get_eject, &FGControls::set_eject);
666   fgSetArchivable("/controls/seat/eject");
667
668   // APU
669   fgTie("/controls/APU/off-start-run", this,
670         &FGControls::get_off_start_run, 
671         &FGControls::set_off_start_run);
672   fgSetArchivable("/controls/APU/off-start-run");
673
674   fgTie("/controls/APU/fire-switch", this,
675         &FGControls::get_APU_fire_switch, 
676         &FGControls::set_APU_fire_switch);
677   fgSetArchivable("/controls/APU/fire-switch");
678
679   // autoflight
680   for (index = 0; index < MAX_AUTOPILOTS; index++) {
681       char name[MAX_NAME_LEN];
682       sprintf(name, 
683          "/controls/autoflight/autopilot[%d]/engage", index);  
684       fgTie(name, this, index,
685         &FGControls::get_autopilot_engage, 
686         &FGControls::set_autopilot_engage);
687       fgSetArchivable(name);
688   }
689  
690   fgTie("/controls/autoflight/autothrottle-arm", this,
691         &FGControls::get_autothrottle_arm, 
692         &FGControls::set_autothrottle_arm);
693   fgSetArchivable("/controls/autoflight/autothrottle-arm");
694
695   fgTie("/controls/autoflight/autothrottle-engage", this,
696         &FGControls::get_autothrottle_engage, 
697         &FGControls::set_autothrottle_engage);
698   fgSetArchivable("/controls/autoflight/autothrottle-engage");
699
700   fgTie("/controls/autoflight/heading-select", this,
701         &FGControls::get_heading_select, 
702         &FGControls::set_heading_select);
703   fgSetArchivable("/controls/autoflight/heading-select");
704
705   fgTie("/controls/autoflight/altitude-select", this,
706         &FGControls::get_altitude_select, 
707         &FGControls::set_altitude_select);
708   fgSetArchivable("/controls/autoflight/altitude-select");
709
710   fgTie("/controls/autoflight/bank-angle-select", this,
711         &FGControls::get_bank_angle_select, 
712         &FGControls::set_bank_angle_select);
713   fgSetArchivable("/controls/autoflight/bank-angle-select");
714
715   fgTie("/controls/autoflight/vertical-speed-select", this,
716         &FGControls::get_vertical_speed_select, 
717         &FGControls::set_vertical_speed_select);
718   fgSetArchivable("/controls/autoflight/vertical-speed-select");
719
720   fgTie("/controls/autoflight/speed-select", this,
721         &FGControls::get_speed_select, 
722         &FGControls::set_speed_select);
723   fgSetArchivable("/controls/autoflight/speed-select");
724
725   fgTie("/controls/autoflight/mach-select", this,
726         &FGControls::get_mach_select, 
727         &FGControls::set_mach_select);
728   fgSetArchivable("/controls/autoflight/mach-select");
729
730   fgTie("/controls/autoflight/vertical-mode", this,
731         &FGControls::get_vertical_mode, 
732         &FGControls::set_vertical_mode);
733   fgSetArchivable("/controls/autoflight/vertical-mode");
734
735   fgTie("/controls/autoflight/lateral-mode", this,
736         &FGControls::get_lateral_mode, 
737         &FGControls::set_lateral_mode);
738   fgSetArchivable("/controls/autoflight/lateral-mode");
739
740 }
741
742 void FGControls::unbind ()
743 {
744   int index, i;
745   //Tie control properties.
746   fgUntie("/controls/flight/aileron");
747   fgUntie("/controls/flight/aileron-trim");
748   fgUntie("/controls/flight/elevator");
749   fgUntie("/controls/flight/elevator-trim");
750   fgUntie("/controls/flight/rudder");
751   fgUntie("/controls/flight/rudder-trim");
752   fgUntie("/controls/flight/flaps");
753   fgUntie("/controls/flight/slats");
754   fgUntie("/controls/flight/BLC");  
755   fgUntie("/controls/flight/spoilers");  
756   fgUntie("/controls/flight/speedbrake");  
757   fgUntie("/controls/flight/wing-sweep");  
758   fgUntie("/controls/flight/wing-fold");  
759   fgUntie("/controls/flight/drag-chute");
760   for (index = 0; index < MAX_ENGINES; index++) {
761     char name[MAX_NAME_LEN];
762     sprintf(name, "/controls/engines/engine[%d]/throttle", index);
763     fgUntie(name);
764     sprintf(name, "/controls/engines/engine[%d]/starter", index);
765     fgUntie(name);
766     sprintf(name, "/controls/engines/engine[%d]/fuel_pump", index);
767     fgUntie(name);
768     sprintf(name, "/controls/engines/engine[%d]/fire-switch", index);
769     fgUntie(name);
770     sprintf(name, 
771        "/controls/engines/engine[%d]/fire-bottle-discharge", index);
772     fgUntie(name);
773     sprintf(name, "/controls/engines/engine[%d]/throttle_idle", index);
774     fgUntie(name);
775     sprintf(name, "/controls/engines/engine[%d]/cutoff", index);
776     fgUntie(name);
777     sprintf(name, "/controls/engines/engine[%d]/mixture", index);
778     fgUntie(name);
779     sprintf(name, 
780        "/controls/engines/engine[%d]/propeller-pitch", index);
781     fgUntie(name);
782     sprintf(name, "/controls/engines/engine[%d]/magnetos", index);
783     fgUntie(name);
784     sprintf(name, "/controls/engines/engine[%d]/WEP", index);
785     fgUntie(name);
786     sprintf(name, "/controls/engines/engine[%d]/cowl-flaps-norm", index);
787     fgUntie(name);
788     sprintf(name, "/controls/engines/engine[%d]/feather", index);
789     fgUntie(name);
790     sprintf(name, "/controls/engines/engine[%d]/ignition", index);
791     fgUntie(name);
792     sprintf(name, "/controls/engines/engine[%d]/augmentation", index);
793     fgUntie(name);
794     sprintf(name, "/controls/engines/engine[%d]/reverser", index);
795     fgUntie(name);
796     sprintf(name, "/controls/engines/engine[%d]/water-injection", index);
797     fgUntie(name);
798     sprintf(name, "/controls/engines/engine[%d]/condition", index);
799     fgUntie(name);
800   }
801   fgUntie("/controls/fuel/dump-valve");
802   for (index = 0; index < MAX_TANKS; index++) {
803     char name[MAX_NAME_LEN];
804     sprintf(name, "/controls/fuel/tank[%d]/fuel_selector", index);
805     fgUntie(name);
806     sprintf(name, "/controls/fuel/tank[%d]/to_engine", index);
807     fgUntie(name);
808     sprintf(name, "/controls/fuel/tank[%d]/to_tank", index);
809     fgUntie(name);
810     for (i = 0; index < MAX_BOOSTPUMPS; i++) {
811       sprintf(name, "/controls/fuel/tank[%d]/boost-pump[%d]", index, i);
812       fgUntie(name);
813     }
814   }
815   fgUntie("/controls/gear/parking_brake");
816   fgUntie("/controls/gear/steering");
817   fgUntie("/controls/gear/gear_down");
818   fgUntie("/controls/gear/antiskid");
819   fgUntie("/controls/gear/tailhook");
820   fgUntie("/controls/gear/tailwheel-lock");
821   for (index = 0; index < MAX_WHEELS; index++) {
822     char name[MAX_NAME_LEN];
823     sprintf(name, "/controls/gear/wheel[%d]/brakes", index);
824     fgUntie(name);
825     sprintf(name, 
826        "/controls/gear/wheel[%d]/alternate-extension", index);
827     fgUntie(name);
828   }
829   fgUntie("/controls/anti-ice/wing-heat");
830   fgUntie("/controls/anti-ice/pitot-heat");
831   fgUntie("/controls/anti-ice/wiper");
832   fgUntie("/controls/anti-ice/window-heat");
833   for (index = 0; index < MAX_ENGINES; index++) {
834     char name[MAX_NAME_LEN];
835     sprintf(name, "/controls/anti-ice/engine[%d]/carb-heat", index);
836     fgUntie(name);
837     sprintf(name, "/controls/anti-ice/engine[%d]/inlet-heat", index);
838     fgUntie(name);
839   }
840   for (index = 0; index < MAX_HYD_SYSTEMS; index++) {
841     char name[MAX_NAME_LEN];
842     sprintf(name, 
843        "/controls/hydraulic/system[%d]/engine-pump", index);
844     fgUntie(name);
845     sprintf(name, 
846        "/controls/hydraulic/system[%d]/electric-pump", index);
847     fgUntie(name);
848   }
849   fgUntie("/controls/electric/battery-switch");
850   fgUntie("/controls/electric/external-power");
851   fgUntie("/controls/electric/APU-generator");    
852   for (index = 0; index < MAX_ENGINES; index++) {
853     char name[MAX_NAME_LEN];
854      sprintf(name, 
855        "/controls/electric/engine[%d]/generator", index);
856     fgUntie(name);
857     sprintf(name, 
858        "/controls/electric/engine[%d]/bus-tie", index);
859     fgUntie(name);
860   }
861   fgUntie("/controls/pneumatic/APU-bleed");
862   for (index = 0; index < MAX_ENGINES; index++) {
863     char name[MAX_NAME_LEN];
864      sprintf(name, 
865        "/controls/pneumatic/engine[%d]/bleed", index);
866     fgUntie(name);
867   }
868   fgUntie("/controls/pressurization/mode");
869   fgUntie("/controls/pressurization/dump");
870   for (index = 0; index < MAX_PACKS; index++) {
871     char name[MAX_NAME_LEN];
872     sprintf(name, 
873        "/controls/pressurization/pack[%d]/pack-on", index);
874     fgUntie(name);
875   }
876   fgUntie("/controls/lighting/landing-lights");  
877   fgUntie("/controls/lighting/turn-off-lights");  
878   fgUntie("/controls/lighting/taxi-light");  
879   fgUntie("/controls/lighting/logo-lights");  
880   fgUntie("/controls/lighting/nav-lights");  
881   fgUntie("/controls/lighting/beacon");  
882   fgUntie("/controls/lighting/strobe");  
883   fgUntie("/controls/lighting/panel-norm");  
884   fgUntie("/controls/lighting/instruments-norm");  
885   fgUntie("/controls/lighting/dome-norm");
886
887 #ifdef FG_HAVE_ARMAMENT
888   fgUntie("/controls/armament/master-arm");  
889   fgUntie("/controls/armament/station-select");  
890   fgUntie("/controls/armament/release-all");  
891   for (index = 0; index < MAX_STATIONS; index++) {
892     char name[MAX_NAME_LEN];
893     sprintf(name, 
894        "/controls/armament/station[%d]/stick-size", index);
895     fgUntie(name);
896     sprintf(name, 
897        "/controls/armament/station[%d]/release-stick", index);
898     fgUntie(name);
899     sprintf(name, 
900        "/controls/armament/station[%d]/release-all", index);
901     fgUntie(name);
902     sprintf(name, 
903        "/controls/armament/station[%d]/jettison-all", index);
904     fgUntie(name);
905   }
906 #endif
907   fgUntie("/controls/seat/vertical-adjust");  
908   fgUntie("/controls/seat/fore-aft-adjust");  
909   fgUntie("/controls/seat/eject");  
910   fgUntie("/controls/APU/off-start-run");  
911   fgUntie("/controls/APU/fire-switch");  
912   for (index = 0; index < MAX_AUTOPILOTS; index++) {
913     char name[MAX_NAME_LEN];
914     sprintf(name, 
915        "/controls/autoflight/autopilot[%d]/engage", index);
916     fgUntie(name);
917   }
918   fgUntie("/controls/autoflight/autothrottle-arm");  
919   fgUntie("/controls/autoflight/autothrottle-engage");  
920   fgUntie("/controls/autoflight/heading-select");  
921   fgUntie("/controls/autoflight/altitude-select");  
922   fgUntie("/controls/autoflight/bank-angle-select");  
923   fgUntie("/controls/autoflight/vertical-speed-select");  
924   fgUntie("/controls/autoflight/speed-select");  
925   fgUntie("/controls/autoflight/mach-select");  
926   fgUntie("/controls/autoflight/vertical-mode");  
927   fgUntie("/controls/autoflight/lateral-mode");  
928 }
929
930
931 void
932 FGControls::update (double dt)
933 {
934 }
935
936
937 \f
938 ////////////////////////////////////////////////////////////////////////
939 // Setters and adjusters.
940 ////////////////////////////////////////////////////////////////////////
941
942 void
943 FGControls::set_aileron (double pos)
944 {
945   aileron = pos;
946   CLAMP( &aileron, -1.0, 1.0 );
947                         
948   // check for autocoordination
949   if ( auto_coordination->getBoolValue() ) {
950     set_rudder( aileron / 2.0 );
951   }
952 }
953
954 void
955 FGControls::move_aileron (double amt)
956 {
957   aileron += amt;
958   CLAMP( &aileron, -1.0, 1.0 );
959                         
960   // check for autocoordination
961   if ( auto_coordination->getBoolValue() ) {
962     set_rudder( aileron / 2.0 );
963   }
964 }
965
966 void
967 FGControls::set_aileron_trim( double pos )
968 {
969     aileron_trim = pos;
970     CLAMP( &aileron_trim, -1.0, 1.0 );
971 }
972
973 void
974 FGControls::move_aileron_trim( double amt )
975 {
976     aileron_trim += amt;
977     CLAMP( &aileron_trim, -1.0, 1.0 );
978 }
979
980 void
981 FGControls::set_elevator( double pos )
982 {
983     elevator = pos;
984     CLAMP( &elevator, -1.0, 1.0 );
985 }
986
987 void
988 FGControls::move_elevator( double amt )
989 {
990     elevator += amt;
991     CLAMP( &elevator, -1.0, 1.0 );
992 }
993
994 void
995 FGControls::set_elevator_trim( double pos )
996 {
997     elevator_trim = pos;
998     CLAMP( &elevator_trim, -1.0, 1.0 );
999 }
1000
1001 void
1002 FGControls::move_elevator_trim( double amt )
1003 {
1004     elevator_trim += amt;
1005     CLAMP( &elevator_trim, -1.0, 1.0 );
1006 }
1007
1008 void
1009 FGControls::set_rudder( double pos )
1010 {
1011     rudder = pos;
1012     CLAMP( &rudder, -1.0, 1.0 );
1013 }
1014
1015 void
1016 FGControls::move_rudder( double amt )
1017 {
1018     rudder += amt;
1019     CLAMP( &rudder, -1.0, 1.0 );
1020 }
1021
1022 void
1023 FGControls::set_rudder_trim( double pos )
1024 {
1025     rudder_trim = pos;
1026     CLAMP( &rudder_trim, -1.0, 1.0 );
1027 }
1028
1029 void
1030 FGControls::move_rudder_trim( double amt )
1031 {
1032     rudder_trim += amt;
1033     CLAMP( &rudder_trim, -1.0, 1.0 );
1034 }
1035
1036 void
1037 FGControls::set_flaps( double pos )
1038 {
1039     flaps = pos;
1040     CLAMP( &flaps, 0.0, 1.0 );
1041 }
1042
1043 void
1044 FGControls::move_flaps( double amt )
1045 {
1046     flaps += amt;
1047     CLAMP( &flaps, 0.0, 1.0 );
1048 }
1049
1050 void
1051 FGControls::set_slats( double pos )
1052 {
1053     slats = pos;
1054     CLAMP( &slats, 0.0, 1.0 );
1055 }
1056
1057 void
1058 FGControls::move_slats( double amt )
1059 {
1060     slats += amt;
1061     CLAMP( &slats, 0.0, 1.0 );
1062 }
1063
1064 void
1065 FGControls::set_BLC( bool val )
1066 {
1067   BLC = val;
1068 }
1069
1070 void
1071 FGControls::set_spoilers( double pos )
1072 {
1073     spoilers = pos;
1074     CLAMP( &spoilers, 0.0, 1.0 );
1075 }
1076
1077 void
1078 FGControls::move_spoilers( double amt )
1079 {
1080     spoilers += amt;
1081     CLAMP( &spoilers, 0.0, 1.0 );
1082 }
1083
1084 void
1085 FGControls::set_speedbrake( double pos )
1086 {
1087     speedbrake = pos;
1088     CLAMP( &speedbrake, 0.0, 1.0 );
1089 }
1090
1091 void
1092 FGControls::move_speedbrake( double amt )
1093 {
1094     speedbrake += amt;
1095     CLAMP( &speedbrake, 0.0, 1.0 );
1096 }
1097
1098 void
1099 FGControls::set_wing_sweep( double pos )
1100 {
1101     wing_sweep = pos;
1102     CLAMP( &wing_sweep, 0.0, 1.0 );
1103 }
1104
1105 void
1106 FGControls::move_wing_sweep( double amt )
1107 {
1108     wing_sweep += amt;
1109     CLAMP( &wing_sweep, 0.0, 1.0 );
1110 }
1111
1112 void
1113 FGControls::set_wing_fold( bool val )
1114 {
1115   wing_fold = val;
1116 }
1117
1118 void
1119 FGControls::set_drag_chute( bool val )
1120 {
1121   drag_chute = val;
1122 }
1123
1124 void
1125 FGControls::set_throttle_idle( bool val )
1126 {
1127   throttle_idle = val;
1128 }
1129
1130 void
1131 FGControls::set_throttle( int engine, double pos )
1132 {
1133   if ( engine == ALL_ENGINES ) {
1134     for ( int i = 0; i < MAX_ENGINES; i++ ) {
1135       throttle[i] = pos;
1136       CLAMP( &throttle[i], 0.0, 1.0 );
1137     }
1138   } else {
1139     if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1140       throttle[engine] = pos;
1141       CLAMP( &throttle[engine], 0.0, 1.0 );
1142     }
1143   }
1144 }
1145
1146 void
1147 FGControls::move_throttle( int engine, double amt )
1148 {
1149     if ( engine == ALL_ENGINES ) {
1150         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1151             throttle[i] += amt;
1152             CLAMP( &throttle[i], 0.0, 1.0 );
1153         }
1154     } else {
1155         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1156             throttle[engine] += amt;
1157             CLAMP( &throttle[engine], 0.0, 1.0 );
1158         }
1159     }
1160 }
1161
1162 void
1163 FGControls::set_starter( int engine, bool flag )
1164 {
1165     if ( engine == ALL_ENGINES ) {
1166         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1167             starter[i] = flag;
1168         }
1169     } else {
1170         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1171             starter[engine] = flag;
1172         }
1173     }
1174 }
1175
1176 void
1177 FGControls::set_fuel_pump( int engine, bool val )
1178 {
1179     if ( engine == ALL_ENGINES ) {
1180         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1181             fuel_pump[i] = val;
1182         }
1183     } else {
1184         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1185             fuel_pump[engine] = val;
1186         }
1187     }
1188 }
1189
1190 void
1191 FGControls::set_fire_switch( int engine, bool val )
1192 {
1193     if ( engine == ALL_ENGINES ) {
1194         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1195             fire_switch[i] = val;
1196         }
1197     } else {
1198         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1199             fire_switch[engine] = val;
1200         }
1201     }
1202 }
1203
1204 void
1205 FGControls::set_fire_bottle_discharge( int engine, bool val )
1206 {
1207     if ( engine == ALL_ENGINES ) {
1208         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1209             fire_bottle_discharge[i] = val;
1210         }
1211     } else {
1212         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1213             fire_bottle_discharge[engine] = val;
1214         }
1215     }
1216 }
1217
1218 void
1219 FGControls::set_cutoff( int engine, bool val )
1220 {
1221     if ( engine == ALL_ENGINES ) {
1222         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1223             cutoff[i] = val;
1224         }
1225     } else {
1226         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1227             cutoff[engine] = val;
1228         }
1229     }
1230 }
1231
1232
1233 void
1234 FGControls::set_mixture( int engine, double pos )
1235 {
1236     if ( engine == ALL_ENGINES ) {
1237         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1238             mixture[i] = pos;
1239             CLAMP( &mixture[i], 0.0, 1.0 );
1240         }
1241     } else {
1242         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1243             mixture[engine] = pos;
1244             CLAMP( &mixture[engine], 0.0, 1.0 );
1245         }
1246     }
1247 }
1248
1249 void
1250 FGControls::move_mixture( int engine, double amt )
1251 {
1252     if ( engine == ALL_ENGINES ) {
1253         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1254             mixture[i] += amt;
1255             CLAMP( &mixture[i], 0.0, 1.0 );
1256         }
1257     } else {
1258         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1259             mixture[engine] += amt;
1260             CLAMP( &mixture[engine], 0.0, 1.0 );
1261         }
1262     }
1263 }
1264
1265 void
1266 FGControls::set_prop_advance( int engine, double pos )
1267 {
1268     if ( engine == ALL_ENGINES ) {
1269         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1270             prop_advance[i] = pos;
1271             CLAMP( &prop_advance[i], 0.0, 1.0 );
1272         }
1273     } else {
1274         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1275             prop_advance[engine] = pos;
1276             CLAMP( &prop_advance[engine], 0.0, 1.0 );
1277         }
1278     }
1279 }
1280
1281 void
1282 FGControls::move_prop_advance( int engine, double amt )
1283 {
1284     if ( engine == ALL_ENGINES ) {
1285         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1286             prop_advance[i] += amt;
1287             CLAMP( &prop_advance[i], 0.0, 1.0 );
1288         }
1289     } else {
1290         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1291             prop_advance[engine] += amt;
1292             CLAMP( &prop_advance[engine], 0.0, 1.0 );
1293         }
1294     }
1295 }
1296
1297 void
1298 FGControls::set_magnetos( int engine, int pos )
1299 {
1300     if ( engine == ALL_ENGINES ) {
1301         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1302             magnetos[i] = pos;
1303             CLAMP( &magnetos[i], 0, 3 );
1304         }
1305     } else {
1306         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1307             magnetos[engine] = pos;
1308             CLAMP( &magnetos[engine], 0, 3 );
1309         }
1310     }
1311 }
1312
1313 void
1314 FGControls::move_magnetos( int engine, int amt )
1315 {
1316     if ( engine == ALL_ENGINES ) {
1317         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1318             magnetos[i] += amt;
1319             CLAMP( &magnetos[i], 0, 3 );
1320         }
1321     } else {
1322         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1323             magnetos[engine] += amt;
1324             CLAMP( &magnetos[engine], 0, 3 );
1325         }
1326     }
1327 }
1328
1329 void
1330 FGControls::set_nitrous_injection( int engine, bool val )
1331 {
1332     if ( engine == ALL_ENGINES ) {
1333         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1334             nitrous_injection[i] = val;
1335         }
1336     } else {
1337         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1338             nitrous_injection[engine] = val;
1339         }
1340     }
1341 }
1342
1343
1344 void
1345 FGControls::set_cowl_flaps_norm( int engine, double pos )
1346 {
1347     if ( engine == ALL_ENGINES ) {
1348         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1349             cowl_flaps_norm[i] = pos;
1350             CLAMP( &cowl_flaps_norm[i], 0.0, 1.0 );
1351         }
1352     } else {
1353         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1354             cowl_flaps_norm[engine] = pos;
1355             CLAMP( &cowl_flaps_norm[engine], 0.0, 1.0 );
1356         }
1357     }
1358 }
1359
1360 void
1361 FGControls::move_cowl_flaps_norm( int engine, double amt )
1362 {
1363     if ( engine == ALL_ENGINES ) {
1364         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1365             cowl_flaps_norm[i] += amt;
1366             CLAMP( &cowl_flaps_norm[i], 0.0, 1.0 );
1367         }
1368     } else {
1369         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1370             cowl_flaps_norm[engine] += amt;
1371             CLAMP( &cowl_flaps_norm[engine], 0.0, 1.0 );
1372         }
1373     }
1374 }
1375
1376 void
1377 FGControls::set_feather( int engine, bool val )
1378 {
1379     if ( engine == ALL_ENGINES ) {
1380         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1381             feather[i] = val;
1382         }
1383     } else {
1384         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1385             feather[engine] = val;
1386         }
1387     }
1388 }
1389
1390 void
1391 FGControls::set_ignition( int engine, int pos )
1392 {
1393     if ( engine == ALL_ENGINES ) {
1394         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1395             ignition[i] = pos;
1396             CLAMP( &ignition[i], 0, 3 );
1397         }
1398     } else {
1399         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1400             ignition[engine] = pos;
1401             CLAMP( &ignition[engine], 0, 3 );
1402         }
1403     }
1404 }
1405
1406 void
1407 FGControls::set_augmentation( int engine, bool val )
1408 {
1409     if ( engine == ALL_ENGINES ) {
1410         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1411             augmentation[i] = val;
1412         }
1413     } else {
1414         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1415             augmentation[engine] = val;
1416         }
1417     }
1418 }
1419
1420 void
1421 FGControls::set_reverser( int engine, bool val )
1422 {
1423     if ( engine == ALL_ENGINES ) {
1424         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1425             reverser[i] = val;
1426         }
1427     } else {
1428         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1429             reverser[engine] = val;
1430         }
1431     }
1432 }
1433
1434 void
1435 FGControls::set_water_injection( int engine, bool val )
1436 {
1437     if ( engine == ALL_ENGINES ) {
1438         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1439             water_injection[i] = val;
1440         }
1441     } else {
1442         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1443             water_injection[engine] = val;
1444         }
1445     }
1446 }
1447
1448 void
1449 FGControls::set_condition( int engine, int val )
1450 {
1451     if ( engine == ALL_ENGINES ) {
1452         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1453             condition[i] = val;
1454             CLAMP( &condition[i], 0, 3 );
1455         }
1456     } else {
1457         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1458             condition[engine] = val;
1459             CLAMP( &condition[engine], 0, 3 );
1460         }
1461     }
1462 }
1463
1464 void
1465 FGControls::set_dump_valve( bool val )
1466 {
1467     dump_valve = val;
1468 }
1469
1470
1471 void
1472 FGControls::set_fuel_selector( int tank, bool pos )
1473 {
1474     if ( tank == ALL_TANKS ) {
1475         for ( int i = 0; i < MAX_TANKS; i++ ) {
1476             fuel_selector[i] = pos;
1477         }
1478     } else {
1479         if ( (tank >= 0) && (tank < MAX_TANKS) ) {
1480             fuel_selector[tank] = pos;
1481         }
1482     }
1483 }
1484
1485 void
1486 FGControls::set_to_engine( int tank, int engine )
1487 {
1488     if ( tank == ALL_TANKS ) {
1489         for ( int i = 0; i < MAX_TANKS; i++ ) {
1490             to_engine[i] = engine;
1491         }
1492     } else {
1493         if ( (tank >= 0) && (tank < MAX_TANKS) ) {
1494             to_engine[tank] = engine;
1495         }
1496     }
1497 }
1498
1499 void
1500 FGControls::set_to_tank( int tank, int dest_tank )
1501 {
1502     if ( tank == ALL_TANKS ) {
1503         for ( int i = 0; i < MAX_TANKS; i++ ) {
1504             to_tank[i] = dest_tank;
1505         }
1506     } else {
1507         if ( (tank >= 0) && (tank < MAX_TANKS) ) {
1508             to_tank[tank] = dest_tank;
1509         }
1510     }
1511 }
1512
1513 void
1514 FGControls::set_boost_pump( int index, bool val ) 
1515 {
1516     if ( index == -1 ) {
1517         for ( int i = 0; i < (MAX_TANKS * MAX_BOOSTPUMPS); i++ ) {
1518             boost_pump[i] = val;
1519         }
1520     } else {
1521         if ( (index >= 0) && (index < (MAX_TANKS * MAX_BOOSTPUMPS)) ) {
1522             boost_pump[index] = val;
1523         }
1524     }
1525 }
1526
1527
1528 void
1529 FGControls::set_parking_brake( double pos )
1530 {
1531     parking_brake = pos;
1532     CLAMP(&parking_brake, 0.0, 1.0);
1533 }
1534
1535 void
1536 FGControls::set_steering( double angle )
1537 {
1538     steering = angle;
1539     CLAMP(&steering, -80.0, 80.0);
1540 }
1541
1542 void
1543 FGControls::move_steering( double angle )
1544 {
1545     steering += angle;
1546     CLAMP(&steering, -80.0, 80.0);
1547 }
1548
1549 void
1550 FGControls::set_gear_down( bool gear )
1551 {
1552   gear_down = gear;
1553 }
1554
1555 void
1556 FGControls::set_antiskid( bool state )
1557 {
1558   antiskid = state;
1559 }
1560
1561 void
1562 FGControls::set_tailhook( bool state )
1563 {
1564   tailhook = state;
1565 }
1566
1567 void
1568 FGControls::set_tailwheel_lock( bool state )
1569 {
1570   tailwheel_lock = state;
1571 }
1572
1573
1574 void
1575 FGControls::set_brake( int wheel, double pos )
1576 {
1577     if ( wheel == ALL_WHEELS ) {
1578         for ( int i = 0; i < MAX_WHEELS; i++ ) {
1579             brake[i] = pos;
1580             CLAMP( &brake[i], 0.0, 1.0 );
1581         }
1582     } else {
1583         if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
1584             brake[wheel] = pos;
1585             CLAMP( &brake[wheel], 0.0, 1.0 );
1586         }
1587     }
1588 }
1589
1590 void
1591 FGControls::move_brake( int wheel, double amt )
1592 {
1593     if ( wheel == ALL_WHEELS ) {
1594         for ( int i = 0; i < MAX_WHEELS; i++ ) {
1595             brake[i] += amt;
1596             CLAMP( &brake[i], 0.0, 1.0 );
1597         }
1598     } else {
1599         if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
1600             brake[wheel] += amt;
1601             CLAMP( &brake[wheel], 0.0, 1.0 );
1602         }
1603     }
1604 }
1605
1606 void
1607 FGControls::set_alternate_extension( int wheel, bool val )
1608 {
1609     if ( wheel == ALL_WHEELS ) {
1610         for ( int i = 0; i < MAX_WHEELS; i++ ) {
1611             alternate_extension[i] = val;
1612         }
1613     } else {
1614         if ( (wheel >= 0) && (wheel < MAX_WHEELS) ) {
1615             alternate_extension[wheel] = val;
1616         }
1617     }
1618 }
1619
1620 void
1621 FGControls::set_wing_heat( bool state )
1622 {
1623   wing_heat = state;
1624 }
1625
1626 void
1627 FGControls::set_pitot_heat( bool state )
1628 {
1629   pitot_heat = state;
1630 }
1631
1632 void
1633 FGControls::set_wiper( int state )
1634 {
1635   wiper = state;
1636 }
1637
1638 void
1639 FGControls::set_window_heat( bool state )
1640 {
1641   window_heat = state;
1642 }
1643
1644 void
1645 FGControls::set_carb_heat( int engine, bool val )
1646 {
1647     if ( engine == ALL_ENGINES ) {
1648         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1649             carb_heat[i] = val;
1650         }
1651     } else {
1652         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1653             carb_heat[engine] = val;
1654         }
1655     }
1656 }
1657
1658 void
1659 FGControls::set_inlet_heat( int engine, bool val )
1660 {
1661     if ( engine == ALL_ENGINES ) {
1662         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1663             inlet_heat[i] = val;
1664         }
1665     } else {
1666         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1667             inlet_heat[engine] = val;
1668         }
1669     }
1670 }
1671
1672 void
1673 FGControls::set_engine_pump( int system, bool val )
1674 {
1675     if ( system == ALL_HYD_SYSTEMS ) {
1676         for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) {
1677             engine_pump[i] = val;
1678         }
1679     } else {
1680         if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) {
1681             engine_pump[system] = val;
1682         }
1683     }
1684 }
1685
1686 void
1687 FGControls::set_electric_pump( int system, bool val )
1688 {
1689     if ( system == ALL_HYD_SYSTEMS ) {
1690         for ( int i = 0; i < MAX_HYD_SYSTEMS; i++ ) {
1691             electric_pump[i] = val;
1692         }
1693     } else {
1694         if ( (system >= 0) && (system < MAX_HYD_SYSTEMS) ) {
1695             electric_pump[system] = val;
1696         }
1697     }
1698 }
1699
1700 void
1701 FGControls::set_battery_switch( bool state )
1702 {
1703   battery_switch = state;
1704 }
1705
1706 void
1707 FGControls::set_external_power( bool state )
1708 {
1709   external_power = state;
1710 }
1711
1712 void
1713 FGControls::set_APU_generator( bool state )
1714 {
1715   APU_generator = state;
1716 }
1717
1718 void
1719 FGControls::set_generator_breaker( int engine, bool val )
1720 {
1721     if ( engine == ALL_ENGINES ) {
1722         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1723             generator_breaker[i] = val;
1724         }
1725     } else {
1726         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1727             generator_breaker[engine] = val;
1728         }
1729     }
1730 }
1731
1732 void
1733 FGControls::set_bus_tie( int engine, bool val )
1734 {
1735     if ( engine == ALL_ENGINES ) {
1736         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1737             bus_tie[i] = val;
1738         }
1739     } else {
1740         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1741             bus_tie[engine] = val;
1742         }
1743     }
1744 }
1745
1746 void
1747 FGControls::set_APU_bleed( bool state )
1748 {
1749   APU_bleed = state;
1750 }
1751
1752 void
1753 FGControls::set_engine_bleed( int engine, bool val )
1754 {
1755     if ( engine == ALL_ENGINES ) {
1756         for ( int i = 0; i < MAX_ENGINES; i++ ) {
1757             engine_bleed[i] = val;
1758         }
1759     } else {
1760         if ( (engine >= 0) && (engine < MAX_ENGINES) ) {
1761             engine_bleed[engine] = val;
1762         }
1763     }
1764 }
1765
1766 void
1767 FGControls::set_mode( int new_mode )
1768 {
1769   mode = new_mode;
1770 }
1771
1772 void
1773 FGControls::set_outflow_valve( double pos )
1774 {
1775   outflow_valve = pos;
1776   CLAMP( &outflow_valve, 0.0, 1.0 );
1777 }
1778
1779 void
1780 FGControls::move_outflow_valve( double amt )
1781 {
1782   outflow_valve += amt;
1783   CLAMP( &outflow_valve, 0.0, 1.0 );
1784 }
1785
1786 void
1787 FGControls::set_dump( bool state )
1788 {
1789   dump = state;
1790 }
1791
1792 void
1793 FGControls::set_pack_on( int pack, bool val )
1794 {
1795     if ( pack == ALL_PACKS ) {
1796         for ( int i = 0; i < MAX_PACKS; i++ ) {
1797             pack_on[i] = val;
1798         }
1799     } else {
1800         if ( (pack >= 0) && (pack < MAX_PACKS) ) {
1801             pack_on[pack] = val;
1802         }
1803     }
1804 }
1805
1806 void
1807 FGControls::set_landing_lights( bool state )
1808 {
1809   landing_lights = state;
1810 }
1811
1812 void
1813 FGControls::set_turn_off_lights( bool state )
1814 {
1815   turn_off_lights = state;
1816 }
1817
1818 void
1819 FGControls::set_taxi_light( bool state )
1820 {
1821   taxi_light = state;
1822 }
1823
1824 void
1825 FGControls::set_logo_lights( bool state )
1826 {
1827   logo_lights = state;
1828 }
1829
1830 void
1831 FGControls::set_nav_lights( bool state )
1832 {
1833   nav_lights = state;
1834 }
1835
1836 void
1837 FGControls::set_beacon( bool state )
1838 {
1839   beacon = state;
1840 }
1841
1842 void
1843 FGControls::set_strobe( bool state )
1844 {
1845   strobe = state;
1846 }
1847
1848 void
1849 FGControls::set_panel_norm( double intensity )
1850 {
1851   panel_norm = intensity;
1852   CLAMP( &panel_norm, 0.0, 1.0 );
1853 }
1854
1855 void
1856 FGControls::move_panel_norm( double amt )
1857 {
1858   panel_norm += amt;
1859   CLAMP( &panel_norm, 0.0, 1.0 );
1860 }
1861
1862 void
1863 FGControls::set_instruments_norm( double intensity )
1864 {
1865   instruments_norm = intensity;
1866   CLAMP( &instruments_norm, 0.0, 1.0 );
1867 }
1868
1869 void
1870 FGControls::move_instruments_norm( double amt )
1871 {
1872   instruments_norm += amt;
1873   CLAMP( &instruments_norm, 0.0, 1.0 );
1874 }
1875
1876 void
1877 FGControls::set_dome_norm( double intensity )
1878 {
1879   dome_norm = intensity;
1880   CLAMP( &dome_norm, 0.0, 1.0 );
1881 }
1882
1883 void
1884 FGControls::move_dome_norm( double amt )
1885 {
1886   dome_norm += amt;
1887   CLAMP( &dome_norm, 0.0, 1.0 );
1888 }
1889
1890 #ifdef FG_HAVE_ARMAMENT
1891
1892 void
1893 FGControls::set_master_arm( bool val )
1894 {
1895   master_arm = val;
1896 }
1897
1898 void
1899 FGControls::set_station_select( int station )
1900 {
1901   station_select = station;
1902   CLAMP( &station_select, 0, MAX_STATIONS );
1903 }
1904
1905 void
1906 FGControls::set_release_ALL( bool val )
1907 {
1908   release_ALL = val;
1909 }
1910
1911 void
1912 FGControls::set_stick_size( int station, int size )
1913 {
1914     if ( station == ALL_STATIONS ) {
1915         for ( int i = 0; i < MAX_STATIONS; i++ ) {
1916             stick_size[i] = size;
1917             CLAMP( &stick_size[i], 1, 20 );
1918         }
1919     } else {
1920         if ( (station >= 0) && (station < MAX_STATIONS) ) {
1921             stick_size[station] = size;
1922             CLAMP( &stick_size[station], 1, 20 );
1923         }
1924     }
1925 }
1926
1927 void
1928 FGControls::set_release_stick( int station, bool val )
1929 {
1930     if ( station == ALL_STATIONS ) {
1931         for ( int i = 0; i < MAX_STATIONS; i++ ) {
1932             release_stick[i] = val;
1933         }
1934     } else {
1935         if ( (station >= 0) && (station < MAX_STATIONS) ) {
1936             release_stick[station] = val;
1937         }
1938     }
1939 }
1940
1941 void
1942 FGControls::set_release_all( int station, bool val )
1943 {
1944     if ( station == ALL_STATIONS ) {
1945         for ( int i = 0; i < MAX_STATIONS; i++ ) {
1946             release_all[i] = val;
1947         }
1948     } else {
1949         if ( (station >= 0) && (station < MAX_STATIONS) ) {
1950             release_all[station] = val;
1951         }
1952     }
1953 }
1954
1955 void
1956 FGControls::set_jettison_all( int station, bool val )
1957 {
1958     if ( station == ALL_STATIONS ) {
1959         for ( int i = 0; i < MAX_STATIONS; i++ ) {
1960             jettison_all[i] = val;
1961         }
1962     } else {
1963         if ( (station >= 0) && (station < MAX_STATIONS) ) {
1964             jettison_all[station] = val;
1965         }
1966     }
1967 }
1968
1969 #endif
1970
1971 void
1972 FGControls::set_vertical_adjust( double pos )
1973 {
1974   vertical_adjust = pos;
1975   CLAMP( &vertical_adjust, -1.0, 1.0 );
1976 }
1977
1978 void
1979 FGControls::move_vertical_adjust( double amt )
1980 {
1981   vertical_adjust += amt;
1982   CLAMP( &vertical_adjust, -1.0, 1.0 );
1983 }
1984
1985 void
1986 FGControls::set_fore_aft_adjust( double pos )
1987 {
1988   fore_aft_adjust = pos;
1989   CLAMP( &fore_aft_adjust, -1.0, 1.0 );
1990 }
1991
1992 void
1993 FGControls::move_fore_aft_adjust( double amt )
1994 {
1995   fore_aft_adjust += amt;
1996   CLAMP( &fore_aft_adjust, -1.0, 1.0 );
1997 }
1998
1999 void
2000 FGControls::set_eject( bool val )
2001 {
2002   eject = val;
2003 }
2004
2005 void
2006 FGControls::set_off_start_run( int pos )
2007 {
2008   off_start_run = pos;
2009   CLAMP( &off_start_run, 0, 3 );
2010 }
2011
2012 void
2013 FGControls::set_APU_fire_switch( bool val )
2014 {
2015   APU_fire_switch = val;
2016 }
2017
2018 void
2019 FGControls::set_autothrottle_arm( bool val )
2020 {
2021   autothrottle_arm = val;
2022 }
2023
2024 void
2025 FGControls::set_autothrottle_engage( bool val )
2026 {
2027   autothrottle_engage = val;
2028 }
2029
2030 void
2031 FGControls::set_heading_select( double heading )
2032 {
2033   heading_select = heading;
2034   CLAMP( &heading_select, 0.0, 360.0 );
2035 }
2036
2037 void
2038 FGControls::move_heading_select( double amt )
2039 {
2040   heading_select += amt;
2041   CLAMP( &heading_select, 0.0, 360.0 );
2042 }
2043
2044 void
2045 FGControls::set_altitude_select( double altitude )
2046 {
2047   altitude_select = altitude;
2048   CLAMP( &altitude_select, -1000.0, 100000.0 );
2049 }
2050
2051 void
2052 FGControls::move_altitude_select( double amt )
2053 {
2054   altitude_select += amt;
2055   CLAMP( &altitude_select, -1000.0, 100000.0 );
2056 }
2057
2058 void
2059 FGControls::set_bank_angle_select( double angle )
2060 {
2061   bank_angle_select = angle;
2062   CLAMP( &bank_angle_select, 10.0, 30.0 );
2063 }
2064
2065 void
2066 FGControls::move_bank_angle_select( double amt )
2067 {
2068   bank_angle_select += amt;
2069   CLAMP( &bank_angle_select, 10.0, 30.0 );
2070 }
2071
2072 void
2073 FGControls::set_vertical_speed_select( double speed )
2074 {
2075   vertical_speed_select = speed;
2076   CLAMP( &vertical_speed_select, -3000.0, 4000.0 );
2077 }
2078
2079 void
2080 FGControls::move_vertical_speed_select( double amt )
2081 {
2082   vertical_speed_select += amt;
2083   CLAMP( &vertical_speed_select, -3000.0, 4000.0 );
2084 }
2085
2086 void
2087 FGControls::set_speed_select( double speed )
2088 {
2089   speed_select = speed;
2090   CLAMP( &speed_select, 60.0, 400.0 );
2091 }
2092
2093 void
2094 FGControls::move_speed_select( double amt )
2095 {
2096   speed_select += amt;
2097   CLAMP( &speed_select, 60.0, 400.0 );
2098 }
2099
2100 void
2101 FGControls::set_mach_select( double mach )
2102 {
2103   mach_select = mach;
2104   CLAMP( &mach_select, 0.4, 4.0 );
2105 }
2106
2107 void
2108 FGControls::move_mach_select( double amt )
2109 {
2110   mach_select += amt;
2111   CLAMP( &mach_select, 0.4, 4.0 );
2112 }
2113
2114 void
2115 FGControls::set_vertical_mode( int mode )
2116 {
2117   vertical_mode = mode;
2118   CLAMP( &vertical_mode, 0, 4 );
2119 }
2120
2121 void
2122 FGControls::set_lateral_mode( int mode )
2123 {
2124   lateral_mode = mode;
2125   CLAMP( &lateral_mode, 0, 4 );
2126 }
2127
2128 void
2129 FGControls::set_autopilot_engage( int ap, bool val )
2130 {
2131     if ( ap == ALL_AUTOPILOTS ) {
2132         for ( int i = 0; i < MAX_AUTOPILOTS; i++ ) {
2133             autopilot_engage[i] = val;
2134         }
2135     } else {
2136         if ( (ap >= 0) && (ap < MAX_AUTOPILOTS) ) {
2137             autopilot_engage[ap] = val;
2138         }
2139     }
2140 }