]> git.mxchange.org Git - flightgear.git/blobdiff - src/Traffic/Schedule.cxx
PLIB net removed from FlightGear
[flightgear.git] / src / Traffic / Schedule.cxx
index 3b990e377d3364213c27d6269af5ee5e3a2f28a9..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++)
@@ -289,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);
 }
 
@@ -356,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();
@@ -482,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()
 // {
@@ -496,7 +526,6 @@ bool compareSchedules(FGAISchedule*a, FGAISchedule*b)
 //   double course;
 //   double dist;
 
-//   Point3D temp;
 //   time_t 
 //     totalTimeEnroute, 
 //     elapsedTimeEnroute;