]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
Fix a Clang warning, checking signed char as if it was unsigned.
[flightgear.git] / src / AIModel / AIAircraft.cxx
index 6abe6af54407f59c92f51519c6a448dc0abcd5ed..180f0bfc8b27809e6f500e81d62d8165b0f89cd6 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 <Viewer/viewer.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Airports/dynamics.hxx>
@@ -119,23 +118,14 @@ 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);
@@ -284,6 +274,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 +375,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
@@ -820,10 +816,10 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr) {
        } 
     if (trafficRef) {
          //cerr << "Tracking callsign : \"" << fgGetString("/ai/track-callsign") << "\"" << endl;
-/*         if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
-              cerr << trafficRef->getCallSign() << " " << tgt_altitude_ft << " " << _getSpeed() << " " 
-                   << _getAltitude() << " "<< _getLatitude() << " " << _getLongitude() << " " << dist_to_go << " " << lead_dist << " " << curr->name << " " << vs << " " << tgt_vs << " " << bearing << " " << minBearing << " " << speedFraction << endl; 
-         }*/
+         //if (trafficRef->getCallSign() == fgGetString("/ai/track-callsign")) {
+              //cerr << trafficRef->getCallSign() << " " << tgt_altitude_ft << " " << _getSpeed() << " " 
+              //     << _getAltitude() << " "<< _getLatitude() << " " << _getLongitude() << " " << dist_to_go << " " << lead_dist << " " << curr->getName() << " " << vs << " " << //tgt_vs << " " << bearing << " " << minBearing << " " << speedFraction << endl; 
+         //}
      }
     if ((dist_to_go < lead_dist) ||
         ((dist_to_go > prev_dist_to_go) && (bearing > (minBearing * 1.1))) ) {
@@ -838,11 +834,12 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr) {
 }
 
 
-bool FGAIAircraft::aiTrafficVisible() {
-  SGGeod userPos(SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"), 
-    fgGetDouble("/position/latitude-deg")));
-  
-  return (SGGeodesy::distanceNm(userPos, pos) <= TRAFFICTOAIDISTTODIE);
+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);
 }
 
 
@@ -887,17 +884,17 @@ bool FGAIAircraft::handleAirportEndPoints(FGAIWaypoint* prev, time_t now) {
     //        fp->shortenToFirst(2, "legend");
     //    }
     //}
-    /*if (prev->contains(string("final"))) {
-        
-         cerr << getCallSign() << " " 
-            << fp->getPreviousWaypoint()->getName() 
-            << ". Alt = " << altitude_ft 
-            << " vs " << vs 
-            << " horizontal speed " << speed 
-            << "Previous crossAT " << fp->getPreviousWaypoint()->getCrossat()
-            << "Airport elevation" << getTrafficRef()->getArrivalAirport()->getElevation() 
-            << "Altitude difference " << (altitude_ft -  fp->getPreviousWaypoint()->getCrossat()) << endl;
-    }*/
+    //if (prev->contains(string("final"))) {
+    //    
+    //     cerr << getCallSign() << " " 
+    //        << fp->getPreviousWaypoint()->getName() 
+    //        << ". Alt = " << altitude_ft 
+    //        << " vs " << vs 
+    //        << " horizontal speed " << speed 
+    //        << "Previous crossAT " << fp->getPreviousWaypoint()->getCrossat()
+    //        << "Airport elevation" << getTrafficRef()->getArrivalAirport()->getElevation() 
+    //        << "Altitude difference " << (altitude_ft -  fp->getPreviousWaypoint()->getCrossat()) << endl;
+    //q}
     // This is the last taxi waypoint, and marks the the end of the flight plan
     // so, the schedule should update and wait for the next departure time.
     if (prev->contains("END")) {
@@ -937,9 +934,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
     }
 }
 
@@ -1056,7 +1053,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)
@@ -1076,9 +1073,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 " 
@@ -1274,9 +1271,9 @@ void FGAIAircraft::updateActualState() {
     updatePosition();
 
     if (onGround())
-        speed = _performance->actualSpeed(this, groundTargetSpeed, dt);
+        speed = _performance->actualSpeed(this, groundTargetSpeed, dt, holdPos);
     else
-        speed = _performance->actualSpeed(this, (tgt_speed *speedFraction), dt);
+        speed = _performance->actualSpeed(this, (tgt_speed *speedFraction), dt, false);
     //assertSpeed(speed);
     updateHeading();
     roll = _performance->actualBankAngle(this, tgt_roll, dt);