]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCmgr.cxx
Alex Romosan:
[flightgear.git] / src / ATC / ATCmgr.cxx
index d87ed5d9650b13a46f5885f633a1a933574a8ac5..6aa95a547c2ae743bb89d352422a048420280bf2 100644 (file)
@@ -86,8 +86,8 @@ void FGATCMgr::unbind() {
 void FGATCMgr::init() {
        //cout << "ATCMgr::init called..." << endl;
        
-       comm_node[0] = fgGetNode("/radios/comm[0]/frequencies/selected-mhz", true);
-       comm_node[1] = fgGetNode("/radios/comm[1]/frequencies/selected-mhz", true);
+       comm_node[0] = fgGetNode("/instrumentation/comm[0]/frequencies/selected-mhz", true);
+       comm_node[1] = fgGetNode("/instrumentation/comm[1]/frequencies/selected-mhz", true);
        lon_node = fgGetNode("/position/longitude-deg", true);
        lat_node = fgGetNode("/position/latitude-deg", true);
        elev_node = fgGetNode("/position/altitude-ft", true);
@@ -117,9 +117,10 @@ void FGATCMgr::init() {
        voiceOK = v1->LoadVoice("default");
        voice = true;
        
-       /* I've loaded the voice even if /sim/sound/audible is false
+       /* 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. */
+       *  subsequently switches /sim/sound/audible to true.
+        *  (which is the right thing to do -- CLO) :-) */
 #else
        voice = false;
 #endif
@@ -198,7 +199,7 @@ void FGATCMgr::update(double dt) {
 
 
 // Returns frequency in KHz - should I alter this to return in MHz?
-unsigned short int FGATCMgr::GetFrequency(string ident, atc_type tp) {
+unsigned short int FGATCMgr::GetFrequency(const string& ident, const atc_type& tp) {
        ATCData test;
        bool ok = current_commlist->FindByCode(ident, test, tp);
        return(ok ? test.freq : 0);
@@ -207,7 +208,7 @@ unsigned short int FGATCMgr::GetFrequency(string ident, atc_type tp) {
 
 // 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(string ident) {
+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()) {
@@ -220,9 +221,9 @@ bool FGATCMgr::AIRegisterAirport(string ident) {
                        //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->lon = ap.longitude;
-                       a->lat = ap.latitude;
-                       a->elev = ap.elevation;
+                       a->lon = ap.getLongitude();
+                       a->lat = ap.getLatitude();
+                       a->elev = ap.getElevation();
                        a->atis_freq = GetFrequency(ident, ATIS);
                        //cout << "ATIS freq = " << a->atis_freq << '\n';
                        a->atis_active = false;
@@ -237,6 +238,8 @@ bool FGATCMgr::AIRegisterAirport(string ident) {
                        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);
@@ -245,9 +248,9 @@ 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, atc_type tp) {
+bool FGATCMgr::CommRegisterAirport(const string& ident, int chan, const atc_type& tp) {
        SG_LOG(SG_ATC, SG_BULK, "Comm channel " << chan << " registered airport " << ident);
-       //cout << "Comm channel " << chan << " registered airport " << ident << '\n';
+       //cout << "Comm channel " << chan << " registered airport " << ident << ' ' << tp << '\n';
        if(airport_atc_map.find(ident) != airport_atc_map.end()) {
                //cout << "IN MAP - flagging set by comm..." << endl;
                airport_atc_map[ident]->set_by_comm[chan][tp] = true;
@@ -267,9 +270,9 @@ bool FGATCMgr::CommRegisterAirport(string ident, int chan, atc_type tp) {
                if(dclFindAirportID(ident, &ap)) {
                        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->lon = ap.longitude;
-                       a->lat = ap.latitude;
-                       a->elev = ap.elevation;
+                       a->lon = ap.getLongitude();
+                       a->lat = ap.getLatitude();
+                       a->elev = ap.getElevation();
                        a->atis_freq = GetFrequency(ident, ATIS);
                        a->atis_active = false;
                        a->tower_freq = GetFrequency(ident, TOWER);
@@ -288,7 +291,7 @@ bool FGATCMgr::CommRegisterAirport(string ident, int chan, atc_type tp) {
                        // TODO - some airports will have a tower/ground frequency but be inactive overnight.
                        a->set_by_AI = false;
                        a->numAI = 0;
-                       a->set_by_comm[chan][tp] = true;                        
+                       a->set_by_comm[chan][tp] = true;
                        airport_atc_map[ident] = a;
                        return(true);
                }
@@ -299,7 +302,7 @@ bool FGATCMgr::CommRegisterAirport(string ident, int chan, atc_type tp) {
 
 // Remove from list only if not needed by the AI system or the other comm channel
 // Note that chan is zero based.
-void FGATCMgr::CommRemoveFromList(string id, atc_type tp, int chan) {
+void FGATCMgr::CommRemoveFromList(const string& id, const atc_type& tp, int chan) {
        SG_LOG(SG_ATC, SG_BULK, "CommRemoveFromList called for airport " << id << " " << tp << " by channel " << chan);
        //cout << "CommRemoveFromList called for airport " << id << " " << tp << " by channel " << chan << '\n';
        if(airport_atc_map.find(id) != airport_atc_map.end()) {
@@ -334,7 +337,7 @@ void FGATCMgr::CommRemoveFromList(string id, atc_type tp, int chan) {
                                }
                                break;
                        }
-                       airport_atc_map[id] = a;
+                       //airport_atc_map[id] = a;
                        return;
                } else {
                        switch(chan) {
@@ -363,7 +366,7 @@ void FGATCMgr::CommRemoveFromList(string id, atc_type tp, int chan) {
 
 // Remove from list - should only be called from above or similar
 // This function *will* remove it from the list regardless of who else might want it.
-void FGATCMgr::RemoveFromList(string id, atc_type tp) {
+void FGATCMgr::RemoveFromList(const string& id, const atc_type& tp) {
        //cout << "FGATCMgr::RemoveFromList called..." << endl;
        //cout << "Requested type = " << tp << endl;
        //cout << "id = " << id << endl;
@@ -371,7 +374,7 @@ void FGATCMgr::RemoveFromList(string id, atc_type tp) {
        while(it != atc_list.end()) {
                //cout << "type = " << (*it)->GetType() << '\n';
                //cout << "Ident = " << (*it)->get_ident() << '\n';
-               if( (!strcmp((*it)->get_ident(), id.c_str()))
+               if( ((*it)->get_ident() == id)
                        && ((*it)->GetType() == tp) ) {
                        //Before removing it stop it transmitting!!
                        //cout << "OBLITERATING FROM LIST!!!\n";
@@ -390,12 +393,12 @@ void FGATCMgr::RemoveFromList(string id, atc_type tp) {
 // Find in list - return a currently active ATC pointer given ICAO code and type
 // Return NULL if the given service is not in the list
 // - *** THE CALLING FUNCTION MUST CHECK FOR THIS ***
-FGATC* FGATCMgr::FindInList(string id, atc_type tp) {
+FGATC* FGATCMgr::FindInList(const string& id, const atc_type& tp) {
        //cout << "Entering FindInList for " << id << ' ' << tp << endl;
        atc_list_iterator it = atc_list.begin();
        while(it != atc_list.end()) {
-               if( (!strcmp((*it)->get_ident(), id.c_str()))
-               && ((*it)->GetType() == tp) ) {
+               if( ((*it)->get_ident() == id)
+                   && ((*it)->GetType() == tp) ) {
                        return(*it);
                }
                ++it;
@@ -406,7 +409,7 @@ FGATC* FGATCMgr::FindInList(string id, atc_type tp) {
 }
 
 // Returns true if the airport is found in the map
-bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
+bool FGATCMgr::GetAirportATCDetails(const string& icao, AirportATC* a) {
        if(airport_atc_map.find(icao) != airport_atc_map.end()) {
                *a = *airport_atc_map[icao];
                return(true);
@@ -420,12 +423,12 @@ bool FGATCMgr::GetAirportATCDetails(string icao, AirportATC* a) {
 // Returns NULL if service doesn't exist - calling function should check for this.
 // We really ought to make this private and call it from the CommRegisterAirport / AIRegisterAirport functions
 // - at the moment all these GetATC... functions exposed are just too complicated.
-FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
+FGATC* FGATCMgr::GetATCPointer(const string& icao, const atc_type& type) {
        if(airport_atc_map.find(icao) == airport_atc_map.end()) {
                //cout << "Unable to find " << icao << ' ' << type << " in the airport_atc_map" << endl;
                return NULL;
        }
-       //cout << "Found " << icao << ' ' << type << endl;
+       //cout << "In GetATCPointer, found " << icao << ' ' << type << endl;
        AirportATC *a = airport_atc_map[icao];
        //cout << "a->lon = " << a->lon << '\n';
        //cout << "a->elev = " << a->elev << '\n';
@@ -434,7 +437,7 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
        case TOWER:
                if(a->tower_active) {
                        // Get the pointer from the list
-                       return(FindInList(icao.c_str(), type));
+                       return(FindInList(icao, type));
                } else {
                        ATCData data;
                        if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->tower_freq, &data, TOWER)) {
@@ -443,7 +446,7 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
                                atc_list.push_back(t);
                                a->tower_active = true;
                                airport_atc_map[icao] = a;
-                               //cout << "Initing tower in GetATCPointer()\n";
+                               //cout << "Initing tower " << icao << " in GetATCPointer()\n";
                                t->Init();
                                return(t);
                        } else {
@@ -460,7 +463,7 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
                //cout << "IN CASE GROUND" << endl;
                if(a->ground_active) {
                        // Get the pointer from the list
-                       return(FindInList(icao.c_str(), type));
+                       return(FindInList(icao, type));
                } else {
                        ATCData data;
                        if(current_commlist->FindByFreq(a->lon, a->lat, a->elev, a->ground_freq, &data, GROUND)) {
@@ -497,7 +500,7 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) {
 // TODO - in the future this will get more complex and dole out country/airport
 // specific voices, and possible make sure that the same voice doesn't get used
 // at different airports in quick succession if a large enough selection are available.
-FGATCVoice* FGATCMgr::GetVoicePointer(atc_type type) {
+FGATCVoice* FGATCMgr::GetVoicePointer(const atc_type& type) {
        // TODO - implement me better - maintain a list of loaded voices and other voices!!
        if(voice) {
                switch(type) {
@@ -670,7 +673,7 @@ void FGATCMgr::AreaSearch() {
                
                for(app_itr = approaches.begin(); app_itr != approaches.end(); app_itr++) {
                        
-                       FGATC* app = FindInList((app_itr->ident).c_str(), app_itr->type);
+                       FGATC* app = FindInList(app_itr->ident, app_itr->type);
                        if(app != NULL) {
                                // The station is already in the ATC list
                                //cout << "In list adding player\n";