X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FATCDCL%2FAIMgr.cxx;h=8b6c448bc8d63720d59e64509a01bd174018815e;hb=7aba4333a261df723fcbe9eaf86c16af89372595;hp=c8f7b8b028fb8f67bc953774755b480ea9acc802;hpb=667e64e1ebc86a0c53112b92b53475898f315c36;p=flightgear.git diff --git a/src/ATCDCL/AIMgr.cxx b/src/ATCDCL/AIMgr.cxx index c8f7b8b02..8b6c448bc 100644 --- a/src/ATCDCL/AIMgr.cxx +++ b/src/ATCDCL/AIMgr.cxx @@ -23,6 +23,8 @@ # include #endif +#include + #include
#include
#include @@ -51,6 +53,9 @@ using std::cout; using namespace simgear; +// extern from Airports/simple.cxx +extern SGGeod fgGetAirportPos( const std::string& id ); + FGAIMgr::FGAIMgr() { ATC = globals->get_ATC_mgr(); initDone = false; @@ -74,10 +79,6 @@ void FGAIMgr::init() { lon_node = fgGetNode("/position/longitude-deg", true); lat_node = fgGetNode("/position/latitude-deg", true); elev_node = fgGetNode("/position/altitude-ft", true); - - lon = lon_node->getDoubleValue(); - lat = lat_node->getDoubleValue(); - elev = elev_node->getDoubleValue(); // Load up models at the start to avoid pausing later // Hack alert - Hardwired paths!! @@ -146,24 +147,6 @@ void FGAIMgr::init() { SearchByPos(15.0); initDone = true; - - //cout << "AIMgr::init done..." << endl; - - /* - // TESTING - FGATCAlignedProjection ortho; - ortho.Init(fgGetAirportPos("KEMT"), 205.0); // Guess of rwy19 heading - //Point3D ip = ortho.ConvertFromLocal(Point3D(6000, 1000, 1000)); // 90 deg entry - //Point3D ip = ortho.ConvertFromLocal(Point3D(-7000, 3000, 1000)); // 45 deg entry - Point3D ip = ortho.ConvertFromLocal(Point3D(1000, -7000, 1000)); // straight-in - ATC->AIRegisterAirport("KEMT"); - FGAIGAVFRTraffic* p = new FGAIGAVFRTraffic(); - p->SetModel(_defaultModel); - p->Init(ip, "KEMT", GenerateShortForm(GenerateUniqueCallsign())); - ai_list.push_back(p); - traffic[ident].push_back(p); - activated["KEMT"] = 1; - */ } void FGAIMgr::bind() { @@ -180,7 +163,7 @@ void FGAIMgr::update(double dt) { //cout << activated.size() << '\n'; - Point3D userPos = Point3D(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue()); + SGGeod userPos = SGGeod::fromDegM(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue()); // TODO - make these class variables!! static int i = 0; @@ -239,7 +222,7 @@ void FGAIMgr::update(double dt) { //cout << "Size of list is " << (*it).second.size() << " at " << s << '\n'; if((*it).second.size()) { FGAIEntity* e = *((*it).second.rbegin()); // Get the last airplane currently scheduled to arrive at this airport. - cd = dclGetHorizontalSeparation(e->GetPos(), fgGetAirportPos(s)); + cd = dclGetHorizontalSeparation(e->getPos(), fgGetAirportPos(s)); if(cd < (d < 5000 ? 10000 : d + 5000)) { gen = true; } @@ -335,11 +318,11 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) } */ - Point3D aptpos = fgGetAirportPos(ident); // TODO - check for elev of -9999 - //cout << "ident = " << ident << ", elev = " << aptpos.elev() << '\n'; + SGGeod aptpos = fgGetAirportPos(ident); // TODO - check for elev of -9999 + //cout << "ident = " << ident << ", elev = " << aptpos.getElevationM() << '\n'; // Operate from airports at 3000ft and below only to avoid the default cloud layers and since we don't degrade AI performance with altitude. - if(aptpos.elev() > 3000) { + if(aptpos.getElevationM() > 3000) { //cout << "High alt airports not yet supported - returning\n"; return; } @@ -349,7 +332,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) // Get the time and only operate VFR in the (approximate) daytime. struct tm *t = globals->get_time_params()->getGmt(); - int loc_time = t->tm_hour + int(aptpos.lon() / (360.0 / 24.0)); + int loc_time = t->tm_hour + int(aptpos.getLongitudeDeg() / (360.0 / 24.0)); while (loc_time < 0) loc_time += 24; while (loc_time >= 24) @@ -362,7 +345,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) double visibility; FGEnvironment stationweather = ((FGEnvironmentMgr *)globals->get_subsystem("environment")) - ->getEnvironment(aptpos.lat(), aptpos.lon(), aptpos.elev()); // TODO - check whether this should take ft or m for elev. + ->getEnvironment(aptpos.getLatitudeDeg(), aptpos.getLongitudeDeg(), aptpos.getElevationM()); // TODO - check whether this should take ft or m for elev. visibility = stationweather.get_visibility_m(); // Technically we can do VFR down to 1 mile (1600m) but that's pretty murky! //cout << "vis = " << visibility << '\n'; @@ -371,7 +354,7 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) ATC->AIRegisterAirport(ident); // Next - get the distance from user to the airport. - Point3D userpos = Point3D(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue()); + SGGeod userpos = SGGeod::fromDegM(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue()); double d = dclGetHorizontalSeparation(userpos, aptpos); // in meters int lev = fgGetInt("/sim/ai-traffic/level"); @@ -408,8 +391,8 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic(); t->SetModel(cessna ? _defaultModel : _piperModel); //cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n"; - Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad); - if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0); + SGGeod tpos = dclUpdatePosition(aptpos, dir, 6.0, ad); + if(tpos.getElevationM() > (aptpos.getElevationM() + 3000.0)) tpos.setElevationM(aptpos.getElevationM() + 3000.0); t->Init(tpos, ident, s); ai_list.push_back(t); } @@ -468,8 +451,8 @@ void FGAIMgr::GenerateSimpleAirportTraffic(const string& ident, double min_dist) FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic(); t->SetModel(cessna ? _defaultModel.get() : (_havePiperModel ? _piperModel.get() : _defaultModel.get())); //cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n"; - Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad); - if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0); // FEET yuk :-( + SGGeod tpos = dclUpdatePosition(aptpos, dir, 6.0, ad); + if(tpos.getElevationM() > (aptpos.getElevationM() + 3000.0)) tpos.setElevationM(aptpos.getElevationM() + 3000.0); // FEET yuk :-( t->Init(tpos, ident, s); ai_list.push_back(t); traffic[ident].push_back(t); @@ -488,10 +471,9 @@ void FGAIMgr::SearchByPos(double range) { //cout << "In SearchByPos(...)" << endl; // get bucket number for plane position - lon = lon_node->getDoubleValue(); - lat = lat_node->getDoubleValue(); - elev = elev_node->getDoubleValue() * SG_FEET_TO_METER; - SGBucket buck(lon, lat); + _userAircraftPos = SGGeod::fromDegFt(lon_node->getDoubleValue(), + lat_node->getDoubleValue(), elev_node->getDoubleValue()); + SGBucket buck(_userAircraftPos); // get neigboring buckets int bx = (int)( range*SG_NM_TO_METER / buck.get_width_m() / 2); @@ -505,7 +487,7 @@ void FGAIMgr::SearchByPos(double range) { //cout << "i loop\n"; for ( int j=-by; j<=by; j++) { //cout << "j loop\n"; - buck = sgBucketOffset(lon, lat, i, j); + buck = sgBucketOffset(_userAircraftPos.getLongitudeDeg(), _userAircraftPos.getLatitudeDeg(), i, j); long int bucket = buck.gen_index(); //cout << "bucket is " << bucket << endl; if(facilities.find(bucket) != facilities.end()) { @@ -517,8 +499,6 @@ void FGAIMgr::SearchByPos(double range) { //double rlon = lon * SGD_DEGREES_TO_RADIANS; //double rlat = lat * SGD_DEGREES_TO_RADIANS; - //Point3D aircraft = sgGeodToCart( Point3D(rlon, rlat, elev) ); - //Point3D airport; for(; current != last; ++current) { //cout << "Found " << *current << endl;; if(activated.find(*current) == activated.end()) { @@ -545,14 +525,14 @@ void FGAIMgr::SearchByPos(double range) { comm_list_type towered; comm_list_iterator twd_itr; - int num_twd = current_commlist->FindByPos(lon, lat, elev, range, &towered, TOWER); + int num_twd = current_commlist->FindByPos(_userAircraftPos, range, &towered, TOWER); if (num_twd != 0) { double closest = 1000000; string s = ""; for(twd_itr = towered.begin(); twd_itr != towered.end(); twd_itr++) { // Only activate the closest airport not already activated each time. if(activated.find(twd_itr->ident) == activated.end()) { - double sep = dclGetHorizontalSeparation(Point3D(lon, lat, elev), fgGetAirportPos(twd_itr->ident)); + double sep = dclGetHorizontalSeparation(_userAircraftPos, fgGetAirportPos(twd_itr->ident)); if(sep < closest) { closest = sep; s = twd_itr->ident; @@ -616,7 +596,7 @@ string FGAIMgr::GenerateShortForm(const string& callsign, const string& plane_st //cout << c << '\n'; string tmp = ""; tmp += c; - if(isalpha(c)) s += GetPhoneticIdent(c); + if(isalpha(c)) s += GetPhoneticLetter(c); else s += ConvertNumToSpokenDigits(tmp); if(i > 1) s += '-'; }