static void ATCDialogOK (puObject *me)
{
- switch(globals->get_ATC_mgr()->GetCurrentATCType()) {
+ // Note that currently the dialog is hardwired to comm1 only here.
+ switch(globals->get_ATC_mgr()->GetComm1ATCType()) {
case INVALID:
break;
case ATIS:
break;
case TOWER: {
- FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetCurrentATCPointer();
+ FGTower* twr = (FGTower*)globals->get_ATC_mgr()->GetComm1ATCPointer();
switch(atcDialogCommunicationOptions->getValue()) {
case 0:
cout << "Option 0 chosen\n";
comm1_tower_valid = false;
comm1_approach_valid = false;
comm1_type = INVALID;
- tuned_atc_ptr = NULL;
+ comm1_atc_ptr = NULL;
+ comm2_ident = "";
+ comm2_atis_ident = "";
+ comm2_tower_ident = "";
+ comm2_approach_ident = "";
+ last_comm2_ident = "";
+ last_comm2_atis_ident = "";
+ last_comm2_tower_ident = "";
+ last_comm2_approach_ident = "";
+ comm2_atis_valid = false;
+ comm2_tower_valid = false;
+ comm2_approach_valid = false;
+ comm2_type = INVALID;
+ comm2_atc_ptr = NULL;
}
FGATCMgr::~FGATCMgr() {
// Search the tuned frequencies every now and then - this should be done with the event scheduler
static int i = 0;
+ if(i == 15) {
+ Search(1);
+ }
if(i == 30) {
- Search();
+ Search(2);
i = 0;
}
++i;
atc_list_itr = atc_list.begin();
while(atc_list_itr != atc_list.end()) {
if( (!strcmp((*atc_list_itr)->GetIdent(), id))
- && ((*atc_list_itr)->GetType() == tp) ) {
- return(*atc_list_itr);
- } // Note that that can upset where we are in the list but that shouldn't really matter
+ && ((*atc_list_itr)->GetType() == tp) ) {
+ return(*atc_list_itr);
+ } // Note that that can upset where we are in the list but that shouldn't really matter
++atc_list_itr;
}
// We need a fallback position
// Render a transmission
// Outputs the transmission either on screen or as audio depending on user preference
+// The refname is a string to identify this sample to the sound manager
// The repeating flag indicates whether the message should be repeated continuously or played once.
-void FGATCMgr::Render(string msg, bool repeating) {
+void FGATCMgr::Render(string msg, string refname, bool repeating) {
#ifdef ENABLE_AUDIO_SUPPORT
voice = voiceOK && fgGetBool("/sim/sound/audible");
if(voice) {
// Cease rendering a transmission.
-// At the moment this can handle one transmission active at a time only.
-void FGATCMgr::NoRender() {
+void FGATCMgr::NoRender(string refname) {
if(playing) {
if(voice) {
#ifdef ENABLE_AUDIO_SUPPORT
// This is in ATCDialogOK()
}
-void FGATCMgr::Search() {
-
- ////////////////////////////////////////////////////////////////////////
- // Comm1.
- ////////////////////////////////////////////////////////////////////////
- //cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
-
- comm1_freq = comm1_node->getDoubleValue();
- //cout << "************* comm1_freq = " << comm1_freq << '\n';
- double lon = lon_node->getDoubleValue();
- double lat = lat_node->getDoubleValue();
- double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
-
- // Store the comm1_type
- //atc_type old_comm1_type = comm1_type;
-
- // We must be able to generalise some of the repetetive searching below!
+////////////////////////////////////////////////////////////////
+//
+// TODO - The whole ATC frequency storage and search is really
+// really ugly and needs reworking at some point.
+//
+////////////////////////////////////////////////////////////////
+// Search the specified comm channel (1 or 2)
+void FGATCMgr::Search(int chan) {
- //Search for ATIS first
- if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
- //cout << "atis found in radiostack search !!!!" << endl;
- //cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
- //cout << "comm1_type " << comm1_type << '\n';
- comm1_atis_ident = atis.GetIdent();
- comm1_atis_valid = true;
- if(last_comm1_atis_ident != comm1_atis_ident) {
- if(last_comm1_atis_ident != "") {
- RemoveFromList(last_comm1_atis_ident, ATIS);
- }
- last_comm1_atis_ident = comm1_atis_ident;
+ if(chan == 1) {
+ ////////////////////////////////////////////////////////////////////////
+ // Comm1.
+ ////////////////////////////////////////////////////////////////////////
+ //cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
+
+ comm1_freq = comm1_node->getDoubleValue();
+ //cout << "************* comm1_freq = " << comm1_freq << '\n';
+ double lon = lon_node->getDoubleValue();
+ double lat = lat_node->getDoubleValue();
+ double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
+
+ // We must be able to generalise some of the repetetive searching below!
+
+ //Search for ATIS first
+ if(current_atislist->query(lon, lat, elev, comm1_freq, &atis)) {
+ //cout << "atis found in radiostack search !!!!" << endl;
//cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
- comm1_type = ATIS;
- comm1_elev = atis.get_elev();
- comm1_range = FG_ATIS_DEFAULT_RANGE;
- comm1_effective_range = comm1_range;
- comm1_x = atis.get_x();
- comm1_y = atis.get_y();
- comm1_z = atis.get_z();
- FGATIS* a = new FGATIS;
- *a = atis;
- tuned_atc_ptr = a;
- a->SetDisplay();
- atc_list.push_back(a);
- //cout << "Found a new atis station in range" << endl;
- //cout << " id = " << atis.GetIdent() << endl;
- return; //This rather assumes that we never have more than one type of station in range.
- }
- } else {
- if(comm1_atis_valid) {
- //cout << "Removing ATIS " << comm1_atis_ident << " from list\n";
- RemoveFromList(comm1_atis_ident, ATIS);
- comm1_atis_valid = false;
- if(comm1_type == ATIS) {
- comm1_type = INVALID;
+ //cout << "comm1_type " << comm1_type << '\n';
+ comm1_atis_ident = atis.GetIdent();
+ comm1_atis_valid = true;
+ if(last_comm1_atis_ident != comm1_atis_ident) {
+ if(last_comm1_atis_ident != "") {
+ RemoveFromList(last_comm1_atis_ident, ATIS);
+ }
+ last_comm1_atis_ident = comm1_atis_ident;
+ //cout << "last_comm1_atis_ident = " << last_comm1_atis_ident << '\n';
+ comm1_type = ATIS;
+ comm1_elev = atis.get_elev();
+ comm1_range = FG_ATIS_DEFAULT_RANGE;
+ comm1_effective_range = comm1_range;
+ comm1_x = atis.get_x();
+ comm1_y = atis.get_y();
+ comm1_z = atis.get_z();
+ FGATIS* a = new FGATIS;
+ *a = atis;
+ comm1_atc_ptr = a;
+ a->SetDisplay();
+ a->set_refname("atis1");
+ atc_list.push_back(a);
+ //cout << "Found a new atis station in range" << endl;
+ //cout << " id = " << atis.GetIdent() << endl;
+ return; //This rather assumes that we never have more than one type of station in range.
}
- comm1_atis_ident = "";
- //comm1_trans_ident = "";
- last_comm1_atis_ident = "";
- tuned_atc_ptr = NULL;
- }
- //cout << "not picking up atis" << endl;
- }
-
- //Next search for tower
- //cout << "comm1_freq = " << comm1_freq << '\n';
- if(current_towerlist->query(lon, lat, elev, comm1_freq, &tower)) {
- //cout << "tower found in radiostack search !!!!" << endl;
- comm1_tower_ident = tower.GetIdent();
- //cout << "comm1_tower_ident = " << comm1_tower_ident << '\n';
- comm1_tower_valid = true;
- if(last_comm1_tower_ident != comm1_tower_ident) {
- if(last_comm1_tower_ident != "") {
- RemoveFromList(last_comm1_tower_ident, TOWER);
+ } else {
+ if(comm1_atis_valid) {
+ //cout << "Removing ATIS " << comm1_atis_ident << " from list\n";
+ RemoveFromList(comm1_atis_ident, ATIS);
+ comm1_atis_valid = false;
+ if(comm1_type == ATIS) {
+ comm1_type = INVALID;
+ }
+ comm1_atis_ident = "";
+ //comm1_trans_ident = "";
+ last_comm1_atis_ident = "";
+ comm1_atc_ptr = NULL;
}
- last_comm1_tower_ident = comm1_tower_ident;
- comm1_type = TOWER;
- comm1_elev = tower.get_elev();
- comm1_range = FG_TOWER_DEFAULT_RANGE;
- comm1_effective_range = comm1_range;
- comm1_x = tower.get_x();
- comm1_y = tower.get_y();
- comm1_z = tower.get_z();
- FGTower* t = new FGTower;
- *t = tower;
- tuned_atc_ptr = t;
- t->SetDisplay();
- atc_list.push_back(t);
- //cout << "Found a new tower station in range" << endl;
- //cout << " id = " << tower.GetIdent() << endl;
- return; //This rather assumes that we never have more than one type of station in range.
+ //cout << "not picking up atis" << endl;
}
- } else {
- if(comm1_tower_valid) {
- //cout << "removing tower\n";
- RemoveFromList(comm1_tower_ident, TOWER);
- //comm1_valid = false;
- if(comm1_type == TOWER) {
- comm1_type = INVALID; // Only invalidate if we haven't switched it to something else
+
+ //Next search for tower
+ //cout << "comm1_freq = " << comm1_freq << '\n';
+ if(current_towerlist->query(lon, lat, elev, comm1_freq, &tower)) {
+ //cout << "tower found in radiostack search !!!!" << endl;
+ comm1_tower_ident = tower.GetIdent();
+ //cout << "comm1_tower_ident = " << comm1_tower_ident << '\n';
+ comm1_tower_valid = true;
+ if(last_comm1_tower_ident != comm1_tower_ident) {
+ if(last_comm1_tower_ident != "") {
+ RemoveFromList(last_comm1_tower_ident, TOWER);
+ }
+ last_comm1_tower_ident = comm1_tower_ident;
+ comm1_type = TOWER;
+ comm1_elev = tower.get_elev();
+ comm1_range = FG_TOWER_DEFAULT_RANGE;
+ comm1_effective_range = comm1_range;
+ comm1_x = tower.get_x();
+ comm1_y = tower.get_y();
+ comm1_z = tower.get_z();
+ FGTower* t = new FGTower;
+ *t = tower;
+ comm1_atc_ptr = t;
+ t->SetDisplay();
+ atc_list.push_back(t);
+ //cout << "Found a new tower station in range" << endl;
+ //cout << " id = " << tower.GetIdent() << endl;
+ return; //This rather assumes that we never have more than one type of station in range.
}
- comm1_tower_valid = false;
- comm1_tower_ident = "";
- last_comm1_tower_ident = "";
- tuned_atc_ptr = NULL;
- //comm1_ident = "";
- //comm1_trans_ident = "";
- //last_comm1_ident = "";
- }
- //cout << "not picking up tower" << endl;
- }
- /*
- //Next search for Ground control
- if(current_groundlist->query(lon, lat, elev, comm1_freq, &ground)) {
- //cout << "Ground Control found in radiostack search !!!!" << endl;
- comm1_ident = ground.GetIdent();
- comm1_valid = true;
- if((last_comm1_ident != comm1_ident) || (comm1_type != GROUND)) {
- if(last_comm1_ident != "") {
- RemoveFromList(last_comm1_ident, GROUND);
+ } else {
+ if(comm1_tower_valid) {
+ //cout << "removing tower\n";
+ RemoveFromList(comm1_tower_ident, TOWER);
+ //comm1_valid = false;
+ if(comm1_type == TOWER) {
+ comm1_type = INVALID; // Only invalidate if we haven't switched it to something else
+ }
+ comm1_tower_valid = false;
+ comm1_tower_ident = "";
+ last_comm1_tower_ident = "";
+ comm1_atc_ptr = NULL;
+ //comm1_ident = "";
+ //comm1_trans_ident = "";
+ //last_comm1_ident = "";
}
- last_comm1_ident = comm1_ident;
- comm1_type = GROUND;
- comm1_elev = ground.get_elev();
- comm1_range = FG_GROUND_DEFAULT_RANGE;
- comm1_effective_range = comm1_range;
- comm1_x = ground.get_x();
- comm1_y = ground.get_y();
- comm1_z = ground.get_z();
- FGGround* g = new FGGround;
- *g = ground;
- g->SetDisplay();
- atc_list.push_back(g);
- // For now we will automatically make contact with ground when the radio is tuned.
- // This rather assumes that the user tunes the radio at the appropriate place
- // (ie. having just turned off the runway) and only uses ground control on arrival
- // but its a start!
- g->NewArrival(current_plane);
- //cout << "Found a new ground station in range" << endl;
- //cout << " id = " << ground.GetIdent() << endl;
- return; //This rather assumes that we never have more than one type of station in range.
+ //cout << "not picking up tower" << endl;
}
- } else {
- if((comm1_valid) && (comm1_type == GROUND)) {
- RemoveFromList(comm1_ident, GROUND);
- comm1_valid = false;
- comm1_type = INVALID;
- comm1_ident = "";
- //comm1_trans_ident = "";
- last_comm1_ident = "";
+ /*
+ //Next search for Ground control
+ if(current_groundlist->query(lon, lat, elev, comm1_freq, &ground)) {
+ //cout << "Ground Control found in radiostack search !!!!" << endl;
+ comm1_ident = ground.GetIdent();
+ comm1_valid = true;
+ if((last_comm1_ident != comm1_ident) || (comm1_type != GROUND)) {
+ if(last_comm1_ident != "") {
+ RemoveFromList(last_comm1_ident, GROUND);
+ }
+ last_comm1_ident = comm1_ident;
+ comm1_type = GROUND;
+ comm1_elev = ground.get_elev();
+ comm1_range = FG_GROUND_DEFAULT_RANGE;
+ comm1_effective_range = comm1_range;
+ comm1_x = ground.get_x();
+ comm1_y = ground.get_y();
+ comm1_z = ground.get_z();
+ FGGround* g = new FGGround;
+ *g = ground;
+ g->SetDisplay();
+ atc_list.push_back(g);
+ // For now we will automatically make contact with ground when the radio is tuned.
+ // This rather assumes that the user tunes the radio at the appropriate place
+ // (ie. having just turned off the runway) and only uses ground control on arrival
+ // but its a start!
+ g->NewArrival(current_plane);
+ //cout << "Found a new ground station in range" << endl;
+ //cout << " id = " << ground.GetIdent() << endl;
+ return; //This rather assumes that we never have more than one type of station in range.
+ }
+ } else {
+ if((comm1_valid) && (comm1_type == GROUND)) {
+ RemoveFromList(comm1_ident, GROUND);
+ comm1_valid = false;
+ comm1_type = INVALID;
+ comm1_ident = "";
+ //comm1_trans_ident = "";
+ last_comm1_ident = "";
+ }
+ //cout << "not picking up ground control" << endl;
}
- //cout << "not picking up ground control" << endl;
- }
- */
- // ================================================================================
- // Search for Approach stations
- // ================================================================================
- // init number of approach stations reachable by plane
- int num_app = 0;
-
- // search stations in range
- current_approachlist->query_bck(lon, lat, elev, approaches, max_app, num_app);
- if (num_app != 0) {
- //cout << num_app << " approaches found in radiostack search !!!!" << endl;
+ */
+ // ================================================================================
+ // Search for Approach stations
+ // ================================================================================
+ // init number of approach stations reachable by plane
+ int num_app = 0;
- for ( int i=0; i<num_app; i++ ) {
- bool new_app = true;
- approach_ident = approaches[i].GetIdent();
+ // search stations in range
+ current_approachlist->query_bck(lon, lat, elev, approaches, max_app, num_app);
+ if (num_app != 0) {
+ //cout << num_app << " approaches found in radiostack search !!!!" << endl;
- // check if station already exists on ATC stack
- atc_list_itr = atc_list.begin();
- while(atc_list_itr != atc_list.end()) {
- //cout << "ATC list: " << (*atc_list_itr)->GetIdent() << endl;
- if((!strcmp((*atc_list_itr)->GetIdent(), approach_ident))
- && ((*atc_list_itr)->GetType() == APPROACH) ) {
- new_app = false;
- string pid = "Player";
- (*atc_list_itr)->AddPlane(pid);
- (*atc_list_itr)->Update();
- break;
- }
- ++atc_list_itr;
+ for ( int i=0; i<num_app; i++ ) {
+ bool new_app = true;
+ approach_ident = approaches[i].GetIdent();
+
+ // check if station already exists on ATC stack
+ atc_list_itr = atc_list.begin();
+ while(atc_list_itr != atc_list.end()) {
+ //cout << "ATC list: " << (*atc_list_itr)->GetIdent() << endl;
+ if((!strcmp((*atc_list_itr)->GetIdent(), approach_ident))
+ && ((*atc_list_itr)->GetType() == APPROACH) ) {
+ new_app = false;
+ string pid = "Player";
+ (*atc_list_itr)->AddPlane(pid);
+ (*atc_list_itr)->Update();
+ break;
+ }
+ ++atc_list_itr;
+ }
+ // generate new Approach on ATC stack
+ if (new_app) {
+ FGApproach* a = new FGApproach;
+ *a = approaches[i];
+ string pid = "Player";
+ a->AddPlane(pid);
+ a->Update();
+ a->SetDisplay();
+ comm1_atc_ptr = a;
+ atc_list.push_back(a);
+ //cout << "Found a new approach station in range: Id = "
+ // << approaches[i].GetIdent() << endl;
+ }
}
- // generate new Approach on ATC stack
- if (new_app) {
- FGApproach* a = new FGApproach;
- *a = approaches[i];
- string pid = "Player";
- a->AddPlane(pid);
- a->Update();
+ }
+
+ // remove planes which are out of range
+ atc_list_itr = atc_list.begin();
+ while(atc_list_itr != atc_list.end()) {
+ if((*atc_list_itr)->GetType() == APPROACH ) {
+ int np = (*atc_list_itr)->RemovePlane();
+ // if approach has no planes left remove it from ATC list
+ if ( np == 0) {
+ (*atc_list_itr)->SetNoDisplay();
+ (*atc_list_itr)->Update();
+ delete (*atc_list_itr);
+ atc_list_itr = atc_list.erase(atc_list_itr);
+ break; // the other stations will be checked next time
+ }
+ }
+ ++atc_list_itr;
+ }
+
+ } else { // chan = 2
+
+ ////////////////////////////////////////////////////////////////////////
+ // Comm2.
+ ////////////////////////////////////////////////////////////////////////
+ //cout << "In FGATCMgr::Search() - atc_list.size = " << atc_list.size() << '\n';
+
+ comm2_freq = comm2_node->getDoubleValue();
+ //cout << "************* comm1_freq = " << comm1_freq << '\n';
+ double lon = lon_node->getDoubleValue();
+ double lat = lat_node->getDoubleValue();
+ double elev = elev_node->getDoubleValue() * SG_FEET_TO_METER;
+
+ if(current_atislist->query(lon, lat, elev, comm2_freq, &atis)) {
+ comm2_atis_ident = atis.GetIdent();
+ comm2_atis_valid = true;
+ if(last_comm2_atis_ident != comm2_atis_ident) {
+ if(last_comm2_atis_ident != "") {
+ RemoveFromList(last_comm2_atis_ident, ATIS);
+ }
+ last_comm2_atis_ident = comm2_atis_ident;
+ comm2_type = ATIS;
+ comm2_elev = atis.get_elev();
+ comm2_range = FG_ATIS_DEFAULT_RANGE;
+ comm2_effective_range = comm2_range;
+ comm2_x = atis.get_x();
+ comm2_y = atis.get_y();
+ comm2_z = atis.get_z();
+ FGATIS* a = new FGATIS;
+ *a = atis;
+ comm2_atc_ptr = a;
a->SetDisplay();
- tuned_atc_ptr = a;
+ a->set_refname("atis2");
atc_list.push_back(a);
- //cout << "Found a new approach station in range: Id = "
- // << approaches[i].GetIdent() << endl;
+ //cout << "Found a new atis station in range" << endl;
+ //cout << " id = " << atis.GetIdent() << endl;
+ return; //This rather assumes that we never have more than one type of station in range.
+ }
+ } else {
+ if(comm2_atis_valid) {
+ RemoveFromList(comm2_atis_ident, ATIS);
+ comm2_atis_valid = false;
+ if(comm2_type == ATIS) {
+ comm2_type = INVALID;
+ }
+ comm2_atis_ident = "";
+ //comm2_trans_ident = "";
+ last_comm2_atis_ident = "";
+ comm2_atc_ptr = NULL;
}
}
- }
-
- // remove planes which are out of range
- atc_list_itr = atc_list.begin();
- while(atc_list_itr != atc_list.end()) {
- if((*atc_list_itr)->GetType() == APPROACH ) {
- int np = (*atc_list_itr)->RemovePlane();
- // if approach has no planes left remove it from ATC list
- if ( np == 0) {
- (*atc_list_itr)->SetNoDisplay();
- (*atc_list_itr)->Update();
- delete (*atc_list_itr);
- atc_list_itr = atc_list.erase(atc_list_itr);
- break; // the other stations will be checked next time
+
+ if(current_towerlist->query(lon, lat, elev, comm2_freq, &tower)) {
+ //cout << "tower found in radiostack search !!!!" << endl;
+ comm2_tower_ident = tower.GetIdent();
+ comm2_tower_valid = true;
+ if(last_comm2_tower_ident != comm2_tower_ident) {
+ if(last_comm2_tower_ident != "") {
+ RemoveFromList(last_comm2_tower_ident, TOWER);
+ }
+ last_comm2_tower_ident = comm2_tower_ident;
+ comm2_type = TOWER;
+ comm2_elev = tower.get_elev();
+ comm2_range = FG_TOWER_DEFAULT_RANGE;
+ comm2_effective_range = comm2_range;
+ comm2_x = tower.get_x();
+ comm2_y = tower.get_y();
+ comm2_z = tower.get_z();
+ FGTower* t = new FGTower;
+ *t = tower;
+ comm2_atc_ptr = t;
+ t->SetDisplay();
+ atc_list.push_back(t);
+ return;
+ }
+ } else {
+ if(comm2_tower_valid) {
+ RemoveFromList(comm2_tower_ident, TOWER);
+ if(comm2_type == TOWER) {
+ comm2_type = INVALID; // Only invalidate if we haven't switched it to something else
+ }
+ comm2_tower_valid = false;
+ comm2_tower_ident = "";
+ last_comm2_tower_ident = "";
+ comm2_atc_ptr = NULL;
}
}
- ++atc_list_itr;
}
}