]> git.mxchange.org Git - flightgear.git/commitdiff
Small step forward: Ensure that traffic information is appropriately updated.
authorDurk Talsma <durk@localhost.(none)>
Mon, 11 Apr 2011 20:23:53 +0000 (22:23 +0200)
committerDurk Talsma <durk@localhost.(none)>
Mon, 11 Apr 2011 20:23:53 +0000 (22:23 +0200)
src/AIModel/AIBase.hxx
src/ATC/atc_mgr.cxx
src/ATC/trafficcontrol.cxx
src/ATC/trafficcontrol.hxx

index 2f83623310c89f178ba42ff517f65920fcd7fd5b..fa68074012da14be211c01c6e64caf0b17414cc6 100644 (file)
@@ -304,6 +304,8 @@ public:
         SGPropertyNode *prop_root);
 
     static bool _isNight();
+
+     string & getCallSign();
 };
 
 inline void FGAIBase::setManager(FGAIManager* mgr, SGPropertyNode* p) {
@@ -364,6 +366,10 @@ inline void FGAIBase::setLatitude ( double latitude ) {
 inline void FGAIBase::setCallSign(const string& s) {
     _callsign = s;
 }
+inline string& FGAIBase::getCallSign() {
+    return _callsign;
+}
+
 inline void FGAIBase::setXoffset(double x) {
     _x_offset = x;
 }
index 828431674e46eaf46c83d5078619921090e0f3fe..d8203552a550e17ab3eceb953252f1f1aaac8928 100644 (file)
@@ -77,6 +77,8 @@ void FGATCManager::init() {
     ai_ac.setAltitude ( altitude  );
     ai_ac.setPerformance("jet_transport");
 
+    // NEXT UP: Create a traffic Schedule and fill that with appropriate information. This we can use to flight plannign.
+
     FGAIFlightPlan *fp = new FGAIFlightPlan;
     
     string flightPlanName = airport + "-" + airport + ".xml";
@@ -105,7 +107,7 @@ void FGATCManager::init() {
             string fltType = "ga";
             fp->createTakeOff(&ai_ac, false, apt, 0, fltType);
         } else {
-            controller = apt->getDynamics()->getGroundNetwork();
+            controller = apt->getDynamics()->getStartupController();
             int stationFreq = apt->getDynamics()->getGroundFrequency(2);
             cerr << "Setting radio frequency to : " << stationFreq << endl;
             fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
@@ -151,11 +153,22 @@ void FGATCManager::addController(FGATCController *controller) {
     activeStations.push_back(controller);
 }
 
-
-
 void FGATCManager::update ( double time ) {
     //cerr << "ATC update code is running at time: " << time << endl;
-   currentATCDialog->update(time);
-
-
+    currentATCDialog->update(time);
+    if (controller) {
+        double longitude = fgGetDouble("/position/longitude-deg");
+        double latitude  = fgGetDouble("/position/latitude-deg");
+        double heading   = fgGetDouble("/orientation/heading-deg");
+        double speed     = fgGetDouble("/velocities/groundspeed-kt");
+        double altitude  = fgGetDouble("/position/altitude-ft");
+
+        cerr << "Running FGATCManager::update()" << endl;
+        controller->updateAircraftInformation(ai_ac.getID(),
+                                              latitude,
+                                              longitude,
+                                              heading,
+                                              speed,
+                                              altitude, time);
+    }
 }
index b4bfb7efd94723b01b885a4f4ae86f701eba3f91..aab81538f35830ff01314ebb0474b6dc341cec85 100644 (file)
@@ -465,6 +465,11 @@ string FGATCController::getGateName(FGAIAircraft * ref)
     return ref->atGate();
 }
 
+bool FGATCController::isUserAircraft(FGAIAircraft* ac) 
+{ 
+    return (ac->getCallSign() == fgGetString("/sim/multiplay/callsign")) ? true : false; 
+};
+
 void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId,
                                AtcMsgDir msgDir)
 {
@@ -1015,6 +1020,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
         }
     }
 //    // update position of the current aircraft
+
     if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
         SG_LOG(SG_GENERAL, SG_ALERT,
                "AI error: updating aircraft without traffic record");
@@ -1025,8 +1031,17 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
     setDt(getDt() + dt);
 
     int state = i->getState();
-    time_t startTime =
-        i->getAircraft()->getTrafficRef()->getDepartureTime();
+
+    // The user controlled aircraft should have crased here, because it doesn't have a traffic reference. 
+    // NOTE: if we create a traffic schedule for the user aircraft, we can use this to plan a flight.
+    time_t startTime = 0;
+    if (isUserAircraft(i->getAircraft())) {
+       cerr << i->getAircraft->getCallSign() << " is user aircraft " << endl;
+    } else {
+        time_t startTime =
+            i->getAircraft()->getTrafficRef()->getDepartureTime();
+
+    }
     time_t now = time(NULL) + fgGetLong("/sim/time/warp");
     //cerr << i->getAircraft()->getTrafficRef()->getCallSign() 
     //     << " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
index 20ec9962ebbb89e825b9ac4cff0007e0a32841ae..3780233404897c99d3c1f84c75bd0fed96b0df82 100644 (file)
@@ -34,8 +34,6 @@
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 
-
-
 #include <string>
 #include <vector>
 
@@ -227,6 +225,7 @@ class FGATCController
 {
 private:
      bool initialized;
+
 protected:
   bool available;
   time_t lastTransmission;
@@ -236,6 +235,7 @@ protected:
 
   string formatATCFrequency3_2(int );
   string genTransponderCode(string fltRules);
+  bool isUserAircraft(FGAIAircraft*); 
 
 public:
   typedef enum {
@@ -278,6 +278,9 @@ public:
   void   setDt(double dt) { dt_count = dt;};
   void transmit(FGTrafficRecord *rec, AtcMsgId msgId, AtcMsgDir msgDir);
   string getGateName(FGAIAircraft *aircraft);
+
+private:
+ AtcMsgDir lastTransmissionDirection;
 };
 
 /******************************************************************************