]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
Make traffic take-off roll look a little better.
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 69c519f63d9824231fd4d33998b48bec2a980467..fe93d938b29385ca9437ea62f96117ad2c0b1582 100644 (file)
 #  include <config.h>
 #endif
 
-#include <simgear/route/waypoint.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/globals.hxx>
-#include <Main/viewer.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Airports/dynamics.hxx>
@@ -109,7 +107,7 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
 
     FGAIBase::readFromScenario(scFileNode);
 
-    setPerformance(scFileNode->getStringValue("class", "jet_transport"));
+    setPerformance("", scFileNode->getStringValue("class", "jet_transport"));
     setFlightPlan(scFileNode->getStringValue("flightplan"),
                   scFileNode->getBoolValue("repeat", false));
     setCallSign(scFileNode->getStringValue("callsign"));
@@ -119,39 +117,31 @@ void FGAIAircraft::readFromScenario(SGPropertyNode* scFileNode) {
 void FGAIAircraft::bind() {
     FGAIBase::bind();
 
-    props->tie("controls/gear/gear-down",
-               SGRawValueMethods<FGAIAircraft,bool>(*this,
-                                                    &FGAIAircraft::_getGearDown));
-    props->tie("transponder-id",
-               SGRawValueMethods<FGAIAircraft,const char*>(*this,
-                                                    &FGAIAircraft::_getTransponderCode));
+    tie("controls/gear/gear-down",
+        SGRawValueMethods<FGAIAircraft,bool>(*this,
+                &FGAIAircraft::_getGearDown));
+    tie("transponder-id",
+        SGRawValueMethods<FGAIAircraft,const char*>(*this,
+                &FGAIAircraft::_getTransponderCode));
 }
 
-
-void FGAIAircraft::unbind() {
-    FGAIBase::unbind();
-
-    props->untie("controls/gear/gear-down");
-    props->untie("transponder-id");
-}
-
-
 void FGAIAircraft::update(double dt) {
     FGAIBase::update(dt);
     Run(dt);
     Transform();
 }
 
-void FGAIAircraft::setPerformance(const std::string& acclass) {
-     static PerformanceDB perfdb; //TODO make it a global service
-     setPerformance(perfdb.getDataFor(acclass));
-  }
-
+void FGAIAircraft::setPerformance(const std::string& acType, const std::string& acclass)
+{
+  static PerformanceDB perfdb; //TODO make it a global service
+  _performance = perfdb.getDataFor(acType, acclass);
+}
 
+#if 0
  void FGAIAircraft::setPerformance(PerformanceData *ps) {
      _performance = ps;
   }
-
+#endif
 
  void FGAIAircraft::Run(double dt) {
       FGAIAircraft::dt = dt;
@@ -182,8 +172,7 @@ void FGAIAircraft::setPerformance(const std::string& acclass) {
 void FGAIAircraft::checkVisibility() 
 {
   double visibility_meters = fgGetDouble("/environment/visibility-m");
-  FGViewer* vw = globals->get_current_view();
-  invisible = (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters);
+  invisible = (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters);
 }
 
 
@@ -284,6 +273,12 @@ void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
         curr = fp->getCurrentWaypoint();
         next = fp->getNextWaypoint();
     }
+    if (!curr)
+    {
+        // Oops! FIXME
+        return;
+    }
+
     if (! leadPointReached(curr)) {
         controlHeading(curr);
         controlSpeed(curr, next);
@@ -379,7 +374,7 @@ double FGAIAircraft::calcVerticalSpeed(double vert_ft, double dist_m, double spe
 {
     // err is negative when we passed too high
     double vert_m = vert_ft * SG_FEET_TO_METER;
-    double err_m  = err     * SG_FEET_TO_METER;
+    //double err_m  = err     * SG_FEET_TO_METER;
     //double angle = atan2(vert_m, dist_m);
     double speedMs = (speed * SG_NM_TO_METER) / 3600;
     //double vs = cos(angle) * speedMs; // Now in m/s
@@ -520,10 +515,8 @@ void FGAIAircraft::getGroundElev(double dt) {
 
     // Only do the proper hitlist stuff if we are within visible range of the viewer.
     if (!invisible) {
-        double visibility_meters = fgGetDouble("/environment/visibility-m");
-        FGViewer* vw = globals->get_current_view();
-        
-        if (SGGeodesy::distanceM(vw->getPosition(), pos) > visibility_meters) {
+        double visibility_meters = fgGetDouble("/environment/visibility-m");        
+        if (SGGeodesy::distanceM(globals->get_view_position(), pos) > visibility_meters) {
             return;
         }
 
@@ -843,7 +836,7 @@ bool FGAIAircraft::aiTrafficVisible()
     SGVec3d cartPos = SGVec3d::fromGeod(pos);
     const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) *
         (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER);
-    return (distSqr(cartPos, globals->get_aircraft_positon_cart()) < d2);
+    return (distSqr(cartPos, globals->get_aircraft_position_cart()) < d2);
 }
 
 
@@ -938,9 +931,9 @@ void FGAIAircraft::controlHeading(FGAIWaypoint* curr) {
         cerr << "calc_bearing is not a finite number : "
         << "Speed " << speed
         << "pos : " << pos.getLatitudeDeg() << ", " << pos.getLongitudeDeg()
-        << "waypoint " << curr->getLatitude() << ", " << curr->getLongitude() << endl;
-        cerr << "waypoint name " << curr->getName();
-        exit(1);                 // FIXME
+        << ", waypoint: " << curr->getLatitude() << ", " << curr->getLongitude() << endl;
+        cerr << "waypoint name: '" << curr->getName() << "'" << endl;
+        //exit(1);                 // FIXME
     }
 }
 
@@ -1057,7 +1050,7 @@ void FGAIAircraft::updateHeading() {
         // If on ground, calculate heading change directly
         if (onGround()) {
             double headingDiff = fabs(hdg-tgt_heading);
-            double bank_sense = 0.0;
+//            double bank_sense = 0.0;
         /*
         double diff = fabs(hdg - tgt_heading);
         if (diff > 180)
@@ -1077,9 +1070,9 @@ void FGAIAircraft::updateHeading() {
             if (sum > 360.0) 
                 sum -= 360.0;
             if (fabs(sum - tgt_heading) > 0.0001) {
-                bank_sense = -1.0;
+//                bank_sense = -1.0;
             } else {
-                bank_sense = 1.0;
+//                bank_sense = 1.0;
             }
             //if (trafficRef)
             // cerr << trafficRef->getCallSign() << " Heading "