From 0e59cf4a08a10745323d2042674418058246dbba Mon Sep 17 00:00:00 2001
From: durk <durk>
Date: Thu, 8 May 2008 06:11:43 +0000
Subject: [PATCH]  - Add some DEBUG level log messages to help users in getting
 traffic files    to work.  - Add the possibility to load only proportion of
 traffic in order to    reduce some of the workload, in case of a slower
 computer.

---
 src/Traffic/Schedule.cxx   | 13 +++++++++----
 src/Traffic/TrafficMgr.cxx |  7 +++++--
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx
index ac2a305c4..557e44963 100644
--- a/src/Traffic/Schedule.cxx
+++ b/src/Traffic/Schedule.cxx
@@ -231,7 +231,7 @@ bool FGAISchedule::update(time_t now)
   if (!deptime)
     deptime = (*flights.begin())->getDepartureTime();
   FGScheduledFlightVecIterator i = flights.begin();
-  SG_LOG (SG_GENERAL, SG_DEBUG,"Processing registration " << registration << " with callsign " << (*i)->getCallSign());
+  SG_LOG (SG_GENERAL, SG_DEBUG,"Traffic Manager: Processing registration " << registration << " with callsign " << (*i)->getCallSign());
   if (AIManagerRef)
     {
       // Check if this aircraft has been released. 
@@ -250,6 +250,7 @@ bool FGAISchedule::update(time_t now)
       // push it forward in time to the next scheduled departure. 
       if (((*i)->getDepartureTime() < now) && ((*i)->getArrivalTime() < now))
 	{
+          SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager:      Flight is in the Past");
 	  (*i)->update();
 	  return true;
 	}
@@ -263,6 +264,7 @@ bool FGAISchedule::update(time_t now)
       // Part of this flight is in the future.
       if ((*i)->getArrivalTime() > now)
 	{
+          
 	  dep = (*i)->getDepartureAirport();
 	  arr = (*i)->getArrivalAirport  ();
 	  if (!(dep && arr))
@@ -288,6 +290,7 @@ bool FGAISchedule::update(time_t now)
 	      //cerr << "Time diff: " << now-i->getDepartureTime() << endl;
 	      elapsedTimeEnroute   = now - (*i)->getDepartureTime();
 	      remainingTimeEnroute = (*i)->getArrivalTime()   - now;  
+              SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager:      Flight is in progress.");
 	    }
 	  else
 	    {
@@ -295,6 +298,7 @@ bool FGAISchedule::update(time_t now)
 	      lon = dep->getLongitude();
 	      elapsedTimeEnroute = 0;
 	      remainingTimeEnroute = totalTimeEnroute;
+              SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic Manager:      Flight is pending.");
 	    }
 	  	  
 	  angle *= ( (double) elapsedTimeEnroute/ (double) totalTimeEnroute);
@@ -350,13 +354,14 @@ bool FGAISchedule::update(time_t now)
 	  // then 500nm, create this flight. At jet speeds 500 nm is roughly
 	  // one hour flight time, so that would be a good approximate point
 	  // to start a more detailed simulation of this aircraft.
-	  //cerr << registration << " is currently enroute from " 
-	  //   << dep->_id << " to " << arr->_id << "distance : " 
-          //   << distanceToUser*SG_METER_TO_NM << endl;
+	  SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic manager: " << registration << " is scheduled for a flight from " 
+	     << dep->getId() << " to " << arr->getId() << ". Current distance to user: " 
+             << distanceToUser*SG_METER_TO_NM);
 	  if ((distanceToUser*SG_METER_TO_NM) < TRAFFICTOAIDIST)
 	    {
 	      string flightPlanName = dep->getId() + string("-") + arr->getId() + 
 		string(".xml");
+              SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic manager: Creating AIModel");
 	      //int alt;
 	      //if  ((i->getDepartureTime() < now))
 	      //{
diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx
index 82a97f2c3..70ce07800 100644
--- a/src/Traffic/TrafficMgr.cxx
+++ b/src/Traffic/TrafficMgr.cxx
@@ -307,8 +307,10 @@ void  FGTrafficManager::endElement (const char * name) {
     }
   else if (element == string("aircraft"))
     {
-      //cerr << "Pushing back aircraft " << registration << endl;
-      scheduledAircraft.push_back(new FGAISchedule(mdl, 
+      int proportion = (int) (fgGetDouble("/sim/traffic-manager/proportion") * 100);
+      int randval = rand() & 100;
+      if (randval < proportion) {
+          scheduledAircraft.push_back(new FGAISchedule(mdl, 
 					       livery, 
 					       registration, 
 					       heavy,
@@ -323,6 +325,7 @@ void  FGTrafficManager::endElement (const char * name) {
      //  while(flights.begin() != flights.end()) {
 // 	flights.pop_back();
 //       }
+      }
       for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
     {
       delete (*flt);