]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIAircraft.cxx
MSVC fix
[flightgear.git] / src / AIModel / AIAircraft.cxx
index cf20462f00118cdb4d9c6d07ac285a07b3e158a3..4dc084bcc935ac607a4f8a27f840f5c1e5081762 100644 (file)
@@ -28,6 +28,7 @@
 #include <Scenery/scenery.hxx>
 #include <string>
 #include <math.h>
+#include <time.h>
 
 SG_USING_STD(string);
 
@@ -51,7 +52,8 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
 };
 
 
-FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
+FGAIAircraft::FGAIAircraft(FGAIManager* mgr, FGAISchedule *ref) {
+  trafficRef = ref;
    manager = mgr;   
    _type_str = "aircraft";
    _otype = otAircraft;
@@ -78,20 +80,22 @@ bool FGAIAircraft::init() {
 void FGAIAircraft::bind() {
     FGAIBase::bind();
 
-/*
     props->tie("controls/gear/gear-down",
-               SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown));
-
+               SGRawValueMethods<FGAIAircraft,bool>(*this,
+                                              &FGAIAircraft::_getGearDown));
+#if 0
     props->getNode("controls/lighting/landing-lights", true)
            ->alias("controls/gear/gear-down");
-*/
+#endif
 }
 
 void FGAIAircraft::unbind() {
     FGAIBase::unbind();
 
-//    props->untie("controls/gear/gear-down");
-//    props->getNode("controls/lighting/landing-lights")->unalias();
+    props->untie("controls/gear/gear-down");
+#if 0
+    props->getNode("controls/lighting/landing-lights")->unalias();
+#endif
 }
 
 
@@ -112,7 +116,14 @@ void FGAIAircraft::Run(double dt) {
 
    FGAIAircraft::dt = dt;
 
-   if (fp) ProcessFlightPlan(dt);
+   if (fp) 
+     {
+       ProcessFlightPlan(dt);
+       time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+       if (now < fp->getStartTime())
+        return;
+       //ProcessFlightPlan(dt);
+     }
        
    double turn_radius_ft;
    double turn_circum_ft;
@@ -293,6 +304,8 @@ void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f) {
 }
 
 void FGAIAircraft::ProcessFlightPlan( double dt ) {
+
   FGAIFlightPlan::waypoint* prev = 0; // the one behind you
   FGAIFlightPlan::waypoint* curr = 0; // the one ahead
   FGAIFlightPlan::waypoint* next = 0; // the next plus 1
@@ -346,10 +359,35 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) {
 
     if ( dist_to_go < lead_dist ) {
       if (curr->finished) {  //end of the flight plan, so terminate
-        setDie(true);
-        return;
+         if (trafficRef)
+           {
+             delete fp;
+             //time_t now = time(NULL) + fgGetLong("/sim/time/warp");
+             trafficRef->next();
+
+             FGAIModelEntity entity;
+              entity.m_class = "jet_transport";
+              //entity.path = modelPath.c_str();
+              entity.flightplan = "none";
+              entity.latitude = _getLatitude();
+              entity.longitude = _getLongitude();
+              entity.altitude = trafficRef->getCruiseAlt() * 100; // convert from FL to feet
+              entity.speed = 450;
+             //entity.fp = new FGAIFlightPlan(&entity, courseToDest, i->getDepartureTime(), dep, arr);
+             entity.fp = new FGAIFlightPlan(&entity, 
+                                            999,  // A hack
+                                            trafficRef->getDepartureTime(), 
+                                            trafficRef->getDepartureAirport(), 
+                                            trafficRef->getArrivalAirport());
+             SetFlightPlan(entity.fp);
+           }
+         else 
+           {
+             setDie(true);
+             return;
+           }
       }
-      // we've reached the lead-point for the waypoint ahead 
+       // we've reached the lead-point for the waypoint ahead 
       if (next) tgt_heading = fp->getBearing(curr, next);  
       fp->IncrementWaypoint();
       prev = fp->getPreviousWaypoint();
@@ -385,3 +423,8 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) {
 }
 
 
+bool FGAIAircraft::_getGearDown() const {
+   return ((props->getFloatValue("position/altitude-agl-ft") < 900.0)
+            && (props->getFloatValue("velocities/airspeed-kt")
+                 < performance->land_speed*1.25));
+}