]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bfi.cxx
Removed cloud layers added for testing.
[flightgear.git] / src / Main / bfi.cxx
index e9707e022a593050bf97b988d2f7f812bbd5af75..1137c0359c2bfe4d174d4ebf0b846ae89d4f9785 100644 (file)
@@ -4,6 +4,8 @@
 //
 // Copyright (C) 2000  David Megginson - david@megginson.com
 //
+// THIS CLASS IS DEPRECATED; USE THE PROPERTY MANAGER INSTEAD.
+//
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 // published by the Free Software Foundation; either version 2 of the
 //
 // $Id$
 
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
-#  include <iostream.h>
-#else
-#  include <iostream>
-#endif
+#include "fgfs.hxx"
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #endif
 
 #include "globals.hxx"
-#include "save.hxx"
 #include "fg_init.hxx"
-#include <simgear/misc/props.hxx>
+#include "fg_props.hxx"
 
-FG_USING_NAMESPACE(std);
+SG_USING_NAMESPACE(std);
 
 
 #include "bfi.hxx"
@@ -91,28 +83,16 @@ reinit ()
                                // that's going to get clobbered
                                // when we reinit the subsystems.
 
-  cout << "BFI: start reinit\n";
+  SG_LOG(SG_GENERAL, SG_INFO, "Starting BFI reinit");
 
                                // TODO: add more AP stuff
-  double elevator = FGBFI::getElevator();
-  double aileron = FGBFI::getAileron();
-  double rudder = FGBFI::getRudder();
-  double throttle = FGBFI::getThrottle();
-  double elevator_trim = FGBFI::getElevatorTrim();
-  double flaps = FGBFI::getFlaps();
-  double brake = FGBFI::getBrakes();
   bool apHeadingLock = FGBFI::getAPHeadingLock();
-  double apHeadingMag = FGBFI::getAPHeadingMag();
   bool apAltitudeLock = FGBFI::getAPAltitudeLock();
   double apAltitude = FGBFI::getAPAltitude();
-  const string &targetAirport = FGBFI::getTargetAirport();
   bool gpsLock = FGBFI::getGPSLock();
   // double gpsLatitude = FGBFI::getGPSTargetLatitude();
   // double gpsLongitude = FGBFI::getGPSTargetLongitude();
 
-  FGBFI::setTargetAirport("");
-  cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
-
   fgReInitSubsystems();
 
                                // FIXME: this is wrong.
@@ -123,55 +103,62 @@ reinit ()
   fgUpdateMoonPos();
   cur_light_params.Update();
   fgUpdateLocalTime();
+#ifndef FG_OLD_WEATHER
   fgUpdateWeatherDatabase();
-  fgRadioSearch();
+#endif
+  current_radiostack->search();
 
                                // Restore all of the old states.
-  FGBFI::setElevator(elevator);
-  FGBFI::setAileron(aileron);
-  FGBFI::setRudder(rudder);
-  FGBFI::setThrottle(throttle);
-  FGBFI::setElevatorTrim(elevator_trim);
-  FGBFI::setFlaps(flaps);
-  FGBFI::setBrakes(brake);
   FGBFI::setAPHeadingLock(apHeadingLock);
-  FGBFI::setAPHeadingMag(apHeadingMag);
   FGBFI::setAPAltitudeLock(apAltitudeLock);
   FGBFI::setAPAltitude(apAltitude);
-  FGBFI::setTargetAirport(targetAirport);
   FGBFI::setGPSLock(gpsLock);
 
   _needReinit = false;
 
-  cout << "BFI: end reinit\n";
+  SG_LOG(SG_GENERAL, SG_INFO, "Ending BFI reinit");
 }
 
-// BEGIN: kludge 2000-12-07
-// This is a kludge around a LaRCsim problem; see setAltitude()
-// for details.
-static int _altitude_countdown = 0;
-static double _requested_altitude = -9999;
-static bool _saved_freeze = false;
-static inline void _check_altitude ()
-{
-  if (_altitude_countdown > 0) {
-    _altitude_countdown--;
-    if (_altitude_countdown == 0) {
-      current_aircraft.fdm_state->set_Altitude(_requested_altitude);
-      globals->set_freeze(_saved_freeze);
-    }
-  }
-}
+// BEGIN: kludge
+// Allow the view to be set from two axes (i.e. a joystick hat)
+// This needs to be in FGViewer itself, somehow.
+static double axisLong = 0.0;
+static double axisLat = 0.0;
 
