]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bfi.cxx
Removed cloud layers added for testing.
[flightgear.git] / src / Main / bfi.cxx
index ac28102750bf29c4e024e59ab9c1396c6dc3ca61..1137c0359c2bfe4d174d4ebf0b846ae89d4f9785 100644 (file)
@@ -83,7 +83,7 @@ reinit ()
                                // that's going to get clobbered
                                // when we reinit the subsystems.
 
-  FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
+  SG_LOG(SG_GENERAL, SG_INFO, "Starting BFI reinit");
 
                                // TODO: add more AP stuff
   bool apHeadingLock = FGBFI::getAPHeadingLock();
@@ -103,7 +103,9 @@ reinit ()
   fgUpdateMoonPos();
   cur_light_params.Update();
   fgUpdateLocalTime();
+#ifndef FG_OLD_WEATHER
   fgUpdateWeatherDatabase();
+#endif
   current_radiostack->search();
 
                                // Restore all of the old states.
@@ -114,7 +116,7 @@ reinit ()
 
   _needReinit = false;
 
-  FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
+  SG_LOG(SG_GENERAL, SG_INFO, "Ending BFI reinit");
 }
 
 // BEGIN: kludge
@@ -153,8 +155,8 @@ _set_view_from_axes ()
       viewDir = 270;
   }
 
-  globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
-//   globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
+  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
@@ -175,10 +177,12 @@ _set_view_from_axes ()
 void
 FGBFI::init ()
 {
-  FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
+  SG_LOG(SG_GENERAL, SG_INFO, "Starting BFI init");
 
                                // Simulation
   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);
 
@@ -199,12 +203,21 @@ FGBFI::init ()
                                // Autopilot
   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);
@@ -219,7 +232,7 @@ FGBFI::init ()
 
   _needReinit = false;
 
-  FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI init");
+  SG_LOG(SG_GENERAL, SG_INFO, "Ending BFI init");
 }
 
 
@@ -270,6 +283,39 @@ FGBFI::setAircraftDir (string dir)
 }
 
 
+/**
+ * Get the current view offset in degrees.
+ */
+double
+FGBFI::getViewOffset ()
+{
+  return (globals->get_current_view()
+         ->get_view_offset() * SGD_RADIANS_TO_DEGREES);
+}
+
+void
+FGBFI::setViewOffset (double offset)
+{
+  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);
+}
+
+void
+FGBFI::setGoalViewOffset (double offset)
+{
+  globals->get_current_view()
+    ->set_goal_view_offset(offset * SGD_DEGREES_TO_RADIANS);
+}
+
+
+
+
 /**
  * Return the current Zulu time.
  */
@@ -310,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;
   }
@@ -327,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();
@@ -362,7 +408,7 @@ FGBFI::getGMTString ()
 double
 FGBFI::getLatitude ()
 {
-  return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
+  return current_aircraft.fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -372,7 +418,7 @@ FGBFI::getLatitude ()
 void
 FGBFI::setLatitude (double latitude)
 {
-  current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
+  current_aircraft.fdm_state->set_Latitude(latitude * SGD_DEGREES_TO_RADIANS);
 }
 
 
@@ -382,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;
 }
 
 
@@ -392,7 +438,7 @@ FGBFI::getLongitude ()
 void
 FGBFI::setLongitude (double longitude)
 {
-  current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
+  current_aircraft.fdm_state->set_Longitude(longitude * SGD_DEGREES_TO_RADIANS);
 }
 
 
@@ -414,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);
 }
 
 
@@ -440,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;
 }
 
 
@@ -450,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();
 }
 
 
@@ -462,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);
 }
 
 
@@ -472,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;
 }
 
 
@@ -483,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());
 }
 
 
@@ -493,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;
 }
 
 
@@ -504,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());
 }
 
 
@@ -737,280 +783,36 @@ FGBFI::getSpeedDown ()
 
 \f
 ////////////////////////////////////////////////////////////////////////
-// Controls
+// Autopilot
 ////////////////////////////////////////////////////////////////////////
 
