]> git.mxchange.org Git - flightgear.git/commitdiff
Delay deletion of AI traffic until after it has had time to release the frequency...
authordaveluff <daveluff>
Sat, 20 Mar 2004 03:13:29 +0000 (03:13 +0000)
committerdaveluff <daveluff>
Sat, 20 Mar 2004 03:13:29 +0000 (03:13 +0000)
src/ATC/AIGAVFRTraffic.cxx
src/ATC/AILocalTraffic.cxx
src/ATC/AILocalTraffic.hxx
src/ATC/AIMgr.cxx
src/ATC/AIPlane.cxx

index 2a5d1e73c028b31b26fd6d4d22a7717441b2d45e..771e6013ddf57d24b3b182a55d30bdf5a5428df7 100644 (file)
@@ -384,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;
        }
 }
@@ -398,6 +400,7 @@ 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) {
@@ -405,6 +408,9 @@ void FGAIGAVFRTraffic::ProcessCallback(int code) {
                        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);
        }
 }
 
index 78fb59a1b34c5cc28f2a836a24fbd15f1c9a1192..2988f2e06b098aca2626fd0f6a84dc100eaeb52d 100644 (file)
@@ -107,6 +107,7 @@ FGAILocalTraffic::FGAILocalTraffic() {
        contactTower = false;
        contactGround = false;
        _taxiToGA = false;
+       _removeSelf = false;
        
        descending = false;
        targetDescentRate = 0.0;
@@ -521,14 +522,20 @@ void FGAILocalTraffic::Update(double dt) {
                string trns = "GA Parking, Thank you and Good Day";
                //double f = globals->get_ATC_mgr()->GetFrequency(airportID, GROUND) / 100.0;   
                pending_transmission = trns;
-               ConditionalTransmit(5.0);
+               ConditionalTransmit(5.0, 99);
+               _taxiToGA = false;
                if(_controlled) {
                        tower->DeregisterAIPlane(plane.callsign);
                }
-               _taxiToGA = false;
-               // HACK - check if we are at a simple airport or not first
-               globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
-       }               
+               // NOTE - we can't delete this instance yet since then the frequency won't get release when the message display finishes.
+       }
+
+       if((_removeSelf) && (responseCounter >= 8.0)) {
+               _removeSelf = false;
+               // MEGA HACK - check if we are at a simple airport or not first instead of simply hardwiring KEMT as the only non-simple airport.
+               // TODO FIXME TODO FIXME !!!!!!!
+               if(airportID != "KEMT") globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
+       }
        
        if((changeFreq) && (responseCounter > 8.0)) {
                switch(changeFreqType) {
@@ -565,9 +572,6 @@ void FGAILocalTraffic::Update(double dt) {
                        tower->DeregisterAIPlane(plane.callsign);
                        tuned_station = ground;
                        freq = (double)ground->get_freq() / 100.0;
-                       // HACK - check if we are at a simple airport or not first
-                       // TODO FIXME TODO FIXME !!!!!!!
-                       if(airportID != "KEMT") globals->get_AI_mgr()->ScheduleRemoval(plane.callsign);
                        break;
                // And to avoid compiler warnings...
                case APPROACH:  break;
@@ -1303,6 +1307,10 @@ void FGAILocalTraffic::ProcessCallback(int code) {
                tower->ReportDownwind(plane.callsign);
        } else if(code == 13) {
                tower->ReportFinal(plane.callsign);
+       } else if(code == 99) { // Flag this instance for deletion
+               responseCounter = 0;
+               _removeSelf = true;
+               SG_LOG(SG_ATC, SG_INFO, "AI local traffic " << plane.callsign << " delete instance callback called.");
        }
 }
 
index c5562b227af5b0fcca637aa27bcd457dbd606416..ac7eea0b4598466a9eb459c38e5e200c1b5c5690 100644 (file)
@@ -200,6 +200,7 @@ private:
        bool contactGround;     // we have been told to contact ground
        bool changeFreq;        // true when we need to change frequency
        bool _taxiToGA;         // Temporary mega-hack indicating we are to taxi to the GA parking and disconnect from tower control.
+       bool _removeSelf;       // Indicates that we wish to remove this instance.  The use of a variable is a hack to allow time for messages to purge before removal, due to the fagility of the current dialog system.
        atc_type changeFreqType;        // the service we need to change to
        bool freeTaxi;  // False if the airport has a facilities file with a logical taxi network defined, true if we need to calculate our own taxiing points.
        
index 621bf5ec83b19f85b6735938cd85d4b65a6e2e72..897f197030227ac12a9cbca932127d9efe424734 100644 (file)
@@ -254,7 +254,7 @@ void FGAIMgr::update(double dt) {
                                bool gen = false;
                                //cout << "Size of list is " << (*it).second.size() << " at " << s << '\n';
                                if((*it).second.size()) {
-                                       FGAIEntity* e = *((*it).second.rbegin());
+                                       FGAIEntity* e = *((*it).second.rbegin());       // Get the last airplane currently scheduled to arrive at this airport.
                                        cd = dclGetHorizontalSeparation(e->GetPos(), dclGetAirportPos(s));
                                        if(cd < (d < 5000 ? 10000 : d + 5000)) {
                                                gen = true;
@@ -266,7 +266,8 @@ void FGAIMgr::update(double dt) {
                                if(gen) {
                                        //cout << "Generating extra traffic at airport " << s << ", at least " << cd << " meters out\n";
                                        //GenerateSimpleAirportTraffic(s, cd);
-                                       GenerateSimpleAirportTraffic(s, cd + 2000.0);   // The random seems a bit wierd - traffic could get far too bunched without the +2000.
+                                       GenerateSimpleAirportTraffic(s, cd + 3000.0);   // The random seems a bit wierd - traffic could get far too bunched without the +3000.
+                                       // TODO - make the anti-random constant variable depending on the ai-traffic level.
                                }
                        }
                        ++it;
@@ -473,6 +474,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(string ident, double min_dist) {
                        double dir = int(sg_random() * 36);
                        if(dir == 36) dir--;
                        dir *= 10;
+                       
                        if(sg_random() < 0.3) cessna = false;
                        else cessna = true;
                        string s = GenerateShortForm(GenerateUniqueCallsign(), (cessna ? "Cessna-" : "Piper-"));
index 1faef86787e4a2d76c099aeacfa0b9e349a5b026..32cea572b0138617807d0962ea3aec1468ddc4a7 100644 (file)
@@ -70,6 +70,10 @@ void FGAIPlane::Update(double dt) {
                                                _timeout = 0.0;
                                                _pending = false;
                                                // timed out - don't render.
+                                               if(_callback_code == 99) {
+                                                       // MEGA-HACK - 99 is the remove self callback - currently this *does* need to be run even if the transmission isn't made.
+                                                       ProcessCallback(_callback_code);
+                                               }
                                        }
                                }
                        }
@@ -107,7 +111,6 @@ void FGAIPlane::Update(double dt) {
                        }
                }
                // Run the callback regardless of whether on same freq as user or not.
-               //cout << "_callback_code = " << _callback_code << '\n';
                if(_callback_code) {
                        ProcessCallback(_callback_code);
                }
@@ -119,6 +122,7 @@ void FGAIPlane::Update(double dt) {
                        _transmitting = false;
                        // For now we'll let ATC decide whether to respond
                        //if(tuned_station) tuned_station->SetResponseReqd(plane.callsign);
+                       //if(tuned_station->get_ident() == "KRHV") cout << "Notifying transmission finished" << endl;
                        if(tuned_station) tuned_station->NotifyTransmissionFinished(plane.callsign);
                }
                _counter += dt;