]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCDialog.cxx
new FSF address
[flightgear.git] / src / ATC / ATCDialog.cxx
index 58f1ceba4c27ee089bf92682253a2ea024c9185b..6265c6b549c8218d9bd6193bc95020168a795ac5 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>
 
@@ -78,7 +82,6 @@ static SGPropertyNode *getNamedNode(SGPropertyNode *prop, const char *name) {
                if ((p = getNamedNode(prop->getChild(i), name)))
                        return p;
 
-
        if (!strcmp(prop->getStringValue("name"), name))
                return prop;
 
@@ -240,6 +243,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);
 
@@ -264,12 +268,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;
@@ -289,10 +296,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;
@@ -308,7 +315,7 @@ void FGATCDialog::FreqDialog() {
        _gui->closeDialog(dialog_name);
 
        SGPropertyNode_ptr button_group = getNamedNode(dlg, "quick-buttons");
-       // remove all dynamic ATC buttons
+       // remove all dynamic airport/ATC buttons
        button_group->removeChildren("button", false);
 
        // Find the ATC stations within a reasonable range (about 40 miles?)
@@ -325,7 +332,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);
@@ -365,8 +372,8 @@ void FGATCDialog::FreqDisplay(string& ident) {
        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;
@@ -379,7 +386,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();