-static int _lighting_countdown = 0;
-static inline void _check_lighting ()
+static inline void
+_set_view_from_axes ()
 {
-  if (_lighting_countdown > 0) {
-    _lighting_countdown--;
-    if (_lighting_countdown == 0)
-      fgUpdateSkyAndLightingParams();
+                               // Take no action when hat is centered
+  if (axisLong == 0 && axisLat == 0)
+    return;
+
+  double viewDir = 0;
+
+  if (axisLong < 0) {          // Longitudinal axis forward
+    if (axisLat < 0)
+      viewDir = 45;
+    else if (axisLat > 0)
+      viewDir = 315;
+    else
+      viewDir = 0;
+  } else if (axisLong > 0) {   // Longitudinal axis backward
+    if (axisLat < 0)
+      viewDir = 135;
+    else if (axisLat > 0)
+      viewDir = 225;
+    else
+      viewDir = 180;
+  } else {                     // Longitudinal axis neutral
+    if (axisLat < 0)
+      viewDir = 90;
+    else
+      viewDir = 270;
   }
+
+  globals->get_current_view()->set_goal_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
+//   globals->get_current_view()->set_view_offset(viewDir*SGD_DEGREES_TO_RADIANS);
 }
+
 // END: kludge
 
 
@@ -180,25 +167,6 @@ static inline void _check_lighting ()
 // Local functions
 ////////////////////////////////////////////////////////////////////////
 
-static inline void 
-TIE_BOOL(const char * name, bool (*getter)(), void (*setter)(bool)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<bool>(getter, setter));
-}
-
-static inline void 
-TIE_INT(const char * name, int (*getter)(), void (*setter)(int)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<int>(getter, setter));
-}
-
-static inline void 
-TIE_DOUBLE(const char * name, double (*getter)(), void (*setter)(double)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<double>(getter, setter));
-}
-
-static inline void 
-TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<string>(getter, setter));
-}
 
 /**
  * Initialize the BFI by binding its functions to properties.
@@ -209,101 +177,62 @@ TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) {
 void
 FGBFI::init ()
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
+  SG_LOG(SG_GENERAL, SG_INFO, "Starting BFI init");
+
                                // Simulation
-  TIE_INT("/sim/flight-model", getFlightModel, setFlightModel);
-  TIE_STRING("/sim/aircraft", getAircraft, setAircraft);
-  TIE_STRING("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
-  TIE_STRING("/sim/time/gmt", getDateString, setDateString);
-  TIE_STRING("/sim/time/gmt-string", getGMTString, 0);
-  TIE_BOOL("/sim/hud/visibility", getHUDVisible, setHUDVisible);
-  TIE_BOOL("/sim/panel/visibility", getPanelVisible, setPanelVisible);
-  TIE_INT("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
-  TIE_INT("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
-
-                               // Position
-  TIE_STRING("/position/airport-id", getTargetAirport, setTargetAirport);
-  TIE_DOUBLE("/position/latitude", getLatitude, setLatitude);
-  TIE_DOUBLE("/position/longitude", getLongitude, setLongitude);
-  TIE_DOUBLE("/position/altitude", getAltitude, setAltitude);
-  TIE_DOUBLE("/position/altitude-agl", getAGL, 0);
+  fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
+  fgTie("/sim/view/offset", getViewOffset, setViewOffset);
+  fgTie("/sim/view/goal-offset", getGoalViewOffset, setGoalViewOffset);
+  fgTie("/sim/time/gmt", getDateString, setDateString);
+  fgTie("/sim/time/gmt-string", getGMTString);
 
                                // Orientation
-  TIE_DOUBLE("/orientation/heading", getHeading, setHeading);
-  TIE_DOUBLE("/orientation/heading-magnetic", getHeadingMag, 0);
-  TIE_DOUBLE("/orientation/pitch", getPitch, setPitch);
-  TIE_DOUBLE("/orientation/roll", getRoll, setRoll);
+  fgTie("/orientation/heading-magnetic", getHeadingMag);
 
                                // Engine
-  TIE_DOUBLE("/engines/engine0/rpm", getRPM, 0);
-  TIE_DOUBLE("/engines/engine0/egt", getEGT, 0);
-  TIE_DOUBLE("/engines/engine0/cht", getCHT, 0);
-  TIE_DOUBLE("/engines/engine0/mp", getMP, 0);
-
-                               // Velocities
-  TIE_DOUBLE("/velocities/airspeed", getAirspeed, setAirspeed);
-  TIE_DOUBLE("/velocities/side-slip", getSideSlip, 0);
-  TIE_DOUBLE("/velocities/vertical-speed", getVerticalSpeed, 0);
-  TIE_DOUBLE("/velocities/speed-north", getSpeedNorth, 0);
-  TIE_DOUBLE("/velocities/speed-east", getSpeedEast, 0);
-  TIE_DOUBLE("/velocities/speed-down", getSpeedDown, 0);
-
-                               // Controls
-  TIE_DOUBLE("/controls/throttle", getThrottle, setThrottle);
-  TIE_DOUBLE("/controls/mixture", getMixture, setMixture);
-  TIE_DOUBLE("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
-  TIE_DOUBLE("/controls/flaps", getFlaps, setFlaps);
-  TIE_DOUBLE("/controls/aileron", getAileron, setAileron);
-  TIE_DOUBLE("/controls/rudder", getRudder, setRudder);
-  TIE_DOUBLE("/controls/elevator", getElevator, setElevator);
-  TIE_DOUBLE("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
-  TIE_DOUBLE("/controls/brakes/all", getBrakes, setBrakes);
-  TIE_DOUBLE("/controls/brakes/left", getLeftBrake, setLeftBrake);
-  TIE_DOUBLE("/controls/brakes/right", getRightBrake, setRightBrake);
-  TIE_DOUBLE("/controls/brakes/center", getRightBrake, setCenterBrake);
+  fgTie("/engines/engine0/rpm", getRPM);
+  fgTie("/engines/engine0/egt", getEGT);
+  fgTie("/engines/engine0/cht", getCHT);
+  fgTie("/engines/engine0/mp", getMP);
+  fgTie("/engines/engine0/fuel-flow", getFuelFlow);
+
+  //consumables
+  fgTie("/consumables/fuel/tank1/level", getTank1Fuel, setTank1Fuel, false);
+  fgTie("/consumables/fuel/tank2/level", getTank2Fuel, setTank2Fuel, false);
 
                                // Autopilot
-  TIE_BOOL("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
-  TIE_DOUBLE("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
-  TIE_BOOL("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
-  TIE_DOUBLE("/autopilot/settings/heading", getAPHeading, setAPHeading);
-  TIE_DOUBLE("/autopilot/settings/heading-magnetic",
-             getAPHeadingMag, setAPHeadingMag);
-  TIE_BOOL("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
-
-                               // Radio navigation
-  TIE_DOUBLE("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
-  TIE_DOUBLE("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
-  TIE_DOUBLE("/radios/nav1/radials/actual", getNAV1Radial, 0);
-  TIE_DOUBLE("/radios/nav1/radials/selected",
-             getNAV1SelRadial, setNAV1SelRadial);
-  TIE_DOUBLE("/radios/nav1/dme/distance", getNAV1DistDME, 0);
-  TIE_BOOL("/radios/nav1/to-flag", getNAV1TO, 0);
-  TIE_BOOL("/radios/nav1/from-flag", getNAV1FROM, 0);
-  TIE_BOOL("/radios/nav1/in-range", getNAV1InRange, 0);
-  TIE_BOOL("/radios/nav1/dme/in-range", getNAV1DMEInRange, 0);
-                              
-  TIE_DOUBLE("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
-  TIE_DOUBLE("/radios/nav2/frequencies/standby",
-             getNAV2AltFreq, setNAV2AltFreq);
-  TIE_DOUBLE("/radios/nav2/radials/actual", getNAV2Radial, 0);
-  TIE_DOUBLE("/radios/nav2/radials/selected",
-             getNAV2SelRadial, setNAV2SelRadial);
-  TIE_DOUBLE("/radios/nav2/dme/distance", getNAV2DistDME, 0);
-  TIE_BOOL("/radios/nav2/to-flag", getNAV2TO, 0);
-  TIE_BOOL("/radios/nav2/from-flag", getNAV2FROM, 0);
-  TIE_BOOL("/radios/nav2/in-range", getNAV2InRange, 0);
-  TIE_BOOL("/radios/nav2/dme/in-range", getNAV2DMEInRange, 0);
-
-  TIE_DOUBLE("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
-  TIE_DOUBLE("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
-  TIE_DOUBLE("/radios/adf/rotation", getADFRotation, setADFRotation);
-
-  TIE_DOUBLE("/environment/visibility", getVisibility, setVisibility);
+  fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
+  fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
+  fgTie("/autopilot/locks/glide-slope", getAPGSLock, setAPGSLock);
+  fgTie("/autopilot/settings/climb-rate", getAPClimb, setAPClimb, false);
+  fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
+  fgTie("/autopilot/settings/heading-bug", getAPHeadingBug, setAPHeadingBug,
+       false);
+  fgTie("/autopilot/locks/wing-leveler", getAPWingLeveler, setAPWingLeveler);
+  fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
+  fgTie("/autopilot/locks/auto-throttle",
+       getAPAutoThrottleLock, setAPAutoThrottleLock);
+  fgTie("/autopilot/control-overrides/rudder",
+       getAPRudderControl, setAPRudderControl);
+  fgTie("/autopilot/control-overrides/elevator",
+       getAPElevatorControl, setAPElevatorControl);
+  fgTie("/autopilot/control-overrides/throttle",
+       getAPThrottleControl, setAPThrottleControl);
+
+                               // Weather
+  fgTie("/environment/visibility", getVisibility, setVisibility);
+  fgTie("/environment/wind-north", getWindNorth, setWindNorth);
+  fgTie("/environment/wind-east", getWindEast, setWindEast);
+  fgTie("/environment/wind-down", getWindDown, setWindDown);
+
+                               // View
+  fgTie("/sim/field-of-view", getFOV, setFOV);
+  fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
+  fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
 
   _needReinit = false;
 
-  FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
+  SG_LOG(SG_GENERAL, SG_INFO, "Ending BFI init");
 }
 
 
@@ -318,8 +247,7 @@ FGBFI::init ()
 void
 FGBFI::update ()
 {
-  _check_altitude();
-  _check_lighting();
+  _set_view_from_axes();
   if (_needReinit) {
     reinit();
   }
@@ -332,81 +260,62 @@ FGBFI::update ()
 ////////////////////////////////////////////////////////////////////////
 
 
-/**
- * Return the flight model as an integer.
- *
- * TODO: use a string instead.
- */
-int
-FGBFI::getFlightModel ()
-{
-  return globals->get_options()->get_flight_model();
-}
-
-
-/**
- * Return the current aircraft as a string.
- */
-string
-FGBFI::getAircraft ()
-{
-  _temp = globals->get_options()->get_aircraft();
-  return _temp;
-}
-
-
 /**
  * Return the current aircraft directory (UIUC) as a string.
  */
 string 
 FGBFI::getAircraftDir ()
 {
-  _temp = aircraft_dir;
-  return _temp;
+  return aircraft_dir;
 }
 
 
 /**
- * Set the flight model as an integer.
- *
- * TODO: use a string instead.
+ * Set the current aircraft directory (UIUC).
  */
 void
