]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/Schedule.cxx
PLIB net removed from FlightGear
[flightgear.git] / src / Traffic / Schedule.cxx
index 517bb3c2117b5e6e1b0000ec91bcc833672b85e7..3b8e7636db1946dca5d873df945a2236272323ff 100644 (file)
@@ -115,8 +115,11 @@ FGAISchedule::FGAISchedule(string model,
        i++)
     flights.push_back(new FGScheduledFlight((*(*i))));*/
   AIManagerRef     = 0;
-  //score    = scre;
+  score    =         0;
   firstRun         = true;
+  runCount         = 0;
+  hits             = 0;
+  initialized      = false;
 }
 
 FGAISchedule::FGAISchedule(const FGAISchedule &other)
@@ -136,13 +139,17 @@ FGAISchedule::FGAISchedule(const FGAISchedule &other)
   radius             = other.radius;
   groundOffset       = other.groundOffset;
   flightType         = other.flightType;
-  //score            = other.score;
+  score              = other.score;
   distanceToUser     = other.distanceToUser;
   currentDestination = other.currentDestination;
   firstRun           = other.firstRun;
+  runCount           = other.runCount;
+  hits               = other.hits;
+  initialized        = other.initialized;
 }
 
 
+
 FGAISchedule::~FGAISchedule()
 {
 /*  for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
@@ -201,15 +208,17 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
   
   if (firstRun) {
      if (fgGetBool("/sim/traffic-manager/instantaneous-action") == true) {
-         deptime = now + rand() % 300; // Wait up to 5 minutes until traffic starts moving to prevent too many aircraft 
+         deptime = now; // + rand() % 300; // Wait up to 5 minutes until traffic starts moving to prevent too many aircraft 
                                    // from cluttering the gate areas.
      }
      firstRun = false;
   }
   
   FGScheduledFlight* flight = flights.front();
-  if (!deptime)
+  if (!deptime) {
     deptime = flight->getDepartureTime();
+    //cerr << "Settiing departure time " << deptime << endl;
+  }
     
   if (AIManagerRef) {
     // Check if this aircraft has been released. 
@@ -287,7 +296,6 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
   if (distanceToUser >= TRAFFICTOAIDISTTOSTART) {
     return true; // out of visual range, for the moment.
   }
-  
   return createAIAircraft(flight, speed, deptime);
 }
 
@@ -354,6 +362,16 @@ void FGAISchedule::scheduleFlights()
     }
     
     currentDestination = flight->getArrivalAirport()->getId();
+    if (!initialized) {
+        string departurePort = flight->getDepartureAirport()->getId();
+       //cerr << "Scheduled " << registration <<  " " << score << " for Flight " 
+       //     << flight-> getCallSign() << " from " << departurePort << " to " << currentDestination << endl;
+        if (fgGetString("/sim/presets/airport-id") == departurePort) {
+            hits++;
+        }
+        //runCount++;
+        initialized = true;
+    }
   
     time_t arr, dep;
     dep = flight->getDepartureTime();
@@ -480,12 +498,26 @@ double FGAISchedule::getSpeed()
   SG_CLAMP_RANGE(speed, 300.0, 500.0);
   return speed;
 }
-/*
+
+void FGAISchedule::setScore   () 
+{ 
+    if (runCount) {
+        score = ((double) hits / (double) runCount);
+    } else {
+        if (homePort == fgGetString("/sim/presets/airport-id")) {
+            score = 0.1;
+        } else {
+            score = 0.0;
+        }
+    }
+    runCount++;
+}
+
 bool compareSchedules(FGAISchedule*a, FGAISchedule*b)
 { 
-  //return (*a) < (*b); 
+  return (*a) < (*b); 
 } 
-*/
+
 
 // void FGAISchedule::setClosestDistanceToUser()
 // {
@@ -494,7 +526,6 @@ bool compareSchedules(FGAISchedule*a, FGAISchedule*b)
 //   double course;
 //   double dist;
 
-//   Point3D temp;
 //   time_t 
 //     totalTimeEnroute, 
 //     elapsedTimeEnroute;