]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/trafficcontrol.cxx
Tolerate the lack of a GUI in some places.
[flightgear.git] / src / ATC / trafficcontrol.cxx
index b919b0830b59d63c6d420b5f9df17ab40339d03b..c71dd034dcd6664ffddfb1b01c21941279890461 100644 (file)
@@ -34,6 +34,7 @@
 #include <simgear/scene/material/EffectGeode.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/material/mat.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
 #include <Scenery/scenery.hxx>
 
 #include "trafficcontrol.hxx"
@@ -51,6 +52,7 @@
 #include <signal.h>
 
 using std::sort;
+using std::string;
 
 /***************************************************************************
  * ActiveRunway
@@ -187,23 +189,18 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
     if (intentions.size()) {
         intVecIterator i = intentions.begin();
         if ((*i) != pos) {
-            SG_LOG(SG_ATC, SG_INFO,
-                   "Skipping repeated intention in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN);
-        } else {
-            intentions.erase(i);
+            SG_LOG(SG_ATC, SG_ALERT,
+                   "Error in FGTrafficRecord::setPositionAndIntentions at " << SG_ORIGIN);
         }
+        intentions.erase(i);
     } else {
         //FGAIFlightPlan::waypoint* const wpt= route->getCurrentWaypoint();
         int size = route->getNrOfWayPoints();
         //cerr << "Setting pos" << pos << " ";
         //cerr << "setting intentions ";
-        for (int i = 0; i < size; i++) {
+        for (int i = 2; i < size; i++) {
             int val = route->getRouteIndex(i);
-            //cerr << val<< " ";
-            if ((val) && (val != pos)) {        // NOTE THAAT THERES A PROBLEM WITH REPEATED INTENSIONS HERE.
-                intentions.push_back(val);
-                //cerr << "[set] ";
-            }
+            intentions.push_back(val);
         }
     }
 }
@@ -278,8 +275,8 @@ int FGTrafficRecord::crosses(FGGroundNetwork * net,
     if (intentions.size()) {
         for (i = intentions.begin(); i != intentions.end(); i++) {
             if ((*i) > 0) {
-                if ((currentTargetNode ==
-                        net->findSegment(*i)->getEnd()->getIndex())) {
+                if (currentTargetNode ==
+                        net->findSegment(*i)->getEnd()->getIndex()) {
                     //cerr << "Current crosses at " << currentTargetNode <<endl;
                     return currentTargetNode;
                 }
@@ -593,8 +590,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
         getDynamics()->getActiveRunway(rwyClass, 1, activeRunway,
                                        heading);
         rec->getAircraft()->GetFlightPlan()->setRunway(activeRunway);
-        fp = rec->getAircraft()->getTrafficRef()->getDepartureAirport()->
-             getDynamics()->getSID(activeRunway, heading);
+        fp = NULL;
         rec->getAircraft()->GetFlightPlan()->setSID(fp);
         if (fp) {
             SID = fp->getName() + " departure";
@@ -730,8 +726,9 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
         // the relevant frequency.
         // Note that distance attenuation is currently not yet implemented
                 
-        if ((onBoardRadioFreqI0 == stationFreq)
-                || (onBoardRadioFreqI1 == stationFreq)) {
+        if ((stationFreq > 0)&&
+            ((onBoardRadioFreqI0 == stationFreq)||
+             (onBoardRadioFreqI1 == stationFreq))) {
             if (rec->allowTransmissions()) {
                
                if( fgGetBool( "/sim/radio/use-itm-attenuation", false ) ) {
@@ -740,11 +737,8 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
                        SGGeod sender_pos;
                        double sender_alt_ft, sender_alt;
                        if(ground_to_air) {
-                                     sender_alt_ft = parent->getElevation();
-                                     sender_alt = sender_alt_ft * SG_FEET_TO_METER;
-                                     sender_pos= SGGeod::fromDegM( parent->getLongitude(),
-                                     parent->getLatitude(), sender_alt );
-                               }
+                  sender_pos = parent->parent()->geod();
+                                }
                                else {
                                      sender_alt_ft = rec->getAltitude();
                                      sender_alt = sender_alt_ft * SG_FEET_TO_METER;
@@ -775,7 +769,7 @@ string FGATCController::formatATCFrequency3_2(int freq)
 
 // TODO: Set transponder codes according to real-world routes.
 // The current version just returns a random string of four octal numbers.
-string FGATCController::genTransponderCode(string fltRules)
+string FGATCController::genTransponderCode(const string& fltRules)
 {
     if (fltRules == "VFR") {
         return string("1200");
@@ -1302,7 +1296,7 @@ static void WorldCoordinate(osg::Matrix& obj_pos, double lat,
                             double lon, double elev, double hdg, double slope)
 {
     SGGeod geod = SGGeod::fromDegM(lon, lat, elev);
-    obj_pos = geod.makeZUpFrame();
+    obj_pos = makeZUpFrame(geod);
     // hdg is not a compass heading, but a counter-clockwise rotation
     // around the Z axis
     obj_pos.preMult(osg::Matrix::rotate(hdg * SGD_DEGREES_TO_RADIANS,
@@ -1332,7 +1326,7 @@ void FGStartupController::render(bool visible)
         group = new osg::Group;
         FGScenery * local_scenery = globals->get_scenery();
         //double elevation_meters = 0.0;
-        double elevation_feet = 0.0;
+        //double elevation_feet = 0.0;
 
 
         //for ( FGTaxiSegmentVectorIterator i = segments.begin(); i != segments.end(); i++) {
@@ -1346,10 +1340,10 @@ void FGStartupController::render(bool visible)
                 if (pos > 0) {
                     FGTaxiSegment *segment  = parent->getGroundNetwork()->findSegment(pos);
                     SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
-                    SGGeod end  (SGGeod::fromDeg(segment->getEnd()->getLongitude(), segment->getEnd()->getLatitude()));
+                    SGGeod end  (segment->getEnd()->geod());
 
                     double length = SGGeodesy::distanceM(start, end);
-                    //heading = SGGeodesy::headingDeg(start->getGeod(), end->getGeod());
+                    //heading = SGGeodesy::headingDeg(start->geod(), end->geod());
 
                     double az2, heading; //, distanceM;
                     SGGeodesy::inverse(start, end, heading, az2, length);
@@ -1374,7 +1368,7 @@ void FGStartupController::render(bool visible)
                         SGGeod center2 = end;
                         center2.setElevationM(SG_MAX_ELEVATION_M);
                         if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
-                            elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
+                            //elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
                             //elevation_meters += 0.5;
                         }
                         else {
@@ -1434,10 +1428,10 @@ void FGStartupController::render(bool visible)
                         double elevationStart = segment->getStart()->getElevationM(parent->getElevation()*SG_FEET_TO_METER);
                         double elevationEnd   = segment->getEnd  ()->getElevationM(parent->getElevation()*SG_FEET_TO_METER);
                         if ((elevationStart == 0) || (elevationStart == parent->getElevation())) {
-                            SGGeod center2 = segment->getStart()->getGeod();
+                            SGGeod center2 = segment->getStart()->geod();
                             center2.setElevationM(SG_MAX_ELEVATION_M);
                             if (local_scenery->get_elevation_m( center2, elevationStart, NULL )) {
-                                elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
+                                //elevation_feet = elevationStart * SG_METER_TO_FEET + 0.5;
                                 //elevation_meters += 0.5;
                             }
                             else {
@@ -1446,10 +1440,10 @@ void FGStartupController::render(bool visible)
                             segment->getStart()->setElevation(elevationStart);
                         }
                         if ((elevationEnd == 0) || (elevationEnd == parent->getElevation())) {
-                            SGGeod center2 = segment->getEnd()->getGeod();
+                            SGGeod center2 = segment->getEnd()->geod();
                             center2.setElevationM(SG_MAX_ELEVATION_M);
                             if (local_scenery->get_elevation_m( center2, elevationEnd, NULL )) {
-                                elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
+                                //elevation_feet = elevationEnd * SG_METER_TO_FEET + 0.5;
                                 //elevation_meters += 0.5;
                             }
                             else {
@@ -1465,8 +1459,9 @@ void FGStartupController::render(bool visible)
 
                         //cerr << "2. Using mean elevation : " << elevationMean << " and " << slope << endl;
 
-
-                        WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope );
+                        SGGeod segCenter(segment->getCenter());
+                        WorldCoordinate( obj_pos, segCenter.getLatitudeDeg(),
+                                        segCenter.getLongitudeDeg(), elevationMean + 0.5 + dx, -(segment->getHeading()), slope );
 
                         //WorldCoordinate( obj_pos, segment->getLatitude(), segment->getLongitude(), parent->getElevation()+8+dx, -(segment->getHeading()) );
 
@@ -1694,7 +1689,7 @@ FGATCInstruction FGApproachController::getInstruction(int id)
 }
 
 
-ActiveRunway *FGApproachController::getRunway(string name)
+ActiveRunway *FGApproachController::getRunway(const string& name)
 {
     ActiveRunwayVecIterator rwy = activeRunways.begin();
     if (activeRunways.size()) {