]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/ATCmgr.cxx
CMake update for new KLN89 file.
[flightgear.git] / src / ATCDCL / ATCmgr.cxx
index 9e5085adbdb8bb2d4f9bd6741abafb54026a22fa..fe03750154a908da65201254280750c380735912 100644 (file)
@@ -59,7 +59,14 @@ AirportATC::AirportATC() :
 FGATCMgr::FGATCMgr() :
     initDone(false),
     atc_list(new atc_list_type),
-    last_in_range(false)
+#ifdef ENABLE_AUDIO_SUPPORT
+    voiceOK(false),
+    voice(true),
+#else
+    voice(false),
+#endif
+    last_in_range(false),
+    v1(0)
 {
 }
 
@@ -89,30 +96,6 @@ void FGATCMgr::init() {
         // Is this still true after the reorganization of the event managar??
         // -EMH-
     
-#ifdef ENABLE_AUDIO_SUPPORT 
-    // Load all available voices.
-    // For now we'll do one hardwired one
-    
-    v1 = new FGATCVoice;
-    try {
-        voiceOK = v1->LoadVoice("default");
-        voice = true;
-    } catch ( sg_io_exception & e) {
-        voiceOK  = false;
-        SG_LOG(SG_ATC, SG_ALERT, "Unable to load default voice : " << e.getFormattedMessage().c_str());
-        voice = false;
-        delete v1;
-        v1 = 0;
-    }
-    
-    /* I've loaded the voice even if /sim/sound/pause is true
-    *  since I know no way of forcing load of the voice if the user
-    *  subsequently switches /sim/sound/audible to true.
-        *  (which is the right thing to do -- CLO) :-) */
-#else
-    voice = false;
-#endif
-
     // Initialise the ATC Dialogs
     //cout << "Initing Transmissions..." << endl;
     SG_LOG(SG_ATC, SG_INFO, "  ATC Transmissions");
@@ -195,45 +178,6 @@ unsigned short int FGATCMgr::GetFrequency(const string& ident, const atc_type& t
     return(ok ? test.freq : 0);
 }   
 
-
-// Register the fact that the AI system wants to activate an airport
-// Might need more sophistication in this in the future - eg registration by aircraft call-sign.
-bool FGATCMgr::AIRegisterAirport(const string& ident) {
-    SG_LOG(SG_ATC, SG_BULK, "AI registered airport " << ident << " with the ATC system");
-    //cout << "AI registered airport " << ident << " with the ATC system" << '\n';
-    if(airport_atc_map.find(ident) != airport_atc_map.end()) {
-        airport_atc_map[ident]->set_by_AI = true;
-        airport_atc_map[ident]->numAI++;
-        return(true);
-    } else {
-        const FGAirport *ap = fgFindAirportID(ident);
-        if (ap) {
-            //cout << "ident = " << ident << '\n';
-            AirportATC *a = new AirportATC;
-            // I'm not entirely sure that this AirportATC structure business is actually needed - it just duplicates what we can find out anyway!
-            a->geod = ap->geod();
-            a->atis_freq = GetFrequency(ident, ATIS)
-                    || GetFrequency(ident, AWOS);
-            //cout << "ATIS freq = " << a->atis_freq << '\n';
-            a->atis_active = false;
-            a->tower_freq = GetFrequency(ident, TOWER);
-            //cout << "Tower freq = " << a->tower_freq << '\n';
-            a->tower_active = false;
-            a->ground_freq = GetFrequency(ident, GROUND);
-            //cout << "Ground freq = " << a->ground_freq << '\n';
-            a->ground_active = false;
-            // TODO - some airports will have a tower/ground frequency but be inactive overnight.
-            a->set_by_AI = true;
-            a->numAI = 1;
-            airport_atc_map[ident] = a;
-            return(true);
-        } else {
-            SG_LOG(SG_ATC, SG_ALERT, "ERROR - can't find airport " << ident << " in AIRegisterAirport(...)");
-        }
-    }
-    return(false);
-}
-
 // Register the fact that the comm radio is tuned to an airport
 // Channel is zero based
 bool FGATCMgr::CommRegisterAirport(const string& ident, int chan, const atc_type& tp) {
@@ -290,8 +234,7 @@ typedef map<string,int> MSI;
 
 void FGATCMgr::ZapOtherService(const string ncunit, const string svc_name){
   for (atc_list_iterator svc = atc_list->begin(); svc != atc_list->end(); svc++) {
-    //cout << "Zapping " << navcomm 
-    //  << "[" << unit << "]"  << "  otherthan: " << svc_name << endl;
+   
     if (svc->first != svc_name) {
       MSI &actv = svc->second->active_on;
       // OK, we have found some OTHER service;
@@ -303,7 +246,9 @@ void FGATCMgr::ZapOtherService(const string ncunit, const string svc_name){
         //cout << "Eradicating service: '" << svc->first << "'" << endl;
     svc->second->SetNoDisplay();
     svc->second->Update(0);     // one last update
-    delete svc->second;
+    SG_LOG(SG_GENERAL, SG_INFO, "would have erased ATC service:" << svc->second->get_name()<< "/" 
+      << svc->second->get_ident());
+   // delete svc->second;
     atc_list->erase(svc);
 // ALL pointers into the ATC list are now invalid,
 // so let's reset them:
@@ -421,6 +366,31 @@ FGATCVoice* FGATCMgr::GetVoicePointer(const atc_type& type) {
     if(voice) {
         switch(type) {
         case ATIS: case AWOS:
+#ifdef ENABLE_AUDIO_SUPPORT
+            // Delayed loading fo all available voices, needed because the
+            // soundmanager might not be initialized (at all) at this point.
+            // For now we'll do one hardwired one
+
+            /* I've loaded the voice even if /sim/sound/pause is true
+             *  since I know no way of forcing load of the voice if the user
+             *  subsequently switches /sim/sound/audible to true.
+             *  (which is the right thing to do -- CLO) :-)
+             */
+            if (!voiceOK && fgGetBool("/sim/sound/working")) {
+                v1 = new FGATCVoice;
+                try {
+                    voiceOK = v1->LoadVoice("default");
+                    voice = voiceOK;
+                } catch ( sg_io_exception & e) {
+                    voiceOK  = false;
+                    SG_LOG(SG_ATC, SG_ALERT, "Unable to load default voice : "
+                                            << e.getFormattedMessage().c_str());
+                    voice = false;
+                    delete v1;
+                    v1 = 0;
+                }
+            }
+#endif
             if(voiceOK) {
                 return(v1);
             }