1
0
Fork 0

Vivian MEAZZA:

"Remove unnecessary, redundant or duplicated code. Functionally, there is no
change"
This commit is contained in:
mfranz 2006-05-24 10:06:44 +00:00
parent b08a588fb1
commit dab5434edb
2 changed files with 86 additions and 184 deletions

View file

@ -49,7 +49,7 @@ TACAN::TACAN ( SGPropertyNode *node )
: _last_distance_nm(0),
_last_frequency_mhz(-1),
_time_before_search_sec(0),
_carrier_valid(false),
_mobile_valid(false),
_transmitter_valid(false),
_transmitter_elevation_ft(0),
_transmitter_range_nm(0),
@ -81,7 +81,7 @@ TACAN::TACAN ()
: _last_distance_nm(0),
_last_frequency_mhz(-1),
_time_before_search_sec(0),
_carrier_valid(false),
_mobile_valid(false),
_transmitter_valid(false),
_transmitter_elevation_ft(0),
_transmitter_range_nm(0),
@ -149,20 +149,10 @@ TACAN::update (double delta_time_sec)
double az2 = 0;
double bearing = 0;
double distance = 0;
double carrier_az2 = 0;
double carrier_bearing = 0;
double carrier_distance = 0;
double tanker_az2 = 0;
double tanker_bearing = 0;
double tanker_distance = 0;
double frequency_mhz = 0;
double mobile_az2 = 0;
double mobile_bearing = 0;
double mobile_distance = 0;
double mobile_elevation_ft = 0;
double mobile_range_nm = 0;
double mobile_bias = 0;
string mobile_name = "";
bool mobile_valid = false;
double frequency_mhz = 0;
string _channel, _last_channel, _channel_1, _channel_2,_channel_3, _channel_4;
@ -223,30 +213,17 @@ TACAN::update (double delta_time_sec)
// Calculate the distance to the transmitter
//calculate the bearing and range of the carrier from the aircraft
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lat " << _carrier_lat);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lon " << _carrier_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_name " << _carrier_name);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_valid " << _carrier_valid);
//calculate the bearing and range of the mobile from the aircraft
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lat " << _mobile_lat);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_lon " << _mobile_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_name " << _mobile_name);
SG_LOG( SG_INSTR, SG_DEBUG, "carrier_valid " << _mobile_valid);
geo_inverse_wgs_84(altitude_m,
latitude_deg,
longitude_deg,
_carrier_lat,
_carrier_lon,
&carrier_bearing, &carrier_az2, &carrier_distance);
//calculate the bearing and range of the tanker from the aircraft
SG_LOG( SG_INSTR, SG_DEBUG, "tanker_lat " << _tanker_lat);
SG_LOG( SG_INSTR, SG_DEBUG, "tanker_lon " << _tanker_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "tanker_name " << _tanker_name);
SG_LOG( SG_INSTR, SG_DEBUG, "tanker_valid " << _tanker_valid);
geo_inverse_wgs_84(altitude_m,
latitude_deg,
longitude_deg,
_tanker_lat,
_tanker_lon,
&tanker_bearing, &tanker_az2, &tanker_distance);
_mobile_lat,
_mobile_lon,
&mobile_bearing, &mobile_az2, &mobile_distance);
//calculate the bearing and range of the station from the aircraft
geo_inverse_wgs_84(altitude_m,
@ -256,63 +233,17 @@ TACAN::update (double delta_time_sec)
_transmitter_lon,
&bearing, &az2, &distance);
//select the nearest valid mobile transmitter
if ( _carrier_valid && (_tanker_valid || _mp_tanker_valid ) ) {
if( carrier_distance <= tanker_distance ){
SG_LOG( SG_INSTR, SG_DEBUG, " select carrier (dist) " );
mobile_bearing = carrier_bearing;
mobile_distance = carrier_distance;
mobile_elevation_ft = _carrier_elevation_ft;
mobile_range_nm = _carrier_range_nm;
mobile_bias = _carrier_bias;
mobile_name = _carrier_name;
}else{
SG_LOG( SG_INSTR, SG_DEBUG, " select tanker (dist) " );
mobile_bearing = tanker_bearing;
mobile_distance = tanker_distance;
mobile_elevation_ft = _tanker_elevation_ft;
mobile_range_nm = _tanker_range_nm;
mobile_bias = _tanker_bias;
mobile_name = _tanker_name;
}
mobile_valid = true;
}
else if ( _carrier_valid && (!_tanker_valid || _mp_tanker_valid) ) {
SG_LOG( SG_INSTR, SG_DEBUG, " select carrier " );
mobile_bearing = carrier_bearing;
mobile_distance = carrier_distance;
mobile_elevation_ft = _carrier_elevation_ft;
mobile_range_nm = _carrier_range_nm;
mobile_bias = _carrier_bias;
mobile_name = _carrier_name;
mobile_valid = true;
}
else if ( !_carrier_valid && (_tanker_valid || _mp_tanker_valid ) ) {
SG_LOG( SG_INSTR, SG_DEBUG, " select tanker " );
mobile_bearing = tanker_bearing;
mobile_distance = tanker_distance;
mobile_elevation_ft = _tanker_elevation_ft;
mobile_range_nm = _tanker_range_nm;
mobile_bias = _tanker_bias;
mobile_name = _tanker_name;
mobile_valid = true;
}else{
mobile_valid = false;
}
//select the nearer
if ( mobile_distance <= distance && mobile_valid) {
if ( mobile_distance <= distance && _mobile_valid) {
SG_LOG( SG_INSTR, SG_DEBUG, "mobile_distance_m " << mobile_distance);
SG_LOG( SG_INSTR, SG_DEBUG, "distance_m " << distance);
bearing = mobile_bearing;
distance = mobile_distance;
_transmitter_elevation_ft = mobile_elevation_ft;
_transmitter_range_nm = mobile_range_nm;
_transmitter_bias = mobile_bias;
_transmitter_name = mobile_name;
_transmitter_elevation_ft = _mobile_elevation_ft;
_transmitter_range_nm = _mobile_range_nm;
_transmitter_bias = _mobile_bias;
_transmitter_name = _mobile_name;
_name_node->setStringValue(_transmitter_name.c_str());
_channel_node->setStringValue(_channel.c_str());
}
@ -329,7 +260,7 @@ TACAN::update (double delta_time_sec)
//// now correct look left/right for yaw
// horiz_offset += yaw;
// use the bearing for plan position indicator display
// use the bearing for a plan position indicator display
double horiz_offset = bearing;
@ -382,7 +313,7 @@ TACAN::update (double delta_time_sec)
}
// If we can't find a valid station set everything to zero
if (!_transmitter_valid && !mobile_valid ) {
if (!_transmitter_valid && !_mobile_valid ) {
_in_range_node->setBoolValue(false);
_distance_node->setDoubleValue(0);
_speed_node->setDoubleValue(0);
@ -403,6 +334,7 @@ TACAN::search (double frequency_mhz, double longitude_rad,
double latitude_rad, double altitude_m)
{
int number, i;
bool freq_valid = false;
SG_LOG( SG_INSTR, SG_DEBUG, "tacan freq " << frequency_mhz );
@ -410,14 +342,14 @@ TACAN::search (double frequency_mhz, double longitude_rad,
_time_before_search_sec = 1.0;
//try any carriers first
FGNavRecord *carrier_tacan
FGNavRecord *mobile_tacan
= globals->get_carrierlist()->findStationByFreq( frequency_mhz );
_carrier_valid = (carrier_tacan != NULL);
freq_valid = (mobile_tacan != NULL);
SG_LOG( SG_INSTR, SG_DEBUG, "mobile freqency valid " << freq_valid );
if ( _carrier_valid ) {
SG_LOG( SG_INSTR, SG_DEBUG, "carrier transmitter valid " << _carrier_valid );
if ( freq_valid ) {
string str1( carrier_tacan->get_name() );
string str1( mobile_tacan->get_name() );
SGPropertyNode * branch = fgGetNode("ai/models", true);
vector<SGPropertyNode_ptr> carrier = branch->getChildren("carrier");
@ -434,40 +366,29 @@ TACAN::search (double frequency_mhz, double longitude_rad,
unsigned int loc1= str1.find( str2, 0 );
if ( loc1 != string::npos && str2 != "" ) {
SG_LOG( SG_INSTR, SG_DEBUG, " string found" );
_carrier_lat = carrier[i]->getDoubleValue("position/latitude-deg");
_carrier_lon = carrier[i]->getDoubleValue("position/longitude-deg");
_carrier_elevation_ft = carrier_tacan->get_elev_ft();
_carrier_range_nm = carrier_tacan->get_range();
_carrier_bias = carrier_tacan->get_multiuse();
_carrier_name = carrier_tacan->get_name();
_carrier_valid = 1;
SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter valid " << _carrier_valid );
_mobile_lat = carrier[i]->getDoubleValue("position/latitude-deg");
_mobile_lon = carrier[i]->getDoubleValue("position/longitude-deg");
_mobile_elevation_ft = mobile_tacan->get_elev_ft();
_mobile_range_nm = mobile_tacan->get_range();
_mobile_bias = mobile_tacan->get_multiuse();
_mobile_name = mobile_tacan->get_name();
_mobile_valid = true;
SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter valid " << _mobile_valid );
break;
} else {
_carrier_valid = 0;
SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter invalid " << _carrier_valid );
_mobile_valid = false;
SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter invalid " << _mobile_valid );
}
}
SG_LOG( SG_INSTR, SG_DEBUG, "name " << _carrier_name);
SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _carrier_lat << "lon " << _carrier_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _carrier_elevation_ft);
SG_LOG( SG_INSTR, SG_DEBUG, "name " << _mobile_name);
SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _mobile_lat << "lon " << _mobile_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _mobile_elevation_ft);
} else {
SG_LOG( SG_INSTR, SG_DEBUG, " carrier transmitter invalid " << _carrier_valid );
}
//try any AI tankers second
//try any tankers second
FGNavRecord *tanker_tacan
= globals->get_carrierlist()->findStationByFreq( frequency_mhz );
_tanker_valid = (tanker_tacan != NULL);
if ( _tanker_valid ) {
SG_LOG( SG_INSTR, SG_DEBUG, "tanker transmitter valid start " << _tanker_valid );
string str3( tanker_tacan->get_name() );
if ( !_mobile_valid) {
SG_LOG( SG_INSTR, SG_DEBUG, "tanker transmitter valid start " << _mobile_valid );
SGPropertyNode * branch = fgGetNode("ai/models", true);
vector<SGPropertyNode_ptr> tanker = branch->getChildren("aircraft");
@ -480,45 +401,35 @@ TACAN::search (double frequency_mhz, double longitude_rad,
string str4 ( tanker[i]->getStringValue("callsign", ""));
SG_LOG( SG_INSTR, SG_DEBUG, "tanker callsign " << str4 );
SG_LOG( SG_INSTR, SG_DEBUG, "strings 3 " << str3 << " 4 " << str4 );
unsigned int loc1= str3.find( str4, 0 );
SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 4 " << str4 );
unsigned int loc1= str1.find( str4, 0 );
if ( loc1 != string::npos && str4 != "" ) {
SG_LOG( SG_INSTR, SG_DEBUG, " string found" );
_tanker_lat = tanker[i]->getDoubleValue("position/latitude-deg");
_tanker_lon = tanker[i]->getDoubleValue("position/longitude-deg");
_tanker_elevation_ft = tanker[i]->getDoubleValue("position/altitude-ft");
_tanker_range_nm = tanker_tacan->get_range();
_tanker_bias = tanker_tacan->get_multiuse();
_tanker_name = tanker_tacan->get_name();
_tanker_valid = 1;
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter valid " << _tanker_valid );
_mobile_lat = tanker[i]->getDoubleValue("position/latitude-deg");
_mobile_lon = tanker[i]->getDoubleValue("position/longitude-deg");
_mobile_elevation_ft = tanker[i]->getDoubleValue("position/altitude-ft");
_mobile_range_nm = mobile_tacan->get_range();
_mobile_bias = mobile_tacan->get_multiuse();
_mobile_name = mobile_tacan->get_name();
_mobile_valid = true;
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter valid " << _mobile_valid );
break;
} else {
_tanker_valid = 0;
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _tanker_valid );
_mobile_valid = false;
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _mobile_valid );
}
}
SG_LOG( SG_INSTR, SG_DEBUG, "tanker name " << _tanker_name);
SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _tanker_lat << "lon " << _tanker_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _tanker_elevation_ft);
SG_LOG( SG_INSTR, SG_DEBUG, "range " << _tanker_range_nm);
} else {
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _tanker_valid );
SG_LOG( SG_INSTR, SG_DEBUG, "tanker name " << _mobile_name);
SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _mobile_lat << "lon " << _mobile_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _mobile_elevation_ft);
SG_LOG( SG_INSTR, SG_DEBUG, "range " << _mobile_range_nm);
}
//try any mp tankers third, if we haven't found the tanker in the ai aircraft
FGNavRecord *mp_tanker_tacan
= globals->get_carrierlist()->findStationByFreq( frequency_mhz );
_mp_tanker_valid = (mp_tanker_tacan != NULL);
if ( _mp_tanker_valid && ! _tanker_valid ) {
SG_LOG( SG_INSTR, SG_DEBUG, " mp tanker transmitter valid start " << _mp_tanker_valid );
string str5( mp_tanker_tacan->get_name() );
if ( !_mobile_valid ) {
SG_LOG( SG_INSTR, SG_DEBUG, " mp tanker transmitter valid start " << _mobile_valid );
SGPropertyNode * branch = fgGetNode("ai/models", true);
vector<SGPropertyNode_ptr> mp_tanker = branch->getChildren("multiplayer");
@ -531,35 +442,35 @@ TACAN::search (double frequency_mhz, double longitude_rad,
string str6 ( mp_tanker[i]->getStringValue("callsign", ""));
SG_LOG( SG_INSTR, SG_DEBUG, "mp tanker callsign " << str6 );
SG_LOG( SG_INSTR, SG_DEBUG, "strings 5 " << str5 << " 5 " << str6 );
unsigned int loc1= str5.find( str6, 0 );
SG_LOG( SG_INSTR, SG_DEBUG, "strings 1 " << str1 << " 5 " << str6 );
unsigned int loc1= str1.find( str6, 0 );
if ( loc1 != string::npos && str6 != "" ) {
SG_LOG( SG_INSTR, SG_DEBUG, " string found" );
_tanker_lat = mp_tanker[i]->getDoubleValue("position/latitude-deg");
_tanker_lon = mp_tanker[i]->getDoubleValue("position/longitude-deg");
_tanker_elevation_ft = mp_tanker[i]->getDoubleValue("position/altitude-ft");
_tanker_range_nm = mp_tanker_tacan->get_range();
_tanker_bias = mp_tanker_tacan->get_multiuse();
_tanker_name = mp_tanker_tacan->get_name();
_mp_tanker_valid = 1;
_mobile_lat = mp_tanker[i]->getDoubleValue("position/latitude-deg");
_mobile_lon = mp_tanker[i]->getDoubleValue("position/longitude-deg");
_mobile_elevation_ft = mp_tanker[i]->getDoubleValue("position/altitude-ft");
_mobile_range_nm = mobile_tacan->get_range();
_mobile_bias = mobile_tacan->get_multiuse();
_mobile_name = mobile_tacan->get_name();
_mobile_valid = true;
SG_LOG( SG_INSTR, SG_DEBUG, " mp tanker transmitter valid " << _mp_tanker_valid );
SG_LOG( SG_INSTR, SG_DEBUG, "mp_tanker name " << _tanker_name);
SG_LOG( SG_INSTR, SG_DEBUG, "lat " << _tanker_lat << "lon " << _tanker_lon);
SG_LOG( SG_INSTR, SG_DEBUG, "elev " << _tanker_elevation_ft);
SG_LOG( SG_INSTR, SG_DEBUG, "range " << _tanker_range_nm);
SG_LOG( SG_INSTR, SG_DEBUG, " mp tanker transmitter valid " << _mobile_valid );
SG_LOG( SG_INSTR, SG_DEBUG, " mp_tanker name " << _mobile_name);
SG_LOG( SG_INSTR, SG_DEBUG, " mp lat " << _mobile_lat << "lon " << _mobile_lon);
SG_LOG( SG_INSTR, SG_DEBUG, " mp elev " << _mobile_elevation_ft);
SG_LOG( SG_INSTR, SG_DEBUG, " mp range " << _mobile_range_nm);
break;
} else {
_mp_tanker_valid = 0;
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _mp_tanker_valid );
_mobile_valid = false;
SG_LOG( SG_INSTR, SG_DEBUG, " mp tanker transmitter invalid " << _mobile_valid );
}
}
}
} else {
SG_LOG( SG_INSTR, SG_DEBUG, " tanker transmitter invalid " << _tanker_valid );
_mobile_valid = false;
SG_LOG( SG_INSTR, SG_DEBUG, " mobile transmitter invalid " << _mobile_valid );
}
// try the TACAN/VORTAC list next
FGNavRecord *tacan
= globals->get_tacanlist()->findByFreq( frequency_mhz, longitude_rad,

View file

@ -87,9 +87,7 @@ private:
double _last_frequency_mhz;
double _time_before_search_sec;
bool _carrier_valid;
bool _tanker_valid;
bool _mp_tanker_valid;
bool _mobile_valid;
bool _transmitter_valid;
Point3D _transmitter;
@ -100,19 +98,12 @@ private:
double _transmitter_bias;
string _transmitter_name;
double _carrier_lat, _carrier_lon;
double _carrier_elevation_ft;
double _carrier_range_nm;
double _carrier_bearing_deg;
double _carrier_bias;
string _carrier_name;
double _tanker_lat, _tanker_lon;
double _tanker_elevation_ft;
double _tanker_range_nm;
double _tanker_bearing_deg;
double _tanker_bias;
string _tanker_name;
double _mobile_lat, _mobile_lon;
double _mobile_elevation_ft;
double _mobile_range_nm;
double _mobile_bearing_deg;
double _mobile_bias;
string _mobile_name;
string name;
int num;