]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/tower.cxx
Fix two bugs in the new autopilot code
[flightgear.git] / src / ATCDCL / tower.cxx
index e8d0b0db46a319bbb4f3951c664aa6310d7e76fb..d44e33018b857cad21a50a9060aa18b8d5929b1c 100644 (file)
@@ -55,6 +55,8 @@ using std::cout;
 
 TowerPlaneRec::TowerPlaneRec() :
        planePtr(NULL),
+       eta(0),
+       dist_out(0),
        clearedToLand(false),
        clearedToLineUp(false),
        clearedToTakeOff(false),
@@ -71,13 +73,13 @@ TowerPlaneRec::TowerPlaneRec() :
        instructedToGoAround(false),
        onRwy(false),
        nextOnRwy(false),
+       gearWasUp(false),
+       gearUpReported(false),
        vfrArrivalReported(false),
        vfrArrivalAcknowledged(false),
        opType(TTT_UNKNOWN),
        leg(LEG_UNKNOWN),
        landingType(AIP_LT_UNKNOWN),
-       gearWasUp(false),
-       gearUpReported(false),
        isUser(false)
 {
        plane.callsign = "UNKNOWN";
@@ -85,6 +87,8 @@ TowerPlaneRec::TowerPlaneRec() :
 
 TowerPlaneRec::TowerPlaneRec(const PlaneRec& p) :
        planePtr(NULL),
+       eta(0),
+       dist_out(0),
        clearedToLand(false),
        clearedToLineUp(false),
        clearedToTakeOff(false),
@@ -101,13 +105,13 @@ TowerPlaneRec::TowerPlaneRec(const PlaneRec& p) :
        instructedToGoAround(false),
        onRwy(false),
        nextOnRwy(false),
+       gearWasUp(false),
+       gearUpReported(false),
        vfrArrivalReported(false),
        vfrArrivalAcknowledged(false),
        opType(TTT_UNKNOWN),
        leg(LEG_UNKNOWN),
        landingType(AIP_LT_UNKNOWN),
-       gearWasUp(false),
-       gearUpReported(false),
        isUser(false)
 {
        plane = p;
@@ -115,6 +119,8 @@ TowerPlaneRec::TowerPlaneRec(const PlaneRec& p) :
 
 TowerPlaneRec::TowerPlaneRec(const SGGeod& pt) :
        planePtr(NULL),
+       eta(0),
+       dist_out(0),
        clearedToLand(false),
        clearedToLineUp(false),
        clearedToTakeOff(false),
@@ -131,13 +137,13 @@ TowerPlaneRec::TowerPlaneRec(const SGGeod& pt) :
        instructedToGoAround(false),
        onRwy(false),
        nextOnRwy(false),
+       gearWasUp(false),
+       gearUpReported(false),
        vfrArrivalReported(false),
        vfrArrivalAcknowledged(false),
        opType(TTT_UNKNOWN),
        leg(LEG_UNKNOWN),
        landingType(AIP_LT_UNKNOWN),
-       gearWasUp(false),
-       gearUpReported(false),
        isUser(false)
 {
        plane.callsign = "UNKNOWN";
@@ -146,6 +152,8 @@ TowerPlaneRec::TowerPlaneRec(const SGGeod& pt) :
 
 TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const SGGeod& pt) :
        planePtr(NULL),
+       eta(0),
+       dist_out(0),
        clearedToLand(false),
        clearedToLineUp(false),
        clearedToTakeOff(false),
@@ -162,13 +170,13 @@ TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const SGGeod& pt) :
        instructedToGoAround(false),
        onRwy(false),
        nextOnRwy(false),
+       gearWasUp(false),
+       gearUpReported(false),
        vfrArrivalReported(false),
        vfrArrivalAcknowledged(false),
        opType(TTT_UNKNOWN),
        leg(LEG_UNKNOWN),
        landingType(AIP_LT_UNKNOWN),
-       gearWasUp(false),
-       gearUpReported(false),
        isUser(false)
 {
        plane = p;
@@ -1409,8 +1417,9 @@ void FGTower::CheckDepartureList(double dt) {
                //cout << "Dep list, checking " << t->plane.callsign;
                
                double distout; // meters
-               if(t->isUser) distout = dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
-               else distout = dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), t->planePtr->getPos());
+               if(t->isUser) distout = dclGetHorizontalSeparation(_geod, 
+      SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
+               else distout = dclGetHorizontalSeparation(_geod, t->planePtr->getPos());
                //cout << " distout = " << distout << '\n';
                if(t->isUser && !(t->clearedToTakeOff)) {       // HACK - we use clearedToTakeOff to check if ATC already contacted with plane (and cleared take-off) or not
                        if(!OnAnyRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
@@ -1496,7 +1505,11 @@ void FGTower::DoRwyDetails() {
        // Based on the airport-id and wind get the active runway
        
   const FGAirport* apt = fgFindAirportID(ident);
-  assert(apt);
+  if (!apt) {
+    SG_LOG(SG_ATC, SG_WARN, "FGTower::DoRwyDetails: unknown ICAO:" << ident);
+    return;
+  }
+  
        FGRunway* runway = apt->getActiveRunwayForUsage();
 
   activeRwy = runway->ident();
@@ -1510,8 +1523,8 @@ void FGTower::DoRwyDetails() {
   }
     // move to the +l end/center of the runway
   //cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
-  double tshlon, tshlat, tshr;
-  double tolon, tolat, tor;
+  double tshlon = 0.0, tshlat = 0.0, tshr = 0.0;
+  double tolon = 0.0, tolat = 0.0, tor = 0.0;
   rwy.length = runway->lengthM();
   geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), other_way, 
                       rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
@@ -1563,7 +1576,7 @@ bool FGTower::OnActiveRunway(const SGGeod& pt) {
 // Only call this at startup - reading the runways database is expensive and needs to be fixed!
 bool FGTower::OnAnyRunway(const SGGeod& pt, bool onGround) {
        ATCData ad;
-       double dist = current_commlist->FindClosest(lon, lat, elev, ad, TOWER, 7.0);
+       double dist = current_commlist->FindClosest(_geod, ad, TOWER, 7.0);
        if(dist < 0.0) {
                return(false);
        }
@@ -2124,6 +2137,7 @@ void FGTower::VFRArrivalContact(const string& ID, const LandingType& opt) {
        
        t->plane.type = GA_SINGLE;      // FIXME - Another assumption!
        t->plane.callsign = usercall;
+       CalcETA(t);
        
        t->vfrArrivalReported = true;
        responseReqd = true;
@@ -2540,7 +2554,7 @@ string FGTower::GenText(const string& m, int c) {
                                else if ( strcmp ( tag, "@MI" ) == 0 ) {
                                        char buf[10];
                                        //sprintf( buf, "%3.1f", tpars.miles );
-                                       int dist_miles = (int)dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
+                                       int dist_miles = (int)dclGetHorizontalSeparation(_geod, SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
                                        sprintf(buf, "%i", dist_miles);
                                        strcat( &dum[0], &buf[0] );
                                }
@@ -2560,7 +2574,7 @@ string FGTower::GenText(const string& m, int c) {
                                        }
                                }
                                else if(strcmp(tag, "@CD") == 0) {      // @CD = compass direction
-                                       double h = GetHeadingFromTo(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
+                                       double h = GetHeadingFromTo(_geod, SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
                                        while(h < 0.0) h += 360.0;
                                        while(h > 360.0) h -= 360.0;
                                        if(h < 22.5 || h > 337.5) {
@@ -2625,9 +2639,13 @@ string FGTower::GetWeather() {
 }
 
 string FGTower::GetATISID() {
-       int hours = fgGetInt("/sim/time/utc/hour");
-       int phonetic_id = current_commlist->GetCallSign(ident, hours, 0);
-       return GetPhoneticIdent(phonetic_id);
+        double tstamp = atof(fgGetString("sim/time/elapsed-sec"));
+        const int minute(60);                   // in SI units
+        int interval = ATIS ? 60*minute : 2*minute;    // AWOS updated frequently
+        int sequence = current_commlist->GetAtisSequence(ident, 
+                              tstamp, interval);
+
+       return GetPhoneticLetter(sequence);  // the sequence letter
 }
 
 ostream& operator << (ostream& os, tower_traffic_type ttt) {