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