From: daveluff Date: Sat, 20 Mar 2004 03:13:29 +0000 (+0000) Subject: Delay deletion of AI traffic until after it has had time to release the frequency... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=db2ef57049102506238db6c98199af6314da8c9c;p=flightgear.git Delay deletion of AI traffic until after it has had time to release the frequency after its last transmission. This is a bit of a band-aid for more deep-seated problems with the dialog model, but it will solve some problems for now --- diff --git a/src/ATC/AIGAVFRTraffic.cxx b/src/ATC/AIGAVFRTraffic.cxx index 2a5d1e73c..771e6013d 100644 --- a/src/ATC/AIGAVFRTraffic.cxx +++ b/src/ATC/AIGAVFRTraffic.cxx @@ -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); } } diff --git a/src/ATC/AILocalTraffic.cxx b/src/ATC/AILocalTraffic.cxx index 78fb59a1b..2988f2e06 100644 --- a/src/ATC/AILocalTraffic.cxx +++ b/src/ATC/AILocalTraffic.cxx @@ -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."); } } diff --git a/src/ATC/AILocalTraffic.hxx b/src/ATC/AILocalTraffic.hxx index c5562b227..ac7eea0b4 100644 --- a/src/ATC/AILocalTraffic.hxx +++ b/src/ATC/AILocalTraffic.hxx @@ -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. diff --git a/src/ATC/AIMgr.cxx b/src/ATC/AIMgr.cxx index 621bf5ec8..897f19703 100644 --- a/src/ATC/AIMgr.cxx +++ b/src/ATC/AIMgr.cxx @@ -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-")); diff --git a/src/ATC/AIPlane.cxx b/src/ATC/AIPlane.cxx index 1faef8678..32cea572b 100644 --- a/src/ATC/AIPlane.cxx +++ b/src/ATC/AIPlane.cxx @@ -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;