]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/AIGAVFRTraffic.cxx
Emergency fix for AI model loading - non existance of the piper model as in the lates...
[flightgear.git] / src / ATC / AIGAVFRTraffic.cxx
index 8449f236c35f8e01e27fbac8c89855e1737e4d2a..771e6013ddf57d24b3b182a55d30bdf5a5428df7 100644 (file)
@@ -84,7 +84,9 @@ bool FGAIGAVFRTraffic::Init(Point3D pt, string destID, const string& callsign) {
        _pos.setelev(_cruise_alt);
        // initially set waypoint as airport location
        _wp = _destPos;
-       //_hdg = GetHeadingFromTo(_pos, _wp);
+       // Set the initial track
+       track = GetHeadingFromTo(_pos, _wp);
+       // And set the plane to keep following it.
        SetTrack(GetHeadingFromTo(_pos, _wp));
        _roll = 0.0;
        _pitch = 0.0;
@@ -168,9 +170,13 @@ void FGAIGAVFRTraffic::FlyPlane(double dt) {
                                //cout << "_" << flush;
                                GetAirportDetails(airportID);
                                //cout << "L" << flush;
-                               // TODO FIXME TODO - need to check that tower is valid before this else if problem -> BOOM!
-                               freq = (double)tower->get_freq() / 100.0;
-                               tuned_station = tower;
+                               if(_controlled) {
+                                       freq = (double)tower->get_freq() / 100.0;
+                                       tuned_station = tower;
+                               } else {
+                                       freq = 122.8;   // TODO - need to get the correct CTAF/Unicom frequency if no tower
+                                       tuned_station = NULL;
+                               }
                                //cout << "freq = " << freq << endl;
                                GetRwyDetails(airportID);
                                //"@AP Tower @CS @MI miles @CD of the airport for full stop with the ATIS"
@@ -178,8 +184,13 @@ void FGAIGAVFRTraffic::FlyPlane(double dt) {
                                if(rwy.rwyID.size() == 3) {
                                        patternDirection = (rwy.rwyID.substr(2,1) == "R" ? 1 : -1);
                                }
-                               pending_transmission = tower->get_name();
-                               pending_transmission += " Tower ";
+                               if(_controlled) {
+                                       pending_transmission = tower->get_name();
+                                       pending_transmission += " Tower ";
+                               } else {
+                                       pending_transmission = "Traffic ";
+                                       // TODO - find some way of getting uncontrolled airport name
+                               }
                                pending_transmission += plane.callsign;
                                //char buf[10];
                                int dist_miles = (int)dclGetHorizontalSeparation(_pos, _destPos) / 1600;
@@ -373,6 +384,8 @@ void FGAIGAVFRTraffic::RegisterTransmission(int code) {
                _clearedDownwindEntry = true;
                break;
        default:
+               SG_LOG(SG_ATC, SG_WARN, "FGAIGAVFRTraffic::RegisterTransmission(...) called with unknown code " << code);
+               FGAILocalTraffic::RegisterTransmission(code);
                break;
        }
 }
@@ -387,10 +400,17 @@ void FGAIGAVFRTraffic::ProcessCallback(int code) {
        // 12 - report base
        // 13 - report final
        // 14 - Contact Tower for VFR arrival
+       // 99 - Remove self
        if(code < 14) {
                FGAILocalTraffic::ProcessCallback(code);
        } else if(code == 14) {
-               tower->VFRArrivalContact(plane, this, FULL_STOP);
+               if(_controlled) {
+                       tower->VFRArrivalContact(plane, this, FULL_STOP);
+               }
+               // TODO else possibly announce arrival intentions at uncontrolled airport?
+       } else if(code == 99) {
+               // Might handle this different in future - hence separated from the other codes to pass to AILocalTraffic.
+               FGAILocalTraffic::ProcessCallback(code);
        }
 }