]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCmgr.cxx
Fix the nmea and garmin output to a) fake a GSA sentence, b) fix a y2k bug
[flightgear.git] / src / ATC / ATCmgr.cxx
index fca3054171ae50210976327cad984505b42cde0f..cd1686d9d50f2617fa6a62c7eecc64514fa84119 100644 (file)
@@ -18,8 +18,6 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-//#include <Time/event.hxx>
-
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/debug/logstream.hxx>
 #include <Airports/simple.hxx>
@@ -36,6 +34,7 @@ static void fgATCSearch( void ) {
        globals->get_ATC_mgr()->Search();
 }
 */ //This wouldn't compile - including Time/event.hxx breaks it :-(
+   // Is this still true?? -EMH-
 
 AirportATC::AirportATC() :
     lon(0.0),
@@ -50,8 +49,10 @@ AirportATC::AirportATC() :
     set_by_AI(false),
        numAI(0)
 {
-    set_by_comm[0] = false;
-       set_by_comm[1] = false;
+       for(int i=0; i<ATC_NUM_TYPES; ++i) {
+               set_by_comm[0][i] = false;
+               set_by_comm[1][i] = false;
+       }
 }
 
 FGATCMgr::FGATCMgr() {
@@ -90,14 +91,20 @@ void FGATCMgr::init() {
        atc_list_itr = atc_list.begin();
        
        // Search for connected ATC stations once per 0.8 seconds or so
-       // global_events.Register( "fgATCSearch()", fgATCSearch,
-       //                  fgEVENT::FG_EVENT_READY, 800);
+       // globals->get_event_mgr()->add( "fgATCSearch()", fgATCSearch,
+        //                                 FGEvent::FG_EVENT_READY, 800);
+        //  
        // For some reason the above doesn't compile - including Time/event.hxx stops compilation.
+        // Is this still true after the reorganization of the event managar??
+        // -EMH-
        
        // Initialise the frequency search map
     current_commlist = new FGCommList;
     SGPath p_comm( globals->get_fg_root() );
     current_commlist->init( p_comm );
+       
+       // Set the user callsign - bit of a hack at the moment - eventually should be read from aircraft file and user-over-rideable
+       fgSetString("/sim/user/callsign", "Golf Foxtrot Sierra");       // C-FGFS
 
 #ifdef ENABLE_AUDIO_SUPPORT    
        // Load all available voices.
@@ -127,12 +134,6 @@ void FGATCMgr::init() {
     current_atcdialog = new FGATCDialog;
     current_atcdialog->Init();
 
-       ATCDialogInit();
-       
-       // DCL - testing
-       //current_atcdialog->add_entry( "EGNX", "Request vectoring for approach", "Request Vectors" );
-       //current_atcdialog->add_entry( "EGNX", "Mayday, Mayday", "Declare Emergency" );
-       
        initDone = true;
 }
 
@@ -142,6 +143,8 @@ void FGATCMgr::update(double dt) {
                SG_LOG(SG_ATC, SG_WARN, "Warning - ATCMgr::update(...) called before ATCMgr::init()");
        }
        
+       current_atcdialog->Update(dt);
+       
        //cout << "Entering update..." << endl;
        //Traverse the list of active stations.
        //Only update one class per update step to avoid the whole ATC system having to calculate between frames.
@@ -159,11 +162,13 @@ void FGATCMgr::update(double dt) {
        }
        
        // Search the tuned frequencies every now and then - this should be done with the event scheduler
-       static int i = 0;
+       static int i = 0;       // Very ugly - but there should only ever be one instance of FGATCMgr.
+       /*
        if(i == 7) {
                //cout << "About to AreaSearch()" << endl;
                AreaSearch();
        }
+       */
        if(i == 15) {
                //cout << "About to search(1)" << endl;
                FreqSearch(1);
@@ -227,20 +232,11 @@ bool FGATCMgr::AIRegisterAirport(string ident) {
 
 // Register the fact that the comm radio is tuned to an airport
 // Channel is zero based
-bool FGATCMgr::CommRegisterAirport(string ident, int chan) {
+bool FGATCMgr::CommRegisterAirport(string ident, int chan, atc_type tp) {
        SG_LOG(SG_ATC, SG_BULK, "Comm channel " << chan << " registered airport " << ident);
        if(airport_atc_map.find(ident) != airport_atc_map.end()) {
                //cout << "IN MAP - flagging set by comm..." << endl;
-               if(chan == 0) {
-                       airport_atc_map[ident]->set_by_comm[0] = true;
-               } else if(chan == 1) {
-                       airport_atc_map[ident]->set_by_comm[1] = true;
-               } else {
-                       SG_LOG(SG_ATC, SG_ALERT, "COMM CHANNEL NOT 0 OR 1 IN FGATCMGR!");
-                       // Just register both and accept the fact that this ATC will probably never get removed!
-                       airport_atc_map[ident]->set_by_comm[0] = true;
-                       airport_atc_map[ident]->set_by_comm[1] = true;
-               }
+               airport_atc_map[ident]->set_by_comm[chan][tp] = true;
                return(true);
        } else {
                //cout << "NOT IN MAP - creating new..." << endl;
@@ -260,16 +256,7 @@ bool FGATCMgr::CommRegisterAirport(string ident, int chan) {
                        // TODO - some airports will have a tower/ground frequency but be inactive overnight.
                        a->set_by_AI = false;
                        a->numAI = 0;
-                       if(chan == 0) {
-                               a->set_by_comm[0] = true;
-                       } else if(chan == 1) {
-                               a->set_by_comm[1] = true;
-                       } else {
-                               SG_LOG(SG_ATC, SG_ALERT, "COMM CHANNEL NOT 1 OR 2 IN FGATCMGR!");
-                               // Just register both and accept the fact that this ATC will probably never get removed!
-                               a->set_by_comm[0] = true;
-                               a->set_by_comm[1] = true;
-                       }                       
+                       a->set_by_comm[chan][tp] = true;                        
                        airport_atc_map[ident] = a;
                        return(true);
                }
@@ -282,18 +269,18 @@ bool FGATCMgr::CommRegisterAirport(string ident, int chan) {
 // Note that chan is zero based.
 void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
        SG_LOG(SG_ATC, SG_BULK, "CommRemoveFromList called for airport " << id << " " << tp << " by channel " << chan);
-       if(airport_atc_map.find((string)id) != airport_atc_map.end()) {
-               AirportATC* a = airport_atc_map[(string)id];
+       if(airport_atc_map.find(id) != airport_atc_map.end()) {
+               AirportATC* a = airport_atc_map[id];
                //cout << "In CommRemoveFromList, a->ground_freq = " << a->ground_freq << endl;
                if(a->set_by_AI && tp != ATIS) {
+                       // Set by AI, so don't remove simply because user isn't tuned in any more - just stop displaying
                        SG_LOG(SG_ATC, SG_BULK, "In CommRemoveFromList, service was set by AI\n");
-                       // Don't remove
-                       FGATC* aptr = GetATCPointer((string)id, tp);
+                       FGATC* aptr = GetATCPointer(id, tp);
                        switch(chan) {
                        case 0:
                                //cout << "chan 1\n";
-                               a->set_by_comm[0] = false;
-                               if(!a->set_by_comm[1]) {
+                               a->set_by_comm[0][tp] = false;
+                               if(!a->set_by_comm[1][tp]) {
                                        //cout << "not set by comm2\n";
                                        if(aptr != NULL) {
                                                //cout << "Got pointer\n";
@@ -305,8 +292,8 @@ void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
                                }
                                break;
                        case 1:
-                               a->set_by_comm[1] = false;
-                               if(!a->set_by_comm[0]) {
+                               a->set_by_comm[1][tp] = false;
+                               if(!a->set_by_comm[0][tp]) {
                                        if(aptr != NULL) {
                                                aptr->SetNoDisplay();
                                                //cout << "Setting no display...\n";
@@ -314,20 +301,20 @@ void FGATCMgr::CommRemoveFromList(const char* id, atc_type tp, int chan) {
                                }
                                break;
                        }
-                       airport_atc_map[(string)id] = a;
+                       airport_atc_map[id] = a;
                        return;
                } else {
                        switch(chan) {
                        case 0:
-                               a->set_by_comm[0] = false;
+                               a->set_by_comm[0][tp] = false;
                                // Remove only if not also set by the other comm channel
-                               if(!a->set_by_comm[1]) {
+                               if(!a->set_by_comm[1][tp]) {
                                        RemoveFromList(id, tp);
                                }
                                break;
                        case 1:
-                               a->set_by_comm[1] = false;
-                               if(!a->set_by_comm[0]) {
+                               a->set_by_comm[1][tp] = false;
+                               if(!a->set_by_comm[0][tp]) {
                                        RemoveFromList(id, tp);
                                }
                                break;
@@ -488,11 +475,6 @@ FGATCVoice* FGATCMgr::GetVoicePointer(atc_type type) {
        }
 }
 
-// Display a dialog box with options relevant to the currently tuned ATC service.
-void FGATCMgr::doPopupDialog() {
-       ATCDoDialog(comm_type[0]);      // FIXME - currently hardwired to comm1
-}
-
 // Search for ATC stations by frequency
 void FGATCMgr::FreqSearch(int channel) {
        int chan = channel - 1;         // Convert to zero-based for the arrays
@@ -533,7 +515,7 @@ void FGATCMgr::FreqSearch(int channel) {
                
                // This was a switch-case statement but the compiler didn't like the new variable creation with it. 
                if(comm_type[chan] == ATIS) {
-                       CommRegisterAirport(comm_ident[chan], chan);
+                       CommRegisterAirport(comm_ident[chan], chan, ATIS);
                        FGATC* app = FindInList(comm_ident[chan], ATIS);
                        if(app != NULL) {
                                // The station is already in the ATC list
@@ -550,25 +532,25 @@ void FGATCMgr::FreqSearch(int channel) {
                                atc_list.push_back(a);
                        }
                } else if (comm_type[chan] == TOWER) {
-                       CommRegisterAirport(comm_ident[chan], chan);
+                       CommRegisterAirport(comm_ident[chan], chan, TOWER);
                        //cout << "Done (TOWER)" << endl;
                        FGATC* app = FindInList(comm_ident[chan], TOWER);
                        if(app != NULL) {
                                // The station is already in the ATC list
-                               //cout << "In list - flagging SetDisplay..." << endl;
+                                SG_LOG(SG_GENERAL, SG_DEBUG, comm_ident[chan] << " is in list - flagging SetDisplay...");
                                app->SetDisplay();
                        } else {
                                // Generate the station and put in the ATC list
-                               //cout << "Not in list - generating..." << endl;
+                                SG_LOG(SG_GENERAL, SG_DEBUG, comm_ident[chan] << " is not in list - generating...");
                                FGTower* t = new FGTower;
                                t->SetData(&data);
                                comm_atc_ptr[chan] = t;
-                               t->SetDisplay();
                                t->Init();
+                               t->SetDisplay();
                                atc_list.push_back(t);
                        }
                }  else if (comm_type[chan] == GROUND) {
-                       CommRegisterAirport(comm_ident[chan], chan);
+                       CommRegisterAirport(comm_ident[chan], chan, GROUND);
                        //cout << "Done (GROUND)" << endl;
                        FGATC* app = FindInList(comm_ident[chan], GROUND);
                        if(app != NULL) {
@@ -579,13 +561,13 @@ void FGATCMgr::FreqSearch(int channel) {
                                FGGround* g = new FGGround;
                                g->SetData(&data);
                                comm_atc_ptr[chan] = g;
-                               g->SetDisplay();
                                g->Init();
+                               g->SetDisplay();
                                atc_list.push_back(g);
                        }
                } else if (comm_type[chan] == APPROACH) {
                        // We have to be a bit more carefull here since approaches are also searched by area
-                       CommRegisterAirport(comm_ident[chan], chan);
+                       CommRegisterAirport(comm_ident[chan], chan, APPROACH);
                        //cout << "Done (APPROACH)" << endl;
                        FGATC* app = FindInList(comm_ident[chan], APPROACH);
                        if(app != NULL) {
@@ -597,9 +579,11 @@ void FGATCMgr::FreqSearch(int channel) {
                                // Generate the station and put in the ATC list
                                FGApproach* a = new FGApproach;
                                a->SetData(&data);
+                               comm_atc_ptr[chan] = a;
+                               a->Init();
+                               a->SetDisplay();
                                a->AddPlane("Player");
                                atc_list.push_back(a);
-                               comm_atc_ptr[chan] = a;
                        }                       
                }
        } else {
@@ -617,7 +601,6 @@ void FGATCMgr::FreqSearch(int channel) {
        }
 }
 
-
 // Search ATC stations by area in order that we appear 'on the radar'
 void FGATCMgr::AreaSearch() {
        // Search for Approach stations
@@ -638,12 +621,14 @@ void FGATCMgr::AreaSearch() {
                        FGATC* app = FindInList((app_itr->ident).c_str(), app_itr->type);
                        if(app != NULL) {
                                // The station is already in the ATC list
+                               //cout << "In list adding player\n";
                                app->AddPlane("Player");
                                //app->Update();
                        } else {
                                // Generate the station and put in the ATC list
                                FGApproach* a = new FGApproach;
                                a->SetData(&(*app_itr));
+                               //cout << "Adding player\n";
                                a->AddPlane("Player");
                                //a->Update();
                                atc_list.push_back(a);