]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCDialog.cxx
Modified Files:
[flightgear.git] / src / ATC / ATCDialog.cxx
index def15c132252e85020fc3a8fb6271cbc25eb2784..3119ae3364adbb6862f4ee114f5656b0f677efc9 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
 #include <simgear/compiler.h>
 
 #include <Airports/simple.hxx>
 
 #include <sstream>
-#include <map>
 
 SG_USING_STD(ostringstream);
-SG_USING_STD(map);
 
 FGATCDialog *current_atcdialog;
 
@@ -71,14 +73,17 @@ static void atcUppercase(string &s) {
 }
 
 // find child whose <name>...</name> entry matches 'name'
-static SGPropertyNode_ptr namedNode(const vector<SGPropertyNode_ptr> &children, const char *name) {
-       SGPropertyNode_ptr ret;
-       for (int i = 0; i < children.size(); i++)
-               if (!strcmp(children[i]->getStringValue("name"), name)) {
-                       ret = children[i];
-                       break;
-               }
-       return ret;
+static SGPropertyNode *getNamedNode(SGPropertyNode *prop, const char *name) {
+       SGPropertyNode* p;
+
+       for (int i = 0; i < prop->nChildren(); i++)
+               if ((p = getNamedNode(prop->getChild(i), name)))
+                       return p;
+
+       if (!strcmp(prop->getStringValue("name"), name))
+               return prop;
+
+       return 0;
 }
 
 
@@ -186,13 +191,13 @@ bool FGATCDialog::trans_reg( const string &station, int code, atc_type type ) {
 // Display the ATC popup dialog box with options relevant to the users current situation.
 void FGATCDialog::PopupDialog() {
        const char *dialog_name = "atc-dialog";
-       SGPropertyNode_ptr dlg = _gui->getDialog(dialog_name);
+       SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name);
        if (!dlg)
                return;
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr button_group = namedNode(dlg->getChildren("group"), "transmission-choice");
+       SGPropertyNode_ptr button_group = getNamedNode(dlg, "transmission-choice");
        // remove all transmission buttons
        button_group->removeChildren("button", false);
 
@@ -236,6 +241,7 @@ void FGATCDialog::PopupDialog() {
                copyProperties(button_group->getNode("button-template", true), entry);
                entry->removeChildren("hide", false);
                entry->setStringValue("property", buf);
+               entry->setIntValue("keynum", '1' + n);
                if (n == 0)
                        entry->setBoolValue("default", true);
 
@@ -260,12 +266,15 @@ void FGATCDialog::PopupCallback(int num) {
                //cout << "TOWER " << endl;
                //cout << "ident is " << atcptr->get_ident() << endl;
                atcmentry_vec_type atcmlist = (available_dialog[TOWER])[atcptr->get_ident()];
-               if(atcmlist.size()) {
+               unsigned int size = atcmlist.size();
+               if(size && num < size) {
                        //cout << "Doing callback...\n";
                        ATCMenuEntry a = atcmlist[num];
                        atcptr->SetFreqInUse();
+                       string pilot = atcptr->GenText(a.transmission, a.callback_code);
+                       fgSetString("/sim/messages/pilot", pilot.c_str());
                        // This is the user's speech getting displayed.
-                       globals->get_ATC_display()->RegisterSingleMessage(atcptr->GenText(a.transmission, a.callback_code));
+                       globals->get_ATC_display()->RegisterSingleMessage(pilot);
                        _callbackPending = true;
                        _callbackTimer = 0.0;
                        _callbackWait = 5.0;
@@ -285,10 +294,10 @@ struct atcdata {
                id = i, name = n, distance = d;
        }
        bool operator<(const atcdata& a) const {
-               return a.id != id && a.distance > distance;
+               return id != a.id && distance < a.distance;
        }
        bool operator==(const atcdata& a) const {
-               return a.distance == distance && a.id == id;
+               return id == a.id && distance == a.distance;
        }
        string id;
        string name;
@@ -297,14 +306,14 @@ struct atcdata {
 
 void FGATCDialog::FreqDialog() {
        const char *dialog_name = "atc-freq-search";
-       SGPropertyNode_ptr dlg = _gui->getDialog(dialog_name);
+       SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name);
        if (!dlg)
                return;
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr button_group = namedNode(dlg->getChildren("group"), "quick-buttons");
-       // remove all dynamic ATC buttons
+       SGPropertyNode_ptr button_group = getNamedNode(dlg, "quick-buttons");
+       // remove all dynamic airport/ATC buttons
        button_group->removeChildren("button", false);
 
        // Find the ATC stations within a reasonable range (about 40 miles?)
@@ -321,7 +330,7 @@ void FGATCDialog::FreqDialog() {
        int num_stat = current_commlist->FindByPos(lon, lat, elev, 40.0, &atc_stations);
        if (num_stat != 0) {
                map<atcdata, bool> uniq;
-               // fill map (sorts by distance)
+               // fill map (sorts by distance and removes duplicates)
                comm_list_iterator itr = atc_stations.begin();
                for (; itr != atc_stations.end(); ++itr) {
                        Point3D station = Point3D(itr->x, itr->y, itr->z);
@@ -340,7 +349,7 @@ void FGATCDialog::FreqDialog() {
        }
 
        // (un)hide message saying no things in range
-       SGPropertyNode_ptr range_error = namedNode(dlg->getChildren("text"), "no-atc-in-range");
+       SGPropertyNode_ptr range_error = getNamedNode(dlg, "no-atc-in-range");
        range_error->setBoolValue("hide", num_stat);
 
        _gui->showDialog(dialog_name);
@@ -348,21 +357,21 @@ void FGATCDialog::FreqDialog() {
 
 void FGATCDialog::FreqDisplay(string& ident) {
        const char *dialog_name = "atc-freq-display";
-       SGPropertyNode_ptr dlg = _gui->getDialog(dialog_name);
+       SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name);
        if (!dlg)
                return;
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr freq_group = namedNode(dlg->getChildren("group"), "frequency-list");
+       SGPropertyNode_ptr freq_group = getNamedNode(dlg, "frequency-list");
        // remove all frequency entries
        freq_group->removeChildren("group", false);
 
        atcUppercase(ident);
        string label;
 
-       FGAirport a;
-       if (!dclFindAirportID(ident, &a)) {
+       const FGAirport *a = fgFindAirportID(ident);
+       if (!a) {
                label = "Airport " + ident + " not found in database.";
                mkDialog(label.c_str());
                return;
@@ -375,7 +384,7 @@ void FGATCDialog::FreqDisplay(string& ident) {
        int n = 0;      // Number of ATC frequencies at this airport
 
        comm_list_type stations;
-       int found = current_commlist->FindByPos(a.getLongitude(), a.getLatitude(), a.getElevation(), 20.0, &stations);
+       int found = current_commlist->FindByPos(a->getLongitude(), a->getLatitude(), a->getElevation(), 20.0, &stations);
        if(found) {
                ostringstream ostr;
                comm_list_iterator itr = stations.begin();