-#if 0
-
-/**
- * Get the throttle setting, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getThrottle ()
-{
-                               // FIXME: add engine selector
-  return controls.get_throttle(0);
-}
-
-
-/**
- * Set the throttle, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setThrottle (double throttle)
-{
-                               // FIXME: allow engine selection
-  controls.set_throttle(0, throttle);
-}
-
-
-/**
- * Get the fuel mixture setting, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getMixture ()
-{
-                               // FIXME: add engine selector
-  return controls.get_mixture(0);
-}
-
-
-/**
- * Set the fuel mixture, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setMixture (double mixture)
-{
-                               // FIXME: allow engine selection
-  controls.set_mixture(0, mixture);
-}
-
-
-/**
- * Get the propellor pitch setting, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getPropAdvance ()
-{
-                               // FIXME: add engine selector
-  return controls.get_prop_advance(0);
-}
-
-
-/**
- * Set the propellor pitch, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setPropAdvance (double pitch)
-{
-                               // FIXME: allow engine selection
-  controls.set_prop_advance(0, pitch);
-}
-
-
-/**
- * Get the flaps setting, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getFlaps ()
-{
-  return controls.get_flaps();
-}
-
-
-/**
- * Set the flaps, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setFlaps (double flaps)
-{
-                               // FIXME: clamp?
-  controls.set_flaps(flaps);
-}
-
-
-/**
- * Get the aileron, from -1.0 (left) to 1.0 (right).
- */
-double
-FGBFI::getAileron ()
-{
-  return controls.get_aileron();
-}
-
-
-/**
- * Set the aileron, from -1.0 (left) to 1.0 (right).
- */
-void
-FGBFI::setAileron (double aileron)
-{
-                               // FIXME: clamp?
-  controls.set_aileron(aileron);
-}
-
-
-/**
- * Get the rudder setting, from -1.0 (left) to 1.0 (right).
- */
-double
-FGBFI::getRudder ()
-{
-  return controls.get_rudder();
-}
-
-
-/**
- * Set the rudder, from -1.0 (left) to 1.0 (right).
- */
-void
-FGBFI::setRudder (double rudder)
-{
-                               // FIXME: clamp?
-  controls.set_rudder(rudder);
-}
-
-
-/**
- * Get the elevator setting, from -1.0 (down) to 1.0 (up).
- */
-double
-FGBFI::getElevator ()
-{
-  return controls.get_elevator();
-}
-
-
-/**
- * Set the elevator, from -1.0 (down) to 1.0 (up).
- */
-void
-FGBFI::setElevator (double elevator)
-{
-                               // FIXME: clamp?
-  controls.set_elevator(elevator);
-}
-
-
-/**
- * Get the elevator trim, from -1.0 (down) to 1.0 (up).
- */
-double
-FGBFI::getElevatorTrim ()
-{
-  return controls.get_elevator_trim();
-}
-
-
-/**
- * Set the elevator trim, from -1.0 (down) to 1.0 (up).
- */
-void
-FGBFI::setElevatorTrim (double trim)
-{
-                               // FIXME: clamp?
-  controls.set_elevator_trim(trim);
-}
-
-
-/**
- * Get the highest brake setting, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getBrakes ()
-{
-  double b1 = getCenterBrake();
-  double b2 = getLeftBrake();
-  double b3 = getRightBrake();
-  return (b1 > b2 ? (b1 > b3 ? b1 : b3) : (b2 > b3 ? b2 : b3));
-}
-
-
-/**
- * Set all brakes, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setBrakes (double brake)
-{
-  setCenterBrake(brake);
-  setLeftBrake(brake);
-  setRightBrake(brake);
-}
-
-
-/**
- * Get the center brake, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getCenterBrake ()
-{
-  return controls.get_brake(2);
-}
-
-
-/**
- * Set the center brake, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setCenterBrake (double brake)
-{
-  controls.set_brake(2, brake);
-}
-
-
-/**
- * Get the left brake, from 0.0 (none) to 1.0 (full).
- */
-double
-FGBFI::getLeftBrake ()
-{
-  return controls.get_brake(0);
-}
-
 
 /**
- * Set the left brake, from 0.0 (none) to 1.0 (full).
- */
-void
-FGBFI::setLeftBrake (double brake)
-{
-  controls.set_brake(0, brake);
-}
-
-
-/**
- * Get the right brake, from 0.0 (none) to 1.0 (full).
+ * Get the autopilot altitude lock (true=on).
  */
-double
-FGBFI::getRightBrake ()
+bool
+FGBFI::getAPAltitudeLock ()
 {
-  return controls.get_brake(1);
+    return current_autopilot->get_AltitudeEnabled();
 }
 
 
 /**
- * Set the right brake, from 0.0 (none) to 1.0 (full).
+ * Set the autopilot altitude lock (true=on).
  */
 void
-FGBFI::setRightBrake (double brake)
+FGBFI::setAPAltitudeLock (bool lock)
 {
-  controls.set_brake(1, brake);
+  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
+  current_autopilot->set_AltitudeEnabled(lock);
 }
 
 
-#endif
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Autopilot
-////////////////////////////////////////////////////////////////////////
-
-
 /**
  * Get the autopilot altitude lock (true=on).
  */
 bool
-FGBFI::getAPAltitudeLock ()
+FGBFI::getAPGSLock ()
 {
     return current_autopilot->get_AltitudeEnabled();
 }
@@ -1020,9 +822,9 @@ FGBFI::getAPAltitudeLock ()
  * Set the autopilot altitude lock (true=on).
  */
 void
-FGBFI::setAPAltitudeLock (bool lock)
+FGBFI::setAPGSLock (bool lock)
 {
-  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_LOCK);
+  current_autopilot->set_AltitudeMode(FGAutopilot::FG_ALTITUDE_GS1);
   current_autopilot->set_AltitudeEnabled(lock);
 }
 