-FGBFI::setFlightModel (int model)
+FGBFI::setAircraftDir (string dir)
 {
-  if (getFlightModel() != model) {
-    globals->get_options()->set_flight_model(model);
+  if (getAircraftDir() != dir) {
+    aircraft_dir = dir;
     needReinit();
   }
 }
 
 
 /**
- * Set the current aircraft.
+ * Get the current view offset in degrees.
  */
+double
+FGBFI::getViewOffset ()
+{
+  return (globals->get_current_view()
+         ->get_view_offset() * SGD_RADIANS_TO_DEGREES);
+}
+
 void
-FGBFI::setAircraft (string aircraft)
+FGBFI::setViewOffset (double offset)
 {
-  if (getAircraft() != aircraft) {
-    globals->get_options()->set_aircraft(aircraft);
-    needReinit();
-  }
+  globals->get_current_view()->set_view_offset(offset * SGD_DEGREES_TO_RADIANS);
 }
 
+double
+FGBFI::getGoalViewOffset ()
+{
+  return (globals->get_current_view()
+         ->get_goal_view_offset() * SGD_RADIANS_TO_DEGREES);
+}
 
-/**
- * Set the current aircraft directory (UIUC).
- */
 void
-FGBFI::setAircraftDir (string dir)
+FGBFI::setGoalViewOffset (double offset)
 {
-  if (getAircraftDir() != dir) {
-    aircraft_dir = dir;
-    needReinit();
-  }
+  globals->get_current_view()
+    ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
 }
 
 
+
+
 /**
  * Return the current Zulu time.
  */
@@ -447,7 +356,7 @@ FGBFI::setDateString (string date_string)
                                // if the save file has been edited
                                // by hand.
   if (ret != 6) {
-    FG_LOG(FG_INPUT, FG_ALERT, "Date/time string " << date_string
+    SG_LOG(SG_INPUT, SG_ALERT, "Date/time string " << date_string
           << " not in YYYY-MM-DDTHH:MM:SS format; skipped");
     return;
   }
@@ -464,7 +373,7 @@ FGBFI::setDateString (string date_string)
     mktime(&new_time) - mktime(current_time) + globals->get_warp();
   double lon = current_aircraft.fdm_state->get_Longitude();
   double lat = current_aircraft.fdm_state->get_Latitude();
-  double alt = current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER;
+  // double alt = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER;
   globals->set_warp(warp);
   st->update(lon, lat, warp);
   fgUpdateSkyAndLightingParams();
@@ -487,98 +396,6 @@ FGBFI::getGMTString ()
 }
 
 
-/**
- * Return true if the HUD is visible.
- */
-bool
-FGBFI::getHUDVisible ()
-{
-  return globals->get_options()->get_hud_status();
-}
-
-
-/**
- * Ensure that the HUD is visible or hidden.
- */
-void
-FGBFI::setHUDVisible (bool visible)
-{
-  globals->get_options()->set_hud_status(visible);
-}
-
-
-/**
- * Return true if the 2D panel is visible.
- */
-bool
-FGBFI::getPanelVisible ()
-{
-  return globals->get_options()->get_panel_status();
-}
-
-
-/**
- * Ensure that the 2D panel is visible or hidden.
- */
-void
-FGBFI::setPanelVisible (bool visible)
-{
-  if (globals->get_options()->get_panel_status() != visible) {
-    globals->get_options()->toggle_panel();
-  }
-}
-
-
-/**
- * Get the panel's current x-shift.
- */
-int
-FGBFI::getPanelXOffset ()
-{
-  if (current_panel != 0)
-    return current_panel->getXOffset();
-  else
-    return 0;
-}
-
-
-/**
- * Set the panel's current x-shift.
- */
-void
-FGBFI::setPanelXOffset (int offset)
-{
-  if (current_panel != 0)
-    current_panel->setXOffset(offset);
-}
-
-
-/**
- * Get the panel's current y-shift.
- */
-int
-FGBFI::getPanelYOffset ()
-{
-  if (current_panel != 0)
-    return current_panel->getYOffset();
-  else
-    return 0;
-}
-
-
-/**
- * Set the panel's current y-shift.
- */
-void
-FGBFI::setPanelYOffset (int offset)
-{
-  if (current_panel != 0)
-    current_panel->setYOffset(offset);
-}
-
-
-
-
 \f
 ////////////////////////////////////////////////////////////////////////
 // Position
@@ -591,7 +408,7 @@ FGBFI::setPanelYOffset (int offset)
 double
 FGBFI::getLatitude ()
 {
-  return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -601,10 +418,7 @@ FGBFI::getLatitude ()
 void
 FGBFI::setLatitude (double latitude)
 {
-  current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
-  fgUpdateSkyAndLightingParams();
-  if (_lighting_countdown <= 0)
-    _lighting_countdown = 5;
+  current_aircraft.fdm_state->set_Latitude(latitude * SGD_DEGREES_TO_RADIANS);
 }
 
 
@@ -614,7 +428,7 @@ FGBFI::setLatitude (double latitude)
 double
 FGBFI::getLongitude ()
 {
-  return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -624,10 +438,7 @@ FGBFI::getLongitude ()
 void
 FGBFI::setLongitude (double longitude)
 {
-  current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
-  fgUpdateSkyAndLightingParams();
-  if (_lighting_countdown <= 0)
-    _lighting_countdown = 5;
+  current_aircraft.fdm_state->set_Longitude(longitude * SGD_DEGREES_TO_RADIANS);
 }
 
 
@@ -649,7 +460,7 @@ double
 FGBFI::getAGL ()
 {
   return current_aircraft.fdm_state->get_Altitude()
-        - (scenery.cur_elev * METER_TO_FEET);
+        - (scenery.cur_elev * SG_METER_TO_FEET);
 }
 
 
@@ -660,22 +471,6 @@ void
 FGBFI::setAltitude (double altitude)
 {
   current_aircraft.fdm_state->set_Altitude(altitude);
-
-                               // 2000-12-07
-                               // This is an ugly kludge around a
-                               // LaRCsim problem; if the
-                               // requested altitude cannot be
-                               // set right away (because it's
-                               // below the last-calculated ground
-                               // level), pause FGFS, wait for
-                               // five frames, and then try again.
-  if (_altitude_countdown <= 0 &&
-      fabs(getAltitude() - altitude) > 5.0) {
-    _altitude_countdown = 5;
-    _requested_altitude = altitude;
-    _saved_freeze = globals->get_freeze();
-    globals->set_freeze(true);
-  }
 }
 
 
@@ -691,7 +486,7 @@ FGBFI::setAltitude (double altitude)
 double
 FGBFI::getHeading ()
 {
-  return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -701,7 +496,7 @@ FGBFI::getHeading ()
 double
 FGBFI::getHeadingMag ()
 {
-  return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG - getMagVar();
+  return current_aircraft.fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES - getMagVar();
 }
 
 
@@ -713,7 +508,7 @@ FGBFI::setHeading (double heading)
 {
   FGInterface * fdm = current_aircraft.fdm_state;
   fdm->set_Euler_Angles(fdm->get_Phi(), fdm->get_Theta(),
-                       heading * DEG_TO_RAD);
+                       heading * SGD_DEGREES_TO_RADIANS);
 }
 
 
@@ -723,7 +518,7 @@ FGBFI::setHeading (double heading)
 double
 FGBFI::getPitch ()
 {
-  return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Theta() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -734,7 +529,7 @@ void
 FGBFI::setPitch (double pitch)
 {
   FGInterface * fdm = current_aircraft.fdm_state;
-  fdm->set_Euler_Angles(fdm->get_Phi(), pitch * DEG_TO_RAD, fdm->get_Psi());
+  fdm->set_Euler_Angles(fdm->get_Phi(), pitch * SGD_DEGREES_TO_RADIANS, fdm->get_Psi());
 }
 
 
@@ -744,7 +539,7 @@ FGBFI::setPitch (double pitch)
 double
 FGBFI::getRoll ()
 {
-  return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Phi() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -755,7 +550,7 @@ void
 FGBFI::setRoll (double roll)
 {
   FGInterface * fdm = current_aircraft.fdm_state;
-  fdm->set_Euler_Angles(roll * DEG_TO_RAD, fdm->get_Theta(), fdm->get_Psi());
+  fdm->set_Euler_Angles(roll * SGD_DEGREES_TO_RADIANS, fdm->get_Theta(), fdm->get_Psi());
 }
 
 
@@ -816,7 +611,7 @@ FGBFI::getCHT ()
 
 
 /**
- * Return the current engine0 CHT.
+ * Return the current engine0 Manifold Pressure.
  */
 double
 FGBFI::getMP ()
@@ -828,6 +623,52 @@ FGBFI::getMP ()
   }
 }
 
+/**
+ * Return the current engine0 fuel flow
+ */
+double
+FGBFI::getFuelFlow ()
+{
+  if ( current_aircraft.fdm_state->get_engine(0) != NULL ) {
+      return current_aircraft.fdm_state->get_engine(0)->get_Fuel_Flow();
+  } else {
+      return 0.0;
+  }
+}
+
+////////////////////////////////////////////////////////////////////////
+// Consumables
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Return the fuel level in tank 1
+ */
+double
+FGBFI::getTank1Fuel ()
+{
+  return current_aircraft.fdm_state->get_Tank1Fuel();
+}
+
+void
+FGBFI::setTank1Fuel ( double gals )
+{
+  current_aircraft.fdm_state->set_Tank1Fuel( gals );
+}
+
+/**
+ * Return the fuel level in tank 2
+ */
+double
+FGBFI::getTank2Fuel ()
+{
+  return current_aircraft.fdm_state->get_Tank2Fuel();
+}
+
+void
+FGBFI::setTank2Fuel ( double gals )
+{
+  current_aircraft.fdm_state->set_Tank2Fuel( gals );
+}
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -942,785 +783,463 @@ FGBFI::getSpeedDown ()
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Controls
+// Autopilot
 ////////////////////////////////////////////////////////////////////////
 
 
 /**
- * Get the throttle setting, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot altitude lock (true=on).
  */
-double
-FGBFI::getThrottle ()
+bool
+FGBFI::getAPAltitudeLock ()
 {
-                               // FIXME: add engine selector
-  return controls.get_throttle(0);
+    return current_autopilot->get_AltitudeEnabled();
 }
 
 
 /**
- * Set the throttle, from 0.0 (none) to 1.0 (full).
+ * Set the autopilot altitude lock (true=on).
  */
 void
-FGBFI::setThrottle (double throttle)
+FGBFI::setAPAltitudeLock (bool lock)
 {
-                               // FIXME: allow engine selection
-  controls.set_throttle(0, throttle);
+  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
+  current_autopilot->set_AltitudeEnabled(lock);
 }
 
 
 /**
- * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot altitude lock (true=on).
  */
-double
-FGBFI::getMixture ()
+bool
+FGBFI::getAPGSLock ()
 {
-                               // FIXME: add engine selector
-  return controls.get_mixture(0);
+    return current_autopilot->get_AltitudeEnabled();
 }
 
 
 /**
- * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
+ * Set the autopilot altitude lock (true=on).
  */
 void
-FGBFI::setMixture (double mixture)
+FGBFI::setAPGSLock (bool lock)
 {
-                               // FIXME: allow engine selection
-  controls.set_mixture(0, mixture);
+  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
+  current_autopilot->set_AltitudeEnabled(lock);
 }
 
 
 /**
- * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot target altitude in feet.
  */
 double
-FGBFI::getPropAdvance ()
+FGBFI::getAPAltitude ()
 {
-                               // FIXME: add engine selector
-  return controls.get_prop_advance(0);
+  return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
 }
 
 
 /**
- * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
+ * Set the autopilot target altitude in feet.
  */
 void
-FGBFI::setPropAdvance (double pitch)
+FGBFI::setAPAltitude (double altitude)
 {
-                               // FIXME: allow engine selection
-  controls.set_prop_advance(0, pitch);
+    current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
 }
 
 
 /**
- * Get the flaps setting, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot target altitude in feet.
  */
 double
-FGBFI::getFlaps ()
+FGBFI::getAPClimb ()
 {
-  return controls.get_flaps();
+  return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
 }
 
 
 /**
- * Set the flaps, from 0.0 (none) to 1.0 (full).
+ * Set the autopilot target altitude in feet.
  */
 void
-FGBFI::setFlaps (double flaps)
+FGBFI::setAPClimb (double rate)
 {
-                               // FIXME: clamp?
-  controls.set_flaps(flaps);
+    current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
 }
 
 
 /**
- * Get the aileron, from -1.0 (left) to 1.0 (right).
+ * Get the autopilot heading lock (true=on).
  */
-double
-FGBFI::getAileron ()
+bool
+FGBFI::getAPHeadingLock ()
 {
-  return controls.get_aileron();
+    return
+      (current_autopilot->get_HeadingEnabled() &&
+       current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
 }
 
 
 /**
- * Set the aileron, from -1.0 (left) to 1.0 (right).
+ * Set the autopilot heading lock (true=on).
  */
 void
-FGBFI::setAileron (double aileron)
+FGBFI::setAPHeadingLock (bool lock)
 {
-                               // FIXME: clamp?
-  controls.set_aileron(aileron);
+    if (lock) {
+       current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
+       current_autopilot->set_HeadingEnabled(true);
+    } else {
+       current_autopilot->set_HeadingEnabled(false);
+    }
 }
 
 
 /**
- * Get the rudder setting, from -1.0 (left) to 1.0 (right).
+ * Get the autopilot heading bug in degrees.
  */
 double
-FGBFI::getRudder ()
+FGBFI::getAPHeadingBug ()
 {
-  return controls.get_rudder();
+  return current_autopilot->get_DGTargetHeading();
 }
 
 
 /**
- * Set the rudder, from -1.0 (left) to 1.0 (right).
+ * Set the autopilot heading bug in degrees.
  */
 void
-FGBFI::setRudder (double rudder)
+FGBFI::setAPHeadingBug (double heading)
 {
-                               // FIXME: clamp?
-  controls.set_rudder(rudder);
+  current_autopilot->set_DGTargetHeading( heading );
 }
 
 
 /**
- * Get the elevator setting, from -1.0 (down) to 1.0 (up).
+ * Get the autopilot wing leveler lock (true=on).
  */
-double
-FGBFI::getElevator ()
+bool
+FGBFI::getAPWingLeveler ()
 {
-  return controls.get_elevator();
+    return
+      (current_autopilot->get_HeadingEnabled() &&
+       current_autopilot->get_HeadingMode() == FGAutopilot::FG_TC_HEADING_LOCK);
 }
 
 
 /**
- * Set the elevator, from -1.0 (down) to 1.0 (up).
+ * Set the autopilot wing leveler lock (true=on).
  */
 void
-FGBFI::setElevator (double elevator)
+FGBFI::setAPWingLeveler (bool lock)
 {
-                               // FIXME: clamp?
-  controls.set_elevator(elevator);
+    if (lock) {
+       current_autopilot->set_HeadingMode(FGAutopilot::FG_TC_HEADING_LOCK);
+       current_autopilot->set_HeadingEnabled(true);
+    } else {
+       current_autopilot->set_HeadingEnabled(false);
+    }
 }
 
 
 /**
- * Get the elevator trim, from -1.0 (down) to 1.0 (up).
+ * Return true if the autopilot is locked to NAV1.
  */
-double
-FGBFI::getElevatorTrim ()
+bool
+FGBFI::getAPNAV1Lock ()
 {
-  return controls.get_elevator_trim();
+  return
+    (current_autopilot->get_HeadingEnabled() &&
+     current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
 }
 
 
 /**
- * Set the elevator trim, from -1.0 (down) to 1.0 (up).
+ * Set the autopilot NAV1 lock.
  */
 void
-FGBFI::setElevatorTrim (double trim)
+FGBFI::setAPNAV1Lock (bool lock)
 {
-                               // FIXME: clamp?
-  controls.set_elevator_trim(trim);
+  if (lock) {
+    current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
+    current_autopilot->set_HeadingEnabled(true);
+  } else if (current_autopilot->get_HeadingMode() ==
+            FGAutopilot::FG_HEADING_NAV1) {
+    current_autopilot->set_HeadingEnabled(false);
+  }
 }
 
-
 /**
- * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot autothrottle lock.
  */
-double
-FGBFI::getBrakes ()
+bool
+FGBFI::getAPAutoThrottleLock ()
 {
-  double b1 = getCenterBrake();
-  double b2 = getLeftBrake();
-  double b3 = getRightBrake();
-  return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
+  return current_autopilot->get_AutoThrottleEnabled();
 }
 
 
 /**
- * Set all brakes, from 0.0 (none) to 1.0 (full).
+ * Set the autothrottle lock.
  */
 void
-FGBFI::setBrakes (double brake)
+FGBFI::setAPAutoThrottleLock (bool lock)
 {
-  setCenterBrake(brake);
-  setLeftBrake(brake);
-  setRightBrake(brake);
+  current_autopilot->set_AutoThrottleEnabled(lock);
 }
 
 
-/**
- * Get the center brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 double
-FGBFI::getCenterBrake ()
+FGBFI::getAPRudderControl ()
 {
-  return controls.get_brake(2);
+    if (getAPHeadingLock())
+        return current_autopilot->get_TargetHeading();
+    else
+        return controls.get_rudder();
 }
 
-
-/**
- * Set the center brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 void
-FGBFI::setCenterBrake (double brake)
+FGBFI::setAPRudderControl (double value)
 {
-  controls.set_brake(2, brake);
+    if (getAPHeadingLock()) {
+        SG_LOG(SG_GENERAL, SG_DEBUG, "setAPRudderControl " << value );
+        value -= current_autopilot->get_TargetHeading();
+        current_autopilot->HeadingAdjust(value < 0.0 ? -1.0 : 1.0);
+    } else {
+        controls.set_rudder(value);
+    }
 }
 
-
-/**
- * Get the left brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 double
-FGBFI::getLeftBrake ()
+FGBFI::getAPElevatorControl ()
 {
-  return controls.get_brake(0);
+  if (getAPAltitudeLock())
+      return current_autopilot->get_TargetAltitude();
+  else
+    return controls.get_elevator();
 }
 
-
-/**
- * Set the left brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 void
-FGBFI::setLeftBrake (double brake)
+FGBFI::setAPElevatorControl (double value)
 {
-  controls.set_brake(0, brake);
+    if (getAPAltitudeLock()) {
+        SG_LOG(SG_GENERAL, SG_DEBUG, "setAPElevatorControl " << value );
+        value -= current_autopilot->get_TargetAltitude();
+        current_autopilot->AltitudeAdjust(value < 0.0 ? 100.0 : -100.0);
+    } else {
+        controls.set_elevator(value);
+    }
 }
 
-
-/**
- * Get the right brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 double
-FGBFI::getRightBrake ()
+FGBFI::getAPThrottleControl ()
 {
-  return controls.get_brake(1);
+  if (getAPAutoThrottleLock())
+    return 0.0;                        // always resets
+  else
+    return controls.get_throttle(0);
 }
 
-
-/**
- * Set the right brake, from 0.0 (none) to 1.0 (full).
- */
+// kludge
 void
-FGBFI::setRightBrake (double brake)
+FGBFI::setAPThrottleControl (double value)
 {
-  controls.set_brake(1, brake);
+  if (getAPAutoThrottleLock())
+    current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
+  else
+    controls.set_throttle(0, value);
 }
 
 
-
-
 \f
 ////////////////////////////////////////////////////////////////////////
-// Autopilot
+// GPS
 ////////////////////////////////////////////////////////////////////////
 
 
 /**
- * Get the autopilot altitude lock (true=on).
+ * Get the autopilot GPS lock (true=on).
  */
 bool
-FGBFI::getAPAltitudeLock ()
+FGBFI::getGPSLock ()
 {
-    return current_autopilot->get_AltitudeEnabled();
+  return (current_autopilot->get_HeadingEnabled() &&
+         (current_autopilot->get_HeadingMode() ==
+          FGAutopilot::FG_HEADING_WAYPOINT ));
 }
 
 
 /**
- * Set the autopilot altitude lock (true=on).
+ * Set the autopilot GPS lock (true=on).
  */
 void
-FGBFI::setAPAltitudeLock (bool lock)
-{
-  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
-  current_autopilot->set_AltitudeEnabled(lock);
-}
-
-
-/**
- * Get the autopilot target altitude in feet.
- */
-double
-FGBFI::getAPAltitude ()
-{
-  return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
-}
-
-
-/**
- * Set the autopilot target altitude in feet.
- */
-void
-FGBFI::setAPAltitude (double altitude)
-{
-    current_autopilot->set_TargetAltitude( altitude );
-}
-
-
-/**
- * Get the autopilot heading lock (true=on).
- */
-bool
-FGBFI::getAPHeadingLock ()
-{
-    return
-      (current_autopilot->get_HeadingEnabled() &&
-       current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_LOCK);
-}
-
-
-/**
- * Set the autopilot heading lock (true=on).
- */
-void
-FGBFI::setAPHeadingLock (bool lock)
+FGBFI::setGPSLock (bool lock)
 {
   if (lock) {
-                               // We need to do this so that
-                               // it's possible to lock onto a
-                               // heading other than the current
-                               // heading.
-    double heading = getAPHeadingMag();
-    current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_LOCK);
+    current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
     current_autopilot->set_HeadingEnabled(true);
-    setAPHeadingMag(heading);
   } else if (current_autopilot->get_HeadingMode() ==
-            FGAutopilot::FG_HEADING_LOCK) {
+            FGAutopilot::FG_HEADING_WAYPOINT) {
     current_autopilot->set_HeadingEnabled(false);
   }
 }
 
 
 /**
- * Get the autopilot target heading in degrees.
+ * Get the GPS target latitude in degrees (negative for south).
  */
 double
-FGBFI::getAPHeading ()
-{
-  return current_autopilot->get_TargetHeading();
-}
-
-
-/**
- * Set the autopilot target heading in degrees.
- */
-void
-FGBFI::setAPHeading (double heading)
+FGBFI::getGPSTargetLatitude ()
 {
-  current_autopilot->set_TargetHeading( heading );
+    return current_autopilot->get_TargetLatitude();
 }
 
 
 /**
- * Get the autopilot target heading in degrees.
+ * Get the GPS target longitude in degrees (negative for west).
  */
 double
-FGBFI::getAPHeadingMag ()
-{
-  return current_autopilot->get_TargetHeading() - getMagVar();
-}
-
-
-/**
- * Set the autopilot target heading in degrees.
- */
-void
-FGBFI::setAPHeadingMag (double heading)
-{
-  current_autopilot->set_TargetHeading( heading + getMagVar() );
-}
-
-
-/**
- * Return true if the autopilot is locked to NAV1.
- */
-bool
-FGBFI::getAPNAV1Lock ()
-{
-  return
-    (current_autopilot->get_HeadingEnabled() &&
-     current_autopilot->get_HeadingMode() == FGAutopilot::FG_HEADING_NAV1);
-}
-
-
-/**
- * Set the autopilot NAV1 lock.
- */
-void
-FGBFI::setAPNAV1Lock (bool lock)
+FGBFI::getGPSTargetLongitude ()
 {
-  if (lock) {
-    current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_NAV1);
-    current_autopilot->set_HeadingEnabled(true);
-  } else if (current_autopilot->get_HeadingMode() ==
-            FGAutopilot::FG_HEADING_NAV1) {
-    current_autopilot->set_HeadingEnabled(false);
-  }
+  return current_autopilot->get_TargetLongitude();
 }
 
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Radio navigation.
+// Weather
 ////////////////////////////////////////////////////////////////////////
 
-double
-FGBFI::getNAV1Freq ()
-{
-  return current_radiostack->get_nav1_freq();
-}
-
-double
-FGBFI::getNAV1AltFreq ()
-{
-  return current_radiostack->get_nav1_alt_freq();
-}
-
-double
-FGBFI::getNAV1Radial ()
-{
-  return current_radiostack->get_nav1_radial();
-}
-
-double
-FGBFI::getNAV1SelRadial ()
-{
-  return current_radiostack->get_nav1_sel_radial();
-}
-
-double
-FGBFI::getNAV1DistDME ()
-{
-  return current_radiostack->get_nav1_dme_dist();
-}
-
-bool 
-FGBFI::getNAV1TO ()
-{
-  if (current_radiostack->get_nav1_inrange()) {
-    double heading = current_radiostack->get_nav1_heading();
-    double radial = current_radiostack->get_nav1_radial();
-    double var = FGBFI::getMagVar();
-    if (current_radiostack->get_nav1_loc()) {
-      double offset = fabs(heading - radial);
-      return (offset<= 8.0 || offset >= 352.0);
-    } else {
-      double offset =
-       fabs(heading - var - radial);
-      return (offset <= 20.0 || offset >= 340.0);
-    }
-  } else {
-    return false;
-  }
-}
-
-bool
-FGBFI::getNAV1FROM ()
-{
-  if (current_radiostack->get_nav1_inrange()) {
-    double heading = current_radiostack->get_nav1_heading();
-    double radial = current_radiostack->get_nav1_radial();
-    double var = FGBFI::getMagVar();
-    if (current_radiostack->get_nav1_loc()) {
-      double offset = fabs(heading - radial);
-      return (offset >= 172.0 && offset<= 188.0);
-    } else {
-      double offset =
-       fabs(heading - var - radial);
-      return (offset >= 160.0 && offset <= 200.0);
-    }
-  } else {
-    return false;
-  }
-}
-
-bool
-FGBFI::getNAV1InRange ()
-{
-  return current_radiostack->get_nav1_inrange();
-}
-
-bool
-FGBFI::getNAV1DMEInRange ()
-{
-  return (current_radiostack->get_nav1_inrange() &&
-         current_radiostack->get_nav1_has_dme());
-}
-
-double
-FGBFI::getNAV2Freq ()
-{
-  return current_radiostack->get_nav2_freq();
-}
-
-double
-FGBFI::getNAV2AltFreq ()
-{
-  return current_radiostack->get_nav2_alt_freq();
-}
-
-double
-FGBFI::getNAV2Radial ()
-{
-  return current_radiostack->get_nav2_radial();
-}
-
-double
-FGBFI::getNAV2SelRadial ()
-{
-  return current_radiostack->get_nav2_sel_radial();
-}
-
-double
-FGBFI::getNAV2DistDME ()
-{
-  return current_radiostack->get_nav2_dme_dist();
-}
-
-bool 
-FGBFI::getNAV2TO ()
-{
-  if (current_radiostack->get_nav2_inrange()) {
-    double heading = current_radiostack->get_nav2_heading();
-    double radial = current_radiostack->get_nav2_radial();
-    double var = FGBFI::getMagVar();
-    if (current_radiostack->get_nav2_loc()) {
-      double offset = fabs(heading - radial);
-      return (offset<= 8.0 || offset >= 352.0);
-    } else {
-      double offset =
-       fabs(heading - var - radial);
-      return (offset <= 20.0 || offset >= 340.0);
-    }
-  } else {
-    return false;
-  }
-}
-
-bool 
-FGBFI::getNAV2FROM ()
-{
-  if (current_radiostack->get_nav2_inrange()) {
-    double heading = current_radiostack->get_nav2_heading();
-    double radial = current_radiostack->get_nav2_radial();
-    double var = FGBFI::getMagVar();
-    if (current_radiostack->get_nav2_loc()) {
-      double offset = fabs(heading - radial);
-      return (offset >= 172.0 && offset<= 188.0);
-    } else {
-      double offset =
-       fabs(heading - var - radial);
-      return (offset >= 160.0 && offset <= 200.0);
-    }
-  } else {
-    return false;
-  }
-}
-
-
-bool
-FGBFI::getNAV2InRange ()
-{
-  return current_radiostack->get_nav2_inrange();
-}
-
-bool
-FGBFI::getNAV2DMEInRange ()
-{
-  return (current_radiostack->get_nav2_inrange() &&
-         current_radiostack->get_nav2_has_dme());
-}
-
-double
-FGBFI::getADFFreq ()
-{
-  return current_radiostack->get_adf_freq();
-}
-
-double
-FGBFI::getADFAltFreq ()
-{
-  return current_radiostack->get_adf_alt_freq();
-}
 
+/**
+ * Get the current visibility (meters).
+ */
 double
-FGBFI::getADFRotation ()
-{
-  return current_radiostack->get_adf_rotation();
-}
-
-void
-FGBFI::setNAV1Freq (double freq)
-{
-  current_radiostack->set_nav1_freq(freq);
-}
-
-void
-FGBFI::setNAV1AltFreq (double freq)
-{
-  current_radiostack->set_nav1_alt_freq(freq);
-}
-
-void
-FGBFI::setNAV1SelRadial (double radial)
-{
-  current_radiostack->set_nav1_sel_radial(radial);
-}
-
-void
-FGBFI::setNAV2Freq (double freq)
-{
-  current_radiostack->set_nav2_freq(freq);
-}
-
-void
-FGBFI::setNAV2AltFreq (double freq)
-{
-  current_radiostack->set_nav2_alt_freq(freq);
-}
-
-void
-FGBFI::setNAV2SelRadial (double radial)
+FGBFI::getVisibility ()
 {
-  current_radiostack->set_nav2_sel_radial(radial);
+#ifndef FG_OLD_WEATHER
+  return WeatherDatabase->getWeatherVisibility();
+#else
+  return current_weather.get_visibility();
+#endif
 }
 
-void
-FGBFI::setADFFreq (double freq)
-{
-  current_radiostack->set_adf_freq(freq);
-}
-
-void
-FGBFI::setADFAltFreq (double freq)
-{
-  current_radiostack->set_adf_alt_freq(freq);
-}
 
+/**
+ * Set the current visibility (meters).
+ */
 void
-FGBFI::setADFRotation (double rot)
+FGBFI::setVisibility (double visibility)
 {
-  current_radiostack->set_adf_rotation(rot);
+#ifndef FG_OLD_WEATHER
+  WeatherDatabase->setWeatherVisibility(visibility);
+#else
+  current_weather.set_visibility(visibility);
+#endif
 }
 
 
-\f
-////////////////////////////////////////////////////////////////////////
-// GPS
-////////////////////////////////////////////////////////////////////////
-
-
 /**
- * Get the autopilot GPS lock (true=on).
+ * Get the current wind north velocity (feet/second).
  */
-bool
-FGBFI::getGPSLock ()
+double
+FGBFI::getWindNorth ()
 {
-  return (current_autopilot->get_HeadingEnabled() &&
-         (current_autopilot->get_HeadingMode() ==
-          FGAutopilot::FG_HEADING_WAYPOINT ));
+  return current_aircraft.fdm_state->get_V_north_airmass();
 }
 
 
 /**
- * Set the autopilot GPS lock (true=on).
+ * Set the current wind north velocity (feet/second).
  */
 void
-FGBFI::setGPSLock (bool lock)
+FGBFI::setWindNorth (double speed)
 {
-  if (lock) {
-    current_autopilot->set_HeadingMode(FGAutopilot::FG_HEADING_WAYPOINT);
-    current_autopilot->set_HeadingEnabled(true);
-  } else if (current_autopilot->get_HeadingMode() ==
-            FGAutopilot::FG_HEADING_WAYPOINT) {
-    current_autopilot->set_HeadingEnabled(false);
-  }
+  current_aircraft.fdm_state->set_Velocities_Local_Airmass(speed,
+                                                          getWindEast(),
+                                                          getWindDown());
 }
 
 
 /**
- * Get the GPS target airport code.
+ * Get the current wind east velocity (feet/second).
  */
-string 
-FGBFI::getTargetAirport ()
+double
+FGBFI::getWindEast ()
 {
-  // FIXME: not thread-safe
-  static string out;
-  out = globals->get_options()->get_airport_id();
-
-  return out;
+  return current_aircraft.fdm_state->get_V_east_airmass();
 }
 
 
 /**
- * Set the GPS target airport code.
+ * Set the current wind east velocity (feet/second).
  */
 void
-FGBFI::setTargetAirport (string airportId)
+FGBFI::setWindEast (double speed)
 {
-  // cout << "setting target airport id = " << airportId << endl;
-  globals->get_options()->set_airport_id(airportId);
+  cout << "Set wind-east to " << speed << endl;
+  current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
+                                                          speed,
+                                                          getWindDown());
 }
 
 
 /**
- * Get the GPS target latitude in degrees (negative for south).
+ * Get the current wind down velocity (feet/second).
  */
 double
-FGBFI::getGPSTargetLatitude ()
+FGBFI::getWindDown ()
 {
-    return current_autopilot->get_TargetLatitude();
+  return current_aircraft.fdm_state->get_V_down_airmass();
 }
 
 
 /**
- * Get the GPS target longitude in degrees (negative for west).
- */
-double
-FGBFI::getGPSTargetLongitude ()
-{
-  return current_autopilot->get_TargetLongitude();
-}
-
-#if 0
-/**
- * Set the GPS target longitude in degrees (negative for west).
+ * Set the current wind down velocity (feet/second).
  */
 void
-FGBFI::setGPSTargetLongitude (double longitude)
+FGBFI::setWindDown (double speed)
 {
-  current_autopilot->set_TargetLongitude( longitude );
+  current_aircraft.fdm_state->set_Velocities_Local_Airmass(getWindNorth(),
+                                                          getWindEast(),
+                                                          speed);
 }
-#endif
 
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Weather
+// View.
 ////////////////////////////////////////////////////////////////////////
 
-
-/**
- * Get the current visible (units??).
- */
 double
-FGBFI::getVisibility ()
+FGBFI::getFOV ()
 {
-#ifndef FG_OLD_WEATHER
-  return WeatherDatabase->getWeatherVisibility();
-#else
-  return current_weather.get_visibility();
-#endif
+  return globals->get_current_view()->get_fov();
 }
 
+void
+FGBFI::setFOV (double fov)
+{
+  globals->get_current_view()->set_fov( fov );
+}
 
-/**
- * Set the current visibility (units??).
- */
 void
-FGBFI::setVisibility (double visibility)
+FGBFI::setViewAxisLong (double axis)
 {
-#ifndef FG_OLD_WEATHER
-  WeatherDatabase->setWeatherVisibility(visibility);
-#else
-  current_weather.set_visibility(visibility);
-#endif
+  axisLong = axis;
 }
 
+void
+FGBFI::setViewAxisLat (double axis)
+{
+  axisLat = axis;
+}
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -1733,7 +1252,7 @@ FGBFI::setVisibility (double visibility)
 double
 FGBFI::getMagVar ()
 {
-  return globals->get_mag()->get_magvar() * RAD_TO_DEG;
+  return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -1743,7 +1262,7 @@ FGBFI::getMagVar ()
 double
 FGBFI::getMagDip ()
 {
-  return globals->get_mag()->get_magdip() * RAD_TO_DEG;
+  return globals->get_mag()->get_magdip() * SGD_RADIANS_TO_DEGREES;
 }