@@ -1033,7 +835,7 @@ FGBFI::setAPAltitudeLock (bool lock)
 double
 FGBFI::getAPAltitude ()
 {
-  return current_autopilot->get_TargetAltitude() * METER_TO_FEET;
+  return current_autopilot->get_TargetAltitude() * SG_METER_TO_FEET;
 }
 
 
@@ -1043,7 +845,7 @@ FGBFI::getAPAltitude ()
 void
 FGBFI::setAPAltitude (double altitude)
 {
-    current_autopilot->set_TargetAltitude( altitude * FEET_TO_METER );
+    current_autopilot->set_TargetAltitude( altitude * SG_FEET_TO_METER );
 }
 
 
@@ -1053,7 +855,7 @@ FGBFI::setAPAltitude (double altitude)
 double
 FGBFI::getAPClimb ()
 {
-  return current_autopilot->get_TargetClimbRate() * METER_TO_FEET;
+  return current_autopilot->get_TargetClimbRate() * SG_METER_TO_FEET;
 }
 
 
@@ -1063,7 +865,7 @@ FGBFI::getAPClimb ()
 void
 FGBFI::setAPClimb (double rate)
 {
-    current_autopilot->set_TargetClimbRate( rate * FEET_TO_METER );
+    current_autopilot->set_TargetClimbRate( rate * SG_FEET_TO_METER );
 }
 
 
@@ -1075,7 +877,7 @@ FGBFI::getAPHeadingLock ()
 {
     return
       (current_autopilot->get_HeadingEnabled() &&
-       current_autopilot->get_HeadingMode() == FGAutopilot::FG_DG_HEADING_LOCK);
+       current_autopilot->get_HeadingMode() == DEFAULT_AP_HEADING_LOCK);
 }
 
 
@@ -1086,7 +888,7 @@ void
 FGBFI::setAPHeadingLock (bool lock)
 {
     if (lock) {
-       current_autopilot->set_HeadingMode(FGAutopilot::FG_DG_HEADING_LOCK);
+       current_autopilot->set_HeadingMode(DEFAULT_AP_HEADING_LOCK);
        current_autopilot->set_HeadingEnabled(true);
     } else {
        current_autopilot->set_HeadingEnabled(false);
@@ -1168,6 +970,92 @@ FGBFI::setAPNAV1Lock (bool lock)
   }
 }
 
+/**
+ * Get the autopilot autothrottle lock.
+ */
+bool
+FGBFI::getAPAutoThrottleLock ()
+{
+  return current_autopilot->get_AutoThrottleEnabled();
+}
+
+
+/**
+ * Set the autothrottle lock.
+ */
+void
+FGBFI::setAPAutoThrottleLock (bool lock)
+{
+  current_autopilot->set_AutoThrottleEnabled(lock);
+}
+
+
+// kludge
+double
+FGBFI::getAPRudderControl ()
+{
+    if (getAPHeadingLock())
+        return current_autopilot->get_TargetHeading();
+    else
+        return controls.get_rudder();
+}
+
+// kludge
+void
+FGBFI::setAPRudderControl (double value)
+{
+    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);
+    }
+}
+
+// kludge
+double
+FGBFI::getAPElevatorControl ()
+{
+  if (getAPAltitudeLock())
+      return current_autopilot->get_TargetAltitude();
+  else
+    return controls.get_elevator();
+}
+
+// kludge
+void
+FGBFI::setAPElevatorControl (double value)
+{
+    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);
+    }
+}
+
+// kludge
+double
+FGBFI::getAPThrottleControl ()
+{
+  if (getAPAutoThrottleLock())
+    return 0.0;                        // always resets
+  else
+    return controls.get_throttle(0);
+}
+
+// kludge
+void
+FGBFI::setAPThrottleControl (double value)
+{
+  if (getAPAutoThrottleLock())
+    current_autopilot->AutoThrottleAdjust(value < 0.0 ? -0.01 : 0.01);
+  else
+    controls.set_throttle(0, value);
+}
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -1222,17 +1110,6 @@ FGBFI::getGPSTargetLongitude ()
   return current_autopilot->get_TargetLongitude();
 }
 
-#if 0
-/**
- * Set the GPS target longitude in degrees (negative for west).
- */
-void
-FGBFI::setGPSTargetLongitude (double longitude)
-{
-  current_autopilot->set_TargetLongitude( longitude );
-}
-#endif
-
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -1375,7 +1252,7 @@ FGBFI::setViewAxisLat (double axis)
 double
 FGBFI::getMagVar ()
 {
-  return globals->get_mag()->get_magvar() * RAD_TO_DEG;
+  return globals->get_mag()->get_magvar() * SGD_RADIANS_TO_DEGREES;
 }
 
 
@@ -1385,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;
 }